@loomcycle/client 0.11.5 → 0.12.8

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.
@@ -89,6 +89,10 @@ class LoomcycleClient {
89
89
  body.user_tier = opts.userTier;
90
90
  if (opts.userBearer !== undefined)
91
91
  body.user_bearer = opts.userBearer;
92
+ if (opts.userCredentials !== undefined)
93
+ body.user_credentials = opts.userCredentials;
94
+ if (opts.parentContext !== undefined)
95
+ body.parent_context = opts.parentContext;
92
96
  yield* this.streamSSE("/v1/runs", body, opts.signal, opts.debug);
93
97
  }
94
98
  /**
@@ -125,6 +129,10 @@ class LoomcycleClient {
125
129
  body.user_tier = opts.userTier;
126
130
  if (opts.userBearer !== undefined)
127
131
  body.user_bearer = opts.userBearer;
132
+ if (opts.userCredentials !== undefined)
133
+ body.user_credentials = opts.userCredentials;
134
+ if (opts.parentContext !== undefined)
135
+ body.parent_context = opts.parentContext;
128
136
  yield* this.streamSSE(`/v1/sessions/${encodeURIComponent(opts.sessionId)}/messages`, body, opts.signal, opts.debug);
129
137
  }
130
138
  // ---- Agent metadata ----
@@ -422,6 +430,38 @@ class LoomcycleClient {
422
430
  async mcpServerDef(input, opts) {
423
431
  return (0, fetch_helpers_js_1.postJSON)(this.ctx, "/v1/_mcpserverdef", input, opts);
424
432
  }
433
+ /** Invoke the v1.x RFC E ScheduleDef substrate tool over HTTP.
434
+ * Author + fork + retire scheduled-run definitions at runtime.
435
+ * Mirror of {@link LoomcycleClient.agentDef} for schedules — the
436
+ * primary use case is JobEmber-style "fork a yaml template
437
+ * per-user with their bearer + tier cron" workflows.
438
+ *
439
+ * Operator-admin-only: this endpoint requires the bearer token.
440
+ *
441
+ * Op-discriminated input: `{op: "create" | "fork" | "get" |
442
+ * "list" | "retire", ...}`. Note that ScheduleDef has 5 ops
443
+ * (no separate `promote` — forks auto-promote by default per
444
+ * RFC E's worked example; no `verify` — no content_sha256 in
445
+ * v1.x).
446
+ *
447
+ * Sharp edges (substrate refuses these):
448
+ * - Name colliding with a static cfg.ScheduledRuns entry is
449
+ * refused on `create` (yaml is ground truth; use `fork` to
450
+ * derive a new version).
451
+ * - Fork against a template with `required_credentials` must
452
+ * supply all keys in `user_credentials` — loud-fail at fork
453
+ * time rather than silent ingestion-time failure when the
454
+ * sweeper fires.
455
+ * - Cron syntax is validated server-side; invalid expressions
456
+ * refuse with a parse error.
457
+ *
458
+ * Raises {@link SubstrateToolRefusedError} on tool-level refusals
459
+ * (static-name collision, missing required credential, invalid
460
+ * cron, etc.); {@link InvalidArgumentError} on 400 (malformed
461
+ * JSON); {@link AuthError} on 401. */
462
+ async scheduleDef(input, opts) {
463
+ return (0, fetch_helpers_js_1.postJSON)(this.ctx, "/v1/_scheduledef", input, opts);
464
+ }
425
465
  // ---- v0.10.3 Library v2 enumeration (read-only, merged yaml+substrate) ----
