glove-foundry 0.6.1 → 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.
@@ -1,18 +1,107 @@
1
- import { ContentPart, Message, IGloveRunnable, StoreAdapter, GloveFoldArgs, Tool, SubscriberAdapter, RuntimeContextProvider, RuntimeContextOptions, ModelAdapter, DisplayManagerAdapter, HookHandler, DefineSkillArgs, DefineSubAgentArgs, InboxItem } from 'glove-core';
1
+ import * as glove_core from 'glove-core';
2
+ import { Displaymanager, DisplayManagerAdapter, Slot, StoreAdapter, Message, IGloveRunnable, GloveFoldArgs, Tool, SubscriberAdapter, RuntimeContextProvider, RuntimeContextOptions, ModelAdapter, HookHandler, DefineSkillArgs, DefineSubAgentArgs, InboxItem, ContentPart, AgentEvent } from 'glove-core';
2
3
  import { Schema, Effect } from 'effect';
3
4
  import { z } from 'zod';
4
- import { MeshAdapter, AgentIdentity } from 'glove-mesh';
5
+ import { AgentIdentity, MeshAdapter } from 'glove-mesh';
5
6
  import { McpCatalogueEntry, McpAdapter } from 'glove-mcp';
6
7
  import { EntityMemoryAdapter, EpisodicMemoryAdapter, ResourceFsAdapter, ContextAdapter } from 'glove-memory';
7
8
  import { MemoryToolOptions, UseGoalRunnerConfig, UseFormRunnerConfig } from 'glove-memory/tools';
8
- import { EnvSnapshot, EnvFsHandle, WorkingEnvironment, CreateWorkingEnvironmentOptions, MountWorkingEnvironmentConfig, Vfs } from 'glove-working-environment';
9
9
  import { JsSession, MountJsConfig } from 'glove-js';
10
10
  import { LispSession, MountLispConfig } from 'glove-lisp';
11
11
  import { PySession, MountPyConfig } from 'glove-python';
12
+ import { EnvFsHandle, EnvSnapshot, WorkingEnvironment, CreateWorkingEnvironmentOptions, MountWorkingEnvironmentConfig, Vfs } from 'glove-working-environment';
12
13
  import { FactAdapter, FactScope, FactStore, FactInput } from 'glove-facts';
13
14
  import { GoalAdapter, GoalScope, GoalProgram, GoalRunner } from 'glove-memory/goals';
14
15
  import { FormAdapter, FormRunner } from 'glove-memory/forms';
15
16
 
17
+ declare const FOUNDRY_APPROVAL_DIRECTORY_ENV = "GLOVE_FOUNDRY_APPROVAL_DIRECTORY";
18
+ /** Default live wait before a run with durable approvals suspends. */
19
+ declare const DEFAULT_APPROVAL_WAIT_MS = 60000;
20
+ /** Default lifetime of a durable approval nobody has decided. */
21
+ declare const DEFAULT_APPROVAL_EXPIRES_AFTER_MS: number;
22
+ /** How a run treats approvals. Durable ones outlive the run; the others expire with it. */
23
+ interface FoundryApprovalPolicy {
24
+ readonly durable: boolean;
25
+ /** How long the run waits for a decision before it suspends (durable) or the approval expires. */
26
+ readonly waitMs: number;
27
+ /** How long a durable approval stays open. */
28
+ readonly expiresAfterMs: number;
29
+ }
30
+ type FoundryApprovalDecision = "approve" | "deny";
31
+ type FoundryApprovalStatus = "pending" | "approved" | "denied" | "expired" | "cancelled";
32
+ interface FoundryApproval {
33
+ readonly id: string;
34
+ /** The run that asked. A resumed approval continues in a later run (`resumeRunId`). */
35
+ readonly runId: string;
36
+ readonly definitionId: string;
37
+ readonly agentId: string;
38
+ readonly conversationId: string;
39
+ readonly workspaceId: string;
40
+ readonly toolName: string;
41
+ readonly toolInput: unknown;
42
+ /** The tool call waiting for this decision, as the model made it. */
43
+ readonly toolCallId?: string;
44
+ readonly status: FoundryApprovalStatus;
45
+ readonly requestedAt: string;
46
+ readonly expiresAt: string;
47
+ readonly resolvedAt?: string;
48
+ /** Where a person decides it: from the application's `approvals.url`. */
49
+ readonly url?: string;
50
+ /** When the run stopped waiting for it. A decision after this resumes the run. */
51
+ readonly suspendedAt?: string;
52
+ /** When the decision was handed to the conversation, and the run that took it. */
53
+ readonly resumedAt?: string;
54
+ readonly resumeRunId?: string;
55
+ /** The run that asked read the decision itself, so no resume is owed. */
56
+ readonly settledInRun?: boolean;
57
+ }
58
+ declare function createFoundryApproval(directory: string, input: {
59
+ readonly runId: string;
60
+ readonly definitionId: string;
61
+ readonly agentId: string;
62
+ readonly conversationId: string;
63
+ readonly workspaceId: string;
64
+ readonly toolName: string;
65
+ readonly toolInput: unknown;
66
+ readonly toolCallId?: string;
67
+ readonly timeoutMs?: number;
68
+ /** A durable approval's lifetime, beyond the live wait. Overrides `timeoutMs`. */
69
+ readonly expiresAfterMs?: number;
70
+ }): Promise<FoundryApproval>;
71
+ declare function listFoundryApprovals(directory: string, filter?: {
72
+ readonly runId?: string;
73
+ readonly status?: FoundryApprovalStatus;
74
+ }): Promise<ReadonlyArray<FoundryApproval>>;
75
+ declare function resolveFoundryApproval(directory: string, id: string, decision: FoundryApprovalDecision): Promise<FoundryApproval>;
76
+ declare class FoundryApprovalDisplayManager extends Displaymanager implements DisplayManagerAdapter {
77
+ private readonly context;
78
+ constructor(context: {
79
+ readonly directory?: string;
80
+ readonly runId: string;
81
+ readonly definitionId: string;
82
+ readonly agentId: string;
83
+ readonly conversationId: string;
84
+ readonly workspaceId: string;
85
+ readonly signal: AbortSignal;
86
+ readonly emit: (event: {
87
+ readonly type: string;
88
+ readonly data?: unknown;
89
+ }) => void;
90
+ /** With durable approvals the run suspends after `waitMs` instead of the approval expiring. */
91
+ readonly policy?: FoundryApprovalPolicy;
92
+ });
93
+ pushAndWait<I, O>(slot: Omit<Slot<I>, "id">): Promise<O>;
94
+ /**
95
+ * A durable approval: wait a while for the decision in this run. If nobody
96
+ * decides in time, or the run is stopping, the approval stays open and the
97
+ * turn suspends at this tool call (`ToolPermissionDeferred`), with no
98
+ * result recorded for it. The runtime resumes it when someone decides.
99
+ */
100
+ private durableDecision;
101
+ }
102
+ /** Add fail-closed per-input permissions to a custom store that omitted them. */
103
+ declare function withFoundryPermissions(store: StoreAdapter): StoreAdapter;
104
+
16
105
  declare const TransmissionId: Schema.brand<Schema.refine<string, typeof Schema.String>, "FoundryTransmissionId">;
17
106
  type TransmissionId = typeof TransmissionId.Type;
18
107
  declare const AgentDefinitionId: Schema.brand<Schema.refine<string, typeof Schema.String>, "FoundryAgentDefinitionId">;
@@ -488,441 +577,436 @@ interface ApplicationConnectionState {
488
577
  }
489
578
  declare function defineConnection<TError = never, TRequirements = never>(options: DefineConnectionOptions<TError, TRequirements>): FoundryApplicationConnection;
490
579
 
