@tanstack/ai 0.46.0 → 0.47.2
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/esm/activities/chat/index.d.ts +36 -11
- package/dist/esm/activities/chat/index.js +440 -79
- package/dist/esm/activities/chat/index.js.map +1 -1
- package/dist/esm/activities/chat/messages.d.ts +1 -0
- package/dist/esm/activities/chat/messages.js +12 -7
- package/dist/esm/activities/chat/messages.js.map +1 -1
- package/dist/esm/activities/chat/middleware/builder.d.ts +7 -2
- package/dist/esm/activities/chat/middleware/builder.js.map +1 -1
- package/dist/esm/activities/chat/middleware/compose.d.ts +10 -3
- package/dist/esm/activities/chat/middleware/compose.js +55 -0
- package/dist/esm/activities/chat/middleware/compose.js.map +1 -1
- package/dist/esm/activities/chat/middleware/define.d.ts +6 -3
- package/dist/esm/activities/chat/middleware/define.js.map +1 -1
- package/dist/esm/activities/chat/middleware/generic-interrupts.d.ts +13 -0
- package/dist/esm/activities/chat/middleware/generic-interrupts.js +8 -0
- package/dist/esm/activities/chat/middleware/generic-interrupts.js.map +1 -0
- package/dist/esm/activities/chat/middleware/index.d.ts +4 -1
- package/dist/esm/activities/chat/middleware/types.d.ts +54 -3
- package/dist/esm/activities/chat/middleware/types.js +16 -0
- package/dist/esm/activities/chat/middleware/types.js.map +1 -0
- package/dist/esm/activities/chat/stream/processor.js +18 -5
- package/dist/esm/activities/chat/stream/processor.js.map +1 -1
- package/dist/esm/adapter-internals.d.ts +6 -0
- package/dist/esm/adapter-internals.js +4 -1
- package/dist/esm/client.d.ts +4 -0
- package/dist/esm/client.js +3 -1
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/generic-interrupt-continuation.d.ts +45 -0
- package/dist/esm/generic-interrupt-continuation.js +80 -0
- package/dist/esm/generic-interrupt-continuation.js.map +1 -0
- package/dist/esm/index.d.ts +6 -1
- package/dist/esm/index.js +4 -1
- package/dist/esm/interrupt-definition.d.ts +113 -0
- package/dist/esm/interrupt-definition.js +169 -0
- package/dist/esm/interrupt-definition.js.map +1 -0
- package/dist/esm/interrupt-resume.d.ts +3 -0
- package/dist/esm/interrupt-resume.js +77 -16
- package/dist/esm/interrupt-resume.js.map +1 -1
- package/dist/esm/interrupts.d.ts +12 -3
- package/dist/esm/interrupts.js.map +1 -1
- package/dist/esm/types.d.ts +11 -3
- package/dist/esm/utilities/chat-params.js +10 -1
- package/dist/esm/utilities/chat-params.js.map +1 -1
- package/package.json +3 -3
- package/skills/ai-core/media-generation/SKILL.md +4 -1
- package/skills/ai-core/middleware/SKILL.md +53 -44
- package/skills/ai-core/structured-outputs/SKILL.md +59 -55
- package/skills/ai-core/tool-calling/SKILL.md +54 -1
- package/src/activities/chat/index.ts +1030 -211
- package/src/activities/chat/messages.ts +11 -3
- package/src/activities/chat/middleware/builder.ts +29 -4
- package/src/activities/chat/middleware/compose.ts +95 -5
- package/src/activities/chat/middleware/define.ts +13 -3
- package/src/activities/chat/middleware/generic-interrupts.ts +26 -0
- package/src/activities/chat/middleware/index.ts +15 -0
- package/src/activities/chat/middleware/types.ts +127 -2
- package/src/activities/chat/stream/processor.ts +21 -0
- package/src/adapter-internals.ts +20 -0
- package/src/client.ts +20 -0
- package/src/generic-interrupt-continuation.ts +162 -0
- package/src/index.ts +34 -0
- package/src/interrupt-definition.ts +581 -0
- package/src/interrupt-resume.ts +156 -25
- package/src/interrupts.ts +13 -3
- package/src/types.ts +11 -3
- package/src/utilities/chat-params.ts +16 -3
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { INTERRUPT_PAYLOAD_METADATA_KEY } from './interrupt-definition'
|
|
2
|
+
import { readUnopenedInterruptBinding } from './interrupt-resume'
|
|
3
|
+
import type { Interrupt } from './types'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* `ResumeEntry.metadata` key for a first-party generic request.
|
|
7
|
+
*
|
|
8
|
+
* AG-UI `resume` only carries the answer (`interruptId`, `status`, `payload`).
|
|
9
|
+
* The original request rides here so an ephemeral server can rebuild it.
|
|
10
|
+
*/
|
|
11
|
+
export const INTERRUPT_CONTINUATION_METADATA_KEY =
|
|
12
|
+
'tanstack:interruptContinuation' as const
|
|
13
|
+
|
|
14
|
+
export const INTERRUPT_CONTINUATION_VERSION = 1 as const
|
|
15
|
+
|
|
16
|
+
export interface GenericInterruptContinuation {
|
|
17
|
+
v: typeof INTERRUPT_CONTINUATION_VERSION
|
|
18
|
+
definitionId: string
|
|
19
|
+
key: string
|
|
20
|
+
batchIndex: number
|
|
21
|
+
reason: string
|
|
22
|
+
message: string
|
|
23
|
+
expiresAt?: string
|
|
24
|
+
responseSchemaHash?: string
|
|
25
|
+
payloadSchemaHash?: string
|
|
26
|
+
payload?: unknown
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type GenericInterruptContinuationReadResult =
|
|
30
|
+
| { status: 'absent' }
|
|
31
|
+
| { status: 'invalid'; message: string }
|
|
32
|
+
| { status: 'ok'; value: GenericInterruptContinuation }
|
|
33
|
+
|
|
34
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
35
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function invalid(
|
|
39
|
+
message: string,
|
|
40
|
+
): Extract<GenericInterruptContinuationReadResult, { status: 'invalid' }> {
|
|
41
|
+
return { status: 'invalid', message }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Read one generic request from `resume[].metadata`.
|
|
46
|
+
*
|
|
47
|
+
* Missing key means this resume item is not a first-party generic continuation.
|
|
48
|
+
* A present key that fails the shape is a protocol error.
|
|
49
|
+
*/
|
|
50
|
+
export function readGenericInterruptContinuation(
|
|
51
|
+
metadata: unknown,
|
|
52
|
+
): GenericInterruptContinuationReadResult {
|
|
53
|
+
if (metadata === undefined) return { status: 'absent' }
|
|
54
|
+
if (!isRecord(metadata)) {
|
|
55
|
+
return invalid('Generic interrupt resume metadata must be an object.')
|
|
56
|
+
}
|
|
57
|
+
if (
|
|
58
|
+
!Object.prototype.hasOwnProperty.call(
|
|
59
|
+
metadata,
|
|
60
|
+
INTERRUPT_CONTINUATION_METADATA_KEY,
|
|
61
|
+
)
|
|
62
|
+
) {
|
|
63
|
+
return { status: 'absent' }
|
|
64
|
+
}
|
|
65
|
+
const raw = metadata[INTERRUPT_CONTINUATION_METADATA_KEY]
|
|
66
|
+
if (!isRecord(raw)) {
|
|
67
|
+
return invalid('Generic interrupt continuation is invalid.')
|
|
68
|
+
}
|
|
69
|
+
if (
|
|
70
|
+
raw.v !== INTERRUPT_CONTINUATION_VERSION ||
|
|
71
|
+
typeof raw.definitionId !== 'string' ||
|
|
72
|
+
typeof raw.key !== 'string' ||
|
|
73
|
+
typeof raw.reason !== 'string' ||
|
|
74
|
+
typeof raw.message !== 'string' ||
|
|
75
|
+
typeof raw.batchIndex !== 'number' ||
|
|
76
|
+
!Number.isInteger(raw.batchIndex) ||
|
|
77
|
+
raw.batchIndex < 0 ||
|
|
78
|
+
(raw.responseSchemaHash !== undefined &&
|
|
79
|
+
typeof raw.responseSchemaHash !== 'string') ||
|
|
80
|
+
(raw.expiresAt !== undefined && typeof raw.expiresAt !== 'string') ||
|
|
81
|
+
(raw.payloadSchemaHash !== undefined &&
|
|
82
|
+
typeof raw.payloadSchemaHash !== 'string')
|
|
83
|
+
) {
|
|
84
|
+
return invalid('Generic interrupt continuation contains invalid fields.')
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
status: 'ok',
|
|
88
|
+
value: {
|
|
89
|
+
v: INTERRUPT_CONTINUATION_VERSION,
|
|
90
|
+
definitionId: raw.definitionId,
|
|
91
|
+
key: raw.key,
|
|
92
|
+
batchIndex: raw.batchIndex,
|
|
93
|
+
reason: raw.reason,
|
|
94
|
+
message: raw.message,
|
|
95
|
+
...(typeof raw.expiresAt === 'string'
|
|
96
|
+
? { expiresAt: raw.expiresAt }
|
|
97
|
+
: {}),
|
|
98
|
+
...(typeof raw.responseSchemaHash === 'string'
|
|
99
|
+
? { responseSchemaHash: raw.responseSchemaHash }
|
|
100
|
+
: {}),
|
|
101
|
+
...(typeof raw.payloadSchemaHash === 'string'
|
|
102
|
+
? { payloadSchemaHash: raw.payloadSchemaHash }
|
|
103
|
+
: {}),
|
|
104
|
+
...(Object.prototype.hasOwnProperty.call(raw, 'payload')
|
|
105
|
+
? { payload: raw.payload }
|
|
106
|
+
: {}),
|
|
107
|
+
},
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Put a parsed continuation on `ResumeEntry.metadata`. */
|
|
112
|
+
export function wrapGenericInterruptContinuation(
|
|
113
|
+
continuation: GenericInterruptContinuation,
|
|
114
|
+
): Record<string, unknown> {
|
|
115
|
+
return { [INTERRUPT_CONTINUATION_METADATA_KEY]: continuation }
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Build the resume-metadata continuation from an outbound AG-UI interrupt.
|
|
120
|
+
*
|
|
121
|
+
* Returns `undefined` when the descriptor is not a first-party generic item.
|
|
122
|
+
*/
|
|
123
|
+
export function genericInterruptContinuationFromDescriptor(
|
|
124
|
+
interrupt: Interrupt,
|
|
125
|
+
): GenericInterruptContinuation | undefined {
|
|
126
|
+
const binding = readUnopenedInterruptBinding(interrupt)
|
|
127
|
+
if (
|
|
128
|
+
binding?.kind !== 'generic' ||
|
|
129
|
+
binding.definitionId === undefined ||
|
|
130
|
+
binding.key === undefined ||
|
|
131
|
+
binding.batchIndex === undefined
|
|
132
|
+
) {
|
|
133
|
+
return undefined
|
|
134
|
+
}
|
|
135
|
+
const metadata = isRecord(interrupt.metadata) ? interrupt.metadata : undefined
|
|
136
|
+
const hasPayload =
|
|
137
|
+
metadata !== undefined &&
|
|
138
|
+
Object.prototype.hasOwnProperty.call(
|
|
139
|
+
metadata,
|
|
140
|
+
INTERRUPT_PAYLOAD_METADATA_KEY,
|
|
141
|
+
)
|
|
142
|
+
return {
|
|
143
|
+
v: INTERRUPT_CONTINUATION_VERSION,
|
|
144
|
+
definitionId: binding.definitionId,
|
|
145
|
+
key: binding.key,
|
|
146
|
+
batchIndex: binding.batchIndex,
|
|
147
|
+
reason: interrupt.reason,
|
|
148
|
+
message: interrupt.message ?? '',
|
|
149
|
+
...(interrupt.expiresAt !== undefined
|
|
150
|
+
? { expiresAt: interrupt.expiresAt }
|
|
151
|
+
: {}),
|
|
152
|
+
...(binding.responseSchemaHash !== undefined
|
|
153
|
+
? { responseSchemaHash: binding.responseSchemaHash }
|
|
154
|
+
: {}),
|
|
155
|
+
...(binding.payloadSchemaHash !== undefined
|
|
156
|
+
? { payloadSchemaHash: binding.payloadSchemaHash }
|
|
157
|
+
: {}),
|
|
158
|
+
...(hasPayload
|
|
159
|
+
? { payload: metadata[INTERRUPT_PAYLOAD_METADATA_KEY] }
|
|
160
|
+
: {}),
|
|
161
|
+
}
|
|
162
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -201,6 +201,17 @@ export type {
|
|
|
201
201
|
SandboxFileEvent,
|
|
202
202
|
SandboxFileHookEvent,
|
|
203
203
|
ChatSandboxHooks,
|
|
204
|
+
InterruptBoundaryPhase,
|
|
205
|
+
InterruptToolResume,
|
|
206
|
+
InterruptResolutionCollection,
|
|
207
|
+
GenericInterruptResolution,
|
|
208
|
+
InterruptBoundaryResult,
|
|
209
|
+
InterruptResolutionResult,
|
|
210
|
+
} from './activities/chat/middleware/index'
|
|
211
|
+
|
|
212
|
+
export {
|
|
213
|
+
INTERRUPT_BOUNDARY_PHASES,
|
|
214
|
+
INTERRUPT_TOOL_RESUMES,
|
|
204
215
|
} from './activities/chat/middleware/index'
|
|
205
216
|
|
|
206
217
|
// Interrupt protocol surface. Deliberately enumerated rather than
|
|
@@ -209,6 +220,29 @@ export type {
|
|
|
209
220
|
// a commitment. Only the ephemeral contract this release actually implements
|
|
210
221
|
// is exported — no durable-recovery or persisted-state types, which would
|
|
211
222
|
// pre-decide a question the orchestration RFC still owns.
|
|
223
|
+
export {
|
|
224
|
+
defineInterrupt,
|
|
225
|
+
createInterruptBinding,
|
|
226
|
+
INTERRUPT_PAYLOAD_METADATA_KEY,
|
|
227
|
+
} from './interrupt-definition'
|
|
228
|
+
export {
|
|
229
|
+
INTERRUPT_CONTINUATION_METADATA_KEY,
|
|
230
|
+
INTERRUPT_CONTINUATION_VERSION,
|
|
231
|
+
genericInterruptContinuationFromDescriptor,
|
|
232
|
+
readGenericInterruptContinuation,
|
|
233
|
+
wrapGenericInterruptContinuation,
|
|
234
|
+
} from './generic-interrupt-continuation'
|
|
235
|
+
export type {
|
|
236
|
+
GenericInterruptContinuation,
|
|
237
|
+
GenericInterruptContinuationReadResult,
|
|
238
|
+
} from './generic-interrupt-continuation'
|
|
239
|
+
export type {
|
|
240
|
+
InterruptDefinition,
|
|
241
|
+
GenericInterruptRequest,
|
|
242
|
+
InterruptDefinitionOptions,
|
|
243
|
+
InterruptBindingDescriptor,
|
|
244
|
+
} from './interrupt-definition'
|
|
245
|
+
|
|
212
246
|
export {
|
|
213
247
|
INTERRUPT_BINDING_VERSION,
|
|
214
248
|
canonicalizeInterruptResolutions,
|