426
466
  /** List every agent the runtime knows about — yaml-static + dynamic
427
467
  * AgentDefs merged into one envelope per name. Each entry carries
package/dist/cjs/index.js CHANGED
@@ -43,9 +43,11 @@
43
43
  * listRunInterrupts(runId, opts?): Promise<InterruptListResponse>
44
44
  * resolveInterrupt(runId, interruptId, opts): Promise<unknown>
45
45
  *
46
- * // Substrate admin (v0.8.22)
46
+ * // Substrate admin (v0.8.22; mcpServerDef v0.9.x; scheduleDef v1.x)
47
47
  * agentDef(input): Promise<SubstrateToolResponse>
48
48
  * skillDef(input): Promise<SubstrateToolResponse>
49
+ * mcpServerDef(input): Promise<SubstrateToolResponse>
50
+ * scheduleDef(input): Promise<SubstrateToolResponse>
49
51
  *
50
52
  * // Library v2 enumeration (v0.10.3 — yaml+substrate merged)
51
53
  * listLibraryAgents(): Promise<LibraryListResponse<LibraryAgentDefinition>>
package/dist/client.d.ts CHANGED
@@ -289,6 +289,38 @@ export declare class LoomcycleClient {
289
289
  mcpServerDef(input: SubstrateToolInput, opts?: {
290
290
  signal?: AbortSignal;
291
291
  }): Promise<SubstrateToolResponse>;
292
+ /** Invoke the v1.x RFC E ScheduleDef substrate tool over HTTP.
293
+ * Author + fork + retire scheduled-run definitions at runtime.
294
+ * Mirror of {@link LoomcycleClient.agentDef} for schedules — the
295
+ * primary use case is JobEmber-style "fork a yaml template
296
+ * per-user with their bearer + tier cron" workflows.
297
+ *
298
+ * Operator-admin-only: this endpoint requires the bearer token.
299
+ *
300
+ * Op-discriminated input: `{op: "create" | "fork" | "get" |
301
+ * "list" | "retire", ...}`. Note that ScheduleDef has 5 ops
302
+ * (no separate `promote` — forks auto-promote by default per
303
+ * RFC E's worked example; no `verify` — no content_sha256 in
304
+ * v1.x).
305
+ *
306
+ * Sharp edges (substrate refuses these):
307
+ * - Name colliding with a static cfg.ScheduledRuns entry is
308
+ * refused on `create` (yaml is ground truth; use `fork` to
309
+ * derive a new version).
310
+ * - Fork against a template with `required_credentials` must
311
+ * supply all keys in `user_credentials` — loud-fail at fork
312
+ * time rather than silent ingestion-time failure when the
313
+ * sweeper fires.
314
+ * - Cron syntax is validated server-side; invalid expressions
315
+ * refuse with a parse error.
316
+ *
317
+ * Raises {@link SubstrateToolRefusedError} on tool-level refusals
318
+ * (static-name collision, missing required credential, invalid
319
+ * cron, etc.); {@link InvalidArgumentError} on 400 (malformed
320
+ * JSON); {@link AuthError} on 401. */
321
+ scheduleDef(input: SubstrateToolInput, opts?: {
322
+ signal?: AbortSignal;
323
+ }): Promise<SubstrateToolResponse>;
292
324
  /** List every agent the runtime knows about — yaml-static + dynamic
293
325
  * AgentDefs merged into one envelope per name. Each entry carries
294
326
  * `source: "static-only" | "dynamic-only" | "both"` so callers can
package/dist/client.js CHANGED
@@ -86,6 +86,10 @@ export class LoomcycleClient {
86
86
  body.user_tier = opts.userTier;
87
87
  if (opts.userBearer !== undefined)
88
88
  body.user_bearer = opts.userBearer;
89
+ if (opts.userCredentials !== undefined)
90
+ body.user_credentials = opts.userCredentials;
91
+ if (opts.parentContext !== undefined)
92
+ body.parent_context = opts.parentContext;
89
93
  yield* this.streamSSE("/v1/runs", body, opts.signal, opts.debug);
90
94
  }
91
95
  /**
@@ -122,6 +126,10 @@ export class LoomcycleClient {
122
126
  body.user_tier = opts.userTier;
123
127
  if (opts.userBearer !== undefined)
124
128
  body.user_bearer = opts.userBearer;
129
+ if (opts.userCredentials !== undefined)
130
+ body.user_credentials = opts.userCredentials;
131
+ if (opts.parentContext !== undefined)
132
+ body.parent_context = opts.parentContext;
125
133
  yield* this.streamSSE(`/v1/sessions/${encodeURIComponent(opts.sessionId)}/messages`, body, opts.signal, opts.debug);
126
134
  }
127
135
  // ---- Agent metadata ----
@@ -419,6 +427,38 @@ export class LoomcycleClient {
419
427
  async mcpServerDef(input, opts) {
420
428
  return postJSON(this.ctx, "/v1/_mcpserverdef", input, opts);
421
429
  }
430
+ /** Invoke the v1.x RFC E ScheduleDef substrate tool over HTTP.
431
+ * Author + fork + retire scheduled-run definitions at runtime.
432
+ * Mirror of {@link LoomcycleClient.agentDef} for schedules — the
433
+ * primary use case is JobEmber-style "fork a yaml template
434
+ * per-user with their bearer + tier cron" workflows.
435
+ *
436
+ * Operator-admin-only: this endpoint requires the bearer token.
437
+ *
438
+ * Op-discriminated input: `{op: "create" | "fork" | "get" |
439
+ * "list" | "retire", ...}`. Note that ScheduleDef has 5 ops
440
+ * (no separate `promote` — forks auto-promote by default per
441
+ * RFC E's worked example; no `verify` — no content_sha256 in
442
+ * v1.x).
443
+ *
444
+ * Sharp edges (substrate refuses these):
445
+ * - Name colliding with a static cfg.ScheduledRuns entry is
446
+ * refused on `create` (yaml is ground truth; use `fork` to
447
+ * derive a new version).
448
+ * - Fork against a template with `required_credentials` must
449
+ * supply all keys in `user_credentials` — loud-fail at fork
450
+ * time rather than silent ingestion-time failure when the
451
+ * sweeper fires.
452
+ * - Cron syntax is validated server-side; invalid expressions
453
+ * refuse with a parse error.
454
+ *
455
+ * Raises {@link SubstrateToolRefusedError} on tool-level refusals
456
+ * (static-name collision, missing required credential, invalid
457
+ * cron, etc.); {@link InvalidArgumentError} on 400 (malformed
458
+ * JSON); {@link AuthError} on 401. */
459
+ async scheduleDef(input, opts) {
460
+ return postJSON(this.ctx, "/v1/_scheduledef", input, opts);
461
+ }
422
462
  // ---- v0.10.3 Library v2 enumeration (read-only, merged yaml+substrate) ----
