@flue/sdk 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.
@@ -112,7 +112,7 @@ interface SessionEnv {
112
112
  resolvePath(p: string): string;
113
113
  }
114
114
  /**
115
- * Filesystem surface for the agent sandbox, exposed on `FlueAgent.fs` and
115
+ * Filesystem surface for the harness sandbox, exposed on `FlueHarness.fs` and
116
116
  * `FlueSession.fs`. Reads and writes happen inside whatever the sandbox
117
117
  * connector points at (a remote container, microVM, in-process FS, etc.).
118
118
  *
@@ -173,7 +173,7 @@ interface ProviderSettings {
173
173
  baseUrl?: string;
174
174
  /** Headers merged into the resolved model's provider-level headers. */
175
175
  headers?: Record<string, string>;
176
- /** API key returned to the underlying agent runtime for this provider. */
176
+ /** API key returned to the underlying harness runtime for this provider. */
177
177
  apiKey?: string;
178
178
  /**
179
179
  * Sends `store: true` for OpenAI Responses API providers. Only enable when
@@ -212,7 +212,10 @@ type ModelConfig = string | false;
212
212
  * `wrangler types`). Compile-time only — no runtime validation of `payload`.
213
213
  */
214
214
  interface FlueContext<TPayload = any, TEnv = Record<string, any>> {
215
+ /** Agent instance id from the URL `<id>` segment. */
215
216
  readonly id: string;
217
+ /** Server-minted id for this HTTP invocation. */
218
+ readonly runId: string;
216
219
  readonly payload: TPayload;
217
220
  /** Platform env bindings (process.env on Node, Worker env on Cloudflare). */
218
221
  readonly env: TEnv;
@@ -238,13 +241,20 @@ interface FlueContext<TPayload = any, TEnv = Record<string, any>> {
238
241
  * trusted proxy on Node. Don't trust headers you don't control.
239
242
  */
240
243
  readonly req: Request | undefined;
241
- /** Initialize an agent runtime with sandbox + persistence. */
242
- init(options: AgentInit): Promise<FlueAgent>;
244
+ /** Emit structured log events visible in the run event stream. */
245
+ readonly log: FlueLogger;
246
+ /** Initialize a harness with sandbox + persistence. */
247
+ init(options: AgentInit): Promise<FlueHarness>;
243
248
  }
244
- /** Agent runtime options. A default model is required unless explicitly disabled with `model: false`. */
249
+ interface FlueLogger {
250
+ info(message: string, attributes?: Record<string, unknown>): void;
251
+ warn(message: string, attributes?: Record<string, unknown>): void;
252
+ error(message: string, attributes?: Record<string, unknown>): void;
253
+ }
254
+ /** Harness options. A default model is required unless explicitly disabled with `model: false`. */
245
255
  interface AgentInit {
246
- /** Agent/sandbox scope id. Defaults to the route/context id. */
247
- id?: string;
256
+ /** Harness name. Defaults to `"default"`. */
257
+ name?: string;
248
258
  /** Working directory for context discovery, tools, and shell calls. Defaults to the sandbox cwd. */
249
259
  cwd?: string;
250
260
  /**
@@ -260,16 +270,16 @@ interface AgentInit {
260
270
  /** Defaults to platform store (in-memory on Node, DO SQLite on Cloudflare). */
261
271
  persist?: SessionStore;
262
272
  /**
263
- * Default model for this agent. Applies to all prompt(), skill(), and task()
273
+ * Default model for this harness. Applies to all prompt(), skill(), and task()
264
274
  * calls unless overridden by a role or at the call site. Pass `false` to require every
265
275
  * model-using call to resolve a model from a role or call-site override.
266
276
  *
267
277
  * Format: `'provider/modelId'` (e.g. `'anthropic/claude-opus-4-20250514'`).
268
278
  *
269
- * Precedence (highest wins): per-call `model` > role `model` > agent `model`.
279
+ * Precedence (highest wins): per-call `model` > role `model` > harness `model`.
270
280
  */
271
281
  model: ModelConfig;
272
- /** Agent-wide default role. Overridden by session-level or per-call roles. */
282
+ /** Harness-wide default role. Overridden by session-level or per-call roles. */
273
283
  role?: string;
274
284
  /**
275
285
  * Default reasoning effort for every prompt(), skill(), and task() call.
@@ -278,38 +288,38 @@ interface AgentInit {
278
288
  * models effectively run with reasoning off after clamping.
279
289
  *
280
290
  * Precedence (highest wins): per-call `thinkingLevel` > role
281
- * `thinkingLevel` > agent `thinkingLevel`. When nothing is set, the harness
291
+ * `thinkingLevel` > harness `thinkingLevel`. When nothing is set, the harness
282
292
  * defaults to `"medium"`. Use `"off"` to explicitly disable reasoning on
283
293
  * models that support it.
284
294
  */
285
295
  thinkingLevel?: ThinkingLevel;
286
296
  /**
287
- * Agent-wide tools. Every prompt(), skill(), and task() call can use these.
297
+ * Harness-wide tools. Every prompt(), skill(), and task() call can use these.
288
298
  * Per-call tools are added on top and must not reuse the same names.
289
299
  */
290
300
  tools?: ToolDef[];
291
301
  }
292
- interface FlueAgent {
293
- readonly id: string;
294
- /** Get or create a session in this agent. Defaults to the "default" session. */
295
- session(id?: string, options?: SessionOptions): Promise<FlueSession>;
302
+ interface FlueHarness {
303
+ readonly name: string;
304
+ /** Get or create a session in this harness. Defaults to the "default" session. */
305
+ session(name?: string, options?: SessionOptions): Promise<FlueSession>;
296
306
  /** Explicit session management helpers. */
297
307
  readonly sessions: FlueSessions;
298
- /** Run a shell command in the agent sandbox without recording it in a conversation. */
308
+ /** Run a shell command in the harness sandbox without recording it in a conversation. */
299
309
  shell(command: string, options?: ShellOptions): CallHandle<ShellResult>;
300
310
  /**
301
- * Read and write files in the agent sandbox without recording in a
311
+ * Read and write files in the harness sandbox without recording in a
302
312
  * conversation. See {@link FlueFs}.
303
313
  */
304
314
  readonly fs: FlueFs;
305
315
  }
306
316
  interface FlueSessions {
307
317
  /** Load an existing session. Throws if it does not exist. */
308
- get(id?: string, options?: SessionOptions): Promise<FlueSession>;
318
+ get(name?: string, options?: SessionOptions): Promise<FlueSession>;
309
319
  /** Create a new session. Throws if it already exists. */
310
- create(id?: string, options?: SessionOptions): Promise<FlueSession>;
320
+ create(name?: string, options?: SessionOptions): Promise<FlueSession>;
311
321
  /** Delete a session's stored conversation state. No-op when missing. */
312
- delete(id?: string): Promise<void>;
322
+ delete(name?: string): Promise<void>;
313
323
  }
314
324
  interface SessionOptions {
315
325
  /** Session-wide default role. Per-call roles override this. */
@@ -328,7 +338,7 @@ interface CallHandle<T> extends PromiseLike<T> {
328
338
  abort(reason?: unknown): void;
329
339
  }
330
340
  interface FlueSession {
331
- readonly id: string;
341
+ readonly name: string;
332
342
  prompt<S extends v.GenericSchema>(text: string, options: PromptOptions<S> & {
333
343
  schema: S;
334
344
  }): CallHandle<PromptResultResponse<v.InferOutput<S>>>;
@@ -408,7 +418,7 @@ interface PromptResultResponse<T> {
408
418
  model: PromptModel;
409
419
  }
410
420
  interface SessionData {
411
- version: 2;
421
+ version: 3;
412
422
  entries: SessionEntry[];
413
423
  leafId: string | null;
414
424
  metadata: Record<string, any>;
@@ -566,7 +576,12 @@ interface BashLike {
566
576
  /** Factory that constructs the agent's Bash-like runtime. Called once at init. */
567
577
  type BashFactory = () => BashLike | Promise<BashLike>;
568
578
  type FlueEvent = ({
569
- type: 'agent_start';
579
+ type: 'run_start';
580
+ runId: string;
581
+ instanceId: string;
582
+ agentName: string;
583
+ startedAt: string;
584
+ payload: unknown;
570
585
  } | {
571
586
  type: 'text_delta';
572
587
  text: string;
@@ -584,13 +599,20 @@ type FlueEvent = ({
584
599
  toolCallId: string;
585
600
  args?: any;
586
601
  } | {
587
- type: 'tool_end';
602
+ type: 'tool_call';
588
603
  toolName: string;
589
604
  toolCallId: string;
590
605
  isError: boolean;
591
606
  result?: any;
607
+ durationMs: number;
592
608
  } | {
593
- type: 'turn_end';
609
+ type: 'turn';
610
+ durationMs: number;
611
+ model?: string;
612
+ usage?: PromptUsage;
613
+ stopReason?: string;
614
+ isError: boolean;
615
+ error?: unknown;
594
616
  } | {
595
617
  type: 'task_start';
596
618
  taskId: string;
@@ -598,26 +620,59 @@ type FlueEvent = ({
598
620
  role?: string;
599
621
  cwd?: string;
600
622
  } | {
601
- type: 'task_end';
623
+ type: 'task';
602
624
  taskId: string;
603
625
  isError: boolean;
604
626
  result?: any;
627
+ durationMs: number;
605
628
  } | {
606
629
  type: 'compaction_start';
607
630
  reason: 'threshold' | 'overflow';
608
631
  estimatedTokens: number;
609
632
  } | {
610
- type: 'compaction_end';
633
+ type: 'compaction';
611
634
  messagesBefore: number;
612
635
  messagesAfter: number;
636
+ durationMs: number;
637
+ usage?: PromptUsage;
638
+ } | {
639
+ type: 'operation_start';
640
+ operationId: string;
641
+ operationKind: 'prompt' | 'skill' | 'task' | 'shell';
642
+ } | {
643
+ type: 'operation';
644
+ operationId: string;
645
+ operationKind: 'prompt' | 'skill' | 'task' | 'shell';
646
+ durationMs: number;
647
+ isError: boolean;
648
+ error?: unknown;
649
+ result?: unknown;
650
+ usage?: PromptUsage;
651
+ } | {
652
+ type: 'log';
653
+ level: 'info' | 'warn' | 'error';
654
+ message: string;
655
+ attributes?: Record<string, unknown>;
613
656
  } | {
614
657
  type: 'idle';
658
+ } | {
659
+ type: 'run_end';
660
+ runId: string;
661
+ result?: unknown;
662
+ isError: boolean;
663
+ error?: unknown;
664
+ durationMs: number;
615
665
  }) & {
616
- sessionId?: string;
617
- parentSessionId?: string;
666
+ runId?: string;
667
+ eventIndex?: number;
668
+ timestamp?: string;
669
+ session?: string;
670
+ parentSession?: string;
618
671
  taskId?: string;
672
+ harness?: string;
673
+ operationId?: string;
619
674
  };
620
- type FlueEventCallback = (event: FlueEvent) => void;
675
+ type FlueEventCallback = (event: FlueEvent) => void | Promise<void>;
621
676
  interface AgentInfo {
622
677
  name: string;
623
678
  filePath: string;
@@ -724,4 +779,4 @@ interface BuildOptions {
724
779
  plugin?: BuildPlugin;
725
780
  }
726
781
  //#endregion
727
- export { SessionStore as A, PromptUsage as C, SessionData as D, SandboxFactory as E, TaskOptions as F, ThinkingLevel as I, ToolDef as L, ShellResult as M, Skill as N, SessionEnv as O, SkillOptions as P, ToolParameters as R, PromptResultResponse as S, Role as T, FlueSessions as _, BashLike as a, PromptOptions as b, BuildPlugin as c, FlueAgent as d, FlueContext as f, FlueSession as g, FlueFs as h, BashFactory as i, ShellOptions as j, SessionOptions as k, CallHandle as l, FlueEventCallback as m, AgentInfo as n, BuildContext as o, FlueEvent as p, AgentInit as r, BuildOptions as s, AgentConfig as t, FileStat as u, ModelConfig as v, ProviderSettings as w, PromptResponse as x, PromptModel as y };
782
+ export { SessionStore as A, PromptUsage as C, SessionData as D, SandboxFactory as E, TaskOptions as F, ThinkingLevel as I, ToolDef as L, ShellResult as M, Skill as N, SessionEnv as O, SkillOptions as P, ToolParameters as R, PromptResultResponse as S, Role as T, FlueSessions as _, BashLike as a, PromptOptions as b, BuildPlugin as c, FlueContext as d, FlueEvent as f, FlueSession as g, FlueHarness as h, BashFactory as i, ShellOptions as j, SessionOptions as k, CallHandle as l, FlueFs as m, AgentInfo as n, BuildContext as o, FlueEventCallback as p, AgentInit as r, BuildOptions as s, AgentConfig as t, FileStat as u, ModelConfig as v, ProviderSettings as w, PromptResponse as x, PromptModel as y };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flue/sdk",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "exports": {
@@ -57,6 +57,7 @@
57
57
  "just-bash": "^2.14.2",
58
58
  "package-up": "^5.0.0",
59
59
  "typescript": "^5.9.2",
60
+ "ulidx": "^2.4.1",
60
61
  "valibot": "^1.0.0"
61
62
  },
62
63
  "devDependencies": {