ai 6.0.32 → 6.0.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/index.js +12 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +12 -2
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.mjs +1 -1
- package/docs/02-foundations/03-prompts.mdx +2 -2
- package/docs/03-ai-sdk-core/15-tools-and-tool-calling.mdx +1 -1
- package/docs/07-reference/01-ai-sdk-core/28-output.mdx +1 -1
- package/package.json +6 -4
- package/src/agent/agent.ts +116 -0
- package/src/agent/create-agent-ui-stream-response.test.ts +258 -0
- package/src/agent/create-agent-ui-stream-response.ts +50 -0
- package/src/agent/create-agent-ui-stream.ts +73 -0
- package/src/agent/index.ts +33 -0
- package/src/agent/infer-agent-tools.ts +7 -0
- package/src/agent/infer-agent-ui-message.test-d.ts +54 -0
- package/src/agent/infer-agent-ui-message.ts +11 -0
- package/src/agent/pipe-agent-ui-stream-to-response.ts +52 -0
- package/src/agent/tool-loop-agent-on-finish-callback.ts +31 -0
- package/src/agent/tool-loop-agent-on-step-finish-callback.ts +11 -0
- package/src/agent/tool-loop-agent-settings.ts +182 -0
- package/src/agent/tool-loop-agent.test-d.ts +114 -0
- package/src/agent/tool-loop-agent.test.ts +442 -0
- package/src/agent/tool-loop-agent.ts +114 -0
- package/src/embed/__snapshots__/embed-many.test.ts.snap +191 -0
- package/src/embed/__snapshots__/embed.test.ts.snap +81 -0
- package/src/embed/embed-many-result.ts +53 -0
- package/src/embed/embed-many.test.ts +653 -0
- package/src/embed/embed-many.ts +378 -0
- package/src/embed/embed-result.ts +50 -0
- package/src/embed/embed.test.ts +298 -0
- package/src/embed/embed.ts +211 -0
- package/src/embed/index.ts +4 -0
- package/src/error/index.ts +34 -0
- package/src/error/invalid-argument-error.ts +34 -0
- package/src/error/invalid-stream-part-error.ts +28 -0
- package/src/error/invalid-tool-approval-error.ts +26 -0
- package/src/error/invalid-tool-input-error.ts +33 -0
- package/src/error/no-image-generated-error.ts +39 -0
- package/src/error/no-object-generated-error.ts +70 -0
- package/src/error/no-output-generated-error.ts +26 -0
- package/src/error/no-speech-generated-error.ts +18 -0
- package/src/error/no-such-tool-error.ts +35 -0
- package/src/error/no-transcript-generated-error.ts +20 -0
- package/src/error/tool-call-not-found-for-approval-error.ts +32 -0
- package/src/error/tool-call-repair-error.ts +30 -0
- package/src/error/unsupported-model-version-error.ts +23 -0
- package/src/error/verify-no-object-generated-error.ts +27 -0
- package/src/generate-image/generate-image-result.ts +42 -0
- package/src/generate-image/generate-image.test.ts +1420 -0
- package/src/generate-image/generate-image.ts +360 -0
- package/src/generate-image/index.ts +18 -0
- package/src/generate-object/__snapshots__/generate-object.test.ts.snap +133 -0
- package/src/generate-object/__snapshots__/stream-object.test.ts.snap +297 -0
- package/src/generate-object/generate-object-result.ts +67 -0
- package/src/generate-object/generate-object.test-d.ts +49 -0
- package/src/generate-object/generate-object.test.ts +1191 -0
- package/src/generate-object/generate-object.ts +518 -0
- package/src/generate-object/index.ts +9 -0
- package/src/generate-object/inject-json-instruction.test.ts +181 -0
- package/src/generate-object/inject-json-instruction.ts +30 -0
- package/src/generate-object/output-strategy.ts +415 -0
- package/src/generate-object/parse-and-validate-object-result.ts +111 -0
- package/src/generate-object/repair-text.ts +12 -0
- package/src/generate-object/stream-object-result.ts +120 -0
- package/src/generate-object/stream-object.test-d.ts +74 -0
- package/src/generate-object/stream-object.test.ts +1950 -0
- package/src/generate-object/stream-object.ts +986 -0
- package/src/generate-object/validate-object-generation-input.ts +144 -0
- package/src/generate-speech/generate-speech-result.ts +30 -0
- package/src/generate-speech/generate-speech.test.ts +300 -0
- package/src/generate-speech/generate-speech.ts +190 -0
- package/src/generate-speech/generated-audio-file.ts +65 -0
- package/src/generate-speech/index.ts +3 -0
- package/src/generate-text/__snapshots__/generate-text.test.ts.snap +1872 -0
- package/src/generate-text/__snapshots__/stream-text.test.ts.snap +1255 -0
- package/src/generate-text/collect-tool-approvals.test.ts +553 -0
- package/src/generate-text/collect-tool-approvals.ts +116 -0
- package/src/generate-text/content-part.ts +25 -0
- package/src/generate-text/execute-tool-call.ts +129 -0
- package/src/generate-text/extract-reasoning-content.ts +17 -0
- package/src/generate-text/extract-text-content.ts +15 -0
- package/src/generate-text/generate-text-result.ts +168 -0
- package/src/generate-text/generate-text.test-d.ts +68 -0
- package/src/generate-text/generate-text.test.ts +7011 -0
- package/src/generate-text/generate-text.ts +1223 -0
- package/src/generate-text/generated-file.ts +70 -0
- package/src/generate-text/index.ts +57 -0
- package/src/generate-text/is-approval-needed.ts +29 -0
- package/src/generate-text/output-utils.ts +23 -0
- package/src/generate-text/output.test.ts +698 -0
- package/src/generate-text/output.ts +590 -0
- package/src/generate-text/parse-tool-call.test.ts +570 -0
- package/src/generate-text/parse-tool-call.ts +188 -0
- package/src/generate-text/prepare-step.ts +103 -0
- package/src/generate-text/prune-messages.test.ts +720 -0
- package/src/generate-text/prune-messages.ts +167 -0
- package/src/generate-text/reasoning-output.ts +20 -0
- package/src/generate-text/reasoning.ts +8 -0
- package/src/generate-text/response-message.ts +10 -0
- package/src/generate-text/run-tools-transformation.test.ts +1143 -0
- package/src/generate-text/run-tools-transformation.ts +420 -0
- package/src/generate-text/smooth-stream.test.ts +2101 -0
- package/src/generate-text/smooth-stream.ts +162 -0
- package/src/generate-text/step-result.ts +238 -0
- package/src/generate-text/stop-condition.ts +29 -0
- package/src/generate-text/stream-text-result.ts +463 -0
- package/src/generate-text/stream-text.test-d.ts +200 -0
- package/src/generate-text/stream-text.test.ts +19979 -0
- package/src/generate-text/stream-text.ts +2505 -0
- package/src/generate-text/to-response-messages.test.ts +922 -0
- package/src/generate-text/to-response-messages.ts +163 -0
- package/src/generate-text/tool-approval-request-output.ts +21 -0
- package/src/generate-text/tool-call-repair-function.ts +27 -0
- package/src/generate-text/tool-call.ts +47 -0
- package/src/generate-text/tool-error.ts +34 -0
- package/src/generate-text/tool-output-denied.ts +21 -0
- package/src/generate-text/tool-output.ts +7 -0
- package/src/generate-text/tool-result.ts +36 -0
- package/src/generate-text/tool-set.ts +14 -0
- package/src/global.ts +24 -0
- package/src/index.ts +50 -0
- package/src/logger/index.ts +6 -0
- package/src/logger/log-warnings.test.ts +351 -0
- package/src/logger/log-warnings.ts +119 -0
- package/src/middleware/__snapshots__/simulate-streaming-middleware.test.ts.snap +64 -0
- package/src/middleware/add-tool-input-examples-middleware.test.ts +476 -0
- package/src/middleware/add-tool-input-examples-middleware.ts +90 -0
- package/src/middleware/default-embedding-settings-middleware.test.ts +126 -0
- package/src/middleware/default-embedding-settings-middleware.ts +22 -0
- package/src/middleware/default-settings-middleware.test.ts +388 -0
- package/src/middleware/default-settings-middleware.ts +33 -0
- package/src/middleware/extract-json-middleware.test.ts +827 -0
- package/src/middleware/extract-json-middleware.ts +197 -0
- package/src/middleware/extract-reasoning-middleware.test.ts +1028 -0
- package/src/middleware/extract-reasoning-middleware.ts +238 -0
- package/src/middleware/index.ts +10 -0
- package/src/middleware/simulate-streaming-middleware.test.ts +911 -0
- package/src/middleware/simulate-streaming-middleware.ts +79 -0
- package/src/middleware/wrap-embedding-model.test.ts +358 -0
- package/src/middleware/wrap-embedding-model.ts +86 -0
- package/src/middleware/wrap-image-model.test.ts +423 -0
- package/src/middleware/wrap-image-model.ts +85 -0
- package/src/middleware/wrap-language-model.test.ts +518 -0
- package/src/middleware/wrap-language-model.ts +104 -0
- package/src/middleware/wrap-provider.test.ts +120 -0
- package/src/middleware/wrap-provider.ts +51 -0
- package/src/model/as-embedding-model-v3.test.ts +319 -0
- package/src/model/as-embedding-model-v3.ts +24 -0
- package/src/model/as-image-model-v3.test.ts +409 -0
- package/src/model/as-image-model-v3.ts +24 -0
- package/src/model/as-language-model-v3.test.ts +508 -0
- package/src/model/as-language-model-v3.ts +103 -0
- package/src/model/as-provider-v3.ts +36 -0
- package/src/model/as-speech-model-v3.test.ts +356 -0
- package/src/model/as-speech-model-v3.ts +24 -0
- package/src/model/as-transcription-model-v3.test.ts +529 -0
- package/src/model/as-transcription-model-v3.ts +24 -0
- package/src/model/resolve-model.test.ts +244 -0
- package/src/model/resolve-model.ts +126 -0
- package/src/prompt/call-settings.ts +148 -0
- package/src/prompt/content-part.ts +209 -0
- package/src/prompt/convert-to-language-model-prompt.test.ts +2018 -0
- package/src/prompt/convert-to-language-model-prompt.ts +442 -0
- package/src/prompt/create-tool-model-output.test.ts +508 -0
- package/src/prompt/create-tool-model-output.ts +34 -0
- package/src/prompt/data-content.test.ts +15 -0
- package/src/prompt/data-content.ts +134 -0
- package/src/prompt/index.ts +27 -0
- package/src/prompt/invalid-data-content-error.ts +29 -0
- package/src/prompt/invalid-message-role-error.ts +27 -0
- package/src/prompt/message-conversion-error.ts +28 -0
- package/src/prompt/message.ts +68 -0
- package/src/prompt/prepare-call-settings.test.ts +159 -0
- package/src/prompt/prepare-call-settings.ts +108 -0
- package/src/prompt/prepare-tools-and-tool-choice.test.ts +461 -0
- package/src/prompt/prepare-tools-and-tool-choice.ts +86 -0
- package/src/prompt/prompt.ts +43 -0
- package/src/prompt/split-data-url.ts +17 -0
- package/src/prompt/standardize-prompt.test.ts +82 -0
- package/src/prompt/standardize-prompt.ts +99 -0
- package/src/prompt/wrap-gateway-error.ts +29 -0
- package/src/registry/custom-provider.test.ts +211 -0
- package/src/registry/custom-provider.ts +155 -0
- package/src/registry/index.ts +7 -0
- package/src/registry/no-such-provider-error.ts +41 -0
- package/src/registry/provider-registry.test.ts +691 -0
- package/src/registry/provider-registry.ts +328 -0
- package/src/rerank/index.ts +2 -0
- package/src/rerank/rerank-result.ts +70 -0
- package/src/rerank/rerank.test.ts +516 -0
- package/src/rerank/rerank.ts +237 -0
- package/src/telemetry/assemble-operation-name.ts +21 -0
- package/src/telemetry/get-base-telemetry-attributes.ts +53 -0
- package/src/telemetry/get-tracer.ts +20 -0
- package/src/telemetry/noop-tracer.ts +69 -0
- package/src/telemetry/record-span.ts +63 -0
- package/src/telemetry/select-telemetry-attributes.ts +78 -0
- package/src/telemetry/select-temetry-attributes.test.ts +114 -0
- package/src/telemetry/stringify-for-telemetry.test.ts +114 -0
- package/src/telemetry/stringify-for-telemetry.ts +33 -0
- package/src/telemetry/telemetry-settings.ts +44 -0
- package/src/test/mock-embedding-model-v2.ts +35 -0
- package/src/test/mock-embedding-model-v3.ts +48 -0
- package/src/test/mock-image-model-v2.ts +28 -0
- package/src/test/mock-image-model-v3.ts +28 -0
- package/src/test/mock-language-model-v2.ts +72 -0
- package/src/test/mock-language-model-v3.ts +77 -0
- package/src/test/mock-provider-v2.ts +68 -0
- package/src/test/mock-provider-v3.ts +80 -0
- package/src/test/mock-reranking-model-v3.ts +25 -0
- package/src/test/mock-server-response.ts +69 -0
- package/src/test/mock-speech-model-v2.ts +24 -0
- package/src/test/mock-speech-model-v3.ts +24 -0
- package/src/test/mock-tracer.ts +156 -0
- package/src/test/mock-transcription-model-v2.ts +24 -0
- package/src/test/mock-transcription-model-v3.ts +24 -0
- package/src/test/mock-values.ts +4 -0
- package/src/test/not-implemented.ts +3 -0
- package/src/text-stream/create-text-stream-response.test.ts +38 -0
- package/src/text-stream/create-text-stream-response.ts +18 -0
- package/src/text-stream/index.ts +2 -0
- package/src/text-stream/pipe-text-stream-to-response.test.ts +38 -0
- package/src/text-stream/pipe-text-stream-to-response.ts +26 -0
- package/src/transcribe/index.ts +2 -0
- package/src/transcribe/transcribe-result.ts +60 -0
- package/src/transcribe/transcribe.test.ts +313 -0
- package/src/transcribe/transcribe.ts +173 -0
- package/src/types/embedding-model-middleware.ts +3 -0
- package/src/types/embedding-model.ts +18 -0
- package/src/types/image-model-middleware.ts +3 -0
- package/src/types/image-model-response-metadata.ts +16 -0
- package/src/types/image-model.ts +19 -0
- package/src/types/index.ts +29 -0
- package/src/types/json-value.ts +15 -0
- package/src/types/language-model-middleware.ts +3 -0
- package/src/types/language-model-request-metadata.ts +6 -0
- package/src/types/language-model-response-metadata.ts +21 -0
- package/src/types/language-model.ts +104 -0
- package/src/types/provider-metadata.ts +16 -0
- package/src/types/provider.ts +55 -0
- package/src/types/reranking-model.ts +6 -0
- package/src/types/speech-model-response-metadata.ts +21 -0
- package/src/types/speech-model.ts +6 -0
- package/src/types/transcription-model-response-metadata.ts +16 -0
- package/src/types/transcription-model.ts +9 -0
- package/src/types/usage.ts +200 -0
- package/src/types/warning.ts +7 -0
- package/src/ui/__snapshots__/append-response-messages.test.ts.snap +416 -0
- package/src/ui/__snapshots__/convert-to-model-messages.test.ts.snap +419 -0
- package/src/ui/__snapshots__/process-chat-text-response.test.ts.snap +142 -0
- package/src/ui/call-completion-api.ts +157 -0
- package/src/ui/chat-transport.ts +83 -0
- package/src/ui/chat.test-d.ts +233 -0
- package/src/ui/chat.test.ts +2695 -0
- package/src/ui/chat.ts +716 -0
- package/src/ui/convert-file-list-to-file-ui-parts.ts +36 -0
- package/src/ui/convert-to-model-messages.test.ts +2775 -0
- package/src/ui/convert-to-model-messages.ts +373 -0
- package/src/ui/default-chat-transport.ts +36 -0
- package/src/ui/direct-chat-transport.test.ts +446 -0
- package/src/ui/direct-chat-transport.ts +118 -0
- package/src/ui/http-chat-transport.test.ts +185 -0
- package/src/ui/http-chat-transport.ts +292 -0
- package/src/ui/index.ts +71 -0
- package/src/ui/last-assistant-message-is-complete-with-approval-responses.ts +44 -0
- package/src/ui/last-assistant-message-is-complete-with-tool-calls.test.ts +371 -0
- package/src/ui/last-assistant-message-is-complete-with-tool-calls.ts +39 -0
- package/src/ui/process-text-stream.test.ts +38 -0
- package/src/ui/process-text-stream.ts +16 -0
- package/src/ui/process-ui-message-stream.test.ts +8052 -0
- package/src/ui/process-ui-message-stream.ts +713 -0
- package/src/ui/text-stream-chat-transport.ts +23 -0
- package/src/ui/transform-text-to-ui-message-stream.test.ts +124 -0
- package/src/ui/transform-text-to-ui-message-stream.ts +27 -0
- package/src/ui/ui-messages.test.ts +48 -0
- package/src/ui/ui-messages.ts +534 -0
- package/src/ui/use-completion.ts +84 -0
- package/src/ui/validate-ui-messages.test.ts +1428 -0
- package/src/ui/validate-ui-messages.ts +476 -0
- package/src/ui-message-stream/create-ui-message-stream-response.test.ts +266 -0
- package/src/ui-message-stream/create-ui-message-stream-response.ts +32 -0
- package/src/ui-message-stream/create-ui-message-stream.test.ts +639 -0
- package/src/ui-message-stream/create-ui-message-stream.ts +124 -0
- package/src/ui-message-stream/get-response-ui-message-id.test.ts +55 -0
- package/src/ui-message-stream/get-response-ui-message-id.ts +24 -0
- package/src/ui-message-stream/handle-ui-message-stream-finish.test.ts +429 -0
- package/src/ui-message-stream/handle-ui-message-stream-finish.ts +135 -0
- package/src/ui-message-stream/index.ts +13 -0
- package/src/ui-message-stream/json-to-sse-transform-stream.ts +12 -0
- package/src/ui-message-stream/pipe-ui-message-stream-to-response.test.ts +90 -0
- package/src/ui-message-stream/pipe-ui-message-stream-to-response.ts +40 -0
- package/src/ui-message-stream/read-ui-message-stream.test.ts +122 -0
- package/src/ui-message-stream/read-ui-message-stream.ts +87 -0
- package/src/ui-message-stream/ui-message-chunks.test-d.ts +18 -0
- package/src/ui-message-stream/ui-message-chunks.ts +344 -0
- package/src/ui-message-stream/ui-message-stream-headers.ts +7 -0
- package/src/ui-message-stream/ui-message-stream-on-finish-callback.ts +32 -0
- package/src/ui-message-stream/ui-message-stream-response-init.ts +5 -0
- package/src/ui-message-stream/ui-message-stream-writer.ts +24 -0
- package/src/util/as-array.ts +3 -0
- package/src/util/async-iterable-stream.test.ts +241 -0
- package/src/util/async-iterable-stream.ts +94 -0
- package/src/util/consume-stream.ts +29 -0
- package/src/util/cosine-similarity.test.ts +57 -0
- package/src/util/cosine-similarity.ts +47 -0
- package/src/util/create-resolvable-promise.ts +30 -0
- package/src/util/create-stitchable-stream.test.ts +239 -0
- package/src/util/create-stitchable-stream.ts +112 -0
- package/src/util/data-url.ts +17 -0
- package/src/util/deep-partial.ts +84 -0
- package/src/util/detect-media-type.test.ts +670 -0
- package/src/util/detect-media-type.ts +184 -0
- package/src/util/download/download-function.ts +45 -0
- package/src/util/download/download.test.ts +69 -0
- package/src/util/download/download.ts +46 -0
- package/src/util/error-handler.ts +1 -0
- package/src/util/fix-json.test.ts +279 -0
- package/src/util/fix-json.ts +401 -0
- package/src/util/get-potential-start-index.test.ts +34 -0
- package/src/util/get-potential-start-index.ts +30 -0
- package/src/util/index.ts +11 -0
- package/src/util/is-deep-equal-data.test.ts +119 -0
- package/src/util/is-deep-equal-data.ts +48 -0
- package/src/util/is-non-empty-object.ts +5 -0
- package/src/util/job.ts +1 -0
- package/src/util/log-v2-compatibility-warning.ts +21 -0
- package/src/util/merge-abort-signals.test.ts +155 -0
- package/src/util/merge-abort-signals.ts +43 -0
- package/src/util/merge-objects.test.ts +118 -0
- package/src/util/merge-objects.ts +79 -0
- package/src/util/now.ts +4 -0
- package/src/util/parse-partial-json.test.ts +80 -0
- package/src/util/parse-partial-json.ts +30 -0
- package/src/util/prepare-headers.test.ts +51 -0
- package/src/util/prepare-headers.ts +14 -0
- package/src/util/prepare-retries.test.ts +10 -0
- package/src/util/prepare-retries.ts +47 -0
- package/src/util/retry-error.ts +41 -0
- package/src/util/retry-with-exponential-backoff.test.ts +446 -0
- package/src/util/retry-with-exponential-backoff.ts +154 -0
- package/src/util/serial-job-executor.test.ts +162 -0
- package/src/util/serial-job-executor.ts +36 -0
- package/src/util/simulate-readable-stream.test.ts +98 -0
- package/src/util/simulate-readable-stream.ts +39 -0
- package/src/util/split-array.test.ts +60 -0
- package/src/util/split-array.ts +20 -0
- package/src/util/value-of.ts +65 -0
- package/src/util/write-to-server-response.test.ts +266 -0
- package/src/util/write-to-server-response.ts +49 -0
- package/src/version.ts +5 -0
|
@@ -0,0 +1,534 @@
|
|
|
1
|
+
import {
|
|
2
|
+
InferToolInput,
|
|
3
|
+
InferToolOutput,
|
|
4
|
+
Tool,
|
|
5
|
+
ToolCall,
|
|
6
|
+
} from '@ai-sdk/provider-utils';
|
|
7
|
+
import { ToolSet } from '../generate-text';
|
|
8
|
+
import { ProviderMetadata } from '../types/provider-metadata';
|
|
9
|
+
import { DeepPartial } from '../util/deep-partial';
|
|
10
|
+
import { ValueOf } from '../util/value-of';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
The data types that can be used in the UI message for the UI message data parts.
|
|
14
|
+
*/
|
|
15
|
+
export type UIDataTypes = Record<string, unknown>;
|
|
16
|
+
|
|
17
|
+
export type UITool = {
|
|
18
|
+
input: unknown;
|
|
19
|
+
output: unknown | undefined;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Infer the input and output types of a tool so it can be used as a UI tool.
|
|
24
|
+
*/
|
|
25
|
+
export type InferUITool<TOOL extends Tool> = {
|
|
26
|
+
input: InferToolInput<TOOL>;
|
|
27
|
+
output: InferToolOutput<TOOL>;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Infer the input and output types of a tool set so it can be used as a UI tool set.
|
|
32
|
+
*/
|
|
33
|
+
export type InferUITools<TOOLS extends ToolSet> = {
|
|
34
|
+
[NAME in keyof TOOLS & string]: InferUITool<TOOLS[NAME]>;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type UITools = Record<string, UITool>;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
AI SDK UI Messages. They are used in the client and to communicate between the frontend and the API routes.
|
|
41
|
+
*/
|
|
42
|
+
export interface UIMessage<
|
|
43
|
+
METADATA = unknown,
|
|
44
|
+
DATA_PARTS extends UIDataTypes = UIDataTypes,
|
|
45
|
+
TOOLS extends UITools = UITools,
|
|
46
|
+
> {
|
|
47
|
+
/**
|
|
48
|
+
A unique identifier for the message.
|
|
49
|
+
*/
|
|
50
|
+
id: string;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
The role of the message.
|
|
54
|
+
*/
|
|
55
|
+
role: 'system' | 'user' | 'assistant';
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
The metadata of the message.
|
|
59
|
+
*/
|
|
60
|
+
metadata?: METADATA;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
The parts of the message. Use this for rendering the message in the UI.
|
|
64
|
+
|
|
65
|
+
System messages should be avoided (set the system prompt on the server instead).
|
|
66
|
+
They can have text parts.
|
|
67
|
+
|
|
68
|
+
User messages can have text parts and file parts.
|
|
69
|
+
|
|
70
|
+
Assistant messages can have text, reasoning, tool invocation, and file parts.
|
|
71
|
+
*/
|
|
72
|
+
parts: Array<UIMessagePart<DATA_PARTS, TOOLS>>;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export type UIMessagePart<
|
|
76
|
+
DATA_TYPES extends UIDataTypes,
|
|
77
|
+
TOOLS extends UITools,
|
|
78
|
+
> =
|
|
79
|
+
| TextUIPart
|
|
80
|
+
| ReasoningUIPart
|
|
81
|
+
| ToolUIPart<TOOLS>
|
|
82
|
+
| DynamicToolUIPart
|
|
83
|
+
| SourceUrlUIPart
|
|
84
|
+
| SourceDocumentUIPart
|
|
85
|
+
| FileUIPart
|
|
86
|
+
| DataUIPart<DATA_TYPES>
|
|
87
|
+
| StepStartUIPart;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* A text part of a message.
|
|
91
|
+
*/
|
|
92
|
+
export type TextUIPart = {
|
|
93
|
+
type: 'text';
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* The text content.
|
|
97
|
+
*/
|
|
98
|
+
text: string;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* The state of the text part.
|
|
102
|
+
*/
|
|
103
|
+
state?: 'streaming' | 'done';
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* The provider metadata.
|
|
107
|
+
*/
|
|
108
|
+
providerMetadata?: ProviderMetadata;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* A reasoning part of a message.
|
|
113
|
+
*/
|
|
114
|
+
export type ReasoningUIPart = {
|
|
115
|
+
type: 'reasoning';
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* The reasoning text.
|
|
119
|
+
*/
|
|
120
|
+
text: string;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* The state of the reasoning part.
|
|
124
|
+
*/
|
|
125
|
+
state?: 'streaming' | 'done';
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* The provider metadata.
|
|
129
|
+
*/
|
|
130
|
+
providerMetadata?: ProviderMetadata;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* A source part of a message.
|
|
135
|
+
*/
|
|
136
|
+
export type SourceUrlUIPart = {
|
|
137
|
+
type: 'source-url';
|
|
138
|
+
sourceId: string;
|
|
139
|
+
url: string;
|
|
140
|
+
title?: string;
|
|
141
|
+
providerMetadata?: ProviderMetadata;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* A document source part of a message.
|
|
146
|
+
*/
|
|
147
|
+
export type SourceDocumentUIPart = {
|
|
148
|
+
type: 'source-document';
|
|
149
|
+
sourceId: string;
|
|
150
|
+
mediaType: string;
|
|
151
|
+
title: string;
|
|
152
|
+
filename?: string;
|
|
153
|
+
providerMetadata?: ProviderMetadata;
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* A file part of a message.
|
|
158
|
+
*/
|
|
159
|
+
export type FileUIPart = {
|
|
160
|
+
type: 'file';
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* IANA media type of the file.
|
|
164
|
+
*
|
|
165
|
+
* @see https://www.iana.org/assignments/media-types/media-types.xhtml
|
|
166
|
+
*/
|
|
167
|
+
mediaType: string;
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Optional filename of the file.
|
|
171
|
+
*/
|
|
172
|
+
filename?: string;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* The URL of the file.
|
|
176
|
+
* It can either be a URL to a hosted file or a [Data URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs).
|
|
177
|
+
*/
|
|
178
|
+
url: string;
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* The provider metadata.
|
|
182
|
+
*/
|
|
183
|
+
providerMetadata?: ProviderMetadata;
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* A step boundary part of a message.
|
|
188
|
+
*/
|
|
189
|
+
export type StepStartUIPart = {
|
|
190
|
+
type: 'step-start';
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
export type DataUIPart<DATA_TYPES extends UIDataTypes> = ValueOf<{
|
|
194
|
+
[NAME in keyof DATA_TYPES & string]: {
|
|
195
|
+
type: `data-${NAME}`;
|
|
196
|
+
id?: string;
|
|
197
|
+
data: DATA_TYPES[NAME];
|
|
198
|
+
};
|
|
199
|
+
}>;
|
|
200
|
+
|
|
201
|
+
type asUITool<TOOL extends UITool | Tool> = TOOL extends Tool
|
|
202
|
+
? InferUITool<TOOL>
|
|
203
|
+
: TOOL;
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Check if a message part is a data part.
|
|
207
|
+
*/
|
|
208
|
+
export function isDataUIPart<DATA_TYPES extends UIDataTypes>(
|
|
209
|
+
part: UIMessagePart<DATA_TYPES, UITools>,
|
|
210
|
+
): part is DataUIPart<DATA_TYPES> {
|
|
211
|
+
return part.type.startsWith('data-');
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* A UI tool invocation contains all the information needed to render a tool invocation in the UI.
|
|
216
|
+
* It can be derived from a tool without knowing the tool name, and can be used to define
|
|
217
|
+
* UI components for the tool.
|
|
218
|
+
*/
|
|
219
|
+
export type UIToolInvocation<TOOL extends UITool | Tool> = {
|
|
220
|
+
/**
|
|
221
|
+
* ID of the tool call.
|
|
222
|
+
*/
|
|
223
|
+
toolCallId: string;
|
|
224
|
+
title?: string;
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Whether the tool call was executed by the provider.
|
|
228
|
+
*/
|
|
229
|
+
providerExecuted?: boolean;
|
|
230
|
+
} & (
|
|
231
|
+
| {
|
|
232
|
+
state: 'input-streaming';
|
|
233
|
+
input: DeepPartial<asUITool<TOOL>['input']> | undefined;
|
|
234
|
+
output?: never;
|
|
235
|
+
errorText?: never;
|
|
236
|
+
approval?: never;
|
|
237
|
+
}
|
|
238
|
+
| {
|
|
239
|
+
state: 'input-available';
|
|
240
|
+
input: asUITool<TOOL>['input'];
|
|
241
|
+
output?: never;
|
|
242
|
+
errorText?: never;
|
|
243
|
+
callProviderMetadata?: ProviderMetadata;
|
|
244
|
+
approval?: never;
|
|
245
|
+
}
|
|
246
|
+
| {
|
|
247
|
+
state: 'approval-requested';
|
|
248
|
+
input: asUITool<TOOL>['input'];
|
|
249
|
+
output?: never;
|
|
250
|
+
errorText?: never;
|
|
251
|
+
callProviderMetadata?: ProviderMetadata;
|
|
252
|
+
approval: {
|
|
253
|
+
id: string;
|
|
254
|
+
approved?: never;
|
|
255
|
+
reason?: never;
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
| {
|
|
259
|
+
state: 'approval-responded';
|
|
260
|
+
input: asUITool<TOOL>['input'];
|
|
261
|
+
output?: never;
|
|
262
|
+
errorText?: never;
|
|
263
|
+
callProviderMetadata?: ProviderMetadata;
|
|
264
|
+
approval: {
|
|
265
|
+
id: string;
|
|
266
|
+
approved: boolean;
|
|
267
|
+
reason?: string;
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
| {
|
|
271
|
+
state: 'output-available';
|
|
272
|
+
input: asUITool<TOOL>['input'];
|
|
273
|
+
output: asUITool<TOOL>['output'];
|
|
274
|
+
errorText?: never;
|
|
275
|
+
callProviderMetadata?: ProviderMetadata;
|
|
276
|
+
preliminary?: boolean;
|
|
277
|
+
approval?: {
|
|
278
|
+
id: string;
|
|
279
|
+
approved: true;
|
|
280
|
+
reason?: string;
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
| {
|
|
284
|
+
state: 'output-error'; // TODO AI SDK 6: change to 'error' state
|
|
285
|
+
input: asUITool<TOOL>['input'] | undefined;
|
|
286
|
+
rawInput?: unknown; // TODO AI SDK 6: remove this field, input should be unknown
|
|
287
|
+
output?: never;
|
|
288
|
+
errorText: string;
|
|
289
|
+
callProviderMetadata?: ProviderMetadata;
|
|
290
|
+
approval?: {
|
|
291
|
+
id: string;
|
|
292
|
+
approved: true;
|
|
293
|
+
reason?: string;
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
| {
|
|
297
|
+
state: 'output-denied';
|
|
298
|
+
input: asUITool<TOOL>['input'];
|
|
299
|
+
output?: never;
|
|
300
|
+
errorText?: never;
|
|
301
|
+
callProviderMetadata?: ProviderMetadata;
|
|
302
|
+
approval: {
|
|
303
|
+
id: string;
|
|
304
|
+
approved: false;
|
|
305
|
+
reason?: string;
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
);
|
|
309
|
+
|
|
310
|
+
export type ToolUIPart<TOOLS extends UITools = UITools> = ValueOf<{
|
|
311
|
+
[NAME in keyof TOOLS & string]: {
|
|
312
|
+
type: `tool-${NAME}`;
|
|
313
|
+
} & UIToolInvocation<TOOLS[NAME]>;
|
|
314
|
+
}>;
|
|
315
|
+
|
|
316
|
+
export type DynamicToolUIPart = {
|
|
317
|
+
type: 'dynamic-tool';
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Name of the tool that is being called.
|
|
321
|
+
*/
|
|
322
|
+
toolName: string;
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* ID of the tool call.
|
|
326
|
+
*/
|
|
327
|
+
toolCallId: string;
|
|
328
|
+
title?: string;
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Whether the tool call was executed by the provider.
|
|
332
|
+
*/
|
|
333
|
+
providerExecuted?: boolean;
|
|
334
|
+
} & (
|
|
335
|
+
| {
|
|
336
|
+
state: 'input-streaming';
|
|
337
|
+
input: unknown | undefined;
|
|
338
|
+
output?: never;
|
|
339
|
+
errorText?: never;
|
|
340
|
+
approval?: never;
|
|
341
|
+
}
|
|
342
|
+
| {
|
|
343
|
+
state: 'input-available';
|
|
344
|
+
input: unknown;
|
|
345
|
+
output?: never;
|
|
346
|
+
errorText?: never;
|
|
347
|
+
callProviderMetadata?: ProviderMetadata;
|
|
348
|
+
approval?: never;
|
|
349
|
+
}
|
|
350
|
+
| {
|
|
351
|
+
state: 'approval-requested';
|
|
352
|
+
input: unknown;
|
|
353
|
+
output?: never;
|
|
354
|
+
errorText?: never;
|
|
355
|
+
callProviderMetadata?: ProviderMetadata;
|
|
356
|
+
approval: {
|
|
357
|
+
id: string;
|
|
358
|
+
approved?: never;
|
|
359
|
+
reason?: never;
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
| {
|
|
363
|
+
state: 'approval-responded';
|
|
364
|
+
input: unknown;
|
|
365
|
+
output?: never;
|
|
366
|
+
errorText?: never;
|
|
367
|
+
callProviderMetadata?: ProviderMetadata;
|
|
368
|
+
approval: {
|
|
369
|
+
id: string;
|
|
370
|
+
approved: boolean;
|
|
371
|
+
reason?: string;
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
| {
|
|
375
|
+
state: 'output-available';
|
|
376
|
+
input: unknown;
|
|
377
|
+
output: unknown;
|
|
378
|
+
errorText?: never;
|
|
379
|
+
callProviderMetadata?: ProviderMetadata;
|
|
380
|
+
preliminary?: boolean;
|
|
381
|
+
approval?: {
|
|
382
|
+
id: string;
|
|
383
|
+
approved: true;
|
|
384
|
+
reason?: string;
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
| {
|
|
388
|
+
state: 'output-error'; // TODO AI SDK 6: change to 'error' state
|
|
389
|
+
input: unknown;
|
|
390
|
+
output?: never;
|
|
391
|
+
errorText: string;
|
|
392
|
+
callProviderMetadata?: ProviderMetadata;
|
|
393
|
+
approval?: {
|
|
394
|
+
id: string;
|
|
395
|
+
approved: true;
|
|
396
|
+
reason?: string;
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
| {
|
|
400
|
+
state: 'output-denied';
|
|
401
|
+
input: unknown;
|
|
402
|
+
output?: never;
|
|
403
|
+
errorText?: never;
|
|
404
|
+
callProviderMetadata?: ProviderMetadata;
|
|
405
|
+
approval: {
|
|
406
|
+
id: string;
|
|
407
|
+
approved: false;
|
|
408
|
+
reason?: string;
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
);
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Type guard to check if a message part is a text part.
|
|
415
|
+
*/
|
|
416
|
+
export function isTextUIPart(
|
|
417
|
+
part: UIMessagePart<UIDataTypes, UITools>,
|
|
418
|
+
): part is TextUIPart {
|
|
419
|
+
return part.type === 'text';
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Type guard to check if a message part is a file part.
|
|
424
|
+
*/
|
|
425
|
+
export function isFileUIPart(
|
|
426
|
+
part: UIMessagePart<UIDataTypes, UITools>,
|
|
427
|
+
): part is FileUIPart {
|
|
428
|
+
return part.type === 'file';
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Type guard to check if a message part is a reasoning part.
|
|
433
|
+
*/
|
|
434
|
+
export function isReasoningUIPart(
|
|
435
|
+
part: UIMessagePart<UIDataTypes, UITools>,
|
|
436
|
+
): part is ReasoningUIPart {
|
|
437
|
+
return part.type === 'reasoning';
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* Check if a message part is a static tool part.
|
|
442
|
+
*
|
|
443
|
+
* Static tools are tools for which the types are known at development time.
|
|
444
|
+
*/
|
|
445
|
+
export function isStaticToolUIPart<TOOLS extends UITools>(
|
|
446
|
+
part: UIMessagePart<UIDataTypes, TOOLS>,
|
|
447
|
+
): part is ToolUIPart<TOOLS> {
|
|
448
|
+
return part.type.startsWith('tool-');
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* Check if a message part is a dynamic tool part.
|
|
453
|
+
*
|
|
454
|
+
* Dynamic tools are tools for which the input and output types are unknown.
|
|
455
|
+
*/
|
|
456
|
+
export function isDynamicToolUIPart(
|
|
457
|
+
part: UIMessagePart<UIDataTypes, UITools>,
|
|
458
|
+
): part is DynamicToolUIPart {
|
|
459
|
+
return part.type === 'dynamic-tool';
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* Check if a message part is a tool part.
|
|
464
|
+
*
|
|
465
|
+
* Tool parts are either static or dynamic tools.
|
|
466
|
+
*
|
|
467
|
+
* Use `isStaticToolUIPart` or `isDynamicToolUIPart` to check the type of the tool.
|
|
468
|
+
*/
|
|
469
|
+
export function isToolUIPart<TOOLS extends UITools>(
|
|
470
|
+
part: UIMessagePart<UIDataTypes, TOOLS>,
|
|
471
|
+
): part is ToolUIPart<TOOLS> | DynamicToolUIPart {
|
|
472
|
+
return isStaticToolUIPart(part) || isDynamicToolUIPart(part);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* @deprecated Use isToolUIPart instead.
|
|
477
|
+
*/
|
|
478
|
+
export const isToolOrDynamicToolUIPart = isToolUIPart;
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* Returns the name of the static tool.
|
|
482
|
+
*
|
|
483
|
+
* The possible values are the keys of the tool set.
|
|
484
|
+
*/
|
|
485
|
+
export function getStaticToolName<TOOLS extends UITools>(
|
|
486
|
+
part: ToolUIPart<TOOLS>,
|
|
487
|
+
): keyof TOOLS {
|
|
488
|
+
return part.type.split('-').slice(1).join('-') as keyof TOOLS;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* Returns the name of the tool (static or dynamic).
|
|
493
|
+
*
|
|
494
|
+
* This function will not restrict the name to the keys of the tool set.
|
|
495
|
+
* If you need to restrict the name to the keys of the tool set, use `getStaticToolName` instead.
|
|
496
|
+
*/
|
|
497
|
+
export function getToolName(
|
|
498
|
+
part: ToolUIPart<UITools> | DynamicToolUIPart,
|
|
499
|
+
): string {
|
|
500
|
+
return isDynamicToolUIPart(part) ? part.toolName : getStaticToolName(part);
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* @deprecated Use getToolName instead.
|
|
505
|
+
*/
|
|
506
|
+
export const getToolOrDynamicToolName = getToolName;
|
|
507
|
+
|
|
508
|
+
export type InferUIMessageMetadata<T extends UIMessage> =
|
|
509
|
+
T extends UIMessage<infer METADATA> ? METADATA : unknown;
|
|
510
|
+
|
|
511
|
+
export type InferUIMessageData<T extends UIMessage> =
|
|
512
|
+
T extends UIMessage<unknown, infer DATA_TYPES> ? DATA_TYPES : UIDataTypes;
|
|
513
|
+
|
|
514
|
+
export type InferUIMessageTools<T extends UIMessage> =
|
|
515
|
+
T extends UIMessage<unknown, UIDataTypes, infer TOOLS> ? TOOLS : UITools;
|
|
516
|
+
|
|
517
|
+
export type InferUIMessageToolOutputs<UI_MESSAGE extends UIMessage> =
|
|
518
|
+
InferUIMessageTools<UI_MESSAGE>[keyof InferUIMessageTools<UI_MESSAGE>]['output'];
|
|
519
|
+
|
|
520
|
+
export type InferUIMessageToolCall<UI_MESSAGE extends UIMessage> =
|
|
521
|
+
| ValueOf<{
|
|
522
|
+
[NAME in keyof InferUIMessageTools<UI_MESSAGE>]: ToolCall<
|
|
523
|
+
NAME & string,
|
|
524
|
+
InferUIMessageTools<UI_MESSAGE>[NAME] extends { input: infer INPUT }
|
|
525
|
+
? INPUT
|
|
526
|
+
: never
|
|
527
|
+
> & { dynamic?: false };
|
|
528
|
+
}>
|
|
529
|
+
| (ToolCall<string, unknown> & { dynamic: true });
|
|
530
|
+
|
|
531
|
+
export type InferUIMessagePart<UI_MESSAGE extends UIMessage> = UIMessagePart<
|
|
532
|
+
InferUIMessageData<UI_MESSAGE>,
|
|
533
|
+
InferUIMessageTools<UI_MESSAGE>
|
|
534
|
+
>;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
2
|
+
|
|
3
|
+
export type CompletionRequestOptions = {
|
|
4
|
+
/**
|
|
5
|
+
An optional object of headers to be passed to the API endpoint.
|
|
6
|
+
*/
|
|
7
|
+
headers?: Record<string, string> | Headers;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
An optional object to be passed to the API endpoint.
|
|
11
|
+
*/
|
|
12
|
+
body?: object;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type UseCompletionOptions = {
|
|
16
|
+
/**
|
|
17
|
+
* The API endpoint that accepts a `{ prompt: string }` object and returns
|
|
18
|
+
* a stream of tokens of the AI completion response. Defaults to `/api/completion`.
|
|
19
|
+
*/
|
|
20
|
+
api?: string;
|
|
21
|
+
/**
|
|
22
|
+
* An unique identifier for the chat. If not provided, a random one will be
|
|
23
|
+
* generated. When provided, the `useChat` hook with the same `id` will
|
|
24
|
+
* have shared states across components.
|
|
25
|
+
*/
|
|
26
|
+
id?: string;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Initial prompt input of the completion.
|
|
30
|
+
*/
|
|
31
|
+
initialInput?: string;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Initial completion result. Useful to load an existing history.
|
|
35
|
+
*/
|
|
36
|
+
initialCompletion?: string;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Callback function to be called when the completion is finished streaming.
|
|
40
|
+
*/
|
|
41
|
+
onFinish?: (prompt: string, completion: string) => void;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Callback function to be called when an error is encountered.
|
|
45
|
+
*/
|
|
46
|
+
onError?: (error: Error) => void;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The credentials mode to be used for the fetch request.
|
|
50
|
+
* Possible values are: 'omit', 'same-origin', 'include'.
|
|
51
|
+
* Defaults to 'same-origin'.
|
|
52
|
+
*/
|
|
53
|
+
credentials?: RequestCredentials;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* HTTP headers to be sent with the API request.
|
|
57
|
+
*/
|
|
58
|
+
headers?: Record<string, string> | Headers;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Extra body object to be sent with the API request.
|
|
62
|
+
* @example
|
|
63
|
+
* Send a `sessionId` to the API along with the prompt.
|
|
64
|
+
* ```js
|
|
65
|
+
* useChat({
|
|
66
|
+
* body: {
|
|
67
|
+
* sessionId: '123',
|
|
68
|
+
* }
|
|
69
|
+
* })
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
body?: object;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
Streaming protocol that is used. Defaults to `data`.
|
|
76
|
+
*/
|
|
77
|
+
streamProtocol?: 'data' | 'text';
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
Custom fetch implementation. You can use it as a middleware to intercept requests,
|
|
81
|
+
or to provide a custom fetch implementation for e.g. testing.
|
|
82
|
+
*/
|
|
83
|
+
fetch?: FetchFunction;
|
|
84
|
+
};
|