@cubos/agent-sdk 0.0.1136563
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 +446 -0
- package/dist/admin/agents.d.ts +191 -0
- package/dist/admin/ai-providers.d.ts +122 -0
- package/dist/admin/channels.d.ts +261 -0
- package/dist/admin/client-tools.d.ts +74 -0
- package/dist/admin/component-libraries.d.ts +63 -0
- package/dist/admin/conversations.d.ts +434 -0
- package/dist/admin/global.d.ts +137 -0
- package/dist/admin/index.d.ts +67 -0
- package/dist/admin/knowledge-bases.d.ts +142 -0
- package/dist/admin/mcps.d.ts +134 -0
- package/dist/admin/paths.d.ts +9 -0
- package/dist/admin/skills.d.ts +43 -0
- package/dist/admin/task-templates.d.ts +185 -0
- package/dist/admin/users.d.ts +208 -0
- package/dist/cache.d.ts +68 -0
- package/dist/client-tools.d.ts +96 -0
- package/dist/client.d.ts +427 -0
- package/dist/errors.d.ts +52 -0
- package/dist/generated/schema.d.ts +13564 -0
- package/dist/http.d.ts +42 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +1826 -0
- package/dist/index.js.map +30 -0
- package/dist/mapping.d.ts +170 -0
- package/dist/schemas.d.ts +2 -0
- package/dist/sse.d.ts +48 -0
- package/dist/sse.js +209 -0
- package/dist/sse.js.map +11 -0
- package/dist/types.d.ts +263 -0
- package/package.json +51 -0
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import type { Transport } from "../http.js";
|
|
2
|
+
import type { Schemas } from "../schemas.js";
|
|
3
|
+
export declare function usersApi(t: Transport, tenantSlug: string): {
|
|
4
|
+
list: (query?: {
|
|
5
|
+
status?: string;
|
|
6
|
+
role?: string;
|
|
7
|
+
}, signal?: AbortSignal) => Promise<{
|
|
8
|
+
created_at: string;
|
|
9
|
+
display_name: string | null;
|
|
10
|
+
first_contact_at: string | null;
|
|
11
|
+
id: string;
|
|
12
|
+
primary_identifier: string | null;
|
|
13
|
+
status: string;
|
|
14
|
+
updated_at: string;
|
|
15
|
+
user_md_length: number;
|
|
16
|
+
}[]>;
|
|
17
|
+
get: (id: string, signal?: AbortSignal) => Promise<{
|
|
18
|
+
created_at: string;
|
|
19
|
+
display_name: string | null;
|
|
20
|
+
first_contact_at: string | null;
|
|
21
|
+
id: string;
|
|
22
|
+
identities: import("../generated/schema.js").components["schemas"]["UserIdentity"][];
|
|
23
|
+
primary_identifier: string | null;
|
|
24
|
+
role_slugs: string[];
|
|
25
|
+
status: string;
|
|
26
|
+
timezone: string;
|
|
27
|
+
total_cost_usd: number;
|
|
28
|
+
updated_at: string;
|
|
29
|
+
user_md: string;
|
|
30
|
+
}>;
|
|
31
|
+
create: (input: Schemas["CreateUserInput"]) => Promise<{
|
|
32
|
+
created_at: string;
|
|
33
|
+
display_name: string | null;
|
|
34
|
+
first_contact_at: string | null;
|
|
35
|
+
id: string;
|
|
36
|
+
identities: import("../generated/schema.js").components["schemas"]["UserIdentity"][];
|
|
37
|
+
primary_identifier: string | null;
|
|
38
|
+
role_slugs: string[];
|
|
39
|
+
status: string;
|
|
40
|
+
timezone: string;
|
|
41
|
+
total_cost_usd: number;
|
|
42
|
+
updated_at: string;
|
|
43
|
+
user_md: string;
|
|
44
|
+
}>;
|
|
45
|
+
update: (id: string, input: Schemas["UpdateUserInput"]) => Promise<{
|
|
46
|
+
created_at: string;
|
|
47
|
+
display_name: string | null;
|
|
48
|
+
first_contact_at: string | null;
|
|
49
|
+
id: string;
|
|
50
|
+
identities: import("../generated/schema.js").components["schemas"]["UserIdentity"][];
|
|
51
|
+
primary_identifier: string | null;
|
|
52
|
+
role_slugs: string[];
|
|
53
|
+
status: string;
|
|
54
|
+
timezone: string;
|
|
55
|
+
total_cost_usd: number;
|
|
56
|
+
updated_at: string;
|
|
57
|
+
user_md: string;
|
|
58
|
+
}>;
|
|
59
|
+
delete: (id: string) => Promise<void>;
|
|
60
|
+
approve: (id: string, input: Schemas["ApproveUserInput"]) => Promise<{
|
|
61
|
+
created_at: string;
|
|
62
|
+
display_name: string | null;
|
|
63
|
+
first_contact_at: string | null;
|
|
64
|
+
id: string;
|
|
65
|
+
identities: import("../generated/schema.js").components["schemas"]["UserIdentity"][];
|
|
66
|
+
primary_identifier: string | null;
|
|
67
|
+
role_slugs: string[];
|
|
68
|
+
status: string;
|
|
69
|
+
timezone: string;
|
|
70
|
+
total_cost_usd: number;
|
|
71
|
+
updated_at: string;
|
|
72
|
+
user_md: string;
|
|
73
|
+
}>;
|
|
74
|
+
block: (id: string) => Promise<{
|
|
75
|
+
created_at: string;
|
|
76
|
+
display_name: string | null;
|
|
77
|
+
first_contact_at: string | null;
|
|
78
|
+
id: string;
|
|
79
|
+
identities: import("../generated/schema.js").components["schemas"]["UserIdentity"][];
|
|
80
|
+
primary_identifier: string | null;
|
|
81
|
+
role_slugs: string[];
|
|
82
|
+
status: string;
|
|
83
|
+
timezone: string;
|
|
84
|
+
total_cost_usd: number;
|
|
85
|
+
updated_at: string;
|
|
86
|
+
user_md: string;
|
|
87
|
+
}>;
|
|
88
|
+
unblock: (id: string) => Promise<{
|
|
89
|
+
created_at: string;
|
|
90
|
+
display_name: string | null;
|
|
91
|
+
first_contact_at: string | null;
|
|
92
|
+
id: string;
|
|
93
|
+
identities: import("../generated/schema.js").components["schemas"]["UserIdentity"][];
|
|
94
|
+
primary_identifier: string | null;
|
|
95
|
+
role_slugs: string[];
|
|
96
|
+
status: string;
|
|
97
|
+
timezone: string;
|
|
98
|
+
total_cost_usd: number;
|
|
99
|
+
updated_at: string;
|
|
100
|
+
user_md: string;
|
|
101
|
+
}>;
|
|
102
|
+
merge: (id: string, input: Schemas["MergeUserInput"]) => Promise<{
|
|
103
|
+
created_at: string;
|
|
104
|
+
display_name: string | null;
|
|
105
|
+
first_contact_at: string | null;
|
|
106
|
+
id: string;
|
|
107
|
+
identities: import("../generated/schema.js").components["schemas"]["UserIdentity"][];
|
|
108
|
+
primary_identifier: string | null;
|
|
109
|
+
role_slugs: string[];
|
|
110
|
+
status: string;
|
|
111
|
+
timezone: string;
|
|
112
|
+
total_cost_usd: number;
|
|
113
|
+
updated_at: string;
|
|
114
|
+
user_md: string;
|
|
115
|
+
}>;
|
|
116
|
+
attachRole: (id: string, roleSlug: string) => Promise<void>;
|
|
117
|
+
detachRole: (id: string, roleSlug: string) => Promise<void>;
|
|
118
|
+
addIdentity: (id: string, input: Schemas["CreateIdentityInput"]) => Promise<{
|
|
119
|
+
channel_type: import("../generated/schema.js").components["schemas"]["ChannelType"];
|
|
120
|
+
created_at: string;
|
|
121
|
+
id: string;
|
|
122
|
+
identifier: string;
|
|
123
|
+
label: string | null;
|
|
124
|
+
}>;
|
|
125
|
+
deleteIdentity: (id: string, identityId: string) => Promise<void>;
|
|
126
|
+
listKnowledgeBases: (id: string, signal?: AbortSignal) => Promise<{
|
|
127
|
+
created_at: string;
|
|
128
|
+
display_name: string;
|
|
129
|
+
id: string;
|
|
130
|
+
pending_count: number;
|
|
131
|
+
slug: string;
|
|
132
|
+
updated_at: string;
|
|
133
|
+
}[]>;
|
|
134
|
+
attachKnowledgeBase: (id: string, kbSlug: string) => Promise<void>;
|
|
135
|
+
detachKnowledgeBase: (id: string, kbSlug: string) => Promise<void>;
|
|
136
|
+
getMemory: (id: string, signal?: AbortSignal) => Promise<{
|
|
137
|
+
created_at: string;
|
|
138
|
+
id: string;
|
|
139
|
+
profile: string | null;
|
|
140
|
+
updated_at: string;
|
|
141
|
+
}>;
|
|
142
|
+
listMemoryObservations: (id: string, signal?: AbortSignal) => Promise<{
|
|
143
|
+
content: string;
|
|
144
|
+
id: string;
|
|
145
|
+
memory_id: string;
|
|
146
|
+
metadata: Record<string, unknown>;
|
|
147
|
+
recorded_at: string;
|
|
148
|
+
source_conversation: null | import("../generated/schema.js").components["schemas"]["ConversationRef"];
|
|
149
|
+
}[]>;
|
|
150
|
+
createMemoryObservation: (id: string, input: Schemas["CreateMemoryObservationInput"]) => Promise<{
|
|
151
|
+
content: string;
|
|
152
|
+
id: string;
|
|
153
|
+
memory_id: string;
|
|
154
|
+
metadata: Record<string, unknown>;
|
|
155
|
+
recorded_at: string;
|
|
156
|
+
source_conversation: null | import("../generated/schema.js").components["schemas"]["ConversationRef"];
|
|
157
|
+
}>;
|
|
158
|
+
deleteMemoryObservation: (id: string, observationId: string) => Promise<void>;
|
|
159
|
+
updateMemoryProfile: (id: string, input: Schemas["UpdateMemoryProfileInput"]) => Promise<{
|
|
160
|
+
profile: string | null;
|
|
161
|
+
}>;
|
|
162
|
+
};
|
|
163
|
+
export declare function userRolesApi(t: Transport, tenantSlug: string): {
|
|
164
|
+
list: (signal?: AbortSignal) => Promise<{
|
|
165
|
+
created_at: string;
|
|
166
|
+
description: string;
|
|
167
|
+
display_name: string;
|
|
168
|
+
id: string;
|
|
169
|
+
slug: string;
|
|
170
|
+
updated_at: string;
|
|
171
|
+
}[]>;
|
|
172
|
+
get: (slug: string, signal?: AbortSignal) => Promise<{
|
|
173
|
+
created_at: string;
|
|
174
|
+
description: string;
|
|
175
|
+
display_name: string;
|
|
176
|
+
id: string;
|
|
177
|
+
slug: string;
|
|
178
|
+
updated_at: string;
|
|
179
|
+
}>;
|
|
180
|
+
create: (input: Schemas["CreateUserRoleInput"]) => Promise<{
|
|
181
|
+
created_at: string;
|
|
182
|
+
description: string;
|
|
183
|
+
display_name: string;
|
|
184
|
+
id: string;
|
|
185
|
+
slug: string;
|
|
186
|
+
updated_at: string;
|
|
187
|
+
}>;
|
|
188
|
+
update: (slug: string, input: Schemas["UpdateUserRoleInput"]) => Promise<{
|
|
189
|
+
created_at: string;
|
|
190
|
+
description: string;
|
|
191
|
+
display_name: string;
|
|
192
|
+
id: string;
|
|
193
|
+
slug: string;
|
|
194
|
+
updated_at: string;
|
|
195
|
+
}>;
|
|
196
|
+
delete: (slug: string) => Promise<void>;
|
|
197
|
+
};
|
|
198
|
+
/**
|
|
199
|
+
* Mints the short-lived tokens a browser SDK runs on (see `createUserClient`).
|
|
200
|
+
* Call this from your own backend only — it needs an api_key, which must never
|
|
201
|
+
* reach a browser.
|
|
202
|
+
*/
|
|
203
|
+
export declare function userTokensApi(t: Transport, tenantSlug: string): {
|
|
204
|
+
create: (input: Schemas["CreateUserTokenInput"]) => Promise<{
|
|
205
|
+
expires_at: string;
|
|
206
|
+
token: string;
|
|
207
|
+
}>;
|
|
208
|
+
};
|
package/dist/cache.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { Message, PlanSnapshot, ToolActivity } from "./types.js";
|
|
2
|
+
/** Bumped when the cached shape changes; entries written by an older SDK are
|
|
3
|
+
* dropped rather than misread. */
|
|
4
|
+
export declare const CACHE_VERSION = 3;
|
|
5
|
+
export interface CachedConversation {
|
|
6
|
+
version: number;
|
|
7
|
+
/** Oldest first, as `listMessagesPage` returns them. */
|
|
8
|
+
messages: Message[];
|
|
9
|
+
/** The tools behind those messages, folded. Absent on entries written before
|
|
10
|
+
* the trail existed, which the version bump already invalidates — typed
|
|
11
|
+
* optional only so a hand-written cache doesn't have to supply it. */
|
|
12
|
+
toolActivity?: ToolActivity[];
|
|
13
|
+
/** Plan revisions, same optionality and the same reason. */
|
|
14
|
+
plans?: PlanSnapshot[];
|
|
15
|
+
/** Newest finished turn, so a reload does not show a turn as running. */
|
|
16
|
+
lastTurnDoneSeq?: number | null;
|
|
17
|
+
/** Highest `change_seq` folded in. Pass to `subscribe` as `since`. */
|
|
18
|
+
latestChangeSeq: number;
|
|
19
|
+
/** Cursor for the page before the oldest message held. */
|
|
20
|
+
oldestSeq: number | null;
|
|
21
|
+
hasOlder: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Where a client keeps conversations it has already loaded.
|
|
25
|
+
*
|
|
26
|
+
* Async on purpose: the in-memory default doesn't need it, but IndexedDB,
|
|
27
|
+
* AsyncStorage and SQLite all do, and a synchronous interface would shut them
|
|
28
|
+
* out. Keys are opaque strings already scoped to tenant and user by the client —
|
|
29
|
+
* an implementation must not reinterpret them.
|
|
30
|
+
*
|
|
31
|
+
* Failures should reject rather than throw synchronously; the client treats any
|
|
32
|
+
* rejection as a cache miss, so a broken store degrades to the network path
|
|
33
|
+
* instead of breaking the app.
|
|
34
|
+
*/
|
|
35
|
+
export interface ConversationCache {
|
|
36
|
+
read(key: string): Promise<CachedConversation | null>;
|
|
37
|
+
write(key: string, entry: CachedConversation): Promise<void>;
|
|
38
|
+
/** Drops one key, or everything when called with no argument. */
|
|
39
|
+
clear(key?: string): Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
export interface MemoryConversationCacheOptions {
|
|
42
|
+
/** How many conversations to retain, least-recently-used evicted first. */
|
|
43
|
+
maxConversations?: number;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The default: a bounded LRU in a `Map`, lost on reload.
|
|
47
|
+
*
|
|
48
|
+
* Bounded because the natural failure mode of a chat cache is a user who opens
|
|
49
|
+
* fifty conversations in one session and never reloads.
|
|
50
|
+
*/
|
|
51
|
+
export declare class MemoryConversationCache implements ConversationCache {
|
|
52
|
+
#private;
|
|
53
|
+
constructor(options?: MemoryConversationCacheOptions);
|
|
54
|
+
read(key: string): Promise<CachedConversation | null>;
|
|
55
|
+
write(key: string, entry: CachedConversation): Promise<void>;
|
|
56
|
+
clear(key?: string): Promise<void>;
|
|
57
|
+
/** Retained conversations. For tests and diagnostics. */
|
|
58
|
+
get size(): number;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Trims an entry to the newest `limit` messages before it is stored.
|
|
62
|
+
*
|
|
63
|
+
* Dropping the front changes what the caller may still page back to, so the
|
|
64
|
+
* cursors move with it: `oldestSeq` becomes the retained head's `seq` (the
|
|
65
|
+
* server's `before` is exclusive, so that page picks up right behind it) and
|
|
66
|
+
* `hasOlder` becomes true, because there now demonstrably is.
|
|
67
|
+
*/
|
|
68
|
+
export declare function trimCached(entry: CachedConversation, limit: number): CachedConversation;
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { Transport } from "./http.js";
|
|
2
|
+
import type { Schemas } from "./schemas.js";
|
|
3
|
+
/** One tool: its declaration and the function that implements it. */
|
|
4
|
+
export interface ClientTool<Args = Record<string, unknown>, Result = unknown> {
|
|
5
|
+
description?: string;
|
|
6
|
+
/** JSON Schema for the arguments. Defaults to an open object, which leaves
|
|
7
|
+
* the model to guess — worth writing. */
|
|
8
|
+
inputSchema?: Record<string, unknown>;
|
|
9
|
+
/** JSON Schema for what you return. The server validates against it before
|
|
10
|
+
* the model sees anything, so a bug in your handler surfaces as a rejected
|
|
11
|
+
* submit rather than as nonsense in the transcript. */
|
|
12
|
+
outputSchema?: Record<string, unknown>;
|
|
13
|
+
/** `true` promises the call mutates nothing, which exempts it from the
|
|
14
|
+
* agent's guardrail. Don't claim it lightly. */
|
|
15
|
+
readOnlyHint?: boolean;
|
|
16
|
+
destructiveHint?: boolean;
|
|
17
|
+
/** `true` promises the call is safe to run twice. Without it the server
|
|
18
|
+
* assumes it isn't, and pins the lease to the call's deadline so no second
|
|
19
|
+
* client can pick the call up mid-execution — safer, but a client that dies
|
|
20
|
+
* holds the call until it times out instead of failing over. */
|
|
21
|
+
idempotentHint?: boolean;
|
|
22
|
+
/** Seconds the server waits before failing the call on your behalf.
|
|
23
|
+
* Defaults to 90. Keep it tight: a pending call also holds back any user
|
|
24
|
+
* message that arrives meanwhile. */
|
|
25
|
+
timeoutSeconds?: number;
|
|
26
|
+
handler: (args: Args, ctx: ClientToolContext) => Promise<Result> | Result;
|
|
27
|
+
}
|
|
28
|
+
export interface ClientToolContext {
|
|
29
|
+
/** The call's id, echoed on the result. Handy for logs. */
|
|
30
|
+
toolCallId: string;
|
|
31
|
+
conversationId: string;
|
|
32
|
+
/** Aborts when the session stops, so a long handler can bail out. */
|
|
33
|
+
signal: AbortSignal;
|
|
34
|
+
}
|
|
35
|
+
export interface ServeClientToolsOptions {
|
|
36
|
+
tools: Record<string, ClientTool<never, unknown>>;
|
|
37
|
+
/** Stops the session. Same effect as calling `stop()`. */
|
|
38
|
+
signal?: AbortSignal;
|
|
39
|
+
/** Identifies this runner when leasing calls. Defaults to a random id, which
|
|
40
|
+
* is what you want unless you're deliberately resuming another runner's
|
|
41
|
+
* leases. */
|
|
42
|
+
claimant?: string;
|
|
43
|
+
/** Lease length in seconds; the runner renews at half of it. Defaults to 70.
|
|
44
|
+
* Ignored for a tool that writes and isn't declared `idempotentHint: true` —
|
|
45
|
+
* the server pins that lease to the call's deadline, because handing such a
|
|
46
|
+
* call to a second client is worse than making the first one wait. */
|
|
47
|
+
claimTtlSeconds?: number;
|
|
48
|
+
/** Skip the declaration sync — for when the tools are already declared and
|
|
49
|
+
* you only want to execute. */
|
|
50
|
+
declare?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Open the conversation's event stream to watch for calls. On by default.
|
|
53
|
+
*
|
|
54
|
+
* Turn it off when you already hold that stream — a chat UI does — and drive
|
|
55
|
+
* the session with `poke()` instead: once for every `client_tool_call` frame,
|
|
56
|
+
* and once each time the stream (re)connects. One connection instead of two,
|
|
57
|
+
* and the server caps how many a user may hold open at once.
|
|
58
|
+
*/
|
|
59
|
+
watch?: boolean;
|
|
60
|
+
/** Reported failures that the runner recovered from: a stream drop, a
|
|
61
|
+
* handler that threw. Losing a claim race is not one of them — that is
|
|
62
|
+
* ordinary coordination, and the runner keeps watching the call instead. */
|
|
63
|
+
onError?: (err: unknown) => void;
|
|
64
|
+
}
|
|
65
|
+
export interface ClientToolsSession {
|
|
66
|
+
stop(): void;
|
|
67
|
+
/**
|
|
68
|
+
* Look for calls to run, now. Cheap and safe to call spuriously: it reads the
|
|
69
|
+
* pending list, and a call already being handled is skipped.
|
|
70
|
+
*
|
|
71
|
+
* Only needed with `watch: false`, where something else owns the stream.
|
|
72
|
+
*/
|
|
73
|
+
poke(): void;
|
|
74
|
+
/** Resolves when the session has stopped and no handler is still running. */
|
|
75
|
+
done: Promise<void>;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Declares `tools` on the conversation, then executes every call the agent
|
|
79
|
+
* makes against them until stopped.
|
|
80
|
+
*
|
|
81
|
+
* `conversationPath` is a thunk rather than a string because the two clients
|
|
82
|
+
* learn the tenant differently: the operator client is constructed with the
|
|
83
|
+
* slug, while an end-user client discovers it from the token via `me()` and so
|
|
84
|
+
* can only answer asynchronously.
|
|
85
|
+
*
|
|
86
|
+
* The cycle per call is claim → handler → submit. The claim is what keeps two
|
|
87
|
+
* runners on the same conversation from both executing it; it is renewed while
|
|
88
|
+
* the handler runs, so a slow handler doesn't lose the call, and it lapses if
|
|
89
|
+
* this process dies, so the call isn't stranded either.
|
|
90
|
+
*
|
|
91
|
+
* A handler that throws submits the failure rather than swallowing it: the
|
|
92
|
+
* agent needs to hear that the tool failed, otherwise it waits out the
|
|
93
|
+
* server-side deadline for no reason.
|
|
94
|
+
*/
|
|
95
|
+
export declare function serveClientTools(t: Transport, conversationPath: () => Promise<string>, conversationId: string, options: ServeClientToolsOptions): ClientToolsSession;
|
|
96
|
+
export declare function declarations(tools: Record<string, ClientTool<never, unknown>>): Schemas["NamedClientToolInput"][];
|