@loomcycle/client 0.8.20 → 0.9.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/client.d.ts +27 -1
- package/dist/client.js +27 -0
- package/dist/errors.d.ts +19 -0
- package/dist/errors.js +19 -0
- package/dist/fetch-helpers.js +19 -2
- package/dist/index.d.ts +8 -3
- package/dist/index.js +7 -2
- package/dist/types.d.ts +25 -0
- package/package.json +2 -2
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, HealthResponse, Hook, InterruptListResponse, InterruptStatus, ListUsersResponse, MemoryEntriesResponse, MemoryEntryResponse, MemoryScopeIDsResponse, MemoryScopesResponse, PauseResult, RegisterHookOptions, RegisterHookResponse, ResolveInterruptOptions, ResumeResult, RunOptions, RuntimeStateResponse, SnapshotCreateResponse, SnapshotDescriptor, SnapshotEnvelope, SnapshotRestoreResponse, TranscriptResponse } from "./types.js";
|
|
26
|
+
import type { Agent, AgentEvent, AgentStatus, CancelAgentResult, ClientOptions, ContinueOptions, CreateSnapshotOptions, HealthResponse, Hook, InterruptListResponse, InterruptStatus, ListUsersResponse, MemoryEntriesResponse, MemoryEntryResponse, MemoryScopeIDsResponse, MemoryScopesResponse, PauseResult, RegisterHookOptions, RegisterHookResponse, ResolveInterruptOptions, ResumeResult, RunOptions, RuntimeStateResponse, SnapshotCreateResponse, SnapshotDescriptor, SnapshotEnvelope, SnapshotRestoreResponse, SubstrateToolInput, SubstrateToolResponse, TranscriptResponse } from "./types.js";
|
|
27
27
|
export declare class LoomcycleClient {
|
|
28
28
|
private ctx;
|
|
29
29
|
constructor(opts?: ClientOptions);
|
|
@@ -207,6 +207,32 @@ export declare class LoomcycleClient {
|
|
|
207
207
|
deleteHook(id: string, opts?: {
|
|
208
208
|
signal?: AbortSignal;
|
|
209
209
|
}): Promise<void>;
|
|
210
|
+
/** Invoke the AgentDef substrate tool over HTTP. Mirrors the
|
|
211
|
+
* MCP `agentdef` meta-tool and the in-band agent tool_use of
|
|
212
|
+
* the same name — different transport, identical semantics.
|
|
213
|
+
*
|
|
214
|
+
* The `input.op` field discriminates create / fork / get /
|
|
215
|
+
* list / promote / retire. The remaining fields are op-specific;
|
|
216
|
+
* see the in-process tool's documentation.
|
|
217
|
+
*
|
|
218
|
+
* Raises {@link SubstrateToolRefusedError} when the tool itself
|
|
219
|
+
* refuses the call (scope deny, empty body, allowed-tools
|
|
220
|
+
* widening, etc.) — distinct from transport failures so callers
|
|
221
|
+
* can branch on the typed error class.
|
|
222
|
+
*
|
|
223
|
+
* Raises {@link InvalidArgumentError} on 400 (malformed JSON
|
|
224
|
+
* body); {@link AuthError} on 401; {@link UnavailableError} on
|
|
225
|
+
* 503 (store / connector unwired). */
|
|
226
|
+
agentDef(input: SubstrateToolInput, opts?: {
|
|
227
|
+
signal?: AbortSignal;
|
|
228
|
+
}): Promise<SubstrateToolResponse>;
|
|
229
|
+
/** Invoke the SkillDef substrate tool over HTTP. Mirror of
|
|
230
|
+
* {@link LoomcycleClient.agentDef} for skills (v0.8.22+). Same
|
|
231
|
+
* input grammar, same error class on refusal. See the
|
|
232
|
+
* agentDef() doc for the full shape and error contract. */
|
|
233
|
+
skillDef(input: SubstrateToolInput, opts?: {
|
|
234
|
+
signal?: AbortSignal;
|
|
235
|
+
}): Promise<SubstrateToolResponse>;
|
|
210
236
|
/** Shared SSE POST → stream-of-AgentEvent path. Used by
|
|
211
237
|
* runStreaming + continueSession. */
|
|
212
238
|
private streamSSE;
|
package/dist/client.js
CHANGED
|
@@ -333,6 +333,33 @@ export class LoomcycleClient {
|
|
|
333
333
|
async deleteHook(id, opts) {
|
|
334
334
|
await deleteRequest(this.ctx, `/v1/hooks/${encodeURIComponent(id)}`, opts);
|
|
335
335
|
}
|
|
336
|
+
// ---- v0.8.22 substrate admin (AgentDef + SkillDef) ----
|
|
337
|
+
/** Invoke the AgentDef substrate tool over HTTP. Mirrors the
|
|
338
|
+
* MCP `agentdef` meta-tool and the in-band agent tool_use of
|
|
339
|
+
* the same name — different transport, identical semantics.
|
|
340
|
+
*
|
|
341
|
+
* The `input.op` field discriminates create / fork / get /
|
|
342
|
+
* list / promote / retire. The remaining fields are op-specific;
|
|
343
|
+
* see the in-process tool's documentation.
|
|
344
|
+
*
|
|
345
|
+
* Raises {@link SubstrateToolRefusedError} when the tool itself
|
|
346
|
+
* refuses the call (scope deny, empty body, allowed-tools
|
|
347
|
+
* widening, etc.) — distinct from transport failures so callers
|
|
348
|
+
* can branch on the typed error class.
|
|
349
|
+
*
|
|
350
|
+
* Raises {@link InvalidArgumentError} on 400 (malformed JSON
|
|
351
|
+
* body); {@link AuthError} on 401; {@link UnavailableError} on
|
|
352
|
+
* 503 (store / connector unwired). */
|
|
353
|
+
async agentDef(input, opts) {
|
|
354
|
+
return postJSON(this.ctx, "/v1/_agentdef", input, opts);
|
|
355
|
+
}
|
|
356
|
+
/** Invoke the SkillDef substrate tool over HTTP. Mirror of
|
|
357
|
+
* {@link LoomcycleClient.agentDef} for skills (v0.8.22+). Same
|
|
358
|
+
* input grammar, same error class on refusal. See the
|
|
359
|
+
* agentDef() doc for the full shape and error contract. */
|
|
360
|
+
async skillDef(input, opts) {
|
|
361
|
+
return postJSON(this.ctx, "/v1/_skilldef", input, opts);
|
|
362
|
+
}
|
|
336
363
|
// ---- Internal helpers ----
|
|
337
364
|
/** Shared SSE POST → stream-of-AgentEvent path. Used by
|
|
338
365
|
* runStreaming + continueSession. */
|
package/dist/errors.d.ts
CHANGED
|
@@ -133,3 +133,22 @@ export declare class HookNotFoundError extends NotFoundError {
|
|
|
133
133
|
bodyText?: string;
|
|
134
134
|
});
|
|
135
135
|
}
|
|
136
|
+
/** SubstrateToolRefusedError — raised by `client.agentDef()` /
|
|
137
|
+
* `client.skillDef()` when the in-process tool refused the call
|
|
138
|
+
* (scope deny, empty body, allowed-tools widening, etc.). HTTP
|
|
139
|
+
* status 422 with `{code: "tool_refused", error, tool}` body.
|
|
140
|
+
*
|
|
141
|
+
* Distinct from transport failures: the request reached the
|
|
142
|
+
* server, the substrate tool ran, and the tool itself returned
|
|
143
|
+
* IsError=true. Operators catching this error should surface the
|
|
144
|
+
* reason in `message` to the calling agent / user rather than
|
|
145
|
+
* retrying. */
|
|
146
|
+
export declare class SubstrateToolRefusedError extends LoomcycleError {
|
|
147
|
+
/** Which substrate tool refused — "AgentDef" or "SkillDef". */
|
|
148
|
+
readonly tool: string;
|
|
149
|
+
constructor(message: string, opts?: {
|
|
150
|
+
status?: number;
|
|
151
|
+
bodyText?: string;
|
|
152
|
+
tool?: string;
|
|
153
|
+
});
|
|
154
|
+
}
|
package/dist/errors.js
CHANGED
|
@@ -136,3 +136,22 @@ export class HookNotFoundError extends NotFoundError {
|
|
|
136
136
|
this.name = "HookNotFoundError";
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
|
+
/** SubstrateToolRefusedError — raised by `client.agentDef()` /
|
|
140
|
+
* `client.skillDef()` when the in-process tool refused the call
|
|
141
|
+
* (scope deny, empty body, allowed-tools widening, etc.). HTTP
|
|
142
|
+
* status 422 with `{code: "tool_refused", error, tool}` body.
|
|
143
|
+
*
|
|
144
|
+
* Distinct from transport failures: the request reached the
|
|
145
|
+
* server, the substrate tool ran, and the tool itself returned
|
|
146
|
+
* IsError=true. Operators catching this error should surface the
|
|
147
|
+
* reason in `message` to the calling agent / user rather than
|
|
148
|
+
* retrying. */
|
|
149
|
+
export class SubstrateToolRefusedError extends LoomcycleError {
|
|
150
|
+
/** Which substrate tool refused — "AgentDef" or "SkillDef". */
|
|
151
|
+
tool;
|
|
152
|
+
constructor(message, opts) {
|
|
153
|
+
super(message, opts);
|
|
154
|
+
this.name = "SubstrateToolRefusedError";
|
|
155
|
+
this.tool = opts?.tool ?? "";
|
|
156
|
+
}
|
|
157
|
+
}
|
package/dist/fetch-helpers.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* Method-level code in client.ts stays focused on URL + body shape;
|
|
10
10
|
* the boring fetch + error-translation machinery lives here.
|
|
11
11
|
*/
|
|
12
|
-
import { AgentIDInUseError, AgentNotFoundError, AlreadyPausingError, AuthError, BackpressureError, HookNotFoundError, InvalidArgumentError, LoomcycleError, NotFoundError, NotPausedError, PauseNotConfiguredError, SessionBusyError, SessionNotFoundError, SnapshotNotFoundError, SnapshotTooLargeError, SnapshotVersionError, UnavailableError, } from "./errors.js";
|
|
12
|
+
import { AgentIDInUseError, AgentNotFoundError, AlreadyPausingError, AuthError, BackpressureError, HookNotFoundError, InvalidArgumentError, LoomcycleError, NotFoundError, NotPausedError, PauseNotConfiguredError, SessionBusyError, SessionNotFoundError, SnapshotNotFoundError, SnapshotTooLargeError, SnapshotVersionError, SubstrateToolRefusedError, UnavailableError, } from "./errors.js";
|
|
13
13
|
/** authHeaders builds the standard request header set: JSON Accept
|
|
14
14
|
* + Bearer token when the client was constructed with one. The
|
|
15
15
|
* caller adds Content-Type when posting a body. */
|
|
@@ -164,8 +164,25 @@ export async function raiseFromResponse(resp) {
|
|
|
164
164
|
throw new LoomcycleError(msg, opts);
|
|
165
165
|
case 413:
|
|
166
166
|
throw new SnapshotTooLargeError(msg, opts);
|
|
167
|
-
case 422:
|
|
167
|
+
case 422: {
|
|
168
|
+
// 422 is shared between snapshot version errors (existing)
|
|
169
|
+
// and v0.8.22 substrate tool refusals. Discriminate by body:
|
|
170
|
+
// the substrate path returns `{code: "tool_refused", tool,
|
|
171
|
+
// error}` JSON; the snapshot path returns a free-form text.
|
|
172
|
+
try {
|
|
173
|
+
const parsed = JSON.parse(bodyText);
|
|
174
|
+
if (parsed.code === "tool_refused") {
|
|
175
|
+
throw new SubstrateToolRefusedError(parsed.error ?? msg, { status, bodyText, tool: parsed.tool });
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
catch (e) {
|
|
179
|
+
// Re-throw our typed error if we matched; fall through to
|
|
180
|
+
// SnapshotVersionError on any JSON-parse failure.
|
|
181
|
+
if (e instanceof SubstrateToolRefusedError)
|
|
182
|
+
throw e;
|
|
183
|
+
}
|
|
168
184
|
throw new SnapshotVersionError(msg, opts);
|
|
185
|
+
}
|
|
169
186
|
case 429:
|
|
170
187
|
throw new BackpressureError(msg, opts);
|
|
171
188
|
case 503:
|
package/dist/index.d.ts
CHANGED
|
@@ -42,6 +42,10 @@
|
|
|
42
42
|
* listRunInterrupts(runId, opts?): Promise<InterruptListResponse>
|
|
43
43
|
* resolveInterrupt(runId, interruptId, opts): Promise<unknown>
|
|
44
44
|
*
|
|
45
|
+
* // Substrate admin (v0.8.22)
|
|
46
|
+
* agentDef(input): Promise<SubstrateToolResponse>
|
|
47
|
+
* skillDef(input): Promise<SubstrateToolResponse>
|
|
48
|
+
*
|
|
45
49
|
* Errors (typed subclasses of LoomcycleError; see README for the
|
|
46
50
|
* full HTTP-status → typed-error mapping table):
|
|
47
51
|
* LoomcycleError, AgentNotFoundError, SessionNotFoundError,
|
|
@@ -49,7 +53,8 @@
|
|
|
49
53
|
* AuthError, UnavailableError, InvalidArgumentError,
|
|
50
54
|
* PauseNotConfiguredError (subclass of UnavailableError),
|
|
51
55
|
* AlreadyPausingError, NotPausedError, SnapshotNotFoundError,
|
|
52
|
-
* SnapshotTooLargeError, SnapshotVersionError
|
|
56
|
+
* SnapshotTooLargeError, SnapshotVersionError,
|
|
57
|
+
* SubstrateToolRefusedError (v0.8.22)
|
|
53
58
|
*
|
|
54
59
|
* Transport: HTTP+SSE. Auth: Bearer token via the Authorization
|
|
55
60
|
* header. Designed for Node ≥18 (engines pinned); Bun/Deno likely
|
|
@@ -59,5 +64,5 @@
|
|
|
59
64
|
* See `adapters/ts/README.md` for usage examples.
|
|
60
65
|
*/
|
|
61
66
|
export { LoomcycleClient } from "./client.js";
|
|
62
|
-
export type { AgentEvent, ClientOptions, ContinueOptions, EventType, HostWidening, PromptContent, PromptSegment, RetryInfo, RunOptions, ToolUse, Usage, Agent, AgentStatus, AgentUsage, CancelAgentResult, ListAgentsResponse, TranscriptEvent, TranscriptResponse, HealthResponse, ListUsersResponse, UserSummary, PauseResult, ResumeResult, RuntimeStateResponse, RuntimeStateStatus, CreateSnapshotOptions, SnapshotCreateResponse, SnapshotDescriptor, SnapshotEnvelope, SnapshotListResponse, SnapshotRestoreResponse, MemoryEntriesResponse, MemoryEntry, MemoryEntryResponse, MemoryScopeIDsResponse, MemoryScopeIDSummary, MemoryScopeKind, MemoryScopesResponse, InterruptListResponse, InterruptRow, InterruptStatus, ResolveInterruptOptions, Hook, HookFailMode, HookPhase, HookToolCall, HookToolResult, ListHooksResponse, PostHookCall, PostHookResult, PreHookCall, PreHookResult, RegisterHookOptions, RegisterHookResponse, } from "./types.js";
|
|
63
|
-
export { AgentIDInUseError, AgentNotFoundError, AlreadyPausingError, AuthError, BackpressureError, HookNotFoundError, NotFoundError, InvalidArgumentError, LoomcycleError, NotPausedError, PauseNotConfiguredError, SessionBusyError, SessionNotFoundError, SnapshotNotFoundError, SnapshotTooLargeError, SnapshotVersionError, UnavailableError, } from "./errors.js";
|
|
67
|
+
export type { AgentEvent, ClientOptions, ContinueOptions, EventType, HostWidening, PromptContent, PromptSegment, RetryInfo, RunOptions, ToolUse, Usage, Agent, AgentStatus, AgentUsage, CancelAgentResult, ListAgentsResponse, TranscriptEvent, TranscriptResponse, HealthResponse, ListUsersResponse, UserSummary, PauseResult, ResumeResult, RuntimeStateResponse, RuntimeStateStatus, CreateSnapshotOptions, SnapshotCreateResponse, SnapshotDescriptor, SnapshotEnvelope, SnapshotListResponse, SnapshotRestoreResponse, MemoryEntriesResponse, MemoryEntry, MemoryEntryResponse, MemoryScopeIDsResponse, MemoryScopeIDSummary, MemoryScopeKind, MemoryScopesResponse, InterruptListResponse, InterruptRow, InterruptStatus, ResolveInterruptOptions, Hook, HookFailMode, HookPhase, HookToolCall, HookToolResult, ListHooksResponse, PostHookCall, PostHookResult, PreHookCall, PreHookResult, RegisterHookOptions, RegisterHookResponse, SubstrateToolInput, SubstrateToolResponse, } from "./types.js";
|
|
68
|
+
export { AgentIDInUseError, AgentNotFoundError, AlreadyPausingError, AuthError, BackpressureError, HookNotFoundError, NotFoundError, InvalidArgumentError, LoomcycleError, NotPausedError, PauseNotConfiguredError, SessionBusyError, SessionNotFoundError, SnapshotNotFoundError, SnapshotTooLargeError, SnapshotVersionError, SubstrateToolRefusedError, UnavailableError, } from "./errors.js";
|
package/dist/index.js
CHANGED
|
@@ -42,6 +42,10 @@
|
|
|
42
42
|
* listRunInterrupts(runId, opts?): Promise<InterruptListResponse>
|
|
43
43
|
* resolveInterrupt(runId, interruptId, opts): Promise<unknown>
|
|
44
44
|
*
|
|
45
|
+
* // Substrate admin (v0.8.22)
|
|
46
|
+
* agentDef(input): Promise<SubstrateToolResponse>
|
|
47
|
+
* skillDef(input): Promise<SubstrateToolResponse>
|
|
48
|
+
*
|
|
45
49
|
* Errors (typed subclasses of LoomcycleError; see README for the
|
|
46
50
|
* full HTTP-status → typed-error mapping table):
|
|
47
51
|
* LoomcycleError, AgentNotFoundError, SessionNotFoundError,
|
|
@@ -49,7 +53,8 @@
|
|
|
49
53
|
* AuthError, UnavailableError, InvalidArgumentError,
|
|
50
54
|
* PauseNotConfiguredError (subclass of UnavailableError),
|
|
51
55
|
* AlreadyPausingError, NotPausedError, SnapshotNotFoundError,
|
|
52
|
-
* SnapshotTooLargeError, SnapshotVersionError
|
|
56
|
+
* SnapshotTooLargeError, SnapshotVersionError,
|
|
57
|
+
* SubstrateToolRefusedError (v0.8.22)
|
|
53
58
|
*
|
|
54
59
|
* Transport: HTTP+SSE. Auth: Bearer token via the Authorization
|
|
55
60
|
* header. Designed for Node ≥18 (engines pinned); Bun/Deno likely
|
|
@@ -59,4 +64,4 @@
|
|
|
59
64
|
* See `adapters/ts/README.md` for usage examples.
|
|
60
65
|
*/
|
|
61
66
|
export { LoomcycleClient } from "./client.js";
|
|
62
|
-
export { AgentIDInUseError, AgentNotFoundError, AlreadyPausingError, AuthError, BackpressureError, HookNotFoundError, NotFoundError, InvalidArgumentError, LoomcycleError, NotPausedError, PauseNotConfiguredError, SessionBusyError, SessionNotFoundError, SnapshotNotFoundError, SnapshotTooLargeError, SnapshotVersionError, UnavailableError, } from "./errors.js";
|
|
67
|
+
export { AgentIDInUseError, AgentNotFoundError, AlreadyPausingError, AuthError, BackpressureError, HookNotFoundError, NotFoundError, InvalidArgumentError, LoomcycleError, NotPausedError, PauseNotConfiguredError, SessionBusyError, SessionNotFoundError, SnapshotNotFoundError, SnapshotTooLargeError, SnapshotVersionError, SubstrateToolRefusedError, UnavailableError, } from "./errors.js";
|
package/dist/types.d.ts
CHANGED
|
@@ -472,6 +472,31 @@ export interface PostHookCall {
|
|
|
472
472
|
tool_call: HookToolCall;
|
|
473
473
|
tool_result: HookToolResult;
|
|
474
474
|
}
|
|
475
|
+
/** Input shape for {@link LoomcycleClient.agentDef} and
|
|
476
|
+
* {@link LoomcycleClient.skillDef}. Mirrors the in-process tool
|
|
477
|
+
* input — `op` discriminates create / fork / get / list / promote
|
|
478
|
+
* / retire and the remaining fields are op-specific.
|
|
479
|
+
*
|
|
480
|
+
* Typed loosely because the in-process tool owns the full schema;
|
|
481
|
+
* the adapter doesn't re-validate. Use the optional `extra` index
|
|
482
|
+
* signature for forward-compat fields. */
|
|
483
|
+
export type SubstrateToolInput = {
|
|
484
|
+
op: "create" | "fork" | "get" | "list" | "promote" | "retire";
|
|
485
|
+
name?: string;
|
|
486
|
+
def_id?: string;
|
|
487
|
+
parent_def_id?: string;
|
|
488
|
+
overlay?: Record<string, unknown>;
|
|
489
|
+
description?: string;
|
|
490
|
+
promote?: boolean;
|
|
491
|
+
retired?: boolean;
|
|
492
|
+
[extra: string]: unknown;
|
|
493
|
+
};
|
|
494
|
+
/** Response shape for {@link LoomcycleClient.agentDef} and
|
|
495
|
+
* {@link LoomcycleClient.skillDef}. `unknown` because the shape
|
|
496
|
+
* varies per op — create/fork return a row envelope, list returns
|
|
497
|
+
* `{name, versions: [...]}`, promote/retire return summary shapes.
|
|
498
|
+
* Callers narrow as needed. */
|
|
499
|
+
export type SubstrateToolResponse = unknown;
|
|
475
500
|
/** Response a Post webhook returns. When result is omitted the tool
|
|
476
501
|
* result passes through unchanged. */
|
|
477
502
|
export interface PostHookResult {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loomcycle/client",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "TypeScript client for the loomcycle sidecar (HTTP+SSE).
|
|
3
|
+
"version": "0.9.0",
|
|
4
|
+
"description": "TypeScript client for the loomcycle sidecar (HTTP+SSE). 29 methods covering run streaming, agent metadata, pause/resume/state, snapshot lifecycle, memory admin (incl. v0.9.0 Vector Memory embed_stats + reembed), interruption resolve, hook management, and v0.8.22 substrate admin (agentDef + skillDef).",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"repository": {
|