runwork 0.25.2 → 0.26.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.
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Framework client entry: browser-side helpers an app's frontend imports as
3
+ * `@runworkai/framework/client`, so app code never carries this plumbing
4
+ * itself.
5
+ *
6
+ * Analytics: what people do in the app, reported to the workspace.
7
+ *
8
+ * Envelope follows the Segment Spec (the de-facto standard Google Analytics,
9
+ * Mixpanel, PostHog and friends all map to), so nothing here needs to change
10
+ * if the workspace later forwards events to a real analytics tool.
11
+ *
12
+ * The app does not interpret events. `/api/analytics` stamps the app's
13
+ * identity and forwards to the workspace, which decides what each one means.
14
+ * Today a `page` counts as one USE of the app, the multiplier behind a
15
+ * standalone app's value in the workspace's reports. `track` events are kept
16
+ * for a later analytics surface.
17
+ *
18
+ * A page load is reported here because the document is served before the
19
+ * app's Worker runs, leaving no server-side trace otherwise. Once per
20
+ * document, not per route change: the workspace counts an opened tool, and a
21
+ * person navigating inside it is still one use.
22
+ *
23
+ * Fire-and-forget. Nothing here may ever affect the person using the app.
24
+ */
25
+ /** Record a custom event. Use a flat Title Case name ("Report Exported") and put variables in properties. */
26
+ export declare function track(event: string, properties?: Record<string, unknown>): void;
27
+ /** Record a named screen or view inside the app. */
28
+ export declare function screen(name: string, properties?: Record<string, unknown>): void;
29
+ /**
30
+ * Tell the workspace who this browser belongs to, in the APP's own terms.
31
+ * A claim, recorded as data; the workspace never grants anything on it.
32
+ */
33
+ export declare function identify(userId: string, traits?: Record<string, unknown>): void;
34
+ /** Attach this person to a company, account or team the app knows about. */
35
+ export declare function group(groupId: string, traits?: Record<string, unknown>): void;
36
+ /** Link a past anonymous identity to a known one. */
37
+ export declare function alias(userId: string, previousId?: string): void;
38
+ /** Record that this app was opened. Called once automatically on load. */
39
+ export declare function page(): void;
@@ -230,8 +230,8 @@ export declare const integrationApiSchema: z.ZodObject<{
230
230
  endpoint: z.ZodString;
231
231
  data: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
232
232
  }, "strip", z.ZodTypeAny, {
233
- method: "POST" | "GET" | "PUT" | "PATCH" | "DELETE";
234
233
  endpoint: string;
234
+ method: "POST" | "GET" | "PUT" | "PATCH" | "DELETE";
235
235
  data?: Record<string, unknown> | undefined;
236
236
  }, {
237
237
  endpoint: string;
@@ -66,8 +66,6 @@ export type Doc<T> = {
66
66
  * - Security validation on all field names
67
67
  */
68
68
  export declare class EntityDO extends DurableObject<Env> {
69
- ctx: DurableObjectState;
70
- env: Env;
71
69
  private _tableReady;
72
70
  private _migrationDone;
73
71
  constructor(ctx: DurableObjectState, env: Env);
@@ -41,12 +41,5 @@ export declare function toChannelName(appName: string): string;
41
41
  * these entries in the observability timeline.
42
42
  */
43
43
  export declare function flog(level: 'info' | 'warn' | 'error', system: string, message: string, data?: Record<string, unknown>): void;
44
- /**
45
- * Emit an event to the workspace unified event stream.
46
- * Fire-and-forget: uses ctx.waitUntil so it doesn't block the response.
47
- * Silently skips if workspace env vars are not configured (standalone mode).
48
- *
49
- * Automatically routes events to a channel derived from APP_NAME when available.
50
- */
51
44
  export declare function emitEvent(ctx: WaitUntilContext, env: EventEnv, event: EmitEventParams): void;
52
45
  export {};
@@ -207,10 +207,6 @@ export declare class FileStorageClient {
207
207
  */
208
208
  export declare function createFileStorageClient(env: Env): FileStorageClient;
209
209
  import type { Hono } from 'hono';
210
- /**
211
- * Mount file storage routes on the Hono app
212
- * Provides REST API for R2 bucket operations
213
- */
214
210
  export declare function fileStorageRoutes(app: Hono<{
215
211
  Bindings: Env;
216
212
  }>): void;
@@ -69,7 +69,109 @@ export declare const isStr: (s: unknown) => s is string;
69
69
  * that would cause structured clone to fail in ctx.storage.put().
70
70
  */
71
71
  export declare function safeClone<T>(value: T, fallback?: T): T;
72
- export declare function platformFetch(env: Env, url: string | URL, init?: RequestInit): Promise<Response>;
72
+ /**
73
+ * Platform fetch - routes requests through WorkspaceObject DO for production workers.
74
+ *
75
+ * Workers for Platforms (WfP) workers cannot reliably make HTTP requests back to their
76
+ * parent platform worker (they get 522 timeouts). This utility routes platform API calls
77
+ * through the WorkspaceObject Durable Object binding, which works across worker boundaries.
78
+ *
79
+ * Supported paths:
80
+ * - /api/proxy/integrations/* - Integration proxy (Nango)
81
+ * - /api/proxy/openai/* - AI Gateway proxy
82
+ * - /api/storage/presign - Storage presigned URLs
83
+ *
84
+ * For preview containers (DEPLOYMENT_MODE !== 'production'), uses standard fetch.
85
+ *
86
+ * @example
87
+ * ```typescript
88
+ * // Instead of:
89
+ * const response = await fetch('https://runwork.ai/api/proxy/integrations/proxy/contacts', options);
90
+ *
91
+ * // Use:
92
+ * const response = await platformFetch(env, 'https://runwork.ai/api/proxy/integrations/proxy/contacts', options);
93
+ * ```
94
+ */
95
+ /**
96
+ * What the app was doing when it made a call.
97
+ *
98
+ * Internal plumbing, deliberately not exported from the package: app authors
99
+ * never set this, the framework establishes it at each entry point (schedule
100
+ * tick, workflow run, route handler, agent turn) and `platformFetch` below
101
+ * reads it. It lives beside `platformFetch` because that is its only consumer.
102
+ *
103
+ * WHY IT EXISTS: usage rows record `appId` and `userId` and nothing about what
104
+ * was executing, so a HubSpot call made by a nightly schedule cannot be told
105
+ * apart from one a person made from their own agent. `runId` is the field that
106
+ * cannot be reconstructed later: it links one run's AI calls and integration
107
+ * calls together, which is what per-run cost is built from.
108
+ *
109
+ * Design: docs/plans/2026-08-28-baselines-capture-redesign.md section 4.1.
110
+ */
111
+ export interface RunContext {
112
+ /**
113
+ * WHAT was executing. Only constructs the framework itself runs, never
114
+ * "where the caller was" (a browser, MCP, the CLI): that is a different
115
+ * question and `audit_logs.actor_type` owns it.
116
+ */
117
+ kind: 'schedule' | 'workflow' | 'endpoint' | 'route' | 'agent';
118
+ /**
119
+ * Human-readable name, following the convention the audit rows already use:
120
+ * a schedule/workflow/agent slug, or `METHOD /path` for endpoints and routes.
121
+ *
122
+ * OMITTED rather than defaulted when genuinely unknown. A placeholder string
123
+ * like 'unknown' becomes a value every query has to filter out, and it is
124
+ * indistinguishable from an app that named something 'unknown'.
125
+ */
126
+ name?: string;
127
+ /**
128
+ * App-local registry key, so a usage row joins back to a registration. The
129
+ * app id is a column of its own, so this is the part after it: a slug for
130
+ * schedules, workflows and agents, `METHOD /path` for endpoints.
131
+ */
132
+ resourceKey?: string;
133
+ /** One id shared by everything emitted inside this execution. */
134
+ runId: string;
135
+ /** The enclosing run, for workflow steps, nested calls and sub-agents. */
136
+ parentRunId?: string;
137
+ trigger?: 'cron' | 'manual' | 'webhook' | 'chat' | 'api';
138
+ /**
139
+ * The person who started this run. Named to match the governance program's
140
+ * `DelegationChain.triggererUserId` (`worker/types/permissions.ts`), which is
141
+ * the same fact: one name for it across both programs.
142
+ *
143
+ * ATTRIBUTION, NEVER AUTHORITY. This travels on a header from the app, behind
144
+ * the shared WORKSPACE_API_KEY, so an app can put any user id here. The
145
+ * platform may RECORD it; nothing may ever AUTHORIZE on it. Whose authority a
146
+ * run borrows is resolved platform-side by PermissionService, not stated by
147
+ * the caller.
148
+ */
149
+ triggererUserId?: string;
150
+ attempt?: number;
151
+ }
152
+ /** Header carrying the context to the platform side, which writes the audit row. */
153
+ export declare const RUN_CONTEXT_HEADER = "x-runwork-run-context";
154
+ /**
155
+ * Run `fn` with `ctx` as the ambient execution context.
156
+ *
157
+ * Nesting is automatic: entering a context inside another records the outer
158
+ * `runId` as `parentRunId` unless the caller set one. That is what makes a
159
+ * sub-agent's calls point at the run that started it. Re-entering the SAME
160
+ * run id is not nesting (a workflow resumes into its own run across wake-ups)
161
+ * and must not make a run its own parent.
162
+ */
163
+ export declare function withRunContext<T>(ctx: RunContext, fn: () => T): T;
164
+ /** The current execution context, or undefined outside any entry point. */
165
+ export declare function getRunContext(): RunContext | undefined;
166
+ /**
167
+ * Merge the context header into request headers.
168
+ *
169
+ * One serialised header rather than several, so adding a field never needs a
170
+ * matching change in the platform's parsing. Never overwrites a header the
171
+ * caller set: a caller that knows its own context beats the ambient one.
172
+ */
173
+ export declare function withRunContextHeader(init?: HeadersInit): HeadersInit | undefined;
174
+ export declare function platformFetch(env: Env, url: string | URL, rawInit?: RequestInit): Promise<Response>;
73
175
  /**
74
176
  * Workspace API fetch - routes workspace service requests through WorkspaceObject DO
75
177
  * for production WfP workers, avoiding 522 recursive invocation errors.
@@ -82,4 +184,4 @@ export declare function platformFetch(env: Env, url: string | URL, init?: Reques
82
184
  * @param path - Workspace API sub-path (e.g., '/ingest-event')
83
185
  * @param init - Standard fetch options
84
186
  */
85
- export declare function workspaceApiFetch(env: Pick<Env, 'WORKSPACE_API_URL' | 'WORKSPACE_API_KEY' | 'WORKSPACE_ID' | 'DEPLOYMENT_MODE' | 'WorkspaceObject'>, path: string, init?: RequestInit): Promise<Response>;
187
+ export declare function workspaceApiFetch(env: Pick<Env, 'WORKSPACE_API_URL' | 'WORKSPACE_API_KEY' | 'WORKSPACE_ID' | 'DEPLOYMENT_MODE' | 'WorkspaceObject'>, path: string, rawInit?: RequestInit): Promise<Response>;
@@ -9,7 +9,7 @@
9
9
  * - Types are defined in core-workflow-types.ts
10
10
  * - Native DO-based implementation is in core-workflow-instance.ts and core-workflow-coordinator.ts
11
11
  */
12
- import type { Env } from './core-utils';
12
+ import { type Env } from './core-utils';
13
13
  export type { WorkflowResult, WorkflowStatus, WorkflowInstanceInfo, WorkflowDefinition, WorkflowContext, WorkflowStepUtilities, StepOptions, WaitEventOptions, WorkflowLogger, WorkflowState, WorkflowStatusResponse, } from './core-workflow-types';
14
14
  import type { WorkflowInstanceInfo } from './core-workflow-types';
15
15
  /**