gemi 0.235.0 → 0.236.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.
Files changed (51) hide show
  1. package/dist/ai/client/conformance.d.ts +4 -2
  2. package/dist/ai/client/conformance.d.ts.map +1 -1
  3. package/dist/ai/client/index.js +72 -6
  4. package/dist/ai/client/index.js.map +1 -1
  5. package/dist/ai/client/reducer.d.ts.map +1 -1
  6. package/dist/ai/index.js +3 -3
  7. package/dist/ai/index.js.map +3 -3
  8. package/dist/ai/providers/call.d.ts +1 -1
  9. package/dist/ai/types.d.ts +5 -0
  10. package/dist/ai/types.d.ts.map +1 -1
  11. package/dist/ai/useChat.d.ts +35 -0
  12. package/dist/ai/useChat.d.ts.map +1 -1
  13. package/dist/auth/AuthController.d.ts.map +1 -1
  14. package/dist/{chunk-adfkz2kf.js → chunk-0e5sq42y.js} +1 -1
  15. package/dist/chunk-4800w7qx.js.map +2 -2
  16. package/dist/{chunk-cb7mgx75.js → chunk-73541m4t.js} +6 -6
  17. package/dist/{chunk-cb7mgx75.js.map → chunk-73541m4t.js.map} +3 -3
  18. package/dist/{chunk-t5gbp0yr.js → chunk-dav7mv8t.js} +2 -2
  19. package/dist/{chunk-t5gbp0yr.js.map → chunk-dav7mv8t.js.map} +3 -3
  20. package/dist/{chunk-1yws1nvb.js → chunk-hy54f691.js} +2 -2
  21. package/dist/{chunk-1yws1nvb.js.map → chunk-hy54f691.js.map} +1 -1
  22. package/dist/{chunk-2hw8sr4d.js → chunk-wbj4jh1h.js} +1 -1
  23. package/dist/{chunk-2hw8sr4d.js.map → chunk-wbj4jh1h.js.map} +1 -1
  24. package/dist/{chunk-9359fg6r.js → chunk-yknc5rgh.js} +1 -1
  25. package/dist/{chunk-9359fg6r.js.map → chunk-yknc5rgh.js.map} +1 -1
  26. package/dist/chunks/{RealtimeClient-C5Zh3fD6.js → RealtimeClient-DRVodyn1.js} +2 -2
  27. package/dist/chunks/{RealtimeClient-C5Zh3fD6.js.map → RealtimeClient-DRVodyn1.js.map} +1 -1
  28. package/dist/chunks/{ThemeProvider-bbbE-N3t.js → ThemeProvider-1WtAS7dH.js} +4 -4
  29. package/dist/chunks/{ThemeProvider-bbbE-N3t.js.map → ThemeProvider-1WtAS7dH.js.map} +1 -1
  30. package/dist/chunks/{fetchFileRequest-JXhnEi-R.js → fetchFileRequest-CVCelZqS.js} +2 -2
  31. package/dist/chunks/{fetchFileRequest-JXhnEi-R.js.map → fetchFileRequest-CVCelZqS.js.map} +1 -1
  32. package/dist/chunks/{live-CApTRvmK.js → live-twEh9Qwt.js} +3 -3
  33. package/dist/chunks/{live-CApTRvmK.js.map → live-twEh9Qwt.js.map} +1 -1
  34. package/dist/chunks/{mutationExtras-C2qSSZ2Q.js → mutationExtras-CM77Ur-9.js} +2 -2
  35. package/dist/chunks/{mutationExtras-C2qSSZ2Q.js.map → mutationExtras-CM77Ur-9.js.map} +1 -1
  36. package/dist/chunks/{subscriptionStream-DQLW7dTW.js → subscriptionStream-DQp1Krwi.js} +2 -2
  37. package/dist/chunks/{subscriptionStream-DQLW7dTW.js.map → subscriptionStream-DQp1Krwi.js.map} +1 -1
  38. package/dist/client/chunkLoadRecovery.d.ts +1 -1
  39. package/dist/client/index.js +4 -4
  40. package/dist/client/index.js.map +1 -1
  41. package/dist/facades/index.js +1 -1
  42. package/dist/http/index.js +1 -1
  43. package/dist/i18n/index.js +1 -1
  44. package/dist/kernel/index.js +1 -1
  45. package/dist/orm/index.js.map +1 -1
  46. package/dist/server/index.js +1 -1
  47. package/dist/services/index.js +1 -1
  48. package/dist/services/mcp/http/callers.d.ts +1 -1
  49. package/dist/testing/index.js +2 -2
  50. package/package.json +1 -1
  51. /package/dist/{chunk-adfkz2kf.js.map → chunk-0e5sq42y.js.map} +0 -0
