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,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
mountFoundryGuidance,
|
|
3
3
|
mountFoundryWorkbench
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-RSU7NEDK.js";
|
|
5
5
|
import {
|
|
6
6
|
EMPTY_CAPABILITY_REGISTRY,
|
|
7
7
|
EMPTY_FOUNDRY_APPLICATION,
|
|
@@ -23,20 +23,38 @@ import {
|
|
|
23
23
|
isInboxCapableStore,
|
|
24
24
|
materializeComposedPlaybook,
|
|
25
25
|
mountAgentDefinitionMemory,
|
|
26
|
-
mountFoundrySurfaces,
|
|
27
26
|
normalizeScheduleTiming,
|
|
28
27
|
toGloveMessage,
|
|
29
28
|
toGloveRequestInput,
|
|
30
29
|
withFoundryPermissions
|
|
31
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-OBTOFA7W.js";
|
|
31
|
+
import {
|
|
32
|
+
FOUNDRY_CONVERSATION_LEASE_EVENT,
|
|
33
|
+
FOUNDRY_CONVERSATION_LISTEN_EVENT,
|
|
34
|
+
FOUNDRY_MAILBOX_DIRECTORY_ENV,
|
|
35
|
+
RunEventQueue,
|
|
36
|
+
createDelegatorTools,
|
|
37
|
+
createWorkerTools,
|
|
38
|
+
delegationFromContext,
|
|
39
|
+
deliveryEvent,
|
|
40
|
+
formatRunEvents,
|
|
41
|
+
isDelegationUpdate,
|
|
42
|
+
isOpenDelegation,
|
|
43
|
+
normalizeDelegates,
|
|
44
|
+
openRunMailbox,
|
|
45
|
+
renderOpenDelegations,
|
|
46
|
+
waitForConversationLease
|
|
47
|
+
} from "./chunk-B36BGF5R.js";
|
|
32
48
|
import {
|
|
33
49
|
FOUNDRY_APPLICATION_ENV,
|
|
34
50
|
FOUNDRY_EVENT_PREFIX,
|
|
35
51
|
FOUNDRY_EXECUTION_MARKER,
|
|
52
|
+
FOUNDRY_RUN_PROCESS_EVENT,
|
|
36
53
|
defineAgentFromModule,
|
|
37
54
|
internalAgentName,
|
|
55
|
+
mountFoundrySurfaces,
|
|
38
56
|
resolveResolvable
|
|
39
|
-
} from "./chunk-
|
|
57
|
+
} from "./chunk-K2EU63MB.js";
|
|
40
58
|
|
|
41
59
|
// src/agent-runtime.ts
|
|
42
60
|
import { pathToFileURL } from "node:url";
|
|
@@ -45,6 +63,7 @@ import { mountMesh } from "glove-mesh";
|
|
|
45
63
|
import { Effect } from "effect";
|
|
46
64
|
import { signal } from "station-signal";
|
|
47
65
|
import { z } from "zod";
|
|
66
|
+
var DEFAULT_ANSWER_WAIT_MS = 9e4;
|
|
48
67
|
var INBOX_ITEMS_SCHEMA = z.array(z.object({
|
|
49
68
|
id: z.string().min(1),
|
|
50
69
|
tag: z.string(),
|
|
@@ -173,6 +192,14 @@ async function executeSpawned(spawned, message, signal2) {
|
|
|
173
192
|
return spawned;
|
|
174
193
|
}
|
|
175
194
|
async function runDefinition(definition, id, runtimeValue) {
|
|
195
|
+
await writeAgentEvent(FOUNDRY_RUN_PROCESS_EVENT, { state: "acquired" }).catch(() => void 0);
|
|
196
|
+
try {
|
|
197
|
+
return await executeDefinition(definition, id, runtimeValue);
|
|
198
|
+
} finally {
|
|
199
|
+
await writeAgentEvent(FOUNDRY_RUN_PROCESS_EVENT, { state: "released" }).catch(() => void 0);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
async function executeDefinition(definition, id, runtimeValue) {
|
|
176
203
|
const envelope = runtimeValue;
|
|
177
204
|
const request = envelope.request;
|
|
178
205
|
const input = request;
|
|
@@ -181,6 +208,16 @@ async function runDefinition(definition, id, runtimeValue) {
|
|
|
181
208
|
const abortController = new AbortController();
|
|
182
209
|
const onTerminate = () => abortController.abort();
|
|
183
210
|
process.once("SIGTERM", onTerminate);
|
|
211
|
+
const leaseDirectory = process.env[FOUNDRY_MAILBOX_DIRECTORY_ENV];
|
|
212
|
+
if (!envelope.conversationLease && leaseDirectory) {
|
|
213
|
+
try {
|
|
214
|
+
await writeAgentEvent(FOUNDRY_CONVERSATION_LEASE_EVENT, { conversationId: request.conversationId });
|
|
215
|
+
await waitForConversationLease(leaseDirectory, runId, abortController.signal);
|
|
216
|
+
} catch (cause) {
|
|
217
|
+
process.removeListener("SIGTERM", onTerminate);
|
|
218
|
+
throw cause;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
184
221
|
let disposeSurfaces;
|
|
185
222
|
const cleanups = [];
|
|
186
223
|
const application = await loadRuntimeApplication();
|
|
@@ -228,6 +265,8 @@ async function runDefinition(definition, id, runtimeValue) {
|
|
|
228
265
|
agentInstance: envelope.agent,
|
|
229
266
|
conversation: envelope.conversation,
|
|
230
267
|
activations: Object.freeze([...envelope.activations ?? []]),
|
|
268
|
+
delegations: Object.freeze([...envelope.delegations ?? []]),
|
|
269
|
+
...delegationFromContext(envelope.conversation.context) ? { delegation: delegationFromContext(envelope.conversation.context) } : {},
|
|
231
270
|
data,
|
|
232
271
|
input,
|
|
233
272
|
message,
|
|
@@ -268,8 +307,10 @@ async function runDefinition(definition, id, runtimeValue) {
|
|
|
268
307
|
resolveOptional("compactionInstructions", definition.compactionInstructions, "Preserve goals, decisions, unresolved work, tool results, and pending inbox items."),
|
|
269
308
|
resolveOptional("maxTurns", definition.maxTurns, void 0)
|
|
270
309
|
]);
|
|
310
|
+
const eventQueue = new RunEventQueue();
|
|
271
311
|
const base = new Glove({
|
|
272
312
|
...runtimeStore ? { store: runtimeStore } : {},
|
|
313
|
+
events: { queue: eventQueue, policy: () => "defer", deferTimeoutMs: Infinity, formatter: formatRunEvents },
|
|
273
314
|
model,
|
|
274
315
|
displayManager,
|
|
275
316
|
systemPrompt,
|
|
@@ -284,11 +325,12 @@ async function runDefinition(definition, id, runtimeValue) {
|
|
|
284
325
|
...definition.enableToolResultSummary !== void 0 ? { enableToolResultSummary: definition.enableToolResultSummary } : {}
|
|
285
326
|
}).build();
|
|
286
327
|
base.addSubscriber(subscriber);
|
|
287
|
-
const [tools, hooks, skills, subagents, memory, inboxItems, layers, subscribers, calls, playbooks, schedules, mesh, workingEnvironment, repl] = await Promise.all([
|
|
328
|
+
const [tools, hooks, skills, subagents, delegates, memory, inboxItems, layers, subscribers, calls, playbooks, schedules, mesh, workingEnvironment, repl] = await Promise.all([
|
|
288
329
|
resolveOptional("tools", definition.tools, []),
|
|
289
330
|
resolveOptional("hooks", definition.hooks, []),
|
|
290
331
|
resolveOptional("skills", definition.skills, []),
|
|
291
332
|
resolveOptional("subagents", definition.subagents, []),
|
|
333
|
+
resolveOptional("delegates", definition.delegates, []),
|
|
292
334
|
resolveOptional("memory", definition.memory, []),
|
|
293
335
|
definition.inboxes ? resolveAgentValue(
|
|
294
336
|
definition,
|
|
@@ -393,6 +435,112 @@ async function runDefinition(definition, id, runtimeValue) {
|
|
|
393
435
|
for (const hook of hooks) base.defineHook(hook.name, hook.handler);
|
|
394
436
|
for (const skill of skills) base.defineSkill(skill);
|
|
395
437
|
for (const subagent of subagents) base.defineSubAgent(subagent);
|
|
438
|
+
const mailboxDirectory = process.env[FOUNDRY_MAILBOX_DIRECTORY_ENV];
|
|
439
|
+
const emitDelegationCommand = (command) => {
|
|
440
|
+
controls.commands.push(command);
|
|
441
|
+
controls.emit({ type: FOUNDRY_CORE_COMMAND_EVENT, data: command });
|
|
442
|
+
};
|
|
443
|
+
const forwarded = /* @__PURE__ */ new Map();
|
|
444
|
+
const heard = /* @__PURE__ */ new Map();
|
|
445
|
+
const pendingQuestion = {};
|
|
446
|
+
const ownDelegation = assemblyContext.delegation?.workerAgentId === request.agentId ? assemblyContext.delegation : void 0;
|
|
447
|
+
let runMailbox;
|
|
448
|
+
const mailbox = () => {
|
|
449
|
+
if (!mailboxDirectory) {
|
|
450
|
+
throw new Error("Foundry cannot deliver to this run without its parent runtime.");
|
|
451
|
+
}
|
|
452
|
+
if (!runMailbox) {
|
|
453
|
+
runMailbox = openRunMailbox({
|
|
454
|
+
directory: mailboxDirectory,
|
|
455
|
+
conversationId: request.conversationId,
|
|
456
|
+
report: (state) => writeAgentEvent(FOUNDRY_CONVERSATION_LISTEN_EVENT, { state }).catch(() => void 0),
|
|
457
|
+
sink: {
|
|
458
|
+
async forward(deliveries) {
|
|
459
|
+
for (const delivery of deliveries) {
|
|
460
|
+
const event = deliveryEvent(delivery);
|
|
461
|
+
forwarded.set(event.id, delivery);
|
|
462
|
+
await base.emitEvent(event);
|
|
463
|
+
}
|
|
464
|
+
},
|
|
465
|
+
async reclaim(match) {
|
|
466
|
+
const taken = await eventQueue.reclaim(match);
|
|
467
|
+
for (const { id: id2 } of taken) forwarded.delete(id2);
|
|
468
|
+
return taken.map(({ delivery }) => delivery);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
});
|
|
472
|
+
const opened = runMailbox;
|
|
473
|
+
cleanups.push(() => opened.close());
|
|
474
|
+
}
|
|
475
|
+
return runMailbox;
|
|
476
|
+
};
|
|
477
|
+
base.addSubscriber({
|
|
478
|
+
async record(type, data2) {
|
|
479
|
+
if (type !== "event_injected") return;
|
|
480
|
+
for (const id2 of data2.ids) {
|
|
481
|
+
const delivery = forwarded.get(id2);
|
|
482
|
+
if (!delivery) continue;
|
|
483
|
+
forwarded.delete(id2);
|
|
484
|
+
if (isDelegationUpdate(delivery)) heard.set(delivery.delegationId, delivery);
|
|
485
|
+
else if (delivery.kind === "reply" && pendingQuestion.current?.delegationId === delivery.delegationId) {
|
|
486
|
+
pendingQuestion.current = void 0;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
});
|
|
491
|
+
const delegationTarget = {
|
|
492
|
+
definitionId: id,
|
|
493
|
+
agentId: request.agentId,
|
|
494
|
+
conversationId: request.conversationId,
|
|
495
|
+
workspaceId: request.workspaceId,
|
|
496
|
+
emit: emitDelegationCommand
|
|
497
|
+
};
|
|
498
|
+
const startedHere = [];
|
|
499
|
+
const normalizedDelegates = normalizeDelegates(delegates);
|
|
500
|
+
const onReplied = (delegationId) => {
|
|
501
|
+
heard.set(delegationId, "replied");
|
|
502
|
+
};
|
|
503
|
+
for (const tool of createDelegatorTools(delegationTarget, normalizedDelegates, (started) => {
|
|
504
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
505
|
+
startedHere.push({
|
|
506
|
+
id: started.id,
|
|
507
|
+
to: started.to,
|
|
508
|
+
workerAgentId: "",
|
|
509
|
+
workspaceId: request.workspaceId,
|
|
510
|
+
from: { definitionId: id, agentId: request.agentId, conversationId: request.conversationId, runId },
|
|
511
|
+
task: started.task,
|
|
512
|
+
status: "working",
|
|
513
|
+
createdAt: now,
|
|
514
|
+
updatedAt: now
|
|
515
|
+
});
|
|
516
|
+
}, onReplied)) base.fold(tool);
|
|
517
|
+
if (normalizedDelegates.length > 0 || assemblyContext.delegations.length > 0) {
|
|
518
|
+
base.addContextProvider(
|
|
519
|
+
() => renderOpenDelegations(
|
|
520
|
+
[...assemblyContext.delegations.filter(isOpenDelegation), ...startedHere].flatMap((item) => {
|
|
521
|
+
const update = heard.get(item.id);
|
|
522
|
+
if (!update) return [item];
|
|
523
|
+
if (update === "replied") return [{ ...item, status: "working" }];
|
|
524
|
+
if (update.kind === "question") return [{ ...item, status: "waiting", question: update.question }];
|
|
525
|
+
return [];
|
|
526
|
+
})
|
|
527
|
+
)
|
|
528
|
+
);
|
|
529
|
+
controls.emit({
|
|
530
|
+
type: "foundry.definition.delegates.loaded",
|
|
531
|
+
data: { delegates: normalizedDelegates.map((delegate) => delegate.agent), open: assemblyContext.delegations.length }
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
if (ownDelegation) {
|
|
535
|
+
const answerWaitMs = definition.answerWaitMs ?? DEFAULT_ANSWER_WAIT_MS;
|
|
536
|
+
const waitForReply = async (timeoutMs) => mailboxDirectory ? mailbox().waitForReply(ownDelegation.id, timeoutMs, abortController.signal) : null;
|
|
537
|
+
for (const tool of createWorkerTools(delegationTarget, ownDelegation, {
|
|
538
|
+
answerWaitMs,
|
|
539
|
+
pending: pendingQuestion,
|
|
540
|
+
waitForReply
|
|
541
|
+
})) base.fold(tool);
|
|
542
|
+
}
|
|
543
|
+
if (mailboxDirectory) mailbox();
|
|
396
544
|
const workbench = await mountFoundryWorkbench({
|
|
397
545
|
glove: base,
|
|
398
546
|
context: assemblyContext,
|
|
@@ -448,7 +596,12 @@ async function runDefinition(definition, id, runtimeValue) {
|
|
|
448
596
|
onCleanup: (cleanup) => {
|
|
449
597
|
cleanups.push(cleanup);
|
|
450
598
|
},
|
|
451
|
-
invoke
|
|
599
|
+
invoke,
|
|
600
|
+
onDelegationUpdate: (handler) => {
|
|
601
|
+
const stop = mailbox().onUpdates(handler);
|
|
602
|
+
cleanups.push(stop);
|
|
603
|
+
return stop;
|
|
604
|
+
}
|
|
452
605
|
};
|
|
453
606
|
for (const call of calls) {
|
|
454
607
|
if (callByName.has(call.name)) throw new Error(`Duplicate Foundry call "${call.name}".`);
|
|
@@ -531,6 +684,11 @@ async function runDefinition(definition, id, runtimeValue) {
|
|
|
531
684
|
}
|
|
532
685
|
if (mesh) {
|
|
533
686
|
await mountMesh(base, {
|
|
687
|
+
// Foundry builds a runnable per run, so a message that arrives
|
|
688
|
+
// between runs has to wait in the conversation store, not in an
|
|
689
|
+
// in-memory event queue that is gone once the run ends. The inbox
|
|
690
|
+
// still delivers mid-run messages at the next tool step.
|
|
691
|
+
delivery: "inbox",
|
|
534
692
|
adapter: mesh.adapter,
|
|
535
693
|
identity: {
|
|
536
694
|
id: mesh.identity?.id ?? request.agentId,
|
|
@@ -575,13 +733,14 @@ async function runDefinition(definition, id, runtimeValue) {
|
|
|
575
733
|
const sleep = [...controls.commands].reverse().find(
|
|
576
734
|
(command) => command.type === "sleep"
|
|
577
735
|
);
|
|
736
|
+
const question = pendingQuestion.current;
|
|
578
737
|
return {
|
|
579
|
-
status: sleep ? "suspended" : "completed",
|
|
738
|
+
status: sleep || question ? "suspended" : "completed",
|
|
580
739
|
value: serializable(result),
|
|
581
740
|
agentId: request.agentId,
|
|
582
741
|
conversationId: request.conversationId,
|
|
583
742
|
workspaceId: request.workspaceId,
|
|
584
|
-
...sleep && sleep.type === "sleep" ? { suspension: { commandId: sleep.id, wakeAt: sleep.wakeAt } } : {}
|
|
743
|
+
...question ? { suspension: { kind: "question", ...question } } : sleep && sleep.type === "sleep" ? { suspension: { commandId: sleep.id, wakeAt: sleep.wakeAt } } : {}
|
|
585
744
|
};
|
|
586
745
|
} finally {
|
|
587
746
|
const failures = [];
|
|
@@ -621,7 +780,7 @@ function compileAgentDefinition(definition, route) {
|
|
|
621
780
|
payload: z.unknown().optional(),
|
|
622
781
|
context: z.record(z.string(), z.unknown()).optional(),
|
|
623
782
|
source: z.object({
|
|
624
|
-
kind: z.enum(["direct", "transmission", "activation", "spawn", "background"]),
|
|
783
|
+
kind: z.enum(["direct", "transmission", "activation", "spawn", "background", "delegation"]),
|
|
625
784
|
id: z.string().optional(),
|
|
626
785
|
provider: z.string().optional(),
|
|
627
786
|
eventId: z.string().optional(),
|
|
@@ -706,7 +865,27 @@ function compileAgentDefinition(definition, route) {
|
|
|
706
865
|
lastRunId: z.string().optional(),
|
|
707
866
|
createdAt: z.string(),
|
|
708
867
|
updatedAt: z.string()
|
|
709
|
-
})).default([])
|
|
868
|
+
})).default([]),
|
|
869
|
+
delegations: z.array(z.object({
|
|
870
|
+
id: z.string(),
|
|
871
|
+
to: z.string(),
|
|
872
|
+
workerAgentId: z.string(),
|
|
873
|
+
workspaceId: z.string(),
|
|
874
|
+
from: z.object({
|
|
875
|
+
definitionId: z.string(),
|
|
876
|
+
agentId: z.string(),
|
|
877
|
+
conversationId: z.string(),
|
|
878
|
+
runId: z.string()
|
|
879
|
+
}),
|
|
880
|
+
task: z.string(),
|
|
881
|
+
status: z.enum(["working", "waiting", "completed", "failed", "cancelled"]),
|
|
882
|
+
question: z.string().optional(),
|
|
883
|
+
result: z.string().optional(),
|
|
884
|
+
error: z.string().optional(),
|
|
885
|
+
createdAt: z.string(),
|
|
886
|
+
updatedAt: z.string()
|
|
887
|
+
})).default([]),
|
|
888
|
+
conversationLease: z.literal(true).optional()
|
|
710
889
|
});
|
|
711
890
|
let builder = signal(internalAgentName(route)).input(executionEnvelope).output(z.object({
|
|
712
891
|
status: z.enum(["completed", "suspended"]),
|
|
@@ -714,7 +893,15 @@ function compileAgentDefinition(definition, route) {
|
|
|
714
893
|
agentId: z.string(),
|
|
715
894
|
conversationId: z.string(),
|
|
716
895
|
workspaceId: z.string(),
|
|
717
|
-
suspension: z.
|
|
896
|
+
suspension: z.union([
|
|
897
|
+
z.object({ kind: z.literal("sleep").optional(), commandId: z.string(), wakeAt: z.string() }),
|
|
898
|
+
z.object({
|
|
899
|
+
kind: z.literal("question"),
|
|
900
|
+
commandId: z.string(),
|
|
901
|
+
delegationId: z.string(),
|
|
902
|
+
question: z.string()
|
|
903
|
+
})
|
|
904
|
+
]).optional()
|
|
718
905
|
}));
|
|
719
906
|
const built = builder.run(
|
|
720
907
|
(value) => runDefinition(definition, route, value)
|