@prismshadow/mmsp 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/README.md +121 -0
  2. package/dist/ant_messages/client.d.ts +59 -0
  3. package/dist/ant_messages/client.d.ts.map +1 -0
  4. package/dist/ant_messages/client.js +419 -0
  5. package/dist/ant_messages/index.d.ts +2 -0
  6. package/dist/ant_messages/index.d.ts.map +1 -0
  7. package/dist/ant_messages/index.js +18 -0
  8. package/dist/anthropic_official/client.d.ts +63 -0
  9. package/dist/anthropic_official/client.d.ts.map +1 -0
  10. package/dist/anthropic_official/client.js +540 -0
  11. package/dist/anthropic_official/index.d.ts +2 -0
  12. package/dist/anthropic_official/index.d.ts.map +1 -0
  13. package/dist/anthropic_official/index.js +18 -0
  14. package/dist/autoClient.d.ts +96 -0
  15. package/dist/autoClient.d.ts.map +1 -0
  16. package/dist/autoClient.js +258 -0
  17. package/dist/baseClient.d.ts +111 -0
  18. package/dist/baseClient.d.ts.map +1 -0
  19. package/dist/baseClient.js +284 -0
  20. package/dist/deepseek_official/client.d.ts +60 -0
  21. package/dist/deepseek_official/client.d.ts.map +1 -0
  22. package/dist/deepseek_official/client.js +407 -0
  23. package/dist/deepseek_official/index.d.ts +2 -0
  24. package/dist/deepseek_official/index.d.ts.map +1 -0
  25. package/dist/deepseek_official/index.js +18 -0
  26. package/dist/errors.d.ts +84 -0
  27. package/dist/errors.d.ts.map +1 -0
  28. package/dist/errors.js +140 -0
  29. package/dist/gemini_generate_content/client.d.ts +86 -0
  30. package/dist/gemini_generate_content/client.d.ts.map +1 -0
  31. package/dist/gemini_generate_content/client.js +809 -0
  32. package/dist/gemini_generate_content/index.d.ts +2 -0
  33. package/dist/gemini_generate_content/index.d.ts.map +1 -0
  34. package/dist/gemini_generate_content/index.js +18 -0
  35. package/dist/gemini_official/client.d.ts +87 -0
  36. package/dist/gemini_official/client.d.ts.map +1 -0
  37. package/dist/gemini_official/client.js +780 -0
  38. package/dist/gemini_official/index.d.ts +2 -0
  39. package/dist/gemini_official/index.d.ts.map +1 -0
  40. package/dist/gemini_official/index.js +18 -0
  41. package/dist/index.d.ts +6 -0
  42. package/dist/index.d.ts.map +1 -0
  43. package/dist/index.js +44 -0
  44. package/dist/integration/index.d.ts +1 -0
  45. package/dist/integration/index.d.ts.map +1 -0
  46. package/dist/integration/index.js +14 -0
  47. package/dist/integration/playground.d.ts +17 -0
  48. package/dist/integration/playground.d.ts.map +1 -0
  49. package/dist/integration/playground.js +3246 -0
  50. package/dist/integration/tracer.d.ts +188 -0
  51. package/dist/integration/tracer.d.ts.map +1 -0
  52. package/dist/integration/tracer.js +1928 -0
  53. package/dist/legacy.d.ts +13 -0
  54. package/dist/legacy.d.ts.map +1 -0
  55. package/dist/legacy.js +59 -0
  56. package/dist/minimax_official/client.d.ts +43 -0
  57. package/dist/minimax_official/client.d.ts.map +1 -0
  58. package/dist/minimax_official/client.js +346 -0
  59. package/dist/minimax_official/index.d.ts +2 -0
  60. package/dist/minimax_official/index.d.ts.map +1 -0
  61. package/dist/minimax_official/index.js +18 -0
  62. package/dist/moonshot_official/client.d.ts +73 -0
  63. package/dist/moonshot_official/client.d.ts.map +1 -0
  64. package/dist/moonshot_official/client.js +477 -0
  65. package/dist/moonshot_official/index.d.ts +2 -0
  66. package/dist/moonshot_official/index.d.ts.map +1 -0
  67. package/dist/moonshot_official/index.js +18 -0
  68. package/dist/openai_chat/client.d.ts +67 -0
  69. package/dist/openai_chat/client.d.ts.map +1 -0
  70. package/dist/openai_chat/client.js +419 -0
  71. package/dist/openai_chat/index.d.ts +2 -0
  72. package/dist/openai_chat/index.d.ts.map +1 -0
  73. package/dist/openai_chat/index.js +18 -0
  74. package/dist/openai_chat_vllm_adapter/client.d.ts +15 -0
  75. package/dist/openai_chat_vllm_adapter/client.d.ts.map +1 -0
  76. package/dist/openai_chat_vllm_adapter/client.js +118 -0
  77. package/dist/openai_chat_vllm_adapter/index.d.ts +2 -0
  78. package/dist/openai_chat_vllm_adapter/index.d.ts.map +1 -0
  79. package/dist/openai_chat_vllm_adapter/index.js +5 -0
  80. package/dist/openai_embedding/client.d.ts +46 -0
  81. package/dist/openai_embedding/client.d.ts.map +1 -0
  82. package/dist/openai_embedding/client.js +124 -0
  83. package/dist/openai_embedding/index.d.ts +2 -0
  84. package/dist/openai_embedding/index.d.ts.map +1 -0
  85. package/dist/openai_embedding/index.js +18 -0
  86. package/dist/openai_official/client.d.ts +61 -0
  87. package/dist/openai_official/client.d.ts.map +1 -0
  88. package/dist/openai_official/client.js +464 -0
  89. package/dist/openai_official/index.d.ts +2 -0
  90. package/dist/openai_official/index.d.ts.map +1 -0
  91. package/dist/openai_official/index.js +18 -0
  92. package/dist/openai_responses/client.d.ts +61 -0
  93. package/dist/openai_responses/client.d.ts.map +1 -0
  94. package/dist/openai_responses/client.js +449 -0
  95. package/dist/openai_responses/index.d.ts +2 -0
  96. package/dist/openai_responses/index.d.ts.map +1 -0
  97. package/dist/openai_responses/index.js +18 -0
  98. package/dist/registry.d.ts +49 -0
  99. package/dist/registry.d.ts.map +1 -0
  100. package/dist/registry.js +798 -0
  101. package/dist/streamItems.d.ts +36 -0
  102. package/dist/streamItems.d.ts.map +1 -0
  103. package/dist/streamItems.js +183 -0
  104. package/dist/types.d.ts +190 -0
  105. package/dist/types.d.ts.map +1 -0
  106. package/dist/types.js +37 -0
  107. package/dist/utils.d.ts +99 -0
  108. package/dist/utils.d.ts.map +1 -0
  109. package/dist/utils.js +312 -0
  110. package/dist/zai_official/client.d.ts +78 -0
  111. package/dist/zai_official/client.d.ts.map +1 -0
  112. package/dist/zai_official/client.js +420 -0
  113. package/dist/zai_official/index.d.ts +2 -0
  114. package/dist/zai_official/index.d.ts.map +1 -0
  115. package/dist/zai_official/index.js +18 -0
  116. package/package.json +68 -0
