@xopcai/xopc 0.0.479 → 0.0.480

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.
@@ -11,7 +11,7 @@
11
11
  <link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png?v=20260910-1" />
12
12
  <link rel="manifest" href="/site.webmanifest?v=20260910-1" />
13
13
  <title>XOPC — Keep what matters moving.</title>
14
- <script type="module" crossorigin src="/assets/index-DUul4ykl.js"></script>
14
+ <script type="module" crossorigin src="/assets/index-BWJ0tePz.js"></script>
15
15
  <link rel="modulepreload" crossorigin href="/assets/rolldown-runtime-aKtaBQYM.js">
16
16
  <link rel="modulepreload" crossorigin href="/assets/diagnostics-Bo0Z42P_.js">
17
17
  <link rel="modulepreload" crossorigin href="/assets/vendor-react-BOUWij0V.js">
package/dist/package.js CHANGED
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "0.0.479";
2
+ var version = "0.0.480";
3
3
  //#endregion
4
4
  export { version };
@@ -20,6 +20,7 @@ export declare class ChatStreamMapper {
20
20
  private currentAssistantMessageId;
21
21
  private lastAssistantMessageId;
22
22
  private currentAssistantText;
23
+ private reasoningFilter?;
23
24
  private lastAssistantText;
24
25
  private currentAssistantReviewEmitted;
25
26
  private toolCallToMessageId;
@@ -38,6 +39,8 @@ export declare class ChatStreamMapper {
38
39
  private mapMessageStart;
39
40
  private mapMessageUpdate;
40
41
  private mapAssistantSnapshot;
42
+ private appendAssistantText;
43
+ private mapAssistantTextSnapshot;
41
44
  private mapMessageEnd;
42
45
  private mapToolStart;
43
46
  private mapToolUpdate;
@@ -4,6 +4,7 @@ import { isUserTurnDocument } from "../../../packages/gateway-contract/src/user-
4
4
  import { readClarificationPresentation } from "../../../packages/gateway-contract/src/clarifications.js";
5
5
  import { init_src } from "../../../packages/gateway-contract/src/index.js";
6
6
  import { stripRuntimeContextFromUserContent } from "../../session/user-message-display.js";
7
+ import { LeadingAssistantReasoningFilter } from "../../session/assistant-reasoning-text.js";
7
8
  import { productDeliveries } from "../../session/compact-history.js";
8
9
  import { createPetFeedback } from "./pet-feedback.js";
9
10
  //#region src/gateway/chat-stream/mapper.ts
@@ -21,6 +22,7 @@ var ChatStreamMapper = class {
21
22
  currentAssistantMessageId;
22
23
  lastAssistantMessageId;
23
24
  currentAssistantText = "";
25
+ reasoningFilter;
24
26
  lastAssistantText = "";
25
27
  currentAssistantReviewEmitted = false;
26
28
  toolCallToMessageId = /* @__PURE__ */ new Map();
@@ -155,6 +157,7 @@ var ChatStreamMapper = class {
155
157
  const messageId = this.nextAssistantMessageId();
156
158
  this.currentAssistantMessageId = messageId;
157
159
  this.currentAssistantText = "";
160
+ this.reasoningFilter = this.opts.textSurface === "conversation" ? new LeadingAssistantReasoningFilter() : void 0;
158
161
  this.currentAssistantReviewEmitted = false;
159
162
  return [this.make("assistant_message_start", { messageId })];
160
163
  }
@@ -173,29 +176,14 @@ var ChatStreamMapper = class {
173
176
  }
174
177
  const delta = event.assistantMessageEvent;
175
178
  if (delta?.type === "text_delta" && typeof delta.delta === "string" && delta.delta) {
176
- events.push(this.make("assistant_delta", {
177
- messageId,
178
- delta: delta.delta,
179
- offset: this.currentAssistantText.length
180
- }));
181
- this.currentAssistantText += delta.delta;
179
+ const visible = this.reasoningFilter?.append(delta.delta) ?? delta.delta;
180
+ events.push(...this.appendAssistantText(messageId, visible));
182
181
  }
183
182
  if (delta?.type === "thinking_delta" && typeof delta.delta === "string" && delta.delta) events.push(this.make("thinking_delta", {
184
183
  messageId,
185
184
  delta: delta.delta
186
185
  }));
187
- if (!delta) {
188
- const text = extractTextFromMessage(message);
189
- const suffix = appendSuffix(this.currentAssistantText, text);
190
- if (suffix) {
191
- events.push(this.make("assistant_delta", {
192
- messageId,
193
- delta: suffix,
194
- offset: this.currentAssistantText.length
195
- }));
196
- this.currentAssistantText = text || `${this.currentAssistantText}${suffix}`;
197
- }
198
- }
186
+ if (!delta) events.push(...this.mapAssistantTextSnapshot(messageId, message));
199
187
  return events;
200
188
  }
201
189
  mapAssistantSnapshot(raw) {
@@ -210,17 +198,30 @@ var ChatStreamMapper = class {
210
198
  review
211
199
  })];
212
200
  }
