@puku-ai/sdk 4.0.3 → 4.0.4

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 (199) hide show
  1. package/README.md +24 -7
  2. package/dist/index.cjs +85 -0
  3. package/dist/vendor/_vendor/partial-json-parser/parser.cjs +225 -0
  4. package/dist/vendor/api-promise.cjs +18 -0
  5. package/dist/vendor/client.cjs +1013 -0
  6. package/dist/vendor/core/api-promise.cjs +80 -0
  7. package/dist/vendor/core/api.cjs +2 -0
  8. package/dist/vendor/core/credentials.cjs +313 -0
  9. package/dist/vendor/core/error.cjs +156 -0
  10. package/dist/vendor/core/middleware.cjs +173 -0
  11. package/dist/vendor/core/pagination.cjs +215 -0
  12. package/dist/vendor/core/resource.cjs +11 -0
  13. package/dist/vendor/core/streaming.cjs +346 -0
  14. package/dist/vendor/core/uploads.cjs +5 -0
  15. package/dist/vendor/error.cjs +18 -0
  16. package/dist/vendor/helpers/beta/environments.cjs +30 -0
  17. package/dist/vendor/helpers/beta/json-schema.cjs +56 -0
  18. package/dist/vendor/helpers/beta/mcp.cjs +418 -0
  19. package/dist/vendor/helpers/beta/memory.cjs +17 -0
  20. package/dist/vendor/helpers/beta/standard-schema.cjs +57 -0
  21. package/dist/vendor/helpers/beta/zod.cjs +88 -0
  22. package/dist/vendor/helpers/index.cjs +7 -0
  23. package/dist/vendor/helpers/json-schema.cjs +36 -0
  24. package/dist/vendor/helpers/zod.cjs +77 -0
  25. package/dist/vendor/index.cjs +54 -0
  26. package/dist/vendor/internal/builtin-types.cjs +3 -0
  27. package/dist/vendor/internal/constants.cjs +12 -0
  28. package/dist/vendor/internal/decoders/jsonl.cjs +40 -0
  29. package/dist/vendor/internal/decoders/line.cjs +109 -0
  30. package/dist/vendor/internal/detect-platform.cjs +159 -0
  31. package/dist/vendor/internal/errors.cjs +42 -0
  32. package/dist/vendor/internal/file-store.cjs +535 -0
  33. package/dist/vendor/internal/headers.cjs +119 -0
  34. package/dist/vendor/internal/message-stream-utils.cjs +33 -0
  35. package/dist/vendor/internal/node.browser.cjs +21 -0
  36. package/dist/vendor/internal/node.cjs +55 -0
  37. package/dist/vendor/internal/parse.cjs +65 -0
  38. package/dist/vendor/internal/qs/formats.cjs +12 -0
  39. package/dist/vendor/internal/qs/index.cjs +13 -0
  40. package/dist/vendor/internal/qs/stringify.cjs +276 -0
  41. package/dist/vendor/internal/qs/types.cjs +2 -0
  42. package/dist/vendor/internal/qs/utils.cjs +229 -0
  43. package/dist/vendor/internal/request-options.cjs +31 -0
  44. package/dist/vendor/internal/request-signal.cjs +49 -0
  45. package/dist/vendor/internal/shim-types.cjs +3 -0
  46. package/dist/vendor/internal/shims.cjs +91 -0
  47. package/dist/vendor/internal/stainless-helper-header.cjs +90 -0
  48. package/dist/vendor/internal/stream-utils.cjs +37 -0
  49. package/dist/vendor/internal/to-file.cjs +95 -0
  50. package/dist/vendor/internal/types.cjs +3 -0
  51. package/dist/vendor/internal/uploads.cjs +148 -0
  52. package/dist/vendor/internal/utils/abort.cjs +24 -0
  53. package/dist/vendor/internal/utils/async-queue.cjs +69 -0
  54. package/dist/vendor/internal/utils/backoff.cjs +43 -0
  55. package/dist/vendor/internal/utils/base64.cjs +37 -0
  56. package/dist/vendor/internal/utils/bytes.cjs +30 -0
  57. package/dist/vendor/internal/utils/env.cjs +21 -0
  58. package/dist/vendor/internal/utils/log.cjs +111 -0
  59. package/dist/vendor/internal/utils/path.cjs +78 -0
  60. package/dist/vendor/internal/utils/promise.cjs +17 -0
  61. package/dist/vendor/internal/utils/query.cjs +41 -0
  62. package/dist/vendor/internal/utils/sleep.cjs +27 -0
  63. package/dist/vendor/internal/utils/time.cjs +7 -0
  64. package/dist/vendor/internal/utils/uuid.cjs +18 -0
  65. package/dist/vendor/internal/utils/values.cjs +125 -0
  66. package/dist/vendor/internal/utils.cjs +24 -0
  67. package/dist/vendor/lib/BetaMessageStream.cjs +665 -0
  68. package/dist/vendor/lib/MessageStream.cjs +612 -0
  69. package/dist/vendor/lib/beta-parser.cjs +78 -0
  70. package/dist/vendor/lib/credentials/credential-chain.cjs +244 -0
  71. package/dist/vendor/lib/credentials/identity-token.cjs +71 -0
  72. package/dist/vendor/lib/credentials/oidc-federation.cjs +81 -0
  73. package/dist/vendor/lib/credentials/token-cache.cjs +113 -0
  74. package/dist/vendor/lib/credentials/types.cjs +267 -0
  75. package/dist/vendor/lib/credentials/user-oauth.cjs +129 -0
  76. package/dist/vendor/lib/credentials.cjs +7 -0
  77. package/dist/vendor/lib/environments/index.cjs +17 -0
  78. package/dist/vendor/lib/environments/poller.cjs +226 -0
  79. package/dist/vendor/lib/environments/worker.cjs +609 -0
  80. package/dist/vendor/lib/helper-client.cjs +57 -0
  81. package/dist/vendor/lib/middleware.cjs +779 -0
  82. package/dist/vendor/lib/parser.cjs +65 -0
  83. package/dist/vendor/lib/sessions/accumulate.cjs +44 -0
  84. package/dist/vendor/lib/standard-schema.cjs +44 -0
  85. package/dist/vendor/lib/tools/BetaRunnableTool.cjs +30 -0
  86. package/dist/vendor/lib/tools/BetaToolRunner.cjs +500 -0
  87. package/dist/vendor/lib/tools/CompactionControl.cjs +27 -0
  88. package/dist/vendor/lib/tools/SessionToolRunner.cjs +740 -0
  89. package/dist/vendor/lib/tools/ToolError.cjs +46 -0
  90. package/dist/vendor/lib/transform-json-schema.cjs +113 -0
  91. package/dist/vendor/pagination.cjs +18 -0
  92. package/dist/vendor/resource.cjs +18 -0
  93. package/dist/vendor/resources/beta/agents/agents.cjs +159 -0
  94. package/dist/vendor/resources/beta/agents/index.cjs +8 -0
  95. package/dist/vendor/resources/beta/agents/versions.cjs +35 -0
  96. package/dist/vendor/resources/beta/agents.cjs +18 -0
  97. package/dist/vendor/resources/beta/beta.cjs +105 -0
  98. package/dist/vendor/resources/beta/deployment-runs.cjs +54 -0
  99. package/dist/vendor/resources/beta/deployments.cjs +195 -0
  100. package/dist/vendor/resources/beta/dreams.cjs +115 -0
  101. package/dist/vendor/resources/beta/environments/environments.cjs +178 -0
  102. package/dist/vendor/resources/beta/environments/index.cjs +8 -0
  103. package/dist/vendor/resources/beta/environments/work.cjs +256 -0
  104. package/dist/vendor/resources/beta/environments.cjs +18 -0
  105. package/dist/vendor/resources/beta/files.cjs +123 -0
  106. package/dist/vendor/resources/beta/index.cjs +38 -0
  107. package/dist/vendor/resources/beta/memory-stores/index.cjs +10 -0
  108. package/dist/vendor/resources/beta/memory-stores/memories.cjs +129 -0
  109. package/dist/vendor/resources/beta/memory-stores/memory-stores.cjs +173 -0
  110. package/dist/vendor/resources/beta/memory-stores/memory-versions.cjs +80 -0
  111. package/dist/vendor/resources/beta/memory-stores.cjs +18 -0
  112. package/dist/vendor/resources/beta/messages/batches.cjs +206 -0
  113. package/dist/vendor/resources/beta/messages/index.cjs +11 -0
  114. package/dist/vendor/resources/beta/messages/messages.cjs +189 -0
  115. package/dist/vendor/resources/beta/messages.cjs +18 -0
  116. package/dist/vendor/resources/beta/models.cjs +59 -0
  117. package/dist/vendor/resources/beta/organization/api-keys.cjs +55 -0
  118. package/dist/vendor/resources/beta/organization/compliance-settings.cjs +51 -0
  119. package/dist/vendor/resources/beta/organization/external-keys.cjs +118 -0
  120. package/dist/vendor/resources/beta/organization/federation/federation.cjs +49 -0
  121. package/dist/vendor/resources/beta/organization/federation/index.cjs +10 -0
  122. package/dist/vendor/resources/beta/organization/federation/issuers.cjs +168 -0
  123. package/dist/vendor/resources/beta/organization/federation/rules/index.cjs +8 -0
  124. package/dist/vendor/resources/beta/organization/federation/rules/rules.cjs +226 -0
  125. package/dist/vendor/resources/beta/organization/federation/rules/workspaces.cjs +113 -0
  126. package/dist/vendor/resources/beta/organization/federation/rules.cjs +18 -0
  127. package/dist/vendor/resources/beta/organization/federation.cjs +18 -0
  128. package/dist/vendor/resources/beta/organization/index.cjs +24 -0
  129. package/dist/vendor/resources/beta/organization/invites.cjs +75 -0
  130. package/dist/vendor/resources/beta/organization/organization.cjs +90 -0
  131. package/dist/vendor/resources/beta/organization/rate-limits.cjs +30 -0
  132. package/dist/vendor/resources/beta/organization/service-accounts/index.cjs +8 -0
  133. package/dist/vendor/resources/beta/organization/service-accounts/service-accounts.cjs +202 -0
  134. package/dist/vendor/resources/beta/organization/service-accounts/workspaces.cjs +124 -0
  135. package/dist/vendor/resources/beta/organization/service-accounts.cjs +18 -0
  136. package/dist/vendor/resources/beta/organization/users.cjs +66 -0
  137. package/dist/vendor/resources/beta/organization/workspaces/index.cjs +12 -0
  138. package/dist/vendor/resources/beta/organization/workspaces/members.cjs +101 -0
  139. package/dist/vendor/resources/beta/organization/workspaces/rate-limits.cjs +33 -0
  140. package/dist/vendor/resources/beta/organization/workspaces/service-accounts.cjs +188 -0
  141. package/dist/vendor/resources/beta/organization/workspaces/workspaces.cjs +140 -0
  142. package/dist/vendor/resources/beta/organization/workspaces.cjs +18 -0
  143. package/dist/vendor/resources/beta/organization.cjs +18 -0
  144. package/dist/vendor/resources/beta/sessions/events.cjs +119 -0
  145. package/dist/vendor/resources/beta/sessions/index.cjs +12 -0
  146. package/dist/vendor/resources/beta/sessions/resources.cjs +131 -0
  147. package/dist/vendor/resources/beta/sessions/sessions.cjs +186 -0
  148. package/dist/vendor/resources/beta/sessions/threads/events.cjs +60 -0
  149. package/dist/vendor/resources/beta/sessions/threads/index.cjs +8 -0
  150. package/dist/vendor/resources/beta/sessions/threads/threads.cjs +116 -0
  151. package/dist/vendor/resources/beta/sessions/threads.cjs +18 -0
  152. package/dist/vendor/resources/beta/sessions.cjs +18 -0
  153. package/dist/vendor/resources/beta/skills/index.cjs +8 -0
  154. package/dist/vendor/resources/beta/skills/skills.cjs +132 -0
  155. package/dist/vendor/resources/beta/skills/versions.cjs +128 -0
  156. package/dist/vendor/resources/beta/skills.cjs +18 -0
  157. package/dist/vendor/resources/beta/tunnels/certificates.cjs +128 -0
  158. package/dist/vendor/resources/beta/tunnels/index.cjs +8 -0
  159. package/dist/vendor/resources/beta/tunnels/tunnels.cjs +209 -0
  160. package/dist/vendor/resources/beta/tunnels.cjs +18 -0
  161. package/dist/vendor/resources/beta/user-profiles.cjs +117 -0
  162. package/dist/vendor/resources/beta/vaults/credentials.cjs +176 -0
  163. package/dist/vendor/resources/beta/vaults/index.cjs +8 -0
  164. package/dist/vendor/resources/beta/vaults/vaults.cjs +177 -0
  165. package/dist/vendor/resources/beta/vaults.cjs +18 -0
  166. package/dist/vendor/resources/beta/webhooks.cjs +32 -0
  167. package/dist/vendor/resources/beta.cjs +18 -0
  168. package/dist/vendor/resources/completions.cjs +22 -0
  169. package/dist/vendor/resources/files.cjs +51 -0
  170. package/dist/vendor/resources/index.cjs +31 -0
  171. package/dist/vendor/resources/messages/batches.cjs +160 -0
  172. package/dist/vendor/resources/messages/index.cjs +8 -0
  173. package/dist/vendor/resources/messages/messages.cjs +159 -0
  174. package/dist/vendor/resources/messages.cjs +18 -0
  175. package/dist/vendor/resources/models.cjs +44 -0
  176. package/dist/vendor/resources/shared.cjs +3 -0
  177. package/dist/vendor/resources/skills/index.cjs +8 -0
  178. package/dist/vendor/resources/skills/skills.cjs +72 -0
  179. package/dist/vendor/resources/skills/versions.cjs +40 -0
  180. package/dist/vendor/resources/skills.cjs +18 -0
  181. package/dist/vendor/resources/top-level.cjs +3 -0
  182. package/dist/vendor/resources.cjs +17 -0
  183. package/dist/vendor/streaming.cjs +18 -0
  184. package/dist/vendor/tools/agent-toolset/fs-util.cjs +193 -0
  185. package/dist/vendor/tools/agent-toolset/memories.cjs +916 -0
  186. package/dist/vendor/tools/agent-toolset/node.browser.cjs +147 -0
  187. package/dist/vendor/tools/agent-toolset/node.cjs +939 -0
  188. package/dist/vendor/tools/agent-toolset/skills.cjs +325 -0
  189. package/dist/vendor/tools/agent-toolset/sync-interval.cjs +28 -0
  190. package/dist/vendor/tools/memory/node.browser.cjs +48 -0
  191. package/dist/vendor/tools/memory/node.cjs +364 -0
  192. package/dist/vendor/uploads.cjs +18 -0
  193. package/dist/vendor/version.cjs +4 -0
  194. package/package.json +12 -13
  195. package/sdk.cjs +0 -14271
  196. package/sdk.cjs.map +0 -149
  197. package/sdk.d.ts +0 -10866
  198. package/sdk.mjs +0 -68
  199. package/sdk.mjs.map +0 -149
