-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.ts
More file actions
81 lines (72 loc) · 2.2 KB
/
Copy pathserver.ts
File metadata and controls
81 lines (72 loc) · 2.2 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
import {
ARCPServer,
InMemoryCredentialStore,
StaticBearerVerifier,
startWebSocketServer,
type CredentialIssueContext,
type CredentialProvisioner,
type IssuedCredential,
} from "@agentruntimecontrolprotocol/sdk";
const PORT = Number(process.env["ARCP_DEMO_PORT"] ?? 7899);
const TOKEN = process.env["ARCP_DEMO_TOKEN"] ?? "demo-token";
class MockProvisioner implements CredentialProvisioner {
public readonly revoked: string[] = [];
async issue(ctx: CredentialIssueContext): Promise<IssuedCredential[]> {
const models = ctx.lease["model.use"] ?? [];
if (models.length === 0) return [];
const id = `${ctx.jobId}:mock-llm`;
return [
{
wire: {
id,
scheme: "bearer",
value: `mock-key-${ctx.jobId}`,
endpoint: "http://localhost/mock-llm/v1",
constraints: {
allowed_models: [...models],
...(ctx.leaseConstraints?.expires_at === undefined
? {}
: { expires_at: ctx.leaseConstraints.expires_at }),
},
},
provisionerId: id,
},
];
}
async revoke(provisionerId: string): Promise<void> {
this.revoked.push(provisionerId);
process.stdout.write(`revoked ${provisionerId}\n`);
}
}
async function main(): Promise<void> {
const server = new ARCPServer({
runtime: { name: "provisioned-credentials-demo", version: "1.0.0" },
capabilities: {
encodings: ["json"],
agents: ["ask-model"],
},
bearer: new StaticBearerVerifier(new Map([[TOKEN, { principal: "demo" }]])),
credentialProvisioner: new MockProvisioner(),
credentialStore: new InMemoryCredentialStore(),
});
server.registerAgent("ask-model", async (_input, ctx) => {
return {
modelLease: ctx.lease["model.use"] ?? [],
};
});
const ws = await startWebSocketServer({
host: "127.0.0.1",
port: PORT,
onTransport: (t) => {
server.accept(t);
},
});
process.stdout.write(`ARCP server listening on ${ws.url}\n`);
process.on("SIGINT", () => {
void ws.close().then(() => server.close());
});
}
void main().catch((err) => {
process.stderr.write(`${err instanceof Error ? err.stack : String(err)}\n`);
process.exit(1);
});