@eaziz/prepare 0.1.1 → 0.1.3
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 +8 -2
- package/dist/address.d.ts +12 -0
- package/dist/address.d.ts.map +1 -0
- package/dist/address.js +16 -0
- package/dist/address.js.map +1 -0
- package/dist/contracts.d.ts +3 -46
- package/dist/contracts.d.ts.map +1 -1
- package/dist/headers.d.ts +2 -0
- package/dist/headers.d.ts.map +1 -0
- package/dist/headers.js +8 -0
- package/dist/headers.js.map +1 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/media-codecs.d.ts +5 -0
- package/dist/media-codecs.d.ts.map +1 -0
- package/dist/media-codecs.js +30 -0
- package/dist/media-codecs.js.map +1 -0
- package/dist/protocol-capabilities.d.ts +111 -0
- package/dist/protocol-capabilities.d.ts.map +1 -0
- package/dist/protocol-capabilities.js +58 -0
- package/dist/protocol-capabilities.js.map +1 -0
- package/dist/protocol-registry.d.ts +60 -0
- package/dist/protocol-registry.d.ts.map +1 -0
- package/dist/protocol-registry.js +89 -0
- package/dist/protocol-registry.js.map +1 -0
- package/dist/protocols/catalog.d.ts +4 -8
- package/dist/protocols/catalog.d.ts.map +1 -1
- package/dist/protocols/catalog.js +3 -10
- package/dist/protocols/catalog.js.map +1 -1
- package/dist/protocols/images.d.ts +4 -8
- package/dist/protocols/images.d.ts.map +1 -1
- package/dist/protocols/images.js +13 -17
- package/dist/protocols/images.js.map +1 -1
- package/dist/protocols/media.d.ts +2 -1
- package/dist/protocols/media.d.ts.map +1 -1
- package/dist/protocols/media.js +38 -12
- package/dist/protocols/media.js.map +1 -1
- package/dist/protocols/realtime.d.ts +7 -0
- package/dist/protocols/realtime.d.ts.map +1 -0
- package/dist/protocols/realtime.js +13 -0
- package/dist/protocols/realtime.js.map +1 -0
- package/dist/protocols/speech.d.ts +19 -0
- package/dist/protocols/speech.d.ts.map +1 -0
- package/dist/protocols/speech.js +77 -0
- package/dist/protocols/speech.js.map +1 -0
- package/dist/protocols/text.d.ts +13 -6
- package/dist/protocols/text.d.ts.map +1 -1
- package/dist/protocols/text.js +14 -133
- package/dist/protocols/text.js.map +1 -1
- package/dist/protocols/transcription.d.ts +16 -0
- package/dist/protocols/transcription.d.ts.map +1 -0
- package/dist/protocols/transcription.js +53 -0
- package/dist/protocols/transcription.js.map +1 -0
- package/dist/protocols/video.d.ts +17 -0
- package/dist/protocols/video.d.ts.map +1 -0
- package/dist/protocols/video.js +36 -0
- package/dist/protocols/video.js.map +1 -0
- package/dist/request-builders/http.d.ts +24 -0
- package/dist/request-builders/http.d.ts.map +1 -0
- package/dist/request-builders/http.js +20 -0
- package/dist/request-builders/http.js.map +1 -0
- package/dist/request-builders/multipart.d.ts +5 -0
- package/dist/request-builders/multipart.d.ts.map +1 -0
- package/dist/request-builders/multipart.js +9 -0
- package/dist/request-builders/multipart.js.map +1 -0
- package/dist/request-builders/websocket.d.ts +12 -0
- package/dist/request-builders/websocket.d.ts.map +1 -0
- package/dist/request-builders/websocket.js +22 -0
- package/dist/request-builders/websocket.js.map +1 -0
- package/dist/request-builders.d.ts +13 -0
- package/dist/request-builders.d.ts.map +1 -0
- package/dist/request-builders.js +9 -0
- package/dist/request-builders.js.map +1 -0
- package/dist/request-compiler.d.ts +10 -12
- package/dist/request-compiler.d.ts.map +1 -1
- package/dist/request-compiler.js +2 -100
- package/dist/request-compiler.js.map +1 -1
- package/dist/request-types.d.ts +126 -62
- package/dist/request-types.d.ts.map +1 -1
- package/dist/request-utils.d.ts +5 -28
- package/dist/request-utils.d.ts.map +1 -1
- package/dist/request-utils.js +5 -78
- package/dist/request-utils.js.map +1 -1
- package/package.json +1 -1
package/dist/protocols/text.js
CHANGED
|
@@ -1,140 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
"openai-chat-completions": prepareOpenAIChat,
|
|
5
|
-
"openai-responses": prepareOpenAIResponses,
|
|
6
|
-
"anthropic-messages": prepareAnthropic,
|
|
7
|
-
"gemini-generate-content": prepareGemini,
|
|
8
|
-
};
|
|
9
|
-
export function prepareText(request) {
|
|
10
|
-
return adapters[request.protocol](request);
|
|
1
|
+
import { jsonRequest as buildJsonRequest } from "../request-builders/http.js";
|
|
2
|
+
export function prepareOpenAIChat(request) {
|
|
3
|
+
return jsonRequest(request, "/v1/chat/completions", { ...request.input, model: request.model }, {}, request.input.stream ? "http-stream" : "http");
|
|
11
4
|
}
|
|
12
|
-
function
|
|
13
|
-
return jsonRequest(request, "/v1/
|
|
14
|
-
...request.input.extraBody,
|
|
15
|
-
model: request.model,
|
|
16
|
-
messages: request.input.messages.map(toOpenAIMessage),
|
|
17
|
-
...commonOpenAIFields(request.input),
|
|
18
|
-
});
|
|
5
|
+
export function prepareOpenAIResponses(request) {
|
|
6
|
+
return jsonRequest(request, "/v1/responses", { ...request.input, model: request.model }, {}, request.input.stream ? "http-stream" : "http");
|
|
19
7
|
}
|
|
20
|
-
function
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
model: request.model,
|
|
24
|
-
input: request.input.messages.map(toResponsesMessage),
|
|
25
|
-
...(request.input.instructions ? { instructions: request.input.instructions } : {}),
|
|
26
|
-
...(request.input.stream !== undefined ? { stream: request.input.stream } : {}),
|
|
27
|
-
...(request.input.maxTokens !== undefined ? { max_output_tokens: request.input.maxTokens } : {}),
|
|
28
|
-
...(request.input.temperature !== undefined ? { temperature: request.input.temperature } : {}),
|
|
29
|
-
...(request.input.topP !== undefined ? { top_p: request.input.topP } : {}),
|
|
30
|
-
...(request.input.tools ? { tools: request.input.tools } : {}),
|
|
31
|
-
...(request.input.toolChoice !== undefined ? { tool_choice: request.input.toolChoice } : {}),
|
|
32
|
-
...(request.input.reasoning ? { reasoning: request.input.reasoning } : {}),
|
|
33
|
-
...(request.input.responseFormat !== undefined
|
|
34
|
-
? { text: { format: request.input.responseFormat } }
|
|
35
|
-
: {}),
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
function prepareAnthropic(request) {
|
|
39
|
-
if (request.input.maxTokens === undefined) {
|
|
40
|
-
throw new Error('Protocol "anthropic-messages" requires input.maxTokens.');
|
|
8
|
+
export function prepareAnthropic(request) {
|
|
9
|
+
if (request.input.max_tokens === undefined) {
|
|
10
|
+
throw new Error('Protocol "anthropic-messages" requires input.max_tokens.');
|
|
41
11
|
}
|
|
42
|
-
return jsonRequest(request, "/v1/messages",
|
|
43
|
-
}
|
|
44
|
-
function prepareGemini(request) {
|
|
45
|
-
const systemParts = [
|
|
46
|
-
...(request.input.instructions ? [{ text: request.input.instructions }] : []),
|
|
47
|
-
...request.input.messages
|
|
48
|
-
.filter((message) => message.role === "system" || message.role === "developer")
|
|
49
|
-
.flatMap((message) => geminiParts(message.content)),
|
|
50
|
-
];
|
|
51
|
-
const contents = request.input.messages
|
|
52
|
-
.filter((message) => message.role !== "system" && message.role !== "developer")
|
|
53
|
-
.map((message) => ({
|
|
54
|
-
role: message.role === "assistant" ? "model" : "user",
|
|
55
|
-
parts: geminiParts(message.content),
|
|
56
|
-
}));
|
|
57
|
-
const generationConfig = {
|
|
58
|
-
...(request.input.temperature !== undefined ? { temperature: request.input.temperature } : {}),
|
|
59
|
-
...(request.input.topP !== undefined ? { topP: request.input.topP } : {}),
|
|
60
|
-
...(request.input.maxTokens !== undefined ? { maxOutputTokens: request.input.maxTokens } : {}),
|
|
61
|
-
...(request.input.stop !== undefined
|
|
62
|
-
? { stopSequences: typeof request.input.stop === "string" ? [request.input.stop] : request.input.stop }
|
|
63
|
-
: {}),
|
|
64
|
-
};
|
|
65
|
-
const operation = request.input.stream ? "streamGenerateContent?alt=sse" : "generateContent";
|
|
66
|
-
return jsonRequest(request, `/v1beta/models/${encodeURIComponent(request.model)}:${operation}`, {
|
|
67
|
-
...request.input.extraBody,
|
|
68
|
-
contents,
|
|
69
|
-
...(systemParts.length > 0 ? { systemInstruction: { parts: systemParts } } : {}),
|
|
70
|
-
...(Object.keys(generationConfig).length > 0 ? { generationConfig } : {}),
|
|
71
|
-
...(request.input.tools
|
|
72
|
-
? {
|
|
73
|
-
tools: [
|
|
74
|
-
{
|
|
75
|
-
functionDeclarations: request.input.tools.map((tool) => ({
|
|
76
|
-
name: tool.name,
|
|
77
|
-
...(tool.description ? { description: tool.description } : {}),
|
|
78
|
-
parameters: tool.parameters,
|
|
79
|
-
})),
|
|
80
|
-
},
|
|
81
|
-
],
|
|
82
|
-
}
|
|
83
|
-
: {}),
|
|
84
|
-
});
|
|
12
|
+
return jsonRequest(request, "/v1/messages", { ...request.input, model: request.model }, { "anthropic-version": "2023-06-01" }, request.input.stream ? "http-stream" : "http");
|
|
85
13
|
}
|
|
86
|
-
function
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
...(input.temperature !== undefined ? { temperature: input.temperature } : {}),
|
|
90
|
-
...(input.topP !== undefined ? { top_p: input.topP } : {}),
|
|
91
|
-
...(input.maxTokens !== undefined ? { max_tokens: input.maxTokens } : {}),
|
|
92
|
-
...(input.tools
|
|
93
|
-
? { tools: input.tools.map((tool) => ({ type: "function", function: tool })) }
|
|
94
|
-
: {}),
|
|
95
|
-
...(input.toolChoice !== undefined ? { tool_choice: input.toolChoice } : {}),
|
|
96
|
-
...(input.responseFormat !== undefined ? { response_format: input.responseFormat } : {}),
|
|
97
|
-
...(input.stop !== undefined ? { stop: input.stop } : {}),
|
|
98
|
-
};
|
|
14
|
+
export function prepareGemini(request) {
|
|
15
|
+
const { stream, ...body } = request.input;
|
|
16
|
+
return jsonRequest(request, `/v1beta/models/${encodeURIComponent(request.model)}:${stream ? "streamGenerateContent?alt=sse" : "generateContent"}`, body, {}, stream ? "http-stream" : "http");
|
|
99
17
|
}
|
|
100
|
-
function
|
|
101
|
-
|
|
102
|
-
...(input.instructions ? [{ type: "text", text: input.instructions }] : []),
|
|
103
|
-
...input.messages
|
|
104
|
-
.filter((message) => message.role === "system" || message.role === "developer")
|
|
105
|
-
.flatMap((message) => anthropicContent(message.content)),
|
|
106
|
-
];
|
|
107
|
-
const messages = input.messages
|
|
108
|
-
.filter((message) => message.role !== "system" && message.role !== "developer")
|
|
109
|
-
.map((message) => ({
|
|
110
|
-
role: message.role === "assistant" ? "assistant" : "user",
|
|
111
|
-
content: message.role === "tool"
|
|
112
|
-
? [{ type: "tool_result", tool_use_id: message.toolCallId, content: message.content }]
|
|
113
|
-
: anthropicContent(message.content),
|
|
114
|
-
...message.protocolMetadata,
|
|
115
|
-
}));
|
|
116
|
-
return {
|
|
117
|
-
...input.extraBody,
|
|
118
|
-
model,
|
|
119
|
-
messages,
|
|
120
|
-
max_tokens: input.maxTokens,
|
|
121
|
-
...(system.length > 0 ? { system } : {}),
|
|
122
|
-
...(input.stream !== undefined ? { stream: input.stream } : {}),
|
|
123
|
-
...(input.temperature !== undefined ? { temperature: input.temperature } : {}),
|
|
124
|
-
...(input.topP !== undefined ? { top_p: input.topP } : {}),
|
|
125
|
-
...(input.stop !== undefined
|
|
126
|
-
? { stop_sequences: typeof input.stop === "string" ? [input.stop] : input.stop }
|
|
127
|
-
: {}),
|
|
128
|
-
...(input.tools
|
|
129
|
-
? {
|
|
130
|
-
tools: input.tools.map((tool) => ({
|
|
131
|
-
name: tool.name,
|
|
132
|
-
...(tool.description ? { description: tool.description } : {}),
|
|
133
|
-
input_schema: tool.parameters,
|
|
134
|
-
})),
|
|
135
|
-
}
|
|
136
|
-
: {}),
|
|
137
|
-
...(input.toolChoice !== undefined ? { tool_choice: input.toolChoice } : {}),
|
|
138
|
-
};
|
|
18
|
+
function jsonRequest(request, path, body, headers = {}, transport = "http") {
|
|
19
|
+
return buildJsonRequest(request, path, body, headers, transport);
|
|
139
20
|
}
|
|
140
21
|
//# sourceMappingURL=text.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.js","sourceRoot":"","sources":["../../src/protocols/text.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,
|
|
1
|
+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K,CAAC;IAC1C,OAAO,WAAW,CAChB,OAAO,EACP,kBAAkB,kBAAkB,CAAC,OAAO,CAAC,KAAK,CAAC,IACjD,MAAM,CAAC,CAAC,CAAC,+BAA+B,CAAC,CAAC,CAAC,iBAC7C,EAAE,EACF,IAAI,EACJ,EAAE,EACF,MAAM,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,MAAM,CAChC,CAAC;AACJ,CAAC;AAED,SAAS,WAAW,CAClB,OAA+C,EAC/C,IAAY,EACZ,IAAuC,EACvC,UAA4C,EAAE,EAC9C,YAAoC,MAAM;IAE1C,OAAO,gBAAgB,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;AACnE,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ProtocolRequest } from "../request-types.js";
|
|
2
|
+
import { type PreparedRequest } from "../request-builders/http.js";
|
|
3
|
+
type TranscriptionProtocol = "openai-audio" | "zhipu-audio" | "volcengine-audio" | "dashscope-transcription";
|
|
4
|
+
type TranscriptionRequest<P extends TranscriptionProtocol> = ProtocolRequest<"transcription", P>;
|
|
5
|
+
export interface PreparedTranscriptionRequest extends PreparedRequest {
|
|
6
|
+
readonly response: {
|
|
7
|
+
readonly kind: "json";
|
|
8
|
+
readonly field: "text";
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export declare function prepareVolcengineTranscription(request: TranscriptionRequest<"volcengine-audio">): PreparedTranscriptionRequest;
|
|
12
|
+
export declare function prepareDashScopeTranscription(request: TranscriptionRequest<"dashscope-transcription">): PreparedTranscriptionRequest;
|
|
13
|
+
export declare function prepareOpenAITranscription(request: TranscriptionRequest<"openai-audio">): PreparedTranscriptionRequest;
|
|
14
|
+
export declare function prepareZhipuTranscription(request: TranscriptionRequest<"zhipu-audio">): PreparedTranscriptionRequest;
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=transcription.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transcription.d.ts","sourceRoot":"","sources":["../../src/protocols/transcription.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAe,KAAK,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAIhF,KAAK,qBAAqB,GACtB,cAAc,GACd,aAAa,GACb,kBAAkB,GAClB,yBAAyB,CAAC;AAC9B,KAAK,oBAAoB,CAAC,CAAC,SAAS,qBAAqB,IAAI,eAAe,CAC1E,eAAe,EACf,CAAC,CACF,CAAC;AAEF,MAAM,WAAW,4BAA6B,SAAQ,eAAe;IACnE,QAAQ,CAAC,QAAQ,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;CACtE;AAED,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,oBAAoB,CAAC,kBAAkB,CAAC,GAChD,4BAA4B,CAU9B;AAED,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,oBAAoB,CAAC,yBAAyB,CAAC,GACvD,4BAA4B,CAQ9B;AAED,wBAAgB,0BAA0B,CACxC,OAAO,EAAE,oBAAoB,CAAC,cAAc,CAAC,GAC5C,4BAA4B,CAE9B;AAED,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,oBAAoB,CAAC,aAAa,CAAC,GAC3C,4BAA4B,CAM9B"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { jsonRequest } from "../request-builders/http.js";
|
|
2
|
+
import { multipartRequest } from "../request-builders/multipart.js";
|
|
3
|
+
import { websocketRequest } from "../request-builders/websocket.js";
|
|
4
|
+
export function prepareVolcengineTranscription(request) {
|
|
5
|
+
if (!request.input.audio) {
|
|
6
|
+
throw new Error("Volcengine transcription requires input.audio.");
|
|
7
|
+
}
|
|
8
|
+
return {
|
|
9
|
+
...websocketRequest(request, "/api/v3/sauc/bigmodel", {
|
|
10
|
+
...request.input,
|
|
11
|
+
}),
|
|
12
|
+
response: { kind: "json", field: "text" },
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export function prepareDashScopeTranscription(request) {
|
|
16
|
+
return {
|
|
17
|
+
...jsonRequest(request, "/api/v1/services/audio/asr/transcription", {
|
|
18
|
+
...request.input,
|
|
19
|
+
model: request.model,
|
|
20
|
+
}),
|
|
21
|
+
response: { kind: "json", field: "text" },
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export function prepareOpenAITranscription(request) {
|
|
25
|
+
return multipartTranscription(request, "/v1/audio/transcriptions", true);
|
|
26
|
+
}
|
|
27
|
+
export function prepareZhipuTranscription(request) {
|
|
28
|
+
return multipartTranscription(request, "/paas/v4/audio/transcriptions", false);
|
|
29
|
+
}
|
|
30
|
+
function multipartTranscription(request, path, allowString) {
|
|
31
|
+
const input = request.input;
|
|
32
|
+
if (!allowString && typeof input.file === "string") {
|
|
33
|
+
throw new Error(`Protocol "${request.protocol}" multipart transcription requires binary file data.`);
|
|
34
|
+
}
|
|
35
|
+
const form = new FormData();
|
|
36
|
+
const blob = input.file instanceof Blob
|
|
37
|
+
? input.file
|
|
38
|
+
: typeof input.file === "string"
|
|
39
|
+
? new Blob([input.file])
|
|
40
|
+
: new Blob([new Uint8Array(input.file).buffer]);
|
|
41
|
+
form.set("file", blob, input.filename ?? "audio");
|
|
42
|
+
form.set("model", request.model);
|
|
43
|
+
for (const [key, value] of Object.entries(input)) {
|
|
44
|
+
if (["file", "filename"].includes(key) || value === undefined)
|
|
45
|
+
continue;
|
|
46
|
+
form.set(key, typeof value === "string" ? value : JSON.stringify(value));
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
...multipartRequest(request, path, form),
|
|
50
|
+
response: { kind: "json", field: "text" },
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=transcription.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
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AM,EAAE;KAC1C,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ProtocolRequest } from "../request-types.js";
|
|
2
|
+
import type { ProtocolContext } from "../protocol-registry.js";
|
|
3
|
+
import { type PreparedRequest } from "../request-builders/http.js";
|
|
4
|
+
type VideoRequest<P extends "dashscope-video" | "volcengine-video"> = ProtocolRequest<"video-generation", P>;
|
|
5
|
+
export interface PreparedVideoRequest {
|
|
6
|
+
readonly submit: PreparedRequest;
|
|
7
|
+
readonly lifecycle: {
|
|
8
|
+
readonly kind: "async-job";
|
|
9
|
+
readonly taskIdPath: string;
|
|
10
|
+
readonly status: (taskId: string) => PreparedRequest;
|
|
11
|
+
readonly resultPath: string;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export declare function prepareDashScopeVideo(request: VideoRequest<"dashscope-video">, context: ProtocolContext): PreparedVideoRequest;
|
|
15
|
+
export declare function prepareVolcengineVideo(request: VideoRequest<"volcengine-video">, context: ProtocolContext): PreparedVideoRequest;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=video.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"video.d.ts","sourceRoot":"","sources":["../../src/protocols/video.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,KAAK,EACV,eAAe,EAEhB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAGL,KAAK,eAAe,EACrB,MAAM,6BAA6B,CAAC;AAErC,KAAK,YAAY,CAAC,CAAC,SAAS,iBAAiB,GAAG,kBAAkB,IAChE,eAAe,CAAC,kBAAkB,EAAE,CAAC,CAAC,CAAC;AACzC,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,MAAM,EAAE,eAAe,CAAC;IACjC,QAAQ,CAAC,SAAS,EAAE;QAClB,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;QAC3B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;QAC5B,QAAQ,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,eAAe,CAAC;QACrD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;KAC7B,CAAC;CACH;AAED,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,YAAY,CAAC,iBAAiB,CAAC,EACxC,OAAO,EAAE,eAAe,GACvB,oBAAoB,CActB;AAED,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,YAAY,CAAC,kBAAkB,CAAC,EACzC,OAAO,EAAE,eAAe,GACvB,oBAAoB,CAStB"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { httpRequest, jsonRequest, } from "../request-builders/http.js";
|
|
2
|
+
export function prepareDashScopeVideo(request, context) {
|
|
3
|
+
const input = request.input;
|
|
4
|
+
return {
|
|
5
|
+
submit: jsonRequest(request, "/api/v1/services/aigc/video-generation/video-synthesis", {
|
|
6
|
+
...input,
|
|
7
|
+
model: request.model,
|
|
8
|
+
}, { "x-dashscope-async": "enable" }),
|
|
9
|
+
lifecycle: lifecycle(request, context.lifecycle),
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export function prepareVolcengineVideo(request, context) {
|
|
13
|
+
const input = request.input;
|
|
14
|
+
return {
|
|
15
|
+
submit: jsonRequest(request, "/api/v3/contents/generations/tasks", {
|
|
16
|
+
...input,
|
|
17
|
+
model: request.model,
|
|
18
|
+
}),
|
|
19
|
+
lifecycle: lifecycle(request, context.lifecycle),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function lifecycle(request, metadata) {
|
|
23
|
+
if (!metadata)
|
|
24
|
+
throw new Error(`Protocol "${request.protocol}" requires lifecycle metadata.`);
|
|
25
|
+
return {
|
|
26
|
+
kind: "async-job",
|
|
27
|
+
taskIdPath: metadata.taskIdPath,
|
|
28
|
+
resultPath: metadata.resultPath,
|
|
29
|
+
status: (taskId) => {
|
|
30
|
+
const path = metadata.statusPath.replace("{taskId}", encodeURIComponent(taskId));
|
|
31
|
+
// A submit endpoint override must not replace the polling endpoint.
|
|
32
|
+
return httpRequest({ baseURL: request.baseURL, headers: request.headers }, path, { method: "GET" });
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=video.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"video.js","sourceRoot":"","sources":["../../src/protocols/video.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,WAAW,EACX,WAAW,GAEZ,MAAM,6BAA6B,CAAC;AAcrC,MAAM,UAAU,qBAAqB,CACnC,OAAwC,EACxC,OAAwB;IAExB,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAC5B,OAAO;QACL,MAAM,EAAE,WAAW,CACjB,OAAO,EACP,wDAAwD,EACxD;YACE,GAAG,KAAK;YACR,KAAK,EAAE,OAAO,CAAC,KAAK;SACrB,EACD,EAAE,mBAAmB,EAAE,QAAQ,EAAE,CAClC;QACD,SAAS,EAAE,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC;KACjD,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,sBAAsB,CACpC,OAAyC,EACzC,OAAwB;IAExB,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;IAC5B,OAAO;QACL,MAAM,EAAE,WAAW,CAAC,OAAO,EAAE,oCAAoC,EAAE;YACjE,GAAG,KAAK;YACR,KAAK,EAAE,OAAO,CAAC,KAAK;SACrB,CAAC;QACF,SAAS,EAAE,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC;KACjD,CAAC;AACJ,CAAC;AAED,SAAS,SAAS,CAChB,OAA6D,EAC7D,QAA4B;IAE5B,IAAI,CAAC,QAAQ;QACX,MAAM,IAAI,KAAK,CACb,aAAa,OAAO,CAAC,QAAQ,gCAAgC,CAC9D,CAAC;IACJ,OAAO;QACL,IAAI,EAAE,WAAW;QACjB,UAAU,EAAE,QAAQ,CAAC,UAAU;QAC/B,UAAU,EAAE,QAAQ,CAAC,UAAU;QAC/B,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE;YACjB,MAAM,IAAI,GAAG,QAAQ,CAAC,UAAU,CAAC,OAAO,CACtC,UAAU,EACV,kBAAkB,CAAC,MAAM,CAAC,CAC3B,CAAC;YACF,oEAAoE;YACpE,OAAO,WAAW,CAChB,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,EACtD,IAAI,EACJ,EAAE,MAAM,EAAE,KAAK,EAAE,CAClB,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Transport } from "../contracts.js";
|
|
2
|
+
import { type RequestAddress } from "../address.js";
|
|
3
|
+
/** Shared request view retained for existing consumers. */
|
|
4
|
+
export interface PreparedRequest {
|
|
5
|
+
readonly method: "POST" | "GET";
|
|
6
|
+
readonly path: string;
|
|
7
|
+
readonly url?: string;
|
|
8
|
+
readonly transport?: Transport;
|
|
9
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
10
|
+
readonly body?: string | FormData | Uint8Array;
|
|
11
|
+
}
|
|
12
|
+
export type HttpTransport = Exclude<Transport, "websocket">;
|
|
13
|
+
export interface PreparedHttpRequest extends PreparedRequest {
|
|
14
|
+
readonly transport: HttpTransport;
|
|
15
|
+
}
|
|
16
|
+
export interface HttpRequestOptions {
|
|
17
|
+
readonly method?: PreparedRequest["method"];
|
|
18
|
+
readonly transport?: HttpTransport;
|
|
19
|
+
readonly body?: PreparedRequest["body"];
|
|
20
|
+
readonly headers?: HeadersInit;
|
|
21
|
+
}
|
|
22
|
+
export declare function httpRequest(request: RequestAddress, path: string, options?: HttpRequestOptions): PreparedHttpRequest;
|
|
23
|
+
export declare function jsonRequest(request: RequestAddress, path: string, body: Readonly<Record<string, unknown>>, protocolHeaders?: Readonly<Record<string, string>>, transport?: HttpTransport): PreparedHttpRequest;
|
|
24
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/request-builders/http.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD,OAAO,EAAc,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AAEhE,2DAA2D;AAC3D,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,KAAK,CAAC;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,CAAC;IAC/B,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACnD,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,UAAU,CAAC;CAChD;AAED,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;AAC5D,MAAM,WAAW,mBAAoB,SAAQ,eAAe;IAC1D,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC;CACnC;AAED,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,MAAM,CAAC,EAAE,eAAe,CAAC,QAAQ,CAAC,CAAC;IAC5C,QAAQ,CAAC,SAAS,CAAC,EAAE,aAAa,CAAC;IACnC,QAAQ,CAAC,IAAI,CAAC,EAAE,eAAe,CAAC,MAAM,CAAC,CAAC;IACxC,QAAQ,CAAC,OAAO,CAAC,EAAE,WAAW,CAAC;CAChC;AAED,wBAAgB,WAAW,CACzB,OAAO,EAAE,cAAc,EACvB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,kBAAuB,GAC/B,mBAAmB,CASrB;AAED,wBAAgB,WAAW,CACzB,OAAO,EAAE,cAAc,EACvB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EACvC,eAAe,GAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAM,EACtD,SAAS,GAAE,aAAsB,GAChC,mBAAmB,CAMrB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { headerRecord } from "../headers.js";
|
|
2
|
+
import { requestURL } from "../address.js";
|
|
3
|
+
export function httpRequest(request, path, options = {}) {
|
|
4
|
+
return {
|
|
5
|
+
method: options.method ?? "POST",
|
|
6
|
+
path,
|
|
7
|
+
...requestURL(request, path),
|
|
8
|
+
transport: options.transport ?? "http",
|
|
9
|
+
headers: { ...headerRecord(options.headers), ...headerRecord(request.headers) },
|
|
10
|
+
...(options.body !== undefined ? { body: options.body } : {}),
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export function jsonRequest(request, path, body, protocolHeaders = {}, transport = "http") {
|
|
14
|
+
return httpRequest(request, path, {
|
|
15
|
+
transport,
|
|
16
|
+
headers: { "content-type": "application/json", ...protocolHeaders },
|
|
17
|
+
body: JSON.stringify(body),
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=http.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/request-builders/http.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAuB,MAAM,eAAe,CAAC;AAwBhE,MAAM,UAAU,WAAW,CACzB,OAAuB,EACvB,IAAY,EACZ,UAA8B,EAAE;IAEhC,OAAO;QACL,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,MAAM;QAChC,IAAI;QACJ,GAAG,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC;QAC5B,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,MAAM;QACtC,OAAO,EAAE,EAAE,GAAG,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,GAAG,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;QAC/E,GAAG,CAAC,OAAO,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC9D,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,WAAW,CACzB,OAAuB,EACvB,IAAY,EACZ,IAAuC,EACvC,kBAAoD,EAAE,EACtD,YAA2B,MAAM;IAEjC,OAAO,WAAW,CAAC,OAAO,EAAE,IAAI,EAAE;QAChC,SAAS;QACT,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,GAAG,eAAe,EAAE;QACnE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;KAC3B,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { RequestAddress } from "../address.js";
|
|
2
|
+
import { type PreparedHttpRequest } from "./http.js";
|
|
3
|
+
/** Leave the multipart boundary to the runtime that serializes FormData. */
|
|
4
|
+
export declare function multipartRequest(request: RequestAddress, path: string, body: FormData): PreparedHttpRequest;
|
|
5
|
+
//# sourceMappingURL=multipart.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multipart.d.ts","sourceRoot":"","sources":["../../src/request-builders/multipart.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAe,KAAK,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAElE,4EAA4E;AAC5E,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,cAAc,EACvB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,QAAQ,GACb,mBAAmB,CAIrB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { headerRecord } from "../headers.js";
|
|
2
|
+
import { httpRequest } from "./http.js";
|
|
3
|
+
/** Leave the multipart boundary to the runtime that serializes FormData. */
|
|
4
|
+
export function multipartRequest(request, path, body) {
|
|
5
|
+
const headers = headerRecord(request.headers);
|
|
6
|
+
delete headers["content-type"];
|
|
7
|
+
return httpRequest({ ...request, headers }, path, { body });
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=multipart.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multipart.js","sourceRoot":"","sources":["../../src/request-builders/multipart.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,OAAO,EAAE,WAAW,EAA4B,MAAM,WAAW,CAAC;AAElE,4EAA4E;AAC5E,MAAM,UAAU,gBAAgB,CAC9B,OAAuB,EACvB,IAAY,EACZ,IAAc;IAEd,MAAM,OAAO,GAAG,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC9C,OAAO,OAAO,CAAC,cAAc,CAAC,CAAC;IAC/B,OAAO,WAAW,CAAC,EAAE,GAAG,OAAO,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type RequestAddress } from "../address.js";
|
|
2
|
+
import type { PreparedRequest } from "./http.js";
|
|
3
|
+
export interface PreparedWebSocketRequest extends Omit<PreparedRequest, "method" | "transport" | "body"> {
|
|
4
|
+
readonly method: "GET";
|
|
5
|
+
readonly transport: "websocket";
|
|
6
|
+
/** Initial message after the handshake, never an HTTP request body. */
|
|
7
|
+
readonly body?: string | Uint8Array;
|
|
8
|
+
}
|
|
9
|
+
export declare function websocketRequest(address: RequestAddress, path: string, message?: Readonly<Record<string, unknown>>): PreparedWebSocketRequest;
|
|
10
|
+
/** @deprecated Pass an address, path, and initial message instead. */
|
|
11
|
+
export declare function websocketRequest(request: PreparedRequest): PreparedWebSocketRequest;
|
|
12
|
+
//# sourceMappingURL=websocket.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websocket.d.ts","sourceRoot":"","sources":["../../src/request-builders/websocket.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AAEhE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAEjD,MAAM,WAAW,wBAAyB,SAAQ,IAAI,CAAC,eAAe,EAAE,QAAQ,GAAG,WAAW,GAAG,MAAM,CAAC;IACtG,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC;IACvB,QAAQ,CAAC,SAAS,EAAE,WAAW,CAAC;IAChC,uEAAuE;IACvE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;CACrC;AAED,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,cAAc,EACvB,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAC1C,wBAAwB,CAAC;AAC5B,sEAAsE;AACtE,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,eAAe,GAAG,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { requestURL } from "../address.js";
|
|
2
|
+
import { headerRecord } from "../headers.js";
|
|
3
|
+
export function websocketRequest(address, path, message) {
|
|
4
|
+
const legacy = "method" in address ? address : undefined;
|
|
5
|
+
const requestPath = path ?? legacy?.path;
|
|
6
|
+
if (requestPath === undefined)
|
|
7
|
+
throw new Error("WebSocket request requires a path.");
|
|
8
|
+
const requestAddress = legacy ? { headers: legacy.headers } : address;
|
|
9
|
+
const url = legacy?.url ?? requestURL(requestAddress, requestPath).url;
|
|
10
|
+
const body = message !== undefined ? JSON.stringify(message) : legacy?.body;
|
|
11
|
+
if (body instanceof FormData)
|
|
12
|
+
throw new Error("WebSocket messages cannot contain FormData.");
|
|
13
|
+
return {
|
|
14
|
+
method: "GET",
|
|
15
|
+
path: requestPath,
|
|
16
|
+
...(url ? { url: url.replace(/^https:/i, "wss:").replace(/^http:/i, "ws:") } : {}),
|
|
17
|
+
transport: "websocket",
|
|
18
|
+
headers: headerRecord(requestAddress.headers),
|
|
19
|
+
...(body !== undefined ? { body } : {}),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=websocket.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websocket.js","sourceRoot":"","sources":["../../src/request-builders/websocket.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAuB,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAiB7C,MAAM,UAAU,gBAAgB,CAC9B,OAAyC,EACzC,IAAa,EACb,OAA2C;IAE3C,MAAM,MAAM,GAAG,QAAQ,IAAI,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC;IACzD,MAAM,WAAW,GAAG,IAAI,IAAI,MAAM,EAAE,IAAI,CAAC;IACzC,IAAI,WAAW,KAAK,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;IACrF,MAAM,cAAc,GAAmB,MAAM,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;IACtF,MAAM,GAAG,GAAG,MAAM,EAAE,GAAG,IAAI,UAAU,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC,GAAG,CAAC;IACvE,MAAM,IAAI,GAAG,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC;IAC5E,IAAI,IAAI,YAAY,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;IAC7F,OAAO;QACL,MAAM,EAAE,KAAK;QACb,IAAI,EAAE,WAAW;QACjB,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAClF,SAAS,EAAE,WAAW;QACtB,OAAO,EAAE,YAAY,CAAC,cAAc,CAAC,OAAO,CAAC;QAC7C,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACxC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Transport } from "./contracts.js";
|
|
2
|
+
import { type RequestAddress } from "./address.js";
|
|
3
|
+
export interface PreparedRequest {
|
|
4
|
+
readonly method: "POST" | "GET";
|
|
5
|
+
readonly path: string;
|
|
6
|
+
readonly url?: string;
|
|
7
|
+
readonly transport?: Transport;
|
|
8
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
9
|
+
readonly body?: string | FormData | Uint8Array;
|
|
10
|
+
}
|
|
11
|
+
export declare function jsonRequest(request: RequestAddress, path: string, body: Readonly<Record<string, unknown>>, protocolHeaders?: Readonly<Record<string, string>>): PreparedRequest;
|
|
12
|
+
export declare function requestWithBody(request: RequestAddress, path: string, body: string | FormData | Uint8Array): PreparedRequest;
|
|
13
|
+
//# sourceMappingURL=request-builders.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-builders.d.ts","sourceRoot":"","sources":["../src/request-builders.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhD,OAAO,EAAc,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAC/D,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,KAAK,CAAC;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,CAAC;IAC/B,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACnD,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,UAAU,CAAC;CAChD;AACD,wBAAgB,WAAW,CAAC,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,EAAE,eAAe,GAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAM,GAAG,eAAe,CAEnL;AACD,wBAAgB,eAAe,CAAC,OAAO,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,UAAU,GAAG,eAAe,CAE5H"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { headerRecord } from "./headers.js";
|
|
2
|
+
import { requestURL } from "./address.js";
|
|
3
|
+
export function jsonRequest(request, path, body, protocolHeaders = {}) {
|
|
4
|
+
return { method: "POST", path, ...requestURL(request, path), headers: { "content-type": "application/json", ...protocolHeaders, ...headerRecord(request.headers) }, body: JSON.stringify(body) };
|
|
5
|
+
}
|
|
6
|
+
export function requestWithBody(request, path, body) {
|
|
7
|
+
return { method: "POST", path, ...requestURL(request, path), headers: headerRecord(request.headers), body };
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=request-builders.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-builders.js","sourceRoot":"","sources":["../src/request-builders.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAuB,MAAM,cAAc,CAAC;AAS/D,MAAM,UAAU,WAAW,CAAC,OAAuB,EAAE,IAAY,EAAE,IAAuC,EAAE,kBAAoD,EAAE;IAChK,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE,GAAG,eAAe,EAAE,GAAG,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;AACnM,CAAC;AACD,MAAM,UAAU,eAAe,CAAC,OAAuB,EAAE,IAAY,EAAE,IAAoC;IACzG,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC;AAC9G,CAAC"}
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import type { RequestPreparation } from "./request-types.js";
|
|
2
|
-
import { type
|
|
3
|
-
export type
|
|
4
|
-
export type {
|
|
5
|
-
export type
|
|
6
|
-
export type
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
} ? PreparedTranscriptionRequest : PreparedRequest;
|
|
13
|
-
/** Converts a semantic request into a wire-protocol request without sending it. */
|
|
2
|
+
import { type PreparedByModelType } from "./protocol-registry.js";
|
|
3
|
+
export type * from "./request-types.js";
|
|
4
|
+
export type { PreparedRequest } from "./request-builders/http.js";
|
|
5
|
+
export type { PreparedSpeechRequest } from "./protocols/speech.js";
|
|
6
|
+
export type { PreparedTranscriptionRequest } from "./protocols/transcription.js";
|
|
7
|
+
export type { PreparedVideoRequest } from "./protocols/video.js";
|
|
8
|
+
export type PreparedMediaRequest = PreparedByModelType["speech-generation" | "transcription" | "video-generation"];
|
|
9
|
+
export type PreparedProtocolRequest = PreparedByModelType[keyof PreparedByModelType];
|
|
10
|
+
export type PreparedFor<TRequest extends RequestPreparation> = PreparedByModelType[TRequest["modelType"]];
|
|
11
|
+
/** Validates and dispatches through the single protocol registry. Never sends a request. */
|
|
14
12
|
export declare function prepare<TRequest extends RequestPreparation>(request: TRequest): PreparedFor<TRequest>;
|
|
15
13
|
export declare const compileRequest: typeof prepare;
|
|
16
14
|
//# sourceMappingURL=request-compiler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-compiler.d.ts","sourceRoot":"","sources":["../src/request-compiler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"request-compiler.d.ts","sourceRoot":"","sources":["../src/request-compiler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAyB,KAAK,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAEzF,mBAAmB,oBAAoB,CAAC;AACxC,YAAY,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,YAAY,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AACnE,YAAY,EAAE,4BAA4B,EAAE,MAAM,8BAA8B,CAAC;AACjF,YAAY,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACjE,MAAM,MAAM,oBAAoB,GAAG,mBAAmB,CAAC,mBAAmB,GAAG,eAAe,GAAG,kBAAkB,CAAC,CAAC;AACnH,MAAM,MAAM,uBAAuB,GAAG,mBAAmB,CAAC,MAAM,mBAAmB,CAAC,CAAC;AACrF,MAAM,MAAM,WAAW,CAAC,QAAQ,SAAS,kBAAkB,IAAI,mBAAmB,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC;AAE1G,4FAA4F;AAC5F,wBAAgB,OAAO,CAAC,QAAQ,SAAS,kBAAkB,EAAE,OAAO,EAAE,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC;AAIvG,eAAO,MAAM,cAAc,gBAAU,CAAC"}
|