@@ -1,7 +1,8 @@
1
- import { applyFrame, initialChatState, markAborted } from "./reducer";
1
+ import { applyFrame, initialChatState, markAborted, settledBy } from "./reducer";
2
2
  import { SSEFrameDecoder } from "./sse";
3
3
  /**
4
- * `applyFrame`, `markAborted` and `initialChatState`, recording as they run.
4
+ * `applyFrame`, `markAborted`, `initialChatState` and `settledBy`, recording
5
+ * as they run.
5
6
  *
6
7
  * Identical calls are kept once. The tests fold the same run from scratch many
7
8
  * times over, and a corpus of the same case repeated is only slower to replay.
@@ -12,6 +13,7 @@ export declare function recordReducer(target: string): {
12
13
  applyFrame: typeof applyFrame;
13
14
  markAborted: typeof markAborted;
14
15
  initialChatState: typeof initialChatState;
16
+ settledBy: typeof settledBy;
15
17
  };
16
18
  /**
17
19
  * An `SSEFrameDecoder` that logs every push and flush with what came out and
@@ -1 +1 @@
1
- {"version":3,"file":"conformance.d.ts","sourceRoot":"","sources":["../../../ai/client/conformance.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAgIxC;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM;gBAqClC,OAAO,UAAU;iBAajB,OAAO,WAAW;sBAYlB,OAAO,gBAAgB;EAEhC;AAeD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,eAAe,CAuCvE"}
1
+ {"version":3,"file":"conformance.d.ts","sourceRoot":"","sources":["../../../ai/client/conformance.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACjF,OAAO,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAkIxC;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM;gBAqClC,OAAO,UAAU;iBAajB,OAAO,WAAW;sBAYlB,OAAO,gBAAgB;eAcvB,OAAO,SAAS;EAEzB;AAeD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,eAAe,CAuCvE"}
@@ -243,7 +243,8 @@ function reduce(state, event, now) {
243
243
  };
244
244
  case "message-start": return withMessage(state, event.messageId, now, (message) => ({
245
245
  ...message,
246
- role: event.role
246
+ role: event.role,
247
+ ...event.turn && message.turn === void 0 ? { turn: event.turn } : {}
247
248
  }));
248
249
  case "text-delta":
249
250
  if (isFinished(state, event.messageId)) return state;
@@ -1082,6 +1083,26 @@ function findToolCall(messages, toolCallId) {
1082
1083
  if (part) return part;
1083
1084
  }
1084
1085
  }
1086
+ /** `ChatRun` of a request in flight. */
1087
+ function flightRun(flight) {
1088
+ const answered = flight.turns instanceof Set && flight.turns.size === 1 ? [...flight.turns][0] : void 0;
1089
+ const turn = flight.turn ?? answered;
1090
+ const runId = flight.runId ?? flight.asked;
1091
+ return {
1092
+ id: flight.id,
1093
+ ...runId ? { runId } : {},
1094
+ ...turn ? { turn } : {},
1095
+ status: flight.seen ? "streaming" : "submitted"
1096
+ };
1097
+ }
1098
+ /**
1099
+ * Whether `flight` is a reply in progress. An attach (a mount, focus or
1100
+ * `watch` probe, `reattach`) is one only once a frame of a run has landed:
1101
+ * until then it may find nothing, and showing it would show a reply that
1102
+ * isn't there.
1103
+ */
1104
+ var listed = (flight) => flight.clientRunId !== void 0 || flight.seen === true;
1105
+ var sameRuns = (a, b) => a.length === b.length && a.every((run, i) => run.id === b[i].id && run.runId === b[i].runId && run.turn === b[i].turn && run.status === b[i].status);
1085
1106
  /** How often a run announced mid-stream checks whether the chat is free to attach it. */