@@ -0,0 +1,418 @@
1
+ "use strict";
2
+ /**
3
+ * Helper functions for integrating MCP (Model Context Protocol) SDK types
4
+ * with the PukuAI SDK.
5
+ *
6
+ * These helpers reduce boilerplate when converting between MCP types and
7
+ * PukuAI API types. The interfaces defined here use TypeScript's structural
8
+ * typing to match MCP SDK types without requiring a direct dependency.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.UnsupportedMCPValueError = exports.stainlessHelperHeader = exports.collectStainlessHelpers = exports.SDK_HELPER_SYMBOL = void 0;
12
+ exports.mcpTool = mcpTool;
13
+ exports.mcpTools = mcpTools;
14
+ exports.mcpMessage = mcpMessage;
15
+ exports.mcpMessages = mcpMessages;
16
+ exports.mcpContent = mcpContent;
17
+ exports.mcpResourceToContent = mcpResourceToContent;
18
+ exports.mcpResourceToFile = mcpResourceToFile;
19
+ const ToolError_1 = require("../../lib/tools/ToolError");
20
+ const stainless_helper_header_1 = require("../../internal/stainless-helper-header");
21
+ Object.defineProperty(exports, "SDK_HELPER_SYMBOL", { enumerable: true, get: function () { return stainless_helper_header_1.SDK_HELPER_SYMBOL; } });
22
+ Object.defineProperty(exports, "collectStainlessHelpers", { enumerable: true, get: function () { return stainless_helper_header_1.collectStainlessHelpers; } });
23
+ Object.defineProperty(exports, "stainlessHelperHeader", { enumerable: true, get: function () { return stainless_helper_header_1.stainlessHelperHeader; } });
24
+ const base64_1 = require("../../internal/utils/base64");
25
+ // -----------------------------------------------------------------------------
26
+ // Supported MIME types
27
+ // -----------------------------------------------------------------------------
28
+ const SUPPORTED_IMAGE_TYPES = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'];
29
+ function isSupportedImageType(mimeType) {
30
+ return SUPPORTED_IMAGE_TYPES.includes(mimeType);
31
+ }
32
+ function isSupportedResourceMimeType(mimeType) {
33
+ return (!mimeType ||
34
+ mimeType.startsWith('text/') ||
35
+ mimeType === 'application/pdf' ||
36
+ isSupportedImageType(mimeType));
37
+ }
38
+ // -----------------------------------------------------------------------------
39
+ // Error classes
40
+ // -----------------------------------------------------------------------------
41
+ /**
42
+ * Error thrown when an MCP value cannot be converted to a format supported by the Puku API.
43
+ */
44
+ class UnsupportedMCPValueError extends Error {
45
+ constructor(message) {
46
+ super(message);
47
+ this.name = 'UnsupportedMCPValueError';
48
+ }
49
+ }
50
+ exports.UnsupportedMCPValueError = UnsupportedMCPValueError;
51
+ // -----------------------------------------------------------------------------
52
+ // Helper functions
53
+ // -----------------------------------------------------------------------------
54
+ /**
55
+ * Converts an MCP tool to a BetaRunnableTool for use with the PukuAI SDK's
56
+ * `toolRunner()` method.
57
+ *
58
+ * @param tool The MCP tool definition from `mcpClient.listTools()`
59
+ * @param mcpClient The MCP client instance used to call the tool
60
+ * @param extraProps Additional Puku API properties to include in the tool definition
61
+ * @returns A runnable tool for use with `puku.beta.messages.toolRunner()`
62
+ * @throws {UnsupportedMCPValueError} When the tool returns unsupported content types
63
+ * @throws {UnsupportedMCPValueError} When the tool returns unsupported resource links
64
+ * @throws {UnsupportedMCPValueError} When the tool returns resources with unsupported MIME types
65
+ *
66
+ * @example
67
+ * ```ts
68
+ * import { Client } from "@modelcontextprotocol/sdk/client/index.js";
69
+ * import PukuAI from "@puku-ai/sdk";
70
+ * import { mcpTool } from "@puku-ai/sdk/helpers/beta/mcp";
71
+ *
72
+ * const mcpClient = new Client({ name: "example", version: "1.0.0" });
73
+ * const puku = new PukuAI();
74
+ *
75
+ * const tools = await mcpClient.listTools();
76
+ * const runner = await puku.beta.messages.toolRunner({
77
+ * model: "puku-ai-2.8",
78
+ * max_tokens: 1024,
79
+ * tools: tools.tools.map(tool => mcpTool(tool, mcpClient)),
80
+ * messages: [{ role: "user", content: "Use the available tools" }],
81
+ * });
82
+ * ```
83
+ */
84
+ function mcpTool(tool, mcpClient, extraProps) {
85
+ // Transform inputSchema to match BetaTool.InputSchema (convert undefined to null)
86
+ const inputSchema = {
87
+ ...tool.inputSchema,
88
+ type: 'object',
89
+ properties: tool.inputSchema.properties ?? null,
90
+ required: tool.inputSchema.required ?? null,
91
+ };
92
+ const betaTool = {
93
+ name: tool.name,
94
+ input_schema: inputSchema,
95
+ ...(tool.description !== undefined ? { description: tool.description } : {}),
96
+ ...extraProps,
97
+ };
98
+ const runnableTool = {
99
+ ...betaTool,
100
+ run: async (input) => {
101
+ const result = await mcpClient.callTool({
102
+ name: tool.name,
103
+ arguments: input,
104
+ });
105
+ if (result.isError) {
106
+ const content = result.content.map((item) => mcpContent(item));
107
+ throw new ToolError_1.ToolError(content);
108
+ }
109
+ // If content is empty but structuredContent is present, JSON encode it
110
+ // Spec: "For backwards compatibility, a tool that returns structured content SHOULD also return the serialized JSON in a TextContent block."
111
+ // meaning it's not required and cannot be assumed.
112
+ if (result.content.length === 0 &&
113
+ // Spec: "Structured content is returned as a JSON object in the structuredContent field of a result."
114
+ typeof result.structuredContent === 'object' &&
115
+ result.structuredContent !== null) {
116
+ return JSON.stringify(result.structuredContent);
117
+ }
118
+ return result.content.map((item) => mcpContent(item));
119
+ },
120
+ parse: (content) => content,
121
+ [stainless_helper_header_1.SDK_HELPER_SYMBOL]: 'mcpTool',
122
+ };
123
+ return runnableTool;
124
+ }
125
+ /**
126
+ * Converts an array of MCP tools to BetaRunnableTools.
127
+ *
128
+ * @param tools Array of MCP tool definitions from `mcpClient.listTools()`
129
+ * @param mcpClient The MCP client instance used to call the tools
130
+ * @param extraProps Additional Puku API properties to include in each tool definition
131
+ * @returns An array of runnable tools for use with `puku.beta.messages.toolRunner()`
132
+ *
133
+ * @example
134
+ * ```ts
135
+ * const { tools } = await mcpClient.listTools();
136
+ * const runner = await puku.beta.messages.toolRunner({
137
+ * model: "puku-ai-2.8",
138
+ * max_tokens: 1024,
139
+ * tools: mcpTools(tools, mcpClient),
140
+ * messages: [{ role: "user", content: "Use the available tools" }],
141
+ * });
142
+ * ```
143
+ */
144
+ function mcpTools(tools, mcpClient, extraProps) {
145
+ return tools.map((tool) => mcpTool(tool, mcpClient, extraProps));
146
+ }
147
+ /**
148
+ * Converts an MCP prompt message to an PukuAI BetaMessageParam.
149
+ *
150
+ * @param mcpMessage The MCP prompt message from `mcpClient.getPrompt()`
151
+ * @param extraProps Additional Puku API properties to include in content blocks (e.g., `cache_control`)
152
+ * @returns A message parameter for use with `puku.beta.messages.create()`
153
+ * @throws {UnsupportedMCPValueError} When the message contains unsupported content types
154
+ * @throws {UnsupportedMCPValueError} When the message contains unsupported resource links
155
+ * @throws {UnsupportedMCPValueError} When the message contains resources with unsupported MIME types
156
+ *
157
+ * @example
158
+ * ```ts
159
+ * import { Client } from "@modelcontextprotocol/sdk/client/index.js";
160
+ * import PukuAI from "@puku-ai/sdk";
161
+ * import { mcpMessage } from "@puku-ai/sdk/helpers/beta/mcp";
162
+ *
163
+ * const mcpClient = new Client({ name: "example", version: "1.0.0" });
164
+ * const puku = new PukuAI();
165
+ *
166
+ * const prompt = await mcpClient.getPrompt({
167
+ * name: "example-prompt",
168
+ * arguments: { arg1: "value" },
169
+ * });
170
+ *
171
+ * await puku.beta.messages.create({
172
+ * model: "puku-ai-2.8",
173
+ * max_tokens: 1024,
174
+ * messages: prompt.messages.map(msg => mcpMessage(msg)),
175
+ * });
176
+ * ```
177
+ */
178
+ function mcpMessage(mcpMessage, extraProps) {
179
+ const message = {
180
+ role: mcpMessage.role,
181
+ content: [mcpContent(mcpMessage.content, extraProps)],
182
+ [stainless_helper_header_1.SDK_HELPER_SYMBOL]: 'mcpMessage',
183
+ };
184
+ return message;
185
+ }
186
+ /**
187
+ * Converts an array of MCP prompt messages to PukuAI BetaMessageParams.
188
+ *
189
+ * @param messages Array of MCP prompt messages from `mcpClient.getPrompt()`
190
+ * @param extraProps Additional Puku API properties to include in content blocks (e.g., `cache_control`)
191
+ * @returns An array of message parameters for use with `puku.beta.messages.create()`
192
+ * @throws {UnsupportedMCPValueError} When any message contains unsupported content types
193
+ * @throws {UnsupportedMCPValueError} When any message contains unsupported resource links
194
+ * @throws {UnsupportedMCPValueError} When any message contains resources with unsupported MIME types
195
+ *
196
+ * @example
197
+ * ```ts
198
+ * const { messages } = await mcpClient.getPrompt({ name: "example-prompt" });
199
+ * await puku.beta.messages.create({
200
+ * model: "puku-ai-2.8",
201
+ * max_tokens: 1024,
202
+ * messages: mcpMessages(messages),
203
+ * });
204
+ * ```
205
+ */
206
+ function mcpMessages(messages, extraProps) {
207
+ return messages.map((message) => mcpMessage(message, extraProps));
208
+ }
209
+ /**
210
+ * Converts a single MCP prompt content item to an PukuAI content block.
211
+ *
212
+ * @param content The MCP content item (text, image, or embedded resource)
213
+ * @param extraProps Additional Puku API properties to include in the content block (e.g., `cache_control`)
214
+ * @returns A Puku content block for use in a message's content array
215
+ * @throws {UnsupportedMCPValueError} When the content type is not supported (e.g., 'audio')
216
+ * @throws {UnsupportedMCPValueError} When resource links use non-http/https protocols
217
+ * @throws {UnsupportedMCPValueError} When resources have unsupported MIME types
218
+ *
219
+ * @example
220
+ * ```ts
221
+ * const { messages } = await mcpClient.getPrompt({ name: "my-prompt" });
222
+ * // If you need to mix MCP content with other content:
223
+ * await puku.beta.messages.create({
224
+ * model: "puku-ai-2.8",
225
+ * max_tokens: 1024,
226
+ * messages: [{
227
+ * role: "user",
228
+ * content: [
229
+ * mcpContent(messages[0].content),
230
+ * { type: "text", text: "Additional context" },
231
+ * ],
232
+ * }],
233
+ * });
234
+ * ```
235
+ */
236
+ function mcpContent(content, extraProps) {
237
+ switch (content.type) {
238
+ case 'text': {
239
+ const textBlock = {
240
+ type: 'text',
241
+ text: content.text,
242
+ ...extraProps,
243
+ [stainless_helper_header_1.SDK_HELPER_SYMBOL]: 'mcpContent',
244
+ };
245
+ return textBlock;
246
+ }
247
+ case 'image': {
248
+ if (!isSupportedImageType(content.mimeType)) {
249
+ throw new UnsupportedMCPValueError(`Unsupported image MIME type: ${content.mimeType}`);
250
+ }
251
+ const imageBlock = {
252
+ type: 'image',
253
+ source: {
254
+ type: 'base64',
255
+ data: content.data,
256
+ media_type: content.mimeType,
257
+ },
258
+ ...extraProps,
259
+ [stainless_helper_header_1.SDK_HELPER_SYMBOL]: 'mcpContent',
260
+ };
261
+ return imageBlock;
262
+ }
263
+ case 'resource':
264
+ return mcpResourceContentToContentBlock(content.resource, extraProps, 'mcpContent');
265
+ case 'resource_link':
266
+ case 'audio':
267
+ throw new UnsupportedMCPValueError(`Unsupported MCP content type: ${content.type}`);
268
+ default:
269
+ // This should never happen as we handle all MCPPromptContentLike types
270
+ content;
271
+ throw new UnsupportedMCPValueError(`Unsupported MCP content type: ${content.type}`);
272
+ }
273
+ }
274
+ /**
275
+ * Converts a single MCP resource contents item to an PukuAI content block.
276
+ */
277
+ function mcpResourceContentToContentBlock(resourceContent, extraProps, helperName = 'mcpResourceToContent') {
278
+ const mimeType = resourceContent.mimeType;
279
+ // Handle images (requires blob - base64-encoded binary data)
280
+ if (mimeType && isSupportedImageType(mimeType)) {
281
+ if (!('blob' in resourceContent)) {
282
+ throw new UnsupportedMCPValueError(`Image resource must have blob data, not text. URI: ${resourceContent.uri}`);
283
+ }
284
+ const imageBlock = {
285
+ type: 'image',
286
+ source: {
287
+ type: 'base64',
288
+ data: resourceContent.blob,
289
+ media_type: mimeType,
290
+ },
291
+ ...extraProps,
292
+ [stainless_helper_header_1.SDK_HELPER_SYMBOL]: helperName,
293
+ };
294
+ return imageBlock;
295
+ }
296
+ // Handle PDFs (requires blob - base64-encoded binary data)
297
+ if (mimeType === 'application/pdf') {
298
+ if (!('blob' in resourceContent)) {
299
+ throw new UnsupportedMCPValueError(`PDF resource must have blob data, not text. URI: ${resourceContent.uri}`);
300
+ }
301
+ const pdfBlock = {
302
+ type: 'document',
303
+ source: {
304
+ type: 'base64',
305
+ data: resourceContent.blob,
306
+ media_type: 'application/pdf',
307
+ },
308
+ ...extraProps,
309
+ [stainless_helper_header_1.SDK_HELPER_SYMBOL]: helperName,
310
+ };
311
+ return pdfBlock;
312
+ }
313
+ // Handle text types (text/*, or no MIME type defaults to text)
314
+ if (!mimeType || mimeType.startsWith('text/')) {
315
+ const textDocBlock = {
316
+ type: 'document',
317
+ source: textSourceFromResource(resourceContent),
318
+ ...extraProps,
319
+ [stainless_helper_header_1.SDK_HELPER_SYMBOL]: helperName,
320
+ };
321
+ return textDocBlock;
322
+ }
323
+ throw new UnsupportedMCPValueError(`Unsupported MIME type "${mimeType}" for resource: ${resourceContent.uri}`);
324
+ }
325
+ /**
326
+ * Converts MCP resource contents to an PukuAI content block.
327
+ *
328
+ * This helper is useful when you have resource contents from `mcpClient.readResource()`
329
+ * and want to include them in a message or as a document source. It automatically
330
+ * finds the first resource with a supported MIME type.
331
+ *
332
+ * @param result The result from `mcpClient.readResource()`
333
+ * @param extraProps Additional Puku API properties to include in the content block (e.g., `cache_control`)
334
+ * @returns A Puku content block
335
+ * @throws {UnsupportedMCPValueError} When contents array is empty or none have a supported MIME type
336
+ *
337
+ * @example
338
+ * ```ts
339
+ * import { Client } from "@modelcontextprotocol/sdk/client/index.js";
340
+ * import PukuAI from "@puku-ai/sdk";
341
+ * import { mcpResourceToContent } from "@puku-ai/sdk/helpers/beta/mcp";
342
+ *
343
+ * const mcpClient = new Client({ name: "example", version: "1.0.0" });
344
+ * const puku = new PukuAI();
345
+ *
346
+ * const resource = await mcpClient.readResource({ uri: "file:///example.txt" });
347
+ * await puku.beta.messages.create({
348
+ * model: "puku-ai-2.8",
349
+ * max_tokens: 1024,
350
+ * messages: [{
351
+ * role: "user",
352
+ * content: [mcpResourceToContent(resource)],
353
+ * }],
354
+ * });
355
+ * ```
356
+ */
357
+ function mcpResourceToContent(result, extraProps) {
358
+ if (result.contents.length === 0) {
359
+ throw new UnsupportedMCPValueError('Resource contents array must contain at least one item');
360
+ }
361
+ const supported = result.contents.find((c) => isSupportedResourceMimeType(c.mimeType));
362
+ if (!supported) {
363
+ const mimeTypes = result.contents.map((c) => c.mimeType).filter((m) => m !== undefined);
364
+ throw new UnsupportedMCPValueError(`No supported MIME type found in resource contents. Available: ${mimeTypes.join(', ')}`);
365
+ }
366
+ return mcpResourceContentToContentBlock(supported, extraProps);
367
+ }
368
+ /**
369
+ * Gets the raw bytes from an MCP resource.
370
+ */
371
+ function bytesFromResource(resource) {
372
+ if ('blob' in resource) {
373
+ return (0, base64_1.fromBase64)(resource.blob);
374
+ }
375
+ return new TextEncoder().encode(resource.text);
376
+ }
377
+ /**
378
+ * Creates a text document source from an MCP resource, decoding base64 blob to UTF-8 if needed.
379
+ */
380
+ function textSourceFromResource(resource) {
381
+ const data = 'text' in resource ? resource.text : new TextDecoder().decode((0, base64_1.fromBase64)(resource.blob));
382
+ return { type: 'text', data, media_type: 'text/plain' };
383
+ }
384
+ /**
385
+ * Converts an MCP resource to a File object suitable for uploading via `puku.beta.files.upload()`.
386
+ *
387
+ * @param result The result from `mcpClient.readResource()`
388
+ * @returns A File object for use with `puku.beta.files.upload()`
389
+ * @throws {UnsupportedMCPValueError} When contents array is empty
390
+ *
391
+ * @example
392
+ * ```ts
393
+ * import { Client } from "@modelcontextprotocol/sdk/client/index.js";
394
+ * import PukuAI from "@puku-ai/sdk";
395
+ * import { mcpResourceToFile } from "@puku-ai/sdk/helpers/beta/mcp";
396
+ *
397
+ * const mcpClient = new Client({ name: "example", version: "1.0.0" });
398
+ * const puku = new PukuAI();
399
+ *
400
+ * const resource = await mcpClient.readResource({ uri: "file:///document.pdf" });
401
+ *
402
+ * const uploaded = await puku.beta.files.upload({
403
+ * file: mcpResourceToFile(resource),
404
+ * });
405
+ * ```
406
+ */
407
+ function mcpResourceToFile(result) {
408
+ if (result.contents.length === 0) {
409
+ throw new UnsupportedMCPValueError('Resource contents array must contain at least one item');
410
+ }
411
+ const resourceContents = result.contents[0];
412
+ const name = new URL(resourceContents.uri).pathname.split('/').at(-1) || 'file';
413
+ const type = resourceContents.mimeType;
414
+ const data = bytesFromResource(resourceContents);
415
+ const file = new File([data], name, type ? { type } : undefined);
416
+ file[stainless_helper_header_1.SDK_HELPER_SYMBOL] = 'mcpResourceToFile';
417
+ return file;
418
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.betaMemoryTool = betaMemoryTool;
4
+ function betaMemoryTool(handlers) {
5
+ return {
6
+ type: 'memory_20250818',
7
+ name: 'memory',
8
+ parse: (content) => content,
9
+ run: (args) => {
10
+ const handler = handlers[args.command];
11
+ if (!handler) {
12
+ throw new Error(`${args.command} not implemented`);
13
+ }
14
+ return handler.bind(handlers)(args);
15
+ },
16
+ };
17
+ }
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.betaStandardSchemaOutputFormat = betaStandardSchemaOutputFormat;
4
+ exports.betaStandardSchemaTool = betaStandardSchemaTool;
5
+ const transform_json_schema_1 = require("../../lib/transform-json-schema");
6
+ const error_1 = require("../../core/error");
7
+ const standard_schema_1 = require("../../lib/standard-schema");
8
+ /**
9
+ * Creates a JSON schema output format object from the given
10
+ * [Standard Schema](https://standardschema.dev) (Zod, Valibot, ArkType, ...).
11
+ *
12
+ * If this is passed to the `.parse()` method then the response message will contain a
13
+ * `.parsed_output` property that is the result of parsing the content with the given schema.
14
+ *
15
+ * This can be passed directly to the `.create()` method but will not
16
+ * result in any automatic parsing, you'll have to parse the response yourself.
17
+ */
18
+ function betaStandardSchemaOutputFormat(schema, options) {
19
+ const jsonSchema = (0, transform_json_schema_1.transformJSONSchema)((0, standard_schema_1.standardSchemaToJSONSchema)(schema, options?.jsonSchema));
20
+ return {
21
+ type: 'json_schema',
22
+ schema: {
23
+ ...jsonSchema,
24
+ },
25
+ parse: (content) => {
26
+ let parsed;
27
+ try {
28
+ parsed = JSON.parse(content);
29
+ }
30
+ catch (error) {
31
+ throw new error_1.PukuError(`Failed to parse structured output as JSON: ${error instanceof Error ? error.message : String(error)}`);
32
+ }
33
+ return (0, standard_schema_1.parseWithStandardSchema)(schema, parsed);
34
+ },
35
+ };
36
+ }
37
+ /**
38
+ * Creates a tool using the provided [Standard Schema](https://standardschema.dev)
39
+ * (Zod, Valibot, ArkType, ...) that can be passed into the `.toolRunner()` method.
40
+ * The schema's JSON Schema representation is sent to the API and the provided
41
+ * function's input arguments will be validated against the schema.
42
+ */
43
+ function betaStandardSchemaTool(options) {
44
+ const jsonSchema = (0, standard_schema_1.standardSchemaToJSONSchema)(options.inputSchema, options.jsonSchema);
45
+ if (jsonSchema['type'] !== 'object') {
46
+ throw new Error(`Schema for tool "${options.name}" must be an object, but got ${String(jsonSchema['type'])}`);
47
+ }
48
+ return {
49
+ type: 'custom',
50
+ name: options.name,
51
+ input_schema: jsonSchema,
52
+ description: options.description,
53
+ run: options.run,
54
+ parse: (args) => (0, standard_schema_1.parseWithStandardSchema)(options.inputSchema, args),
55
+ ...(options.close ? { close: options.close } : {}),
56
+ };
57
+ }
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.betaZodOutputFormat = betaZodOutputFormat;
37
+ exports.betaZodTool = betaZodTool;
38
+ const transform_json_schema_1 = require("../..//lib/transform-json-schema");
39
+ const z = __importStar(require("zod/v4"));
40
+ const error_1 = require("../../core/error");
41
+ /**
42
+ * Creates a JSON schema output format object from the given Zod schema.
43
+ *
44
+ * If this is passed to the `.parse()` method then the response message will contain a
45
+ * `.parsed_output` property that is the result of parsing the content with the given Zod object.
46
+ *
47
+ * This can be passed directly to the `.create()` method but will not
48
+ * result in any automatic parsing, you'll have to parse the response yourself.
49
+ */
50
+ function betaZodOutputFormat(zodObject) {
51
+ const jsonSchema = (0, transform_json_schema_1.transformJSONSchema)(z.toJSONSchema(zodObject, { reused: 'ref' }));
52
+ return {
53
+ type: 'json_schema',
54
+ schema: {
55
+ ...jsonSchema,
56
+ },
57
+ parse: (content) => {
58
+ const output = zodObject.safeParse(JSON.parse(content));
59
+ if (!output.success) {
60
+ throw new error_1.PukuError(`Failed to parse structured output: ${output.error.message} cause: ${output.error.issues}`);
61
+ }
62
+ return output.data;
63
+ },
64
+ };
65
+ }
66
+ /**
67
+ * Creates a tool using the provided Zod schema that can be passed
68
+ * into the `.toolRunner()` method. The Zod schema will automatically be
69
+ * converted into JSON Schema when passed to the API. The provided function's
70
+ * input arguments will also be validated against the provided schema.
71
+ */
72
+ function betaZodTool(options) {
73
+ const jsonSchema = z.toJSONSchema(options.inputSchema, { reused: 'ref' });
74
+ if (jsonSchema.type !== 'object') {
75
+ throw new Error(`Zod schema for tool "${options.name}" must be an object, but got ${jsonSchema.type}`);
76
+ }
77
+ // TypeScript doesn't narrow the type after the runtime check, so we need to assert it
78
+ const objectSchema = jsonSchema;
79
+ return {
80
+ type: 'custom',
81
+ name: options.name,
82
+ input_schema: objectSchema,
83
+ description: options.description,
84
+ run: options.run,
85
+ parse: (args) => options.inputSchema.parse(args),
86
+ ...(options.close ? { close: options.close } : {}),
87
+ };
88
+ }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.zodOutputFormat = exports.jsonSchemaOutputFormat = void 0;
4
+ var json_schema_1 = require("./json-schema");
5
+ Object.defineProperty(exports, "jsonSchemaOutputFormat", { enumerable: true, get: function () { return json_schema_1.jsonSchemaOutputFormat; } });
6
+ var zod_1 = require("./zod");
7
+ Object.defineProperty(exports, "zodOutputFormat", { enumerable: true, get: function () { return zod_1.zodOutputFormat; } });
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.jsonSchemaOutputFormat = jsonSchemaOutputFormat;
4
+ const error_1 = require("../core/error");
5
+ const transform_json_schema_1 = require("../lib/transform-json-schema");
6
+ /**
7
+ * Creates a JSON schema output format object from the given JSON schema.
8
+ * If this is passed to the `.parse()` method then the response message will contain a
9
+ * `.parsed_output` property that is the result of parsing the content with the given JSON schema.
10
+ *
11
+ * Note: When `transform` is enabled (the default), the schema is deep-cloned before transformation,
12
+ * so the original schema object is not modified.
13
+ */
14
+ function jsonSchemaOutputFormat(jsonSchema, options) {
15
+ if (jsonSchema.type !== 'object') {
16
+ throw new Error(`JSON schema must be an object, but got ${jsonSchema.type}`);
17
+ }
18
+ const transform = options?.transform ?? true;
19
+ if (transform) {
20
+ jsonSchema = (0, transform_json_schema_1.transformJSONSchema)(jsonSchema);
21
+ }
22
+ return {
23
+ type: 'json_schema',
24
+ schema: {
25
+ ...jsonSchema,
26
+ },
27
+ parse: (content) => {
28
+ try {
29
+ return JSON.parse(content);
30
+ }
31
+ catch (error) {
32
+ throw new error_1.PukuError(`Failed to parse structured output: ${error instanceof Error ? error.message : String(error)}`);
33
+ }
34
+ },
35
+ };
36
+ }