@rkat/sdk 0.8.23 → 0.8.26
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 +92 -15
- package/dist/client.d.ts +32 -24
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +145 -17
- package/dist/client.js.map +1 -1
- package/dist/events.d.ts +15 -2
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +9 -2
- package/dist/events.js.map +1 -1
- package/dist/generated/event_types.d.ts +904 -0
- package/dist/generated/event_types.d.ts.map +1 -0
- package/dist/generated/event_types.js +9 -0
- package/dist/generated/event_types.js.map +1 -0
- package/dist/generated/events.d.ts +1 -1
- package/dist/generated/events.d.ts.map +1 -1
- package/dist/generated/events.js +2 -0
- package/dist/generated/events.js.map +1 -1
- package/dist/generated/index.d.ts +1 -0
- package/dist/generated/index.d.ts.map +1 -1
- package/dist/generated/index.js +1 -0
- package/dist/generated/index.js.map +1 -1
- package/dist/generated/rpc_contracts.d.ts +679 -0
- package/dist/generated/rpc_contracts.d.ts.map +1 -0
- package/dist/generated/rpc_contracts.js +2 -0
- package/dist/generated/rpc_contracts.js.map +1 -0
- package/dist/generated/types.d.ts +505 -11
- package/dist/generated/types.d.ts.map +1 -1
- package/dist/generated/types.js +2 -2
- package/dist/generated/types.js.map +1 -1
- package/dist/mob.d.ts +3 -3
- package/dist/mob.d.ts.map +1 -1
- package/dist/mob.js.map +1 -1
- package/dist/types.d.ts +15 -39
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -122,6 +122,88 @@ function setIfDefined(payload, key, value) {
|
|
|
122
122
|
payload[key] = value;
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
|
+
function toWireContentBlock(block) {
|
|
126
|
+
if (block.type === "text")
|
|
127
|
+
return block;
|
|
128
|
+
if (block.type === "image") {
|
|
129
|
+
return block.source === "blob"
|
|
130
|
+
? block
|
|
131
|
+
: { ...block, source: "inline" };
|
|
132
|
+
}
|
|
133
|
+
return block.source === "uri"
|
|
134
|
+
? block
|
|
135
|
+
: { ...block, source: "inline" };
|
|
136
|
+
}
|
|
137
|
+
function toWireContentInput(content) {
|
|
138
|
+
return typeof content === "string"
|
|
139
|
+
? content
|
|
140
|
+
: content.map(toWireContentBlock);
|
|
141
|
+
}
|
|
142
|
+
function toMutableWire(value) {
|
|
143
|
+
if (Array.isArray(value)) {
|
|
144
|
+
return value.map((item) => toMutableWire(item));
|
|
145
|
+
}
|
|
146
|
+
if (value !== null && typeof value === "object") {
|
|
147
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, toMutableWire(item)]));
|
|
148
|
+
}
|
|
149
|
+
return value;
|
|
150
|
+
}
|
|
151
|
+
function toWirePeerRequestParams(params) {
|
|
152
|
+
const mutable = toMutableWire(params);
|
|
153
|
+
if (!("command" in params) ||
|
|
154
|
+
params.command !== "deliver_member_input") {
|
|
155
|
+
return mutable;
|
|
156
|
+
}
|
|
157
|
+
return {
|
|
158
|
+
...mutable,
|
|
159
|
+
content: toWireContentInput(params.content),
|
|
160
|
+
injected_context: params.injected_context?.map(toWireContentInput),
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
function toWireCommsSendParams(sessionId, command) {
|
|
164
|
+
switch (command.kind) {
|
|
165
|
+
case "input":
|
|
166
|
+
case "peer_message":
|
|
167
|
+
return {
|
|
168
|
+
...command,
|
|
169
|
+
session_id: sessionId,
|
|
170
|
+
blocks: command.blocks?.map(toWireContentBlock),
|
|
171
|
+
};
|
|
172
|
+
case "peer_request":
|
|
173
|
+
return {
|
|
174
|
+
...command,
|
|
175
|
+
session_id: sessionId,
|
|
176
|
+
params: toWirePeerRequestParams(command.params),
|
|
177
|
+
blocks: command.blocks?.map(toWireContentBlock),
|
|
178
|
+
};
|
|
179
|
+
case "peer_lifecycle":
|
|
180
|
+
case "peer_response":
|
|
181
|
+
return { ...command, session_id: sessionId };
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
function toWireMobProfile(profile) {
|
|
185
|
+
const { resume_overrides, skills, ...rest } = profile;
|
|
186
|
+
const payload = { ...rest };
|
|
187
|
+
setIfDefined(payload, "resume_overrides", resume_overrides ? [...resume_overrides] : undefined);
|
|
188
|
+
setIfDefined(payload, "skills", skills ? [...skills] : undefined);
|
|
189
|
+
return payload;
|
|
190
|
+
}
|
|
191
|
+
function toWireMobDefinition(definition) {
|
|
192
|
+
const { models, flows, skills, ...rest } = definition;
|
|
193
|
+
const payload = {
|
|
194
|
+
...rest,
|
|
195
|
+
profiles: Object.fromEntries(Object.entries(definition.profiles).map(([name, binding]) => [
|
|
196
|
+
name,
|
|
197
|
+
"realm_profile" in binding
|
|
198
|
+
? { realm_profile: binding.realm_profile }
|
|
199
|
+
: toWireMobProfile(binding),
|
|
200
|
+
])),
|
|
201
|
+
};
|
|
202
|
+
setIfDefined(payload, "models", models ? { ...models } : undefined);
|
|
203
|
+
setIfDefined(payload, "flows", flows ? { ...flows } : undefined);
|
|
204
|
+
setIfDefined(payload, "skills", skills ? { ...skills } : undefined);
|
|
205
|
+
return payload;
|
|
206
|
+
}
|
|
125
207
|
function mobSpawnPayload(mobId, spec) {
|
|
126
208
|
const payload = {
|
|
127
209
|
mob_id: mobId,
|
|
@@ -136,7 +218,7 @@ function mobSpawnPayload(mobId, spec) {
|
|
|
136
218
|
setIfDefined(payload, "additional_instructions", spec.additionalInstructions);
|
|
137
219
|
setIfDefined(payload, "placement", spec.placement);
|
|
138
220
|
setIfDefined(payload, "binding", spec.binding);
|
|
139
|
-
setIfDefined(payload, "shell_env", spec.shellEnv);
|
|
221
|
+
setIfDefined(payload, "shell_env", spec.shellEnv ? { ...spec.shellEnv } : undefined);
|
|
140
222
|
setIfDefined(payload, "auto_wire_parent", spec.autoWireParent);
|
|
141
223
|
setIfDefined(payload, "launch_mode", spec.launchMode);
|
|
142
224
|
setIfDefined(payload, "tool_access_policy", spec.toolAccessPolicy);
|
|
@@ -607,7 +689,7 @@ export class MeerkatClient {
|
|
|
607
689
|
payload,
|
|
608
690
|
};
|
|
609
691
|
if (options?.blocks !== undefined) {
|
|
610
|
-
params.blocks = options.blocks;
|
|
692
|
+
params.blocks = options.blocks.map(toWireContentBlock);
|
|
611
693
|
}
|
|
612
694
|
return this.request("session/external_event", params);
|
|
613
695
|
}
|
|
@@ -678,7 +760,8 @@ export class MeerkatClient {
|
|
|
678
760
|
if (options?.modelName !== undefined) {
|
|
679
761
|
params.model_name = options.modelName;
|
|
680
762
|
}
|
|
681
|
-
|
|
763
|
+
const result = await this.request("session/export_atif", params);
|
|
764
|
+
return MeerkatClient.requireRecord(result, "result", "Invalid session/export_atif response");
|
|
682
765
|
}
|
|
683
766
|
async readSessionTranscriptRevision(sessionId, revision, options) {
|
|
684
767
|
const params = {
|
|
@@ -1019,10 +1102,11 @@ export class MeerkatClient {
|
|
|
1019
1102
|
return { tools };
|
|
1020
1103
|
}
|
|
1021
1104
|
async callScheduleTool(request) {
|
|
1022
|
-
|
|
1105
|
+
const result = await this.request("schedule/call", {
|
|
1023
1106
|
name: request.name,
|
|
1024
1107
|
arguments: request.arguments ?? {},
|
|
1025
1108
|
});
|
|
1109
|
+
return MeerkatClient.requireRecord(result, "result", "Invalid schedule/call response");
|
|
1026
1110
|
}
|
|
1027
1111
|
async getWorkGraphItem(itemId, options) {
|
|
1028
1112
|
const params = { id: itemId };
|
|
@@ -1067,7 +1151,9 @@ export class MeerkatClient {
|
|
|
1067
1151
|
}
|
|
1068
1152
|
async createMob(options) {
|
|
1069
1153
|
this.requireCapability("mob");
|
|
1070
|
-
const result = await this.request("mob/create",
|
|
1154
|
+
const result = await this.request("mob/create", {
|
|
1155
|
+
definition: toWireMobDefinition(options.definition),
|
|
1156
|
+
});
|
|
1071
1157
|
return new Mob(this, MeerkatClient.requireStringField(result, "mob_id", "Invalid mob/create response"));
|
|
1072
1158
|
}
|
|
1073
1159
|
mob(mobId) {
|
|
@@ -1129,7 +1215,7 @@ export class MeerkatClient {
|
|
|
1129
1215
|
const result = await this.request("mob/member_send", {
|
|
1130
1216
|
mob_id: mobId,
|
|
1131
1217
|
agent_identity: agentIdentity,
|
|
1132
|
-
content,
|
|
1218
|
+
content: toWireContentInput(content),
|
|
1133
1219
|
handling_mode: options?.handlingMode,
|
|
1134
1220
|
render_metadata: options?.renderMetadata,
|
|
1135
1221
|
});
|
|
@@ -1313,6 +1399,39 @@ export class MeerkatClient {
|
|
|
1313
1399
|
};
|
|
1314
1400
|
}
|
|
1315
1401
|
// ─── Multi-host console verbs (phase 7, DEC-P7A-9) ────────────────────
|
|
1402
|
+
/** Read one member's durable tool declaration and fresh convergence. */
|
|
1403
|
+
async mobMemberToolDeclaration(mobId, agentIdentity) {
|
|
1404
|
+
return this.request("mob/member_tool_declaration", {
|
|
1405
|
+
mob_id: mobId,
|
|
1406
|
+
agent_identity: agentIdentity,
|
|
1407
|
+
});
|
|
1408
|
+
}
|
|
1409
|
+
/** Apply one revision-fenced durable member-tool declaration. */
|
|
1410
|
+
async applyMobMemberToolDeclaration(mobId, agentIdentity, requestId, expectedIntentRevision, declaration, convergence) {
|
|
1411
|
+
return this.request("mob/apply_member_tool_declaration", {
|
|
1412
|
+
mob_id: mobId,
|
|
1413
|
+
agent_identity: agentIdentity,
|
|
1414
|
+
request_id: requestId,
|
|
1415
|
+
expected_intent_revision: expectedIntentRevision,
|
|
1416
|
+
declaration,
|
|
1417
|
+
convergence,
|
|
1418
|
+
});
|
|
1419
|
+
}
|
|
1420
|
+
/** Adopt one already-realized member under an explicit expected-absent declaration. */
|
|
1421
|
+
async adoptMobMemberIdentityDeclaration(params) {
|
|
1422
|
+
return this.request("mob/adopt_member_identity_declaration", params);
|
|
1423
|
+
}
|
|
1424
|
+
/** Continue blocked identity convergence under exact revision fences. */
|
|
1425
|
+
async resolveMobIdentityConvergenceBlock(mobId, agentIdentity, requestId, expectedDesiredRevision, observedActiveRevision, convergence) {
|
|
1426
|
+
return this.request("mob/resolve_identity_convergence_block", {
|
|
1427
|
+
mob_id: mobId,
|
|
1428
|
+
agent_identity: agentIdentity,
|
|
1429
|
+
request_id: requestId,
|
|
1430
|
+
expected_desired_revision: expectedDesiredRevision,
|
|
1431
|
+
observed_active_revision: observedActiveRevision,
|
|
1432
|
+
convergence,
|
|
1433
|
+
});
|
|
1434
|
+
}
|
|
1316
1435
|
/**
|
|
1317
1436
|
* Read a mob member transcript page by identity (`mob/member_history`).
|
|
1318
1437
|
* One shape local and remote; the envelope carries typed placement +
|
|
@@ -1473,7 +1592,7 @@ export class MeerkatClient {
|
|
|
1473
1592
|
const result = await this.request("mob/respawn", {
|
|
1474
1593
|
mob_id: mobId,
|
|
1475
1594
|
agent_identity: agentIdentity,
|
|
1476
|
-
initial_message: initialMessage,
|
|
1595
|
+
initial_message: initialMessage === undefined ? undefined : toWireContentInput(initialMessage),
|
|
1477
1596
|
});
|
|
1478
1597
|
const respawnContext = "Invalid mob/respawn response";
|
|
1479
1598
|
const respawnRecord = MeerkatClient.requireRecord(result, "result", respawnContext);
|
|
@@ -1612,14 +1731,14 @@ export class MeerkatClient {
|
|
|
1612
1731
|
async mobSubmitWork(args) {
|
|
1613
1732
|
const params = {
|
|
1614
1733
|
member_ref: args.memberRef,
|
|
1615
|
-
content: args.content,
|
|
1734
|
+
content: toWireContentInput(args.content),
|
|
1616
1735
|
origin: args.origin ?? "external",
|
|
1617
1736
|
};
|
|
1618
1737
|
if (args.workRef !== undefined) {
|
|
1619
1738
|
params.work_ref = args.workRef;
|
|
1620
1739
|
}
|
|
1621
1740
|
if (args.injectedContext !== undefined && args.injectedContext.length > 0) {
|
|
1622
|
-
params.injected_context = args.injectedContext;
|
|
1741
|
+
params.injected_context = args.injectedContext.map(toWireContentInput);
|
|
1623
1742
|
}
|
|
1624
1743
|
if (args.transientTurnContext !== undefined) {
|
|
1625
1744
|
params.transient_turn_context = args.transientTurnContext;
|
|
@@ -1832,7 +1951,7 @@ export class MeerkatClient {
|
|
|
1832
1951
|
async createMobProfile(name, profile) {
|
|
1833
1952
|
const raw = await this.request("mob/profile/create", {
|
|
1834
1953
|
name,
|
|
1835
|
-
profile,
|
|
1954
|
+
profile: toWireMobProfile(profile),
|
|
1836
1955
|
});
|
|
1837
1956
|
return MeerkatClient.parseMobProfileLookup(raw);
|
|
1838
1957
|
}
|
|
@@ -1848,7 +1967,7 @@ export class MeerkatClient {
|
|
|
1848
1967
|
async updateMobProfile(name, profile, expectedRevision) {
|
|
1849
1968
|
const raw = await this.request("mob/profile/update", {
|
|
1850
1969
|
name,
|
|
1851
|
-
profile,
|
|
1970
|
+
profile: toWireMobProfile(profile),
|
|
1852
1971
|
expected_revision: expectedRevision,
|
|
1853
1972
|
});
|
|
1854
1973
|
return MeerkatClient.parseMobProfileLookup(raw);
|
|
@@ -1926,7 +2045,9 @@ export class MeerkatClient {
|
|
|
1926
2045
|
this.process.stdin.write(JSON.stringify(rpcRequest) + "\n");
|
|
1927
2046
|
return responsePromise;
|
|
1928
2047
|
})()
|
|
1929
|
-
:
|
|
2048
|
+
: openMethod === "session/stream_open"
|
|
2049
|
+
? await this.request("session/stream_open", params)
|
|
2050
|
+
: await this.request("mob/stream_open", params);
|
|
1930
2051
|
const streamId = String(result.stream_id ?? "");
|
|
1931
2052
|
if (!streamId) {
|
|
1932
2053
|
throw new MeerkatError("INVALID_RESPONSE", `${openMethod} did not return stream_id`);
|
|
@@ -1947,7 +2068,12 @@ export class MeerkatClient {
|
|
|
1947
2068
|
closeRemote: async (id) => {
|
|
1948
2069
|
// Await stream-close authority before tearing down local dispatch:
|
|
1949
2070
|
// a rejected close must leave the subscription delivering events.
|
|
1950
|
-
|
|
2071
|
+
if (closeMethod === "session/stream_close") {
|
|
2072
|
+
await this.request("session/stream_close", { stream_id: id });
|
|
2073
|
+
}
|
|
2074
|
+
else {
|
|
2075
|
+
await this.request("mob/stream_close", { stream_id: id });
|
|
2076
|
+
}
|
|
1951
2077
|
this.streamQueues.delete(id);
|
|
1952
2078
|
},
|
|
1953
2079
|
parseEvent: parse,
|
|
@@ -2223,7 +2349,7 @@ export class MeerkatClient {
|
|
|
2223
2349
|
* boundary.
|
|
2224
2350
|
*/
|
|
2225
2351
|
async send(sessionId, command) {
|
|
2226
|
-
const result = await this.request("comms/send",
|
|
2352
|
+
const result = await this.request("comms/send", toWireCommsSendParams(sessionId, command));
|
|
2227
2353
|
return MeerkatClient.parseCommsSendReceipt(result);
|
|
2228
2354
|
}
|
|
2229
2355
|
async peers(sessionId) {
|
|
@@ -4085,13 +4211,13 @@ export class MeerkatClient {
|
|
|
4085
4211
|
case "message":
|
|
4086
4212
|
return {
|
|
4087
4213
|
type: "message",
|
|
4088
|
-
message: replacement.message,
|
|
4214
|
+
message: MeerkatClient.serializeTranscriptRewriteMessage(replacement.message),
|
|
4089
4215
|
};
|
|
4090
4216
|
case "user_content_block":
|
|
4091
4217
|
return {
|
|
4092
4218
|
type: "user_content_block",
|
|
4093
4219
|
block_index: replacement.blockIndex,
|
|
4094
|
-
block: replacement.block,
|
|
4220
|
+
block: toWireContentBlock(replacement.block),
|
|
4095
4221
|
};
|
|
4096
4222
|
case "assistant_block":
|
|
4097
4223
|
return {
|
|
@@ -4104,7 +4230,7 @@ export class MeerkatClient {
|
|
|
4104
4230
|
type: "tool_result_content_block",
|
|
4105
4231
|
result_index: replacement.resultIndex,
|
|
4106
4232
|
block_index: replacement.blockIndex,
|
|
4107
|
-
block: replacement.block,
|
|
4233
|
+
block: toWireContentBlock(replacement.block),
|
|
4108
4234
|
};
|
|
4109
4235
|
}
|
|
4110
4236
|
throw new Error(`Unsupported transcript replacement type: ${replacement.type}`);
|
|
@@ -4223,6 +4349,8 @@ export class MeerkatClient {
|
|
|
4223
4349
|
is_error: result.isError,
|
|
4224
4350
|
}));
|
|
4225
4351
|
}
|
|
4352
|
+
// SessionMessage.raw was accepted by the fail-closed transcript parser
|
|
4353
|
+
// above; this branch only restores the exact snake_case wire spelling.
|
|
4226
4354
|
return payload;
|
|
4227
4355
|
}
|
|
4228
4356
|
return { ...message };
|