@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,185 @@
1
+ /*
2
+ * Copyright 2026 Palantir Technologies, Inc. All rights reserved.
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
+ */
16
+
17
+ import { uiMessagesToModelMessages } from "./internal/uiMessageBridge.js";
18
+ import { streamText } from "./streamText.js";
19
+
20
+ /**
21
+ * Options for {@link LmsChatTransport}. Configures the streamed chat
22
+ * completion against the Foundry Language Model Service.
23
+ */
24
+
25
+ /**
26
+ * Stream chat completions through the Foundry Language Model Service via
27
+ * `streamText`. Implements `ChatTransport`, so any consumer that accepts a
28
+ * transport can plug it in (e.g. to inject custom sampling).
29
+ */
30
+ export class LmsChatTransport {
31
+ constructor(opts) {
32
+ this.opts = opts;
33
+ }
34
+ sendMessages = async args => {
35
+ const result = streamText({
36
+ model: this.opts.model,
37
+ // System prompt is folded into the model-message list by the bridge so
38
+ // it isn't double-prepended (transport.system + system messages from
39
+ // args.messages would both land otherwise).
40
+ messages: uiMessagesToModelMessages(args.messages, this.opts.system),
41
+ temperature: this.opts.temperature,
42
+ maxOutputTokens: this.opts.maxOutputTokens,
43
+ topP: this.opts.topP,
44
+ presencePenalty: this.opts.presencePenalty,
45
+ frequencyPenalty: this.opts.frequencyPenalty,
46
+ stopSequences: this.opts.stopSequences,
47
+ seed: this.opts.seed,
48
+ headers: mergeHeaders(this.opts.headers, args.headers),
49
+ abortSignal: args.abortSignal
50
+ });
51
+ const assistantId = args.messageId;
52
+ const textPartId = `${assistantId}-text-0`;
53
+ const reasoningPartId = `${assistantId}-reasoning-0`;
54
+ let textOpen = false;
55
+ let reasoningOpen = false;
56
+ let startEmitted = false;
57
+ return result.fullStream.pipeThrough(new TransformStream({
58
+ transform(chunk, controller) {
59
+ if (!startEmitted) {
60
+ startEmitted = true;
61
+ controller.enqueue({
62
+ type: "start",
63
+ messageId: assistantId
64
+ });
65
+ controller.enqueue({
66
+ type: "start-step"
67
+ });
68
+ }
69
+ const closeText = () => {
70
+ if (textOpen) {
71
+ textOpen = false;
72
+ controller.enqueue({
73
+ type: "text-end",
74
+ id: textPartId
75
+ });
76
+ }
77
+ };
78
+ const closeReasoning = () => {
79
+ if (reasoningOpen) {
80
+ reasoningOpen = false;
81
+ controller.enqueue({
82
+ type: "reasoning-end",
83
+ id: reasoningPartId
84
+ });
85
+ }
86
+ };
87
+ switch (chunk.type) {
88
+ case "text-delta":
89
+ {
90
+ if (!textOpen) {
91
+ textOpen = true;
92
+ controller.enqueue({
93
+ type: "text-start",
94
+ id: textPartId
95
+ });
96
+ }
97
+ controller.enqueue({
98
+ type: "text-delta",
99
+ id: textPartId,
100
+ delta: chunk.delta
101
+ });
102
+ return;
103
+ }
104
+ case "reasoning-delta":
105
+ {
106
+ if (!reasoningOpen) {
107
+ reasoningOpen = true;
108
+ controller.enqueue({
109
+ type: "reasoning-start",
110
+ id: reasoningPartId
111
+ });
112
+ }
113
+ controller.enqueue({
114
+ type: "reasoning-delta",
115
+ id: reasoningPartId,
116
+ delta: chunk.delta
117
+ });
118
+ return;
119
+ }
120
+ case "tool-call":
121
+ {
122
+ controller.enqueue({
123
+ type: "tool-input-available",
124
+ toolCallId: chunk.toolCallId,
125
+ toolName: chunk.toolName,
126
+ input: chunk.input
127
+ });
128
+ return;
129
+ }
130
+ case "finish":
131
+ {
132
+ closeText();
133
+ closeReasoning();
134
+ controller.enqueue({
135
+ type: "finish-step"
136
+ });
137
+ controller.enqueue({
138
+ type: "finish",
139
+ messageMetadata: {
140
+ finishReason: chunk.finishReason,
141
+ usage: chunk.usage
142
+ }
143
+ });
144
+ return;
145
+ }
146
+ case "error":
147
+ {
148
+ closeText();
149
+ closeReasoning();
150
+ controller.enqueue({
151
+ type: "error",
152
+ errorText: chunk.error.message
153
+ });
154
+ return;
155
+ }
156
+ default:
157
+ {
158
+ controller.enqueue({
159
+ type: "error",
160
+ errorText: `Unhandled chunk type "${chunk.type}"`
161
+ });
162
+ }
163
+ }
164
+ }
165
+ }));
166
+ };
167
+ reconnectToStream = async () => {
168
+ return null;
169
+ };
170
+ }
171
+ function mergeHeaders(base, override) {
172
+ if (base == null && override == null) {
173
+ return undefined;
174
+ }
175
+ const out = {
176
+ ...(base ?? {})
177
+ };
178
+ if (override != null) {
179
+ for (const [k, v] of Object.entries(override)) {
180
+ out[k] = v;
181
+ }
182
+ }
183
+ return out;
184
+ }
185
+ //# sourceMappingURL=lmsChatTransport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lmsChatTransport.js","names":["uiMessagesToModelMessages","streamText","LmsChatTransport","constructor","opts","sendMessages","args","result","model","messages","system","temperature","maxOutputTokens","topP","presencePenalty","frequencyPenalty","stopSequences","seed","headers","mergeHeaders","abortSignal","assistantId","messageId","textPartId","reasoningPartId","textOpen","reasoningOpen","startEmitted","fullStream","pipeThrough","TransformStream","transform","chunk","controller","enqueue","type","closeText","id","closeReasoning","delta","toolCallId","toolName","input","messageMetadata","finishReason","usage","errorText","error","message","reconnectToStream","base","override","undefined","out","k","v","Object","entries"],"sources":["lmsChatTransport.ts"],"sourcesContent":["/*\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 { uiMessagesToModelMessages } from \"./internal/uiMessageBridge.js\";\nimport type { LanguageModel } from \"./model.js\";\nimport { streamText, type TextStreamChunk } from \"./streamText.js\";\nimport type {\n ChatTransport,\n ChatTransportReconnectArgs,\n ChatTransportSendMessagesArgs,\n UIMessage,\n UIMessageChunk,\n} from \"./uiMessage.js\";\n\ntype SendMessagesArgs = ChatTransportSendMessagesArgs<UIMessage>;\n\n/**\n * Options for {@link LmsChatTransport}. Configures the streamed chat\n * completion against the Foundry Language Model Service.\n */\nexport interface LmsChatTransportOptions {\n /** Foundry-LMS-backed language model. Build via `foundryModel(...)`. */\n model: LanguageModel;\n\n /** System prompt prepended to every request. */\n system?: string;\n\n /** Sampling controls. */\n temperature?: number;\n maxOutputTokens?: number;\n topP?: number;\n presencePenalty?: number;\n frequencyPenalty?: number;\n stopSequences?: Array<string>;\n seed?: number;\n\n /** Extra HTTP headers forwarded to LMS. */\n headers?: Record<string, string | undefined>;\n}\n\n/**\n * Stream chat completions through the Foundry Language Model Service via\n * `streamText`. Implements `ChatTransport`, so any consumer that accepts a\n * transport can plug it in (e.g. to inject custom sampling).\n */\nexport class LmsChatTransport implements ChatTransport<UIMessage> {\n private readonly opts: LmsChatTransportOptions;\n\n constructor(opts: LmsChatTransportOptions) {\n this.opts = opts;\n }\n\n sendMessages = async (\n args: SendMessagesArgs,\n ): Promise<ReadableStream<UIMessageChunk>> => {\n const result = streamText({\n model: this.opts.model,\n // System prompt is folded into the model-message list by the bridge so\n // it isn't double-prepended (transport.system + system messages from\n // args.messages would both land otherwise).\n messages: uiMessagesToModelMessages(args.messages, this.opts.system),\n temperature: this.opts.temperature,\n maxOutputTokens: this.opts.maxOutputTokens,\n topP: this.opts.topP,\n presencePenalty: this.opts.presencePenalty,\n frequencyPenalty: this.opts.frequencyPenalty,\n stopSequences: this.opts.stopSequences,\n seed: this.opts.seed,\n headers: mergeHeaders(this.opts.headers, args.headers),\n abortSignal: args.abortSignal,\n });\n\n const assistantId = args.messageId;\n const textPartId = `${assistantId}-text-0`;\n const reasoningPartId = `${assistantId}-reasoning-0`;\n let textOpen = false;\n let reasoningOpen = false;\n let startEmitted = false;\n\n return result.fullStream.pipeThrough(\n new TransformStream<TextStreamChunk, UIMessageChunk>({\n transform(chunk, controller) {\n if (!startEmitted) {\n startEmitted = true;\n controller.enqueue({ type: \"start\", messageId: assistantId });\n controller.enqueue({ type: \"start-step\" });\n }\n const closeText = (): void => {\n if (textOpen) {\n textOpen = false;\n controller.enqueue({ type: \"text-end\", id: textPartId });\n }\n };\n const closeReasoning = (): void => {\n if (reasoningOpen) {\n reasoningOpen = false;\n controller.enqueue({\n type: \"reasoning-end\",\n id: reasoningPartId,\n });\n }\n };\n switch (chunk.type) {\n case \"text-delta\": {\n if (!textOpen) {\n textOpen = true;\n controller.enqueue({ type: \"text-start\", id: textPartId });\n }\n controller.enqueue({\n type: \"text-delta\",\n id: textPartId,\n delta: chunk.delta,\n });\n return;\n }\n case \"reasoning-delta\": {\n if (!reasoningOpen) {\n reasoningOpen = true;\n controller.enqueue({\n type: \"reasoning-start\",\n id: reasoningPartId,\n });\n }\n controller.enqueue({\n type: \"reasoning-delta\",\n id: reasoningPartId,\n delta: chunk.delta,\n });\n return;\n }\n case \"tool-call\": {\n controller.enqueue({\n type: \"tool-input-available\",\n toolCallId: chunk.toolCallId,\n toolName: chunk.toolName,\n input: chunk.input,\n });\n return;\n }\n case \"finish\": {\n closeText();\n closeReasoning();\n controller.enqueue({ type: \"finish-step\" });\n controller.enqueue({\n type: \"finish\",\n messageMetadata: {\n finishReason: chunk.finishReason,\n usage: chunk.usage,\n },\n });\n return;\n }\n case \"error\": {\n closeText();\n closeReasoning();\n controller.enqueue({\n type: \"error\",\n errorText: chunk.error.message,\n });\n return;\n }\n default: {\n const unhandled: { type: string } = chunk;\n controller.enqueue({\n type: \"error\",\n errorText: `Unhandled chunk type \"${unhandled.type}\"`,\n });\n }\n }\n },\n }),\n );\n };\n\n reconnectToStream = async (\n _args: ChatTransportReconnectArgs,\n ): Promise<ReadableStream<UIMessageChunk> | null> => {\n return null;\n };\n}\n\nfunction mergeHeaders(\n base: Record<string, string | undefined> | undefined,\n override: Record<string, string> | undefined,\n): Record<string, string | undefined> | undefined {\n if (base == null && override == null) {\n return undefined;\n }\n const out: Record<string, string | undefined> = { ...(base ?? {}) };\n if (override != null) {\n for (const [k, v] of Object.entries(override)) {\n out[k] = v;\n }\n }\n return out;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,yBAAyB,QAAQ,+BAA+B;AAEzE,SAASC,UAAU,QAA8B,iBAAiB;;AAWlE;AACA;AACA;AACA;;AAqBA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,gBAAgB,CAAqC;EAGhEC,WAAWA,CAACC,IAA6B,EAAE;IACzC,IAAI,CAACA,IAAI,GAAGA,IAAI;EAClB;EAEAC,YAAY,GAAG,MACbC,IAAsB,IACsB;IAC5C,MAAMC,MAAM,GAAGN,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AO,CAACN,QAAQ,CAAC,EAAE;MAC7CE,GAAG,CAACC,CAAC,CAAC,GAAGC,CAAC;IACZ;EACF;EACA,OAAOF,GAAG;AACZ","ignoreList":[]}
@@ -0,0 +1,74 @@
1
+ /*
2
+ * Copyright 2026 Palantir Technologies, Inc. All rights reserved.
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
+ */
16
+
17
+ /**
18
+ * Identifies a model in the Foundry Language Model Service.
19
+ *
20
+ * - `lmsModel`: a built-in LMS model addressed by `apiName` (e.g. "gpt-4o")
21
+ * - `registeredModel`: a customer-registered model addressed by RID
22
+ */
23
+
24
+ /** Opaque language model handle accepted by `generateText` / `streamText`. */
25
+
26
+ /** @internal */
27
+
28
+ const internals = new WeakMap();
29
+
30
+ /**
31
+ * Construct a Foundry-LMS-backed {@link LanguageModel}.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * import { foundryModel, generateText } from "@osdk/aip-core";
36
+ *
37
+ * const model = foundryModel({ client, model: "gpt-4o" });
38
+ * const { text } = await generateText({
39
+ * model,
40
+ * prompt: "Hello, world",
41
+ * });
42
+ * ```
43
+ */
44
+ export function foundryModel(options) {
45
+ const identifier = typeof options.model === "string" ? {
46
+ type: "lmsModel",
47
+ apiName: options.model
48
+ } : options.model;
49
+ const id = identifier.type === "lmsModel" ? identifier.apiName : identifier.registeredModelRid;
50
+ const handle = Object.freeze({
51
+ modelId: `foundry/${id}`,
52
+ provider: "foundry-lms"
53
+ });
54
+ internals.set(handle, {
55
+ client: options.client,
56
+ identifier
57
+ });
58
+ return handle;
59
+ }
60
+
61
+ /**
62
+ * Internal accessor for the foundry handle. Not exported from the package
63
+ * index. `runStep` calls this; consumers should never need it.
64
+ *
65
+ * @internal
66
+ */
67
+ export function _getFoundryInternal(model) {
68
+ const handle = internals.get(model);
69
+ if (handle == null) {
70
+ throw new Error(`LanguageModel(modelId=${model.modelId}, provider=${model.provider}) ` + `was not constructed via foundryModel(). Only foundry-lms models are supported in v0.`);
71
+ }
72
+ return handle;
73
+ }
74
+ //# sourceMappingURL=model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.js","names":["internals","WeakMap","foundryModel","options","identifier","model","type","apiName","id","registeredModelRid","handle","Object","freeze","modelId","provider","set","client","_getFoundryInternal","get","Error"],"sources":["model.ts"],"sourcesContent":["/*\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 type { PlatformClient } from \"@osdk/client\";\n\n/**\n * Identifies a model in the Foundry Language Model Service.\n *\n * - `lmsModel`: a built-in LMS model addressed by `apiName` (e.g. \"gpt-4o\")\n * - `registeredModel`: a customer-registered model addressed by RID\n */\nexport type ModelIdentifier =\n | { type: \"lmsModel\"; apiName: string }\n | { type: \"registeredModel\"; registeredModelRid: string };\n\n/** Opaque language model handle accepted by `generateText` / `streamText`. */\nexport interface LanguageModel {\n /** Stable identifier for logging / telemetry, e.g. \"foundry/gpt-4o\". */\n readonly modelId: string;\n /** Provider tag — `\"foundry-lms\"` for the built-in LMS adapter. */\n readonly provider: string;\n}\n\nexport interface FoundryModelOptions {\n /** Foundry PlatformClient providing the auth token + base URL. */\n client: PlatformClient;\n /** LMS model API name or registered model RID. */\n model: string | ModelIdentifier;\n}\n\n/** @internal */\nexport interface FoundryInternalHandle {\n client: PlatformClient;\n identifier: ModelIdentifier;\n}\n\nconst internals: WeakMap<LanguageModel, FoundryInternalHandle> = new WeakMap();\n\n/**\n * Construct a Foundry-LMS-backed {@link LanguageModel}.\n *\n * @example\n * ```ts\n * import { foundryModel, generateText } from \"@osdk/aip-core\";\n *\n * const model = foundryModel({ client, model: \"gpt-4o\" });\n * const { text } = await generateText({\n * model,\n * prompt: \"Hello, world\",\n * });\n * ```\n */\nexport function foundryModel(options: FoundryModelOptions): LanguageModel {\n const identifier: ModelIdentifier = typeof options.model === \"string\"\n ? { type: \"lmsModel\", apiName: options.model }\n : options.model;\n\n const id = identifier.type === \"lmsModel\"\n ? identifier.apiName\n : identifier.registeredModelRid;\n\n const handle: LanguageModel = Object.freeze({\n modelId: `foundry/${id}`,\n provider: \"foundry-lms\",\n });\n\n internals.set(handle, {\n client: options.client,\n identifier,\n });\n\n return handle;\n}\n\n/**\n * Internal accessor for the foundry handle. Not exported from the package\n * index. `runStep` calls this; consumers should never need it.\n *\n * @internal\n */\nexport function _getFoundryInternal(\n model: LanguageModel,\n): FoundryInternalHandle {\n const handle = internals.get(model);\n if (handle == null) {\n throw new Error(\n `LanguageModel(modelId=${model.modelId}, provider=${model.provider}) `\n + `was not constructed via foundryModel(). Only foundry-lms models are supported in v0.`,\n );\n }\n return handle;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;;AAKA;;AAeA;;AAMA,MAAMA,SAAwD,GAAG,IAAIC,OAAO,CAAC,CAAC;;AAE9E;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,YAAYA,CAACC,OAA4B,EAAiB;EACxE,MAAMC,UAA2B,GAAG,OAAOD,OAAO,CAACE,KAAK,KAAK,QAAQ,GACjE;IAAEC,IAAI,EAAE,UAAU;IAAEC,OAAO,EAAEJ,OAAO,CAACE;EAAM,CAAC,GAC5CF,OAAO,CAACE,KAAK;EAEjB,MAAMG,EAAE,GAAGJ,UAAU,CAACE,IAAI,KAAK,UAAU,GACrCF,UAAU,CAACG,OAAO,GAClBH,UAAU,CAACK,kBAAkB;EAEjC,MAAMC,MAAqB,GAAGC,MAAM,CAACC,MAAM,CAAC;IAC1CC,OAAO,EAAE,WAAWL,EAAE,EAAE;IACxBM,QAAQ,EAAE;EACZ,CAAC,CAAC;EAEFd,SAAS,CAACe,GAAG,CAACL,MAAM,EAAE;IACpBM,MAAM,EAAEb,OAAO,CAACa,MAAM;IACtBZ;EACF,CAAC,CAAC;EAEF,OAAOM,MAAM;AACf;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASO,mBAAmBA,CACjCZ,KAAoB,EACG;EACvB,MAAMK,MAAM,GAAGV,SAAS,CAACkB,GAAG,CAACb,KAAK,CAAC;EACnC,IAAIK,MAAM,IAAI,IAAI,EAAE;IAClB,MAAM,IAAIS,KAAK,CACb,yBAAyBd,KAAK,CAACQ,OAAO,cAAcR,KAAK,CAACS,QAAQ,IAAI,GAClE,sFACN,CAAC;EACH;EACA,OAAOJ,MAAM;AACf","ignoreList":[]}
@@ -0,0 +1,18 @@
1
+ /*
2
+ * Copyright 2026 Palantir Technologies, Inc. All rights reserved.
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
+ */
16
+
17
+ export { createFoundryAI } from "../ai-sdk/provider.js";
18
+ //# sourceMappingURL=ai-sdk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-sdk.js","names":["createFoundryAI"],"sources":["ai-sdk.ts"],"sourcesContent":["/*\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 { createFoundryAI } from \"../ai-sdk/provider.js\";\nexport type {\n FoundryAIProvider,\n FoundryAIProviderOptions,\n} from \"../ai-sdk/provider.js\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,eAAe,QAAQ,uBAAuB","ignoreList":[]}
@@ -0,0 +1,210 @@
1
+ /*
2
+ * Copyright 2026 Palantir Technologies, Inc. All rights reserved.
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
+ */
16
+
17
+ import { resolveMessages } from "./internal/options.js";
18
+ import { streamStep } from "./internal/streamStep.js";
19
+
20
+ /**
21
+ * Options for {@link streamText}.
22
+ */
23
+
24
+ /**
25
+ * Single chunk emitted on a {@link StreamTextResult.fullStream}.
26
+ *
27
+ * `toolName` is a runtime string — the model returns whatever it returns,
28
+ * so the chunk's tool name is not statically narrowed against the user's
29
+ * `TOOLS` set.
30
+ */
31
+
32
+ /**
33
+ * Result of {@link streamText}.
34
+ *
35
+ * `fullStream` is a `ReadableStream` (not an async iterable) so it can be
36
+ * `pipeThrough`-ed with browser-native transforms.
37
+ */
38
+
39
+ /**
40
+ * Stream a chat completion via the Foundry Language Model Service.
41
+ *
42
+ * v0: single-step. Multi-step tool execution loops, image/file content,
43
+ * structured output, and Zod tool schemas are not yet supported. Unsupported
44
+ * options surface via the `warnings` promise rather than throwing.
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * import { foundryModel, streamText } from "@osdk/aip-core";
49
+ *
50
+ * const { textStream } = streamText({
51
+ * model: foundryModel({ client, model: "gpt-4o" }),
52
+ * prompt: "Tell me a story.",
53
+ * });
54
+ *
55
+ * const reader = textStream.getReader();
56
+ * while (true) {
57
+ * const { done, value } = await reader.read();
58
+ * if (done) break;
59
+ * process.stdout.write(value);
60
+ * }
61
+ * ```
62
+ */
63
+
64
+ export function streamText(options) {
65
+ const warnings = [];
66
+ const messages = resolveMessages("streamText", options.system, options.prompt, options.messages);
67
+ const final = createDeferred();
68
+ const internalAbort = new AbortController();
69
+ const abortHandler = () => internalAbort.abort();
70
+ if (options.abortSignal != null) {
71
+ if (options.abortSignal.aborted) {
72
+ internalAbort.abort();
73
+ } else {
74
+ options.abortSignal.addEventListener("abort", abortHandler);
75
+ }
76
+ }
77
+ const detachAbortHandler = () => {
78
+ options.abortSignal?.removeEventListener("abort", abortHandler);
79
+ };
80
+ let streamController;
81
+ let streamClosed = false;
82
+ const run = async () => {
83
+ try {
84
+ const result = await streamStep({
85
+ model: options.model,
86
+ messages,
87
+ tools: options.tools,
88
+ toolChoice: options.toolChoice,
89
+ maxOutputTokens: options.maxOutputTokens,
90
+ temperature: options.temperature,
91
+ topP: options.topP,
92
+ stopSequences: options.stopSequences,
93
+ seed: options.seed,
94
+ presencePenalty: options.presencePenalty,
95
+ frequencyPenalty: options.frequencyPenalty,
96
+ abortSignal: internalAbort.signal,
97
+ headers: options.headers,
98
+ warnings,
99
+ onChunk: async chunk => {
100
+ if (!streamClosed) {
101
+ streamController?.enqueue(chunk);
102
+ }
103
+ if (options.onChunk != null) {
104
+ await options.onChunk(chunk);
105
+ }
106
+ }
107
+ });
108
+ streamController?.close();
109
+ streamClosed = true;
110
+ const finalWarnings = warnings.length > 0 ? warnings : undefined;
111
+ final.resolve({
112
+ text: result.text,
113
+ reasoningText: result.reasoningText,
114
+ usage: result.usage,
115
+ finishReason: result.finishReason,
116
+ toolCalls: result.toolCalls,
117
+ warnings: finalWarnings,
118
+ response: result.response,
119
+ request: result.request
120
+ });
121
+ if (options.onFinish != null) {
122
+ await options.onFinish({
123
+ finishReason: result.finishReason,
124
+ text: result.text,
125
+ reasoningText: result.reasoningText,
126
+ toolCalls: result.toolCalls,
127
+ usage: result.usage,
128
+ totalUsage: result.usage,
129
+ warnings: finalWarnings,
130
+ response: result.response,
131
+ request: result.request
132
+ });
133
+ }
134
+ } catch (err) {
135
+ const error = err instanceof Error ? err : new Error(String(err));
136
+ if (!streamClosed) {
137
+ streamController?.enqueue({
138
+ type: "error",
139
+ error
140
+ });
141
+ streamController?.error(error);
142
+ streamClosed = true;
143
+ }
144
+ final.reject(error);
145
+ if (options.onError != null) {
146
+ await options.onError(error);
147
+ }
148
+ } finally {
149
+ detachAbortHandler();
150
+ }
151
+ };
152
+ const sourceStream = new ReadableStream({
153
+ start(controller) {
154
+ streamController = controller;
155
+ void run();
156
+ },
157
+ cancel() {
158
+ internalAbort.abort();
159
+ detachAbortHandler();
160
+ }
161
+ });
162
+ const [fullStreamBranch, textStreamBranch] = sourceStream.tee();
163
+ const textStream = textStreamBranch.pipeThrough(new TransformStream({
164
+ transform(chunk, controller) {
165
+ if (chunk.type === "text-delta") {
166
+ controller.enqueue(chunk.delta);
167
+ }
168
+ }
169
+ }));
170
+
171
+ // Warnings settle even if the stream errors, so the consumer can read them
172
+ // off the failure path. Other promises propagate the error.
173
+ const warningsPromise = final.promise.then(s => s.warnings, () => warnings.length > 0 ? warnings : undefined);
174
+ return {
175
+ fullStream: fullStreamBranch,
176
+ textStream,
177
+ text: silence(final.promise.then(s => s.text)),
178
+ reasoningText: silence(final.promise.then(s => s.reasoningText)),
179
+ usage: silence(final.promise.then(s => s.usage)),
180
+ totalUsage: silence(final.promise.then(s => s.usage)),
181
+ finishReason: silence(final.promise.then(s => s.finishReason)),
182
+ toolCalls: silence(final.promise.then(s => s.toolCalls)),
183
+ warnings: warningsPromise,
184
+ response: silence(final.promise.then(s => s.response)),
185
+ request: silence(final.promise.then(s => s.request))
186
+ };
187
+ }
188
+
189
+ // Pre-attach a no-op rejection handler so a consumer that awaits only some of
190
+ // the result promises doesn't trigger unhandled-rejection warnings on the
191
+ // rest. The promise still rejects for any consumer that awaits it.
192
+ function silence(p) {
193
+ p.catch(() => {});
194
+ return p;
195
+ }
196
+ function createDeferred() {
197
+ let resolveFn = () => {};
198
+ let rejectFn = () => {};
199
+ const promise = new Promise((res, rej) => {
200
+ resolveFn = res;
201
+ rejectFn = rej;
202
+ });
203
+ promise.catch(() => {});
204
+ return {
205
+ promise,
206
+ resolve: resolveFn,
207
+ reject: rejectFn
208
+ };
209
+ }
210
+ //# sourceMappingURL=streamText.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"streamText.js","names":["resolveMessages","streamStep","streamText","options","warnings","messages","system","prompt","final","createDeferred","internalAbort","AbortController","abortHandler","abort","abortSignal","aborted","addEventListener","detachAbortHandler","removeEventListener","streamController","streamClosed","run","result","model","tools","toolChoice","maxOutputTokens","temperature","topP","stopSequences","seed","presencePenalty","frequencyPenalty","signal","headers","onChunk","chunk","enqueue","close","finalWarnings","length","undefined","resolve","text","reasoningText","usage","finishReason","toolCalls","response","request","onFinish","totalUsage","err","error","Error","String","type","reject","onError","sourceStream","ReadableStream","start","controller","cancel","fullStreamBranch","textStreamBranch","tee","textStream","pipeThrough","TransformStream","transform","delta","warningsPromise","promise","then","s","fullStream","silence","p","catch","resolveFn","rejectFn","Promise","res","rej"],"sources":["streamText.ts"],"sourcesContent":["/*\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 { resolveMessages } from \"./internal/options.js\";\nimport { type StreamChunkEvent, streamStep } from \"./internal/streamStep.js\";\nimport type { LanguageModel } from \"./model.js\";\nimport type {\n FinishReason,\n LanguageModelUsage,\n ModelMessage,\n RequestMetadata,\n ResponseMetadata,\n SystemModelMessage,\n ToolCall,\n ToolChoice,\n ToolSet,\n Warning,\n} from \"./types.js\";\n\n/**\n * Options for {@link streamText}.\n */\nexport interface StreamTextOptions<TOOLS extends ToolSet = ToolSet> {\n /** The language model to use. Build one via `foundryModel(...)`. */\n model: LanguageModel;\n\n /** Plain text prompt. Mutually exclusive with `messages`. */\n prompt?: string | Array<ModelMessage>;\n\n /** Conversation history. Mutually exclusive with `prompt`. */\n messages?: Array<ModelMessage>;\n\n /** System instructions, prepended to the conversation. */\n system?: string | SystemModelMessage | Array<SystemModelMessage>;\n\n // Tools --------------------------------------------------------------------\n\n tools?: TOOLS;\n toolChoice?: ToolChoice<TOOLS>;\n\n // Sampling -----------------------------------------------------------------\n\n maxOutputTokens?: number;\n temperature?: number;\n topP?: number;\n presencePenalty?: number;\n frequencyPenalty?: number;\n stopSequences?: Array<string>;\n seed?: number;\n\n // Execution ----------------------------------------------------------------\n\n abortSignal?: AbortSignal;\n headers?: Record<string, string | undefined>;\n\n // Callbacks ----------------------------------------------------------------\n\n /** Fires for every chunk emitted on `fullStream`. */\n onChunk?: (chunk: TextStreamChunk) => void | PromiseLike<void>;\n\n /** Fires when the stream errors out. The same error is also emitted via the stream. */\n onError?: (error: Error) => void | PromiseLike<void>;\n\n /** Fires once after the stream completes successfully. */\n onFinish?: (\n event: {\n finishReason: FinishReason;\n text: string;\n reasoningText: string | undefined;\n toolCalls: Array<ToolCall>;\n usage: LanguageModelUsage;\n totalUsage: LanguageModelUsage;\n warnings: Array<Warning> | undefined;\n response: ResponseMetadata | undefined;\n request: RequestMetadata | undefined;\n },\n ) => void | PromiseLike<void>;\n}\n\n/**\n * Single chunk emitted on a {@link StreamTextResult.fullStream}.\n *\n * `toolName` is a runtime string — the model returns whatever it returns,\n * so the chunk's tool name is not statically narrowed against the user's\n * `TOOLS` set.\n */\nexport type TextStreamChunk = StreamChunkEvent;\n\n/**\n * Result of {@link streamText}.\n *\n * `fullStream` is a `ReadableStream` (not an async iterable) so it can be\n * `pipeThrough`-ed with browser-native transforms.\n */\nexport interface StreamTextResult {\n /** Stream of all chunk events. */\n fullStream: ReadableStream<TextStreamChunk>;\n /** Stream of just text-delta strings (convenience). */\n textStream: ReadableStream<string>;\n /** Resolves to the final accumulated assistant text. */\n text: Promise<string>;\n /** Resolves to the final accumulated reasoning text, if any. */\n reasoningText: Promise<string | undefined>;\n /** Resolves to the final usage. */\n usage: Promise<LanguageModelUsage>;\n /** Resolves to the same usage (single-step v0). */\n totalUsage: Promise<LanguageModelUsage>;\n /** Resolves to the finish reason. */\n finishReason: Promise<FinishReason>;\n /** Resolves to the accumulated tool calls. */\n toolCalls: Promise<Array<ToolCall>>;\n /** Resolves to v0 warnings, if any. */\n warnings: Promise<Array<Warning> | undefined>;\n /** Resolves to response metadata once the stream finishes. */\n response: Promise<ResponseMetadata | undefined>;\n /** Resolves to the request metadata. */\n request: Promise<RequestMetadata | undefined>;\n}\n\n/**\n * Stream a chat completion via the Foundry Language Model Service.\n *\n * v0: single-step. Multi-step tool execution loops, image/file content,\n * structured output, and Zod tool schemas are not yet supported. Unsupported\n * options surface via the `warnings` promise rather than throwing.\n *\n * @example\n * ```ts\n * import { foundryModel, streamText } from \"@osdk/aip-core\";\n *\n * const { textStream } = streamText({\n * model: foundryModel({ client, model: \"gpt-4o\" }),\n * prompt: \"Tell me a story.\",\n * });\n *\n * const reader = textStream.getReader();\n * while (true) {\n * const { done, value } = await reader.read();\n * if (done) break;\n * process.stdout.write(value);\n * }\n * ```\n */\ninterface FinalState {\n text: string;\n reasoningText: string | undefined;\n usage: LanguageModelUsage;\n finishReason: FinishReason;\n toolCalls: Array<ToolCall>;\n warnings: Array<Warning> | undefined;\n response: ResponseMetadata | undefined;\n request: RequestMetadata | undefined;\n}\n\nexport function streamText<TOOLS extends ToolSet = ToolSet>(\n options: StreamTextOptions<TOOLS>,\n): StreamTextResult {\n const warnings: Array<Warning> = [];\n const messages = resolveMessages(\n \"streamText\",\n options.system,\n options.prompt,\n options.messages,\n );\n\n const final = createDeferred<FinalState>();\n\n const internalAbort = new AbortController();\n const abortHandler = (): void => internalAbort.abort();\n if (options.abortSignal != null) {\n if (options.abortSignal.aborted) {\n internalAbort.abort();\n } else {\n options.abortSignal.addEventListener(\"abort\", abortHandler);\n }\n }\n const detachAbortHandler = (): void => {\n options.abortSignal?.removeEventListener(\"abort\", abortHandler);\n };\n\n let streamController:\n | ReadableStreamDefaultController<TextStreamChunk>\n | undefined;\n let streamClosed = false;\n\n const run = async (): Promise<void> => {\n try {\n const result = await streamStep<TOOLS>({\n model: options.model,\n messages,\n tools: options.tools,\n toolChoice: options.toolChoice,\n maxOutputTokens: options.maxOutputTokens,\n temperature: options.temperature,\n topP: options.topP,\n stopSequences: options.stopSequences,\n seed: options.seed,\n presencePenalty: options.presencePenalty,\n frequencyPenalty: options.frequencyPenalty,\n abortSignal: internalAbort.signal,\n headers: options.headers,\n warnings,\n onChunk: async (chunk) => {\n if (!streamClosed) {\n streamController?.enqueue(chunk);\n }\n if (options.onChunk != null) {\n await options.onChunk(chunk);\n }\n },\n });\n\n streamController?.close();\n streamClosed = true;\n\n const finalWarnings = warnings.length > 0 ? warnings : undefined;\n final.resolve({\n text: result.text,\n reasoningText: result.reasoningText,\n usage: result.usage,\n finishReason: result.finishReason,\n toolCalls: result.toolCalls,\n warnings: finalWarnings,\n response: result.response,\n request: result.request,\n });\n\n if (options.onFinish != null) {\n await options.onFinish({\n finishReason: result.finishReason,\n text: result.text,\n reasoningText: result.reasoningText,\n toolCalls: result.toolCalls,\n usage: result.usage,\n totalUsage: result.usage,\n warnings: finalWarnings,\n response: result.response,\n request: result.request,\n });\n }\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err));\n if (!streamClosed) {\n streamController?.enqueue({ type: \"error\", error });\n streamController?.error(error);\n streamClosed = true;\n }\n final.reject(error);\n\n if (options.onError != null) {\n await options.onError(error);\n }\n } finally {\n detachAbortHandler();\n }\n };\n\n const sourceStream = new ReadableStream<TextStreamChunk>({\n start(controller) {\n streamController = controller;\n void run();\n },\n cancel() {\n internalAbort.abort();\n detachAbortHandler();\n },\n });\n\n const [fullStreamBranch, textStreamBranch] = sourceStream.tee();\n\n const textStream = textStreamBranch.pipeThrough(\n new TransformStream<TextStreamChunk, string>({\n transform(chunk, controller) {\n if (chunk.type === \"text-delta\") {\n controller.enqueue(chunk.delta);\n }\n },\n }),\n );\n\n // Warnings settle even if the stream errors, so the consumer can read them\n // off the failure path. Other promises propagate the error.\n const warningsPromise: Promise<Array<Warning> | undefined> = final.promise\n .then(\n (s) => s.warnings,\n () => (warnings.length > 0 ? warnings : undefined),\n );\n\n return {\n fullStream: fullStreamBranch,\n textStream,\n text: silence(final.promise.then((s) => s.text)),\n reasoningText: silence(final.promise.then((s) => s.reasoningText)),\n usage: silence(final.promise.then((s) => s.usage)),\n totalUsage: silence(final.promise.then((s) => s.usage)),\n finishReason: silence(final.promise.then((s) => s.finishReason)),\n toolCalls: silence(final.promise.then((s) => s.toolCalls)),\n warnings: warningsPromise,\n response: silence(final.promise.then((s) => s.response)),\n request: silence(final.promise.then((s) => s.request)),\n };\n}\n\n// Pre-attach a no-op rejection handler so a consumer that awaits only some of\n// the result promises doesn't trigger unhandled-rejection warnings on the\n// rest. The promise still rejects for any consumer that awaits it.\nfunction silence<T>(p: Promise<T>): Promise<T> {\n p.catch(() => {});\n return p;\n}\n\ninterface Deferred<T> {\n promise: Promise<T>;\n resolve: (value: T) => void;\n reject: (error: Error) => void;\n}\n\nfunction createDeferred<T>(): Deferred<T> {\n let resolveFn: (value: T) => void = () => {};\n let rejectFn: (error: Error) => void = () => {};\n const promise = new Promise<T>((res, rej) => {\n resolveFn = res;\n rejectFn = rej;\n });\n promise.catch(() => {});\n return { promise, resolve: resolveFn, reject: rejectFn };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,eAAe,QAAQ,uBAAuB;AACvD,SAAgCC,UAAU,QAAQ,0BAA0B;;AAe5E;AACA;AACA;;AA0DA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;;AA0BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAYA,OAAO,SAASC,UAAUA,CACxBC,OAAiC,EACf;EAClB,MAAMC,QAAwB,GAAG,EAAE;EACnC,MAAMC,QAAQ,GAAGL,eAAe,CAC9B,YAAY,EACZG,OAAO,CAACG,MAAM,EACdH,OAAO,CAACI,MAAM,EACdJ,OAAO,CAACE,QACV,CAAC;EAED,MAAMG,KAAK,GAAGC,cAAc,CAAa,CAAC;EAE1C,MAAMC,aAAa,GAAG,IAAIC,eAAe,CAAC,CAAC;EAC3C,MAAMC,YAAY,GAAGA,CAAA,KAAYF,aAAa,CAACG,KAAK,CAAC,CAAC;EACtD,IAAIV,OAAO,CAACW,WAAW,IAAI,IAAI,EAAE;IAC/B,IAAIX,OAAO,CAACW,WAAW,CAACC,OAAO,EAAE;MAC/BL,a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/C,MAAMR,OAAO,GAAG,IAAIS,OAAO,CAAI,CAACC,GAAG,EAAEC,GAAG,KAAK;IAC3CJ,SAAS,GAAGG,GAAG;IACfF,QAAQ,GAAGG,GAAG;EAChB,CAAC,CAAC;EACFX,OAAO,CAACM,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;EACvB,OAAO;IAAEN,OAAO;IAAE/B,OAAO,EAAEsC,SAAS;IAAEvB,MAAM,EAAEwB;EAAS,CAAC;AAC1D","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","names":[],"sources":["types.ts"],"sourcesContent":["/*\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\n/**\n * Shared types for the AIP SDK's chat completion primitives.\n */\n\nexport type Role = \"system\" | \"user\" | \"assistant\" | \"tool\";\n\nexport interface SystemModelMessage {\n role: \"system\";\n content: string;\n providerOptions?: ProviderOptions;\n}\n\nexport interface UserModelMessage {\n role: \"user\";\n content: string | Array<TextPart | ImagePart | FilePart>;\n providerOptions?: ProviderOptions;\n}\n\nexport interface AssistantModelMessage {\n role: \"assistant\";\n content:\n | string\n | Array<TextPart | ReasoningPart | ToolCallPart | FilePart>;\n providerOptions?: ProviderOptions;\n}\n\nexport interface ToolModelMessage {\n role: \"tool\";\n content: Array<ToolResultPart>;\n providerOptions?: ProviderOptions;\n}\n\nexport type ModelMessage =\n | SystemModelMessage\n | UserModelMessage\n | AssistantModelMessage\n | ToolModelMessage;\n\nexport interface TextPart {\n type: \"text\";\n text: string;\n providerOptions?: ProviderOptions;\n}\n\nexport interface ReasoningPart {\n type: \"reasoning\";\n text: string;\n providerOptions?: ProviderOptions;\n}\n\nexport interface ImagePart {\n type: \"image\";\n /** Base64 string, data URL, ArrayBuffer, Uint8Array, or remote URL. */\n image: string | Uint8Array | ArrayBuffer | URL;\n mediaType?: string;\n providerOptions?: ProviderOptions;\n}\n\nexport interface FilePart {\n type: \"file\";\n data: string | Uint8Array | ArrayBuffer | URL;\n mediaType: string;\n filename?: string;\n providerOptions?: ProviderOptions;\n}\n\nexport interface ToolCallPart {\n type: \"tool-call\";\n toolCallId: string;\n toolName: string;\n input: unknown;\n providerOptions?: ProviderOptions;\n}\n\nexport interface ToolResultPart {\n type: \"tool-result\";\n toolCallId: string;\n toolName: string;\n output: ToolResultOutput;\n providerOptions?: ProviderOptions;\n}\n\nexport type ToolResultOutput =\n | { type: \"text\"; value: string }\n | { type: \"json\"; value: unknown }\n | { type: \"error-text\"; value: string }\n | { type: \"error-json\"; value: unknown }\n | {\n type: \"content\";\n value: Array<\n | { type: \"text\"; text: string }\n | { type: \"media\"; data: string; mediaType: string }\n >;\n };\n\n/**\n * Tool definition.\n *\n * `inputSchema` is intentionally typed as `unknown` rather than a specific\n * schema library type — it can be a Zod schema, a JSON Schema object, or any\n * other validator the consumer supplies.\n */\nexport interface Tool {\n description?: string;\n inputSchema: unknown;\n /** Provider-specific options, e.g. OpenAI strict mode. */\n providerOptions?: ProviderOptions;\n}\n\nexport type ToolSet = Record<string, Tool>;\n\nexport type ToolChoice<TOOLS extends ToolSet = ToolSet> =\n | \"auto\"\n | \"none\"\n | \"required\"\n | { type: \"tool\"; toolName: keyof TOOLS & string };\n\nexport interface ToolCall<NAME extends string = string, INPUT = unknown> {\n type: \"tool-call\";\n toolCallId: string;\n toolName: NAME;\n input: INPUT;\n providerExecuted?: boolean;\n providerMetadata?: ProviderMetadata;\n}\n\nexport interface ToolResult<\n NAME extends string = string,\n INPUT = unknown,\n OUTPUT = unknown,\n> {\n type: \"tool-result\";\n toolCallId: string;\n toolName: NAME;\n input: INPUT;\n output: OUTPUT;\n providerMetadata?: ProviderMetadata;\n}\n\nexport type FinishReason =\n | \"stop\"\n | \"length\"\n | \"content-filter\"\n | \"tool-calls\"\n | \"error\"\n | \"other\";\n\nexport interface LanguageModelUsage {\n inputTokens: number | undefined;\n outputTokens: number | undefined;\n totalTokens: number | undefined;\n reasoningTokens?: number;\n cachedInputTokens?: number;\n}\n\nexport interface ProviderMetadata {\n [providerId: string]: Record<string, unknown>;\n}\n\nexport type ProviderOptions = ProviderMetadata;\n\nexport interface Warning {\n type: \"unsupported-tool\" | \"other\";\n details?: string;\n message?: string;\n}\n\nexport interface RequestMetadata {\n body?: unknown;\n}\n\nexport interface ResponseMetadata {\n id?: string;\n modelId?: string;\n timestamp?: Date;\n headers?: Record<string, string>;\n body?: unknown;\n /** Raw assistant messages emitted by the provider. */\n messages?: Array<AssistantModelMessage | ToolModelMessage>;\n}\n\nexport interface ReasoningOutput {\n type: \"reasoning\";\n text: string;\n providerMetadata?: ProviderMetadata;\n}\n\nexport type ContentPart<TOOLS extends ToolSet = ToolSet> =\n | { type: \"text\"; text: string; providerMetadata?: ProviderMetadata }\n | {\n type: \"reasoning\";\n text: string;\n providerMetadata?: ProviderMetadata;\n }\n | (ToolCall<keyof TOOLS & string> & { type: \"tool-call\" })\n | (ToolResult<keyof TOOLS & string> & { type: \"tool-result\" });\n\nexport interface StepResult<TOOLS extends ToolSet = ToolSet> {\n content: Array<ContentPart<TOOLS>>;\n text: string;\n reasoning: Array<ReasoningOutput>;\n reasoningText: string | undefined;\n toolCalls: Array<ToolCall<keyof TOOLS & string>>;\n toolResults: Array<ToolResult<keyof TOOLS & string>>;\n finishReason: FinishReason;\n rawFinishReason: string | undefined;\n usage: LanguageModelUsage;\n warnings: Array<Warning> | undefined;\n request?: RequestMetadata;\n response?: ResponseMetadata;\n providerMetadata: ProviderMetadata | undefined;\n}\n"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,34 @@
1
+ /*
2
+ * Copyright 2026 Palantir Technologies, Inc. All rights reserved.
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
+ */
16
+
17
+ /**
18
+ * UI-level message and stream-chunk shapes for the AIP SDK's chat
19
+ * primitives. Describes the wire format that transports produce and UI
20
+ * consumers read — a thin local subset of the AI SDK v5 UI types
21
+ * covering the v0 text-only surface.
22
+ */
23
+
24
+ /** Concatenate all `text` parts of a UIMessage into a single string. */
25
+ export function getUIMessageText(message) {
26
+ let buf = "";
27
+ for (const p of message.parts) {
28
+ if (p.type === "text") {
29
+ buf += p.text;
30
+ }
31
+ }
32
+ return buf;
33
+ }
34
+ //# sourceMappingURL=uiMessage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uiMessage.js","names":["getUIMessageText","message","buf","p","parts","type","text"],"sources":["uiMessage.ts"],"sourcesContent":["/*\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\n/**\n * UI-level message and stream-chunk shapes for the AIP SDK's chat\n * primitives. Describes the wire format that transports produce and UI\n * consumers read — a thin local subset of the AI SDK v5 UI types\n * covering the v0 text-only surface.\n */\n\nimport type { FinishReason, LanguageModelUsage } from \"./types.js\";\n\nexport type UIMessageRole = \"system\" | \"user\" | \"assistant\";\n\nexport type UIMessagePart =\n | { type: \"text\"; text: string }\n | { type: \"reasoning\"; text: string }\n | { type: \"file\"; url: string; mediaType: string };\n\nexport interface UIMessage {\n id: string;\n role: UIMessageRole;\n parts: Array<UIMessagePart>;\n metadata?: Record<string, unknown>;\n}\n\nexport type UIMessageChunk =\n | { type: \"start\"; messageId: string }\n | { type: \"start-step\" }\n | { type: \"text-start\"; id: string }\n | { type: \"text-delta\"; id: string; delta: string }\n | { type: \"text-end\"; id: string }\n | { type: \"reasoning-start\"; id: string }\n | { type: \"reasoning-delta\"; id: string; delta: string }\n | { type: \"reasoning-end\"; id: string }\n | {\n type: \"tool-input-available\";\n toolCallId: string;\n toolName: string;\n input: unknown;\n }\n | { type: \"finish-step\" }\n | {\n type: \"finish\";\n messageMetadata?: {\n finishReason?: FinishReason;\n usage?: LanguageModelUsage;\n };\n }\n | { type: \"error\"; errorText: string };\n\nexport type ChatTransportTrigger = \"submit-message\" | \"regenerate-message\";\n\nexport interface ChatTransportSendMessagesArgs<MSG extends UIMessage> {\n trigger: ChatTransportTrigger;\n chatId: string;\n messageId: string;\n messages: ReadonlyArray<MSG>;\n abortSignal: AbortSignal | undefined;\n headers?: Record<string, string>;\n}\n\nexport interface ChatTransportReconnectArgs {\n chatId: string;\n}\n\nexport interface ChatTransport<MSG extends UIMessage = UIMessage> {\n sendMessages(\n args: ChatTransportSendMessagesArgs<MSG>,\n ): Promise<ReadableStream<UIMessageChunk>>;\n\n reconnectToStream(\n args: ChatTransportReconnectArgs,\n ): Promise<ReadableStream<UIMessageChunk> | null>;\n}\n\n/** Concatenate all `text` parts of a UIMessage into a single string. */\nexport function getUIMessageText(message: UIMessage): string {\n let buf = \"\";\n for (const p of message.parts) {\n if (p.type === \"text\") {\n buf += p.text;\n }\n }\n return buf;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAoEA;AACA,OAAO,SAASA,gBAAgBA,CAACC,OAAkB,EAAU;EAC3D,IAAIC,GAAG,GAAG,EAAE;EACZ,KAAK,MAAMC,CAAC,IAAIF,OAAO,CAACG,KAAK,EAAE;IAC7B,IAAID,CAAC,CAACE,IAAI,KAAK,MAAM,EAAE;MACrBH,GAAG,IAAIC,CAAC,CAACG,IAAI;IACf;EACF;EACA,OAAOJ,GAAG;AACZ","ignoreList":[]}
@@ -0,0 +1,19 @@
1
+ import type { LanguageModelV3Prompt, SharedV3Warning } from "@ai-sdk/provider";
2
+ export interface OpenAiMessage {
3
+ role: "system" | "user" | "assistant" | "tool";
4
+ content: string | Array<{
5
+ type: "text"
6
+ text: string
7
+ }> | null;
8
+ tool_calls?: Array<OpenAiAssistantToolCall>;
9
+ tool_call_id?: string;
10
+ }
11
+ export interface OpenAiAssistantToolCall {
12
+ id: string;
13
+ type: "function";
14
+ function: {
15
+ name: string
16
+ arguments: string
17
+ };
18
+ }
19
+ export declare function convertPrompt(prompt: LanguageModelV3Prompt, warnings: Array<SharedV3Warning>): Array<OpenAiMessage>;