runwork 0.4.1 → 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
@@ -24,6 +24,7 @@
24
24
  import { z } from 'zod';
25
25
  import type { Env } from './core-utils';
26
26
  import type { IntegrationClient } from './core-integrations';
27
+ import type { ExecutionLimits } from './task-delegation/types';
27
28
  /**
28
29
  * Agent state persisted across conversations
29
30
  */
@@ -84,6 +85,10 @@ export interface AgentDefinition {
84
85
  memoryStrategy?: MemoryStrategy;
85
86
  /** Custom tools for this agent */
86
87
  customTools?: AgentToolDefinition[];
88
+ /** Default task instruction for task agents. Can be overridden per execution. */
89
+ prompt?: string;
90
+ /** Cost/time limits for task agent sandbox execution. Optional overrides. */
91
+ executionLimits?: ExecutionLimits;
87
92
  }
88
93
  /**
89
94
  * Custom tool definition for agents
@@ -134,6 +139,9 @@ export interface RegisterAgentRequest {
134
139
  integrations: string[];
135
140
  entities: string[];
136
141
  tools?: AgentToolMeta[];
142
+ systemPrompt?: string;
143
+ prompt?: string;
144
+ executionLimits?: ExecutionLimits;
137
145
  }
138
146
  /**
139
147
  * Tool metadata for API responses (JSON-serializable, no Zod)
@@ -65,6 +65,10 @@ export declare class BaseAgent extends AIChatAgent<Env> {
65
65
  * Uses entity classes directly with EntityContext
66
66
  */
67
67
  private buildEntityTools;
68
+ /**
69
+ * Build tools for running complex tasks via a sandboxed AI sub-agent
70
+ */
71
+ private buildCodeExecutionTools;
68
72
  /**
69
73
  * Get integration client (lazy-loaded)
70
74
  */
@@ -0,0 +1,101 @@
1
+ /**
2
+ * This file defines default types provided by the platform.
3
+ * DO NOT EDIT THIS FILE. You can define your own types in `shared/types.ts` file.
4
+ */
5
+ export interface ApiResponse<T = unknown> {
6
+ success: boolean;
7
+ data?: T;
8
+ error?: string;
9
+ }
10
+ /**
11
+ * Response from a Nango action or sync trigger
12
+ */
13
+ export interface NangoActionResponse<T = unknown> {
14
+ success: boolean;
15
+ data?: T;
16
+ error?: string;
17
+ /** True if error is due to missing integration connection (user hasn't connected yet) */
18
+ isConnectionError?: boolean;
19
+ /** True if error is due to insufficient permissions/scopes (401/403 from external API) */
20
+ isPermissionError?: boolean;
21
+ /** HTTP status code from the external API (if available) */
22
+ statusCode?: number;
23
+ }
24
+ /**
25
+ * Nango proxy request options - used for direct API calls through Nango
26
+ */
27
+ export interface NangoProxyOptions {
28
+ method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
29
+ endpoint: string;
30
+ providerConfigKey: string;
31
+ data?: Record<string, unknown>;
32
+ headers?: Record<string, string>;
33
+ params?: Record<string, string>;
34
+ retries?: number;
35
+ }
36
+ /**
37
+ * Metadata for a stored file
38
+ */
39
+ export interface FileMetadata {
40
+ id: string;
41
+ key: string;
42
+ name: string;
43
+ size: number;
44
+ contentType: string;
45
+ uploadedAt: number;
46
+ uploadedBy?: string;
47
+ customMetadata?: Record<string, string>;
48
+ }
49
+ /**
50
+ * Options for uploading a file
51
+ */
52
+ export interface UploadOptions {
53
+ key?: string;
54
+ name?: string;
55
+ contentType?: string;
56
+ uploadedBy?: string;
57
+ customMetadata?: Record<string, string>;
58
+ }
59
+ /**
60
+ * Options for downloading a file
61
+ */
62
+ export interface DownloadOptions {
63
+ range?: {
64
+ offset?: number;
65
+ length?: number;
66
+ };
67
+ }
68
+ /**
69
+ * Options for listing files
70
+ */
71
+ export interface ListFilesOptions {
72
+ prefix?: string;
73
+ limit?: number;
74
+ cursor?: string;
75
+ delimiter?: string;
76
+ }
77
+ /**
78
+ * Result of listing files
79
+ */
80
+ export interface ListFilesResult {
81
+ files: FileMetadata[];
82
+ cursor?: string;
83
+ truncated: boolean;
84
+ }
85
+ /**
86
+ * Request for generating a presigned URL
87
+ */
88
+ export interface PresignedUrlRequest {
89
+ appId: string;
90
+ key: string;
91
+ action: 'read' | 'write';
92
+ contentType?: string;
93
+ expiresIn?: number;
94
+ }
95
+ /**
96
+ * Response containing a presigned URL
97
+ */
98
+ export interface PresignedUrlResponse {
99
+ url: string;
100
+ expiresAt: number;
101
+ }
@@ -7,6 +7,7 @@
7
7
  * their capabilities (entities, components, endpoints, etc.).
