-
Notifications
You must be signed in to change notification settings - Fork 157
Expand file tree
/
Copy pathindex.ts
More file actions
109 lines (101 loc) · 2.88 KB
/
Copy pathindex.ts
File metadata and controls
109 lines (101 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import express from 'express';
import { A2A_PROTOCOL_VERSION, AgentCard } from '../../index.js';
import {
InMemoryTaskStore,
TaskStore,
AgentExecutor,
DefaultRequestHandler,
} from '../../server/index.js';
import { jsonRpcHandler } from '../../server/express/index.js';
import { AuthenticationAgentExecutor } from './agent_executor.js';
import { userBuilder } from './user_builder.js';
import { authenticationHandler } from './authentication_middleware.js';
// --- Server Setup ---
const authenticationAgentCard: AgentCard = {
name: 'Sample Authentication Agent',
description: 'A sample agent to test the authentication functionality',
supportedInterfaces: [
{
url: 'http://localhost:41241/',
protocolBinding: 'JSONRPC',
tenant: '',
protocolVersion: A2A_PROTOCOL_VERSION,
},
],
provider: {
organization: 'A2A Samples',
url: 'https://example.com/a2a-samples',
},
version: '1.0.0',
capabilities: {
streaming: false,
pushNotifications: false,
extensions: [],
extendedAgentCard: false,
},
defaultInputModes: ['text'],
defaultOutputModes: ['text', 'task-status'],
skills: [
{
id: 'sample_agent',
name: 'Sample Agent',
description: 'Simulate the general flow of an agent with authentication feature.',
tags: ['sample'],
examples: ['hello, who am i?'],
inputModes: ['text'],
outputModes: ['text', 'task-status'],
securityRequirements: [],
},
],
securityRequirements: [{ schemes: { Bearer: { list: [] } } }],
securitySchemes: {
Bearer: {
scheme: {
$case: 'httpAuthSecurityScheme',
value: {
description: 'Bearer Token',
scheme: 'bearer',
bearerFormat: 'JWT',
},
},
},
},
documentationUrl: 'https://example.com/docs',
signatures: [],
};
async function main() {
// 1. Create TaskStore
const taskStore: TaskStore = new InMemoryTaskStore();
// 2. Create AgentExecutor
const agentExecutor: AgentExecutor = new AuthenticationAgentExecutor();
// 3. Create DefaultRequestHandler
const requestHandler = new DefaultRequestHandler(
authenticationAgentCard,
taskStore,
agentExecutor
);
// 4. Create and setup express app, with authentication middleware and user builder.
const app = express();
app.use(authenticationHandler);
app.use(
jsonRpcHandler({
requestHandler,
userBuilder,
})
);
// 5. Start the server
const PORT = process.env.PORT || 41241;
app.listen(PORT, (err: unknown) => {
if (err) {
throw err;
}
console.log(
`[AuthenticationAgent] Server using new framework started on http://localhost:${PORT}`
);
console.log(
`[AuthenticationAgent] Agent Card: http://localhost:${PORT}/.well-known/agent-card.json`
);
console.log('[AuthenticationAgent] Press Ctrl+C to stop the server');
});
}
main().catch(console.error);