@beanx/cathygo-protocol 0.1.5 → 0.1.6
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/index.d.ts +12 -2
- package/dist/index.js +34 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -66,6 +66,9 @@ type LearningTurnEventPayload = {
|
|
|
66
66
|
message_id?: string;
|
|
67
67
|
role?: "user" | "assistant" | "system";
|
|
68
68
|
delta?: string;
|
|
69
|
+
content?: string;
|
|
70
|
+
content_revision?: number;
|
|
71
|
+
persisted_message_id?: string;
|
|
69
72
|
message?: string;
|
|
70
73
|
parts?: ConversationMessagePart[];
|
|
71
74
|
metadata?: Record<string, unknown>;
|
|
@@ -87,7 +90,7 @@ type LearningTurnEventPayload = {
|
|
|
87
90
|
};
|
|
88
91
|
type LearningTurnEvent = {
|
|
89
92
|
type: "event";
|
|
90
|
-
event: "session.created" | "session.deleted" | "session.input.accepted" | "session.stop.requested" | "user.message.created" | "turn.started" | "assistant.delta" | "assistant.completed" | "turn.completed" | "turn.failed" | "turn.cancelled" | "agent.activity.started" | "agent.activity.updated" | "agent.activity.completed" | "agent.progress.delta" | `debug.${string}` | `experimental.${string}`;
|
|
93
|
+
event: "session.created" | "session.deleted" | "session.input.accepted" | "session.stop.requested" | "user.message.created" | "turn.started" | "assistant.delta" | "assistant.message" | "assistant.completed" | "turn.completed" | "turn.failed" | "turn.cancelled" | "agent.activity.started" | "agent.activity.updated" | "agent.activity.completed" | "agent.progress.delta" | `debug.${string}` | `experimental.${string}`;
|
|
91
94
|
seq: number;
|
|
92
95
|
payload: LearningTurnEventPayload;
|
|
93
96
|
};
|
|
@@ -197,6 +200,8 @@ interface ConversationMessage {
|
|
|
197
200
|
content: string;
|
|
198
201
|
parts?: ConversationMessagePart[];
|
|
199
202
|
turn_id?: string | null;
|
|
203
|
+
status?: "streaming" | "completed" | "failed" | "aborted" | "superseded";
|
|
204
|
+
content_revision?: number;
|
|
200
205
|
created_at: string;
|
|
201
206
|
metadata?: Record<string, unknown>;
|
|
202
207
|
}
|
|
@@ -392,11 +397,14 @@ type CathyGOTransport = {
|
|
|
392
397
|
|
|
393
398
|
declare class SessionEventCursorStore {
|
|
394
399
|
private readonly cursors;
|
|
400
|
+
private readonly turnStartSeq;
|
|
395
401
|
getAfterSeq(sessionId: string): number;
|
|
402
|
+
getTurnStartSeq(sessionId: string): number | undefined;
|
|
396
403
|
observeEvent(event: LearningTurnEvent): void;
|
|
397
404
|
setAfterSeq(sessionId: string, seq: number): void;
|
|
398
405
|
clear(): void;
|
|
399
406
|
}
|
|
407
|
+
declare function resolveSubscribeAfterSeq(cursorStore: SessionEventCursorStore, sessionId: string, runtime?: SessionRuntimeSnapshot | null): number;
|
|
400
408
|
type SessionSubscriptionClient = {
|
|
401
409
|
getSession(sessionId: string): Promise<ConversationDetail>;
|
|
402
410
|
subscribeSession(sessionId: string, afterSeq: number): Promise<void>;
|
|
@@ -450,8 +458,10 @@ declare class CathyGOProtocolClient {
|
|
|
450
458
|
attachment_relay_max_file_bytes?: number;
|
|
451
459
|
attachment_relay_progress_min_interval_ms?: number;
|
|
452
460
|
} | undefined;
|
|
461
|
+
getConnectResult(): CathyGOConnectResult | undefined;
|
|
453
462
|
getSessionEventCursorStore(): SessionEventCursorStore;
|
|
454
463
|
getLastEventSeq(sessionId: string): number;
|
|
464
|
+
resolveSubscribeAfterSeq(sessionId: string, detail: ConversationDetail): number;
|
|
455
465
|
getActiveSubscriptionSessionId(): string | null;
|
|
456
466
|
activateSession(sessionId: string, afterSeq?: number): Promise<ConversationDetail>;
|
|
457
467
|
deactivateSessionSubscription(): void;
|
|
@@ -497,4 +507,4 @@ declare function photoQuestionTurnInput(text: string, attachments: GatewayAttach
|
|
|
497
507
|
declare function capabilityForTurn(attachments: GatewayAttachment[]): LearningCapability;
|
|
498
508
|
declare function learningTurnInput(text: string, attachments: GatewayAttachment[]): TurnInput;
|
|
499
509
|
|
|
500
|
-
export { type AgentActivity, type AgentPresenceEvent, type AttachmentCommitBlob, type AttachmentCommitParams, type AttachmentInput, type AttachmentRelayProgress, type AttachmentRelayProgressEvent, type AttachmentRelayProgressHandler, type BeanXAccountRuntimeConfig, CathyGOClientError, type CathyGOClientRole, type CathyGOConnectOptions, type CathyGOConnectResult, type CathyGODeviceContext, type CathyGOFrame, type CathyGOIncomingFrame, CathyGOProtocolClient, type CathyGOProtocolClientCallbacks, type CathyGOProtocolClientOptions, type CathyGORequest, type CathyGOResponse, type CathyGOTransport, type CathyGOTransportEventHandler, type CathyGOTransportFrameHandler, type ConversationDetail, type ConversationMessage, type ConversationMessagePart, type ConversationSummary, type GatewayAgentProfile, type GatewayAttachment, type GatewayModelConfig, type GatewayModelConfigUpdate, type GatewayModelOption, type GatewayModelStatus, type GatewayVisibleSettings, type LearningCapability, type LearningTurnEvent, type LearningTurnEventHandler, type LearningTurnEventPayload, type ListResponse, type MessagePartInput, type MultimodalTurnInput, type SameSessionPolicy, SessionEventCursorStore, type SessionInputOptions, type SessionInputResult, type SessionRuntimeSnapshot, type SessionStopResult, type SessionSubscriptionClient, SessionSubscriptionManager, type SettingsItem, type SettingsItemKind, type SettingsSection, type TextTurnInput, type TurnInput, type UploadAttachmentViaRelayOptions, type UploadScope, capabilityForTurn, connectPayload, isAttachmentRelayProgressEvent, isLearningTurnEvent, learningTurnInput, parseConnectPayload, photoQuestionTurnInput, settingsFromPayload, textTurnInput, uploadAttachmentViaRelay };
|
|
510
|
+
export { type AgentActivity, type AgentPresenceEvent, type AttachmentCommitBlob, type AttachmentCommitParams, type AttachmentInput, type AttachmentRelayProgress, type AttachmentRelayProgressEvent, type AttachmentRelayProgressHandler, type BeanXAccountRuntimeConfig, CathyGOClientError, type CathyGOClientRole, type CathyGOConnectOptions, type CathyGOConnectResult, type CathyGODeviceContext, type CathyGOFrame, type CathyGOIncomingFrame, CathyGOProtocolClient, type CathyGOProtocolClientCallbacks, type CathyGOProtocolClientOptions, type CathyGORequest, type CathyGOResponse, type CathyGOTransport, type CathyGOTransportEventHandler, type CathyGOTransportFrameHandler, type ConversationDetail, type ConversationMessage, type ConversationMessagePart, type ConversationSummary, type GatewayAgentProfile, type GatewayAttachment, type GatewayModelConfig, type GatewayModelConfigUpdate, type GatewayModelOption, type GatewayModelStatus, type GatewayVisibleSettings, type LearningCapability, type LearningTurnEvent, type LearningTurnEventHandler, type LearningTurnEventPayload, type ListResponse, type MessagePartInput, type MultimodalTurnInput, type SameSessionPolicy, SessionEventCursorStore, type SessionInputOptions, type SessionInputResult, type SessionRuntimeSnapshot, type SessionStopResult, type SessionSubscriptionClient, SessionSubscriptionManager, type SettingsItem, type SettingsItemKind, type SettingsSection, type TextTurnInput, type TurnInput, type UploadAttachmentViaRelayOptions, type UploadScope, capabilityForTurn, connectPayload, isAttachmentRelayProgressEvent, isLearningTurnEvent, learningTurnInput, parseConnectPayload, photoQuestionTurnInput, resolveSubscribeAfterSeq, settingsFromPayload, textTurnInput, uploadAttachmentViaRelay };
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
// src/session-subscription.ts
|
|
2
|
+
var TERMINAL_TURN_EVENTS = /* @__PURE__ */ new Set(["turn.completed", "turn.failed", "turn.cancelled"]);
|
|
2
3
|
var SessionEventCursorStore = class {
|
|
3
4
|
cursors = /* @__PURE__ */ new Map();
|
|
5
|
+
turnStartSeq = /* @__PURE__ */ new Map();
|
|
4
6
|
getAfterSeq(sessionId) {
|
|
5
7
|
return this.cursors.get(sessionId) ?? 0;
|
|
6
8
|
}
|
|
9
|
+
getTurnStartSeq(sessionId) {
|
|
10
|
+
return this.turnStartSeq.get(sessionId);
|
|
11
|
+
}
|
|
7
12
|
observeEvent(event) {
|
|
8
13
|
const sessionId = sessionIdFromEvent(event);
|
|
9
14
|
if (!sessionId || !event.seq || event.seq <= 0) return;
|
|
@@ -11,6 +16,13 @@ var SessionEventCursorStore = class {
|
|
|
11
16
|
if (event.seq > current) {
|
|
12
17
|
this.cursors.set(sessionId, event.seq);
|
|
13
18
|
}
|
|
19
|
+
if (event.event === "turn.started") {
|
|
20
|
+
this.turnStartSeq.set(sessionId, event.seq);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (TERMINAL_TURN_EVENTS.has(event.event)) {
|
|
24
|
+
this.turnStartSeq.delete(sessionId);
|
|
25
|
+
}
|
|
14
26
|
}
|
|
15
27
|
setAfterSeq(sessionId, seq) {
|
|
16
28
|
if (seq > 0) {
|
|
@@ -19,8 +31,20 @@ var SessionEventCursorStore = class {
|
|
|
19
31
|
}
|
|
20
32
|
clear() {
|
|
21
33
|
this.cursors.clear();
|
|
34
|
+
this.turnStartSeq.clear();
|
|
22
35
|
}
|
|
23
36
|
};
|
|
37
|
+
function resolveSubscribeAfterSeq(cursorStore, sessionId, runtime) {
|
|
38
|
+
const lastEventSeq = runtime?.last_event_seq ?? 0;
|
|
39
|
+
if (!runtime?.active_turn_id) {
|
|
40
|
+
return lastEventSeq;
|
|
41
|
+
}
|
|
42
|
+
const turnStartSeq = cursorStore.getTurnStartSeq(sessionId);
|
|
43
|
+
if (turnStartSeq != null && turnStartSeq > 0) {
|
|
44
|
+
return Math.max(0, turnStartSeq - 1);
|
|
45
|
+
}
|
|
46
|
+
return 0;
|
|
47
|
+
}
|
|
24
48
|
var SessionSubscriptionManager = class {
|
|
25
49
|
constructor(client, cursorStore) {
|
|
26
50
|
this.client = client;
|
|
@@ -35,8 +59,8 @@ var SessionSubscriptionManager = class {
|
|
|
35
59
|
async activateSession(sessionId, afterSeq) {
|
|
36
60
|
this.activeSessionId = sessionId;
|
|
37
61
|
const detail = await this.client.getSession(sessionId);
|
|
38
|
-
const
|
|
39
|
-
const subscribeFrom = afterSeq ??
|
|
62
|
+
const runtime = detail.runtime ?? detail.session.runtime;
|
|
63
|
+
const subscribeFrom = afterSeq ?? resolveSubscribeAfterSeq(this.cursorStore, sessionId, runtime);
|
|
40
64
|
await this.client.subscribeSession(sessionId, subscribeFrom);
|
|
41
65
|
return detail;
|
|
42
66
|
}
|
|
@@ -136,12 +160,19 @@ var CathyGOProtocolClient = class {
|
|
|
136
160
|
getLimits() {
|
|
137
161
|
return this.lastConnect?.limits;
|
|
138
162
|
}
|
|
163
|
+
getConnectResult() {
|
|
164
|
+
return this.lastConnect;
|
|
165
|
+
}
|
|
139
166
|
getSessionEventCursorStore() {
|
|
140
167
|
return this.cursorStore;
|
|
141
168
|
}
|
|
142
169
|
getLastEventSeq(sessionId) {
|
|
143
170
|
return this.cursorStore.getAfterSeq(sessionId);
|
|
144
171
|
}
|
|
172
|
+
resolveSubscribeAfterSeq(sessionId, detail) {
|
|
173
|
+
const runtime = detail.runtime ?? detail.session.runtime;
|
|
174
|
+
return resolveSubscribeAfterSeq(this.cursorStore, sessionId, runtime);
|
|
175
|
+
}
|
|
145
176
|
getActiveSubscriptionSessionId() {
|
|
146
177
|
return this.subscriptionManager.activeSession;
|
|
147
178
|
}
|
|
@@ -538,6 +569,7 @@ export {
|
|
|
538
569
|
learningTurnInput,
|
|
539
570
|
parseConnectPayload,
|
|
540
571
|
photoQuestionTurnInput,
|
|
572
|
+
resolveSubscribeAfterSeq,
|
|
541
573
|
settingsFromPayload,
|
|
542
574
|
textTurnInput,
|
|
543
575
|
uploadAttachmentViaRelay
|