@loomcycle/client 1.81.0 → 1.82.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.
@@ -113,8 +113,42 @@ function runBody(opts) {
113
113
  body.max_context_tokens = opts.maxContextTokens;
114
114
  if (opts.interactive !== undefined)
115
115
  body.interactive = opts.interactive;
116
+ applyOverridesToWire(body, opts);
116
117
  return body;
117
118
  }
119
+ /** Serializes the RFC DC per-run overrides onto a request body.
120
+ *
121
+ * One function rather than two copies of the list, because this file already
122
+ * serializes RunOptions field-by-field at two call sites — and a field added
123
+ * to the TYPE but to only one of those lists is invisible on the wire from one
124
+ * of them, silently. That is the shape of the bug RFC DA shipped.
125
+ */
126
+ function applyOverridesToWire(body, opts) {
127
+ if (opts.model !== undefined)
128
+ body.model = opts.model;
129
+ if (opts.provider !== undefined)
130
+ body.provider = opts.provider;
131
+ if (opts.tier !== undefined)
132
+ body.tier = opts.tier;
133
+ if (opts.effort !== undefined)
134
+ body.effort = opts.effort;
135
+ if (opts.maxTokens !== undefined)
136
+ body.max_tokens = opts.maxTokens;
137
+ if (opts.maxIterations !== undefined)
138
+ body.max_iterations = opts.maxIterations;
139
+ if (opts.unboundedIterations !== undefined)
140
+ body.unbounded_iterations = opts.unboundedIterations;
141
+ if (opts.maxConcurrentChildren !== undefined)
142
+ body.max_concurrent_children = opts.maxConcurrentChildren;
143
+ if (opts.retryAttempts !== undefined)
144
+ body.retry_attempts = opts.retryAttempts;
145
+ if (opts.memoryInjectMaxTokens !== undefined)
146
+ body.memory_inject_max_tokens = opts.memoryInjectMaxTokens;
147
+ if (opts.memoryIndexMaxBytes !== undefined)
148
+ body.memory_index_max_bytes = opts.memoryIndexMaxBytes;
149
+ if (opts.injectToolGuide !== undefined)
150
+ body.inject_tool_guide = opts.injectToolGuide;
151
+ }
118
152
  class LoomcycleClient {
119
153
  ctx;
120
154
  constructor(opts = {}) {
@@ -199,6 +233,7 @@ class LoomcycleClient {
199
233
  body.max_context_tokens = opts.maxContextTokens;
200
234
  if (opts.interactive !== undefined)
201
235
  body.interactive = opts.interactive;
236
+ applyOverridesToWire(body, opts);
202
237
  yield* this.streamSSE(`/v1/sessions/${encodeURIComponent(opts.sessionId)}/messages`, body, opts.signal, opts.debug);
203
238
  }
204
239
  /** Push an operator steering message into a LIVE interactive run (RFC AI).
package/dist/client.js CHANGED
@@ -110,8 +110,42 @@ function runBody(opts) {
110
110
  body.max_context_tokens = opts.maxContextTokens;
111
111
  if (opts.interactive !== undefined)
112
112
  body.interactive = opts.interactive;
113
+ applyOverridesToWire(body, opts);
113
114
  return body;
114
115
  }
116
+ /** Serializes the RFC DC per-run overrides onto a request body.
117
+ *
118
+ * One function rather than two copies of the list, because this file already
119
+ * serializes RunOptions field-by-field at two call sites — and a field added
120
+ * to the TYPE but to only one of those lists is invisible on the wire from one
121
+ * of them, silently. That is the shape of the bug RFC DA shipped.
122
+ */
123
+ function applyOverridesToWire(body, opts) {
124
+ if (opts.model !== undefined)
125
+ body.model = opts.model;
126
+ if (opts.provider !== undefined)
127
+ body.provider = opts.provider;
128
+ if (opts.tier !== undefined)
129
+ body.tier = opts.tier;
130
+ if (opts.effort !== undefined)
131
+ body.effort = opts.effort;
132
+ if (opts.maxTokens !== undefined)
133
+ body.max_tokens = opts.maxTokens;
134
+ if (opts.maxIterations !== undefined)
135
+ body.max_iterations = opts.maxIterations;
136
+ if (opts.unboundedIterations !== undefined)
137
+ body.unbounded_iterations = opts.unboundedIterations;
138
+ if (opts.maxConcurrentChildren !== undefined)
139
+ body.max_concurrent_children = opts.maxConcurrentChildren;
140
+ if (opts.retryAttempts !== undefined)
141
+ body.retry_attempts = opts.retryAttempts;
142
+ if (opts.memoryInjectMaxTokens !== undefined)
143
+ body.memory_inject_max_tokens = opts.memoryInjectMaxTokens;
144
+ if (opts.memoryIndexMaxBytes !== undefined)
145
+ body.memory_index_max_bytes = opts.memoryIndexMaxBytes;
146
+ if (opts.injectToolGuide !== undefined)
147
+ body.inject_tool_guide = opts.injectToolGuide;
148
+ }
115
149
  export class LoomcycleClient {
116
150
  ctx;
117
151
  constructor(opts = {}) {
@@ -196,6 +230,7 @@ export class LoomcycleClient {
196
230
  body.max_context_tokens = opts.maxContextTokens;
197
231
  if (opts.interactive !== undefined)
198
232
  body.interactive = opts.interactive;
233
+ applyOverridesToWire(body, opts);
199
234
  yield* this.streamSSE(`/v1/sessions/${encodeURIComponent(opts.sessionId)}/messages`, body, opts.signal, opts.debug);
200
235
  }
201
236
  /** Push an operator steering message into a LIVE interactive run (RFC AI).
package/dist/types.d.ts CHANGED
@@ -7,7 +7,7 @@
7
7
  * `client.ts` for the input shapes (RunOptions, CreateSnapshotOptions,
8
8
  * etc.) — those are translated to snake_case in the request body.
9
9
  */
10
- export type EventType = "started" | "text" | "tool_call" | "tool_result" | "usage" | "done" | "error" | "retry" | "host_widened" | "session" | "agent" | "awaiting_input" | "steer" | "context_compaction" | "limit" | "_meta";
10
+ export type EventType = "started" | "text" | "tool_call" | "tool_result" | "usage" | "done" | "error" | "retry" | "host_widened" | "session" | "agent" | "awaiting_input" | "steer" | "context_compaction" | "limit" | "override" | "_meta";
11
11
  export interface ToolUse {
12
12
  id: string;
13
13
  name: string;
@@ -60,6 +60,28 @@ export interface HostWidening {
60
60
  * scope stands against its ceiling — so a UI can render "tenant acme at 1.2M /
61
61
  * 1M tokens this month" without a follow-up fetch. Wire-stable; mirrors
62
62
  * providers.LimitInfo. */
63
+ /** OverrideInfo accompanies an `event: override` frame (RFC DC per-run
64
+ * overrides): a run's own configuration changed mid-run because an operator
65
+ * retuned it.
66
+ *
67
+ * It names what MOVED rather than what the settings now are, because "the
68
+ * configuration changed" answers nothing for someone trying to explain why the
69
+ * answers got different after turn 12.
70
+ *
71
+ * Carries only operator-chosen configuration whose effects are already visible
72
+ * — a model name, a budget. No credential, no operator host. */
73
+ export interface OverrideInfo {
74
+ /** Who changed it. "operator" today; present so a later automatic retune is
75
+ * distinguishable rather than indistinguishable. */
76
+ source: string;
77
+ /** "provider/model" before the change. Absent when routing did not move. */
78
+ from_model?: string;
79
+ /** "provider/model" after the change. */
80
+ to_model?: string;
81
+ /** The override keys the request actually set — so a budget or tuning change
82
+ * that moved no model is still legible. */
83
+ fields?: string[];
84
+ }
63
85
  /** The machine-readable half of a terminal run failure, carried on
64
86
  * `event: error` frames.
65
87
  *
@@ -128,6 +150,9 @@ export interface AgentEvent {
128
150
  /** Payload on `event: limit` (RFC AW) — a per-scope token-budget crossing.
129
151
  * Nil on all other event types. */
130
152
  limit?: LimitInfo;
153
+ /** Set on `event: override` frames — what the operator changed, and from
154
+ * what to what. */
155
+ override?: OverrideInfo;
131
156
  /** Payload on `event: error` — the classification of a TERMINAL run failure.
132
157
  * Absent on every other event type, and absent for a failure the runtime
133
158
  * cannot categorise: there is deliberately no "unknown" category, so a
@@ -161,7 +186,55 @@ export interface PromptSegment {
161
186
  role: "system" | "user";
162
187
  content: PromptContent[];
163
188
  }
164
- export interface RunOptions {
189
+ /** The per-run overrides (RFC DC) — a run's own answer to how it should run,
190
+ * instead of its agent definition's. Persisted with the run, so they survive a
191
+ * pause; a parked run can also be retuned via `sendRunInput`.
192
+ *
193
+ * Declared ONCE and extended by both {@link RunOptions} and
194
+ * {@link ContinueOptions}, because the serializer that writes them is shared
195
+ * by both paths — a copy on one interface and not the other compiles as a type
196
+ * error at best and drops the caller's value at worst.
197
+ */
198
+ export interface RunOverrideOptions {
199
+ /** Run on a specific model. Must be one the agent's definition already
200
+ * allows — an override selects WITHIN that set and cannot widen it, so
201
+ * which vendor sees the conversation stays an operator decision. Naming a
202
+ * model PINS it: the tier stops choosing and stops falling back. */
203
+ model?: string;
204
+ /** Run on a specific provider. Must be one the definition already allows.
205
+ * Unlike `model` this NARROWS rather than pins — the tier still chooses the
206
+ * model within that vendor and still falls back within it. */
207
+ provider?: string;
208
+ /** Route through a different configured tier. */
209
+ tier?: string;
210
+ /** Reasoning-effort hint. Any value outside low|medium|high is REFUSED
211
+ * rather than ignored: "effort was dropped" and "effort was applied" look
212
+ * identical from the outside. */
213
+ effort?: "low" | "medium" | "high";
214
+ /** Per-reply output cap. May be RAISED above the agent's own. */
215
+ maxTokens?: number;
216
+ /** Loop bound. May be RAISED above the agent's own. */
217
+ maxIterations?: number;
218
+ /** Lift or restore the loop bound. `false` bounds an otherwise-unbounded
219
+ * agent for this run only — which is why it is a boolean you can set rather
220
+ * than a flag you can only turn on. */
221
+ unboundedIterations?: boolean;
222
+ /** How wide this run may fan out into sub-agents. May only be LOWERED below
223
+ * what the definition allows; raising it is refused, because a child takes
224
+ * no admission slot and is not budget-checked at spawn, so this is the only
225
+ * bound on fan-out that exists. */
226
+ maxConcurrentChildren?: number;
227
+ /** How many times to retry the same provider before falling back. 0 disables
228
+ * retrying for this run. */
229
+ retryAttempts?: number;
230
+ /** Token budget for memory injected into the prompt. 0 injects none. */
231
+ memoryInjectMaxTokens?: number;
232
+ /** Byte budget for the memory index. 0 omits it. */
233
+ memoryIndexMaxBytes?: number;
234
+ /** Whether to inject the generated tool guide into the prompt. */
235
+ injectToolGuide?: boolean;
236
+ }
237
+ export interface RunOptions extends RunOverrideOptions {
165
238
  agent: string;
166
239
  segments: PromptSegment[];
167
240
  tools?: string[];
@@ -338,7 +411,7 @@ export interface ParentContext {
338
411
  * position and not an absent one. */
339
412
  wave_index?: number;
340
413
  }
341
- export interface ContinueOptions {
414
+ export interface ContinueOptions extends RunOverrideOptions {
342
415
  /** Required — the session to continue. */
343
416
  sessionId: string;
344
417
  segments: PromptSegment[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loomcycle/client",
3
- "version": "1.81.0",
3
+ "version": "1.82.0",
4
4
  "description": "TypeScript client for the loomcycle sidecar (HTTP+SSE). 71 methods covering run streaming, agent metadata, pause/resume/state, resolver re-probe (resolveProbe — issue #88 operator escape hatch), operator-token admin (operatorTokenDef — RFC L OSS multi-tenant auth) + whoami (RFC L authoritative principal, v0.17.0) + tenant-scoped listUsers / listUserAgents, dynamic MCP registration (mcpServerDef + v0.18.0 typed mcpServerDefVerify + ensureMcpServer idempotent register-if-changed), snapshot lifecycle, memory admin (incl. v0.9.0 Vector Memory embed_stats + reembed AND v0.11.5 setMemoryEntry + deleteMemoryEntry), interruption resolve, hook management, v0.8.22 substrate admin (agentDef + skillDef), v0.9.x n8n Phase 0 (listChannels + streamUserRunStates), v0.9.x Channel CRUD (publishChannel + subscribeChannel + peekChannel + ackChannel), v0.11.5 Channel admin CRUD (createChannel + updateChannel + deleteChannel — runtime substrate; yaml channels refuse mutation with HTTP 409), v0.9.x content_sha256 verify, v0.9.1 transcript first-cycle, v0.9.x dynamic MCP server registration (mcpServerDef + MCPServerDefVerifyResult), v0.10.3 Library v2 enumeration (listLibraryAgents + listLibrarySkills + listLibraryMcpServers), and v0.11.0 LLM Gateway (llmChat + llmStream — direct provider routing without agent overhead; primary target is n8n's LoomCycleChatModel AI Agent sub-node and any LangChain-compatible consumer). v0.10.1 — dual ESM + CommonJS distribution (additive — ESM consumers unchanged; CJS consumers like n8n's community-node loader now work). v0.19.0 — typed inline code-js agent ingestion (AgentDefOverlay.code_body + ensureCodeAgent — register a deterministic code agent through the substrate with no host filesystem bind; RFC J). v0.20.0 — ensureMcpServer surfaces discoveredToolCount straight from create (loomcycle now auto-discovers MCP tools at ingestion); rediscover is now an explicit force-refresh. v0.21.0 — run/continue accept optional non-secret `metadata` (repo name, review policy, …) passed to the agent, symmetric with the WebHook/Schedule trigger paths. v0.22.0 — version-aligned lockstep release; no client-surface change (RFC N tenant isolation of the agent/skill/MCP/Schedule/Webhook definition plane + real op-schemas on the builtin MCP meta-tools are both server-side). v0.23.0 — version-aligned lockstep release; no client-surface change (RFCs O/P/R MCP-server hardening + thin client and the RFC Q DeepSeek tool-content fix are all server-side / MCP-transport-side). v0.24.0 — purgeChannel clears a channel's buffered messages without deleting its definition (allowed on yaml-declared channels too, unlike deleteChannel — F20); AgentDefOverlay gains channels / evaluation_scopes / interruption so a COMPLETE interactive/multi-agent agent round-trips over the substrate (F14). (Consolidates the interim 0.24/0.25 package bumps, which were never tag-published, back into lockstep with the loomcycle v0.24.0 tag.) v0.25.0 — adds the RFC S channel fan-in/fan-out client twins: awaitChannels() (wait for any/all/at_least N messages across channels, or a timeout — non-committing) + broadcastChannels() (publish one payload to N channels in one atomic-pre-flight call), the client-facing counterparts of the in-band Channel.await / Channel.broadcast tool ops (the rest of v0.25.0 — the manual-management Web UI console + Context op=time + max_fires self-retiring schedules — is server-side / in-band, no client-surface change). v0.29.1 — Usage gains optional `max_context_tokens` (the serving model's context-window ceiling, stamped by the loop from Provider.Capabilities() on each usage event) so a consumer can render a 'context used / max' gauge without a hard-coded per-model table; additive + optional, no behavior change. (Lockstep catch-up: the field landed in loomcycle v0.29.0 but the adapter publish skipped on a version mismatch; v0.29.1 realigns the package version with the release tag so it publishes.) v0.33.0 — gRPC + TS client parity for the RFC Y external fan-out and the compaction surface: spawnRunBatch() (POST /v1/runs:batch — spawn up to 32 fresh runs concurrently in one call, combined index-aligned envelope, per-child failures in-envelope) + compactRun(runId) (POST /v1/runs/{run_id}/compact — summarize a parked run's context); plus per-run sampling + compaction overrides now accepted on runStreaming / continueSession (an explicit temperature 0 is preserved as deterministic, not dropped as falsy). (The gRPC half adds the matching SpawnRunBatch / CompactRun RPCs + the sampling/compaction fields on RunRequest/ContinueRequest — server-side.) v0.34.0 — version-aligned lockstep release; no client-surface change (context-transform plugins / RFC Z Phase 1a are server-side config; the exp7 hardening pass is server-side; the R2 cross-provider thinking-model downgrade surfaces a new `model_downgraded` SSE event the generic stream passes through unchanged). v0.35.0 — RFC AH dynamic filesystem volumes: volumeDef() (POST /v1/_volumedef — op-discriminated create/get/list/delete/purge; a Volume is flat, so delete unmaps + purge RemoveAll's, no retire/promote/fork) + listVolumes() / listEphemeralVolumes() (GET /v1/_volumes[/ephemeral] — tenant-scoped; host paths redacted for non-operator callers). Tenant-confined; the runtime derives the path inside an operator-blessed dynamic_root, so callers pass name + mode, never a host path. v1.1.1 — RFC AI interactive agentic sessions: an `interactive: true` flag on runStreaming/continueSession (a run that parks at end_turn for steering) + sendRunInput(runId, text) (POST /v1/runs/{id}/input — steer a live run) + streamRunByID(runId, {fromSeq}) (GET /v1/runs/{id}/stream — re-attach by run_id; the operator's prior turns replay as `steer` events so a cold client reconstructs the whole conversation) + a high-level InteractiveSession driver (client.interactiveSession / attachInteractiveSession — events()/send()/cancel(), the adapter port of the Web UI run terminal). The AgentEvent union gains awaiting_input/steer/context_compaction frames. Version-aligned with the loomcycle v1.1.x line so the v1.1.1 tag publishes it (also carrying the previously-unpublished v0.35.0 volume surface). v1.4.0 — RFC AL Path VFS + RFC AK Document on the wire: path(input) (POST /v1/_path — a Unix-like filesystem over Memory/Volumes/Documents; resolve/ls/stat/mkdir/mv/rm) + document(input) (POST /v1/_document — chunked-graph documents; 13 ops, needs SQL Memory on the sidecar). Scope (agent/user/tenant) + tenant are resolved server-side from the authenticated principal, never the wire; an off-run scope:'user' op keys on the principal subject so it interoperates with that user's agent runs. New PathToolInput / DocumentToolInput types; responses are op-varying (unknown — narrow as needed). v1.7.0 — RFC AT image/vision input: the PromptContent union gains an `image` variant ({ type:'image'; media_type: ImageMediaType; data: base64-no-prefix }) accepted in a user segment by runStreaming / continueSession (segments pass through unchanged — no method change). The model must be vision-capable or the run errors before the call. New ImageMediaType type (image/png|jpeg|gif|webp). v1.12.1 — Path/Document browse-by-subject + the full Document op set (RFC AS/AK): path(input, opts) / document(input, opts) accept optional scopeId / tenant browse overrides sent as ?scope_id= / ?tenant= query params (server reads them from the URL, re-checks authorization; omit both to browse your own subject — byte-identical to the pre-RFC-AS request), and DocumentToolInput.op now covers all 16 backend ops (adds set_path, export_md, import_md) with the matching include_metadata / markdown fields. Additive — existing path() / document() callers are unchanged. v1.16.0 — RFC BC client-executed tools (local tool host): connectClientTools({tools,onInvoke}) opens a persistent WebSocket to /v1/client-tools, registers tools this client runs on the user's machine (browser DOM / files / shell), and answers the invoke frames loomcycle routes when an agent of your principal calls a client:<tool> — returning your reply as an ordinary tool result. Returns a ClientToolHost driver (.close() to stop; auto-reconnect); dependency-free (global WebSocket in browsers / Node 22+, or an injected WebSocketImpl like the ws package on older Node); the bearer rides the Sec-WebSocket-Protocol subprotocol (browsers can't set an Authorization header on a WebSocket). The runtime's first WebSocket surface. v1.45.0 — RFC BL P5 subject erasure: erasureReport(subject, {tenant}) (GET /v1/_erasure — what this deployment holds about one subject, in three tiers: deletable with existing primitives, subject-keyed but not deletable, and facts ABOUT the subject in scopes they do not own) + erasureExecute(subject, {dryRun, confirm, tenant}) (POST /v1/_erasure — removes tiers 1 and 2). DEFAULTS TO A DRY RUN: dryRun defaults true and a live run also requires confirm === subject. The tier-3 residue is traceable only through the subject's chats, which a live run deletes, so a report afterwards shows rows: 0 while those facts remain — the returned object is the only durable record of what was not reached; persist it. New ErasureReport / ErasureResult / ErasureTier / ErasureResidue types. v1.47.0 — RFC BV memory-view SDK: memorySearch() (POST /v1/_memory/search — off-run unified semantic search spanning k/v entries AND document-chunk bodies in one ranked list, each hit tagged kind memory|document with chunk_id on document hits) + memoryEmbedStats(scope) + reembedMemory(scope, scopeId, {dryRun,limit}) (the Vector Memory embed-admin reads the memory-view console needs; dry_run defaults true). Fact reads (list_facts + get_chunk's entity block) ride the existing document() passthrough. Additive — existing callers unchanged. v1.61.0 — RFC CJ per-run context-window override: runStreaming / continueSession accept an optional maxContextTokens (integer tokens) that wins over the agent's own max_context_tokens; omitted inherits it (which defers to the provider/driver default). Distinct from a model's output cap; primarily for local inference (Ollama num_ctx). Serialized as the snake_case max_context_tokens field on POST /v1/runs + the continuation body; additive, existing callers unchanged. v1.72.1 — the TeamDef version lifecycle: listTeamVersions(name) (op=list — every version of one team, newest first), promoteTeam(defId) (op=promote — point the active pointer, which is what a run BY NAME executes; forkTeam defaults to promote:false, so authoring and putting in force stay two steps), retireTeam(defId, retired) (op=retire — reversible and version-scoped, unlike deleteTeam) and verifyTeam(name, contentSha256) (op=verify — the drift check for a workflow kept in source control and pushed to several deployments; an absent team answers deployed:false rather than raising). The ops existed on the substrate and over HTTP; a client that could author a team could not put one in force.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",