8
8
  */
9
9
  import type { Env } from './core-utils';
10
+ import type { ExecutionLimits } from './task-delegation/types';
10
11
  /**
11
12
  * WorkspaceUser - Represents a member of the workspace
12
13
  * Read-only data provided by the platform
@@ -153,6 +154,9 @@ export interface RegisterAgentRequest extends Record<string, unknown> {
153
154
  integrations: string[];
154
155
  entities: string[];
155
156
  deploymentMode?: 'preview' | 'production';
157
+ systemPrompt?: string;
158
+ prompt?: string;
159
+ executionLimits?: ExecutionLimits;
156
160
  }
157
161
  /**
158
162
  * WorkspaceContext - Helper for cross-app data queries
@@ -255,6 +259,9 @@ export declare class WorkspaceContext {
255
259
  type: 'conversational' | 'task';
256
260
  integrations: string[];
257
261
  entities: string[];
262
+ systemPrompt?: string;
263
+ prompt?: string;
264
+ executionLimits?: ExecutionLimits;
258
265
  }): Promise<void>;
259
266
  /**
260
267
  * Register all scheduled jobs, removing any stale entries not in the list.
@@ -309,6 +316,9 @@ export declare class WorkspaceContext {
309
316
  type: 'conversational' | 'task';
310
317
  integrations?: string[];
311
318
  entities?: string[];
319
+ systemPrompt?: string;
320
+ prompt?: string;
321
+ executionLimits?: ExecutionLimits;
312
322
  }>): Promise<void>;
313
323
  /**
314
324
  * Register all components, removing any stale entries not in the list.
@@ -17,3 +17,5 @@ export * from './channels';
17
17
  export * from './workspace';
18
18
  export * from './events';
19
19
  export * from './components';
20
+ export { runAgentTask, getAgentTaskStatus } from './task-delegation';
21
+ export type { AgentTaskExecution, RunAgentTaskOptions } from './task-delegation';
@@ -0,0 +1,101 @@
1
+ /**
2
+ * This file defines default types provided by the platform.
3
+ * DO NOT EDIT THIS FILE. You can define your own types in `shared/types.ts` file.
4
+ */
5
+ export interface ApiResponse<T = unknown> {
6
+ success: boolean;
7
+ data?: T;
8
+ error?: string;
9
+ }
10
+ /**
11
+ * Response from a Nango action or sync trigger
12
+ */
13
+ export interface NangoActionResponse<T = unknown> {
14
+ success: boolean;
15
+ data?: T;
16
+ error?: string;
17
+ /** True if error is due to missing integration connection (user hasn't connected yet) */
18
+ isConnectionError?: boolean;
19
+ /** True if error is due to insufficient permissions/scopes (401/403 from external API) */
20
+ isPermissionError?: boolean;
21
+ /** HTTP status code from the external API (if available) */
22
+ statusCode?: number;
23
+ }
24
+ /**
25
+ * Nango proxy request options - used for direct API calls through Nango
26
+ */
27
+ export interface NangoProxyOptions {
28
+ method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
29
+ endpoint: string;
30
+ providerConfigKey: string;
31
+ data?: Record<string, unknown>;
32
+ headers?: Record<string, string>;
33
+ params?: Record<string, string>;
34
+ retries?: number;
35
+ }
36
+ /**
37
+ * Metadata for a stored file
38
+ */
39
+ export interface FileMetadata {
40
+ id: string;
41
+ key: string;
42
+ name: string;
43
+ size: number;
44
+ contentType: string;
45
+ uploadedAt: number;
46
+ uploadedBy?: string;
47
+ customMetadata?: Record<string, string>;
48
+ }
49
+ /**
50
+ * Options for uploading a file
51
+ */
52
+ export interface UploadOptions {
53
+ key?: string;
54
+ name?: string;
55
+ contentType?: string;
56
+ uploadedBy?: string;
57
+ customMetadata?: Record<string, string>;
58
+ }
59
+ /**
60
+ * Options for downloading a file
61
+ */
62
+ export interface DownloadOptions {
63
+ range?: {
64
+ offset?: number;
65
+ length?: number;
66
+ };
67
+ }
68
+ /**
69
+ * Options for listing files
70
+ */
71
+ export interface ListFilesOptions {
72
+ prefix?: string;
73
+ limit?: number;
74
+ cursor?: string;
75
+ delimiter?: string;
76
+ }
77
+ /**
78
+ * Result of listing files
79
+ */
80
+ export interface ListFilesResult {
81
+ files: FileMetadata[];
82
+ cursor?: string;
83
+ truncated: boolean;
84
+ }
85
+ /**
86
+ * Request for generating a presigned URL
87
+ */
88
+ export interface PresignedUrlRequest {
89
+ appId: string;
90
+ key: string;
91
+ action: 'read' | 'write';
92
+ contentType?: string;
93
+ expiresIn?: number;
94
+ }
95
+ /**
96
+ * Response containing a presigned URL
97
+ */
98
+ export interface PresignedUrlResponse {
99
+ url: string;
100
+ expiresAt: number;
101
+ }
@@ -0,0 +1,101 @@
1
+ /**
2
+ * This file defines default types provided by the platform.
3
+ * DO NOT EDIT THIS FILE. You can define your own types in `shared/types.ts` file.
4
+ */
5
+ export interface ApiResponse<T = unknown> {
6
+ success: boolean;
7
+ data?: T;
8
+ error?: string;
9
+ }
10
+ /**
11
+ * Response from a Nango action or sync trigger
12
+ */
13
+ export interface NangoActionResponse<T = unknown> {
14
+ success: boolean;
15
+ data?: T;
16
+ error?: string;
17
+ /** True if error is due to missing integration connection (user hasn't connected yet) */
18
+ isConnectionError?: boolean;
19
+ /** True if error is due to insufficient permissions/scopes (401/403 from external API) */
20
+ isPermissionError?: boolean;
21
+ /** HTTP status code from the external API (if available) */
22
+ statusCode?: number;
23
+ }
24
+ /**
25
+ * Nango proxy request options - used for direct API calls through Nango
26
+ */
27
+ export interface NangoProxyOptions {
28
+ method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
29
+ endpoint: string;
30
+ providerConfigKey: string;
31
+ data?: Record<string, unknown>;
32
+ headers?: Record<string, string>;
33
+ params?: Record<string, string>;
34
+ retries?: number;
35
+ }
36
+ /**
37
+ * Metadata for a stored file
38
+ */
39
+ export interface FileMetadata {
40
+ id: string;
41
+ key: string;
42
+ name: string;
43
+ size: number;
44
+ contentType: string;
45
+ uploadedAt: number;
46
+ uploadedBy?: string;
47
+ customMetadata?: Record<string, string>;
48
+ }
49
+ /**
50
+ * Options for uploading a file
51
+ */
52
+ export interface UploadOptions {
53
+ key?: string;
54
+ name?: string;
55
+ contentType?: string;
56
+ uploadedBy?: string;
57
+ customMetadata?: Record<string, string>;
58
+ }
59
+ /**
60
+ * Options for downloading a file
61
+ */
62
+ export interface DownloadOptions {
63
+ range?: {
64
+ offset?: number;
65
+ length?: number;
66
+ };
67
+ }
68
+ /**
69
+ * Options for listing files
70
+ */
71
+ export interface ListFilesOptions {
72
+ prefix?: string;
73
+ limit?: number;
74
+ cursor?: string;
75
+ delimiter?: string;
76
+ }
77
+ /**
78
+ * Result of listing files
79
+ */
80
+ export interface ListFilesResult {
81
+ files: FileMetadata[];
82
+ cursor?: string;
83
+ truncated: boolean;
84
+ }
85
+ /**
86
+ * Request for generating a presigned URL
87
+ */
88
+ export interface PresignedUrlRequest {
89
+ appId: string;
90
+ key: string;
91
+ action: 'read' | 'write';
92
+ contentType?: string;
93
+ expiresIn?: number;
94
+ }
95
+ /**
96
+ * Response containing a presigned URL
97
+ */
98
+ export interface PresignedUrlResponse {
99
+ url: string;
100
+ expiresAt: number;
101
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * delegateTask -- orchestrates the full task-delegation flow.
3
+ *
4
+ * 1. Validates required env vars (WORKSPACE_API_URL, WORKSPACE_API_KEY)
5
+ * 2. Resolves execution limits (per-call options tighten but cannot loosen agent-level limits)
6
+ * 3. Creates a SandboxBridge and prepares the session
7
+ * 4. Executes the agent task with keepalive and timeout
8
+ * 5. Reads output files and returns the result
9
+ */
10
+ import type { DelegateTaskOptions, DelegateTaskResult, DelegateTaskStream, ExecutionLimits } from './types';
11
+ export { SandboxBridge } from './sandbox-bridge';
12
+ export { StreamParser } from './stream-parser';
13
+ export { filterEnvVars, generateSessionId, parseDurationToMs, buildSessionClaudeMd, buildWorkspaceClaudeMd, buildMcpSettingsJson, buildPrepareSessionRequest, buildCleanupCommands, } from './session-manager';
14
+ export { delegateTaskToolSchema, RESERVED_ENV_VARS } from './types';
15
+ export type { DelegateTaskOptions, DelegateTaskResult, DelegateTaskStream, DelegateTaskStreamEvent, DelegateTaskStreamTextEvent, DelegateTaskStreamToolUseEvent, DelegateTaskStreamToolResultEvent, DelegateTaskStreamErrorEvent, DelegateTaskStreamStatusEvent, DelegateTaskUsage, DelegateTaskInputFile, DelegateTaskOutputFile, ExecutionLimits, ExecutionStreamLog, DelegateWorkspaceContext, PrepareSessionRequest, PrepareSessionResponse, ExecuteAgentRequest, ExecuteAgentResponse, ReadOutputsRequest, ReadOutputsResponse, } from './types';
16
+ /**
17
+ * Contextual information provided by the calling agent/framework
18
+ * to configure the delegated task execution environment.
19
+ */
20
+ export interface DelegateTaskContext {
21
+ env: {
22
+ WORKSPACE_API_URL?: string;
23
+ WORKSPACE_API_KEY?: string;
24
+ WORKSPACE_ID?: string;
25
+ APP_ID?: string;
26
+ APP_NAME?: string;
27
+ RUNWORK_AI_PROXY_URL?: string;
28
+ RUNWORK_PROXY_TOKEN?: string;
29
+ [key: string]: string | undefined;
30
+ };
31
+ /** Name of the agent initiating the task; used for logging and session paths */
32
+ agentName?: string;
33
+ /** Agent-level execution limits; per-call options can tighten but not loosen these */
34
+ executionLimits?: ExecutionLimits;
35
+ }
36
+ /**
37
+ * Delegate a task to a subordinate agent process running in a sandboxed
38
+ * environment. The process has access to tools, can read/write files, and
39
+ * returns structured output when complete.
40
+ *
41
+ * Non-streaming overload: awaits the full result.
42
+ */
43
+ export declare function delegateTask(options: DelegateTaskOptions, context: DelegateTaskContext): Promise<DelegateTaskResult>;
44
+ /**
45
+ * Streaming overload: returns a DelegateTaskStream that yields events as the
46
+ * task progresses. The final result is available via `stream.result`.
47
+ */
48
+ export declare function delegateTask(options: DelegateTaskOptions & {
49
+ stream: true;
50
+ }, context: DelegateTaskContext): DelegateTaskStream;
@@ -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,30 @@
1
+ /**
2
+ * Task delegation -- thin HTTP wrappers for the platform's task agent API.
3
+ *
4
+ * runAgentTask() triggers execution via /trigger-task-agent.
5
+ * getAgentTaskStatus() polls execution status via /agent-execution/:id.
6
+ */
7
+ import type { RunAgentTaskOptions, AgentTaskExecution } from './types';
8
+ import type { Env } from '../core-utils';
9
+ export { agentTaskToolSchema, RESERVED_ENV_VARS } from './types';
10
+ export type { AgentTaskResult, AgentTaskUsage, AgentTaskInputFile, AgentTaskOutputFile, ExecutionLimits, AgentTaskExecution, RunAgentTaskOptions, } from './types';
11
+ /**
12
+ * Trigger a task agent execution via the platform's /trigger-task-agent endpoint.
13
+ *
14
+ * This is a thin HTTP wrapper -- it asks the platform to start (or resume) an
15
+ * agent execution and returns the execution metadata. Use
16
+ * {@link getAgentTaskStatus} to poll for completion when running in async mode.
17
+ *
18
+ * @param agentName - Agent name. Use "appId:agentName" to target an agent in
19
+ * another app; otherwise the current app's APP_ID is used.
20
+ * @param env - Worker environment bindings (needs WORKSPACE_API_URL, WORKSPACE_API_KEY, APP_ID)
21
+ * @param options - Optional prompt, input files, timeout, session resume, and await flag
22
+ */
23
+ export declare function runAgentTask(agentName: string, env: Env, options?: RunAgentTaskOptions): Promise<AgentTaskExecution>;
24
+ /**
25
+ * Query the status of a task agent execution by its execution ID.
26
+ *
27
+ * @param executionId - The execution identifier returned by {@link runAgentTask}
28
+ * @param env - Worker environment bindings (needs WORKSPACE_API_URL, WORKSPACE_API_KEY)
29
+ */
30
+ export declare function getAgentTaskStatus(executionId: string, env: Env): Promise<AgentTaskExecution>;