423
463
  /** List every agent the runtime knows about — yaml-static + dynamic
424
464
  * AgentDefs merged into one envelope per name. Each entry carries
package/dist/index.d.ts CHANGED
@@ -42,9 +42,11 @@
42
42
  * listRunInterrupts(runId, opts?): Promise<InterruptListResponse>
43
43
  * resolveInterrupt(runId, interruptId, opts): Promise<unknown>
44
44
  *
45
- * // Substrate admin (v0.8.22)
45
+ * // Substrate admin (v0.8.22; mcpServerDef v0.9.x; scheduleDef v1.x)
46
46
  * agentDef(input): Promise<SubstrateToolResponse>
47
47
  * skillDef(input): Promise<SubstrateToolResponse>
48
+ * mcpServerDef(input): Promise<SubstrateToolResponse>
49
+ * scheduleDef(input): Promise<SubstrateToolResponse>
48
50
  *
49
51
  * // Library v2 enumeration (v0.10.3 — yaml+substrate merged)
50
52
  * listLibraryAgents(): Promise<LibraryListResponse<LibraryAgentDefinition>>
@@ -76,5 +78,5 @@
76
78
  * See `adapters/ts/README.md` for usage examples.
77
79
  */
78
80
  export { LoomcycleClient } from "./client.js";
