@loomcycle/client 1.10.0 → 1.12.1
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/README.md +1 -0
- package/dist/cjs/client.js +61 -7
- package/dist/cjs/fetch-helpers.js +19 -2
- package/dist/client.d.ts +45 -6
- package/dist/client.js +61 -7
- package/dist/fetch-helpers.d.ts +4 -1
- package/dist/fetch-helpers.js +19 -2
- package/dist/index.d.ts +1 -1
- package/dist/types.d.ts +70 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -12,6 +12,7 @@ TypeScript client for the [loomcycle](https://github.com/denn-gubsky/loomcycle)
|
|
|
12
12
|
|
|
13
13
|
### What's new since v0.8.18
|
|
14
14
|
|
|
15
|
+
- **Path/Document browse-by-subject + the full Document op set** (v1.12.1, RFC AS/AK) — `path(input, opts)` and `document(input, opts)` accept optional `scopeId` / `tenant` browse overrides, sent as `?scope_id=` / `?tenant=` query params (the server reads them from the URL and re-checks authorization — a tenant principal's `tenant` is ignored, `scopeId` picks any subject it may see); omit both to browse your own subject (byte-identical to the pre-RFC-AS request). `DocumentToolInput.op` now covers all 16 backend ops — adds **`set_path`** (attach/re-home a Path-tree name for an existing document), **`export_md`** (render to Markdown; `include_metadata: false` for clean human-facing output), and **`import_md`** (build a document from export_md-shaped `markdown`). Additive — existing `path()` / `document()` callers are unchanged.
|
|
15
16
|
- **`interactiveSession` / `sendRunInput` / `streamRunByID` + the `interactive` flag** (v1.1.1, RFC AI) — the interactive agentic session, the adapter port of the Web UI's run terminal. Pass `interactive: true` to `runStreaming` / `continueSession` to start a **persistent** run that parks at end_turn (an `awaiting_input` frame) instead of ending; **`sendRunInput(runId, text)`** steers it (the response arrives on the same stream); **`streamRunByID(runId, {fromSeq})`** re-attaches by run_id (the operator's prior turns replay as `steer` events, `user_input.source === "replay"`, so a cold client — e.g. another device — reconstructs the whole conversation). The high-level **`client.interactiveSession({agent, segments})`** returns an `InteractiveSession` with `events()` / `send()` / `cancel()`; **`attachInteractiveSession(runId)`** resumes one. The `AgentEvent` union gains `awaiting_input` / `steer` / `context_compaction`.
|
|
16
17
|
- **`volumeDef` / `listVolumes` / `listEphemeralVolumes`** (v0.35.0, RFC AH) — the dynamic filesystem-volume surface. `volumeDef` is the op-discriminated substrate tool (`create` / `get` / `list` / `delete` / `purge`); a Volume is **flat** (a pointer to mutable on-disk state, not a versioned def), so `delete` unmaps + leaves files while `purge` removes the row **and** the directory tree — there is no retire/promote/fork. Tenant-confined (`ScopeTenant`): the runtime derives the path inside an operator-blessed `dynamic_root`, so you pass `{name, mode}`, never a host path. `listVolumes()` / `listEphemeralVolumes()` return the tenant's persistent + live run-scoped volumes; host paths are redacted (`""`) for a non-operator caller.
|
|
17
18
|
- **`ensureMcpServer` / `mcpServerDefVerify`** (v0.18.0) — typed ergonomics for the dynamic-MCP dedup flow. `ensureMcpServer({name, url, headers?, rediscover?})` registers a callback MCP server **idempotently**: it runs `create` (a no-op in loomcycle ≥ v0.18.0 when the active def already carries identical content) plus an optional `rediscover` (a no-op on unchanged tools), and returns `{defId, version, changed, discoveredToolCount?}` — so a consumer re-registering on every startup gets `changed: false` once its registration content is stable. Keep `${run.*}` / `${LOOMCYCLE_*}` header placeholders **literal** (don't bake a per-restart token) or the content varies each boot and dedup can't engage. `mcpServerDefVerify(name, sha)` is the typed `op: verify` wrapper (`matches: true` = no-op signal).
|
package/dist/cjs/client.js
CHANGED
|
@@ -343,6 +343,31 @@ class LoomcycleClient {
|
|
|
343
343
|
const q = params.toString() ? `?${params.toString()}` : "";
|
|
344
344
|
return (0, fetch_helpers_js_1.jsonFetch)(this.ctx, `/v1/_usage${q}`, opts);
|
|
345
345
|
}
|
|
346
|
+
/** List the per-scope token budgets visible to the caller (RFC AW), each with
|
|
347
|
+
* its live month-to-date usage. Tenant-scoped server-side: a tenant operator
|
|
348
|
+
* sees only its own tenant's budgets; an admin sees all (or focuses one via
|
|
349
|
+
* `tenant`). Mirrors `GET /v1/_limits`. */
|
|
350
|
+
async listLimits(opts) {
|
|
351
|
+
const q = opts?.tenant ? `?tenant=${encodeURIComponent(opts.tenant)}` : "";
|
|
352
|
+
return (0, fetch_helpers_js_1.jsonFetch)(this.ctx, `/v1/_limits${q}`, opts);
|
|
353
|
+
}
|
|
354
|
+
/** Upsert one token budget (RFC AW). A present `soft_limit`/`hard_limit` sets
|
|
355
|
+
* that tier; omitting it clears the tier (unlimited on that axis) — a
|
|
356
|
+
* full-row upsert. The operator-global scope + any cross-tenant `tenant_id`
|
|
357
|
+
* are admin-only (403 otherwise). Mirrors `PUT /v1/_limits`. */
|
|
358
|
+
async setLimit(body, opts) {
|
|
359
|
+
return (0, fetch_helpers_js_1.putJSON)(this.ctx, "/v1/_limits", body, opts);
|
|
360
|
+
}
|
|
361
|
+
/** Delete a token budget → the scope is unlimited again (RFC AW). Same
|
|
362
|
+
* tenant-confinement as `setLimit`. Mirrors `DELETE /v1/_limits`. */
|
|
363
|
+
async deleteLimit(scope, opts) {
|
|
364
|
+
const params = new URLSearchParams({ scope });
|
|
365
|
+
if (opts?.scopeId)
|
|
366
|
+
params.set("scope_id", opts.scopeId);
|
|
367
|
+
if (opts?.tenant)
|
|
368
|
+
params.set("tenant", opts.tenant);
|
|
369
|
+
return (0, fetch_helpers_js_1.deleteRequest)(this.ctx, `/v1/_limits?${params.toString()}`, opts);
|
|
370
|
+
}
|
|
346
371
|
/** Read the full event log for a session. Each entry has seq,
|
|
347
372
|
* run_id, ts_ns, type, event (the providers.Event payload). */
|
|
348
373
|
async getTranscript(sessionId, opts) {
|
|
@@ -857,16 +882,26 @@ class LoomcycleClient {
|
|
|
857
882
|
*
|
|
858
883
|
* Raises {@link SubstrateToolRefusedError} on tool-level refusals (bad
|
|
859
884
|
* path, rm of a non-empty path without recursive, etc.);
|
|
860
|
-
* {@link InvalidArgumentError} on 400; {@link AuthError} on 401.
|
|
885
|
+
* {@link InvalidArgumentError} on 400; {@link AuthError} on 401.
|
|
886
|
+
*
|
|
887
|
+
* `opts.scopeId` / `opts.tenant` are the RFC AS browse-by-subject overrides
|
|
888
|
+
* (sent as `?scope_id=` / `?tenant=` query params — the server reads them
|
|
889
|
+
* from the URL, not the body, and re-checks authorization: a tenant
|
|
890
|
+
* principal's `tenant` is ignored, `scopeId` picks any subject it may see).
|
|
891
|
+
* Omit both to browse your own subject (byte-identical to the pre-RFC-AS
|
|
892
|
+
* request). */
|
|
861
893
|
async path(input, opts) {
|
|
862
|
-
return (0, fetch_helpers_js_1.postJSON)(this.ctx, "/v1/_path", input,
|
|
894
|
+
return (0, fetch_helpers_js_1.postJSON)(this.ctx, "/v1/_path", input, {
|
|
895
|
+
signal: opts?.signal,
|
|
896
|
+
query: browseQuery(opts),
|
|
897
|
+
});
|
|
863
898
|
}
|
|
864
899
|
/** Invoke the RFC AK Document tool over HTTP (`POST /v1/_document`). A
|
|
865
900
|
* chunked-graph document where each chunk is a first-class unit (UUID,
|
|
866
901
|
* hierarchy, type, fields, graph edges, Markdown body) that agents and
|
|
867
|
-
* humans co-author. Op-discriminated (
|
|
868
|
-
* edges, query_chunks, type defs). Scope
|
|
869
|
-
* resolved server-side from the principal.
|
|
902
|
+
* humans co-author. Op-discriminated (16 ops: document/chunk lifecycle,
|
|
903
|
+
* set_path, edges, query_chunks, type defs, export_md/import_md). Scope
|
|
904
|
+
* agent/user (tenant deferred); resolved server-side from the principal.
|
|
870
905
|
*
|
|
871
906
|
* Requires SQL Memory enabled on the sidecar (`LOOMCYCLE_SQLMEM_ENABLED=1`)
|
|
872
907
|
* — the chunk-structure tables live there. Without it the call is refused
|
|
@@ -874,9 +909,15 @@ class LoomcycleClient {
|
|
|
874
909
|
*
|
|
875
910
|
* Response varies per op — `create_document` returns
|
|
876
911
|
* `{document_id, root_chunk_id, ...}`, `query_chunks` returns rows.
|
|
877
|
-
* {@link InvalidArgumentError} on 400; {@link AuthError} on 401.
|
|
912
|
+
* {@link InvalidArgumentError} on 400; {@link AuthError} on 401.
|
|
913
|
+
*
|
|
914
|
+
* `opts.scopeId` / `opts.tenant` are the RFC AS browse-by-subject overrides —
|
|
915
|
+
* see {@link LoomcycleClient.path}. Omit both to browse your own subject. */
|
|
878
916
|
async document(input, opts) {
|
|
879
|
-
return (0, fetch_helpers_js_1.postJSON)(this.ctx, "/v1/_document", input,
|
|
917
|
+
return (0, fetch_helpers_js_1.postJSON)(this.ctx, "/v1/_document", input, {
|
|
918
|
+
signal: opts?.signal,
|
|
919
|
+
query: browseQuery(opts),
|
|
920
|
+
});
|
|
880
921
|
}
|
|
881
922
|
/** List the PERSISTENT volume universe for the caller's tenant — every
|
|
882
923
|
* static volume (the shared bind floor, `source: "static"`, read-only)
|
|
@@ -1484,6 +1525,19 @@ function channelOpPath(channel, scope, userId, op) {
|
|
|
1484
1525
|
}
|
|
1485
1526
|
return `/v1/_channels/${enc}/${op}`;
|
|
1486
1527
|
}
|
|
1528
|
+
// browseQuery maps the RFC AS browse-by-subject opts to the wire query-param
|
|
1529
|
+
// names the off-run Path/Document endpoints read from the URL (scope_id /
|
|
1530
|
+
// tenant — matching web/src/api.ts:substratePost). Only set values are
|
|
1531
|
+
// included; postJSON drops the query entirely when the map is empty, so a
|
|
1532
|
+
// caller passing neither builds the same URL as before RFC AS.
|
|
1533
|
+
function browseQuery(opts) {
|
|
1534
|
+
const q = {};
|
|
1535
|
+
if (opts?.scopeId)
|
|
1536
|
+
q.scope_id = opts.scopeId;
|
|
1537
|
+
if (opts?.tenant)
|
|
1538
|
+
q.tenant = opts.tenant;
|
|
1539
|
+
return q;
|
|
1540
|
+
}
|
|
1487
1541
|
// ---- v0.11.0 LLM Gateway helpers ----
|
|
1488
1542
|
/** serializeLLMOptions strips the AbortSignal (transport concern) and
|
|
1489
1543
|
* forces the stream flag to match the call mode. */
|
|
@@ -28,6 +28,21 @@ function authHeaders(ctx) {
|
|
|
28
28
|
h.Authorization = `Bearer ${ctx.authToken}`;
|
|
29
29
|
return h;
|
|
30
30
|
}
|
|
31
|
+
/** queryString turns an optional param map into a leading-`?` query
|
|
32
|
+
* string, dropping empty-valued entries. Returns "" for an absent or
|
|
33
|
+
* all-empty map so a caller that passes no query builds the same URL as
|
|
34
|
+
* before. Insertion order is preserved (URLSearchParams is stable). */
|
|
35
|
+
function queryString(query) {
|
|
36
|
+
if (!query)
|
|
37
|
+
return "";
|
|
38
|
+
const qs = new URLSearchParams();
|
|
39
|
+
for (const [k, v] of Object.entries(query)) {
|
|
40
|
+
if (v)
|
|
41
|
+
qs.set(k, v);
|
|
42
|
+
}
|
|
43
|
+
const s = qs.toString();
|
|
44
|
+
return s ? `?${s}` : "";
|
|
45
|
+
}
|
|
31
46
|
/** jsonFetch performs a GET and unwraps the JSON body. Non-2xx
|
|
32
47
|
* status maps to a typed error via raiseFromResponse. */
|
|
33
48
|
async function jsonFetch(ctx, path, opts) {
|
|
@@ -43,7 +58,9 @@ async function jsonFetch(ctx, path, opts) {
|
|
|
43
58
|
}
|
|
44
59
|
/** postJSON sends a JSON-encoded body and unwraps the response.
|
|
45
60
|
* When `body` is undefined, no body is sent (Content-Type
|
|
46
|
-
* omitted).
|
|
61
|
+
* omitted). `opts.query` appends URL query params (empty-valued
|
|
62
|
+
* entries are dropped; an all-empty/absent map yields no `?`, so
|
|
63
|
+
* existing callers produce a byte-identical URL). */
|
|
47
64
|
async function postJSON(ctx, path, body, opts) {
|
|
48
65
|
const headers = authHeaders(ctx);
|
|
49
66
|
let bodyStr;
|
|
@@ -51,7 +68,7 @@ async function postJSON(ctx, path, body, opts) {
|
|
|
51
68
|
headers["Content-Type"] = "application/json";
|
|
52
69
|
bodyStr = JSON.stringify(body);
|
|
53
70
|
}
|
|
54
|
-
const resp = await ctx.fetchImpl(ctx.baseUrl + path, {
|
|
71
|
+
const resp = await ctx.fetchImpl(ctx.baseUrl + path + queryString(opts?.query), {
|
|
55
72
|
method: "POST",
|
|
56
73
|
headers,
|
|
57
74
|
body: bodyStr,
|
package/dist/client.d.ts
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* full mapping table.
|
|
25
25
|
*/
|
|
26
26
|
import { InteractiveSession } from "./interactive.js";
|
|
27
|
-
import type { Agent, AgentEvent, AgentStatus, CancelAgentResult, ClientOptions, ContinueOptions, CreateSnapshotOptions, EnsureCodeAgentOptions, EnsureCodeAgentResult, EnsureMcpServerOptions, EnsureMcpServerResult, HealthResponse, Hook, InterruptListResponse, InterruptStatus, AckChannelOptions, AwaitChannelsOptions, BroadcastChannelsOptions, ChannelAckResult, ChannelAwaitResult, ChannelBroadcastResult, ChannelDescriptor, ChannelPeekResult, ChannelPublishResult, ChannelPurgeResult, 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, PersistentVolumesResponse, EphemeralVolumesResponse, RegisterHookOptions, RegisterHookResponse, ResolveInterruptOptions, ResumeResult, ResolverMatrix, CompactRunResult, RunBatchOptions, RunBatchResult, RunOptions, RunStateStreamItem, RuntimeStateResponse, SnapshotCreateResponse, SnapshotDescriptor, SnapshotEnvelope, SnapshotRestoreResponse, StreamUserRunStatesOptions, SubstrateToolInput, SubstrateToolResponse, PathToolInput, PathToolResponse, DocumentToolInput, DocumentToolResponse, TranscriptResponse, WhoamiResponse, UsageDimension, UsageReportResponse } from "./types.js";
|
|
27
|
+
import type { Agent, AgentEvent, AgentStatus, CancelAgentResult, ClientOptions, ContinueOptions, CreateSnapshotOptions, EnsureCodeAgentOptions, EnsureCodeAgentResult, EnsureMcpServerOptions, EnsureMcpServerResult, HealthResponse, Hook, InterruptListResponse, InterruptStatus, AckChannelOptions, AwaitChannelsOptions, BroadcastChannelsOptions, ChannelAckResult, ChannelAwaitResult, ChannelBroadcastResult, ChannelDescriptor, ChannelPeekResult, ChannelPublishResult, ChannelPurgeResult, 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, PersistentVolumesResponse, EphemeralVolumesResponse, RegisterHookOptions, RegisterHookResponse, ResolveInterruptOptions, ResumeResult, ResolverMatrix, CompactRunResult, RunBatchOptions, RunBatchResult, RunOptions, RunStateStreamItem, RuntimeStateResponse, SnapshotCreateResponse, SnapshotDescriptor, SnapshotEnvelope, SnapshotRestoreResponse, StreamUserRunStatesOptions, SubstrateToolInput, SubstrateToolResponse, PathToolInput, PathToolResponse, DocumentToolInput, DocumentToolResponse, TranscriptResponse, WhoamiResponse, UsageDimension, UsageReportResponse, TokenLimit, TokenLimitsResponse, SetTokenLimitRequest } from "./types.js";
|
|
28
28
|
export declare class LoomcycleClient {
|
|
29
29
|
private ctx;
|
|
30
30
|
constructor(opts?: ClientOptions);
|
|
@@ -184,6 +184,31 @@ export declare class LoomcycleClient {
|
|
|
184
184
|
tenant?: string;
|
|
185
185
|
signal?: AbortSignal;
|
|
186
186
|
}): Promise<UsageReportResponse>;
|
|
187
|
+
/** List the per-scope token budgets visible to the caller (RFC AW), each with
|
|
188
|
+
* its live month-to-date usage. Tenant-scoped server-side: a tenant operator
|
|
189
|
+
* sees only its own tenant's budgets; an admin sees all (or focuses one via
|
|
190
|
+
* `tenant`). Mirrors `GET /v1/_limits`. */
|
|
191
|
+
listLimits(opts?: {
|
|
192
|
+
/** Admin-only tenant focus (?tenant=); ignored for a tenant principal. */
|
|
193
|
+
tenant?: string;
|
|
194
|
+
signal?: AbortSignal;
|
|
195
|
+
}): Promise<TokenLimitsResponse>;
|
|
196
|
+
/** Upsert one token budget (RFC AW). A present `soft_limit`/`hard_limit` sets
|
|
197
|
+
* that tier; omitting it clears the tier (unlimited on that axis) — a
|
|
198
|
+
* full-row upsert. The operator-global scope + any cross-tenant `tenant_id`
|
|
199
|
+
* are admin-only (403 otherwise). Mirrors `PUT /v1/_limits`. */
|
|
200
|
+
setLimit(body: SetTokenLimitRequest, opts?: {
|
|
201
|
+
signal?: AbortSignal;
|
|
202
|
+
}): Promise<TokenLimit>;
|
|
203
|
+
/** Delete a token budget → the scope is unlimited again (RFC AW). Same
|
|
204
|
+
* tenant-confinement as `setLimit`. Mirrors `DELETE /v1/_limits`. */
|
|
205
|
+
deleteLimit(scope: string, opts?: {
|
|
206
|
+
/** Required for scope=user (the subject); empty for scope=tenant. */
|
|
207
|
+
scopeId?: string;
|
|
208
|
+
/** Admin-only target tenant; ignored for a tenant principal. */
|
|
209
|
+
tenant?: string;
|
|
210
|
+
signal?: AbortSignal;
|
|
211
|
+
}): Promise<void>;
|
|
187
212
|
/** Read the full event log for a session. Each entry has seq,
|
|
188
213
|
* run_id, ts_ns, type, event (the providers.Event payload). */
|
|
189
214
|
getTranscript(sessionId: string, opts?: {
|
|
@@ -583,16 +608,25 @@ export declare class LoomcycleClient {
|
|
|
583
608
|
*
|
|
584
609
|
* Raises {@link SubstrateToolRefusedError} on tool-level refusals (bad
|
|
585
610
|
* path, rm of a non-empty path without recursive, etc.);
|
|
586
|
-
* {@link InvalidArgumentError} on 400; {@link AuthError} on 401.
|
|
611
|
+
* {@link InvalidArgumentError} on 400; {@link AuthError} on 401.
|
|
612
|
+
*
|
|
613
|
+
* `opts.scopeId` / `opts.tenant` are the RFC AS browse-by-subject overrides
|
|
614
|
+
* (sent as `?scope_id=` / `?tenant=` query params — the server reads them
|
|
615
|
+
* from the URL, not the body, and re-checks authorization: a tenant
|
|
616
|
+
* principal's `tenant` is ignored, `scopeId` picks any subject it may see).
|
|
617
|
+
* Omit both to browse your own subject (byte-identical to the pre-RFC-AS
|
|
618
|
+
* request). */
|
|
587
619
|
path(input: PathToolInput, opts?: {
|
|
588
620
|
signal?: AbortSignal;
|
|
621
|
+
scopeId?: string;
|
|
622
|
+
tenant?: string;
|
|
589
623
|
}): Promise<PathToolResponse>;
|
|
590
624
|
/** Invoke the RFC AK Document tool over HTTP (`POST /v1/_document`). A
|
|
591
625
|
* chunked-graph document where each chunk is a first-class unit (UUID,
|
|
592
626
|
* hierarchy, type, fields, graph edges, Markdown body) that agents and
|
|
593
|
-
* humans co-author. Op-discriminated (
|
|
594
|
-
* edges, query_chunks, type defs). Scope
|
|
595
|
-
* resolved server-side from the principal.
|
|
627
|
+
* humans co-author. Op-discriminated (16 ops: document/chunk lifecycle,
|
|
628
|
+
* set_path, edges, query_chunks, type defs, export_md/import_md). Scope
|
|
629
|
+
* agent/user (tenant deferred); resolved server-side from the principal.
|
|
596
630
|
*
|
|
597
631
|
* Requires SQL Memory enabled on the sidecar (`LOOMCYCLE_SQLMEM_ENABLED=1`)
|
|
598
632
|
* — the chunk-structure tables live there. Without it the call is refused
|
|
@@ -600,9 +634,14 @@ export declare class LoomcycleClient {
|
|
|
600
634
|
*
|
|
601
635
|
* Response varies per op — `create_document` returns
|
|
602
636
|
* `{document_id, root_chunk_id, ...}`, `query_chunks` returns rows.
|
|
603
|
-
* {@link InvalidArgumentError} on 400; {@link AuthError} on 401.
|
|
637
|
+
* {@link InvalidArgumentError} on 400; {@link AuthError} on 401.
|
|
638
|
+
*
|
|
639
|
+
* `opts.scopeId` / `opts.tenant` are the RFC AS browse-by-subject overrides —
|
|
640
|
+
* see {@link LoomcycleClient.path}. Omit both to browse your own subject. */
|
|
604
641
|
document(input: DocumentToolInput, opts?: {
|
|
605
642
|
signal?: AbortSignal;
|
|
643
|
+
scopeId?: string;
|
|
644
|
+
tenant?: string;
|
|
606
645
|
}): Promise<DocumentToolResponse>;
|
|
607
646
|
/** List the PERSISTENT volume universe for the caller's tenant — every
|
|
608
647
|
* static volume (the shared bind floor, `source: "static"`, read-only)
|
package/dist/client.js
CHANGED
|
@@ -340,6 +340,31 @@ export class LoomcycleClient {
|
|
|
340
340
|
const q = params.toString() ? `?${params.toString()}` : "";
|
|
341
341
|
return jsonFetch(this.ctx, `/v1/_usage${q}`, opts);
|
|
342
342
|
}
|
|
343
|
+
/** List the per-scope token budgets visible to the caller (RFC AW), each with
|
|
344
|
+
* its live month-to-date usage. Tenant-scoped server-side: a tenant operator
|
|
345
|
+
* sees only its own tenant's budgets; an admin sees all (or focuses one via
|
|
346
|
+
* `tenant`). Mirrors `GET /v1/_limits`. */
|
|
347
|
+
async listLimits(opts) {
|
|
348
|
+
const q = opts?.tenant ? `?tenant=${encodeURIComponent(opts.tenant)}` : "";
|
|
349
|
+
return jsonFetch(this.ctx, `/v1/_limits${q}`, opts);
|
|
350
|
+
}
|
|
351
|
+
/** Upsert one token budget (RFC AW). A present `soft_limit`/`hard_limit` sets
|
|
352
|
+
* that tier; omitting it clears the tier (unlimited on that axis) — a
|
|
353
|
+
* full-row upsert. The operator-global scope + any cross-tenant `tenant_id`
|
|
354
|
+
* are admin-only (403 otherwise). Mirrors `PUT /v1/_limits`. */
|
|
355
|
+
async setLimit(body, opts) {
|
|
356
|
+
return putJSON(this.ctx, "/v1/_limits", body, opts);
|
|
357
|
+
}
|
|
358
|
+
/** Delete a token budget → the scope is unlimited again (RFC AW). Same
|
|
359
|
+
* tenant-confinement as `setLimit`. Mirrors `DELETE /v1/_limits`. */
|
|
360
|
+
async deleteLimit(scope, opts) {
|
|
361
|
+
const params = new URLSearchParams({ scope });
|
|
362
|
+
if (opts?.scopeId)
|
|
363
|
+
params.set("scope_id", opts.scopeId);
|
|
364
|
+
if (opts?.tenant)
|
|
365
|
+
params.set("tenant", opts.tenant);
|
|
366
|
+
return deleteRequest(this.ctx, `/v1/_limits?${params.toString()}`, opts);
|
|
367
|
+
}
|
|
343
368
|
/** Read the full event log for a session. Each entry has seq,
|
|
344
369
|
* run_id, ts_ns, type, event (the providers.Event payload). */
|
|
345
370
|
async getTranscript(sessionId, opts) {
|
|
@@ -854,16 +879,26 @@ export class LoomcycleClient {
|
|
|
854
879
|
*
|
|
855
880
|
* Raises {@link SubstrateToolRefusedError} on tool-level refusals (bad
|
|
856
881
|
* path, rm of a non-empty path without recursive, etc.);
|
|
857
|
-
* {@link InvalidArgumentError} on 400; {@link AuthError} on 401.
|
|
882
|
+
* {@link InvalidArgumentError} on 400; {@link AuthError} on 401.
|
|
883
|
+
*
|
|
884
|
+
* `opts.scopeId` / `opts.tenant` are the RFC AS browse-by-subject overrides
|
|
885
|
+
* (sent as `?scope_id=` / `?tenant=` query params — the server reads them
|
|
886
|
+
* from the URL, not the body, and re-checks authorization: a tenant
|
|
887
|
+
* principal's `tenant` is ignored, `scopeId` picks any subject it may see).
|
|
888
|
+
* Omit both to browse your own subject (byte-identical to the pre-RFC-AS
|
|
889
|
+
* request). */
|
|
858
890
|
async path(input, opts) {
|
|
859
|
-
return postJSON(this.ctx, "/v1/_path", input,
|
|
891
|
+
return postJSON(this.ctx, "/v1/_path", input, {
|
|
892
|
+
signal: opts?.signal,
|
|
893
|
+
query: browseQuery(opts),
|
|
894
|
+
});
|
|
860
895
|
}
|
|
861
896
|
/** Invoke the RFC AK Document tool over HTTP (`POST /v1/_document`). A
|
|
862
897
|
* chunked-graph document where each chunk is a first-class unit (UUID,
|
|
863
898
|
* hierarchy, type, fields, graph edges, Markdown body) that agents and
|
|
864
|
-
* humans co-author. Op-discriminated (
|
|
865
|
-
* edges, query_chunks, type defs). Scope
|
|
866
|
-
* resolved server-side from the principal.
|
|
899
|
+
* humans co-author. Op-discriminated (16 ops: document/chunk lifecycle,
|
|
900
|
+
* set_path, edges, query_chunks, type defs, export_md/import_md). Scope
|
|
901
|
+
* agent/user (tenant deferred); resolved server-side from the principal.
|
|
867
902
|
*
|
|
868
903
|
* Requires SQL Memory enabled on the sidecar (`LOOMCYCLE_SQLMEM_ENABLED=1`)
|
|
869
904
|
* — the chunk-structure tables live there. Without it the call is refused
|
|
@@ -871,9 +906,15 @@ export class LoomcycleClient {
|
|
|
871
906
|
*
|
|
872
907
|
* Response varies per op — `create_document` returns
|
|
873
908
|
* `{document_id, root_chunk_id, ...}`, `query_chunks` returns rows.
|
|
874
|
-
* {@link InvalidArgumentError} on 400; {@link AuthError} on 401.
|
|
909
|
+
* {@link InvalidArgumentError} on 400; {@link AuthError} on 401.
|
|
910
|
+
*
|
|
911
|
+
* `opts.scopeId` / `opts.tenant` are the RFC AS browse-by-subject overrides —
|
|
912
|
+
* see {@link LoomcycleClient.path}. Omit both to browse your own subject. */
|
|
875
913
|
async document(input, opts) {
|
|
876
|
-
return postJSON(this.ctx, "/v1/_document", input,
|
|
914
|
+
return postJSON(this.ctx, "/v1/_document", input, {
|
|
915
|
+
signal: opts?.signal,
|
|
916
|
+
query: browseQuery(opts),
|
|
917
|
+
});
|
|
877
918
|
}
|
|
878
919
|
/** List the PERSISTENT volume universe for the caller's tenant — every
|
|
879
920
|
* static volume (the shared bind floor, `source: "static"`, read-only)
|
|
@@ -1480,6 +1521,19 @@ function channelOpPath(channel, scope, userId, op) {
|
|
|
1480
1521
|
}
|
|
1481
1522
|
return `/v1/_channels/${enc}/${op}`;
|
|
1482
1523
|
}
|
|
1524
|
+
// browseQuery maps the RFC AS browse-by-subject opts to the wire query-param
|
|
1525
|
+
// names the off-run Path/Document endpoints read from the URL (scope_id /
|
|
1526
|
+
// tenant — matching web/src/api.ts:substratePost). Only set values are
|
|
1527
|
+
// included; postJSON drops the query entirely when the map is empty, so a
|
|
1528
|
+
// caller passing neither builds the same URL as before RFC AS.
|
|
1529
|
+
function browseQuery(opts) {
|
|
1530
|
+
const q = {};
|
|
1531
|
+
if (opts?.scopeId)
|
|
1532
|
+
q.scope_id = opts.scopeId;
|
|
1533
|
+
if (opts?.tenant)
|
|
1534
|
+
q.tenant = opts.tenant;
|
|
1535
|
+
return q;
|
|
1536
|
+
}
|
|
1483
1537
|
// ---- v0.11.0 LLM Gateway helpers ----
|
|
1484
1538
|
/** serializeLLMOptions strips the AbortSignal (transport concern) and
|
|
1485
1539
|
* forces the stream flag to match the call mode. */
|
package/dist/fetch-helpers.d.ts
CHANGED
|
@@ -39,9 +39,12 @@ export declare function jsonFetch<T>(ctx: _FetchContext, path: string, opts?: {
|
|
|
39
39
|
}): Promise<T>;
|
|
40
40
|
/** postJSON sends a JSON-encoded body and unwraps the response.
|
|
41
41
|
* When `body` is undefined, no body is sent (Content-Type
|
|
42
|
-
* omitted).
|
|
42
|
+
* omitted). `opts.query` appends URL query params (empty-valued
|
|
43
|
+
* entries are dropped; an all-empty/absent map yields no `?`, so
|
|
44
|
+
* existing callers produce a byte-identical URL). */
|
|
43
45
|
export declare function postJSON<T>(ctx: _FetchContext, path: string, body?: unknown, opts?: {
|
|
44
46
|
signal?: AbortSignal;
|
|
47
|
+
query?: Record<string, string>;
|
|
45
48
|
}): Promise<T>;
|
|
46
49
|
/** putJSON sends a JSON-encoded body via PUT and unwraps the
|
|
47
50
|
* response. Idempotent — REST-canonical verb for "create or
|
package/dist/fetch-helpers.js
CHANGED
|
@@ -19,6 +19,21 @@ export function authHeaders(ctx) {
|
|
|
19
19
|
h.Authorization = `Bearer ${ctx.authToken}`;
|
|
20
20
|
return h;
|
|
21
21
|
}
|
|
22
|
+
/** queryString turns an optional param map into a leading-`?` query
|
|
23
|
+
* string, dropping empty-valued entries. Returns "" for an absent or
|
|
24
|
+
* all-empty map so a caller that passes no query builds the same URL as
|
|
25
|
+
* before. Insertion order is preserved (URLSearchParams is stable). */
|
|
26
|
+
function queryString(query) {
|
|
27
|
+
if (!query)
|
|
28
|
+
return "";
|
|
29
|
+
const qs = new URLSearchParams();
|
|
30
|
+
for (const [k, v] of Object.entries(query)) {
|
|
31
|
+
if (v)
|
|
32
|
+
qs.set(k, v);
|
|
33
|
+
}
|
|
34
|
+
const s = qs.toString();
|
|
35
|
+
return s ? `?${s}` : "";
|
|
36
|
+
}
|
|
22
37
|
/** jsonFetch performs a GET and unwraps the JSON body. Non-2xx
|
|
23
38
|
* status maps to a typed error via raiseFromResponse. */
|
|
24
39
|
export async function jsonFetch(ctx, path, opts) {
|
|
@@ -34,7 +49,9 @@ export async function jsonFetch(ctx, path, opts) {
|
|
|
34
49
|
}
|
|
35
50
|
/** postJSON sends a JSON-encoded body and unwraps the response.
|
|
36
51
|
* When `body` is undefined, no body is sent (Content-Type
|
|
37
|
-
* omitted).
|
|
52
|
+
* omitted). `opts.query` appends URL query params (empty-valued
|
|
53
|
+
* entries are dropped; an all-empty/absent map yields no `?`, so
|
|
54
|
+
* existing callers produce a byte-identical URL). */
|
|
38
55
|
export async function postJSON(ctx, path, body, opts) {
|
|
39
56
|
const headers = authHeaders(ctx);
|
|
40
57
|
let bodyStr;
|
|
@@ -42,7 +59,7 @@ export async function postJSON(ctx, path, body, opts) {
|
|
|
42
59
|
headers["Content-Type"] = "application/json";
|
|
43
60
|
bodyStr = JSON.stringify(body);
|
|
44
61
|
}
|
|
45
|
-
const resp = await ctx.fetchImpl(ctx.baseUrl + path, {
|
|
62
|
+
const resp = await ctx.fetchImpl(ctx.baseUrl + path + queryString(opts?.query), {
|
|
46
63
|
method: "POST",
|
|
47
64
|
headers,
|
|
48
65
|
body: bodyStr,
|
package/dist/index.d.ts
CHANGED
|
@@ -93,5 +93,5 @@
|
|
|
93
93
|
export { LoomcycleClient } from "./client.js";
|
|
94
94
|
export { InteractiveSession } from "./interactive.js";
|
|
95
95
|
export type { InteractiveSessionOps } from "./interactive.js";
|
|
96
|
-
export type { AgentEvent, ClientOptions, ContinueOptions, EventType, HostWidening, ImageMediaType, ParentContext, PromptContent, PromptSegment, RetryInfo, RunOptions, SamplingOptions, CompactionOptions, ToolUse, Usage, Agent, AgentStatus, AgentUsage, CancelAgentResult, ListAgentsResponse, RunBatchOptions, RunBatchResult, SpawnRunResult, CompactRunResult, 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, PathToolInput, PathToolResponse, DocumentToolInput, DocumentToolResponse, VolumeMode, PersistentVolumeEntry, PersistentVolumesResponse, EphemeralVolumeEntry, EphemeralVolumesResponse, SystemPromptPayload, UserInputPayload, ChannelDescriptor, ListChannelsResponse, RunStateEvent, RunStateStreamClose, RunStateStreamItem, RunStateStreamOpen, StreamUserRunStatesOptions, AckChannelOptions, ChannelAckResult, ChannelMessageItem, ChannelPeekResult, ChannelPublishResult, ChannelPurgeResult, ChannelScope, ChannelSubscribeResult, PeekChannelOptions, PublishChannelOptions, SubscribeChannelOptions, AwaitChannelsOptions, BroadcastChannelsOptions, ChannelAwaitEntry, ChannelAwaitMode, ChannelAwaitResult, ChannelBroadcastEntry, ChannelBroadcastResult, 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, UsageDimension, UsageAggregate, UsageReportResponse, } from "./types.js";
|
|
96
|
+
export type { AgentEvent, ClientOptions, ContinueOptions, EventType, HostWidening, ImageMediaType, ParentContext, PromptContent, PromptSegment, RetryInfo, RunOptions, SamplingOptions, CompactionOptions, ToolUse, Usage, Agent, AgentStatus, AgentUsage, CancelAgentResult, ListAgentsResponse, RunBatchOptions, RunBatchResult, SpawnRunResult, CompactRunResult, 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, PathToolInput, PathToolResponse, DocumentToolInput, DocumentToolResponse, VolumeMode, PersistentVolumeEntry, PersistentVolumesResponse, EphemeralVolumeEntry, EphemeralVolumesResponse, SystemPromptPayload, UserInputPayload, ChannelDescriptor, ListChannelsResponse, RunStateEvent, RunStateStreamClose, RunStateStreamItem, RunStateStreamOpen, StreamUserRunStatesOptions, AckChannelOptions, ChannelAckResult, ChannelMessageItem, ChannelPeekResult, ChannelPublishResult, ChannelPurgeResult, ChannelScope, ChannelSubscribeResult, PeekChannelOptions, PublishChannelOptions, SubscribeChannelOptions, AwaitChannelsOptions, BroadcastChannelsOptions, ChannelAwaitEntry, ChannelAwaitMode, ChannelAwaitResult, ChannelBroadcastEntry, ChannelBroadcastResult, 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, UsageDimension, UsageAggregate, UsageReportResponse, LimitInfo, TokenLimit, TokenLimitsResponse, SetTokenLimitRequest, } from "./types.js";
|
|
97
97
|
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
|
@@ -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" | "_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" | "_meta";
|
|
11
11
|
export interface ToolUse {
|
|
12
12
|
id: string;
|
|
13
13
|
name: string;
|
|
@@ -54,6 +54,29 @@ export interface HostWidening {
|
|
|
54
54
|
hook_name: string;
|
|
55
55
|
hosts_added: string[];
|
|
56
56
|
}
|
|
57
|
+
/** LimitInfo accompanies an `event: limit` frame (RFC AW per-scope token
|
|
58
|
+
* budgets). Names which scope tripped, how hard (`soft` warns + the run
|
|
59
|
+
* continues; `hard` means the NEXT run is refused at admission), and where the
|
|
60
|
+
* scope stands against its ceiling — so a UI can render "tenant acme at 1.2M /
|
|
61
|
+
* 1M tokens this month" without a follow-up fetch. Wire-stable; mirrors
|
|
62
|
+
* providers.LimitInfo. */
|
|
63
|
+
export interface LimitInfo {
|
|
64
|
+
/** Which axis tripped: "operator" | "tenant" | "user". */
|
|
65
|
+
scope: string;
|
|
66
|
+
/** The tripped scope's id — tenant id (scope=tenant), user subject
|
|
67
|
+
* (scope=user), "" (operator-global). */
|
|
68
|
+
scope_id?: string;
|
|
69
|
+
/** "soft" (warn, run continues) | "hard" (next run refused at admission). */
|
|
70
|
+
severity: string;
|
|
71
|
+
/** Budget window; "month" (calendar month, UTC) in Phase 1. */
|
|
72
|
+
window: string;
|
|
73
|
+
/** The scope's month-to-date token total at the crossing. */
|
|
74
|
+
used: number;
|
|
75
|
+
/** The tier that was crossed (the soft or hard ceiling). */
|
|
76
|
+
limit: number;
|
|
77
|
+
/** Human-readable banner string. Optional. */
|
|
78
|
+
message?: string;
|
|
79
|
+
}
|
|
57
80
|
export interface AgentEvent {
|
|
58
81
|
type: EventType;
|
|
59
82
|
text?: string;
|
|
@@ -82,6 +105,9 @@ export interface AgentEvent {
|
|
|
82
105
|
source?: string;
|
|
83
106
|
seen_at?: string;
|
|
84
107
|
};
|
|
108
|
+
/** Payload on `event: limit` (RFC AW) — a per-scope token-budget crossing.
|
|
109
|
+
* Nil on all other event types. */
|
|
110
|
+
limit?: LimitInfo;
|
|
85
111
|
agent_id?: string;
|
|
86
112
|
run_id?: string;
|
|
87
113
|
session_id?: string;
|
|
@@ -791,10 +817,10 @@ export type PathToolInput = {
|
|
|
791
817
|
[extra: string]: unknown;
|
|
792
818
|
};
|
|
793
819
|
/** Input for {@link LoomcycleClient.document} — the RFC AK chunked-graph
|
|
794
|
-
* Document tool (POST /v1/_document). Op-discriminated (
|
|
820
|
+
* Document tool (POST /v1/_document). Op-discriminated (16 ops); requires
|
|
795
821
|
* SQL Memory on the sidecar. Scope agent/user (tenant deferred). */
|
|
796
822
|
export type DocumentToolInput = {
|
|
797
|
-
op: "create_document" | "get_document" | "delete_document" | "create_chunk" | "get_chunk" | "update_chunk" | "delete_chunk" | "move_chunk" | "link_chunks" | "unlink_chunks" | "query_chunks" | "define_type" | "list_types";
|
|
823
|
+
op: "create_document" | "get_document" | "delete_document" | "set_path" | "create_chunk" | "get_chunk" | "update_chunk" | "delete_chunk" | "move_chunk" | "link_chunks" | "unlink_chunks" | "query_chunks" | "define_type" | "list_types" | "export_md" | "import_md";
|
|
798
824
|
scope?: "agent" | "user";
|
|
799
825
|
/** Document id (get/delete_document) or chunk id (get/update/delete/move_chunk). */
|
|
800
826
|
id?: string;
|
|
@@ -821,6 +847,14 @@ export type DocumentToolInput = {
|
|
|
821
847
|
limit?: number;
|
|
822
848
|
/** define/list_types: the type name. */
|
|
823
849
|
name?: string;
|
|
850
|
+
/** export_md: embed round-trippable chunk metadata + edges as HTML comments
|
|
851
|
+
* (default true server-side). false = clean human-facing Markdown. */
|
|
852
|
+
include_metadata?: boolean;
|
|
853
|
+
/** import_md: an export_md-shaped Markdown document (headings = hierarchy;
|
|
854
|
+
* `<!-- loom: ... -->` metadata; `<!-- loom-edges: ... -->` trailer). Omit
|
|
855
|
+
* document_id to create a new document; pass it (+ optional parent_id) to
|
|
856
|
+
* import under an existing chunk. */
|
|
857
|
+
markdown?: string;
|
|
824
858
|
[extra: string]: unknown;
|
|
825
859
|
};
|
|
826
860
|
/** Response shape for {@link LoomcycleClient.path} and
|
|
@@ -1685,3 +1719,36 @@ export interface UsageReportResponse {
|
|
|
1685
1719
|
to?: string;
|
|
1686
1720
|
rows: UsageAggregate[];
|
|
1687
1721
|
}
|
|
1722
|
+
/** A per-scope token budget (RFC AW) plus its live month-to-date usage.
|
|
1723
|
+
* `soft_limit` / `hard_limit` are absent when that tier is unset (no ceiling
|
|
1724
|
+
* on that axis). Mirrors one row of GET /v1/_limits. */
|
|
1725
|
+
export interface TokenLimit {
|
|
1726
|
+
tenant_id: string;
|
|
1727
|
+
/** "operator" | "tenant" | "user" */
|
|
1728
|
+
scope: string;
|
|
1729
|
+
/** tenant id (scope=tenant), user subject (scope=user), "" (operator). */
|
|
1730
|
+
scope_id?: string;
|
|
1731
|
+
soft_limit?: number;
|
|
1732
|
+
hard_limit?: number;
|
|
1733
|
+
/** The scope's current month-to-date token total. */
|
|
1734
|
+
used: number;
|
|
1735
|
+
updated_at?: string;
|
|
1736
|
+
updated_by?: string;
|
|
1737
|
+
}
|
|
1738
|
+
export interface TokenLimitsResponse {
|
|
1739
|
+
limits: TokenLimit[];
|
|
1740
|
+
}
|
|
1741
|
+
/** The PUT /v1/_limits body (RFC AW). A present `soft_limit`/`hard_limit` sets
|
|
1742
|
+
* that tier; omitting it clears the tier (unlimited on that axis) — a full-row
|
|
1743
|
+
* upsert. `tenant_id` is an admin-only target; a tenant operator is confined to
|
|
1744
|
+
* its own tenant regardless of this field. */
|
|
1745
|
+
export interface SetTokenLimitRequest {
|
|
1746
|
+
/** Admin-only target tenant; ignored for confinement on a scoped caller. */
|
|
1747
|
+
tenant_id?: string;
|
|
1748
|
+
/** "operator" | "tenant" | "user" */
|
|
1749
|
+
scope: string;
|
|
1750
|
+
/** Required for scope=user (the subject); must be empty for scope=tenant. */
|
|
1751
|
+
scope_id?: string;
|
|
1752
|
+
soft_limit?: number;
|
|
1753
|
+
hard_limit?: number;
|
|
1754
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loomcycle/client",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "TypeScript client for the loomcycle sidecar (HTTP+SSE). 63 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).",
|
|
3
|
+
"version": "1.12.1",
|
|
4
|
+
"description": "TypeScript client for the loomcycle sidecar (HTTP+SSE). 63 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.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"repository": {
|