@loomcycle/client 1.105.0 → 1.107.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.
package/dist/types.d.ts CHANGED
@@ -611,6 +611,9 @@ export interface AgentEvent {
611
611
  run_id?: string;
612
612
  session_id?: string;
613
613
  parent_agent_id?: string | null;
614
+ /** On the `agent` frame: the request's `idempotencyKey` was already held by
615
+ * a run, and this stream is that existing run's. */
616
+ deduplicated?: boolean;
614
617
  parent_context?: ParentContext;
615
618
  /** Payload on `context_compaction`. */
616
619
  context_compaction?: ContextCompactionInfo;
@@ -813,6 +816,22 @@ export interface RunOptions extends RunOverrideOptions {
813
816
  * user-initiated request that spawned the whole tree. Not a secret.
814
817
  * Omitted = no tracking context. */
815
818
  parentContext?: ParentContext;
819
+ /** Makes starting this run safe to retry: 1 to 200 characters of
820
+ * `[A-Za-z0-9:._-]`. A second request with the same key, from the same
821
+ * tenant and user, starts nothing. `runStreaming` then yields the existing
822
+ * run's stream — its `agent` frame carries `deduplicated: true` and its
823
+ * events follow from the first — and a `spawnRunBatch` child reports the
824
+ * existing run with `deduplicated: true`. The request body is not
825
+ * compared, so build the key from what makes the work distinct. A fresh
826
+ * run only: refused with `sessionId`. */
827
+ idempotencyKey?: string;
828
+ /** Bound how long the run may LIVE, in seconds (omitted or 0 = no bound; at
829
+ * most 30 days). Past it the run is cancelled, with what it started, and
830
+ * ends `cancelled` with `stop_reason: "wall_limit"`. Waits count; time the
831
+ * runtime is paused does not. It belongs to the run, not to the call, so it
832
+ * is the time bound for a `mode: "detach"` batch child, where `timeoutMs`
833
+ * is refused. Any agent, model-driven or code-js. */
834
+ maxWallSeconds?: number;
816
835
  /** Optional NON-SECRET structured metadata passed to the agent (repo
817
836
  * name, review policy, preferred skills, …) — symmetric with the
818
837
  * WebHook/Schedule trigger paths. As a first-party (bearer-authed)
@@ -1252,6 +1271,10 @@ export interface RunSpec {
1252
1271
  context?: Record<string, unknown>;
1253
1272
  max_context_tokens?: number;
1254
1273
  run_timeout_seconds?: number;
1274
+ /** The run's own lifetime limit, in seconds, when it was started with
1275
+ * `maxWallSeconds`: past it the run ends `cancelled` with
1276
+ * `stop_reason: "wall_limit"`. Absent when the run has no such limit. */
1277
+ max_wall_seconds?: number;
1255
1278
  review_ttl_seconds?: number;
1256
1279
  /** Which model serves the run: model / provider / tier / effort. */
1257
1280
  routing?: Record<string, unknown>;
@@ -1486,6 +1509,9 @@ export interface SpawnRunResult {
1486
1509
  final_text?: string;
1487
1510
  usage?: AgentUsage;
1488
1511
  error?: string;
1512
+ /** The child's `idempotencyKey` was already held by a run: the ids, status
1513
+ * and result are that run's, and this request started nothing. */
1514
+ deduplicated?: boolean;
1489
1515
  }
1490
1516
  /** Result of {@link LoomcycleClient.spawnRunBatch} — `results` is index-aligned
1491
1517
  * with the request's `spawns`. */
@@ -3353,6 +3379,16 @@ export interface MemoryRerank {
3353
3379
  /** Per-candidate character budget (200-20000). Default 1200. */
3354
3380
  max_chars?: number;
3355
3381
  }
3382
+ /** An agent's narrowing of the server's decision models (`decision`). It can
3383
+ * only narrow: every name must be one the server's `decision:` block lists. A
3384
+ * fork overlay that sets it replaces the parent's block whole. */
3385
+ export interface AgentDecision {
3386
+ /** The model that answers a Decision call naming none. One of `models` when
3387
+ * `models` is set. */
3388
+ default?: string;
3389
+ /** The models a Decision call may name. Empty = every model the server lists. */
3390
+ models?: string[];
3391
+ }
3356
3392
  export interface AgentDefOverlay {
3357
3393
  provider?: string;
3358
3394
  model?: string;
@@ -3407,6 +3443,9 @@ export interface AgentDefOverlay {
3407
3443
  * reports `reranked` (and `rerank_reason` when false); a failed or unavailable
3408
3444
  * rerank keeps the search's own order. */
3409
3445
  memory_rerank?: MemoryRerank;
3446
+ /** Which of the server's decision models this agent's `Decision` tool may ask,
3447
+ * and its default. Unset: all of them, and the server's default. */
3448
+ decision?: AgentDecision;
3410
3449
  /** `false` makes this agent's searches ignore Document derived search units — the
3411
3450
  * short descriptions, claims and questions an operator may generate for a
3412
3451
  * document so a question can match them. Unset uses them wherever they exist
@@ -3909,3 +3948,121 @@ export interface CredentialListResponse {
3909
3948
  scope: string;
3910
3949
  credentials: CredentialMeta[];
3911
3950
  }
3951
+ /** A `choice` question: pick one of the options. Each key of `criteria` is an
3952
+ * option and its value describes it, or is `null` when the key explains
3953
+ * itself. The key is what comes back as the answer. */
3954
+ export interface DecisionChoiceQuestion {
3955
+ type: "choice";
3956
+ /** The question itself, in plain words. */
3957
+ instructions: string;
3958
+ criteria: Record<string, string | null>;
3959
+ }
3960
+ /** A `noul` question: yes or no. `criteria` is optional: describe `true`
3961
+ * and/or `false` when the plain question is not enough. */
3962
+ export interface DecisionNoulQuestion {
3963
+ type: "noul";
3964
+ instructions: string;
3965
+ criteria?: {
3966
+ true?: string;
3967
+ false?: string;
3968
+ };
3969
+ }
3970
+ /** A `score` question: a position on a scale. `criteria` is the level
3971
+ * descriptions, LOWEST FIRST. */
3972
+ export interface DecisionScoreQuestion {
3973
+ type: "score";
3974
+ instructions: string;
3975
+ criteria: string[];
3976
+ }
3977
+ export type DecisionQuestion = DecisionChoiceQuestion | DecisionNoulQuestion | DecisionScoreQuestion;
3978
+ /** Body of {@link LoomcycleClient.decide}: every question is answered about the
3979
+ * same `state`. */
3980
+ export interface DecideRequest {
3981
+ /** Which decision model answers: a name from
3982
+ * {@link LoomcycleClient.listDecisionModels}. Omit for the default. */
3983
+ model?: string;
3984
+ /** What the questions are about. Any JSON object; the model reads only this,
3985
+ * and it is never shortened for you (an over-long request is refused with
3986
+ * code `prompt_too_large`). */
3987
+ state: Record<string, unknown>;
3988
+ /** The questions, keyed by names you choose; each answer comes back under its
3989
+ * question's name. */
3990
+ questions: Record<string, DecisionQuestion>;
3991
+ }
3992
+ /** The answer to a `choice` question. */
3993
+ export interface DecisionChoiceAnswer {
3994
+ type: "choice";
3995
+ /** The option picked: one of the question's `criteria` keys. */
3996
+ choice: string;
3997
+ /** One probability per option, summing to 1. */
3998
+ probabilities: Record<string, number>;
3999
+ /** How concentrated the probabilities are: near 1 when one option holds
4000
+ * almost all the weight, near 0 when they are spread evenly. */
4001
+ confidence: number;
4002
+ /** The answer is the model's own, passed through unchanged; a later model may
4003
+ * add fields. */
4004
+ [extra: string]: unknown;
4005
+ }
4006
+ /** The answer to a `noul` question. */
4007
+ export interface DecisionNoulAnswer {
4008
+ type: "noul";
4009
+ /** The probability that the answer is YES, from 0 to 1. `0` is a definite
4010
+ * no, not a missing answer: test it with `=== undefined`, never truthiness. */
4011
+ noul: number;
4012
+ [extra: string]: unknown;
4013
+ }
4014
+ /** The answer to a `score` question. */
4015
+ export interface DecisionScoreAnswer {
4016
+ type: "score";
4017
+ /** The expected position on the scale, counted from 0 (`1.7` is between
4018
+ * level 1 and level 2). */
4019
+ score: number;
4020
+ /** Position → the description you gave that level. */
4021
+ legend: Record<string, string>;
4022
+ /** One probability per position. */
4023
+ probabilities: Record<string, number>;
4024
+ confidence: number;
4025
+ [extra: string]: unknown;
4026
+ }
4027
+ /** One answer, discriminated on `type` (the type of the question it answers). */
4028
+ export type DecisionAnswer = DecisionChoiceAnswer | DecisionNoulAnswer | DecisionScoreAnswer;
4029
+ /** Result of {@link LoomcycleClient.decide}. The probabilities are a judgement,
4030
+ * not a measurement: compare options within one answer, and do not treat a
4031
+ * fixed threshold as a guarantee. */
4032
+ export interface DecideResponse {
4033
+ /** The name that answered, as the deployment lists it (the default's name
4034
+ * when the request named none). */
4035
+ model: string;
4036
+ provider: string;
4037
+ /** What the provider says answered. */
4038
+ served_model: string;
4039
+ /** One answer per question, under the question's name. */
4040
+ answers: Record<string, DecisionAnswer>;
4041
+ /** Tokens of this call, charged to the caller and counted against its token
4042
+ * budget. */
4043
+ usage: {
4044
+ input_tokens: number;
4045
+ output_tokens: number;
4046
+ };
4047
+ }
4048
+ /** One decision model a {@link LoomcycleClient.decide} call may name. */
4049
+ export interface DecisionModel {
4050
+ /** What `DecideRequest.model` is set to. */
4051
+ name: string;
4052
+ provider: string;
4053
+ /** The model the provider serves under that name. */
4054
+ model: string;
4055
+ limits: {
4056
+ max_questions: number;
4057
+ /** `min_options` and `max_options` bound a choice's options and a score's
4058
+ * levels. */
4059
+ min_options: number;
4060
+ max_options: number;
4061
+ };
4062
+ }
4063
+ /** Result of {@link LoomcycleClient.listDecisionModels}. */
4064
+ export interface DecisionModelsResponse {
4065
+ /** The name used when a call names no model. */
4066
+ default: string;
4067
+ models: DecisionModel[];
4068
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loomcycle/client",
3
- "version": "1.105.0",
3
+ "version": "1.107.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",