@vrealtime/server 0.1.0 → 0.2.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/dist/capabilities.d.ts +1 -1
- package/dist/capabilities.js +7 -2
- package/dist/index.js +10 -4
- package/dist/tool-stream.d.ts +8 -0
- package/dist/tool-stream.js +29 -0
- package/package.json +3 -3
package/dist/capabilities.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export interface CapabilityRule {
|
|
|
7
7
|
token: string;
|
|
8
8
|
available(model: Capabilities): boolean;
|
|
9
9
|
}
|
|
10
|
-
/** Every capability this server implements.
|
|
10
|
+
/** Every capability this server implements. */
|
|
11
11
|
export declare const CAPABILITY_RULES: readonly CapabilityRule[];
|
|
12
12
|
/** The tokens sessions of an agent with this model may negotiate. */
|
|
13
13
|
export declare function supportedCapabilities(model: Capabilities, rules?: readonly CapabilityRule[]): ReadonlySet<string>;
|
package/dist/capabilities.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { GLOBAL_TOOL_IDS_V1, TOOL_STREAM_V1 } from '@vrealtime/protocol';
|
|
2
|
+
/** Every capability this server implements. */
|
|
3
|
+
export const CAPABILITY_RULES = [
|
|
4
|
+
// Any model: without argument streaming a call goes straight from start to arguments-complete.
|
|
5
|
+
{ token: TOOL_STREAM_V1, available: () => true },
|
|
6
|
+
{ token: GLOBAL_TOOL_IDS_V1, available: () => true },
|
|
7
|
+
];
|
|
3
8
|
/** The tokens sessions of an agent with this model may negotiate. */
|
|
4
9
|
export function supportedCapabilities(model, rules = CAPABILITY_RULES) {
|
|
5
10
|
return new Set(rules.filter((rule) => rule.available(model)).map((rule) => rule.token));
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { startSession, } from '@vrealtime/core';
|
|
2
|
-
import { Inbox, Outbox, decodeAudioFrame, decodeClientMessage, encodeAudioFrame, encodeMessage, negotiateCapabilities, PROTOCOL_VERSION, } from '@vrealtime/protocol';
|
|
2
|
+
import { Inbox, Outbox, decodeAudioFrame, decodeClientMessage, encodeAudioFrame, encodeMessage, negotiateCapabilities, PROTOCOL_VERSION, TOOL_STREAM_V1, } from '@vrealtime/protocol';
|
|
3
3
|
import { supportedCapabilities } from './capabilities.js';
|
|
4
|
+
import { legacyPreview, toolStreamMessage } from './tool-stream.js';
|
|
4
5
|
const PCM24 = { encoding: 'pcm16', sampleRate: 24000, channels: 1 };
|
|
5
6
|
const REFUSED = Symbol('refused');
|
|
6
7
|
const FLUSH_INTERVAL_MS = 10;
|
|
@@ -62,10 +63,15 @@ class LiveSession {
|
|
|
62
63
|
agentSession.on('transcript', (e) => this.send({ type: 'transcript', role: e.role, itemId: e.itemId, text: e.text, final: e.final }));
|
|
63
64
|
agentSession.on('text', (e) => this.send({ type: 'text', responseId: e.responseId, delta: e.delta }));
|
|
64
65
|
agentSession.on('audio', (e) => this.#audio(e));
|
|
65
|
-
// `arguments`
|
|
66
|
+
// `arguments` is a required member on the wire: a missing value is sent as null.
|
|
66
67
|
agentSession.on('tool.call', (e) => this.send({ type: 'tool.call', callId: e.callId, epoch: e.epoch, turnId: e.turnId, name: e.name, arguments: e.arguments ?? null }));
|
|
67
|
-
|
|
68
|
-
|
|
68
|
+
// One source for call progress: the full lifecycle with tool-stream-v1, the 1.0 preview without it, never both.
|
|
69
|
+
const toolStream = this.capabilities.includes(TOOL_STREAM_V1);
|
|
70
|
+
agentSession.on('tool.stream', (e) => {
|
|
71
|
+
const message = toolStream ? toolStreamMessage(e) : legacyPreview(e);
|
|
72
|
+
if (message)
|
|
73
|
+
this.send(message);
|
|
74
|
+
});
|
|
69
75
|
agentSession.on('interrupted', (e) => {
|
|
70
76
|
this.#dropAudio(e.epoch);
|
|
71
77
|
this.send({ type: 'interrupted', epoch: e.epoch });
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ToolStreamEvent } from '@vrealtime/core';
|
|
2
|
+
import type { ServerMessage, Unsequenced } from '@vrealtime/protocol';
|
|
3
|
+
type Outgoing = Unsequenced<ServerMessage>;
|
|
4
|
+
/** With `tool-stream-v1`: the step as a `tool.stream` message. A server tool's output never leaves the server. */
|
|
5
|
+
export declare function toolStreamMessage(event: ToolStreamEvent): Outgoing;
|
|
6
|
+
/** Without the capability: argument fragments and progress as the `tool.call.delta` preview of protocol 1.0; nothing else is sent. */
|
|
7
|
+
export declare function legacyPreview(event: ToolStreamEvent): Outgoing | undefined;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** With `tool-stream-v1`: the step as a `tool.stream` message. A server tool's output never leaves the server. */
|
|
2
|
+
export function toolStreamMessage(event) {
|
|
3
|
+
const call = { type: 'tool.stream', callId: event.callId, epoch: event.epoch, turnId: event.turnId, name: event.name };
|
|
4
|
+
switch (event.phase) {
|
|
5
|
+
case 'start':
|
|
6
|
+
case 'cancelled':
|
|
7
|
+
return { ...call, phase: event.phase };
|
|
8
|
+
case 'arguments-delta':
|
|
9
|
+
return { ...call, phase: event.phase, delta: event.delta };
|
|
10
|
+
// Required members on the wire: a missing value is sent as null.
|
|
11
|
+
case 'arguments-complete':
|
|
12
|
+
return { ...call, phase: event.phase, arguments: event.arguments ?? null };
|
|
13
|
+
case 'progress':
|
|
14
|
+
return { ...call, phase: event.phase, progress: event.progress ?? null };
|
|
15
|
+
case 'settled':
|
|
16
|
+
return event.result.ok ? { ...call, phase: 'settled', ok: true } : { ...call, phase: 'settled', ok: false, code: event.result.code };
|
|
17
|
+
case 'failed':
|
|
18
|
+
return { ...call, phase: event.phase, message: event.message };
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/** Without the capability: argument fragments and progress as the `tool.call.delta` preview of protocol 1.0; nothing else is sent. */
|
|
22
|
+
export function legacyPreview(event) {
|
|
23
|
+
const call = { type: 'tool.call.delta', callId: event.callId, epoch: event.epoch, name: event.name };
|
|
24
|
+
if (event.phase === 'arguments-delta')
|
|
25
|
+
return { ...call, preview: { argumentsDelta: event.delta } };
|
|
26
|
+
if (event.phase === 'progress')
|
|
27
|
+
return { ...call, preview: event.progress ?? null };
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vrealtime/server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "vRealTime server: attach any WebSocket, Node serve(), Cloudflare Workers and Durable Objects",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
"build": "tsc -p tsconfig.build.json"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"@vrealtime/core": "0.
|
|
54
|
-
"@vrealtime/protocol": "0.
|
|
53
|
+
"@vrealtime/core": "0.2.0",
|
|
54
|
+
"@vrealtime/protocol": "0.2.0"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
57
|
"ws": "^8.0.0"
|