@tanstack/ai 0.53.0 → 0.55.0
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/README.md +14 -13
- package/dist/esm/activities/chat/index.js +22 -4
- package/dist/esm/activities/chat/index.js.map +1 -1
- package/dist/esm/activities/chat/messages.d.ts +21 -1
- package/dist/esm/activities/chat/messages.js +50 -1
- package/dist/esm/activities/chat/messages.js.map +1 -1
- package/dist/esm/activities/chat/stream/processor.d.ts +17 -0
- package/dist/esm/activities/chat/stream/processor.js +27 -0
- package/dist/esm/activities/chat/stream/processor.js.map +1 -1
- package/dist/esm/activities/generateLiveVideo/adapter.d.ts +69 -0
- package/dist/esm/activities/generateLiveVideo/adapter.js +23 -0
- package/dist/esm/activities/generateLiveVideo/adapter.js.map +1 -0
- package/dist/esm/activities/generateLiveVideo/index.d.ts +99 -0
- package/dist/esm/activities/generateLiveVideo/index.js +162 -0
- package/dist/esm/activities/generateLiveVideo/index.js.map +1 -0
- package/dist/esm/activities/generateVideo/index.js +3 -1
- package/dist/esm/activities/generateVideo/index.js.map +1 -1
- package/dist/esm/activities/generateWorld/adapter.d.ts +69 -0
- package/dist/esm/activities/generateWorld/adapter.js +23 -0
- package/dist/esm/activities/generateWorld/adapter.js.map +1 -0
- package/dist/esm/activities/generateWorld/index.d.ts +99 -0
- package/dist/esm/activities/generateWorld/index.js +162 -0
- package/dist/esm/activities/generateWorld/index.js.map +1 -0
- package/dist/esm/activities/index.d.ts +8 -2
- package/dist/esm/activities/index.js +11 -7
- package/dist/esm/activities/middleware/types.d.ts +1 -1
- package/dist/esm/client.d.ts +4 -2
- package/dist/esm/client.js +3 -1
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/index.d.ts +4 -2
- package/dist/esm/index.js +3 -1
- package/dist/esm/middlewares/otel.js +3 -1
- package/dist/esm/middlewares/otel.js.map +1 -1
- package/dist/esm/types.d.ts +112 -0
- package/package.json +3 -3
- package/skills/ai-core/adapter-configuration/SKILL.md +91 -43
- package/skills/ai-core/adapter-configuration/references/anthropic-adapter.md +39 -21
- package/skills/ai-core/adapter-configuration/references/byteplus-adapter.md +5 -0
- package/skills/ai-core/adapter-configuration/references/gemini-adapter.md +14 -6
- package/skills/ai-core/adapter-configuration/references/grok-adapter.md +33 -25
- package/skills/ai-core/adapter-configuration/references/groq-adapter.md +7 -2
- package/skills/ai-core/adapter-configuration/references/ollama-adapter.md +25 -12
- package/skills/ai-core/adapter-configuration/references/openai-adapter.md +19 -9
- package/skills/ai-core/adapter-configuration/references/openrouter-adapter.md +34 -21
- package/skills/ai-core/ag-ui-protocol/SKILL.md +16 -10
- package/skills/ai-core/chat-experience/SKILL.md +228 -108
- package/skills/ai-core/client-persistence/SKILL.md +21 -9
- package/skills/ai-core/custom-backend-integration/SKILL.md +86 -52
- package/skills/ai-core/debug-logging/SKILL.md +100 -18
- package/skills/ai-core/locks/SKILL.md +35 -7
- package/skills/ai-core/media-generation/SKILL.md +136 -61
- package/skills/ai-core/middleware/SKILL.md +174 -69
- package/skills/ai-core/structured-outputs/SKILL.md +98 -49
- package/skills/ai-core/tool-calling/SKILL.md +245 -158
- package/src/activities/chat/index.ts +29 -7
- package/src/activities/chat/messages.ts +60 -0
- package/src/activities/chat/stream/processor.ts +31 -0
- package/src/activities/generateLiveVideo/adapter.ts +99 -0
- package/src/activities/generateLiveVideo/index.ts +339 -0
- package/src/activities/generateVideo/index.ts +3 -4
- package/src/activities/generateWorld/adapter.ts +96 -0
- package/src/activities/generateWorld/index.ts +339 -0
- package/src/activities/index.ts +44 -0
- package/src/activities/middleware/types.ts +2 -0
- package/src/client.ts +8 -0
- package/src/index.ts +8 -0
- package/src/middlewares/otel.ts +2 -0
- package/src/types.ts +128 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { WorldGenerationOptions, WorldGenerationResult } from '../../types'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Configuration for world generation adapter instances.
|
|
5
|
+
*
|
|
6
|
+
* @experimental World generation is an experimental feature and may change.
|
|
7
|
+
*/
|
|
8
|
+
export interface WorldAdapterConfig {
|
|
9
|
+
apiKey?: string
|
|
10
|
+
baseUrl?: string
|
|
11
|
+
timeout?: number
|
|
12
|
+
maxRetries?: number
|
|
13
|
+
headers?: Record<string, string>
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* World adapter interface with pre-resolved generics.
|
|
18
|
+
*
|
|
19
|
+
* An adapter is created by a provider function: `provider('model')` → `adapter`.
|
|
20
|
+
* All type resolution happens at the provider call site, not in this interface.
|
|
21
|
+
*
|
|
22
|
+
* Generic parameters:
|
|
23
|
+
* - TModel: The specific model name (e.g. 'visko-orbis-stable')
|
|
24
|
+
* - TProviderOptions: Provider-specific options (already resolved)
|
|
25
|
+
*
|
|
26
|
+
* @experimental World generation is an experimental feature and may change.
|
|
27
|
+
*/
|
|
28
|
+
export interface WorldAdapter<
|
|
29
|
+
TModel extends string = string,
|
|
30
|
+
TProviderOptions extends object = Record<string, unknown>,
|
|
31
|
+
> {
|
|
32
|
+
/** Discriminator for adapter kind - used to determine API shape */
|
|
33
|
+
readonly kind: 'world'
|
|
34
|
+
/** Adapter name identifier */
|
|
35
|
+
readonly name: string
|
|
36
|
+
/** The model this adapter is configured for */
|
|
37
|
+
readonly model: TModel
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @internal Type-only properties for inference. Not assigned at runtime.
|
|
41
|
+
*/
|
|
42
|
+
'~types': {
|
|
43
|
+
providerOptions: TProviderOptions
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Open a world session from a prompt.
|
|
48
|
+
*
|
|
49
|
+
* Server adapters typically mint a short-lived token and return it with the
|
|
50
|
+
* prompt so a browser can connect, set the prompt, and start streaming.
|
|
51
|
+
*/
|
|
52
|
+
createWorld: (
|
|
53
|
+
options: WorldGenerationOptions<TProviderOptions>,
|
|
54
|
+
) => Promise<WorldGenerationResult>
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* A WorldAdapter with any/unknown type parameters.
|
|
59
|
+
* Useful as a constraint in generic functions and interfaces.
|
|
60
|
+
*/
|
|
61
|
+
export type AnyWorldAdapter = WorldAdapter<any, any>
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Abstract base class for world generation adapters.
|
|
65
|
+
* Extend this class to implement a world adapter for a specific provider.
|
|
66
|
+
*
|
|
67
|
+
* @experimental World generation is an experimental feature and may change.
|
|
68
|
+
*/
|
|
69
|
+
export abstract class BaseWorldAdapter<
|
|
70
|
+
TModel extends string = string,
|
|
71
|
+
TProviderOptions extends object = Record<string, unknown>,
|
|
72
|
+
> implements WorldAdapter<TModel, TProviderOptions> {
|
|
73
|
+
readonly kind = 'world' as const
|
|
74
|
+
abstract readonly name: string
|
|
75
|
+
readonly model: TModel
|
|
76
|
+
|
|
77
|
+
// Type-only property - never assigned at runtime
|
|
78
|
+
declare '~types': {
|
|
79
|
+
providerOptions: TProviderOptions
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
protected config: WorldAdapterConfig
|
|
83
|
+
|
|
84
|
+
constructor(model: TModel, config: WorldAdapterConfig = {}) {
|
|
85
|
+
this.config = config
|
|
86
|
+
this.model = model
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
abstract createWorld(
|
|
90
|
+
options: WorldGenerationOptions<TProviderOptions>,
|
|
91
|
+
): Promise<WorldGenerationResult>
|
|
92
|
+
|
|
93
|
+
protected generateId(): string {
|
|
94
|
+
return `${this.name}-${Date.now()}-${Math.random().toString(36).substring(7)}`
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* World Activity (Experimental)
|
|
3
|
+
*
|
|
4
|
+
* Mints a session token for a live, prompt-steerable world. Unlike
|
|
5
|
+
* generateVideo (a job that finishes with a URL), the browser then connects
|
|
6
|
+
* with the token, sets the prompt, and streams until pause/reset/close.
|
|
7
|
+
*
|
|
8
|
+
* @experimental World generation is an experimental feature and may change.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { aiEventClient } from '@tanstack/ai-event-client'
|
|
12
|
+
import { streamGenerationResult } from '../stream-generation-result.js'
|
|
13
|
+
import { resolveDebugOption } from '../../logger/resolve'
|
|
14
|
+
import {
|
|
15
|
+
applyGenerationResultTransforms,
|
|
16
|
+
createGenerationContext,
|
|
17
|
+
runGenerationAbort,
|
|
18
|
+
runGenerationError,
|
|
19
|
+
runGenerationFinish,
|
|
20
|
+
runGenerationStart,
|
|
21
|
+
runGenerationUsage,
|
|
22
|
+
} from '../middleware/run'
|
|
23
|
+
import {
|
|
24
|
+
abortReasonMessage,
|
|
25
|
+
createActivityAbortControls,
|
|
26
|
+
isActivityAbortError,
|
|
27
|
+
raceWithAbort,
|
|
28
|
+
} from '../../utilities/activity-abort'
|
|
29
|
+
import type { InternalLogger } from '../../logger/internal-logger'
|
|
30
|
+
import type { DebugOption } from '../../logger/types'
|
|
31
|
+
import type { GenerationMiddleware } from '../middleware/types'
|
|
32
|
+
import type { WorldAdapter } from './adapter'
|
|
33
|
+
import type { StreamChunk, WorldGenerationResult } from '../../types'
|
|
34
|
+
|
|
35
|
+
// ===========================
|
|
36
|
+
// Activity Kind
|
|
37
|
+
// ===========================
|
|
38
|
+
|
|
39
|
+
/** The adapter kind this activity handles */
|
|
40
|
+
export const kind = 'world' as const
|
|
41
|
+
|
|
42
|
+
// ===========================
|
|
43
|
+
// Type Extraction Helpers
|
|
44
|
+
// ===========================
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Extract provider options from a WorldAdapter via ~types.
|
|
48
|
+
*/
|
|
49
|
+
export type WorldProviderOptions<TAdapter> = TAdapter extends {
|
|
50
|
+
'~types': { providerOptions: infer P extends object }
|
|
51
|
+
}
|
|
52
|
+
? P
|
|
53
|
+
: object
|
|
54
|
+
|
|
55
|
+
// ===========================
|
|
56
|
+
// Activity Options Type
|
|
57
|
+
// ===========================
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Options for the world generation activity.
|
|
61
|
+
* The model is extracted from the adapter's model property.
|
|
62
|
+
*
|
|
63
|
+
* @template TAdapter - The world adapter type
|
|
64
|
+
* @template TStream - Whether to stream the output
|
|
65
|
+
*
|
|
66
|
+
* @experimental World generation is an experimental feature and may change.
|
|
67
|
+
*/
|
|
68
|
+
export interface WorldActivityOptions<
|
|
69
|
+
TAdapter extends WorldAdapter<string, WorldProviderOptions<TAdapter>>,
|
|
70
|
+
TStream extends boolean = false,
|
|
71
|
+
> {
|
|
72
|
+
/** The world adapter to use (must be created with a model) */
|
|
73
|
+
adapter: TAdapter & { kind: typeof kind }
|
|
74
|
+
/** Natural-language description of the world or scene */
|
|
75
|
+
prompt: string
|
|
76
|
+
/** Provider-specific options for world generation */
|
|
77
|
+
modelOptions?: WorldProviderOptions<TAdapter>
|
|
78
|
+
/**
|
|
79
|
+
* Whether to wrap the token result as StreamChunks for SSE transport.
|
|
80
|
+
* This is not the live video. When false or omitted, returns
|
|
81
|
+
* Promise<WorldGenerationResult>.
|
|
82
|
+
*
|
|
83
|
+
* @default false
|
|
84
|
+
*/
|
|
85
|
+
stream?: TStream
|
|
86
|
+
/**
|
|
87
|
+
* Enable debug logging. Pass `true` to enable all categories, `false` to
|
|
88
|
+
* silence everything including errors, or a `DebugConfig` object for granular
|
|
89
|
+
* control and/or a custom `Logger`.
|
|
90
|
+
*/
|
|
91
|
+
debug?: DebugOption
|
|
92
|
+
/**
|
|
93
|
+
* Observe-only middleware notified on start, usage, success, and error. Pass
|
|
94
|
+
* `otelMiddleware()` to emit OpenTelemetry spans, or implement the
|
|
95
|
+
* `GenerationMiddleware` contract for a custom backend.
|
|
96
|
+
*/
|
|
97
|
+
middleware?: Array<GenerationMiddleware>
|
|
98
|
+
/** Stable conversation/thread id for correlating this run when persisted. */
|
|
99
|
+
threadId?: string
|
|
100
|
+
/** Stable run id for correlating this run when persisted. */
|
|
101
|
+
runId?: string
|
|
102
|
+
/**
|
|
103
|
+
* Maximum duration of the token mint in milliseconds.
|
|
104
|
+
* No SDK-wide default. Composed with {@link abortSignal}; the first abort wins.
|
|
105
|
+
*/
|
|
106
|
+
timeout?: number
|
|
107
|
+
/**
|
|
108
|
+
* Caller cancellation signal (request disconnects, job/runtime cancellation).
|
|
109
|
+
* Composed with {@link timeout} into an effective signal forwarded to the
|
|
110
|
+
* adapter. Request-specific — not stored on global provider client config.
|
|
111
|
+
*/
|
|
112
|
+
abortSignal?: AbortSignal
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// ===========================
|
|
116
|
+
// Activity Result Type
|
|
117
|
+
// ===========================
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Result type for the world generation activity.
|
|
121
|
+
* - If stream is true: AsyncIterable<StreamChunk>
|
|
122
|
+
* - Otherwise: Promise<WorldGenerationResult>
|
|
123
|
+
*/
|
|
124
|
+
export type WorldActivityResult<TStream extends boolean = false> =
|
|
125
|
+
TStream extends true
|
|
126
|
+
? AsyncIterable<StreamChunk>
|
|
127
|
+
: Promise<WorldGenerationResult>
|
|
128
|
+
|
|
129
|
+
function createId(prefix: string): string {
|
|
130
|
+
return `${prefix}-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// ===========================
|
|
134
|
+
// Activity Implementation
|
|
135
|
+
// ===========================
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* World generation activity - opens a live, prompt-steerable world session.
|
|
139
|
+
*
|
|
140
|
+
* @example Mint a session token on the server
|
|
141
|
+
* ```ts
|
|
142
|
+
* import { generateWorld } from '@tanstack/ai'
|
|
143
|
+
* import { reactorWorld } from '@tanstack/ai-reactor'
|
|
144
|
+
*
|
|
145
|
+
* const world = await generateWorld({
|
|
146
|
+
* adapter: reactorWorld('visko-orbis-stable'),
|
|
147
|
+
* prompt: 'A neon cyberpunk city at night, slow aerial drift',
|
|
148
|
+
* })
|
|
149
|
+
*
|
|
150
|
+
* // Hand world.token, world.model, and world.prompt to the browser.
|
|
151
|
+
* ```
|
|
152
|
+
*
|
|
153
|
+
* @experimental World generation is an experimental feature and may change.
|
|
154
|
+
*/
|
|
155
|
+
export function generateWorld<
|
|
156
|
+
TAdapter extends WorldAdapter<string, WorldProviderOptions<TAdapter>>,
|
|
157
|
+
TStream extends boolean = false,
|
|
158
|
+
>(
|
|
159
|
+
options: WorldActivityOptions<TAdapter, TStream>,
|
|
160
|
+
): WorldActivityResult<TStream> {
|
|
161
|
+
if (options.stream) {
|
|
162
|
+
return streamGenerationResult(
|
|
163
|
+
(resolved) => runGenerateWorld({ ...options, runId: resolved.runId }),
|
|
164
|
+
options,
|
|
165
|
+
) as WorldActivityResult<TStream>
|
|
166
|
+
}
|
|
167
|
+
return runGenerateWorld(options) as WorldActivityResult<TStream>
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Run the core world generation logic (non-streaming).
|
|
172
|
+
*/
|
|
173
|
+
async function runGenerateWorld<
|
|
174
|
+
TAdapter extends WorldAdapter<string, WorldProviderOptions<TAdapter>>,
|
|
175
|
+
>(
|
|
176
|
+
options: WorldActivityOptions<TAdapter, boolean>,
|
|
177
|
+
): Promise<WorldGenerationResult> {
|
|
178
|
+
const {
|
|
179
|
+
adapter,
|
|
180
|
+
stream: _stream,
|
|
181
|
+
debug: _debug,
|
|
182
|
+
middleware,
|
|
183
|
+
threadId,
|
|
184
|
+
runId,
|
|
185
|
+
timeout,
|
|
186
|
+
abortSignal: callerAbortSignal,
|
|
187
|
+
...rest
|
|
188
|
+
} = options
|
|
189
|
+
const model = adapter.model
|
|
190
|
+
const requestId = createId('world')
|
|
191
|
+
const startTime = Date.now()
|
|
192
|
+
const logger: InternalLogger = resolveDebugOption(options.debug)
|
|
193
|
+
const abortControls = createActivityAbortControls({
|
|
194
|
+
timeout,
|
|
195
|
+
abortSignal: callerAbortSignal,
|
|
196
|
+
})
|
|
197
|
+
const providerName =
|
|
198
|
+
(adapter as { name?: string; provider?: string }).provider ??
|
|
199
|
+
(adapter as { name?: string }).name ??
|
|
200
|
+
'unknown'
|
|
201
|
+
|
|
202
|
+
const mwCtx = createGenerationContext({
|
|
203
|
+
requestId,
|
|
204
|
+
activity: 'world',
|
|
205
|
+
provider: adapter.name,
|
|
206
|
+
model,
|
|
207
|
+
modelOptions: rest.modelOptions,
|
|
208
|
+
threadId,
|
|
209
|
+
runId,
|
|
210
|
+
artifactInputs: { prompt: rest.prompt },
|
|
211
|
+
createId,
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
await runGenerationStart(middleware, mwCtx)
|
|
215
|
+
|
|
216
|
+
aiEventClient.emit('world:request:started', {
|
|
217
|
+
requestId,
|
|
218
|
+
provider: adapter.name,
|
|
219
|
+
model,
|
|
220
|
+
prompt: rest.prompt,
|
|
221
|
+
timestamp: startTime,
|
|
222
|
+
...(rest.modelOptions !== undefined && {
|
|
223
|
+
modelOptions: rest.modelOptions as Record<string, unknown>,
|
|
224
|
+
}),
|
|
225
|
+
})
|
|
226
|
+
|
|
227
|
+
logger.request(`activity=generateWorld provider=${providerName}`, {
|
|
228
|
+
provider: providerName,
|
|
229
|
+
model,
|
|
230
|
+
})
|
|
231
|
+
|
|
232
|
+
try {
|
|
233
|
+
const rawResult = await raceWithAbort(
|
|
234
|
+
adapter.createWorld({
|
|
235
|
+
...rest,
|
|
236
|
+
model,
|
|
237
|
+
logger,
|
|
238
|
+
...(abortControls.signal ? { abortSignal: abortControls.signal } : {}),
|
|
239
|
+
}),
|
|
240
|
+
abortControls.signal,
|
|
241
|
+
)
|
|
242
|
+
abortControls.clear()
|
|
243
|
+
const result = await applyGenerationResultTransforms(mwCtx, rawResult)
|
|
244
|
+
const elapsedMs = Date.now() - startTime
|
|
245
|
+
|
|
246
|
+
aiEventClient.emit('world:request:completed', {
|
|
247
|
+
requestId,
|
|
248
|
+
provider: adapter.name,
|
|
249
|
+
model: result.model,
|
|
250
|
+
prompt: result.prompt,
|
|
251
|
+
status: result.status,
|
|
252
|
+
duration: elapsedMs,
|
|
253
|
+
timestamp: Date.now(),
|
|
254
|
+
...(rest.modelOptions !== undefined && {
|
|
255
|
+
modelOptions: rest.modelOptions as Record<string, unknown>,
|
|
256
|
+
}),
|
|
257
|
+
})
|
|
258
|
+
|
|
259
|
+
if (result.usage) {
|
|
260
|
+
aiEventClient.emit('world:usage', {
|
|
261
|
+
requestId,
|
|
262
|
+
model: result.model,
|
|
263
|
+
usage: result.usage,
|
|
264
|
+
timestamp: Date.now(),
|
|
265
|
+
...(rest.modelOptions !== undefined && {
|
|
266
|
+
modelOptions: rest.modelOptions as Record<string, unknown>,
|
|
267
|
+
}),
|
|
268
|
+
})
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
logger.output(`activity=generateWorld provider=${providerName}`, {
|
|
272
|
+
model: result.model,
|
|
273
|
+
status: result.status,
|
|
274
|
+
})
|
|
275
|
+
|
|
276
|
+
if (result.usage) await runGenerationUsage(middleware, mwCtx, result.usage)
|
|
277
|
+
await runGenerationFinish(middleware, mwCtx, {
|
|
278
|
+
duration: elapsedMs,
|
|
279
|
+
usage: result.usage,
|
|
280
|
+
})
|
|
281
|
+
|
|
282
|
+
return result
|
|
283
|
+
} catch (error) {
|
|
284
|
+
abortControls.clear()
|
|
285
|
+
const elapsedMs = Date.now() - startTime
|
|
286
|
+
const err = error as Error
|
|
287
|
+
aiEventClient.emit('world:request:error', {
|
|
288
|
+
requestId,
|
|
289
|
+
provider: adapter.name,
|
|
290
|
+
model,
|
|
291
|
+
error: { message: err.message, name: err.name },
|
|
292
|
+
duration: elapsedMs,
|
|
293
|
+
timestamp: Date.now(),
|
|
294
|
+
...(rest.modelOptions !== undefined && {
|
|
295
|
+
modelOptions: rest.modelOptions as Record<string, unknown>,
|
|
296
|
+
}),
|
|
297
|
+
})
|
|
298
|
+
if (isActivityAbortError(error, abortControls.signal)) {
|
|
299
|
+
await runGenerationAbort(middleware, mwCtx, {
|
|
300
|
+
reason: abortReasonMessage(error, abortControls.signal),
|
|
301
|
+
duration: elapsedMs,
|
|
302
|
+
})
|
|
303
|
+
} else {
|
|
304
|
+
await runGenerationError(middleware, mwCtx, {
|
|
305
|
+
error,
|
|
306
|
+
duration: elapsedMs,
|
|
307
|
+
})
|
|
308
|
+
}
|
|
309
|
+
logger.errors('generateWorld activity failed', {
|
|
310
|
+
error,
|
|
311
|
+
source: 'generateWorld',
|
|
312
|
+
})
|
|
313
|
+
throw error
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// ===========================
|
|
318
|
+
// Options Factory
|
|
319
|
+
// ===========================
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Create typed options for the generateWorld() function without executing.
|
|
323
|
+
*/
|
|
324
|
+
export function createWorldOptions<
|
|
325
|
+
TAdapter extends WorldAdapter<string, WorldProviderOptions<TAdapter>>,
|
|
326
|
+
TStream extends boolean = false,
|
|
327
|
+
>(
|
|
328
|
+
options: WorldActivityOptions<TAdapter, TStream>,
|
|
329
|
+
): WorldActivityOptions<TAdapter, TStream> {
|
|
330
|
+
return options
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// Re-export adapter types
|
|
334
|
+
export type {
|
|
335
|
+
WorldAdapter,
|
|
336
|
+
WorldAdapterConfig,
|
|
337
|
+
AnyWorldAdapter,
|
|
338
|
+
} from './adapter'
|
|
339
|
+
export { BaseWorldAdapter } from './adapter'
|
package/src/activities/index.ts
CHANGED
|
@@ -23,6 +23,8 @@ import type { AnyTTSAdapter } from './generateSpeech/adapter'
|
|
|
23
23
|
import type { AnyTranscriptionAdapter } from './generateTranscription/adapter'
|
|
24
24
|
import type { AnyEmbeddingAdapter } from './embed/adapter'
|
|
25
25
|
import type { AnyRerankAdapter } from './rerank/adapter'
|
|
26
|
+
import type { AnyWorldAdapter } from './generateWorld/adapter'
|
|
27
|
+
import type { AnyLiveVideoAdapter } from './generateLiveVideo/adapter'
|
|
26
28
|
|
|
27
29
|
// ===========================
|
|
28
30
|
// Chat Activity
|
|
@@ -210,6 +212,44 @@ export {
|
|
|
210
212
|
type AnyEmbeddingAdapter,
|
|
211
213
|
} from './embed/adapter'
|
|
212
214
|
|
|
215
|
+
// ===========================
|
|
216
|
+
// World Activity (Experimental)
|
|
217
|
+
// ===========================
|
|
218
|
+
|
|
219
|
+
export {
|
|
220
|
+
kind as worldKind,
|
|
221
|
+
generateWorld,
|
|
222
|
+
type WorldActivityOptions,
|
|
223
|
+
type WorldActivityResult,
|
|
224
|
+
type WorldProviderOptions,
|
|
225
|
+
} from './generateWorld/index'
|
|
226
|
+
|
|
227
|
+
export {
|
|
228
|
+
BaseWorldAdapter,
|
|
229
|
+
type WorldAdapter,
|
|
230
|
+
type WorldAdapterConfig,
|
|
231
|
+
type AnyWorldAdapter,
|
|
232
|
+
} from './generateWorld/adapter'
|
|
233
|
+
|
|
234
|
+
// ===========================
|
|
235
|
+
// Live Activity (Experimental)
|
|
236
|
+
// ===========================
|
|
237
|
+
|
|
238
|
+
export {
|
|
239
|
+
kind as liveVideoKind,
|
|
240
|
+
generateLiveVideo,
|
|
241
|
+
type LiveVideoActivityOptions,
|
|
242
|
+
type LiveVideoActivityResult,
|
|
243
|
+
type LiveVideoProviderOptions,
|
|
244
|
+
} from './generateLiveVideo/index'
|
|
245
|
+
|
|
246
|
+
export {
|
|
247
|
+
BaseLiveVideoAdapter,
|
|
248
|
+
type LiveVideoAdapter,
|
|
249
|
+
type LiveVideoAdapterConfig,
|
|
250
|
+
type AnyLiveVideoAdapter,
|
|
251
|
+
} from './generateLiveVideo/adapter'
|
|
252
|
+
|
|
213
253
|
// ===========================
|
|
214
254
|
// Adapter Union Types
|
|
215
255
|
// ===========================
|
|
@@ -225,6 +265,8 @@ export type AIAdapter =
|
|
|
225
265
|
| AnyTranscriptionAdapter
|
|
226
266
|
| AnyEmbeddingAdapter
|
|
227
267
|
| AnyRerankAdapter
|
|
268
|
+
| AnyWorldAdapter
|
|
269
|
+
| AnyLiveVideoAdapter
|
|
228
270
|
|
|
229
271
|
/** Union type of all adapter kinds */
|
|
230
272
|
export type AdapterKind =
|
|
@@ -237,3 +279,5 @@ export type AdapterKind =
|
|
|
237
279
|
| 'transcription'
|
|
238
280
|
| 'embedding'
|
|
239
281
|
| 'rerank'
|
|
282
|
+
| 'world'
|
|
283
|
+
| 'liveVideo'
|
package/src/client.ts
CHANGED
|
@@ -4,6 +4,8 @@ import type {
|
|
|
4
4
|
TTSOptions,
|
|
5
5
|
TranscriptionOptions,
|
|
6
6
|
VideoGenerationOptions,
|
|
7
|
+
WorldGenerationOptions,
|
|
8
|
+
LiveVideoGenerationOptions,
|
|
7
9
|
} from './types'
|
|
8
10
|
|
|
9
11
|
export type GenerationKind =
|
|
@@ -12,6 +14,8 @@ export type GenerationKind =
|
|
|
12
14
|
| 'tts'
|
|
13
15
|
| 'video'
|
|
14
16
|
| 'transcription'
|
|
17
|
+
| 'world'
|
|
18
|
+
| 'liveVideo'
|
|
15
19
|
|
|
16
20
|
type GenerationInputByKind = {
|
|
17
21
|
image: Omit<ImageGenerationOptions, 'logger' | 'model'>
|
|
@@ -19,6 +23,8 @@ type GenerationInputByKind = {
|
|
|
19
23
|
tts: Omit<TTSOptions, 'logger' | 'model'>
|
|
20
24
|
video: Omit<VideoGenerationOptions, 'logger' | 'model'>
|
|
21
25
|
transcription: Omit<TranscriptionOptions, 'logger' | 'model'>
|
|
26
|
+
world: Omit<WorldGenerationOptions, 'logger' | 'model'>
|
|
27
|
+
liveVideo: Omit<LiveVideoGenerationOptions, 'logger' | 'model'>
|
|
22
28
|
}
|
|
23
29
|
|
|
24
30
|
export interface GenerationParams<TKind extends GenerationKind> {
|
|
@@ -34,6 +40,8 @@ const generationKinds = [
|
|
|
34
40
|
'tts',
|
|
35
41
|
'video',
|
|
36
42
|
'transcription',
|
|
43
|
+
'world',
|
|
44
|
+
'liveVideo',
|
|
37
45
|
] as const satisfies ReadonlyArray<GenerationKind>
|
|
38
46
|
|
|
39
47
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
package/src/index.ts
CHANGED
|
@@ -10,6 +10,8 @@ export {
|
|
|
10
10
|
generateSpeech,
|
|
11
11
|
generateTranscription,
|
|
12
12
|
embed,
|
|
13
|
+
generateWorld,
|
|
14
|
+
generateLiveVideo,
|
|
13
15
|
} from './activities/index'
|
|
14
16
|
|
|
15
17
|
// Create options functions - for pre-defining typed configurations
|
|
@@ -22,6 +24,8 @@ export { createVideoOptions } from './activities/generateVideo/index'
|
|
|
22
24
|
export { createSpeechOptions } from './activities/generateSpeech/index'
|
|
23
25
|
export { createTranscriptionOptions } from './activities/generateTranscription/index'
|
|
24
26
|
export { createEmbedOptions } from './activities/embed/index'
|
|
27
|
+
export { createWorldOptions } from './activities/generateWorld/index'
|
|
28
|
+
export { createLiveVideoOptions } from './activities/generateLiveVideo/index'
|
|
25
29
|
|
|
26
30
|
// Re-export types
|
|
27
31
|
export type {
|
|
@@ -44,6 +48,10 @@ export type {
|
|
|
44
48
|
EmbeddingAdapter,
|
|
45
49
|
AnyRerankAdapter,
|
|
46
50
|
RerankAdapter,
|
|
51
|
+
AnyWorldAdapter,
|
|
52
|
+
WorldAdapter,
|
|
53
|
+
AnyLiveVideoAdapter,
|
|
54
|
+
LiveVideoAdapter,
|
|
47
55
|
} from './activities/index'
|
|
48
56
|
|
|
49
57
|
// Rerank adapter base + types
|
package/src/middlewares/otel.ts
CHANGED