runwork 0.4.0 → 0.5.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 (95) hide show
  1. package/bundled-types/core-agent.d.ts +8 -0
  2. package/bundled-types/core-base-agent.d.ts +4 -0
  3. package/bundled-types/core-types.d.ts +101 -0
  4. package/bundled-types/core-workspace.d.ts +10 -0
  5. package/bundled-types/index.d.ts +2 -0
  6. package/bundled-types/shared/core-types.d.ts +101 -0
  7. package/bundled-types/shared/shared/core-types.d.ts +101 -0
  8. package/bundled-types/task-delegation/index.d.ts +50 -0
  9. package/bundled-types/task-delegation/sandbox-bridge.d.ts +88 -0
  10. package/bundled-types/task-delegation/session-manager.d.ts +86 -0
  11. package/bundled-types/task-delegation/stream-parser.d.ts +25 -0
  12. package/bundled-types/task-delegation/task-delegation/index.d.ts +30 -0
  13. package/bundled-types/task-delegation/task-delegation/sandbox-bridge.d.ts +88 -0
  14. package/bundled-types/task-delegation/task-delegation/session-manager.d.ts +86 -0
  15. package/bundled-types/task-delegation/task-delegation/stream-parser.d.ts +25 -0
  16. package/bundled-types/task-delegation/task-delegation/types.d.ts +165 -0
  17. package/bundled-types/task-delegation/types.d.ts +336 -0
  18. package/bundled-types/task-delegation.d.ts +2 -0
  19. package/dist/__tests__/curl-parser.test.d.ts +1 -0
  20. package/dist/__tests__/curl-parser.test.js +250 -0
  21. package/dist/__tests__/types-manager.test.js +22 -18
  22. package/dist/agents/claude-code.d.ts +10 -0
  23. package/dist/agents/claude-code.js +50 -0
  24. package/dist/agents/claude-desktop.d.ts +10 -0
  25. package/dist/agents/claude-desktop.js +141 -0
  26. package/dist/agents/codex.d.ts +10 -0
  27. package/dist/agents/codex.js +45 -0
  28. package/dist/agents/copilot-cli.d.ts +10 -0
  29. package/dist/agents/copilot-cli.js +46 -0
  30. package/dist/agents/copilot-vscode.d.ts +10 -0
  31. package/dist/agents/copilot-vscode.js +37 -0
  32. package/dist/agents/cursor.d.ts +10 -0
  33. package/dist/agents/cursor.js +55 -0
  34. package/dist/agents/detect.d.ts +4 -0
  35. package/dist/agents/detect.js +43 -0
  36. package/dist/agents/gemini.d.ts +10 -0
  37. package/dist/agents/gemini.js +47 -0
  38. package/dist/agents/types.d.ts +35 -0
  39. package/dist/agents/types.js +13 -0
  40. package/dist/agents/utils/json-config.d.ts +14 -0
  41. package/dist/agents/utils/json-config.js +42 -0
  42. package/dist/agents/utils/toml-config.d.ts +8 -0
  43. package/dist/agents/utils/toml-config.js +27 -0
  44. package/dist/agents/windsurf.d.ts +10 -0
  45. package/dist/agents/windsurf.js +50 -0
  46. package/dist/api/client.d.ts +97 -1
  47. package/dist/api/client.js +199 -0
  48. package/dist/auth/store.js +18 -0
  49. package/dist/commands/agents.d.ts +2 -0
  50. package/dist/commands/agents.js +160 -0
  51. package/dist/commands/api-keys.d.ts +2 -0
  52. package/dist/commands/api-keys.js +95 -0
  53. package/dist/commands/apps.d.ts +2 -0
  54. package/dist/commands/apps.js +82 -0
  55. package/dist/commands/components.d.ts +2 -0
  56. package/dist/commands/components.js +43 -0
  57. package/dist/commands/endpoints.d.ts +2 -0
  58. package/dist/commands/endpoints.js +188 -0
  59. package/dist/commands/entities.d.ts +2 -0
  60. package/dist/commands/entities.js +198 -0
  61. package/dist/commands/files.d.ts +2 -0
  62. package/dist/commands/files.js +192 -0
  63. package/dist/commands/info.d.ts +1 -0
  64. package/dist/commands/info.js +71 -127
  65. package/dist/commands/init.d.ts +2 -0
  66. package/dist/commands/init.js +10 -8
  67. package/dist/commands/integrations.js +105 -12
  68. package/dist/commands/mcp.d.ts +2 -0
  69. package/dist/commands/mcp.js +117 -0
  70. package/dist/commands/schedules.d.ts +2 -0
  71. package/dist/commands/schedules.js +221 -0
  72. package/dist/commands/setup.d.ts +2 -0
  73. package/dist/commands/setup.js +199 -0
  74. package/dist/commands/skills.d.ts +2 -0
  75. package/dist/commands/skills.js +134 -0
  76. package/dist/commands/sync.d.ts +2 -0
  77. package/dist/commands/sync.js +146 -0
  78. package/dist/commands/workflows.d.ts +2 -0
  79. package/dist/commands/workflows.js +187 -0
  80. package/dist/generated/bundled-types.js +35 -33
  81. package/dist/generated/version.d.ts +1 -1
  82. package/dist/generated/version.js +1 -1
  83. package/dist/index.js +26 -0
  84. package/dist/logs/tailer.js +41 -1
  85. package/dist/types.d.ts +204 -0
  86. package/dist/ui/banner.js +7 -6
  87. package/dist/utils/app-info.d.ts +66 -0
  88. package/dist/utils/app-info.js +150 -0
  89. package/dist/utils/curl-parser.d.ts +12 -0
  90. package/dist/utils/curl-parser.js +44 -0
  91. package/dist/utils/data-input.d.ts +1 -0
  92. package/dist/utils/data-input.js +38 -0
  93. package/dist/workspace/resolve.d.ts +19 -0
  94. package/dist/workspace/resolve.js +100 -0
  95. package/package.json +3 -2
