@osdk/aip-core 0.2.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 (131) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +211 -0
  3. package/ai-sdk.d.ts +17 -0
  4. package/build/browser/ai-sdk/convert-prompt.js +136 -0
  5. package/build/browser/ai-sdk/convert-prompt.js.map +1 -0
  6. package/build/browser/ai-sdk/foundry-chat-language-model.js +386 -0
  7. package/build/browser/ai-sdk/foundry-chat-language-model.js.map +1 -0
  8. package/build/browser/ai-sdk/map-finish-reason.js +42 -0
  9. package/build/browser/ai-sdk/map-finish-reason.js.map +1 -0
  10. package/build/browser/ai-sdk/provider.js +62 -0
  11. package/build/browser/ai-sdk/provider.js.map +1 -0
  12. package/build/browser/ai-sdk/types.js +2 -0
  13. package/build/browser/ai-sdk/types.js.map +1 -0
  14. package/build/browser/generateText.js +76 -0
  15. package/build/browser/generateText.js.map +1 -0
  16. package/build/browser/index.js +23 -0
  17. package/build/browser/index.js.map +1 -0
  18. package/build/browser/internal/__test__/mockPlatformClient.js +36 -0
  19. package/build/browser/internal/__test__/mockPlatformClient.js.map +1 -0
  20. package/build/browser/internal/ids.js +23 -0
  21. package/build/browser/internal/ids.js.map +1 -0
  22. package/build/browser/internal/openAi.js +293 -0
  23. package/build/browser/internal/openAi.js.map +1 -0
  24. package/build/browser/internal/options.js +58 -0
  25. package/build/browser/internal/options.js.map +1 -0
  26. package/build/browser/internal/runStep.js +107 -0
  27. package/build/browser/internal/runStep.js.map +1 -0
  28. package/build/browser/internal/streamStep.js +223 -0
  29. package/build/browser/internal/streamStep.js.map +1 -0
  30. package/build/browser/internal/uiMessageBridge.js +55 -0
  31. package/build/browser/internal/uiMessageBridge.js.map +1 -0
  32. package/build/browser/lmsChatTransport.js +185 -0
  33. package/build/browser/lmsChatTransport.js.map +1 -0
  34. package/build/browser/model.js +74 -0
  35. package/build/browser/model.js.map +1 -0
  36. package/build/browser/public/ai-sdk.js +18 -0
  37. package/build/browser/public/ai-sdk.js.map +1 -0
  38. package/build/browser/streamText.js +210 -0
  39. package/build/browser/streamText.js.map +1 -0
  40. package/build/browser/types.js +2 -0
  41. package/build/browser/types.js.map +1 -0
  42. package/build/browser/uiMessage.js +34 -0
  43. package/build/browser/uiMessage.js.map +1 -0
  44. package/build/cjs/index.cjs +1012 -0
  45. package/build/cjs/index.cjs.map +1 -0
  46. package/build/cjs/index.d.cts +467 -0
  47. package/build/cjs/model-B5uS56VB.d.cts +45 -0
  48. package/build/cjs/public/ai-sdk.cjs +534 -0
  49. package/build/cjs/public/ai-sdk.cjs.map +1 -0
  50. package/build/cjs/public/ai-sdk.d.cts +49 -0
  51. package/build/esm/ai-sdk/convert-prompt.js +136 -0
  52. package/build/esm/ai-sdk/convert-prompt.js.map +1 -0
  53. package/build/esm/ai-sdk/foundry-chat-language-model.js +386 -0
  54. package/build/esm/ai-sdk/foundry-chat-language-model.js.map +1 -0
  55. package/build/esm/ai-sdk/map-finish-reason.js +42 -0
  56. package/build/esm/ai-sdk/map-finish-reason.js.map +1 -0
  57. package/build/esm/ai-sdk/provider.js +62 -0
  58. package/build/esm/ai-sdk/provider.js.map +1 -0
  59. package/build/esm/ai-sdk/types.js +2 -0
  60. package/build/esm/ai-sdk/types.js.map +1 -0
  61. package/build/esm/generateText.js +76 -0
  62. package/build/esm/generateText.js.map +1 -0
  63. package/build/esm/index.js +23 -0
  64. package/build/esm/index.js.map +1 -0
  65. package/build/esm/internal/__test__/mockPlatformClient.js +36 -0
  66. package/build/esm/internal/__test__/mockPlatformClient.js.map +1 -0
  67. package/build/esm/internal/ids.js +23 -0
  68. package/build/esm/internal/ids.js.map +1 -0
  69. package/build/esm/internal/openAi.js +293 -0
  70. package/build/esm/internal/openAi.js.map +1 -0
  71. package/build/esm/internal/options.js +58 -0
  72. package/build/esm/internal/options.js.map +1 -0
  73. package/build/esm/internal/runStep.js +107 -0
  74. package/build/esm/internal/runStep.js.map +1 -0
  75. package/build/esm/internal/streamStep.js +223 -0
  76. package/build/esm/internal/streamStep.js.map +1 -0
  77. package/build/esm/internal/uiMessageBridge.js +55 -0
  78. package/build/esm/internal/uiMessageBridge.js.map +1 -0
  79. package/build/esm/lmsChatTransport.js +185 -0
  80. package/build/esm/lmsChatTransport.js.map +1 -0
  81. package/build/esm/model.js +74 -0
  82. package/build/esm/model.js.map +1 -0
  83. package/build/esm/public/ai-sdk.js +18 -0
  84. package/build/esm/public/ai-sdk.js.map +1 -0
  85. package/build/esm/streamText.js +210 -0
  86. package/build/esm/streamText.js.map +1 -0
  87. package/build/esm/types.js +2 -0
  88. package/build/esm/types.js.map +1 -0
  89. package/build/esm/uiMessage.js +34 -0
  90. package/build/esm/uiMessage.js.map +1 -0
  91. package/build/types/ai-sdk/convert-prompt.d.ts +19 -0
  92. package/build/types/ai-sdk/convert-prompt.d.ts.map +1 -0
  93. package/build/types/ai-sdk/foundry-chat-language-model.d.ts +20 -0
  94. package/build/types/ai-sdk/foundry-chat-language-model.d.ts.map +1 -0
  95. package/build/types/ai-sdk/map-finish-reason.d.ts +2 -0
  96. package/build/types/ai-sdk/map-finish-reason.d.ts.map +1 -0
  97. package/build/types/ai-sdk/provider.d.ts +46 -0
  98. package/build/types/ai-sdk/provider.d.ts.map +1 -0
  99. package/build/types/ai-sdk/types.d.ts +1 -0
  100. package/build/types/ai-sdk/types.d.ts.map +1 -0
  101. package/build/types/generateText.d.ts +56 -0
  102. package/build/types/generateText.d.ts.map +1 -0
  103. package/build/types/index.d.ts +12 -0
  104. package/build/types/index.d.ts.map +1 -0
  105. package/build/types/internal/__test__/mockPlatformClient.d.ts +13 -0
  106. package/build/types/internal/__test__/mockPlatformClient.d.ts.map +1 -0
  107. package/build/types/internal/ids.d.ts +1 -0
  108. package/build/types/internal/ids.d.ts.map +1 -0
  109. package/build/types/internal/openAi.d.ts +107 -0
  110. package/build/types/internal/openAi.d.ts.map +1 -0
  111. package/build/types/internal/options.d.ts +4 -0
  112. package/build/types/internal/options.d.ts.map +1 -0
  113. package/build/types/internal/runStep.d.ts +29 -0
  114. package/build/types/internal/runStep.d.ts.map +1 -0
  115. package/build/types/internal/streamStep.d.ts +52 -0
  116. package/build/types/internal/streamStep.d.ts.map +1 -0
  117. package/build/types/internal/uiMessageBridge.d.ts +15 -0
  118. package/build/types/internal/uiMessageBridge.d.ts.map +1 -0
  119. package/build/types/lmsChatTransport.d.ts +35 -0
  120. package/build/types/lmsChatTransport.d.ts.map +1 -0
  121. package/build/types/model.d.ts +42 -0
  122. package/build/types/model.d.ts.map +1 -0
  123. package/build/types/public/ai-sdk.d.ts +2 -0
  124. package/build/types/public/ai-sdk.d.ts.map +1 -0
  125. package/build/types/streamText.d.ts +82 -0
  126. package/build/types/streamText.d.ts.map +1 -0
  127. package/build/types/types.d.ts +189 -0
  128. package/build/types/types.d.ts.map +1 -0
  129. package/build/types/uiMessage.d.ts +85 -0
  130. package/build/types/uiMessage.d.ts.map +1 -0
  131. package/package.json +87 -0
