@opencode/ai 2.2.4 → 2.2.6
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 +133 -69
- package/dist/cache-policy.d.ts +1 -1
- package/dist/cache-policy.js +16 -4
- package/dist/decision-client.d.ts +3 -3
- package/dist/decision.d.ts +20 -125
- package/dist/decision.js +25 -15
- package/dist/effect.d.ts +4 -15
- package/dist/effect.js +2 -6
- package/dist/effort-updates.d.ts +3 -3
- package/dist/effort-updates.js +2 -2
- package/dist/experimental/cloudflare-run-extraction.d.ts +7 -3
- package/dist/experimental/cloudflare-run-extraction.js +4 -1
- package/dist/experimental/extraction.d.ts +10 -40
- package/dist/experimental/extraction.js +14 -13
- package/dist/experimental.d.ts +8 -8
- package/dist/experimental.js +4 -4
- package/dist/generation.d.ts +0 -2
- package/dist/generation.js +2 -2
- package/dist/image-client.d.ts +13 -7
- package/dist/image-client.js +1 -1
- package/dist/image.d.ts +357 -464
- package/dist/image.js +17 -15
- package/dist/index.d.ts +28 -465
- package/dist/index.js +18 -17
- package/dist/llm.d.ts +65 -266
- package/dist/llm.js +101 -92
- package/dist/loop.d.ts +38 -0
- package/dist/loop.js +136 -0
- package/dist/media-model.d.ts +1 -1
- package/dist/media-model.js +8 -6
- package/dist/media.d.ts +9 -0
- package/dist/media.js +37 -2
- package/dist/protocols/alibaba-chat.d.ts +5 -1
- package/dist/protocols/alibaba-chat.js +3 -3
- package/dist/protocols/alibaba-images.d.ts +2 -2
- package/dist/protocols/alibaba-messages.js +3 -3
- package/dist/protocols/alibaba-responses.js +8 -20
- package/dist/protocols/anthropic-messages.d.ts +1 -1
- package/dist/protocols/anthropic-messages.js +57 -185
- package/dist/protocols/assemblyai-transcription.d.ts +2 -2
- package/dist/protocols/bedrock-converse.js +11 -22
- package/dist/protocols/cartesia-speech.d.ts +2 -2
- package/dist/protocols/cloudflare-workers-ai-images.d.ts +2 -2
- package/dist/protocols/cohere-chat.js +9 -12
- package/dist/protocols/deepgram-speech.d.ts +2 -2
- package/dist/protocols/deepgram-transcription.d.ts +2 -2
- package/dist/protocols/elevenlabs-speech.d.ts +2 -2
- package/dist/protocols/elevenlabs-transcription.d.ts +2 -2
- package/dist/protocols/gemini.d.ts +3 -0
- package/dist/protocols/gemini.js +56 -89
- package/dist/protocols/google-images.d.ts +2 -2
- package/dist/protocols/google-interactions.d.ts +3 -4
- package/dist/protocols/google-interactions.js +54 -32
- package/dist/protocols/google-speech.d.ts +2 -2
- package/dist/protocols/google-transcription.d.ts +2 -2
- package/dist/protocols/google-video.d.ts +2 -2
- package/dist/protocols/meta-images.d.ts +2 -2
- package/dist/protocols/meta-responses.js +26 -23
- package/dist/protocols/minimax-images.d.ts +2 -2
- package/dist/protocols/mistral-chat.js +14 -20
- package/dist/protocols/open-responses-channel.js +6 -19
- package/dist/protocols/open-responses-continuation.d.ts +1 -5
- package/dist/protocols/open-responses-continuation.js +1 -3
- package/dist/protocols/open-responses.d.ts +1 -21
- package/dist/protocols/open-responses.js +10 -15
- package/dist/protocols/openai-chat.d.ts +3 -23
- package/dist/protocols/openai-chat.js +26 -47
- package/dist/protocols/openai-compatible-chat.d.ts +1 -1
- package/dist/protocols/openai-compatible-responses.d.ts +2 -2
- package/dist/protocols/openai-compatible-responses.js +1 -1
- package/dist/protocols/openai-decisions.js +1 -1
- package/dist/protocols/openai-images.d.ts +2 -2
- package/dist/protocols/openai-responses.js +10 -29
- package/dist/protocols/openai-speech.d.ts +2 -2
- package/dist/protocols/openai-transcription.d.ts +2 -2
- package/dist/protocols/runway-video.d.ts +2 -2
- package/dist/protocols/shared.d.ts +1 -4
- package/dist/protocols/shared.js +13 -11
- package/dist/protocols/system-one.d.ts +4 -4
- package/dist/protocols/utils/bedrock-cache.js +2 -5
- package/dist/protocols/utils/bedrock-media.d.ts +0 -3
- package/dist/protocols/utils/cache.d.ts +3 -0
- package/dist/protocols/utils/cache.js +15 -2
- package/dist/protocols/utils/image-sizing.d.ts +1 -1
- package/dist/protocols/utils/responses-checkpoint.js +1 -1
- package/dist/protocols/utils/responses-compaction.d.ts +1 -1
- package/dist/protocols/utils/responses-compaction.js +6 -5
- package/dist/protocols/utils/responses-hosted-tools.d.ts +97 -1
- package/dist/protocols/utils/responses-hosted-tools.js +31 -0
- package/dist/protocols/utils/tool-stream.d.ts +5 -271
- package/dist/protocols/utils/tool-stream.js +3 -13
- package/dist/protocols/venice-chat.d.ts +3 -1
- package/dist/protocols/venice-chat.js +4 -4
- package/dist/protocols/xai-images.d.ts +2 -2
- package/dist/protocols/xai-responses.js +5 -25
- package/dist/protocols/xai-video.d.ts +2 -2
- package/dist/protocols/zai-chat.d.ts +5 -1
- package/dist/protocols/zai-chat.js +1 -1
- package/dist/protocols/zai-images.d.ts +2 -2
- package/dist/protocols/zai-messages.js +3 -3
- package/dist/provider-error.d.ts +0 -1
- package/dist/provider-error.js +9 -80
- package/dist/providers/alibaba.d.ts +67 -4
- package/dist/providers/alibaba.js +6 -1
- package/dist/providers/amazon-bedrock-mantle.d.ts +6 -3
- package/dist/providers/amazon-bedrock-mantle.js +6 -3
- package/dist/providers/amazon-bedrock.d.ts +6 -7
- package/dist/providers/amazon-bedrock.js +1 -1
- package/dist/providers/anthropic-compatible.d.ts +7 -8
- package/dist/providers/anthropic-compatible.js +2 -5
- package/dist/providers/anthropic.d.ts +8 -9
- package/dist/providers/anthropic.js +2 -7
- package/dist/providers/assemblyai.d.ts +2 -2
- package/dist/providers/assemblyai.js +2 -7
- package/dist/providers/azure/messages.d.ts +2 -0
- package/dist/providers/azure/messages.js +1 -0
- package/dist/providers/azure.d.ts +322 -7
- package/dist/providers/azure.js +25 -9
- package/dist/providers/baseten.d.ts +5 -5
- package/dist/providers/baseten.js +7 -21
- package/dist/providers/cartesia.d.ts +1 -1
- package/dist/providers/cerebras.d.ts +5 -5
- package/dist/providers/cerebras.js +4 -15
- package/dist/providers/cloudflare-ai-gateway.d.ts +21 -13
- package/dist/providers/cloudflare-ai-gateway.js +28 -40
- package/dist/providers/cloudflare-shared.d.ts +9 -0
- package/dist/providers/cloudflare-shared.js +25 -0
- package/dist/providers/cloudflare-workers-ai.d.ts +4 -4
- package/dist/providers/cloudflare-workers-ai.js +4 -20
- package/dist/providers/cohere/chat.js +2 -7
- package/dist/providers/cohere.d.ts +6 -5
- package/dist/providers/cohere.js +7 -13
- package/dist/providers/deepgram.d.ts +2 -2
- package/dist/providers/deepgram.js +2 -7
- package/dist/providers/deepinfra.d.ts +5 -5
- package/dist/providers/deepinfra.js +5 -13
- package/dist/providers/deepseek.d.ts +5 -5
- package/dist/providers/deepseek.js +3 -14
- package/dist/providers/digitalocean.d.ts +8 -5
- package/dist/providers/digitalocean.js +13 -14
- package/dist/providers/elevenlabs.d.ts +2 -2
- package/dist/providers/elevenlabs.js +2 -7
- package/dist/providers/fireworks.d.ts +5 -5
- package/dist/providers/fireworks.js +4 -15
- package/dist/providers/google/interactions.d.ts +1 -1
- package/dist/providers/google/interactions.js +2 -7
- package/dist/providers/google-vertex-chat.d.ts +3 -3
- package/dist/providers/google-vertex-chat.js +3 -29
- package/dist/providers/google-vertex-interactions.d.ts +3 -3
- package/dist/providers/google-vertex-messages.d.ts +3 -3
- package/dist/providers/google-vertex-messages.js +3 -29
- package/dist/providers/google-vertex-mistral.d.ts +3 -3
- package/dist/providers/google-vertex-mistral.js +3 -29
- package/dist/providers/google-vertex-responses.d.ts +3 -3
- package/dist/providers/google-vertex-responses.js +4 -30
- package/dist/providers/google-vertex-shared.d.ts +31 -0
- package/dist/providers/google-vertex-shared.js +25 -0
- package/dist/providers/google-vertex.d.ts +3 -3
- package/dist/providers/google.d.ts +15 -13
- package/dist/providers/google.js +9 -19
- package/dist/providers/groq.d.ts +5 -5
- package/dist/providers/groq.js +4 -15
- package/dist/providers/meta.d.ts +5 -5
- package/dist/providers/meta.js +10 -24
- package/dist/providers/minimax/chat.js +2 -7
- package/dist/providers/minimax/responses.js +2 -7
- package/dist/providers/minimax.d.ts +5 -5
- package/dist/providers/minimax.js +11 -23
- package/dist/providers/mistral.d.ts +10 -11
- package/dist/providers/mistral.js +3 -14
- package/dist/providers/moonshot/messages.js +2 -7
- package/dist/providers/moonshot/responses.js +2 -7
- package/dist/providers/moonshot.d.ts +5 -5
- package/dist/providers/moonshot.js +4 -16
- package/dist/providers/openai-compatible-responses.d.ts +6 -7
- package/dist/providers/openai-compatible-responses.js +2 -8
- package/dist/providers/openai-compatible.d.ts +6 -7
- package/dist/providers/openai-compatible.js +4 -10
- package/dist/providers/openai.d.ts +4 -4
- package/dist/providers/openai.js +3 -3
- package/dist/providers/opencode.d.ts +4 -4
- package/dist/providers/opencode.js +6 -2
- package/dist/providers/openrouter.d.ts +8 -5
- package/dist/providers/openrouter.js +16 -24
- package/dist/providers/runway.d.ts +1 -1
- package/dist/providers/settings.d.ts +40 -0
- package/dist/providers/settings.js +19 -0
- package/dist/providers/togetherai.d.ts +5 -5
- package/dist/providers/togetherai.js +5 -15
- package/dist/providers/typesafe-ai.d.ts +4 -4
- package/dist/providers/typesafe-ai.js +6 -2
- package/dist/providers/venice.d.ts +4 -4
- package/dist/providers/venice.js +6 -2
- package/dist/providers/vercel-ai-gateway.d.ts +5 -5
- package/dist/providers/vercel-ai-gateway.js +15 -28
- package/dist/providers/xai.d.ts +4 -4
- package/dist/providers/xai.js +4 -12
- package/dist/providers/zai-coding-plan/messages.js +2 -7
- package/dist/providers/zai-coding-plan/responses.js +2 -7
- package/dist/providers/zai-coding-plan.d.ts +5 -5
- package/dist/providers/zai-coding-plan.js +8 -15
- package/dist/providers/zai.d.ts +5 -5
- package/dist/providers/zai.js +10 -22
- package/dist/public.d.ts +12 -0
- package/dist/public.js +5 -0
- package/dist/route/auth-options.d.ts +9 -5
- package/dist/route/auth-options.js +10 -7
- package/dist/route/client.d.ts +50 -37
- package/dist/route/client.js +42 -53
- package/dist/route/decision.d.ts +8 -8
- package/dist/route/decision.js +3 -3
- package/dist/route/executor.d.ts +5 -0
- package/dist/route/executor.js +10 -0
- package/dist/route/index.d.ts +5 -7
- package/dist/route/index.js +1 -1
- package/dist/route/media.d.ts +7 -11
- package/dist/route/media.js +22 -26
- package/dist/route/transport/http.js +6 -5
- package/dist/route/transport/websocket.js +7 -1
- package/dist/schema/errors.d.ts +16 -17
- package/dist/schema/errors.js +63 -12
- package/dist/schema/events.d.ts +2563 -2954
- package/dist/schema/events.js +54 -109
- package/dist/schema/messages.d.ts +194 -137
- package/dist/schema/messages.js +66 -83
- package/dist/schema/options.d.ts +112 -65
- package/dist/schema/options.js +52 -101
- package/dist/speech-client.d.ts +7 -7
- package/dist/speech.d.ts +306 -316
- package/dist/speech.js +16 -14
- package/dist/testing.d.ts +31 -175
- package/dist/testing.js +60 -5
- package/dist/tool-history.d.ts +1 -1
- package/dist/tool-history.js +3 -10
- package/dist/tool-runtime.d.ts +9 -2
- package/dist/tool-runtime.js +17 -31
- package/dist/tool.d.ts +39 -43
- package/dist/tool.js +16 -26
- package/dist/transcription-client.d.ts +7 -7
- package/dist/transcription.d.ts +314 -265
- package/dist/transcription.js +16 -14
- package/dist/utils/provider-codes.d.ts +3 -0
- package/dist/utils/provider-codes.js +41 -0
- package/dist/video-client.d.ts +7 -7
- package/dist/video-client.js +1 -1
- package/dist/video.d.ts +269 -287
- package/dist/video.js +16 -14
- package/package.json +9 -9
- package/dist/experimental/testing.d.ts +0 -3
- package/dist/experimental/testing.js +0 -3
- package/dist/testing/decision.d.ts +0 -16
- package/dist/testing/decision.js +0 -20
- package/dist/testing/image.d.ts +0 -14
- package/dist/testing/image.js +0 -12
- package/dist/testing/media.d.ts +0 -18
- package/dist/testing/media.js +0 -36
- package/dist/testing/script.d.ts +0 -28
- package/dist/testing/script.js +0 -60
- package/dist/testing/speech.d.ts +0 -14
- package/dist/testing/speech.js +0 -12
- package/dist/testing/transcription.d.ts +0 -14
- package/dist/testing/transcription.js +0 -12
- package/dist/testing/video.d.ts +0 -14
- package/dist/testing/video.js +0 -12
package/dist/decision.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Effect, Schema } from "effect";
|
|
2
2
|
import { Service, type Execute } from "./decision-client.js";
|
|
3
3
|
import { Media } from "./media.js";
|
|
4
|
-
import { AIError, HttpOptions, ModelID, ProviderID, ProviderOptions, type OpenString } from "./schema/index.js";
|
|
4
|
+
import { AIError, type BaseRequest, type HttpOptions, ModelID, ProviderID, ProviderOptions, type OpenString } from "./schema/index.js";
|
|
5
5
|
export declare const DecisionTextPart: Schema.Struct<{
|
|
6
6
|
readonly type: Schema.Literal<"text">;
|
|
7
7
|
readonly text: Schema.String;
|
|
@@ -87,8 +87,16 @@ export declare const DecisionPart: Schema.toTaggedUnion<"type", readonly [Schema
|
|
|
87
87
|
readonly filename: Schema.optional<Schema.String>;
|
|
88
88
|
}>]>;
|
|
89
89
|
export type DecisionPart = Schema.Schema.Type<typeof DecisionPart>;
|
|
90
|
+
/** A media part as input: `media` may be plain data, with `mediaType` naming its type when the content can't. */
|
|
91
|
+
export type DecisionMediaPartInput = Omit<typeof DecisionMediaPart.Type, "media"> & {
|
|
92
|
+
readonly media: Media.Input;
|
|
93
|
+
readonly mediaType?: string;
|
|
94
|
+
};
|
|
95
|
+
export type DecisionPartInput = Exclude<DecisionPart, {
|
|
96
|
+
readonly type: "media";
|
|
97
|
+
}> | DecisionMediaPartInput;
|
|
90
98
|
/** A plain object is one `json` part. */
|
|
91
|
-
export type DecisionInput = typeof Schema.JsonObject.Type | ReadonlyArray<
|
|
99
|
+
export type DecisionInput = typeof Schema.JsonObject.Type | ReadonlyArray<DecisionPartInput>;
|
|
92
100
|
/** Choice values are typed: `true` and `"true"` are different values. */
|
|
93
101
|
export declare const ChoiceValue: Schema.Union<readonly [Schema.String, Schema.Boolean]>;
|
|
94
102
|
export type ChoiceValue = Schema.Schema.Type<typeof ChoiceValue>;
|
|
@@ -245,7 +253,7 @@ export type DecisionOptions = Record<string, unknown>;
|
|
|
245
253
|
/** What a decision model's route does; `DecisionRoute.make(...).model(...)` builds one from a protocol. */
|
|
246
254
|
export interface DecisionModelRoute<Options extends DecisionOptions = DecisionOptions> {
|
|
247
255
|
readonly id: string;
|
|
248
|
-
generate(request:
|
|
256
|
+
generate(request: DecisionRequest<DecisionModel<Options>>, execute: Execute): Effect.Effect<DecisionResponse, AIError>;
|
|
249
257
|
}
|
|
250
258
|
declare const DecisionModelCompatibility_base: Schema.Class<DecisionModelCompatibility, Schema.Struct<{
|
|
251
259
|
/**
|
|
@@ -290,128 +298,16 @@ export declare namespace DecisionModel {
|
|
|
290
298
|
}
|
|
291
299
|
export declare const DecisionModelSchema: Schema.declare<DecisionModel<DecisionOptions>, DecisionModel<DecisionOptions>>;
|
|
292
300
|
export type DecisionModelOptions<Model> = Model extends DecisionModel<infer Options> ? Options : never;
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
readonly input:
|
|
296
|
-
readonly type: Schema.Literal<"text">;
|
|
297
|
-
readonly text: Schema.String;
|
|
298
|
-
}>, Schema.Struct<{
|
|
299
|
-
readonly type: Schema.Literal<"json">;
|
|
300
|
-
readonly value: Schema.Codec<Schema.Json, Schema.Json, never, never>;
|
|
301
|
-
}>, Schema.Struct<{
|
|
302
|
-
readonly type: Schema.Literal<"media">;
|
|
303
|
-
readonly media: Schema.decodeTo<Schema.declare<Media.Asset, Media.Asset>, Schema.Struct<{
|
|
304
|
-
readonly source: Schema.Union<readonly [Schema.Struct<{
|
|
305
|
-
readonly type: Schema.Literal<"bytes">;
|
|
306
|
-
readonly data: Schema.Uint8Array;
|
|
307
|
-
readonly mediaType: Schema.String;
|
|
308
|
-
}>, Schema.Struct<{
|
|
309
|
-
readonly type: Schema.Literal<"base64">;
|
|
310
|
-
readonly data: Schema.String;
|
|
311
|
-
readonly mediaType: Schema.String;
|
|
312
|
-
}>, Schema.Struct<{
|
|
313
|
-
readonly type: Schema.Literal<"url">;
|
|
314
|
-
readonly url: Schema.String;
|
|
315
|
-
readonly mediaType: Schema.optional<Schema.String>;
|
|
316
|
-
readonly expiresAt: Schema.optional<Schema.Number>;
|
|
317
|
-
}>, Schema.Struct<{
|
|
318
|
-
readonly type: Schema.Literal<"ref">;
|
|
319
|
-
readonly provider: Schema.brand<Schema.String, "AI.ProviderID">;
|
|
320
|
-
readonly id: Schema.String;
|
|
321
|
-
readonly mediaType: Schema.optional<Schema.String>;
|
|
322
|
-
}>]>;
|
|
323
|
-
readonly info: Schema.optional<Schema.Struct<{
|
|
324
|
-
readonly width: Schema.optional<Schema.Number>;
|
|
325
|
-
readonly height: Schema.optional<Schema.Number>;
|
|
326
|
-
readonly durationSeconds: Schema.optional<Schema.Number>;
|
|
327
|
-
readonly sampleRate: Schema.optional<Schema.Number>;
|
|
328
|
-
readonly channels: Schema.optional<Schema.Number>;
|
|
329
|
-
readonly encoding: Schema.optional<Schema.String>;
|
|
330
|
-
readonly format: Schema.optional<Schema.String>;
|
|
331
|
-
}>>;
|
|
332
|
-
readonly providerMetadata: Schema.optional<Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>>;
|
|
333
|
-
}>, never, never>;
|
|
334
|
-
readonly filename: Schema.optional<Schema.String>;
|
|
335
|
-
}>]>>;
|
|
336
|
-
readonly questions: Schema.refine<readonly ({
|
|
337
|
-
readonly name: string;
|
|
338
|
-
readonly type: "predicate";
|
|
339
|
-
readonly instructions: string;
|
|
340
|
-
} | {
|
|
341
|
-
readonly name: string;
|
|
342
|
-
readonly type: "choice";
|
|
343
|
-
readonly instructions: string;
|
|
344
|
-
readonly choices: readonly {
|
|
345
|
-
readonly value: string | boolean;
|
|
346
|
-
readonly description?: string | undefined;
|
|
347
|
-
}[];
|
|
348
|
-
} | {
|
|
349
|
-
readonly name: string;
|
|
350
|
-
readonly type: "score";
|
|
351
|
-
readonly instructions: string;
|
|
352
|
-
readonly levels: readonly {
|
|
353
|
-
readonly label: string;
|
|
354
|
-
readonly description?: string | undefined;
|
|
355
|
-
}[];
|
|
356
|
-
})[], Schema.refine<readonly ({
|
|
357
|
-
readonly name: string;
|
|
358
|
-
readonly type: "predicate";
|
|
359
|
-
readonly instructions: string;
|
|
360
|
-
} | {
|
|
361
|
-
readonly name: string;
|
|
362
|
-
readonly type: "choice";
|
|
363
|
-
readonly instructions: string;
|
|
364
|
-
readonly choices: readonly {
|
|
365
|
-
readonly value: string | boolean;
|
|
366
|
-
readonly description?: string | undefined;
|
|
367
|
-
}[];
|
|
368
|
-
} | {
|
|
369
|
-
readonly name: string;
|
|
370
|
-
readonly type: "score";
|
|
371
|
-
readonly instructions: string;
|
|
372
|
-
readonly levels: readonly {
|
|
373
|
-
readonly label: string;
|
|
374
|
-
readonly description?: string | undefined;
|
|
375
|
-
}[];
|
|
376
|
-
})[], Schema.$Array<Schema.toTaggedUnion<"type", readonly [Schema.Struct<{
|
|
377
|
-
readonly name: Schema.String;
|
|
378
|
-
readonly type: Schema.Literal<"predicate">;
|
|
379
|
-
readonly instructions: Schema.String;
|
|
380
|
-
}>, Schema.Struct<{
|
|
381
|
-
readonly name: Schema.String;
|
|
382
|
-
readonly type: Schema.Literal<"choice">;
|
|
383
|
-
readonly instructions: Schema.String;
|
|
384
|
-
readonly choices: Schema.$Array<Schema.Struct<{
|
|
385
|
-
readonly value: Schema.Union<readonly [Schema.String, Schema.Boolean]>;
|
|
386
|
-
readonly description: Schema.optional<Schema.String>;
|
|
387
|
-
}>>;
|
|
388
|
-
}>, Schema.Struct<{
|
|
389
|
-
readonly name: Schema.String;
|
|
390
|
-
readonly type: Schema.Literal<"score">;
|
|
391
|
-
readonly instructions: Schema.String;
|
|
392
|
-
readonly levels: Schema.$Array<Schema.Struct<{
|
|
393
|
-
readonly label: Schema.String;
|
|
394
|
-
readonly description: Schema.optional<Schema.String>;
|
|
395
|
-
}>>;
|
|
396
|
-
}>]>>>>;
|
|
397
|
-
readonly providerOptions: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
398
|
-
readonly http: Schema.optional<typeof HttpOptions>;
|
|
399
|
-
}>, {}>;
|
|
400
|
-
export declare class DecisionRequest extends DecisionRequest_base {
|
|
401
|
-
protected readonly _DecisionRequest: void;
|
|
402
|
-
}
|
|
403
|
-
export type DecisionRequestFor<Options extends DecisionOptions = DecisionOptions, Questions extends DecisionQuestions = DecisionQuestions> = Omit<DecisionRequest, "model" | "questions" | "providerOptions"> & {
|
|
404
|
-
readonly model: DecisionModel<Options>;
|
|
301
|
+
/** A normalized decision request, the plain object `ai.decision.request(...)` returns. */
|
|
302
|
+
export interface DecisionRequest<Model extends DecisionModel = DecisionModel, Questions extends DecisionQuestions = DecisionQuestions> extends BaseRequest<Model, DecisionModelOptions<Model>> {
|
|
303
|
+
readonly input: ReadonlyArray<DecisionPart>;
|
|
405
304
|
readonly questions: Questions;
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
export
|
|
409
|
-
readonly model: Model;
|
|
305
|
+
}
|
|
306
|
+
/** Input accepted by `ai.decision.request` and `generate`. A `DecisionRequest` is also a valid input. */
|
|
307
|
+
export interface DecisionRequestInput<Model extends DecisionModel = DecisionModel, Questions extends DecisionQuestions = DecisionQuestions> extends BaseRequest<Model, NoInfer<DecisionModelOptions<Model>>> {
|
|
410
308
|
readonly input: DecisionInput;
|
|
411
309
|
readonly questions: Questions;
|
|
412
|
-
|
|
413
|
-
readonly http?: HttpOptions.Input;
|
|
414
|
-
};
|
|
310
|
+
}
|
|
415
311
|
declare const DecisionUsage_base: Schema.Class<DecisionUsage, Schema.Struct<{
|
|
416
312
|
readonly inputTokens: Schema.optional<Schema.Number>;
|
|
417
313
|
readonly outputTokens: Schema.optional<Schema.Number>;
|
|
@@ -460,9 +356,8 @@ export declare class DecisionResponse extends DecisionResponse_base {
|
|
|
460
356
|
export type DecisionResponseFor<Questions extends DecisionQuestions> = Omit<DecisionResponse, "answers"> & {
|
|
461
357
|
readonly answers: AnswersFor<Questions>;
|
|
462
358
|
};
|
|
463
|
-
|
|
464
|
-
export declare
|
|
465
|
-
export declare function request(input: DecisionRequest | DecisionRequestInput): DecisionRequest;
|
|
359
|
+
/** Normalize decision request input into a plain `DecisionRequest`; a plain object `input` becomes one `json` part. */
|
|
360
|
+
export declare const request: <const Model extends DecisionModel, const Questions extends DecisionQuestions>(input: DecisionRequestInput<Model, Questions>) => DecisionRequest<Model, Questions>;
|
|
466
361
|
export declare function generate<const Model extends DecisionModel, const Questions extends DecisionQuestions>(input: DecisionRequestInput<Model, Questions>): Effect.Effect<DecisionResponseFor<Questions>, AIError, Service>;
|
|
467
362
|
export declare const Decision: {
|
|
468
363
|
readonly request: typeof request;
|
package/dist/decision.js
CHANGED
|
@@ -2,7 +2,7 @@ import { Effect, Schema } from "effect";
|
|
|
2
2
|
import { DecisionClient, Service } from "./decision-client.js";
|
|
3
3
|
import { Media } from "./media.js";
|
|
4
4
|
import { tryRequest } from "./media-model.js";
|
|
5
|
-
import { AIError,
|
|
5
|
+
import { AIError, ModelID, ProviderID, ProviderMetadata, ProviderOptions, } from "./schema/index.js";
|
|
6
6
|
// ---------------------------------------------------------------------------
|
|
7
7
|
// Input
|
|
8
8
|
// ---------------------------------------------------------------------------
|
|
@@ -117,14 +117,12 @@ export const DecisionModelSchema = Schema.declare((value) => value instanceof De
|
|
|
117
117
|
// ---------------------------------------------------------------------------
|
|
118
118
|
// Request and response
|
|
119
119
|
// ---------------------------------------------------------------------------
|
|
120
|
-
|
|
120
|
+
const DecisionRequestSchema = Schema.Struct({
|
|
121
121
|
model: DecisionModelSchema,
|
|
122
122
|
input: Schema.Array(DecisionPart),
|
|
123
123
|
questions: DecisionQuestionList,
|
|
124
124
|
providerOptions: Schema.optional(ProviderOptions),
|
|
125
|
-
|
|
126
|
-
}) {
|
|
127
|
-
}
|
|
125
|
+
});
|
|
128
126
|
/** What decision hosts report; their raw usage stays in the response's `providerMetadata`. */
|
|
129
127
|
export class DecisionUsage extends Schema.Class("Decision.Usage")({
|
|
130
128
|
inputTokens: Schema.optional(Schema.Number),
|
|
@@ -140,17 +138,29 @@ export class DecisionResponse extends Schema.Class("Decision.Response")({
|
|
|
140
138
|
providerMetadata: Schema.optional(ProviderMetadata),
|
|
141
139
|
}) {
|
|
142
140
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
141
|
+
// ---------------------------------------------------------------------------
|
|
142
|
+
// Call API
|
|
143
|
+
// ---------------------------------------------------------------------------
|
|
144
|
+
/** Normalize decision request input into a plain `DecisionRequest`; a plain object `input` becomes one `json` part. */
|
|
145
|
+
export const request = (input) => ({
|
|
146
|
+
...input,
|
|
147
|
+
input: isParts(input.input) ? input.input.map(decisionPart) : [{ type: "json", value: input.input }],
|
|
148
|
+
});
|
|
149
|
+
const validate = Schema.decodeUnknownSync(DecisionRequestSchema);
|
|
150
|
+
// `Array.isArray` doesn't narrow a readonly array union, so the object branch would keep the parts type.
|
|
151
|
+
const isParts = (input) => Array.isArray(input);
|
|
152
|
+
const decisionPart = (part) => {
|
|
153
|
+
if (part.type !== "media")
|
|
154
|
+
return part;
|
|
155
|
+
const { mediaType, ...rest } = part;
|
|
156
|
+
return { ...rest, media: Media.make(part.media, mediaType) };
|
|
157
|
+
};
|
|
152
158
|
export function generate(input) {
|
|
153
|
-
return tryRequest(() =>
|
|
159
|
+
return tryRequest(() => {
|
|
160
|
+
const normalized = request(input);
|
|
161
|
+
validate(normalized);
|
|
162
|
+
return normalized;
|
|
163
|
+
}).pipe(Effect.flatMap(DecisionClient.generate));
|
|
154
164
|
}
|
|
155
165
|
export const Decision = {
|
|
156
166
|
request,
|
package/dist/effect.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare const ai: {
|
|
|
5
5
|
readonly generate: typeof LLM.generate;
|
|
6
6
|
readonly stream: typeof LLM.stream;
|
|
7
7
|
readonly loop: typeof LLM.loop;
|
|
8
|
-
readonly
|
|
8
|
+
readonly collect: typeof LLM.collect;
|
|
9
9
|
readonly compact: typeof LLM.compact;
|
|
10
10
|
readonly canCompact: typeof LLM.canCompact;
|
|
11
11
|
readonly image: {
|
|
@@ -47,22 +47,11 @@ export { LLMClient } from "./route/client.js";
|
|
|
47
47
|
export { ImageClient } from "./image-client.js";
|
|
48
48
|
export { Auth } from "./route/auth.js";
|
|
49
49
|
export { ProviderPackage } from "./provider-package.js";
|
|
50
|
-
export {
|
|
51
|
-
export type { Interface as LLMClientShape, LLMClientService } from "./route/client.js";
|
|
52
|
-
export { ProtocolID, RouteID, ModelID, ProviderID, ResponseID, ContentBlockID, ToolCallID, JsonSchema, ProviderOptions, ProviderMetadata, HttpTimeout, RequestEncoding, HttpOptions, GenerationOptions, LanguageModelDefaults, ReasoningEfforts, ReasoningEffort, LanguageModelCompatibility, LanguageModel, LanguageModelSchema, CacheTTL, CacheHint, CachePolicyObject, CachePolicy, MessageRole, SystemPart, TextPart, MediaPart, ToolResultValue, ToolOutput, ToolCallPart, ToolResultPart, ReasoningPart, CompactionPart, EffortPart, ContentPart, Message, Freeform, ToolDefinition, ToolNamespace, ToolEntry, ToolChoice, LLMRequest, FinishReason, Usage, MediaUsage, CompactionResponse, CompactionCheckpointResponse, StepStart, TextStart, TextDelta, TextEnd, ReasoningStart, ReasoningDelta, ReasoningEnd, ToolInputStart, ToolInputDelta, ToolInputEnd, ToolInputError, ToolCall, ToolResult, ToolError, FinishReasonDetails, StepFinish, Finish, MediaEvent, ProviderErrorEvent, LLMEvent, LLMResponse, HttpContext, HttpRateLimitDetails, InvalidRequestError, UnsupportedOperationError, ProviderConfigurationError, NoRouteError, AuthenticationError, RateLimitError, QuotaExceededError, ContentPolicyError, ProviderInternalError, TransportType, TransportOperation, TransportError, InvalidProviderOutputError, UnknownProviderError, TimeoutError, AIErrorReason, AIError, } from "./schema/index.js";
|
|
53
|
-
export type { GenerationOptionsFields, GenerationOptionsInput, LanguageModelInput, LanguageModelProviderOptions, ToolDefinitionInput, ToolNamespaceInput, ToolNamespaceEntryInput, ToolEntryInput, UsageInput, } from "./schema/index.js";
|
|
54
|
-
export { ImageAspectRatio, ImageEvent, ImageModel, ImageModelSchema, ImageRequest, ImageResponse } from "./image.js";
|
|
55
|
-
export type { ImageModelOptions, ImageOptions, ImageRequestFor, ImageRequestInput, ImageResolution, ImageRoute, } from "./image.js";
|
|
50
|
+
export type { LLMClientService } from "./route/client.js";
|
|
56
51
|
export { DecisionClient } from "./decision-client.js";
|
|
57
|
-
export { ChoiceAnswer, ChoiceQuestion, ChoiceValue, DecisionAnswer, DecisionJsonPart, DecisionMediaPart, DecisionModel, DecisionModelCompatibility, DecisionModelSchema, DecisionPart, DecisionQuestion, DecisionRequest, DecisionResponse, DecisionTextPart, DecisionUsage, ErrorAnswer, ErrorReason, PredicateAnswer, PredicateQuestion, ScoreAnswer, ScoreQuestion, } from "./decision.js";
|
|
58
|
-
export type { AnswerFor, AnswersFor, DecisionInput, DecisionModelOptions, DecisionOptions, DecisionQuestions, DecisionRequestFor, DecisionRequestInput, DecisionResponseFor, DecisionModelRoute, } from "./decision.js";
|
|
59
52
|
export { DecisionRoute } from "./route/decision.js";
|
|
60
|
-
export { Media } from "./media.js";
|
|
61
53
|
export { Generation } from "./generation.js";
|
|
62
|
-
export type { AwaitOptions as GenerationAwaitOptions, Event as GenerationEvent, Poll, Route as GenerationRoute, Snapshot as GenerationSnapshot, Status as GenerationStatus, } from "./generation.js";
|
|
63
54
|
export { ToolFailure, emptyInputJsonSchema, toDefinitions, tool } from "./tool.js";
|
|
64
55
|
export { ToolRuntime } from "./tool-runtime.js";
|
|
65
|
-
export type {
|
|
66
|
-
export
|
|
67
|
-
export type { LLM } from "./llm.js";
|
|
68
|
-
export type { Definition as ProviderPackageDefinition, Settings as ProviderPackageSettings, } from "./provider-package.js";
|
|
56
|
+
export type { ToolSettlement } from "./tool-runtime.js";
|
|
57
|
+
export * from "./public.js";
|
package/dist/effect.js
CHANGED
|
@@ -10,7 +10,7 @@ export const ai = {
|
|
|
10
10
|
generate: LLM.generate,
|
|
11
11
|
stream: LLM.stream,
|
|
12
12
|
loop: LLM.loop,
|
|
13
|
-
|
|
13
|
+
collect: LLM.collect,
|
|
14
14
|
compact: LLM.compact,
|
|
15
15
|
canCompact: LLM.canCompact,
|
|
16
16
|
image: Image,
|
|
@@ -27,13 +27,9 @@ export { LLMClient } from "./route/client.js";
|
|
|
27
27
|
export { ImageClient } from "./image-client.js";
|
|
28
28
|
export { Auth } from "./route/auth.js";
|
|
29
29
|
export { ProviderPackage } from "./provider-package.js";
|
|
30
|
-
export { isContextOverflow, isContextOverflowFailure, isRetryable } from "./provider-error.js";
|
|
31
|
-
export { ProtocolID, RouteID, ModelID, ProviderID, ResponseID, ContentBlockID, ToolCallID, JsonSchema, ProviderOptions, ProviderMetadata, HttpTimeout, RequestEncoding, HttpOptions, GenerationOptions, LanguageModelDefaults, ReasoningEfforts, ReasoningEffort, LanguageModelCompatibility, LanguageModel, LanguageModelSchema, CacheTTL, CacheHint, CachePolicyObject, CachePolicy, MessageRole, SystemPart, TextPart, MediaPart, ToolResultValue, ToolOutput, ToolCallPart, ToolResultPart, ReasoningPart, CompactionPart, EffortPart, ContentPart, Message, Freeform, ToolDefinition, ToolNamespace, ToolEntry, ToolChoice, LLMRequest, FinishReason, Usage, MediaUsage, CompactionResponse, CompactionCheckpointResponse, StepStart, TextStart, TextDelta, TextEnd, ReasoningStart, ReasoningDelta, ReasoningEnd, ToolInputStart, ToolInputDelta, ToolInputEnd, ToolInputError, ToolCall, ToolResult, ToolError, FinishReasonDetails, StepFinish, Finish, MediaEvent, ProviderErrorEvent, LLMEvent, LLMResponse, HttpContext, HttpRateLimitDetails, InvalidRequestError, UnsupportedOperationError, ProviderConfigurationError, NoRouteError, AuthenticationError, RateLimitError, QuotaExceededError, ContentPolicyError, ProviderInternalError, TransportType, TransportOperation, TransportError, InvalidProviderOutputError, UnknownProviderError, TimeoutError, AIErrorReason, AIError, } from "./schema/index.js";
|
|
32
|
-
export { ImageAspectRatio, ImageEvent, ImageModel, ImageModelSchema, ImageRequest, ImageResponse } from "./image.js";
|
|
33
30
|
export { DecisionClient } from "./decision-client.js";
|
|
34
|
-
export { ChoiceAnswer, ChoiceQuestion, ChoiceValue, DecisionAnswer, DecisionJsonPart, DecisionMediaPart, DecisionModel, DecisionModelCompatibility, DecisionModelSchema, DecisionPart, DecisionQuestion, DecisionRequest, DecisionResponse, DecisionTextPart, DecisionUsage, ErrorAnswer, ErrorReason, PredicateAnswer, PredicateQuestion, ScoreAnswer, ScoreQuestion, } from "./decision.js";
|
|
35
31
|
export { DecisionRoute } from "./route/decision.js";
|
|
36
|
-
export { Media } from "./media.js";
|
|
37
32
|
export { Generation } from "./generation.js";
|
|
38
33
|
export { ToolFailure, emptyInputJsonSchema, toDefinitions, tool } from "./tool.js";
|
|
39
34
|
export { ToolRuntime } from "./tool-runtime.js";
|
|
35
|
+
export * from "./public.js";
|
package/dist/effort-updates.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { LLMRequest, type EffortPart, type Message } from "./schema/messages.js";
|
|
1
|
+
import { type LLMRequest, type EffortPart, type Message } from "./schema/messages.js";
|
|
2
2
|
export declare const effortUpdate: (message: Message) => EffortPart | undefined;
|
|
3
|
-
export declare const stripEffortUpdates: (request: LLMRequest) => LLMRequest<import("./
|
|
3
|
+
export declare const stripEffortUpdates: (request: LLMRequest) => LLMRequest<import("./public.js").LanguageModel<{
|
|
4
4
|
readonly [x: string]: unknown;
|
|
5
5
|
}, import("./route.js").CompactionOperations | undefined>>;
|
|
6
6
|
export declare const applyEffortUpdates: (request: LLMRequest) => LLMRequest;
|
|
7
7
|
export declare const resolveEffortUpdates: (request: LLMRequest, current: string | undefined) => {
|
|
8
|
-
request: LLMRequest<import("./
|
|
8
|
+
request: LLMRequest<import("./public.js").LanguageModel<{
|
|
9
9
|
readonly [x: string]: unknown;
|
|
10
10
|
}, import("./route.js").CompactionOperations | undefined>>;
|
|
11
11
|
effort: string | undefined;
|
package/dist/effort-updates.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Changing the top-level reasoning effort invalidates the provider prompt cache. Protocols with a native
|
|
2
2
|
// per-message update keep it frozen and lower `Message.effort(...)` markers instead; other routes strip them.
|
|
3
|
-
import {
|
|
3
|
+
import {} from "./schema/messages.js";
|
|
4
4
|
export const effortUpdate = (message) => {
|
|
5
5
|
if (message.role !== "system" || message.content.length !== 1)
|
|
6
6
|
return undefined;
|
|
@@ -9,7 +9,7 @@ export const effortUpdate = (message) => {
|
|
|
9
9
|
};
|
|
10
10
|
export const stripEffortUpdates = (request) => {
|
|
11
11
|
const messages = request.messages.filter((message) => effortUpdate(message) === undefined);
|
|
12
|
-
return messages.length === request.messages.length ? request :
|
|
12
|
+
return messages.length === request.messages.length ? request : { ...request, messages };
|
|
13
13
|
};
|
|
14
14
|
export const applyEffortUpdates = (request) => request.model.route.supportsEffortUpdates?.(request) ? request : stripEffortUpdates(request);
|
|
15
15
|
// Reverted or forked history can leave the last marker disagreeing with the requested effort.
|
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import { ExtractionModel, ExtractionResponse, type
|
|
1
|
+
import { ExtractionModel, ExtractionResponse, type ExtractionRequest } from "./extraction.js";
|
|
2
2
|
import { MediaProtocol } from "../route/media-protocol.js";
|
|
3
3
|
import { MediaRoute } from "../route/media.js";
|
|
4
4
|
/** Posts Clairic's `{ model, state, fields }` body to Cloudflare's `/ai/run/{model}`. */
|
|
5
|
-
export declare const protocol: MediaProtocol.Inline<
|
|
5
|
+
export declare const protocol: MediaProtocol.Inline<ExtractionRequest<ExtractionModel<{
|
|
6
|
+
readonly [x: string]: unknown;
|
|
7
|
+
}>, Readonly<Record<string, import("./extraction.js").ExtractionField>>>, ExtractionResponse>;
|
|
6
8
|
/** `baseURL` is the Run API base, `.../client/v4/accounts/{account}/ai/run`. */
|
|
7
9
|
export declare const model: (input: MediaRoute.ModelInput) => ExtractionModel<{
|
|
8
10
|
readonly [x: string]: unknown;
|
|
9
11
|
}>;
|
|
10
12
|
export declare const CloudflareRunExtraction: {
|
|
11
|
-
readonly protocol: MediaProtocol.Inline<
|
|
13
|
+
readonly protocol: MediaProtocol.Inline<ExtractionRequest<ExtractionModel<{
|
|
14
|
+
readonly [x: string]: unknown;
|
|
15
|
+
}>, Readonly<Record<string, import("./extraction.js").ExtractionField>>>, ExtractionResponse>;
|
|
12
16
|
readonly model: typeof model;
|
|
13
17
|
};
|
|
@@ -16,7 +16,10 @@ const decodeEnvelope = route.decodeJson(Schema.Struct({
|
|
|
16
16
|
answers: Schema.Record(Schema.String, JsonObject),
|
|
17
17
|
truncated: Schema.optional(Schema.Boolean),
|
|
18
18
|
state_text: Schema.optional(Schema.String),
|
|
19
|
-
usage: Schema.optional(Schema.StructWithRest(Schema.Struct({
|
|
19
|
+
usage: Schema.optional(Schema.StructWithRest(Schema.Struct({
|
|
20
|
+
input_tokens: Schema.optional(Schema.Number),
|
|
21
|
+
output_tokens: Schema.optional(Schema.Number),
|
|
22
|
+
}), [JsonObject])),
|
|
20
23
|
}),
|
|
21
24
|
}));
|
|
22
25
|
/** Posts Clairic's `{ model, state, fields }` body to Cloudflare's `/ai/run/{model}`. */
|
|
@@ -2,7 +2,7 @@ import { Effect, Schema } from "effect";
|
|
|
2
2
|
import { MediaModel } from "../media-model.js";
|
|
3
3
|
import { RequestExecutor } from "../route/executor.js";
|
|
4
4
|
import type { MediaRoute } from "../route/media.js";
|
|
5
|
-
import { AIError,
|
|
5
|
+
import { AIError, Usage, type BaseRequest, type OpenString } from "../schema/index.js";
|
|
6
6
|
/**
|
|
7
7
|
* The answer schema for each field type Clairic documents, decoding its wire keys (`p_null` and friends). Answers to
|
|
8
8
|
* other field types pass through as sent.
|
|
@@ -116,50 +116,22 @@ export type ExtractionField = typeof ExtractionFieldSchema.Type & {
|
|
|
116
116
|
};
|
|
117
117
|
export type ExtractionFields = Readonly<Record<string, ExtractionField>>;
|
|
118
118
|
export type ExtractionOptions = MediaModel.Options;
|
|
119
|
-
export type ExtractionRoute = MediaRoute.InlineRoute<
|
|
119
|
+
export type ExtractionRoute = MediaRoute.InlineRoute<ExtractionRequest, ExtractionResponse>;
|
|
120
120
|
export declare class ExtractionModel<Options extends ExtractionOptions = ExtractionOptions> extends MediaModel<ExtractionRoute, Options> {
|
|
121
121
|
protected readonly _ExtractionModel: void;
|
|
122
122
|
}
|
|
123
123
|
export type ExtractionModelOptions<Model> = Model extends ExtractionModel<infer Options> ? Options : never;
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
readonly [x: string]: unknown;
|
|
127
|
-
}>, unknown>;
|
|
124
|
+
/** A normalized extraction request, the plain object `Extraction.request(...)` returns. */
|
|
125
|
+
export interface ExtractionRequest<Model extends ExtractionModel = ExtractionModel, Fields extends ExtractionFields = ExtractionFields> extends BaseRequest<Model, ExtractionModelOptions<Model>> {
|
|
128
126
|
/** The text to read; text answers carry spans into it. */
|
|
129
|
-
readonly input: Schema.String;
|
|
130
|
-
readonly fields: Schema.refine<{
|
|
131
|
-
readonly [x: string]: {
|
|
132
|
-
readonly [x: string]: unknown;
|
|
133
|
-
readonly type: string;
|
|
134
|
-
readonly instructions?: string | undefined;
|
|
135
|
-
readonly nullThreshold?: number | undefined;
|
|
136
|
-
};
|
|
137
|
-
}, Schema.$Record<Schema.String, Schema.StructWithRest<Schema.Struct<{
|
|
138
|
-
readonly type: Schema.String;
|
|
139
|
-
readonly instructions: Schema.optional<Schema.String>;
|
|
140
|
-
/** Probability of null above which the value is null; the host's default is 0.5. */
|
|
141
|
-
readonly nullThreshold: Schema.optional<Schema.Number>;
|
|
142
|
-
}>, readonly [Schema.$Record<Schema.String, Schema.Unknown>]>>>;
|
|
143
|
-
/** ISO date that anchors dates written without a year. */
|
|
144
|
-
readonly referenceDate: Schema.optional<Schema.String>;
|
|
145
|
-
readonly providerOptions: Schema.optional<Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
146
|
-
readonly http: Schema.optional<typeof HttpOptions>;
|
|
147
|
-
}>, {}>;
|
|
148
|
-
export declare class ExtractionRequest extends ExtractionRequest_base {
|
|
149
|
-
protected readonly _ExtractionRequest: void;
|
|
150
|
-
}
|
|
151
|
-
export type ExtractionRequestFor<Options extends ExtractionOptions = ExtractionOptions, Fields extends ExtractionFields = ExtractionFields> = Omit<ExtractionRequest, "model" | "fields" | "providerOptions"> & {
|
|
152
|
-
readonly model: ExtractionModel<Options>;
|
|
153
|
-
readonly fields: Fields;
|
|
154
|
-
readonly providerOptions?: Options;
|
|
155
|
-
};
|
|
156
|
-
export type ExtractionRequestInput<Model extends ExtractionModel = ExtractionModel, Fields extends ExtractionFields = ExtractionFields> = {
|
|
157
|
-
readonly model: Model;
|
|
158
127
|
readonly input: string;
|
|
159
128
|
readonly fields: Fields;
|
|
129
|
+
/** ISO date that anchors dates written without a year. */
|
|
160
130
|
readonly referenceDate?: string;
|
|
131
|
+
}
|
|
132
|
+
/** Input accepted by `Extraction.request` and `generate`; an `ExtractionRequest` is also a valid input. */
|
|
133
|
+
export type ExtractionRequestInput<Model extends ExtractionModel = ExtractionModel, Fields extends ExtractionFields = ExtractionFields> = Omit<ExtractionRequest<Model, Fields>, "providerOptions"> & {
|
|
161
134
|
readonly providerOptions?: NoInfer<ExtractionModelOptions<Model>>;
|
|
162
|
-
readonly http?: HttpOptions.Input;
|
|
163
135
|
};
|
|
164
136
|
declare const ExtractionResponse_base: Schema.Class<ExtractionResponse, Schema.Struct<{
|
|
165
137
|
readonly answers: Schema.$Record<Schema.String, Schema.$Record<Schema.String, Schema.Unknown>>;
|
|
@@ -171,11 +143,9 @@ export declare class ExtractionResponse extends ExtractionResponse_base {
|
|
|
171
143
|
export type ExtractionResponseFor<Fields extends ExtractionFields> = Omit<ExtractionResponse, "answers"> & {
|
|
172
144
|
readonly answers: ExtractionAnswersFor<Fields>;
|
|
173
145
|
};
|
|
174
|
-
|
|
175
|
-
export declare
|
|
176
|
-
export declare function request(input: ExtractionRequest | ExtractionRequestInput): ExtractionRequest;
|
|
146
|
+
/** Normalize extraction request input into a plain `ExtractionRequest`. */
|
|
147
|
+
export declare const request: <const Model extends ExtractionModel, const Fields extends ExtractionFields>(input: ExtractionRequestInput<Model, Fields>) => ExtractionRequest<Model, Fields>;
|
|
177
148
|
export declare function generate<const Model extends ExtractionModel, const Fields extends ExtractionFields>(input: ExtractionRequestInput<Model, Fields>): Effect.Effect<ExtractionResponseFor<Fields>, AIError, RequestExecutor.Service>;
|
|
178
|
-
export declare function generate(input: ExtractionRequest): Effect.Effect<ExtractionResponse, AIError, RequestExecutor.Service>;
|
|
179
149
|
export declare const Extraction: {
|
|
180
150
|
readonly request: typeof request;
|
|
181
151
|
readonly generate: typeof generate;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Effect, Schema } from "effect";
|
|
2
2
|
import { MediaModel, tryRequest } from "../media-model.js";
|
|
3
3
|
import { RequestExecutor } from "../route/executor.js";
|
|
4
|
-
import { AIError,
|
|
4
|
+
import { AIError, ProviderMetadata, ProviderOptions, Usage, } from "../schema/index.js";
|
|
5
5
|
// ---------------------------------------------------------------------------
|
|
6
6
|
// Answers
|
|
7
7
|
// ---------------------------------------------------------------------------
|
|
@@ -65,34 +65,35 @@ export class ExtractionModel extends MediaModel {
|
|
|
65
65
|
// ---------------------------------------------------------------------------
|
|
66
66
|
// Request and response
|
|
67
67
|
// ---------------------------------------------------------------------------
|
|
68
|
-
|
|
68
|
+
const ExtractionRequestSchema = Schema.Struct({
|
|
69
69
|
model: Schema.declare((value) => value instanceof ExtractionModel, {
|
|
70
70
|
expected: "Extraction.Model",
|
|
71
71
|
}),
|
|
72
|
-
/** The text to read; text answers carry spans into it. */
|
|
73
72
|
input: Schema.String,
|
|
74
73
|
fields: Schema.Record(Schema.String, ExtractionFieldSchema).pipe(Schema.refine((x) => Object.keys(x).length > 0, { message: "Extraction fields must not be empty" })),
|
|
75
|
-
/** ISO date that anchors dates written without a year. */
|
|
76
74
|
referenceDate: Schema.optional(Schema.String),
|
|
77
75
|
providerOptions: Schema.optional(ProviderOptions),
|
|
78
|
-
|
|
79
|
-
}) {
|
|
80
|
-
}
|
|
76
|
+
});
|
|
81
77
|
export class ExtractionResponse extends Schema.Class("Extraction.Response")({
|
|
82
78
|
answers: Schema.Record(Schema.String, Schema.Record(Schema.String, Schema.Unknown)),
|
|
83
79
|
usage: Schema.optional(Usage),
|
|
84
80
|
providerMetadata: Schema.optional(ProviderMetadata),
|
|
85
81
|
}) {
|
|
86
82
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
83
|
+
// ---------------------------------------------------------------------------
|
|
84
|
+
// Call API
|
|
85
|
+
// ---------------------------------------------------------------------------
|
|
86
|
+
/** Normalize extraction request input into a plain `ExtractionRequest`. */
|
|
87
|
+
export const request = (input) => ({ ...input });
|
|
88
|
+
const validate = Schema.decodeUnknownSync(ExtractionRequestSchema);
|
|
92
89
|
export function generate(input) {
|
|
93
90
|
return Effect.gen(function* () {
|
|
94
91
|
const executor = yield* RequestExecutor.Service;
|
|
95
|
-
const built = yield* tryRequest(() =>
|
|
92
|
+
const built = yield* tryRequest(() => {
|
|
93
|
+
const normalized = request(input);
|
|
94
|
+
validate(normalized);
|
|
95
|
+
return normalized;
|
|
96
|
+
});
|
|
96
97
|
return yield* built.model.route.generate(built, executor.execute);
|
|
97
98
|
});
|
|
98
99
|
}
|
package/dist/experimental.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
export { VideoClient } from "./video-client.js";
|
|
2
|
-
export { VideoAspectRatio, VideoEvent, VideoFrames, VideoModel, VideoModelSchema,
|
|
3
|
-
export type { VideoModelOptions, VideoOptions,
|
|
2
|
+
export { VideoAspectRatio, VideoEvent, VideoFrames, VideoModel, VideoModelSchema, VideoResponse } from "./video.js";
|
|
3
|
+
export type { VideoModelOptions, VideoOptions, VideoRequest, VideoRequestInput, VideoResolution, VideoRoute, } from "./video.js";
|
|
4
4
|
export { Video } from "./video.js";
|
|
5
5
|
export { SpeechClient } from "./speech-client.js";
|
|
6
|
-
export { SpeechEvent, SpeechModel, SpeechModelSchema,
|
|
7
|
-
export type { SpeechFormat, SpeechModelOptions, SpeechOptions,
|
|
6
|
+
export { SpeechEvent, SpeechModel, SpeechModelSchema, SpeechResponse, SpeechTimestamp, SpeechVoice } from "./speech.js";
|
|
7
|
+
export type { SpeechFormat, SpeechModelOptions, SpeechOptions, SpeechRequest, SpeechRequestInput, SpeechRoute, } from "./speech.js";
|
|
8
8
|
export { Speech } from "./speech.js";
|
|
9
9
|
export { TranscriptionClient } from "./transcription-client.js";
|
|
10
|
-
export { TranscriptionEvent, TranscriptionModel, TranscriptionModelSchema,
|
|
11
|
-
export type { TranscriptionModelOptions, TranscriptionOptions,
|
|
10
|
+
export { TranscriptionEvent, TranscriptionModel, TranscriptionModelSchema, TranscriptionResponse, TranscriptionSegment, TranscriptionTimestamps, TranscriptionWord, } from "./transcription.js";
|
|
11
|
+
export type { TranscriptionModelOptions, TranscriptionOptions, TranscriptionRequest, TranscriptionRequestInput, TranscriptionRoute, } from "./transcription.js";
|
|
12
12
|
export { Transcription } from "./transcription.js";
|
|
13
|
-
export { Extraction, ExtractionModel,
|
|
14
|
-
export type { ExtractionAnswerFor, ExtractionAnswersFor, ExtractionField, ExtractionFields, ExtractionModelOptions, ExtractionOptions,
|
|
13
|
+
export { Extraction, ExtractionModel, ExtractionResponse } from "./experimental/extraction.js";
|
|
14
|
+
export type { ExtractionAnswerFor, ExtractionAnswersFor, ExtractionField, ExtractionFields, ExtractionModelOptions, ExtractionOptions, ExtractionRequest, ExtractionRequestInput, ExtractionResponseFor, ExtractionRoute, } from "./experimental/extraction.js";
|
|
15
15
|
export { Realtime } from "./experimental/realtime.js";
|
|
16
16
|
export type { RealtimeConnectInput, RealtimeSession, RealtimeTransport, RealtimeTransportInput, RealtimeTransportType, } from "./experimental/realtime.js";
|
package/dist/experimental.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export { VideoClient } from "./video-client.js";
|
|
2
|
-
export { VideoAspectRatio, VideoEvent, VideoFrames, VideoModel, VideoModelSchema,
|
|
2
|
+
export { VideoAspectRatio, VideoEvent, VideoFrames, VideoModel, VideoModelSchema, VideoResponse } from "./video.js";
|
|
3
3
|
export { Video } from "./video.js";
|
|
4
4
|
export { SpeechClient } from "./speech-client.js";
|
|
5
|
-
export { SpeechEvent, SpeechModel, SpeechModelSchema,
|
|
5
|
+
export { SpeechEvent, SpeechModel, SpeechModelSchema, SpeechResponse, SpeechTimestamp, SpeechVoice } from "./speech.js";
|
|
6
6
|
export { Speech } from "./speech.js";
|
|
7
7
|
export { TranscriptionClient } from "./transcription-client.js";
|
|
8
|
-
export { TranscriptionEvent, TranscriptionModel, TranscriptionModelSchema,
|
|
8
|
+
export { TranscriptionEvent, TranscriptionModel, TranscriptionModelSchema, TranscriptionResponse, TranscriptionSegment, TranscriptionTimestamps, TranscriptionWord, } from "./transcription.js";
|
|
9
9
|
export { Transcription } from "./transcription.js";
|
|
10
|
-
export { Extraction, ExtractionModel,
|
|
10
|
+
export { Extraction, ExtractionModel, ExtractionResponse } from "./experimental/extraction.js";
|
|
11
11
|
export { Realtime } from "./experimental/realtime.js";
|
package/dist/generation.d.ts
CHANGED
|
@@ -26,8 +26,6 @@ export interface Poll {
|
|
|
26
26
|
export interface AwaitOptions {
|
|
27
27
|
readonly poll?: Poll;
|
|
28
28
|
}
|
|
29
|
-
export declare const DEFAULT_POLL_INTERVAL: Duration.Duration;
|
|
30
|
-
export declare const DEFAULT_POLL_TIMEOUT: Duration.Duration;
|
|
31
29
|
export declare const QueuedEvent: Schema.Struct<{
|
|
32
30
|
readonly type: Schema.tag<"generation-queued">;
|
|
33
31
|
readonly id: Schema.String;
|
package/dist/generation.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Clock, Duration, Effect, Schedule, Schema, Stream } from "effect";
|
|
2
2
|
import { AIError, TimeoutError } from "./schema/errors.js";
|
|
3
3
|
export const Status = Schema.Literals(["queued", "running", "completed", "failed", "cancelled", "expired"]);
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const DEFAULT_POLL_INTERVAL = Duration.seconds(5);
|
|
5
|
+
const DEFAULT_POLL_TIMEOUT = Duration.minutes(10);
|
|
6
6
|
export const QueuedEvent = Schema.Struct({
|
|
7
7
|
type: Schema.tag("generation-queued"),
|
|
8
8
|
id: Schema.String,
|