213
- const text = extractTextFromMessage(message);
214
- const suffix = appendSuffix(this.currentAssistantText, text);
215
- if (!suffix) return [];
201
+ return this.mapAssistantTextSnapshot(messageId, message);
202
+ }
203
+ appendAssistantText(messageId, delta) {
204
+ if (!delta) return [];
216
205
  const offset = this.currentAssistantText.length;
217
- this.currentAssistantText = text || `${this.currentAssistantText}${suffix}`;
206
+ this.currentAssistantText += delta;
218
207
  return [this.make("assistant_delta", {
219
208
  messageId,
220
- delta: suffix,
209
+ delta,
221
210
  offset
222
211
  })];
223
212
  }
213
+ mapAssistantTextSnapshot(messageId, message, complete = false) {
214
+ let text = extractTextFromMessage(message);
215
+ if (this.reasoningFilter) {
216
+ if (text !== void 0) {
217
+ this.reasoningFilter = new LeadingAssistantReasoningFilter();
218
+ text = this.reasoningFilter.append(text, complete);
219
+ } else if (complete) return this.appendAssistantText(messageId, this.reasoningFilter.append("", true));
220
+ }
221
+ const events = this.appendAssistantText(messageId, appendSuffix(this.currentAssistantText, text));
222
+ if (text && (complete || events.length)) this.currentAssistantText = text;
223
+ return events;
224
+ }
224
225
  mapMessageEnd(raw) {
225
226
  const message = raw;
226
227
  if (message?.role !== "assistant") return [];
@@ -234,14 +235,7 @@ var ChatStreamMapper = class {
234
235
  review
235
236
  }));
236
237
  }
237
- const text = extractTextFromMessage(message);
238
- const suffix = appendSuffix(this.currentAssistantText, text);
239
- if (suffix) events.push(this.make("assistant_delta", {
240
- messageId,
241
- delta: suffix,
242
- offset: this.currentAssistantText.length
243
- }));
244
- this.currentAssistantText = text || this.currentAssistantText;
238
+ events.push(...this.mapAssistantTextSnapshot(messageId, message, true));
245
239
  events.push(this.make("thinking_end", { messageId }));
