@finalai/agent-provider 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/HOSTING.md +7 -7
  2. package/README.md +54 -0
  3. package/dist/modules/channel-socket.d.mts +8 -4
  4. package/dist/modules/channel-socket.mjs +39 -2
  5. package/dist/modules/channel-socket.mjs.map +2 -2
  6. package/dist/modules/channel.d.mts +323 -363
  7. package/dist/modules/channel.mjs +60 -145
  8. package/dist/modules/channel.mjs.map +3 -3
  9. package/dist/modules/credentials.mjs.map +2 -2
  10. package/dist/modules/index.d.mts +0 -1
  11. package/dist/modules/index.mjs +0 -1
  12. package/dist/modules/index.mjs.map +2 -2
  13. package/dist/modules/local-channel-context.d.mts +10 -0
  14. package/dist/modules/local-channel-context.mjs +55 -0
  15. package/dist/modules/local-channel-context.mjs.map +7 -0
  16. package/dist/modules/local-channel-socket.d.mts +8 -4
  17. package/dist/modules/local-channel-socket.mjs +1 -13
  18. package/dist/modules/local-channel-socket.mjs.map +2 -2
  19. package/dist/modules/manifest.d.mts +92 -4
  20. package/dist/modules/manifest.mjs +29 -9
  21. package/dist/modules/manifest.mjs.map +2 -2
  22. package/dist/modules/room-surface.d.mts +370 -0
  23. package/dist/modules/room-surface.mjs +156 -0
  24. package/dist/modules/room-surface.mjs.map +7 -0
  25. package/dist/modules/sandbox/networking.mjs +1 -0
  26. package/dist/modules/sandbox/networking.mjs.map +2 -2
  27. package/dist/modules/sandbox/types.d.mts +20 -0
  28. package/dist/modules/sandbox/types.mjs +6 -0
  29. package/dist/modules/sandbox/types.mjs.map +2 -2
  30. package/dist/modules/semantic-events.d.mts +69 -1
  31. package/dist/modules/semantic-events.mjs +14 -1
  32. package/dist/modules/semantic-events.mjs.map +2 -2
  33. package/package.json +14 -9
  34. package/dist/modules/channel-context.d.mts +0 -106
  35. package/dist/modules/channel-context.mjs +0 -45
  36. package/dist/modules/channel-context.mjs.map +0 -7
@@ -233,6 +233,23 @@ export interface SandboxActingUserIface {
233
233
  current(): Promise<string | null>;
234
234
  }
235
235
  export declare const noSandboxActingUser: SandboxActingUserIface;
