glove-foundry 0.10.1 → 0.12.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-L72FKI7P.js → chunk-DAYYZPVE.js} +620 -57
- package/dist/{chunk-X3HZYVZS.js → chunk-SEP6QFRK.js} +1 -1
- package/dist/{chunk-VLD3DKPI.js → chunk-UGYXSWPE.js} +131 -1
- package/dist/{chunk-CYOIHSUX.js → chunk-WK2O4GIB.js} +6 -0
- package/dist/{chunk-J6NHL4SM.js → chunk-WRGSTYBW.js} +121 -8
- package/dist/cli.js +4 -4
- package/dist/{client-HM2x2-Ut.d.ts → client-Dy6_aqsi.d.ts} +93 -5
- package/dist/client.d.ts +2 -2
- package/dist/{event-delivery-C7rYiNPs.d.ts → event-delivery-CWxarW6L.d.ts} +646 -293
- package/dist/execution-agent.js +1 -1
- package/dist/execution-daemon.js +1 -1
- package/dist/execution-loader.js +132 -14
- package/dist/index.d.ts +9 -5
- package/dist/index.js +50 -5
- package/dist/voice.d.ts +81 -3
- package/dist/voice.js +323 -21
- package/docs/architecture.md +8 -0
- package/docs/building-with-foundry.md +1 -0
- package/package.json +6 -6
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assertEventReceipt,
|
|
3
|
+
matchesReceiptFilter
|
|
4
|
+
} from "./chunk-WRGSTYBW.js";
|
|
1
5
|
import {
|
|
2
6
|
DURABLE_SEGMENT,
|
|
3
7
|
EMPTY_CAPABILITY_REGISTRY,
|
|
@@ -21,7 +25,7 @@ import {
|
|
|
21
25
|
installationKey,
|
|
22
26
|
internalAgentName,
|
|
23
27
|
waitForFoundryCoreCommandResult
|
|
24
|
-
} from "./chunk-
|
|
28
|
+
} from "./chunk-WK2O4GIB.js";
|
|
25
29
|
|
|
26
30
|
// src/application.ts
|
|
27
31
|
var FOUNDRY_APPLICATION_BRAND = /* @__PURE__ */ Symbol.for(
|
|
@@ -943,6 +947,7 @@ var MemoryFoundryDataAdapter = class {
|
|
|
943
947
|
approvals = /* @__PURE__ */ new Map();
|
|
944
948
|
activations = /* @__PURE__ */ new Map();
|
|
945
949
|
occurrences = /* @__PURE__ */ new Map();
|
|
950
|
+
receipts = /* @__PURE__ */ new Map();
|
|
946
951
|
conversations = /* @__PURE__ */ new Map();
|
|
947
952
|
workspace = /* @__PURE__ */ new Map();
|
|
948
953
|
workingEnvironments = /* @__PURE__ */ new Map();
|
|
@@ -1028,6 +1033,7 @@ var MemoryFoundryDataAdapter = class {
|
|
|
1028
1033
|
for (const [id2, item] of this.approvals) if (item.agentId === agentId) this.approvals.delete(id2);
|
|
1029
1034
|
for (const [id2, item] of this.activations) if (item.agentId === agentId) this.activations.delete(id2);
|
|
1030
1035
|
for (const [id2, item] of this.occurrences) if (item.agentId === agentId) this.occurrences.delete(id2);
|
|
1036
|
+
for (const [id2, item] of this.receipts) if (item.agentId === agentId) this.receipts.delete(id2);
|
|
1031
1037
|
for (const id2 of conversationIds) this.conversations.delete(id2);
|
|
1032
1038
|
for (const [id2, item] of this.inbox) if (item.agentId === agentId || conversationIds.has(item.conversationId ?? "")) this.inbox.delete(id2);
|
|
1033
1039
|
for (const [id2, item] of this.tasks) if (item.agentId === agentId || conversationIds.has(item.conversationId ?? "")) this.tasks.delete(id2);
|
|
@@ -1113,6 +1119,29 @@ var MemoryFoundryDataAdapter = class {
|
|
|
1113
1119
|
listEvents() {
|
|
1114
1120
|
return Effect2.sync(() => [...this.events.values()].map((record) => structuredClone(record)));
|
|
1115
1121
|
}
|
|
1122
|
+
claimEventReceipt(receipt) {
|
|
1123
|
+
return Effect2.sync(() => {
|
|
1124
|
+
assertEventReceipt(receipt);
|
|
1125
|
+
if (this.receipts.has(receipt.id)) return false;
|
|
1126
|
+
this.receipts.set(receipt.id, structuredClone(receipt));
|
|
1127
|
+
return true;
|
|
1128
|
+
});
|
|
1129
|
+
}
|
|
1130
|
+
putEventReceipt(receipt) {
|
|
1131
|
+
return Effect2.sync(() => {
|
|
1132
|
+
assertEventReceipt(receipt);
|
|
1133
|
+
this.receipts.set(receipt.id, structuredClone(receipt));
|
|
1134
|
+
});
|
|
1135
|
+
}
|
|
1136
|
+
getEventReceipt(id2) {
|
|
1137
|
+
return Effect2.sync(() => {
|
|
1138
|
+
const receipt = this.receipts.get(id2);
|
|
1139
|
+
return receipt ? structuredClone(receipt) : null;
|
|
1140
|
+
});
|
|
1141
|
+
}
|
|
1142
|
+
listEventReceipts(filter) {
|
|
1143
|
+
return Effect2.sync(() => [...this.receipts.values()].filter((item) => matchesReceiptFilter(item, filter)).map((item) => structuredClone(item)));
|
|
1144
|
+
}
|
|
1116
1145
|
claimScheduleOccurrence(occurrence) {
|
|
1117
1146
|
return Effect2.sync(() => {
|
|
1118
1147
|
assertScheduleOccurrence(occurrence);
|
|
@@ -2085,6 +2114,98 @@ function createFoundryCoreTools(context, desiredSchedules = [], outbound = {}) {
|
|
|
2085
2114
|
];
|
|
2086
2115
|
}
|
|
2087
2116
|
|
|
2117
|
+
// src/builtins.ts
|
|
2118
|
+
var FOUNDRY_BUILTIN_TOOLS = Object.freeze([
|
|
2119
|
+
{ name: "glove_foundry_spawn", group: "spawning", workspaceWide: true },
|
|
2120
|
+
{ name: "glove_foundry_background", group: "spawning", workspaceWide: false },
|
|
2121
|
+
{ name: "glove_foundry_schedule", group: "scheduling", workspaceWide: false },
|
|
2122
|
+
{ name: "glove_foundry_schedules", group: "scheduling", workspaceWide: false },
|
|
2123
|
+
{ name: "glove_foundry_sleep", group: "scheduling", workspaceWide: false },
|
|
2124
|
+
{ name: "glove_foundry_transmit", group: "transmission", workspaceWide: false },
|
|
2125
|
+
{ name: "glove_foundry_conversations", group: "conversations", workspaceWide: true },
|
|
2126
|
+
{ name: "glove_foundry_workspace", group: "workspace", workspaceWide: true },
|
|
2127
|
+
{ name: "glove_foundry_shared_inbox", group: "workspace", workspaceWide: true },
|
|
2128
|
+
{ name: "glove_foundry_tasks", group: "workspace", workspaceWide: true },
|
|
2129
|
+
{ name: "glove_foundry_environment", group: "environment", workspaceWide: false },
|
|
2130
|
+
{ name: "glove_foundry_delegate", group: "delegation", workspaceWide: false },
|
|
2131
|
+
{ name: "glove_foundry_reply", group: "delegation", workspaceWide: false },
|
|
2132
|
+
{ name: "glove_foundry_ask", group: "delegation", workspaceWide: false },
|
|
2133
|
+
{ name: "glove_foundry_message", group: "messaging", workspaceWide: false },
|
|
2134
|
+
{ name: "glove_mesh_list_agents", group: "mesh", workspaceWide: false },
|
|
2135
|
+
{ name: "glove_mesh_send_message", group: "mesh", workspaceWide: false },
|
|
2136
|
+
{ name: "glove_mesh_broadcast", group: "mesh", workspaceWide: false },
|
|
2137
|
+
{ name: "glove_mesh_acknowledge", group: "mesh", workspaceWide: false }
|
|
2138
|
+
].map((tool) => Object.freeze(tool)));
|
|
2139
|
+
var BY_NAME = new Map(FOUNDRY_BUILTIN_TOOLS.map((tool) => [tool.name, tool]));
|
|
2140
|
+
function isFoundryBuiltin(name) {
|
|
2141
|
+
return BY_NAME.has(name);
|
|
2142
|
+
}
|
|
2143
|
+
function matcher(patterns) {
|
|
2144
|
+
const exact = new Set(patterns.filter((pattern) => !pattern.endsWith("*")));
|
|
2145
|
+
const prefixes = patterns.filter((pattern) => pattern.endsWith("*")).map((pattern) => pattern.slice(0, -1));
|
|
2146
|
+
return (name) => exact.has(name) || prefixes.some((prefix) => name.startsWith(prefix));
|
|
2147
|
+
}
|
|
2148
|
+
function builtinAllowed(policy) {
|
|
2149
|
+
if (policy === void 0) return () => true;
|
|
2150
|
+
let decide;
|
|
2151
|
+
const form = policy;
|
|
2152
|
+
if (Array.isArray(policy)) {
|
|
2153
|
+
const allowed = matcher(policy);
|
|
2154
|
+
decide = (tool) => allowed(tool.name);
|
|
2155
|
+
} else if (Array.isArray(form.allow)) {
|
|
2156
|
+
const allowed = matcher(form.allow);
|
|
2157
|
+
decide = (tool) => allowed(tool.name);
|
|
2158
|
+
} else if (Array.isArray(form.block)) {
|
|
2159
|
+
const blocked = matcher(form.block);
|
|
2160
|
+
decide = (tool) => !blocked(tool.name);
|
|
2161
|
+
} else if (typeof form.filter === "function") {
|
|
2162
|
+
decide = form.filter;
|
|
2163
|
+
} else {
|
|
2164
|
+
throw new Error("builtins must be a list of names, { allow }, { block } or { filter }.");
|
|
2165
|
+
}
|
|
2166
|
+
return (name) => {
|
|
2167
|
+
const tool = BY_NAME.get(name);
|
|
2168
|
+
return tool ? Boolean(decide(tool)) : true;
|
|
2169
|
+
};
|
|
2170
|
+
}
|
|
2171
|
+
function builtinsForCommand(type) {
|
|
2172
|
+
switch (type) {
|
|
2173
|
+
case "spawn":
|
|
2174
|
+
return ["glove_foundry_spawn"];
|
|
2175
|
+
case "background":
|
|
2176
|
+
return ["glove_foundry_background"];
|
|
2177
|
+
case "schedule":
|
|
2178
|
+
return ["glove_foundry_schedule"];
|
|
2179
|
+
case "schedule.update":
|
|
2180
|
+
case "schedule.pause":
|
|
2181
|
+
case "schedule.resume":
|
|
2182
|
+
case "schedule.cancel":
|
|
2183
|
+
return ["glove_foundry_schedules"];
|
|
2184
|
+
case "sleep":
|
|
2185
|
+
return ["glove_foundry_sleep"];
|
|
2186
|
+
case "delegate":
|
|
2187
|
+
return ["glove_foundry_delegate"];
|
|
2188
|
+
case "delegate.reply":
|
|
2189
|
+
return ["glove_foundry_reply"];
|
|
2190
|
+
case "delegate.ask":
|
|
2191
|
+
return ["glove_foundry_ask"];
|
|
2192
|
+
case "agent.message":
|
|
2193
|
+
return ["glove_foundry_message"];
|
|
2194
|
+
case "mesh.list":
|
|
2195
|
+
return ["glove_mesh_list_agents", "glove_mesh_broadcast"];
|
|
2196
|
+
case "mesh.send":
|
|
2197
|
+
return ["glove_mesh_send_message", "glove_mesh_broadcast"];
|
|
2198
|
+
case "mesh.ack":
|
|
2199
|
+
return ["glove_mesh_acknowledge"];
|
|
2200
|
+
// Installed apps' own transmission tools send it too; see the runtime.
|
|
2201
|
+
case "transmit":
|
|
2202
|
+
return ["glove_foundry_transmit"];
|
|
2203
|
+
default:
|
|
2204
|
+
return null;
|
|
2205
|
+
}
|
|
2206
|
+
}
|
|
2207
|
+
var FOUNDRY_BUILTINS_MOUNTED_EVENT = "foundry.builtins.mounted";
|
|
2208
|
+
|
|
2088
2209
|
// src/approval.ts
|
|
2089
2210
|
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
2090
2211
|
import { mkdir, readFile, readdir as readdir2, writeFile } from "node:fs/promises";
|
|
@@ -2112,6 +2233,9 @@ function readApprovalPolicy(value) {
|
|
|
2112
2233
|
}
|
|
2113
2234
|
}
|
|
2114
2235
|
var APPROVAL_ID = /^approval_[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
2236
|
+
function isFoundryApprovalId(value) {
|
|
2237
|
+
return APPROVAL_ID.test(value);
|
|
2238
|
+
}
|
|
2115
2239
|
function approvalPath(directory, id2, suffix) {
|
|
2116
2240
|
if (!APPROVAL_ID.test(id2)) throw new Error("Invalid Foundry approval id.");
|
|
2117
2241
|
return join(directory, `${id2}${suffix}`);
|
|
@@ -2620,11 +2744,17 @@ export {
|
|
|
2620
2744
|
installedApplicationTransmissionToolName,
|
|
2621
2745
|
createInstalledApplicationTransmissionTools,
|
|
2622
2746
|
createFoundryCoreTools,
|
|
2747
|
+
FOUNDRY_BUILTIN_TOOLS,
|
|
2748
|
+
isFoundryBuiltin,
|
|
2749
|
+
builtinAllowed,
|
|
2750
|
+
builtinsForCommand,
|
|
2751
|
+
FOUNDRY_BUILTINS_MOUNTED_EVENT,
|
|
2623
2752
|
FOUNDRY_APPROVAL_DIRECTORY_ENV,
|
|
2624
2753
|
FOUNDRY_APPROVAL_POLICY_ENV,
|
|
2625
2754
|
DEFAULT_APPROVAL_WAIT_MS,
|
|
2626
2755
|
DEFAULT_APPROVAL_EXPIRES_AFTER_MS,
|
|
2627
2756
|
readApprovalPolicy,
|
|
2757
|
+
isFoundryApprovalId,
|
|
2628
2758
|
createFoundryApproval,
|
|
2629
2759
|
listFoundryApprovals,
|
|
2630
2760
|
resolveFoundryApproval,
|
|
@@ -226,6 +226,9 @@ function eventRecordId(target, eventId) {
|
|
|
226
226
|
function eventDue(record, now = Date.now()) {
|
|
227
227
|
return record.policy.whenIdle !== "defer" || record.policy.deferTimeoutMs !== void 0 && now >= Date.parse(record.createdAt) + record.policy.deferTimeoutMs;
|
|
228
228
|
}
|
|
229
|
+
function isGenericDelivery(delivery) {
|
|
230
|
+
return delivery.kind === "agent-message" || delivery.kind === "transmission";
|
|
231
|
+
}
|
|
229
232
|
|
|
230
233
|
// src/core-command-result.ts
|
|
231
234
|
import { mkdir, readFile, unlink, writeFile } from "node:fs/promises";
|
|
@@ -1151,6 +1154,8 @@ var CONVENTION_EXPORTS = [
|
|
|
1151
1154
|
"delegates",
|
|
1152
1155
|
"durableSubagents",
|
|
1153
1156
|
"eventDelivery",
|
|
1157
|
+
"prepareEvent",
|
|
1158
|
+
"builtins",
|
|
1154
1159
|
"answerWaitMs",
|
|
1155
1160
|
"memory",
|
|
1156
1161
|
"goals",
|
|
@@ -1295,6 +1300,7 @@ export {
|
|
|
1295
1300
|
foundryEventSchema,
|
|
1296
1301
|
eventRecordId,
|
|
1297
1302
|
eventDue,
|
|
1303
|
+
isGenericDelivery,
|
|
1298
1304
|
FOUNDRY_CORE_COMMAND_DIRECTORY_ENV,
|
|
1299
1305
|
createFoundryCoreCommandRequest,
|
|
1300
1306
|
getFoundryCoreCommandRequest,
|
|
@@ -33,6 +33,9 @@ function startedThreadIds(context) {
|
|
|
33
33
|
function isOpenThread(thread) {
|
|
34
34
|
return thread.status === "working" || thread.status === "waiting";
|
|
35
35
|
}
|
|
36
|
+
function isTakenOverBy(thread, agentId) {
|
|
37
|
+
return Boolean(thread.takenOver?.agentIds.includes(agentId));
|
|
38
|
+
}
|
|
36
39
|
function clip(text, max) {
|
|
37
40
|
const flat = text.replace(/\s+/g, " ").trim();
|
|
38
41
|
return flat.length > max ? `${flat.slice(0, max - 1)}\u2026` : flat;
|
|
@@ -43,13 +46,16 @@ function threadSubject(content) {
|
|
|
43
46
|
function escapeAttribute(value) {
|
|
44
47
|
return value.replaceAll("&", "&").replaceAll('"', """).replaceAll("<", "<");
|
|
45
48
|
}
|
|
46
|
-
function renderMeshMessage(message, side) {
|
|
49
|
+
function renderMeshMessage(message, side, peer) {
|
|
47
50
|
const who = `${message.from.name} (${message.from.agentId})`;
|
|
48
51
|
const status = message.kind === "message" ? "" : ` status="${message.kind === "reply" ? "replied" : message.kind}"`;
|
|
49
|
-
const
|
|
52
|
+
const human = message.from.kind === "human";
|
|
53
|
+
const open = `<mesh-message id="${escapeAttribute(message.id)}" thread="${escapeAttribute(message.threadId)}" from="${escapeAttribute(message.from.agentId)}" name="${escapeAttribute(message.from.name)}"${human ? ' party="human"' : ""}${status}>`;
|
|
50
54
|
const body = message.kind === "failed" ? `It stopped: ${message.content}` : message.content;
|
|
51
55
|
const lines = [open, body, "</mesh-message>"];
|
|
52
|
-
if (
|
|
56
|
+
if (human) {
|
|
57
|
+
lines.push(side === "recipient" ? `${message.from.name} is a person in this thread, not an agent. Your final reply goes to the thread on its own.` : `${message.from.name} is a person in your thread${peer ? ` with ${peer}` : ""}. To answer in the thread, use glove_mesh_send_message${peer ? ` to "${peer}"` : ""} with in_reply_to "${message.id}".`);
|
|
58
|
+
} else if (side === "recipient") {
|
|
53
59
|
lines.push(
|
|
54
60
|
`${who} is another agent, not the user. Your final reply goes back to them on its own, so make it the answer itself.`,
|
|
55
61
|
`If you cannot go on without something only they or their user know, ask with glove_mesh_send_message to "${message.from.agentId}".`
|
|
@@ -212,6 +218,11 @@ function createMeshTools(context) {
|
|
|
212
218
|
}
|
|
213
219
|
];
|
|
214
220
|
}
|
|
221
|
+
var DEFAULT_MESH_REFUSAL = "Your message could not be sent.";
|
|
222
|
+
var RECORD_ID = /^[A-Za-z0-9][A-Za-z0-9_.:-]{0,199}$/;
|
|
223
|
+
function isBindableThreadId(value) {
|
|
224
|
+
return RECORD_ID.test(value) && !value.includes("..");
|
|
225
|
+
}
|
|
215
226
|
|
|
216
227
|
// src/delegation.ts
|
|
217
228
|
import { createHash, randomUUID as randomUUID2 } from "node:crypto";
|
|
@@ -289,7 +300,7 @@ function renderDelegatedTask(input) {
|
|
|
289
300
|
}
|
|
290
301
|
function renderDelivery(delivery) {
|
|
291
302
|
if (delivery.kind === "transmission" || delivery.kind === "agent-message") return delivery.message;
|
|
292
|
-
if (delivery.kind === "mesh") return renderMeshMessage(delivery.message, delivery.side);
|
|
303
|
+
if (delivery.kind === "mesh") return renderMeshMessage(delivery.message, delivery.side, delivery.peer);
|
|
293
304
|
if (delivery.kind === "reply") {
|
|
294
305
|
return [
|
|
295
306
|
`<delegation-reply id="${escapeAttribute2(delivery.delegationId)}" from="${escapeAttribute2(delivery.from)}">`,
|
|
@@ -576,6 +587,7 @@ function openRunMailbox(options) {
|
|
|
576
587
|
const meshWaiters = /* @__PURE__ */ new Map();
|
|
577
588
|
const handlers = /* @__PURE__ */ new Set();
|
|
578
589
|
const meshHandlers = /* @__PURE__ */ new Set();
|
|
590
|
+
const eventRoutes = /* @__PURE__ */ new Set();
|
|
579
591
|
let closed = false;
|
|
580
592
|
const toHandlers = async (updates) => {
|
|
581
593
|
for (const handler of [...handlers]) await handler(updates);
|
|
@@ -590,6 +602,7 @@ function openRunMailbox(options) {
|
|
|
590
602
|
const meshAnswers = /* @__PURE__ */ new Map();
|
|
591
603
|
const heardMesh = [];
|
|
592
604
|
const updates = [];
|
|
605
|
+
const routed = [];
|
|
593
606
|
const rest = [];
|
|
594
607
|
for (const delivery of deliveries) {
|
|
595
608
|
if (delivery.durable?.event.expiresAt && Date.parse(delivery.durable.event.expiresAt) <= Date.now()) {
|
|
@@ -609,7 +622,9 @@ function openRunMailbox(options) {
|
|
|
609
622
|
} else if (isDelegationUpdate(delivery) && handlers.size > 0) {
|
|
610
623
|
updates.push(delivery);
|
|
611
624
|
} else {
|
|
612
|
-
|
|
625
|
+
const route = [...eventRoutes].find((candidate) => candidate.match(delivery));
|
|
626
|
+
if (route) routed.push({ route, delivery });
|
|
627
|
+
else rest.push(delivery);
|
|
613
628
|
}
|
|
614
629
|
}
|
|
615
630
|
for (const [delegationId, batch] of replies) {
|
|
@@ -622,6 +637,7 @@ function openRunMailbox(options) {
|
|
|
622
637
|
if (updates.length > 0) await toHandlers(updates);
|
|
623
638
|
if (heardMesh.length > 0) for (const handler of [...meshHandlers]) await handler(heardMesh.map((item) => item.message));
|
|
624
639
|
options.consumed?.([...[...replies.values()].flat(), ...[...meshAnswers.values()].flat(), ...updates, ...heardMesh]);
|
|
640
|
+
for (const { route, delivery } of routed) await route.take(delivery);
|
|
625
641
|
if (rest.length > 0) await options.sink.forward(rest);
|
|
626
642
|
}
|
|
627
643
|
});
|
|
@@ -687,13 +703,25 @@ function openRunMailbox(options) {
|
|
|
687
703
|
await waiting;
|
|
688
704
|
};
|
|
689
705
|
},
|
|
706
|
+
onEvents(match, take) {
|
|
707
|
+
const route = { match, take };
|
|
708
|
+
eventRoutes.add(route);
|
|
709
|
+
const waiting = options.sink.reclaim(match).then(async (taken) => {
|
|
710
|
+
for (const delivery of taken) await take(delivery);
|
|
711
|
+
});
|
|
712
|
+
return async () => {
|
|
713
|
+
eventRoutes.delete(route);
|
|
714
|
+
await waiting;
|
|
715
|
+
};
|
|
716
|
+
},
|
|
690
717
|
async close() {
|
|
691
718
|
if (closed) return;
|
|
692
719
|
closed = true;
|
|
693
720
|
for (const finish of [...waiters.values()]) finish(null);
|
|
694
721
|
for (const finish of [...meshWaiters.values()]) finish(null);
|
|
695
722
|
await listener.stop(async () => {
|
|
696
|
-
|
|
723
|
+
const unused = options.sink.release ? await options.sink.release() : await options.sink.reclaim(() => true);
|
|
724
|
+
for (const delivery of unused) {
|
|
697
725
|
await writeMailboxDelivery(options.directory, options.conversationId, delivery);
|
|
698
726
|
}
|
|
699
727
|
});
|
|
@@ -736,6 +764,9 @@ function deliveryOf(event) {
|
|
|
736
764
|
}
|
|
737
765
|
var formatRunEvents = defaultEventFormatter;
|
|
738
766
|
var RunEventQueue = class {
|
|
767
|
+
constructor(preparation) {
|
|
768
|
+
this.preparation = preparation;
|
|
769
|
+
}
|
|
739
770
|
events = [];
|
|
740
771
|
async push(event) {
|
|
741
772
|
if (this.events.some((queued) => queued.id === event.id)) return false;
|
|
@@ -748,7 +779,26 @@ var RunEventQueue = class {
|
|
|
748
779
|
async take() {
|
|
749
780
|
const taken = this.events;
|
|
750
781
|
this.events = [];
|
|
751
|
-
return taken;
|
|
782
|
+
if (!this.preparation) return taken;
|
|
783
|
+
const ready = [];
|
|
784
|
+
const kept = [];
|
|
785
|
+
for (const event of taken) {
|
|
786
|
+
const delivery = deliveryOf(event);
|
|
787
|
+
if (!delivery || !this.preparation.applies(delivery)) {
|
|
788
|
+
ready.push(event);
|
|
789
|
+
continue;
|
|
790
|
+
}
|
|
791
|
+
try {
|
|
792
|
+
const prepared = await this.preparation.prepare(event, delivery);
|
|
793
|
+
if ("suppress" in prepared) this.preparation.suppressed(delivery, prepared.suppress);
|
|
794
|
+
else ready.push({ ...event, content: prepared.say });
|
|
795
|
+
} catch (cause) {
|
|
796
|
+
kept.push(event);
|
|
797
|
+
this.preparation.failed(event, cause);
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
this.events = [...kept, ...this.events];
|
|
801
|
+
return ready;
|
|
752
802
|
}
|
|
753
803
|
async remove(ids) {
|
|
754
804
|
const drop = new Set(ids);
|
|
@@ -787,6 +837,60 @@ async function waitForConversationLease(directory, runId, signal, pollMs = 25) {
|
|
|
787
837
|
}
|
|
788
838
|
}
|
|
789
839
|
|
|
840
|
+
// src/event-receipts.ts
|
|
841
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
842
|
+
import { Effect } from "effect";
|
|
843
|
+
function matchesReceiptFilter(receipt, filter = {}) {
|
|
844
|
+
if (filter.agentId && receipt.agentId !== filter.agentId) return false;
|
|
845
|
+
if (filter.conversationId && receipt.conversationId !== filter.conversationId) return false;
|
|
846
|
+
if (filter.status) {
|
|
847
|
+
const statuses = typeof filter.status === "string" ? [filter.status] : filter.status;
|
|
848
|
+
if (!statuses.includes(receipt.status)) return false;
|
|
849
|
+
}
|
|
850
|
+
return true;
|
|
851
|
+
}
|
|
852
|
+
function assertEventReceipt(receipt) {
|
|
853
|
+
if (!receipt.id || !receipt.eventId) throw new Error("Event receipt must name its event.");
|
|
854
|
+
if (!receipt.agentId || !receipt.conversationId) throw new Error("Event receipt must name its conversation.");
|
|
855
|
+
}
|
|
856
|
+
function lateChatEffectId(receiptId) {
|
|
857
|
+
return `effect_${createHash2("sha256").update(`late-chat\0${receiptId}`).digest("hex")}`;
|
|
858
|
+
}
|
|
859
|
+
function eventTranscriptMessageId(receiptId) {
|
|
860
|
+
return `foundry-event:${receiptId}`;
|
|
861
|
+
}
|
|
862
|
+
var processReceipts = /* @__PURE__ */ new WeakMap();
|
|
863
|
+
function eventReceiptStore(data) {
|
|
864
|
+
if (data.claimEventReceipt && data.putEventReceipt && data.getEventReceipt) {
|
|
865
|
+
return {
|
|
866
|
+
durable: true,
|
|
867
|
+
get: (id) => Effect.runPromise(data.getEventReceipt(id)),
|
|
868
|
+
claim: (receipt) => Effect.runPromise(data.claimEventReceipt(receipt)),
|
|
869
|
+
put: (receipt) => Effect.runPromise(data.putEventReceipt(receipt))
|
|
870
|
+
};
|
|
871
|
+
}
|
|
872
|
+
let local = processReceipts.get(data);
|
|
873
|
+
if (!local) processReceipts.set(data, local = /* @__PURE__ */ new Map());
|
|
874
|
+
const memory = local;
|
|
875
|
+
return {
|
|
876
|
+
durable: false,
|
|
877
|
+
async get(id) {
|
|
878
|
+
const receipt = memory.get(id);
|
|
879
|
+
return receipt ? structuredClone(receipt) : null;
|
|
880
|
+
},
|
|
881
|
+
async claim(receipt) {
|
|
882
|
+
assertEventReceipt(receipt);
|
|
883
|
+
if (memory.has(receipt.id)) return false;
|
|
884
|
+
memory.set(receipt.id, structuredClone(receipt));
|
|
885
|
+
return true;
|
|
886
|
+
},
|
|
887
|
+
async put(receipt) {
|
|
888
|
+
assertEventReceipt(receipt);
|
|
889
|
+
memory.set(receipt.id, structuredClone(receipt));
|
|
890
|
+
}
|
|
891
|
+
};
|
|
892
|
+
}
|
|
893
|
+
|
|
790
894
|
export {
|
|
791
895
|
meshIdentity,
|
|
792
896
|
isThreadId,
|
|
@@ -794,12 +898,15 @@ export {
|
|
|
794
898
|
threadFromContext,
|
|
795
899
|
startedThreadIds,
|
|
796
900
|
isOpenThread,
|
|
901
|
+
isTakenOverBy,
|
|
797
902
|
threadSubject,
|
|
798
903
|
renderMeshMessages,
|
|
799
904
|
renderOpenThreads,
|
|
800
905
|
renderOwnThread,
|
|
801
906
|
isMeshCommand,
|
|
802
907
|
createMeshTools,
|
|
908
|
+
DEFAULT_MESH_REFUSAL,
|
|
909
|
+
isBindableThreadId,
|
|
803
910
|
FOUNDRY_MAILBOX_DIRECTORY_ENV,
|
|
804
911
|
FOUNDRY_CONVERSATION_LISTEN_EVENT,
|
|
805
912
|
FOUNDRY_CONVERSATION_LEASE_EVENT,
|
|
@@ -819,8 +926,14 @@ export {
|
|
|
819
926
|
drainMailbox,
|
|
820
927
|
openRunMailbox,
|
|
821
928
|
deliveryEvent,
|
|
929
|
+
deliveryOf,
|
|
822
930
|
formatRunEvents,
|
|
823
931
|
RunEventQueue,
|
|
824
932
|
writeConversationLease,
|
|
825
|
-
waitForConversationLease
|
|
933
|
+
waitForConversationLease,
|
|
934
|
+
matchesReceiptFilter,
|
|
935
|
+
assertEventReceipt,
|
|
936
|
+
lateChatEffectId,
|
|
937
|
+
eventTranscriptMessageId,
|
|
938
|
+
eventReceiptStore
|
|
826
939
|
};
|
package/dist/cli.js
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
FoundryRuntime,
|
|
4
4
|
FoundryServer,
|
|
5
5
|
writeGeneratedTypes
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-DAYYZPVE.js";
|
|
7
7
|
import {
|
|
8
8
|
DEFAULT_FOUNDRY_CONFIG
|
|
9
9
|
} from "./chunk-ZFNMFE3T.js";
|
|
@@ -11,9 +11,9 @@ import "./chunk-J7ZBJM54.js";
|
|
|
11
11
|
import {
|
|
12
12
|
EMPTY_FOUNDRY_APPLICATION,
|
|
13
13
|
isFoundryApplication
|
|
14
|
-
} from "./chunk-
|
|
15
|
-
import "./chunk-
|
|
16
|
-
import "./chunk-
|
|
14
|
+
} from "./chunk-UGYXSWPE.js";
|
|
15
|
+
import "./chunk-WRGSTYBW.js";
|
|
16
|
+
import "./chunk-WK2O4GIB.js";
|
|
17
17
|
|
|
18
18
|
// src/cli.ts
|
|
19
19
|
import { watch } from "node:fs";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { StoreAdapter, AgentEvent, Message, TokenConsumptionCounter } from 'glove-core';
|
|
2
|
-
import {
|
|
2
|
+
import { B as AccountId, r as AccountReference, D as AccountNotFound, dm as TransmissionId, de as RouteId, dd as Route, df as RouteNotFound, dj as TopologyConflict, a6 as BindingId, t as AgentBinding, a7 as BindingNotFound, U as AgentId, aC as EventReference, az as EventId, aA as EventNotFound, dh as RunId, G as AccountSessionUnavailable, d as FoundryDataAdapter, bO as FoundryInstanceProvisioner, m as FoundryApproval, bc as FoundryApplicationMesh, b5 as FoundryAgentDefinition, dg as RunGrant, cS as GrantResolutionError, q as AnyFoundryTransmission, bq as FoundryCapabilityRegistry, ci as FoundryNativeRegistry, cq as FoundryRequest, ac as CreateAgentInstanceOptions, e as AgentInstance, ce as FoundryMessageOptions, Z as AgentMessageReceipt, bD as FoundryEventTarget, bA as FoundryEventPolicy, C as Conversation, h as FoundryEventRecord, f as FoundryActivationRecord, l as FoundryPendingInbound, o as FoundryTask, S as SharedInboxItem, ad as CreateConversationOptions, p as AgentPlaybook, P as PlaybookSubscription, ap as DefinePlaybookSubscriptionOptions, a4 as ApplicationConnectionState, dr as UpdateAgentInstanceOptions, ds as UpdateConversationOptions, W as WorkspaceEntry, E as EnvironmentValue, cd as FoundryMessageInput, ct as FoundryResult, bg as FoundryApprovalStatus, bd as FoundryApprovalDecision, bo as FoundryCapabilityManifest, cg as FoundryNativeManifest, X as AgentInstallation, by as FoundryDelegationStatus, bw as FoundryDelegation, cc as FoundryMeshThreadStatus, ca as FoundryMeshThread, c as FoundryMeshMessage, k as FoundryScheduleOccurrenceFilter, j as FoundryScheduleOccurrence, cu as FoundryRouteMap, H as AccountSummary, a1 as AnyFoundryAgent } from './event-delivery-CWxarW6L.js';
|
|
3
3
|
import * as effect_Brand from 'effect/Brand';
|
|
4
4
|
import { Context, Effect, Layer, Schema } from 'effect';
|
|
5
5
|
import { FoundryStationDaemonAdapter } from './station.js';
|
|
@@ -133,6 +133,12 @@ interface FoundryApplicationOptions {
|
|
|
133
133
|
*/
|
|
134
134
|
readonly url?: (approval: FoundryApproval) => string | undefined;
|
|
135
135
|
};
|
|
136
|
+
/**
|
|
137
|
+
* The hosted mesh under your rules: peers across workspaces, a gate on
|
|
138
|
+
* every message, and threads bound and committed to your own record.
|
|
139
|
+
* Omitted, agents on the mesh see their own workspace, ungated.
|
|
140
|
+
*/
|
|
141
|
+
readonly mesh?: FoundryApplicationMesh;
|
|
136
142
|
readonly services?: Layer.Layer<AccountDirectory | TopologyStore | EventStore, unknown>;
|
|
137
143
|
}
|
|
138
144
|
type FoundryApplication = Readonly<FoundryApplicationOptions> & {
|
|
@@ -456,10 +462,14 @@ declare class FoundryRuntime {
|
|
|
456
462
|
private readonly gate;
|
|
457
463
|
/** Pending inbound records each run is handling, so they are cleared when it settles. */
|
|
458
464
|
private readonly eventTimers;
|
|
465
|
+
/** Events a run withheld because preparing them failed: attempts so far and the pending retry. */
|
|
466
|
+
private readonly eventRetries;
|
|
459
467
|
private readonly completedEventRuns;
|
|
460
468
|
private readonly pendingInboundByRun;
|
|
461
469
|
/** Recently settled runs, for a record assigned to a run that already finished. */
|
|
462
470
|
private readonly settledRuns;
|
|
471
|
+
/** The built-ins each restricted run mounted, as it reported them. Runs without a policy are absent. */
|
|
472
|
+
private readonly runBuiltins;
|
|
463
473
|
/** How runs treat approvals; durable when the data adapter can keep them. */
|
|
464
474
|
private readonly approvalPolicy;
|
|
465
475
|
/** Approval records change one at a time. */
|
|
@@ -727,6 +737,13 @@ declare class FoundryRuntime {
|
|
|
727
737
|
/** Start one run with everything held for a conversation, once nothing else holds it. */
|
|
728
738
|
private flushHeldDeliveries;
|
|
729
739
|
private markHandedOver;
|
|
740
|
+
/**
|
|
741
|
+
* Deliver events again after a delay that doubles each time (1s up to 5
|
|
742
|
+
* minutes), when a run withheld them because preparing them failed. They
|
|
743
|
+
* stay pending meanwhile; a restart delivers them as usual.
|
|
744
|
+
*/
|
|
745
|
+
private scheduleEventRetries;
|
|
746
|
+
private retryEvent;
|
|
730
747
|
private finishEvents;
|
|
731
748
|
private redeliverEvents;
|
|
732
749
|
/** Clear the bookkeeping that lets a restart hand these deliveries over again. */
|
|
@@ -765,9 +782,11 @@ declare class FoundryRuntime {
|
|
|
765
782
|
readonly status?: FoundryMeshThreadStatus;
|
|
766
783
|
}): Promise<ReadonlyArray<FoundryMeshThread>>;
|
|
767
784
|
/**
|
|
768
|
-
*
|
|
769
|
-
*
|
|
770
|
-
*
|
|
785
|
+
* At start: older thread records kept their own lists of messages not
|
|
786
|
+
* handed over yet; move them to the event journal once. Then finish what a
|
|
787
|
+
* stop cut short: messages committed (or being committed) to the
|
|
788
|
+
* application's record and not handed over, and drafts decided but not
|
|
789
|
+
* delivered or dropped. Message ids keep a retry from delivering twice.
|
|
771
790
|
*/
|
|
772
791
|
private redeliverThreads;
|
|
773
792
|
/** The open threads a conversation started, oldest first. */
|
|
@@ -776,19 +795,88 @@ declare class FoundryRuntime {
|
|
|
776
795
|
private updateThread;
|
|
777
796
|
private starterTarget;
|
|
778
797
|
private recipientTarget;
|
|
798
|
+
private sideTarget;
|
|
779
799
|
/**
|
|
780
800
|
* Hand mesh messages to one side of a thread. Messages, replies and
|
|
781
801
|
* failures go through durable delivery. A read receipt only ever reaches a
|
|
782
802
|
* run that is listening, and is dropped otherwise.
|
|
783
803
|
*/
|
|
784
804
|
private deliverMesh;
|
|
805
|
+
/**
|
|
806
|
+
* Send messages to one side of a thread. Under the application's mesh they
|
|
807
|
+
* go through the thread's outbox: committed to the application's record
|
|
808
|
+
* first, then handed over, so the record and the journal agree. A side
|
|
809
|
+
* that was taken over gets nothing; the record still does.
|
|
810
|
+
*/
|
|
811
|
+
private sendToSide;
|
|
812
|
+
/** Commit each outbox message to the application's record, then deliver it. */
|
|
813
|
+
private flushOutbox;
|
|
814
|
+
private retryOutbox;
|
|
815
|
+
private reportMeshFailure;
|
|
816
|
+
private meshHookContext;
|
|
817
|
+
private meshRefusal;
|
|
818
|
+
/** The application's gate. Without one, everything is delivered. */
|
|
819
|
+
private gateMesh;
|
|
820
|
+
/**
|
|
821
|
+
* Act on the gate's decision for one message to one side. Held and drafted
|
|
822
|
+
* messages are stored on the thread, not delivered; `onDeliver` is what
|
|
823
|
+
* delivery changes on the thread, applied only when it happens, because
|
|
824
|
+
* the side waiting for it must not see a message it has not been given.
|
|
825
|
+
*/
|
|
826
|
+
private dispatchMesh;
|
|
827
|
+
/** A drafted message waits on an approval nobody resumes a run for. */
|
|
828
|
+
private draftApproval;
|
|
829
|
+
/** A drafted message's approval was decided: deliver it, or drop it. */
|
|
830
|
+
private settleMeshDraft;
|
|
831
|
+
/**
|
|
832
|
+
* Release a message the application's gate held: deliver it (committed to
|
|
833
|
+
* your record first) or discard it. The sender is not told either way.
|
|
834
|
+
* Drafts are decided through their approval instead.
|
|
835
|
+
*/
|
|
836
|
+
releaseMeshMessage(threadId: string, messageId: string, decision: "deliver" | "discard"): Promise<FoundryMeshThread>;
|
|
837
|
+
private releaseHeld;
|
|
838
|
+
/**
|
|
839
|
+
* A person's message in a thread, entered by the application from its own
|
|
840
|
+
* record (so it is not committed again). It reaches each agent still in
|
|
841
|
+
* the thread as a message from a person, and starts the recipient working
|
|
842
|
+
* again. Pass `id` (your record's message id) to make a retry a no-op.
|
|
843
|
+
*/
|
|
844
|
+
meshHumanMessage(threadId: string, input: {
|
|
845
|
+
readonly authorId: string;
|
|
846
|
+
readonly name?: string;
|
|
847
|
+
readonly text: string;
|
|
848
|
+
readonly id?: string;
|
|
849
|
+
}): Promise<FoundryMeshMessage>;
|
|
850
|
+
/**
|
|
851
|
+
* A person takes a thread over. The agents named (default: both) leave it:
|
|
852
|
+
* nothing more is delivered to them in this thread, what they send to it
|
|
853
|
+
* is refused, and a recipient run working on it is cancelled without a
|
|
854
|
+
* reply. Messages to a side that left still reach your record.
|
|
855
|
+
*/
|
|
856
|
+
meshTakeOver(threadId: string, options: {
|
|
857
|
+
readonly by: string;
|
|
858
|
+
readonly agentId?: string;
|
|
859
|
+
}): Promise<FoundryMeshThread>;
|
|
785
860
|
/** A run's mesh call: answered through its request, so the tool hears the outcome. */
|
|
786
861
|
private runMeshCommand;
|
|
787
|
-
/**
|
|
862
|
+
/**
|
|
863
|
+
* The agents an agent may see and message: its workspace, or whoever the
|
|
864
|
+
* application's `mesh.peers` names; then narrowed by its definition's rule.
|
|
865
|
+
*/
|
|
788
866
|
private meshPeers;
|
|
789
867
|
private executeMeshCommand;
|
|
868
|
+
/** Remember on the starter's conversation that it started a thread. */
|
|
869
|
+
private noteStartedThread;
|
|
790
870
|
/** When the recipient's run on a thread ends, its reply (or its failure) goes back. */
|
|
791
871
|
private settleThread;
|
|
872
|
+
/** The gate for a recipient's final answer, when the application has one. */
|
|
873
|
+
private gateReply;
|
|
874
|
+
/**
|
|
875
|
+
* A run whose definition restricts built-ins may only send the commands its
|
|
876
|
+
* mounted tools send. Anything else is refused, however it was emitted.
|
|
877
|
+
*/
|
|
878
|
+
private withheldBuiltinRefusal;
|
|
879
|
+
private refuseCoreCommand;
|
|
792
880
|
private handleRunSettled;
|
|
793
881
|
private enqueueCoreRequest;
|
|
794
882
|
/**
|
package/dist/client.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import 'glove-core';
|
|
2
|
-
import './event-delivery-
|
|
3
|
-
export { k as FoundryClient, l as FoundryClientAuthorizationAdapter, m as FoundryClientOptions, q as FoundryHealth, y as FoundryRunHandle, G as FoundrySteerHandleResult, W as WaitOptions, N as createFoundryClient } from './client-
|
|
2
|
+
import './event-delivery-CWxarW6L.js';
|
|
3
|
+
export { k as FoundryClient, l as FoundryClientAuthorizationAdapter, m as FoundryClientOptions, q as FoundryHealth, y as FoundryRunHandle, G as FoundrySteerHandleResult, W as WaitOptions, N as createFoundryClient } from './client-Dy6_aqsi.js';
|
|
4
4
|
import 'effect';
|
|
5
5
|
import 'zod';
|
|
6
6
|
import 'glove-mesh';
|