glove-foundry 0.5.1 → 0.6.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 +104 -15
- package/dist/{chunk-GKZLWD5M.js → chunk-7F7QVO6I.js} +4 -1
- package/dist/chunk-B36BGF5R.js +530 -0
- package/dist/{chunk-5NFLGHOC.js → chunk-K2EU63MB.js} +216 -29
- package/dist/{chunk-KBMD4RYU.js → chunk-OBTOFA7W.js} +63 -198
- package/dist/{chunk-LW5PJ2FN.js → chunk-RSU7NEDK.js} +9 -3
- package/dist/{chunk-TH5ETCG2.js → chunk-TFGETZYH.js} +198 -11
- package/dist/{chunk-SGF3CFUR.js → chunk-X6EWEWWM.js} +942 -57
- package/dist/cli.js +8 -5
- package/dist/client-DWPYe_Nc.d.ts +888 -0
- package/dist/client.d.ts +2 -1
- package/dist/client.js +1 -1
- package/dist/{client-DcsnudMI.d.ts → definition-A8o11aez.d.ts} +195 -812
- package/dist/execution-agent.js +5 -4
- package/dist/execution-daemon.js +37 -2
- package/dist/execution-loader.js +5 -4
- package/dist/index.d.ts +8 -3
- package/dist/index.js +39 -14
- package/dist/voice.d.ts +168 -0
- package/dist/voice.js +348 -0
- package/docs/building-with-foundry.md +32 -21
- package/docs/durable-execution.md +56 -0
- package/docs/release-verification.md +1 -1
- package/package.json +16 -9
- package/templates/minimal/README.md +34 -8
- package/templates/minimal/agents/assistant/agent.ts +24 -10
- package/templates/minimal/foundry.application.ts +11 -3
- package/templates/minimal/gitignore +1 -0
- package/templates/minimal/lib/file-store.ts +95 -0
- package/templates/travel-concierge/README.md +46 -12
- package/templates/travel-concierge/agents/concierge/agent.ts +10 -4
- package/templates/travel-concierge/agents/concierge/composition.ts +9 -2
- package/templates/travel-concierge/agents/concierge/flights.ts +43 -0
- package/templates/travel-concierge/agents/concierge/instances.ts +42 -0
- package/templates/travel-concierge/agents/concierge/memory/traveller.memory.ts +13 -8
- package/templates/travel-concierge/agents/concierge/tools/convert-currency.tool.ts +34 -0
- package/templates/travel-concierge/agents/concierge/workbench.ts +4 -1
- package/templates/travel-concierge/foundry.application.ts +15 -6
- package/templates/travel-concierge/gitignore +1 -0
- package/templates/travel-concierge/lib/demo-model.ts +89 -25
- package/templates/travel-concierge/lib/file-context.ts +60 -0
- package/templates/travel-concierge/lib/file-store.ts +95 -0
- package/templates/minimal/agents/assistant/tools/current-time.tool.ts +0 -17
- package/templates/travel-concierge/agents/concierge/tools/find-flights.tool.ts +0 -49
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
import { Displaymanager, Glove } from "glove-core";
|
|
1
|
+
// src/surfaces.ts
|
|
3
2
|
import { Effect } from "effect";
|
|
4
3
|
|
|
5
4
|
// src/identity.ts
|
|
@@ -54,12 +53,157 @@ function fileDefinitionLabel(value) {
|
|
|
54
53
|
return cell?.id ?? `<${cell?.kind ?? "definition"} file route>`;
|
|
55
54
|
}
|
|
56
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
|
+
|
|
57
198
|
// src/definition.ts
|
|
199
|
+
import { Displaymanager, Glove } from "glove-core";
|
|
200
|
+
import { Effect as Effect2 } from "effect";
|
|
58
201
|
var FOUNDRY_AGENT_DEFINITION_BRAND = /* @__PURE__ */ Symbol.for(
|
|
59
202
|
"glove-foundry-agent-definition"
|
|
60
203
|
);
|
|
61
204
|
var FOUNDRY_AGENT_BRAND = FOUNDRY_AGENT_DEFINITION_BRAND;
|
|
62
205
|
var FOUNDRY_EVENT_PREFIX = "__GLOVE_FOUNDRY_EVENT__";
|
|
206
|
+
var FOUNDRY_RUN_PROCESS_EVENT = "foundry.run.process";
|
|
63
207
|
var FOUNDRY_APPLICATION_ENV = "GLOVE_FOUNDRY_APPLICATION_FILE";
|
|
64
208
|
var FOUNDRY_AGENT_ROUTE_ENV = "GLOVE_FOUNDRY_AGENT_ROUTE";
|
|
65
209
|
var FOUNDRY_AGENT_FILE_ENV = "GLOVE_FOUNDRY_AGENT_FILE";
|
|
@@ -104,6 +248,9 @@ function validateDefinition(options, route) {
|
|
|
104
248
|
if (options.model && options.systemPrompt === void 0) {
|
|
105
249
|
throw new Error(`Foundry agent "${id ?? "<file route>"}" must define systemPrompt when it defines a model.`);
|
|
106
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
|
+
}
|
|
107
254
|
if (options.inboxes !== void 0 && typeof options.inboxes !== "function") {
|
|
108
255
|
throw new Error(
|
|
109
256
|
`Foundry agent "${id ?? "<file route>"}" inboxes must be a lazy resolver function.`
|
|
@@ -147,6 +294,8 @@ var CONVENTION_EXPORTS = [
|
|
|
147
294
|
"hooks",
|
|
148
295
|
"skills",
|
|
149
296
|
"subagents",
|
|
297
|
+
"delegates",
|
|
298
|
+
"answerWaitMs",
|
|
150
299
|
"memory",
|
|
151
300
|
"goals",
|
|
152
301
|
"facts",
|
|
@@ -217,39 +366,67 @@ function defineSubagent(options) {
|
|
|
217
366
|
for (const hook of options.hooks ?? []) glove.defineHook(hook.name, hook.handler);
|
|
218
367
|
for (const skill of options.skills ?? []) glove.defineSkill(skill);
|
|
219
368
|
for (const subagent of options.subagents ?? []) glove.defineSubAgent(subagent);
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
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;
|
|
246
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
|
+
};
|
|
247
421
|
return glove;
|
|
248
422
|
}
|
|
249
423
|
});
|
|
250
424
|
}
|
|
425
|
+
function uniqueById(values) {
|
|
426
|
+
return [...new Map(values.map((value) => [value.id, value])).values()];
|
|
427
|
+
}
|
|
251
428
|
async function resolveResolvable(value) {
|
|
252
|
-
if (
|
|
429
|
+
if (Effect2.isEffect(value)) return Effect2.runPromise(value);
|
|
253
430
|
return Promise.resolve(value);
|
|
254
431
|
}
|
|
255
432
|
function defineRoutes(routes) {
|
|
@@ -261,9 +438,19 @@ export {
|
|
|
261
438
|
bindFileIdentity,
|
|
262
439
|
fileDefinitionKey,
|
|
263
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,
|
|
264
450
|
FOUNDRY_AGENT_DEFINITION_BRAND,
|
|
265
451
|
FOUNDRY_AGENT_BRAND,
|
|
266
452
|
FOUNDRY_EVENT_PREFIX,
|
|
453
|
+
FOUNDRY_RUN_PROCESS_EVENT,
|
|
267
454
|
FOUNDRY_APPLICATION_ENV,
|
|
268
455
|
FOUNDRY_AGENT_ROUTE_ENV,
|
|
269
456
|
FOUNDRY_AGENT_FILE_ENV,
|