@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,159 @@
1
+ "use strict";
2
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ exports.Messages = void 0;
38
+ const resource_1 = require("../../core/resource");
39
+ const headers_1 = require("../../internal/headers");
40
+ const stainless_helper_header_1 = require("../../internal/stainless-helper-header");
41
+ const MessageStream_1 = require("../../lib/MessageStream");
42
+ const parser_1 = require("../../lib/parser");
43
+ const BatchesAPI = __importStar(require("./batches"));
44
+ const batches_1 = require("./batches");
45
+ const constants_1 = require("../../internal/constants");
46
+ class Messages extends resource_1.APIResource {
47
+ batches = new BatchesAPI.Batches(this._client);
48
+ create(params, options) {
49
+ const { user_profile_id, ...body } = params;
50
+ if (body.model in DEPRECATED_MODELS) {
51
+ console.warn(`The Puku SDK model '${body.model}' is deprecated and will reach end-of-life on ${DEPRECATED_MODELS[body.model]}\nPlease migrate to a newer model. Visit https://puku.ai/docs/resources/model-deprecations for more information.`);
52
+ }
53
+ if (MODELS_TO_WARN_WITH_THINKING_ENABLED.includes(body.model) &&
54
+ body.thinking &&
55
+ body.thinking.type === 'enabled') {
56
+ console.warn(`Using Puku with ${body.model} and 'thinking.type=enabled' is deprecated. Use 'thinking.type=adaptive' instead which results in better model performance in our testing: https://puku.ai/docs/en/build-with-puku/adaptive-thinking`);
57
+ }
58
+ let timeout = options?.timeout ?? this._client._options.timeout;
59
+ if (!body.stream && timeout == null) {
60
+ const maxNonstreamingTokens = constants_1.MODEL_NONSTREAMING_TOKENS[body.model] ?? undefined;
61
+ timeout = this._client.calculateNonstreamingTimeout(body.max_tokens, maxNonstreamingTokens);
62
+ }
63
+ // Collect helper info from tools and messages
64
+ const helperHeader = (0, stainless_helper_header_1.stainlessHelperHeader)(body.tools, body.messages);
65
+ return this._client.post('/v1/messages', {
66
+ body,
67
+ timeout: timeout ?? 600000,
68
+ ...options,
69
+ headers: (0, headers_1.buildHeaders)([
70
+ { ...(user_profile_id != null ? { 'puku-user-profile-id': user_profile_id } : undefined) },
71
+ helperHeader,
72
+ options?.headers,
73
+ ]),
74
+ stream: params.stream ?? false,
75
+ });
76
+ }
77
+ /**
78
+ * Send a structured list of input messages with text and/or image content, along with an expected `output_config.format` and
79
+ * the response will be automatically parsed and available in the `parsed_output` property of the message.
80
+ *
81
+ * @example
82
+ * ```ts
83
+ * const message = await client.messages.parse({
84
+ * model: 'puku-ai-2.8',
85
+ * max_tokens: 1024,
86
+ * messages: [{ role: 'user', content: 'What is 2+2?' }],
87
+ * output_config: {
88
+ * format: zodOutputFormat(z.object({ answer: z.number() })),
89
+ * },
90
+ * });
91
+ *
92
+ * console.log(message.parsed_output?.answer); // 4
93
+ * ```
94
+ */
95
+ parse(params, options) {
96
+ return this.create(params, options).then((message) => (0, parser_1.parseMessage)(message, params, { logger: this._client.logger ?? console }));
97
+ }
98
+ /**
99
+ * Create a Message stream.
100
+ *
101
+ * If `output_config.format` is provided with a parseable format (like `zodOutputFormat()`),
102
+ * the final message will include a `parsed_output` property with the parsed content.
103
+ *
104
+ * @example
105
+ * ```ts
106
+ * const stream = client.messages.stream({
107
+ * model: 'puku-ai-2.8',
108
+ * max_tokens: 1024,
109
+ * messages: [{ role: 'user', content: 'What is 2+2?' }],
110
+ * output_config: {
111
+ * format: zodOutputFormat(z.object({ answer: z.number() })),
112
+ * },
113
+ * });
114
+ *
115
+ * const message = await stream.finalMessage();
116
+ * console.log(message.parsed_output?.answer); // 4
117
+ * ```
118
+ */
119
+ stream(body, options) {
120
+ return MessageStream_1.MessageStream.createMessage(this, body, options, { logger: this._client.logger ?? console });
121
+ }
122
+ /**
123
+ * Count the number of tokens in a Message.
124
+ *
125
+ * The Token Count API can be used to count the number of tokens in a Message,
126
+ * including tools, images, and documents, without creating it.
127
+ *
128
+ * Learn more about token counting in our
129
+ * [user guide](https://platform.puku.com/docs/en/build-with-puku/token-counting)
130
+ *
131
+ * @example
132
+ * ```ts
133
+ * const messageTokensCount =
134
+ * await client.messages.countTokens({
135
+ * messages: [{ content: 'Hello, world', role: 'user' }],
136
+ * model: 'puku-ai-2.8',
137
+ * });
138
+ * ```
139
+ */
140
+ countTokens(params, options) {
141
+ const { user_profile_id, ...body } = params;
142
+ return this._client.post('/v1/messages/count_tokens', {
143
+ body,
144
+ ...options,
145
+ headers: (0, headers_1.buildHeaders)([
146
+ { ...(user_profile_id != null ? { 'puku-user-profile-id': user_profile_id } : undefined) },
147
+ options?.headers,
148
+ ]),
149
+ });
150
+ }
151
+ }
152
+ exports.Messages = Messages;
153
+ const DEPRECATED_MODELS = {
154
+ // Puku AI exposes `puku-ai-2.7`, `puku-ai-2.8`, and `opus-4.8`. None of
155
+ // these are deprecated at this time — extend this map when (and only
156
+ // when) a model is announced for retirement. Date format: 'Month Dth, YYYY'.
157
+ };
158
+ const MODELS_TO_WARN_WITH_THINKING_ENABLED = [];
159
+ Messages.Batches = batches_1.Batches;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ __exportStar(require("./messages/index"), exports);
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.Models = void 0;
5
+ const resource_1 = require("../core/resource");
6
+ const pagination_1 = require("../core/pagination");
7
+ const headers_1 = require("../internal/headers");
8
+ const path_1 = require("../internal/utils/path");
9
+ class Models extends resource_1.APIResource {
10
+ /**
11
+ * Get a specific model.
12
+ *
13
+ * The Models API response can be used to determine information about a specific
14
+ * model or resolve a model alias to a model ID.
15
+ */
16
+ retrieve(modelID, params = {}, options) {
17
+ const { betas } = params ?? {};
18
+ return this._client.get((0, path_1.path) `/v1/models/${modelID}`, {
19
+ ...options,
20
+ headers: (0, headers_1.buildHeaders)([
21
+ { ...(betas?.toString() != null ? { 'puku-beta': betas?.toString() } : undefined) },
22
+ options?.headers,
23
+ ]),
24
+ });
25
+ }
26
+ /**
27
+ * List available models.
28
+ *
29
+ * The Models API response can be used to determine which models are available for
30
+ * use in the API. More recently released models are listed first.
31
+ */
32
+ list(params = {}, options) {
33
+ const { betas, ...query } = params ?? {};
34
+ return this._client.getAPIList('/v1/models', (pagination_1.Page), {
35
+ query,
36
+ ...options,
37
+ headers: (0, headers_1.buildHeaders)([
38
+ { ...(betas?.toString() != null ? { 'puku-beta': betas?.toString() } : undefined) },
39
+ options?.headers,
40
+ ]),
41
+ });
42
+ }
43
+ }
44
+ exports.Models = Models;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.Versions = exports.Skills = void 0;
5
+ var skills_1 = require("./skills");
6
+ Object.defineProperty(exports, "Skills", { enumerable: true, get: function () { return skills_1.Skills; } });
7
+ var versions_1 = require("./versions");
8
+ Object.defineProperty(exports, "Versions", { enumerable: true, get: function () { return versions_1.Versions; } });
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ exports.Skills = void 0;
38
+ const resource_1 = require("../../core/resource");
39
+ const VersionsAPI = __importStar(require("./versions"));
40
+ const versions_1 = require("./versions");
41
+ const pagination_1 = require("../../core/pagination");
42
+ const uploads_1 = require("../../internal/uploads");
43
+ const path_1 = require("../../internal/utils/path");
44
+ class Skills extends resource_1.APIResource {
45
+ versions = new VersionsAPI.Versions(this._client);
46
+ /**
47
+ * Create Skill
48
+ */
49
+ create(body, options) {
50
+ return this._client.post('/v1/skills', (0, uploads_1.multipartFormRequestOptions)({ body, ...options }, this._client, false));
51
+ }
52
+ /**
53
+ * Get Skill
54
+ */
55
+ retrieve(skillID, options) {
56
+ return this._client.get((0, path_1.path) `/v1/skills/${skillID}`, options);
57
+ }
58
+ /**
59
+ * List Skills
60
+ */
61
+ list(query = {}, options) {
62
+ return this._client.getAPIList('/v1/skills', (pagination_1.PageCursor), { query, ...options });
63
+ }
64
+ /**
65
+ * Delete Skill
66
+ */
67
+ delete(skillID, options) {
68
+ return this._client.delete((0, path_1.path) `/v1/skills/${skillID}`, options);
69
+ }
70
+ }
71
+ exports.Skills = Skills;
72
+ Skills.Versions = versions_1.Versions;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.Versions = void 0;
5
+ const resource_1 = require("../../core/resource");
6
+ const pagination_1 = require("../../core/pagination");
7
+ const uploads_1 = require("../../internal/uploads");
8
+ const path_1 = require("../../internal/utils/path");
9
+ class Versions extends resource_1.APIResource {
10
+ /**
11
+ * Create Skill Version
12
+ */
13
+ create(skillID, body, options) {
14
+ return this._client.post((0, path_1.path) `/v1/skills/${skillID}/versions`, (0, uploads_1.multipartFormRequestOptions)({ body, ...options }, this._client, false));
15
+ }
16
+ /**
17
+ * Get Skill Version
18
+ */
19
+ retrieve(version, params, options) {
20
+ const { skill_id } = params;
21
+ return this._client.get((0, path_1.path) `/v1/skills/${skill_id}/versions/${version}`, options);
22
+ }
23
+ /**
24
+ * List Skill Versions
25
+ */
26
+ list(skillID, query = {}, options) {
27
+ return this._client.getAPIList((0, path_1.path) `/v1/skills/${skillID}/versions`, (pagination_1.PageCursor), {
28
+ query,
29
+ ...options,
30
+ });
31
+ }
32
+ /**
33
+ * Delete Skill Version
34
+ */
35
+ delete(version, params, options) {
36
+ const { skill_id } = params;
37
+ return this._client.delete((0, path_1.path) `/v1/skills/${skill_id}/versions/${version}`, options);
38
+ }
39
+ }
40
+ exports.Versions = Versions;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ __exportStar(require("./skills/index"), exports);
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,17 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./resources/index"), exports);
@@ -0,0 +1,18 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ /** @deprecated Import from ./core/streaming instead */
18
+ __exportStar(require("./core/streaming"), exports);
@@ -0,0 +1,193 @@
1
+ "use strict";
2
+ /**
3
+ * Shared, Node-only filesystem helpers for the agent toolset's file tools:
4
+ * path confinement (symlink-aware), an atomic write, and language-independent
5
+ * error messages. Kept out of `node.ts` so the tool implementations stay focused
6
+ * and these helpers can be reused by every file tool.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.FILE_CREATE_MODE = exports.DIR_CREATE_MODE = void 0;
10
+ exports.isWithin = isWithin;
11
+ exports.containingRoot = containingRoot;
12
+ exports.errnoCode = errnoCode;
13
+ exports.canonicalize = canonicalize;
14
+ exports.confineToRoot = confineToRoot;
15
+ exports.atomicWriteFile = atomicWriteFile;
16
+ exports.fsErrorMessage = fsErrorMessage;
17
+ const node_1 = require("../../internal/node");
18
+ const ToolError_1 = require("../../lib/tools/ToolError");
19
+ const fs = node_1.fs.promises;
20
+ /** Mode for directories the file tools create — not world-writable under a 0 umask. */
21
+ exports.DIR_CREATE_MODE = 0o755;
22
+ /** Mode for files the file tools create. */
23
+ exports.FILE_CREATE_MODE = 0o644;
24
+ /** True when `p` is `root` itself or lexically contained within it. */
25
+ function isWithin(root, p) {
26
+ const rel = node_1.path.relative(root, p);
27
+ return rel === '' || (!rel.startsWith('..' + node_1.path.sep) && rel !== '..' && !node_1.path.isAbsolute(rel));
28
+ }
29
+ /**
30
+ * The first entry of `roots` whose canonical form contains the
31
+ * already-canonical `target`, returned as configured; `undefined` when none
32
+ * does. Each root goes through {@link canonicalize} at check time, exactly like
33
+ * the workdir in {@link confineToRoot}, so granting access (`allowedRoots`)
34
+ * and refusing writes (`readOnlyRoots`) can never resolve the same entry two
35
+ * different ways.
36
+ */
37
+ async function containingRoot(roots, target) {
38
+ for (const root of roots) {
39
+ if (isWithin(await canonicalize(node_1.path.resolve(root)), target))
40
+ return root;
41
+ }
42
+ return undefined;
43
+ }
44
+ /** Matches Linux MAXSYMLINKS, the threshold at which `realpath` itself reports ELOOP. */
45
+ const MAX_SYMLINK_HOPS = 40;
46
+ /** The `code` of a Node system error, or `undefined` for anything else. */
47
+ function errnoCode(err) {
48
+ const code = err?.code;
49
+ return typeof code === 'string' ? code : undefined;
50
+ }
51
+ /**
52
+ * Fully resolve `abs`: `realpath` the longest existing ancestor and re-append
53
+ * the rest, but never re-append a component that is itself a symlink — read the
54
+ * link and continue from its target instead. This handles paths being created
55
+ * (write/edit) without letting a symlink leaf (e.g. a dangling one pointing
56
+ * outside a confinement root) slip through unresolved.
57
+ *
58
+ * Returns a symlink-free path or throws an errno-carrying error (`ELOOP` for a
59
+ * cycle or more than {@link MAX_SYMLINK_HOPS} links, the `lstat`/`realpath`
60
+ * error for an unreadable component); it never returns `abs` unresolved. Only
61
+ * symlink hops count against the cap, so any depth of not-yet-existing
62
+ * directories still resolves.
63
+ */
64
+ async function canonicalize(abs) {
65
+ const tail = [];
66
+ let prefix = abs;
67
+ let hops = 0;
68
+ for (;;) {
69
+ let real;
70
+ try {
71
+ real = await fs.realpath(prefix);
72
+ }
73
+ catch (realpathErr) {
74
+ let isLink;
75
+ try {
76
+ isLink = (await fs.lstat(prefix)).isSymbolicLink();
77
+ }
78
+ catch (lstatErr) {
79
+ const code = errnoCode(lstatErr);
80
+ if (code !== 'ENOENT' && code !== 'ENOTDIR')
81
+ throw lstatErr;
82
+ const parent = node_1.path.dirname(prefix);
83
+ if (parent === prefix)
84
+ throw lstatErr;
85
+ tail.push(node_1.path.basename(prefix));
86
+ prefix = parent;
87
+ continue;
88
+ }
89
+ if (!isLink)
90
+ throw realpathErr;
91
+ if (++hops > MAX_SYMLINK_HOPS) {
92
+ throw Object.assign(new Error('too many levels of symbolic links'), { code: 'ELOOP' });
93
+ }
94
+ prefix = node_1.path.resolve(node_1.path.dirname(prefix), await fs.readlink(prefix));
95
+ continue;
96
+ }
97
+ return tail.length ? node_1.path.join(real, ...tail.reverse()) : real;
98
+ }
99
+ }
100
+ /**
101
+ * Resolve `p` against `root` and confine it to `root` or one of `allowedRoots`
102
+ * (absolute paths, resolved at check time exactly like `root`).
103
+ *
104
+ * Absolute and relative inputs go through the same canonicalise-then-contain
105
+ * check — an absolute path that lands inside a permitted root is accepted,
106
+ * only paths that resolve *outside* all of them are rejected. Every symlink in
107
+ * `p` (including the leaf, even a dangling one) is resolved before the
108
+ * confinement check, and the resolved path is what the caller then operates
109
+ * on, so a symlink inside `root` that points outside it can neither pass the
110
+ * check nor be followed afterwards. `..` is collapsed lexically before any
111
+ * symlink is followed. A path that cannot be resolved (symlink loop, unreadable
112
+ * component) is rejected with a `ToolError` naming `p`, never the host's
113
+ * absolute path.
114
+ *
115
+ * Residual TOCTOU: a component could still be swapped for a symlink between this
116
+ * call and the eventual `fs` operation. Closing that fully needs per-component
117
+ * `O_NOFOLLOW`/`openat`, which Node does not expose ergonomically; this is why a
118
+ * sandbox is still recommended for the toolset as a whole.
119
+ */
120
+ async function confineToRoot(root, p, opts) {
121
+ const allowedRoots = opts?.allowedRoots ?? [];
122
+ const realRoot = await canonicalize(node_1.path.resolve(root));
123
+ let real;
124
+ try {
125
+ real = await canonicalize(node_1.path.resolve(realRoot, p));
126
+ }
127
+ catch (err) {
128
+ throw new ToolError_1.ToolError(fsErrorMessage(err, `path ${JSON.stringify(p)}`));
129
+ }
130
+ if (isWithin(realRoot, real) || (await containingRoot(allowedRoots, real)) !== undefined) {
131
+ return real;
132
+ }
133
+ const permitted = allowedRoots.length ?
134
+ "the session's working directory and its other permitted directories"
135
+ : "the session's working directory";
136
+ throw new ToolError_1.ToolError(`path ${JSON.stringify(p)} is outside ${permitted}`);
137
+ }
138
+ /**
139
+ * Atomically write `content` to `targetPath`: write a sibling temp file, fsync
140
+ * it, then rename over the target. The rename is atomic on most filesystems, so
141
+ * a crash mid-write never leaves the target half-written.
142
+ */
143
+ async function atomicWriteFile(targetPath, content) {
144
+ const dir = node_1.path.dirname(targetPath);
145
+ const tempPath = node_1.path.join(dir, `.tmp-${process.pid}-${node_1.crypto.randomUUID()}`);
146
+ let handle;
147
+ try {
148
+ handle = await fs.open(tempPath, 'wx', exports.FILE_CREATE_MODE);
149
+ await handle.writeFile(content, 'utf-8');
150
+ await handle.sync();
151
+ await handle.close();
152
+ handle = undefined;
153
+ await fs.rename(tempPath, targetPath);
154
+ }
155
+ catch (err) {
156
+ if (handle)
157
+ await handle.close().catch(() => { });
158
+ await fs.unlink(tempPath).catch(() => { });
159
+ throw err;
160
+ }
161
+ }
162
+ /**
163
+ * Map a thrown filesystem error to a consistent, language-independent message,
164
+ * so the model sees the same wording regardless of the runtime (Node's raw
165
+ * `ENOENT: no such file...` text would otherwise leak through). Codes we don't
166
+ * special-case render as the bare code, never Node's message, which embeds the
167
+ * host's absolute path.
168
+ */
169
+ function fsErrorMessage(err, file) {
170
+ const code = errnoCode(err);
171
+ switch (code) {
172
+ case 'ENOENT':
173
+ return `${file}: no such file or directory`;
174
+ case 'EACCES':
175
+ case 'EPERM':
176
+ return `${file}: permission denied`;
177
+ case 'ENOTDIR':
178
+ return `${file}: not a directory`;
179
+ case 'EISDIR':
180
+ return `${file}: is a directory`;
181
+ case 'ELOOP':
182
+ return `${file}: too many levels of symbolic links`;
183
+ case 'ENAMETOOLONG':
184
+ return `${file}: file name too long`;
185
+ case 'ENOSPC':
186
+ return `${file}: no space left on device`;
187
+ case 'EMFILE':
188
+ case 'ENFILE':
189
+ return `${file}: too many open files`;
190
+ default:
191
+ return `${file}: ${code !== undefined ? `i/o error (${code})` : 'i/o error'}`;
192
+ }
193
+ }