@rkat/sdk 0.4.5 → 0.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.d.ts +85 -20
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +388 -58
- package/dist/client.js.map +1 -1
- package/dist/generated/types.d.ts +36 -1
- package/dist/generated/types.d.ts.map +1 -1
- package/dist/generated/types.js +2 -2
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -6
- package/dist/index.js.map +1 -1
- package/dist/mob.d.ts +29 -0
- package/dist/mob.d.ts.map +1 -0
- package/dist/mob.js +58 -0
- package/dist/mob.js.map +1 -0
- package/dist/session.d.ts +51 -41
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +52 -43
- package/dist/session.js.map +1 -1
- package/dist/streaming.d.ts +8 -18
- package/dist/streaming.d.ts.map +1 -1
- package/dist/streaming.js +95 -54
- package/dist/streaming.js.map +1 -1
- package/dist/subscription.d.ts +23 -0
- package/dist/subscription.d.ts.map +1 -0
- package/dist/subscription.js +42 -0
- package/dist/subscription.js.map +1 -0
- package/dist/types.d.ts +109 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -2
package/dist/session.js
CHANGED
|
@@ -31,101 +31,110 @@ export class Session {
|
|
|
31
31
|
this._ref = result.sessionRef;
|
|
32
32
|
this._lastResult = result;
|
|
33
33
|
}
|
|
34
|
-
// -- Identity -----------------------------------------------------------
|
|
35
|
-
/** The stable UUID for this session. */
|
|
36
34
|
get id() {
|
|
37
35
|
return this._id;
|
|
38
36
|
}
|
|
39
|
-
/** Optional human-readable session reference. */
|
|
40
37
|
get ref() {
|
|
41
38
|
return this._ref;
|
|
42
39
|
}
|
|
43
|
-
// -- Last result shortcuts ----------------------------------------------
|
|
44
|
-
/** The most recent {@link RunResult}. */
|
|
45
40
|
get lastResult() {
|
|
46
41
|
return this._lastResult;
|
|
47
42
|
}
|
|
48
|
-
/** The assistant's text from the last turn. */
|
|
49
43
|
get text() {
|
|
50
44
|
return this._lastResult.text;
|
|
51
45
|
}
|
|
52
|
-
/** Token usage from the last turn. */
|
|
53
46
|
get usage() {
|
|
54
47
|
return this._lastResult.usage;
|
|
55
48
|
}
|
|
56
|
-
/** Number of LLM turns in the last run. */
|
|
57
49
|
get turns() {
|
|
58
50
|
return this._lastResult.turns;
|
|
59
51
|
}
|
|
60
|
-
/** Number of tool calls in the last run. */
|
|
61
52
|
get toolCalls() {
|
|
62
53
|
return this._lastResult.toolCalls;
|
|
63
54
|
}
|
|
64
|
-
/** Structured output from the last run, if requested. */
|
|
65
55
|
get structuredOutput() {
|
|
66
56
|
return this._lastResult.structuredOutput;
|
|
67
57
|
}
|
|
68
|
-
// -- Multi-turn ---------------------------------------------------------
|
|
69
|
-
/** Run another turn on this session (non-streaming). */
|
|
70
58
|
async turn(prompt, options) {
|
|
71
59
|
const result = await this._client._startTurn(this._id, prompt, options);
|
|
72
60
|
this._lastResult = result;
|
|
73
61
|
return result;
|
|
74
62
|
}
|
|
75
|
-
/**
|
|
76
|
-
* Run another turn on this session with streaming events.
|
|
77
|
-
*
|
|
78
|
-
* Returns an {@link EventStream} `AsyncIterable<AgentEvent>`.
|
|
79
|
-
*
|
|
80
|
-
* @example
|
|
81
|
-
* ```ts
|
|
82
|
-
* for await (const event of session.stream("prompt")) {
|
|
83
|
-
* // ...
|
|
84
|
-
* }
|
|
85
|
-
* ```
|
|
86
|
-
*/
|
|
87
63
|
stream(prompt, options) {
|
|
88
64
|
return this._client._startTurnStreaming(this._id, prompt, options, this);
|
|
89
65
|
}
|
|
90
|
-
// -- Lifecycle ----------------------------------------------------------
|
|
91
|
-
/** Cancel the currently running turn, if any. */
|
|
92
66
|
async interrupt() {
|
|
93
67
|
await this._client._interrupt(this._id);
|
|
94
68
|
}
|
|
95
|
-
/** Archive (remove) this session from the server. */
|
|
96
69
|
async archive() {
|
|
97
70
|
await this._client._archive(this._id);
|
|
98
71
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
*/
|
|
72
|
+
async history(options) {
|
|
73
|
+
return this._client.readSessionHistory(this._id, options);
|
|
74
|
+
}
|
|
75
|
+
async subscribeEvents() {
|
|
76
|
+
return this._client.subscribeSessionEvents(this._id);
|
|
77
|
+
}
|
|
106
78
|
async invokeSkill(skillRef, prompt) {
|
|
107
79
|
this._client.requireCapability("skills");
|
|
108
80
|
return this.turn(prompt, { skillRefs: [skillRef] });
|
|
109
81
|
}
|
|
110
|
-
// -- Comms convenience --------------------------------------------------
|
|
111
|
-
/** Send a comms command scoped to this session. */
|
|
112
82
|
async send(command) {
|
|
113
|
-
|
|
83
|
+
const { session_id: _ignored, ...rest } = command;
|
|
84
|
+
return this._client._send(this._id, rest);
|
|
114
85
|
}
|
|
115
|
-
/** List peers visible to this session's comms runtime. */
|
|
116
86
|
async peers() {
|
|
117
87
|
const result = await this._client._peers(this._id);
|
|
118
88
|
return (result.peers ?? []);
|
|
119
89
|
}
|
|
120
|
-
|
|
121
|
-
|
|
90
|
+
toString() {
|
|
91
|
+
const ref = this._ref ? ` ref=${this._ref}` : "";
|
|
92
|
+
return `Session(id=${this._id}${ref})`;
|
|
122
93
|
}
|
|
123
|
-
|
|
124
|
-
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* A session created with `initial_turn: "deferred"`.
|
|
97
|
+
*
|
|
98
|
+
* No first turn has been executed yet. Use {@link startTurn} to run the first
|
|
99
|
+
* turn with optional per-turn overrides.
|
|
100
|
+
*/
|
|
101
|
+
export class DeferredSession {
|
|
102
|
+
_client;
|
|
103
|
+
_id;
|
|
104
|
+
_ref;
|
|
105
|
+
/** @internal — constructed by MeerkatClient, not directly. */
|
|
106
|
+
constructor(client, sessionId, sessionRef) {
|
|
107
|
+
this._client = client;
|
|
108
|
+
this._id = sessionId;
|
|
109
|
+
this._ref = sessionRef;
|
|
110
|
+
}
|
|
111
|
+
get id() {
|
|
112
|
+
return this._id;
|
|
113
|
+
}
|
|
114
|
+
get ref() {
|
|
115
|
+
return this._ref;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Run the first turn on this deferred session.
|
|
119
|
+
*
|
|
120
|
+
* Accepts per-turn overrides (model, provider, etc.) that are applied
|
|
121
|
+
* before the session is materialized.
|
|
122
|
+
*/
|
|
123
|
+
async startTurn(prompt, options) {
|
|
124
|
+
return this._client._startTurn(this._id, prompt, options);
|
|
125
|
+
}
|
|
126
|
+
async interrupt() {
|
|
127
|
+
await this._client._interrupt(this._id);
|
|
128
|
+
}
|
|
129
|
+
async archive() {
|
|
130
|
+
await this._client._archive(this._id);
|
|
131
|
+
}
|
|
132
|
+
async history(options) {
|
|
133
|
+
return this._client.readSessionHistory(this._id, options);
|
|
125
134
|
}
|
|
126
135
|
toString() {
|
|
127
136
|
const ref = this._ref ? ` ref=${this._ref}` : "";
|
|
128
|
-
return `
|
|
137
|
+
return `DeferredSession(id=${this._id}${ref})`;
|
|
129
138
|
}
|
|
130
139
|
}
|
|
131
140
|
//# sourceMappingURL=session.js.map
|
package/dist/session.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.js","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAaH,MAAM,OAAO,OAAO;IAClB,gBAAgB;IAChB,WAAW,CAAY;IAEN,OAAO,CAAgB;IACvB,GAAG,CAAS;IACZ,IAAI,CAAqB;IAE1C,8DAA8D;IAC9D,YAAY,MAAqB,EAAE,MAAiB;QAClD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,SAAS,CAAC;QAC5B,IAAI,CAAC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types.js";
|
|
20
20
|
import type { Session } from "./session.js";
|
|
21
21
|
/** @internal Queue with promise-based get(). */
|
|
22
|
-
declare class AsyncQueue<T> {
|
|
22
|
+
export declare class AsyncQueue<T> {
|
|
23
23
|
private buffer;
|
|
24
24
|
private waiters;
|
|
25
|
+
private nextWaiterId;
|
|
25
26
|
put(item: T): void;
|
|
26
27
|
get(): Promise<T>;
|
|
28
|
+
private _get;
|
|
29
|
+
waitForItemCancelable(): {
|
|
30
|
+
promise: Promise<void>;
|
|
31
|
+
cancel: () => void;
|
|
32
|
+
};
|
|
27
33
|
tryGet(): T | undefined;
|
|
28
34
|
get isEmpty(): boolean;
|
|
29
35
|
failAll(error: Error): void;
|
|
@@ -58,23 +64,7 @@ export declare class EventStream implements AsyncIterable<StreamEvent> {
|
|
|
58
64
|
collect(): Promise<RunResult>;
|
|
59
65
|
/** Consume events, accumulate text deltas, return `[fullText, result]`. */
|
|
60
66
|
collectText(): Promise<[string, RunResult]>;
|
|
67
|
+
private _drainLateEvents;
|
|
61
68
|
private _finalise;
|
|
62
69
|
}
|
|
63
|
-
/**
|
|
64
|
-
* Async iterable of raw comms stream notifications emitted via `comms/stream_event`.
|
|
65
|
-
*/
|
|
66
|
-
export declare class CommsEventStream implements AsyncIterable<Record<string, unknown>> {
|
|
67
|
-
private readonly _streamId;
|
|
68
|
-
private readonly _eventQueue;
|
|
69
|
-
private readonly _onClose;
|
|
70
|
-
constructor(opts: {
|
|
71
|
-
streamId: string;
|
|
72
|
-
eventQueue: AsyncQueue<Record<string, unknown> | null>;
|
|
73
|
-
onClose: (streamId: string) => Promise<void>;
|
|
74
|
-
});
|
|
75
|
-
get streamId(): string;
|
|
76
|
-
[Symbol.asyncIterator](): AsyncGenerator<Record<string, unknown>, void, undefined>;
|
|
77
|
-
close(): Promise<void>;
|
|
78
|
-
}
|
|
79
|
-
export { AsyncQueue };
|
|
80
70
|
//# sourceMappingURL=streaming.d.ts.map
|
package/dist/streaming.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["../src/streaming.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAG5C,gDAAgD;AAChD,
|
|
1
|
+
{"version":3,"file":"streaming.d.ts","sourceRoot":"","sources":["../src/streaming.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAG5C,gDAAgD;AAChD,qBAAa,UAAU,CAAC,CAAC;IACvB,OAAO,CAAC,MAAM,CAAW;IACzB,OAAO,CAAC,OAAO,CAAkD;IACjE,OAAO,CAAC,YAAY,CAAK;IAEzB,GAAG,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI;IAalB,GAAG,IAAI,OAAO,CAAC,CAAC,CAAC;YAIH,IAAI;IAOlB,qBAAqB,IAAI;QAAE,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;QAAC,MAAM,EAAE,MAAM,IAAI,CAAA;KAAE;IAqCvE,MAAM,IAAI,CAAC,GAAG,SAAS;IAIvB,IAAI,OAAO,IAAI,OAAO,CAErB;IAED,OAAO,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;CAW5B;AAID;;;;;GAKG;AACH,qBAAa,WAAY,YAAW,aAAa,CAAC,WAAW,CAAC;IAC5D,gBAAgB,CAAC,UAAU,EAAE,MAAM,CAAC;IACpC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA6C;IACzE,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAmC;IACpE,OAAO,CAAC,QAAQ,CAAC,YAAY,CAA8C;IAC3E,OAAO,CAAC,OAAO,CAA0B;IACzC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAiB;IAE1C,8DAA8D;gBAClD,IAAI,EAAE;QAChB,SAAS,EAAE,MAAM,CAAC;QAClB,UAAU,EAAE,UAAU,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;QACvD,eAAe,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;QAClD,WAAW,EAAE,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,SAAS,CAAC;QACzD,OAAO,CAAC,EAAE,OAAO,CAAC;KACnB;IAQD,oCAAoC;IACpC,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED,wEAAwE;IACxE,IAAI,MAAM,IAAI,SAAS,CAQtB;IAEM,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,cAAc,CAAC,WAAW,EAAE,IAAI,EAAE,SAAS,CAAC;IA2C7E,+DAA+D;IACzD,OAAO,IAAI,OAAO,CAAC,SAAS,CAAC;IAOnC,2EAA2E;IACrE,WAAW,IAAI,OAAO,CAAC,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;YAUlC,gBAAgB;IAgC/B,OAAO,CAAC,SAAS;CASlB"}
|
package/dist/streaming.js
CHANGED
|
@@ -18,24 +18,63 @@
|
|
|
18
18
|
import { isTextDelta, parseEvent } from "./events.js";
|
|
19
19
|
import { MeerkatError } from "./generated/errors.js";
|
|
20
20
|
/** @internal Queue with promise-based get(). */
|
|
21
|
-
class AsyncQueue {
|
|
21
|
+
export class AsyncQueue {
|
|
22
22
|
buffer = [];
|
|
23
23
|
waiters = [];
|
|
24
|
+
nextWaiterId = 0;
|
|
24
25
|
put(item) {
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
this.buffer.push(item);
|
|
27
|
+
if (this.waiters.length === 0) {
|
|
28
|
+
return;
|
|
27
29
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
const waiters = this.waiters;
|
|
31
|
+
this.waiters = [];
|
|
32
|
+
for (const waiter of waiters) {
|
|
33
|
+
waiter.resolve();
|
|
30
34
|
}
|
|
31
35
|
}
|
|
32
36
|
get() {
|
|
37
|
+
return this._get();
|
|
38
|
+
}
|
|
39
|
+
async _get() {
|
|
40
|
+
while (this.buffer.length === 0) {
|
|
41
|
+
await this.waitForItemCancelable().promise;
|
|
42
|
+
}
|
|
43
|
+
return this.buffer.shift();
|
|
44
|
+
}
|
|
45
|
+
waitForItemCancelable() {
|
|
33
46
|
if (this.buffer.length > 0) {
|
|
34
|
-
return
|
|
47
|
+
return {
|
|
48
|
+
promise: Promise.resolve(),
|
|
49
|
+
cancel: () => {
|
|
50
|
+
// Already resolved from the buffer.
|
|
51
|
+
},
|
|
52
|
+
};
|
|
35
53
|
}
|
|
36
|
-
|
|
37
|
-
|
|
54
|
+
const waiterId = this.nextWaiterId++;
|
|
55
|
+
let settled = false;
|
|
56
|
+
const promise = new Promise((resolve) => {
|
|
57
|
+
this.waiters.push({
|
|
58
|
+
id: waiterId,
|
|
59
|
+
resolve: () => {
|
|
60
|
+
settled = true;
|
|
61
|
+
resolve();
|
|
62
|
+
},
|
|
63
|
+
});
|
|
38
64
|
});
|
|
65
|
+
return {
|
|
66
|
+
promise,
|
|
67
|
+
cancel: () => {
|
|
68
|
+
if (settled) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const waiterIndex = this.waiters.findIndex((waiter) => waiter.id === waiterId);
|
|
72
|
+
if (waiterIndex >= 0) {
|
|
73
|
+
this.waiters.splice(waiterIndex, 1);
|
|
74
|
+
}
|
|
75
|
+
settled = true;
|
|
76
|
+
},
|
|
77
|
+
};
|
|
39
78
|
}
|
|
40
79
|
tryGet() {
|
|
41
80
|
return this.buffer.shift();
|
|
@@ -44,16 +83,18 @@ class AsyncQueue {
|
|
|
44
83
|
return this.buffer.length === 0;
|
|
45
84
|
}
|
|
46
85
|
failAll(error) {
|
|
47
|
-
//
|
|
48
|
-
for (
|
|
49
|
-
|
|
50
|
-
waiter(undefined);
|
|
86
|
+
// Wake every current waiter with a sentinel so pending gets can complete.
|
|
87
|
+
for (let i = 0; i < Math.max(this.waiters.length, 1); i += 1) {
|
|
88
|
+
this.buffer.push(undefined);
|
|
51
89
|
}
|
|
90
|
+
const waiters = this.waiters;
|
|
52
91
|
this.waiters = [];
|
|
92
|
+
for (const waiter of waiters) {
|
|
93
|
+
waiter.resolve();
|
|
94
|
+
}
|
|
53
95
|
}
|
|
54
96
|
}
|
|
55
|
-
|
|
56
|
-
const SENTINEL = Symbol("eos");
|
|
97
|
+
const RESPONSE_DRAIN_GRACE_MS = 75;
|
|
57
98
|
/**
|
|
58
99
|
* Typed async iterable of {@link StreamEvent} objects from a running turn.
|
|
59
100
|
*
|
|
@@ -96,30 +137,31 @@ export class EventStream {
|
|
|
96
137
|
});
|
|
97
138
|
while (true) {
|
|
98
139
|
if (responseDone) {
|
|
99
|
-
|
|
100
|
-
while (!this._eventQueue.isEmpty) {
|
|
101
|
-
const raw = this._eventQueue.tryGet();
|
|
102
|
-
if (raw == null)
|
|
103
|
-
break;
|
|
104
|
-
yield parseEvent(raw);
|
|
105
|
-
}
|
|
140
|
+
yield* this._drainLateEvents();
|
|
106
141
|
this._finalise(responseResult);
|
|
107
142
|
return;
|
|
108
143
|
}
|
|
109
144
|
// Race: next event vs response
|
|
110
|
-
const
|
|
145
|
+
const { promise: itemReady, cancel } = this._eventQueue.waitForItemCancelable();
|
|
111
146
|
const result = await Promise.race([
|
|
112
|
-
|
|
147
|
+
itemReady.then(() => ({ kind: "event" })),
|
|
113
148
|
responseHandler.then(() => ({ kind: "response", raw: null })),
|
|
114
149
|
]);
|
|
115
150
|
if (result.kind === "event") {
|
|
116
|
-
|
|
151
|
+
const raw = this._eventQueue.tryGet();
|
|
152
|
+
if (raw === undefined) {
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
if (raw === null) {
|
|
117
156
|
// Sentinel — stream ended
|
|
118
157
|
await responseHandler;
|
|
119
158
|
this._finalise(responseResult);
|
|
120
159
|
return;
|
|
121
160
|
}
|
|
122
|
-
yield parseEvent(
|
|
161
|
+
yield parseEvent(raw);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
cancel();
|
|
123
165
|
}
|
|
124
166
|
// If response, loop back to the top which handles drain
|
|
125
167
|
}
|
|
@@ -141,6 +183,34 @@ export class EventStream {
|
|
|
141
183
|
}
|
|
142
184
|
return [parts.join(""), this.result];
|
|
143
185
|
}
|
|
186
|
+
async *_drainLateEvents() {
|
|
187
|
+
let deadline = Date.now() + RESPONSE_DRAIN_GRACE_MS;
|
|
188
|
+
while (true) {
|
|
189
|
+
let yieldedEvent = false;
|
|
190
|
+
while (!this._eventQueue.isEmpty) {
|
|
191
|
+
const raw = this._eventQueue.tryGet();
|
|
192
|
+
if (raw === undefined) {
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
if (raw === null) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
yieldedEvent = true;
|
|
199
|
+
yield parseEvent(raw);
|
|
200
|
+
}
|
|
201
|
+
if (yieldedEvent) {
|
|
202
|
+
deadline = Date.now() + RESPONSE_DRAIN_GRACE_MS;
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
const remainingMs = deadline - Date.now();
|
|
206
|
+
if (remainingMs <= 0) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
await new Promise((resolve) => {
|
|
210
|
+
setTimeout(resolve, Math.min(remainingMs, 5));
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
}
|
|
144
214
|
_finalise(rawResult) {
|
|
145
215
|
this._result = this._parseResult(rawResult);
|
|
146
216
|
if (!this._sessionId) {
|
|
@@ -151,33 +221,4 @@ export class EventStream {
|
|
|
151
221
|
}
|
|
152
222
|
}
|
|
153
223
|
}
|
|
154
|
-
/**
|
|
155
|
-
* Async iterable of raw comms stream notifications emitted via `comms/stream_event`.
|
|
156
|
-
*/
|
|
157
|
-
export class CommsEventStream {
|
|
158
|
-
_streamId;
|
|
159
|
-
_eventQueue;
|
|
160
|
-
_onClose;
|
|
161
|
-
constructor(opts) {
|
|
162
|
-
this._streamId = opts.streamId;
|
|
163
|
-
this._eventQueue = opts.eventQueue;
|
|
164
|
-
this._onClose = opts.onClose;
|
|
165
|
-
}
|
|
166
|
-
get streamId() {
|
|
167
|
-
return this._streamId;
|
|
168
|
-
}
|
|
169
|
-
async *[Symbol.asyncIterator]() {
|
|
170
|
-
while (true) {
|
|
171
|
-
const raw = await this._eventQueue.get();
|
|
172
|
-
if (raw == null)
|
|
173
|
-
return;
|
|
174
|
-
yield raw;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
async close() {
|
|
178
|
-
await this._onClose(this._streamId);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
// Re-export AsyncQueue for internal use by client
|
|
182
|
-
export { AsyncQueue };
|
|
183
224
|
//# sourceMappingURL=streaming.js.map
|
package/dist/streaming.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streaming.js","sourceRoot":"","sources":["../src/streaming.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGtD,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,gDAAgD;AAChD,MAAM,UAAU;
|
|
1
|
+
{"version":3,"file":"streaming.js","sourceRoot":"","sources":["../src/streaming.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGtD,OAAO,EAAE,YA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AAC,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC;YAChD,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAEO,SAAS,CAAC,SAAkC;QAClD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;QAC5C,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACrB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC;QAC3C,CAAC;QACD,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClB,IAAI,CAAC,QAAQ,CAAC,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC;QAC3C,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { AsyncQueue } from "./streaming.js";
|
|
2
|
+
export declare class EventSubscription<T> implements AsyncIterable<T> {
|
|
3
|
+
private readonly streamId;
|
|
4
|
+
private readonly queue;
|
|
5
|
+
private readonly closeRemote;
|
|
6
|
+
private readonly parseEvent;
|
|
7
|
+
private readonly getTerminalOutcome;
|
|
8
|
+
private closed;
|
|
9
|
+
/** @internal */
|
|
10
|
+
constructor(opts: {
|
|
11
|
+
streamId: string;
|
|
12
|
+
queue: AsyncQueue<Record<string, unknown> | null>;
|
|
13
|
+
closeRemote: (streamId: string) => Promise<void>;
|
|
14
|
+
parseEvent: (raw: Record<string, unknown>) => T;
|
|
15
|
+
getTerminalOutcome: () => Record<string, unknown> | undefined;
|
|
16
|
+
});
|
|
17
|
+
get id(): string;
|
|
18
|
+
get isClosed(): boolean;
|
|
19
|
+
get terminalOutcome(): Record<string, unknown> | undefined;
|
|
20
|
+
close(): Promise<void>;
|
|
21
|
+
[Symbol.asyncIterator](): AsyncGenerator<T, void, undefined>;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=subscription.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscription.d.ts","sourceRo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
5
|
+
parseEvent;
|
|
6
|
+
getTerminalOutcome;
|
|
7
|
+
closed = false;
|
|
8
|
+
/** @internal */
|
|
9
|
+
constructor(opts) {
|
|
10
|
+
this.streamId = opts.streamId;
|
|
11
|
+
this.queue = opts.queue;
|
|
12
|
+
this.closeRemote = opts.closeRemote;
|
|
13
|
+
this.parseEvent = opts.parseEvent;
|
|
14
|
+
this.getTerminalOutcome = opts.getTerminalOutcome;
|
|
15
|
+
}
|
|
16
|
+
get id() {
|
|
17
|
+
return this.streamId;
|
|
18
|
+
}
|
|
19
|
+
get isClosed() {
|
|
20
|
+
return this.closed;
|
|
21
|
+
}
|
|
22
|
+
get terminalOutcome() {
|
|
23
|
+
return this.getTerminalOutcome();
|
|
24
|
+
}
|
|
25
|
+
async close() {
|
|
26
|
+
if (this.closed)
|
|
27
|
+
return;
|
|
28
|
+
this.closed = true;
|
|
29
|
+
this.queue.put(null);
|
|
30
|
+
await this.closeRemote(this.streamId);
|
|
31
|
+
}
|
|
32
|
+
async *[Symbol.asyncIterator]() {
|
|
33
|
+
while (true) {
|
|
34
|
+
const raw = await this.queue.get();
|
|
35
|
+
if (raw == null) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
yield this.parseEvent(raw);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=subscription.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscription.js","sourceRoot":"","sources":["../src/subscription.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,iBAAiB;IACX,QAAQ,CAAS;IACjB,KAAK,CAA6C;IAClD,WAAW,CAAsC;IACjD,UAAU,CAAsC;IAChD,kBAAkB,CAA4C;IACvE,MAAM,GAAG,KAAK,CAAC;IAEvB,gBAAgB;IAChB,YAAY,IAMX;QACC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC9B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QACxB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;QACpC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;QAClC,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC,kBAAkB,CAAC;IACpD,CAAC;IAED,IAAI,EAAE;QACJ,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,IAAI,eAAe;QACjB,OAAO,IAAI,CAAC,kBAAkB,EAAE,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,KAAK;QACT,IAAI,IAAI,CAAC,MAAM;YAAE,OAAO;QACxB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACrB,MAAM,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACxC,CAAC;IAED,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC;QAC3B,OAAO,IAAI,EAAE,CAAC;YACZ,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;YACnC,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;gBAChB,OAAO;YACT,CAAC;YACD,MAAM,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QAC7B,CAAC;IACH,CAAC;CACF"}
|
package/dist/types.d.ts
CHANGED
|
@@ -71,7 +71,97 @@ export interface SessionInfo {
|
|
|
71
71
|
readonly totalTokens: number;
|
|
72
72
|
readonly isActive: boolean;
|
|
73
73
|
}
|
|
74
|
+
export interface SessionToolCall {
|
|
75
|
+
readonly id: string;
|
|
76
|
+
readonly name: string;
|
|
77
|
+
readonly args: unknown;
|
|
78
|
+
}
|
|
79
|
+
export interface SessionToolResult {
|
|
80
|
+
readonly toolUseId: string;
|
|
81
|
+
readonly content: string;
|
|
82
|
+
readonly isError: boolean;
|
|
83
|
+
}
|
|
84
|
+
export interface SessionAssistantBlock {
|
|
85
|
+
readonly blockType: string;
|
|
86
|
+
readonly text?: string;
|
|
87
|
+
readonly id?: string;
|
|
88
|
+
readonly name?: string;
|
|
89
|
+
readonly args?: unknown;
|
|
90
|
+
readonly meta?: Record<string, unknown>;
|
|
91
|
+
}
|
|
92
|
+
export interface SessionMessage {
|
|
93
|
+
readonly role: string;
|
|
94
|
+
readonly content?: string;
|
|
95
|
+
readonly toolCalls: readonly SessionToolCall[];
|
|
96
|
+
readonly stopReason?: string;
|
|
97
|
+
readonly blocks: readonly SessionAssistantBlock[];
|
|
98
|
+
readonly results: readonly SessionToolResult[];
|
|
99
|
+
}
|
|
100
|
+
export interface SessionHistory {
|
|
101
|
+
readonly sessionId: string;
|
|
102
|
+
readonly sessionRef?: string;
|
|
103
|
+
readonly messageCount: number;
|
|
104
|
+
readonly offset: number;
|
|
105
|
+
readonly limit?: number;
|
|
106
|
+
readonly hasMore: boolean;
|
|
107
|
+
readonly messages: readonly SessionMessage[];
|
|
108
|
+
}
|
|
74
109
|
/** A runtime capability and its availability status. */
|
|
110
|
+
export interface EventEnvelope<T = unknown> {
|
|
111
|
+
readonly timestamp_ms: number;
|
|
112
|
+
readonly source_id: string;
|
|
113
|
+
readonly seq: number;
|
|
114
|
+
readonly event_id: string;
|
|
115
|
+
readonly payload: T;
|
|
116
|
+
}
|
|
117
|
+
export interface AttributedEvent {
|
|
118
|
+
readonly source: string;
|
|
119
|
+
readonly profile: string;
|
|
120
|
+
readonly envelope: EventEnvelope;
|
|
121
|
+
}
|
|
122
|
+
export interface MobDefinition {
|
|
123
|
+
readonly id: string;
|
|
124
|
+
readonly profiles: Record<string, unknown>;
|
|
125
|
+
readonly wiring?: Record<string, unknown>;
|
|
126
|
+
readonly flows?: Record<string, unknown>;
|
|
127
|
+
readonly mcp_servers?: Record<string, unknown>;
|
|
128
|
+
readonly skills?: Record<string, unknown>;
|
|
129
|
+
readonly orchestrator?: unknown;
|
|
130
|
+
readonly backend?: unknown;
|
|
131
|
+
}
|
|
132
|
+
export interface SpawnSpec {
|
|
133
|
+
readonly profile: string;
|
|
134
|
+
readonly meerkatId: string;
|
|
135
|
+
readonly initialMessage?: string;
|
|
136
|
+
readonly runtimeMode?: "turn_driven" | "autonomous_host";
|
|
137
|
+
readonly backend?: "subagent" | "external";
|
|
138
|
+
readonly labels?: Record<string, string>;
|
|
139
|
+
readonly context?: Record<string, unknown>;
|
|
140
|
+
readonly resumeSessionId?: string;
|
|
141
|
+
readonly additionalInstructions?: string[];
|
|
142
|
+
}
|
|
143
|
+
export interface MobMember {
|
|
144
|
+
readonly meerkatId: string;
|
|
145
|
+
readonly profile: string;
|
|
146
|
+
readonly memberRef?: Record<string, unknown>;
|
|
147
|
+
readonly runtimeMode?: string;
|
|
148
|
+
readonly state?: string;
|
|
149
|
+
readonly wiredTo?: readonly string[];
|
|
150
|
+
readonly labels?: Record<string, string>;
|
|
151
|
+
readonly sessionId?: string;
|
|
152
|
+
}
|
|
153
|
+
export interface MobSummary {
|
|
154
|
+
readonly mobId: string;
|
|
155
|
+
readonly status: string;
|
|
156
|
+
}
|
|
157
|
+
export interface MobStatus {
|
|
158
|
+
readonly mobId: string;
|
|
159
|
+
readonly status: string;
|
|
160
|
+
}
|
|
161
|
+
export type MobLifecycleAction = "stop" | "resume" | "complete" | "destroy" | "reset";
|
|
162
|
+
export interface MobFlowStatus {
|
|
163
|
+
readonly run?: Record<string, unknown> | null;
|
|
164
|
+
}
|
|
75
165
|
export interface Capability {
|
|
76
166
|
readonly id: string;
|
|
77
167
|
readonly description: string;
|
|
@@ -100,4 +190,23 @@ export interface SessionOptions {
|
|
|
100
190
|
skillRefs?: SkillRef[];
|
|
101
191
|
skillReferences?: string[];
|
|
102
192
|
}
|
|
193
|
+
/** Explicit standalone session-event envelope. */
|
|
194
|
+
export interface AgentEventEnvelope {
|
|
195
|
+
readonly eventId: string;
|
|
196
|
+
readonly sourceId: string;
|
|
197
|
+
readonly seq: number;
|
|
198
|
+
readonly timestampMs: number;
|
|
199
|
+
readonly payload: import("./events.js").AgentEvent;
|
|
200
|
+
}
|
|
201
|
+
/** Mob-wide attributed event emitted by member/mob observation streams. */
|
|
202
|
+
export interface AttributedMobEvent {
|
|
203
|
+
readonly source: string;
|
|
204
|
+
readonly profile: string;
|
|
205
|
+
readonly envelope: AgentEventEnvelope;
|
|
206
|
+
}
|
|
207
|
+
/** Options for creating a mob through the RPC-backed SDK surface. */
|
|
208
|
+
export interface MobCreateOptions {
|
|
209
|
+
prefab?: string;
|
|
210
|
+
definition?: Record<string, unknown>;
|
|
211
|
+
}
|
|
103
212
|
//# sourceMappingURL=types.d.ts.map
|