@@ -0,0 +1,45 @@
1
+ import { PlatformClient } from '@osdk/client';
2
+
3
+ /**
4
+ * Identifies a model in the Foundry Language Model Service.
5
+ *
6
+ * - `lmsModel`: a built-in LMS model addressed by `apiName` (e.g. "gpt-4o")
7
+ * - `registeredModel`: a customer-registered model addressed by RID
8
+ */
9
+ type ModelIdentifier = {
10
+ type: "lmsModel";
11
+ apiName: string;
12
+ } | {
13
+ type: "registeredModel";
14
+ registeredModelRid: string;
15
+ };
16
+ /** Opaque language model handle accepted by `generateText` / `streamText`. */
17
+ interface LanguageModel {
18
+ /** Stable identifier for logging / telemetry, e.g. "foundry/gpt-4o". */
19
+ readonly modelId: string;
20
+ /** Provider tag — `"foundry-lms"` for the built-in LMS adapter. */
21
+ readonly provider: string;
22
+ }
23
+ interface FoundryModelOptions {
24
+ /** Foundry PlatformClient providing the auth token + base URL. */
25
+ client: PlatformClient;
26
+ /** LMS model API name or registered model RID. */
27
+ model: string | ModelIdentifier;
28
+ }
29
+ /**
30
+ * Construct a Foundry-LMS-backed {@link LanguageModel}.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * import { foundryModel, generateText } from "@osdk/aip-core";
35
+ *
36
+ * const model = foundryModel({ client, model: "gpt-4o" });
37
+ * const { text } = await generateText({
38
+ * model,
39
+ * prompt: "Hello, world",
40
+ * });
41
+ * ```
42
+ */
43
+ declare function foundryModel(options: FoundryModelOptions): LanguageModel;
44
+
45
+ export { type FoundryModelOptions as F, type LanguageModel as L, type ModelIdentifier as M, foundryModel as f };
@@ -0,0 +1,534 @@
1
+ 'use strict';
2
+
3
+ var languageModels = require('@osdk/language-models');
4
+
5
+ // src/ai-sdk/foundry-chat-language-model.ts
6
+
7
+ // src/ai-sdk/convert-prompt.ts
8
+ function convertPrompt(prompt, warnings) {
9
+ const messages = [];
10
+ for (const message of prompt) {
11
+ messages.push(...convertMessage(message, warnings));
12
+ }
13
+ return messages;
14
+ }
15
+ function convertMessage(message, warnings) {
16
+ switch (message.role) {
17
+ case "system":
18
+ return [{
19
+ role: "system",
20
+ content: message.content
21
+ }];
22
+ case "user": {
23
+ const parts = [];
24
+ for (const part of message.content) {
25
+ switch (part.type) {
26
+ case "text":
27
+ parts.push({
28
+ type: "text",
29
+ text: part.text
30
+ });
31
+ break;
32
+ case "file":
33
+ warnings.push({
34
+ type: "unsupported",
35
+ feature: "user file content",
36
+ details: "File content in user messages is not supported in v0 \u2014 ignored"
37
+ });
38
+ break;
39
+ }
40
+ }
41
+ if (parts.length === 0) {
42
+ parts.push({
43
+ type: "text",
44
+ text: ""
45
+ });
46
+ }
47
+ return [{
48
+ role: "user",
49
+ content: parts
50
+ }];
51
+ }
52
+ case "assistant": {
53
+ let text = "";
54
+ const toolCalls = [];
55
+ for (const part of message.content) {
56
+ switch (part.type) {
57
+ case "text":
58
+ text += part.text;
59
+ break;
60
+ case "tool-call":
61
+ toolCalls.push({
62
+ id: part.toolCallId,
63
+ type: "function",
64
+ function: {
65
+ name: part.toolName,
66
+ arguments: typeof part.input === "string" ? part.input : JSON.stringify(part.input ?? {})
67
+ }
68
+ });
69
+ break;
70
+ case "reasoning":
71
+ case "file":
72
+ case "tool-result":
73
+ warnings.push({
74
+ type: "unsupported",
75
+ feature: `assistant ${part.type} content`,
76
+ details: `"${part.type}" parts in assistant messages are not supported in v0 \u2014 ignored`
77
+ });
78
+ break;
79
+ }
80
+ }
81
+ return [{
82
+ role: "assistant",
83
+ content: text.length > 0 ? text : null,
84
+ tool_calls: toolCalls.length > 0 ? toolCalls : void 0
85
+ }];
86
+ }
87
+ case "tool":
88
+ return message.content.filter((part) => {
89
+ if (part.type === "tool-result") return true;
90
+ warnings.push({
91
+ type: "unsupported",
92
+ feature: `tool ${part.type} content`,
93
+ details: `"${part.type}" parts in tool messages are not supported in v0 \u2014 ignored`
94
+ });
95
+ return false;
96
+ }).map((part) => ({
97
+ role: "tool",
98
+ content: stringifyToolResult(part.output, warnings),
99
+ tool_call_id: part.toolCallId
100
+ }));
101
+ }
102
+ }
103
+ function stringifyToolResult(output, warnings) {
104
+ switch (output.type) {
105
+ case "text":
106
+ case "error-text":
107
+ return output.value;
108
+ case "json":
109
+ case "error-json":
110
+ return JSON.stringify(output.value);
111
+ case "execution-denied":
112
+ return output.reason ?? "Tool execution denied";
113
+ case "content":
114
+ return output.value.map((c) => {
115
+ if (c.type === "text") return c.text;
116
+ warnings.push({
117
+ type: "unsupported",
118
+ feature: "tool result media content",
119
+ details: "Non-text tool result content is not supported in v0 \u2014 ignored"
120
+ });
121
+ return "";
122
+ }).filter((s) => s.length > 0).join("\n");
123
+ }
124
+ }
125
+
126
+ // src/ai-sdk/map-finish-reason.ts
127
+ function mapFinishReason(raw) {
128
+ let unified;
129
+ switch (raw) {
130
+ case "stop":
131
+ unified = "stop";
132
+ break;
133
+ case "length":
134
+ unified = "length";
135
+ break;
136
+ case "tool_calls":
137
+ case "function_call":
138
+ unified = "tool-calls";
139
+ break;
140
+ case "content_filter":
141
+ unified = "content-filter";
142
+ break;
143
+ default:
144
+ unified = "other";
145
+ break;
146
+ }
147
+ return {
148
+ unified,
149
+ raw
150
+ };
151
+ }
152
+
153
+ // src/ai-sdk/foundry-chat-language-model.ts
154
+ var FoundryChatLanguageModel = class {
155
+ specificationVersion = "v3";
156
+ supportedUrls = {};
157
+ constructor(modelId, config) {
158
+ this.provider = "foundry-lms";
159
+ this.modelId = modelId;
160
+ this.config = config;
161
+ }
162
+ async doGenerate(options) {
163
+ const warnings = [];
164
+ const {
165
+ body,
166
+ url
167
+ } = this.buildRequest(options, warnings);
168
+ const res = await this.config.client.fetch(url, {
169
+ method: "POST",
170
+ headers: filterHeaders({
171
+ "Content-Type": "application/json",
172
+ Accept: "application/json",
173
+ ...options.headers ?? {}
174
+ }),
175
+ body: JSON.stringify(body),
176
+ signal: options.abortSignal
177
+ });
178
+ if (!res.ok) {
179
+ const errBody = await safeReadText(res);
180
+ throw new Error(`LMS chat/completions request failed: ${res.status} ${res.statusText}` + (errBody ? ` \u2014 ${errBody}` : ""));
181
+ }
182
+ const data = await res.json();
183
+ return this.parseGenerateResponse(data, body, warnings);
184
+ }
185
+ async doStream(options) {
186
+ const warnings = [];
187
+ const {
188
+ body,
189
+ url
190
+ } = this.buildRequest(options, warnings);
191
+ body.stream = true;
192
+ const res = await this.config.client.fetch(url, {
193
+ method: "POST",
194
+ headers: filterHeaders({
195
+ "Content-Type": "application/json",
196
+ Accept: "text/event-stream",
197
+ ...options.headers ?? {}
198
+ }),
199
+ body: JSON.stringify(body),
200
+ signal: options.abortSignal
201
+ });
202
+ if (!res.ok) {
203
+ const errBody = await safeReadText(res);
204
+ throw new Error(`LMS chat/completions request failed: ${res.status} ${res.statusText}` + (errBody ? ` \u2014 ${errBody}` : ""));
205
+ }
206
+ const stream = this.parseStreamResponse(res, body, warnings);
207
+ return {
208
+ stream,
209
+ request: {
210
+ body
211
+ }
212
+ };
213
+ }
214
+ buildRequest(options, warnings) {
215
+ const baseUrl = languageModels.getOpenAiBaseUrl(this.config.client);
216
+ const url = new URL("chat/completions", `${baseUrl}/`).toString();
217
+ const apiName = this.config.identifier.type === "lmsModel" ? this.config.identifier.apiName : this.config.identifier.registeredModelRid;
218
+ const messages = convertPrompt(options.prompt, warnings);
219
+ const tools = options.tools?.filter((t) => {
220
+ if (t.type === "function") return true;
221
+ warnings.push({
222
+ type: "unsupported",
223
+ feature: `${t.type} tool type`,
224
+ details: `Only "function" tools are supported; "${t.type}" tools are ignored`
225
+ });
226
+ return false;
227
+ }).map((t) => ({
228
+ type: "function",
229
+ function: {
230
+ name: t.name,
231
+ description: t.description,
232
+ parameters: t.inputSchema
233
+ }
234
+ }));
235
+ const toolChoice = convertToolChoice(options.toolChoice);
236
+ if (options.topK != null) {
237
+ warnings.push({
238
+ type: "unsupported",
239
+ feature: "topK",
240
+ details: "topK is not supported by the Foundry LMS OpenAI proxy \u2014 ignored"
241
+ });
242
+ }
243
+ if (options.responseFormat?.type === "json") {
244
+ warnings.push({
245
+ type: "unsupported",
246
+ feature: "JSON response format",
247
+ details: "Structured JSON output is not supported in v0 \u2014 ignored"
248
+ });
249
+ }
250
+ const body = {
251
+ model: apiName,
252
+ messages,
253
+ max_tokens: options.maxOutputTokens,
254
+ temperature: options.temperature,
255
+ top_p: options.topP,
256
+ stop: options.stopSequences,
257
+ seed: options.seed,
258
+ presence_penalty: options.presencePenalty,
259
+ frequency_penalty: options.frequencyPenalty,
260
+ tools: tools != null && tools.length > 0 ? tools : void 0,
261
+ tool_choice: toolChoice,
262
+ stream: false
263
+ };
264
+ return {
265
+ body,
266
+ url
267
+ };
268
+ }
269
+ parseGenerateResponse(res, request, warnings) {
270
+ const choice = res.choices[0];
271
+ if (choice == null) {
272
+ throw new Error("LMS chat/completions response did not include any choices");
273
+ }
274
+ const message = choice.message;
275
+ const content = [];
276
+ if (message.content != null && message.content.length > 0) {
277
+ content.push({
278
+ type: "text",
279
+ text: message.content
280
+ });
281
+ }
282
+ const reasoningText = message.reasoning ?? message.reasoning_content;
283
+ if (reasoningText != null) {
284
+ content.push({
285
+ type: "reasoning",
286
+ text: reasoningText
287
+ });
288
+ }
289
+ if (message.tool_calls != null) {
290
+ for (const tc of message.tool_calls) {
291
+ content.push({
292
+ type: "tool-call",
293
+ toolCallId: tc.id,
294
+ toolName: tc.function.name,
295
+ input: tc.function.arguments
296
+ });
297
+ }
298
+ }
299
+ return {
300
+ content,
301
+ finishReason: mapFinishReason(choice.finish_reason),
302
+ usage: mapUsage(res.usage),
303
+ request: {
304
+ body: request
305
+ },
306
+ response: {
307
+ id: res.id,
308
+ modelId: res.model,
309
+ timestamp: new Date(res.created * 1e3),
310
+ body: res
311
+ },
312
+ warnings
313
+ };
314
+ }
315
+ parseStreamResponse(res, request, warnings) {
316
+ const body = res.body;
317
+ if (body == null) {
318
+ throw new Error("LMS streaming response has no body");
319
+ }
320
+ const reader = body.getReader();
321
+ const decoder = new TextDecoder();
322
+ let buffer = "";
323
+ let sentStart = false;
324
+ const textId = "text-0";
325
+ let textStarted = false;
326
+ const toolInputStarted = /* @__PURE__ */ new Set();
327
+ return new ReadableStream({
328
+ pull: async (controller) => {
329
+ while (true) {
330
+ const {
331
+ done,
332
+ value
333
+ } = await reader.read();
334
+ if (done) {
335
+ if (textStarted) {
336
+ controller.enqueue({
337
+ type: "text-end",
338
+ id: textId
339
+ });
340
+ }
341
+ controller.close();
342
+ return;
343
+ }
344
+ buffer += decoder.decode(value, {
345
+ stream: true
346
+ });
347
+ const lines = buffer.split("\n");
348
+ buffer = lines.pop() ?? "";
349
+ for (const line of lines) {
350
+ const trimmed = line.trim();
351
+ if (!trimmed.startsWith("data:")) continue;
352
+ const data = trimmed.slice(5).trim();
353
+ if (data === "[DONE]") {
354
+ if (textStarted) {
355
+ controller.enqueue({
356
+ type: "text-end",
357
+ id: textId
358
+ });
359
+ }
360
+ controller.close();
361
+ return;
362
+ }
363
+ let chunk;
364
+ try {
365
+ chunk = JSON.parse(data);
366
+ } catch {
367
+ continue;
368
+ }
369
+ if (!sentStart) {
370
+ sentStart = true;
371
+ controller.enqueue({
372
+ type: "stream-start",
373
+ warnings
374
+ });
375
+ controller.enqueue({
376
+ type: "response-metadata",
377
+ id: chunk.id,
378
+ modelId: chunk.model,
379
+ timestamp: new Date(chunk.created * 1e3)
380
+ });
381
+ }
382
+ const delta = chunk.choices?.[0]?.delta;
383
+ if (delta == null) {
384
+ if (chunk.usage != null) {
385
+ controller.enqueue({
386
+ type: "finish",
387
+ usage: mapUsage(chunk.usage),
388
+ finishReason: mapFinishReason(chunk.choices?.[0]?.finish_reason ?? void 0)
389
+ });
390
+ }
391
+ continue;
392
+ }
393
+ if (delta.content != null && delta.content.length > 0) {
394
+ if (!textStarted) {
395
+ textStarted = true;
396
+ controller.enqueue({
397
+ type: "text-start",
398
+ id: textId
399
+ });
400
+ }
401
+ controller.enqueue({
402
+ type: "text-delta",
403
+ id: textId,
404
+ delta: delta.content
405
+ });
406
+ }
407
+ if (delta.tool_calls != null) {
408
+ for (const tc of delta.tool_calls) {
409
+ const id = tc.id ?? `tool-${tc.index}`;
410
+ if (tc.function?.name != null && !toolInputStarted.has(id)) {
411
+ if (textStarted) {
412
+ textStarted = false;
413
+ controller.enqueue({
414
+ type: "text-end",
415
+ id: textId
416
+ });
417
+ }
418
+ toolInputStarted.add(id);
419
+ controller.enqueue({
420
+ type: "tool-input-start",
421
+ id,
422
+ toolName: tc.function.name
423
+ });
424
+ }
425
+ if (tc.function?.arguments != null) {
426
+ controller.enqueue({
427
+ type: "tool-input-delta",
428
+ id,
429
+ delta: tc.function.arguments
430
+ });
431
+ }
432
+ }
433
+ }
434
+ const finishReason = chunk.choices?.[0]?.finish_reason;
435
+ if (finishReason != null) {
436
+ if (textStarted) {
437
+ textStarted = false;
438
+ controller.enqueue({
439
+ type: "text-end",
440
+ id: textId
441
+ });
442
+ }
443
+ for (const id of toolInputStarted) {
444
+ controller.enqueue({
445
+ type: "tool-input-end",
446
+ id
447
+ });
448
+ }
449
+ controller.enqueue({
450
+ type: "finish",
451
+ usage: mapUsage(chunk.usage),
452
+ finishReason: mapFinishReason(finishReason)
453
+ });
454
+ }
455
+ }
456
+ }
457
+ },
458
+ cancel: () => {
459
+ void reader.cancel();
460
+ }
461
+ });
462
+ }
463
+ };
464
+ function convertToolChoice(choice) {
465
+ if (choice == null) return void 0;
466
+ switch (choice.type) {
467
+ case "auto":
468
+ return "auto";
469
+ case "none":
470
+ return "none";
471
+ case "required":
472
+ return "required";
473
+ case "tool":
474
+ return {
475
+ type: "function",
476
+ function: {
477
+ name: choice.toolName
478
+ }
479
+ };
480
+ }
481
+ }
482
+ function mapUsage(usage) {
483
+ return {
484
+ inputTokens: {
485
+ total: usage?.prompt_tokens,
486
+ noCache: void 0,
487
+ cacheRead: usage?.prompt_tokens_details?.cached_tokens,
488
+ cacheWrite: void 0
489
+ },
490
+ outputTokens: {
491
+ total: usage?.completion_tokens,
492
+ text: void 0,
493
+ reasoning: usage?.completion_tokens_details?.reasoning_tokens
494
+ }
495
+ };
496
+ }
497
+ function filterHeaders(input) {
498
+ const out = {};
499
+ for (const [k, v] of Object.entries(input)) {
500
+ if (v != null) out[k] = v;
501
+ }
502
+ return out;
503
+ }
504
+ async function safeReadText(res) {
505
+ try {
506
+ return await res.text();
507
+ } catch {
508
+ return void 0;
509
+ }
510
+ }
511
+
512
+ // src/ai-sdk/provider.ts
513
+ function createFoundryAI(options) {
514
+ const createLanguageModel = (model) => {
515
+ const identifier = typeof model === "string" ? {
516
+ type: "lmsModel",
517
+ apiName: model
518
+ } : model;
519
+ const id = identifier.type === "lmsModel" ? identifier.apiName : identifier.registeredModelRid;
520
+ return new FoundryChatLanguageModel(`foundry/${id}`, {
521
+ client: options.client,
522
+ identifier
523
+ });
524
+ };
525
+ const provider = function(model) {
526
+ return createLanguageModel(model);
527
+ };
528
+ provider.languageModel = createLanguageModel;
529
+ return provider;
530
+ }
531
+
532
+ exports.createFoundryAI = createFoundryAI;
533
+ //# sourceMappingURL=ai-sdk.cjs.map
534
+ //# sourceMappingURL=ai-sdk.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/ai-sdk/convert-prompt.ts","../../../src/ai-sdk/map-finish-reason.ts","../../../src/ai-sdk/foundry-chat-language-model.ts","../../../src/ai-sdk/provider.ts"],"names":["getOpenAiBaseUrl"],"mappings":";;;;;;;AAgBO,SAAS,aAAA,CAAc,QAAQ,QAAA,EAAU;AAC9C,EAAA,MAAM,WAAW,EAAC;AAClB,EAAA,KAAA,MAAW,WAAW,MAAA,EAAQ;AAC5B,IAAA,QAAA,CAAS,IAAA,CAAK,GAAG,cAAA,CAAe,OAAA,EAAS,QAAQ,CAAC,CAAA;AAAA,EACpD;AACA,EAAA,OAAO,QAAA;AACT;AACA,SAAS,cAAA,CAAe,SAAS,QAAA,EAAU;AACzC,EAAA,QAAQ,QAAQ,IAAA;AAAM,IACpB,KAAK,QAAA;AACH,MAAA,OAAO,CAAC;AAAA,QACN,IAAA,EAAM,QAAA;AAAA,QACN,SAAS,OAAA,CAAQ;AAAA,OAClB,CAAA;AAAA,IACH,KAAK,MAAA,EACH;AACE,MAAA,MAAM,QAAQ,EAAC;AACf,MAAA,KAAA,MAAW,IAAA,IAAQ,QAAQ,OAAA,EAAS;AAClC,QAAA,QAAQ,KAAK,IAAA;AAAM,UACjB,KAAK,MAAA;AACH,YAAA,KAAA,CAAM,IAAA,CAAK;AAAA,cACT,IAAA,EAAM,MAAA;AAAA,cACN,MAAM,IAAA,CAAK;AAAA,aACZ,CAAA;AACD,YAAA;AAAA,UACF,KAAK,MAAA;AACH,YAAA,QAAA,CAAS,IAAA,CAAK;AAAA,cACZ,IAAA,EAAM,aAAA;AAAA,cACN,OAAA,EAAS,mBAAA;AAAA,cACT,OAAA,EAAS;AAAA,aACV,CAAA;AACD,YAAA;AAAA;AACJ,MACF;AACA,MAAA,IAAI,KAAA,CAAM,WAAW,CAAA,EAAG;AACtB,QAAA,KAAA,CAAM,IAAA,CAAK;AAAA,UACT,IAAA,EAAM,MAAA;AAAA,UACN,IAAA,EAAM;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2026 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport function convertPrompt(prompt, warnings) {\n const messages = [];\n for (const message of prompt) {\n messages.push(...convertMessage(message, warnings));\n }\n return messages;\n}\nfunction convertMessage(message, warnings) {\n switch (message.role) {\n case \"system\":\n return [{\n role: \"system\",\n content: message.content\n }];\n case \"user\":\n {\n const parts = [];\n for (const part of message.content) {\n switch (part.type) {\n case \"text\":\n parts.push({\n type: \"text\",\n text: part.text\n });\n break;\n case \"file\":\n warnings.push({\n type: \"unsupported\",\n feature: \"user file content\",\n details: \"File content in user messages is not supported in v0 — ignored\"\n });\n break;\n }\n }\n if (parts.length === 0) {\n parts.push({\n type: \"text\",\n text: \"\"\n });\n }\n return [{\n role: \"user\",\n content: parts\n }];\n }\n case \"assistant\":\n {\n let text = \"\";\n const toolCalls = [];\n for (const part of message.content) {\n switch (part.type) {\n case \"text\":\n text += part.text;\n break;\n case \"tool-call\":\n toolCalls.push({\n id: part.toolCallId,\n type: \"function\",\n function: {\n name: part.toolName,\n arguments: typeof part.input === \"string\" ? part.input : JSON.stringify(part.input ?? {})\n }\n });\n break;\n case \"reasoning\":\n case \"file\":\n case \"tool-result\":\n warnings.push({\n type: \"unsupported\",\n feature: `assistant ${part.type} content`,\n details: `\"${part.type}\" parts in assistant messages are not supported in v0 — ignored`\n });\n break;\n }\n }\n return [{\n role: \"assistant\",\n content: text.length > 0 ? text : null,\n tool_calls: toolCalls.length > 0 ? toolCalls : undefined\n }];\n }\n case \"tool\":\n return message.content.filter(part => {\n if (part.type === \"tool-result\") return true;\n warnings.push({\n type: \"unsupported\",\n feature: `tool ${part.type} content`,\n details: `\"${part.type}\" parts in tool messages are not supported in v0 — ignored`\n });\n return false;\n }).map(part => ({\n role: \"tool\",\n content: stringifyToolResult(part.output, warnings),\n tool_call_id: part.toolCallId\n }));\n }\n}\nfunction stringifyToolResult(output, warnings) {\n switch (output.type) {\n case \"text\":\n case \"error-text\":\n return output.value;\n case \"json\":\n case \"error-json\":\n return JSON.stringify(output.value);\n case \"execution-denied\":\n return output.reason ?? \"Tool execution denied\";\n case \"content\":\n return output.value.map(c => {\n if (c.type === \"text\") return c.text;\n warnings.push({\n type: \"unsupported\",\n feature: \"tool result media content\",\n details: \"Non-text tool result content is not supported in v0 — ignored\"\n });\n return \"\";\n }).filter(s => s.length > 0).join(\"\\n\");\n }\n}","/*\n * Copyright 2026 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport function mapFinishReason(raw) {\n let unified;\n switch (raw) {\n case \"stop\":\n unified = \"stop\";\n break;\n case \"length\":\n unified = \"length\";\n break;\n case \"tool_calls\":\n case \"function_call\":\n unified = \"tool-calls\";\n break;\n case \"content_filter\":\n unified = \"content-filter\";\n break;\n default:\n unified = \"other\";\n break;\n }\n return {\n unified,\n raw\n };\n}","/*\n * Copyright 2026 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { getOpenAiBaseUrl } from \"@osdk/language-models\";\nimport { convertPrompt } from \"./convert-prompt.js\";\nimport { mapFinishReason } from \"./map-finish-reason.js\";\nexport class FoundryChatLanguageModel {\n specificationVersion = \"v3\";\n supportedUrls = {};\n constructor(modelId, config) {\n this.provider = \"foundry-lms\";\n this.modelId = modelId;\n this.config = config;\n }\n async doGenerate(options) {\n const warnings = [];\n const {\n body,\n url\n } = this.buildRequest(options, warnings);\n const res = await this.config.client.fetch(url, {\n method: \"POST\",\n headers: filterHeaders({\n \"Content-Type\": \"application/json\",\n Accept: \"application/json\",\n ...(options.headers ?? {})\n }),\n body: JSON.stringify(body),\n signal: options.abortSignal\n });\n if (!res.ok) {\n const errBody = await safeReadText(res);\n throw new Error(`LMS chat/completions request failed: ${res.status} ${res.statusText}` + (errBody ? ` — ${errBody}` : \"\"));\n }\n const data = await res.json();\n return this.parseGenerateResponse(data, body, warnings);\n }\n async doStream(options) {\n const warnings = [];\n const {\n body,\n url\n } = this.buildRequest(options, warnings);\n body.stream = true;\n const res = await this.config.client.fetch(url, {\n method: \"POST\",\n headers: filterHeaders({\n \"Content-Type\": \"application/json\",\n Accept: \"text/event-stream\",\n ...(options.headers ?? {})\n }),\n body: JSON.stringify(body),\n signal: options.abortSignal\n });\n if (!res.ok) {\n const errBody = await safeReadText(res);\n throw new Error(`LMS chat/completions request failed: ${res.status} ${res.statusText}` + (errBody ? ` — ${errBody}` : \"\"));\n }\n const stream = this.parseStreamResponse(res, body, warnings);\n return {\n stream,\n request: {\n body\n }\n };\n }\n buildRequest(options, warnings) {\n const baseUrl = getOpenAiBaseUrl(this.config.client);\n const url = new URL(\"chat/completions\", `${baseUrl}/`).toString();\n const apiName = this.config.identifier.type === \"lmsModel\" ? this.config.identifier.apiName : this.config.identifier.registeredModelRid;\n const messages = convertPrompt(options.prompt, warnings);\n const tools = options.tools?.filter(t => {\n if (t.type === \"function\") return true;\n warnings.push({\n type: \"unsupported\",\n feature: `${t.type} tool type`,\n details: `Only \"function\" tools are supported; \"${t.type}\" tools are ignored`\n });\n return false;\n }).map(t => ({\n type: \"function\",\n function: {\n name: t.name,\n description: t.description,\n parameters: t.inputSchema\n }\n }));\n const toolChoice = convertToolChoice(options.toolChoice);\n if (options.topK != null) {\n warnings.push({\n type: \"unsupported\",\n feature: \"topK\",\n details: \"topK is not supported by the Foundry LMS OpenAI proxy — ignored\"\n });\n }\n if (options.responseFormat?.type === \"json\") {\n warnings.push({\n type: \"unsupported\",\n feature: \"JSON response format\",\n details: \"Structured JSON output is not supported in v0 — ignored\"\n });\n }\n const body = {\n model: apiName,\n messages,\n max_tokens: options.maxOutputTokens,\n temperature: options.temperature,\n top_p: options.topP,\n stop: options.stopSequences,\n seed: options.seed,\n presence_penalty: options.presencePenalty,\n frequency_penalty: options.frequencyPenalty,\n tools: tools != null && tools.length > 0 ? tools : undefined,\n tool_choice: toolChoice,\n stream: false\n };\n return {\n body,\n url\n };\n }\n parseGenerateResponse(res, request, warnings) {\n const choice = res.choices[0];\n if (choice == null) {\n throw new Error(\"LMS chat/completions response did not include any choices\");\n }\n const message = choice.message;\n const content = [];\n if (message.content != null && message.content.length > 0) {\n content.push({\n type: \"text\",\n text: message.content\n });\n }\n const reasoningText = message.reasoning ?? message.reasoning_content;\n if (reasoningText != null) {\n content.push({\n type: \"reasoning\",\n text: reasoningText\n });\n }\n if (message.tool_calls != null) {\n for (const tc of message.tool_calls) {\n content.push({\n type: \"tool-call\",\n toolCallId: tc.id,\n toolName: tc.function.name,\n input: tc.function.arguments\n });\n }\n }\n return {\n content,\n finishReason: mapFinishReason(choice.finish_reason),\n usage: mapUsage(res.usage),\n request: {\n body: request\n },\n response: {\n id: res.id,\n modelId: res.model,\n timestamp: new Date(res.created * 1000),\n body: res\n },\n warnings\n };\n }\n parseStreamResponse(res, request, warnings) {\n const body = res.body;\n if (body == null) {\n throw new Error(\"LMS streaming response has no body\");\n }\n const reader = body.getReader();\n const decoder = new TextDecoder();\n let buffer = \"\";\n let sentStart = false;\n const textId = \"text-0\";\n let textStarted = false;\n const toolInputStarted = new Set();\n return new ReadableStream({\n pull: async controller => {\n while (true) {\n const {\n done,\n value\n } = await reader.read();\n if (done) {\n if (textStarted) {\n controller.enqueue({\n type: \"text-end\",\n id: textId\n });\n }\n controller.close();\n return;\n }\n buffer += decoder.decode(value, {\n stream: true\n });\n const lines = buffer.split(\"\\n\");\n buffer = lines.pop() ?? \"\";\n for (const line of lines) {\n const trimmed = line.trim();\n if (!trimmed.startsWith(\"data:\")) continue;\n const data = trimmed.slice(5).trim();\n if (data === \"[DONE]\") {\n if (textStarted) {\n controller.enqueue({\n type: \"text-end\",\n id: textId\n });\n }\n controller.close();\n return;\n }\n let chunk;\n try {\n chunk = JSON.parse(data);\n } catch {\n continue;\n }\n if (!sentStart) {\n sentStart = true;\n controller.enqueue({\n type: \"stream-start\",\n warnings\n });\n controller.enqueue({\n type: \"response-metadata\",\n id: chunk.id,\n modelId: chunk.model,\n timestamp: new Date(chunk.created * 1000)\n });\n }\n const delta = chunk.choices?.[0]?.delta;\n if (delta == null) {\n if (chunk.usage != null) {\n controller.enqueue({\n type: \"finish\",\n usage: mapUsage(chunk.usage),\n finishReason: mapFinishReason(chunk.choices?.[0]?.finish_reason ?? undefined)\n });\n }\n continue;\n }\n if (delta.content != null && delta.content.length > 0) {\n if (!textStarted) {\n textStarted = true;\n controller.enqueue({\n type: \"text-start\",\n id: textId\n });\n }\n controller.enqueue({\n type: \"text-delta\",\n id: textId,\n delta: delta.content\n });\n }\n if (delta.tool_calls != null) {\n for (const tc of delta.tool_calls) {\n const id = tc.id ?? `tool-${tc.index}`;\n if (tc.function?.name != null && !toolInputStarted.has(id)) {\n if (textStarted) {\n textStarted = false;\n controller.enqueue({\n type: \"text-end\",\n id: textId\n });\n }\n toolInputStarted.add(id);\n controller.enqueue({\n type: \"tool-input-start\",\n id,\n toolName: tc.function.name\n });\n }\n if (tc.function?.arguments != null) {\n controller.enqueue({\n type: \"tool-input-delta\",\n id,\n delta: tc.function.arguments\n });\n }\n }\n }\n const finishReason = chunk.choices?.[0]?.finish_reason;\n if (finishReason != null) {\n if (textStarted) {\n textStarted = false;\n controller.enqueue({\n type: \"text-end\",\n id: textId\n });\n }\n for (const id of toolInputStarted) {\n controller.enqueue({\n type: \"tool-input-end\",\n id\n });\n }\n controller.enqueue({\n type: \"finish\",\n usage: mapUsage(chunk.usage),\n finishReason: mapFinishReason(finishReason)\n });\n }\n }\n }\n },\n cancel: () => {\n void reader.cancel();\n }\n });\n }\n}\n\n// ---------------------------------------------------------------------------\n// OpenAI types\n// ---------------------------------------------------------------------------\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\nfunction convertToolChoice(choice) {\n if (choice == null) return undefined;\n switch (choice.type) {\n case \"auto\":\n return \"auto\";\n case \"none\":\n return \"none\";\n case \"required\":\n return \"required\";\n case \"tool\":\n return {\n type: \"function\",\n function: {\n name: choice.toolName\n }\n };\n }\n}\nfunction mapUsage(usage) {\n return {\n inputTokens: {\n total: usage?.prompt_tokens,\n noCache: undefined,\n cacheRead: usage?.prompt_tokens_details?.cached_tokens,\n cacheWrite: undefined\n },\n outputTokens: {\n total: usage?.completion_tokens,\n text: undefined,\n reasoning: usage?.completion_tokens_details?.reasoning_tokens\n }\n };\n}\nfunction filterHeaders(input) {\n const out = {};\n for (const [k, v] of Object.entries(input)) {\n if (v != null) out[k] = v;\n }\n return out;\n}\nasync function safeReadText(res) {\n try {\n return await res.text();\n } catch {\n return undefined;\n }\n}","/*\n * Copyright 2026 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { FoundryChatLanguageModel } from \"./foundry-chat-language-model.js\";\n\n/**\n * A Foundry AI provider for the AI SDK.\n *\n * Can be called directly as a function to get a language model, or use\n * the `.languageModel()` method.\n *\n * @example\n * ```ts\n * import { generateText } from \"ai\";\n * import { createFoundryAI } from \"@osdk/aip-core/ai-sdk\";\n *\n * const foundryAI = createFoundryAI({ client });\n * const { text } = await generateText({\n * model: foundryAI(\"gpt-4o\"),\n * prompt: \"Hello, world\",\n * });\n * ```\n */\n\n/**\n * Create a Foundry AI provider for the AI SDK.\n *\n * @param options - Configuration including the Foundry PlatformClient.\n * @returns A provider that can be called directly or via `.languageModel()`.\n */\nexport function createFoundryAI(options) {\n const createLanguageModel = model => {\n const identifier = typeof model === \"string\" ? {\n type: \"lmsModel\",\n apiName: model\n } : model;\n const id = identifier.type === \"lmsModel\" ? identifier.apiName : identifier.registeredModelRid;\n return new FoundryChatLanguageModel(`foundry/${id}`, {\n client: options.client,\n identifier\n });\n };\n const provider = function (model) {\n return createLanguageModel(model);\n };\n provider.languageModel = createLanguageModel;\n return provider;\n}"]}