79
- export type { AgentEvent, ClientOptions, ContinueOptions, EventType, HostWidening, PromptContent, PromptSegment, RetryInfo, RunOptions, ToolUse, Usage, Agent, AgentStatus, AgentUsage, CancelAgentResult, ListAgentsResponse, TranscriptEvent, TranscriptResponse, HealthResponse, ListUsersResponse, UserSummary, PauseResult, ResumeResult, RuntimeStateResponse, RuntimeStateStatus, CreateSnapshotOptions, SnapshotCreateResponse, SnapshotDescriptor, SnapshotEnvelope, SnapshotListResponse, SnapshotRestoreResponse, MemoryEntriesResponse, MemoryEntry, MemoryEntryResponse, MemoryScopeIDsResponse, MemoryScopeIDSummary, MemoryScopeKind, MemoryScopesResponse, InterruptListResponse, InterruptRow, InterruptStatus, ResolveInterruptOptions, Hook, HookFailMode, HookPhase, HookToolCall, HookToolResult, ListHooksResponse, PostHookCall, PostHookResult, PreHookCall, PreHookResult, RegisterHookOptions, RegisterHookResponse, SubstrateToolInput, SubstrateToolResponse, SystemPromptPayload, UserInputPayload, ChannelDescriptor, ListChannelsResponse, RunStateEvent, RunStateStreamClose, RunStateStreamItem, RunStateStreamOpen, StreamUserRunStatesOptions, AckChannelOptions, ChannelAckResult, ChannelMessageItem, ChannelPeekResult, ChannelPublishResult, ChannelScope, ChannelSubscribeResult, PeekChannelOptions, PublishChannelOptions, SubscribeChannelOptions, CreateChannelOptions, UpdateChannelOptions, SetMemoryEntryOptions, SetMemoryEntryResponse, AgentDefRowResponse, AgentDefVerifyResult, SkillDefVerifyResult, MCPServerDefRowResponse, MCPServerDefVerifyResult, LibraryAgentDefinition, LibraryEntry, LibraryListResponse, LibraryMcpServerDefinition, LibrarySkillDefinition, LLMChatContent, LLMChatMessage, LLMChatOptions, LLMChatResponse, LLMChatStreamDelta, LLMChatStreamItem, LLMChatToolCall, LLMChatUsage, LLMTool, LLMEmbeddingItem, LLMEmbeddingsOptions, LLMEmbeddingsResponse, LLMEmbeddingsUsage, } from "./types.js";
81
+ export type { AgentEvent, ClientOptions, ContinueOptions, EventType, HostWidening, ParentContext, PromptContent, PromptSegment, RetryInfo, RunOptions, ToolUse, Usage, Agent, AgentStatus, AgentUsage, CancelAgentResult, ListAgentsResponse, TranscriptEvent, TranscriptResponse, HealthResponse, ListUsersResponse, UserSummary, PauseResult, ResumeResult, RuntimeStateResponse, RuntimeStateStatus, CreateSnapshotOptions, SnapshotCreateResponse, SnapshotDescriptor, SnapshotEnvelope, SnapshotListResponse, SnapshotRestoreResponse, MemoryEntriesResponse, MemoryEntry, MemoryEntryResponse, MemoryScopeIDsResponse, MemoryScopeIDSummary, MemoryScopeKind, MemoryScopesResponse, InterruptListResponse, InterruptRow, InterruptStatus, ResolveInterruptOptions, Hook, HookFailMode, HookPhase, HookToolCall, HookToolResult, ListHooksResponse, PostHookCall, PostHookResult, PreHookCall, PreHookResult, RegisterHookOptions, RegisterHookResponse, SubstrateToolInput, SubstrateToolResponse, SystemPromptPayload, UserInputPayload, ChannelDescriptor, ListChannelsResponse, RunStateEvent, RunStateStreamClose, RunStateStreamItem, RunStateStreamOpen, StreamUserRunStatesOptions, AckChannelOptions, ChannelAckResult, ChannelMessageItem, ChannelPeekResult, ChannelPublishResult, ChannelScope, ChannelSubscribeResult, PeekChannelOptions, PublishChannelOptions, SubscribeChannelOptions, CreateChannelOptions, UpdateChannelOptions, SetMemoryEntryOptions, SetMemoryEntryResponse, AgentDefRowResponse, AgentDefVerifyResult, SkillDefVerifyResult, MCPServerDefRowResponse, MCPServerDefVerifyResult, LibraryAgentDefinition, LibraryEntry, LibraryListResponse, LibraryMcpServerDefinition, LibrarySkillDefinition, LLMChatContent, LLMChatMessage, LLMChatOptions, LLMChatResponse, LLMChatStreamDelta, LLMChatStreamItem, LLMChatToolCall, LLMChatUsage, LLMTool, LLMEmbeddingItem, LLMEmbeddingsOptions, LLMEmbeddingsResponse, LLMEmbeddingsUsage, } from "./types.js";
80
82
  export { AgentIDInUseError, AgentNotFoundError, AlreadyPausingError, AuthError, BackpressureError, HookNotFoundError, NotFoundError, InvalidArgumentError, ChannelCursorRegressionError, LoomcycleError, NotPausedError, PauseNotConfiguredError, PerUserQuotaExhaustedError, SessionBusyError, SessionNotFoundError, SnapshotNotFoundError, SnapshotTooLargeError, SnapshotVersionError, SubstrateToolRefusedError, UnavailableError, } from "./errors.js";
