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