491
- type AgentProvisioningPolicy = {
492
- readonly mode: "singleton";
493
- readonly key?: string;
494
- } | {
495
- readonly mode: "per-thread";
496
- } | {
497
- readonly mode: "per-event";
498
- } | {
499
- readonly mode: "existing";
500
- readonly agentIds: ReadonlyArray<string>;
501
- } | {
502
- readonly mode: "custom";
503
- readonly adapter: string;
504
- };
505
- interface PlaybookSubscriptionTarget {
506
- readonly definitionId: string;
507
- readonly provisioning: AgentProvisioningPolicy;
508
- readonly context: Readonly<Record<string, unknown>>;
509
- readonly installations: ReadonlyArray<AgentInstallation>;
510
- }
511
- interface PlaybookSubscription {
580
+ declare const FOUNDRY_SHARED_TOOL_BRAND: unique symbol;
581
+ declare const FOUNDRY_AGENT_APPLICATION_BRAND: unique symbol;
582
+ declare const FOUNDRY_MCP_BRAND: unique symbol;
583
+ declare const FOUNDRY_MEMORY_BRAND: unique symbol;
584
+ type AgentInstallationKind = "tool" | "application" | "mcp";
585
+ type FoundryCapabilityKind = AgentInstallationKind | "memory";
586
+ interface AgentInstallation {
587
+ readonly kind: AgentInstallationKind;
512
588
  readonly id: string;
513
- readonly workspaceId: string;
514
- readonly enabled: boolean;
515
- readonly playbook: AgentPlaybook;
516
- readonly targets: ReadonlyArray<PlaybookSubscriptionTarget>;
517
- readonly createdAt: string;
518
- readonly updatedAt: string;
589
+ /** Durable account selection; code authoring supplies this through an AccountReference. */
590
+ readonly accountId?: string;
591
+ readonly config?: unknown;
519
592
  }
520
- interface PlaybookSubscriptionTargetInput {
521
- readonly agent: FoundryAgentDefinition;
522
- readonly provisioning?: AgentProvisioningPolicy;
523
- readonly context?: Readonly<Record<string, unknown>>;
524
- readonly installations?: ReadonlyArray<AgentInstallation>;
593
+ type FoundryInstallable = FoundrySharedTool<any> | FoundryAgentApplication | FoundryMcp;
594
+ /** Create persisted installation data from a code definition. */
595
+ type DefinitionConfigInput<TDefinition> = TDefinition extends {
596
+ readonly config?: infer TSchema;
597
+ } ? TSchema extends z.ZodType ? z.input<TSchema> : never : never;
598
+ interface InstallationSelection {
599
+ readonly account?: AccountReference;
525
600
  }
526
- interface DefinePlaybookSubscriptionOptions {
527
- /** @deprecated File-routed subscriptions derive identity from their filename. */
528
- readonly id?: string;
529
- readonly workspaceId?: string;
530
- readonly enabled?: boolean;
531
- readonly playbook: AgentPlaybookInput | AgentPlaybook;
532
- readonly targets: ReadonlyArray<PlaybookSubscriptionTargetInput>;
533
- readonly createdAt?: string;
534
- readonly updatedAt?: string;
601
+ declare function install<TDefinition extends FoundryInstallable>(capability: TDefinition, ...configuration: [DefinitionConfigInput<TDefinition>] extends [never] ? [config?: never, selection?: InstallationSelection] : [config: DefinitionConfigInput<TDefinition>, selection?: InstallationSelection]): AgentInstallation;
602
+ declare function installationKey(installation: AgentInstallation): string;
603
+ interface AgentMountBaseContext {
604
+ readonly definitionId: string;
605
+ readonly agentId: string;
606
+ readonly conversationId: string;
607
+ readonly workspaceId: string;
608
+ readonly runId: string;
609
+ readonly input: unknown;
610
+ readonly request: FoundryRequest;
611
+ readonly message: Message;
612
+ readonly messageInput: FoundryMessageInput;
613
+ readonly messageText: string;
614
+ readonly history: ReadonlyArray<Message>;
615
+ readonly messages: ReadonlyArray<Message>;
616
+ readonly glove: IGloveRunnable;
617
+ readonly store: StoreAdapter;
618
+ readonly emit: (event: {
619
+ type: string;
620
+ data?: unknown;
621
+ }) => void;
535
622
  }
536
- interface CustomProvisioningContext {
537
- readonly subscription: PlaybookSubscription;
538
- readonly target: PlaybookSubscriptionTarget;
539
- readonly route: InboundRoute;
540
- readonly eventId: string;
541
- readonly eventName: string;
542
- readonly threadKey: string;
543
- readonly event: unknown;
623
+ interface AgentInstallContext<TConfig = unknown> extends AgentMountBaseContext {
624
+ readonly installation: AgentInstallation;
625
+ readonly config: TConfig;
626
+ readonly accountId?: string;
627
+ readonly withAccountSession?: <A>(operation: string, use: (session: unknown) => Effect.Effect<A, unknown, never>) => Effect.Effect<A, unknown, never>;
544
628
  }
545
- interface CustomProvisionedAgent extends CreateAgentInstanceOptions {
546
- /** Stable uniqueness key; the data adapter enforces it atomically. */
547
- readonly provisioningKey: string;
629
+ interface AgentDefinitionSurfaceContext extends AgentMountBaseContext {
630
+ readonly surface: {
631
+ readonly kind: "memory";
632
+ readonly id: string;
633
+ };
634
+ readonly config: unknown;
548
635
  }
549
- interface FoundryInstanceProvisioner {
550
- readonly identifier: string;
551
- provision(adapter: string, context: CustomProvisioningContext): Effect.Effect<ReadonlyArray<CustomProvisionedAgent>, unknown, never>;
636
+ /** Pure application-definition context. It deliberately exposes no Glove. */
637
+ type AgentApplicationInstallContext<TConfig = unknown> = Omit<AgentInstallContext<TConfig>, "glove" | "store">;
638
+ interface AgentApplicationContribution {
639
+ /** Tools Foundry will mount after the installer returns. */
640
+ readonly tools?: ReadonlyArray<GloveFoldArgs<any>>;
552
641
  }
553
- declare function definePlaybookSubscription(options: DefinePlaybookSubscriptionOptions): PlaybookSubscription;
554
- /** Rehydrate the value-only representation returned by a durable adapter. */
555
- declare function reconstructPlaybookSubscription(subscription: PlaybookSubscription): PlaybookSubscription;
556
-
557
- declare const FOUNDRY_SCHEDULE_BRAND: unique symbol;
558
- type FoundryScheduleTimingInput = {
559
- readonly kind: "at";
560
- readonly at: string;
561
- } | {
562
- readonly kind: "after";
563
- readonly duration: string;
564
- } | {
565
- readonly kind: "every";
566
- readonly interval: string;
567
- } | {
568
- readonly kind: "cron";
569
- readonly expression: string;
570
- readonly timezone?: string;
571
- };
572
- type FoundryScheduleTiming = {
573
- readonly kind: "at";
574
- readonly at: string;
575
- } | {
576
- readonly kind: "every";
577
- readonly intervalMs: number;
642
+ interface ConfiguredCapability<TConfigSchema extends z.ZodType | undefined = z.ZodType | undefined> {
643
+ /** @deprecated File-routed definitions derive identity from their filename. */
644
+ readonly id?: string;
645
+ readonly description: string;
646
+ readonly config?: TConfigSchema;
647
+ }
648
+ type SharedToolOptions<TInput = unknown, TConfigSchema extends z.ZodType | undefined = undefined> = ConfiguredCapability<TConfigSchema> & ({
649
+ readonly tool: GloveFoldArgs<TInput>;
650
+ readonly create?: never;
578
651
  } | {
579
- readonly kind: "cron";
580
- readonly expression: string;
581
- readonly timezone: string;
652
+ readonly tool?: never;
653
+ readonly create: (context: AgentInstallContext<TConfigSchema extends z.ZodType ? z.output<TConfigSchema> : unknown>) => Effect.Effect<GloveFoldArgs<TInput>, unknown, never>;
654
+ });
655
+ type FoundrySharedTool<TInput = unknown, TConfigSchema extends z.ZodType | undefined = any> = Readonly<SharedToolOptions<TInput, TConfigSchema>> & {
656
+ readonly id: string;
657
+ readonly [FOUNDRY_SHARED_TOOL_BRAND]: true;
582
658
  };
583
- interface DefineFoundryScheduleOptions {
584
- /** Stable semantic name within one agent definition. It is not a runtime id. */
659
+ declare function defineSharedTool<TInput, const TConfigSchema extends z.ZodType | undefined = undefined>(options: SharedToolOptions<TInput, TConfigSchema>): FoundrySharedTool<TInput, TConfigSchema>;
660
+ /** What an installed app does with one of its MCP server's tools. */
661
+ type FoundryAppToolDecision = "allow" | "ask" | "hide";
662
+ /** One tool on an app's MCP server, as the app's tool policy sees it. */
663
+ interface FoundryAppMcpTool {
664
+ /** The tool's name on the server. */
585
665
  readonly name: string;
586
666
  readonly description?: string;
587
- readonly message: string;
588
- readonly payload?: unknown;
589
- readonly timing: FoundryScheduleTimingInput;
590
- readonly enabled?: boolean;
591
- }
592
- type FoundryScheduleDefinition = Readonly<DefineFoundryScheduleOptions> & {
593
- readonly [FOUNDRY_SCHEDULE_BRAND]: true;
594
- };
595
- declare function defineSchedule(options: DefineFoundryScheduleOptions): FoundryScheduleDefinition;
596
- declare function isFoundrySchedule(value: unknown): value is FoundryScheduleDefinition;
597
-
598
- interface AgentInstance {
599
- readonly id: string;
600
- readonly definitionId: string;
601
- readonly workspaceId: string;
602
- /** Stable adapter-enforced key used by lazy subscription provisioning. */
603
- readonly provisioningKey?: string;
604
- readonly context: Readonly<Record<string, unknown>>;
605
- /** Persisted desired state. Definitions only provide the capability catalogue. */
606
- readonly installations: ReadonlyArray<AgentInstallation>;
607
- readonly playbooks: ReadonlyArray<AgentPlaybook>;
608
- readonly createdAt: string;
609
- readonly updatedAt: string;
610
- }
611
- interface Conversation {
612
- readonly id: string;
613
- readonly agentId: string;
614
- readonly workspaceId: string;
615
- readonly title?: string;
616
- readonly context: Readonly<Record<string, unknown>>;
617
- readonly createdAt: string;
618
- readonly updatedAt: string;
667
+ /** The server marks the tool read-only. */
668
+ readonly readOnly: boolean;
669
+ /** The server marks the tool destructive. */
670
+ readonly destructive: boolean;
619
671
  }
620
- interface WorkspaceEntry {
621
- readonly workspaceId: string;
622
- readonly key: string;
623
- readonly value: unknown;
624
- readonly updatedAt: string;
672
+ /**
673
+ * Back an app with an MCP server. The app stays the unit a person connects:
674
+ * the server's tools reach the agent through the app, opened with the
675
+ * installation's account and filtered by the app's tool policy.
676
+ */
677
+ interface FoundryAppMcp<TConfig = unknown> {
678
+ /** Where the server is: a static entry, or one resolved from the installation. */
679
+ readonly entry: McpCatalogueEntryWithoutId | ((context: AgentApplicationInstallContext<TConfig>) => McpCatalogueEntryWithoutId | Promise<McpCatalogueEntryWithoutId> | Effect.Effect<McpCatalogueEntryWithoutId, unknown, never>);
680
+ /**
681
+ * Turn the installation's account session into credentials for the
682
+ * connection: HTTP headers for an HTTP server, environment variables for a
683
+ * stdio one. It runs inside the agent's `accountSessions` boundary, so
684
+ * Foundry never holds the credential. Omit it for a server that needs none.
685
+ */
686
+ readonly auth?: (session: unknown, context: AgentApplicationInstallContext<TConfig>) => Record<string, string> | Promise<Record<string, string>>;
687
+ /**
688
+ * Decide each tool: run it, ask the person first, or leave it out. The
689
+ * default runs read-only tools and asks before everything else.
690
+ */
691
+ readonly tools?: (tool: FoundryAppMcpTool, context: AgentApplicationInstallContext<TConfig>) => FoundryAppToolDecision;
625
692
  }
626
- interface SharedInboxItem {
693
+ /** One installed app and the tools it mounted for this run. */
694
+ interface FoundryInstalledApp {
627
695
  readonly id: string;
628
- readonly workspaceId: string;
629
- readonly conversationId?: string;
630
- readonly agentId?: string;
631
- readonly topic: string;
632
- readonly payload: unknown;
633
- readonly status: "pending" | "resolved" | "dismissed";
634
- readonly createdAt: string;
635
- readonly updatedAt: string;
696
+ readonly description: string;
697
+ readonly accountId?: string;
698
+ /** The app's live tool names, with whether each only reads. */
699
+ readonly tools: ReadonlyArray<{
700
+ readonly name: string;
701
+ readonly readOnly?: boolean;
702
+ }>;
636
703
  }
637
- interface EnvironmentValue {
638
- readonly key: string;
639
- /** Secret values are deliberately never exposed through this primitive. */
640
- readonly value: unknown;
641
- readonly scope: "workspace" | "agent" | "conversation";
642
- readonly workspaceId: string;
643
- readonly agentId?: string;
644
- readonly conversationId?: string;
704
+ interface AgentApplicationOptions<TConfigSchema extends z.ZodType | undefined = undefined> extends ConfiguredCapability<TConfigSchema> {
705
+ /** Tools from an MCP server, connected with the installation's account. */
706
+ readonly mcp?: FoundryAppMcp<TConfigSchema extends z.ZodType ? z.output<TConfigSchema> : unknown>;
707
+ /** Inbound transmission mechanisms owned by this application. */
708
+ readonly inbound?: ReadonlyArray<AnyFoundryTransmission>;
709
+ /** Outbound transmission mechanisms mounted as tools when installed. */
710
+ readonly outbound?: ReadonlyArray<AnyFoundryTransmission>;
711
+ /** Mixed/bidirectional definitions; prefer inbound/outbound for clarity. */
712
+ readonly transmissions?: ReadonlyArray<AnyFoundryTransmission>;
713
+ /** Purpose-built long-lived provider connections for inbound transmissions. */
714
+ readonly connections?: ReadonlyArray<FoundryApplicationConnection>;
715
+ readonly install?: (context: AgentApplicationInstallContext<TConfigSchema extends z.ZodType ? z.output<TConfigSchema> : unknown>) => Effect.Effect<AgentApplicationContribution | void, unknown, never>;
645
716
  }
646
- interface FoundryTask {
717
+ type FoundryAgentApplication<TConfigSchema extends z.ZodType | undefined = any> = Readonly<AgentApplicationOptions<TConfigSchema>> & {
647
718
  readonly id: string;
648
- readonly workspaceId: string;
649
- readonly agentId?: string;
650
- readonly conversationId?: string;
651
- readonly title: string;
652
- readonly detail?: string;
653
- readonly status: "open" | "in-progress" | "completed" | "cancelled";
654
- readonly createdAt: string;
655
- readonly updatedAt: string;
656
- }
657
- interface InboundDeliveryClaim {
658
- readonly key: string;
659
- readonly status: "pending" | "completed";
660
- readonly runIds: ReadonlyArray<string>;
661
- readonly claimedAt: string;
662
- readonly completedAt?: string;
719
+ readonly [FOUNDRY_AGENT_APPLICATION_BRAND]: true;
720
+ readonly restrictions?: AppRestrictions;
721
+ };
722
+ declare function defineAgentApplication<const TConfigSchema extends z.ZodType | undefined = undefined>(options: AgentApplicationOptions<TConfigSchema>): FoundryAgentApplication<TConfigSchema>;
723
+ /** Explicit allowlists. Omitted lists grant nothing; nested restrictions intersect. */
724
+ interface AppRestrictions {
725
+ readonly tools?: ReadonlyArray<string>;
726
+ readonly operations?: ReadonlyArray<string>;
727
+ readonly transmissions?: ReadonlyArray<string>;
728
+ }
729
+ /** A restricted view of the same app identity, usable in a catalogue or inheritance. */
730
+ declare function restrictApp<T extends FoundryAgentApplication>(app: T, restrictions: AppRestrictions): T;
731
+ /** Concise authoring name for an agent-local application definition. */
732
+ declare const defineApp: typeof defineAgentApplication;
733
+ type FoundryApp = FoundryAgentApplication;
734
+ interface FoundryMcpOptions<TConfigSchema extends z.ZodType | undefined = undefined> {
735
+ /** @deprecated File-routed definitions derive identity from their filename. */
736
+ readonly id?: string;
737
+ readonly description?: string;
738
+ readonly config?: TConfigSchema;
739
+ /**
740
+ * Static catalogue metadata or a lazy, instance-configured resolver.
741
+ *
742
+ * The resolver receives decoded installation data but never credentials.
743
+ * Auth remains the responsibility of the agent-owned `mcpAdapter` and is
744
+ * resolved only when glove-mcp opens a connection.
745
+ */
746
+ readonly entry: McpCatalogueEntryWithoutId | ((context: AgentApplicationInstallContext<TConfigSchema extends z.ZodType ? z.output<TConfigSchema> : unknown>) => McpCatalogueEntryWithoutId | Promise<McpCatalogueEntryWithoutId> | Effect.Effect<McpCatalogueEntryWithoutId, unknown, never>);
663
747
  }
664
- /**
665
- * An inbound event handed to one agent and not yet finished with: kept from
666
- * dispatch until the run that handles it settles, so a restart delivers it
667
- * again instead of losing it with the in-memory run queue.
668
- */
669
- interface FoundryPendingInbound {
670
- /** `<routeId>:<eventId>:<agentId>`. */
748
+ type McpCatalogueEntryWithoutId = McpCatalogueEntry extends infer Entry ? Entry extends unknown ? Omit<Entry, "id"> : never : never;
749
+ type FoundryMcp<TConfigSchema extends z.ZodType | undefined = any> = Readonly<FoundryMcpOptions<TConfigSchema>> & {
671
750
  readonly id: string;
672
- readonly definitionId: string;
673
- /** The request a run for this event starts from. */
674
- readonly request: FoundryRequest;
675
- /** The run handling it now; absent while the event waits for its conversation. */
676
- readonly runId?: string;
677
- readonly createdAt: string;
751
+ readonly [FOUNDRY_MCP_BRAND]: true;
752
+ };
753
+ declare function defineMcp<const TConfigSchema extends z.ZodType | undefined = undefined>(options: FoundryMcpOptions<TConfigSchema>): FoundryMcp<TConfigSchema>;
754
+ type MemoryAdapterFactory<A> = (context: AgentDefinitionSurfaceContext) => Effect.Effect<A, unknown, never>;
755
+ interface MemorySurfaceOptions {
756
+ readonly access?: "reader" | "curator";
757
+ readonly tools?: MemoryToolOptions["tools"];
678
758
  }
679
- interface FoundryWorkingEnvironmentSnapshotOwner {
680
- readonly scope: "agent" | "conversation";
681
- readonly definitionId: string;
682
- readonly agentId: string;
683
- readonly conversationId: string;
684
- readonly workspaceId: string;
759
+ interface FoundryMemoryProfileOptions<TConfigSchema extends z.ZodType | undefined = undefined> extends ConfiguredCapability<TConfigSchema> {
760
+ readonly entity?: MemorySurfaceOptions & {
761
+ readonly adapter: MemoryAdapterFactory<EntityMemoryAdapter>;
762
+ };
763
+ readonly episodic?: MemorySurfaceOptions & {
764
+ readonly adapter: MemoryAdapterFactory<EpisodicMemoryAdapter>;
765
+ };
766
+ readonly resources?: MemorySurfaceOptions & {
767
+ readonly adapter: MemoryAdapterFactory<ResourceFsAdapter>;
768
+ };
769
+ /** Ambient context remains on the main agent, matching glove-memory. */
770
+ readonly context?: {
771
+ readonly adapter: MemoryAdapterFactory<ContextAdapter>;
772
+ readonly tools?: MemoryToolOptions["tools"];
773
+ };
774
+ /** Escape hatch for subagent-delegated or application-specific composition. */
775
+ readonly mount?: (context: AgentDefinitionSurfaceContext) => Effect.Effect<void, unknown, never>;
685
776
  }
686
- /**
687
- * Adapter-backed runtime data created by Foundry's scheduling and sleep tools.
688
- * This is reconstructed state, never a file-authored definition primitive.
689
- */
690
- interface FoundryActivationRecord {
777
+ type FoundryMemoryProfile<TConfigSchema extends z.ZodType | undefined = any> = Readonly<FoundryMemoryProfileOptions<TConfigSchema>> & {
691
778
  readonly id: string;
692
- readonly kind: "scheduled" | "sleep";
693
- readonly definitionId: string;
694
- readonly agentId: string;
695
- readonly conversationId: string;
696
- readonly workspaceId: string;
697
- readonly message: string;
698
- readonly payload?: unknown;
699
- readonly timing: FoundryScheduleTiming;
700
- readonly origin: "agent-definition" | "agent-tool";
701
- readonly scheduleName?: string;
702
- /** Hash of the last reconciled definition value; runtime edits remain overrides. */
703
- readonly definitionRevision?: string;
704
- readonly status: "pending" | "active" | "paused" | "completed" | "cancelled";
705
- readonly createdByRunId: string;
706
- readonly lastRunId?: string;
707
- readonly createdAt: string;
708
- readonly updatedAt: string;
779
+ readonly [FOUNDRY_MEMORY_BRAND]: true;
780
+ };
781
+ declare function defineMemory<const TConfigSchema extends z.ZodType | undefined = undefined>(options: FoundryMemoryProfileOptions<TConfigSchema>): FoundryMemoryProfile<TConfigSchema>;
782
+ interface FoundryCapabilityRegistry {
783
+ readonly tools: ReadonlyArray<FoundrySharedTool<any>>;
784
+ readonly applications: ReadonlyArray<FoundryAgentApplication>;
785
+ readonly mcp: ReadonlyArray<FoundryMcp>;
786
+ readonly memory: ReadonlyArray<FoundryMemoryProfile>;
709
787
  }
710
- interface FoundryDataAdapter {
788
+ interface FoundryCapabilityManifestEntry {
789
+ readonly id: string;
790
+ readonly kind: FoundryCapabilityKind;
791
+ readonly description: string;
792
+ readonly ownership: "instance" | "definition";
793
+ readonly file?: string;
794
+ }
795
+ interface FoundryCapabilityManifest {
796
+ readonly tools: ReadonlyArray<FoundryCapabilityManifestEntry>;
797
+ readonly applications: ReadonlyArray<FoundryCapabilityManifestEntry>;
798
+ readonly mcp: ReadonlyArray<FoundryCapabilityManifestEntry>;
799
+ readonly memory: ReadonlyArray<FoundryCapabilityManifestEntry>;
800
+ }
801
+ declare const EMPTY_CAPABILITY_REGISTRY: FoundryCapabilityRegistry;
802
+ interface McpAdapterFactory {
803
+ (context: Omit<AgentInstallContext, "installation" | "config"> & {
804
+ readonly installed: ReadonlyArray<FoundryMcp>;
805
+ /** Fully decoded, per-instance MCP selections for this assembly. */
806
+ readonly resolved: ReadonlyArray<FoundryResolvedMcp>;
807
+ }): Effect.Effect<McpAdapter, unknown, never>;
808
+ }
809
+ interface FoundryResolvedMcp {
810
+ readonly definition: FoundryMcp;
811
+ readonly installation: AgentInstallation;
812
+ readonly config: unknown;
813
+ readonly entry: McpCatalogueEntry;
814
+ }
815
+ declare function isInboxCapableStore(store: StoreAdapter): store is StoreAdapter & Required<Pick<StoreAdapter, "getInboxItems" | "addInboxItem" | "updateInboxItem" | "getResolvedInboxItems">>;
816
+ interface FoundryMemoryReference<TProfile extends FoundryMemoryProfile<any> = FoundryMemoryProfile<any>> {
817
+ readonly profile: TProfile;
818
+ readonly config: DefinitionConfigInput<TProfile>;
819
+ }
820
+ type FoundryMemorySelection = FoundryMemoryProfile | FoundryMemoryReference;
821
+ /** Select a configured memory profile with schema-inferred input. */
822
+ declare function configureMemory<TProfile extends FoundryMemoryProfile<any>>(profile: TProfile, config: DefinitionConfigInput<TProfile>): FoundryMemoryReference<TProfile>;
823
+ interface MountAgentDefinitionMemoryOptions {
824
+ readonly registry: FoundryCapabilityRegistry;
825
+ readonly memory: ReadonlyArray<FoundryMemorySelection>;
826
+ readonly context: Omit<AgentDefinitionSurfaceContext, "surface" | "config">;
827
+ }
828
+ /** Mount definition-owned memory surfaces for one assembled run. */
829
+ declare function mountAgentDefinitionMemory(options: MountAgentDefinitionMemoryOptions): Effect.Effect<void, unknown, never>;
830
+ interface InstallRegistryOptions {
831
+ /** Revalidate borrowed installation authority before each tool/session operation. */
832
+ readonly authorizeInstallation?: (installation: AgentInstallation) => Effect.Effect<void, unknown, never>;
833
+ readonly registry: FoundryCapabilityRegistry;
834
+ readonly installations: ReadonlyArray<AgentInstallation>;
835
+ readonly context: Omit<AgentInstallContext, "installation" | "config">;
836
+ readonly mcpAdapter?: McpAdapterFactory;
837
+ readonly accountSessions?: FoundryAccountSessionAdapter;
838
+ /** Receives each installed app and its tools. */
839
+ readonly onApp?: (app: FoundryInstalledApp) => void;
840
+ /** Receives work to do when the run ends, such as closing app connections. */
841
+ readonly onCleanup?: (cleanup: () => Promise<void>) => void;
842
+ }
843
+ interface FoundryAccountSessionAdapter {
711
844
  readonly identifier: string;
712
- getAgent(id: string): Effect.Effect<AgentInstance | null, unknown, never>;
713
- putAgent(agent: AgentInstance): Effect.Effect<void, unknown, never>;
714
- listAgents(definitionId?: string): Effect.Effect<ReadonlyArray<AgentInstance>, unknown, never>;
715
- provisionAgent(input: ProvisionAgentOptions): Effect.Effect<AgentInstance, unknown, never>;
716
- getPlaybookSubscription(id: string): Effect.Effect<PlaybookSubscription | null, unknown, never>;
717
- putPlaybookSubscription(subscription: PlaybookSubscription): Effect.Effect<void, unknown, never>;
718
- deletePlaybookSubscription(id: string): Effect.Effect<boolean, unknown, never>;
719
- listPlaybookSubscriptions(workspaceId?: string): Effect.Effect<ReadonlyArray<PlaybookSubscription>, unknown, never>;
720
- getInboundDelivery(key: string): Effect.Effect<InboundDeliveryClaim | null, unknown, never>;
721
- claimInboundDelivery(key: string): Effect.Effect<boolean, unknown, never>;
722
- completeInboundDelivery(key: string, runIds: ReadonlyArray<string>): Effect.Effect<void, unknown, never>;
723
- releaseInboundDelivery(key: string): Effect.Effect<void, unknown, never>;
724
- /**
725
- * Pending inbound events (optional). With these, an inbound event survives
726
- * a restart until the run that handles it finishes; without them, an event
727
- * whose run was still queued or running when the process stopped is lost.
728
- */
729
- putPendingInbound?(record: FoundryPendingInbound): Effect.Effect<void, unknown, never>;
730
- deletePendingInbound?(id: string): Effect.Effect<void, unknown, never>;
731
- listPendingInbound?(): Effect.Effect<ReadonlyArray<FoundryPendingInbound>, unknown, never>;
732
- getActivation(id: string): Effect.Effect<FoundryActivationRecord | null, unknown, never>;
733
- putActivation(activation: FoundryActivationRecord): Effect.Effect<void, unknown, never>;
734
- listActivations(workspaceId?: string): Effect.Effect<ReadonlyArray<FoundryActivationRecord>, unknown, never>;
735
- getConversation(id: string): Effect.Effect<Conversation | null, unknown, never>;
736
- putConversation(conversation: Conversation): Effect.Effect<void, unknown, never>;
737
- listConversations(agentId: string): Effect.Effect<ReadonlyArray<Conversation>, unknown, never>;
738
- getWorkspaceEntry(workspaceId: string, key: string): Effect.Effect<WorkspaceEntry | null, unknown, never>;
739
- putWorkspaceEntry(entry: WorkspaceEntry): Effect.Effect<void, unknown, never>;
740
- /** Atomic optimistic update. null requires absence; updates must advance updatedAt. */
741
- compareAndSetWorkspaceEntry?(entry: WorkspaceEntry, expectedUpdatedAt: string | null): Effect.Effect<boolean, unknown, never>;
742
- listWorkspaceEntries(workspaceId: string): Effect.Effect<ReadonlyArray<WorkspaceEntry>, unknown, never>;
743
- /** Private VFS persistence; snapshots are never exposed as workspace entries. */
744
- getWorkingEnvironmentSnapshot(owner: FoundryWorkingEnvironmentSnapshotOwner): Effect.Effect<EnvSnapshot | null, unknown, never>;
745
- putWorkingEnvironmentSnapshot(owner: FoundryWorkingEnvironmentSnapshotOwner, snapshot: EnvSnapshot): Effect.Effect<void, unknown, never>;
746
- putInboxItem(item: SharedInboxItem): Effect.Effect<void, unknown, never>;
747
- listInboxItems(workspaceId: string): Effect.Effect<ReadonlyArray<SharedInboxItem>, unknown, never>;
748
- putTask(task: FoundryTask): Effect.Effect<void, unknown, never>;
749
- listTasks(workspaceId: string): Effect.Effect<ReadonlyArray<FoundryTask>, unknown, never>;
750
- listEnvironment(scope: {
845
+ withSession<A>(request: {
846
+ readonly accountId: string;
847
+ readonly operation: string;
848
+ readonly agentId: string;
849
+ readonly conversationId: string;
751
850
  readonly workspaceId: string;
752
- readonly agentId?: string;
753
- readonly conversationId?: string;
754
- }): Effect.Effect<ReadonlyArray<EnvironmentValue>, unknown, never>;
851
+ }, use: (session: unknown) => Effect.Effect<A, unknown, never>): Effect.Effect<A, unknown, never>;
755
852
  }
756
- /** The exact request shape accepted by `Glove.processRequest`. */
757
- type FoundryMessageInput = string | ReadonlyArray<ContentPart>;
758
- interface FoundryRequest {
853
+ /** Install only explicitly selected capabilities onto a running Glove. */
854
+ declare function installRegistry(options: InstallRegistryOptions): Effect.Effect<ReadonlyArray<AgentInstallation>, unknown, never>;
855
+ declare function isFoundryCapability(value: unknown): boolean;
856
+
857
+ declare const FOUNDRY_WORKING_ENVIRONMENT_BRAND: unique symbol;
858
+ declare const FOUNDRY_REPL_BRAND: unique symbol;
859
+ type FoundryVfs = Vfs;
860
+ type FoundryVfsHandle = EnvFsHandle;
861
+ interface FoundryWorkingEnvironmentPersistenceContext {
862
+ readonly definitionId: string;
759
863
  readonly agentId: string;
760
864
  readonly conversationId: string;
761
865
  readonly workspaceId: string;
762
- readonly message: FoundryMessageInput;
763
- readonly payload?: unknown;
764
- readonly context?: Readonly<Record<string, unknown>>;
765
- readonly source?: {
766
- readonly kind: "direct" | "transmission" | "activation" | "spawn" | "background" | "delegation";
767
- readonly id?: string;
768
- readonly provider?: string;
769
- readonly eventId?: string;
770
- readonly threadKey?: string;
771
- };
866
+ readonly runId: string;
867
+ readonly data: FoundryDataAdapter;
868
+ readonly signal: AbortSignal;
772
869
  }
773
870
  /**
774
- * Normalize Foundry's wire input into the native user `Message` seen by the
775
- * Glove loop. Lazy assembly happens before hooks run, so this intentionally
776
- * represents the unmodified inbound turn.
871
+ * Storage is deliberately adapter-owned. Foundry never chooses a database,
872
+ * object store, locking policy, or credential lifecycle for an environment.
777
873
  */
778
- declare function toGloveMessage(input: FoundryMessageInput): Message;
779
- /** Clone readonly request parts for Glove's mutable public input signature. */
780
- declare function toGloveRequestInput(input: FoundryMessageInput): string | ContentPart[];
781
- interface FoundryResult {
782
- readonly status: "completed" | "suspended";
783
- readonly value: unknown;
784
- readonly agentId: string;
785
- readonly conversationId: string;
786
- readonly workspaceId: string;
787
- readonly suspension?: FoundrySuspension;
874
+ interface FoundryWorkingEnvironmentPersistenceAdapter {
875
+ readonly identifier: string;
876
+ readonly load: (context: FoundryWorkingEnvironmentPersistenceContext) => Resolvable<EnvSnapshot | null>;
877
+ readonly save: (snapshot: EnvSnapshot, context: FoundryWorkingEnvironmentPersistenceContext) => Resolvable<void>;
788
878
  }
789
- /** Why a run ended without finishing: it went to sleep, or it asked a question. */
790
- type FoundrySuspension = {
791
- readonly kind?: "sleep";
792
- readonly commandId: string;
793
- readonly wakeAt: string;
794
- } | {
795
- readonly kind: "question";
796
- readonly commandId: string;
797
- readonly delegationId: string;
798
- readonly question: string;
799
- };
800
- interface CreateAgentInstanceOptions {
801
- readonly id?: string;
802
- readonly workspaceId?: string;
803
- readonly context?: Readonly<Record<string, unknown>>;
804
- readonly installations?: ReadonlyArray<AgentInstallation>;
805
- readonly playbooks?: ReadonlyArray<AgentPlaybook>;
806
- }
807
- interface ProvisionAgentOptions extends CreateAgentInstanceOptions {
808
- readonly definitionId: string;
809
- readonly provisioningKey: string;
810
- }
811
- interface UpdateAgentInstanceOptions {
812
- readonly context?: Readonly<Record<string, unknown>>;
813
- readonly installations?: ReadonlyArray<AgentInstallation>;
814
- readonly playbooks?: ReadonlyArray<AgentPlaybook>;
879
+ interface FoundryWorkingEnvironmentCreateContext {
880
+ readonly assembly: AgentAssemblyContext<FoundryRequest>;
881
+ readonly snapshot: EnvSnapshot | null;
815
882
  }
816
- interface CreateConversationOptions {
817
- readonly id?: string;
818
- readonly workspaceId?: string;
819
- readonly title?: string;
820
- readonly context?: Readonly<Record<string, unknown>>;
883
+ interface DefineFoundryWorkingEnvironmentOptions {
884
+ /**
885
+ * Build the native Glove environment. Use this when creation itself needs
886
+ * custom logic. The loaded snapshot is provided but never applied implicitly.
887
+ */
888
+ readonly create?: (context: FoundryWorkingEnvironmentCreateContext) => Resolvable<WorkingEnvironment>;
889
+ /**
890
+ * Native environment options. When persistence returns a snapshot and no
891
+ * filesystem is supplied, Foundry restores that snapshot automatically.
892
+ */
893
+ readonly options?: CreateWorkingEnvironmentOptions | ((context: FoundryWorkingEnvironmentCreateContext) => Resolvable<CreateWorkingEnvironmentOptions>);
894
+ readonly persistence?: FoundryWorkingEnvironmentPersistenceAdapter;
895
+ /** Native mount behavior: prompt priming and optional tool prefix. */
896
+ readonly mount?: Omit<MountWorkingEnvironmentConfig, "env">;
897
+ /** Close worker/adaptor resources after the run. Default true. */
898
+ readonly close?: boolean;
821
899
  }
822
- interface UpdateConversationOptions {
823
- readonly title?: string;
824
- readonly context?: Readonly<Record<string, unknown>>;
900
+ type FoundryWorkingEnvironmentDefinition = Readonly<DefineFoundryWorkingEnvironmentOptions> & {
901
+ readonly [FOUNDRY_WORKING_ENVIRONMENT_BRAND]: true;
902
+ };
903
+ declare function defineWorkingEnvironment(options?: DefineFoundryWorkingEnvironmentOptions): FoundryWorkingEnvironmentDefinition;
904
+ /**
905
+ * Convenience persistence over the configured FoundryDataAdapter's private
906
+ * snapshot seam. VFS contents never become public workspace entries.
907
+ * Scope "agent" (default) keeps one snapshot per instance, "conversation" one
908
+ * per conversation, and "workspace" one shared by every agent in the
909
+ * workspace. Saves replace the snapshot, so with "workspace" the last run to
910
+ * finish wins; give agents that write at the same time a live machine instead.
911
+ */
912
+ declare function foundryDataEnvironmentPersistence(options?: {
913
+ readonly scope?: "agent" | "conversation" | "workspace";
914
+ }): FoundryWorkingEnvironmentPersistenceAdapter;
915
+ interface FoundryReplBase {
916
+ readonly [FOUNDRY_REPL_BRAND]: true;
917
+ /**
918
+ * Project an explicit set of the fully assembled agent's tools into the
919
+ * sandbox as ordinary functions. Selection happens after applications,
920
+ * installed capabilities, memory, mesh, calls, and `configure` have mounted.
921
+ *
922
+ * Returning the actual tool values keeps code relationships referential;
923
+ * Foundry never accepts a second list of copied string ids here.
924
+ */
925
+ readonly programmaticTools?: FoundryProgrammaticTools;
825
926
  }
826
- declare class MemoryFoundryDataAdapter implements FoundryDataAdapter {
827
- readonly identifier: string;
828
- private readonly agents;
829
- private readonly agentsByProvisioningKey;
830
- private readonly subscriptions;
831
- private readonly inboundDeliveries;
832
- private readonly pendingInbound;
833
- private readonly activations;
834
- private readonly conversations;
835
- private readonly workspace;
836
- private readonly workingEnvironments;
837
- private readonly inbox;
838
- private readonly tasks;
839
- private readonly environment;
840
- private pendingAgents;
841
- private pendingSubscriptions;
842
- constructor(options?: {
843
- readonly identifier?: string;
844
- readonly environment?: ReadonlyArray<EnvironmentValue>;
845
- readonly agents?: ReadonlyArray<AgentInstance>;
846
- readonly conversations?: ReadonlyArray<Conversation>;
847
- readonly subscriptions?: ReadonlyArray<PlaybookSubscription>;
848
- readonly activations?: ReadonlyArray<FoundryActivationRecord>;
849
- });
850
- /** Resolve file-owned identities only after Foundry discovery has bound them. */
851
- private materializeSeeds;
852
- getAgent(id: string): Effect.Effect<AgentInstance | null, never, never>;
853
- putAgent(agent: AgentInstance): Effect.Effect<void, never, never>;
854
- listAgents(definitionId?: string): Effect.Effect<AgentInstance[], never, never>;
855
- provisionAgent(input: ProvisionAgentOptions): Effect.Effect<AgentInstance, never, never>;
856
- getPlaybookSubscription(id: string): Effect.Effect<PlaybookSubscription | null, never, never>;
857
- putPlaybookSubscription(subscription: PlaybookSubscription): Effect.Effect<void, never, never>;
858
- deletePlaybookSubscription(id: string): Effect.Effect<boolean, never, never>;
859
- listPlaybookSubscriptions(workspaceId?: string): Effect.Effect<PlaybookSubscription[], never, never>;
860
- getInboundDelivery(key: string): Effect.Effect<InboundDeliveryClaim | null, never, never>;
861
- claimInboundDelivery(key: string): Effect.Effect<boolean, never, never>;
862
- completeInboundDelivery(key: string, runIds: ReadonlyArray<string>): Effect.Effect<void, never, never>;
863
- releaseInboundDelivery(key: string): Effect.Effect<void, never, never>;
864
- putPendingInbound(record: FoundryPendingInbound): Effect.Effect<void, never, never>;
865
- deletePendingInbound(id: string): Effect.Effect<void, never, never>;
866
- listPendingInbound(): Effect.Effect<FoundryPendingInbound[], never, never>;
867
- getActivation(id: string): Effect.Effect<FoundryActivationRecord | null, never, never>;
868
- putActivation(activation: FoundryActivationRecord): Effect.Effect<void, never, never>;
869
- listActivations(workspaceId?: string): Effect.Effect<FoundryActivationRecord[], never, never>;
870
- getConversation(id: string): Effect.Effect<Conversation | null, never, never>;
871
- putConversation(conversation: Conversation): Effect.Effect<void, never, never>;
872
- listConversations(agentId: string): Effect.Effect<Conversation[], never, never>;
873
- getWorkspaceEntry(workspaceId: string, key: string): Effect.Effect<WorkspaceEntry | null, never, never>;
874
- putWorkspaceEntry(entry: WorkspaceEntry): Effect.Effect<void, never, never>;
875
- compareAndSetWorkspaceEntry(entry: WorkspaceEntry, expectedUpdatedAt: string | null): Effect.Effect<boolean, never, never>;
876
- listWorkspaceEntries(workspaceId: string): Effect.Effect<WorkspaceEntry[], never, never>;
877
- getWorkingEnvironmentSnapshot(owner: FoundryWorkingEnvironmentSnapshotOwner): Effect.Effect<EnvSnapshot | null, never, never>;
878
- putWorkingEnvironmentSnapshot(owner: FoundryWorkingEnvironmentSnapshotOwner, snapshot: EnvSnapshot): Effect.Effect<void, never, never>;
879
- putInboxItem(item: SharedInboxItem): Effect.Effect<void, never, never>;
880
- listInboxItems(workspaceId: string): Effect.Effect<SharedInboxItem[], never, never>;
881
- putTask(task: FoundryTask): Effect.Effect<void, never, never>;
882
- listTasks(workspaceId: string): Effect.Effect<FoundryTask[], never, never>;
883
- listEnvironment(scope: {
884
- readonly workspaceId: string;
885
- readonly agentId?: string;
886
- readonly conversationId?: string;
887
- }): Effect.Effect<EnvironmentValue[], never, never>;
927
+ interface FoundryProgrammaticToolSelection {
928
+ /** One of the exact live tools supplied to the selector context. */
929
+ readonly tool: Tool<unknown>;
930
+ /** Optional valid interpreter identifier when the tool name is unsuitable. */
931
+ readonly name?: string;
932
+ /** Informational effect hint used by capability discovery. */
933
+ readonly readOnly?: boolean;
934
+ /** Optional capability group used by progressive discovery. */
935
+ readonly server?: string;
936
+ readonly serverDescription?: string;
937
+ readonly resultShape?: string;
888
938
  }
889
- declare function createAgentInstance(definitionId: string, options?: CreateAgentInstanceOptions, provisioningKey?: string): AgentInstance;
890
- /** Code-authoring helper; instance data stores the referenced definition id. */
891
- declare function defineAgentInstance(definition: FoundryAgentDefinition, options?: CreateAgentInstanceOptions): AgentInstance;
892
- /** Rehydrate a durable adapter record into Foundry's immutable runtime shape. */
893
- declare function reconstructAgentInstance(agent: AgentInstance): AgentInstance;
894
- declare function createConversation(agent: AgentInstance, options?: CreateConversationOptions): Conversation;
895
-
896
- declare const FOUNDRY_SHARED_TOOL_BRAND: unique symbol;
897
- declare const FOUNDRY_AGENT_APPLICATION_BRAND: unique symbol;
898
- declare const FOUNDRY_MCP_BRAND: unique symbol;
899
- declare const FOUNDRY_MEMORY_BRAND: unique symbol;
900
- type AgentInstallationKind = "tool" | "application" | "mcp";
901
- type FoundryCapabilityKind = AgentInstallationKind | "memory";
902
- interface AgentInstallation {
903
- readonly kind: AgentInstallationKind;
939
+ /** An installed app, with its live tools ready to select into the REPL. */
940
+ interface FoundryReplApp {
904
941
  readonly id: string;
905
- /** Durable account selection; code authoring supplies this through an AccountReference. */
942
+ readonly description: string;
906
943
  readonly accountId?: string;
907
- readonly config?: unknown;
944
+ /** Each tool grouped under the app, named for code, and marked when it only reads. */
945
+ readonly tools: ReadonlyArray<FoundryProgrammaticToolSelection>;
908
946
  }
909
- type FoundryInstallable = FoundrySharedTool<any> | FoundryAgentApplication | FoundryMcp;
910
- /** Create persisted installation data from a code definition. */
911
- type DefinitionConfigInput<TDefinition> = TDefinition extends {
912
- readonly config?: infer TSchema;
913
- } ? TSchema extends z.ZodType ? z.input<TSchema> : never : never;
914
- interface InstallationSelection {
915
- readonly account?: AccountReference;
947
+ interface FoundryProgrammaticToolContext {
948
+ readonly assembly: AgentAssemblyContext<FoundryRequest>;
949
+ readonly glove: IGloveRunnable;
950
+ /** Snapshot of every tool mounted before the programmatic surface itself. */
951
+ readonly tools: ReadonlyArray<Tool<unknown>>;
952
+ /** The apps installed on this agent, one group per app. */
953
+ readonly apps: ReadonlyArray<FoundryReplApp>;
954
+ readonly workingEnvironment?: WorkingEnvironment;
955
+ readonly vfs?: EnvFsHandle;
916
956
  }
917
- declare function install<TDefinition extends FoundryInstallable>(capability: TDefinition, ...configuration: [DefinitionConfigInput<TDefinition>] extends [never] ? [config?: never, selection?: InstallationSelection] : [config: DefinitionConfigInput<TDefinition>, selection?: InstallationSelection]): AgentInstallation;
918
- declare function installationKey(installation: AgentInstallation): string;
919
- interface AgentMountBaseContext {
957
+ interface FoundryProgrammaticTools {
958
+ /**
959
+ * Select direct live tool references. A selection may decorate its callable
960
+ * name and discovery metadata without replacing the underlying capability.
961
+ */
962
+ readonly select: (context: FoundryProgrammaticToolContext) => Resolvable<ReadonlyArray<Tool<unknown> | FoundryProgrammaticToolSelection>>;
963
+ /** Total underlying calls permitted during this assembled run. Default 50. */
964
+ readonly maxCalls?: number;
965
+ /**
966
+ * Keep selected tools in the model's direct tool list as well. Default true.
967
+ * Pass false to reach them only from code, which keeps a large app
968
+ * catalogue out of context. A tool that needs approval always stays direct.
969
+ */
970
+ readonly keepDirect?: boolean;
971
+ }
972
+ type FoundryJavaScriptReplDefinition = FoundryReplBase & Readonly<{
973
+ readonly language: "javascript";
974
+ readonly session: JsSession;
975
+ readonly mount?: Omit<MountJsConfig, "session">;
976
+ }>;
977
+ type FoundryPythonReplDefinition = FoundryReplBase & Readonly<{
978
+ readonly language: "python";
979
+ readonly session: PySession;
980
+ readonly mount?: Omit<MountPyConfig, "session">;
981
+ }>;
982
+ type FoundryLispReplDefinition = FoundryReplBase & Readonly<{
983
+ readonly language: "lisp";
984
+ readonly session: LispSession;
985
+ readonly mount?: Omit<MountLispConfig, "session">;
986
+ }>;
987
+ type FoundryReplDefinition = FoundryJavaScriptReplDefinition | FoundryPythonReplDefinition | FoundryLispReplDefinition;
988
+ type DefineFoundryReplOptions = Omit<FoundryJavaScriptReplDefinition, typeof FOUNDRY_REPL_BRAND> | Omit<FoundryPythonReplDefinition, typeof FOUNDRY_REPL_BRAND> | Omit<FoundryLispReplDefinition, typeof FOUNDRY_REPL_BRAND>;
989
+ declare function defineRepl(options: DefineFoundryReplOptions): FoundryReplDefinition;
990
+ type FoundryMountedRepl = Readonly<{
991
+ readonly language: "javascript";
992
+ readonly session: JsSession;
993
+ }> | Readonly<{
994
+ readonly language: "python";
995
+ readonly session: PySession;
996
+ }> | Readonly<{
997
+ readonly language: "lisp";
998
+ readonly session: LispSession;
999
+ }>;
1000
+
1001
+ declare const FOUNDRY_LAYER_BRAND: unique symbol;
1002
+ declare const FOUNDRY_SUBSCRIBER_BRAND: unique symbol;
1003
+ interface FoundrySurfaceContext<TInput = unknown> {
920
1004
  readonly definitionId: string;
921
1005
  readonly agentId: string;
922
1006
  readonly conversationId: string;
923
1007
  readonly workspaceId: string;
924
1008
  readonly runId: string;
925
- readonly input: unknown;
1009
+ readonly input: TInput;
926
1010
  readonly request: FoundryRequest;
927
1011
  readonly message: Message;
928
1012
  readonly messageInput: FoundryMessageInput;
@@ -930,535 +1014,260 @@ interface AgentMountBaseContext {
930
1014
  readonly history: ReadonlyArray<Message>;
931
1015
  readonly messages: ReadonlyArray<Message>;
932
1016
  readonly glove: IGloveRunnable;
933
- readonly store: StoreAdapter;
1017
+ readonly workingEnvironment?: WorkingEnvironment;
1018
+ readonly vfs?: FoundryVfsHandle;
1019
+ readonly repl?: FoundryMountedRepl;
1020
+ readonly signal: AbortSignal;
934
1021
  readonly emit: (event: {
935
1022
  type: string;
936
1023
  data?: unknown;
937
1024
  }) => void;
938
1025
  }
939
- interface AgentInstallContext<TConfig = unknown> extends AgentMountBaseContext {
940
- readonly installation: AgentInstallation;
941
- readonly config: TConfig;
942
- readonly accountId?: string;
943
- readonly withAccountSession?: <A>(operation: string, use: (session: unknown) => Effect.Effect<A, unknown, never>) => Effect.Effect<A, unknown, never>;
944
- }
945
- interface AgentDefinitionSurfaceContext extends AgentMountBaseContext {
946
- readonly surface: {
947
- readonly kind: "memory";
948
- readonly id: string;
949
- };
950
- readonly config: unknown;
951
- }
952
- /** Pure application-definition context. It deliberately exposes no Glove. */
953
- type AgentApplicationInstallContext<TConfig = unknown> = Omit<AgentInstallContext<TConfig>, "glove" | "store">;
954
- interface AgentApplicationContribution {
955
- /** Tools Foundry will mount after the installer returns. */
956
- readonly tools?: ReadonlyArray<GloveFoldArgs<any>>;
957
- }
958
- interface ConfiguredCapability<TConfigSchema extends z.ZodType | undefined = z.ZodType | undefined> {
1026
+ type FoundrySurfaceCleanup = () => void | Promise<void> | Effect.Effect<void, unknown, never>;
1027
+ interface FoundryLayerOptions<TConfigSchema extends z.ZodType | undefined = undefined> {
959
1028
  /** @deprecated File-routed definitions derive identity from their filename. */
960
1029
  readonly id?: string;
961
1030
  readonly description: string;
962
1031
  readonly config?: TConfigSchema;
1032
+ /**
1033
+ * Mount any Glove-native package or application concern onto the compiled
1034
+ * runnable. Mesh, memory subagent composition, scratchpads, image surfaces,
1035
+ * voice bridges and future Glove packages all fit through this seam.
1036
+ */
1037
+ readonly setup: (context: FoundrySurfaceContext & {
1038
+ readonly config: TConfigSchema extends z.ZodType ? z.output<TConfigSchema> : unknown;
1039
+ }) => Effect.Effect<void | FoundrySurfaceCleanup, unknown, never>;
963
1040
  }
964
- type SharedToolOptions<TInput = unknown, TConfigSchema extends z.ZodType | undefined = undefined> = ConfiguredCapability<TConfigSchema> & ({
965
- readonly tool: GloveFoldArgs<TInput>;
966
- readonly create?: never;
967
- } | {
968
- readonly tool?: never;
969
- readonly create: (context: AgentInstallContext<TConfigSchema extends z.ZodType ? z.output<TConfigSchema> : unknown>) => Effect.Effect<GloveFoldArgs<TInput>, unknown, never>;
970
- });
971
- type FoundrySharedTool<TInput = unknown, TConfigSchema extends z.ZodType | undefined = any> = Readonly<SharedToolOptions<TInput, TConfigSchema>> & {
1041
+ type FoundryLayer<TConfigSchema extends z.ZodType | undefined = undefined> = Readonly<FoundryLayerOptions<TConfigSchema>> & {
972
1042
  readonly id: string;
973
- readonly [FOUNDRY_SHARED_TOOL_BRAND]: true;
1043
+ readonly [FOUNDRY_LAYER_BRAND]: true;
974
1044
  };
975
- declare function defineSharedTool<TInput, const TConfigSchema extends z.ZodType | undefined = undefined>(options: SharedToolOptions<TInput, TConfigSchema>): FoundrySharedTool<TInput, TConfigSchema>;
976
- interface AgentApplicationOptions<TConfigSchema extends z.ZodType | undefined = undefined> extends ConfiguredCapability<TConfigSchema> {
977
- /** Inbound transmission mechanisms owned by this application. */
978
- readonly inbound?: ReadonlyArray<AnyFoundryTransmission>;
979
- /** Outbound transmission mechanisms mounted as tools when installed. */
980
- readonly outbound?: ReadonlyArray<AnyFoundryTransmission>;
981
- /** Mixed/bidirectional definitions; prefer inbound/outbound for clarity. */
982
- readonly transmissions?: ReadonlyArray<AnyFoundryTransmission>;
983
- /** Purpose-built long-lived provider connections for inbound transmissions. */
984
- readonly connections?: ReadonlyArray<FoundryApplicationConnection>;
985
- readonly install?: (context: AgentApplicationInstallContext<TConfigSchema extends z.ZodType ? z.output<TConfigSchema> : unknown>) => Effect.Effect<AgentApplicationContribution | void, unknown, never>;
1045
+ declare function defineLayer<TConfigSchema extends z.ZodType | undefined = undefined>(options: FoundryLayerOptions<TConfigSchema>): FoundryLayer<TConfigSchema>;
1046
+ interface FoundryLayerReference<TLayer extends FoundryLayer<any> = FoundryLayer<any>> {
1047
+ readonly layer: TLayer;
1048
+ readonly config?: TLayer extends FoundryLayer<infer TSchema> ? TSchema extends z.ZodType ? z.input<TSchema> : never : never;
986
1049
  }
987
- type FoundryAgentApplication<TConfigSchema extends z.ZodType | undefined = any> = Readonly<AgentApplicationOptions<TConfigSchema>> & {
988
- readonly id: string;
989
- readonly [FOUNDRY_AGENT_APPLICATION_BRAND]: true;
990
- };
991
- declare function defineAgentApplication<const TConfigSchema extends z.ZodType | undefined = undefined>(options: AgentApplicationOptions<TConfigSchema>): FoundryAgentApplication<TConfigSchema>;
992
- /** Concise authoring name for an agent-local application definition. */
993
- declare const defineApp: typeof defineAgentApplication;
994
- type FoundryApp = FoundryAgentApplication;
995
- interface FoundryMcpOptions<TConfigSchema extends z.ZodType | undefined = undefined> {
1050
+ type FoundryLayerSelection = FoundryLayerReference<any> | FoundryLayer<any>;
1051
+ /** Select a configured layer with schema-inferred input. */
1052
+ declare function configureLayer<TLayer extends FoundryLayer<any>>(layer: TLayer, config: FoundryLayerReference<TLayer>["config"]): FoundryLayerReference<TLayer>;
1053
+ interface FoundrySubscriberOptions {
996
1054
  /** @deprecated File-routed definitions derive identity from their filename. */
997
1055
  readonly id?: string;
998
- readonly description?: string;
999
- readonly config?: TConfigSchema;
1000
- /**
1001
- * Static catalogue metadata or a lazy, instance-configured resolver.
1002
- *
1003
- * The resolver receives decoded installation data but never credentials.
1004
- * Auth remains the responsibility of the agent-owned `mcpAdapter` and is
1005
- * resolved only when glove-mcp opens a connection.
1006
- */
1007
- readonly entry: McpCatalogueEntryWithoutId | ((context: AgentApplicationInstallContext<TConfigSchema extends z.ZodType ? z.output<TConfigSchema> : unknown>) => McpCatalogueEntryWithoutId | Promise<McpCatalogueEntryWithoutId> | Effect.Effect<McpCatalogueEntryWithoutId, unknown, never>);
1008
- }
1009
- type McpCatalogueEntryWithoutId = McpCatalogueEntry extends infer Entry ? Entry extends unknown ? Omit<Entry, "id"> : never : never;
1010
- type FoundryMcp<TConfigSchema extends z.ZodType | undefined = any> = Readonly<FoundryMcpOptions<TConfigSchema>> & {
1011
- readonly id: string;
1012
- readonly [FOUNDRY_MCP_BRAND]: true;
1013
- };
1014
- declare function defineMcp<const TConfigSchema extends z.ZodType | undefined = undefined>(options: FoundryMcpOptions<TConfigSchema>): FoundryMcp<TConfigSchema>;
1015
- type MemoryAdapterFactory<A> = (context: AgentDefinitionSurfaceContext) => Effect.Effect<A, unknown, never>;
1016
- interface MemorySurfaceOptions {
1017
- readonly access?: "reader" | "curator";
1018
- readonly tools?: MemoryToolOptions["tools"];
1019
- }
1020
- interface FoundryMemoryProfileOptions<TConfigSchema extends z.ZodType | undefined = undefined> extends ConfiguredCapability<TConfigSchema> {
1021
- readonly entity?: MemorySurfaceOptions & {
1022
- readonly adapter: MemoryAdapterFactory<EntityMemoryAdapter>;
1023
- };
1024
- readonly episodic?: MemorySurfaceOptions & {
1025
- readonly adapter: MemoryAdapterFactory<EpisodicMemoryAdapter>;
1026
- };
1027
- readonly resources?: MemorySurfaceOptions & {
1028
- readonly adapter: MemoryAdapterFactory<ResourceFsAdapter>;
1029
- };
1030
- /** Ambient context remains on the main agent, matching glove-memory. */
1031
- readonly context?: {
1032
- readonly adapter: MemoryAdapterFactory<ContextAdapter>;
1033
- readonly tools?: MemoryToolOptions["tools"];
1034
- };
1035
- /** Escape hatch for subagent-delegated or application-specific composition. */
1036
- readonly mount?: (context: AgentDefinitionSurfaceContext) => Effect.Effect<void, unknown, never>;
1056
+ readonly description: string;
1057
+ readonly create: SubscriberAdapter | ((context: FoundrySurfaceContext) => SubscriberAdapter | Promise<SubscriberAdapter> | Effect.Effect<SubscriberAdapter, unknown, never>);
1037
1058
  }
1038
- type FoundryMemoryProfile<TConfigSchema extends z.ZodType | undefined = any> = Readonly<FoundryMemoryProfileOptions<TConfigSchema>> & {
1059
+ type FoundrySubscriber = Readonly<FoundrySubscriberOptions> & {
1039
1060
  readonly id: string;
1040
- readonly [FOUNDRY_MEMORY_BRAND]: true;
1061
+ readonly [FOUNDRY_SUBSCRIBER_BRAND]: true;
1041
1062
  };
1042
- declare function defineMemory<const TConfigSchema extends z.ZodType | undefined = undefined>(options: FoundryMemoryProfileOptions<TConfigSchema>): FoundryMemoryProfile<TConfigSchema>;
1043
- interface FoundryCapabilityRegistry {
1044
- readonly tools: ReadonlyArray<FoundrySharedTool<any>>;
1045
- readonly applications: ReadonlyArray<FoundryAgentApplication>;
1046
- readonly mcp: ReadonlyArray<FoundryMcp>;
1047
- readonly memory: ReadonlyArray<FoundryMemoryProfile>;
1063
+ declare function defineSubscriber(options: FoundrySubscriberOptions): FoundrySubscriber;
1064
+ type FoundrySubscriberSelection = FoundrySubscriber;
1065
+ interface FoundryNativeRegistry {
1066
+ readonly layers: ReadonlyArray<FoundryLayer<any>>;
1067
+ readonly subscribers: ReadonlyArray<FoundrySubscriber>;
1048
1068
  }
1049
- interface FoundryCapabilityManifestEntry {
1069
+ interface FoundryNativeManifestEntry {
1050
1070
  readonly id: string;
1051
- readonly kind: FoundryCapabilityKind;
1071
+ readonly kind: "layer" | "subscriber";
1052
1072
  readonly description: string;
1053
- readonly ownership: "instance" | "definition";
1054
1073
  readonly file?: string;
1055
1074
  }
1056
- interface FoundryCapabilityManifest {
1057
- readonly tools: ReadonlyArray<FoundryCapabilityManifestEntry>;
1058
- readonly applications: ReadonlyArray<FoundryCapabilityManifestEntry>;
1059
- readonly mcp: ReadonlyArray<FoundryCapabilityManifestEntry>;
1060
- readonly memory: ReadonlyArray<FoundryCapabilityManifestEntry>;
1061
- }
1062
- declare const EMPTY_CAPABILITY_REGISTRY: FoundryCapabilityRegistry;
1063
- interface McpAdapterFactory {
1064
- (context: Omit<AgentInstallContext, "installation" | "config"> & {
1065
- readonly installed: ReadonlyArray<FoundryMcp>;
1066
- /** Fully decoded, per-instance MCP selections for this assembly. */
1067
- readonly resolved: ReadonlyArray<FoundryResolvedMcp>;
1068
- }): Effect.Effect<McpAdapter, unknown, never>;
1069
- }
1070
- interface FoundryResolvedMcp {
1071
- readonly definition: FoundryMcp;
1072
- readonly installation: AgentInstallation;
1073
- readonly config: unknown;
1074
- readonly entry: McpCatalogueEntry;
1075
- }
1076
- declare function isInboxCapableStore(store: StoreAdapter): store is StoreAdapter & Required<Pick<StoreAdapter, "getInboxItems" | "addInboxItem" | "updateInboxItem" | "getResolvedInboxItems">>;
1077
- interface FoundryMemoryReference<TProfile extends FoundryMemoryProfile<any> = FoundryMemoryProfile<any>> {
1078
- readonly profile: TProfile;
1079
- readonly config: DefinitionConfigInput<TProfile>;
1080
- }
1081
- type FoundryMemorySelection = FoundryMemoryProfile | FoundryMemoryReference;
1082
- /** Select a configured memory profile with schema-inferred input. */
1083
- declare function configureMemory<TProfile extends FoundryMemoryProfile<any>>(profile: TProfile, config: DefinitionConfigInput<TProfile>): FoundryMemoryReference<TProfile>;
1084
- interface MountAgentDefinitionMemoryOptions {
1085
- readonly registry: FoundryCapabilityRegistry;
1086
- readonly memory: ReadonlyArray<FoundryMemorySelection>;
1087
- readonly context: Omit<AgentDefinitionSurfaceContext, "surface" | "config">;
1088
- }
1089
- /** Mount definition-owned memory surfaces for one assembled run. */
1090
- declare function mountAgentDefinitionMemory(options: MountAgentDefinitionMemoryOptions): Effect.Effect<void, unknown, never>;
1091
- interface InstallRegistryOptions {
1092
- readonly registry: FoundryCapabilityRegistry;
1093
- readonly installations: ReadonlyArray<AgentInstallation>;
1094
- readonly context: Omit<AgentInstallContext, "installation" | "config">;
1095
- readonly mcpAdapter?: McpAdapterFactory;
1096
- readonly accountSessions?: FoundryAccountSessionAdapter;
1097
- }
1098
- interface FoundryAccountSessionAdapter {
1099
- readonly identifier: string;
1100
- withSession<A>(request: {
1101
- readonly accountId: string;
1102
- readonly operation: string;
1103
- readonly agentId: string;
1104
- readonly conversationId: string;
1105
- readonly workspaceId: string;
1106
- }, use: (session: unknown) => Effect.Effect<A, unknown, never>): Effect.Effect<A, unknown, never>;
1075
+ interface FoundryNativeManifest {
1076
+ readonly layers: ReadonlyArray<FoundryNativeManifestEntry>;
1077
+ readonly subscribers: ReadonlyArray<FoundryNativeManifestEntry>;
1107
1078
  }
1108
- /** Install only explicitly selected capabilities onto a running Glove. */
1109
- declare function installRegistry(options: InstallRegistryOptions): Effect.Effect<ReadonlyArray<AgentInstallation>, unknown, never>;
1110
- declare function isFoundryCapability(value: unknown): boolean;
1079
+ declare const EMPTY_NATIVE_REGISTRY: FoundryNativeRegistry;
1080
+ declare function mountFoundrySurfaces(options: {
1081
+ readonly registry: FoundryNativeRegistry;
1082
+ readonly layers?: ReadonlyArray<FoundryLayerSelection>;
1083
+ readonly subscribers?: ReadonlyArray<FoundrySubscriberSelection | SubscriberAdapter>;
1084
+ readonly context: FoundrySurfaceContext;
1085
+ }): Promise<() => Promise<void>>;
1086
+ declare function isFoundryLayer(value: unknown): value is FoundryLayer;
1087
+ declare function isFoundrySubscriber(value: unknown): value is FoundrySubscriber;
1111
1088
 
1112
- declare const FOUNDRY_WORKING_ENVIRONMENT_BRAND: unique symbol;
1113
- declare const FOUNDRY_REPL_BRAND: unique symbol;
1114
- type FoundryVfs = Vfs;
1115
- type FoundryVfsHandle = EnvFsHandle;
1116
- interface FoundryWorkingEnvironmentPersistenceContext {
1117
- readonly definitionId: string;
1118
- readonly agentId: string;
1119
- readonly conversationId: string;
1120
- readonly workspaceId: string;
1121
- readonly runId: string;
1122
- readonly data: FoundryDataAdapter;
1123
- readonly signal: AbortSignal;
1124
- }
1089
+ type FoundryAgentComponent = FoundrySharedTool<any> | FoundryAgentApplication | FoundryMcp | FoundryMemoryProfile | FoundryLayer<any> | FoundrySubscriber;
1125
1090
  /**
1126
- * Storage is deliberately adapter-owned. Foundry never chooses a database,
1127
- * object store, locking policy, or credential lifecycle for an environment.
1091
+ * A colocated `*.tool.ts` may export the Glove tool body directly. Foundry
1092
+ * supplies the runtime tool name from the file route, so the authored module
1093
+ * never has to repeat its identity as a string.
1128
1094
  */
1129
- interface FoundryWorkingEnvironmentPersistenceAdapter {
1130
- readonly identifier: string;
1131
- readonly load: (context: FoundryWorkingEnvironmentPersistenceContext) => Resolvable<EnvSnapshot | null>;
1132
- readonly save: (snapshot: EnvSnapshot, context: FoundryWorkingEnvironmentPersistenceContext) => Resolvable<void>;
1133
- }
1134
- interface FoundryWorkingEnvironmentCreateContext {
1135
- readonly assembly: AgentAssemblyContext<FoundryRequest>;
1136
- readonly snapshot: EnvSnapshot | null;
1095
+ type FoundryToolBody = Omit<GloveFoldArgs<any>, "name">;
1096
+ interface FoundryAgentComposition {
1097
+ readonly capabilities: FoundryCapabilityRegistry;
1098
+ readonly native: FoundryNativeRegistry;
1137
1099
  }
1138
- interface DefineFoundryWorkingEnvironmentOptions {
1100
+ type FoundryCompositionSource = FoundryAgentComponent | FoundryToolBody | FoundryAgentComposition | ReadonlyArray<FoundryCompositionSource> | (() => FoundryCompositionSource) | false | null | undefined;
1101
+ /**
1102
+ * Compose colocated, headless agent parts into one immutable catalogue.
1103
+ * Functions are factories, not runtime installers: they return definitions and
1104
+ * never receive or mutate a Glove instance.
1105
+ */
1106
+ declare function composeAgent(...sources: ReadonlyArray<FoundryCompositionSource>): FoundryAgentComposition;
1107
+ declare const EMPTY_AGENT_COMPOSITION: FoundryAgentComposition;
1108
+
1109
+ /**
1110
+ * Put an agent on the mesh. Its peers are the other agent instances in its
1111
+ * workspace, found from data: a person's bots, a team's agents, whatever the
1112
+ * application created.
1113
+ */
1114
+ interface FoundryMeshOptions {
1139
1115
  /**
1140
- * Build the native Glove environment. Use this when creation itself needs
1141
- * custom logic. The loaded snapshot is provided but never applied implicitly.
1116
+ * Which agents this one may see and message, decided from data. Default:
1117
+ * every other agent in its workspace. An agent can always answer whoever
1118
+ * messaged it.
1142
1119
  */
1143
- readonly create?: (context: FoundryWorkingEnvironmentCreateContext) => Resolvable<WorkingEnvironment>;
1120
+ readonly peers?: (self: AgentInstance, peer: AgentInstance) => boolean;
1121
+ /** How long a blocking send waits in the same run for the reply. Default 90 s. */
1122
+ readonly waitMs?: number;
1144
1123
  /**
1145
- * Native environment options. When persistence returns a snapshot and no
1146
- * filesystem is supplied, Foundry restores that snapshot automatically.
1124
+ * Whether this run gets the mesh tools. Default: every run. Use it to keep a
1125
+ * run that must only read, such as scheduled research, from messaging anyone.
1147
1126
  */
1148
- readonly options?: CreateWorkingEnvironmentOptions | ((context: FoundryWorkingEnvironmentCreateContext) => Resolvable<CreateWorkingEnvironmentOptions>);
1149
- readonly persistence?: FoundryWorkingEnvironmentPersistenceAdapter;
1150
- /** Native mount behavior: prompt priming and optional tool prefix. */
1151
- readonly mount?: Omit<MountWorkingEnvironmentConfig, "env">;
1152
- /** Close worker/adaptor resources after the run. Default true. */
1153
- readonly close?: boolean;
1127
+ readonly mount?: (context: AgentAssemblyContext) => boolean;
1128
+ }
1129
+ /** How an agent appears to its peers: from its instance data. */
1130
+ declare function meshIdentity(agent: AgentInstance): AgentIdentity;
1131
+ type FoundryMeshThreadStatus = "working" | "waiting" | "replied" | "failed" | "cancelled";
1132
+ interface FoundryMeshParty {
1133
+ readonly agentId: string;
1134
+ readonly name: string;
1135
+ readonly definitionId: string;
1154
1136
  }
1155
- type FoundryWorkingEnvironmentDefinition = Readonly<DefineFoundryWorkingEnvironmentOptions> & {
1156
- readonly [FOUNDRY_WORKING_ENVIRONMENT_BRAND]: true;
1157
- };
1158
- declare function defineWorkingEnvironment(options?: DefineFoundryWorkingEnvironmentOptions): FoundryWorkingEnvironmentDefinition;
1159
1137
  /**
1160
- * Convenience persistence over the configured FoundryDataAdapter's private
1161
- * snapshot seam. VFS contents never become public workspace entries.
1138
+ * A conversation between two agents. Its id is also the recipient's
1139
+ * conversation id, and the record lives on that conversation's
1140
+ * `context.meshThread`.
1162
1141
  */
1163
- declare function foundryDataEnvironmentPersistence(options?: {
1164
- readonly scope?: "agent" | "conversation";
1165
- }): FoundryWorkingEnvironmentPersistenceAdapter;
1166
- interface FoundryReplBase {
1167
- readonly [FOUNDRY_REPL_BRAND]: true;
1142
+ interface FoundryMeshThread {
1143
+ readonly id: string;
1144
+ readonly workspaceId: string;
1145
+ /** Who started it, and the conversation its messages go back to. */
1146
+ readonly from: FoundryMeshParty & {
1147
+ readonly conversationId: string;
1148
+ readonly runId: string;
1149
+ };
1150
+ /** Who it was sent to. Their side of the thread is this conversation. */
1151
+ readonly to: FoundryMeshParty;
1152
+ /** The first message, shortened. */
1153
+ readonly subject: string;
1154
+ readonly status: FoundryMeshThreadStatus;
1155
+ /** Every message id in the thread, so either side can reply to one. */
1156
+ readonly messageIds: ReadonlyArray<string>;
1157
+ /** The recipient's open question, while status is "waiting". */
1158
+ readonly question?: string;
1159
+ /** The recipient's last reply. */
1160
+ readonly reply?: string;
1161
+ readonly error?: string;
1168
1162
  /**
1169
- * Project an explicit set of the fully assembled agent's tools into the
1170
- * sandbox as ordinary functions. Selection happens after applications,
1171
- * installed capabilities, memory, mesh, calls, and `configure` have mounted.
1172
- *
1173
- * Returning the actual tool values keeps code relationships referential;
1174
- * Foundry never accepts a second list of copied string ids here.
1163
+ * Older records only: messages not handed over yet, for the starter's
1164
+ * conversation and for this one. On start Foundry moves them to the event
1165
+ * journal and drops these lists.
1175
1166
  */
1176
- readonly programmaticTools?: FoundryProgrammaticTools;
1167
+ readonly undelivered?: ReadonlyArray<FoundryMeshMessage>;
1168
+ readonly pending?: ReadonlyArray<FoundryMeshMessage>;
1169
+ readonly createdAt: string;
1170
+ readonly updatedAt: string;
1177
1171
  }
1178
- interface FoundryProgrammaticToolSelection {
1179
- /** One of the exact live tools supplied to the selector context. */
1180
- readonly tool: Tool<unknown>;
1181
- /** Optional valid interpreter identifier when the tool name is unsuitable. */
1182
- readonly name?: string;
1183
- /** Informational effect hint used by capability discovery. */
1184
- readonly readOnly?: boolean;
1185
- /** Optional capability group used by progressive discovery. */
1186
- readonly server?: string;
1187
- readonly serverDescription?: string;
1188
- readonly resultShape?: string;
1189
- }
1190
- interface FoundryProgrammaticToolContext {
1191
- readonly assembly: AgentAssemblyContext<FoundryRequest>;
1192
- readonly glove: IGloveRunnable;
1193
- /** Snapshot of every tool mounted before the programmatic surface itself. */
1194
- readonly tools: ReadonlyArray<Tool<unknown>>;
1195
- readonly workingEnvironment?: WorkingEnvironment;
1196
- readonly vfs?: EnvFsHandle;
1197
- }
1198
- interface FoundryProgrammaticTools {
1172
+ /** One message between agents, as it reaches a conversation. */
1173
+ interface FoundryMeshMessage {
1199
1174
  /**
1200
- * Select direct live tool references. A selection may decorate its callable
1201
- * name and discovery metadata without replacing the underlying capability.
1175
+ * "message": anything an agent sent. "reply": the recipient's final answer,
1176
+ * sent when its run finished. "failed": the recipient's run stopped.
1177
+ * "ack": a read receipt, which only reaches a run that is waiting.
1202
1178
  */
1203
- readonly select: (context: FoundryProgrammaticToolContext) => Resolvable<ReadonlyArray<Tool<unknown> | FoundryProgrammaticToolSelection>>;
1204
- /** Total underlying calls permitted during this assembled run. Default 50. */
1205
- readonly maxCalls?: number;
1179
+ readonly kind: "message" | "reply" | "failed" | "ack";
1180
+ readonly id: string;
1181
+ readonly threadId: string;
1182
+ readonly from: {
1183
+ readonly agentId: string;
1184
+ readonly name: string;
1185
+ };
1186
+ readonly to: string;
1187
+ readonly content: string;
1188
+ readonly inReplyTo?: string;
1189
+ readonly createdAt: string;
1206
1190
  }
1207
- type FoundryJavaScriptReplDefinition = FoundryReplBase & Readonly<{
1208
- readonly language: "javascript";
1209
- readonly session: JsSession;
1210
- readonly mount?: Omit<MountJsConfig, "session">;
1211
- }>;
1212
- type FoundryPythonReplDefinition = FoundryReplBase & Readonly<{
1213
- readonly language: "python";
1214
- readonly session: PySession;
1215
- readonly mount?: Omit<MountPyConfig, "session">;
1216
- }>;
1217
- type FoundryLispReplDefinition = FoundryReplBase & Readonly<{
1218
- readonly language: "lisp";
1219
- readonly session: LispSession;
1220
- readonly mount?: Omit<MountLispConfig, "session">;
1221
- }>;
1222
- type FoundryReplDefinition = FoundryJavaScriptReplDefinition | FoundryPythonReplDefinition | FoundryLispReplDefinition;
1223
- type DefineFoundryReplOptions = Omit<FoundryJavaScriptReplDefinition, typeof FOUNDRY_REPL_BRAND> | Omit<FoundryPythonReplDefinition, typeof FOUNDRY_REPL_BRAND> | Omit<FoundryLispReplDefinition, typeof FOUNDRY_REPL_BRAND>;
1224
- declare function defineRepl(options: DefineFoundryReplOptions): FoundryReplDefinition;
1225
- type FoundryMountedRepl = Readonly<{
1226
- readonly language: "javascript";
1227
- readonly session: JsSession;
1228
- }> | Readonly<{
1229
- readonly language: "python";
1230
- readonly session: PySession;
1231
- }> | Readonly<{
1232
- readonly language: "lisp";
1233
- readonly session: LispSession;
1234
- }>;
1235
-
1236
- declare const FOUNDRY_LAYER_BRAND: unique symbol;
1237
- declare const FOUNDRY_SUBSCRIBER_BRAND: unique symbol;
1238
- interface FoundrySurfaceContext<TInput = unknown> {
1191
+ interface MeshCommandBase {
1192
+ readonly id: string;
1239
1193
  readonly definitionId: string;
1240
1194
  readonly agentId: string;
1241
1195
  readonly conversationId: string;
1242
1196
  readonly workspaceId: string;
1243
- readonly runId: string;
1244
- readonly input: TInput;
1245
- readonly request: FoundryRequest;
1246
- readonly message: Message;
1247
- readonly messageInput: FoundryMessageInput;
1248
- readonly messageText: string;
1249
- readonly history: ReadonlyArray<Message>;
1250
- readonly messages: ReadonlyArray<Message>;
1251
- readonly glove: IGloveRunnable;
1252
- readonly workingEnvironment?: WorkingEnvironment;
1253
- readonly vfs?: FoundryVfsHandle;
1254
- readonly repl?: FoundryMountedRepl;
1255
- readonly signal: AbortSignal;
1256
- readonly emit: (event: {
1257
- type: string;
1258
- data?: unknown;
1259
- }) => void;
1260
1197
  }
1261
- type FoundrySurfaceCleanup = () => void | Promise<void> | Effect.Effect<void, unknown, never>;
1262
- interface FoundryLayerOptions<TConfigSchema extends z.ZodType | undefined = undefined> {
1263
- /** @deprecated File-routed definitions derive identity from their filename. */
1264
- readonly id?: string;
1265
- readonly description: string;
1266
- readonly config?: TConfigSchema;
1198
+ type FoundryMeshCommand = (MeshCommandBase & {
1199
+ readonly type: "mesh.list";
1200
+ readonly name?: string;
1201
+ }) | (MeshCommandBase & {
1202
+ readonly type: "mesh.send";
1267
1203
  /**
1268
- * Mount any Glove-native package or application concern onto the compiled
1269
- * runnable. Mesh, memory subagent composition, scratchpads, image surfaces,
1270
- * voice bridges and future Glove packages all fit through this seam.
1204
+ * The message. `threadId` is used when it starts a new thread; a reply
1205
+ * in an existing thread takes that thread's id.
1271
1206
  */
1272
- readonly setup: (context: FoundrySurfaceContext & {
1273
- readonly config: TConfigSchema extends z.ZodType ? z.output<TConfigSchema> : unknown;
1274
- }) => Effect.Effect<void | FoundrySurfaceCleanup, unknown, never>;
1275
- }
1276
- type FoundryLayer<TConfigSchema extends z.ZodType | undefined = undefined> = Readonly<FoundryLayerOptions<TConfigSchema>> & {
1277
- readonly id: string;
1278
- readonly [FOUNDRY_LAYER_BRAND]: true;
1207
+ readonly message: {
1208
+ readonly id: string;
1209
+ readonly threadId: string;
1210
+ readonly to: string;
1211
+ readonly content: string;
1212
+ readonly inReplyTo?: string;
1213
+ };
1214
+ }) | (MeshCommandBase & {
1215
+ readonly type: "mesh.ack";
1216
+ readonly messageId: string;
1217
+ readonly note: string;
1218
+ });
1219
+
1220
+ declare const FOUNDRY_SCHEDULE_BRAND: unique symbol;
1221
+ type FoundryScheduleTimingInput = {
1222
+ readonly kind: "at";
1223
+ readonly at: string;
1224
+ } | {
1225
+ readonly kind: "after";
1226
+ readonly duration: string;
1227
+ } | {
1228
+ readonly kind: "every";
1229
+ readonly interval: string;
1230
+ } | {
1231
+ readonly kind: "cron";
1232
+ readonly expression: string;
1233
+ readonly timezone?: string;
1279
1234
  };
1280
- declare function defineLayer<TConfigSchema extends z.ZodType | undefined = undefined>(options: FoundryLayerOptions<TConfigSchema>): FoundryLayer<TConfigSchema>;
1281
- interface FoundryLayerReference<TLayer extends FoundryLayer<any> = FoundryLayer<any>> {
1282
- readonly layer: TLayer;
1283
- readonly config?: TLayer extends FoundryLayer<infer TSchema> ? TSchema extends z.ZodType ? z.input<TSchema> : never : never;
1284
- }
1285
- type FoundryLayerSelection = FoundryLayerReference<any> | FoundryLayer<any>;
1286
- /** Select a configured layer with schema-inferred input. */
1287
- declare function configureLayer<TLayer extends FoundryLayer<any>>(layer: TLayer, config: FoundryLayerReference<TLayer>["config"]): FoundryLayerReference<TLayer>;
1288
- interface FoundrySubscriberOptions {
1289
- /** @deprecated File-routed definitions derive identity from their filename. */
1290
- readonly id?: string;
1291
- readonly description: string;
1292
- readonly create: SubscriberAdapter | ((context: FoundrySurfaceContext) => SubscriberAdapter | Promise<SubscriberAdapter> | Effect.Effect<SubscriberAdapter, unknown, never>);
1293
- }
1294
- type FoundrySubscriber = Readonly<FoundrySubscriberOptions> & {
1295
- readonly id: string;
1296
- readonly [FOUNDRY_SUBSCRIBER_BRAND]: true;
1235
+ type FoundryScheduleTiming = {
1236
+ readonly kind: "at";
1237
+ readonly at: string;
1238
+ } | {
1239
+ readonly kind: "every";
1240
+ readonly intervalMs: number;
1241
+ } | {
1242
+ readonly kind: "cron";
1243
+ readonly expression: string;
1244
+ readonly timezone: string;
1297
1245
  };
1298
- declare function defineSubscriber(options: FoundrySubscriberOptions): FoundrySubscriber;
1299
- type FoundrySubscriberSelection = FoundrySubscriber;
1300
- interface FoundryNativeRegistry {
1301
- readonly layers: ReadonlyArray<FoundryLayer<any>>;
1302
- readonly subscribers: ReadonlyArray<FoundrySubscriber>;
1303
- }
1304
- interface FoundryNativeManifestEntry {
1305
- readonly id: string;
1306
- readonly kind: "layer" | "subscriber";
1307
- readonly description: string;
1308
- readonly file?: string;
1309
- }
1310
- interface FoundryNativeManifest {
1311
- readonly layers: ReadonlyArray<FoundryNativeManifestEntry>;
1312
- readonly subscribers: ReadonlyArray<FoundryNativeManifestEntry>;
1313
- }
1314
- declare const EMPTY_NATIVE_REGISTRY: FoundryNativeRegistry;
1315
- declare function mountFoundrySurfaces(options: {
1316
- readonly registry: FoundryNativeRegistry;
1317
- readonly layers?: ReadonlyArray<FoundryLayerSelection>;
1318
- readonly subscribers?: ReadonlyArray<FoundrySubscriberSelection | SubscriberAdapter>;
1319
- readonly context: FoundrySurfaceContext;
1320
- }): Promise<() => Promise<void>>;
1321
- declare function isFoundryLayer(value: unknown): value is FoundryLayer;
1322
- declare function isFoundrySubscriber(value: unknown): value is FoundrySubscriber;
1323
-
1324
- type FoundryAgentComponent = FoundrySharedTool<any> | FoundryAgentApplication | FoundryMcp | FoundryMemoryProfile | FoundryLayer<any> | FoundrySubscriber;
1325
- /**
1326
- * A colocated `*.tool.ts` may export the Glove tool body directly. Foundry
1327
- * supplies the runtime tool name from the file route, so the authored module
1328
- * never has to repeat its identity as a string.
1329
- */
1330
- type FoundryToolBody = Omit<GloveFoldArgs<any>, "name">;
1331
- interface FoundryAgentComposition {
1332
- readonly capabilities: FoundryCapabilityRegistry;
1333
- readonly native: FoundryNativeRegistry;
1334
- }
1335
- type FoundryCompositionSource = FoundryAgentComponent | FoundryToolBody | FoundryAgentComposition | ReadonlyArray<FoundryCompositionSource> | (() => FoundryCompositionSource) | false | null | undefined;
1336
- /**
1337
- * Compose colocated, headless agent parts into one immutable catalogue.
1338
- * Functions are factories, not runtime installers: they return definitions and
1339
- * never receive or mutate a Glove instance.
1340
- */
1341
- declare function composeAgent(...sources: ReadonlyArray<FoundryCompositionSource>): FoundryAgentComposition;
1342
- declare const EMPTY_AGENT_COMPOSITION: FoundryAgentComposition;
1343
-
1344
- /**
1345
- * A sibling agent this one may hand work to, named by its route
1346
- * (`"coder"` for `agents/coder/agent.ts`). Delegates are named rather than
1347
- * imported so the delegating agent's process never loads the worker's
1348
- * dependencies: a fast voice agent should not start up carrying a sandbox SDK.
1349
- */
1350
- type FoundryDelegate = string | FoundryDelegateOptions;
1351
- interface FoundryDelegateOptions {
1352
- /** Route of the worker definition. */
1353
- readonly agent: string;
1354
- /** What the worker is for. The delegating model reads this to choose. */
1246
+ interface DefineFoundryScheduleOptions {
1247
+ /** Stable semantic name within one agent definition. It is not a runtime id. */
1248
+ readonly name: string;
1355
1249
  readonly description?: string;
1250
+ readonly message: string;
1251
+ readonly payload?: unknown;
1252
+ readonly timing: FoundryScheduleTimingInput;
1253
+ readonly enabled?: boolean;
1356
1254
  }
1357
- type FoundryDelegationStatus = "working" | "waiting" | "completed" | "failed" | "cancelled";
1358
- /**
1359
- * One handed-off task. Its id is also the worker conversation's id, and the
1360
- * record lives on that conversation's `context.delegation`.
1361
- */
1362
- interface FoundryDelegation {
1255
+ type FoundryScheduleDefinition = Readonly<DefineFoundryScheduleOptions> & {
1256
+ readonly [FOUNDRY_SCHEDULE_BRAND]: true;
1257
+ };
1258
+ declare function defineSchedule(options: DefineFoundryScheduleOptions): FoundryScheduleDefinition;
1259
+ declare function isFoundrySchedule(value: unknown): value is FoundryScheduleDefinition;
1260
+
1261
+ declare const FOUNDRY_CORE_COMMAND_EVENT = "foundry.core.command";
1262
+ type FoundryCoreCommand = {
1363
1263
  readonly id: string;
1364
- /** Route of the worker definition. */
1365
- readonly to: string;
1366
- /** The worker instance: one per delegating instance and route. */
1367
- readonly workerAgentId: string;
1264
+ readonly type: "spawn";
1265
+ readonly definitionId: string;
1266
+ readonly agentId?: string;
1267
+ readonly conversationId?: string;
1368
1268
  readonly workspaceId: string;
1369
- readonly from: {
1370
- readonly definitionId: string;
1371
- readonly agentId: string;
1372
- readonly conversationId: string;
1373
- readonly runId: string;
1374
- };
1375
- readonly task: string;
1376
- readonly status: FoundryDelegationStatus;
1377
- /** The open question while status is "waiting". */
1378
- readonly question?: string;
1379
- readonly result?: string;
1380
- readonly error?: string;
1381
- /**
1382
- * Bookkeeping: an update for the delegating conversation, or replies for the
1383
- * worker, not handed over yet. Foundry hands them over again after a restart.
1384
- */
1385
- readonly undelivered?: "result" | "question" | "failed";
1386
- readonly pendingReplies?: ReadonlyArray<string>;
1387
- readonly createdAt: string;
1388
- readonly updatedAt: string;
1389
- }
1390
- /** What reaches the delegating conversation. */
1391
- type FoundryDelegationUpdate = {
1392
- readonly kind: "result";
1393
- readonly delegationId: string;
1394
- readonly agent: string;
1395
- readonly task: string;
1396
- readonly result: string;
1397
- } | {
1398
- readonly kind: "question";
1399
- readonly delegationId: string;
1400
- readonly agent: string;
1401
- readonly task: string;
1402
- readonly question: string;
1403
- } | {
1404
- readonly kind: "failed";
1405
- readonly delegationId: string;
1406
- readonly agent: string;
1407
- readonly task: string;
1408
- readonly error: string;
1409
- };
1410
- /** What reaches a worker: an answer to its question, or more instructions. */
1411
- interface FoundryDelegationReply {
1412
- readonly kind: "reply";
1413
- readonly delegationId: string;
1414
- /** Route of the delegating definition. */
1415
- readonly from: string;
1416
- readonly message: string;
1417
- }
1418
- /**
1419
- * An inbound transmission event for a conversation that already has a run:
1420
- * it joins that run's turn, or waits for the conversation, instead of
1421
- * starting a second run beside it.
1422
- */
1423
- interface FoundryTransmissionDelivery {
1424
- readonly kind: "transmission";
1425
- /** The pending-inbound record that keeps this event until a run finishes with it. */
1426
- readonly pendingId: string;
1427
- readonly routeId: string;
1428
- readonly eventId: string;
1429
- /** The event as the run reads it: the serialized `<transmission>`, or the transmission's own rendering. */
1430
- readonly message: string;
1431
- }
1432
- interface DelegationCommandBase {
1433
- readonly id: string;
1434
- readonly definitionId: string;
1435
- readonly agentId: string;
1436
- readonly conversationId: string;
1437
- readonly workspaceId: string;
1438
- readonly delegationId: string;
1439
- }
1440
- type FoundryDelegationCommand = (DelegationCommandBase & {
1441
- readonly type: "delegate";
1442
- readonly to: string;
1443
- readonly task: string;
1444
- }) | (DelegationCommandBase & {
1445
- readonly type: "delegate.reply";
1446
- readonly message: string;
1447
- }) | (DelegationCommandBase & {
1448
- readonly type: "delegate.ask";
1449
- readonly question: string;
1450
- });
1451
-
1452
- declare const FOUNDRY_CORE_COMMAND_EVENT = "foundry.core.command";
1453
- type FoundryCoreCommand = {
1454
- readonly id: string;
1455
- readonly type: "spawn";
1456
- readonly definitionId: string;
1457
- readonly agentId?: string;
1458
- readonly conversationId?: string;
1459
- readonly workspaceId: string;
1460
- readonly message: string;
1461
- readonly payload?: unknown;
1269
+ readonly message: string;
1270
+ readonly payload?: unknown;
1462
1271
  } | {
1463
1272
  readonly id: string;
1464
1273
  readonly type: "schedule";
@@ -1571,7 +1380,7 @@ type FoundryCoreCommand = {
1571
1380
  readonly observability?: unknown;
1572
1381
  readonly applicationId?: string;
1573
1382
  readonly transmissionId?: string;
1574
- } | FoundryDelegationCommand;
1383
+ } | FoundryDelegationCommand | DurableMessageCommand | FoundryMeshCommand;
1575
1384
  /** Resolve an installed app's generated outbound tool without duplicating ids. */
1576
1385
  declare function installedApplicationTransmissionToolName(application: {
1577
1386
  readonly id: string;
@@ -1586,10 +1395,20 @@ declare function installedApplicationTransmissionToolName(application: {
1586
1395
  * agent subprocess.
1587
1396
  */
1588
1397
  declare function createInstalledApplicationTransmissionTools(context: AgentAssemblyContext, applications: ReadonlyArray<FoundryAgentApplication>, installations: ReadonlyArray<AgentInstallation>, playbooks?: ReadonlyArray<AgentPlaybook>): ReadonlyArray<GloveFoldArgs<any>>;
1398
+ /** An application as the transmit tool sees it: its id and the transmissions it owns. */
1399
+ interface OutboundOwner {
1400
+ readonly id: string;
1401
+ readonly transmissions?: ReadonlyArray<AnyFoundryTransmission>;
1402
+ }
1589
1403
  /** Framework-owned orchestration tools. They emit commands for Foundry's runtime adapters. */
1590
1404
  declare function createFoundryCoreTools(context: AgentAssemblyContext, desiredSchedules?: Extract<FoundryCoreCommand, {
1591
1405
  readonly type: "schedule.sync";
1592
- }>["schedules"]): ReadonlyArray<GloveFoldArgs<any>>;
1406
+ }>["schedules"], outbound?: {
1407
+ /** The playbooks resolved for this run. Default: the instance's stored ones. */
1408
+ readonly playbooks?: ReadonlyArray<AgentPlaybook>;
1409
+ /** The definition's applications, so the approval rule of a route's transmission applies. */
1410
+ readonly applications?: ReadonlyArray<OutboundOwner>;
1411
+ }): ReadonlyArray<GloveFoldArgs<any>>;
1593
1412
 
1594
1413
  /** Conversation isolation is the default. Instance scope deliberately shares conversations. */
1595
1414
  type FoundryGuidanceScope = "conversation" | "instance";
@@ -1674,12 +1493,18 @@ interface AgentAssemblyContext<TInput = unknown> {
1674
1493
  readonly delegations: ReadonlyArray<FoundryDelegation>;
1675
1494
  /** The task this run works on, when another agent delegated it. */
1676
1495
  readonly delegation?: FoundryDelegation;
1496
+ /** Mesh threads this conversation started that were still open when the run began. */
1497
+ readonly threads: ReadonlyArray<FoundryMeshThread>;
1498
+ /** The thread this conversation answers, when a peer on the mesh messaged this one. */
1499
+ readonly thread?: FoundryMeshThread;
1677
1500
  readonly data: FoundryDataAdapter;
1678
1501
  readonly input: TInput;
1679
1502
  /** Native Glove representation of the current inbound user turn. */
1680
1503
  readonly message: Message;
1681
1504
  /** Exact input that will be passed to `Glove.processRequest`. */
1682
1505
  readonly messageInput: FoundryMessageInput;
1506
+ /** Spontaneous events that started this run. Custom handlers acknowledge them on successful return. */
1507
+ readonly events?: ReadonlyArray<glove_core.AgentEvent>;
1683
1508
  /** Convenience text projection matching Glove's multimodal normalization. */
1684
1509
  readonly messageText: string;
1685
1510
  /** Persisted native Glove messages before the current inbound turn. */
@@ -1711,7 +1536,13 @@ interface FoundryCallOptions<TInputSchema extends z.ZodType, TOutputSchema exten
1711
1536
  type FoundryCall<TInputSchema extends z.ZodType = z.ZodType, TOutputSchema extends z.ZodType = z.ZodType> = Readonly<FoundryCallOptions<TInputSchema, TOutputSchema>>;
1712
1537
  declare function defineCall<TInputSchema extends z.ZodType, TOutputSchema extends z.ZodType>(options: FoundryCallOptions<TInputSchema, TOutputSchema>): FoundryCall<TInputSchema, TOutputSchema>;
1713
1538
  interface FoundryExecutionContext<TInput = unknown> extends FoundrySurfaceContext<TInput>, FoundryGuidanceHandles {
1539
+ /** The instance being run, as resolvers see it. */
1540
+ readonly agentInstance: AgentInstance;
1541
+ readonly conversation: Conversation;
1542
+ readonly data: FoundryDataAdapter;
1714
1543
  readonly installations: ReadonlyArray<AgentInstallation>;
1544
+ readonly events?: ReadonlyArray<glove_core.AgentEvent>;
1545
+ readonly delegations?: ReadonlyArray<FoundryDelegation>;
1715
1546
  /** Register run-scoped teardown for an explicitly mounted capability. Runs in reverse order, even if assembly fails. */
1716
1547
  readonly onCleanup: (cleanup: () => void | Promise<void>) => void;
1717
1548
  /** Native persistent environment mounted for this run, when configured. */
@@ -1729,6 +1560,13 @@ interface FoundryExecutionContext<TInput = unknown> extends FoundrySurfaceContex
1729
1560
  * anything that arrives after it goes to that turn, or to a new run.
1730
1561
  */
1731
1562
  readonly onDelegationUpdate: (handler: (updates: ReadonlyArray<FoundryDelegationUpdate>) => void | Promise<void>) => () => Promise<void>;
1563
+ /**
1564
+ * Receive messages from peers on the mesh Foundry hosts inside this run
1565
+ * while it stays live, such as a voice call. Without a handler, a message
1566
+ * joins the run's turn at its next tool step. Returns a function that stops
1567
+ * listening; anything that arrives after it goes to that turn, or to a new run.
1568
+ */
1569
+ readonly onMeshMessage: (handler: (messages: ReadonlyArray<FoundryMeshMessage>) => void | Promise<void>) => () => Promise<void>;
1732
1570
  }
1733
1571
  interface AgentHandlerContext<TInput = unknown> extends FoundryExecutionContext<TInput> {
1734
1572
  /** Run the standard Glove loop, optionally with a handler-enriched message. */
@@ -1744,6 +1582,10 @@ interface AgentAssemblyOptions<TInput = unknown> {
1744
1582
  readonly systemPrompt?: FoundryResolver<string, TInput>;
1745
1583
  readonly displayManager?: FoundryResolver<DisplayManagerAdapter, TInput>;
1746
1584
  readonly serverMode?: boolean;
1585
+ /** Maximum wall time for one run; independent workers can allow hours. */
1586
+ readonly runTimeoutMs?: number;
1587
+ /** Limit concurrent runs of this definition to leave capacity for other agents. */
1588
+ readonly maxConcurrentRuns?: number;
1747
1589
  readonly maxRetries?: number;
1748
1590
  readonly maxConsecutiveErrors?: number;
1749
1591
  readonly compactionLimit?: FoundryResolver<number, TInput>;
@@ -1761,6 +1603,8 @@ interface AgentAssemblyOptions<TInput = unknown> {
1761
1603
  * needs answered, comes back to this conversation.
1762
1604
  */
1763
1605
  readonly delegates?: FoundryListResolver<FoundryDelegate, TInput>;
1606
+ readonly durableSubagents?: DurableSubagents;
1607
+ readonly eventDelivery?: FoundryEventPolicy;
1764
1608
  /**
1765
1609
  * When this agent works on a delegated task, how long glove_foundry_ask
1766
1610
  * waits in the same run for an answer before the run suspends. Default 90s.
@@ -1786,7 +1630,20 @@ interface AgentAssemblyOptions<TInput = unknown> {
1786
1630
  readonly schedules?: FoundryListResolver<FoundryScheduleDefinition, TInput>;
1787
1631
  /** Runtime policy composed from transmission primitives and persisted on the instance. */
1788
1632
  readonly playbooks?: FoundryListResolver<ComposedAgentPlaybook, TInput>;
1789
- readonly mesh?: FoundryResolver<FoundryMeshConfig | undefined, TInput>;
1633
+ /**
1634
+ * Put this agent on Glove Mesh, in one of two ways.
1635
+ *
1636
+ * - Hosted by Foundry: `true` or `{ peers, waitMs, mount }`. The agent gets
1637
+ * glove_mesh_list_agents, glove_mesh_send_message, glove_mesh_broadcast and
1638
+ * glove_mesh_acknowledge, and messages peers that are existing instances
1639
+ * in its workspace, by instance id. Their names come from data. Messages
1640
+ * travel through Foundry's durable event delivery.
1641
+ * - Your own transport: a `FoundryMeshConfig` with an `adapter` (or a
1642
+ * resolver returning one). Foundry mounts glove-mesh on it as is.
1643
+ *
1644
+ * For workers an agent owns, use `durableSubagents` or `delegates`.
1645
+ */
1646
+ readonly mesh?: true | FoundryMeshOptions | FoundryResolver<FoundryMeshConfig | undefined, TInput>;
1790
1647
  /** Sandboxed persistent files + named script execution, assembled per context. */
1791
1648
  readonly workingEnvironment?: FoundryResolver<FoundryWorkingEnvironmentDefinition | undefined, TInput>;
1792
1649
  /** One native Glove JavaScript, Python, or Lisp REPL mounted for this run. */
@@ -1803,11 +1660,20 @@ interface AgentAssemblyOptions<TInput = unknown> {
1803
1660
  readonly handler?: (context: AgentHandlerContext<TInput>) => Resolvable<unknown>;
1804
1661
  }
1805
1662
  interface FoundryMeshConfig {
1663
+ readonly delivery?: "events" | "inbox";
1664
+ readonly whenIdle?: "wake" | "defer" | "auto";
1806
1665
  readonly adapter: MeshAdapter;
1807
1666
  readonly identity?: Omit<AgentIdentity, "id"> & {
1808
1667
  readonly id?: string;
1809
1668
  };
1810
1669
  }
1670
+ /**
1671
+ * Whether a definition's `mesh` names your own transport (a config with an
1672
+ * adapter, or a resolver for one) rather than the mesh Foundry hosts.
1673
+ */
1674
+ declare function isMeshTransport<TInput>(mesh: true | FoundryMeshOptions | FoundryResolver<FoundryMeshConfig | undefined, TInput> | undefined): mesh is FoundryResolver<FoundryMeshConfig | undefined, TInput>;
1675
+ /** The hosted-mesh options a definition asks for, if it asks for the hosted mesh. */
1676
+ declare function hostedMeshOptions<TInput>(mesh: true | FoundryMeshOptions | FoundryResolver<FoundryMeshConfig | undefined, TInput> | undefined): FoundryMeshOptions | undefined;
1811
1677
  interface DefineAgentOptions extends AgentAssemblyOptions<FoundryRequest> {
1812
1678
  /** @deprecated File-routed agents derive identity from agents/<route>/agent.ts. */
1813
1679
  readonly id?: string;
@@ -1846,6 +1712,10 @@ interface FoundryAgentConventionModule {
1846
1712
  readonly systemPrompt?: AgentAssemblyOptions["systemPrompt"];
1847
1713
  readonly displayManager?: AgentAssemblyOptions["displayManager"];
1848
1714
  readonly serverMode?: boolean;
1715
+ /** Maximum wall time for one run; independent workers can allow hours. */
1716
+ readonly runTimeoutMs?: number;
1717
+ /** Limit concurrent runs of this definition to leave capacity for other agents. */
1718
+ readonly maxConcurrentRuns?: number;
1849
1719
  readonly maxRetries?: number;
1850
1720
  readonly maxConsecutiveErrors?: number;
1851
1721
  readonly compactionLimit?: AgentAssemblyOptions["compactionLimit"];
@@ -1857,6 +1727,8 @@ interface FoundryAgentConventionModule {
1857
1727
  readonly skills?: AgentAssemblyOptions["skills"];
1858
1728
  readonly subagents?: AgentAssemblyOptions["subagents"];
1859
1729
  readonly delegates?: AgentAssemblyOptions["delegates"];
1730
+ readonly durableSubagents?: DurableSubagents;
1731
+ readonly eventDelivery?: FoundryEventPolicy;
1860
1732
  readonly answerWaitMs?: number;
1861
1733
  readonly memory?: AgentAssemblyOptions["memory"];
1862
1734
  readonly goals?: AgentAssemblyOptions["goals"];
@@ -1925,4 +1797,641 @@ declare function defineSubagent(options: DefineFoundrySubagentOptions): DefineSu
1925
1797
  type FoundryRouteMap = Record<string, object>;
1926
1798
  declare function defineRoutes<const TRoutes extends FoundryRouteMap>(routes: TRoutes): TRoutes;
1927
1799
 
1928
- export { type ComposedAgentPlaybook as $, type AgentHandlerContext as A, type AgentAssemblyOptions as B, type Conversation as C, AgentDefinitionId as D, type EnvironmentValue as E, type FoundryDelegationUpdate as F, type AgentDefinitionSurfaceContext as G, type AgentFactoryContext as H, type InboundDeliveryClaim as I, AgentId as J, type AgentInstallContext as K, type AgentInstallation as L, type AgentInstallationKind as M, type AgentPlaybookInput as N, OutboundRoute as O, type PlaybookSubscription as P, type AgentProvisioningPolicy as Q, type AgentRuntimeControls as R, type SharedInboxItem as S, type AnyFoundryAgent as T, type ApplicationConnectionContext as U, type ApplicationConnectionState as V, type WorkspaceEntry as W, type ApplicationConnectionStatus as X, BindingId as Y, BindingNotFound as Z, CapabilityId as _, type FoundryDataAdapter as a, type FoundryCoreCommand as a$, type ComposedAgentPlaybookInput as a0, type ConnectionReceiveInput as a1, type CreateAgentInstanceOptions as a2, type CreateConversationOptions as a3, type CustomProvisionedAgent as a4, type CustomProvisioningContext as a5, type DefineAgentOptions as a6, type DefineConnectionOptions as a7, type DefineFoundryReplOptions as a8, type DefineFoundryScheduleOptions as a9, FOUNDRY_PLAYBOOK_ACTION_BRAND as aA, FOUNDRY_REPL_BRAND as aB, FOUNDRY_SCHEDULE_BRAND as aC, FOUNDRY_SHARED_TOOL_BRAND as aD, FOUNDRY_SUBSCRIBER_BRAND as aE, FOUNDRY_TRANSMISSION_BRAND as aF, FOUNDRY_TRANSMISSION_EVENT_BRAND as aG, FOUNDRY_TRANSMISSION_PREDICATE_BRAND as aH, FOUNDRY_WORKING_ENVIRONMENT_BRAND as aI, type FoundryAccountSessionAdapter as aJ, type FoundryAgent as aK, type FoundryAgentComponent as aL, type FoundryAgentComposition as aM, type FoundryAgentConventionModule as aN, type FoundryAgentDefinition as aO, type FoundryAgentMode as aP, type FoundryApp as aQ, type FoundryApplicationConnection as aR, type FoundryCall as aS, type FoundryCallContext as aT, type FoundryCallOptions as aU, type FoundryCapabilityKind as aV, type FoundryCapabilityManifest as aW, type FoundryCapabilityManifestEntry as aX, type FoundryCapabilityRegistry as aY, type FoundryCompositionSource as aZ, type FoundryContextProvider as a_, type DefineFoundrySubagentOptions as aa, type DefineFoundryWorkingEnvironmentOptions as ab, type DefinePlaybookSubscriptionOptions as ac, type DefinitionConfigInput as ad, EMPTY_AGENT_COMPOSITION as ae, EMPTY_CAPABILITY_REGISTRY as af, EMPTY_NATIVE_REGISTRY as ag, type EgressAdapter as ah, type EgressContext as ai, EventId as aj, EventNotFound as ak, EventReference as al, FOUNDRY_AGENT_APPLICATION_BRAND as am, FOUNDRY_AGENT_BRAND as an, FOUNDRY_AGENT_DEFINITION_BRAND as ao, FOUNDRY_AGENT_FILE_ENV as ap, FOUNDRY_AGENT_ROUTE_ENV as aq, FOUNDRY_APPLICATION_ENV as ar, FOUNDRY_COMPOSED_PLAYBOOK_BRAND as as, FOUNDRY_CONNECTION_BRAND as at, FOUNDRY_CORE_COMMAND_EVENT as au, FOUNDRY_EVENT_PREFIX as av, FOUNDRY_EXECUTION_MARKER as aw, FOUNDRY_LAYER_BRAND as ax, FOUNDRY_MCP_BRAND as ay, FOUNDRY_MEMORY_BRAND as az, type AgentInstance as b, type FoundryWorkingEnvironmentDefinition as b$, type FoundryDelegate as b0, type FoundryDelegateOptions as b1, type FoundryDelegation as b2, type FoundryDelegationReply as b3, type FoundryDelegationStatus as b4, type FoundryDomainError as b5, type FoundryExecutionContext as b6, type FoundryFactsOptions as b7, type FoundryFormsOptions as b8, type FoundryGoalsOptions as b9, type FoundryProgrammaticToolSelection as bA, type FoundryProgrammaticTools as bB, type FoundryPythonReplDefinition as bC, type FoundryReplDefinition as bD, type FoundryRequest as bE, type FoundryResolvedMcp as bF, type FoundryResolver as bG, type FoundryResult as bH, type FoundryRouteMap as bI, type FoundryScheduleDefinition as bJ, type FoundryScheduleTiming as bK, type FoundryScheduleTimingInput as bL, type FoundrySharedTool as bM, type FoundrySubagentToolContext as bN, type FoundrySubscriber as bO, type FoundrySubscriberOptions as bP, type FoundrySubscriberSelection as bQ, type FoundrySurfaceContext as bR, type FoundrySuspension as bS, type FoundryToolBody as bT, type FoundryTransmission as bU, type FoundryTransmissionDelivery as bV, type FoundryTransmissionEvent as bW, type FoundryTransmissionPredicate as bX, type FoundryVfs as bY, type FoundryVfsHandle as bZ, type FoundryWorkingEnvironmentCreateContext as b_, type FoundryGuidanceHandles as ba, type FoundryGuidanceScope as bb, type FoundryHookDefinition as bc, type FoundryInstallable as bd, type FoundryInstanceProvisioner as be, type FoundryJavaScriptReplDefinition as bf, type FoundryLayer as bg, type FoundryLayerOptions as bh, type FoundryLayerReference as bi, type FoundryLayerSelection as bj, type FoundryLispReplDefinition as bk, type FoundryListResolver as bl, type FoundryMcp as bm, type FoundryMcpOptions as bn, type FoundryMemoryProfile as bo, type FoundryMemoryProfileOptions as bp, type FoundryMemoryReference as bq, type FoundryMemorySelection as br, type FoundryMeshConfig as bs, type FoundryMessageInput as bt, type FoundryMountedRepl as bu, type FoundryNativeManifest as bv, type FoundryNativeManifestEntry as bw, type FoundryNativeRegistry as bx, type FoundryPlaybookAction as by, type FoundryProgrammaticToolContext as bz, type FoundryActivationRecord as c, defineRepl as c$, type FoundryWorkingEnvironmentPersistenceAdapter as c0, type FoundryWorkingEnvironmentPersistenceContext as c1, GrantResolutionError as c2, type InboundContract as c3, type InferAgentInput as c4, type InferAgentOutput as c5, type InferInboundEvent as c6, type InferOutboundInput as c7, type InferOutboundOutput as c8, type IngressAdapter as c9, type TransmissionPredicateOptions as cA, type TransmissionSerializationContext as cB, type UpdateAgentInstanceOptions as cC, type UpdateConversationOptions as cD, composeAgent as cE, composePlaybook as cF, configureLayer as cG, configureMemory as cH, createAgentInstance as cI, createConversation as cJ, createFoundryCoreTools as cK, createInstalledApplicationTransmissionTools as cL, defineAgent as cM, defineAgentApplication as cN, defineAgentFromModule as cO, defineAgentInstance as cP, defineApp as cQ, defineCall as cR, defineConnection as cS, defineFacts as cT, defineForms as cU, defineGoals as cV, defineLayer as cW, defineMcp as cX, defineMemory as cY, definePlaybookAction as cZ, definePlaybookSubscription as c_, type IngressContext as ca, type InstallationSelection as cb, type McpAdapterFactory as cc, MemoryFoundryDataAdapter as cd, type OutboundContract as ce, type PlaybookActionOptions as cf, type PlaybookDirective as cg, type PlaybookDirectiveInput as ch, type PlaybookMatch as ci, type PlaybookMatchInput as cj, type PlaybookOutboundDirective as ck, type PlaybookOutboundInput as cl, type PlaybookSubscriptionTarget as cm, type PlaybookSubscriptionTargetInput as cn, ReplyPolicy as co, Route as cp, RouteId as cq, RouteNotFound as cr, RunGrant as cs, RunId as ct, type SharedToolOptions as cu, TopologyConflict as cv, type TransmissionEventDirection as cw, type TransmissionEventOptions as cx, TransmissionId as cy, type TransmissionOptions as cz, type ProvisionAgentOptions as d, defineRoutes as d0, defineSchedule as d1, defineSharedTool as d2, defineSubagent as d3, defineSubscriber as d4, defineTransmission as d5, defineTransmissionEvent as d6, defineTransmissionPredicate as d7, defineWorkingEnvironment as d8, foundryDataEnvironmentPersistence as d9, foundryGuidanceSubject as da, install as db, installRegistry as dc, installationKey as dd, installedApplicationTransmissionToolName as de, internalAgentName as df, isFoundryAgent as dg, isFoundryAgentDefinition as dh, isFoundryCapability as di, isFoundryLayer as dj, isFoundrySchedule as dk, isFoundrySubscriber as dl, isFoundryTransmission as dm, isInboxCapableStore as dn, mountAgentDefinitionMemory as dp, mountFoundrySurfaces as dq, reconstructAgentInstance as dr, reconstructPlaybook as ds, reconstructPlaybookSubscription as dt, routeFromInternalAgentName as du, toGloveMessage as dv, toGloveRequestInput as dw, transmissionPredicate as dx, type FoundryPendingInbound as e, type FoundryWorkingEnvironmentSnapshotOwner as f, type FoundryTask as g, type AgentPlaybook as h, type AnyFoundryTransmission as i, AccountReference as j, type InferAccountMetadata as k, AgentBinding as l, type FoundryAgentApplication as m, InboundRoute as n, type CapabilityDefinition as o, type InferInboundConfig as p, type InferOutboundConfig as q, type AccountContract as r, AccountId as s, AccountNotFound as t, AccountSessionUnavailable as u, AccountSummary as v, type AgentApplicationContribution as w, type AgentApplicationInstallContext as x, type AgentApplicationOptions as y, type AgentAssemblyContext as z };
1800
+ interface DurableSubagentOptions {
1801
+ readonly agent: FoundryAgentDefinition;
1802
+ readonly description?: string;
1803
+ readonly eventDelivery?: FoundryEventPolicy;
1804
+ readonly inherit?: {
1805
+ /** A snapshot at provisioning. Transcripts are never inherited. */
1806
+ readonly context?: boolean;
1807
+ readonly tools?: ReadonlyArray<string>;
1808
+ /** Shared memory is read-only unless curator access is explicitly requested. */
1809
+ readonly memory?: "isolated" | "shared" | {
1810
+ readonly scope: "isolated" | "shared";
1811
+ readonly access?: "reader" | "curator";
1812
+ readonly profiles?: ReadonlyArray<string>;
1813
+ };
1814
+ /** Only currently installed parent apps are inherited. Restrictions can only narrow access. */
1815
+ readonly apps?: ReadonlyArray<string | FoundryApp>;
1816
+ };
1817
+ /** Delete application-owned private memory/transcripts/files before purging Foundry records. Must be idempotent. */
1818
+ readonly cleanup?: (input: {
1819
+ readonly agent: AgentInstance;
1820
+ readonly conversationIds: ReadonlyArray<string>;
1821
+ }) => void | Promise<void>;
1822
+ }
1823
+ type DurableSubagents = Readonly<Record<string, DurableSubagentOptions>>;
1824
+ interface DurableSubagentOwnership {
1825
+ readonly parentAgentId: string;
1826
+ readonly name: string;
1827
+ readonly status: "active" | "archived" | "purged";
1828
+ }
1829
+ interface AgentMessageReceipt {
1830
+ readonly messageId: string;
1831
+ readonly agentId: string;
1832
+ readonly conversationId: string;
1833
+ readonly runId?: string;
1834
+ }
1835
+ interface DurableMessageCommand {
1836
+ readonly type: "agent.message";
1837
+ readonly id: string;
1838
+ readonly definitionId: string;
1839
+ readonly agentId: string;
1840
+ readonly conversationId: string;
1841
+ readonly workspaceId: string;
1842
+ readonly to: string;
1843
+ readonly message: string;
1844
+ readonly delivery?: FoundryMessageOptions;
1845
+ }
1846
+
1847
+ type AgentProvisioningPolicy = {
1848
+ readonly mode: "singleton";
1849
+ readonly key?: string;
1850
+ } | {
1851
+ readonly mode: "per-thread";
1852
+ } | {
1853
+ readonly mode: "per-event";
1854
+ } | {
1855
+ readonly mode: "existing";
1856
+ readonly agentIds: ReadonlyArray<string>;
1857
+ } | {
1858
+ readonly mode: "custom";
1859
+ readonly adapter: string;
1860
+ };
1861
+ interface PlaybookSubscriptionTarget {
1862
+ readonly definitionId: string;
1863
+ readonly provisioning: AgentProvisioningPolicy;
1864
+ readonly context: Readonly<Record<string, unknown>>;
1865
+ readonly installations: ReadonlyArray<AgentInstallation>;
1866
+ }
1867
+ interface PlaybookSubscription {
1868
+ readonly id: string;
1869
+ readonly workspaceId: string;
1870
+ readonly enabled: boolean;
1871
+ readonly playbook: AgentPlaybook;
1872
+ readonly targets: ReadonlyArray<PlaybookSubscriptionTarget>;
1873
+ readonly createdAt: string;
1874
+ readonly updatedAt: string;
1875
+ }
1876
+ interface PlaybookSubscriptionTargetInput {
1877
+ readonly agent: FoundryAgentDefinition;
1878
+ readonly provisioning?: AgentProvisioningPolicy;
1879
+ readonly context?: Readonly<Record<string, unknown>>;
1880
+ readonly installations?: ReadonlyArray<AgentInstallation>;
1881
+ }
1882
+ interface DefinePlaybookSubscriptionOptions {
1883
+ /** @deprecated File-routed subscriptions derive identity from their filename. */
1884
+ readonly id?: string;
1885
+ readonly workspaceId?: string;
1886
+ readonly enabled?: boolean;
1887
+ readonly playbook: AgentPlaybookInput | AgentPlaybook;
1888
+ readonly targets: ReadonlyArray<PlaybookSubscriptionTargetInput>;
1889
+ readonly createdAt?: string;
1890
+ readonly updatedAt?: string;
1891
+ }
1892
+ interface CustomProvisioningContext {
1893
+ readonly subscription: PlaybookSubscription;
1894
+ readonly target: PlaybookSubscriptionTarget;
1895
+ readonly route: InboundRoute;
1896
+ readonly eventId: string;
1897
+ readonly eventName: string;
1898
+ readonly threadKey: string;
1899
+ readonly event: unknown;
1900
+ }
1901
+ interface CustomProvisionedAgent extends CreateAgentInstanceOptions {
1902
+ /** Stable uniqueness key; the data adapter enforces it atomically. */
1903
+ readonly provisioningKey: string;
1904
+ }
1905
+ interface FoundryInstanceProvisioner {
1906
+ readonly identifier: string;
1907
+ provision(adapter: string, context: CustomProvisioningContext): Effect.Effect<ReadonlyArray<CustomProvisionedAgent>, unknown, never>;
1908
+ }
1909
+ declare function definePlaybookSubscription(options: DefinePlaybookSubscriptionOptions): PlaybookSubscription;
1910
+ /** Rehydrate the value-only representation returned by a durable adapter. */
1911
+ declare function reconstructPlaybookSubscription(subscription: PlaybookSubscription): PlaybookSubscription;
1912
+
1913
+ interface AgentInstance {
1914
+ readonly durableSubagent?: DurableSubagentOwnership;
1915
+ readonly id: string;
1916
+ readonly definitionId: string;
1917
+ readonly workspaceId: string;
1918
+ /**
1919
+ * Who this agent is, to people and to its peers on the mesh: "Sales
1920
+ * Outbound", "Maya's assistant". Data like the rest of the instance, so it
1921
+ * can change at any time without touching code. Defaults to the id.
1922
+ */
1923
+ readonly name?: string;
1924
+ /** What this agent does, in a sentence its peers can read to choose it. */
1925
+ readonly description?: string;
1926
+ /** Stable adapter-enforced key used by lazy subscription provisioning. */
1927
+ readonly provisioningKey?: string;
1928
+ readonly context: Readonly<Record<string, unknown>>;
1929
+ /** Persisted desired state. Definitions only provide the capability catalogue. */
1930
+ readonly installations: ReadonlyArray<AgentInstallation>;
1931
+ readonly playbooks: ReadonlyArray<AgentPlaybook>;
1932
+ readonly createdAt: string;
1933
+ readonly updatedAt: string;
1934
+ }
1935
+ interface Conversation {
1936
+ readonly id: string;
1937
+ readonly agentId: string;
1938
+ readonly workspaceId: string;
1939
+ readonly title?: string;
1940
+ readonly context: Readonly<Record<string, unknown>>;
1941
+ readonly createdAt: string;
1942
+ readonly updatedAt: string;
1943
+ }
1944
+ interface WorkspaceEntry {
1945
+ readonly workspaceId: string;
1946
+ readonly key: string;
1947
+ readonly value: unknown;
1948
+ readonly updatedAt: string;
1949
+ }
1950
+ interface SharedInboxItem {
1951
+ readonly id: string;
1952
+ readonly workspaceId: string;
1953
+ readonly conversationId?: string;
1954
+ readonly agentId?: string;
1955
+ readonly topic: string;
1956
+ readonly payload: unknown;
1957
+ readonly status: "pending" | "resolved" | "dismissed";
1958
+ readonly createdAt: string;
1959
+ readonly updatedAt: string;
1960
+ }
1961
+ interface EnvironmentValue {
1962
+ readonly key: string;
1963
+ /** Secret values are deliberately never exposed through this primitive. */
1964
+ readonly value: unknown;
1965
+ readonly scope: "workspace" | "agent" | "conversation";
1966
+ readonly workspaceId: string;
1967
+ readonly agentId?: string;
1968
+ readonly conversationId?: string;
1969
+ }
1970
+ interface FoundryTask {
1971
+ readonly id: string;
1972
+ readonly workspaceId: string;
1973
+ readonly agentId?: string;
1974
+ readonly conversationId?: string;
1975
+ readonly title: string;
1976
+ readonly detail?: string;
1977
+ readonly status: "open" | "in-progress" | "completed" | "cancelled";
1978
+ readonly createdAt: string;
1979
+ readonly updatedAt: string;
1980
+ }
1981
+ interface InboundDeliveryClaim {
1982
+ readonly key: string;
1983
+ readonly status: "pending" | "completed";
1984
+ readonly runIds: ReadonlyArray<string>;
1985
+ readonly claimedAt: string;
1986
+ readonly completedAt?: string;
1987
+ }
1988
+ /**
1989
+ * An inbound event handed to one agent and not yet finished with: kept from
1990
+ * dispatch until the run that handles it settles, so a restart delivers it
1991
+ * again instead of losing it with the in-memory run queue.
1992
+ */
1993
+ interface FoundryPendingInbound {
1994
+ /** `<routeId>:<eventId>:<agentId>`. */
1995
+ readonly id: string;
1996
+ readonly definitionId: string;
1997
+ /** The request a run for this event starts from. */
1998
+ readonly request: FoundryRequest;
1999
+ /** The run handling it now; absent while the event waits for its conversation. */
2000
+ readonly runId?: string;
2001
+ readonly createdAt: string;
2002
+ }
2003
+ interface FoundryWorkingEnvironmentSnapshotOwner {
2004
+ /**
2005
+ * "agent": one snapshot per instance. "conversation": one per conversation.
2006
+ * "workspace": one for every agent in the workspace, such as a computer a
2007
+ * person's agents share; definitionId and agentId are empty.
2008
+ */
2009
+ readonly scope: "agent" | "conversation" | "workspace";
2010
+ readonly definitionId: string;
2011
+ readonly agentId: string;
2012
+ readonly conversationId: string;
2013
+ readonly workspaceId: string;
2014
+ }
2015
+ /**
2016
+ * Adapter-backed runtime data created by Foundry's scheduling and sleep tools.
2017
+ * This is reconstructed state, never a file-authored definition primitive.
2018
+ */
2019
+ interface FoundryActivationRecord {
2020
+ readonly id: string;
2021
+ readonly kind: "scheduled" | "sleep";
2022
+ readonly definitionId: string;
2023
+ readonly agentId: string;
2024
+ readonly conversationId: string;
2025
+ readonly workspaceId: string;
2026
+ readonly message: string;
2027
+ readonly payload?: unknown;
2028
+ readonly timing: FoundryScheduleTiming;
2029
+ readonly origin: "agent-definition" | "agent-tool";
2030
+ readonly scheduleName?: string;
2031
+ /** Hash of the last reconciled definition value; runtime edits remain overrides. */
2032
+ readonly definitionRevision?: string;
2033
+ readonly status: "pending" | "active" | "paused" | "completed" | "cancelled";
2034
+ readonly createdByRunId: string;
2035
+ readonly lastRunId?: string;
2036
+ readonly createdAt: string;
2037
+ readonly updatedAt: string;
2038
+ }
2039
+ interface FoundryDataAdapter {
2040
+ /** Atomic insert-if-absent, scoped by eventRecordId. Required for durable event delivery. */
2041
+ claimEvent?(record: FoundryEventRecord): Effect.Effect<boolean, unknown, never>;
2042
+ putEvent?(record: FoundryEventRecord): Effect.Effect<void, unknown, never>;
2043
+ listEvents?(): Effect.Effect<ReadonlyArray<FoundryEventRecord>, unknown, never>;
2044
+ readonly identifier: string;
2045
+ /** Purge an archived worker's owned records, retaining an identity tombstone. Shared workspace data is untouched. */
2046
+ purgeAgentData?(agentId: string): Effect.Effect<void, unknown, never>;
2047
+ getAgent(id: string): Effect.Effect<AgentInstance | null, unknown, never>;
2048
+ putAgent(agent: AgentInstance): Effect.Effect<void, unknown, never>;
2049
+ listAgents(definitionId?: string): Effect.Effect<ReadonlyArray<AgentInstance>, unknown, never>;
2050
+ provisionAgent(input: ProvisionAgentOptions): Effect.Effect<AgentInstance, unknown, never>;
2051
+ getPlaybookSubscription(id: string): Effect.Effect<PlaybookSubscription | null, unknown, never>;
2052
+ putPlaybookSubscription(subscription: PlaybookSubscription): Effect.Effect<void, unknown, never>;
2053
+ deletePlaybookSubscription(id: string): Effect.Effect<boolean, unknown, never>;
2054
+ listPlaybookSubscriptions(workspaceId?: string): Effect.Effect<ReadonlyArray<PlaybookSubscription>, unknown, never>;
2055
+ getInboundDelivery(key: string): Effect.Effect<InboundDeliveryClaim | null, unknown, never>;
2056
+ claimInboundDelivery(key: string): Effect.Effect<boolean, unknown, never>;
2057
+ completeInboundDelivery(key: string, runIds: ReadonlyArray<string>): Effect.Effect<void, unknown, never>;
2058
+ releaseInboundDelivery(key: string): Effect.Effect<void, unknown, never>;
2059
+ /**
2060
+ * Pending inbound events (optional). With these, an inbound event survives
2061
+ * a restart until the run that handles it finishes; without them, an event
2062
+ * whose run was still queued or running when the process stopped is lost.
2063
+ */
2064
+ putPendingInbound?(record: FoundryPendingInbound): Effect.Effect<void, unknown, never>;
2065
+ deletePendingInbound?(id: string): Effect.Effect<void, unknown, never>;
2066
+ listPendingInbound?(): Effect.Effect<ReadonlyArray<FoundryPendingInbound>, unknown, never>;
2067
+ /**
2068
+ * Approvals (optional). With these and the event journal, an approval is
2069
+ * kept until someone decides: the run that asked suspends after a short
2070
+ * wait, the approval survives a restart, and a decision made later resumes
2071
+ * the run at the tool call that asked. Without them, an approval nobody
2072
+ * answers expires while its run waits.
2073
+ */
2074
+ putApproval?(approval: FoundryApproval): Effect.Effect<void, unknown, never>;
2075
+ getApproval?(id: string): Effect.Effect<FoundryApproval | null, unknown, never>;
2076
+ listApprovals?(): Effect.Effect<ReadonlyArray<FoundryApproval>, unknown, never>;
2077
+ getActivation(id: string): Effect.Effect<FoundryActivationRecord | null, unknown, never>;
2078
+ putActivation(activation: FoundryActivationRecord): Effect.Effect<void, unknown, never>;
2079
+ listActivations(workspaceId?: string): Effect.Effect<ReadonlyArray<FoundryActivationRecord>, unknown, never>;
2080
+ getConversation(id: string): Effect.Effect<Conversation | null, unknown, never>;
2081
+ putConversation(conversation: Conversation): Effect.Effect<void, unknown, never>;
2082
+ listConversations(agentId: string): Effect.Effect<ReadonlyArray<Conversation>, unknown, never>;
2083
+ getWorkspaceEntry(workspaceId: string, key: string): Effect.Effect<WorkspaceEntry | null, unknown, never>;
2084
+ putWorkspaceEntry(entry: WorkspaceEntry): Effect.Effect<void, unknown, never>;
2085
+ /** Atomic optimistic update. null requires absence; updates must advance updatedAt. */
2086
+ compareAndSetWorkspaceEntry?(entry: WorkspaceEntry, expectedUpdatedAt: string | null): Effect.Effect<boolean, unknown, never>;
2087
+ listWorkspaceEntries(workspaceId: string): Effect.Effect<ReadonlyArray<WorkspaceEntry>, unknown, never>;
2088
+ /** Private VFS persistence; snapshots are never exposed as workspace entries. */
2089
+ getWorkingEnvironmentSnapshot(owner: FoundryWorkingEnvironmentSnapshotOwner): Effect.Effect<EnvSnapshot | null, unknown, never>;
2090
+ putWorkingEnvironmentSnapshot(owner: FoundryWorkingEnvironmentSnapshotOwner, snapshot: EnvSnapshot): Effect.Effect<void, unknown, never>;
2091
+ putInboxItem(item: SharedInboxItem): Effect.Effect<void, unknown, never>;
2092
+ listInboxItems(workspaceId: string): Effect.Effect<ReadonlyArray<SharedInboxItem>, unknown, never>;
2093
+ putTask(task: FoundryTask): Effect.Effect<void, unknown, never>;
2094
+ listTasks(workspaceId: string): Effect.Effect<ReadonlyArray<FoundryTask>, unknown, never>;
2095
+ listEnvironment(scope: {
2096
+ readonly workspaceId: string;
2097
+ readonly agentId?: string;
2098
+ readonly conversationId?: string;
2099
+ }): Effect.Effect<ReadonlyArray<EnvironmentValue>, unknown, never>;
2100
+ }
2101
+ /** The exact request shape accepted by `Glove.processRequest`. */
2102
+ type FoundryMessageInput = string | ReadonlyArray<ContentPart>;
2103
+ interface FoundryRequest {
2104
+ readonly agentId: string;
2105
+ readonly conversationId: string;
2106
+ readonly workspaceId: string;
2107
+ readonly message: FoundryMessageInput;
2108
+ readonly payload?: unknown;
2109
+ readonly context?: Readonly<Record<string, unknown>>;
2110
+ readonly source?: {
2111
+ readonly kind: "direct" | "transmission" | "activation" | "spawn" | "background" | "delegation" | "agent-message" | "mesh";
2112
+ readonly id?: string;
2113
+ readonly provider?: string;
2114
+ readonly eventId?: string;
2115
+ readonly threadKey?: string;
2116
+ };
2117
+ }
2118
+ /**
2119
+ * Normalize Foundry's wire input into the native user `Message` seen by the
2120
+ * Glove loop. Lazy assembly happens before hooks run, so this intentionally
2121
+ * represents the unmodified inbound turn.
2122
+ */
2123
+ declare function toGloveMessage(input: FoundryMessageInput): Message;
2124
+ /** Clone readonly request parts for Glove's mutable public input signature. */
2125
+ declare function toGloveRequestInput(input: FoundryMessageInput): string | ContentPart[];
2126
+ interface FoundryResult {
2127
+ /** Internal event receipts, acknowledged by the controller only after successful completion. */
2128
+ readonly consumedEventIds?: ReadonlyArray<string>;
2129
+ readonly status: "completed" | "suspended";
2130
+ readonly value: unknown;
2131
+ readonly agentId: string;
2132
+ readonly conversationId: string;
2133
+ readonly workspaceId: string;
2134
+ readonly suspension?: FoundrySuspension;
2135
+ }
2136
+ /**
2137
+ * Why a run ended without finishing: it went to sleep, it asked a question
2138
+ * about a task delegated to it, it is waiting for a peer's reply on the mesh,
2139
+ * or a tool call waits for an approval.
2140
+ */
2141
+ type FoundrySuspension = {
2142
+ readonly kind?: "sleep";
2143
+ readonly commandId: string;
2144
+ readonly wakeAt: string;
2145
+ } | {
2146
+ readonly kind: "question";
2147
+ readonly commandId: string;
2148
+ readonly delegationId: string;
2149
+ readonly question: string;
2150
+ } | {
2151
+ readonly kind: "mesh";
2152
+ readonly commandId: string;
2153
+ readonly threadId: string;
2154
+ readonly messageId: string;
2155
+ } | {
2156
+ /** Its tool call waits for a decision; the decision resumes it in a new run. */
2157
+ readonly kind: "approval";
2158
+ readonly approvalId: string;
2159
+ readonly toolName: string;
2160
+ };
2161
+ interface CreateAgentInstanceOptions {
2162
+ /** @internal Set only by durable worker provisioning. */
2163
+ readonly durableSubagent?: DurableSubagentOwnership;
2164
+ readonly id?: string;
2165
+ readonly workspaceId?: string;
2166
+ readonly name?: string;
2167
+ readonly description?: string;
2168
+ readonly context?: Readonly<Record<string, unknown>>;
2169
+ readonly installations?: ReadonlyArray<AgentInstallation>;
2170
+ readonly playbooks?: ReadonlyArray<AgentPlaybook>;
2171
+ }
2172
+ interface ProvisionAgentOptions extends CreateAgentInstanceOptions {
2173
+ readonly definitionId: string;
2174
+ readonly provisioningKey: string;
2175
+ }
2176
+ interface UpdateAgentInstanceOptions {
2177
+ readonly name?: string;
2178
+ readonly description?: string;
2179
+ readonly context?: Readonly<Record<string, unknown>>;
2180
+ readonly installations?: ReadonlyArray<AgentInstallation>;
2181
+ readonly playbooks?: ReadonlyArray<AgentPlaybook>;
2182
+ }
2183
+ interface CreateConversationOptions {
2184
+ readonly id?: string;
2185
+ readonly workspaceId?: string;
2186
+ readonly title?: string;
2187
+ readonly context?: Readonly<Record<string, unknown>>;
2188
+ }
2189
+ interface UpdateConversationOptions {
2190
+ readonly title?: string;
2191
+ readonly context?: Readonly<Record<string, unknown>>;
2192
+ }
2193
+ declare class MemoryFoundryDataAdapter implements FoundryDataAdapter {
2194
+ readonly identifier: string;
2195
+ private readonly agents;
2196
+ private readonly agentsByProvisioningKey;
2197
+ private readonly subscriptions;
2198
+ private readonly inboundDeliveries;
2199
+ private readonly events;
2200
+ private readonly pendingInbound;
2201
+ private readonly approvals;
2202
+ private readonly activations;
2203
+ private readonly conversations;
2204
+ private readonly workspace;
2205
+ private readonly workingEnvironments;
2206
+ private readonly inbox;
2207
+ private readonly tasks;
2208
+ private readonly environment;
2209
+ private pendingAgents;
2210
+ private pendingSubscriptions;
2211
+ constructor(options?: {
2212
+ readonly identifier?: string;
2213
+ readonly environment?: ReadonlyArray<EnvironmentValue>;
2214
+ readonly agents?: ReadonlyArray<AgentInstance>;
2215
+ readonly conversations?: ReadonlyArray<Conversation>;
2216
+ readonly subscriptions?: ReadonlyArray<PlaybookSubscription>;
2217
+ readonly activations?: ReadonlyArray<FoundryActivationRecord>;
2218
+ });
2219
+ /** Resolve file-owned identities only after Foundry discovery has bound them. */
2220
+ private materializeSeeds;
2221
+ getAgent(id: string): Effect.Effect<AgentInstance | null, never, never>;
2222
+ putAgent(agent: AgentInstance): Effect.Effect<void, never, never>;
2223
+ listAgents(definitionId?: string): Effect.Effect<AgentInstance[], never, never>;
2224
+ provisionAgent(input: ProvisionAgentOptions): Effect.Effect<AgentInstance, never, never>;
2225
+ purgeAgentData(agentId: string): Effect.Effect<void, never, never>;
2226
+ getPlaybookSubscription(id: string): Effect.Effect<PlaybookSubscription | null, never, never>;
2227
+ putPlaybookSubscription(subscription: PlaybookSubscription): Effect.Effect<void, never, never>;
2228
+ deletePlaybookSubscription(id: string): Effect.Effect<boolean, never, never>;
2229
+ listPlaybookSubscriptions(workspaceId?: string): Effect.Effect<PlaybookSubscription[], never, never>;
2230
+ getInboundDelivery(key: string): Effect.Effect<InboundDeliveryClaim | null, never, never>;
2231
+ claimInboundDelivery(key: string): Effect.Effect<boolean, never, never>;
2232
+ completeInboundDelivery(key: string, runIds: ReadonlyArray<string>): Effect.Effect<void, never, never>;
2233
+ releaseInboundDelivery(key: string): Effect.Effect<void, never, never>;
2234
+ claimEvent(record: FoundryEventRecord): Effect.Effect<boolean, never, never>;
2235
+ putEvent(record: FoundryEventRecord): Effect.Effect<void, never, never>;
2236
+ listEvents(): Effect.Effect<FoundryEventRecord[], never, never>;
2237
+ putPendingInbound(record: FoundryPendingInbound): Effect.Effect<void, never, never>;
2238
+ deletePendingInbound(id: string): Effect.Effect<void, never, never>;
2239
+ listPendingInbound(): Effect.Effect<FoundryPendingInbound[], never, never>;
2240
+ putApproval(approval: FoundryApproval): Effect.Effect<void, never, never>;
2241
+ getApproval(id: string): Effect.Effect<FoundryApproval | null, never, never>;
2242
+ listApprovals(): Effect.Effect<FoundryApproval[], never, never>;
2243
+ getActivation(id: string): Effect.Effect<FoundryActivationRecord | null, never, never>;
2244
+ putActivation(activation: FoundryActivationRecord): Effect.Effect<void, never, never>;
2245
+ listActivations(workspaceId?: string): Effect.Effect<FoundryActivationRecord[], never, never>;
2246
+ getConversation(id: string): Effect.Effect<Conversation | null, never, never>;
2247
+ putConversation(conversation: Conversation): Effect.Effect<void, never, never>;
2248
+ listConversations(agentId: string): Effect.Effect<Conversation[], never, never>;
2249
+ getWorkspaceEntry(workspaceId: string, key: string): Effect.Effect<WorkspaceEntry | null, never, never>;
2250
+ putWorkspaceEntry(entry: WorkspaceEntry): Effect.Effect<void, never, never>;
2251
+ compareAndSetWorkspaceEntry(entry: WorkspaceEntry, expectedUpdatedAt: string | null): Effect.Effect<boolean, never, never>;
2252
+ listWorkspaceEntries(workspaceId: string): Effect.Effect<WorkspaceEntry[], never, never>;
2253
+ getWorkingEnvironmentSnapshot(owner: FoundryWorkingEnvironmentSnapshotOwner): Effect.Effect<EnvSnapshot | null, never, never>;
2254
+ putWorkingEnvironmentSnapshot(owner: FoundryWorkingEnvironmentSnapshotOwner, snapshot: EnvSnapshot): Effect.Effect<void, never, never>;
2255
+ putInboxItem(item: SharedInboxItem): Effect.Effect<void, never, never>;
2256
+ listInboxItems(workspaceId: string): Effect.Effect<SharedInboxItem[], never, never>;
2257
+ putTask(task: FoundryTask): Effect.Effect<void, never, never>;
2258
+ listTasks(workspaceId: string): Effect.Effect<FoundryTask[], never, never>;
2259
+ listEnvironment(scope: {
2260
+ readonly workspaceId: string;
2261
+ readonly agentId?: string;
2262
+ readonly conversationId?: string;
2263
+ }): Effect.Effect<EnvironmentValue[], never, never>;
2264
+ }
2265
+ declare function createAgentInstance(definitionId: string, options?: CreateAgentInstanceOptions, provisioningKey?: string): AgentInstance;
2266
+ /** Code-authoring helper; instance data stores the referenced definition id. */
2267
+ declare function defineAgentInstance(definition: FoundryAgentDefinition, options?: CreateAgentInstanceOptions): AgentInstance;
2268
+ /** Rehydrate a durable adapter record into Foundry's immutable runtime shape. */
2269
+ declare function reconstructAgentInstance(agent: AgentInstance): AgentInstance;
2270
+ declare function createConversation(agent: AgentInstance, options?: CreateConversationOptions): Conversation;
2271
+
2272
+ /**
2273
+ * A sibling agent this one may hand work to, named by its route
2274
+ * (`"coder"` for `agents/coder/agent.ts`). Delegates are named rather than
2275
+ * imported so the delegating agent's process never loads the worker's
2276
+ * dependencies: a fast voice agent should not start up carrying a sandbox SDK.
2277
+ */
2278
+ type FoundryDelegate = string | FoundryDelegateOptions;
2279
+ interface FoundryDelegateOptions {
2280
+ /** Route of the worker definition. */
2281
+ readonly agent: string;
2282
+ /** What the worker is for. The delegating model reads this to choose. */
2283
+ readonly description?: string;
2284
+ }
2285
+ type FoundryDelegationStatus = "working" | "waiting" | "completed" | "failed" | "cancelled";
2286
+ /**
2287
+ * One handed-off task. Its id is also the worker conversation's id, and the
2288
+ * record lives on that conversation's `context.delegation`.
2289
+ */
2290
+ interface FoundryDelegation {
2291
+ readonly id: string;
2292
+ /** Route of the worker definition. */
2293
+ readonly to: string;
2294
+ /** The worker instance: one per delegating instance and route. */
2295
+ readonly workerAgentId: string;
2296
+ readonly workspaceId: string;
2297
+ readonly from: {
2298
+ readonly definitionId: string;
2299
+ readonly agentId: string;
2300
+ readonly conversationId: string;
2301
+ readonly runId: string;
2302
+ };
2303
+ readonly task: string;
2304
+ readonly status: FoundryDelegationStatus;
2305
+ /** The open question while status is "waiting". */
2306
+ readonly question?: string;
2307
+ readonly result?: string;
2308
+ readonly error?: string;
2309
+ /**
2310
+ * Bookkeeping: an update for the delegating conversation, or replies for the
2311
+ * worker, not handed over yet. Foundry hands them over again after a restart.
2312
+ */
2313
+ readonly undelivered?: "result" | "question" | "failed";
2314
+ readonly pendingReplies?: ReadonlyArray<string>;
2315
+ readonly pendingReplyIds?: ReadonlyArray<string>;
2316
+ readonly updateId?: string;
2317
+ readonly createdAt: string;
2318
+ readonly updatedAt: string;
2319
+ }
2320
+ /** What reaches the delegating conversation. */
2321
+ type FoundryDelegationUpdate = {
2322
+ readonly kind: "result";
2323
+ readonly delegationId: string;
2324
+ readonly agent: string;
2325
+ readonly task: string;
2326
+ readonly result: string;
2327
+ } | {
2328
+ readonly kind: "question";
2329
+ readonly delegationId: string;
2330
+ readonly agent: string;
2331
+ readonly task: string;
2332
+ readonly question: string;
2333
+ } | {
2334
+ readonly kind: "failed";
2335
+ readonly delegationId: string;
2336
+ readonly agent: string;
2337
+ readonly task: string;
2338
+ readonly error: string;
2339
+ };
2340
+ /** What reaches a worker: an answer to its question, or more instructions. */
2341
+ interface FoundryDelegationReply {
2342
+ readonly kind: "reply";
2343
+ readonly delegationId: string;
2344
+ /** Route of the delegating definition. */
2345
+ readonly from: string;
2346
+ readonly message: string;
2347
+ }
2348
+ /**
2349
+ * An inbound transmission event for a conversation that already has a run:
2350
+ * it joins that run's turn, or waits for the conversation, instead of
2351
+ * starting a second run beside it.
2352
+ */
2353
+ interface FoundryTransmissionDelivery {
2354
+ readonly kind: "transmission";
2355
+ /** The pending-inbound record that keeps this event until a run finishes with it. */
2356
+ readonly pendingId: string;
2357
+ readonly routeId: string;
2358
+ readonly eventId: string;
2359
+ /** The event as the run reads it: the serialized `<transmission>`, or the transmission's own rendering. */
2360
+ readonly message: string;
2361
+ }
2362
+ type FoundryConversationDelivery = (FoundryDelegationUpdate | FoundryDelegationReply | FoundryTransmissionDelivery | {
2363
+ readonly kind: "agent-message";
2364
+ readonly pendingId: string;
2365
+ readonly message: string;
2366
+ } | FoundryMeshDelivery) & {
2367
+ readonly deliveryId?: string;
2368
+ readonly request?: FoundryRequest;
2369
+ /** Durable journal identity; the filesystem mailbox is only a live transport. */
2370
+ readonly durable?: {
2371
+ readonly id: string;
2372
+ readonly event: AgentEvent;
2373
+ readonly policy: FoundryEventPolicy;
2374
+ };
2375
+ };
2376
+ /**
2377
+ * A message on the mesh Foundry hosts, for one side of a thread: the
2378
+ * recipient (the thread's own conversation) or the agent that started it.
2379
+ */
2380
+ interface FoundryMeshDelivery {
2381
+ readonly kind: "mesh";
2382
+ readonly side: "recipient" | "starter";
2383
+ readonly message: FoundryMeshMessage;
2384
+ }
2385
+ interface DelegationCommandBase {
2386
+ readonly id: string;
2387
+ readonly definitionId: string;
2388
+ readonly agentId: string;
2389
+ readonly conversationId: string;
2390
+ readonly workspaceId: string;
2391
+ readonly delegationId: string;
2392
+ }
2393
+ type FoundryDelegationCommand = (DelegationCommandBase & {
2394
+ readonly type: "delegate";
2395
+ readonly to: string;
2396
+ readonly task: string;
2397
+ }) | (DelegationCommandBase & {
2398
+ readonly type: "delegate.reply";
2399
+ readonly message: string;
2400
+ }) | (DelegationCommandBase & {
2401
+ readonly type: "delegate.ask";
2402
+ readonly question: string;
2403
+ });
2404
+
2405
+ /** A stable address. Events never guess which of an agent's conversations is active. */
2406
+ interface FoundryEventTarget {
2407
+ readonly agentId: string;
2408
+ readonly conversationId: string;
2409
+ }
2410
+ interface FoundryEventPolicy {
2411
+ /** While busy, join at the next event boundary. While idle, wake or wait for a turn. */
2412
+ readonly whenIdle?: "wake" | "defer";
2413
+ /** A deferred event wakes after this delay; omission means wait for the next turn. */
2414
+ readonly deferTimeoutMs?: number;
2415
+ }
2416
+ interface FoundryMessageOptions extends FoundryEventPolicy {
2417
+ /** Omit to address the worker's stable default conversation. */
2418
+ readonly conversationId?: string;
2419
+ /** Stable caller-provided id for retries. Scoped to the addressed conversation. */
2420
+ readonly id?: string;
2421
+ readonly expiresAt?: string;
2422
+ }
2423
+ /** Adapter-backed outbox/inflight/receipt record; completed records retain deduplication ids. */
2424
+ interface FoundryEventRecord {
2425
+ readonly id: string;
2426
+ readonly target: FoundryEventTarget;
2427
+ readonly definitionId: string;
2428
+ readonly workspaceId: string;
2429
+ readonly event: AgentEvent;
2430
+ readonly policy: FoundryEventPolicy;
2431
+ readonly delivery: FoundryConversationDelivery;
2432
+ readonly status: "pending" | "acknowledged" | "expired";
2433
+ readonly runId?: string;
2434
+ readonly createdAt: string;
2435
+ }
2436
+
2437
+ export { type ApplicationConnectionState as $, type AgentHandlerContext as A, type AgentApplicationInstallContext as B, type Conversation as C, type AgentApplicationOptions as D, type EnvironmentValue as E, type FoundryDelegationUpdate as F, type AgentAssemblyContext as G, type AgentAssemblyOptions as H, type InboundDeliveryClaim as I, AgentDefinitionId as J, type AgentDefinitionSurfaceContext as K, type AgentFactoryContext as L, AgentId as M, type AgentInstallContext as N, OutboundRoute as O, type PlaybookSubscription as P, type AgentInstallation as Q, type AgentInstallationKind as R, type SharedInboxItem as S, type AgentMessageReceipt as T, type AgentPlaybookInput as U, type AgentProvisioningPolicy as V, type WorkspaceEntry as W, type AgentRuntimeControls as X, type AnyFoundryAgent as Y, type AppRestrictions as Z, type ApplicationConnectionContext as _, type FoundryMeshMessage as a, type FoundryApp as a$, type ApplicationConnectionStatus as a0, BindingId as a1, BindingNotFound as a2, CapabilityId as a3, type ComposedAgentPlaybook as a4, type ComposedAgentPlaybookInput as a5, type ConnectionReceiveInput as a6, type CreateAgentInstanceOptions as a7, type CreateConversationOptions as a8, type CustomProvisionedAgent as a9, FOUNDRY_AGENT_ROUTE_ENV as aA, FOUNDRY_APPLICATION_ENV as aB, FOUNDRY_APPROVAL_DIRECTORY_ENV as aC, FOUNDRY_COMPOSED_PLAYBOOK_BRAND as aD, FOUNDRY_CONNECTION_BRAND as aE, FOUNDRY_CORE_COMMAND_EVENT as aF, FOUNDRY_EVENT_PREFIX as aG, FOUNDRY_EXECUTION_MARKER as aH, FOUNDRY_LAYER_BRAND as aI, FOUNDRY_MCP_BRAND as aJ, FOUNDRY_MEMORY_BRAND as aK, FOUNDRY_PLAYBOOK_ACTION_BRAND as aL, FOUNDRY_REPL_BRAND as aM, FOUNDRY_SCHEDULE_BRAND as aN, FOUNDRY_SHARED_TOOL_BRAND as aO, FOUNDRY_SUBSCRIBER_BRAND as aP, FOUNDRY_TRANSMISSION_BRAND as aQ, FOUNDRY_TRANSMISSION_EVENT_BRAND as aR, FOUNDRY_TRANSMISSION_PREDICATE_BRAND as aS, FOUNDRY_WORKING_ENVIRONMENT_BRAND as aT, type FoundryAccountSessionAdapter as aU, type FoundryAgent as aV, type FoundryAgentComponent as aW, type FoundryAgentComposition as aX, type FoundryAgentConventionModule as aY, type FoundryAgentDefinition as aZ, type FoundryAgentMode as a_, type CustomProvisioningContext as aa, DEFAULT_APPROVAL_EXPIRES_AFTER_MS as ab, DEFAULT_APPROVAL_WAIT_MS as ac, type DefineAgentOptions as ad, type DefineConnectionOptions as ae, type DefineFoundryReplOptions as af, type DefineFoundryScheduleOptions as ag, type DefineFoundrySubagentOptions as ah, type DefineFoundryWorkingEnvironmentOptions as ai, type DefinePlaybookSubscriptionOptions as aj, type DefinitionConfigInput as ak, type DurableSubagentOptions as al, type DurableSubagentOwnership as am, type DurableSubagents as an, EMPTY_AGENT_COMPOSITION as ao, EMPTY_CAPABILITY_REGISTRY as ap, EMPTY_NATIVE_REGISTRY as aq, type EgressAdapter as ar, type EgressContext as as, EventId as at, EventNotFound as au, EventReference as av, FOUNDRY_AGENT_APPLICATION_BRAND as aw, FOUNDRY_AGENT_BRAND as ax, FOUNDRY_AGENT_DEFINITION_BRAND as ay, FOUNDRY_AGENT_FILE_ENV as az, type FoundryDataAdapter as b, type FoundryProgrammaticTools as b$, type FoundryAppMcp as b0, type FoundryAppMcpTool as b1, type FoundryAppToolDecision as b2, type FoundryApplicationConnection as b3, type FoundryApprovalDecision as b4, FoundryApprovalDisplayManager as b5, type FoundryApprovalPolicy as b6, type FoundryApprovalStatus as b7, type FoundryCall as b8, type FoundryCallContext as b9, type FoundryJavaScriptReplDefinition as bA, type FoundryLayer as bB, type FoundryLayerOptions as bC, type FoundryLayerReference as bD, type FoundryLayerSelection as bE, type FoundryLispReplDefinition as bF, type FoundryListResolver as bG, type FoundryMcp as bH, type FoundryMcpOptions as bI, type FoundryMemoryProfile as bJ, type FoundryMemoryProfileOptions as bK, type FoundryMemoryReference as bL, type FoundryMemorySelection as bM, type FoundryMeshConfig as bN, type FoundryMeshOptions as bO, type FoundryMeshParty as bP, type FoundryMeshThread as bQ, type FoundryMeshThreadStatus as bR, type FoundryMessageInput as bS, type FoundryMessageOptions as bT, type FoundryMountedRepl as bU, type FoundryNativeManifest as bV, type FoundryNativeManifestEntry as bW, type FoundryNativeRegistry as bX, type FoundryPlaybookAction as bY, type FoundryProgrammaticToolContext as bZ, type FoundryProgrammaticToolSelection as b_, type FoundryCallOptions as ba, type FoundryCapabilityKind as bb, type FoundryCapabilityManifest as bc, type FoundryCapabilityManifestEntry as bd, type FoundryCapabilityRegistry as be, type FoundryCompositionSource as bf, type FoundryContextProvider as bg, type FoundryCoreCommand as bh, type FoundryDelegate as bi, type FoundryDelegateOptions as bj, type FoundryDelegation as bk, type FoundryDelegationReply as bl, type FoundryDelegationStatus as bm, type FoundryDomainError as bn, type FoundryEventPolicy as bo, type FoundryEventTarget as bp, type FoundryExecutionContext as bq, type FoundryFactsOptions as br, type FoundryFormsOptions as bs, type FoundryGoalsOptions as bt, type FoundryGuidanceHandles as bu, type FoundryGuidanceScope as bv, type FoundryHookDefinition as bw, type FoundryInstallable as bx, type FoundryInstalledApp as by, type FoundryInstanceProvisioner as bz, type AgentInstance as c, type TransmissionPredicateOptions as c$, type FoundryPythonReplDefinition as c0, type FoundryReplApp as c1, type FoundryReplDefinition as c2, type FoundryRequest as c3, type FoundryResolvedMcp as c4, type FoundryResolver as c5, type FoundryResult as c6, type FoundryRouteMap as c7, type FoundryScheduleDefinition as c8, type FoundryScheduleTiming as c9, type IngressAdapter as cA, type IngressContext as cB, type InstallationSelection as cC, type McpAdapterFactory as cD, MemoryFoundryDataAdapter as cE, type OutboundContract as cF, type PlaybookActionOptions as cG, type PlaybookDirective as cH, type PlaybookDirectiveInput as cI, type PlaybookMatch as cJ, type PlaybookMatchInput as cK, type PlaybookOutboundDirective as cL, type PlaybookOutboundInput as cM, type PlaybookSubscriptionTarget as cN, type PlaybookSubscriptionTargetInput as cO, ReplyPolicy as cP, Route as cQ, RouteId as cR, RouteNotFound as cS, RunGrant as cT, RunId as cU, type SharedToolOptions as cV, TopologyConflict as cW, type TransmissionEventDirection as cX, type TransmissionEventOptions as cY, TransmissionId as cZ, type TransmissionOptions as c_, type FoundryScheduleTimingInput as ca, type FoundrySharedTool as cb, type FoundrySubagentToolContext as cc, type FoundrySubscriber as cd, type FoundrySubscriberOptions as ce, type FoundrySubscriberSelection as cf, type FoundrySurfaceContext as cg, type FoundrySuspension as ch, type FoundryToolBody as ci, type FoundryTransmission as cj, type FoundryTransmissionDelivery as ck, type FoundryTransmissionEvent as cl, type FoundryTransmissionPredicate as cm, type FoundryVfs as cn, type FoundryVfsHandle as co, type FoundryWorkingEnvironmentCreateContext as cp, type FoundryWorkingEnvironmentDefinition as cq, type FoundryWorkingEnvironmentPersistenceAdapter as cr, type FoundryWorkingEnvironmentPersistenceContext as cs, GrantResolutionError as ct, type InboundContract as cu, type InferAgentInput as cv, type InferAgentOutput as cw, type InferInboundEvent as cx, type InferOutboundInput as cy, type InferOutboundOutput as cz, type FoundryActivationRecord as d, restrictApp as d$, type TransmissionSerializationContext as d0, type UpdateAgentInstanceOptions as d1, type UpdateConversationOptions as d2, composeAgent as d3, composePlaybook as d4, configureLayer as d5, configureMemory as d6, createAgentInstance as d7, createConversation as d8, createFoundryApproval as d9, defineTransmissionPredicate as dA, defineWorkingEnvironment as dB, foundryDataEnvironmentPersistence as dC, foundryGuidanceSubject as dD, hostedMeshOptions as dE, install as dF, installRegistry as dG, installationKey as dH, installedApplicationTransmissionToolName as dI, internalAgentName as dJ, isFoundryAgent as dK, isFoundryAgentDefinition as dL, isFoundryCapability as dM, isFoundryLayer as dN, isFoundrySchedule as dO, isFoundrySubscriber as dP, isFoundryTransmission as dQ, isInboxCapableStore as dR, isMeshTransport as dS, listFoundryApprovals as dT, meshIdentity as dU, mountAgentDefinitionMemory as dV, mountFoundrySurfaces as dW, reconstructAgentInstance as dX, reconstructPlaybook as dY, reconstructPlaybookSubscription as dZ, resolveFoundryApproval as d_, createFoundryCoreTools as da, createInstalledApplicationTransmissionTools as db, defineAgent as dc, defineAgentApplication as dd, defineAgentFromModule as de, defineAgentInstance as df, defineApp as dg, defineCall as dh, defineConnection as di, defineFacts as dj, defineForms as dk, defineGoals as dl, defineLayer as dm, defineMcp as dn, defineMemory as dp, definePlaybookAction as dq, definePlaybookSubscription as dr, defineRepl as ds, defineRoutes as dt, defineSchedule as du, defineSharedTool as dv, defineSubagent as dw, defineSubscriber as dx, defineTransmission as dy, defineTransmissionEvent as dz, type ProvisionAgentOptions as e, routeFromInternalAgentName as e0, toGloveMessage as e1, toGloveRequestInput as e2, transmissionPredicate as e3, withFoundryPermissions as e4, type FoundryEventRecord as f, type FoundryPendingInbound as g, type FoundryApproval as h, type FoundryWorkingEnvironmentSnapshotOwner as i, type FoundryTask as j, type AgentPlaybook as k, type AnyFoundryTransmission as l, AccountReference as m, type InferAccountMetadata as n, AgentBinding as o, type FoundryAgentApplication as p, InboundRoute as q, type CapabilityDefinition as r, type InferInboundConfig as s, type InferOutboundConfig as t, type AccountContract as u, AccountId as v, AccountNotFound as w, AccountSessionUnavailable as x, AccountSummary as y, type AgentApplicationContribution as z };