package/dist/index.js CHANGED
@@ -42,9 +42,11 @@
42
42
  * listRunInterrupts(runId, opts?): Promise<InterruptListResponse>
43
43
  * resolveInterrupt(runId, interruptId, opts): Promise<unknown>
44
44
  *
45
- * // Substrate admin (v0.8.22)
45
+ * // Substrate admin (v0.8.22; mcpServerDef v0.9.x; scheduleDef v1.x)
46
46
  * agentDef(input): Promise<SubstrateToolResponse>
47
47
  * skillDef(input): Promise<SubstrateToolResponse>
48
+ * mcpServerDef(input): Promise<SubstrateToolResponse>
49
+ * scheduleDef(input): Promise<SubstrateToolResponse>
48
50
  *
49
51
  * // Library v2 enumeration (v0.10.3 — yaml+substrate merged)
50
52
  * listLibraryAgents(): Promise<LibraryListResponse<LibraryAgentDefinition>>
package/dist/types.d.ts CHANGED
@@ -69,6 +69,7 @@ export interface AgentEvent {
69
69
  run_id?: string;
70
70
  session_id?: string;
71
71
  parent_agent_id?: string | null;
72
+ parent_context?: ParentContext;
72
73
  meta_subtype?: "stream_open" | "stream_close";
73
74
  meta_reason?: string;
74
75
  }
