@slashfi/agents-sdk 0.34.1 → 0.35.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/README.md +2 -1
- package/dist/agent-definitions/auth.d.ts +3 -3
- package/dist/agent-definitions/auth.d.ts.map +1 -1
- package/dist/agent-definitions/auth.js +10 -4
- package/dist/agent-definitions/auth.js.map +1 -1
- package/dist/agent-definitions/config.d.ts.map +1 -1
- package/dist/agent-definitions/config.js.map +1 -1
- package/dist/agent-definitions/integrations.d.ts +12 -3
- package/dist/agent-definitions/integrations.d.ts.map +1 -1
- package/dist/agent-definitions/integrations.js +35 -16
- package/dist/agent-definitions/integrations.js.map +1 -1
- package/dist/agent-definitions/remote-registry.d.ts.map +1 -1
- package/dist/agent-definitions/remote-registry.js +17 -22
- package/dist/agent-definitions/remote-registry.js.map +1 -1
- package/dist/agent-definitions/users.d.ts.map +1 -1
- package/dist/agent-definitions/users.js.map +1 -1
- package/dist/auth-governance.js.map +1 -1
- package/dist/call-agent-schema.d.ts.map +1 -1
- package/dist/call-agent-schema.js +1 -2
- package/dist/call-agent-schema.js.map +1 -1
- package/dist/cjs/agent-definitions/auth.js +10 -4
- package/dist/cjs/agent-definitions/auth.js.map +1 -1
- package/dist/cjs/agent-definitions/config.js.map +1 -1
- package/dist/cjs/agent-definitions/integrations.js +35 -16
- package/dist/cjs/agent-definitions/integrations.js.map +1 -1
- package/dist/cjs/agent-definitions/remote-registry.js +17 -22
- package/dist/cjs/agent-definitions/remote-registry.js.map +1 -1
- package/dist/cjs/agent-definitions/users.js.map +1 -1
- package/dist/cjs/auth-governance.js.map +1 -1
- package/dist/cjs/call-agent-schema.js +1 -2
- package/dist/cjs/call-agent-schema.js.map +1 -1
- package/dist/cjs/define.js.map +1 -1
- package/dist/cjs/index.js +6 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/key-manager.js.map +1 -1
- package/dist/cjs/registry-consumer.js +60 -15
- package/dist/cjs/registry-consumer.js.map +1 -1
- package/dist/cjs/registry.js +3 -1
- package/dist/cjs/registry.js.map +1 -1
- package/dist/cjs/server.js +70 -121
- package/dist/cjs/server.js.map +1 -1
- package/dist/cjs/types.js +13 -0
- package/dist/cjs/types.js.map +1 -1
- package/dist/define.d.ts.map +1 -1
- package/dist/define.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/key-manager.d.ts.map +1 -1
- package/dist/key-manager.js +1 -1
- package/dist/key-manager.js.map +1 -1
- package/dist/registry-consumer.d.ts +8 -8
- package/dist/registry-consumer.d.ts.map +1 -1
- package/dist/registry-consumer.js +60 -15
- package/dist/registry-consumer.js.map +1 -1
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +3 -1
- package/dist/registry.js.map +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +63 -114
- package/dist/server.js.map +1 -1
- package/dist/types.d.ts +38 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +10 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
- package/src/agent-definitions/auth.ts +31 -14
- package/src/agent-definitions/config.ts +4 -4
- package/src/agent-definitions/integrations.ts +119 -63
- package/src/agent-definitions/remote-registry.ts +65 -38
- package/src/agent-definitions/users.ts +36 -3
- package/src/auth-governance.ts +2 -2
- package/src/call-agent-schema.test.ts +4 -1
- package/src/call-agent-schema.ts +4 -3
- package/src/consumer.test.ts +4 -1
- package/src/define.ts +18 -12
- package/src/index.ts +11 -0
- package/src/key-manager.ts +9 -2
- package/src/registry-consumer.ts +85 -24
- package/src/registry.ts +3 -1
- package/src/server.ts +122 -153
- package/src/types.ts +62 -0
|
@@ -32,7 +32,13 @@ import {
|
|
|
32
32
|
signJwt,
|
|
33
33
|
verifyJwtFromIssuer,
|
|
34
34
|
} from "../jwt.js";
|
|
35
|
-
import type {
|
|
35
|
+
import type {
|
|
36
|
+
AgentDefinition,
|
|
37
|
+
AuthClientCredentialsTokenResult,
|
|
38
|
+
AuthSecretValue,
|
|
39
|
+
ToolContext,
|
|
40
|
+
ToolDefinition,
|
|
41
|
+
} from "../types.js";
|
|
36
42
|
|
|
37
43
|
// ============================================
|
|
38
44
|
// Auth Types
|
|
@@ -120,8 +126,10 @@ export interface AuthStore {
|
|
|
120
126
|
/** Revoke a client (delete). */
|
|
121
127
|
revokeClient(clientId: string): Promise<boolean>;
|
|
122
128
|
|
|
123
|
-
/** Rotate a client's secret. Returns new
|
|
124
|
-
rotateSecret(
|
|
129
|
+
/** Rotate a client's secret. Returns new secret (wrapped for wire format). */
|
|
130
|
+
rotateSecret(
|
|
131
|
+
clientId: string,
|
|
132
|
+
): Promise<{ clientSecret: AuthSecretValue } | null>;
|
|
125
133
|
|
|
126
134
|
/** Store a token. */
|
|
127
135
|
storeToken(token: AuthToken): Promise<void>;
|
|
@@ -333,8 +341,11 @@ export function createMemoryAuthStore(): AuthStore {
|
|
|
333
341
|
const clientSecret = generateSecret();
|
|
334
342
|
client.clientSecretHash = await hashSecret(clientSecret);
|
|
335
343
|
return {
|
|
336
|
-
clientSecret: {
|
|
337
|
-
|
|
344
|
+
clientSecret: {
|
|
345
|
+
$agent_type: "secret",
|
|
346
|
+
value: clientSecret,
|
|
347
|
+
} satisfies AuthSecretValue,
|
|
348
|
+
};
|
|
338
349
|
},
|
|
339
350
|
|
|
340
351
|
async storeToken(token) {
|
|
@@ -572,7 +583,7 @@ export function createAuthAgent(
|
|
|
572
583
|
refreshToken: { $agent_type: "secret", value: result.refreshToken },
|
|
573
584
|
tokenType: "bearer",
|
|
574
585
|
expiresIn: tokenTtl,
|
|
575
|
-
}
|
|
586
|
+
} satisfies AuthClientCredentialsTokenResult;
|
|
576
587
|
}
|
|
577
588
|
|
|
578
589
|
if (input.grantType !== "client_credentials") {
|
|
@@ -607,7 +618,7 @@ export function createAuthAgent(
|
|
|
607
618
|
tokenType: "bearer",
|
|
608
619
|
expiresIn: tokenTtl,
|
|
609
620
|
scopes: client.scopes,
|
|
610
|
-
};
|
|
621
|
+
} satisfies AuthClientCredentialsTokenResult;
|
|
611
622
|
},
|
|
612
623
|
});
|
|
613
624
|
|
|
@@ -666,9 +677,12 @@ export function createAuthAgent(
|
|
|
666
677
|
|
|
667
678
|
return {
|
|
668
679
|
clientId,
|
|
669
|
-
clientSecret: {
|
|
680
|
+
clientSecret: {
|
|
681
|
+
$agent_type: "secret",
|
|
682
|
+
value: clientSecret,
|
|
683
|
+
} satisfies AuthSecretValue,
|
|
670
684
|
scopes,
|
|
671
|
-
}
|
|
685
|
+
};
|
|
672
686
|
},
|
|
673
687
|
});
|
|
674
688
|
|
|
@@ -907,17 +921,20 @@ export function createAuthAgent(
|
|
|
907
921
|
if (parts.length !== 3) {
|
|
908
922
|
return { success: false, error: "Invalid JWT format" };
|
|
909
923
|
}
|
|
910
|
-
let decoded:
|
|
924
|
+
let decoded: Record<string, unknown>;
|
|
911
925
|
try {
|
|
912
|
-
decoded = JSON.parse(
|
|
926
|
+
decoded = JSON.parse(
|
|
927
|
+
Buffer.from(parts[1], "base64url").toString(),
|
|
928
|
+
) as Record<string, unknown>;
|
|
913
929
|
} catch {
|
|
914
930
|
return { success: false, error: "Failed to decode JWT payload" };
|
|
915
931
|
}
|
|
916
932
|
|
|
917
933
|
const issuer = decoded.iss;
|
|
918
934
|
const sub = decoded.sub;
|
|
919
|
-
const foreignTenantId =
|
|
920
|
-
|
|
935
|
+
const foreignTenantId =
|
|
936
|
+
typeof decoded.tenantId === "string" ? decoded.tenantId : undefined;
|
|
937
|
+
if (typeof issuer !== "string" || typeof sub !== "string") {
|
|
921
938
|
return { success: false, error: "JWT missing iss or sub claims" };
|
|
922
939
|
}
|
|
923
940
|
|
|
@@ -928,7 +945,7 @@ export function createAuthAgent(
|
|
|
928
945
|
}
|
|
929
946
|
|
|
930
947
|
// 3. Verify JWT against the matched issuer's JWKS
|
|
931
|
-
let payload:
|
|
948
|
+
let payload: Awaited<ReturnType<typeof verifyJwtFromIssuer>>;
|
|
932
949
|
try {
|
|
933
950
|
payload = await verifyJwtFromIssuer(input.token, issuer);
|
|
934
951
|
} catch {
|
|
@@ -20,10 +20,10 @@
|
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
|
-
import type { ConsumerConfig, RefEntry } from "../define-config.js";
|
|
23
|
+
import type { ConsumerConfig, RefEntry, RegistryAuth } from "../define-config.js";
|
|
24
24
|
import { normalizeRef } from "../define-config.js";
|
|
25
25
|
import { defineAgent, defineTool } from "../define.js";
|
|
26
|
-
import type { AgentDefinition, ToolContext } from "../types.js";
|
|
26
|
+
import type { AgentDefinition, ToolContext, ToolDefinition } from "../types.js";
|
|
27
27
|
|
|
28
28
|
// ============================================
|
|
29
29
|
// FsStore Interface
|
|
@@ -275,7 +275,7 @@ export function createConfigAgent(
|
|
|
275
275
|
const entry = {
|
|
276
276
|
url: input.url,
|
|
277
277
|
...(input.name && { name: input.name }),
|
|
278
|
-
...(input.auth && { auth: input.auth as
|
|
278
|
+
...(input.auth && { auth: input.auth as RegistryAuth }),
|
|
279
279
|
};
|
|
280
280
|
|
|
281
281
|
// Upsert by URL
|
|
@@ -313,6 +313,6 @@ export function createConfigAgent(
|
|
|
313
313
|
"Manage consumer config — add/remove/list agent refs and registries. " +
|
|
314
314
|
"Replaces @integrations for connecting to third-party services.",
|
|
315
315
|
},
|
|
316
|
-
tools: [addRefTool, removeRefTool, listRefsTool, addRegistryTool] as
|
|
316
|
+
tools: [addRefTool, removeRefTool, listRefsTool, addRegistryTool] as ToolDefinition<ToolContext>[],
|
|
317
317
|
});
|
|
318
318
|
}
|
|
@@ -28,7 +28,23 @@ import {
|
|
|
28
28
|
generateCollectionToken,
|
|
29
29
|
pendingCollections,
|
|
30
30
|
} from "../secret-collection.js";
|
|
31
|
-
import type {
|
|
31
|
+
import type {
|
|
32
|
+
AgentDefinition,
|
|
33
|
+
CallAgentRequest,
|
|
34
|
+
CallAgentResponse,
|
|
35
|
+
JsonSchema,
|
|
36
|
+
ToolContext,
|
|
37
|
+
ToolDefinition,
|
|
38
|
+
} from "../types.js";
|
|
39
|
+
|
|
40
|
+
/** Unwrap `execute_tool` payload from a registry response. */
|
|
41
|
+
function executeToolResult(
|
|
42
|
+
r: CallAgentResponse | undefined,
|
|
43
|
+
): unknown | undefined {
|
|
44
|
+
if (!r || r.success === false) return undefined;
|
|
45
|
+
if ("result" in r) return r.result;
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
32
48
|
|
|
33
49
|
// ============================================
|
|
34
50
|
// OAuth Config Types
|
|
@@ -73,6 +89,9 @@ export interface IntegrationOAuthConfig {
|
|
|
73
89
|
refreshGrantType?: string;
|
|
74
90
|
refreshBodyParams?: string[];
|
|
75
91
|
refreshHeaders?: Record<string, string>;
|
|
92
|
+
|
|
93
|
+
/** OAuth client id (plain string or secret: ref) */
|
|
94
|
+
clientId?: string;
|
|
76
95
|
}
|
|
77
96
|
|
|
78
97
|
// ============================================
|
|
@@ -106,7 +125,14 @@ export interface ProviderConfig {
|
|
|
106
125
|
* Agent path that handles this integration type.
|
|
107
126
|
* @integrations dispatches setup/connect/call to that agent's integrationMethods.
|
|
108
127
|
*/
|
|
109
|
-
agentPath
|
|
128
|
+
agentPath?: string;
|
|
129
|
+
/**
|
|
130
|
+
* @internal Secret store ids for credentials encrypted by @integrations.
|
|
131
|
+
*/
|
|
132
|
+
_clientIdSecretId?: string;
|
|
133
|
+
_clientSecretSecretId?: string;
|
|
134
|
+
/** Client id as plain string or secret: ref (when not using _clientIdSecretId) */
|
|
135
|
+
clientId?: string;
|
|
110
136
|
/**
|
|
111
137
|
* Scope of the integration:
|
|
112
138
|
* - 'user': per-user tokens (Slack, Notion, Linear)
|
|
@@ -515,7 +541,7 @@ export interface IntegrationsAgentOptions {
|
|
|
515
541
|
/** Registry instance for calling other agents' internal tools */
|
|
516
542
|
registry?: {
|
|
517
543
|
list?(): AgentDefinition[];
|
|
518
|
-
call(request:
|
|
544
|
+
call(request: CallAgentRequest): Promise<CallAgentResponse>;
|
|
519
545
|
};
|
|
520
546
|
|
|
521
547
|
/** Secret store for storing/resolving client credentials and tokens */
|
|
@@ -668,29 +694,32 @@ export function createIntegrationsAgent(
|
|
|
668
694
|
},
|
|
669
695
|
required: ["id", "name", "type", "api"],
|
|
670
696
|
},
|
|
671
|
-
execute: async (input:
|
|
697
|
+
execute: async (input: Record<string, unknown>, _ctx: ToolContext) => {
|
|
672
698
|
const config: ProviderConfig = {
|
|
673
|
-
id: input.id,
|
|
674
|
-
name: input.name,
|
|
675
|
-
agentPath: input.agentPath,
|
|
676
|
-
scope: input.scope,
|
|
677
|
-
docs: input.docs,
|
|
678
|
-
auth: input.auth,
|
|
679
|
-
api: input.api,
|
|
699
|
+
id: input.id as string,
|
|
700
|
+
name: input.name as string,
|
|
701
|
+
agentPath: input.agentPath as string | undefined,
|
|
702
|
+
scope: input.scope as "user" | "tenant" | undefined,
|
|
703
|
+
docs: input.docs as ProviderConfig["docs"],
|
|
704
|
+
auth: input.auth as ProviderConfig["auth"],
|
|
705
|
+
api: input.api as ProviderConfig["api"],
|
|
680
706
|
};
|
|
681
707
|
// Store client credentials encrypted and save secret IDs
|
|
682
708
|
const result: Record<string, unknown> = { success: true };
|
|
683
709
|
if (input.clientId) {
|
|
684
|
-
const secretId = await secretStore.store(
|
|
685
|
-
|
|
710
|
+
const secretId = await secretStore.store(
|
|
711
|
+
input.clientId as string,
|
|
712
|
+
SYSTEM_OWNER,
|
|
713
|
+
);
|
|
714
|
+
config._clientIdSecretId = secretId;
|
|
686
715
|
result.clientIdStored = true;
|
|
687
716
|
}
|
|
688
717
|
if (input.clientSecret) {
|
|
689
718
|
const secretId = await secretStore.store(
|
|
690
|
-
input.clientSecret,
|
|
719
|
+
input.clientSecret as string,
|
|
691
720
|
SYSTEM_OWNER,
|
|
692
721
|
);
|
|
693
|
-
|
|
722
|
+
config._clientSecretSecretId = secretId;
|
|
694
723
|
result.clientSecretStored = true;
|
|
695
724
|
}
|
|
696
725
|
|
|
@@ -703,10 +732,11 @@ export function createIntegrationsAgent(
|
|
|
703
732
|
action: "execute_tool",
|
|
704
733
|
path: config.agentPath,
|
|
705
734
|
tool: "setup_integration",
|
|
706
|
-
params: input.config ?? input,
|
|
735
|
+
params: (input.config ?? input) as Record<string, unknown>,
|
|
707
736
|
callerType: "system",
|
|
708
737
|
});
|
|
709
|
-
result.setupResult =
|
|
738
|
+
result.setupResult =
|
|
739
|
+
executeToolResult(setupResult) ?? setupResult;
|
|
710
740
|
} catch (err) {
|
|
711
741
|
result.setupError = err instanceof Error ? err.message : String(err);
|
|
712
742
|
}
|
|
@@ -857,7 +887,7 @@ export function createIntegrationsAgent(
|
|
|
857
887
|
const agents = options.registry.list?.() ?? [];
|
|
858
888
|
for (const agent of agents) {
|
|
859
889
|
const hasListTool = agent.tools?.some(
|
|
860
|
-
(t:
|
|
890
|
+
(t: ToolDefinition) => t.name === "list_integrations",
|
|
861
891
|
);
|
|
862
892
|
if (hasListTool && agent.config?.integration) {
|
|
863
893
|
const meta = {
|
|
@@ -878,9 +908,15 @@ export function createIntegrationsAgent(
|
|
|
878
908
|
callerType: "system",
|
|
879
909
|
})
|
|
880
910
|
: null;
|
|
881
|
-
const
|
|
882
|
-
callResult ??
|
|
883
|
-
|
|
911
|
+
const raw =
|
|
912
|
+
executeToolResult(callResult ?? undefined) ??
|
|
913
|
+
callResult ??
|
|
914
|
+
{ success: false };
|
|
915
|
+
const result = raw as {
|
|
916
|
+
success?: boolean;
|
|
917
|
+
data?: unknown;
|
|
918
|
+
};
|
|
919
|
+
if (result.success && result.data != null) {
|
|
884
920
|
// Flatten: if data has an array field, each item becomes an integration
|
|
885
921
|
const items = Array.isArray(result.data)
|
|
886
922
|
? result.data
|
|
@@ -982,7 +1018,7 @@ export function createIntegrationsAgent(
|
|
|
982
1018
|
params: { ...input, registryId: config.id },
|
|
983
1019
|
callerType: "system",
|
|
984
1020
|
});
|
|
985
|
-
return (connectResult
|
|
1021
|
+
return executeToolResult(connectResult) ?? connectResult;
|
|
986
1022
|
}
|
|
987
1023
|
|
|
988
1024
|
if (!config.auth)
|
|
@@ -998,26 +1034,26 @@ export function createIntegrationsAgent(
|
|
|
998
1034
|
// Check both _clientIdSecretId (from setup_integration direct) and
|
|
999
1035
|
// clientId field as secret:ref (from collect_secrets flow)
|
|
1000
1036
|
let clientId: string | null = null;
|
|
1001
|
-
const cidSecretId =
|
|
1037
|
+
const cidSecretId = config._clientIdSecretId;
|
|
1002
1038
|
if (cidSecretId && secretStore) {
|
|
1003
1039
|
clientId = await secretStore.resolve(cidSecretId, SYSTEM_OWNER);
|
|
1004
1040
|
}
|
|
1005
1041
|
// Also check if auth config has clientId as a secret:ref
|
|
1006
1042
|
if (
|
|
1007
1043
|
!clientId &&
|
|
1008
|
-
|
|
1009
|
-
typeof
|
|
1044
|
+
oauth.clientId &&
|
|
1045
|
+
typeof oauth.clientId === "string"
|
|
1010
1046
|
) {
|
|
1011
|
-
if (
|
|
1012
|
-
const refId =
|
|
1047
|
+
if (oauth.clientId.startsWith("secret:") && secretStore) {
|
|
1048
|
+
const refId = oauth.clientId.slice("secret:".length);
|
|
1013
1049
|
clientId = await secretStore.resolve(refId, SYSTEM_OWNER);
|
|
1014
|
-
} else if (!
|
|
1015
|
-
clientId =
|
|
1050
|
+
} else if (!oauth.clientId.startsWith("secret:")) {
|
|
1051
|
+
clientId = oauth.clientId;
|
|
1016
1052
|
}
|
|
1017
1053
|
}
|
|
1018
1054
|
// Check top-level config too
|
|
1019
|
-
if (!clientId &&
|
|
1020
|
-
const cid =
|
|
1055
|
+
if (!clientId && config.clientId) {
|
|
1056
|
+
const cid = config.clientId;
|
|
1021
1057
|
if (
|
|
1022
1058
|
typeof cid === "string" &&
|
|
1023
1059
|
cid.startsWith("secret:") &&
|
|
@@ -1112,14 +1148,17 @@ export function createIntegrationsAgent(
|
|
|
1112
1148
|
},
|
|
1113
1149
|
required: ["provider", "type"],
|
|
1114
1150
|
},
|
|
1115
|
-
execute: async (input:
|
|
1116
|
-
const config = await store.getProvider(input.provider);
|
|
1151
|
+
execute: async (input: Record<string, unknown>, ctx: ToolContext) => {
|
|
1152
|
+
const config = await store.getProvider(input.provider as string);
|
|
1117
1153
|
if (!config) return { error: `Provider '${input.provider}' not found` };
|
|
1118
1154
|
|
|
1119
1155
|
const userId = ctx.callerId;
|
|
1120
1156
|
|
|
1121
1157
|
// Get access token
|
|
1122
|
-
const connection = await store.getConnection(
|
|
1158
|
+
const connection = await store.getConnection(
|
|
1159
|
+
userId,
|
|
1160
|
+
input.provider as string,
|
|
1161
|
+
);
|
|
1123
1162
|
if (!connection) {
|
|
1124
1163
|
return {
|
|
1125
1164
|
error: `Not connected to '${input.provider}'. Use connect_integration first.`,
|
|
@@ -1135,8 +1174,8 @@ export function createIntegrationsAgent(
|
|
|
1135
1174
|
connection.refreshToken
|
|
1136
1175
|
) {
|
|
1137
1176
|
try {
|
|
1138
|
-
const rCidId =
|
|
1139
|
-
const rCsecId =
|
|
1177
|
+
const rCidId = config._clientIdSecretId;
|
|
1178
|
+
const rCsecId = config._clientSecretSecretId;
|
|
1140
1179
|
if (!rCidId || !rCsecId) {
|
|
1141
1180
|
throw new Error(
|
|
1142
1181
|
"No client credentials stored. Re-run setup_integration with clientId/clientSecret.",
|
|
@@ -1181,12 +1220,12 @@ export function createIntegrationsAgent(
|
|
|
1181
1220
|
return executeRestCall(
|
|
1182
1221
|
config,
|
|
1183
1222
|
{
|
|
1184
|
-
provider: input.provider,
|
|
1223
|
+
provider: input.provider as string,
|
|
1185
1224
|
type: "rest",
|
|
1186
|
-
method: input.method ?? "GET",
|
|
1187
|
-
path: input.path ?? "/",
|
|
1188
|
-
body: input.body,
|
|
1189
|
-
query: input.query,
|
|
1225
|
+
method: (input.method as RestCallInput["method"]) ?? "GET",
|
|
1226
|
+
path: (input.path as string) ?? "/",
|
|
1227
|
+
body: input.body as Record<string, unknown> | undefined,
|
|
1228
|
+
query: input.query as Record<string, string> | undefined,
|
|
1190
1229
|
},
|
|
1191
1230
|
accessToken,
|
|
1192
1231
|
);
|
|
@@ -1195,10 +1234,12 @@ export function createIntegrationsAgent(
|
|
|
1195
1234
|
return executeGraphqlCall(
|
|
1196
1235
|
config,
|
|
1197
1236
|
{
|
|
1198
|
-
provider: input.provider,
|
|
1237
|
+
provider: input.provider as string,
|
|
1199
1238
|
type: "graphql",
|
|
1200
|
-
query: input.graphqlQuery ??
|
|
1201
|
-
variables: input.variables
|
|
1239
|
+
query: String(input.graphqlQuery ?? ""),
|
|
1240
|
+
variables: input.variables as
|
|
1241
|
+
| Record<string, unknown>
|
|
1242
|
+
| undefined,
|
|
1202
1243
|
},
|
|
1203
1244
|
accessToken,
|
|
1204
1245
|
);
|
|
@@ -1249,7 +1290,7 @@ export function createIntegrationsAgent(
|
|
|
1249
1290
|
params: { ...input, registryId: config.id },
|
|
1250
1291
|
callerType: "system",
|
|
1251
1292
|
});
|
|
1252
|
-
return (connectResult
|
|
1293
|
+
return executeToolResult(connectResult) ?? connectResult;
|
|
1253
1294
|
}
|
|
1254
1295
|
|
|
1255
1296
|
if (!config.auth)
|
|
@@ -1266,8 +1307,8 @@ export function createIntegrationsAgent(
|
|
|
1266
1307
|
}
|
|
1267
1308
|
|
|
1268
1309
|
// Resolve client credentials from secret store via config
|
|
1269
|
-
const cbCidId =
|
|
1270
|
-
const cbCsecId =
|
|
1310
|
+
const cbCidId = config._clientIdSecretId;
|
|
1311
|
+
const cbCsecId = config._clientSecretSecretId;
|
|
1271
1312
|
if (!cbCidId || !cbCsecId) {
|
|
1272
1313
|
return { error: "No client credentials stored for this provider." };
|
|
1273
1314
|
}
|
|
@@ -1390,7 +1431,7 @@ export function createIntegrationsAgent(
|
|
|
1390
1431
|
// Fetch tool schema from registry
|
|
1391
1432
|
let toolSchema: {
|
|
1392
1433
|
name: string;
|
|
1393
|
-
inputSchema?:
|
|
1434
|
+
inputSchema?: JsonSchema;
|
|
1394
1435
|
description?: string;
|
|
1395
1436
|
} | null = null;
|
|
1396
1437
|
const registryUrl = input.registry;
|
|
@@ -1414,10 +1455,14 @@ export function createIntegrationsAgent(
|
|
|
1414
1455
|
},
|
|
1415
1456
|
}),
|
|
1416
1457
|
});
|
|
1417
|
-
const data = (await res.json()) as
|
|
1418
|
-
const
|
|
1458
|
+
const data = (await res.json()) as Record<string, unknown>;
|
|
1459
|
+
const resultBlock = data.result as
|
|
1460
|
+
| { content?: Array<{ text?: string }> }
|
|
1461
|
+
| undefined;
|
|
1462
|
+
const parsed = JSON.parse(resultBlock?.content?.[0]?.text ?? "{}");
|
|
1419
1463
|
const tools = parsed?.tools ?? parsed?.result?.tools ?? [];
|
|
1420
|
-
toolSchema =
|
|
1464
|
+
toolSchema =
|
|
1465
|
+
tools.find((t: { name: string }) => t.name === input.tool) ?? null;
|
|
1421
1466
|
|
|
1422
1467
|
if (!toolSchema?.inputSchema) {
|
|
1423
1468
|
return { error: `Tool '${input.tool}' not found on '${input.agent}'` };
|
|
@@ -1437,15 +1482,24 @@ export function createIntegrationsAgent(
|
|
|
1437
1482
|
required: boolean;
|
|
1438
1483
|
}> = [];
|
|
1439
1484
|
|
|
1440
|
-
for (const [name, def] of Object.entries(properties) as [
|
|
1485
|
+
for (const [name, def] of Object.entries(properties) as [
|
|
1486
|
+
string,
|
|
1487
|
+
Record<string, unknown>,
|
|
1488
|
+
][]) {
|
|
1441
1489
|
const isSecret = def.secret === true;
|
|
1442
1490
|
const isRequired = requiredFields.has(name);
|
|
1443
1491
|
const isProvided = name in providedParams;
|
|
1444
1492
|
if (isSecret || (isRequired && !isProvided)) {
|
|
1445
1493
|
fields.push({
|
|
1446
1494
|
name,
|
|
1447
|
-
type:
|
|
1448
|
-
|
|
1495
|
+
type:
|
|
1496
|
+
typeof def.type === "string"
|
|
1497
|
+
? def.type
|
|
1498
|
+
: Array.isArray(def.type)
|
|
1499
|
+
? def.type.join("|")
|
|
1500
|
+
: "string",
|
|
1501
|
+
description:
|
|
1502
|
+
typeof def.description === "string" ? def.description : name,
|
|
1449
1503
|
secret: isSecret,
|
|
1450
1504
|
required: isRequired,
|
|
1451
1505
|
});
|
|
@@ -1502,11 +1556,11 @@ export function createIntegrationsAgent(
|
|
|
1502
1556
|
inputSchema: { type: "object" as const, properties: {} },
|
|
1503
1557
|
execute: async () => {
|
|
1504
1558
|
const agents = options.registry?.list?.() ?? [];
|
|
1505
|
-
const results:
|
|
1559
|
+
const results: unknown[] = [];
|
|
1506
1560
|
if (options.registry) {
|
|
1507
1561
|
for (const agent of agents) {
|
|
1508
1562
|
const hasDiscoverTool = agent.tools?.some(
|
|
1509
|
-
(t:
|
|
1563
|
+
(t: ToolDefinition) => t.name === "discover_integrations",
|
|
1510
1564
|
);
|
|
1511
1565
|
if (hasDiscoverTool) {
|
|
1512
1566
|
try {
|
|
@@ -1518,8 +1572,9 @@ export function createIntegrationsAgent(
|
|
|
1518
1572
|
callerId: "@integrations",
|
|
1519
1573
|
callerType: "system",
|
|
1520
1574
|
});
|
|
1521
|
-
|
|
1522
|
-
|
|
1575
|
+
const payload = executeToolResult(res);
|
|
1576
|
+
if (payload && Array.isArray(payload)) {
|
|
1577
|
+
results.push(...payload);
|
|
1523
1578
|
}
|
|
1524
1579
|
} catch {}
|
|
1525
1580
|
}
|
|
@@ -1542,14 +1597,14 @@ export function createIntegrationsAgent(
|
|
|
1542
1597
|
},
|
|
1543
1598
|
execute: async (input: { agent_path?: string }) => {
|
|
1544
1599
|
const agents = options.registry?.list?.() ?? [];
|
|
1545
|
-
const results:
|
|
1600
|
+
const results: unknown[] = [];
|
|
1546
1601
|
if (options.registry) {
|
|
1547
1602
|
const targetAgents = input.agent_path
|
|
1548
|
-
? agents.filter((a:
|
|
1603
|
+
? agents.filter((a: AgentDefinition) => a.path === input.agent_path)
|
|
1549
1604
|
: agents;
|
|
1550
1605
|
for (const agent of targetAgents) {
|
|
1551
1606
|
const hasListTool = agent.tools?.some(
|
|
1552
|
-
(t:
|
|
1607
|
+
(t: ToolDefinition) => t.name === "list_integrations",
|
|
1553
1608
|
);
|
|
1554
1609
|
if (hasListTool) {
|
|
1555
1610
|
try {
|
|
@@ -1561,8 +1616,9 @@ export function createIntegrationsAgent(
|
|
|
1561
1616
|
callerId: "@integrations",
|
|
1562
1617
|
callerType: "system",
|
|
1563
1618
|
});
|
|
1564
|
-
|
|
1565
|
-
|
|
1619
|
+
const payload = executeToolResult(res);
|
|
1620
|
+
if (payload && Array.isArray(payload)) {
|
|
1621
|
+
results.push(...payload);
|
|
1566
1622
|
}
|
|
1567
1623
|
} catch {}
|
|
1568
1624
|
}
|