@@ -0,0 +1,36 @@
1
+ import { ContentItem, DeltaContentItem, EventContentItem } from "./types";
2
+ /**
3
+ * Assembles the items of one stream from the deltas a client yields. Model output is serial, so
4
+ * the deltas of an item are contiguous and one item streams at a time: it is done when a delta of
5
+ * the next item arrives, or when the stream ends.
6
+ *
7
+ * A delta belongs to the next item when it carries another `fidelity.item_id`, is of another
8
+ * kind, or begins an item by itself (a call's name, an image, a vector). Otherwise it continues
9
+ * the item streaming now: a delta without an id does, and so do a call's arguments whatever id a
10
+ * gateway puts on them. Fidelity sent alone under the item's id is that item's, whatever kind
11
+ * carries it.
12
+ *
13
+ * Every delta goes out as it arrives, without its `item_id`. A done item is the item's first
14
+ * delta with the growing field replaced by the join of every delta's, plus the item's fidelity.
15
+ */
16
+ export declare class StreamItems {
17
+ private readonly client;
18
+ private item;
19
+ constructor(client: string);
20
+ private protocolError;
21
+ /**
22
+ * One delta a client yielded. Returns what goes out: the done item of the item it ended, if
23
+ * any, then the delta itself.
24
+ */
25
+ delta(delta: DeltaContentItem): EventContentItem[];
26
+ /**
27
+ * The next item began, or the stream ended: returns the done item of the item streaming now,
28
+ * or nothing when no delta of it went out.
29
+ */
30
+ end(): ContentItem[];
31
+ /**
32
+ * Whether a delta begins the next item rather than continuing the one streaming now.
33
+ */
34
+ private begins;
35
+ }
36
+ //# sourceMappingURL=streamItems.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"streamItems.d.ts","sourceRoot":"","sources":["../src/streamItems.ts"],"names":[],"mappings":"AAgBA,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAEjB,MAAM,SAAS,CAAC;AAwFjB;;;;;;;;;;;;;GAaG;AACH,qBAAa,WAAW;IAGV,OAAO,CAAC,QAAQ,CAAC,MAAM;IAFnC,OAAO,CAAC,IAAI,CAAqB;gBAEJ,MAAM,EAAE,MAAM;IAE3C,OAAO,CAAC,aAAa;IAIrB;;;OAGG;IACH,KAAK,CAAC,KAAK,EAAE,gBAAgB,GAAG,gBAAgB,EAAE;IA6DlD;;;OAGG;IACH,GAAG,IAAI,WAAW,EAAE;IAsBpB;;OAEG;IACH,OAAO,CAAC,MAAM;CAkBf"}
@@ -0,0 +1,183 @@
1
+ "use strict";
2
+ // Copyright 2025 Prism Shadow. and/or its affiliates
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // http://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.StreamItems = void 0;
17
+ const util_1 = require("util");
18
+ const errors_1 = require("./errors");
19
+ const KINDS = {
20
+ text: { field: "text", header: [], join: (chunks) => chunks.join("") },
21
+ thinking: {
22
+ field: "thinking",
23
+ header: [],
24
+ join: (chunks) => chunks.join(""),
25
+ },
26
+ tool_call: {
27
+ field: "arguments",
28
+ header: ["name", "tool_call_id"],
29
+ join: (chunks) => chunks.join(""),
30
+ parse: (joined, client, header) => (0, errors_1.parseToolCallArguments)(joined, client, header.name, header.tool_call_id),
31
+ // a call's name comes once, on its first delta
32
+ begins: (delta) => Boolean(delta.name),
33
+ },
34
+ // an image arrives whole, while audio streams in chunks
35
+ inline_data: {
36
+ field: "data",
37
+ header: [],
38
+ join: (chunks) => Buffer.concat(chunks),
39
+ begins: (delta) => delta.mime_type.startsWith("image/"),
40
+ },
41
+ inline_thinking: {
42
+ field: "data",
43
+ header: [],
44
+ join: (chunks) => Buffer.concat(chunks),
45
+ begins: () => true,
46
+ },
47
+ // one whole vector per delta, and an empty one still stands for the input it was made of
48
+ embedding: {
49
+ field: "embedding",
50
+ header: [],
51
+ join: (chunks) => chunks.flat(),
52
+ begins: () => true,
53
+ keepsEmpty: true,
54
+ },
55
+ };
56
+ /**
57
+ * Whether a delta carries no content: its growing field and header fields are empty.
58
+ */
59
+ function isEmpty(kind, fields) {
60
+ return (!kind.keepsEmpty &&
61
+ fields[kind.field].length === 0 &&
62
+ kind.header.every((field) => !fields[field]));
63
+ }
64
+ /**
65
+ * Assembles the items of one stream from the deltas a client yields. Model output is serial, so
66
+ * the deltas of an item are contiguous and one item streams at a time: it is done when a delta of
67
+ * the next item arrives, or when the stream ends.
68
+ *
69
+ * A delta belongs to the next item when it carries another `fidelity.item_id`, is of another
70
+ * kind, or begins an item by itself (a call's name, an image, a vector). Otherwise it continues
71
+ * the item streaming now: a delta without an id does, and so do a call's arguments whatever id a
72
+ * gateway puts on them. Fidelity sent alone under the item's id is that item's, whatever kind
73
+ * carries it.
74
+ *
75
+ * Every delta goes out as it arrives, without its `item_id`. A done item is the item's first
76
+ * delta with the growing field replaced by the join of every delta's, plus the item's fidelity.
77
+ */
78
+ class StreamItems {
79
+ constructor(client) {
80
+ this.client = client;
81
+ this.item = null;
82
+ }
83
+ protocolError(message) {
84
+ return new errors_1.StreamProtocolError({ client: this.client, message });
85
+ }
86
+ /**
87
+ * One delta a client yielded. Returns what goes out: the done item of the item it ended, if
88
+ * any, then the delta itself.
89
+ */
90
+ delta(delta) {
91
+ const kind = delta.type.slice(0, -".delta".length);
92
+ if (!delta.type.endsWith(".delta") || !(kind in KINDS)) {
93
+ throw this.protocolError(`a client yields deltas, not ${delta.type}`);
94
+ }
95
+ const { fidelity: carried, ...content } = delta;
96
+ const { item_id: itemId, ...rest } = carried ?? {};
97
+ let fidelity = Object.keys(rest).length > 0 ? rest : undefined;
98
+ let fields = content;
99
+ const out = [];
100
+ let item = this.item;
101
+ if (item?.first !== undefined &&
102
+ item.kind !== kind &&
103
+ itemId &&
104
+ itemId === item.id &&
105
+ fidelity !== undefined &&
106
+ isEmpty(KINDS[kind], fields)) {
107
+ // fidelity sent alone under the item's id is that item's, whatever kind carries it
108
+ const spec = KINDS[item.kind];
109
+ fields = { ...item.first, [spec.field]: spec.join([]) };
110
+ }
111
+ else if (item === null || this.begins(item, kind, itemId, fields)) {
112
+ out.push(...this.end());
113
+ item = this.item = { kind, chunks: [] };
114
+ }
115
+ item.id = item.id || itemId;
116
+ const name = item.id ? `item ${item.id}` : "an item";
117
+ if (fidelity !== undefined) {
118
+ if (item.fidelity === undefined) {
119
+ item.fidelity = fidelity;
120
+ }
121
+ else if ((0, util_1.isDeepStrictEqual)(item.fidelity, fidelity)) {
122
+ // repeated fidelity goes out once
123
+ fidelity = undefined;
124
+ }
125
+ else {
126
+ throw this.protocolError(`${name} carried two different fidelity payloads`);
127
+ }
128
+ }
129
+ const spec = KINDS[item.kind];
130
+ if (isEmpty(spec, fields) && fidelity === undefined) {
131
+ // carries nothing; the item is streaming all the same
132
+ return out;
133
+ }
134
+ if (item.first === undefined) {
135
+ if (!spec.header.every((field) => fields[field])) {
136
+ throw this.protocolError(`the first ${fields.type} of ${name} must carry the ${spec.header.join(" and the ")}`);
137
+ }
138
+ item.first = fields;
139
+ }
140
+ item.chunks.push(fields[spec.field]);
141
+ out.push((fidelity ? { ...fields, fidelity } : fields));
142
+ return out;
143
+ }
144
+ /**
145
+ * The next item began, or the stream ended: returns the done item of the item streaming now,
146
+ * or nothing when no delta of it went out.
147
+ */
148
+ end() {
149
+ const item = this.item;
150
+ this.item = null;
151
+ if (item === null || item.first === undefined) {
152
+ return [];
153
+ }
154
+ const spec = KINDS[item.kind];
155
+ const joined = spec.join(item.chunks);
156
+ const done = {
157
+ ...item.first,
158
+ type: `${item.kind}.done`,
159
+ [spec.field]: spec.parse
160
+ ? spec.parse(joined, this.client, item.first)
161
+ : joined,
162
+ };
163
+ if (item.fidelity !== undefined) {
164
+ done.fidelity = item.fidelity;
165
+ }
166
+ return [done];
167
+ }
168
+ /**
169
+ * Whether a delta begins the next item rather than continuing the one streaming now.
170
+ */
171
+ begins(item, kind, itemId, fields) {
172
+ const spec = KINDS[kind];
173
+ if (item.kind !== kind || spec.begins?.(fields)) {
174
+ return true;
175
+ }
176
+ // what cannot begin an item (a call's arguments) continues the one streaming now
177
+ return (spec.header.length === 0 &&
178
+ Boolean(itemId) &&
179
+ Boolean(item.id) &&
180
+ itemId !== item.id);
181
+ }
182
+ }
183
+ exports.StreamItems = StreamItems;
@@ -0,0 +1,190 @@
1
+ /**
2
+ * Thinking level for model reasoning.
3
+ */
4
+ export declare enum ThinkingLevel {
5
+ NONE = "none",
6
+ LOW = "low",
7
+ MEDIUM = "medium",
8
+ HIGH = "high",
9
+ XHIGH = "xhigh",
10
+ MAX = "max"
11
+ }
12
+ /**
13
+ * Prompt cache configuration for Claude models.
14
+ */
15
+ export declare enum PromptCaching {
16
+ ENABLE = "enable",
17
+ DISABLE = "disable",
18
+ ENHANCE = "enhance"
19
+ }
20
+ export type ToolChoice = ("auto" | "required" | "none") | string[];
21
+ export type Role = "user" | "assistant";
22
+ export type EventType = "delta" | "stop";
23
+ export type FinishReason = "stop" | "length" | "tool_call" | "unknown";
24
+ export type AspectRatio = "1:1" | "2:3" | "3:2" | "3:4" | "4:3" | "9:16" | "16:9" | "21:9";
25
+ export type ImageSize = "1K" | "2K";
26
+ /**
27
+ * Arbitrary JSON-style payload of wire-fidelity data recorded by a client,
28
+ * such as thinking signatures, phase labels, or the upstream reasoning field
29
+ * name. Opaque to consumers: pass it back unchanged so a replay reproduces
30
+ * the original wire message.
31
+ */
32
+ export type Fidelity = Record<string, any>;
33
+ export interface TextDoneItem {
34
+ type: "text.done";
35
+ text: string;
36
+ fidelity?: Fidelity;
37
+ }
38
+ export interface ImageUrlDoneItem {
39
+ type: "image_url.done";
40
+ image_url: string;
41
+ }
42
+ export interface InlineDataDoneItem {
43
+ type: "inline_data.done";
44
+ data: Buffer;
45
+ mime_type: string;
46
+ fidelity?: Fidelity;
47
+ }
48
+ export interface ThinkingDoneItem {
49
+ type: "thinking.done";
50
+ thinking: string;
51
+ fidelity?: Fidelity;
52
+ }
53
+ export interface InlineThinkingDoneItem {
54
+ type: "inline_thinking.done";
55
+ data: Buffer;
56
+ mime_type: string;
57
+ fidelity?: Fidelity;
58
+ }
59
+ export interface ToolCallDoneItem {
60
+ type: "tool_call.done";
61
+ name: string;
62
+ arguments: Record<string, any>;
63
+ tool_call_id: string;
64
+ fidelity?: Fidelity;
65
+ }
66
+ export interface ToolResultDoneItem {
67
+ type: "tool_result.done";
68
+ text: string;
69
+ images?: string[];
70
+ tool_call_id: string;
71
+ }
72
+ export interface EmbeddingDoneItem {
73
+ type: "embedding.done";
74
+ embedding: number[];
75
+ }
76
+ export type ContentItem = TextDoneItem | ImageUrlDoneItem | InlineDataDoneItem | ThinkingDoneItem | InlineThinkingDoneItem | ToolCallDoneItem | ToolResultDoneItem | EmbeddingDoneItem;
77
+ export interface TextDeltaItem {
78
+ type: "text.delta";
79
+ text: string;
80
+ fidelity?: Fidelity;
81
+ }
82
+ export interface InlineDataDeltaItem {
83
+ type: "inline_data.delta";
84
+ data: Buffer;
85
+ mime_type: string;
86
+ fidelity?: Fidelity;
87
+ }
88
+ export interface ThinkingDeltaItem {
89
+ type: "thinking.delta";
90
+ thinking: string;
91
+ fidelity?: Fidelity;
92
+ }
93
+ export interface InlineThinkingDeltaItem {
94
+ type: "inline_thinking.delta";
95
+ data: Buffer;
96
+ mime_type: string;
97
+ fidelity?: Fidelity;
98
+ }
99
+ export interface ToolCallDeltaItem {
100
+ type: "tool_call.delta";
101
+ name: string;
102
+ arguments: string;
103
+ tool_call_id: string;
104
+ fidelity?: Fidelity;
105
+ }
106
+ export interface EmbeddingDeltaItem {
107
+ type: "embedding.delta";
108
+ embedding: number[];
109
+ }
110
+ export type DeltaContentItem = TextDeltaItem | InlineDataDeltaItem | ThinkingDeltaItem | InlineThinkingDeltaItem | ToolCallDeltaItem | EmbeddingDeltaItem;
111
+ export type EventContentItem = DeltaContentItem | ContentItem;
112
+ /**
113
+ * Usage metadata for model response.
114
+ */
115
+ export interface UsageMetadata {
116
+ cached_tokens: number | null;
117
+ prompt_tokens: number | null;
118
+ thoughts_tokens: number | null;
119
+ response_tokens: number | null;
120
+ }
121
+ /**
122
+ * Universal message format for LLM communication.
123
+ */
124
+ export interface UniMessage {
125
+ role: Role;
126
+ content_items: ContentItem[];
127
+ usage_metadata?: UsageMetadata | null;
128
+ finish_reason?: FinishReason | null;
129
+ created_at?: number;
130
+ }
131
+ /**
132
+ * Universal event format for streaming responses: a "delta" event carries exactly one delta or
133
+ * done item and no usage or finish reason; the one "stop" event that ends every successful
134
+ * stream carries no items and both.
135
+ */
136
+ export interface UniEvent {
137
+ role: Role;
138
+ event_type: EventType;
139
+ content_items: EventContentItem[];
140
+ usage_metadata: UsageMetadata | null;
141
+ finish_reason: FinishReason | null;
142
+ created_at?: number;
143
+ }
144
+ /**
145
+ * Available tool schema.
146
+ */
147
+ export interface ToolSchema {
148
+ name: string;
149
+ description: string;
150
+ parameters?: Record<string, any>;
151
+ }
152
+ /**
153
+ * Image generation configuration for models that support image output.
154
+ */
155
+ export interface ImageConfig {
156
+ aspect_ratio?: AspectRatio;
157
+ image_size?: ImageSize;
158
+ }
159
+ /**
160
+ * Speaker and voice assignment for TTS.
161
+ */
162
+ export interface SpeakerConfig {
163
+ voice: string;
164
+ speaker?: string;
165
+ }
166
+ /**
167
+ * Embedding generation configuration.
168
+ */
169
+ export interface EmbeddingConfig {
170
+ dimensions?: number;
171
+ }
172
+ /**
173
+ * Universal configuration format for LLM requests.
174
+ */
175
+ export interface UniConfig {
176
+ max_tokens?: number;
177
+ temperature?: number;
178
+ tools?: ToolSchema[];
179
+ thinking_summary?: boolean;
180
+ thinking_level?: ThinkingLevel;
181
+ tool_choice?: ToolChoice;
182
+ system_prompt?: string;
183
+ prompt_caching?: PromptCaching;
184
+ fast_mode?: boolean;
185
+ image_config?: ImageConfig;
186
+ tts_config?: SpeakerConfig[];
187
+ embedding_config?: EmbeddingConfig;
188
+ trace_id?: string;
189
+ }
190
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAcA;;GAEG;AACH,o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shadow. and/or its affiliates
3
+ //
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // http://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.PromptCaching = exports.ThinkingLevel = void 0;
17
+ /**
18
+ * Thinking level for model reasoning.
19
+ */
20
+ var ThinkingLevel;
21
+ (function (ThinkingLevel) {
22
+ ThinkingLevel["NONE"] = "none";
23
+ ThinkingLevel["LOW"] = "low";
24
+ ThinkingLevel["MEDIUM"] = "medium";
25
+ ThinkingLevel["HIGH"] = "high";
26
+ ThinkingLevel["XHIGH"] = "xhigh";
27
+ ThinkingLevel["MAX"] = "max";
28
+ })(ThinkingLevel || (exports.ThinkingLevel = ThinkingLevel = {}));
29
+ /**
30
+ * Prompt cache configuration for Claude models.
31
+ */
32
+ var PromptCaching;
33
+ (function (PromptCaching) {
34
+ PromptCaching["ENABLE"] = "enable";
35
+ PromptCaching["DISABLE"] = "disable";
36
+ PromptCaching["ENHANCE"] = "enhance";
37
+ })(PromptCaching || (exports.PromptCaching = PromptCaching = {}));
@@ -0,0 +1,99 @@
1
+ import { UsageMetadata } from "./types";
2
+ /**
3
+ * Fix the usage metadata for OpenRouter.
4
+ *
5
+ * OpenRouter occasionally does not include the reasoning tokens to the completion tokens.
6
+ *
7
+ * @param usageMetadata - The usage metadata.
8
+ * @param baseUrl - The API URL.
9
+ * @returns The fixed usage metadata.
10
+ */
11
+ export declare function fixOpenrouterUsageMetadata(usageMetadata: UsageMetadata, baseUrl: string): UsageMetadata;
12
+ /**
13
+ * Whether MMSP_DEBUG asks the clients to fail loudly on output they do not recognize.
14
+ *
15
+ * Streaming clients skip an unrecognized event so that a gateway's own frames cannot
16
+ * kill a long generation. The same silence hides a genuinely new provider event, so the
17
+ * guards stay one environment variable away.
18
+ *
19
+ * @returns Whether debug mode is on.
20
+ */
21
+ /**
22
+ * The key and the endpoint of a client that reads the environment's OPENAI_API_KEY or
23
+ * ANTHROPIC_API_KEY. A key passed in is used as it is. Without one, the environment's key goes
24
+ * out only to the endpoint the environment names: a base URL passed in is another endpoint,
25
+ * which that key was not given for, so it needs a key of its own.
26
+ *
27
+ * @param client - The client's class name, for the error
28
+ * @param options - The key and the base URL passed to the client
29
+ * @param env - The environment variables that hold the key and the base URL
30
+ * @returns The key and the base URL to build the SDK client with, either of which may be undefined
31
+ */
32
+ export declare function resolveCredentials(client: string, options: {
33
+ apiKey?: string;
34
+ baseUrl?: string | null;
35
+ }, env: {
36
+ key: string;
37
+ baseUrl: string;
38
+ }): {
39
+ apiKey: string | undefined;
40
+ baseUrl: string | undefined;
41
+ };
42
+ export declare function isDebugEnabled(): boolean;
43
+ /** Pixel dimensions read from an image header. */
44
+ export interface ImageDimensions {
45
+ width: number;
46
+ height: number;
47
+ }
48
+ /**
49
+ * Read the pixel dimensions from the header of a PNG, JPEG, GIF or WebP image.
50
+ *
51
+ * Only the header is inspected, so the bytes may be a prefix of the file; a
52
+ * prefix that ends before the dimensions are reached reads as unrecognized.
53
+ *
54
+ * @param bytes - The image bytes, or a prefix of them.
55
+ * @returns The dimensions, or null when the bytes are not a recognized image.
56
+ */
57
+ export declare function imageDimensions(bytes: Buffer): ImageDimensions | null;
58
+ /**
59
+ * Whether the OpenAI vision API would reject an image at `original` detail.
60
+ *
61
+ * The API covers an image with 32-pixel patches and rejects one that needs
62
+ * more than 30,000 of them after its own resizing; at `original` detail the
63
+ * only resizing is the 65,535-pixel cap on either side. Only a base64 data URL
64
+ * can be measured here: an HTTP(S) URL answers false. The Responses clients
65
+ * pass such a URL through for the API to fetch; the Chat client fetches it
66
+ * into a data URL first, so it measures the fetched bytes.
67
+ *
68
+ * @param imageUrl - The image URL.
69
+ * @returns Whether the API would reject the image.
70
+ */
71
+ export declare function exceedsOpenaiPatchLimit(imageUrl: string): boolean;
72
+ /**
73
+ * The `detail` an OpenAI image part needs so that the API reads the image.
74
+ *
75
+ * GPT-5.6 reads the default `auto` detail as `original`, which keeps the
76
+ * image's own dimensions and rejects one over 30,000 patches instead of
77
+ * resizing it; `high` has the API fit it into 2,500 patches, so the image is
78
+ * read instead of refused. Every other model keeps a patch budget at every
79
+ * detail level, so no other model gets the field.
80
+ *
81
+ * @param model - The model id the request is sent with.
82
+ * @param imageUrl - The image URL as it goes on the wire.
83
+ * @returns `"high"` when the image needs it, otherwise undefined.
84
+ */
85
+ export declare function openaiImageDetail(model: string, imageUrl: string): "high" | undefined;
86
+ /**
87
+ * Split a two-speaker TTS script into turns, for the TTS models that take each turn's speaker
88
+ * as metadata rather than as a label in the text.
89
+ *
90
+ * A line that starts with a configured speaker's name and a colon ("Joe: How's it going?")
91
+ * begins that speaker's turn; any other line continues the turn before it.
92
+ *
93
+ * @param text - The script, one "Name: line" per turn
94
+ * @param speakers - The speaker names the request configures
95
+ * @returns [speaker, text] per turn, in order
96
+ * @throws Error when the script does not begin with a speaker's label
97
+ */
98
+ export declare function speakerTurns(text: string, speakers: string[]): [string, string][];
99
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CACxC,aAAa,EAAE,aAAa,EAC5B,OAAO,EAAE,MAAM,GACd,aAAa,CAYf;AAED;;;;;;;;GAQG;AACH;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,C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