@slashfi/agents-sdk 0.26.1 → 0.27.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/config.d.ts +44 -0
- package/dist/agent-definitions/config.d.ts.map +1 -0
- package/dist/agent-definitions/config.js +234 -0
- package/dist/agent-definitions/config.js.map +1 -0
- package/dist/cjs/agent-definitions/config.js +237 -0
- package/dist/cjs/agent-definitions/config.js.map +1 -0
- package/dist/cjs/codegen.js +27 -2
- package/dist/cjs/codegen.js.map +1 -1
- package/dist/cjs/index.js +21 -3
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/mcp-client.js +159 -0
- package/dist/cjs/mcp-client.js.map +1 -0
- package/dist/cjs/pkce.js +49 -0
- package/dist/cjs/pkce.js.map +1 -0
- package/dist/cjs/registry-consumer.js +217 -2
- package/dist/cjs/registry-consumer.js.map +1 -1
- package/dist/cjs/registry.js.map +1 -1
- package/dist/cjs/server.js +33 -2
- package/dist/cjs/server.js.map +1 -1
- package/dist/codegen.d.ts +4 -0
- package/dist/codegen.d.ts.map +1 -1
- package/dist/codegen.js +27 -2
- package/dist/codegen.js.map +1 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -2
- package/dist/index.js.map +1 -1
- package/dist/mcp-client.d.ts +87 -0
- package/dist/mcp-client.d.ts.map +1 -0
- package/dist/mcp-client.js +152 -0
- package/dist/mcp-client.js.map +1 -0
- package/dist/pkce.d.ts +29 -0
- package/dist/pkce.d.ts.map +1 -0
- package/dist/pkce.js +44 -0
- package/dist/pkce.js.map +1 -0
- package/dist/registry-consumer.d.ts +4 -0
- package/dist/registry-consumer.d.ts.map +1 -1
- package/dist/registry-consumer.js +216 -2
- package/dist/registry-consumer.js.map +1 -1
- package/dist/registry.d.ts +2 -2
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js.map +1 -1
- package/dist/server.d.ts +13 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +33 -2
- package/dist/server.js.map +1 -1
- package/package.json +1 -1
- package/src/agent-definitions/config.ts +318 -0
- package/src/codegen.ts +33 -1
- package/src/index.ts +34 -2
- package/src/mcp-client.ts +230 -0
- package/src/pkce.ts +54 -0
- package/src/registry-consumer.ts +257 -2
- package/src/registry.ts +3 -3
- package/src/server.ts +49 -2
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config Agent (@config)
|
|
3
|
+
*
|
|
4
|
+
* Built-in agent for managing consumer configuration — refs and registries.
|
|
5
|
+
* Replaces @integrations and the LLM-facing parts of @auth.
|
|
6
|
+
*
|
|
7
|
+
* Provides:
|
|
8
|
+
* - add_ref / remove_ref / list_refs for managing agent refs
|
|
9
|
+
* - add_registry for registering new registries
|
|
10
|
+
* - FsStore interface for pluggable filesystem storage (VCS-backed or local)
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { createAgentRegistry, createConfigAgent } from '@slashfi/agents-sdk';
|
|
15
|
+
*
|
|
16
|
+
* const registry = createAgentRegistry();
|
|
17
|
+
* registry.register(createConfigAgent({
|
|
18
|
+
* store: myFsStore,
|
|
19
|
+
* }));
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
import type { AgentDefinition } from "../types.js";
|
|
23
|
+
/**
|
|
24
|
+
* Filesystem store for reading/writing consumer configs.
|
|
25
|
+
* The storage engine (VCS, local fs, etc.) is abstracted away.
|
|
26
|
+
*/
|
|
27
|
+
export interface FsStore {
|
|
28
|
+
/** Read a file as UTF-8 string. Returns null if not found. */
|
|
29
|
+
readFile(path: string): Promise<string | null>;
|
|
30
|
+
/** Write a file with UTF-8 content. Creates parent dirs if needed. */
|
|
31
|
+
writeFile(path: string, content: string): Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
export interface ConfigAgentOptions {
|
|
34
|
+
/** Filesystem store for persisting consumer config */
|
|
35
|
+
store: FsStore;
|
|
36
|
+
/**
|
|
37
|
+
* Resolve the FsStore for a specific user.
|
|
38
|
+
* When provided, refs are stored per-user.
|
|
39
|
+
* The callerId from ToolContext is passed.
|
|
40
|
+
*/
|
|
41
|
+
resolveUserStore?: (callerId: string) => FsStore;
|
|
42
|
+
}
|
|
43
|
+
export declare function createConfigAgent(options: ConfigAgentOptions): AgentDefinition;
|
|
44
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/agent-definitions/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAKH,OAAO,KAAK,EAAE,eAAe,EAAe,MAAM,aAAa,CAAC;AAMhE;;;GAGG;AACH,MAAM,WAAW,OAAO;IACtB,8DAA8D;IAC9D,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC/C,sEAAsE;IACtE,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACzD;AA6BD,MAAM,WAAW,kBAAkB;IACjC,sDAAsD;IACtD,KAAK,EAAE,OAAO,CAAC;IAEf;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;CAClD;AAMD,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,kBAAkB,GAC1B,eAAe,CAsOjB"}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config Agent (@config)
|
|
3
|
+
*
|
|
4
|
+
* Built-in agent for managing consumer configuration — refs and registries.
|
|
5
|
+
* Replaces @integrations and the LLM-facing parts of @auth.
|
|
6
|
+
*
|
|
7
|
+
* Provides:
|
|
8
|
+
* - add_ref / remove_ref / list_refs for managing agent refs
|
|
9
|
+
* - add_registry for registering new registries
|
|
10
|
+
* - FsStore interface for pluggable filesystem storage (VCS-backed or local)
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { createAgentRegistry, createConfigAgent } from '@slashfi/agents-sdk';
|
|
15
|
+
*
|
|
16
|
+
* const registry = createAgentRegistry();
|
|
17
|
+
* registry.register(createConfigAgent({
|
|
18
|
+
* store: myFsStore,
|
|
19
|
+
* }));
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
import { normalizeRef } from "../define-config.js";
|
|
23
|
+
import { defineAgent, defineTool } from "../define.js";
|
|
24
|
+
// ============================================
|
|
25
|
+
// Config Persistence
|
|
26
|
+
// ============================================
|
|
27
|
+
const CONFIG_PATH = "consumer-config.json";
|
|
28
|
+
async function readConfig(store) {
|
|
29
|
+
const content = await store.readFile(CONFIG_PATH);
|
|
30
|
+
if (!content)
|
|
31
|
+
return {};
|
|
32
|
+
try {
|
|
33
|
+
return JSON.parse(content);
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return {};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async function writeConfig(store, config) {
|
|
40
|
+
await store.writeFile(CONFIG_PATH, JSON.stringify(config, null, 2));
|
|
41
|
+
}
|
|
42
|
+
// ============================================
|
|
43
|
+
// Create Config Agent
|
|
44
|
+
// ============================================
|
|
45
|
+
export function createConfigAgent(options) {
|
|
46
|
+
const { store, resolveUserStore } = options;
|
|
47
|
+
function getStore(ctx) {
|
|
48
|
+
if (resolveUserStore && ctx.callerId) {
|
|
49
|
+
return resolveUserStore(ctx.callerId);
|
|
50
|
+
}
|
|
51
|
+
return store;
|
|
52
|
+
}
|
|
53
|
+
// ---- add_ref ----
|
|
54
|
+
const addRefTool = defineTool({
|
|
55
|
+
name: "add_ref",
|
|
56
|
+
description: "Add or update an agent ref in the consumer config. " +
|
|
57
|
+
"The ref is persisted to the config store.",
|
|
58
|
+
inputSchema: {
|
|
59
|
+
type: "object",
|
|
60
|
+
properties: {
|
|
61
|
+
ref: {
|
|
62
|
+
type: "string",
|
|
63
|
+
description: 'Agent ref name (e.g. "notion", "linear")',
|
|
64
|
+
},
|
|
65
|
+
as: {
|
|
66
|
+
type: "string",
|
|
67
|
+
description: "Local alias (for multi-instance refs)",
|
|
68
|
+
},
|
|
69
|
+
url: {
|
|
70
|
+
type: "string",
|
|
71
|
+
description: "Direct URL to the agent",
|
|
72
|
+
},
|
|
73
|
+
config: {
|
|
74
|
+
type: "object",
|
|
75
|
+
additionalProperties: { type: "string" },
|
|
76
|
+
description: "Per-instance config (secret URIs or literal values)",
|
|
77
|
+
},
|
|
78
|
+
registry: {
|
|
79
|
+
type: "string",
|
|
80
|
+
description: 'Registry to resolve from (e.g. "slash", "mcp", "https")',
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
required: ["ref"],
|
|
84
|
+
},
|
|
85
|
+
execute: async (input, ctx) => {
|
|
86
|
+
const fs = getStore(ctx);
|
|
87
|
+
const currentConfig = await readConfig(fs);
|
|
88
|
+
const entry = {
|
|
89
|
+
ref: input.ref,
|
|
90
|
+
...(input.as && { as: input.as }),
|
|
91
|
+
...(input.url && { url: input.url }),
|
|
92
|
+
...(input.config && { config: input.config }),
|
|
93
|
+
...(input.registry && { registry: input.registry }),
|
|
94
|
+
};
|
|
95
|
+
// Upsert: find existing ref by name/alias, replace or append
|
|
96
|
+
const name = input.as ?? input.ref;
|
|
97
|
+
const refs = currentConfig.refs ?? [];
|
|
98
|
+
const existingIdx = refs.findIndex((r) => {
|
|
99
|
+
const normalized = normalizeRef(r);
|
|
100
|
+
return normalized.name === name;
|
|
101
|
+
});
|
|
102
|
+
if (existingIdx >= 0) {
|
|
103
|
+
refs[existingIdx] = entry;
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
refs.push(entry);
|
|
107
|
+
}
|
|
108
|
+
currentConfig.refs = refs;
|
|
109
|
+
await writeConfig(fs, currentConfig);
|
|
110
|
+
return {
|
|
111
|
+
added: true,
|
|
112
|
+
ref: input.ref,
|
|
113
|
+
name,
|
|
114
|
+
};
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
// ---- remove_ref ----
|
|
118
|
+
const removeRefTool = defineTool({
|
|
119
|
+
name: "remove_ref",
|
|
120
|
+
description: "Remove an agent ref from the consumer config by name or alias.",
|
|
121
|
+
inputSchema: {
|
|
122
|
+
type: "object",
|
|
123
|
+
properties: {
|
|
124
|
+
name: {
|
|
125
|
+
type: "string",
|
|
126
|
+
description: "Ref name or alias to remove",
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
required: ["name"],
|
|
130
|
+
},
|
|
131
|
+
execute: async (input, ctx) => {
|
|
132
|
+
const fs = getStore(ctx);
|
|
133
|
+
const currentConfig = await readConfig(fs);
|
|
134
|
+
const refs = currentConfig.refs ?? [];
|
|
135
|
+
const before = refs.length;
|
|
136
|
+
currentConfig.refs = refs.filter((r) => {
|
|
137
|
+
const normalized = normalizeRef(r);
|
|
138
|
+
return normalized.name !== input.name;
|
|
139
|
+
});
|
|
140
|
+
if (currentConfig.refs.length === before) {
|
|
141
|
+
return { removed: false, error: `Ref "${input.name}" not found` };
|
|
142
|
+
}
|
|
143
|
+
await writeConfig(fs, currentConfig);
|
|
144
|
+
return { removed: true, name: input.name };
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
// ---- list_refs ----
|
|
148
|
+
const listRefsTool = defineTool({
|
|
149
|
+
name: "list_refs",
|
|
150
|
+
description: "List all agent refs in the consumer config. " +
|
|
151
|
+
"Returns normalized refs with their names and config.",
|
|
152
|
+
inputSchema: {
|
|
153
|
+
type: "object",
|
|
154
|
+
properties: {},
|
|
155
|
+
},
|
|
156
|
+
execute: async (_input, ctx) => {
|
|
157
|
+
const fs = getStore(ctx);
|
|
158
|
+
const currentConfig = await readConfig(fs);
|
|
159
|
+
const refs = (currentConfig.refs ?? []).map(normalizeRef);
|
|
160
|
+
return { refs };
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
// ---- add_registry ----
|
|
164
|
+
const addRegistryTool = defineTool({
|
|
165
|
+
name: "add_registry",
|
|
166
|
+
description: "Add or update a registry in the consumer config. " +
|
|
167
|
+
"Registries are where refs resolve from.",
|
|
168
|
+
inputSchema: {
|
|
169
|
+
type: "object",
|
|
170
|
+
properties: {
|
|
171
|
+
name: {
|
|
172
|
+
type: "string",
|
|
173
|
+
description: 'Human-readable name (e.g. "slash", "internal")',
|
|
174
|
+
},
|
|
175
|
+
url: {
|
|
176
|
+
type: "string",
|
|
177
|
+
description: "Registry URL",
|
|
178
|
+
},
|
|
179
|
+
auth: {
|
|
180
|
+
type: "object",
|
|
181
|
+
description: "Auth config for the registry",
|
|
182
|
+
properties: {
|
|
183
|
+
type: {
|
|
184
|
+
type: "string",
|
|
185
|
+
enum: ["none", "bearer", "api-key", "jwt"],
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
required: ["url"],
|
|
191
|
+
},
|
|
192
|
+
execute: async (input, ctx) => {
|
|
193
|
+
const fs = getStore(ctx);
|
|
194
|
+
const currentConfig = await readConfig(fs);
|
|
195
|
+
const registries = currentConfig.registries ?? [];
|
|
196
|
+
const entry = {
|
|
197
|
+
url: input.url,
|
|
198
|
+
...(input.name && { name: input.name }),
|
|
199
|
+
...(input.auth && { auth: input.auth }),
|
|
200
|
+
};
|
|
201
|
+
// Upsert by URL
|
|
202
|
+
const existingIdx = registries.findIndex((r) => {
|
|
203
|
+
const url = typeof r === "string" ? r : r.url;
|
|
204
|
+
return url === input.url;
|
|
205
|
+
});
|
|
206
|
+
if (existingIdx >= 0) {
|
|
207
|
+
registries[existingIdx] = entry;
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
registries.push(entry);
|
|
211
|
+
}
|
|
212
|
+
currentConfig.registries = registries;
|
|
213
|
+
await writeConfig(fs, currentConfig);
|
|
214
|
+
return {
|
|
215
|
+
added: true,
|
|
216
|
+
url: input.url,
|
|
217
|
+
name: input.name ?? new URL(input.url).hostname,
|
|
218
|
+
};
|
|
219
|
+
},
|
|
220
|
+
});
|
|
221
|
+
// ---- Define the agent ----
|
|
222
|
+
return defineAgent({
|
|
223
|
+
path: "@config",
|
|
224
|
+
entrypoint: "Consumer config management. Use add_ref/remove_ref/list_refs to manage agent refs, " +
|
|
225
|
+
"and add_registry to configure registries.",
|
|
226
|
+
config: {
|
|
227
|
+
name: "Config",
|
|
228
|
+
description: "Manage consumer config — add/remove/list agent refs and registries. " +
|
|
229
|
+
"Replaces @integrations for connecting to third-party services.",
|
|
230
|
+
},
|
|
231
|
+
tools: [addRefTool, removeRefTool, listRefsTool, addRegistryTool],
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/agent-definitions/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAkBvD,+CAA+C;AAC/C,qBAAqB;AACrB,+CAA+C;AAE/C,MAAM,WAAW,GAAG,sBAAsB,CAAC;AAE3C,KAAK,UAAU,UAAU,CAAC,KAAc;IACtC,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;IAClD,IAAI,CAAC,OAAO;QAAE,OAAO,EAAE,CAAC;IACxB,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAmB,CAAC;IAC/C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC;AAED,KAAK,UAAU,WAAW,CACxB,KAAc,EACd,MAAsB;IAEtB,MAAM,KAAK,CAAC,SAAS,CAAC,WAAW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EAAsE;gBACtE,gEAAgE;SACnE;QACD,KAAK,EAAE,CAAC,UAAU,EAAE,aAAa,EAAE,YAAY,EAAE,eAAe,CAAQ;KACzE,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Config Agent (@config)
|
|
4
|
+
*
|
|
5
|
+
* Built-in agent for managing consumer configuration — refs and registries.
|
|
6
|
+
* Replaces @integrations and the LLM-facing parts of @auth.
|
|
7
|
+
*
|
|
8
|
+
* Provides:
|
|
9
|
+
* - add_ref / remove_ref / list_refs for managing agent refs
|
|
10
|
+
* - add_registry for registering new registries
|
|
11
|
+
* - FsStore interface for pluggable filesystem storage (VCS-backed or local)
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { createAgentRegistry, createConfigAgent } from '@slashfi/agents-sdk';
|
|
16
|
+
*
|
|
17
|
+
* const registry = createAgentRegistry();
|
|
18
|
+
* registry.register(createConfigAgent({
|
|
19
|
+
* store: myFsStore,
|
|
20
|
+
* }));
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.createConfigAgent = createConfigAgent;
|
|
25
|
+
const define_config_js_1 = require("../define-config.js");
|
|
26
|
+
const define_js_1 = require("../define.js");
|
|
27
|
+
// ============================================
|
|
28
|
+
// Config Persistence
|
|
29
|
+
// ============================================
|
|
30
|
+
const CONFIG_PATH = "consumer-config.json";
|
|
31
|
+
async function readConfig(store) {
|
|
32
|
+
const content = await store.readFile(CONFIG_PATH);
|
|
33
|
+
if (!content)
|
|
34
|
+
return {};
|
|
35
|
+
try {
|
|
36
|
+
return JSON.parse(content);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return {};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async function writeConfig(store, config) {
|
|
43
|
+
await store.writeFile(CONFIG_PATH, JSON.stringify(config, null, 2));
|
|
44
|
+
}
|
|
45
|
+
// ============================================
|
|
46
|
+
// Create Config Agent
|
|
47
|
+
// ============================================
|
|
48
|
+
function createConfigAgent(options) {
|
|
49
|
+
const { store, resolveUserStore } = options;
|
|
50
|
+
function getStore(ctx) {
|
|
51
|
+
if (resolveUserStore && ctx.callerId) {
|
|
52
|
+
return resolveUserStore(ctx.callerId);
|
|
53
|
+
}
|
|
54
|
+
return store;
|
|
55
|
+
}
|
|
56
|
+
// ---- add_ref ----
|
|
57
|
+
const addRefTool = (0, define_js_1.defineTool)({
|
|
58
|
+
name: "add_ref",
|
|
59
|
+
description: "Add or update an agent ref in the consumer config. " +
|
|
60
|
+
"The ref is persisted to the config store.",
|
|
61
|
+
inputSchema: {
|
|
62
|
+
type: "object",
|
|
63
|
+
properties: {
|
|
64
|
+
ref: {
|
|
65
|
+
type: "string",
|
|
66
|
+
description: 'Agent ref name (e.g. "notion", "linear")',
|
|
67
|
+
},
|
|
68
|
+
as: {
|
|
69
|
+
type: "string",
|
|
70
|
+
description: "Local alias (for multi-instance refs)",
|
|
71
|
+
},
|
|
72
|
+
url: {
|
|
73
|
+
type: "string",
|
|
74
|
+
description: "Direct URL to the agent",
|
|
75
|
+
},
|
|
76
|
+
config: {
|
|
77
|
+
type: "object",
|
|
78
|
+
additionalProperties: { type: "string" },
|
|
79
|
+
description: "Per-instance config (secret URIs or literal values)",
|
|
80
|
+
},
|
|
81
|
+
registry: {
|
|
82
|
+
type: "string",
|
|
83
|
+
description: 'Registry to resolve from (e.g. "slash", "mcp", "https")',
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
required: ["ref"],
|
|
87
|
+
},
|
|
88
|
+
execute: async (input, ctx) => {
|
|
89
|
+
const fs = getStore(ctx);
|
|
90
|
+
const currentConfig = await readConfig(fs);
|
|
91
|
+
const entry = {
|
|
92
|
+
ref: input.ref,
|
|
93
|
+
...(input.as && { as: input.as }),
|
|
94
|
+
...(input.url && { url: input.url }),
|
|
95
|
+
...(input.config && { config: input.config }),
|
|
96
|
+
...(input.registry && { registry: input.registry }),
|
|
97
|
+
};
|
|
98
|
+
// Upsert: find existing ref by name/alias, replace or append
|
|
99
|
+
const name = input.as ?? input.ref;
|
|
100
|
+
const refs = currentConfig.refs ?? [];
|
|
101
|
+
const existingIdx = refs.findIndex((r) => {
|
|
102
|
+
const normalized = (0, define_config_js_1.normalizeRef)(r);
|
|
103
|
+
return normalized.name === name;
|
|
104
|
+
});
|
|
105
|
+
if (existingIdx >= 0) {
|
|
106
|
+
refs[existingIdx] = entry;
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
refs.push(entry);
|
|
110
|
+
}
|
|
111
|
+
currentConfig.refs = refs;
|
|
112
|
+
await writeConfig(fs, currentConfig);
|
|
113
|
+
return {
|
|
114
|
+
added: true,
|
|
115
|
+
ref: input.ref,
|
|
116
|
+
name,
|
|
117
|
+
};
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
// ---- remove_ref ----
|
|
121
|
+
const removeRefTool = (0, define_js_1.defineTool)({
|
|
122
|
+
name: "remove_ref",
|
|
123
|
+
description: "Remove an agent ref from the consumer config by name or alias.",
|
|
124
|
+
inputSchema: {
|
|
125
|
+
type: "object",
|
|
126
|
+
properties: {
|
|
127
|
+
name: {
|
|
128
|
+
type: "string",
|
|
129
|
+
description: "Ref name or alias to remove",
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
required: ["name"],
|
|
133
|
+
},
|
|
134
|
+
execute: async (input, ctx) => {
|
|
135
|
+
const fs = getStore(ctx);
|
|
136
|
+
const currentConfig = await readConfig(fs);
|
|
137
|
+
const refs = currentConfig.refs ?? [];
|
|
138
|
+
const before = refs.length;
|
|
139
|
+
currentConfig.refs = refs.filter((r) => {
|
|
140
|
+
const normalized = (0, define_config_js_1.normalizeRef)(r);
|
|
141
|
+
return normalized.name !== input.name;
|
|
142
|
+
});
|
|
143
|
+
if (currentConfig.refs.length === before) {
|
|
144
|
+
return { removed: false, error: `Ref "${input.name}" not found` };
|
|
145
|
+
}
|
|
146
|
+
await writeConfig(fs, currentConfig);
|
|
147
|
+
return { removed: true, name: input.name };
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
// ---- list_refs ----
|
|
151
|
+
const listRefsTool = (0, define_js_1.defineTool)({
|
|
152
|
+
name: "list_refs",
|
|
153
|
+
description: "List all agent refs in the consumer config. " +
|
|
154
|
+
"Returns normalized refs with their names and config.",
|
|
155
|
+
inputSchema: {
|
|
156
|
+
type: "object",
|
|
157
|
+
properties: {},
|
|
158
|
+
},
|
|
159
|
+
execute: async (_input, ctx) => {
|
|
160
|
+
const fs = getStore(ctx);
|
|
161
|
+
const currentConfig = await readConfig(fs);
|
|
162
|
+
const refs = (currentConfig.refs ?? []).map(define_config_js_1.normalizeRef);
|
|
163
|
+
return { refs };
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
// ---- add_registry ----
|
|
167
|
+
const addRegistryTool = (0, define_js_1.defineTool)({
|
|
168
|
+
name: "add_registry",
|
|
169
|
+
description: "Add or update a registry in the consumer config. " +
|
|
170
|
+
"Registries are where refs resolve from.",
|
|
171
|
+
inputSchema: {
|
|
172
|
+
type: "object",
|
|
173
|
+
properties: {
|
|
174
|
+
name: {
|
|
175
|
+
type: "string",
|
|
176
|
+
description: 'Human-readable name (e.g. "slash", "internal")',
|
|
177
|
+
},
|
|
178
|
+
url: {
|
|
179
|
+
type: "string",
|
|
180
|
+
description: "Registry URL",
|
|
181
|
+
},
|
|
182
|
+
auth: {
|
|
183
|
+
type: "object",
|
|
184
|
+
description: "Auth config for the registry",
|
|
185
|
+
properties: {
|
|
186
|
+
type: {
|
|
187
|
+
type: "string",
|
|
188
|
+
enum: ["none", "bearer", "api-key", "jwt"],
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
required: ["url"],
|
|
194
|
+
},
|
|
195
|
+
execute: async (input, ctx) => {
|
|
196
|
+
const fs = getStore(ctx);
|
|
197
|
+
const currentConfig = await readConfig(fs);
|
|
198
|
+
const registries = currentConfig.registries ?? [];
|
|
199
|
+
const entry = {
|
|
200
|
+
url: input.url,
|
|
201
|
+
...(input.name && { name: input.name }),
|
|
202
|
+
...(input.auth && { auth: input.auth }),
|
|
203
|
+
};
|
|
204
|
+
// Upsert by URL
|
|
205
|
+
const existingIdx = registries.findIndex((r) => {
|
|
206
|
+
const url = typeof r === "string" ? r : r.url;
|
|
207
|
+
return url === input.url;
|
|
208
|
+
});
|
|
209
|
+
if (existingIdx >= 0) {
|
|
210
|
+
registries[existingIdx] = entry;
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
registries.push(entry);
|
|
214
|
+
}
|
|
215
|
+
currentConfig.registries = registries;
|
|
216
|
+
await writeConfig(fs, currentConfig);
|
|
217
|
+
return {
|
|
218
|
+
added: true,
|
|
219
|
+
url: input.url,
|
|
220
|
+
name: input.name ?? new URL(input.url).hostname,
|
|
221
|
+
};
|
|
222
|
+
},
|
|
223
|
+
});
|
|
224
|
+
// ---- Define the agent ----
|
|
225
|
+
return (0, define_js_1.defineAgent)({
|
|
226
|
+
path: "@config",
|
|
227
|
+
entrypoint: "Consumer config management. Use add_ref/remove_ref/list_refs to manage agent refs, " +
|
|
228
|
+
"and add_registry to configure registries.",
|
|
229
|
+
config: {
|
|
230
|
+
name: "Config",
|
|
231
|
+
description: "Manage consumer config — add/remove/list agent refs and registries. " +
|
|
232
|
+
"Replaces @integrations for connecting to third-party services.",
|
|
233
|
+
},
|
|
234
|
+
tools: [addRefTool, removeRefTool, listRefsTool, addRegistryTool],
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/agent-definitions/config.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;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AAG,KAAK,CAAC;YAClC,CAAC;iBAAM,CAAC;gBACN,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACzB,CAAC;YAED,aAAa,CAAC,UAAU,GAAG,UAAU,CAAC;YACtC,MAAM,WAAW,CAAC,EAAE,EAAE,aAAa,CAAC,CAAC;YAErC,OAAO;gBACL,KAAK,EAAE,IAAI;gBACX,GAAG,EAAE,KAAK,CAAC,GAAG;gBACd,IAAI,EAAE,KAAK,CAAC,IAAI,IAAI,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,QAAQ;aAChD,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;IAEH,6BAA6B;IAC7B,OAAO,IAAA,uBAAW,EAAC;QACjB,IAAI,EAAE,SAAS;QACf,UAAU,EACR,qFAAqF;YACrF,2CAA2C;QAC7C,MAAM,EAAE;YACN,IAAI,EAAE,QAAQ;YACd,WAAW,EACT,sEAAsE;gBACtE,gEAAgE;SACnE;QACD,KAAK,EAAE,CAAC,UAAU,EAAE,aAAa,EAAE,YAAY,EAAE,eAAe,CAAQ;KACzE,CAAC,CAAC;AACL,CAAC"}
|
package/dist/cjs/codegen.js
CHANGED
|
@@ -41,6 +41,7 @@ exports.useAgent = useAgent;
|
|
|
41
41
|
exports.listAgentTools = listAgentTools;
|
|
42
42
|
const node_fs_1 = require("node:fs");
|
|
43
43
|
const node_path_1 = require("node:path");
|
|
44
|
+
const mcp_client_js_1 = require("./mcp-client.js");
|
|
44
45
|
// ============================================
|
|
45
46
|
// Protocol Constants
|
|
46
47
|
// ============================================
|
|
@@ -477,6 +478,22 @@ function createSseTransport(source) {
|
|
|
477
478
|
// ============================================
|
|
478
479
|
// Source Parsing
|
|
479
480
|
// ============================================
|
|
481
|
+
/**
|
|
482
|
+
* Extract the base URL from a server source (for OAuth discovery).
|
|
483
|
+
* Returns null for stdio/command-based sources.
|
|
484
|
+
*/
|
|
485
|
+
function resolveServerUrl(source) {
|
|
486
|
+
if (typeof source === "string") {
|
|
487
|
+
if (source.startsWith("http://") || source.startsWith("https://")) {
|
|
488
|
+
return source.replace(/\/sse$/, "");
|
|
489
|
+
}
|
|
490
|
+
return null;
|
|
491
|
+
}
|
|
492
|
+
if ("url" in source) {
|
|
493
|
+
return source.url.replace(/\/sse$/, "");
|
|
494
|
+
}
|
|
495
|
+
return null;
|
|
496
|
+
}
|
|
480
497
|
function parseServerSource(source) {
|
|
481
498
|
if (typeof source === "string") {
|
|
482
499
|
// URL -> HTTP or SSE transport
|
|
@@ -870,12 +887,13 @@ function generateCli(serverInfo, tools, agentPath) {
|
|
|
870
887
|
lines.push("");
|
|
871
888
|
return lines.join("\n");
|
|
872
889
|
}
|
|
873
|
-
function generateManifest(serverSource, serverInfo, tools, agentPath) {
|
|
890
|
+
function generateManifest(serverSource, serverInfo, tools, agentPath, oauth) {
|
|
874
891
|
const manifest = {
|
|
875
892
|
agentPath,
|
|
876
893
|
serverSource,
|
|
877
894
|
serverInfo,
|
|
878
895
|
tools: tools.map((t) => ({ name: t.name, description: t.description })),
|
|
896
|
+
...(oauth ? { oauth } : {}),
|
|
879
897
|
generatedAt: new Date().toISOString(),
|
|
880
898
|
};
|
|
881
899
|
return JSON.stringify(manifest, null, 2) + "\n";
|
|
@@ -930,6 +948,12 @@ async function codegen(options) {
|
|
|
930
948
|
if (tools.length === 0) {
|
|
931
949
|
throw new Error("MCP server returned no tools. Is the server running and configured correctly?");
|
|
932
950
|
}
|
|
951
|
+
// 3.5. Discover OAuth metadata (for URL-based servers)
|
|
952
|
+
let oauth = null;
|
|
953
|
+
const serverUrl = resolveServerUrl(options.server);
|
|
954
|
+
if (serverUrl) {
|
|
955
|
+
oauth = await (0, mcp_client_js_1.discoverOAuthMetadata)(serverUrl);
|
|
956
|
+
}
|
|
933
957
|
// 4. Derive agent path
|
|
934
958
|
const agentPath = options.agentPath ??
|
|
935
959
|
`@${(options.name ?? serverInfo.name ?? "mcp-agent").toLowerCase().replace(/[^a-z0-9-]/g, "-")}`;
|
|
@@ -964,7 +988,7 @@ async function codegen(options) {
|
|
|
964
988
|
files.push("cli.ts");
|
|
965
989
|
}
|
|
966
990
|
// 11. Generate manifest (for `agents-sdk use`)
|
|
967
|
-
const manifest = generateManifest(options.server, serverInfo, tools, agentPath);
|
|
991
|
+
const manifest = generateManifest(options.server, serverInfo, tools, agentPath, oauth);
|
|
968
992
|
(0, node_fs_1.writeFileSync)((0, node_path_1.join)(outDir, ".codegen-manifest.json"), manifest);
|
|
969
993
|
files.push(".codegen-manifest.json");
|
|
970
994
|
return {
|
|
@@ -973,6 +997,7 @@ async function codegen(options) {
|
|
|
973
997
|
toolCount: tools.length,
|
|
974
998
|
toolFiles,
|
|
975
999
|
files,
|
|
1000
|
+
...(oauth ? { oauth } : {}),
|
|
976
1001
|
};
|
|
977
1002
|
}
|
|
978
1003
|
// ============================================
|