246
240
  if (this.turnDiffs.length > 0) {
247
241
  events.push(this.make("turn_diff", {
@@ -265,6 +259,7 @@ var ChatStreamMapper = class {
265
259
  this.lastAssistantMessageId = messageId;
266
260
  this.currentAssistantMessageId = void 0;
267
261
  this.currentAssistantText = "";
262
+ this.reasoningFilter = void 0;
268
263
  this.currentAssistantReviewEmitted = false;
269
264
  return events;
270
265
  }
@@ -417,7 +412,10 @@ var ChatStreamMapper = class {
417
412
  return events;
418
413
  }
419
414
  ensureAssistantMessageId() {
420
- if (!this.currentAssistantMessageId) this.currentAssistantMessageId = this.nextAssistantMessageId();
415
+ if (!this.currentAssistantMessageId) {
416
+ this.currentAssistantMessageId = this.nextAssistantMessageId();
417
+ this.reasoningFilter = this.opts.textSurface === "conversation" ? new LeadingAssistantReasoningFilter() : void 0;
418
+ }
421
419
  return this.currentAssistantMessageId;
422
420
  }
423
421
  nextAssistantMessageId() {
@@ -0,0 +1,8 @@
1
+ /** Strip leading provider reasoning tags while keeping the published text append-only. */
2
+ export declare class LeadingAssistantReasoningFilter {
3
+ private prefix;
4
+ private closingTag?;
5
+ private removedReasoning;
6
+ append(chunk: string, complete?: boolean): string;
7
+ }
8
+ export declare function stripLeadingAssistantReasoning(text: string): string;
@@ -0,0 +1,49 @@
1
+ //#region src/session/assistant-reasoning-text.ts
2
+ const REASONING_TAGS = [
3
+ "think",
4
+ "thinking",
5
+ "analysis",
6
+ "reasoning"
7
+ ];
8
+ const LEADING_TAG = /^<\s*(\/?)\s*(think|thinking|analysis|reasoning)\s*>/i;
9
+ const PARTIAL_TAG = /^<\s*\/?\s*([a-z]*)\s*$/i;
10
+ const PARTIAL_CLOSING_TAG = /<\s*(?:\/\s*[a-z]*\s*)?$/i;
11
+ /** Strip leading provider reasoning tags while keeping the published text append-only. */
12
+ var LeadingAssistantReasoningFilter = class {
13
+ prefix = "";
14
+ closingTag;
15
+ removedReasoning = false;
16
+ append(chunk, complete = false) {
17
+ if (this.prefix === void 0) return chunk;
18
+ this.prefix += chunk;
19
+ for (;;) {
20
+ if (this.closingTag) {
21
+ const closing = this.closingTag.exec(this.prefix);
22
+ if (!closing) {
23
+ this.prefix = complete ? void 0 : PARTIAL_CLOSING_TAG.exec(this.prefix)?.[0] ?? "";
24
+ return "";
25
+ }
26
+ this.prefix = this.prefix.slice(closing.index + closing[0].length);
27
+ this.closingTag = void 0;
28
+ }
29
+ const candidate = this.prefix.trimStart();
30
+ const tag = LEADING_TAG.exec(candidate);
31
+ if (tag) {
32
+ this.removedReasoning = true;
33
+ this.prefix = candidate.slice(tag[0].length);
34
+ if (!tag[1]) this.closingTag = new RegExp(`<\\s*\\/\\s*${tag[2]}\\s*>`, "i");
35
+ continue;
36
+ }
37
+ const partial = PARTIAL_TAG.exec(candidate);
38
+ if (!complete && (!candidate || partial && REASONING_TAGS.some((name) => name.startsWith(partial[1].toLowerCase())))) return "";
39
+ const visible = this.removedReasoning ? candidate : this.prefix;
40
+ this.prefix = void 0;
41
+ return visible;
42
+ }
43
+ }
44
+ };
45
+ function stripLeadingAssistantReasoning(text) {
46
+ return new LeadingAssistantReasoningFilter().append(text, true);
47
+ }
48
+ //#endregion
49
+ export { LeadingAssistantReasoningFilter, stripLeadingAssistantReasoning };
@@ -3,4 +3,4 @@ import type { ClientHistoryMessage } from './client-history.js';
3
3
  export declare function conciseProgress(text: string): string;
4
4
  export declare function productDeliveries(result: unknown): ProductDeliveryEnvelope[];
5
5
  /** Transport-only projection: stored transcripts and default clients remain unchanged. */
6
- export declare function compactHistory(messages: ClientHistoryMessage[]): ClientHistoryMessage[];
6
+ export declare function compactHistory(messages: ClientHistoryMessage[], personal?: boolean): ClientHistoryMessage[];
@@ -1,5 +1,6 @@
1
1
  import { parseProductDeliveryEnvelope, parseProductDeliveryText } from "../../packages/gateway-contract/src/product-delivery.js";
2
2
  import { init_src } from "../../packages/gateway-contract/src/index.js";
3
+ import { stripLeadingAssistantReasoning } from "./assistant-reasoning-text.js";
3
4
  //#region src/session/compact-history.ts
4
5
  init_src();
5
6
  function conciseProgress(text) {
@@ -24,13 +25,26 @@ function generatedMediaId(call) {
24
25
  return;
25
26
  }
26
27
  }
28
+ function personalReplyText(message) {
29
+ const hasTools = !!message.toolCalls?.length;
30
+ const blocks = Array.isArray(message.rawContent) ? message.rawContent.flatMap((block) => {
31
+ if (!block || typeof block !== "object") return [];
32
+ const value = block;
33
+ return value.type === "text" && typeof value.text === "string" ? [value] : [];
34
+ }) : [];
35
+ return stripLeadingAssistantReasoning(blocks.length ? blocks.filter((block) => block.presentation === "answer" || !hasTools && block.presentation === void 0).map((block) => block.text).join("") : hasTools ? "" : message.content);
36
+ }
27
37
  /** Transport-only projection: stored transcripts and default clients remain unchanged. */
28
- function compactHistory(messages) {
38
+ function compactHistory(messages, personal = false) {
39
+ const contents = messages.map((message) => {
40
+ if (message.role === "assistant" && personal) return personalReplyText(message);
41
+ return message.toolCalls?.length ? conciseProgress(message.content) : message.content;
42
+ });
29
43
  const replyIndex = /* @__PURE__ */ new Map();
30
44
  const mediaByReply = /* @__PURE__ */ new Map();
31
45
  const seenMedia = /* @__PURE__ */ new Set();
32
46
  messages.forEach((message, index) => {
33
- if (message.role === "assistant" && message.turnId && !message.toolCalls?.length && message.content.trim()) replyIndex.set(message.turnId, index);
47
+ if (message.role === "assistant" && message.turnId && contents[index].trim() && (personal || !message.toolCalls?.length)) replyIndex.set(message.turnId, index);
34
48
  });
35
49
  messages.forEach((message, index) => {
36
50
  for (const call of message.toolCalls ?? []) {
@@ -46,8 +60,8 @@ function compactHistory(messages) {
46
60
  return messages.flatMap((message, index) => {
47
61
  if (message.role === "system") return [];
48
62
  if (message.role === "user") return [message];
49
- const narration = !!message.toolCalls?.length;
50
- const content = narration ? conciseProgress(message.content) : message.content;
63
+ const narration = !(personal && message.role === "assistant") && !!message.toolCalls?.length;
64
+ const content = contents[index];
51
65
  const mediaAndReview = (Array.isArray(message.rawContent) ? message.rawContent : []).filter((block) => block && typeof block === "object" && [
52
66
  "image",
53
67
  "audio",
@@ -206,7 +206,7 @@ var SessionStore = class {
206
206
  startsNewBubbleTurnIds: listTaskUpdateRunIds(key),
207
207
  taskUpdateTriggers: listTaskUpdateTriggers(key)
208
208
  });
209
- const messages = options.compact ? compactHistory(history) : history;
209
+ const messages = options.compact ? compactHistory(history, metadata.customData?.personalAgent === true) : history;
210
210
  const session = {
211
211
  ...metadata,
212
212
  messages,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xopcai/xopc",
3
- "version": "0.0.479",
3
+ "version": "0.0.480",
4
4
  "description": "An open-source AI assistant for work and everyday life. Remembers context and helps you get things done. Local-first, on a computer you choose.",
5
5
  "type": "module",
6
6
  "main": "dist/src/index.js",
@@ -175,9 +175,9 @@
175
175
  "vue": "^3.5.44",
176
176
  "xlsx": "file:web/vendor/xlsx-0.20.3.tgz",
177
177
  "@xopcai/browser-control-contract": "0.1.0",
178
- "@xopcai/endpoint-tools-client": "0.0.0",
179
178
  "@xopcai/computer-control-contract": "0.1.0",
180
179
  "@xopcai/endpoint-tools-protocol": "0.0.0",
180
+ "@xopcai/endpoint-tools-client": "0.0.0",
181
181
  "@xopcai/gateway-contract": "0.0.0",
182
182
  "@xopcai/image-providers": "0.1.0",
183
183
  "@xopcai/realtime-client": "0.0.0",