@pasko70/pibo 1.8.0 → 1.8.2

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.
@@ -8,6 +8,20 @@ export class TelemetryStore {
8
8
  constructor(db) {
9
9
  this.db = db;
10
10
  }
11
+ transaction(action) {
12
+ if (this.db.isTransaction)
13
+ return action();
14
+ this.db.exec("BEGIN IMMEDIATE");
15
+ try {
16
+ const result = action();
17
+ this.db.exec("COMMIT");
18
+ return result;
19
+ }
20
+ catch (error) {
21
+ this.db.exec("ROLLBACK");
22
+ throw error;
23
+ }
24
+ }
11
25
  listSessions(input = {}) {
12
26
  return listTelemetrySessions(this.db, input);
13
27
  }
@@ -75,6 +75,7 @@ export async function sendGatewayMessageAndWaitForReply(event, options = {}) {
75
75
  let settled = false;
76
76
  let response;
77
77
  let reply;
78
+ let messageFinished = false;
78
79
  const timeout = setTimeout(() => {
79
80
  finish(new Error(`Timed out waiting for assistant reply from session "${event.piboSessionId}"`));
80
81
  }, timeoutMs);
@@ -91,14 +92,21 @@ export async function sendGatewayMessageAndWaitForReply(event, options = {}) {
91
92
  resolve(result);
92
93
  }
93
94
  };
95
+ const finishCompletedReply = () => {
96
+ if (!response?.ok || !messageFinished)
97
+ return;
98
+ finish(reply
99
+ ? { response, reply }
100
+ : new Error(`Session "${eventWithId.piboSessionId}" finished without an assistant reply`));
101
+ };
94
102
  const handleFrame = (frame) => {
95
103
  if (frame.type === "res" && frame.id === id) {
96
104
  response = frame;
97
105
  if (!frame.ok) {
98
106
  finish(new Error(frame.error?.message ?? "Gateway rejected the message"));
99
107
  }
100
- else if (reply) {
101
- finish({ response, reply });
108
+ else {
109
+ finishCompletedReply();
102
110
  }
103
111
  return;
104
112
  }
@@ -111,13 +119,14 @@ export async function sendGatewayMessageAndWaitForReply(event, options = {}) {
111
119
  finish(new Error(output.error));
112
120
  return;
113
121
  }
114
- if (output.type === "assistant_message" &&
115
- output.piboSessionId === eventWithId.piboSessionId &&
116
- output.eventId === eventWithId.id) {
122
+ if (output.piboSessionId !== eventWithId.piboSessionId || !("eventId" in output) || output.eventId !== eventWithId.id)
123
+ return;
124
+ if (output.type === "assistant_message") {
117
125
  reply = output;
118
- if (response?.ok) {
119
- finish({ response, reply });
120
- }
126
+ }
127
+ else if (output.type === "message_finished") {
128
+ messageFinished = true;
129
+ finishCompletedReply();
121
130
  }
122
131
  };
123
132
  socket.once("connect", () => {
@@ -252,7 +252,7 @@ export class PiboRalphService {
252
252
  },
253
253
  });
254
254
  this.store.attachRunSession(job.id, run.id, session.id);
255
- const finalAnswer = await this.emitMessageAndWait(session.id, buildRalphPrompt(job), { isCancelled: () => this.cancelledRuns.has(run.id) });
255
+ const finalAnswer = await this.emitMessageAndWait(session.id, buildRalphPrompt(job));
256
256
  return { piboSessionId: session.id, finalAnswer };
257
257
  }
258
258
  resolveTarget(job) { if (job.target.kind === 'room') {
@@ -263,7 +263,7 @@ export class PiboRalphService {
263
263
  throw new Error('Target room is archived');
264
264
  return { roomId: room.id, workspace: room.workspace ?? getDefaultPiboWorkspace() };
265
265
  } const room = this.roomService.ensureDefaultRoom({ name: 'Shared Chat' }); return { roomId: room.id, workspace: room.workspace ?? getDefaultPiboWorkspace() }; }
266
- async emitMessageAndWait(piboSessionId, text, options = {}) {
266
+ async emitMessageAndWait(piboSessionId, text) {
267
267
  const eventId = `ralph_msg_${randomUUID()}`;
268
268
  return await new Promise((resolve, reject) => {
269
269
  let settled = false;
@@ -308,9 +308,7 @@ export class PiboRalphService {
308
308
  finish(lastSessionError ? new Error(lastSessionError) : undefined);
309
309
  if (event.type === 'session_error') {
310
310
  lastSessionError = event.error;
311
- const providerAttempt = event.errorDetails?.origin === 'provider' && Boolean(event.errorDetails.api || event.errorDetails.provider || event.errorDetails.model);
312
- if (!providerAttempt || options.isCancelled?.())
313
- finish(new Error(event.error));
311
+ finish(new Error(event.error));
314
312
  }
315
313
  });
316
314
  this.options.context.emit({ type: 'message', piboSessionId, id: eventId, source: 'service', text }).catch((error) => finish(error instanceof Error ? error : new Error(String(error))));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pasko70/pibo",
3
- "version": "1.8.0",
3
+ "version": "1.8.2",
4
4
  "type": "module",
5
5
  "imports": {
6
6
  "vscode": "./src/apps/chat-vscode/extension/src/vscode-shim.js"