glove-foundry 0.6.0 → 0.7.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/{chunk-X6EWEWWM.js → chunk-2GXPSIRL.js} +623 -100
- package/dist/chunk-64UBLGYM.js +1241 -0
- package/dist/{chunk-B36BGF5R.js → chunk-AC6SRI5V.js} +17 -22
- package/dist/{chunk-7F7QVO6I.js → chunk-EEHGAWXM.js} +26 -0
- package/dist/{chunk-OBTOFA7W.js → chunk-EJZJAVNG.js} +137 -633
- package/dist/{chunk-RSU7NEDK.js → chunk-IPASF7PK.js} +1 -1
- package/dist/cli.js +4 -4
- package/dist/{client-DWPYe_Nc.d.ts → client-BgpgsnoO.d.ts} +158 -107
- package/dist/client.d.ts +3 -3
- package/dist/client.js +1 -1
- package/dist/{definition-A8o11aez.d.ts → event-delivery-BaYe6d9w.d.ts} +1015 -874
- package/dist/execution-agent.d.ts +0 -1
- package/dist/execution-agent.js +3 -14
- package/dist/execution-daemon.js +1 -1
- package/dist/execution-loader.js +1014 -8
- package/dist/index.d.ts +9 -5
- package/dist/index.js +70 -23
- package/dist/voice.d.ts +2 -2
- package/dist/voice.js +1 -1
- package/docs/architecture.md +8 -0
- package/docs/building-with-foundry.md +9 -1
- package/docs/durable-subagents.md +259 -0
- package/package.json +11 -11
- package/dist/chunk-K2EU63MB.js +0 -468
- package/dist/chunk-TFGETZYH.js +0 -917
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "glove-foundry",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "An Effect-native, file-routed framework for typed, observable Glove agent applications",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -77,16 +77,16 @@
|
|
|
77
77
|
"station-client": "^3.0.0",
|
|
78
78
|
"station-beacon": "^3.0.0",
|
|
79
79
|
"station-broadcast": "^3.0.0",
|
|
80
|
-
"glove-
|
|
81
|
-
"glove-
|
|
82
|
-
"glove-lisp": "0.5.
|
|
83
|
-
"glove-
|
|
84
|
-
"glove-
|
|
85
|
-
"glove-
|
|
86
|
-
"glove-
|
|
87
|
-
"glove-python": "0.4.
|
|
88
|
-
"glove-
|
|
89
|
-
"glove-
|
|
80
|
+
"glove-core": "4.6.0",
|
|
81
|
+
"glove-facts": "0.1.7",
|
|
82
|
+
"glove-lisp": "0.5.5",
|
|
83
|
+
"glove-js": "0.5.5",
|
|
84
|
+
"glove-mcp": "1.2.5",
|
|
85
|
+
"glove-mesh": "0.2.2",
|
|
86
|
+
"glove-memory": "2.3.2",
|
|
87
|
+
"glove-python": "0.4.5",
|
|
88
|
+
"glove-working-environment": "0.7.0",
|
|
89
|
+
"glove-voice-s2s": "0.4.5"
|
|
90
90
|
},
|
|
91
91
|
"devDependencies": {
|
|
92
92
|
"@types/node": "^25.2.3",
|
package/dist/chunk-K2EU63MB.js
DELETED
|
@@ -1,468 +0,0 @@
|
|
|
1
|
-
// src/surfaces.ts
|
|
2
|
-
import { Effect } from "effect";
|
|
3
|
-
|
|
4
|
-
// src/identity.ts
|
|
5
|
-
var identities = /* @__PURE__ */ new WeakMap();
|
|
6
|
-
function fileIdentified(value, kind, explicitId) {
|
|
7
|
-
const cell = {
|
|
8
|
-
kind,
|
|
9
|
-
...explicitId ? { id: explicitId } : {},
|
|
10
|
-
explicit: explicitId !== void 0
|
|
11
|
-
};
|
|
12
|
-
const identified = { ...value };
|
|
13
|
-
Object.defineProperty(identified, "id", {
|
|
14
|
-
enumerable: true,
|
|
15
|
-
configurable: false,
|
|
16
|
-
get() {
|
|
17
|
-
if (cell.id) return cell.id;
|
|
18
|
-
throw new Error(
|
|
19
|
-
`Foundry ${kind} identity has not been bound yet. Default-export it from its convention file and let Foundry discovery derive the id.`
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
identities.set(identified, cell);
|
|
24
|
-
return identified;
|
|
25
|
-
}
|
|
26
|
-
function bindFileIdentity(value, id, expectedKind) {
|
|
27
|
-
const cell = identities.get(value);
|
|
28
|
-
if (!cell) {
|
|
29
|
-
const current = value.id;
|
|
30
|
-
if (typeof current === "string" && current !== id) {
|
|
31
|
-
throw new Error(`Foundry file route resolves to "${id}" but the definition declares "${current}".`);
|
|
32
|
-
}
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
if (expectedKind && cell.kind !== expectedKind) {
|
|
36
|
-
throw new Error(
|
|
37
|
-
`Foundry ${expectedKind} route "${id}" received a ${cell.kind} definition.`
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
if (cell.id && cell.id !== id) {
|
|
41
|
-
throw new Error(
|
|
42
|
-
`Foundry ${cell.kind} route resolves to "${id}" but the definition declares "${cell.id}". Remove the explicit id and let the file own identity.`
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
cell.id = id;
|
|
46
|
-
}
|
|
47
|
-
function fileDefinitionKey(value) {
|
|
48
|
-
const cell = identities.get(value);
|
|
49
|
-
return cell ?? value;
|
|
50
|
-
}
|
|
51
|
-
function fileDefinitionLabel(value) {
|
|
52
|
-
const cell = identities.get(value);
|
|
53
|
-
return cell?.id ?? `<${cell?.kind ?? "definition"} file route>`;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// src/surfaces.ts
|
|
57
|
-
var FOUNDRY_LAYER_BRAND = /* @__PURE__ */ Symbol.for("glove-foundry-layer");
|
|
58
|
-
var FOUNDRY_SUBSCRIBER_BRAND = /* @__PURE__ */ Symbol.for(
|
|
59
|
-
"glove-foundry-subscriber"
|
|
60
|
-
);
|
|
61
|
-
var SURFACE_ID = /^[a-z][a-z0-9-]*(?:\/[a-z][a-z0-9-]*)*$/;
|
|
62
|
-
function assertSurfaceId(id, label) {
|
|
63
|
-
if (!SURFACE_ID.test(id)) {
|
|
64
|
-
throw new Error(
|
|
65
|
-
`Invalid Foundry ${label} id "${id}". Use lowercase path segments containing letters, digits, and hyphens.`
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
function defineLayer(options) {
|
|
70
|
-
if (options.id) assertSurfaceId(options.id, "layer");
|
|
71
|
-
const { id, ...definition } = options;
|
|
72
|
-
return Object.freeze(fileIdentified({
|
|
73
|
-
...definition,
|
|
74
|
-
[FOUNDRY_LAYER_BRAND]: true
|
|
75
|
-
}, "layer", id));
|
|
76
|
-
}
|
|
77
|
-
function configureLayer(layer, config) {
|
|
78
|
-
return Object.freeze({ layer, config });
|
|
79
|
-
}
|
|
80
|
-
function defineSubscriber(options) {
|
|
81
|
-
if (options.id) assertSurfaceId(options.id, "subscriber");
|
|
82
|
-
const { id, ...definition } = options;
|
|
83
|
-
return Object.freeze(fileIdentified({
|
|
84
|
-
...definition,
|
|
85
|
-
[FOUNDRY_SUBSCRIBER_BRAND]: true
|
|
86
|
-
}, "subscriber", id));
|
|
87
|
-
}
|
|
88
|
-
var EMPTY_NATIVE_REGISTRY = Object.freeze({
|
|
89
|
-
layers: Object.freeze([]),
|
|
90
|
-
subscribers: Object.freeze([])
|
|
91
|
-
});
|
|
92
|
-
function indexById(values, label) {
|
|
93
|
-
const indexed = /* @__PURE__ */ new Map();
|
|
94
|
-
for (const value of values) {
|
|
95
|
-
if (indexed.has(value.id)) {
|
|
96
|
-
throw new Error(`Duplicate Foundry ${label} id "${value.id}".`);
|
|
97
|
-
}
|
|
98
|
-
indexed.set(value.id, value);
|
|
99
|
-
}
|
|
100
|
-
return indexed;
|
|
101
|
-
}
|
|
102
|
-
async function mountFoundrySurfaces(options) {
|
|
103
|
-
const layers = indexById(options.registry.layers, "layer");
|
|
104
|
-
const subscribers = indexById(options.registry.subscribers, "subscriber");
|
|
105
|
-
const cleanup = [];
|
|
106
|
-
const disposeAll = async () => {
|
|
107
|
-
const failures = [];
|
|
108
|
-
for (const dispose of cleanup.reverse()) {
|
|
109
|
-
try {
|
|
110
|
-
const result = dispose();
|
|
111
|
-
if (Effect.isEffect(result)) await Effect.runPromise(result);
|
|
112
|
-
else await Promise.resolve(result);
|
|
113
|
-
} catch (cause) {
|
|
114
|
-
failures.push(cause);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
if (failures.length > 0) {
|
|
118
|
-
throw new AggregateError(failures, "Foundry surface cleanup failed.");
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
try {
|
|
122
|
-
for (const selected of options.subscribers ?? []) {
|
|
123
|
-
let definition = selected;
|
|
124
|
-
if (typeof definition === "object" && definition !== null && FOUNDRY_SUBSCRIBER_BRAND in definition) {
|
|
125
|
-
const registered = subscribers.get(definition.id);
|
|
126
|
-
if (!registered) {
|
|
127
|
-
throw new Error(
|
|
128
|
-
`Agent "${options.context.agentId}" references unknown subscriber "${definition.id}".`
|
|
129
|
-
);
|
|
130
|
-
}
|
|
131
|
-
definition = registered;
|
|
132
|
-
}
|
|
133
|
-
let subscriber;
|
|
134
|
-
let subscriberId = "inline";
|
|
135
|
-
if (typeof definition === "object" && definition !== null && definition[FOUNDRY_SUBSCRIBER_BRAND] === true) {
|
|
136
|
-
const foundrySubscriber = definition;
|
|
137
|
-
const created = typeof foundrySubscriber.create === "function" ? foundrySubscriber.create(options.context) : foundrySubscriber.create;
|
|
138
|
-
subscriber = Effect.isEffect(created) ? await Effect.runPromise(created) : await Promise.resolve(created);
|
|
139
|
-
subscriberId = foundrySubscriber.id;
|
|
140
|
-
} else {
|
|
141
|
-
subscriber = definition;
|
|
142
|
-
}
|
|
143
|
-
options.context.glove.addSubscriber(subscriber);
|
|
144
|
-
cleanup.push(() => options.context.glove.removeSubscriber(subscriber));
|
|
145
|
-
options.context.emit({
|
|
146
|
-
type: "foundry.subscriber.mounted",
|
|
147
|
-
data: { id: subscriberId }
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
for (const selected of options.layers ?? []) {
|
|
151
|
-
const reference = FOUNDRY_LAYER_BRAND in selected ? { layer: selected } : selected;
|
|
152
|
-
const definition = layers.get(reference.layer.id);
|
|
153
|
-
if (!definition) {
|
|
154
|
-
throw new Error(
|
|
155
|
-
`Agent "${options.context.agentId}" references unknown layer "${reference.layer.id}".`
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
const referenceConfig = "config" in reference ? reference.config : void 0;
|
|
159
|
-
const parsed = definition.config ? definition.config.safeParse(referenceConfig ?? {}) : { success: true, data: referenceConfig };
|
|
160
|
-
if (!parsed.success) {
|
|
161
|
-
throw new Error(
|
|
162
|
-
`Invalid config for layer "${definition.id}": ${parsed.error.message}`
|
|
163
|
-
);
|
|
164
|
-
}
|
|
165
|
-
const dispose = await Effect.runPromise(
|
|
166
|
-
definition.setup({ ...options.context, config: parsed.data })
|
|
167
|
-
);
|
|
168
|
-
if (dispose) cleanup.push(dispose);
|
|
169
|
-
options.context.emit({
|
|
170
|
-
type: "foundry.layer.mounted",
|
|
171
|
-
data: { id: definition.id }
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
} catch (cause) {
|
|
175
|
-
try {
|
|
176
|
-
await disposeAll();
|
|
177
|
-
} catch (cleanupCause) {
|
|
178
|
-
throw new AggregateError(
|
|
179
|
-
[cause, cleanupCause],
|
|
180
|
-
"Foundry surface mount and cleanup failed."
|
|
181
|
-
);
|
|
182
|
-
}
|
|
183
|
-
throw cause;
|
|
184
|
-
}
|
|
185
|
-
return disposeAll;
|
|
186
|
-
}
|
|
187
|
-
function isFoundryLayer(value) {
|
|
188
|
-
return Boolean(
|
|
189
|
-
value && typeof value === "object" && value[FOUNDRY_LAYER_BRAND] === true
|
|
190
|
-
);
|
|
191
|
-
}
|
|
192
|
-
function isFoundrySubscriber(value) {
|
|
193
|
-
return Boolean(
|
|
194
|
-
value && typeof value === "object" && value[FOUNDRY_SUBSCRIBER_BRAND] === true
|
|
195
|
-
);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
// src/definition.ts
|
|
199
|
-
import { Displaymanager, Glove } from "glove-core";
|
|
200
|
-
import { Effect as Effect2 } from "effect";
|
|
201
|
-
var FOUNDRY_AGENT_DEFINITION_BRAND = /* @__PURE__ */ Symbol.for(
|
|
202
|
-
"glove-foundry-agent-definition"
|
|
203
|
-
);
|
|
204
|
-
var FOUNDRY_AGENT_BRAND = FOUNDRY_AGENT_DEFINITION_BRAND;
|
|
205
|
-
var FOUNDRY_EVENT_PREFIX = "__GLOVE_FOUNDRY_EVENT__";
|
|
206
|
-
var FOUNDRY_RUN_PROCESS_EVENT = "foundry.run.process";
|
|
207
|
-
var FOUNDRY_APPLICATION_ENV = "GLOVE_FOUNDRY_APPLICATION_FILE";
|
|
208
|
-
var FOUNDRY_AGENT_ROUTE_ENV = "GLOVE_FOUNDRY_AGENT_ROUTE";
|
|
209
|
-
var FOUNDRY_AGENT_FILE_ENV = "GLOVE_FOUNDRY_AGENT_FILE";
|
|
210
|
-
var FOUNDRY_EXECUTION_MARKER = "__glove_foundry_execution_v1";
|
|
211
|
-
function defineCall(options) {
|
|
212
|
-
if (!/^[A-Za-z][A-Za-z0-9_-]*$/.test(options.name)) {
|
|
213
|
-
throw new Error(`Invalid Foundry call name "${options.name}".`);
|
|
214
|
-
}
|
|
215
|
-
return Object.freeze({ ...options });
|
|
216
|
-
}
|
|
217
|
-
var ROUTE_PATTERN = /^[a-z][a-z0-9-]*(?:\/[a-z][a-z0-9-]*)*$/;
|
|
218
|
-
function assertAgentRoute(route) {
|
|
219
|
-
if (!ROUTE_PATTERN.test(route)) {
|
|
220
|
-
throw new Error(
|
|
221
|
-
`Invalid Foundry agent id "${route}". Use lowercase path segments containing letters, digits, and hyphens.`
|
|
222
|
-
);
|
|
223
|
-
}
|
|
224
|
-
if (route.includes("__")) {
|
|
225
|
-
throw new Error(`Invalid Foundry agent id "${route}": "__" is reserved.`);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
function internalAgentName(route) {
|
|
229
|
-
assertAgentRoute(route);
|
|
230
|
-
return `foundry_${route.replaceAll("/", "__").replaceAll("-", "_")}`;
|
|
231
|
-
}
|
|
232
|
-
function routeFromInternalAgentName(name) {
|
|
233
|
-
if (!name.startsWith("foundry_")) return name;
|
|
234
|
-
return name.slice("foundry_".length).replaceAll("__", "/").replaceAll("_", "-");
|
|
235
|
-
}
|
|
236
|
-
function isFoundryAgentDefinition(value) {
|
|
237
|
-
return Boolean(
|
|
238
|
-
value && typeof value === "object" && value[FOUNDRY_AGENT_DEFINITION_BRAND] === true
|
|
239
|
-
);
|
|
240
|
-
}
|
|
241
|
-
var isFoundryAgent = isFoundryAgentDefinition;
|
|
242
|
-
function validateDefinition(options, route) {
|
|
243
|
-
const id = route ?? options.id;
|
|
244
|
-
if (id) assertAgentRoute(id);
|
|
245
|
-
if (!options.model && !options.run && !options.handler && !options.spawn) {
|
|
246
|
-
throw new Error(`Foundry agent "${id ?? "<file route>"}" must define model, run, handler, or spawn.`);
|
|
247
|
-
}
|
|
248
|
-
if (options.model && options.systemPrompt === void 0) {
|
|
249
|
-
throw new Error(`Foundry agent "${id ?? "<file route>"}" must define systemPrompt when it defines a model.`);
|
|
250
|
-
}
|
|
251
|
-
if (options.answerWaitMs !== void 0 && (!Number.isFinite(options.answerWaitMs) || options.answerWaitMs < 0)) {
|
|
252
|
-
throw new Error(`Foundry agent "${id ?? "<file route>"}" answerWaitMs must be a non-negative number.`);
|
|
253
|
-
}
|
|
254
|
-
if (options.inboxes !== void 0 && typeof options.inboxes !== "function") {
|
|
255
|
-
throw new Error(
|
|
256
|
-
`Foundry agent "${id ?? "<file route>"}" inboxes must be a lazy resolver function.`
|
|
257
|
-
);
|
|
258
|
-
}
|
|
259
|
-
const forbidden = ["input", "output"];
|
|
260
|
-
for (const key of forbidden) {
|
|
261
|
-
if (key in options) {
|
|
262
|
-
throw new Error(`Foundry agent "${id ?? "<file route>"}" cannot define ${key}; invocation contracts are framework-owned.`);
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
function defineAgent(options) {
|
|
267
|
-
validateDefinition(options);
|
|
268
|
-
const { id, ...definition } = options;
|
|
269
|
-
return Object.freeze(fileIdentified({
|
|
270
|
-
...definition,
|
|
271
|
-
tags: Object.freeze([...options.tags ?? []]),
|
|
272
|
-
[FOUNDRY_AGENT_DEFINITION_BRAND]: true
|
|
273
|
-
}, "agent", id));
|
|
274
|
-
}
|
|
275
|
-
var CONVENTION_EXPORTS = [
|
|
276
|
-
"id",
|
|
277
|
-
"description",
|
|
278
|
-
"tags",
|
|
279
|
-
"components",
|
|
280
|
-
"mcpAdapter",
|
|
281
|
-
"accountSessions",
|
|
282
|
-
"store",
|
|
283
|
-
"model",
|
|
284
|
-
"systemPrompt",
|
|
285
|
-
"displayManager",
|
|
286
|
-
"serverMode",
|
|
287
|
-
"maxRetries",
|
|
288
|
-
"maxConsecutiveErrors",
|
|
289
|
-
"compactionLimit",
|
|
290
|
-
"compactionInstructions",
|
|
291
|
-
"maxTurns",
|
|
292
|
-
"enableToolResultSummary",
|
|
293
|
-
"tools",
|
|
294
|
-
"hooks",
|
|
295
|
-
"skills",
|
|
296
|
-
"subagents",
|
|
297
|
-
"delegates",
|
|
298
|
-
"answerWaitMs",
|
|
299
|
-
"memory",
|
|
300
|
-
"goals",
|
|
301
|
-
"facts",
|
|
302
|
-
"forms",
|
|
303
|
-
"contextProviders",
|
|
304
|
-
"inboxes",
|
|
305
|
-
"subscribers",
|
|
306
|
-
"layers",
|
|
307
|
-
"calls",
|
|
308
|
-
"schedules",
|
|
309
|
-
"playbooks",
|
|
310
|
-
"mesh",
|
|
311
|
-
"workingEnvironment",
|
|
312
|
-
"repl",
|
|
313
|
-
"configure",
|
|
314
|
-
"build",
|
|
315
|
-
"spawn",
|
|
316
|
-
"run",
|
|
317
|
-
"handler"
|
|
318
|
-
];
|
|
319
|
-
function defineAgentFromModule(route, module) {
|
|
320
|
-
assertAgentRoute(route);
|
|
321
|
-
if (isFoundryAgentDefinition(module.default)) {
|
|
322
|
-
const definition2 = module.default;
|
|
323
|
-
bindFileIdentity(definition2, route, "agent");
|
|
324
|
-
validateDefinition(definition2, route);
|
|
325
|
-
return definition2;
|
|
326
|
-
}
|
|
327
|
-
if (!module.description) {
|
|
328
|
-
throw new Error(`Foundry route "${route}" must default-export defineAgent(...) or export description.`);
|
|
329
|
-
}
|
|
330
|
-
const options = {};
|
|
331
|
-
for (const key of CONVENTION_EXPORTS) {
|
|
332
|
-
if (module[key] !== void 0) options[key] = module[key];
|
|
333
|
-
}
|
|
334
|
-
const definition = defineAgent(options);
|
|
335
|
-
bindFileIdentity(definition, route, "agent");
|
|
336
|
-
return definition;
|
|
337
|
-
}
|
|
338
|
-
function defineSubagent(options) {
|
|
339
|
-
if (!/^[A-Za-z][\w-]*$/.test(options.name)) throw new Error(`Invalid Foundry subagent name "${options.name}".`);
|
|
340
|
-
return Object.freeze({
|
|
341
|
-
name: options.name,
|
|
342
|
-
description: options.description,
|
|
343
|
-
factory: async ({ parentStore, parentControls, prompt }) => {
|
|
344
|
-
const store = await parentStore.createSubAgentStore?.(options.name, options.durable ?? false) ?? void 0;
|
|
345
|
-
const tools = typeof options.tools === "function" ? await resolveResolvable(options.tools({
|
|
346
|
-
name: options.name,
|
|
347
|
-
prompt,
|
|
348
|
-
parent: parentControls.glove
|
|
349
|
-
})) : options.tools ?? [];
|
|
350
|
-
const glove = new Glove({
|
|
351
|
-
...store ? { store } : {},
|
|
352
|
-
model: options.model ?? parentControls.glove.model,
|
|
353
|
-
displayManager: parentControls.displayManager ?? new Displaymanager(),
|
|
354
|
-
systemPrompt: options.systemPrompt,
|
|
355
|
-
serverMode: options.serverMode ?? parentControls.glove.serverMode,
|
|
356
|
-
...options.maxRetries !== void 0 ? { maxRetries: options.maxRetries } : {},
|
|
357
|
-
...options.maxConsecutiveErrors !== void 0 ? { maxConsecutiveErrors: options.maxConsecutiveErrors } : {},
|
|
358
|
-
compaction_config: {
|
|
359
|
-
compaction_instructions: options.compactionInstructions ?? `Preserve the ${options.name} subagent's findings and unresolved work.`,
|
|
360
|
-
...options.maxTurns !== void 0 ? { max_turns: options.maxTurns } : {},
|
|
361
|
-
...options.compactionLimit !== void 0 ? { compaction_context_limit: options.compactionLimit } : {}
|
|
362
|
-
},
|
|
363
|
-
...options.enableToolResultSummary !== void 0 ? { enableToolResultSummary: options.enableToolResultSummary } : {}
|
|
364
|
-
}).build();
|
|
365
|
-
for (const tool of tools) glove.fold(tool);
|
|
366
|
-
for (const hook of options.hooks ?? []) glove.defineHook(hook.name, hook.handler);
|
|
367
|
-
for (const skill of options.skills ?? []) glove.defineSkill(skill);
|
|
368
|
-
for (const subagent of options.subagents ?? []) glove.defineSubAgent(subagent);
|
|
369
|
-
const message = { sender: "user", text: prompt };
|
|
370
|
-
const request = {
|
|
371
|
-
agentId: options.name,
|
|
372
|
-
conversationId: `subagent:${options.name}`,
|
|
373
|
-
workspaceId: "subagent",
|
|
374
|
-
message: prompt,
|
|
375
|
-
source: { kind: "spawn" }
|
|
376
|
-
};
|
|
377
|
-
const context = {
|
|
378
|
-
definitionId: options.name,
|
|
379
|
-
agentId: options.name,
|
|
380
|
-
conversationId: request.conversationId,
|
|
381
|
-
workspaceId: request.workspaceId,
|
|
382
|
-
runId: `subagent:${options.name}`,
|
|
383
|
-
input: prompt,
|
|
384
|
-
request,
|
|
385
|
-
message,
|
|
386
|
-
messageInput: prompt,
|
|
387
|
-
messageText: prompt,
|
|
388
|
-
history: [],
|
|
389
|
-
messages: [message],
|
|
390
|
-
glove,
|
|
391
|
-
signal: new AbortController().signal,
|
|
392
|
-
emit: () => void 0
|
|
393
|
-
};
|
|
394
|
-
const disposeSurfaces = await mountFoundrySurfaces({
|
|
395
|
-
registry: {
|
|
396
|
-
layers: uniqueById((options.layers ?? []).map((selected) => "layer" in selected ? selected.layer : selected)),
|
|
397
|
-
subscribers: uniqueById((options.subscribers ?? []).filter(isFoundrySubscriber))
|
|
398
|
-
},
|
|
399
|
-
layers: options.layers ?? [],
|
|
400
|
-
subscribers: options.subscribers ?? [],
|
|
401
|
-
context
|
|
402
|
-
});
|
|
403
|
-
try {
|
|
404
|
-
if (options.configure) await resolveResolvable(options.configure(context));
|
|
405
|
-
} catch (cause) {
|
|
406
|
-
await disposeSurfaces();
|
|
407
|
-
throw cause;
|
|
408
|
-
}
|
|
409
|
-
const processRequest = glove.processRequest.bind(glove);
|
|
410
|
-
let disposed = false;
|
|
411
|
-
glove.processRequest = async (...args) => {
|
|
412
|
-
try {
|
|
413
|
-
return await processRequest(...args);
|
|
414
|
-
} finally {
|
|
415
|
-
if (!disposed) {
|
|
416
|
-
disposed = true;
|
|
417
|
-
await disposeSurfaces();
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
};
|
|
421
|
-
return glove;
|
|
422
|
-
}
|
|
423
|
-
});
|
|
424
|
-
}
|
|
425
|
-
function uniqueById(values) {
|
|
426
|
-
return [...new Map(values.map((value) => [value.id, value])).values()];
|
|
427
|
-
}
|
|
428
|
-
async function resolveResolvable(value) {
|
|
429
|
-
if (Effect2.isEffect(value)) return Effect2.runPromise(value);
|
|
430
|
-
return Promise.resolve(value);
|
|
431
|
-
}
|
|
432
|
-
function defineRoutes(routes) {
|
|
433
|
-
return Object.freeze({ ...routes });
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
export {
|
|
437
|
-
fileIdentified,
|
|
438
|
-
bindFileIdentity,
|
|
439
|
-
fileDefinitionKey,
|
|
440
|
-
fileDefinitionLabel,
|
|
441
|
-
FOUNDRY_LAYER_BRAND,
|
|
442
|
-
FOUNDRY_SUBSCRIBER_BRAND,
|
|
443
|
-
defineLayer,
|
|
444
|
-
configureLayer,
|
|
445
|
-
defineSubscriber,
|
|
446
|
-
EMPTY_NATIVE_REGISTRY,
|
|
447
|
-
mountFoundrySurfaces,
|
|
448
|
-
isFoundryLayer,
|
|
449
|
-
isFoundrySubscriber,
|
|
450
|
-
FOUNDRY_AGENT_DEFINITION_BRAND,
|
|
451
|
-
FOUNDRY_AGENT_BRAND,
|
|
452
|
-
FOUNDRY_EVENT_PREFIX,
|
|
453
|
-
FOUNDRY_RUN_PROCESS_EVENT,
|
|
454
|
-
FOUNDRY_APPLICATION_ENV,
|
|
455
|
-
FOUNDRY_AGENT_ROUTE_ENV,
|
|
456
|
-
FOUNDRY_AGENT_FILE_ENV,
|
|
457
|
-
FOUNDRY_EXECUTION_MARKER,
|
|
458
|
-
defineCall,
|
|
459
|
-
internalAgentName,
|
|
460
|
-
routeFromInternalAgentName,
|
|
461
|
-
isFoundryAgentDefinition,
|
|
462
|
-
isFoundryAgent,
|
|
463
|
-
defineAgent,
|
|
464
|
-
defineAgentFromModule,
|
|
465
|
-
defineSubagent,
|
|
466
|
-
resolveResolvable,
|
|
467
|
-
defineRoutes
|
|
468
|
-
};
|