@@ -130,6 +131,23 @@ export interface RunOptions {
130
131
  * (static-bearer setups unaffected). Sub-agents inherit identically.
131
132
  * Never persisted; never logged in full. */
132
133
  userBearer?: string;
134
+ /** Per-tool named credentials map (v1.x RFC F). Per-MCP-server bearers
135
+ * keyed by operator-chosen name (convention: the `mcp_servers.<name>`
136
+ * yaml key). Substituted into MCP HTTP header values containing
137
+ * `${run.credentials.<name>}` at outbound request-build time. Keys
138
+ * match `[a-zA-Z0-9_-]{1,64}`; values arbitrary strings. Sub-agents
139
+ * inherit the whole map. Coexists with `userBearer` — the legacy
140
+ * field auto-promotes to `userCredentials.default` for back-compat
141
+ * with v0.8.x flows. Never persisted; never logged. */
142
+ userCredentials?: Record<string, string>;
143
+ /** Opaque caller-tracking lineage (v0.12.x). Carried verbatim by the
144
+ * runtime, inherited UNCHANGED by every sub-agent the Agent tool
145
+ * spawns, persisted on each run row, and echoed back on the per-agent
146
+ * report surfaces (agent status, run-state stream, the `event: agent`
147
+ * frame) — so you can attribute a child sub-agent's usage to the
148
+ * user-initiated request that spawned the whole tree. Not a secret.
149
+ * Omitted = no tracking context. */
150
+ parentContext?: ParentContext;
133
151
  /** Opt-in observability: when true, the iterator emits client-
134
152
  * synthesized `{ type: "_meta", meta_subtype: "stream_open" | "stream_close" }`
135
153
  * events around the real event stream. `meta_reason` carries the
@@ -140,6 +158,20 @@ export interface RunOptions {
140
158
  debug?: boolean;
141
159
  signal?: AbortSignal;
142
160
  }
161
+ /** Opaque caller-tracking lineage (v0.12.x) attached to a run and
162
+ * propagated to all its sub-agents. The runtime stores and echoes
163
+ * these fields verbatim and never interprets them. All fields
164
+ * optional; an all-empty object is treated as absent. */
165
+ export interface ParentContext {
166
+ /** The consumer's identifier for the user-initiated run at the root of
167
+ * the spawn tree — echoed on every descendant. */
168
+ root_agent_run_id?: string;
169
+ /** The consumer's logical-operation key for the root request. */
170
+ function_key?: string;
171
+ /** The consumer's tier marker captured at root-run time (distinct from
172
+ * `userTier`, which is loomcycle's resolver policy). */
173
+ tier_at_run?: string;
174
+ }
143
175
  export interface ContinueOptions {
144
176
  /** Required — the session to continue. */
145
177
  sessionId: string;
@@ -166,6 +198,14 @@ export interface ContinueOptions {
166
198
  * so different continuations in the same session may carry
167
199
  * different end-user tokens. */
168
200
  userBearer?: string;
201
+ /** Per-tool named credentials map (v1.x RFC F). See
202
+ * {@link RunOptions.userCredentials} for the full shape — same
203
+ * semantics, supplied per-continuation rather than per-fresh-run. */
204
+ userCredentials?: Record<string, string>;
205
+ /** Opaque caller-tracking lineage (v0.12.x). See
206
+ * {@link RunOptions.parentContext} — same shape; a continuation may
207
+ * (re)set the lineage for the new run it creates. */
208
+ parentContext?: ParentContext;
169
209
  /** Opt-in observability: see {@link RunOptions.debug}. Same shape. */
170
210
  debug?: boolean;
171
211
  signal?: AbortSignal;
@@ -192,6 +232,7 @@ export interface AgentUsage {
192
232
  cache_creation_tokens?: number;
193
233
  cache_read_tokens?: number;
194
234
  model?: string;
235
+ provider?: string;
195
236
  }
196
237
  export interface Agent {
197
238
  agent_id: string;
@@ -208,6 +249,11 @@ export interface Agent {
208
249
  usage: AgentUsage;
209
250
  last_heartbeat_at: string | null;
210
251
  live: boolean;
252
+ /** Opaque caller-tracking lineage this run carries (inherited from its
253
+ * root for sub-agents), v0.12.x. Echoed here alongside `usage` so you
254
+ * can attribute a child sub-agent's cost to the user-initiated request
255
+ * in a single fetch. Omitted when the run carried no context. */
256
+ parent_context?: ParentContext;
211
257
  }
212
258
  export interface ListAgentsResponse {
213
259
  agents: Agent[];
@@ -730,6 +776,10 @@ export interface RunStateEvent {
730
776
  stop_reason?: string;
731
777
  error?: string;
732
778
  ts: string;
779
+ /** Opaque caller-tracking lineage echoed on the transition (v0.12.x),
780
+ * so a subscriber learns which root request a finishing sub-agent
781
+ * belongs to. Omitted when the run carried no context. */
782
+ parent_context?: ParentContext;
733
783
  }
734
784
  /** Initial stream_open frame emitted before the first run_state. */
735
785
  export interface RunStateStreamOpen {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loomcycle/client",
3
- "version": "0.11.5",
3
+ "version": "0.12.8",
4
4
  "description": "TypeScript client for the loomcycle sidecar (HTTP+SSE). 46 methods covering run streaming, agent metadata, pause/resume/state, 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).",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",