@g9tm/aiassistant 1.9.4 → 1.9.5

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.
@@ -106,6 +106,8 @@ export declare class Assistant {
106
106
  private emit;
107
107
  /** Opens a conversation from its history (from the end; history never animates). */
108
108
  open(conversationId: string): Promise<void>;
109
+ /** Counts fresh(): a send that returns after one is dropped. */
110
+ private generation;
109
111
  /** A new conversation. */
110
112
  fresh(): void;
111
113
  /** Sends a question; refused while a run is working (the button is "stop" then). With `refs`, the things picked by `@`. */
package/dist/assistant.js CHANGED
@@ -33,6 +33,8 @@ export class Assistant {
33
33
  this.error = null;
34
34
  /** `client.call`s already answered (a replayed event never runs a tool twice). */
35
35
  this.answeredCalls = new Set();
36
+ /** Counts fresh(): a send that returns after one is dropped. */
37
+ this.generation = 0;
36
38
  this.api = new AssistantApi(host, options.base);
37
39
  this.texts = createTexts(host.locale, options.texts);
38
40
  this.transport = pickTransport(this.api, host, options);
@@ -81,6 +83,7 @@ export class Assistant {
81
83
  }
82
84
  /** A new conversation. */
83
85
  fresh() {
86
+ this.generation++;
84
87
  // A run still working belongs to the old conversation: it is cancelled on the server (no tokens spent on an answer
85
88
  // nobody waits for) and dropped here — kept, it held «busy» for good and every later question was refused (a
86
89
  // host's eval battery, 2026-11-28).
@@ -119,8 +122,15 @@ export class Assistant {
119
122
  input.model = this.model;
120
123
  if (refs?.length)
121
124
  input.refs = refs.slice(0, 5).map(({ kind, id, label }) => ({ kind, id, label }));
125
+ const generation = this.generation;
122
126
  try {
123
127
  const t = await this.api.send(input);
128
+ // A new conversation began while this question was on its way: its run belongs to nobody — cancelled, not
129
+ // followed (else it waited on the device's tool calls for minutes; a host's eval battery, 2026-11-28).
130
+ if (generation !== this.generation) {
131
+ void this.api.cancel(t.runId).catch(() => undefined);
132
+ return false;
133
+ }
124
134
  this.store.id = t.conversationId;
125
135
  this.attachments = [];
126
136
  this.follow(t.runId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@g9tm/aiassistant",
3
- "version": "1.9.4",
3
+ "version": "1.9.5",
4
4
  "description": "Headless client of the G9 AI assistant: API client, run state, transports, block view models, safe text and Persian helpers. No DOM, no framework.",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -33,7 +33,7 @@
33
33
  "access": "public"
34
34
  },
35
35
  "dependencies": {
36
- "@g9tm/aiassistant-contracts": "1.9.4"
36
+ "@g9tm/aiassistant-contracts": "1.9.5"
37
37
  },
38
38
  "scripts": {
39
39
  "build": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\" && tsc -p tsconfig.json",