@slashfi/agents-sdk 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-definitions/auth.d.ts +17 -0
- package/dist/agent-definitions/auth.d.ts.map +1 -1
- package/dist/agent-definitions/auth.js +135 -1
- package/dist/agent-definitions/auth.js.map +1 -1
- package/dist/agent-definitions/integrations.d.ts +28 -12
- package/dist/agent-definitions/integrations.d.ts.map +1 -1
- package/dist/agent-definitions/integrations.js +239 -41
- package/dist/agent-definitions/integrations.js.map +1 -1
- package/dist/agent-definitions/remote-registry.d.ts +32 -0
- package/dist/agent-definitions/remote-registry.d.ts.map +1 -0
- package/dist/agent-definitions/remote-registry.js +460 -0
- package/dist/agent-definitions/remote-registry.js.map +1 -0
- package/dist/index.d.ts +12 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -2
- package/dist/index.js.map +1 -1
- package/dist/integration-interface.d.ts +37 -0
- package/dist/integration-interface.d.ts.map +1 -0
- package/dist/integration-interface.js +94 -0
- package/dist/integration-interface.js.map +1 -0
- package/dist/integrations-store.d.ts +33 -0
- package/dist/integrations-store.d.ts.map +1 -0
- package/dist/integrations-store.js +50 -0
- package/dist/integrations-store.js.map +1 -0
- package/dist/jwt.d.ts +86 -17
- package/dist/jwt.d.ts.map +1 -1
- package/dist/jwt.js +140 -17
- package/dist/jwt.js.map +1 -1
- package/dist/registry.d.ts +7 -0
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +14 -21
- package/dist/registry.js.map +1 -1
- package/dist/secret-collection.d.ts +37 -0
- package/dist/secret-collection.d.ts.map +1 -0
- package/dist/secret-collection.js +37 -0
- package/dist/secret-collection.js.map +1 -0
- package/dist/server.d.ts +41 -42
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +232 -555
- package/dist/server.js.map +1 -1
- package/dist/types.d.ts +24 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +5 -2
- package/src/agent-definitions/auth.ts +187 -1
- package/src/agent-definitions/integrations.ts +287 -55
- package/src/agent-definitions/remote-registry.ts +621 -0
- package/src/index.ts +22 -5
- package/src/integration-interface.ts +118 -0
- package/src/integrations-store.ts +84 -0
- package/src/jwt.ts +233 -65
- package/src/registry.ts +23 -2
- package/src/secret-collection.ts +66 -0
- package/src/server.ts +268 -647
- package/src/types.ts +28 -2
- package/dist/slack-oauth.d.ts +0 -27
- package/dist/slack-oauth.d.ts.map +0 -1
- package/dist/slack-oauth.js +0 -48
- package/dist/slack-oauth.js.map +0 -1
- package/dist/web-pages.d.ts +0 -8
- package/dist/web-pages.d.ts.map +0 -1
- package/dist/web-pages.js +0 -169
- package/dist/web-pages.js.map +0 -1
- package/src/slack-oauth.ts +0 -66
- package/src/web-pages.ts +0 -178
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integration interface — standard tools that integration agents implement.
|
|
3
|
+
*
|
|
4
|
+
* Any agent that acts as an integration source should implement these tools.
|
|
5
|
+
* They are all internal visibility and only callable by @integrations.
|
|
6
|
+
*/
|
|
7
|
+
import { defineTool } from './define.js';
|
|
8
|
+
/**
|
|
9
|
+
* Create the standard _integration tools for an agent.
|
|
10
|
+
* Returns an array of ToolDefinitions to include in the agent's tools.
|
|
11
|
+
*/
|
|
12
|
+
export function createIntegrationTools(config) {
|
|
13
|
+
const { agentPath, store, discover, setup, connect } = config;
|
|
14
|
+
const discoverTool = defineTool({
|
|
15
|
+
name: 'discover_integrations',
|
|
16
|
+
description: `Discover available integrations for ${agentPath}.`,
|
|
17
|
+
visibility: 'internal',
|
|
18
|
+
inputSchema: {
|
|
19
|
+
type: 'object',
|
|
20
|
+
properties: {},
|
|
21
|
+
},
|
|
22
|
+
execute: async () => {
|
|
23
|
+
const available = await discover();
|
|
24
|
+
return available;
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
const setupTool = defineTool({
|
|
28
|
+
name: 'setup_integration',
|
|
29
|
+
description: `Set up a new integration for ${agentPath}.`,
|
|
30
|
+
visibility: 'internal',
|
|
31
|
+
inputSchema: {
|
|
32
|
+
type: 'object',
|
|
33
|
+
properties: {
|
|
34
|
+
config: { type: 'object', description: 'Integration configuration' },
|
|
35
|
+
},
|
|
36
|
+
required: ['config'],
|
|
37
|
+
},
|
|
38
|
+
execute: async (input, ctx) => {
|
|
39
|
+
const result = await setup(input.config, ctx);
|
|
40
|
+
if (result.success && !result.oauthUrl) {
|
|
41
|
+
// Direct setup (no OAuth needed) — create integration row
|
|
42
|
+
const integration = await store.create({
|
|
43
|
+
agentPath,
|
|
44
|
+
config: input.config,
|
|
45
|
+
installedBy: ctx.callerId,
|
|
46
|
+
});
|
|
47
|
+
return { success: true, integrationId: integration.id };
|
|
48
|
+
}
|
|
49
|
+
return result;
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
const connectTool = defineTool({
|
|
53
|
+
name: 'connect_integration',
|
|
54
|
+
description: `Test or authorize a ${agentPath} integration connection.`,
|
|
55
|
+
visibility: 'internal',
|
|
56
|
+
inputSchema: {
|
|
57
|
+
type: 'object',
|
|
58
|
+
properties: {
|
|
59
|
+
integration_id: { type: 'string', description: 'Integration ID to connect' },
|
|
60
|
+
},
|
|
61
|
+
required: ['integration_id'],
|
|
62
|
+
},
|
|
63
|
+
execute: async (input, ctx) => {
|
|
64
|
+
if (connect) {
|
|
65
|
+
const result = await connect(input.integration_id, ctx);
|
|
66
|
+
if (result.success) {
|
|
67
|
+
await store.update(input.integration_id, { status: 'active' });
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
await store.update(input.integration_id, { status: 'error' });
|
|
71
|
+
}
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
return { success: true };
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
const listTool = defineTool({
|
|
78
|
+
name: 'list_integrations',
|
|
79
|
+
description: `List installed integrations for ${agentPath}.`,
|
|
80
|
+
visibility: 'internal',
|
|
81
|
+
inputSchema: {
|
|
82
|
+
type: 'object',
|
|
83
|
+
properties: {
|
|
84
|
+
tenant_id: { type: 'string', description: 'Filter by tenant' },
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
execute: async (input) => {
|
|
88
|
+
const integrations = await store.listByAgent(agentPath, input.tenant_id);
|
|
89
|
+
return integrations;
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
return [discoverTool, setupTool, connectTool, listTool];
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=integration-interface.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"integration-interface.js","sourceRoot":"","sources":["../src/integration-interface.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAqBzC;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CAAC,MAAkC;IACvE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;IAE9D,MAAM,YAAY,GAAG,UAAU,CAAC;QAC9B,IAAI,EAAE,uBAAuB;QAC7B,WAAW,EAAE,uCAAuC,SAAS,GAAG;QAChE,UAAU,EAAE,UAAmB;QAC/B,WAAW,EAAE;YACX,IAAI,EAAE,QAAiB;YACvB,UAAU,EAAE,EAAE;SACf;QACD,OAAO,EAAE,KAAK,IAAI,EAAE;YAClB,MAAM,SAAS,GAAG,MAAM,QAAQ,EAAE,CAAC;YACnC,OAAO,SAAS,CAAC;QACnB,CAAC;KACF,CAAC,CAAC;IAEH,MAAM,SAAS,GAAG,UAAU,CAAC;QAC3B,IAAI,EAAE,mBAAmB;QACzB,WAAW,EAAE,gCAAgC,SAAS,GAAG;QACzD,UAAU,EAAE,UAAmB;QAC/B,WAAW,EAAE;YACX,IAAI,EAAE,QAAiB;YACvB,UAAU,EAAE;gBACV,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,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AM,EAAE,QAAQ,EAAE,CAAC,CAAC;gBACjE,CAAC;qBAAM,CAAC;oBACN,MAAM,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,cAAc,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;gBAChE,CAAC;gBACD,OAAO,MAAM,CAAC;YAChB,CAAC;YACD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QAC3B,CAAC;KACF,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG,UAAU,CAAC;QAC1B,IAAI,EAAE,mBAAmB;QACzB,WAAW,EAAE,mCAAmC,SAAS,GAAG;QAC5D,UAAU,EAAE,UAAmB;QAC/B,WAAW,EAAE;YACX,IAAI,EAAE,QAAiB;YACvB,UAAU,EAAE;gBACV,SAAS,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,kBAAkB,EAAE;aAC/D;SACF;QACD,OAAO,EAAE,KAAK,EAAE,KAA6B,EAAE,EAAE;YAC/C,MAAM,YAAY,GAAG,MAAM,KAAK,CAAC,WAAW,CAAC,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;YACzE,OAAO,YAAY,CAAC;QACtB,CAAC;KACF,CAAC,CAAC;IAEH,OAAO,CAAC,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,CAAkC,CAAC;AAC3F,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IntegrationsStore — persistence interface for installed integrations.
|
|
3
|
+
*
|
|
4
|
+
* Each integration is an agent that's been configured and connected.
|
|
5
|
+
* The store tracks what's installed, its config, and status.
|
|
6
|
+
*/
|
|
7
|
+
export interface Integration {
|
|
8
|
+
id: string;
|
|
9
|
+
agentPath: string;
|
|
10
|
+
tenantId?: string;
|
|
11
|
+
status: 'active' | 'disabled' | 'error';
|
|
12
|
+
config: Record<string, unknown>;
|
|
13
|
+
installedBy?: string;
|
|
14
|
+
installedAt: number;
|
|
15
|
+
updatedAt: number;
|
|
16
|
+
}
|
|
17
|
+
export interface CreateIntegrationInput {
|
|
18
|
+
agentPath: string;
|
|
19
|
+
tenantId?: string;
|
|
20
|
+
config: Record<string, unknown>;
|
|
21
|
+
installedBy?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface IntegrationsStore {
|
|
24
|
+
create(input: CreateIntegrationInput): Promise<Integration>;
|
|
25
|
+
get(id: string): Promise<Integration | null>;
|
|
26
|
+
list(tenantId?: string): Promise<Integration[]>;
|
|
27
|
+
listByAgent(agentPath: string, tenantId?: string): Promise<Integration[]>;
|
|
28
|
+
update(id: string, updates: Partial<Pick<Integration, 'status' | 'config' | 'updatedAt'>>): Promise<Integration | null>;
|
|
29
|
+
delete(id: string): Promise<boolean>;
|
|
30
|
+
}
|
|
31
|
+
/** In-memory implementation for testing / lightweight use */
|
|
32
|
+
export declare function createInMemoryIntegrationsStore(): IntegrationsStore;
|
|
33
|
+
//# sourceMappingURL=integrations-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"integrations-store.d.ts","sourceRoot":"","sources":["../src/integrations-store.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,QAAQ,GAAG,UAAU,GAAG,OAAO,CAAC;IACxC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,sBAAsB;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,CAAC,KAAK,EAAE,sBAAsB,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAC5D,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;IAC7C,IAAI,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;IAChD,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;IAC1E,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,QAAQ,GAAG,QAAQ,GAAG,WAAW,CAAC,CAAC,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;IACxH,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACtC;AAED,6DAA6D;AAC7D,wBAAgB,+BAA+B,IAAI,iBAAiB,CAgDnE"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IntegrationsStore — persistence interface for installed integrations.
|
|
3
|
+
*
|
|
4
|
+
* Each integration is an agent that's been configured and connected.
|
|
5
|
+
* The store tracks what's installed, its config, and status.
|
|
6
|
+
*/
|
|
7
|
+
/** In-memory implementation for testing / lightweight use */
|
|
8
|
+
export function createInMemoryIntegrationsStore() {
|
|
9
|
+
const integrations = new Map();
|
|
10
|
+
return {
|
|
11
|
+
async create(input) {
|
|
12
|
+
const id = `int_${Math.random().toString(36).slice(2, 14)}`;
|
|
13
|
+
const now = Date.now();
|
|
14
|
+
const integration = {
|
|
15
|
+
id,
|
|
16
|
+
agentPath: input.agentPath,
|
|
17
|
+
tenantId: input.tenantId,
|
|
18
|
+
status: 'active',
|
|
19
|
+
config: input.config,
|
|
20
|
+
installedBy: input.installedBy,
|
|
21
|
+
installedAt: now,
|
|
22
|
+
updatedAt: now,
|
|
23
|
+
};
|
|
24
|
+
integrations.set(id, integration);
|
|
25
|
+
return integration;
|
|
26
|
+
},
|
|
27
|
+
async get(id) {
|
|
28
|
+
return integrations.get(id) ?? null;
|
|
29
|
+
},
|
|
30
|
+
async list(tenantId) {
|
|
31
|
+
const all = Array.from(integrations.values());
|
|
32
|
+
return tenantId ? all.filter(i => i.tenantId === tenantId) : all;
|
|
33
|
+
},
|
|
34
|
+
async listByAgent(agentPath, tenantId) {
|
|
35
|
+
return Array.from(integrations.values()).filter(i => i.agentPath === agentPath && (!tenantId || i.tenantId === tenantId));
|
|
36
|
+
},
|
|
37
|
+
async update(id, updates) {
|
|
38
|
+
const existing = integrations.get(id);
|
|
39
|
+
if (!existing)
|
|
40
|
+
return null;
|
|
41
|
+
const updated = { ...existing, ...updates, updatedAt: Date.now() };
|
|
42
|
+
integrations.set(id, updated);
|
|
43
|
+
return updated;
|
|
44
|
+
},
|
|
45
|
+
async delete(id) {
|
|
46
|
+
return integrations.delete(id);
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=integrations-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"integrations-store.js","sourceRoot":"","sources":["../src/integrations-store.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA6BH,6DAA6D;AAC7D,MAAM,UAAU,+BAA+B;IAC7C,MAAM,YAAY,GAAG,IAAI,GAAG,EAAuB,CAAC;IAEpD,OAAO;QACL,KAAK,CAAC,MAAM,CAAC,KAAK;YAChB,MAAM,EAAE,GAAG,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC;YAC5D,MAAM,GAAG,GAAG,IAAI,C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AI,CAAC;YAC3B,MAAM,OAAO,GAAG,EAAE,GAAG,QAAQ,EAAE,GAAG,OAAO,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC;YACnE,YAAY,CAAC,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;YAC9B,OAAO,OAAO,CAAC;QACjB,CAAC;QAED,KAAK,CAAC,MAAM,CAAC,EAAE;YACb,OAAO,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACjC,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/jwt.d.ts
CHANGED
|
@@ -1,38 +1,107 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* JWT utilities for auth tokens.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Supports two modes:
|
|
5
|
+
* - ES256 (asymmetric) — for production / cross-registry trust
|
|
6
|
+
* - HS256 (HMAC) — for backward compat / simple single-server setups
|
|
7
|
+
*
|
|
8
|
+
* Uses `jose` library for all crypto operations.
|
|
6
9
|
*/
|
|
10
|
+
import { type JWK } from "jose";
|
|
7
11
|
/** JWT payload for auth tokens */
|
|
8
|
-
export interface
|
|
9
|
-
/** Subject - the client ID */
|
|
12
|
+
export interface AgentJwtPayload {
|
|
13
|
+
/** Subject - the client ID or user ID */
|
|
10
14
|
sub: string;
|
|
11
|
-
/** Client name */
|
|
15
|
+
/** Client/user name */
|
|
12
16
|
name: string;
|
|
17
|
+
/** Issuer URL */
|
|
18
|
+
iss?: string;
|
|
13
19
|
/** Tenant ID */
|
|
14
20
|
tenantId?: string;
|
|
21
|
+
/** User ID (when acting on behalf of a user) */
|
|
22
|
+
userId?: string;
|
|
15
23
|
/** Scopes */
|
|
16
24
|
scopes: string[];
|
|
25
|
+
/** Identities (for cross-registry provisioning) */
|
|
26
|
+
identities?: Array<{
|
|
27
|
+
provider: string;
|
|
28
|
+
id: string;
|
|
29
|
+
[key: string]: unknown;
|
|
30
|
+
}>;
|
|
17
31
|
/** Issued at (unix seconds) */
|
|
18
32
|
iat: number;
|
|
19
33
|
/** Expires at (unix seconds) */
|
|
20
34
|
exp: number;
|
|
21
35
|
}
|
|
36
|
+
/** A signing key with metadata */
|
|
37
|
+
export interface SigningKey {
|
|
38
|
+
/** Unique key ID */
|
|
39
|
+
kid: string;
|
|
40
|
+
/** Private key (for signing) */
|
|
41
|
+
privateKey: CryptoKey;
|
|
42
|
+
/** Public key (for verification + JWKS) */
|
|
43
|
+
publicKey: CryptoKey;
|
|
44
|
+
/** Algorithm */
|
|
45
|
+
alg: string;
|
|
46
|
+
/** Status */
|
|
47
|
+
status: "active" | "deprecated" | "revoked";
|
|
48
|
+
/** When this key was created */
|
|
49
|
+
createdAt: number;
|
|
50
|
+
}
|
|
51
|
+
/** Exported key pair for storage */
|
|
52
|
+
export interface ExportedKeyPair {
|
|
53
|
+
kid: string;
|
|
54
|
+
alg: string;
|
|
55
|
+
privateKeyJwk: JWK;
|
|
56
|
+
publicKeyJwk: JWK;
|
|
57
|
+
status: "active" | "deprecated" | "revoked";
|
|
58
|
+
createdAt: number;
|
|
59
|
+
}
|
|
22
60
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* @param payload - JWT payload (client_id, scopes, etc.)
|
|
26
|
-
* @param secret - Signing secret (the client's secret hash)
|
|
27
|
-
* @returns Signed JWT string
|
|
61
|
+
* Generate a new ES256 signing key pair.
|
|
28
62
|
*/
|
|
29
|
-
export declare function
|
|
63
|
+
export declare function generateSigningKey(kid?: string): Promise<SigningKey>;
|
|
30
64
|
/**
|
|
31
|
-
*
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
*
|
|
65
|
+
* Export a signing key to JWK format (for storage).
|
|
66
|
+
*/
|
|
67
|
+
export declare function exportSigningKey(key: SigningKey): Promise<ExportedKeyPair>;
|
|
68
|
+
/**
|
|
69
|
+
* Import a signing key from stored JWK format.
|
|
70
|
+
*/
|
|
71
|
+
export declare function importSigningKey(exported: ExportedKeyPair): Promise<SigningKey>;
|
|
72
|
+
/**
|
|
73
|
+
* Build a JWKS (JSON Web Key Set) from signing keys.
|
|
74
|
+
* Only includes public keys.
|
|
75
|
+
*/
|
|
76
|
+
export declare function buildJwks(keys: SigningKey[]): Promise<{
|
|
77
|
+
keys: JWK[];
|
|
78
|
+
}>;
|
|
79
|
+
/**
|
|
80
|
+
* Sign a JWT with ES256 using the server's private key.
|
|
81
|
+
*/
|
|
82
|
+
export declare function signJwtES256(payload: Omit<AgentJwtPayload, "iat" | "exp"> & {
|
|
83
|
+
iat?: number;
|
|
84
|
+
exp?: number;
|
|
85
|
+
}, privateKey: CryptoKey, kid: string, issuer?: string, expiresIn?: string): Promise<string>;
|
|
86
|
+
/**
|
|
87
|
+
* Verify a JWT against a local public key.
|
|
88
|
+
*/
|
|
89
|
+
export declare function verifyJwtLocal(token: string, publicKey: CryptoKey): Promise<AgentJwtPayload | null>;
|
|
90
|
+
/**
|
|
91
|
+
* Verify a JWT against a remote issuer's JWKS.
|
|
92
|
+
* Fetches and caches the JWKS from the issuer's /.well-known/jwks.json
|
|
93
|
+
*/
|
|
94
|
+
export declare function verifyJwtFromIssuer(token: string, issuerUrl: string): Promise<AgentJwtPayload | null>;
|
|
95
|
+
/** @deprecated Use AgentJwtPayload instead */
|
|
96
|
+
export type JwtPayload = AgentJwtPayload;
|
|
97
|
+
/**
|
|
98
|
+
* Sign a JWT with HMAC-SHA256 (legacy).
|
|
99
|
+
* @deprecated Use signJwtES256 for new code.
|
|
100
|
+
*/
|
|
101
|
+
export declare function signJwt(payload: AgentJwtPayload, secret: string): Promise<string>;
|
|
102
|
+
/**
|
|
103
|
+
* Verify and decode a JWT (HMAC-SHA256, legacy).
|
|
104
|
+
* @deprecated Use verifyJwtLocal or verifyJwtFromIssuer for new code.
|
|
36
105
|
*/
|
|
37
|
-
export declare function verifyJwt(token: string, secret: string): Promise<
|
|
106
|
+
export declare function verifyJwt(token: string, secret: string): Promise<AgentJwtPayload | null>;
|
|
38
107
|
//# sourceMappingURL=jwt.d.ts.map
|
package/dist/jwt.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["../src/jwt.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"jwt.d.ts","sourceRoot":"","sources":["../src/jwt.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EASL,KAAK,GAAG,EACT,MAAM,MAAM,CAAC;AAMd,kCAAkC;AAClC,MAAM,WAAW,eAAe;IAC9B,yCAAyC;IACzC,GAAG,EAAE,MAAM,CAAC;IACZ,uBAAuB;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,iBAAiB;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,gBAAgB;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gDAAgD;IAChD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,aAAa;IACb,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,mDAAmD;IACnD,UAAU,CAAC,EAAE,KAAK,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC,CAAC;IAC7E,+BAA+B;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,gCAAgC;IAChC,GAAG,EAAE,MAAM,CAAC;CACb;AAED,kCAAkC;AAClC,MAAM,WAAW,UAAU;IACzB,oBAAoB;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,gCAAgC;IAChC,UAAU,EAAE,SAAS,CAAC;IACtB,2CAA2C;IAC3C,SAAS,EAAE,SAAS,CAAC;IACrB,gBAAgB;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,aAAa;IACb,MAAM,EAAE,QAAQ,GAAG,YAAY,GAAG,SAAS,CAAC;IAC5C,gCAAgC;IAChC,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,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAajC;AAoCD,8CAA8C;AAC9C,MAAM,MAAM,UAAU,GAAG,eAAe,CAAC;AAEzC;;;GAGG;AACH,wBAAsB,OAAO,CAC3B,OAAO,EAAE,eAAe,EACxB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,CAAC,CAOjB;AAED;;;GAGG;AACH,wBAAsB,SAAS,CAC7B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAiBjC"}
|
package/dist/jwt.js
CHANGED
|
@@ -1,9 +1,141 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* JWT utilities for auth tokens.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Supports two modes:
|
|
5
|
+
* - ES256 (asymmetric) — for production / cross-registry trust
|
|
6
|
+
* - HS256 (HMAC) — for backward compat / simple single-server setups
|
|
7
|
+
*
|
|
8
|
+
* Uses `jose` library for all crypto operations.
|
|
9
|
+
*/
|
|
10
|
+
import { SignJWT, jwtVerify, generateKeyPair, exportJWK, importJWK, createRemoteJWKSet, } from "jose";
|
|
11
|
+
// ============================================
|
|
12
|
+
// Key Generation
|
|
13
|
+
// ============================================
|
|
14
|
+
/**
|
|
15
|
+
* Generate a new ES256 signing key pair.
|
|
16
|
+
*/
|
|
17
|
+
export async function generateSigningKey(kid) {
|
|
18
|
+
const { privateKey, publicKey } = await generateKeyPair("ES256");
|
|
19
|
+
return {
|
|
20
|
+
kid: kid ?? `key-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
|
|
21
|
+
privateKey,
|
|
22
|
+
publicKey,
|
|
23
|
+
alg: "ES256",
|
|
24
|
+
status: "active",
|
|
25
|
+
createdAt: Date.now(),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Export a signing key to JWK format (for storage).
|
|
30
|
+
*/
|
|
31
|
+
export async function exportSigningKey(key) {
|
|
32
|
+
const privateKeyJwk = await exportJWK(key.privateKey);
|
|
33
|
+
const publicKeyJwk = await exportJWK(key.publicKey);
|
|
34
|
+
return {
|
|
35
|
+
kid: key.kid,
|
|
36
|
+
alg: key.alg,
|
|
37
|
+
privateKeyJwk,
|
|
38
|
+
publicKeyJwk,
|
|
39
|
+
status: key.status,
|
|
40
|
+
createdAt: key.createdAt,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Import a signing key from stored JWK format.
|
|
45
|
+
*/
|
|
46
|
+
export async function importSigningKey(exported) {
|
|
47
|
+
const privateKey = await importJWK(exported.privateKeyJwk, exported.alg);
|
|
48
|
+
const publicKey = await importJWK(exported.publicKeyJwk, exported.alg);
|
|
49
|
+
return {
|
|
50
|
+
kid: exported.kid,
|
|
51
|
+
privateKey,
|
|
52
|
+
publicKey,
|
|
53
|
+
alg: exported.alg,
|
|
54
|
+
status: exported.status,
|
|
55
|
+
createdAt: exported.createdAt,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Build a JWKS (JSON Web Key Set) from signing keys.
|
|
60
|
+
* Only includes public keys.
|
|
61
|
+
*/
|
|
62
|
+
export async function buildJwks(keys) {
|
|
63
|
+
const jwks = [];
|
|
64
|
+
for (const key of keys) {
|
|
65
|
+
if (key.status === "revoked")
|
|
66
|
+
continue;
|
|
67
|
+
const jwk = await exportJWK(key.publicKey);
|
|
68
|
+
jwk.kid = key.kid;
|
|
69
|
+
jwk.alg = key.alg;
|
|
70
|
+
jwk.use = "sig";
|
|
71
|
+
jwks.push(jwk);
|
|
72
|
+
}
|
|
73
|
+
return { keys: jwks };
|
|
74
|
+
}
|
|
75
|
+
// ============================================
|
|
76
|
+
// Signing (ES256)
|
|
77
|
+
// ============================================
|
|
78
|
+
/**
|
|
79
|
+
* Sign a JWT with ES256 using the server's private key.
|
|
80
|
+
*/
|
|
81
|
+
export async function signJwtES256(payload, privateKey, kid, issuer, expiresIn) {
|
|
82
|
+
let builder = new SignJWT(payload)
|
|
83
|
+
.setProtectedHeader({ alg: "ES256", kid })
|
|
84
|
+
.setIssuedAt();
|
|
85
|
+
if (issuer)
|
|
86
|
+
builder = builder.setIssuer(issuer);
|
|
87
|
+
if (payload.sub)
|
|
88
|
+
builder = builder.setSubject(payload.sub);
|
|
89
|
+
if (expiresIn) {
|
|
90
|
+
builder = builder.setExpirationTime(expiresIn);
|
|
91
|
+
}
|
|
92
|
+
else if (payload.exp) {
|
|
93
|
+
builder = builder.setExpirationTime(payload.exp);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
builder = builder.setExpirationTime("1h");
|
|
97
|
+
}
|
|
98
|
+
return builder.sign(privateKey);
|
|
99
|
+
}
|
|
100
|
+
// ============================================
|
|
101
|
+
// Verification
|
|
102
|
+
// ============================================
|
|
103
|
+
/**
|
|
104
|
+
* Verify a JWT against a local public key.
|
|
6
105
|
*/
|
|
106
|
+
export async function verifyJwtLocal(token, publicKey) {
|
|
107
|
+
try {
|
|
108
|
+
const { payload } = await jwtVerify(token, publicKey);
|
|
109
|
+
return payload;
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/** JWKS cache for remote issuers */
|
|
116
|
+
const jwksCache = new Map();
|
|
117
|
+
/**
|
|
118
|
+
* Verify a JWT against a remote issuer's JWKS.
|
|
119
|
+
* Fetches and caches the JWKS from the issuer's /.well-known/jwks.json
|
|
120
|
+
*/
|
|
121
|
+
export async function verifyJwtFromIssuer(token, issuerUrl) {
|
|
122
|
+
try {
|
|
123
|
+
const jwksUrl = issuerUrl.replace(/\/$/, "") + "/.well-known/jwks.json";
|
|
124
|
+
let jwks = jwksCache.get(jwksUrl);
|
|
125
|
+
if (!jwks) {
|
|
126
|
+
jwks = createRemoteJWKSet(new URL(jwksUrl));
|
|
127
|
+
jwksCache.set(jwksUrl, jwks);
|
|
128
|
+
}
|
|
129
|
+
const { payload } = await jwtVerify(token, jwks);
|
|
130
|
+
return payload;
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
// ============================================
|
|
137
|
+
// Legacy HMAC (backward compat)
|
|
138
|
+
// ============================================
|
|
7
139
|
const encoder = new TextEncoder();
|
|
8
140
|
function base64UrlEncode(data) {
|
|
9
141
|
const str = btoa(String.fromCharCode(...data));
|
|
@@ -24,11 +156,8 @@ async function hmacVerify(data, signature, secret) {
|
|
|
24
156
|
return crypto.subtle.verify("HMAC", key, signature.buffer, encoder.encode(data));
|
|
25
157
|
}
|
|
26
158
|
/**
|
|
27
|
-
* Sign a JWT with HMAC-SHA256.
|
|
28
|
-
*
|
|
29
|
-
* @param payload - JWT payload (client_id, scopes, etc.)
|
|
30
|
-
* @param secret - Signing secret (the client's secret hash)
|
|
31
|
-
* @returns Signed JWT string
|
|
159
|
+
* Sign a JWT with HMAC-SHA256 (legacy).
|
|
160
|
+
* @deprecated Use signJwtES256 for new code.
|
|
32
161
|
*/
|
|
33
162
|
export async function signJwt(payload, secret) {
|
|
34
163
|
const header = { alg: "HS256", typ: "JWT" };
|
|
@@ -36,15 +165,11 @@ export async function signJwt(payload, secret) {
|
|
|
36
165
|
const payloadB64 = base64UrlEncode(encoder.encode(JSON.stringify(payload)));
|
|
37
166
|
const signingInput = `${headerB64}.${payloadB64}`;
|
|
38
167
|
const signature = await hmacSign(signingInput, secret);
|
|
39
|
-
|
|
40
|
-
return `${signingInput}.${signatureB64}`;
|
|
168
|
+
return `${signingInput}.${base64UrlEncode(signature)}`;
|
|
41
169
|
}
|
|
42
170
|
/**
|
|
43
|
-
* Verify and decode a JWT.
|
|
44
|
-
*
|
|
45
|
-
* @param token - JWT string
|
|
46
|
-
* @param secret - Signing secret to verify against
|
|
47
|
-
* @returns Decoded payload, or null if invalid/expired
|
|
171
|
+
* Verify and decode a JWT (HMAC-SHA256, legacy).
|
|
172
|
+
* @deprecated Use verifyJwtLocal or verifyJwtFromIssuer for new code.
|
|
48
173
|
*/
|
|
49
174
|
export async function verifyJwt(token, secret) {
|
|
50
175
|
const parts = token.split(".");
|
|
@@ -58,10 +183,8 @@ export async function verifyJwt(token, secret) {
|
|
|
58
183
|
if (!valid)
|
|
59
184
|
return null;
|
|
60
185
|
const payload = JSON.parse(new TextDecoder().decode(base64UrlDecode(payloadB64)));
|
|
61
|
-
|
|
62
|
-
if (payload.exp && payload.exp < Date.now() / 1000) {
|
|
186
|
+
if (payload.exp && payload.exp < Date.now() / 1000)
|
|
63
187
|
return null;
|
|
64
|
-
}
|
|
65
188
|
return payload;
|
|
66
189
|
}
|
|
67
190
|
catch {
|
package/dist/jwt.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwt.js","sourceRoot":"","sources":["../src/jwt.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"jwt.js","sourceRoot":"","sources":["../src/jwt.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EACL,OAAO,EACP,SAAS,EACT,eAAe,EACf,SAAS,EACT,SAAS,EACT,kBAAkB,GAInB,MAAM,MAAM,CAAC;AAsDd,+CAA+C;AAC/C,iBAAiB;AACjB,+CAA+C;AAE/C;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,GAAY;IACnD,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,MAAM,eAAe,CAAC,OAAO,CAAC,CAAC;IACjE,OAAO;QACL,GAAG,EAAE,GAAG,IAAI,OAAO,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE;QACzE,UAAU;QACV,SAAS;QACT,GAAG,EAAE,OAAO;QACZ,MAAM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,OAAO,GAAG,IAAI,CAAC,KAAK,CACxB,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC,CACnC,CAAC;QACrB,IAAI,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI;YAAE,OAAO,IAAI,CAAC;QAChE,OAAO,OAAO,CAAC;IACjB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
package/dist/registry.d.ts
CHANGED
|
@@ -10,6 +10,8 @@ import type { AgentDefinition, CallAgentRequest, CallAgentResponse, Visibility }
|
|
|
10
10
|
export interface AgentRegistryOptions {
|
|
11
11
|
/** Default visibility for agents without explicit visibility */
|
|
12
12
|
defaultVisibility?: Visibility;
|
|
13
|
+
/** Factory to enrich ToolContext with application-specific data */
|
|
14
|
+
contextFactory?: ContextFactory;
|
|
13
15
|
}
|
|
14
16
|
/**
|
|
15
17
|
* Agent registry interface.
|
|
@@ -44,5 +46,10 @@ export interface AgentRegistry {
|
|
|
44
46
|
* });
|
|
45
47
|
* ```
|
|
46
48
|
*/
|
|
49
|
+
/**
|
|
50
|
+
* Factory function that enriches the base ToolContext with application-specific data.
|
|
51
|
+
* Called before every tool execution.
|
|
52
|
+
*/
|
|
53
|
+
export type ContextFactory = (baseCtx: import("./types.js").ToolContext) => import("./types.js").ToolContext;
|
|
47
54
|
export declare function createAgentRegistry(options?: AgentRegistryOptions): AgentRegistry;
|
|
48
55
|
//# sourceMappingURL=registry.d.ts.map
|
package/dist/registry.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAEV,eAAe,EAMf,gBAAgB,EAChB,iBAAiB,EAIjB,UAAU,EACX,MAAM,YAAY,CAAC;AAapB;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,gEAAgE;IAChE,iBAAiB,CAAC,EAAE,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAEV,eAAe,EAMf,gBAAgB,EAChB,iBAAiB,EAIjB,UAAU,EACX,MAAM,YAAY,CAAC;AAapB;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,gEAAgE;IAChE,iBAAiB,CAAC,EAAE,UAAU,CAAC;IAC/B,mEAAmE;IACnE,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,wBAAwB;IACxB,QAAQ,CAAC,KAAK,EAAE,eAAe,GAAG,IAAI,CAAC;IAEvC,2BAA2B;IAC3B,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS,CAAC;IAE/C,+BAA+B;IAC/B,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAE3B,iCAAiC;IACjC,IAAI,IAAI,eAAe,EAAE,CAAC;IAE1B,sCAAsC;IACtC,SAAS,IAAI,MAAM,EAAE,CAAC;IAEtB,qCAAqC;IACrC,IAAI,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;CAC7D;AAMD;;;;;;;;;;;;;;;GAeG;AACH;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,EAAE,OAAO,YAAY,EAAE,WAAW,KAAK,OAAO,YAAY,EAAE,WAAW,CAAC;AAE7G,wBAAgB,mBAAmB,CACjC,OAAO,GAAE,oBAAyB,GACjC,aAAa,CAyUf"}
|
package/dist/registry.js
CHANGED
|
@@ -9,25 +9,6 @@ const DEFAULT_SUPPORTED_ACTIONS = [
|
|
|
9
9
|
"describe_tools",
|
|
10
10
|
"load",
|
|
11
11
|
];
|
|
12
|
-
// ============================================
|
|
13
|
-
// Create Registry
|
|
14
|
-
// ============================================
|
|
15
|
-
/**
|
|
16
|
-
* Create an agent registry.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```typescript
|
|
20
|
-
* const registry = createAgentRegistry();
|
|
21
|
-
* registry.register(myAgent);
|
|
22
|
-
*
|
|
23
|
-
* const result = await registry.call({
|
|
24
|
-
* action: 'execute_tool',
|
|
25
|
-
* path: '@my-agent',
|
|
26
|
-
* tool: 'greet',
|
|
27
|
-
* params: { name: 'World' }
|
|
28
|
-
* });
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
12
|
export function createAgentRegistry(options = {}) {
|
|
32
13
|
const { defaultVisibility = "internal" } = options;
|
|
33
14
|
const agents = new Map();
|
|
@@ -87,6 +68,8 @@ export function createAgentRegistry(options = {}) {
|
|
|
87
68
|
return true;
|
|
88
69
|
case "internal":
|
|
89
70
|
return (callerType === "agent" || (callerType != null && callerId != null));
|
|
71
|
+
case "authenticated":
|
|
72
|
+
return callerId != null && callerId !== "anonymous";
|
|
90
73
|
case "private":
|
|
91
74
|
return callerId === agent.path;
|
|
92
75
|
default:
|
|
@@ -173,18 +156,28 @@ export function createAgentRegistry(options = {}) {
|
|
|
173
156
|
if (!checkToolAccess(agent, request.tool, request.callerId, request.callerType)) {
|
|
174
157
|
return {
|
|
175
158
|
success: false,
|
|
176
|
-
error: `Access denied to tool: ${request.tool}`,
|
|
159
|
+
error: `Access denied to tool: ${request.tool} (visibility=${tool.visibility}, callerId=${request.callerId}, callerType=${request.callerType})`,
|
|
177
160
|
code: "ACCESS_DENIED",
|
|
178
161
|
};
|
|
179
162
|
}
|
|
180
|
-
|
|
163
|
+
let ctx = {
|
|
181
164
|
tenantId: "default",
|
|
182
165
|
agentPath: agent.path,
|
|
183
166
|
callerId: request.callerId ?? "unknown",
|
|
184
167
|
callerType: request.callerType ?? "system",
|
|
185
168
|
metadata: request.metadata,
|
|
186
169
|
};
|
|
170
|
+
// Apply contextFactory if provided
|
|
171
|
+
if (options.contextFactory) {
|
|
172
|
+
ctx = options.contextFactory(ctx);
|
|
173
|
+
}
|
|
187
174
|
try {
|
|
175
|
+
if (!tool.execute) {
|
|
176
|
+
return {
|
|
177
|
+
success: false,
|
|
178
|
+
error: `Tool ${request.tool} has no execute function`,
|
|
179
|
+
};
|
|
180
|
+
}
|
|
188
181
|
const result = await tool.execute(request.params, ctx);
|
|
189
182
|
return {
|
|
190
183
|
success: true,
|