@workglow/ai 0.2.33 → 0.2.34

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.
package/dist/browser.js CHANGED
@@ -1470,7 +1470,7 @@ var AiChatOutputSchema = {
1470
1470
  text: {
1471
1471
  type: "string",
1472
1472
  title: "Text",
1473
- description: "Last assistant response",
1473
+ description: "Full streamed transcript across all assistant turns",
1474
1474
  "x-stream": "append"
1475
1475
  },
1476
1476
  messages: {
@@ -1555,6 +1555,7 @@ class AiChatTask extends StreamingAiTask {
1555
1555
  await getAiProviderRegistry().disposeSession(model.provider, sessionId);
1556
1556
  });
1557
1557
  }
1558
+ let completedTurns = 0;
1558
1559
  yield {
1559
1560
  type: "object-delta",
1560
1561
  port: "messages",
@@ -1580,6 +1581,7 @@ class AiChatTask extends StreamingAiTask {
1580
1581
  content: [{ type: "text", text: assistantText }]
1581
1582
  };
1582
1583
  history.push(assistantMsg);
1584
+ completedTurns = turn + 1;
1583
1585
  yield {
1584
1586
  type: "object-delta",
1585
1587
  port: "messages",
@@ -1619,7 +1621,10 @@ class AiChatTask extends StreamingAiTask {
1619
1621
  objectDelta: [userMsg]
1620
1622
  };
1621
1623
  }
1622
- yield { type: "finish" };
1624
+ yield {
1625
+ type: "finish",
1626
+ data: { iterations: completedTurns }
1627
+ };
1623
1628
  }
1624
1629
  }
1625
1630
 
@@ -1846,7 +1851,7 @@ var AiChatWithKbOutputSchema = {
1846
1851
  text: {
1847
1852
  type: "string",
1848
1853
  title: "Text",
1849
- description: "Last assistant response",
1854
+ description: "Full streamed transcript across all assistant turns",
1850
1855
  "x-stream": "append"
1851
1856
  },
1852
1857
  messages: {
@@ -1938,6 +1943,7 @@ class AiChatWithKbTask extends StreamingAiTask {
1938
1943
  const topK = input.topKPerKb ?? 4;
1939
1944
  const minScore = input.minScore ?? 0.3;
1940
1945
  const maxRefs = input.maxReferences ?? 6;
1946
+ let completedTurns = 0;
1941
1947
  let lastNonEmptyRefs = [];
1942
1948
  for (let turn = 0;turn < maxIterations; turn++) {
1943
1949
  const lastUserText = extractLastUserText(history);
@@ -1964,12 +1970,13 @@ class AiChatWithKbTask extends StreamingAiTask {
1964
1970
  }));
1965
1971
  }
1966
1972
  const allChunks = perKbResults.flatMap(({ kbId, kbLabel, kb, results }) => results.filter((r) => r.score >= minScore).map((r) => ({ kbId, kbLabel, kb, r }))).sort((a, b) => b.r.score - a.r.score).slice(0, maxRefs);
1973
+ const docUrlKey = (kbId, docId) => `${kbId}:${docId}`;
1967
1974
  const docUrls = new Map;
1968
1975
  const docFetches = [];
1969
- for (const { kb, r } of allChunks) {
1976
+ for (const { kbId, kb, r } of allChunks) {
1970
1977
  if (!kb)
1971
1978
  continue;
1972
- const key = `${r.doc_id}`;
1979
+ const key = docUrlKey(kbId, r.doc_id);
1973
1980
  if (docUrls.has(key))
1974
1981
  continue;
1975
1982
  docUrls.set(key, undefined);
@@ -1985,7 +1992,7 @@ class AiChatWithKbTask extends StreamingAiTask {
1985
1992
  kbId: entry.kbId,
1986
1993
  kbLabel: entry.kbLabel,
1987
1994
  result: entry.r,
1988
- url: docUrls.get(entry.r.doc_id)
1995
+ url: docUrls.get(docUrlKey(entry.kbId, entry.r.doc_id))
1989
1996
  }));
1990
1997
  const effectiveRefs = refs.length > 0 ? refs : lastNonEmptyRefs;
1991
1998
  if (refs.length > 0) {
@@ -2045,6 +2052,7 @@ class AiChatWithKbTask extends StreamingAiTask {
2045
2052
  content: [{ type: "text", text: assistantText }]
2046
2053
  };
2047
2054
  history.push(assistantMsg);
2055
+ completedTurns = turn + 1;
2048
2056
  yield {
2049
2057
  type: "object-delta",
2050
2058
  port: "messages",
@@ -2084,7 +2092,10 @@ class AiChatWithKbTask extends StreamingAiTask {
2084
2092
  objectDelta: [userMsg]
2085
2093
  };
2086
2094
  }
2087
- yield { type: "finish" };
2095
+ yield {
2096
+ type: "finish",
2097
+ data: { iterations: completedTurns }
2098
+ };
2088
2099
  }
2089
2100
  }
2090
2101
  function extractLastUserText(messages) {
@@ -8027,4 +8038,4 @@ export {
8027
8038
  AI_PROVIDER_REGISTRY
8028
8039
  };
8029
8040
 
8030
- //# debugId=1A55924D1D53BC9B64756E2164756E21
8041
+ //# debugId=AE848783BD0282C164756E2164756E21