1086
1107
  var WATCH_RECHECK_MS = 100;
1087
1108
  /** The first wait before `watch` follows the thread again after a dropped stream. */
@@ -1127,6 +1148,12 @@ function useChat(path, params = {}) {
1127
1148
  const [phase, setPhase] = useState("idle");
1128
1149
  const mountedRef = useRef(true);
1129
1150
  const flightsRef = useRef(/* @__PURE__ */ new Set());
1151
+ const [flightRuns, setFlightRuns] = useState([]);
1152
+ const syncRuns = useCallback(() => {
1153
+ if (!mountedRef.current) return;
1154
+ const next = [...flightsRef.current].filter(listed).map(flightRun);
1155
+ setFlightRuns((current) => sameRuns(current, next) ? current : next);
1156
+ }, []);
1130
1157
  const phaseRef = useRef("idle");
1131
1158
  const handlers = useRef({
1132
1159
  onFinish,
@@ -1177,8 +1204,9 @@ function useChat(path, params = {}) {
1177
1204
  /** Ends a request: idle once none is left. */
1178
1205
  const land = useCallback((flight) => {
1179
1206
  if (!flightsRef.current.delete(flight)) return;
1207
+ syncRuns();
1180
1208
  if (flightsRef.current.size === 0) setPhaseSafe("idle");
1181
- }, [setPhaseSafe]);
1209
+ }, [setPhaseSafe, syncRuns]);
1182
1210
  /**
1183
1211
  * Report a failure without touching the conversation.
1184
1212
  *
@@ -1242,6 +1270,13 @@ function useChat(path, params = {}) {
1242
1270
  setPhaseSafe("streaming");
1243
1271
  const previous = stateRef.current;
1244
1272
  const next = applyRunFrame(previous, flight.runId ?? flight.asked, frame);
1273
+ const named = "messageId" in frame.event ? frame.event.messageId : void 0;
1274
+ const turn = named ? next.messages.find((m) => m.id === named)?.turn : void 0;
1275
+ if (!flight.seen || frame.event.type === "run-start" || turn && flight.turn !== turn) {
1276
+ flight.seen = true;
1277
+ if (turn) flight.turn = turn;
1278
+ syncRuns();
1279
+ }
1245
1280
  if (next === previous) continue;
1246
1281
  commit(next);
1247
1282
  const event = frame.event;
@@ -1266,7 +1301,11 @@ function useChat(path, params = {}) {
1266
1301
  handlers.current.onRetry?.(retry);
1267
1302
  }
1268
1303
  }
1269
- }, [commit, setPhaseSafe]);
1304
+ }, [
1305
+ commit,
1306
+ setPhaseSafe,
1307
+ syncRuns
1308
+ ]);
1270
1309
  const send = useCallback(async (turn, options = {}) => {
1271
1310
  const { base: url, extraBody, ifBusy: defaultIfBusy } = requestRef.current;
1272
1311
  const asked = stateRef.current.threadId ? options.ifBusy ?? defaultIfBusy : void 0;
@@ -1294,13 +1333,16 @@ function useChat(path, params = {}) {
1294
1333
  }
1295
1334
  const clientRunId = localId();
1296
1335
  const controller = new AbortController();
1336
+ const single = answerTurns?.size === 1 ? `turn:${[...answerTurns][0]}` : void 0;
1297
1337
  const flight = {
1298
1338
  controller,
1299
1339
  clientRunId,
1340
+ id: single && ![...flightsRef.current].some((other) => other.id === single) ? single : clientRunId,
1300
1341
  ...answerTurns ? { turns: answerTurns } : turn.text || turn.files?.length ? { turns: "new" } : {}
1301
1342
  };
1302
1343
  const wasBusy = flightsRef.current.size > 0;
1303
1344
  flightsRef.current.add(flight);
1345
+ syncRuns();
1304
1346
  for (const cut of superseded) {
1305
1347
  const { threadId } = stateRef.current;
1306
1348
  const runId = cut.runId ?? (superseded.length === 1 ? stateRef.current.runId : void 0);
@@ -1397,7 +1439,8 @@ function useChat(path, params = {}) {
1397
1439
  land,
1398
1440
  post,
1399
1441
  postStop,
1400
- setPhaseSafe
1442
+ setPhaseSafe,
1443
+ syncRuns
1401
1444
  ]);
1402
1445
  const sendMessage = useCallback((turn, options = {}) => send(typeof turn === "string" ? { text: turn } : turn, {
1403
1446
  ...options.body ? { body: options.body } : {},
@@ -1547,6 +1590,7 @@ function useChat(path, params = {}) {
1547
1590
  const flights = [...flightsRef.current];
1548
1591
  for (const flight of flights) flight.controller.abort();
1549
1592
  flightsRef.current.clear();
1593
+ syncRuns();
1550
1594
  const stopped = markAllAborted(stateRef.current);
1551
1595
  commit({
1552
1596
  ...stopped,
@@ -1575,7 +1619,8 @@ function useChat(path, params = {}) {
1575
1619
  commit,
1576
1620
  fail,
1577
1621
  postStop,
1578
- setPhaseSafe
1622
+ setPhaseSafe,
1623
+ syncRuns
1579
1624
  ]);
1580
1625
  const regenerate = useCallback(async () => {
1581
1626
  const messages = stateRef.current.messages;
@@ -1663,9 +1708,11 @@ function useChat(path, params = {}) {
1663
1708
  const controller = new AbortController();
1664
1709
  const flight = {
1665
1710
  controller,
1711
+ id: localId(),
1666
1712
  ...cursorRunId ? { asked: cursorRunId } : {}
1667
1713
  };
1668
1714
  flightsRef.current.add(flight);
1715
+ syncRuns();
1669
1716
  try {
1670
1717
  const body = {
1671
1718
  threadId,
@@ -1689,7 +1736,8 @@ function useChat(path, params = {}) {
1689
1736
  consume,
1690
1737
  following,
1691
1738
  land,
1692
- post
1739
+ post,
1740
+ syncRuns
1693
1741
  ]);
1694
1742
  const reattach = useCallback(() => probe(false), [probe]);
1695
1743
  useEffect(() => {
@@ -1767,9 +1815,27 @@ function useChat(path, params = {}) {
1767
1815
  following
1768
1816
  ]);
1769
1817
  const status = state.pending.length > 0 ? "awaiting-input" : phase !== "idle" ? phase : state.error ? "error" : "idle";
1818
+ const pendingNow = state.pending;
1819
+ const runs = useMemo(() => {
1820
+ const flying = new Set(flightRuns.map((run) => run.turn).filter(Boolean));
1821
+ const waiting = [];
1822
+ for (const call of pendingNow) {
1823
+ if (call.answering) continue;
1824
+ const turn = call.turn;
1825
+ if (turn ? flying.has(turn) : flightRuns.length > 0) continue;
1826
+ if (waiting.some((run) => run.turn === turn)) continue;
1827
+ waiting.push({
1828
+ id: turn ? `turn:${turn}` : "turn",
1829
+ ...turn ? { turn } : {},
1830
+ status: "awaiting-input"
1831
+ });
1832
+ }
1833
+ return waiting.length === 0 ? flightRuns : [...flightRuns, ...waiting];
1834
+ }, [flightRuns, pendingNow]);
1770
1835
  return {
1771
1836
  messages: state.messages,
1772
1837
  status,
1838
+ runs,
1773
1839
  error: state.error,
1774
1840
  threadId: state.threadId,
1775
1841
  runId: state.runId,