@@ -0,0 +1,88 @@
1
+ /**
2
+ * SandboxBridge - HTTP client for the WorkspaceAgent /agent-sandbox/* routes.
3
+ * Runs inside vibe-app Workers/DOs (framework code) and uses the standard
4
+ * Cloudflare Workers fetch API — no external dependencies.
5
+ */
6
+ import type { PrepareSessionRequest, PrepareSessionResponse, ExecuteAgentRequest, ExecuteAgentResponse, ReadOutputsRequest, ReadOutputsResponse, DelegateWorkspaceContext } from './types';
7
+ export declare class SandboxBridge {
8
+ private readonly baseUrl;
9
+ private readonly apiKey;
10
+ private readonly workspaceId;
11
+ constructor(workspaceApiUrl: string, workspaceApiKey: string, workspaceId: string);
12
+ private request;
13
+ /**
14
+ * Prepare (or resume) a sandbox session.
15
+ * Must be called before executing code in a new session.
16
+ */
17
+ prepareSession(req: PrepareSessionRequest): Promise<PrepareSessionResponse>;
18
+ /**
19
+ * Execute a Agent task inside the sandbox session.
20
+ * Returns the full output once the run completes.
21
+ */
22
+ executeAgent(req: ExecuteAgentRequest): Promise<ExecuteAgentResponse>;
23
+ /**
24
+ * Execute a Agent task with SSE streaming output.
25
+ * Returns the raw Response so the caller can parse the event stream.
26
+ * The body contains `stream: true` and `Accept: text/event-stream` is set.
27
+ */
28
+ executeAgentStream(req: ExecuteAgentRequest): Promise<Response>;
29
+ /**
30
+ * Read file contents back from the sandbox after execution.
31
+ */
32
+ readOutputs(req: ReadOutputsRequest): Promise<ReadOutputsResponse>;
33
+ /**
34
+ * Query the current status of a sandbox session.
35
+ * Returns whether the session process is still running and its exit code if finished.
36
+ */
37
+ getSessionStatus(sessionId: string): Promise<{
38
+ running: boolean;
39
+ exitCode?: number;
40
+ }>;
41
+ /**
42
+ * Fetch workspace context (apps, MCP servers, skills) from the WorkspaceAgent.
43
+ * Used to populate CLAUDE.md and MCP settings with real workspace data.
44
+ */
45
+ getWorkspaceContext(): Promise<DelegateWorkspaceContext>;
46
+ /**
47
+ * Save the full event log for a completed execution to R2 for replay.
48
+ */
49
+ saveExecutionStream(req: {
50
+ sessionId: string;
51
+ content: string;
52
+ }): Promise<void>;
53
+ /**
54
+ * Retrieve a previously saved execution stream from R2.
55
+ * Returns null if the stream has not been persisted yet.
56
+ */
57
+ getExecutionStream(sessionId: string): Promise<{
58
+ executionId: string;
59
+ events: Array<{
60
+ type: string;
61
+ [key: string]: unknown;
62
+ }>;
63
+ result: {
64
+ response: string;
65
+ usage: {
66
+ inputTokens: number;
67
+ outputTokens: number;
68
+ cost: number;
69
+ };
70
+ exitCode: number;
71
+ };
72
+ timestamp: string;
73
+ } | null>;
74
+ /**
75
+ * Read new content from the stream.log file for a running or completed execution.
76
+ * Uses offset-based reads so callers only get new content each poll.
77
+ * Returns the new content and the updated offset for the next poll.
78
+ */
79
+ readStreamLog(sessionPath: string, offset?: number): Promise<{
80
+ content: string;
81
+ offset: number;
82
+ }>;
83
+ /**
84
+ * Send a keepalive ping to reset the sandbox idle timer.
85
+ * Fire-and-forget: errors are silently swallowed to avoid disrupting the caller.
86
+ */
87
+ sendKeepalive(): void;
88
+ }
@@ -0,0 +1,86 @@
1
+ import type { DelegateTaskOptions } from './types';
2
+ export declare function generateSessionId(): string;
3
+ export declare function buildWorkspaceClaudeMd(context: {
4
+ workspaceName: string;
5
+ workspaceId: string;
6
+ apps: Array<{
7
+ name: string;
8
+ id: string;
9
+ description: string;
10
+ }>;
11
+ mcpServers: string[];
12
+ externalMcpServers: string[];
13
+ }): string;
14
+ export declare function buildSessionClaudeMd(context: {
15
+ appName: string;
16
+ appId: string;
17
+ agentName: string;
18
+ sessionId: string;
19
+ maxBudget: number;
20
+ timeout: string;
21
+ }): string;
22
+ export declare function buildMcpSettingsJson(context: {
23
+ workspaceId: string;
24
+ workspaceMcpUrl?: string;
25
+ apps: Array<{
26
+ name: string;
27
+ id: string;
28
+ mcpUrl?: string;
29
+ }>;
30
+ externalMcpServers?: Array<{
31
+ name: string;
32
+ url?: string;
33
+ command?: string;
34
+ args?: string[];
35
+ }>;
36
+ }): string;
37
+ export declare function filterEnvVars(env: Record<string, string> | undefined): Record<string, string>;
38
+ export declare function buildPrepareSessionRequest(options: DelegateTaskOptions, context: {
39
+ appId: string;
40
+ appName: string;
41
+ agentName: string;
42
+ maxBudget: number;
43
+ timeout: string;
44
+ workspaceName: string;
45
+ workspaceId: string;
46
+ workspaceMcpUrl?: string;
47
+ apps: Array<{
48
+ name: string;
49
+ id: string;
50
+ description: string;
51
+ mcpUrl?: string;
52
+ }>;
53
+ mcpServers: string[];
54
+ externalMcpServers: Array<{
55
+ name: string;
56
+ url?: string;
57
+ command?: string;
58
+ args?: string[];
59
+ }>;
60
+ skillFiles: Array<{
61
+ name: string;
62
+ content: string;
63
+ }>;
64
+ }): {
65
+ appId: string;
66
+ agentName: string;
67
+ sessionId: string;
68
+ inputFiles: {
69
+ name: string;
70
+ content: string;
71
+ encoding: "utf-8" | "base64";
72
+ }[];
73
+ claudeMdContent: string;
74
+ workspaceClaudeMdContent: string;
75
+ settingsJsonContent: string;
76
+ skillFiles: {
77
+ name: string;
78
+ content: string;
79
+ }[];
80
+ };
81
+ /**
82
+ * Returns shell commands to clean up sessions older than maxAgeDays.
83
+ * Called lazily by prepare-session route before creating new sessions.
84
+ */
85
+ export declare function buildCleanupCommands(basePath: string, appId: string, agentName: string, maxAgeDays?: number): string[];
86
+ export declare function parseDurationToMs(duration: string): number;
@@ -0,0 +1,25 @@
1
+ import type { DelegateTaskStreamEvent, DelegateTaskUsage } from './types';
2
+ /**
3
+ * Parses Agent sandbox `--output-format stream-json` output into typed events.
4
+ *
5
+ * Agent sandbox emits one JSON object per line. This parser converts each line
6
+ * into zero or more DelegateTaskStreamEvent objects and accumulates token
7
+ * usage/cost across the full run.
8
+ *
9
+ * Designed for use both in real-time streaming (parse each line as it arrives)
10
+ * and post-hoc parsing (parse all stdout lines after execution completes).
11
+ */
12
+ export declare class StreamParser {
13
+ private accumulatedUsage;
14
+ private lastResponse;
15
+ /**
16
+ * Parse a single line of Agent sandbox stream-json output into zero or more
17
+ * DelegateTaskStreamEvents. Returns an empty array for empty lines, invalid
18
+ * JSON, or unknown message types.
19
+ */
20
+ parseLine(line: string): DelegateTaskStreamEvent[];
21
+ /** Return a copy of the usage accumulated across all parsed messages. */
22
+ getAccumulatedUsage(): DelegateTaskUsage;
23
+ /** Return the last assistant response text seen in the stream. */
24
+ getLastResponse(): string;
25
+ }
@@ -0,0 +1,165 @@
1
+ /**
2
+ * Types for the task agent execution feature.
3
+ *
4
+ * This module defines the interfaces and schemas used when triggering
5
+ * task agent executions via the platform's /trigger-task-agent endpoint.
6
+ */
7
+ import { z } from 'zod';
8
+ /**
9
+ * Configures resource limits for task agent executions.
10
+ * Defaults are intentionally conservative to prevent runaway costs.
11
+ */
12
+ export interface ExecutionLimits {
13
+ /** Maximum spend in USD for a single task (default: 10.00) */
14
+ maxBudgetPerTask?: number;
15
+ /** Maximum agent turns before the task is forcibly stopped. Omit to use CLI default. */
16
+ maxTurnsPerTask?: number;
17
+ /** Maximum wall-clock time expressed as a duration string, e.g. "1h" (default: "1h") */
18
+ maxDurationPerTask?: string;
19
+ /**
20
+ * Model to use for the sandbox agent, e.g. "claude-sonnet-4-6".
21
+ * If omitted, the sandbox CLI picks its default model.
22
+ */
23
+ model?: string;
24
+ }
25
+ /**
26
+ * A file to provide to the task agent process as part of the task context.
27
+ * Files are written into the sandbox before execution begins.
28
+ */
29
+ export interface AgentTaskInputFile {
30
+ /** Relative path under which the file will be written inside the sandbox */
31
+ name: string;
32
+ /** Raw file content -- either a UTF-8 string or a binary Buffer. Required if fileId is not set. */
33
+ content?: string | Buffer;
34
+ /**
35
+ * Platform file ID. When set, the platform resolves the file content
36
+ * from file storage before sending to the sandbox.
37
+ * Either content or fileId must be provided.
38
+ */
39
+ fileId?: string;
40
+ /** Content encoding; defaults to 'utf-8' */
41
+ encoding?: 'utf-8' | 'base64';
42
+ }
43
+ /**
44
+ * A file produced by the task agent process and returned to the caller.
45
+ * All files written to the `outputs/` directory are automatically captured.
46
+ */
47
+ export interface AgentTaskOutputFile {
48
+ /** Relative path of the file within the sandbox */
49
+ path: string;
50
+ /** File content, already decoded to a string */
51
+ content: string;
52
+ /** Encoding that was used to transfer the content (typically "utf-8") */
53
+ encoding: string;
54
+ }
55
+ /** Token and cost accounting for a completed task agent execution */
56
+ export interface AgentTaskUsage {
57
+ /** Total input tokens consumed across all turns */
58
+ inputTokens: number;
59
+ /** Total output tokens produced across all turns */
60
+ outputTokens: number;
61
+ /** Approximate cost in USD */
62
+ cost: number;
63
+ }
64
+ /**
65
+ * The final result returned once a task agent execution completes (or fails).
66
+ */
67
+ export interface AgentTaskResult {
68
+ /** The final text response produced by the task agent process */
69
+ response: string;
70
+ /** All files found in the outputs/ directory after execution */
71
+ outputFiles: AgentTaskOutputFile[];
72
+ /** Aggregated token usage and cost */
73
+ usage: AgentTaskUsage;
74
+ /**
75
+ * Exit code of the task agent process; 0 indicates success, non-zero
76
+ * indicates an error or an aborted task.
77
+ */
78
+ exitCode: number;
79
+ /** The sandbox session identifier that can be passed to a subsequent call to resume */
80
+ sessionId: string;
81
+ }
82
+ /**
83
+ * Result of triggering or querying a task agent execution via the platform API.
84
+ */
85
+ export interface AgentTaskExecution {
86
+ executionId: string;
87
+ sessionId?: string;
88
+ status: 'running' | 'completed' | 'partial' | 'error' | 'timeout';
89
+ result?: AgentTaskResult;
90
+ }
91
+ /**
92
+ * Options for {@link runAgentTask}. All fields are optional; the platform
93
+ * uses sensible defaults when omitted.
94
+ */
95
+ export interface RunAgentTaskOptions {
96
+ /** The instruction to pass to the task agent */
97
+ prompt?: string;
98
+ /** Files to provide as input context */
99
+ inputFiles?: AgentTaskInputFile[];
100
+ /** Maximum wall-clock duration, e.g. "30m" or "1h" */
101
+ timeout?: string;
102
+ /** Resume a previous session by passing its identifier */
103
+ sessionId?: string;
104
+ /** When true, the HTTP call blocks until the agent finishes (default: false / async) */
105
+ await?: boolean;
106
+ /** Maximum number of agent turns before the task is forcibly stopped */
107
+ maxTurns?: number;
108
+ /** Model override, e.g. "claude-sonnet-4-6" */
109
+ model?: string;
110
+ /**
111
+ * Ad-hoc system prompt. When provided, the platform allows execution even if
112
+ * the agent name is not found in the registry -- treating this as an ad-hoc
113
+ * task execution rather than a registered agent invocation.
114
+ */
115
+ systemPrompt?: string;
116
+ }
117
+ /**
118
+ * Zod schema for the `run_agent_task` LLM tool parameters.
119
+ * Used when exposing task agent execution as a tool to the orchestrating agent.
120
+ */
121
+ export declare const agentTaskToolSchema: z.ZodObject<{
122
+ prompt: z.ZodString;
123
+ inputFiles: z.ZodOptional<z.ZodArray<z.ZodObject<{
124
+ name: z.ZodString;
125
+ content: z.ZodString;
126
+ encoding: z.ZodOptional<z.ZodEnum<["utf-8", "base64"]>>;
127
+ }, "strip", z.ZodTypeAny, {
128
+ name: string;
129
+ content: string;
130
+ encoding?: "utf-8" | "base64" | undefined;
131
+ }, {
132
+ name: string;
133
+ content: string;
134
+ encoding?: "utf-8" | "base64" | undefined;
135
+ }>, "many">>;
136
+ maxTurns: z.ZodOptional<z.ZodNumber>;
137
+ timeout: z.ZodOptional<z.ZodString>;
138
+ sessionId: z.ZodOptional<z.ZodString>;
139
+ }, "strip", z.ZodTypeAny, {
140
+ prompt: string;
141
+ timeout?: string | undefined;
142
+ inputFiles?: {
143
+ name: string;
144
+ content: string;
145
+ encoding?: "utf-8" | "base64" | undefined;
146
+ }[] | undefined;
147
+ maxTurns?: number | undefined;
148
+ sessionId?: string | undefined;
149
+ }, {
150
+ prompt: string;
151
+ timeout?: string | undefined;
152
+ inputFiles?: {
153
+ name: string;
154
+ content: string;
155
+ encoding?: "utf-8" | "base64" | undefined;
156
+ }[] | undefined;
157
+ maxTurns?: number | undefined;
158
+ sessionId?: string | undefined;
159
+ }>;
160
+ /**
161
+ * Environment variable names that the platform always controls. Any values
162
+ * supplied for these keys are silently discarded to prevent callers from
163
+ * overriding critical platform credentials.
164
+ */
165
+ export declare const RESERVED_ENV_VARS: string[];
@@ -0,0 +1,336 @@
1
+ /**
2
+ * Types for the delegateTask code execution feature.
3
+ *
4
+ * This module defines the interfaces and schemas used when an AI agent
5
+ * delegates a task to a subordinate agent process running in a sandboxed
6
+ * environment. The delegated process has access to tools, can read/write
7
+ * files, and streams progress back to the caller.
8
+ */
9
+ import { z } from 'zod';
10
+ /**
11
+ * Configures resource limits for a single delegateTask invocation.
12
+ * Defaults are intentionally conservative to prevent runaway costs.
13
+ */
14
+ export interface ExecutionLimits {
15
+ /** Maximum spend in USD for a single task (default: 10.00) */
16
+ maxBudgetPerTask?: number;
17
+ /** Maximum agent turns before the task is forcibly stopped. Omit to use CLI default. */
18
+ maxTurnsPerTask?: number;
19
+ /** Maximum wall-clock time expressed as a duration string, e.g. "1h" (default: "1h") */
20
+ maxDurationPerTask?: string;
21
+ /**
22
+ * Model to use for the sandbox agent, e.g. "claude-sonnet-4-6".
23
+ * If omitted, the sandbox CLI picks its default model.
24
+ */
25
+ model?: string;
26
+ }
27
+ /**
28
+ * A file to provide to the delegated agent process as part of the task
29
+ * context. Files are written into the sandbox before execution begins.
30
+ */
31
+ export interface DelegateTaskInputFile {
32
+ /** Relative path under which the file will be written inside the sandbox */
33
+ name: string;
34
+ /** Raw file content — either a UTF-8 string or a binary Buffer. Required if fileId is not set. */
35
+ content?: string | Buffer;
36
+ /**
37
+ * Platform file ID. When set, the framework resolves the file content
38
+ * from the platform's file storage before sending to the sandbox.
39
+ * Either content or fileId must be provided.
40
+ */
41
+ fileId?: string;
42
+ /** Content encoding; defaults to 'utf-8' */
43
+ encoding?: 'utf-8' | 'base64';
44
+ }
45
+ /**
46
+ * A file produced by the delegated agent process and returned to the caller.
47
+ * Which files are returned is controlled by `outputFilePatterns` in
48
+ * {@link DelegateTaskOptions}.
49
+ */
50
+ export interface DelegateTaskOutputFile {
51
+ /** Relative path of the file within the sandbox */
52
+ path: string;
53
+ /** File content, already decoded to a string */
54
+ content: string;
55
+ /** Encoding that was used to transfer the content (typically "utf-8") */
56
+ encoding: string;
57
+ }
58
+ /**
59
+ * Options passed to a `delegateTask` call. All fields except `prompt` are
60
+ * optional and fall back to platform defaults or the agent's
61
+ * {@link ExecutionLimits}.
62
+ */
63
+ export interface DelegateTaskOptions {
64
+ /** The instruction to pass to the subordinate agent process */
65
+ prompt: string;
66
+ /** Files to make available inside the sandbox before the task starts */
67
+ inputFiles?: DelegateTaskInputFile[];
68
+ /**
69
+ * Glob patterns (relative to the sandbox workspace root) that identify which
70
+ * files should be captured and returned in {@link DelegateTaskResult.outputFiles}.
71
+ */
72
+ outputFilePatterns?: string[];
73
+ /** Maximum number of agent turns; overrides the agent-level limit */
74
+ maxTurns?: number;
75
+ /** Maximum spend in USD; overrides the agent-level limit */
76
+ maxBudget?: number;
77
+ /** Maximum wall-clock duration string, e.g. "30m"; overrides the agent-level limit */
78
+ timeout?: string;
79
+ /** When true the call returns a {@link DelegateTaskStream} instead of awaiting a full result */
80
+ stream?: boolean;
81
+ /**
82
+ * Opaque session identifier. Pass the value received in a previous result to
83
+ * resume a task within the same sandbox session.
84
+ */
85
+ sessionId?: string;
86
+ /**
87
+ * Additional environment variables injected into the sandbox.
88
+ * Variables listed in {@link RESERVED_ENV_VARS} are silently ignored.
89
+ */
90
+ env?: Record<string, string>;
91
+ /** Model override for the sandbox agent, e.g. "claude-sonnet-4-6". Overrides agent-level model. */
92
+ model?: string;
93
+ }
94
+ /** Token and cost accounting for a completed delegated task */
95
+ export interface DelegateTaskUsage {
96
+ /** Total input tokens consumed across all turns */
97
+ inputTokens: number;
98
+ /** Total output tokens produced across all turns */
99
+ outputTokens: number;
100
+ /** Approximate cost in USD */
101
+ cost: number;
102
+ }
103
+ /**
104
+ * The final result returned once a delegated task completes (or fails).
105
+ */
106
+ export interface DelegateTaskResult {
107
+ /** The final text response produced by the subordinate agent process */
108
+ response: string;
109
+ /** Files captured according to the `outputFilePatterns` option */
110
+ outputFiles: DelegateTaskOutputFile[];
111
+ /** Aggregated token usage and cost */
112
+ usage: DelegateTaskUsage;
113
+ /**
114
+ * Exit code of the subordinate process; 0 indicates success, non-zero
115
+ * indicates an error or an aborted task.
116
+ */
117
+ exitCode: number;
118
+ /** The sandbox session identifier that can be passed to a subsequent call to resume */
119
+ sessionId: string;
120
+ }
121
+ /** A text chunk emitted while the subordinate process is generating a response */
122
+ export interface DelegateTaskStreamTextEvent {
123
+ type: 'text';
124
+ text: string;
125
+ }
126
+ /** Notification that the subordinate process is invoking a tool */
127
+ export interface DelegateTaskStreamToolUseEvent {
128
+ type: 'tool_use';
129
+ toolName: string;
130
+ toolInput: Record<string, unknown>;
131
+ }
132
+ /** The result returned by a tool call in the subordinate process */
133
+ export interface DelegateTaskStreamToolResultEvent {
134
+ type: 'tool_result';
135
+ toolName: string;
136
+ result: unknown;
137
+ }
138
+ /** A fatal or non-fatal error raised during execution */
139
+ export interface DelegateTaskStreamErrorEvent {
140
+ type: 'error';
141
+ message: string;
142
+ code?: string;
143
+ }
144
+ /** A status update about the overall execution progress */
145
+ export interface DelegateTaskStreamStatusEvent {
146
+ type: 'status';
147
+ status: 'starting' | 'running' | 'finishing' | 'done';
148
+ message?: string;
149
+ }
150
+ /** Union of all events that can appear in a {@link DelegateTaskStream} */
151
+ export type DelegateTaskStreamEvent = DelegateTaskStreamTextEvent | DelegateTaskStreamToolUseEvent | DelegateTaskStreamToolResultEvent | DelegateTaskStreamErrorEvent | DelegateTaskStreamStatusEvent;
152
+ /**
153
+ * An async iterable stream of {@link DelegateTaskStreamEvent} values.
154
+ * Consuming the stream drives the subordinate process forward; the final
155
+ * {@link DelegateTaskResult} is available via the `result` promise once the
156
+ * stream is exhausted.
157
+ */
158
+ export interface DelegateTaskStream extends AsyncIterable<DelegateTaskStreamEvent> {
159
+ /** Resolves to the complete result after the stream has ended */
160
+ result: Promise<DelegateTaskResult>;
161
+ }
162
+ /**
163
+ * Sent to the sandbox bridge to prepare (or resume) a session before code
164
+ * execution starts. Must include all context for CLAUDE.md, skills, etc.
165
+ */
166
+ export interface PrepareSessionRequest {
167
+ appId: string;
168
+ agentName: string;
169
+ /** Opaque session identifier; omit to start a new session */
170
+ sessionId?: string;
171
+ /** Files to write into the sandbox inputs/ directory */
172
+ inputFiles?: Array<{
173
+ name: string;
174
+ content: string;
175
+ encoding: string;
176
+ }>;
177
+ /** Session-level CLAUDE.md content */
178
+ claudeMdContent: string;
179
+ /** Workspace-level CLAUDE.md content */
180
+ workspaceClaudeMdContent: string;
181
+ /** .claude/settings.json content (MCP servers config) */
182
+ settingsJsonContent: string;
183
+ /** Skill files to write into .claude/skills/ */
184
+ skillFiles?: Array<{
185
+ name: string;
186
+ content: string;
187
+ }>;
188
+ }
189
+ /** Response from the sandbox bridge after session preparation */
190
+ export interface PrepareSessionResponse {
191
+ /** The session identifier to use in subsequent requests */
192
+ sessionId: string;
193
+ /** Absolute path to the session directory in the sandbox */
194
+ sessionPath: string;
195
+ /** Absolute path to the agent sandbox working directory */
196
+ workDir: string;
197
+ }
198
+ /**
199
+ * Sent to the sandbox bridge to execute agent sandbox in the sandbox.
200
+ */
201
+ export interface ExecuteAgentRequest {
202
+ /** The session identifier returned by {@link PrepareSessionResponse} */
203
+ sessionId: string;
204
+ /** Absolute path to the agent sandbox working directory */
205
+ workDir: string;
206
+ /** The prompt to pass to the subordinate agent process */
207
+ prompt: string;
208
+ /** Maximum number of agent turns. Omit to use CLI default. */
209
+ maxTurns?: number;
210
+ /** Execution timeout as a duration string, e.g. "1h" */
211
+ timeout?: string;
212
+ /** Environment variables to set for the agent sandbox process */
213
+ envVars: Record<string, string>;
214
+ /** Model override, e.g. "claude-sonnet-4-6". Omit to use CLI default. */
215
+ model?: string;
216
+ /** When true the bridge streams events back rather than buffering */
217
+ stream: boolean;
218
+ }
219
+ /** Response from the sandbox bridge after (non-streaming) execution */
220
+ export interface ExecuteAgentResponse {
221
+ /** Raw stdout from the agent sandbox process (stream-json lines) */
222
+ stdout: string;
223
+ /** Exit code of the subordinate process */
224
+ exitCode: number;
225
+ /** Whether the process was killed due to timeout */
226
+ timedOut: boolean;
227
+ }
228
+ /**
229
+ * Sent to the sandbox bridge to read output files from a completed session.
230
+ */
231
+ export interface ReadOutputsRequest {
232
+ /** Absolute path to the session directory */
233
+ sessionPath: string;
234
+ /** Glob patterns identifying which files to capture */
235
+ patterns: string[];
236
+ }
237
+ /** Response from the sandbox bridge containing the requested output files */
238
+ export interface ReadOutputsResponse {
239
+ /** The captured files matching the requested patterns */
240
+ files: DelegateTaskOutputFile[];
241
+ }
242
+ /**
243
+ * Workspace context fetched from the WorkspaceAgent at runtime.
244
+ * Used to populate CLAUDE.md, MCP settings, and skills for delegated tasks.
245
+ */
246
+ export interface DelegateWorkspaceContext {
247
+ workspaceName: string;
248
+ workspaceId: string;
249
+ apps: Array<{
250
+ name: string;
251
+ id: string;
252
+ description: string;
253
+ mcpUrl?: string;
254
+ }>;
255
+ workspaceMcpUrl?: string;
256
+ externalMcpServers: Array<{
257
+ name: string;
258
+ url?: string;
259
+ command?: string;
260
+ args?: string[];
261
+ }>;
262
+ skills: Array<{
263
+ name: string;
264
+ content: string;
265
+ }>;
266
+ }
267
+ /**
268
+ * The full event log persisted to R2 after a streaming execution completes.
269
+ * Used for replay and debugging.
270
+ */
271
+ export interface ExecutionStreamLog {
272
+ /** The session/execution identifier */
273
+ executionId: string;
274
+ /** All events emitted during the streaming execution */
275
+ events: DelegateTaskStreamEvent[];
276
+ /** Summary result of the execution */
277
+ result: {
278
+ response: string;
279
+ usage: DelegateTaskUsage;
280
+ exitCode: number;
281
+ };
282
+ /** ISO timestamp when the log was persisted */
283
+ timestamp: string;
284
+ }
285
+ /**
286
+ * Zod schema for the `delegateTask` LLM tool parameters.
287
+ * Used when exposing delegateTask as a tool to the orchestrating agent.
288
+ */
289
+ export declare const delegateTaskToolSchema: z.ZodObject<{
290
+ prompt: z.ZodString;
291
+ inputFiles: z.ZodOptional<z.ZodArray<z.ZodObject<{
292
+ name: z.ZodString;
293
+ content: z.ZodString;
294
+ encoding: z.ZodOptional<z.ZodEnum<["utf-8", "base64"]>>;
295
+ }, "strip", z.ZodTypeAny, {
296
+ name: string;
297
+ content: string;
298
+ encoding?: "utf-8" | "base64" | undefined;
299
+ }, {
300
+ name: string;
301
+ content: string;
302
+ encoding?: "utf-8" | "base64" | undefined;
303
+ }>, "many">>;
304
+ outputFilePatterns: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
305
+ maxTurns: z.ZodOptional<z.ZodNumber>;
306
+ timeout: z.ZodOptional<z.ZodString>;
307
+ sessionId: z.ZodOptional<z.ZodString>;
308
+ }, "strip", z.ZodTypeAny, {
309
+ prompt: string;
310
+ inputFiles?: {
311
+ name: string;
312
+ content: string;
313
+ encoding?: "utf-8" | "base64" | undefined;
314
+ }[] | undefined;
315
+ outputFilePatterns?: string[] | undefined;
316
+ maxTurns?: number | undefined;
317
+ timeout?: string | undefined;
318
+ sessionId?: string | undefined;
319
+ }, {
320
+ prompt: string;
321
+ inputFiles?: {
322
+ name: string;
323
+ content: string;
324
+ encoding?: "utf-8" | "base64" | undefined;
325
+ }[] | undefined;
326
+ outputFilePatterns?: string[] | undefined;
327
+ maxTurns?: number | undefined;
328
+ timeout?: string | undefined;
329
+ sessionId?: string | undefined;
330
+ }>;
331
+ /**
332
+ * Environment variable names that the platform always controls. Any values
333
+ * supplied via {@link DelegateTaskOptions.env} for these keys are silently
334
+ * discarded to prevent callers from overriding critical platform credentials.
335
+ */
336
+ export declare const RESERVED_ENV_VARS: string[];