@rkat/sdk 0.6.23 → 0.6.24
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 +5 -3
- package/dist/client.d.ts +23 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +325 -1
- package/dist/client.js.map +1 -1
- package/dist/events.d.ts +6 -1
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +9 -0
- package/dist/events.js.map +1 -1
- package/dist/generated/types.d.ts +175 -2
- package/dist/generated/types.d.ts.map +1 -1
- package/dist/generated/types.js +2 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/session.d.ts +13 -1
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +18 -0
- package/dist/session.js.map +1 -1
- package/dist/types.d.ts +117 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -78,6 +78,26 @@ const MOB_SPAWN_MANY_FAILURE_CAUSES = new Set([
|
|
|
78
78
|
"work_not_found",
|
|
79
79
|
"internal",
|
|
80
80
|
]);
|
|
81
|
+
const WORK_ATTENTION_DELEGATED_AUTHORITIES = new Set([
|
|
82
|
+
"add_evidence",
|
|
83
|
+
"close_own_review_item",
|
|
84
|
+
"request_closure",
|
|
85
|
+
"close_if_policy_allows",
|
|
86
|
+
]);
|
|
87
|
+
const WORK_ATTENTION_MODES = new Set([
|
|
88
|
+
"pursue",
|
|
89
|
+
"coordinate",
|
|
90
|
+
"review",
|
|
91
|
+
"falsify",
|
|
92
|
+
"judge",
|
|
93
|
+
"observe",
|
|
94
|
+
]);
|
|
95
|
+
const WORK_ATTENTION_STATES = new Set([
|
|
96
|
+
"active",
|
|
97
|
+
"paused",
|
|
98
|
+
"superseded",
|
|
99
|
+
"stopped",
|
|
100
|
+
]);
|
|
81
101
|
function isMobSpawnManyFailureCause(value) {
|
|
82
102
|
return typeof value === "string" && MOB_SPAWN_MANY_FAILURE_CAUSES.has(value);
|
|
83
103
|
}
|
|
@@ -505,6 +525,18 @@ export class MeerkatClient {
|
|
|
505
525
|
const raw = await this.request("session/history", params);
|
|
506
526
|
return MeerkatClient.parseSessionHistory(raw);
|
|
507
527
|
}
|
|
528
|
+
async readSessionTranscriptRevision(sessionId, revision, options) {
|
|
529
|
+
const params = {
|
|
530
|
+
session_id: sessionId,
|
|
531
|
+
revision,
|
|
532
|
+
offset: options?.offset ?? 0,
|
|
533
|
+
};
|
|
534
|
+
if (options?.limit !== undefined) {
|
|
535
|
+
params.limit = options.limit;
|
|
536
|
+
}
|
|
537
|
+
const raw = await this.request("session/transcript_revision", params);
|
|
538
|
+
return MeerkatClient.parseSessionTranscriptRevision(raw);
|
|
539
|
+
}
|
|
508
540
|
async forkSessionAt(sessionId, messageIndex, options) {
|
|
509
541
|
const params = {
|
|
510
542
|
session_id: sessionId,
|
|
@@ -528,6 +560,43 @@ export class MeerkatClient {
|
|
|
528
560
|
const raw = await this.request("session/fork_replace", params);
|
|
529
561
|
return MeerkatClient.parseSessionForkResult(raw);
|
|
530
562
|
}
|
|
563
|
+
async rewriteSessionTranscript(sessionId, selection, replacement, reason, options) {
|
|
564
|
+
const params = {
|
|
565
|
+
session_id: sessionId,
|
|
566
|
+
selection,
|
|
567
|
+
replacement: replacement.map((message) => MeerkatClient.serializeTranscriptRewriteMessage(message)),
|
|
568
|
+
reason,
|
|
569
|
+
};
|
|
570
|
+
if (options?.actor !== undefined) {
|
|
571
|
+
params.actor = options.actor;
|
|
572
|
+
}
|
|
573
|
+
if (options?.expectedParentRevision !== undefined) {
|
|
574
|
+
params.expected_parent_revision = options.expectedParentRevision;
|
|
575
|
+
}
|
|
576
|
+
if (options?.runningBehavior !== undefined) {
|
|
577
|
+
params.running_behavior = options.runningBehavior;
|
|
578
|
+
}
|
|
579
|
+
const raw = await this.request("session/rewrite_transcript", params);
|
|
580
|
+
return MeerkatClient.parseSessionTranscriptRewriteResult(raw);
|
|
581
|
+
}
|
|
582
|
+
async restoreSessionTranscriptRevision(sessionId, revision, reason, options) {
|
|
583
|
+
const params = {
|
|
584
|
+
session_id: sessionId,
|
|
585
|
+
revision,
|
|
586
|
+
reason,
|
|
587
|
+
};
|
|
588
|
+
if (options?.actor !== undefined) {
|
|
589
|
+
params.actor = options.actor;
|
|
590
|
+
}
|
|
591
|
+
if (options?.expectedParentRevision !== undefined) {
|
|
592
|
+
params.expected_parent_revision = options.expectedParentRevision;
|
|
593
|
+
}
|
|
594
|
+
if (options?.runningBehavior !== undefined) {
|
|
595
|
+
params.running_behavior = options.runningBehavior;
|
|
596
|
+
}
|
|
597
|
+
const raw = await this.request("session/restore_transcript_revision", params);
|
|
598
|
+
return MeerkatClient.parseSessionTranscriptRewriteResult(raw);
|
|
599
|
+
}
|
|
531
600
|
// -- Capabilities -------------------------------------------------------
|
|
532
601
|
get capabilities() {
|
|
533
602
|
return this._capabilities;
|
|
@@ -738,6 +807,16 @@ export class MeerkatClient {
|
|
|
738
807
|
events: MeerkatClient.parseWorkGraphEventArray(result.events),
|
|
739
808
|
};
|
|
740
809
|
}
|
|
810
|
+
async getWorkGraphGoalStatus(params) {
|
|
811
|
+
const result = await this.request("workgraph/goal/status", MeerkatClient.toWireWorkGraphGoalStatusRequest(params));
|
|
812
|
+
return MeerkatClient.parseWorkGraphGoalResult(result);
|
|
813
|
+
}
|
|
814
|
+
async listWorkGraphAttention(params = {}) {
|
|
815
|
+
const result = await this.request("workgraph/attention/list", MeerkatClient.toWireWorkGraphAttentionListRequest(params));
|
|
816
|
+
return {
|
|
817
|
+
attention: MeerkatClient.parseWorkAttentionBindingArray(result.attention),
|
|
818
|
+
};
|
|
819
|
+
}
|
|
741
820
|
async subscribeSessionEvents(sessionId) {
|
|
742
821
|
return this.openEventSubscription("session/stream_open", { session_id: sessionId }, "session/stream_close", MeerkatClient.parseAgentEventEnvelope);
|
|
743
822
|
}
|
|
@@ -1951,7 +2030,10 @@ export class MeerkatClient {
|
|
|
1951
2030
|
}
|
|
1952
2031
|
registerRequest(id) {
|
|
1953
2032
|
return new Promise((resolve, reject) => {
|
|
1954
|
-
this.pendingRequests.set(id, {
|
|
2033
|
+
this.pendingRequests.set(id, {
|
|
2034
|
+
resolve: (value) => resolve(value),
|
|
2035
|
+
reject,
|
|
2036
|
+
});
|
|
1955
2037
|
});
|
|
1956
2038
|
}
|
|
1957
2039
|
// -- Static helpers -----------------------------------------------------
|
|
@@ -1971,6 +2053,15 @@ export class MeerkatClient {
|
|
|
1971
2053
|
}
|
|
1972
2054
|
return raw;
|
|
1973
2055
|
}
|
|
2056
|
+
static optionalRecord(raw) {
|
|
2057
|
+
if (raw === undefined || raw === null) {
|
|
2058
|
+
return undefined;
|
|
2059
|
+
}
|
|
2060
|
+
if (typeof raw !== "object" || Array.isArray(raw)) {
|
|
2061
|
+
return undefined;
|
|
2062
|
+
}
|
|
2063
|
+
return raw;
|
|
2064
|
+
}
|
|
1974
2065
|
static requireStringField(raw, field, context) {
|
|
1975
2066
|
const value = raw[field];
|
|
1976
2067
|
if (typeof value !== "string" || value.length === 0) {
|
|
@@ -2310,6 +2401,25 @@ export class MeerkatClient {
|
|
|
2310
2401
|
setIfDefined(params, "limit", filter.limit);
|
|
2311
2402
|
return params;
|
|
2312
2403
|
}
|
|
2404
|
+
static toWireWorkGraphGoalStatusRequest(request) {
|
|
2405
|
+
const params = MeerkatClient.toWireWorkGraphScope(request);
|
|
2406
|
+
params.binding_id = request.bindingId;
|
|
2407
|
+
return params;
|
|
2408
|
+
}
|
|
2409
|
+
static toWireWorkGraphAttentionTarget(target) {
|
|
2410
|
+
if (target.kind === "session") {
|
|
2411
|
+
return { kind: "session", session_id: target.sessionId };
|
|
2412
|
+
}
|
|
2413
|
+
return { kind: "lowered_owner", owner_key: target.ownerKey };
|
|
2414
|
+
}
|
|
2415
|
+
static toWireWorkGraphAttentionListRequest(request) {
|
|
2416
|
+
const params = MeerkatClient.toWireWorkGraphScope(request);
|
|
2417
|
+
setIfDefined(params, "status", request.status);
|
|
2418
|
+
if (request.target !== undefined) {
|
|
2419
|
+
params.target = MeerkatClient.toWireWorkGraphAttentionTarget(request.target);
|
|
2420
|
+
}
|
|
2421
|
+
return params;
|
|
2422
|
+
}
|
|
2313
2423
|
static parseStringArray(value, context) {
|
|
2314
2424
|
if (value == null) {
|
|
2315
2425
|
return [];
|
|
@@ -2357,6 +2467,17 @@ export class MeerkatClient {
|
|
|
2357
2467
|
displayName: MeerkatClient.parseOptionalString(data.display_name),
|
|
2358
2468
|
};
|
|
2359
2469
|
}
|
|
2470
|
+
static parseWorkOwnerKey(raw, context) {
|
|
2471
|
+
const key = MeerkatClient.requireRecord(raw, "owner_key", context);
|
|
2472
|
+
const kind = MeerkatClient.requireStringField(key, "kind", context);
|
|
2473
|
+
if (!["principal", "agent", "session", "mob", "label"].includes(kind)) {
|
|
2474
|
+
throw new MeerkatError("INVALID_RESPONSE", `${context}: invalid owner key kind`);
|
|
2475
|
+
}
|
|
2476
|
+
return {
|
|
2477
|
+
kind: kind,
|
|
2478
|
+
id: MeerkatClient.requireStringField(key, "id", context),
|
|
2479
|
+
};
|
|
2480
|
+
}
|
|
2360
2481
|
static parseMobWireMembersBatchEdge(raw, context) {
|
|
2361
2482
|
const data = MeerkatClient.requireRecord(raw, "edge", context);
|
|
2362
2483
|
return {
|
|
@@ -2390,6 +2511,31 @@ export class MeerkatClient {
|
|
|
2390
2511
|
leaseExpiresAt: MeerkatClient.parseOptionalString(data.lease_expires_at),
|
|
2391
2512
|
};
|
|
2392
2513
|
}
|
|
2514
|
+
static parseWorkCompletionPolicy(raw) {
|
|
2515
|
+
if (raw === undefined || raw === null) {
|
|
2516
|
+
return { kind: "self_attest" };
|
|
2517
|
+
}
|
|
2518
|
+
const policy = MeerkatClient.requireRecord(raw, "completion_policy", "Invalid workgraph item");
|
|
2519
|
+
const kind = MeerkatClient.requireStringField(policy, "kind", "Invalid workgraph completion policy");
|
|
2520
|
+
switch (kind) {
|
|
2521
|
+
case "self_attest":
|
|
2522
|
+
case "host_confirmed":
|
|
2523
|
+
case "principal_confirmed":
|
|
2524
|
+
return { kind };
|
|
2525
|
+
case "supervisor":
|
|
2526
|
+
return {
|
|
2527
|
+
kind,
|
|
2528
|
+
owner_key: MeerkatClient.parseWorkOwnerKey(policy.owner_key, "Invalid workgraph completion policy"),
|
|
2529
|
+
};
|
|
2530
|
+
case "reviewer_quorum":
|
|
2531
|
+
return {
|
|
2532
|
+
kind,
|
|
2533
|
+
threshold: MeerkatClient.requireNumberField(policy, "threshold", "Invalid workgraph completion policy"),
|
|
2534
|
+
};
|
|
2535
|
+
default:
|
|
2536
|
+
throw new MeerkatError("INVALID_RESPONSE", "Invalid workgraph completion policy: invalid kind");
|
|
2537
|
+
}
|
|
2538
|
+
}
|
|
2393
2539
|
static parseWorkItem(data) {
|
|
2394
2540
|
const status = MeerkatClient.requireStringField(data, "status", "Invalid workgraph item");
|
|
2395
2541
|
if (!["open", "in_progress", "blocked", "completed", "cancelled", "failed"].includes(status)) {
|
|
@@ -2407,9 +2553,11 @@ export class MeerkatClient {
|
|
|
2407
2553
|
description: MeerkatClient.parseOptionalString(data.description),
|
|
2408
2554
|
status: status,
|
|
2409
2555
|
priority: priority,
|
|
2556
|
+
completionPolicy: MeerkatClient.parseWorkCompletionPolicy(data.completion_policy),
|
|
2410
2557
|
labels: MeerkatClient.parseStringArray(data.labels, "Invalid workgraph item labels"),
|
|
2411
2558
|
owner: MeerkatClient.parseWorkGraphOwner(data.owner, "Invalid workgraph item"),
|
|
2412
2559
|
claim: MeerkatClient.parseWorkGraphClaim(data.claim),
|
|
2560
|
+
machineState: MeerkatClient.requireRecord(data.machine_state, "machine_state", "Invalid workgraph item"),
|
|
2413
2561
|
revision: MeerkatClient.requireNumberField(data, "revision", "Invalid workgraph item"),
|
|
2414
2562
|
dueAt: MeerkatClient.parseOptionalString(data.due_at),
|
|
2415
2563
|
notBefore: MeerkatClient.parseOptionalString(data.not_before),
|
|
@@ -2433,6 +2581,73 @@ export class MeerkatClient {
|
|
|
2433
2581
|
static parseWorkItemArray(value, context = "Invalid workgraph item list") {
|
|
2434
2582
|
return MeerkatClient.requireRecordArray(value, context).map((item) => MeerkatClient.parseWorkItem(item));
|
|
2435
2583
|
}
|
|
2584
|
+
static parseWorkGraphGoalResult(data) {
|
|
2585
|
+
return {
|
|
2586
|
+
item: MeerkatClient.parseWorkItem(MeerkatClient.requireRecord(data.item, "item", "Invalid workgraph goal result")),
|
|
2587
|
+
attention: MeerkatClient.parseWorkAttentionBinding(MeerkatClient.requireRecord(data.attention, "attention", "Invalid workgraph goal result")),
|
|
2588
|
+
};
|
|
2589
|
+
}
|
|
2590
|
+
static parseWorkAttentionBinding(data) {
|
|
2591
|
+
const bindingId = MeerkatClient.requireStringField(data, "binding_id", "Invalid workgraph attention binding");
|
|
2592
|
+
const createdAt = MeerkatClient.requireStringField(data, "created_at", "Invalid workgraph attention binding");
|
|
2593
|
+
const delegatedAuthority = MeerkatClient.requireStringField(data, "delegated_authority", "Invalid workgraph attention binding");
|
|
2594
|
+
if (!WORK_ATTENTION_DELEGATED_AUTHORITIES.has(delegatedAuthority)) {
|
|
2595
|
+
throw new MeerkatError("INVALID_RESPONSE", "Invalid workgraph attention binding: invalid delegated_authority");
|
|
2596
|
+
}
|
|
2597
|
+
const mode = MeerkatClient.requireStringField(data, "mode", "Invalid workgraph attention binding");
|
|
2598
|
+
if (!WORK_ATTENTION_MODES.has(mode)) {
|
|
2599
|
+
throw new MeerkatError("INVALID_RESPONSE", "Invalid workgraph attention binding: invalid mode");
|
|
2600
|
+
}
|
|
2601
|
+
const updatedAt = MeerkatClient.requireStringField(data, "updated_at", "Invalid workgraph attention binding");
|
|
2602
|
+
const status = MeerkatClient.requireRecord(data.status, "status", "Invalid workgraph attention binding");
|
|
2603
|
+
const statusState = MeerkatClient.requireStringField(status, "state", "Invalid workgraph attention status");
|
|
2604
|
+
if (!WORK_ATTENTION_STATES.has(statusState)) {
|
|
2605
|
+
throw new MeerkatError("INVALID_RESPONSE", "Invalid workgraph attention status: invalid state");
|
|
2606
|
+
}
|
|
2607
|
+
const target = MeerkatClient.requireRecord(data.target, "target", "Invalid workgraph attention binding");
|
|
2608
|
+
const targetKind = MeerkatClient.requireStringField(target, "kind", "Invalid workgraph attention target");
|
|
2609
|
+
if (targetKind === "session") {
|
|
2610
|
+
MeerkatClient.requireStringField(target, "session_id", "Invalid workgraph attention target");
|
|
2611
|
+
}
|
|
2612
|
+
else if (targetKind === "lowered_owner") {
|
|
2613
|
+
MeerkatClient.requireRecord(target.owner_key, "owner_key", "Invalid workgraph attention target");
|
|
2614
|
+
}
|
|
2615
|
+
else {
|
|
2616
|
+
throw new MeerkatError("INVALID_RESPONSE", "Invalid workgraph attention target: invalid kind");
|
|
2617
|
+
}
|
|
2618
|
+
const workRef = MeerkatClient.requireRecord(data.work_ref, "work_ref", "Invalid workgraph attention binding");
|
|
2619
|
+
MeerkatClient.requireStringField(workRef, "realm_id", "Invalid workgraph attention work ref");
|
|
2620
|
+
MeerkatClient.requireStringField(workRef, "namespace", "Invalid workgraph attention work ref");
|
|
2621
|
+
MeerkatClient.requireStringField(workRef, "item_id", "Invalid workgraph attention work ref");
|
|
2622
|
+
const attention = {
|
|
2623
|
+
bindingId,
|
|
2624
|
+
createdAt,
|
|
2625
|
+
delegatedAuthority: delegatedAuthority,
|
|
2626
|
+
machineState: MeerkatClient.optionalRecord(data.machine_state),
|
|
2627
|
+
mode: mode,
|
|
2628
|
+
projectionPolicy: MeerkatClient.optionalRecord(data.projection_policy),
|
|
2629
|
+
status: status,
|
|
2630
|
+
target: targetKind === "session"
|
|
2631
|
+
? {
|
|
2632
|
+
kind: "session",
|
|
2633
|
+
sessionId: MeerkatClient.requireStringField(target, "session_id", "Invalid workgraph attention target"),
|
|
2634
|
+
}
|
|
2635
|
+
: {
|
|
2636
|
+
kind: "loweredOwner",
|
|
2637
|
+
ownerKey: MeerkatClient.parseWorkOwnerKey(target.owner_key, "Invalid workgraph attention target"),
|
|
2638
|
+
},
|
|
2639
|
+
updatedAt,
|
|
2640
|
+
workRef: {
|
|
2641
|
+
realmId: MeerkatClient.requireStringField(workRef, "realm_id", "Invalid workgraph attention work ref"),
|
|
2642
|
+
namespace: MeerkatClient.requireStringField(workRef, "namespace", "Invalid workgraph attention work ref"),
|
|
2643
|
+
itemId: MeerkatClient.requireStringField(workRef, "item_id", "Invalid workgraph attention work ref"),
|
|
2644
|
+
},
|
|
2645
|
+
};
|
|
2646
|
+
return attention;
|
|
2647
|
+
}
|
|
2648
|
+
static parseWorkAttentionBindingArray(value) {
|
|
2649
|
+
return MeerkatClient.requireRecordArray(value, "Invalid workgraph attention list").map((attention) => MeerkatClient.parseWorkAttentionBinding(attention));
|
|
2650
|
+
}
|
|
2436
2651
|
static parseWorkGraphEdge(data) {
|
|
2437
2652
|
const kind = MeerkatClient.requireStringField(data, "kind", "Invalid workgraph edge");
|
|
2438
2653
|
if (!["blocks", "parent", "related", "supersedes", "derived_from"].includes(kind)) {
|
|
@@ -2458,6 +2673,8 @@ export class MeerkatClient {
|
|
|
2458
2673
|
"closed",
|
|
2459
2674
|
"linked",
|
|
2460
2675
|
"evidence_added",
|
|
2676
|
+
"attention_created",
|
|
2677
|
+
"attention_updated",
|
|
2461
2678
|
].includes(kind)) {
|
|
2462
2679
|
throw new MeerkatError("INVALID_RESPONSE", "Invalid workgraph event: invalid kind");
|
|
2463
2680
|
}
|
|
@@ -2483,6 +2700,7 @@ export class MeerkatClient {
|
|
|
2483
2700
|
eventHighWaterMark: MeerkatClient.parseOptionalNumber(data.event_high_water_mark),
|
|
2484
2701
|
items: MeerkatClient.parseWorkItemArray(data.items, "Invalid workgraph snapshot items"),
|
|
2485
2702
|
edges: MeerkatClient.requireRecordArray(data.edges, "Invalid workgraph snapshot edges").map((edge) => MeerkatClient.parseWorkGraphEdge(edge)),
|
|
2703
|
+
attention: MeerkatClient.parseWorkAttentionBindingArray(data.attention ?? []),
|
|
2486
2704
|
readyItemIds: MeerkatClient.requireStringArray(data.ready_item_ids, "Invalid workgraph snapshot ready item ids"),
|
|
2487
2705
|
};
|
|
2488
2706
|
}
|
|
@@ -2547,6 +2765,22 @@ export class MeerkatClient {
|
|
|
2547
2765
|
messages: rawMessages.map((message) => MeerkatClient.parseSessionMessage(message)),
|
|
2548
2766
|
};
|
|
2549
2767
|
}
|
|
2768
|
+
static parseSessionTranscriptRevision(data) {
|
|
2769
|
+
const rawMessages = Array.isArray(data.messages)
|
|
2770
|
+
? data.messages
|
|
2771
|
+
: [];
|
|
2772
|
+
return {
|
|
2773
|
+
sessionId: String(data.session_id ?? ""),
|
|
2774
|
+
sessionRef: data.session_ref != null ? String(data.session_ref) : undefined,
|
|
2775
|
+
revision: String(data.revision ?? ""),
|
|
2776
|
+
headRevision: String(data.head_revision ?? ""),
|
|
2777
|
+
messageCount: Number(data.message_count ?? 0),
|
|
2778
|
+
offset: Number(data.offset ?? 0),
|
|
2779
|
+
limit: data.limit != null ? Number(data.limit) : undefined,
|
|
2780
|
+
hasMore: Boolean(data.has_more ?? false),
|
|
2781
|
+
messages: rawMessages.map((message) => MeerkatClient.parseSessionMessage(message)),
|
|
2782
|
+
};
|
|
2783
|
+
}
|
|
2550
2784
|
static parseSessionForkResult(data) {
|
|
2551
2785
|
return {
|
|
2552
2786
|
sourceSessionId: String(data.source_session_id ?? ""),
|
|
@@ -2555,6 +2789,15 @@ export class MeerkatClient {
|
|
|
2555
2789
|
messageCount: Number(data.message_count ?? 0),
|
|
2556
2790
|
};
|
|
2557
2791
|
}
|
|
2792
|
+
static parseSessionTranscriptRewriteResult(data) {
|
|
2793
|
+
return {
|
|
2794
|
+
sessionId: String(data.session_id ?? ""),
|
|
2795
|
+
parentRevision: String(data.parent_revision ?? ""),
|
|
2796
|
+
revision: String(data.revision ?? ""),
|
|
2797
|
+
messageCount: Number(data.message_count ?? 0),
|
|
2798
|
+
commit: (data.commit ?? {}),
|
|
2799
|
+
};
|
|
2800
|
+
}
|
|
2558
2801
|
static serializeTranscriptReplacement(replacement) {
|
|
2559
2802
|
switch (replacement.type) {
|
|
2560
2803
|
case "message":
|
|
@@ -2601,6 +2844,8 @@ export class MeerkatClient {
|
|
|
2601
2844
|
return {
|
|
2602
2845
|
role,
|
|
2603
2846
|
createdAt: String(data.created_at ?? ""),
|
|
2847
|
+
kind: data.kind != null ? String(data.kind) : undefined,
|
|
2848
|
+
body: data.body != null ? String(data.body) : undefined,
|
|
2604
2849
|
content: contentValue != null ? MeerkatClient.parseContentInput(contentValue) : undefined,
|
|
2605
2850
|
toolCalls: rawToolCalls.map((toolCall) => ({
|
|
2606
2851
|
id: String(toolCall.id ?? ""),
|
|
@@ -2614,6 +2859,84 @@ export class MeerkatClient {
|
|
|
2614
2859
|
content: MeerkatClient.parseContentInput(result.content),
|
|
2615
2860
|
isError: Boolean(result.is_error ?? false),
|
|
2616
2861
|
})),
|
|
2862
|
+
raw: { ...data },
|
|
2863
|
+
};
|
|
2864
|
+
}
|
|
2865
|
+
static serializeTranscriptRewriteMessage(message) {
|
|
2866
|
+
const camel = message;
|
|
2867
|
+
if (camel.createdAt !== undefined) {
|
|
2868
|
+
const payload = {
|
|
2869
|
+
...(camel.raw ?? {}),
|
|
2870
|
+
role: camel.role,
|
|
2871
|
+
created_at: camel.createdAt,
|
|
2872
|
+
};
|
|
2873
|
+
if (camel.kind !== undefined) {
|
|
2874
|
+
payload.kind = camel.kind;
|
|
2875
|
+
}
|
|
2876
|
+
if (camel.role === "system_notice") {
|
|
2877
|
+
delete payload.body;
|
|
2878
|
+
delete payload.content;
|
|
2879
|
+
if (camel.body !== undefined) {
|
|
2880
|
+
payload.body = camel.body;
|
|
2881
|
+
}
|
|
2882
|
+
else if (camel.content !== undefined) {
|
|
2883
|
+
payload.content = camel.content;
|
|
2884
|
+
}
|
|
2885
|
+
}
|
|
2886
|
+
else {
|
|
2887
|
+
if (camel.body !== undefined) {
|
|
2888
|
+
payload.body = camel.body;
|
|
2889
|
+
}
|
|
2890
|
+
if (camel.content !== undefined) {
|
|
2891
|
+
payload.content = camel.content;
|
|
2892
|
+
}
|
|
2893
|
+
}
|
|
2894
|
+
if (camel.toolCalls?.length > 0) {
|
|
2895
|
+
payload.tool_calls = camel.toolCalls.map((toolCall) => ({
|
|
2896
|
+
id: toolCall.id,
|
|
2897
|
+
name: toolCall.name,
|
|
2898
|
+
args: toolCall.args,
|
|
2899
|
+
}));
|
|
2900
|
+
}
|
|
2901
|
+
if (camel.stopReason !== undefined) {
|
|
2902
|
+
payload.stop_reason = camel.stopReason;
|
|
2903
|
+
}
|
|
2904
|
+
if (camel.blocks?.length > 0) {
|
|
2905
|
+
payload.blocks = camel.blocks.map((block) => MeerkatClient.serializeSessionAssistantBlock(block));
|
|
2906
|
+
}
|
|
2907
|
+
if (camel.results?.length > 0) {
|
|
2908
|
+
payload.results = camel.results.map((result) => ({
|
|
2909
|
+
tool_use_id: result.toolUseId,
|
|
2910
|
+
content: result.content,
|
|
2911
|
+
is_error: result.isError,
|
|
2912
|
+
}));
|
|
2913
|
+
}
|
|
2914
|
+
return payload;
|
|
2915
|
+
}
|
|
2916
|
+
return { ...message };
|
|
2917
|
+
}
|
|
2918
|
+
static serializeSessionAssistantBlock(block) {
|
|
2919
|
+
const data = {
|
|
2920
|
+
...(block.raw?.data ?? {}),
|
|
2921
|
+
};
|
|
2922
|
+
setIfDefined(data, "text", block.text);
|
|
2923
|
+
setIfDefined(data, "id", block.id);
|
|
2924
|
+
setIfDefined(data, "name", block.name);
|
|
2925
|
+
setIfDefined(data, "args", block.args);
|
|
2926
|
+
setIfDefined(data, "image_id", block.imageId);
|
|
2927
|
+
if (block.blobId !== undefined) {
|
|
2928
|
+
data.blob_ref = { blob_id: block.blobId };
|
|
2929
|
+
}
|
|
2930
|
+
setIfDefined(data, "media_type", block.mediaType);
|
|
2931
|
+
setIfDefined(data, "width", block.width);
|
|
2932
|
+
setIfDefined(data, "height", block.height);
|
|
2933
|
+
setIfDefined(data, "revised_prompt", block.revisedPrompt);
|
|
2934
|
+
setIfDefined(data, "meta", block.meta);
|
|
2935
|
+
setIfDefined(data, "source", block.source);
|
|
2936
|
+
return {
|
|
2937
|
+
...(block.raw ?? {}),
|
|
2938
|
+
block_type: block.blockType,
|
|
2939
|
+
data,
|
|
2617
2940
|
};
|
|
2618
2941
|
}
|
|
2619
2942
|
static parseContentInput(value) {
|
|
@@ -2679,6 +3002,7 @@ export class MeerkatClient {
|
|
|
2679
3002
|
// Lane provenance for transcript blocks (typed enum on the wire,
|
|
2680
3003
|
// serialized as a snake_case string — currently only "spoken").
|
|
2681
3004
|
source: typeof blockData.source === "string" ? blockData.source : undefined,
|
|
3005
|
+
raw: { ...data },
|
|
2682
3006
|
};
|
|
2683
3007
|
}
|
|
2684
3008
|
static parseMcpLiveOpResponse(raw) {
|