@oneie/sdk 0.8.0 → 0.10.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/LICENSE +18 -0
- package/README.md +336 -190
- package/dist/auth.d.ts +102 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +156 -0
- package/dist/auth.js.map +1 -0
- package/dist/brain.d.ts +36 -0
- package/dist/brain.d.ts.map +1 -0
- package/dist/brain.js +99 -0
- package/dist/brain.js.map +1 -0
- package/dist/client.d.ts +222 -30
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +339 -173
- package/dist/client.js.map +1 -1
- package/dist/compile.d.ts +123 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +652 -0
- package/dist/compile.js.map +1 -0
- package/dist/fetch.d.ts +40 -0
- package/dist/fetch.d.ts.map +1 -0
- package/dist/fetch.js +158 -0
- package/dist/fetch.js.map +1 -0
- package/dist/generated/types.d.ts +104 -0
- package/dist/generated/types.d.ts.map +1 -0
- package/dist/generated/types.js +5 -0
- package/dist/generated/types.js.map +1 -0
- package/dist/index.d.ts +17 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/dist/meta.d.ts +45 -0
- package/dist/meta.d.ts.map +1 -0
- package/dist/meta.js +44 -0
- package/dist/meta.js.map +1 -0
- package/dist/openapi.d.ts +27 -0
- package/dist/openapi.d.ts.map +1 -0
- package/dist/openapi.js +62 -0
- package/dist/openapi.js.map +1 -0
- package/dist/pay.d.ts +2 -2
- package/dist/pay.d.ts.map +1 -1
- package/dist/pay.js +5 -5
- package/dist/pay.js.map +1 -1
- package/dist/receivers.d.ts +743 -0
- package/dist/receivers.d.ts.map +1 -0
- package/dist/receivers.js +626 -0
- package/dist/receivers.js.map +1 -0
- package/dist/schemas.d.ts +39 -0
- package/dist/schemas.d.ts.map +1 -1
- package/dist/schemas.js +26 -0
- package/dist/schemas.js.map +1 -1
- package/dist/skills.d.ts +40 -0
- package/dist/skills.d.ts.map +1 -0
- package/dist/skills.js +16 -0
- package/dist/skills.js.map +1 -0
- package/dist/soul.d.ts +10 -0
- package/dist/soul.d.ts.map +1 -0
- package/dist/soul.js +31 -0
- package/dist/soul.js.map +1 -0
- package/dist/storage.d.ts +7 -8
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +61 -33
- package/dist/storage.js.map +1 -1
- package/dist/telemetry.d.ts +9 -0
- package/dist/telemetry.d.ts.map +1 -1
- package/dist/telemetry.js +11 -0
- package/dist/telemetry.js.map +1 -1
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +4 -3
- package/dist/testing/index.js.map +1 -1
- package/dist/types.d.ts +113 -22
- package/dist/types.d.ts.map +1 -1
- package/package.json +43 -17
- package/dist/react/context.d.ts +0 -11
- package/dist/react/context.d.ts.map +0 -1
- package/dist/react/context.js +0 -13
- package/dist/react/context.js.map +0 -1
- package/dist/react/hooks.d.ts +0 -104
- package/dist/react/hooks.d.ts.map +0 -1
- package/dist/react/hooks.js +0 -247
- package/dist/react/hooks.js.map +0 -1
- package/dist/react/index.d.ts +0 -6
- package/dist/react/index.d.ts.map +0 -1
- package/dist/react/index.js +0 -5
- package/dist/react/index.js.map +0 -1
- package/dist/react/optimistic.d.ts +0 -45
- package/dist/react/optimistic.d.ts.map +0 -1
- package/dist/react/optimistic.js +0 -52
- package/dist/react/optimistic.js.map +0 -1
- package/dist/react/stream.d.ts +0 -18
- package/dist/react/stream.d.ts.map +0 -1
- package/dist/react/stream.js +0 -60
- package/dist/react/stream.js.map +0 -1
package/dist/client.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { accept as payAccept, request as payRequest, status as payStatus } from "./pay.js";
|
|
2
|
+
import { skillsImport } from "./skills.js";
|
|
3
|
+
import { getToken, clearToken } from "./storage.js";
|
|
2
4
|
import { AuthError, RateLimitError, SubstrateError, TimeoutError, ValidationError } from "./errors.js";
|
|
3
5
|
import { resolveApiKey, resolveBaseUrl } from "./urls.js";
|
|
4
6
|
import { emit } from "./telemetry.js";
|
|
@@ -41,9 +43,14 @@ async function withRetry(fn, config) {
|
|
|
41
43
|
}
|
|
42
44
|
async function req(baseUrl, path, init = {}, apiKey) {
|
|
43
45
|
const headers = { "Content-Type": "application/json" };
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
// Prefer explicit API key; fall back to persisted session token.
|
|
47
|
+
const bearer = apiKey ?? getToken();
|
|
48
|
+
if (bearer)
|
|
49
|
+
headers["Authorization"] = `Bearer ${bearer}`;
|
|
46
50
|
const res = await fetch(`${baseUrl}${path}`, { ...init, headers });
|
|
51
|
+
// On 401, the persisted token is no longer valid — clear it so the caller gets a clean state.
|
|
52
|
+
if (res.status === 401)
|
|
53
|
+
clearToken();
|
|
47
54
|
if (!res.ok)
|
|
48
55
|
throwForStatus(res.status, init.method ?? "GET", path);
|
|
49
56
|
return res.json();
|
|
@@ -55,6 +62,8 @@ export class SubstrateClient {
|
|
|
55
62
|
validateMode;
|
|
56
63
|
/** Pay module — accept, request, status. Bound to this client's baseUrl + apiKey. */
|
|
57
64
|
pay;
|
|
65
|
+
/** Skills module — import a skill by ref or content. */
|
|
66
|
+
skills;
|
|
58
67
|
constructor(cfg = {}) {
|
|
59
68
|
this.baseUrl = resolveBaseUrl(cfg.baseUrl);
|
|
60
69
|
this.apiKey = resolveApiKey(cfg.apiKey);
|
|
@@ -66,6 +75,10 @@ export class SubstrateClient {
|
|
|
66
75
|
request: (opts) => payRequest(opts, cfg),
|
|
67
76
|
status: (ref) => payStatus(ref, cfg),
|
|
68
77
|
};
|
|
78
|
+
// Bind skills module methods to this client's resolved baseUrl + apiKey
|
|
79
|
+
this.skills = {
|
|
80
|
+
import: (opts) => skillsImport({ baseUrl: this.baseUrl, apiKey: this.apiKey ?? "" }, opts),
|
|
81
|
+
};
|
|
69
82
|
}
|
|
70
83
|
static fromApiKey(key, baseUrl) {
|
|
71
84
|
return new SubstrateClient({ apiKey: key, baseUrl });
|
|
@@ -73,14 +86,17 @@ export class SubstrateClient {
|
|
|
73
86
|
r(path, init = {}) {
|
|
74
87
|
return withRetry(() => req(this.baseUrl, path, init, this.apiKey), this.retryConfig);
|
|
75
88
|
}
|
|
76
|
-
async signal(
|
|
77
|
-
const result = await this.r(
|
|
89
|
+
async signal(receiver, data) {
|
|
90
|
+
const result = await this.r(`/api/signal/${encodeURIComponent(receiver)}`, { method: "POST", body: JSON.stringify({ data }) });
|
|
78
91
|
emit("toolkit:sdk:signal", ["sdk", "method-signal", result.success ? "200" : "error"]);
|
|
79
92
|
return result;
|
|
80
93
|
}
|
|
81
|
-
async
|
|
94
|
+
async emitAgentEvent(slug, agentId, event, payload) {
|
|
95
|
+
return this.r("/api/agent-events", { method: "POST", body: JSON.stringify({ slug, agentId, event: `custom:${event}`, payload }) });
|
|
96
|
+
}
|
|
97
|
+
async ask(receiver, data, timeoutMs) {
|
|
82
98
|
const t = Date.now();
|
|
83
|
-
const raw = await this.r(
|
|
99
|
+
const raw = await this.r(`/api/ask/${encodeURIComponent(receiver)}`, { method: "POST", body: JSON.stringify({ data, timeoutMs }) });
|
|
84
100
|
const kind = "result" in raw ? "result"
|
|
85
101
|
: "timeout" in raw ? "timeout"
|
|
86
102
|
: "dissolved" in raw ? "dissolved"
|
|
@@ -89,142 +105,341 @@ export class SubstrateClient {
|
|
|
89
105
|
emit("toolkit:sdk:ask", ["sdk", "method-ask", `outcome-${kind}`], { latencyMs: Date.now() - t });
|
|
90
106
|
return result;
|
|
91
107
|
}
|
|
92
|
-
async mark(edge,
|
|
93
|
-
const result = await this.r(
|
|
108
|
+
async mark(edge, strength = 1) {
|
|
109
|
+
const result = await this.r(`/api/mark/${encodeURIComponent(edge)}`, { method: "POST", body: JSON.stringify({ strength }) });
|
|
94
110
|
emit("toolkit:sdk:mark", ["sdk", "method-mark"]);
|
|
95
111
|
return result;
|
|
96
112
|
}
|
|
97
|
-
async warn(edge,
|
|
98
|
-
const result = await this.r(
|
|
113
|
+
async warn(edge, strength = 1) {
|
|
114
|
+
const result = await this.r(`/api/warn/${encodeURIComponent(edge)}`, { method: "POST", body: JSON.stringify({ strength }) });
|
|
99
115
|
emit("toolkit:sdk:warn", ["sdk", "method-warn"]);
|
|
100
116
|
return result;
|
|
101
117
|
}
|
|
102
|
-
async fade(
|
|
103
|
-
const result = await this.r("/api/
|
|
118
|
+
async fade(rate) {
|
|
119
|
+
const result = await this.r("/api/fade", { method: "POST", body: JSON.stringify({ rate }) });
|
|
104
120
|
emit("toolkit:sdk:fade", ["sdk", "method-fade"]);
|
|
105
121
|
return result;
|
|
106
122
|
}
|
|
107
|
-
async highways(limit =
|
|
108
|
-
const
|
|
123
|
+
async highways(limit = 50, from) {
|
|
124
|
+
const params = new URLSearchParams({ limit: String(limit) });
|
|
125
|
+
if (from)
|
|
126
|
+
params.set("from", from);
|
|
127
|
+
const result = await this.r(`/api/export/highways?${params}`);
|
|
109
128
|
emit("toolkit:sdk:highways", ["sdk", "method-highways"]);
|
|
110
129
|
return result;
|
|
111
130
|
}
|
|
112
|
-
async recall(status) {
|
|
113
|
-
const
|
|
114
|
-
|
|
131
|
+
async recall(status, search, limit = 20) {
|
|
132
|
+
const params = new URLSearchParams({ limit: String(limit) });
|
|
133
|
+
if (status)
|
|
134
|
+
params.set("status", status);
|
|
135
|
+
if (search)
|
|
136
|
+
params.set("search", search);
|
|
137
|
+
const result = await this.r(`/api/learning?${params}`);
|
|
115
138
|
emit("toolkit:sdk:recall", ["sdk", "method-recall"]);
|
|
116
139
|
return result;
|
|
117
140
|
}
|
|
118
|
-
async reveal(uid) {
|
|
119
|
-
const
|
|
141
|
+
async reveal(uid, field) {
|
|
142
|
+
const qs = field ? `?field=${encodeURIComponent(field)}` : "";
|
|
143
|
+
const result = await this.r(`/api/pii/reveal/${encodeURIComponent(uid)}${qs}`);
|
|
120
144
|
emit("toolkit:sdk:reveal", ["sdk", "method-reveal"]);
|
|
121
145
|
return result;
|
|
122
146
|
}
|
|
123
|
-
async forget(uid) {
|
|
124
|
-
const result = await this.r(
|
|
147
|
+
async forget(uid, source) {
|
|
148
|
+
const result = await this.r("/api/forget", { method: "POST", body: JSON.stringify({ actorId: uid, source: source ?? "sdk" }) });
|
|
125
149
|
emit("toolkit:sdk:forget", ["sdk", "method-forget"]);
|
|
126
150
|
return result;
|
|
127
151
|
}
|
|
128
|
-
async frontier(
|
|
129
|
-
const result = await this.r(`/api/
|
|
152
|
+
async frontier(limit = 50) {
|
|
153
|
+
const result = await this.r(`/api/frontiers?limit=${limit}`);
|
|
130
154
|
emit("toolkit:sdk:frontier", ["sdk", "method-frontier"]);
|
|
131
155
|
return result;
|
|
132
156
|
}
|
|
133
|
-
async
|
|
134
|
-
const result = await this.r(
|
|
135
|
-
emit("toolkit:sdk:
|
|
157
|
+
async follow(tag) {
|
|
158
|
+
const result = await this.r(`/api/follow?tag=${encodeURIComponent(tag)}`);
|
|
159
|
+
emit("toolkit:sdk:follow", ["sdk", "method-follow"]);
|
|
136
160
|
return result;
|
|
137
161
|
}
|
|
162
|
+
/** @deprecated No server-side tick endpoint. Use fade() on a schedule instead. */
|
|
163
|
+
async know() {
|
|
164
|
+
return {};
|
|
165
|
+
}
|
|
138
166
|
async walletFor(uid) {
|
|
139
|
-
const result = await this.
|
|
167
|
+
const result = await this.ask("identity:address", { uid });
|
|
140
168
|
emit("toolkit:sdk:walletFor", ["sdk", "method-walletFor", "stage:wallet"]);
|
|
141
|
-
return
|
|
169
|
+
return "result" in result && result.result ? result.result : { uid, address: "" };
|
|
142
170
|
}
|
|
143
171
|
async signIn(opts) {
|
|
144
|
-
const result = await this.
|
|
172
|
+
const result = await this.ask("auth:sign-in", opts);
|
|
145
173
|
emit("toolkit:sdk:signIn", ["sdk", "method-signIn", "stage:sign-in:human"]);
|
|
146
|
-
return result;
|
|
174
|
+
return "result" in result && result.result ? result.result : { sessionId: "", userId: "" };
|
|
147
175
|
}
|
|
148
176
|
async signOut() {
|
|
149
|
-
await this.
|
|
177
|
+
await this.signal("auth:sign-out");
|
|
150
178
|
emit("toolkit:sdk:signOut", ["sdk", "method-signOut", "stage:sign-in:human"]);
|
|
151
179
|
}
|
|
152
180
|
async join(opts) {
|
|
153
|
-
const result = await this.
|
|
181
|
+
const result = await this.ask("board:join", opts);
|
|
154
182
|
emit("toolkit:sdk:join", ["sdk", "method-join", "stage:join-board"]);
|
|
155
|
-
return result;
|
|
183
|
+
return "result" in result && result.result ? result.result : { ok: false, uid: opts.uid, group: opts.group ?? "", role: "" };
|
|
156
184
|
}
|
|
157
185
|
async createGroup(opts) {
|
|
158
|
-
const
|
|
186
|
+
const { parentGid, ...rest } = opts;
|
|
187
|
+
const result = await this.r("/api/groups", { method: "POST", body: JSON.stringify({ ...rest, parent_gid: parentGid }) });
|
|
159
188
|
emit("toolkit:sdk:createGroup", ["sdk", "method-createGroup", "stage:groups"]);
|
|
160
189
|
return result;
|
|
161
190
|
}
|
|
191
|
+
/** Change a member's role in a group (C2). Escalation-guarded server-side. */
|
|
192
|
+
async changeRole(gid, aid, role) {
|
|
193
|
+
const result = await this.r("/api/groups/members", { method: "PUT", body: JSON.stringify({ gid, aid, role }) });
|
|
194
|
+
emit("toolkit:sdk:changeRole", ["sdk", "method-changeRole", "stage:groups"]);
|
|
195
|
+
return result;
|
|
196
|
+
}
|
|
197
|
+
/** Remove a member from a group (C3). The sole owner cannot be removed. */
|
|
198
|
+
async removeMember(gid, aid) {
|
|
199
|
+
const result = await this.r("/api/groups/members", { method: "DELETE", body: JSON.stringify({ gid, aid }) });
|
|
200
|
+
emit("toolkit:sdk:removeMember", ["sdk", "method-removeMember", "stage:groups"]);
|
|
201
|
+
return result;
|
|
202
|
+
}
|
|
162
203
|
async listGroups() {
|
|
163
204
|
const result = await this.r("/api/groups");
|
|
164
205
|
emit("toolkit:sdk:listGroups", ["sdk", "method-listGroups", "stage:groups"]);
|
|
165
206
|
return result;
|
|
166
207
|
}
|
|
208
|
+
/**
|
|
209
|
+
* Provision a client workspace in one call. Thin sugar over POST /api/groups:
|
|
210
|
+
* the endpoint already creates the child group, writes the parent hierarchy
|
|
211
|
+
* edge, seeds the owner membership, and (when inviteEmail is given) issues an
|
|
212
|
+
* admin invite credential — all atomically. Cross-workspace escalation is
|
|
213
|
+
* guarded server-side (the agency must be an ancestor of the new client).
|
|
214
|
+
*/
|
|
215
|
+
async provisionClient(opts) {
|
|
216
|
+
const result = await this.r("/api/groups", {
|
|
217
|
+
method: "POST",
|
|
218
|
+
body: JSON.stringify({
|
|
219
|
+
name: opts.name,
|
|
220
|
+
handle: opts.handle,
|
|
221
|
+
type: "client",
|
|
222
|
+
parent_gid: opts.parentGid,
|
|
223
|
+
invite_email: opts.inviteEmail,
|
|
224
|
+
plan: opts.plan,
|
|
225
|
+
}),
|
|
226
|
+
});
|
|
227
|
+
emit("toolkit:sdk:provisionClient", ["sdk", "method-provisionClient", "stage:groups"]);
|
|
228
|
+
return result;
|
|
229
|
+
}
|
|
167
230
|
async joinGroup(gid) {
|
|
168
|
-
|
|
231
|
+
await this.signal("groups:join", { gid });
|
|
169
232
|
emit("toolkit:sdk:joinGroup", ["sdk", "method-joinGroup", "stage:groups"]);
|
|
170
|
-
return
|
|
233
|
+
return { ok: true, gid, role: "member" };
|
|
171
234
|
}
|
|
172
235
|
async leaveGroup(gid) {
|
|
173
|
-
|
|
236
|
+
await this.signal("groups:leave", { gid });
|
|
174
237
|
emit("toolkit:sdk:leaveGroup", ["sdk", "method-leaveGroup", "stage:groups"]);
|
|
175
|
-
return
|
|
238
|
+
return { ok: true };
|
|
176
239
|
}
|
|
177
240
|
async groupMembers(gid) {
|
|
178
|
-
const result = await this.
|
|
241
|
+
const result = await this.ask("groups:members", { gid });
|
|
179
242
|
emit("toolkit:sdk:groupMembers", ["sdk", "method-groupMembers", "stage:groups"]);
|
|
180
|
-
return result;
|
|
243
|
+
return "result" in result && result.result ? result.result : { gid, members: [] };
|
|
181
244
|
}
|
|
182
245
|
async inviteMember(gid, uid, role = "member") {
|
|
183
|
-
|
|
246
|
+
await this.signal("groups:invite", { gid, uid, role });
|
|
184
247
|
emit("toolkit:sdk:inviteMember", ["sdk", "method-inviteMember", "stage:groups"]);
|
|
185
|
-
return
|
|
248
|
+
return { ok: true };
|
|
186
249
|
}
|
|
187
250
|
async bridge(from, to) {
|
|
188
|
-
const result = await this.
|
|
251
|
+
const result = await this.ask("paths:bridge", { from, to });
|
|
189
252
|
emit("toolkit:sdk:bridge", ["sdk", "method-bridge", "stage:groups"]);
|
|
190
|
-
return result;
|
|
253
|
+
return "result" in result && result.result ? result.result : {};
|
|
191
254
|
}
|
|
192
255
|
async inbox(uid, opts) {
|
|
193
|
-
const
|
|
194
|
-
if (opts?.limit !== undefined)
|
|
195
|
-
params.set("limit", String(opts.limit));
|
|
196
|
-
if (opts?.before !== undefined)
|
|
197
|
-
params.set("before", opts.before);
|
|
198
|
-
const qs = params.size ? `?${params}` : "";
|
|
199
|
-
const result = await this.r(`/api/inbox/${encodeURIComponent(uid)}${qs}`);
|
|
256
|
+
const result = await this.ask(`inbox:${uid}`, opts);
|
|
200
257
|
emit("toolkit:sdk:inbox", ["sdk", "method-inbox", "stage:groups"]);
|
|
258
|
+
return "result" in result && result.result ? result.result : { uid, signals: [] };
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Publish an agent.md to a workspace. The content is the full markdown
|
|
262
|
+
* (frontmatter + body). The server writes it to R2 at
|
|
263
|
+
* `{slug}/agents/{name}.md` and the next chat request loads it as the
|
|
264
|
+
* system prompt.
|
|
265
|
+
*
|
|
266
|
+
* Auth: this method requires the SDK to be configured with a token whose
|
|
267
|
+
* scope includes the target slug (use `<slug>:<token>` for owner-scoped
|
|
268
|
+
* publishes, or the SERVER_SECRET for CI/internal tooling).
|
|
269
|
+
*
|
|
270
|
+
* Mirrors the CLI flow: `oneie agent publish --slug <slug> <path>`.
|
|
271
|
+
*/
|
|
272
|
+
async publishAgent(opts) {
|
|
273
|
+
const result = await this.r("/api/agents/publish", { method: "POST", body: JSON.stringify(opts) });
|
|
274
|
+
emit("toolkit:sdk:publishAgent", ["sdk", "method-publishAgent", "stage:author:publish"]);
|
|
275
|
+
return result;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Pull a previously published agent.md back from the workspace. Returns
|
|
279
|
+
* the file content verbatim — caller decides whether to write to disk,
|
|
280
|
+
* diff, or hand to compileAgent. Auth: same Bearer scope as publishAgent.
|
|
281
|
+
*/
|
|
282
|
+
async pullAgent(opts) {
|
|
283
|
+
const qs = `slug=${encodeURIComponent(opts.slug)}&name=${encodeURIComponent(opts.name)}`;
|
|
284
|
+
const result = await this.r(`/api/agents/publish?${qs}`, { method: "GET" });
|
|
285
|
+
emit("toolkit:sdk:pullAgent", ["sdk", "method-pullAgent", "stage:author:pull"]);
|
|
286
|
+
return result;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Unpublish — remove a previously uploaded agent from the workspace.
|
|
290
|
+
* Idempotent: deleting a non-existent agent returns ok with removed=false.
|
|
291
|
+
*/
|
|
292
|
+
async unpublishAgent(opts) {
|
|
293
|
+
const qs = `slug=${encodeURIComponent(opts.slug)}&name=${encodeURIComponent(opts.name)}`;
|
|
294
|
+
const result = await this.r(`/api/agents/publish?${qs}`, { method: "DELETE" });
|
|
295
|
+
emit("toolkit:sdk:unpublishAgent", ["sdk", "method-unpublishAgent", "stage:author:unpublish"]);
|
|
201
296
|
return result;
|
|
202
297
|
}
|
|
203
298
|
async deployOnBehalf(opts) {
|
|
204
|
-
const result = await this.
|
|
299
|
+
const result = await this.ask("agents:deploy-on-behalf", opts);
|
|
205
300
|
emit("toolkit:sdk:deployOnBehalf", ["sdk", "method-deployOnBehalf", "stage:team-deploy:on-behalf"]);
|
|
301
|
+
return "result" in result && result.result ? result.result : { ok: false, uid: "", owner: opts.owner, inheritedPaths: [] };
|
|
302
|
+
}
|
|
303
|
+
async sub(opts) {
|
|
304
|
+
await this.signal("subscriptions:register", opts);
|
|
305
|
+
emit("toolkit:sdk:sub", ["sdk", "method-sub", "stage:subscribe"]);
|
|
306
|
+
return { ok: true };
|
|
307
|
+
}
|
|
308
|
+
/** @deprecated Use sub() */
|
|
309
|
+
subscribe = this.sub;
|
|
310
|
+
async select(tag) {
|
|
311
|
+
const qs = tag ? `?tag=${encodeURIComponent(tag)}` : "";
|
|
312
|
+
const result = await this.r(`/api/select${qs}`);
|
|
313
|
+
emit("toolkit:sdk:select", ["sdk", "method-select"]);
|
|
206
314
|
return result;
|
|
207
315
|
}
|
|
208
|
-
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
|
|
316
|
+
groups(filters) {
|
|
317
|
+
const self = this;
|
|
318
|
+
const q = new URLSearchParams();
|
|
319
|
+
if (filters?.type)
|
|
320
|
+
q.set('type', filters.type);
|
|
321
|
+
if (filters?.after)
|
|
322
|
+
q.set('after', filters.after);
|
|
323
|
+
if (filters?.limit)
|
|
324
|
+
q.set('limit', String(filters.limit));
|
|
325
|
+
const iter = (async function* () {
|
|
326
|
+
const data = await self.r(`/api/export/groups${q.toString() ? `?${q}` : ''}`);
|
|
327
|
+
yield* (data.groups ?? []);
|
|
328
|
+
})();
|
|
329
|
+
return Object.assign(iter, {
|
|
330
|
+
get: (gid) => self.r(`/api/export/groups/${encodeURIComponent(gid)}`)
|
|
331
|
+
});
|
|
212
332
|
}
|
|
213
|
-
|
|
214
|
-
const
|
|
215
|
-
|
|
216
|
-
|
|
333
|
+
actors(filters) {
|
|
334
|
+
const self = this;
|
|
335
|
+
const q = new URLSearchParams();
|
|
336
|
+
if (filters?.type)
|
|
337
|
+
q.set('type', filters.type);
|
|
338
|
+
if (filters?.tag)
|
|
339
|
+
q.set('tag', filters.tag);
|
|
340
|
+
if (filters?.after)
|
|
341
|
+
q.set('after', filters.after);
|
|
342
|
+
if (filters?.limit)
|
|
343
|
+
q.set('limit', String(filters.limit));
|
|
344
|
+
const iter = (async function* () {
|
|
345
|
+
const data = await self.r(`/api/export/actors${q.toString() ? `?${q}` : ''}`);
|
|
346
|
+
yield* (data.actors ?? []);
|
|
347
|
+
})();
|
|
348
|
+
return Object.assign(iter, {
|
|
349
|
+
get: (aid) => self.r(`/api/actors/${encodeURIComponent(aid)}`)
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
things(filters) {
|
|
353
|
+
const self = this;
|
|
354
|
+
const q = new URLSearchParams();
|
|
355
|
+
if (filters?.type)
|
|
356
|
+
q.set('type', filters.type);
|
|
357
|
+
if (filters?.tag)
|
|
358
|
+
q.set('tag', filters.tag);
|
|
359
|
+
if (filters?.after)
|
|
360
|
+
q.set('after', filters.after);
|
|
361
|
+
if (filters?.limit)
|
|
362
|
+
q.set('limit', String(filters.limit));
|
|
363
|
+
const iter = (async function* () {
|
|
364
|
+
const data = await self.r(`/api/things${q.toString() ? `?${q}` : ''}`);
|
|
365
|
+
yield* (data.things ?? []);
|
|
366
|
+
})();
|
|
367
|
+
return Object.assign(iter, {
|
|
368
|
+
get: (tid) => self.r(`/api/things/${encodeURIComponent(tid)}`)
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
paths(filters) {
|
|
372
|
+
const self = this;
|
|
373
|
+
const q = new URLSearchParams();
|
|
374
|
+
if (filters?.source)
|
|
375
|
+
q.set('source', filters.source);
|
|
376
|
+
if (filters?.target)
|
|
377
|
+
q.set('target', filters.target);
|
|
378
|
+
if (filters?.minStrength)
|
|
379
|
+
q.set('minStrength', String(filters.minStrength));
|
|
380
|
+
if (filters?.after)
|
|
381
|
+
q.set('after', filters.after);
|
|
382
|
+
if (filters?.limit)
|
|
383
|
+
q.set('limit', String(filters.limit));
|
|
384
|
+
const iter = (async function* () {
|
|
385
|
+
const data = await self.r(`/api/export/paths${q.toString() ? `?${q}` : ''}`);
|
|
386
|
+
yield* (data.paths ?? []);
|
|
387
|
+
})();
|
|
388
|
+
return Object.assign(iter, {
|
|
389
|
+
get: (edge) => self.r(`/api/export/paths/${encodeURIComponent(edge)}`)
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
events(filters) {
|
|
393
|
+
const self = this;
|
|
394
|
+
const q = new URLSearchParams();
|
|
395
|
+
if (filters?.actor)
|
|
396
|
+
q.set('actor', filters.actor);
|
|
397
|
+
if (filters?.tag)
|
|
398
|
+
q.set('tag', filters.tag);
|
|
399
|
+
if (filters?.from)
|
|
400
|
+
q.set('from', filters.from);
|
|
401
|
+
if (filters?.to)
|
|
402
|
+
q.set('to', filters.to);
|
|
403
|
+
if (filters?.limit)
|
|
404
|
+
q.set('limit', String(filters.limit));
|
|
405
|
+
const iter = (async function* () {
|
|
406
|
+
const data = await self.r(`/api/events${q.toString() ? `?${q}` : ''}`);
|
|
407
|
+
yield* (data.events ?? []);
|
|
408
|
+
})();
|
|
409
|
+
return Object.assign(iter, {
|
|
410
|
+
get: (id) => self.r(`/api/events/${encodeURIComponent(id)}`)
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
learning(filters) {
|
|
414
|
+
const self = this;
|
|
415
|
+
const q = new URLSearchParams();
|
|
416
|
+
if (filters?.status)
|
|
417
|
+
q.set('status', filters.status);
|
|
418
|
+
if (filters?.actor)
|
|
419
|
+
q.set('actor', filters.actor);
|
|
420
|
+
if (filters?.tag)
|
|
421
|
+
q.set('tag', filters.tag);
|
|
422
|
+
if (filters?.limit)
|
|
423
|
+
q.set('limit', String(filters.limit));
|
|
424
|
+
const iter = (async function* () {
|
|
425
|
+
const data = await self.r(`/api/learning${q.toString() ? `?${q}` : ''}`);
|
|
426
|
+
yield* (data.hypotheses ?? []);
|
|
427
|
+
})();
|
|
428
|
+
return Object.assign(iter, {
|
|
429
|
+
get: (hid) => self.r(`/api/learning/${encodeURIComponent(hid)}`)
|
|
430
|
+
});
|
|
217
431
|
}
|
|
218
432
|
async authAgent(opts = {}) {
|
|
219
|
-
const result = await this.
|
|
220
|
-
|
|
221
|
-
|
|
433
|
+
const result = await this.ask("auth:agent", opts);
|
|
434
|
+
const out = "result" in result && result.result ? result.result : { uid: "", name: "", kind: "agent", wallet: null, apiKey: "", keyId: "", returning: false };
|
|
435
|
+
emit("toolkit:sdk:authAgent", ["sdk", "method-authAgent", out.returning ? "returning" : "new", "stage:sign-in:agent"]);
|
|
436
|
+
return out;
|
|
222
437
|
}
|
|
223
438
|
async syncAgent(input) {
|
|
224
|
-
const
|
|
225
|
-
const result = await this.
|
|
439
|
+
const data = typeof input === "string" ? { markdown: input } : input;
|
|
440
|
+
const result = await this.ask("agents:sync", data);
|
|
226
441
|
emit("toolkit:sdk:syncAgent", ["sdk", "method-syncAgent", "stage:team-deploy"]);
|
|
227
|
-
return result;
|
|
442
|
+
return "result" in result && result.result ? result.result : { ok: false, uid: "", skills: [] };
|
|
228
443
|
}
|
|
229
444
|
async discover(skill, limit = 10) {
|
|
230
445
|
const result = await this.r(`/api/agents/discover?skill=${encodeURIComponent(skill)}&limit=${limit}`);
|
|
@@ -232,44 +447,44 @@ export class SubstrateClient {
|
|
|
232
447
|
return result;
|
|
233
448
|
}
|
|
234
449
|
async register(uid, opts = {}) {
|
|
235
|
-
const result = await this.
|
|
450
|
+
const result = await this.ask("agents:register", { uid, ...opts });
|
|
236
451
|
emit("toolkit:sdk:register", ["sdk", "method-register", "stage:sell"]);
|
|
237
|
-
return result;
|
|
452
|
+
return "result" in result && result.result ? result.result : { ok: false, uid, status: "pending", kind: "agent", wallet: null, walletLinked: false, capabilities: 0 };
|
|
238
453
|
}
|
|
239
454
|
async payWeight(from, to, task, amount) {
|
|
240
|
-
const result = await this.
|
|
455
|
+
const result = await this.ask("pay:weight", { from, to, task, amount });
|
|
241
456
|
emit("toolkit:sdk:payWeight", ["sdk", "method-payWeight", "stage:buy"]);
|
|
242
|
-
return result;
|
|
457
|
+
return "result" in result && result.result ? result.result : { ok: false, from, to, task, amount, sui: null };
|
|
243
458
|
}
|
|
244
459
|
async claw(name, opts = {}) {
|
|
245
|
-
const result = await this.
|
|
460
|
+
const result = await this.ask(`claw:${name}`, opts);
|
|
246
461
|
emit("toolkit:sdk:claw", ["sdk", "method-claw"]);
|
|
247
|
-
return result;
|
|
462
|
+
return "result" in result && result.result ? result.result : { ok: true };
|
|
248
463
|
}
|
|
249
464
|
async commend(uid) {
|
|
250
|
-
|
|
465
|
+
await this.signal("agents:commend", { uid });
|
|
251
466
|
emit("toolkit:sdk:commend", ["sdk", "method-commend"]);
|
|
252
|
-
return
|
|
467
|
+
return { ok: true, id: uid, action: "commend" };
|
|
253
468
|
}
|
|
254
469
|
async flag(uid) {
|
|
255
|
-
|
|
470
|
+
await this.signal("agents:flag", { uid });
|
|
256
471
|
emit("toolkit:sdk:flag", ["sdk", "method-flag"]);
|
|
257
|
-
return
|
|
472
|
+
return { ok: true, id: uid, action: "flag" };
|
|
258
473
|
}
|
|
259
474
|
async status(uid, active) {
|
|
260
|
-
|
|
475
|
+
await this.signal("agents:status", { uid, status: active ? "active" : "inactive" });
|
|
261
476
|
emit("toolkit:sdk:status", ["sdk", "method-status"]);
|
|
262
|
-
return
|
|
477
|
+
return { ok: true, id: uid, status: active ? "active" : "inactive" };
|
|
263
478
|
}
|
|
264
479
|
async capabilities(uid) {
|
|
265
|
-
const result = await this.
|
|
480
|
+
const result = await this.ask("agents:capabilities", { uid });
|
|
266
481
|
emit("toolkit:sdk:capabilities", ["sdk", "method-capabilities"]);
|
|
267
|
-
return result;
|
|
482
|
+
return "result" in result && result.result ? result.result : [];
|
|
268
483
|
}
|
|
269
484
|
async stats() {
|
|
270
|
-
const result = await this.
|
|
485
|
+
const result = await this.ask("stats:current");
|
|
271
486
|
emit("toolkit:sdk:stats", ["sdk", "method-stats"]);
|
|
272
|
-
return result;
|
|
487
|
+
return "result" in result && result.result ? result.result : { units: { total: 0, proven: 0, atRisk: 0 }, skills: { total: 0 }, highways: { count: 0, totalEdges: 0 }, revenue: { total: 0, gdp: 0 }, signals: { total: 0, recent: 0 }, timestamp: new Date().toISOString() };
|
|
273
488
|
}
|
|
274
489
|
async health() {
|
|
275
490
|
const result = await this.r("/api/health");
|
|
@@ -277,44 +492,29 @@ export class SubstrateClient {
|
|
|
277
492
|
return result;
|
|
278
493
|
}
|
|
279
494
|
async usage() {
|
|
280
|
-
const result = await this.
|
|
495
|
+
const result = await this.ask("dashboard:usage");
|
|
281
496
|
emit("toolkit:sdk:usage", ["sdk", "method-usage"]);
|
|
282
|
-
return result;
|
|
497
|
+
return "result" in result && result.result ? result.result : {};
|
|
283
498
|
}
|
|
284
499
|
async hire(providerUid, skillId, opts) {
|
|
285
|
-
const result = await this.
|
|
286
|
-
method: "POST",
|
|
287
|
-
body: JSON.stringify({ providerUid, skillId, ...opts }),
|
|
288
|
-
});
|
|
500
|
+
const result = await this.ask("market:hire", { providerUid, skillId, ...opts });
|
|
289
501
|
emit("toolkit:sdk:hire", ["sdk", "method-hire"]);
|
|
290
|
-
return result;
|
|
502
|
+
return "result" in result && result.result ? result.result : { status: 402, code: "dissolved", escrow_template: {}, expires_at: "" };
|
|
291
503
|
}
|
|
292
504
|
async bounty(opts) {
|
|
293
|
-
const result = await this.
|
|
294
|
-
method: "POST",
|
|
295
|
-
body: JSON.stringify(opts),
|
|
296
|
-
});
|
|
505
|
+
const result = await this.ask("market:bounty", opts);
|
|
297
506
|
emit("toolkit:sdk:bounty", ["sdk", "method-bounty"]);
|
|
298
|
-
return result;
|
|
507
|
+
return "result" in result && result.result ? result.result : { id: "", data: {} };
|
|
299
508
|
}
|
|
300
509
|
async bounties(query) {
|
|
301
|
-
const
|
|
302
|
-
if (query?.seller)
|
|
303
|
-
params.set("seller", query.seller);
|
|
304
|
-
if (query?.poster)
|
|
305
|
-
params.set("poster", query.poster);
|
|
306
|
-
const qs = params.size ? `?${params}` : "";
|
|
307
|
-
const result = await this.r(`/api/market/bounty${qs}`);
|
|
510
|
+
const result = await this.ask("market:bounties", query);
|
|
308
511
|
emit("toolkit:sdk:bounties", ["sdk", "method-bounties"]);
|
|
309
|
-
return result;
|
|
512
|
+
return "result" in result && result.result ? result.result : [];
|
|
310
513
|
}
|
|
311
514
|
async publish(opts) {
|
|
312
|
-
const result = await this.
|
|
313
|
-
method: "POST",
|
|
314
|
-
body: JSON.stringify(opts),
|
|
315
|
-
});
|
|
515
|
+
const result = await this.ask("capabilities:publish", opts);
|
|
316
516
|
emit("toolkit:sdk:publish", ["sdk", "method-publish"]);
|
|
317
|
-
return result;
|
|
517
|
+
return "result" in result && result.result ? result.result : { ok: true, sid: "", scope: "" };
|
|
318
518
|
}
|
|
319
519
|
async revenue() {
|
|
320
520
|
const result = await this.r("/api/revenue");
|
|
@@ -331,44 +531,50 @@ export class SubstrateClient {
|
|
|
331
531
|
emit("toolkit:sdk:listAgents", ["sdk", "method-listAgents"]);
|
|
332
532
|
return result;
|
|
333
533
|
}
|
|
334
|
-
async
|
|
335
|
-
const
|
|
534
|
+
async agentHistory(opts) {
|
|
535
|
+
const params = new URLSearchParams({ slug: opts.slug, name: opts.name });
|
|
536
|
+
const result = await this.r(`/api/agents/history?${params}`);
|
|
537
|
+
emit("toolkit:sdk:agentHistory", ["sdk", "method-agentHistory"]);
|
|
538
|
+
return result;
|
|
539
|
+
}
|
|
540
|
+
async rollbackAgent(opts) {
|
|
541
|
+
const result = await this.r("/api/agents/rollback", {
|
|
336
542
|
method: "POST",
|
|
337
|
-
body: JSON.stringify(
|
|
543
|
+
body: JSON.stringify(opts),
|
|
338
544
|
});
|
|
339
|
-
emit("toolkit:sdk:
|
|
545
|
+
emit("toolkit:sdk:rollbackAgent", ["sdk", "method-rollbackAgent"]);
|
|
546
|
+
return result;
|
|
547
|
+
}
|
|
548
|
+
async listSkills(opts) {
|
|
549
|
+
const params = new URLSearchParams({ slug: opts.slug });
|
|
550
|
+
const result = await this.r(`/api/skills/workspace?${params}`);
|
|
551
|
+
emit("toolkit:sdk:listSkills", ["sdk", "method-listSkills"]);
|
|
552
|
+
return result;
|
|
553
|
+
}
|
|
554
|
+
async unimportSkill(opts) {
|
|
555
|
+
const result = await this.r(`/api/skill/${encodeURIComponent(opts.name)}?slug=${encodeURIComponent(opts.slug)}`, { method: "DELETE" });
|
|
556
|
+
emit("toolkit:sdk:unimportSkill", ["sdk", "method-unimportSkill"]);
|
|
340
557
|
return result;
|
|
341
558
|
}
|
|
559
|
+
async closeLoop(session, outcome, opts) {
|
|
560
|
+
const result = await this.ask("loop:close", { session, outcome, ...opts });
|
|
561
|
+
emit("toolkit:sdk:closeLoop", ["sdk", "method-closeLoop"]);
|
|
562
|
+
return "result" in result && result.result ? result.result : { ok: true, stages: [], highways: [] };
|
|
563
|
+
}
|
|
342
564
|
async signals(opts) {
|
|
343
|
-
const
|
|
344
|
-
if (opts?.limit !== undefined)
|
|
345
|
-
params.set("limit", String(opts.limit));
|
|
346
|
-
if (opts?.since !== undefined)
|
|
347
|
-
params.set("since", String(opts.since));
|
|
348
|
-
if (opts?.from !== undefined)
|
|
349
|
-
params.set("from", String(opts.from));
|
|
350
|
-
if (opts?.to !== undefined)
|
|
351
|
-
params.set("to", String(opts.to));
|
|
352
|
-
const qs = params.size ? `?${params}` : "";
|
|
353
|
-
const result = await this.r(`/api/signals${qs}`);
|
|
565
|
+
const result = await this.ask("signals:list", opts);
|
|
354
566
|
emit("toolkit:sdk:signals", ["sdk", "method-signals"]);
|
|
355
|
-
return result;
|
|
567
|
+
return "result" in result && result.result ? result.result : [];
|
|
356
568
|
}
|
|
357
569
|
async state() {
|
|
358
|
-
const result = await this.
|
|
570
|
+
const result = await this.ask("world:state");
|
|
359
571
|
emit("toolkit:sdk:state", ["sdk", "method-state"]);
|
|
360
|
-
return result;
|
|
572
|
+
return "result" in result && result.result ? result.result : { units: [], edges: [], highways: [], tags: [], tagMap: {}, stats: {} };
|
|
361
573
|
}
|
|
362
574
|
async listMarket(opts) {
|
|
363
|
-
const
|
|
364
|
-
if (opts?.tag)
|
|
365
|
-
params.set("tag", opts.tag);
|
|
366
|
-
if (opts?.maxPrice !== undefined)
|
|
367
|
-
params.set("maxPrice", String(opts.maxPrice));
|
|
368
|
-
const qs = params.size ? `?${params}` : "";
|
|
369
|
-
const result = await this.r(`/api/market/list${qs}`);
|
|
575
|
+
const result = await this.ask("market:list", opts);
|
|
370
576
|
emit("toolkit:sdk:listMarket", ["sdk", "method-listMarket"]);
|
|
371
|
-
return result;
|
|
577
|
+
return "result" in result && result.result ? result.result : { capabilities: [] };
|
|
372
578
|
}
|
|
373
579
|
async chat(messages, opts) {
|
|
374
580
|
const url = `${this.baseUrl}/api/chat`;
|
|
@@ -385,45 +591,5 @@ export class SubstrateClient {
|
|
|
385
591
|
emit("toolkit:sdk:chat", ["sdk", "method-chat"]);
|
|
386
592
|
return res.body;
|
|
387
593
|
}
|
|
388
|
-
async *streamState() {
|
|
389
|
-
const url = `${this.baseUrl}/api/stream`;
|
|
390
|
-
const headers = {};
|
|
391
|
-
if (this.apiKey)
|
|
392
|
-
headers["Authorization"] = `Bearer ${this.apiKey}`;
|
|
393
|
-
const res = await fetch(url, { headers });
|
|
394
|
-
if (!res.ok || !res.body)
|
|
395
|
-
throw new SubstrateError(`stream failed: ${res.status}`, res.status);
|
|
396
|
-
emit("toolkit:sdk:streamState", ["sdk", "method-streamState"]);
|
|
397
|
-
const reader = res.body.getReader();
|
|
398
|
-
const decoder = new TextDecoder();
|
|
399
|
-
let buf = "";
|
|
400
|
-
let currentEvent = "connected";
|
|
401
|
-
try {
|
|
402
|
-
while (true) {
|
|
403
|
-
const { done, value } = await reader.read();
|
|
404
|
-
if (done)
|
|
405
|
-
break;
|
|
406
|
-
buf += decoder.decode(value, { stream: true });
|
|
407
|
-
const lines = buf.split("\n");
|
|
408
|
-
buf = lines.pop() ?? "";
|
|
409
|
-
for (const line of lines) {
|
|
410
|
-
if (line.startsWith("event:"))
|
|
411
|
-
currentEvent = line.slice(6).trim();
|
|
412
|
-
else if (line.startsWith("data:")) {
|
|
413
|
-
try {
|
|
414
|
-
yield { event: currentEvent, data: JSON.parse(line.slice(5).trim()) };
|
|
415
|
-
}
|
|
416
|
-
catch {
|
|
417
|
-
yield { event: currentEvent, data: line.slice(5).trim() };
|
|
418
|
-
}
|
|
419
|
-
currentEvent = "connected";
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
finally {
|
|
425
|
-
reader.releaseLock();
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
594
|
}
|
|
429
595
|
//# sourceMappingURL=client.js.map
|