glove-foundry 0.7.0 → 0.8.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 +80 -4
- package/dist/{chunk-64UBLGYM.js → chunk-CYOIHSUX.js} +131 -7
- package/dist/{chunk-2GXPSIRL.js → chunk-DTFCEX67.js} +1384 -104
- package/dist/{chunk-EJZJAVNG.js → chunk-EUGKVW3J.js} +335 -7
- package/dist/{chunk-AC6SRI5V.js → chunk-J6NHL4SM.js} +357 -56
- package/dist/{chunk-EEHGAWXM.js → chunk-L5JQVTHD.js} +4 -0
- package/dist/{chunk-IPASF7PK.js → chunk-X3HZYVZS.js} +36 -1
- package/dist/cli.js +4 -4
- package/dist/{client-BgpgsnoO.d.ts → client-CekanYLW.d.ts} +96 -56
- package/dist/client.d.ts +2 -2
- package/dist/client.js +1 -1
- package/dist/config.d.ts +7 -0
- package/dist/{event-delivery-BaYe6d9w.d.ts → event-delivery-CNCsVqi8.d.ts} +379 -11
- package/dist/execution-agent.js +1 -1
- package/dist/execution-daemon.js +10 -5
- package/dist/execution-loader.js +174 -17
- package/dist/index.d.ts +17 -6
- package/dist/index.js +114 -15
- package/dist/voice.d.ts +11 -7
- package/dist/voice.js +51 -10
- package/docs/README.md +1 -1
- package/docs/building-with-foundry.md +128 -4
- package/docs/durable-subagents.md +101 -23
- package/docs/execution.md +4 -0
- package/docs/inspector.md +137 -29
- package/package.json +12 -11
- package/templates/travel-concierge/README.md +1 -1
package/dist/index.js
CHANGED
|
@@ -43,12 +43,12 @@ import {
|
|
|
43
43
|
memoryTopologyStore,
|
|
44
44
|
serializeInboundTransmissionXml,
|
|
45
45
|
writeGeneratedTypes
|
|
46
|
-
} from "./chunk-
|
|
46
|
+
} from "./chunk-DTFCEX67.js";
|
|
47
47
|
import {
|
|
48
48
|
FoundryClient,
|
|
49
49
|
FoundryRunHandle,
|
|
50
50
|
createFoundryClient
|
|
51
|
-
} from "./chunk-
|
|
51
|
+
} from "./chunk-L5JQVTHD.js";
|
|
52
52
|
import {
|
|
53
53
|
defineConfig
|
|
54
54
|
} from "./chunk-ZFNMFE3T.js";
|
|
@@ -63,8 +63,10 @@ import {
|
|
|
63
63
|
defineWorkingEnvironment,
|
|
64
64
|
foundryDataEnvironmentPersistence,
|
|
65
65
|
foundryGuidanceSubject
|
|
66
|
-
} from "./chunk-
|
|
66
|
+
} from "./chunk-X3HZYVZS.js";
|
|
67
67
|
import {
|
|
68
|
+
DEFAULT_APPROVAL_EXPIRES_AFTER_MS,
|
|
69
|
+
DEFAULT_APPROVAL_WAIT_MS,
|
|
68
70
|
EMPTY_AGENT_COMPOSITION,
|
|
69
71
|
EMPTY_FOUNDRY_APPLICATION,
|
|
70
72
|
FOUNDRY_APPLICATION_BRAND,
|
|
@@ -112,8 +114,10 @@ import {
|
|
|
112
114
|
toGloveRequestInput,
|
|
113
115
|
transmissionPredicate,
|
|
114
116
|
withFoundryPermissions
|
|
115
|
-
} from "./chunk-
|
|
116
|
-
import
|
|
117
|
+
} from "./chunk-EUGKVW3J.js";
|
|
118
|
+
import {
|
|
119
|
+
meshIdentity
|
|
120
|
+
} from "./chunk-J6NHL4SM.js";
|
|
117
121
|
import {
|
|
118
122
|
EMPTY_CAPABILITY_REGISTRY,
|
|
119
123
|
EMPTY_NATIVE_REGISTRY,
|
|
@@ -144,6 +148,7 @@ import {
|
|
|
144
148
|
defineSharedTool,
|
|
145
149
|
defineSubagent,
|
|
146
150
|
defineSubscriber,
|
|
151
|
+
hostedMeshOptions,
|
|
147
152
|
install,
|
|
148
153
|
installRegistry,
|
|
149
154
|
installationKey,
|
|
@@ -154,17 +159,18 @@ import {
|
|
|
154
159
|
isFoundryLayer,
|
|
155
160
|
isFoundrySubscriber,
|
|
156
161
|
isInboxCapableStore,
|
|
162
|
+
isMeshTransport,
|
|
157
163
|
mountAgentDefinitionMemory,
|
|
158
164
|
mountFoundrySurfaces,
|
|
159
165
|
restrictApp,
|
|
160
166
|
routeFromInternalAgentName
|
|
161
|
-
} from "./chunk-
|
|
167
|
+
} from "./chunk-CYOIHSUX.js";
|
|
162
168
|
|
|
163
169
|
// src/file-data.ts
|
|
164
170
|
import { randomUUID } from "node:crypto";
|
|
165
171
|
import { mkdir, open, readFile, rename, stat, unlink } from "node:fs/promises";
|
|
166
172
|
import { dirname } from "node:path";
|
|
167
|
-
import { Effect } from "effect";
|
|
173
|
+
import { Effect, Layer, Ref, Schema } from "effect";
|
|
168
174
|
function emptyState(environment) {
|
|
169
175
|
return {
|
|
170
176
|
version: 1,
|
|
@@ -173,6 +179,7 @@ function emptyState(environment) {
|
|
|
173
179
|
inboundDeliveries: [],
|
|
174
180
|
events: [],
|
|
175
181
|
pendingInbound: [],
|
|
182
|
+
approvals: [],
|
|
176
183
|
activations: [],
|
|
177
184
|
conversations: [],
|
|
178
185
|
workspaceEntries: [],
|
|
@@ -281,6 +288,7 @@ var FileFoundryDataAdapter = class {
|
|
|
281
288
|
inboundDeliveries: parsed.inboundDeliveries ?? [],
|
|
282
289
|
events: parsed.events ?? [],
|
|
283
290
|
pendingInbound: parsed.pendingInbound ?? [],
|
|
291
|
+
approvals: parsed.approvals ?? [],
|
|
284
292
|
activations: parsed.activations ?? [],
|
|
285
293
|
conversations: parsed.conversations ?? [],
|
|
286
294
|
workspaceEntries: parsed.workspaceEntries ?? [],
|
|
@@ -404,6 +412,7 @@ var FileFoundryDataAdapter = class {
|
|
|
404
412
|
const ids = new Set(state.conversations.filter((item) => item.agentId === agentId).map((item) => item.id));
|
|
405
413
|
state.events = state.events.filter((item) => item.target.agentId !== agentId);
|
|
406
414
|
state.pendingInbound = state.pendingInbound.filter((item) => item.request.agentId !== agentId);
|
|
415
|
+
state.approvals = state.approvals.filter((item) => item.agentId !== agentId);
|
|
407
416
|
state.activations = state.activations.filter((item) => item.agentId !== agentId);
|
|
408
417
|
state.conversations = state.conversations.filter((item) => item.agentId !== agentId);
|
|
409
418
|
state.workingEnvironments = state.workingEnvironments.filter((item) => item.owner.agentId !== agentId);
|
|
@@ -518,6 +527,20 @@ var FileFoundryDataAdapter = class {
|
|
|
518
527
|
listPendingInbound() {
|
|
519
528
|
return effect(async () => structuredClone((await this.snapshot()).pendingInbound));
|
|
520
529
|
}
|
|
530
|
+
putApproval(approval) {
|
|
531
|
+
return effect(async () => {
|
|
532
|
+
await this.ensureInitialized();
|
|
533
|
+
await this.mutate((state) => {
|
|
534
|
+
replaceById(state.approvals, structuredClone(approval));
|
|
535
|
+
});
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
getApproval(id) {
|
|
539
|
+
return effect(async () => structuredClone((await this.snapshot()).approvals.find((item) => item.id === id) ?? null));
|
|
540
|
+
}
|
|
541
|
+
listApprovals() {
|
|
542
|
+
return effect(async () => structuredClone((await this.snapshot()).approvals));
|
|
543
|
+
}
|
|
521
544
|
releaseInboundDelivery(key) {
|
|
522
545
|
return effect(async () => {
|
|
523
546
|
await this.ensureInitialized();
|
|
@@ -627,9 +650,79 @@ var FileFoundryDataAdapter = class {
|
|
|
627
650
|
)));
|
|
628
651
|
}
|
|
629
652
|
};
|
|
653
|
+
function fileTopologyStore(file) {
|
|
654
|
+
return Layer.effect(TopologyStore, Effect.gen(function* () {
|
|
655
|
+
const loaded = yield* Effect.promise(async () => {
|
|
656
|
+
try {
|
|
657
|
+
const parsed = JSON.parse(await readFile(file, "utf8"));
|
|
658
|
+
return {
|
|
659
|
+
version: 1,
|
|
660
|
+
routes: (parsed.routes ?? []).map((route) => Schema.decodeUnknownSync(Route)(route)),
|
|
661
|
+
bindings: (parsed.bindings ?? []).map((binding) => Schema.decodeUnknownSync(AgentBinding)(binding))
|
|
662
|
+
};
|
|
663
|
+
} catch (cause) {
|
|
664
|
+
if (cause.code === "ENOENT") return { version: 1, routes: [], bindings: [] };
|
|
665
|
+
throw cause;
|
|
666
|
+
}
|
|
667
|
+
});
|
|
668
|
+
const state = yield* Ref.make(loaded);
|
|
669
|
+
const lock = yield* Effect.makeSemaphore(1);
|
|
670
|
+
const commit = (next) => Effect.promise(async () => {
|
|
671
|
+
await mkdir(dirname(file), { recursive: true });
|
|
672
|
+
const temporary = `${file}.${process.pid}.${randomUUID()}.tmp`;
|
|
673
|
+
const handle = await open(temporary, "wx", 384);
|
|
674
|
+
try {
|
|
675
|
+
await handle.writeFile(`${JSON.stringify(next, null, 2)}
|
|
676
|
+
`, "utf8");
|
|
677
|
+
await handle.sync();
|
|
678
|
+
} finally {
|
|
679
|
+
await handle.close();
|
|
680
|
+
}
|
|
681
|
+
try {
|
|
682
|
+
await rename(temporary, file);
|
|
683
|
+
} catch (cause) {
|
|
684
|
+
try {
|
|
685
|
+
await unlink(temporary);
|
|
686
|
+
} catch {
|
|
687
|
+
}
|
|
688
|
+
throw cause;
|
|
689
|
+
}
|
|
690
|
+
});
|
|
691
|
+
const update = (change) => lock.withPermits(1)(Effect.gen(function* () {
|
|
692
|
+
const [result, next] = change(yield* Ref.get(state));
|
|
693
|
+
if (next) {
|
|
694
|
+
yield* commit(next);
|
|
695
|
+
yield* Ref.set(state, next);
|
|
696
|
+
}
|
|
697
|
+
return result;
|
|
698
|
+
}));
|
|
699
|
+
const withRoutes = (current, routes) => ({ ...current, routes });
|
|
700
|
+
const withBindings = (current, bindings) => ({ ...current, bindings });
|
|
701
|
+
return {
|
|
702
|
+
getRoute: (id) => Ref.get(state).pipe(Effect.flatMap((current) => {
|
|
703
|
+
const route = current.routes.find((candidate) => candidate.id === id);
|
|
704
|
+
return route ? Effect.succeed(route) : Effect.fail(new RouteNotFound({ routeId: id }));
|
|
705
|
+
})),
|
|
706
|
+
listRoutes: (filter = {}) => Ref.get(state).pipe(Effect.map((current) => current.routes.filter((route) => (filter.transmissionId === void 0 || route.transmissionId === filter.transmissionId) && (filter.accountId === void 0 || route.accountId === filter.accountId) && (filter.direction === void 0 || route.direction === filter.direction) && (filter.enabled === void 0 || route.enabled === filter.enabled)))),
|
|
707
|
+
putRoute: (route) => update((current) => [route, withRoutes(current, [...current.routes.filter((candidate) => candidate.id !== route.id), route])]),
|
|
708
|
+
removeRoute: (id) => update((current) => current.routes.some((route) => route.id === id) ? [true, withRoutes(current, current.routes.filter((route) => route.id !== id))] : [false, void 0]).pipe(
|
|
709
|
+
Effect.flatMap((removed) => removed ? Effect.void : Effect.fail(new RouteNotFound({ routeId: id })))
|
|
710
|
+
),
|
|
711
|
+
getBinding: (id) => Ref.get(state).pipe(Effect.flatMap((current) => {
|
|
712
|
+
const binding = current.bindings.find((candidate) => candidate.id === id);
|
|
713
|
+
return binding ? Effect.succeed(binding) : Effect.fail(new BindingNotFound({ bindingId: id }));
|
|
714
|
+
})),
|
|
715
|
+
listBindings: (filter = {}) => Ref.get(state).pipe(Effect.map((current) => current.bindings.filter((binding) => (filter.agentId === void 0 || binding.agentId === filter.agentId) && (filter.transmissionId === void 0 || binding.transmissionId === filter.transmissionId) && (filter.accountId === void 0 || binding.accountId === filter.accountId) && (filter.routeId === void 0 || binding.routeId === filter.routeId) && (filter.enabled === void 0 || binding.enabled === filter.enabled)))),
|
|
716
|
+
putBinding: (binding) => update((current) => [binding, withBindings(current, [...current.bindings.filter((candidate) => candidate.id !== binding.id), binding])]),
|
|
717
|
+
removeBinding: (id) => update((current) => current.bindings.some((binding) => binding.id === id) ? [true, withBindings(current, current.bindings.filter((binding) => binding.id !== id))] : [false, void 0]).pipe(
|
|
718
|
+
Effect.flatMap((removed) => removed ? Effect.void : Effect.fail(new BindingNotFound({ bindingId: id })))
|
|
719
|
+
)
|
|
720
|
+
};
|
|
721
|
+
}));
|
|
722
|
+
}
|
|
630
723
|
|
|
631
724
|
// src/authoring.ts
|
|
632
|
-
import { Schema } from "effect";
|
|
725
|
+
import { Schema as Schema2 } from "effect";
|
|
633
726
|
var accountTransmissions = /* @__PURE__ */ new WeakMap();
|
|
634
727
|
var routeTransmissions = /* @__PURE__ */ new WeakMap();
|
|
635
728
|
function defineAccount(options) {
|
|
@@ -637,8 +730,8 @@ function defineAccount(options) {
|
|
|
637
730
|
if (!transmission.account) {
|
|
638
731
|
throw new Error("The referenced transmission has no account contract.");
|
|
639
732
|
}
|
|
640
|
-
const metadata =
|
|
641
|
-
const decoded =
|
|
733
|
+
const metadata = Schema2.decodeUnknownSync(transmission.account.metadata)(data.metadata);
|
|
734
|
+
const decoded = Schema2.decodeUnknownSync(AccountReference)({
|
|
642
735
|
...data,
|
|
643
736
|
metadata,
|
|
644
737
|
transmissionId: "pending"
|
|
@@ -659,8 +752,8 @@ function defineInboundRoute(options) {
|
|
|
659
752
|
if (account && accountTransmissions.get(account) !== transmission) {
|
|
660
753
|
throw new Error(`Account "${account.id}" belongs to another transmission.`);
|
|
661
754
|
}
|
|
662
|
-
const config =
|
|
663
|
-
const decoded =
|
|
755
|
+
const config = Schema2.decodeUnknownSync(transmission.inbound.config)(data.config);
|
|
756
|
+
const decoded = Schema2.decodeUnknownSync(InboundRoute)({
|
|
664
757
|
...data,
|
|
665
758
|
config,
|
|
666
759
|
direction: "inbound",
|
|
@@ -683,8 +776,8 @@ function defineOutboundRoute(options) {
|
|
|
683
776
|
if (account && accountTransmissions.get(account) !== transmission) {
|
|
684
777
|
throw new Error(`Account "${account.id}" belongs to another transmission.`);
|
|
685
778
|
}
|
|
686
|
-
const config =
|
|
687
|
-
const decoded =
|
|
779
|
+
const config = Schema2.decodeUnknownSync(transmission.outbound.config)(data.config);
|
|
780
|
+
const decoded = Schema2.decodeUnknownSync(OutboundRoute)({
|
|
688
781
|
...data,
|
|
689
782
|
config,
|
|
690
783
|
direction: "outbound",
|
|
@@ -727,7 +820,7 @@ function defineBinding(options) {
|
|
|
727
820
|
`Account "${account.id}" does not belong to the referenced transmission.`
|
|
728
821
|
);
|
|
729
822
|
}
|
|
730
|
-
const decoded =
|
|
823
|
+
const decoded = Schema2.decodeUnknownSync(AgentBinding)({
|
|
731
824
|
...data,
|
|
732
825
|
agentId: agent.id,
|
|
733
826
|
transmissionId: "pending",
|
|
@@ -758,6 +851,8 @@ export {
|
|
|
758
851
|
BindingId,
|
|
759
852
|
BindingNotFound,
|
|
760
853
|
CapabilityId,
|
|
854
|
+
DEFAULT_APPROVAL_EXPIRES_AFTER_MS,
|
|
855
|
+
DEFAULT_APPROVAL_WAIT_MS,
|
|
761
856
|
EMPTY_AGENT_COMPOSITION,
|
|
762
857
|
EMPTY_CAPABILITY_REGISTRY,
|
|
763
858
|
EMPTY_FOUNDRY_APPLICATION,
|
|
@@ -861,10 +956,12 @@ export {
|
|
|
861
956
|
defineTransmissionPredicate,
|
|
862
957
|
defineWorkingEnvironment,
|
|
863
958
|
discoverAgents,
|
|
959
|
+
fileTopologyStore,
|
|
864
960
|
findAgentFiles,
|
|
865
961
|
foundryDataEnvironmentPersistence,
|
|
866
962
|
foundryGuidanceSubject,
|
|
867
963
|
grantResolverLive,
|
|
964
|
+
hostedMeshOptions,
|
|
868
965
|
install,
|
|
869
966
|
installRegistry,
|
|
870
967
|
installationKey,
|
|
@@ -879,10 +976,12 @@ export {
|
|
|
879
976
|
isFoundrySubscriber,
|
|
880
977
|
isFoundryTransmission,
|
|
881
978
|
isInboxCapableStore,
|
|
979
|
+
isMeshTransport,
|
|
882
980
|
listFoundryApprovals,
|
|
883
981
|
memoryAccountDirectory,
|
|
884
982
|
memoryEventStore,
|
|
885
983
|
memoryTopologyStore,
|
|
984
|
+
meshIdentity,
|
|
886
985
|
mountAgentDefinitionMemory,
|
|
887
986
|
mountFoundrySurfaces,
|
|
888
987
|
reconstructAgentInstance,
|
package/dist/voice.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IGloveRunnable } from 'glove-core';
|
|
2
2
|
import { RealtimeAgent, RealtimeAgentConfig } from 'glove-voice-s2s';
|
|
3
|
-
import { A as AgentHandlerContext, F as FoundryDelegationUpdate } from './event-delivery-
|
|
3
|
+
import { A as AgentHandlerContext, F as FoundryDelegationUpdate, a as FoundryMeshMessage } from './event-delivery-CNCsVqi8.js';
|
|
4
4
|
import 'effect';
|
|
5
5
|
import 'zod';
|
|
6
6
|
import 'glove-mesh';
|
|
@@ -78,9 +78,11 @@ interface VoiceCallOptions {
|
|
|
78
78
|
readonly realtime?: Omit<RealtimeAgentConfig, "agent">;
|
|
79
79
|
/** How a delegation update is put to the model. Return null to keep it silent. */
|
|
80
80
|
readonly announce?: (update: FoundryDelegationUpdate) => string | null;
|
|
81
|
+
/** How a message from a peer on the mesh Foundry hosts is put to the model. Return null to keep it silent. */
|
|
82
|
+
readonly announceMesh?: (message: FoundryMeshMessage) => string | null;
|
|
81
83
|
/**
|
|
82
|
-
* A run that is not a call: a delegation result
|
|
83
|
-
* caller hung up. By default it is saved to the conversation, so the next
|
|
84
|
+
* A run that is not a call: a delegation result, or a peer's reply on the
|
|
85
|
+
* mesh, that arrived after the caller hung up. By default it is saved to the conversation, so the next
|
|
84
86
|
* call starts knowing it.
|
|
85
87
|
*/
|
|
86
88
|
readonly offCall?: (agent: IGloveRunnable, context: AgentHandlerContext) => unknown;
|
|
@@ -90,19 +92,21 @@ interface VoiceCallResult {
|
|
|
90
92
|
readonly durationMs: number;
|
|
91
93
|
/** How many times the agent spoke. */
|
|
92
94
|
readonly turns: number;
|
|
93
|
-
/** Delegation updates put to the caller during the call. */
|
|
95
|
+
/** Delegation updates and mesh messages put to the caller during the call. */
|
|
94
96
|
readonly updatesSpoken: number;
|
|
95
97
|
}
|
|
96
98
|
/** The default way a delegation update is put to the model mid-call. */
|
|
97
99
|
declare function announceDelegationUpdate(update: FoundryDelegationUpdate): string;
|
|
100
|
+
/** The default way a message from a peer on the mesh is put to the model mid-call. */
|
|
101
|
+
declare function announceMeshMessage(message: FoundryMeshMessage): string;
|
|
98
102
|
/**
|
|
99
103
|
* Run an agent as a live voice call: use it as a definition's `run`.
|
|
100
104
|
*
|
|
101
105
|
* The agent's prompt, tools and context configure a realtime speech session
|
|
102
106
|
* (its model must be `s2sDrivenModel(...)`, or pass `realtime.adapter`). The
|
|
103
107
|
* room connects callers. What both sides say is saved to the conversation.
|
|
104
|
-
* Delegation results and questions
|
|
105
|
-
* waiting for the call to end. Foundry's bookkeeping tools and any tool that
|
|
108
|
+
* Delegation results and questions, and messages from peers on the mesh, are
|
|
109
|
+
* spoken at the next pause instead of waiting for the call to end. Foundry's bookkeeping tools and any tool that
|
|
106
110
|
* needs an approval are kept off the call; delegate that work instead.
|
|
107
111
|
*/
|
|
108
112
|
declare function voiceCall(options: VoiceCallOptions): (agent: IGloveRunnable, context: AgentHandlerContext) => Promise<VoiceCallResult | unknown>;
|
|
@@ -165,4 +169,4 @@ interface WebSocketRoomOptions {
|
|
|
165
169
|
*/
|
|
166
170
|
declare function webSocketRoom(options: WebSocketRoomOptions): FoundryVoiceRoom;
|
|
167
171
|
|
|
168
|
-
export { type FoundryVoiceCall, type FoundryVoiceRoom, VOICE_EXCLUDED_FOUNDRY_TOOLS, type VoiceCallOptions, type VoiceCallResult, type VoiceRoomClientMessage, type VoiceRoomServerMessage, type WebSocketRoomOptions, announceDelegationUpdate, voiceCall, webSocketRoom };
|
|
172
|
+
export { type FoundryVoiceCall, type FoundryVoiceRoom, VOICE_EXCLUDED_FOUNDRY_TOOLS, type VoiceCallOptions, type VoiceCallResult, type VoiceRoomClientMessage, type VoiceRoomServerMessage, type WebSocketRoomOptions, announceDelegationUpdate, announceMeshMessage, voiceCall, webSocketRoom };
|
package/dist/voice.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
-
renderDeliveries
|
|
3
|
-
|
|
2
|
+
renderDeliveries,
|
|
3
|
+
renderMeshMessages
|
|
4
|
+
} from "./chunk-J6NHL4SM.js";
|
|
4
5
|
|
|
5
6
|
// src/voice.ts
|
|
6
7
|
import { createServer } from "node:http";
|
|
@@ -38,12 +39,33 @@ function announceDelegationUpdate(update) {
|
|
|
38
39
|
"Let the caller know, briefly."
|
|
39
40
|
].join("\n");
|
|
40
41
|
}
|
|
42
|
+
function announceMeshMessage(message) {
|
|
43
|
+
const who = `${message.from.name} (${message.from.agentId})`;
|
|
44
|
+
if (message.kind === "reply") {
|
|
45
|
+
return [
|
|
46
|
+
`${who} replied to what you sent them (thread ${message.threadId}):`,
|
|
47
|
+
message.content,
|
|
48
|
+
"Tell the caller what matters, briefly and in plain speech."
|
|
49
|
+
].join("\n");
|
|
50
|
+
}
|
|
51
|
+
if (message.kind === "failed") {
|
|
52
|
+
return [
|
|
53
|
+
`${who} could not finish (thread ${message.threadId}): ${message.content}`,
|
|
54
|
+
"Let the caller know, briefly."
|
|
55
|
+
].join("\n");
|
|
56
|
+
}
|
|
57
|
+
return [
|
|
58
|
+
`${who} asks (thread ${message.threadId}): ${message.content}`,
|
|
59
|
+
`If you already know the answer, reply with glove_mesh_send_message to "${message.from.agentId}" with in_reply_to "${message.id}".`,
|
|
60
|
+
"Otherwise ask the caller, then reply with their answer."
|
|
61
|
+
].join("\n");
|
|
62
|
+
}
|
|
41
63
|
function gatedTools(agent) {
|
|
42
64
|
return agent.tools.filter((tool) => tool.requiresPermission !== void 0 && tool.requiresPermission !== false).map((tool) => tool.name);
|
|
43
65
|
}
|
|
44
66
|
function voiceCall(options) {
|
|
45
67
|
return async (agent, context) => {
|
|
46
|
-
if (context.request.source?.kind === "delegation") {
|
|
68
|
+
if (context.request.source?.kind === "delegation" || context.request.source?.kind === "mesh") {
|
|
47
69
|
if (options.offCall) return options.offCall(agent, context);
|
|
48
70
|
await agent.store.appendMessages([{ sender: "user", text: context.messageText }]);
|
|
49
71
|
return { endedBecause: "not a call", durationMs: 0, turns: 0, updatesSpoken: 0 };
|
|
@@ -81,7 +103,17 @@ function voiceCall(options) {
|
|
|
81
103
|
realtime.on("tool_started", (name) => context.emit({ type: "foundry.voice.tool", data: { name, phase: "start" } }));
|
|
82
104
|
realtime.on("tool_finished", (name) => context.emit({ type: "foundry.voice.tool", data: { name, phase: "done" } }));
|
|
83
105
|
const announce = options.announce ?? announceDelegationUpdate;
|
|
106
|
+
const announceMesh = options.announceMesh ?? announceMeshMessage;
|
|
84
107
|
const queue = [];
|
|
108
|
+
const meshSide = (message) => message.threadId === context.conversationId ? "recipient" : "starter";
|
|
109
|
+
const rendered = (batch) => {
|
|
110
|
+
const updates = batch.flatMap((item) => "update" in item ? [item.update] : []);
|
|
111
|
+
const messages = batch.flatMap((item) => "mesh" in item ? [item.mesh] : []);
|
|
112
|
+
return [
|
|
113
|
+
updates.length ? renderDeliveries(updates) : "",
|
|
114
|
+
messages.length ? renderMeshMessages(messages, meshSide) : ""
|
|
115
|
+
].filter(Boolean).join("\n\n");
|
|
116
|
+
};
|
|
85
117
|
let heldSince = 0;
|
|
86
118
|
let retry;
|
|
87
119
|
const pump = () => {
|
|
@@ -97,13 +129,16 @@ function voiceCall(options) {
|
|
|
97
129
|
return;
|
|
98
130
|
}
|
|
99
131
|
const batch = queue.splice(0);
|
|
100
|
-
save([{ sender: "user", text:
|
|
101
|
-
const text = batch.map(announce).filter((line) => Boolean(line)).join("\n\n");
|
|
132
|
+
save([{ sender: "user", text: rendered(batch) }]);
|
|
133
|
+
const text = batch.map((item) => "update" in item ? announce(item.update) : announceMesh(item.mesh)).filter((line) => Boolean(line)).join("\n\n");
|
|
102
134
|
if (text) realtime.inject(text, { respond: true });
|
|
103
135
|
updatesSpoken += batch.length;
|
|
104
136
|
context.emit({
|
|
105
137
|
type: "foundry.voice.updates.spoken",
|
|
106
|
-
data: {
|
|
138
|
+
data: {
|
|
139
|
+
delegationIds: batch.flatMap((item) => "update" in item ? [item.update.delegationId] : []),
|
|
140
|
+
threadIds: batch.flatMap((item) => "mesh" in item ? [item.mesh.threadId] : [])
|
|
141
|
+
}
|
|
107
142
|
});
|
|
108
143
|
};
|
|
109
144
|
realtime.adapter.on("agent_speech_started", () => {
|
|
@@ -123,11 +158,16 @@ function voiceCall(options) {
|
|
|
123
158
|
realtime.adapter.on("interrupted", () => {
|
|
124
159
|
agentSpeaking = false;
|
|
125
160
|
});
|
|
126
|
-
const
|
|
161
|
+
const hear = (items) => {
|
|
127
162
|
if (queue.length === 0) heldSince = Date.now();
|
|
128
|
-
queue.push(...
|
|
163
|
+
queue.push(...items);
|
|
129
164
|
pump();
|
|
130
|
-
}
|
|
165
|
+
};
|
|
166
|
+
const stopUpdates = context.onDelegationUpdate((updates) => hear(updates.map((update) => ({ update }))));
|
|
167
|
+
const stopMesh = context.onMeshMessage((messages) => hear(messages.map((mesh) => ({ mesh }))));
|
|
168
|
+
const stopListening = async () => {
|
|
169
|
+
await Promise.all([stopUpdates(), stopMesh()]);
|
|
170
|
+
};
|
|
131
171
|
const room = typeof options.room === "function" ? await options.room(context) : options.room;
|
|
132
172
|
const idleMs = options.idleMs ?? 12e4;
|
|
133
173
|
const maxDurationMs = options.maxDurationMs ?? 30 * 6e4;
|
|
@@ -196,7 +236,7 @@ function voiceCall(options) {
|
|
|
196
236
|
if (retry) clearTimeout(retry);
|
|
197
237
|
context.signal.removeEventListener("abort", onAbort);
|
|
198
238
|
await stopListening();
|
|
199
|
-
if (queue.length > 0) save([{ sender: "user", text:
|
|
239
|
+
if (queue.length > 0) save([{ sender: "user", text: rendered(queue.splice(0)) }]);
|
|
200
240
|
try {
|
|
201
241
|
await room.close();
|
|
202
242
|
} catch {
|
|
@@ -343,6 +383,7 @@ function webSocketRoom(options) {
|
|
|
343
383
|
export {
|
|
344
384
|
VOICE_EXCLUDED_FOUNDRY_TOOLS,
|
|
345
385
|
announceDelegationUpdate,
|
|
386
|
+
announceMeshMessage,
|
|
346
387
|
voiceCall,
|
|
347
388
|
webSocketRoom
|
|
348
389
|
};
|
package/docs/README.md
CHANGED
|
@@ -7,7 +7,7 @@ These package-local documents provide the implementation-level companion referen
|
|
|
7
7
|
- [Building with Foundry](./building-with-foundry.md): project layout and complete authoring flow.
|
|
8
8
|
- [Architecture](./architecture.md): definitions, instances, subscriptions, connections, and adapter boundaries.
|
|
9
9
|
- [HTTP files and host secrets](../../glove-working-environment/HTTP-AND-SECRETS.md): secure downloads/uploads, HTTP calls, keystore references, and per-instance storage.
|
|
10
|
-
- [Inspector](./inspector.md): page hierarchy,
|
|
10
|
+
- [Inspector](./inspector.md): page hierarchy, runs opened like DevTools (Network, Console, Context), live updates, and the operator API.
|
|
11
11
|
- [Evaluation checklist](./evaluation-checklist.md): concrete review criteria and verification commands.
|
|
12
12
|
- [Implementation backlog](./implementation-backlog.md): remaining follow-up work, if any.
|
|
13
13
|
|
|
@@ -190,6 +190,21 @@ export default defineAgent({
|
|
|
190
190
|
|
|
191
191
|
An agent definition describes lazy assembly. It never declares request input or result output; those are Foundry contracts. An agent definition is also not an instance. Instances are durable data and may be created, updated, removed, or reconstructed independently.
|
|
192
192
|
|
|
193
|
+
### Agents are data
|
|
194
|
+
|
|
195
|
+
A definition is everything a kind of agent can be, like a server-rendered page
|
|
196
|
+
that renders any props. Each agent is an instance, and who it is lives on the
|
|
197
|
+
instance: `name`, `description`, `context`, `installations` and `workspaceId`.
|
|
198
|
+
Write one definition per kind of agent, never one per agent. A person making a
|
|
199
|
+
bot, renaming it or giving it an app is a write (`createAgent`,
|
|
200
|
+
`configureAgent`, `install`), not a deploy. Read names, jobs and per-user
|
|
201
|
+
settings from the instance in resolvers, branch on its data (`context.routines`)
|
|
202
|
+
rather than its id, and let agents change their own data with tools, such as a
|
|
203
|
+
`take_job` tool that writes `name` and `description` with `ctx.data.putAgent`.
|
|
204
|
+
A workspace is a tenant: its agents share workspace entries, and with `mesh` they are peers.
|
|
205
|
+
Add a definition only when a kind of agent runs differently, loads different
|
|
206
|
+
dependencies, or must never have another kind's tools.
|
|
207
|
+
|
|
193
208
|
## Define and compose colocated pieces
|
|
194
209
|
|
|
195
210
|
```ts
|
|
@@ -263,6 +278,65 @@ servers from stalling a run indefinitely.
|
|
|
263
278
|
Stdio-only idle and lifetime limits can recycle memory-heavy children without
|
|
264
279
|
interrupting in-flight calls; adapter environment values are resolved again on reopen.
|
|
265
280
|
|
|
281
|
+
### Apps people connect
|
|
282
|
+
|
|
283
|
+
When a person connects one of their own accounts (their Gmail, their Linear),
|
|
284
|
+
connect it through an app, not a bare MCP definition. The app is the unit they
|
|
285
|
+
connect, and it holds everything about that provider: the MCP server whose
|
|
286
|
+
tools the agent uses, the account they open with, the transmissions that carry
|
|
287
|
+
events in and deliveries out, and the connection that listens.
|
|
288
|
+
|
|
289
|
+
```ts
|
|
290
|
+
// agents/assistant/apps/gmail.app.ts
|
|
291
|
+
export default defineApp({
|
|
292
|
+
description: "Gmail: search, read and draft, send with approval, hear about new mail",
|
|
293
|
+
config: z.object({ alwaysAllow: z.array(z.string()).default([]) }),
|
|
294
|
+
inbound: [gmail], // new mail, as events
|
|
295
|
+
outbound: [gmail], // sending, delivered by Foundry
|
|
296
|
+
connections: [gmailWatch], // users.watch + Pub/Sub, one per account
|
|
297
|
+
mcp: {
|
|
298
|
+
entry: { name: "Gmail", url: "https://gmailmcp.googleapis.com/mcp/v1" },
|
|
299
|
+
// Runs inside the agent's accountSessions; Foundry never holds the token.
|
|
300
|
+
auth: (session) => ({ authorization: `Bearer ${(session as GoogleSession).accessToken}` }),
|
|
301
|
+
// "allow", "ask" or "hide" per tool. Default: read-only tools run, the rest ask.
|
|
302
|
+
tools: (tool, { config }) =>
|
|
303
|
+
tool.readOnly || config.alwaysAllow.includes(tool.name) ? "allow" : "ask",
|
|
304
|
+
},
|
|
305
|
+
})
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
Install it with the person's account: `install(gmailApp, config, { account })`
|
|
309
|
+
in code, or `{ kind: "application", id: "gmail", accountId }` over HTTP. The
|
|
310
|
+
server's tools mount as `gmail__search_threads` and so on, opened with that
|
|
311
|
+
account; a stdio server gets `auth`'s result as its environment instead. An app
|
|
312
|
+
whose `mcp` has `auth` refuses an installation without an account, and its
|
|
313
|
+
connection closes when the run ends.
|
|
314
|
+
|
|
315
|
+
Splitting the work this way keeps each part where it is safest:
|
|
316
|
+
|
|
317
|
+
- **Reads and drafts** come from the provider's MCP server, through the app's
|
|
318
|
+
tool policy.
|
|
319
|
+
- **Sends** belong in an outbound transmission when the provider's server has
|
|
320
|
+
none or when the send should not run in the agent: Foundry delivers it in its
|
|
321
|
+
own process, with the route's account session, after the exact input is
|
|
322
|
+
approved, and only for a run whose bindings grant the route.
|
|
323
|
+
- **Incoming events** (new mail, a webhook) are an inbound transmission. A
|
|
324
|
+
connection keeps the provider subscription alive per account; a playbook on
|
|
325
|
+
the instance decides which agent hears them.
|
|
326
|
+
|
|
327
|
+
An app that is only an MCP server (Linear's, Google Calendar's) needs only
|
|
328
|
+
`mcp`. Accounts belong to your application: your OAuth callback stores the
|
|
329
|
+
account and its tokens, your `accountSessions` resolves and refreshes them,
|
|
330
|
+
and Foundry reads accounts through your account directory (see "Runtime
|
|
331
|
+
topology is data").
|
|
332
|
+
|
|
333
|
+
An agent can put its own policy around an app's generated send in
|
|
334
|
+
`configure(agent, ctx)`: replace the tool with one whose `requiresPermission`
|
|
335
|
+
applies the person's rules and whose `do` calls the original tool's `run`.
|
|
336
|
+
Glove asks for approval from the tool the model calls, so the wrapper's rule
|
|
337
|
+
is the one that counts, and delivery still happens in Foundry's process.
|
|
338
|
+
`configure` sees the instance, its conversation and the data adapter.
|
|
339
|
+
|
|
266
340
|
## Mount optional capabilities
|
|
267
341
|
|
|
268
342
|
Use `configure(agent, context)` to call capability packages' mount functions on the assembled agent. Register resource teardown with `context.onCleanup(() => handle.close())`; callbacks run in reverse order after execution, including failed setup or cancellation. Register cleanup as soon as you acquire a resource, before any later setup can fail.
|
|
@@ -344,6 +418,21 @@ export default defineAgent({
|
|
|
344
418
|
|
|
345
419
|
`workingEnvironment` and `repl` accept the same direct-value-or-lazy-resolver shape as the other assembly fields. JavaScript, Python, and Lisp sessions are supported through one discriminated `defineRepl` API. Foundry exposes the mounted `workingEnvironment`, its guarded `vfs` handle, and the native `repl` session to layers, `configure`, calls, and `run` handlers.
|
|
346
420
|
|
|
421
|
+
Installed apps arrive grouped. `select` receives `apps`, one entry per
|
|
422
|
+
installed app with its live tools already named for code, grouped under the
|
|
423
|
+
app and marked read-only where the server says so. Selecting an app's reads
|
|
424
|
+
gives the agent `gmail.search_threads(...)` and `linear.list_issues(...)` in one
|
|
425
|
+
program. `keepDirect: false` takes the selected tools out of the model's direct
|
|
426
|
+
tool list, so a large app catalogue stays out of context; a tool that needs
|
|
427
|
+
approval always stays direct.
|
|
428
|
+
|
|
429
|
+
```ts
|
|
430
|
+
programmaticTools: {
|
|
431
|
+
select: ({ apps }) => apps.flatMap((app) => app.tools.filter((tool) => tool.readOnly)),
|
|
432
|
+
keepDirect: false,
|
|
433
|
+
}
|
|
434
|
+
```
|
|
435
|
+
|
|
347
436
|
`programmaticTools` turns an explicit least-privilege projection of the live
|
|
348
437
|
agent tool registry into functions inside that sandbox. The selector runs after
|
|
349
438
|
application transmissions, instance-installed tools and MCPs, calls, memory,
|
|
@@ -547,6 +636,28 @@ export const ticketInbound = defineInboundRoute({
|
|
|
547
636
|
|
|
548
637
|
`accessRef` is opaque to Foundry. Credential acquisition and refresh belong to the user-owned account-session adapter.
|
|
549
638
|
|
|
639
|
+
Foundry never creates accounts. When people connect accounts at runtime, keep
|
|
640
|
+
them in your own store and give Foundry a read-only `AccountDirectory` over it.
|
|
641
|
+
Supplying `services` replaces `defineApplication({ accounts })`, so list any
|
|
642
|
+
code-defined accounts in your directory too. Routes and bindings you write when
|
|
643
|
+
someone connects (`putRoute`, `putBinding`) live in the topology store; on a
|
|
644
|
+
single host, `fileTopologyStore(file)` keeps them across restarts.
|
|
645
|
+
|
|
646
|
+
```ts
|
|
647
|
+
export default defineApplication({
|
|
648
|
+
name: "Assistants",
|
|
649
|
+
data,
|
|
650
|
+
services: Layer.mergeAll(
|
|
651
|
+
myAccountDirectory, // reads your accounts table
|
|
652
|
+
fileTopologyStore(join(dataDir, "topology.json")),
|
|
653
|
+
memoryEventStore,
|
|
654
|
+
),
|
|
655
|
+
})
|
|
656
|
+
```
|
|
657
|
+
|
|
658
|
+
Application connections find their account through that directory, so a newly
|
|
659
|
+
connected account starts its connection on the next reconciliation.
|
|
660
|
+
|
|
550
661
|
## Runtime-composed playbooks and dynamic installations
|
|
551
662
|
|
|
552
663
|
```ts
|
|
@@ -629,6 +740,10 @@ glove_foundry_schedule({
|
|
|
629
740
|
timing: { kind: "every", interval: "24h" },
|
|
630
741
|
})
|
|
631
742
|
|
|
743
|
+
// Deliver through an outbound route this instance's playbooks declare.
|
|
744
|
+
// It asks for approval whenever the route's transmission requires it:
|
|
745
|
+
glove_foundry_transmit({ routeId: "support-replies", payload: { message: "Done." } })
|
|
746
|
+
|
|
632
747
|
// Suspend this conversation and wake the same instance later:
|
|
633
748
|
glove_foundry_sleep({
|
|
634
749
|
kind: "for",
|
|
@@ -698,9 +813,13 @@ during active work through the typed steering operation.
|
|
|
698
813
|
## Effect approvals
|
|
699
814
|
|
|
700
815
|
A Glove tool can set `requiresPermission: true` or return a boolean from
|
|
701
|
-
`requiresPermission(input)`. In Foundry, an unset decision becomes a
|
|
702
|
-
|
|
703
|
-
|
|
816
|
+
`requiresPermission(input)`. In Foundry, an unset decision becomes a stored
|
|
817
|
+
approval record rather than an unresolved in-process display promise. The worker
|
|
818
|
+
waits `approvals.waitMs` (60 s); if nobody decides, the run suspends at that call
|
|
819
|
+
and the approval stays open (7 days, through restarts). A trusted host lists and
|
|
820
|
+
resolves the exact request, or opens one by id from a link
|
|
821
|
+
(`client.approval(id)`); a decision after the run suspended resumes the
|
|
822
|
+
conversation at the waiting call:
|
|
704
823
|
|
|
705
824
|
```ts
|
|
706
825
|
const [approval] = await client.approvals({
|
|
@@ -744,7 +863,9 @@ tool with `requiresPermission` off the call, because a realtime session runs
|
|
|
744
863
|
tools directly and would skip the approval. A delegation result that arrives
|
|
745
864
|
after the caller hangs up runs as an ordinary turn (`source.kind` is
|
|
746
865
|
`"delegation"`); by default `voiceCall` saves it to the conversation, or pass
|
|
747
|
-
`offCall` to handle it, for instance with a text model.
|
|
866
|
+
`offCall` to handle it, for instance with a text model. A call's agent on the
|
|
867
|
+
hosted mesh hears messages from its peers the same way (`announceMeshMessage`,
|
|
868
|
+
or your own `announce`); one that arrives after the call is a `"mesh"` turn.
|
|
748
869
|
|
|
749
870
|
Use `glove-voice-s2s` for Gemini Live, OpenAI Realtime, or GPT-Live and `glove-voice` for a
|
|
750
871
|
speech-to-text / Glove / text-to-speech pipeline.
|
|
@@ -793,13 +914,16 @@ run cleanup. See the [document adapter](../../glove-env-documents/README.md).
|
|
|
793
914
|
- IDs appear when definitions are serialized into durable data.
|
|
794
915
|
- Runtime data IDs remain explicit because users and adapters create those records.
|
|
795
916
|
- Applications, shared tools, and MCPs mount only when an instance installs them.
|
|
917
|
+
- A person's accounts connect through apps: MCP for tools, transmissions for sends and events, connections for subscriptions, your own account directory and `accountSessions` for credentials.
|
|
796
918
|
- Memory and inboxes are agent-definition surfaces and may resolve from current context/message.
|
|
797
919
|
- Working environments and one native REPL are agent-definition surfaces and may resolve from current context/message.
|
|
798
920
|
- VFS persistence, remote storage, and locking remain adapter-owned.
|
|
799
921
|
- Transmissions own executable integration logic; playbooks remain serializable policy.
|
|
800
922
|
- Provider adapters own credential acquisition and refresh.
|
|
801
923
|
- Voice rooms own audio transport; `voiceCall` owns the session and the transcript; Foundry owns the durable run.
|
|
924
|
+
- A definition is what a kind of agent can be; each agent, its name and its job are instance data.
|
|
802
925
|
- Interactors keep the person's context; workers keep one task's. Delegation results and questions come back to the conversation that delegated.
|
|
926
|
+
- Agents that already exist as peers in one workspace can message each other on the hosted mesh. Replies come back to the conversation that sent the message.
|
|
803
927
|
|
|
804
928
|
## Durable subagents
|
|
805
929
|
|