@foir/sdk 0.30.0 → 0.30.1

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.
@@ -133,12 +133,6 @@ export interface FoirChatTransportOptions {
133
133
  */
134
134
  pageTools?: Record<string, FoirPageTool>;
135
135
  }
136
- /**
137
- * One run's events as `useChat`'s chunks. A run outlives a stream: it stops
138
- * for a decision and carries on once it is made, so what the person has
139
- * already been shown (the steps, the last event) is kept per run, and each
140
- * stream only opens and closes its own text.
141
- */
142
136
  export declare class FoirRunChunks {
143
137
  private readonly runId;
144
138
  private readonly runs;
@@ -158,6 +152,8 @@ export declare class FoirRunChunks {
158
152
  private toRun;
159
153
  /** Acts held for a decision, by anyone. */
160
154
  private readonly held;
155
+ /** The messages whose text this run has shown, streamed or whole. */
156
+ private readonly shown;
161
157
  /** `runs` names the page's tools the transport runs itself. */
162
158
  constructor(runId: string, runs?: (tool: string) => boolean);
163
159
  /** The calls to the page's tools that arrived for the transport to run. */
package/dist/ai.js CHANGED
@@ -60,6 +60,12 @@ function randomSecret() {
60
60
  // src/ai/index.ts
61
61
  var TOOL_KINDS = /* @__PURE__ */ new Set(["VERB", "OPERATION", "MCP_TOOL", "AGENT", "PAGE_TOOL"]);
62
62
  var STOPS = /* @__PURE__ */ new Set(["COMPLETED", "FAILED", "SKIPPED", "CANCELLED", "HELD"]);
63
+ function keptText(parts) {
64
+ return parts.map((p) => {
65
+ const part = p;
66
+ return part && part.type === "text" && typeof part.text === "string" ? part.text : "";
67
+ }).join("");
68
+ }
63
69
  var FoirRunChunks = class {
64
70
  /** `runs` names the page's tools the transport runs itself. */
65
71
  constructor(runId, runs = () => false) {
@@ -84,6 +90,8 @@ var FoirRunChunks = class {
84
90
  toRun = [];
85
91
  /** Acts held for a decision, by anyone. */
86
92
  held = /* @__PURE__ */ new Set();
93
+ /** The messages whose text this run has shown, streamed or whole. */
94
+ shown = /* @__PURE__ */ new Set();
87
95
  /** The calls to the page's tools that arrived for the transport to run. */
88
96
  takeCalls() {
89
97
  const out = this.toRun;
@@ -118,6 +126,7 @@ var FoirRunChunks = class {
118
126
  switch (event.kind) {
119
127
  case "TEXT": {
120
128
  if (!event.text) break;
129
+ if (event.messageId) this.shown.add(event.messageId);
121
130
  this.open(out, fresh);
122
131
  this.closeReasoning(out);
123
132
  if (!this.textId) {
@@ -146,6 +155,19 @@ var FoirRunChunks = class {
146
155
  out.push(...this.toolChunks(node));
147
156
  break;
148
157
  }
158
+ case "MESSAGE": {
159
+ const message = event.message;
160
+ if (!message || message.role !== "ASSISTANT" || this.shown.has(message.id)) break;
161
+ const text = keptText(message.parts);
162
+ if (!text) break;
163
+ this.shown.add(message.id);
164
+ this.open(out, fresh);
165
+ this.closeText(out);
166
+ this.closeReasoning(out);
167
+ const id = `${this.runId}:m:${message.id}`;
168
+ out.push({ type: "text-start", id }, { type: "text-delta", id, delta: text }, { type: "text-end", id });
169
+ break;
170
+ }
149
171
  case "DATA": {
150
172
  if (!event.dataName) break;
151
173
  this.open(out, fresh);
@@ -161,7 +183,7 @@ var FoirRunChunks = class {
161
183
  if (event.status === "FAILED") {
162
184
  out.push({ type: "error", errorText: event.error || "The answer could not be finished." });
163
185
  }
164
- if (event.status === "SKIPPED" && event.answer && this.tools.size === 0) {
186
+ if (event.status === "SKIPPED" && event.answer && this.tools.size === 0 && this.shown.size === 0) {
165
187
  const id = `${this.runId}:refusal`;
166
188
  out.push({ type: "text-start", id }, { type: "text-delta", id, delta: event.answer }, { type: "text-end", id });
167
189
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foir/sdk",
3
- "version": "0.30.0",
3
+ "version": "0.30.1",
4
4
  "description": "Official Foir SDK — editor iframe client + server-side platform helpers",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -186,8 +186,8 @@
186
186
  "ws": "^8.18.0",
187
187
  "y-websocket": "^3.0.0",
188
188
  "yjs": "^13.6.30",
189
- "@foir/proto-ts": "0.109.0",
190
- "@foir/access-vocab": "0.0.0"
189
+ "@foir/access-vocab": "0.0.0",
190
+ "@foir/proto-ts": "0.109.0"
191
191
  },
192
192
  "engines": {
193
193
  "node": ">=18.0.0"