@tanstack/ai 0.2.2 → 0.3.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 (44) hide show
  1. package/README.md +1 -0
  2. package/dist/esm/activities/chat/index.js +264 -186
  3. package/dist/esm/activities/chat/index.js.map +1 -1
  4. package/dist/esm/activities/chat/messages.js +22 -0
  5. package/dist/esm/activities/chat/messages.js.map +1 -1
  6. package/dist/esm/activities/chat/stream/index.d.ts +1 -1
  7. package/dist/esm/activities/chat/stream/processor.d.ts +22 -43
  8. package/dist/esm/activities/chat/stream/processor.js +93 -157
  9. package/dist/esm/activities/chat/stream/processor.js.map +1 -1
  10. package/dist/esm/activities/chat/tools/tool-calls.d.ts +22 -21
  11. package/dist/esm/activities/chat/tools/tool-calls.js +40 -27
  12. package/dist/esm/activities/chat/tools/tool-calls.js.map +1 -1
  13. package/dist/esm/activities/generateImage/index.js +41 -1
  14. package/dist/esm/activities/generateImage/index.js.map +1 -1
  15. package/dist/esm/activities/generateSpeech/index.js +33 -1
  16. package/dist/esm/activities/generateSpeech/index.js.map +1 -1
  17. package/dist/esm/activities/generateTranscription/index.js +29 -1
  18. package/dist/esm/activities/generateTranscription/index.js.map +1 -1
  19. package/dist/esm/activities/generateVideo/index.js +50 -0
  20. package/dist/esm/activities/generateVideo/index.js.map +1 -1
  21. package/dist/esm/activities/summarize/index.js +9 -8
  22. package/dist/esm/activities/summarize/index.js.map +1 -1
  23. package/dist/esm/event-client.d.ts +378 -254
  24. package/dist/esm/event-client.js.map +1 -1
  25. package/dist/esm/index.d.ts +2 -2
  26. package/dist/esm/stream-to-response.d.ts +1 -1
  27. package/dist/esm/stream-to-response.js +5 -3
  28. package/dist/esm/stream-to-response.js.map +1 -1
  29. package/dist/esm/types.d.ts +162 -46
  30. package/package.json +1 -1
  31. package/src/activities/chat/index.ts +362 -216
  32. package/src/activities/chat/messages.ts +40 -1
  33. package/src/activities/chat/stream/index.ts +1 -5
  34. package/src/activities/chat/stream/processor.ts +142 -270
  35. package/src/activities/chat/tools/tool-calls.ts +55 -49
  36. package/src/activities/generateImage/index.ts +47 -2
  37. package/src/activities/generateSpeech/index.ts +37 -1
  38. package/src/activities/generateTranscription/index.ts +33 -1
  39. package/src/activities/generateVideo/index.ts +54 -0
  40. package/src/activities/summarize/index.ts +10 -9
  41. package/src/event-client.ts +460 -256
  42. package/src/index.ts +2 -3
  43. package/src/stream-to-response.ts +8 -6
  44. package/src/types.ts +209 -65
@@ -123,7 +123,11 @@ export function uiMessageToModelMessages(
123
123
  })
124
124
  }
125
125
 
126
- // Add tool result messages (only completed ones)
126
+ // Add tool result messages for completed tool calls
127
+ // This includes:
128
+ // 1. Explicit tool-result parts (from server tools)
129
+ // 2. Client tool calls with output set
130
+ // 3. Approval-responded tool calls (approval result)
127
131
  for (const toolResultPart of toolResultParts) {
128
132
  if (
129
133
  toolResultPart.state === 'complete' ||
@@ -137,6 +141,41 @@ export function uiMessageToModelMessages(
137
141
  }
138
142
  }
139
143
 
144
+ // Add tool result messages for client tool results (tools with output)
145
+ // and approval responses (so iteration tracking works correctly)
146
+ for (const toolCallPart of toolCallParts) {
147
+ // Client tool with output - add as tool result
148
+ if (toolCallPart.output !== undefined && !toolCallPart.approval) {
149
+ messageList.push({
150
+ role: 'tool',
151
+ content: JSON.stringify(toolCallPart.output),
152
+ toolCallId: toolCallPart.id,
153
+ })
154
+ }
155
+
156
+ // Approval response - add as tool result for iteration tracking
157
+ // For APPROVED: includes pendingExecution marker so the tool still executes
158
+ // For DENIED: just marks the tool as complete (no execution needed)
159
+ if (
160
+ toolCallPart.state === 'approval-responded' &&
161
+ toolCallPart.approval?.approved !== undefined
162
+ ) {
163
+ const approved = toolCallPart.approval.approved
164
+ messageList.push({
165
+ role: 'tool',
166
+ content: JSON.stringify({
167
+ approved,
168
+ // Mark approved tools as pending execution - they still need to run
169
+ ...(approved && { pendingExecution: true }),
170
+ message: approved
171
+ ? 'User approved this action'
172
+ : 'User denied this action',
173
+ }),
174
+ toolCallId: toolCallPart.id,
175
+ })
176
+ }
177
+ }
178
+
140
179
  return messageList
141
180
  }
142
181
 
@@ -6,11 +6,7 @@
6
6
 
7
7
  // Core processor
8
8
  export { StreamProcessor, createReplayStream } from './processor'
9
- export type {
10
- StreamProcessorEvents,
11
- StreamProcessorHandlers,
12
- StreamProcessorOptions,
13
- } from './processor'
9
+ export type { StreamProcessorEvents, StreamProcessorOptions } from './processor'
14
10
 
15
11
  // Strategies
16
12
  export {