236
+ export interface FinalPlatformAccessIface {
237
+ baseUrl: string;
238
+ token: string;
239
+ }
240
+ export interface SandboxCredentialsIface {
241
+ computersAccess(args?: {
242
+ refresh?: boolean;
243
+ }): Promise<FinalPlatformAccessIface | null>;
244
+ deviceAccess(args?: {
245
+ actingUserId?: string | null;
246
+ refresh?: boolean;
247
+ }): Promise<FinalPlatformAccessIface | null>;
248
+ secret(args: {
249
+ secretRef: string;
250
+ }): Promise<string | null>;
251
+ }
252
+ export declare const noSandboxCredentials: SandboxCredentialsIface;
236
253
  export interface SandboxOfferContextIface {
237
254
  executionPolicy?: SandboxExecutionPolicyIface;
238
255
  platformNetworkPolicy?: (policy: NetworkPolicyIface) => Promise<void>;
@@ -240,6 +257,7 @@ export interface SandboxOfferContextIface {
240
257
  workspaceId?: string;
241
258
  bindings?: HostedBindingsIface;
242
259
  organizationId: string;
260
+ credentials?: SandboxCredentialsIface;
243
261
  actingUser: SandboxActingUserIface;
244
262
  }
245
263
  export interface SandboxEnvironmentContextIface {
@@ -267,6 +285,7 @@ export interface SandboxPrepareContextIface {
267
285
  sourceRevision: string;
268
286
  storagePath: string;
269
287
  organizationId: string;
288
+ credentials?: SandboxCredentialsIface;
270
289
  guides: SandboxGuidesIface;
271
290
  actingUser: SandboxActingUserIface;
272
291
  log?: (message: string) => void;
@@ -286,6 +305,7 @@ export interface SandboxStartContextIface {
286
305
  workspaceId?: string;
287
306
  target: string;
288
307
  };
308
+ credentials?: SandboxCredentialsIface;
289
309
  storagePath: string;
290
310
  guides: SandboxGuidesIface;
291
311
  variables: SandboxVariablesIface;
@@ -39,6 +39,11 @@ const noSandboxRepositories = {
39
39
  };
40
40
  const noSandboxVariables = { get: async () => null };
41
41
  const noSandboxActingUser = { current: async () => null };
42
+ const noSandboxCredentials = {
43
+ computersAccess: async () => null,
44
+ deviceAccess: async () => null,
45
+ secret: async () => null
46
+ };
42
47
  const PLATFORM_ENVIRONMENT_NAMES = /* @__PURE__ */ new Set([
43
48
  "HTTPS_PROXY",
44
49
  "HTTP_PROXY",
@@ -151,6 +156,7 @@ export {
151
156
  defineSandboxProvider,
152
157
  isMcpChannelEndpoint,
153
158
  noSandboxActingUser,
159
+ noSandboxCredentials,
154
160
  noSandboxGuides,
155
161
  noSandboxRepositories,
156
162
  noSandboxVariables,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../src/sandbox/types.ts"],
4
- "sourcesContent": ["import { SandboxEntryType } from \"./file-kind.mjs\";\nexport { SandboxEntryType } from \"./file-kind.mjs\";\nimport type { HostedBindingsIface } from \"../hosted-bindings.mjs\";\nimport { createSandboxHandle, type SandboxExecutionPolicyIface } from \"./handle.mjs\";\nimport { withSandboxOverrides } from \"./overrides.mjs\";\nimport { WorkspaceNetworkPolicy as NetworkPolicy } from '@finalai/agent-protocol/device-egress';\nimport type {\n WorkspaceEgressRequestIface,\n WorkspaceEgressStatusIface,\n WorkspaceNetworkPolicyIface as NetworkPolicyIface,\n} from '@finalai/agent-protocol/device-egress';\nexport {\n WorkspaceNetworkPolicy as NetworkPolicy,\n type WorkspaceNetworkPolicyIface as NetworkPolicyIface,\n} from '@finalai/agent-protocol/device-egress';\nimport type {\n ProcessInspectionRequestIface,\n ProcessInspectionResultIface,\n} from '@finalai/agent-protocol/process-inspection';\nimport type { JsonValue } from \"../json.mjs\";\nimport type { ToolDescriptorIface } from \"../manifest.mjs\";\nimport {\n SandboxEditorOperation,\n type SandboxEditorRequestIface,\n type SandboxEditorResultIface,\n} from \"./editor.mjs\";\nimport { SandboxExecutionOperation } from \"./execution-guard.mjs\";\nimport { awaitableOpenRequest, type AwaitableSandboxOpenRequestIface } from \"./open-scope.mjs\";\nimport type { SandboxSnapshotRequestIface, SandboxSnapshotResponseIface } from \"./snapshots.mjs\";\n\n// Sandbox providers and consumers share the streaming session contract.\n\nexport interface AbortableIface {\n abortSignal?: AbortSignal;\n}\n\nexport interface SandboxProcessOptionsIface extends AbortableIface {\n command: string;\n args?: string[];\n cwd?: string;\n env?: Record<string, string>;\n // Run through the sandbox's login shell (`bash -lc`) instead of exec'ing.\n shell?: boolean;\n stdin?: ReadableStream<Uint8Array> | string;\n timeoutMs?: number;\n}\n\nexport interface SandboxProcessIface {\n readonly pid: string | null;\n readonly stdout: ReadableStream<Uint8Array>;\n readonly stderr: ReadableStream<Uint8Array>;\n // Writes to the process's stdin; closes stdin when `end` is true.\n write(data: Uint8Array | string, options?: { end?: boolean }): Promise<void>;\n wait(): Promise<{ exitCode: number }>;\n kill(signal?: string): Promise<void>;\n}\n\nexport interface SandboxRunResultIface {\n exitCode: number;\n stdout: string;\n stderr: string;\n}\n\nexport interface StatIface {\n path: string;\n type: SandboxEntryType;\n size: number;\n modifiedAt: string | null;\n mode: number | null;\n}\n\nexport interface DirEntryIface {\n name: string;\n path: string;\n type: SandboxEntryType;\n size: number | null;\n}\n\nexport interface ConfinedSandboxFilesIface {\n readFile(\n options: { path: string; root: string } & AbortableIface,\n ): Promise<ReadableStream<Uint8Array> | null>;\n stat(options: { path: string; root: string } & AbortableIface): Promise<StatIface | null>;\n readDir(\n options: { path: string; root: string } & AbortableIface,\n ): Promise<DirEntryIface[] | null>;\n}\n\nexport interface SandboxSessionIface {\n readonly description: string;\n readonly confinedFileReader?: ConfinedSandboxFilesIface;\n // On the RPC surface, root confines viewer reads to this directory, rejects\n // symlink ancestors and requires Python 3 in the sandbox (confinedFiles feature).\n readFile(\n options: { path: string; root?: string } & AbortableIface,\n ): Promise<ReadableStream<Uint8Array> | null>;\n readBinaryFile(options: { path: string } & AbortableIface): Promise<Uint8Array | null>;\n readTextFile(\n options: {\n path: string;\n encoding?: string;\n startLine?: number;\n endLine?: number;\n } & AbortableIface,\n ): Promise<string | null>;\n writeFile(\n options: { path: string; content: ReadableStream<Uint8Array> } & AbortableIface,\n ): Promise<void>;\n writeBinaryFile(options: { path: string; content: Uint8Array } & AbortableIface): Promise<void>;\n // Writes create missing parent directories.\n writeTextFile(\n options: { path: string; content: string; encoding?: string } & AbortableIface,\n ): Promise<void>;\n spawn(options: SandboxProcessOptionsIface): Promise<SandboxProcessIface>;\n run(options: SandboxProcessOptionsIface): Promise<SandboxRunResultIface>;\n stat(options: { path: string; root?: string } & AbortableIface): Promise<StatIface | null>;\n readDir(options: { path: string; root?: string } & AbortableIface): Promise<DirEntryIface[]>;\n resolvePath(path: string): string;\n removePath(\n options: { path: string; recursive?: boolean; force?: boolean } & AbortableIface,\n ): Promise<void>;\n}\n\nexport enum PortProtocol {\n Http = 'http',\n Https = 'https',\n Ws = 'ws',\n}\n\n// An MCP transport the sandbox serves for an optional capability: an HTTP MCP\n// endpoint the harness (or the session service) can dial.\nexport interface McpEndpointIface {\n name: string;\n url: string;\n headers: Record<string, string>;\n}\n\n// A JSON-RPC message channel to an MCP server the sandbox hosts, for backends\n// whose API reaches it some other way than HTTP MCP (a byte pipe, a socket).\n// Messages are JSON-RPC objects, in order.\nexport interface McpChannelIface {\n send(message: JsonValue, options?: AbortableIface): Promise<void>;\n // The messages that arrived since the last call; [] when none did.\n receive(options?: AbortableIface): Promise<JsonValue[]>;\n close(): Promise<void>;\n}\n\n// An MCP server the sandbox hosts, opened in process by whoever runs the handle.\n// It cannot cross the handle RPC wire.\nexport interface McpChannelEndpointIface {\n name: string;\n connect(options?: AbortableIface): Promise<McpChannelIface>;\n}\n\nexport type SandboxMcpEndpoint = McpEndpointIface | McpChannelEndpointIface;\n\n// The tools of a sandbox's hosted MCP servers, as far as they are known without\n// starting it. Null: unknown until the sandbox is attached and asked.\nexport interface SandboxMcpCatalogIface {\n computerUse: ToolDescriptorIface[] | null;\n // Local MCP server name \u2192 its tools.\n localMcp: Record<string, ToolDescriptorIface[]> | null;\n // Partial discovery retains known tools and must be retried, including after caching.\n localMcpIncomplete?: boolean;\n}\n\nexport const isMcpChannelEndpoint = (\n endpoint: SandboxMcpEndpoint,\n): endpoint is McpChannelEndpointIface => 'connect' in endpoint;\n\nexport interface ScreenOptionsIface {\n // View-only by default; explicit input control requires execute access.\n viewOnly?: boolean;\n}\n\nexport interface ScreenSessionIface {\n // A short-lived viewer grant; providers enforce the requested input access.\n url: string;\n token: string;\n expiresAt: string;\n}\n\nexport interface NetworkSandboxSessionIface extends SandboxSessionIface {\n readonly id: string;\n readonly defaultWorkingDirectory: string;\n readonly ports: readonly number[];\n getPortEndpoint(options: {\n port: number;\n protocol?: PortProtocol;\n }): Promise<{ url: string; headers?: Record<string, string> }>;\n getPortUrl(options: { port: number; protocol?: PortProtocol }): Promise<string>;\n stop(): Promise<void>;\n destroy(): Promise<void>;\n setNetworkPolicy?(policy: NetworkPolicyIface): Promise<void>;\n egress?(request: WorkspaceEgressRequestIface): Promise<WorkspaceEgressStatusIface>;\n computerUse?(): Promise<SandboxMcpEndpoint>;\n screen?(options?: ScreenOptionsIface): Promise<ScreenSessionIface>;\n localMcp?(): Promise<SandboxMcpEndpoint[]>;\n}\n\n// Capabilities a started sandbox advertises (and the handle RPC exposes).\nexport enum SandboxCapability {\n Files = 'files',\n Process = 'process',\n Ports = 'ports',\n NetworkPolicy = 'networkPolicy',\n Egress = 'egress',\n ComputerUse = 'computerUse',\n Screen = 'screen',\n LocalMcp = 'localMcp',\n Browser = 'browser',\n}\n\nexport interface SandboxProviderHandleIface<S extends SandboxSessionIface> {\n readonly sandbox: S;\n // Pending policy; the generic handle constructor consumes it before exposing execution.\n readonly executionPolicy?: SandboxExecutionPolicyIface;\n onSandboxStop(): Promise<void>;\n onSandboxDelete(options?: { reason?: string }): Promise<void>;\n onRuntimeShutdown(): Promise<void>;\n}\n\n// A saved computer setup guide version: Build's versioned build-\n// and start-time inputs for a sandbox, as the session service serves them.\nexport interface SandboxGuideVersionIface {\n guideId: string;\n versionId: string;\n slug: string;\n title: string;\n number: number;\n image: string;\n // `.final/sandbox-template.yaml` v2 as JSON.\n templateConfig: JsonValue;\n // The start-time parameters this version defaults to.\n defaultParameters: JsonValue;\n instructionsMarkdown: string | null;\n // A ready build from the guide's provider, reusable independently of workspace seeds.\n preparedArtifact?: { providerRef: string; key: string; artifact: JsonValue };\n}\n\n// The organization's computer setup guides, read through the session service.\n// Every provider gets the same reader; a provider whose\n// environments name no guide never calls it.\nexport interface SandboxGuidesIface {\n get(args: { ref: string; version: number | 'latest' }): Promise<SandboxGuideVersionIface | null>;\n // The organization's default guide; null when it has none.\n default(): Promise<SandboxGuideVersionIface | null>;\n}\n\n// Where to clone a repository from, with a short-lived read credential that\n// must reach only the clone process (never a repository's git config).\nexport interface SandboxRepositoryCloneSourceIface {\n url: string;\n // Checked out after the clone; null keeps the default branch.\n ref: string | null;\n // An HTTP Authorization header value for the clone, or null.\n authorization: string | null;\n}\n\n// Repository credentials for the repositories an environment names (a Code\n// Storage id, a GitHub owner/name), resolved by the session service for the\n// session's organization only. Null: not a repository it can resolve.\nexport interface SandboxRepositoriesIface {\n cloneSource(args: {\n repository: string;\n ref: string | null;\n }): Promise<SandboxRepositoryCloneSourceIface | null>;\n}\n\n// Reads a named organization variable (managed in Build) for the session's\n// organization. Values are injected into the sandbox only, never stored in a\n// manifest, a state or the log.\nexport interface SandboxVariablesIface {\n get(name: string): Promise<string | null>;\n}\n\nexport const noSandboxGuides: SandboxGuidesIface = {\n get: async () => null,\n default: async () => null,\n};\n\nexport const noSandboxRepositories: SandboxRepositoriesIface = {\n cloneSource: async () => null,\n};\n\nexport const noSandboxVariables: SandboxVariablesIface = { get: async () => null };\n\n// The user a session acts for: the author of its running turn, else its owner,\n// else the user whose Home its conversation is. A call a person makes through\n// the platform's sandbox viewer acts for that person instead. Null when it acts\n// for no user (a turn nobody prompted in a shared conversation) and outside any\n// session (a guide build). Read on each call, because it changes between turns\n// and between callers.\nexport interface SandboxActingUserIface {\n current(): Promise<string | null>;\n}\n\nexport const noSandboxActingUser: SandboxActingUserIface = { current: async () => null };\n\n// What an environment's pre-start reads (capabilities, mcpCatalog) are given.\nexport interface SandboxOfferContextIface {\n executionPolicy?: SandboxExecutionPolicyIface;\n platformNetworkPolicy?: (policy: NetworkPolicyIface) => Promise<void>;\n // Retain platform transport access when an extension restores an allowlist.\n platformEgressHosts?: string[];\n // Logical identity when inspecting an existing workspace or opening an execution extension.\n workspaceId?: string;\n bindings?: HostedBindingsIface;\n organizationId: string;\n actingUser: SandboxActingUserIface;\n}\n\n// What an environment's hooks are given before anything starts.\nexport interface SandboxEnvironmentContextIface {\n bindings?: HostedBindingsIface;\n organizationId: string;\n guides: SandboxGuidesIface;\n}\n\n// Scoped by the host to this organization and provider. Providers can retain\n// reusable intermediate artifacts independently of a revision's seed files.\nexport interface SandboxArtifactsIface {\n get(key: string): Promise<JsonValue | null>;\n put(key: string, artifact: JsonValue): Promise<void>;\n}\n\nexport interface SandboxPreparationSourceIface {\n sourceRevision: string;\n read(): Promise<{ files: Record<string, string>; resources: Record<string, JsonValue> }>;\n}\n\nexport interface SandboxPrepareContextIface {\n bindings?: HostedBindingsIface;\n // A host-persisted resource source; artifacts may retain its identity instead of seed contents.\n preparation?: SandboxPreparationSourceIface;\n artifacts?: SandboxArtifactsIface;\n // Agent revisions supply workspace-relative seeds; setup-guide builds supply\n // guide.json and optional instructions.md. Resources name workspace, skills or guide.\n // Model instructions remain harness config.\n files: Record<string, string>;\n resources: Record<string, JsonValue>;\n sourceRevision: string;\n storagePath: string;\n organizationId: string;\n // The guide inputs (build-time) an environment names, resolved by the platform.\n guides: SandboxGuidesIface;\n // Who the session the artifact is prepared for acts for, for environments that\n // name a backend resource relative to that user; the key must then name it.\n actingUser: SandboxActingUserIface;\n log?: (message: string) => void;\n}\n\nexport interface SandboxStartContextIface {\n // Host policy composes before the provider's policy, on every exposed execution path.\n executionPolicy?: SandboxExecutionPolicyIface;\n bindings?: HostedBindingsIface;\n /** Passive recovery only: never wake, create, seed, or restart backend services. */\n passive?: boolean;\n preparation?: SandboxPreparationSourceIface;\n session: {\n id: string;\n organizationId: string;\n conversationId: string | null;\n definitionId: string;\n bindingId: string;\n // Stable logical identity supplied by the host, independent of provider resource names.\n workspaceId?: string;\n target: string;\n };\n storagePath: string;\n // Start-time inputs: guides, the variables to inject, repository credentials.\n guides: SandboxGuidesIface;\n variables: SandboxVariablesIface;\n repositories: SandboxRepositoriesIface;\n actingUser: SandboxActingUserIface;\n // Variables the platform sets in every process of this sandbox: the egress\n // proxy, trust for its CA, and one placeholder per bound secret. Evaluated\n // again for every spawn/run, never once per session: a secret bound\n // mid-session must reach the next command. May resolve to {} (no proxy\n // configured, or not ready yet). Platform values override the spec's env.\n platformEnvironment?: () => Promise<Record<string, string>>;\n // Hosts the sandbox must be able to reach for the proxy to work, to append\n // to any allowlist-mode network policy the spec declares.\n platformEgressHosts?: string[];\n // Reports the network policy now in force on the sandbox, exactly as the\n // provider applied it to its backend (after withPlatformEgressHosts). The\n // platform records it so the egress proxy serves only those destinations.\n // Called after awaitRunning and before platformFiles or any command, on start,\n // resume and a reused sandbox; never for a session's own setNetworkPolicy,\n // which the platform records itself. A rejection fails the start or resume.\n platformNetworkPolicy: (policy: NetworkPolicyIface) => Promise<void>;\n // Files the platform needs in the sandbox before any clone, setup step or\n // service runs: written right after the sandbox exists, on start and resume.\n // Paths are absolute; missing parent directories are created.\n platformFiles?: () => Promise<Record<string, string>>;\n}\n\n// The variables `platformEnvironment` owns. A spec that sets one (as a plain\n// value or an organization variable) is refused at start.\nexport const PLATFORM_ENVIRONMENT_NAMES: ReadonlySet<string> = new Set([\n 'HTTPS_PROXY',\n 'HTTP_PROXY',\n 'NO_PROXY',\n 'NODE_USE_ENV_PROXY',\n 'SSL_CERT_FILE',\n 'CURL_CA_BUNDLE',\n 'REQUESTS_CA_BUNDLE',\n 'GIT_SSL_CAINFO',\n 'CARGO_HTTP_CAINFO',\n 'DENO_CERT',\n 'NODE_EXTRA_CA_CERTS',\n 'FINAL_EGRESS_URL',\n 'FINAL_EGRESS_TOKEN',\n 'GH_TOKEN',\n 'GITHUB_TOKEN',\n]);\n\n// A process's base environment: the spec's variables under the platform's,\n// read again on every call.\nexport const platformProcessEnvironment =\n (\n ctx: Pick<SandboxStartContextIface, 'platformEnvironment'>,\n specEnv: Record<string, string>,\n ): (() => Promise<Record<string, string>>) =>\n async () => ({ ...specEnv, ...(await ctx.platformEnvironment?.()) });\n\n// Writes `platformFiles` into a sandbox that now exists, before it runs anything.\n// Relies on writeTextFile creating missing parent directories.\nexport const writePlatformFiles = async (\n ctx: Pick<SandboxStartContextIface, 'platformFiles'>,\n sandbox: Pick<SandboxSessionIface, 'writeTextFile'>,\n): Promise<void> => {\n for (const [path, content] of Object.entries((await ctx.platformFiles?.()) ?? {}))\n await sandbox.writeTextFile({ path, content });\n};\n\n// Reports the policy a provider just applied to its backend: `allow` only for an\n// allowlist, its entries (hosts, `*.suffix` patterns, CIDRs) unchanged.\nexport const reportPlatformNetworkPolicy = async (\n ctx: Pick<SandboxStartContextIface, 'platformNetworkPolicy'>,\n policy: NetworkPolicyIface,\n): Promise<void> =>\n ctx.platformNetworkPolicy(\n policy.mode === NetworkPolicy.Allowlist\n ? { mode: policy.mode, allow: [...(policy.allow ?? [])] }\n : { mode: policy.mode },\n );\n\n// An allowlist policy with the platform's egress hosts appended; any other\n// policy unchanged.\nexport const withPlatformEgressHosts = (\n ctx: Pick<SandboxStartContextIface, 'platformEgressHosts'>,\n policy: NetworkPolicyIface,\n): NetworkPolicyIface => {\n const hosts = ctx.platformEgressHosts ?? [];\n if (policy.mode !== NetworkPolicy.Allowlist || hosts.length === 0) return policy;\n return { ...policy, allow: [...new Set([...(policy.allow ?? []), ...hosts])] };\n};\n\nexport enum SandboxSessionEndReason {\n Completed = 'completed',\n Expired = 'expired',\n Failed = 'failed',\n}\n\n// How long an environment's sandbox outlives a session: `session`\n// keeps it for the session's life; `conversation` gives every session in the\n// conversation one shared sandbox per target, surviving session resets;\n// `ephemeral` discards it when released.\nexport enum SandboxWorkspace {\n Session = 'session',\n Conversation = 'conversation',\n Ephemeral = 'ephemeral',\n}\n\nexport interface SandboxProviderImplementationIface<\n OpenOptions,\n Artifact extends JsonValue,\n State extends JsonValue,\n S extends NetworkSandboxSessionIface,\n> {\n // The workspace this environment declares, read before anything starts so the\n // session service knows which sessions share a binding. Absent or null: session.\n workspace?(ctx: SandboxEnvironmentContextIface): Promise<SandboxWorkspace | null>;\n // The capabilities this environment's sandboxes offer, read before anything\n // starts through the backend's own API. Absent or null: unknown\n // until started; local MCP is then not projected.\n capabilities?(ctx: SandboxOfferContextIface): Promise<SandboxCapability[] | null>;\n // Known positive offers when the rest of the pre-start capability set is unknown.\n additionalCapabilities?(ctx: SandboxOfferContextIface): Promise<SandboxCapability[]>;\n // The hosted MCP servers' tool catalogs the backend can give without starting\n // a sandbox (from its own records), so the MCP projection lists them from the\n // first `tools/list`. The projection checks a server's catalog against the\n // live server when a call first opens that server (servers a session never\n // uses stay closed) and announces a change with\n // `notifications/tools/list_changed`.\n //\n // Trade-off: a catalog left unknown (absent hook, null, or a null field) can\n // only be learned from the live sandbox, so the first `tools/list` that finds\n // it unknown starts the sandbox in the background, at session start rather\n // than on the first tool call. Otherwise those tools would never be listed,\n // and nothing would ever call them. Providers that can give the catalog keep\n // attach lazy.\n mcpCatalog?(ctx: SandboxOfferContextIface): Promise<SandboxMcpCatalogIface | null>;\n // Reads committed files without starting/resuming a sandbox. Null means the backend\n // is live or offers no snapshot. An unavailable sleeping snapshot must throw,\n // never fall through to a read that wakes it. Pin subsequent ranges by snapshotId.\n readSnapshot?(\n ctx: SandboxOfferContextIface,\n state: State,\n request: SandboxSnapshotRequestIface,\n ): Promise<SandboxSnapshotResponseIface | null>;\n // Inspect retained backend processes without opening, resuming or extending a sandbox.\n // Stop requires execute access; the provider also enforces backend ownership.\n processes?(\n ctx: SandboxOfferContextIface & { bindingId: string },\n state: State,\n request: ProcessInspectionRequestIface,\n ): Promise<ProcessInspectionResultIface>;\n // Browser editor for this provider's existing workspace. The host checks write\n // authorization; this hook never creates or wakes a backend. Credentials stay\n // in the authentication form, never the editor URL or stored provider state.\n editor?(\n ctx: SandboxOfferContextIface,\n state: State,\n request: SandboxEditorRequestIface,\n ): Promise<SandboxEditorResultIface>;\n // Content-addressed by `artifactKey`; the session service caches artifacts in\n // agent.sandbox_artifacts and calls prepare only on a miss.\n artifactKey(ctx: SandboxPrepareContextIface): Promise<string>;\n prepare(ctx: SandboxPrepareContextIface): Promise<Artifact>;\n // Resolves once the backend sandbox named by `state` is running and will\n // accept a command or a file write; rejects with a clear error after\n // `timeoutMs`. Backend-specific: the provider chooses the readiness signal,\n // the polling cadence and the backoff for its API's rate limits. The\n // platform never polls a backend itself.\n //\n // `start`, `resume` and `resumePassive` call it on the sandbox they just\n // created, started or reused, before anything touches it: create or start \u2192\n // state \u2192 awaitRunning \u2192 platformNetworkPolicy \u2192 platformFiles \u2192 repositories,\n // seeds, setup, services \u2192 handle. On timeout `start` fails and tears down.\n awaitRunning(\n ctx: SandboxStartContextIface,\n state: State,\n options: { timeoutMs: number },\n ): Promise<void>;\n // `region`: where the backend placed the sandbox (its own region name), so the\n // session service can place the harness near it; null when unknown.\n start(\n ctx: SandboxStartContextIface,\n options: OpenOptions | undefined,\n artifact: Artifact,\n ): Promise<{ handle: SandboxProviderHandleIface<S>; state: State; region?: string | null }>;\n resume(\n ctx: SandboxStartContextIface,\n artifact: Artifact,\n state: State,\n ): Promise<SandboxProviderHandleIface<S>>;\n // Reconnect to an already running backend after host restart for a read-only viewer.\n // Absent: viewers can use a retained live handle but cannot trigger resume.\n resumePassive?(\n ctx: SandboxStartContextIface,\n artifact: Artifact,\n state: State,\n ): Promise<SandboxProviderHandleIface<S>>;\n // Park: pause or stop the sandbox, returning the state resume needs.\n park?(ctx: SandboxStartContextIface, artifact: Artifact, state: State): Promise<State>;\n onSessionEnd?(\n ctx: SandboxStartContextIface,\n artifact: Artifact,\n state: State,\n options: { reason: SandboxSessionEndReason },\n ): Promise<void>;\n}\n\nexport interface SandboxProviderDefinitionIface<\n EnvOptions,\n OpenOptions,\n Artifact extends JsonValue,\n State extends JsonValue,\n S extends NetworkSandboxSessionIface,\n> {\n name: string;\n // The version of `State`'s shape. The session service records it with each\n // binding and refuses to resume a state written under another version (the\n // next call starts the sandbox again instead).\n stateProtocolVersion?: number;\n environment(\n options?: EnvOptions,\n ): SandboxProviderImplementationIface<OpenOptions, Artifact, State, S>;\n}\n\n// A defined provider: the definition plus authoring sugar. `environment(opts)`\n// returns an environment whose `.open(openOptions)` records a sandbox binding\n// target when authored, and is what the session service drives at run time.\nexport interface SandboxProviderIface<\n EnvOptions,\n OpenOptions,\n Artifact extends JsonValue,\n State extends JsonValue,\n S extends NetworkSandboxSessionIface,\n> {\n readonly definition: SandboxProviderDefinitionIface<EnvOptions, OpenOptions, Artifact, State, S>;\n readonly name: string;\n environment(options?: EnvOptions): AwaitableSandboxEnvironmentIface<EnvOptions, OpenOptions>;\n}\n\nexport interface SandboxEnvironmentIface<EnvOptions, OpenOptions> {\n readonly providerName: string;\n readonly options: EnvOptions | undefined;\n // Provider-authored notices shown by the compiler and Build before publication.\n readonly authoringWarnings?: readonly string[];\n // Authoring: records the open options (access, ...) for this target.\n open(options?: OpenOptions): SandboxOpenRequestIface<EnvOptions, OpenOptions>;\n}\n\n// An environment whose open request a sandbox.ts selector can await to get\n// the live session (open-scope.ts); what defineSandboxProvider and the\n// installed helpers return.\nexport interface AwaitableSandboxEnvironmentIface<\n EnvOptions,\n OpenOptions,\n> extends SandboxEnvironmentIface<EnvOptions, OpenOptions> {\n open(options?: OpenOptions): AwaitableSandboxOpenRequestIface<EnvOptions, OpenOptions>;\n}\n\nexport interface SandboxOpenRequestIface<EnvOptions, OpenOptions> {\n readonly providerName: string;\n readonly environmentOptions: EnvOptions | undefined;\n readonly openOptions: OpenOptions | undefined;\n readonly authoringWarnings?: readonly string[];\n}\n\nexport const defineSandboxProvider = <\n EnvOptions,\n OpenOptions,\n Artifact extends JsonValue,\n State extends JsonValue,\n S extends NetworkSandboxSessionIface,\n>(\n definition: SandboxProviderDefinitionIface<EnvOptions, OpenOptions, Artifact, State, S>,\n): SandboxProviderIface<EnvOptions, OpenOptions, Artifact, State, S> => ({\n definition: withSandboxOverrides(definition, {\n environment: (options?: EnvOptions) => {\n const implementation = definition.environment(options);\n if (typeof implementation.awaitRunning !== 'function')\n throw new Error(`sandbox provider ${definition.name} does not implement awaitRunning`);\n const overrides: Partial<typeof implementation> = {\n start: async (ctx, openOptions, artifact) => {\n const started = await implementation.start(ctx, openOptions, artifact);\n return {\n ...started,\n handle: createSandboxHandle({\n handle: started.handle,\n executionPolicy: ctx.executionPolicy,\n }),\n };\n },\n resume: async (ctx, artifact, state) =>\n createSandboxHandle({\n handle: await implementation.resume(ctx, artifact, state),\n executionPolicy: ctx.executionPolicy,\n }),\n };\n if (implementation.editor != null) {\n const editor = implementation.editor.bind(implementation);\n overrides.editor = async (ctx, state, request) => {\n if (\n request.operation === SandboxEditorOperation.Open ||\n request.operation === SandboxEditorOperation.Refresh\n )\n await ctx.executionPolicy?.beforeExecution({\n operation: SandboxExecutionOperation.Editor,\n background: false,\n });\n return editor(ctx, state, request);\n };\n }\n if (implementation.resumePassive != null) {\n const resumePassive = implementation.resumePassive.bind(implementation);\n overrides.resumePassive = async (ctx, artifact, state) =>\n createSandboxHandle({\n handle: await resumePassive(ctx, artifact, state),\n executionPolicy: ctx.executionPolicy,\n });\n }\n return withSandboxOverrides(implementation, overrides);\n },\n }),\n name: definition.name,\n environment: (options) => ({\n providerName: definition.name,\n options,\n open: (openOptions) =>\n awaitableOpenRequest({\n providerName: definition.name,\n environmentOptions: options,\n openOptions,\n }),\n }),\n});\n\n// Erased form the session service stores in its provider registry.\nexport type AnySandboxProviderIface = SandboxProviderIface<\n JsonValue,\n JsonValue,\n JsonValue,\n JsonValue,\n NetworkSandboxSessionIface\n>;\n\n// Events emitted through a sandbox provider's process lifecycle.\nexport enum SandboxEventKind {\n ProcessExited = 'process_exited',\n}\n"],
5
- "mappings": "AAAA,SAAS,wBAAwB;AACjC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A;",
4
+ "sourcesContent": ["import { SandboxEntryType } from \"./file-kind.mjs\";\nexport { SandboxEntryType } from \"./file-kind.mjs\";\nimport type { HostedBindingsIface } from \"../hosted-bindings.mjs\";\nimport { createSandboxHandle, type SandboxExecutionPolicyIface } from \"./handle.mjs\";\nimport { withSandboxOverrides } from \"./overrides.mjs\";\nimport { WorkspaceNetworkPolicy as NetworkPolicy } from '@finalai/agent-protocol/device-egress';\nimport type {\n WorkspaceEgressRequestIface,\n WorkspaceEgressStatusIface,\n WorkspaceNetworkPolicyIface as NetworkPolicyIface,\n} from '@finalai/agent-protocol/device-egress';\nexport {\n WorkspaceNetworkPolicy as NetworkPolicy,\n type WorkspaceNetworkPolicyIface as NetworkPolicyIface,\n} from '@finalai/agent-protocol/device-egress';\nimport type {\n ProcessInspectionRequestIface,\n ProcessInspectionResultIface,\n} from '@finalai/agent-protocol/process-inspection';\nimport type { JsonValue } from \"../json.mjs\";\nimport type { ToolDescriptorIface } from \"../manifest.mjs\";\nimport {\n SandboxEditorOperation,\n type SandboxEditorRequestIface,\n type SandboxEditorResultIface,\n} from \"./editor.mjs\";\nimport { SandboxExecutionOperation } from \"./execution-guard.mjs\";\nimport { awaitableOpenRequest, type AwaitableSandboxOpenRequestIface } from \"./open-scope.mjs\";\nimport type { SandboxSnapshotRequestIface, SandboxSnapshotResponseIface } from \"./snapshots.mjs\";\n\n// Sandbox providers and consumers share the streaming session contract.\n\nexport interface AbortableIface {\n abortSignal?: AbortSignal;\n}\n\nexport interface SandboxProcessOptionsIface extends AbortableIface {\n command: string;\n args?: string[];\n cwd?: string;\n env?: Record<string, string>;\n // Run through the sandbox's login shell (`bash -lc`) instead of exec'ing.\n shell?: boolean;\n stdin?: ReadableStream<Uint8Array> | string;\n timeoutMs?: number;\n}\n\nexport interface SandboxProcessIface {\n readonly pid: string | null;\n readonly stdout: ReadableStream<Uint8Array>;\n readonly stderr: ReadableStream<Uint8Array>;\n // Writes to the process's stdin; closes stdin when `end` is true.\n write(data: Uint8Array | string, options?: { end?: boolean }): Promise<void>;\n wait(): Promise<{ exitCode: number }>;\n kill(signal?: string): Promise<void>;\n}\n\nexport interface SandboxRunResultIface {\n exitCode: number;\n stdout: string;\n stderr: string;\n}\n\nexport interface StatIface {\n path: string;\n type: SandboxEntryType;\n size: number;\n modifiedAt: string | null;\n mode: number | null;\n}\n\nexport interface DirEntryIface {\n name: string;\n path: string;\n type: SandboxEntryType;\n size: number | null;\n}\n\nexport interface ConfinedSandboxFilesIface {\n readFile(\n options: { path: string; root: string } & AbortableIface,\n ): Promise<ReadableStream<Uint8Array> | null>;\n stat(options: { path: string; root: string } & AbortableIface): Promise<StatIface | null>;\n readDir(\n options: { path: string; root: string } & AbortableIface,\n ): Promise<DirEntryIface[] | null>;\n}\n\nexport interface SandboxSessionIface {\n readonly description: string;\n readonly confinedFileReader?: ConfinedSandboxFilesIface;\n // On the RPC surface, root confines viewer reads to this directory, rejects\n // symlink ancestors and requires Python 3 in the sandbox (confinedFiles feature).\n readFile(\n options: { path: string; root?: string } & AbortableIface,\n ): Promise<ReadableStream<Uint8Array> | null>;\n readBinaryFile(options: { path: string } & AbortableIface): Promise<Uint8Array | null>;\n readTextFile(\n options: {\n path: string;\n encoding?: string;\n startLine?: number;\n endLine?: number;\n } & AbortableIface,\n ): Promise<string | null>;\n writeFile(\n options: { path: string; content: ReadableStream<Uint8Array> } & AbortableIface,\n ): Promise<void>;\n writeBinaryFile(options: { path: string; content: Uint8Array } & AbortableIface): Promise<void>;\n // Writes create missing parent directories.\n writeTextFile(\n options: { path: string; content: string; encoding?: string } & AbortableIface,\n ): Promise<void>;\n spawn(options: SandboxProcessOptionsIface): Promise<SandboxProcessIface>;\n run(options: SandboxProcessOptionsIface): Promise<SandboxRunResultIface>;\n stat(options: { path: string; root?: string } & AbortableIface): Promise<StatIface | null>;\n readDir(options: { path: string; root?: string } & AbortableIface): Promise<DirEntryIface[]>;\n resolvePath(path: string): string;\n removePath(\n options: { path: string; recursive?: boolean; force?: boolean } & AbortableIface,\n ): Promise<void>;\n}\n\nexport enum PortProtocol {\n Http = 'http',\n Https = 'https',\n Ws = 'ws',\n}\n\n// An MCP transport the sandbox serves for an optional capability: an HTTP MCP\n// endpoint the harness (or the host) can dial.\nexport interface McpEndpointIface {\n name: string;\n url: string;\n headers: Record<string, string>;\n}\n\n// A JSON-RPC message channel to an MCP server the sandbox hosts, for backends\n// whose API reaches it some other way than HTTP MCP (a byte pipe, a socket).\n// Messages are JSON-RPC objects, in order.\nexport interface McpChannelIface {\n send(message: JsonValue, options?: AbortableIface): Promise<void>;\n // The messages that arrived since the last call; [] when none did.\n receive(options?: AbortableIface): Promise<JsonValue[]>;\n close(): Promise<void>;\n}\n\n// An MCP server the sandbox hosts, opened in process by whoever runs the handle.\n// It cannot cross the handle RPC wire.\nexport interface McpChannelEndpointIface {\n name: string;\n connect(options?: AbortableIface): Promise<McpChannelIface>;\n}\n\nexport type SandboxMcpEndpoint = McpEndpointIface | McpChannelEndpointIface;\n\n// The tools of a sandbox's hosted MCP servers, as far as they are known without\n// starting it. Null: unknown until the sandbox is attached and asked.\nexport interface SandboxMcpCatalogIface {\n computerUse: ToolDescriptorIface[] | null;\n // Local MCP server name \u2192 its tools.\n localMcp: Record<string, ToolDescriptorIface[]> | null;\n // Partial discovery retains known tools and must be retried, including after caching.\n localMcpIncomplete?: boolean;\n}\n\nexport const isMcpChannelEndpoint = (\n endpoint: SandboxMcpEndpoint,\n): endpoint is McpChannelEndpointIface => 'connect' in endpoint;\n\nexport interface ScreenOptionsIface {\n // View-only by default; explicit input control requires execute access.\n viewOnly?: boolean;\n}\n\nexport interface ScreenSessionIface {\n // A short-lived viewer grant; providers enforce the requested input access.\n url: string;\n token: string;\n expiresAt: string;\n}\n\nexport interface NetworkSandboxSessionIface extends SandboxSessionIface {\n readonly id: string;\n readonly defaultWorkingDirectory: string;\n readonly ports: readonly number[];\n getPortEndpoint(options: {\n port: number;\n protocol?: PortProtocol;\n }): Promise<{ url: string; headers?: Record<string, string> }>;\n getPortUrl(options: { port: number; protocol?: PortProtocol }): Promise<string>;\n stop(): Promise<void>;\n destroy(): Promise<void>;\n setNetworkPolicy?(policy: NetworkPolicyIface): Promise<void>;\n egress?(request: WorkspaceEgressRequestIface): Promise<WorkspaceEgressStatusIface>;\n computerUse?(): Promise<SandboxMcpEndpoint>;\n screen?(options?: ScreenOptionsIface): Promise<ScreenSessionIface>;\n localMcp?(): Promise<SandboxMcpEndpoint[]>;\n}\n\n// Capabilities a started sandbox advertises (and the handle RPC exposes).\nexport enum SandboxCapability {\n Files = 'files',\n Process = 'process',\n Ports = 'ports',\n NetworkPolicy = 'networkPolicy',\n Egress = 'egress',\n ComputerUse = 'computerUse',\n Screen = 'screen',\n LocalMcp = 'localMcp',\n Browser = 'browser',\n}\n\nexport interface SandboxProviderHandleIface<S extends SandboxSessionIface> {\n readonly sandbox: S;\n // Pending policy; the generic handle constructor consumes it before exposing execution.\n readonly executionPolicy?: SandboxExecutionPolicyIface;\n onSandboxStop(): Promise<void>;\n onSandboxDelete(options?: { reason?: string }): Promise<void>;\n onRuntimeShutdown(): Promise<void>;\n}\n\n// A saved computer setup guide version: Build's versioned build-\n// and start-time inputs for a sandbox, as the host serves them.\nexport interface SandboxGuideVersionIface {\n guideId: string;\n versionId: string;\n slug: string;\n title: string;\n number: number;\n image: string;\n // `.final/sandbox-template.yaml` v2 as JSON.\n templateConfig: JsonValue;\n // The start-time parameters this version defaults to.\n defaultParameters: JsonValue;\n instructionsMarkdown: string | null;\n // A ready build from the guide's provider, reusable independently of workspace seeds.\n preparedArtifact?: { providerRef: string; key: string; artifact: JsonValue };\n}\n\n// The organization's computer setup guides, read through the host.\n// Every provider gets the same reader; a provider whose\n// environments name no guide never calls it.\nexport interface SandboxGuidesIface {\n get(args: { ref: string; version: number | 'latest' }): Promise<SandboxGuideVersionIface | null>;\n // The organization's default guide; null when it has none.\n default(): Promise<SandboxGuideVersionIface | null>;\n}\n\n// Where to clone a repository from, with a short-lived read credential that\n// must reach only the clone process (never a repository's git config).\nexport interface SandboxRepositoryCloneSourceIface {\n url: string;\n // Checked out after the clone; null keeps the default branch.\n ref: string | null;\n // An HTTP Authorization header value for the clone, or null.\n authorization: string | null;\n}\n\n// Repository credentials for the repositories an environment names (a Final\n// repository id, a GitHub owner/name), resolved by the host for the session's\n// organization only. Null: not a repository it can resolve.\nexport interface SandboxRepositoriesIface {\n cloneSource(args: {\n repository: string;\n ref: string | null;\n }): Promise<SandboxRepositoryCloneSourceIface | null>;\n}\n\n// Reads a named variable (a secret managed in Build) for the session. Values are\n// injected into the sandbox only, never stored in a manifest, a state or the log.\nexport interface SandboxVariablesIface {\n get(name: string): Promise<string | null>;\n}\n\nexport const noSandboxGuides: SandboxGuidesIface = {\n get: async () => null,\n default: async () => null,\n};\n\nexport const noSandboxRepositories: SandboxRepositoriesIface = {\n cloneSource: async () => null,\n};\n\nexport const noSandboxVariables: SandboxVariablesIface = { get: async () => null };\n\n// The user a session acts for: the author of its running turn, else its owner,\n// else the user whose Home its conversation is. A call a person makes through\n// the platform's sandbox viewer acts for that person instead. Null when it acts\n// for no user (a turn nobody prompted in a shared conversation) and outside any\n// session (a guide build). Read on each call, because it changes between turns\n// and between callers.\nexport interface SandboxActingUserIface {\n current(): Promise<string | null>;\n}\n\nexport const noSandboxActingUser: SandboxActingUserIface = { current: async () => null };\n\n// Access to a Final API: its origin and a short-lived bearer token. The token\n// determines the organization and project, so requests name neither.\nexport interface FinalPlatformAccessIface {\n // The API origin; requests go to `<baseUrl>/v1/...`.\n baseUrl: string;\n token: string;\n}\n\n// Credentials the host supplies with a sandbox context. Providers read no secrets\n// and name no project themselves.\nexport interface SandboxCredentialsIface {\n // Access to the Computers API (the `computer` sandbox); null when the host grants\n // none. `refresh` asks for a new token after the API rejected the last one.\n computersAccess(args?: { refresh?: boolean }): Promise<FinalPlatformAccessIface | null>;\n // Access to the Device API (the `device` sandbox and workspace Device egress),\n // acting for `actingUserId` when given (null or absent: service access for\n // workspace networking); null when the host grants none.\n deviceAccess(args?: {\n actingUserId?: string | null;\n refresh?: boolean;\n }): Promise<FinalPlatformAccessIface | null>;\n // The value of the secret a provider's `credential.secretRef` names; null when it\n // is not set.\n secret(args: { secretRef: string }): Promise<string | null>;\n}\n\nexport const noSandboxCredentials: SandboxCredentialsIface = {\n computersAccess: async () => null,\n deviceAccess: async () => null,\n secret: async () => null,\n};\n\n// What an environment's pre-start reads (capabilities, mcpCatalog) are given.\nexport interface SandboxOfferContextIface {\n executionPolicy?: SandboxExecutionPolicyIface;\n platformNetworkPolicy?: (policy: NetworkPolicyIface) => Promise<void>;\n // Retain platform transport access when an extension restores an allowlist.\n platformEgressHosts?: string[];\n // Logical identity when inspecting an existing workspace or opening an execution extension.\n workspaceId?: string;\n bindings?: HostedBindingsIface;\n organizationId: string;\n credentials?: SandboxCredentialsIface;\n actingUser: SandboxActingUserIface;\n}\n\n// What an environment's hooks are given before anything starts.\nexport interface SandboxEnvironmentContextIface {\n bindings?: HostedBindingsIface;\n organizationId: string;\n guides: SandboxGuidesIface;\n}\n\n// Scoped by the host to this organization and provider. Providers can retain\n// reusable intermediate artifacts independently of a revision's seed files.\nexport interface SandboxArtifactsIface {\n get(key: string): Promise<JsonValue | null>;\n put(key: string, artifact: JsonValue): Promise<void>;\n}\n\nexport interface SandboxPreparationSourceIface {\n sourceRevision: string;\n read(): Promise<{ files: Record<string, string>; resources: Record<string, JsonValue> }>;\n}\n\nexport interface SandboxPrepareContextIface {\n bindings?: HostedBindingsIface;\n // A host-persisted resource source; artifacts may retain its identity instead of seed contents.\n preparation?: SandboxPreparationSourceIface;\n artifacts?: SandboxArtifactsIface;\n // Agent revisions supply workspace-relative seeds; setup-guide builds supply\n // guide.json and optional instructions.md. Resources name workspace, skills or guide.\n // Model instructions remain harness config.\n files: Record<string, string>;\n resources: Record<string, JsonValue>;\n sourceRevision: string;\n storagePath: string;\n organizationId: string;\n credentials?: SandboxCredentialsIface;\n // The guide inputs (build-time) an environment names, resolved by the platform.\n guides: SandboxGuidesIface;\n // Who the session the artifact is prepared for acts for, for environments that\n // name a backend resource relative to that user; the key must then name it.\n actingUser: SandboxActingUserIface;\n log?: (message: string) => void;\n}\n\nexport interface SandboxStartContextIface {\n // Host policy composes before the provider's policy, on every exposed execution path.\n executionPolicy?: SandboxExecutionPolicyIface;\n bindings?: HostedBindingsIface;\n /** Passive recovery only: never wake, create, seed, or restart backend services. */\n passive?: boolean;\n preparation?: SandboxPreparationSourceIface;\n session: {\n id: string;\n organizationId: string;\n conversationId: string | null;\n definitionId: string;\n bindingId: string;\n // Stable logical identity supplied by the host, independent of provider resource names.\n workspaceId?: string;\n target: string;\n };\n credentials?: SandboxCredentialsIface;\n storagePath: string;\n // Start-time inputs: guides, the variables to inject, repository credentials.\n guides: SandboxGuidesIface;\n variables: SandboxVariablesIface;\n repositories: SandboxRepositoriesIface;\n actingUser: SandboxActingUserIface;\n // Variables the platform sets in every process of this sandbox: the egress\n // proxy, trust for its CA, and one placeholder per bound secret. Evaluated\n // again for every spawn/run, never once per session: a secret bound\n // mid-session must reach the next command. May resolve to {} (no proxy\n // configured, or not ready yet). Platform values override the spec's env.\n platformEnvironment?: () => Promise<Record<string, string>>;\n // Hosts the sandbox must be able to reach for the proxy to work, to append\n // to any allowlist-mode network policy the spec declares.\n platformEgressHosts?: string[];\n // Reports the network policy now in force on the sandbox, exactly as the\n // provider applied it to its backend (after withPlatformEgressHosts). The\n // platform permits only those destinations.\n // Called after awaitRunning and before platformFiles or any command, on start,\n // resume and a reused sandbox; never for a session's own setNetworkPolicy,\n // which the platform records itself. A rejection fails the start or resume.\n platformNetworkPolicy: (policy: NetworkPolicyIface) => Promise<void>;\n // Files the platform needs in the sandbox before any clone, setup step or\n // service runs: written right after the sandbox exists, on start and resume.\n // Paths are absolute; missing parent directories are created.\n platformFiles?: () => Promise<Record<string, string>>;\n}\n\n// The variables `platformEnvironment` owns. A spec that sets one (as a plain\n// value or a named variable) is refused at start.\nexport const PLATFORM_ENVIRONMENT_NAMES: ReadonlySet<string> = new Set([\n 'HTTPS_PROXY',\n 'HTTP_PROXY',\n 'NO_PROXY',\n 'NODE_USE_ENV_PROXY',\n 'SSL_CERT_FILE',\n 'CURL_CA_BUNDLE',\n 'REQUESTS_CA_BUNDLE',\n 'GIT_SSL_CAINFO',\n 'CARGO_HTTP_CAINFO',\n 'DENO_CERT',\n 'NODE_EXTRA_CA_CERTS',\n 'FINAL_EGRESS_URL',\n 'FINAL_EGRESS_TOKEN',\n 'GH_TOKEN',\n 'GITHUB_TOKEN',\n]);\n\n// A process's base environment: the spec's variables under the platform's,\n// read again on every call.\nexport const platformProcessEnvironment =\n (\n ctx: Pick<SandboxStartContextIface, 'platformEnvironment'>,\n specEnv: Record<string, string>,\n ): (() => Promise<Record<string, string>>) =>\n async () => ({ ...specEnv, ...(await ctx.platformEnvironment?.()) });\n\n// Writes `platformFiles` into a sandbox that now exists, before it runs anything.\n// Relies on writeTextFile creating missing parent directories.\nexport const writePlatformFiles = async (\n ctx: Pick<SandboxStartContextIface, 'platformFiles'>,\n sandbox: Pick<SandboxSessionIface, 'writeTextFile'>,\n): Promise<void> => {\n for (const [path, content] of Object.entries((await ctx.platformFiles?.()) ?? {}))\n await sandbox.writeTextFile({ path, content });\n};\n\n// Reports the policy a provider just applied to its backend: `allow` only for an\n// allowlist, its entries (hosts, `*.suffix` patterns, CIDRs) unchanged.\nexport const reportPlatformNetworkPolicy = async (\n ctx: Pick<SandboxStartContextIface, 'platformNetworkPolicy'>,\n policy: NetworkPolicyIface,\n): Promise<void> =>\n ctx.platformNetworkPolicy(\n policy.mode === NetworkPolicy.Allowlist\n ? { mode: policy.mode, allow: [...(policy.allow ?? [])] }\n : { mode: policy.mode },\n );\n\n// An allowlist policy with the platform's egress hosts appended; any other\n// policy unchanged.\nexport const withPlatformEgressHosts = (\n ctx: Pick<SandboxStartContextIface, 'platformEgressHosts'>,\n policy: NetworkPolicyIface,\n): NetworkPolicyIface => {\n const hosts = ctx.platformEgressHosts ?? [];\n if (policy.mode !== NetworkPolicy.Allowlist || hosts.length === 0) return policy;\n return { ...policy, allow: [...new Set([...(policy.allow ?? []), ...hosts])] };\n};\n\nexport enum SandboxSessionEndReason {\n Completed = 'completed',\n Expired = 'expired',\n Failed = 'failed',\n}\n\n// How long an environment's sandbox outlives a session: `session`\n// keeps it for the session's life; `conversation` gives every session in the\n// conversation one shared sandbox per target, surviving session resets;\n// `ephemeral` discards it when released.\nexport enum SandboxWorkspace {\n Session = 'session',\n Conversation = 'conversation',\n Ephemeral = 'ephemeral',\n}\n\nexport interface SandboxProviderImplementationIface<\n OpenOptions,\n Artifact extends JsonValue,\n State extends JsonValue,\n S extends NetworkSandboxSessionIface,\n> {\n // The workspace this environment declares, read before anything starts so the\n // host knows which sessions share a binding. Absent or null: session.\n workspace?(ctx: SandboxEnvironmentContextIface): Promise<SandboxWorkspace | null>;\n // The capabilities this environment's sandboxes offer, read before anything\n // starts through the backend's own API. Absent or null: unknown\n // until started; local MCP is then not projected.\n capabilities?(ctx: SandboxOfferContextIface): Promise<SandboxCapability[] | null>;\n // Known positive offers when the rest of the pre-start capability set is unknown.\n additionalCapabilities?(ctx: SandboxOfferContextIface): Promise<SandboxCapability[]>;\n // The hosted MCP servers' tool catalogs the backend can give without starting\n // a sandbox (from its own records), so the MCP projection lists them from the\n // first `tools/list`. The projection checks a server's catalog against the\n // live server when a call first opens that server (servers a session never\n // uses stay closed) and announces a change with\n // `notifications/tools/list_changed`.\n //\n // Trade-off: a catalog left unknown (absent hook, null, or a null field) can\n // only be learned from the live sandbox, so the first `tools/list` that finds\n // it unknown starts the sandbox in the background, at session start rather\n // than on the first tool call. Otherwise those tools would never be listed,\n // and nothing would ever call them. Providers that can give the catalog keep\n // attach lazy.\n mcpCatalog?(ctx: SandboxOfferContextIface): Promise<SandboxMcpCatalogIface | null>;\n // Reads committed files without starting/resuming a sandbox. Null means the backend\n // is live or offers no snapshot. An unavailable sleeping snapshot must throw,\n // never fall through to a read that wakes it. Pin subsequent ranges by snapshotId.\n readSnapshot?(\n ctx: SandboxOfferContextIface,\n state: State,\n request: SandboxSnapshotRequestIface,\n ): Promise<SandboxSnapshotResponseIface | null>;\n // Inspect retained backend processes without opening, resuming or extending a sandbox.\n // Stop requires execute access; the provider also enforces backend ownership.\n processes?(\n ctx: SandboxOfferContextIface & { bindingId: string },\n state: State,\n request: ProcessInspectionRequestIface,\n ): Promise<ProcessInspectionResultIface>;\n // Browser editor for this provider's existing workspace. The host checks write\n // authorization; this hook never creates or wakes a backend. Credentials stay\n // in the authentication form, never the editor URL or stored provider state.\n editor?(\n ctx: SandboxOfferContextIface,\n state: State,\n request: SandboxEditorRequestIface,\n ): Promise<SandboxEditorResultIface>;\n // Content-addressed by `artifactKey`; the host caches artifacts and calls\n // prepare only on a miss.\n artifactKey(ctx: SandboxPrepareContextIface): Promise<string>;\n prepare(ctx: SandboxPrepareContextIface): Promise<Artifact>;\n // Resolves once the backend sandbox named by `state` is running and will\n // accept a command or a file write; rejects with a clear error after\n // `timeoutMs`. Backend-specific: the provider chooses the readiness signal,\n // the polling cadence and the backoff for its API's rate limits. The\n // platform never polls a backend itself.\n //\n // `start`, `resume` and `resumePassive` call it on the sandbox they just\n // created, started or reused, before anything touches it: create or start \u2192\n // state \u2192 awaitRunning \u2192 platformNetworkPolicy \u2192 platformFiles \u2192 repositories,\n // seeds, setup, services \u2192 handle. On timeout `start` fails and tears down.\n awaitRunning(\n ctx: SandboxStartContextIface,\n state: State,\n options: { timeoutMs: number },\n ): Promise<void>;\n // `region`: where the backend placed the sandbox (its own region name), so the\n // host can place the harness near it; null when unknown.\n start(\n ctx: SandboxStartContextIface,\n options: OpenOptions | undefined,\n artifact: Artifact,\n ): Promise<{ handle: SandboxProviderHandleIface<S>; state: State; region?: string | null }>;\n resume(\n ctx: SandboxStartContextIface,\n artifact: Artifact,\n state: State,\n ): Promise<SandboxProviderHandleIface<S>>;\n // Reconnect to an already running backend after host restart for a read-only viewer.\n // Absent: viewers can use a retained live handle but cannot trigger resume.\n resumePassive?(\n ctx: SandboxStartContextIface,\n artifact: Artifact,\n state: State,\n ): Promise<SandboxProviderHandleIface<S>>;\n // Park: pause or stop the sandbox, returning the state resume needs.\n park?(ctx: SandboxStartContextIface, artifact: Artifact, state: State): Promise<State>;\n onSessionEnd?(\n ctx: SandboxStartContextIface,\n artifact: Artifact,\n state: State,\n options: { reason: SandboxSessionEndReason },\n ): Promise<void>;\n}\n\nexport interface SandboxProviderDefinitionIface<\n EnvOptions,\n OpenOptions,\n Artifact extends JsonValue,\n State extends JsonValue,\n S extends NetworkSandboxSessionIface,\n> {\n name: string;\n // The version of `State`'s shape. The host records it with each\n // binding and refuses to resume a state written under another version (the\n // next call starts the sandbox again instead).\n stateProtocolVersion?: number;\n environment(\n options?: EnvOptions,\n ): SandboxProviderImplementationIface<OpenOptions, Artifact, State, S>;\n}\n\n// A defined provider: the definition plus authoring sugar. `environment(opts)`\n// returns an environment whose `.open(openOptions)` records a sandbox binding\n// target when authored, and is what the host drives at run time.\nexport interface SandboxProviderIface<\n EnvOptions,\n OpenOptions,\n Artifact extends JsonValue,\n State extends JsonValue,\n S extends NetworkSandboxSessionIface,\n> {\n readonly definition: SandboxProviderDefinitionIface<EnvOptions, OpenOptions, Artifact, State, S>;\n readonly name: string;\n environment(options?: EnvOptions): AwaitableSandboxEnvironmentIface<EnvOptions, OpenOptions>;\n}\n\nexport interface SandboxEnvironmentIface<EnvOptions, OpenOptions> {\n readonly providerName: string;\n readonly options: EnvOptions | undefined;\n // Provider-authored notices shown by the compiler and Build before publication.\n readonly authoringWarnings?: readonly string[];\n // Authoring: records the open options (access, ...) for this target.\n open(options?: OpenOptions): SandboxOpenRequestIface<EnvOptions, OpenOptions>;\n}\n\n// An environment whose open request a sandbox.ts selector can await to get\n// the live session (open-scope.ts); what defineSandboxProvider and the\n// installed helpers return.\nexport interface AwaitableSandboxEnvironmentIface<\n EnvOptions,\n OpenOptions,\n> extends SandboxEnvironmentIface<EnvOptions, OpenOptions> {\n open(options?: OpenOptions): AwaitableSandboxOpenRequestIface<EnvOptions, OpenOptions>;\n}\n\nexport interface SandboxOpenRequestIface<EnvOptions, OpenOptions> {\n readonly providerName: string;\n readonly environmentOptions: EnvOptions | undefined;\n readonly openOptions: OpenOptions | undefined;\n readonly authoringWarnings?: readonly string[];\n}\n\nexport const defineSandboxProvider = <\n EnvOptions,\n OpenOptions,\n Artifact extends JsonValue,\n State extends JsonValue,\n S extends NetworkSandboxSessionIface,\n>(\n definition: SandboxProviderDefinitionIface<EnvOptions, OpenOptions, Artifact, State, S>,\n): SandboxProviderIface<EnvOptions, OpenOptions, Artifact, State, S> => ({\n definition: withSandboxOverrides(definition, {\n environment: (options?: EnvOptions) => {\n const implementation = definition.environment(options);\n if (typeof implementation.awaitRunning !== 'function')\n throw new Error(`sandbox provider ${definition.name} does not implement awaitRunning`);\n const overrides: Partial<typeof implementation> = {\n start: async (ctx, openOptions, artifact) => {\n const started = await implementation.start(ctx, openOptions, artifact);\n return {\n ...started,\n handle: createSandboxHandle({\n handle: started.handle,\n executionPolicy: ctx.executionPolicy,\n }),\n };\n },\n resume: async (ctx, artifact, state) =>\n createSandboxHandle({\n handle: await implementation.resume(ctx, artifact, state),\n executionPolicy: ctx.executionPolicy,\n }),\n };\n if (implementation.editor != null) {\n const editor = implementation.editor.bind(implementation);\n overrides.editor = async (ctx, state, request) => {\n if (\n request.operation === SandboxEditorOperation.Open ||\n request.operation === SandboxEditorOperation.Refresh\n )\n await ctx.executionPolicy?.beforeExecution({\n operation: SandboxExecutionOperation.Editor,\n background: false,\n });\n return editor(ctx, state, request);\n };\n }\n if (implementation.resumePassive != null) {\n const resumePassive = implementation.resumePassive.bind(implementation);\n overrides.resumePassive = async (ctx, artifact, state) =>\n createSandboxHandle({\n handle: await resumePassive(ctx, artifact, state),\n executionPolicy: ctx.executionPolicy,\n });\n }\n return withSandboxOverrides(implementation, overrides);\n },\n }),\n name: definition.name,\n environment: (options) => ({\n providerName: definition.name,\n options,\n open: (openOptions) =>\n awaitableOpenRequest({\n providerName: definition.name,\n environmentOptions: options,\n openOptions,\n }),\n }),\n});\n\n// Erased form a host stores in its provider registry.\nexport type AnySandboxProviderIface = SandboxProviderIface<\n JsonValue,\n JsonValue,\n JsonValue,\n JsonValue,\n NetworkSandboxSessionIface\n>;\n\n// Events emitted through a sandbox provider's process lifecycle.\nexport enum SandboxEventKind {\n ProcessExited = 'process_exited',\n}\n"],
5
+ "mappings": "AAAA,SAAS,wBAAwB;AACjC,SAAS,oBAAAA,yBAAwB;AAEjC,SAAS,2BAA6D;AACtE,SAAS,4BAA4B;AACrC,SAAS,0BAA0B,qBAAqB;AAMxD;AAAA,EAC4B;AAAA,OAErB;AAOP;AAAA,EACE;AAAA,OAGK;AACP,SAAS,iCAAiC;AAC1C,SAAS,4BAAmE;AAgGrE,IAAK,eAAL,kBAAKC,kBAAL;AACL,EAAAA,cAAA,UAAO;AACP,EAAAA,cAAA,WAAQ;AACR,EAAAA,cAAA,QAAK;AAHK,SAAAA;AAAA,GAAA;AA2CL,MAAM,uBAAuB,CAClC,aACwC,aAAa;AAiChD,IAAK,oBAAL,kBAAKC,uBAAL;AACL,EAAAA,mBAAA,WAAQ;AACR,EAAAA,mBAAA,aAAU;AACV,EAAAA,mBAAA,WAAQ;AACR,EAAAA,mBAAA,mBAAgB;AAChB,EAAAA,mBAAA,YAAS;AACT,EAAAA,mBAAA,iBAAc;AACd,EAAAA,mBAAA,YAAS;AACT,EAAAA,mBAAA,cAAW;AACX,EAAAA,mBAAA,aAAU;AATA,SAAAA;AAAA,GAAA;AA0EL,MAAM,kBAAsC;AAAA,EACjD,KAAK,YAAY;AAAA,EACjB,SAAS,YAAY;AACvB;AAEO,MAAM,wBAAkD;AAAA,EAC7D,aAAa,YAAY;AAC3B;AAEO,MAAM,qBAA4C,EAAE,KAAK,YAAY,KAAK;AAY1E,MAAM,sBAA8C,EAAE,SAAS,YAAY,KAAK;AA4BhF,MAAM,uBAAgD;AAAA,EAC3D,iBAAiB,YAA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iBAAiB,IAAI;AAAA,QACvB,CAAC;AAAA,MACL;AACA,aAAO,qBAAqB,gBAAgB,SAAS;AAAA,IACvD;AAAA,EACF,CAAC;AAAA,EACD,MAAM,WAAW;AAAA,EACjB,aAAa,CAAC,aAAa;AAAA,IACzB,cAAc,WAAW;AAAA,IACzB;AAAA,IACA,MAAM,CAAC,gBACL,qBAAqB;AAAA,MACnB,cAAc,WAAW;AAAA,MACzB,oBAAoB;AAAA,MACpB;AAAA,IACF,CAAC;AAAA,EACL;AACF;AAYO,IAAK,mBAAL,kBAAKC,sBAAL;AACL,EAAAA,kBAAA,mBAAgB;AADN,SAAAA;AAAA,GAAA;",
6
6
  "names": ["SandboxEntryType", "PortProtocol", "SandboxCapability", "SandboxSessionEndReason", "SandboxWorkspace", "SandboxEventKind"]
7
7
  }
@@ -4,7 +4,17 @@ export declare enum SemanticChannelEventKind {
4
4
  MessageDelta = "message.delta",
5
5
  MessageCompleted = "message.completed",
6
6
  TurnStarted = "turn.started",
7
- TurnCompleted = "turn.completed"
7
+ TurnCompleted = "turn.completed",
8
+ ToolStarted = "tool.started",
9
+ ToolCompleted = "tool.completed",
10
+ PlanUpdated = "plan.updated",
11
+ DecisionCreated = "decision.created",
12
+ DecisionResolved = "decision.resolved",
13
+ MessageEdited = "message.edited",
14
+ MessageRemoved = "message.removed",
15
+ MessagePosted = "message.posted",
16
+ ReactionAdded = "reaction.added",
17
+ ReactionRemoved = "reaction.removed"
8
18
  }
9
19
  export declare const channelMessageCompletedSchema: z.ZodObject<{
10
20
  message: z.ZodObject<{
@@ -21,6 +31,12 @@ export interface ChannelMessageDeltaDataIface {
21
31
  export declare const channelTurnEventSchema: z.ZodObject<{
22
32
  turnId: z.ZodString;
23
33
  stopReason: z.ZodOptional<z.ZodNullable<z.ZodString>>;
34
+ content: z.ZodOptional<z.ZodArray<z.ZodType<JsonObject, unknown, z.core.$ZodTypeInternals<JsonObject, unknown>>>>;
35
+ messages: z.ZodOptional<z.ZodArray<z.ZodObject<{
36
+ id: z.ZodString;
37
+ content: z.ZodArray<z.ZodType<JsonObject, unknown, z.core.$ZodTypeInternals<JsonObject, unknown>>>;
38
+ }, z.core.$strip>>>;
39
+ externalKey: z.ZodOptional<z.ZodString>;
24
40
  }, z.core.$strip>;
25
41
  export type ChannelTurnEventDataIface = z.infer<typeof channelTurnEventSchema>;
26
42
  export interface ChannelSemanticDataByKindIface {
@@ -29,3 +45,55 @@ export interface ChannelSemanticDataByKindIface {
29
45
  'turn.started': ChannelTurnEventDataIface;
30
46
  'turn.completed': ChannelTurnEventDataIface;
31
47
  }
48
+ export interface ChannelToolEventDataIface {
49
+ toolCallId: string;
50
+ title: string;
51
+ status: string;
52
+ content?: JsonObject[];
53
+ }
54
+ export interface ChannelPlanUpdatedDataIface {
55
+ entries: JsonObject[];
56
+ }
57
+ export interface ChannelDecisionEventDataIface {
58
+ decisionId: string;
59
+ kind: string;
60
+ request: JsonObject;
61
+ requester?: import("./channel.mjs").PrincipalRef;
62
+ outcome?: import("./json.mjs").JsonValue;
63
+ }
64
+ export interface ChannelOriginMessageDataIface {
65
+ externalKey: string;
66
+ message: {
67
+ id: string;
68
+ content: JsonObject[];
69
+ };
70
+ author: {
71
+ displayName: string;
72
+ kind: string;
73
+ };
74
+ replyOf?: {
75
+ externalKey: string;
76
+ turnId: string;
77
+ };
78
+ }
79
+ export interface ChannelReactionEventDataIface {
80
+ externalKey: string;
81
+ emoji: string;
82
+ principal: import("./channel.mjs").PrincipalRef;
83
+ replyOf?: {
84
+ externalKey: string;
85
+ turnId: string;
86
+ };
87
+ }
88
+ export interface ChannelSemanticDataByKindIface {
89
+ 'tool.started': ChannelToolEventDataIface;
90
+ 'tool.completed': ChannelToolEventDataIface;
91
+ 'plan.updated': ChannelPlanUpdatedDataIface;
92
+ 'decision.created': ChannelDecisionEventDataIface;
93
+ 'decision.resolved': ChannelDecisionEventDataIface;
94
+ 'message.edited': ChannelOriginMessageDataIface;
95
+ 'message.removed': ChannelOriginMessageDataIface;
96
+ 'message.posted': ChannelOriginMessageDataIface;
97
+ 'reaction.added': ChannelReactionEventDataIface;
98
+ 'reaction.removed': ChannelReactionEventDataIface;
99
+ }
@@ -5,6 +5,16 @@ var SemanticChannelEventKind = /* @__PURE__ */ ((SemanticChannelEventKind2) => {
5
5
  SemanticChannelEventKind2["MessageCompleted"] = "message.completed";
6
6
  SemanticChannelEventKind2["TurnStarted"] = "turn.started";
7
7
  SemanticChannelEventKind2["TurnCompleted"] = "turn.completed";
8
+ SemanticChannelEventKind2["ToolStarted"] = "tool.started";
9
+ SemanticChannelEventKind2["ToolCompleted"] = "tool.completed";
10
+ SemanticChannelEventKind2["PlanUpdated"] = "plan.updated";
11
+ SemanticChannelEventKind2["DecisionCreated"] = "decision.created";
12
+ SemanticChannelEventKind2["DecisionResolved"] = "decision.resolved";
13
+ SemanticChannelEventKind2["MessageEdited"] = "message.edited";
14
+ SemanticChannelEventKind2["MessageRemoved"] = "message.removed";
15
+ SemanticChannelEventKind2["MessagePosted"] = "message.posted";
16
+ SemanticChannelEventKind2["ReactionAdded"] = "reaction.added";
17
+ SemanticChannelEventKind2["ReactionRemoved"] = "reaction.removed";
8
18
  return SemanticChannelEventKind2;
9
19
  })(SemanticChannelEventKind || {});
10
20
  const channelMessageCompletedSchema = z.object({
@@ -13,7 +23,10 @@ const channelMessageCompletedSchema = z.object({
13
23
  });
14
24
  const channelTurnEventSchema = z.object({
15
25
  turnId: z.string(),
16
- stopReason: z.string().nullable().optional()
26
+ stopReason: z.string().nullable().optional(),
27
+ content: z.array(jsonObjectSchema).optional(),
28
+ messages: z.array(z.object({ id: z.string(), content: z.array(jsonObjectSchema) })).optional(),
29
+ externalKey: z.string().optional()
17
30
  });
18
31
  export {
19
32
  SemanticChannelEventKind,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/semantic-events.ts"],
4
- "sourcesContent": ["import * as z from 'zod';\nimport { jsonObjectSchema, type JsonObject } from \"./json.mjs\";\n\nexport enum SemanticChannelEventKind {\n MessageDelta = 'message.delta',\n MessageCompleted = 'message.completed',\n TurnStarted = 'turn.started',\n TurnCompleted = 'turn.completed',\n}\n\nexport const channelMessageCompletedSchema = z.object({\n message: z.object({ id: z.string(), content: z.array(jsonObjectSchema) }),\n finishReason: z.string().nullable(),\n});\nexport type ChannelMessageCompletedDataIface = z.infer<typeof channelMessageCompletedSchema>;\nexport interface ChannelMessageDeltaDataIface {\n messageId: string;\n delta: JsonObject;\n}\nexport const channelTurnEventSchema = z.object({\n turnId: z.string(),\n stopReason: z.string().nullable().optional(),\n});\nexport type ChannelTurnEventDataIface = z.infer<typeof channelTurnEventSchema>;\nexport interface ChannelSemanticDataByKindIface {\n 'message.delta': ChannelMessageDeltaDataIface;\n 'message.completed': ChannelMessageCompletedDataIface;\n 'turn.started': ChannelTurnEventDataIface;\n 'turn.completed': ChannelTurnEventDataIface;\n}\n"],
5
- "mappings": "AAAA,YAAY,OAAO;AACnB,SAAS,wBAAyC;AAE3C,IAAK,2BAAL,kBAAKA,8BAAL;AACL,EAAAA,0BAAA,kBAAe;AACf,EAAAA,0BAAA,sBAAmB;AACnB,EAAAA,0BAAA,iBAAc;AACd,EAAAA,0BAAA,mBAAgB;AAJN,SAAAA;AAAA,GAAA;AAOL,MAAM,gCAAgC,EAAE,OAAO;AAAA,EACpD,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,GAAG,SAAS,EAAE,MAAM,gBAAgB,EAAE,CAAC;AAAA,EACxE,cAAc,EAAE,OAAO,EAAE,SAAS;AACpC,CAAC;AAMM,MAAM,yBAAyB,EAAE,OAAO;AAAA,EAC7C,QAAQ,EAAE,OAAO;AAAA,EACjB,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS;AAC7C,CAAC;",
4
+ "sourcesContent": ["import * as z from 'zod';\nimport { jsonObjectSchema, type JsonObject } from \"./json.mjs\";\n\nexport enum SemanticChannelEventKind {\n MessageDelta = 'message.delta',\n MessageCompleted = 'message.completed',\n TurnStarted = 'turn.started',\n TurnCompleted = 'turn.completed',\n ToolStarted = 'tool.started',\n ToolCompleted = 'tool.completed',\n PlanUpdated = 'plan.updated',\n DecisionCreated = 'decision.created',\n DecisionResolved = 'decision.resolved',\n MessageEdited = 'message.edited',\n MessageRemoved = 'message.removed',\n MessagePosted = 'message.posted',\n ReactionAdded = 'reaction.added',\n ReactionRemoved = 'reaction.removed',\n}\n\nexport const channelMessageCompletedSchema = z.object({\n message: z.object({ id: z.string(), content: z.array(jsonObjectSchema) }),\n finishReason: z.string().nullable(),\n});\nexport type ChannelMessageCompletedDataIface = z.infer<typeof channelMessageCompletedSchema>;\nexport interface ChannelMessageDeltaDataIface {\n messageId: string;\n delta: JsonObject;\n}\nexport const channelTurnEventSchema = z.object({\n turnId: z.string(),\n stopReason: z.string().nullable().optional(),\n content: z.array(jsonObjectSchema).optional(),\n messages: z.array(z.object({ id: z.string(), content: z.array(jsonObjectSchema) })).optional(),\n externalKey: z.string().optional(),\n});\nexport type ChannelTurnEventDataIface = z.infer<typeof channelTurnEventSchema>;\nexport interface ChannelSemanticDataByKindIface {\n 'message.delta': ChannelMessageDeltaDataIface;\n 'message.completed': ChannelMessageCompletedDataIface;\n 'turn.started': ChannelTurnEventDataIface;\n 'turn.completed': ChannelTurnEventDataIface;\n}\n\nexport interface ChannelToolEventDataIface {\n toolCallId: string;\n title: string;\n status: string;\n content?: JsonObject[];\n}\nexport interface ChannelPlanUpdatedDataIface {\n entries: JsonObject[];\n}\nexport interface ChannelDecisionEventDataIface {\n decisionId: string;\n kind: string;\n request: JsonObject;\n requester?: import(\"./channel.mjs\").PrincipalRef;\n outcome?: import(\"./json.mjs\").JsonValue;\n}\nexport interface ChannelOriginMessageDataIface {\n externalKey: string;\n message: { id: string; content: JsonObject[] };\n author: { displayName: string; kind: string };\n replyOf?: { externalKey: string; turnId: string };\n}\nexport interface ChannelReactionEventDataIface {\n externalKey: string;\n emoji: string;\n principal: import(\"./channel.mjs\").PrincipalRef;\n replyOf?: { externalKey: string; turnId: string };\n}\nexport interface ChannelSemanticDataByKindIface {\n 'tool.started': ChannelToolEventDataIface;\n 'tool.completed': ChannelToolEventDataIface;\n 'plan.updated': ChannelPlanUpdatedDataIface;\n 'decision.created': ChannelDecisionEventDataIface;\n 'decision.resolved': ChannelDecisionEventDataIface;\n 'message.edited': ChannelOriginMessageDataIface;\n 'message.removed': ChannelOriginMessageDataIface;\n 'message.posted': ChannelOriginMessageDataIface;\n 'reaction.added': ChannelReactionEventDataIface;\n 'reaction.removed': ChannelReactionEventDataIface;\n}\n"],
5
+ "mappings": "AAAA,YAAY,OAAO;AACnB,SAAS,wBAAyC;AAE3C,IAAK,2BAAL,kBAAKA,8BAAL;AACL,EAAAA,0BAAA,kBAAe;AACf,EAAAA,0BAAA,sBAAmB;AACnB,EAAAA,0BAAA,iBAAc;AACd,EAAAA,0BAAA,mBAAgB;AAChB,EAAAA,0BAAA,iBAAc;AACd,EAAAA,0BAAA,mBAAgB;AAChB,EAAAA,0BAAA,iBAAc;AACd,EAAAA,0BAAA,qBAAkB;AAClB,EAAAA,0BAAA,sBAAmB;AACnB,EAAAA,0BAAA,mBAAgB;AAChB,EAAAA,0BAAA,oBAAiB;AACjB,EAAAA,0BAAA,mBAAgB;AAChB,EAAAA,0BAAA,mBAAgB;AAChB,EAAAA,0BAAA,qBAAkB;AAdR,SAAAA;AAAA,GAAA;AAiBL,MAAM,gCAAgC,EAAE,OAAO;AAAA,EACpD,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,GAAG,SAAS,EAAE,MAAM,gBAAgB,EAAE,CAAC;AAAA,EACxE,cAAc,EAAE,OAAO,EAAE,SAAS;AACpC,CAAC;AAMM,MAAM,yBAAyB,EAAE,OAAO;AAAA,EAC7C,QAAQ,EAAE,OAAO;AAAA,EACjB,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS;AAAA,EAC3C,SAAS,EAAE,MAAM,gBAAgB,EAAE,SAAS;AAAA,EAC5C,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,GAAG,SAAS,EAAE,MAAM,gBAAgB,EAAE,CAAC,CAAC,EAAE,SAAS;AAAA,EAC7F,aAAa,EAAE,OAAO,EAAE,SAAS;AACnC,CAAC;",
6
6
  "names": ["SemanticChannelEventKind"]
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@finalai/agent-provider",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "private": false,
5
5
  "description": "Provider contracts for the agent stack: harnesses, sandboxes (handle, wire, MCP projection), channels, credential policies, and the conformance kit.",
6
6
  "license": "Apache-2.0",
@@ -131,11 +131,6 @@
131
131
  "import": "./dist/modules/semantic-events.mjs",
132
132
  "default": "./dist/modules/semantic-events.mjs"
133
133
  },
134
- "./channel-context": {
135
- "types": "./dist/modules/channel-context.d.mts",
136
- "import": "./dist/modules/channel-context.mjs",
137
- "default": "./dist/modules/channel-context.mjs"
138
- },
139
134
  "./sandbox/types": {
140
135
  "types": "./dist/modules/sandbox/types.d.mts",
141
136
  "import": "./dist/modules/sandbox/types.mjs",
@@ -175,6 +170,16 @@
175
170
  "types": "./dist/modules/local-channel-socket.d.mts",
176
171
  "import": "./dist/modules/local-channel-socket.mjs",
177
172
  "default": "./dist/modules/local-channel-socket.mjs"
173
+ },
174
+ "./room-surface": {
175
+ "types": "./dist/modules/room-surface.d.mts",
176
+ "import": "./dist/modules/room-surface.mjs",
177
+ "default": "./dist/modules/room-surface.mjs"
178
+ },
179
+ "./local-channel-context": {
180
+ "types": "./dist/modules/local-channel-context.d.mts",
181
+ "import": "./dist/modules/local-channel-context.mjs",
182
+ "default": "./dist/modules/local-channel-context.mjs"
178
183
  }
179
184
  },
180
185
  "publishConfig": {
@@ -183,13 +188,13 @@
183
188
  },
184
189
  "dependencies": {
185
190
  "@agentclientprotocol/sdk": "1.8.0",
186
- "@finalai/acp-session": "0.1.10",
187
- "@finalai/agent-protocol": "0.5.0",
191
+ "@finalai/acp-session": "0.1.11",
192
+ "@finalai/agent-protocol": "0.7.0",
188
193
  "@modelcontextprotocol/client": "^2.1.0",
189
194
  "@modelcontextprotocol/core": "^2.1.0",
190
195
  "@modelcontextprotocol/server": "^2.1.0",
191
196
  "re2js": "2.8.6",
192
- "zod": "4.6.5"
197
+ "zod": "4.6.6"
193
198
  },
194
199
  "engines": {
195
200
  "node": ">=26"
@@ -1,106 +0,0 @@
1
- import type { ContentBlock } from '@agentclientprotocol/sdk/experimental/v2';
2
- import * as z from 'zod';
3
- import { type ChannelAuthIface, type ChannelPlatformIface, type TurnPolicy } from "./channel.mjs";
4
- import type { JsonObject, JsonValue } from "./json.mjs";
5
- export { ChannelPrincipalType, channelAuthSchema, type ChannelAuthIface } from "./channel.mjs";
6
- export interface ChannelInputSourceIface {
7
- label: string;
8
- }
9
- export interface ChannelSendInputIface {
10
- content: ContentBlock[];
11
- idempotencyKey: string;
12
- auth: ChannelAuthIface;
13
- context?: string[];
14
- title?: string;
15
- turnPolicy?: TurnPolicy | `${TurnPolicy}`;
16
- actingUserId?: string;
17
- originTurnId?: string;
18
- source?: ChannelInputSourceIface;
19
- }
20
- export interface ChannelResponseInputIface {
21
- decisionId: string;
22
- outcome: JsonValue;
23
- auth: ChannelAuthIface;
24
- }
25
- export interface ChannelSessionTargetIface {
26
- address?: string;
27
- sessionId?: string;
28
- conversationId?: string;
29
- participantId?: string;
30
- }
31
- export interface ChannelInputReceiptIface {
32
- inputId: string;
33
- sessionId: string;
34
- }
35
- export declare const channelInputReceiptSchema: z.ZodObject<{
36
- inputId: z.ZodString;
37
- sessionId: z.ZodString;
38
- }, z.core.$strip>;
39
- export interface ChannelHandoffReceiptIface {
40
- inputId: string | null;
41
- sessionId: string | null;
42
- }
43
- export declare const channelHandoffReceiptSchema: z.ZodObject<{
44
- inputId: z.ZodNullable<z.ZodString>;
45
- sessionId: z.ZodNullable<z.ZodString>;
46
- }, z.core.$strip>;
47
- export interface ChannelSessionSnapshotIface {
48
- sessionId: string;
49
- conversationId: string | null;
50
- }
51
- export interface ChannelCancelInputIface {
52
- reason?: string;
53
- throughMessageSeq?: number;
54
- }
55
- export interface ChannelSessionOperationsIface {
56
- inspect(target: ChannelSessionTargetIface): Promise<ChannelSessionSnapshotIface | null>;
57
- resolve(target: ChannelSessionTargetIface): Promise<string | null>;
58
- send(target: ChannelSessionTargetIface, input: ChannelSendInputIface): Promise<ChannelInputReceiptIface>;
59
- respond(target: ChannelSessionTargetIface, input: ChannelResponseInputIface): Promise<{
60
- resolved: boolean;
61
- }>;
62
- cancel(target: ChannelSessionTargetIface, input?: ChannelCancelInputIface): Promise<{
63
- accepted: boolean;
64
- }>;
65
- close(target: ChannelSessionTargetIface): Promise<void>;
66
- observe(target: ChannelSessionTargetIface, input: {
67
- content: ContentBlock[];
68
- idempotencyKey: string;
69
- }): Promise<void>;
70
- setConfigOption(target: ChannelSessionTargetIface, input: {
71
- configId: string;
72
- value: JsonValue;
73
- }): Promise<void>;
74
- park(target: ChannelSessionTargetIface): Promise<void>;
75
- getState(target: ChannelSessionTargetIface): Promise<JsonObject>;
76
- setState(target: ChannelSessionTargetIface, state: JsonObject): Promise<void>;
77
- handoff(channel: string, target: JsonValue, input: ChannelSendInputIface): Promise<ChannelHandoffReceiptIface>;
78
- }
79
- export interface ChannelSessionHandleIface {
80
- inspect(): Promise<ChannelSessionSnapshotIface | null>;
81
- resolveSession(): Promise<string | null>;
82
- send(input: ChannelSendInputIface): ReturnType<ChannelSessionOperationsIface['send']>;
83
- respond(input: ChannelResponseInputIface): ReturnType<ChannelSessionOperationsIface['respond']>;
84
- cancel(input?: ChannelCancelInputIface): ReturnType<ChannelSessionOperationsIface['cancel']>;
85
- close(): Promise<void>;
86
- observe(input: {
87
- content: ContentBlock[];
88
- idempotencyKey: string;
89
- }): Promise<void>;
90
- setConfigOption(input: {
91
- configId: string;
92
- value: JsonValue;
93
- }): Promise<void>;
94
- park(): Promise<void>;
95
- getState(): Promise<JsonObject>;
96
- setState(state: JsonObject): Promise<void>;
97
- }
98
- export interface ChannelAddressContextIface {
99
- from(address: string): ChannelSessionHandleIface;
100
- resolveSession(address: string): Promise<string | null>;
101
- attachSession(id: string): ChannelSessionHandleIface;
102
- to(channel: string, target: JsonValue): {
103
- send(input: ChannelSendInputIface): Promise<ChannelHandoffReceiptIface>;
104
- };
105
- }
106
- export declare const channelAccessors: (platform: Pick<ChannelPlatformIface, "channelSessions">) => ChannelAddressContextIface;
@@ -1,45 +0,0 @@
1
- import * as z from "zod";
2
- import {} from "./channel.mjs";
3
- import { ChannelPrincipalType, channelAuthSchema } from "./channel.mjs";
4
- const channelInputReceiptSchema = z.object({
5
- inputId: z.string().min(1),
6
- sessionId: z.string().min(1)
7
- });
8
- const channelHandoffReceiptSchema = z.object({
9
- inputId: z.string().min(1).nullable(),
10
- sessionId: z.string().min(1).nullable()
11
- });
12
- const channelAccessors = (platform) => {
13
- const operations = () => {
14
- if (platform.channelSessions == null)
15
- throw new Error("channel session operations are unavailable");
16
- return platform.channelSessions;
17
- };
18
- const handle = (target) => ({
19
- inspect: () => operations().inspect(target),
20
- resolveSession: () => operations().resolve(target),
21
- send: (input) => operations().send(target, input),
22
- respond: (input) => operations().respond(target, input),
23
- cancel: (input) => operations().cancel(target, input),
24
- close: () => operations().close(target),
25
- observe: (input) => operations().observe(target, input),
26
- setConfigOption: (input) => operations().setConfigOption(target, input),
27
- park: () => operations().park(target),
28
- getState: () => operations().getState(target),
29
- setState: (state) => operations().setState(target, state)
30
- });
31
- return {
32
- from: (address) => handle({ address }),
33
- resolveSession: (address) => operations().resolve({ address }),
34
- attachSession: (sessionId) => handle({ sessionId }),
35
- to: (channel, target) => ({ send: (input) => operations().handoff(channel, target, input) })
36
- };
37
- };
38
- export {
39
- ChannelPrincipalType,
40
- channelAccessors,
41
- channelAuthSchema,
42
- channelHandoffReceiptSchema,
43
- channelInputReceiptSchema
44
- };
45
- //# sourceMappingURL=channel-context.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../../src/channel-context.ts"],
4
- "sourcesContent": ["import type { ContentBlock } from '@agentclientprotocol/sdk/experimental/v2';\nimport * as z from 'zod';\nimport { type ChannelAuthIface, type ChannelPlatformIface, type TurnPolicy } from \"./channel.mjs\";\nimport type { JsonObject, JsonValue } from \"./json.mjs\";\n\nexport { ChannelPrincipalType, channelAuthSchema, type ChannelAuthIface } from \"./channel.mjs\";\n\n// How a Final room captions the agent's reply to the input (\"After the 9:00\n// schedule\", \"From Dana in #support\"); the platform names the principal when absent.\nexport interface ChannelInputSourceIface {\n label: string;\n}\n\nexport interface ChannelSendInputIface {\n content: ContentBlock[];\n idempotencyKey: string;\n // Required: the platform records the principal of every input.\n auth: ChannelAuthIface;\n context?: string[];\n title?: string;\n turnPolicy?: TurnPolicy | `${TurnPolicy}`;\n // The person the input acts for when its principal is a service: who pays and answers.\n actingUserId?: string;\n // The turn whose work produced the input (a relay or handoff), for loop limits.\n originTurnId?: string;\n source?: ChannelInputSourceIface;\n}\n\nexport interface ChannelResponseInputIface {\n decisionId: string;\n outcome: JsonValue;\n // Who answered; the channel decides who may (its audience policy) before responding.\n auth: ChannelAuthIface;\n}\n\n// Exactly one of an address (the channel's own), an attached session, or a\n// Final room (`conversationId`, optionally one agent `participantId` in it).\nexport interface ChannelSessionTargetIface {\n address?: string;\n sessionId?: string;\n conversationId?: string;\n participantId?: string;\n}\n\n// `send` accepts the input before any agent runs: the prompt follows, retried\n// by the platform, and the reply arrives through the channel's events.\nexport interface ChannelInputReceiptIface {\n inputId: string;\n sessionId: string;\n}\n\nexport const channelInputReceiptSchema = z.object({\n inputId: z.string().min(1),\n sessionId: z.string().min(1),\n});\n\n// Where a handoff went: a Final room's input, or another channel's own receive\n// (which names a session or nothing).\nexport interface ChannelHandoffReceiptIface {\n inputId: string | null;\n sessionId: string | null;\n}\n\nexport const channelHandoffReceiptSchema = z.object({\n inputId: z.string().min(1).nullable(),\n sessionId: z.string().min(1).nullable(),\n});\n\nexport interface ChannelSessionSnapshotIface {\n sessionId: string;\n conversationId: string | null;\n}\n\nexport interface ChannelCancelInputIface {\n reason?: string;\n throughMessageSeq?: number;\n}\n\nexport interface ChannelSessionOperationsIface {\n inspect(target: ChannelSessionTargetIface): Promise<ChannelSessionSnapshotIface | null>;\n resolve(target: ChannelSessionTargetIface): Promise<string | null>;\n send(\n target: ChannelSessionTargetIface,\n input: ChannelSendInputIface,\n ): Promise<ChannelInputReceiptIface>;\n respond(\n target: ChannelSessionTargetIface,\n input: ChannelResponseInputIface,\n ): Promise<{ resolved: boolean }>;\n cancel(\n target: ChannelSessionTargetIface,\n input?: ChannelCancelInputIface,\n ): Promise<{ accepted: boolean }>;\n close(target: ChannelSessionTargetIface): Promise<void>;\n observe(\n target: ChannelSessionTargetIface,\n input: { content: ContentBlock[]; idempotencyKey: string },\n ): Promise<void>;\n setConfigOption(\n target: ChannelSessionTargetIface,\n input: { configId: string; value: JsonValue },\n ): Promise<void>;\n park(target: ChannelSessionTargetIface): Promise<void>;\n getState(target: ChannelSessionTargetIface): Promise<JsonObject>;\n setState(target: ChannelSessionTargetIface, state: JsonObject): Promise<void>;\n // Input for another of the agent's channels: `final` targets `{ conversationId, participantId? }`.\n handoff(\n channel: string,\n target: JsonValue,\n input: ChannelSendInputIface,\n ): Promise<ChannelHandoffReceiptIface>;\n}\n\nexport interface ChannelSessionHandleIface {\n inspect(): Promise<ChannelSessionSnapshotIface | null>;\n resolveSession(): Promise<string | null>;\n send(input: ChannelSendInputIface): ReturnType<ChannelSessionOperationsIface['send']>;\n respond(input: ChannelResponseInputIface): ReturnType<ChannelSessionOperationsIface['respond']>;\n cancel(input?: ChannelCancelInputIface): ReturnType<ChannelSessionOperationsIface['cancel']>;\n close(): Promise<void>;\n observe(input: { content: ContentBlock[]; idempotencyKey: string }): Promise<void>;\n setConfigOption(input: { configId: string; value: JsonValue }): Promise<void>;\n park(): Promise<void>;\n getState(): Promise<JsonObject>;\n setState(state: JsonObject): Promise<void>;\n}\n\nexport interface ChannelAddressContextIface {\n from(address: string): ChannelSessionHandleIface;\n resolveSession(address: string): Promise<string | null>;\n attachSession(id: string): ChannelSessionHandleIface;\n to(\n channel: string,\n target: JsonValue,\n ): { send(input: ChannelSendInputIface): Promise<ChannelHandoffReceiptIface> };\n}\n\n// Handles resolve at operation time. Only attachSession captures a session ID.\nexport const channelAccessors = (\n platform: Pick<ChannelPlatformIface, 'channelSessions'>,\n): ChannelAddressContextIface => {\n const operations = () => {\n if (platform.channelSessions == null)\n throw new Error('channel session operations are unavailable');\n return platform.channelSessions;\n };\n const handle = (target: ChannelSessionTargetIface): ChannelSessionHandleIface => ({\n inspect: () => operations().inspect(target),\n resolveSession: () => operations().resolve(target),\n send: (input) => operations().send(target, input),\n respond: (input) => operations().respond(target, input),\n cancel: (input) => operations().cancel(target, input),\n close: () => operations().close(target),\n observe: (input) => operations().observe(target, input),\n setConfigOption: (input) => operations().setConfigOption(target, input),\n park: () => operations().park(target),\n getState: () => operations().getState(target),\n setState: (state) => operations().setState(target, state),\n });\n return {\n from: (address) => handle({ address }),\n resolveSession: (address) => operations().resolve({ address }),\n attachSession: (sessionId) => handle({ sessionId }),\n to: (channel, target) => ({ send: (input) => operations().handoff(channel, target, input) }),\n };\n};\n"],
5
- "mappings": "AACA,YAAY,OAAO;AACnB,eAAkF;AAGlF,SAAS,sBAAsB,yBAAgD;AA8CxE,MAAM,4BAA4B,EAAE,OAAO;AAAA,EAChD,SAAS,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA,EACzB,WAAW,EAAE,OAAO,EAAE,IAAI,CAAC;AAC7B,CAAC;AASM,MAAM,8BAA8B,EAAE,OAAO;AAAA,EAClD,SAAS,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,SAAS;AAAA,EACpC,WAAW,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,SAAS;AACxC,CAAC;AAwEM,MAAM,mBAAmB,CAC9B,aAC+B;AAC/B,QAAM,aA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