@loomcycle/client 0.18.0 → 0.21.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.
@@ -93,6 +93,10 @@ class LoomcycleClient {
93
93
  body.user_credentials = opts.userCredentials;
94
94
  if (opts.parentContext !== undefined)
95
95
  body.parent_context = opts.parentContext;
96
+ if (opts.metadata !== undefined)
97
+ body.metadata = opts.metadata;
98
+ if (opts.runTimeoutSeconds !== undefined)
99
+ body.run_timeout_seconds = opts.runTimeoutSeconds;
96
100
  yield* this.streamSSE("/v1/runs", body, opts.signal, opts.debug);
97
101
  }
98
102
  /**
@@ -133,6 +137,10 @@ class LoomcycleClient {
133
137
  body.user_credentials = opts.userCredentials;
134
138
  if (opts.parentContext !== undefined)
135
139
  body.parent_context = opts.parentContext;
140
+ if (opts.metadata !== undefined)
141
+ body.metadata = opts.metadata;
142
+ if (opts.runTimeoutSeconds !== undefined)
143
+ body.run_timeout_seconds = opts.runTimeoutSeconds;
136
144
  yield* this.streamSSE(`/v1/sessions/${encodeURIComponent(opts.sessionId)}/messages`, body, opts.signal, opts.debug);
137
145
  }
138
146
  // ---- Agent metadata ----
@@ -418,6 +426,41 @@ class LoomcycleClient {
418
426
  async agentDef(input, opts) {
419
427
  return (0, fetch_helpers_js_1.postJSON)(this.ctx, "/v1/_agentdef", input, opts);
420
428
  }
429
+ /** Register (or refresh) a code-js agent idempotently from an INLINE JS body
430
+ * — the typed "ship a code agent with no host filesystem" convenience
431
+ * (RFC J), mirror of {@link LoomcycleClient.ensureMcpServer}.
432
+ *
433
+ * Runs `agentDef({op:"create", overlay:{provider:"code-js", code_body, …}})`,
434
+ * which is content-addressed-idempotent in loomcycle: a byte-identical
435
+ * re-registration is a no-op (`changed:false`), not a new version. This is
436
+ * what makes code agents work across container boundaries / pure-cloud —
437
+ * the JS no longer has to exist at `agent_code/<name>/index.js` on the
438
+ * sidecar's disk.
439
+ *
440
+ * Requires `LOOMCYCLE_CODE_AGENTS_ENABLED=1` on the sidecar — the same
441
+ * switch that registers the code-js provider. Without it the create is
442
+ * refused (raises {@link SubstrateToolRefusedError}). Keep `${run.*}` /
443
+ * `${LOOMCYCLE_*}` placeholders in the body LITERAL so the content stays
444
+ * stable and dedup engages on re-register. */
445
+ async ensureCodeAgent(opts, callOpts) {
446
+ const overlay = { provider: "code-js", code_body: opts.code };
447
+ if (opts.allowedTools)
448
+ overlay.allowed_tools = opts.allowedTools;
449
+ if (opts.tier)
450
+ overlay.tier = opts.tier;
451
+ if (opts.model)
452
+ overlay.model = opts.model;
453
+ const input = { op: "create", name: opts.name, overlay };
454
+ if (opts.description)
455
+ input.description = opts.description;
456
+ const row = (await this.agentDef(input, callOpts));
457
+ return {
458
+ name: opts.name,
459
+ defId: row.def_id,
460
+ version: row.version,
461
+ changed: row.deduplicated !== true,
462
+ };
463
+ }
421
464
  /** Invoke the SkillDef substrate tool over HTTP. Mirror of
422
465
  * {@link LoomcycleClient.agentDef} for skills (v0.8.22+). Same
423
466
  * input grammar, same error class on refusal. See the
@@ -466,15 +509,21 @@ class LoomcycleClient {
466
509
  * "register-if-changed" convenience for a consumer that re-registers its
467
510
  * own callback server on every startup.
468
511
  *
469
- * Runs `create` (which is content-addressed-idempotent in loomcycle
470
- * ≥ v0.18.0 — a byte-identical re-registration is a no-op, not a new
471
- * version) and, when {@link EnsureMcpServerOptions.rediscover} is set, a
472
- * `tools/list` rediscover (also idempotent on unchanged tools). The
473
- * returned {@link EnsureMcpServerResult.changed} is false when loomcycle
474
- * deduped both — so a stable-content re-register on every boot is a clean
475
- * no-op. Keep `${run.*}` / `${LOOMCYCLE_*}` header placeholders LITERAL
476
- * (don't resolve a per-restart token) or the content varies each boot and
477
- * dedup can't engage. */
512
+ * Runs `create`, which is content-addressed-idempotent (a byte-identical
513
+ * re-registration is a no-op, not a new version) AND auto-discovers the
514
+ * upstream's tools at ingestion — so {@link EnsureMcpServerResult.changed}
515
+ * is false on a stable-content re-register, and
516
+ * {@link EnsureMcpServerResult.discoveredToolCount} is populated straight
517
+ * from the `create` (no separate rediscover needed for the count). On a
518
+ * deduplicated re-register the count is absent (the tool surface was
519
+ * unchanged), so it reflects only the freshly-discovered case.
520
+ *
521
+ * Pass {@link EnsureMcpServerOptions.rediscover} only to FORCE a refresh
522
+ * when the upstream's tools changed but the registration content didn't.
523
+ *
524
+ * Keep `${run.*}` / `${LOOMCYCLE_*}` header placeholders LITERAL (don't
525
+ * resolve a per-restart token) or the content varies each boot and dedup
526
+ * can't engage. */
478
527
  async ensureMcpServer(opts, callOpts) {
479
528
  const overlay = {
480
529
  transport: opts.transport ?? "http",
@@ -488,13 +537,15 @@ class LoomcycleClient {
488
537
  const created = (await this.mcpServerDef(createInput, callOpts));
489
538
  let row = created;
490
539
  let changed = created.deduplicated !== true;
491
- let discoveredToolCount;
540
+ // create auto-discovers at ingestion → the count is on the create response.
541
+ let discoveredToolCount = created.discovered;
492
542
  if (opts.rediscover) {
493
543
  const red = (await this.mcpServerDef({ op: "rediscover", name: opts.name }, callOpts));
494
544
  row = red;
495
545
  if (red.deduplicated !== true)
496
546
  changed = true;
497
- discoveredToolCount = red.discovered;
547
+ if (red.discovered !== undefined)
548
+ discoveredToolCount = red.discovered;
498
549
  }
499
550
  const result = {
500
551
  name: opts.name,
package/dist/client.d.ts CHANGED
@@ -23,7 +23,7 @@
23
23
  * via fetch-helpers.ts:raiseFromResponse — see README.md for the
24
24
  * full mapping table.
25
25
  */
26
- import type { Agent, AgentEvent, AgentStatus, CancelAgentResult, ClientOptions, ContinueOptions, CreateSnapshotOptions, EnsureMcpServerOptions, EnsureMcpServerResult, HealthResponse, Hook, InterruptListResponse, InterruptStatus, AckChannelOptions, ChannelAckResult, ChannelDescriptor, ChannelPeekResult, ChannelPublishResult, ChannelSubscribeResult, CreateChannelOptions, ListChannelsResponse, PeekChannelOptions, PublishChannelOptions, SetMemoryEntryOptions, SetMemoryEntryResponse, SubscribeChannelOptions, UpdateChannelOptions, LibraryAgentDefinition, LibraryListResponse, LibraryMcpServerDefinition, LibrarySkillDefinition, ListUsersResponse, LLMChatOptions, LLMChatResponse, LLMChatStreamItem, LLMEmbeddingsOptions, LLMEmbeddingsResponse, MCPServerDefVerifyResult, MemoryEntriesResponse, MemoryEntryResponse, MemoryScopeIDsResponse, MemoryScopesResponse, PauseResult, RegisterHookOptions, RegisterHookResponse, ResolveInterruptOptions, ResumeResult, ResolverMatrix, RunOptions, RunStateStreamItem, RuntimeStateResponse, SnapshotCreateResponse, SnapshotDescriptor, SnapshotEnvelope, SnapshotRestoreResponse, StreamUserRunStatesOptions, SubstrateToolInput, SubstrateToolResponse, TranscriptResponse, WhoamiResponse } from "./types.js";
26
+ import type { Agent, AgentEvent, AgentStatus, CancelAgentResult, ClientOptions, ContinueOptions, CreateSnapshotOptions, EnsureCodeAgentOptions, EnsureCodeAgentResult, EnsureMcpServerOptions, EnsureMcpServerResult, HealthResponse, Hook, InterruptListResponse, InterruptStatus, AckChannelOptions, ChannelAckResult, ChannelDescriptor, ChannelPeekResult, ChannelPublishResult, ChannelSubscribeResult, CreateChannelOptions, ListChannelsResponse, PeekChannelOptions, PublishChannelOptions, SetMemoryEntryOptions, SetMemoryEntryResponse, SubscribeChannelOptions, UpdateChannelOptions, LibraryAgentDefinition, LibraryListResponse, LibraryMcpServerDefinition, LibrarySkillDefinition, ListUsersResponse, LLMChatOptions, LLMChatResponse, LLMChatStreamItem, LLMEmbeddingsOptions, LLMEmbeddingsResponse, MCPServerDefVerifyResult, MemoryEntriesResponse, MemoryEntryResponse, MemoryScopeIDsResponse, MemoryScopesResponse, PauseResult, RegisterHookOptions, RegisterHookResponse, ResolveInterruptOptions, ResumeResult, ResolverMatrix, RunOptions, RunStateStreamItem, RuntimeStateResponse, SnapshotCreateResponse, SnapshotDescriptor, SnapshotEnvelope, SnapshotRestoreResponse, StreamUserRunStatesOptions, SubstrateToolInput, SubstrateToolResponse, TranscriptResponse, WhoamiResponse } from "./types.js";
27
27
  export declare class LoomcycleClient {
28
28
  private ctx;
29
29
  constructor(opts?: ClientOptions);
@@ -275,6 +275,25 @@ export declare class LoomcycleClient {
275
275
  agentDef(input: SubstrateToolInput, opts?: {
276
276
  signal?: AbortSignal;
277
277
  }): Promise<SubstrateToolResponse>;
278
+ /** Register (or refresh) a code-js agent idempotently from an INLINE JS body
279
+ * — the typed "ship a code agent with no host filesystem" convenience
280
+ * (RFC J), mirror of {@link LoomcycleClient.ensureMcpServer}.
281
+ *
282
+ * Runs `agentDef({op:"create", overlay:{provider:"code-js", code_body, …}})`,
283
+ * which is content-addressed-idempotent in loomcycle: a byte-identical
284
+ * re-registration is a no-op (`changed:false`), not a new version. This is
285
+ * what makes code agents work across container boundaries / pure-cloud —
286
+ * the JS no longer has to exist at `agent_code/<name>/index.js` on the
287
+ * sidecar's disk.
288
+ *
289
+ * Requires `LOOMCYCLE_CODE_AGENTS_ENABLED=1` on the sidecar — the same
290
+ * switch that registers the code-js provider. Without it the create is
291
+ * refused (raises {@link SubstrateToolRefusedError}). Keep `${run.*}` /
292
+ * `${LOOMCYCLE_*}` placeholders in the body LITERAL so the content stays
293
+ * stable and dedup engages on re-register. */
294
+ ensureCodeAgent(opts: EnsureCodeAgentOptions, callOpts?: {
295
+ signal?: AbortSignal;
296
+ }): Promise<EnsureCodeAgentResult>;
278
297
  /** Invoke the SkillDef substrate tool over HTTP. Mirror of
279
298
  * {@link LoomcycleClient.agentDef} for skills (v0.8.22+). Same
280
299
  * input grammar, same error class on refusal. See the
@@ -323,15 +342,21 @@ export declare class LoomcycleClient {
323
342
  * "register-if-changed" convenience for a consumer that re-registers its
324
343
  * own callback server on every startup.
325
344
  *
326
- * Runs `create` (which is content-addressed-idempotent in loomcycle
327
- * ≥ v0.18.0 — a byte-identical re-registration is a no-op, not a new
328
- * version) and, when {@link EnsureMcpServerOptions.rediscover} is set, a
329
- * `tools/list` rediscover (also idempotent on unchanged tools). The
330
- * returned {@link EnsureMcpServerResult.changed} is false when loomcycle
331
- * deduped both — so a stable-content re-register on every boot is a clean
332
- * no-op. Keep `${run.*}` / `${LOOMCYCLE_*}` header placeholders LITERAL
333
- * (don't resolve a per-restart token) or the content varies each boot and
334
- * dedup can't engage. */
345
+ * Runs `create`, which is content-addressed-idempotent (a byte-identical
346
+ * re-registration is a no-op, not a new version) AND auto-discovers the
347
+ * upstream's tools at ingestion — so {@link EnsureMcpServerResult.changed}
348
+ * is false on a stable-content re-register, and
349
+ * {@link EnsureMcpServerResult.discoveredToolCount} is populated straight
350
+ * from the `create` (no separate rediscover needed for the count). On a
351
+ * deduplicated re-register the count is absent (the tool surface was
352
+ * unchanged), so it reflects only the freshly-discovered case.
353
+ *
354
+ * Pass {@link EnsureMcpServerOptions.rediscover} only to FORCE a refresh
355
+ * when the upstream's tools changed but the registration content didn't.
356
+ *
357
+ * Keep `${run.*}` / `${LOOMCYCLE_*}` header placeholders LITERAL (don't
358
+ * resolve a per-restart token) or the content varies each boot and dedup
359
+ * can't engage. */
335
360
  ensureMcpServer(opts: EnsureMcpServerOptions, callOpts?: {
336
361
  signal?: AbortSignal;
337
362
  }): Promise<EnsureMcpServerResult>;
package/dist/client.js CHANGED
@@ -90,6 +90,10 @@ export class LoomcycleClient {
90
90
  body.user_credentials = opts.userCredentials;
91
91
  if (opts.parentContext !== undefined)
92
92
  body.parent_context = opts.parentContext;
93
+ if (opts.metadata !== undefined)
94
+ body.metadata = opts.metadata;
95
+ if (opts.runTimeoutSeconds !== undefined)
96
+ body.run_timeout_seconds = opts.runTimeoutSeconds;
93
97
  yield* this.streamSSE("/v1/runs", body, opts.signal, opts.debug);
94
98
  }
95
99
  /**
@@ -130,6 +134,10 @@ export class LoomcycleClient {
130
134
  body.user_credentials = opts.userCredentials;
131
135
  if (opts.parentContext !== undefined)
132
136
  body.parent_context = opts.parentContext;
137
+ if (opts.metadata !== undefined)
138
+ body.metadata = opts.metadata;
139
+ if (opts.runTimeoutSeconds !== undefined)
140
+ body.run_timeout_seconds = opts.runTimeoutSeconds;
133
141
  yield* this.streamSSE(`/v1/sessions/${encodeURIComponent(opts.sessionId)}/messages`, body, opts.signal, opts.debug);
134
142
  }
135
143
  // ---- Agent metadata ----
@@ -415,6 +423,41 @@ export class LoomcycleClient {
415
423
  async agentDef(input, opts) {
416
424
  return postJSON(this.ctx, "/v1/_agentdef", input, opts);
417
425
  }
426
+ /** Register (or refresh) a code-js agent idempotently from an INLINE JS body
427
+ * — the typed "ship a code agent with no host filesystem" convenience
428
+ * (RFC J), mirror of {@link LoomcycleClient.ensureMcpServer}.
429
+ *
430
+ * Runs `agentDef({op:"create", overlay:{provider:"code-js", code_body, …}})`,
431
+ * which is content-addressed-idempotent in loomcycle: a byte-identical
432
+ * re-registration is a no-op (`changed:false`), not a new version. This is
433
+ * what makes code agents work across container boundaries / pure-cloud —
434
+ * the JS no longer has to exist at `agent_code/<name>/index.js` on the
435
+ * sidecar's disk.
436
+ *
437
+ * Requires `LOOMCYCLE_CODE_AGENTS_ENABLED=1` on the sidecar — the same
438
+ * switch that registers the code-js provider. Without it the create is
439
+ * refused (raises {@link SubstrateToolRefusedError}). Keep `${run.*}` /
440
+ * `${LOOMCYCLE_*}` placeholders in the body LITERAL so the content stays
441
+ * stable and dedup engages on re-register. */
442
+ async ensureCodeAgent(opts, callOpts) {
443
+ const overlay = { provider: "code-js", code_body: opts.code };
444
+ if (opts.allowedTools)
445
+ overlay.allowed_tools = opts.allowedTools;
446
+ if (opts.tier)
447
+ overlay.tier = opts.tier;
448
+ if (opts.model)
449
+ overlay.model = opts.model;
450
+ const input = { op: "create", name: opts.name, overlay };
451
+ if (opts.description)
452
+ input.description = opts.description;
453
+ const row = (await this.agentDef(input, callOpts));
454
+ return {
455
+ name: opts.name,
456
+ defId: row.def_id,
457
+ version: row.version,
458
+ changed: row.deduplicated !== true,
459
+ };
460
+ }
418
461
  /** Invoke the SkillDef substrate tool over HTTP. Mirror of
419
462
  * {@link LoomcycleClient.agentDef} for skills (v0.8.22+). Same
420
463
  * input grammar, same error class on refusal. See the
@@ -463,15 +506,21 @@ export class LoomcycleClient {
463
506
  * "register-if-changed" convenience for a consumer that re-registers its
464
507
  * own callback server on every startup.
465
508
  *
466
- * Runs `create` (which is content-addressed-idempotent in loomcycle
467
- * ≥ v0.18.0 — a byte-identical re-registration is a no-op, not a new
468
- * version) and, when {@link EnsureMcpServerOptions.rediscover} is set, a
469
- * `tools/list` rediscover (also idempotent on unchanged tools). The
470
- * returned {@link EnsureMcpServerResult.changed} is false when loomcycle
471
- * deduped both — so a stable-content re-register on every boot is a clean
472
- * no-op. Keep `${run.*}` / `${LOOMCYCLE_*}` header placeholders LITERAL
473
- * (don't resolve a per-restart token) or the content varies each boot and
474
- * dedup can't engage. */
509
+ * Runs `create`, which is content-addressed-idempotent (a byte-identical
510
+ * re-registration is a no-op, not a new version) AND auto-discovers the
511
+ * upstream's tools at ingestion — so {@link EnsureMcpServerResult.changed}
512
+ * is false on a stable-content re-register, and
513
+ * {@link EnsureMcpServerResult.discoveredToolCount} is populated straight
514
+ * from the `create` (no separate rediscover needed for the count). On a
515
+ * deduplicated re-register the count is absent (the tool surface was
516
+ * unchanged), so it reflects only the freshly-discovered case.
517
+ *
518
+ * Pass {@link EnsureMcpServerOptions.rediscover} only to FORCE a refresh
519
+ * when the upstream's tools changed but the registration content didn't.
520
+ *
521
+ * Keep `${run.*}` / `${LOOMCYCLE_*}` header placeholders LITERAL (don't
522
+ * resolve a per-restart token) or the content varies each boot and dedup
523
+ * can't engage. */
475
524
  async ensureMcpServer(opts, callOpts) {
476
525
  const overlay = {
477
526
  transport: opts.transport ?? "http",
@@ -485,13 +534,15 @@ export class LoomcycleClient {
485
534
  const created = (await this.mcpServerDef(createInput, callOpts));
486
535
  let row = created;
487
536
  let changed = created.deduplicated !== true;
488
- let discoveredToolCount;
537
+ // create auto-discovers at ingestion → the count is on the create response.
538
+ let discoveredToolCount = created.discovered;
489
539
  if (opts.rediscover) {
490
540
  const red = (await this.mcpServerDef({ op: "rediscover", name: opts.name }, callOpts));
491
541
  row = red;
492
542
  if (red.deduplicated !== true)
493
543
  changed = true;
494
- discoveredToolCount = red.discovered;
544
+ if (red.discovered !== undefined)
545
+ discoveredToolCount = red.discovered;
495
546
  }
496
547
  const result = {
497
548
  name: opts.name,
package/dist/index.d.ts CHANGED
@@ -82,5 +82,5 @@
82
82
  * See `adapters/ts/README.md` for usage examples.
83
83
  */
84
84
  export { LoomcycleClient } from "./client.js";
85
- export type { AgentEvent, ClientOptions, ContinueOptions, EventType, HostWidening, ParentContext, PromptContent, PromptSegment, RetryInfo, RunOptions, ToolUse, Usage, Agent, AgentStatus, AgentUsage, CancelAgentResult, ListAgentsResponse, TranscriptEvent, TranscriptResponse, HealthResponse, ListUsersResponse, UserSummary, WhoamiResponse, PauseResult, ResumeResult, RuntimeStateResponse, RuntimeStateStatus, ResolverMatrix, ResolverModelStatus, ResolverProviderAvailability, 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, EnsureMcpServerOptions, EnsureMcpServerResult, MCPServerDefRowResponse, MCPServerDefVerifyResult, LibraryAgentDefinition, LibraryEntry, LibraryListResponse, LibraryMcpServerDefinition, LibrarySkillDefinition, LLMChatContent, LLMChatMessage, LLMChatOptions, LLMChatResponse, LLMChatStreamDelta, LLMChatStreamItem, LLMChatToolCall, LLMChatUsage, LLMTool, LLMEmbeddingItem, LLMEmbeddingsOptions, LLMEmbeddingsResponse, LLMEmbeddingsUsage, } from "./types.js";
85
+ export type { AgentEvent, ClientOptions, ContinueOptions, EventType, HostWidening, ParentContext, PromptContent, PromptSegment, RetryInfo, RunOptions, ToolUse, Usage, Agent, AgentStatus, AgentUsage, CancelAgentResult, ListAgentsResponse, TranscriptEvent, TranscriptResponse, HealthResponse, ListUsersResponse, UserSummary, WhoamiResponse, PauseResult, ResumeResult, RuntimeStateResponse, RuntimeStateStatus, ResolverMatrix, ResolverModelStatus, ResolverProviderAvailability, 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, EnsureMcpServerOptions, EnsureMcpServerResult, MCPServerDefRowResponse, MCPServerDefVerifyResult, AgentDefOverlay, EnsureCodeAgentOptions, EnsureCodeAgentResult, LibraryAgentDefinition, LibraryEntry, LibraryListResponse, LibraryMcpServerDefinition, LibrarySkillDefinition, LLMChatContent, LLMChatMessage, LLMChatOptions, LLMChatResponse, LLMChatStreamDelta, LLMChatStreamItem, LLMChatToolCall, LLMChatUsage, LLMTool, LLMEmbeddingItem, LLMEmbeddingsOptions, LLMEmbeddingsResponse, LLMEmbeddingsUsage, } from "./types.js";
86
86
  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/types.d.ts CHANGED
@@ -148,6 +148,21 @@ export interface RunOptions {
148
148
  * user-initiated request that spawned the whole tree. Not a secret.
149
149
  * Omitted = no tracking context. */
150
150
  parentContext?: ParentContext;
151
+ /** Optional NON-SECRET structured metadata passed to the agent (repo
152
+ * name, review policy, preferred skills, …) — symmetric with the
153
+ * WebHook/Schedule trigger paths. As a first-party (bearer-authed)
154
+ * caller this is TRUSTED: a code-js agent reads it as `input.metadata`;
155
+ * an LLM agent receives it as a trusted prompt block. NOT for secrets —
156
+ * use {@link RunOptions.userCredentials} for tokens. Per-call, not session
157
+ * state: a continuation does not inherit it — re-send on continue(). */
158
+ metadata?: Record<string, unknown>;
159
+ /** Optional ad-hoc per-run wall-clock budget (seconds) for a CODE-JS agent,
160
+ * overriding the agent's `run_timeout_seconds` and the sidecar's global
161
+ * default (precedence: per-run > per-agent > global). Use it for a fan-out
162
+ * orchestrator that blocks in Agent.parallel_spawn awaiting LLM children —
163
+ * its budget spans that wait, so the CPU-oriented default is often too low.
164
+ * Ignored by LLM agents. 0 / omitted = inherit. */
165
+ runTimeoutSeconds?: number;
151
166
  /** Opt-in observability: when true, the iterator emits client-
152
167
  * synthesized `{ type: "_meta", meta_subtype: "stream_open" | "stream_close" }`
153
168
  * events around the real event stream. `meta_reason` carries the
@@ -206,6 +221,14 @@ export interface ContinueOptions {
206
221
  * {@link RunOptions.parentContext} — same shape; a continuation may
207
222
  * (re)set the lineage for the new run it creates. */
208
223
  parentContext?: ParentContext;
224
+ /** Optional NON-SECRET structured metadata for the new run — see
225
+ * {@link RunOptions.metadata}. Same shape + trust posture. NOT inherited
226
+ * from the original run (metadata is a per-call input, not session state):
227
+ * re-send it on the continuation to carry it forward. */
228
+ metadata?: Record<string, unknown>;
229
+ /** Optional ad-hoc per-run code-js wall-clock budget (seconds) for the
230
+ * continuation's new run — see {@link RunOptions.runTimeoutSeconds}. */
231
+ runTimeoutSeconds?: number;
209
232
  /** Opt-in observability: see {@link RunOptions.debug}. Same shape. */
210
233
  debug?: boolean;
211
234
  signal?: AbortSignal;
@@ -886,6 +909,10 @@ export interface AgentDefRowResponse {
886
909
  /** Only populated on `set` / `fork` responses (was the new row
887
910
  * auto-promoted to active?). Absent on get/list. */
888
911
  promoted?: boolean;
912
+ /** True when create was a content-addressed no-op: the active def already
913
+ * carried identical content, so no new version was minted. Absent on a
914
+ * real mint. Drives {@link LoomcycleClient.ensureCodeAgent}'s `changed`. */
915
+ deduplicated?: boolean;
889
916
  }
890
917
  /** Response shape for `AgentDef verify`. Answers "is the supplied
891
918
  * content_sha256 the active deployed version of this name?"
@@ -943,7 +970,11 @@ export interface MCPServerDefRowResponse {
943
970
  * content (create) or identical discovered_tools (rediscover), so no
944
971
  * new version was minted. Absent (undefined) on a real mint. */
945
972
  deduplicated?: boolean;
946
- /** Only on `rediscover` responses — the number of tools discovered. */
973
+ /** Number of tools discovered via the upstream's `tools/list`. Present on
974
+ * `rediscover` responses and — since loomcycle auto-discovers at ingestion
975
+ * — on a fresh `create`/`fork` that ran the handshake. Absent on a
976
+ * deduplicated create (the active tool surface was unchanged) and when
977
+ * `discover:false` was passed. */
947
978
  discovered?: number;
948
979
  }
949
980
  /** Options for {@link LoomcycleClient.ensureMcpServer}. */
@@ -960,7 +991,14 @@ export interface EnsureMcpServerOptions {
960
991
  * loomcycle's idempotent create dedup the re-registration. */
961
992
  headers?: Record<string, string>;
962
993
  description?: string;
963
- /** Run a `tools/list` rediscover after registering. Default false. */
994
+ /** Force a `tools/list` refresh after registering. Default false.
995
+ *
996
+ * You usually do NOT need this: registration auto-discovers the upstream's
997
+ * tools at ingestion, so {@link EnsureMcpServerResult.discoveredToolCount}
998
+ * is already populated from the `create`. Set this only to force a re-read
999
+ * when the upstream's tool surface changed but the registration content
1000
+ * (url/headers) did not — a plain re-register would dedup and keep the
1001
+ * cached tools, whereas a rediscover re-runs the handshake. */
964
1002
  rediscover?: boolean;
965
1003
  }
966
1004
  /** Result of {@link LoomcycleClient.ensureMcpServer}. */
@@ -976,6 +1014,65 @@ export interface EnsureMcpServerResult {
976
1014
  /** Populated when `rediscover` ran: the number of tools discovered. */
977
1015
  discoveredToolCount?: number;
978
1016
  }
1017
+ /** Typed `overlay` for an {@link LoomcycleClient.agentDef} create/fork —
1018
+ * the mutable subset of an agent definition. All fields optional (a fork
1019
+ * overlays only what changes). The `[extra]` tail keeps it forward-compatible
1020
+ * with fields the in-process tool may accept that the adapter doesn't model
1021
+ * yet — the tool owns the authoritative schema; the adapter doesn't re-validate.
1022
+ *
1023
+ * `code_body` is the inline code-js orchestrator source (RFC J): set it (with
1024
+ * `provider: "code-js"`) to ingest a code agent through the substrate with NO
1025
+ * host filesystem bind — the symmetry that makes code agents work in
1026
+ * containers / pure-cloud. Requires `LOOMCYCLE_CODE_AGENTS_ENABLED=1` on the
1027
+ * sidecar; create/fork refuses a non-empty `code_body` otherwise. */
1028
+ export interface AgentDefOverlay {
1029
+ provider?: string;
1030
+ model?: string;
1031
+ /** Inline code-js source. Empty/absent ⇒ the provider falls back to
1032
+ * `agent_code/<name>/index.js`. Stored verbatim (whitespace is hash-
1033
+ * significant); participates in content_sha256. */
1034
+ code_body?: string;
1035
+ tier?: string;
1036
+ effort?: string;
1037
+ max_tokens?: number;
1038
+ max_iterations?: number;
1039
+ max_concurrent_children?: number;
1040
+ system_prompt?: string;
1041
+ allowed_tools?: string[];
1042
+ skills?: string[];
1043
+ memory_scopes?: string[];
1044
+ memory_quota_bytes?: number;
1045
+ memory_backend?: string;
1046
+ retry_attempts?: number;
1047
+ [extra: string]: unknown;
1048
+ }
1049
+ /** Options for {@link LoomcycleClient.ensureCodeAgent}. */
1050
+ export interface EnsureCodeAgentOptions {
1051
+ /** Agent name (substrate; must not collide with a static cfg.Agents name —
1052
+ * use a fork for those). */
1053
+ name: string;
1054
+ /** The inline code-js orchestrator source (the `function run(input){…}` body).
1055
+ * Keep any `${run.*}` / `${LOOMCYCLE_*}` placeholders LITERAL so the content
1056
+ * is stable across restarts — that's what lets loomcycle dedup the
1057
+ * re-registration. */
1058
+ code: string;
1059
+ /** The agent's allowed_tools ceiling (must be a subset of the caller's). */
1060
+ allowedTools?: string[];
1061
+ /** Per-user tier policy name (mutually exclusive with `model` in practice). */
1062
+ tier?: string;
1063
+ /** Pin a concrete model id (overrides tier resolution). */
1064
+ model?: string;
1065
+ description?: string;
1066
+ }
1067
+ /** Result of {@link LoomcycleClient.ensureCodeAgent}. */
1068
+ export interface EnsureCodeAgentResult {
1069
+ name: string;
1070
+ defId: string;
1071
+ version: number;
1072
+ /** True when this call minted a new version; false when loomcycle deduped
1073
+ * it (identical body + config already active). */
1074
+ changed: boolean;
1075
+ }
979
1076
  /** Response shape for `MCPServerDef verify`. Same semantics as
980
1077
  * AgentDefVerifyResult / SkillDefVerifyResult — answers "is the
981
1078
  * supplied content_sha256 the deployed active version of this name?" */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@loomcycle/client",
3
- "version": "0.18.0",
4
- "description": "TypeScript client for the loomcycle sidecar (HTTP+SSE). 51 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).",
3
+ "version": "0.21.0",
4
+ "description": "TypeScript client for the loomcycle sidecar (HTTP+SSE). 51 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.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
7
7
  "repository": {