@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.
- package/README.md +24 -7
- package/dist/index.cjs +85 -0
- package/dist/vendor/_vendor/partial-json-parser/parser.cjs +225 -0
- package/dist/vendor/api-promise.cjs +18 -0
- package/dist/vendor/client.cjs +1013 -0
- package/dist/vendor/core/api-promise.cjs +80 -0
- package/dist/vendor/core/api.cjs +2 -0
- package/dist/vendor/core/credentials.cjs +313 -0
- package/dist/vendor/core/error.cjs +156 -0
- package/dist/vendor/core/middleware.cjs +173 -0
- package/dist/vendor/core/pagination.cjs +215 -0
- package/dist/vendor/core/resource.cjs +11 -0
- package/dist/vendor/core/streaming.cjs +346 -0
- package/dist/vendor/core/uploads.cjs +5 -0
- package/dist/vendor/error.cjs +18 -0
- package/dist/vendor/helpers/beta/environments.cjs +30 -0
- package/dist/vendor/helpers/beta/json-schema.cjs +56 -0
- package/dist/vendor/helpers/beta/mcp.cjs +418 -0
- package/dist/vendor/helpers/beta/memory.cjs +17 -0
- package/dist/vendor/helpers/beta/standard-schema.cjs +57 -0
- package/dist/vendor/helpers/beta/zod.cjs +88 -0
- package/dist/vendor/helpers/index.cjs +7 -0
- package/dist/vendor/helpers/json-schema.cjs +36 -0
- package/dist/vendor/helpers/zod.cjs +77 -0
- package/dist/vendor/index.cjs +54 -0
- package/dist/vendor/internal/builtin-types.cjs +3 -0
- package/dist/vendor/internal/constants.cjs +12 -0
- package/dist/vendor/internal/decoders/jsonl.cjs +40 -0
- package/dist/vendor/internal/decoders/line.cjs +109 -0
- package/dist/vendor/internal/detect-platform.cjs +159 -0
- package/dist/vendor/internal/errors.cjs +42 -0
- package/dist/vendor/internal/file-store.cjs +535 -0
- package/dist/vendor/internal/headers.cjs +119 -0
- package/dist/vendor/internal/message-stream-utils.cjs +33 -0
- package/dist/vendor/internal/node.browser.cjs +21 -0
- package/dist/vendor/internal/node.cjs +55 -0
- package/dist/vendor/internal/parse.cjs +65 -0
- package/dist/vendor/internal/qs/formats.cjs +12 -0
- package/dist/vendor/internal/qs/index.cjs +13 -0
- package/dist/vendor/internal/qs/stringify.cjs +276 -0
- package/dist/vendor/internal/qs/types.cjs +2 -0
- package/dist/vendor/internal/qs/utils.cjs +229 -0
- package/dist/vendor/internal/request-options.cjs +31 -0
- package/dist/vendor/internal/request-signal.cjs +49 -0
- package/dist/vendor/internal/shim-types.cjs +3 -0
- package/dist/vendor/internal/shims.cjs +91 -0
- package/dist/vendor/internal/stainless-helper-header.cjs +90 -0
- package/dist/vendor/internal/stream-utils.cjs +37 -0
- package/dist/vendor/internal/to-file.cjs +95 -0
- package/dist/vendor/internal/types.cjs +3 -0
- package/dist/vendor/internal/uploads.cjs +148 -0
- package/dist/vendor/internal/utils/abort.cjs +24 -0
- package/dist/vendor/internal/utils/async-queue.cjs +69 -0
- package/dist/vendor/internal/utils/backoff.cjs +43 -0
- package/dist/vendor/internal/utils/base64.cjs +37 -0
- package/dist/vendor/internal/utils/bytes.cjs +30 -0
- package/dist/vendor/internal/utils/env.cjs +21 -0
- package/dist/vendor/internal/utils/log.cjs +111 -0
- package/dist/vendor/internal/utils/path.cjs +78 -0
- package/dist/vendor/internal/utils/promise.cjs +17 -0
- package/dist/vendor/internal/utils/query.cjs +41 -0
- package/dist/vendor/internal/utils/sleep.cjs +27 -0
- package/dist/vendor/internal/utils/time.cjs +7 -0
- package/dist/vendor/internal/utils/uuid.cjs +18 -0
- package/dist/vendor/internal/utils/values.cjs +125 -0
- package/dist/vendor/internal/utils.cjs +24 -0
- package/dist/vendor/lib/BetaMessageStream.cjs +665 -0
- package/dist/vendor/lib/MessageStream.cjs +612 -0
- package/dist/vendor/lib/beta-parser.cjs +78 -0
- package/dist/vendor/lib/credentials/credential-chain.cjs +244 -0
- package/dist/vendor/lib/credentials/identity-token.cjs +71 -0
- package/dist/vendor/lib/credentials/oidc-federation.cjs +81 -0
- package/dist/vendor/lib/credentials/token-cache.cjs +113 -0
- package/dist/vendor/lib/credentials/types.cjs +267 -0
- package/dist/vendor/lib/credentials/user-oauth.cjs +129 -0
- package/dist/vendor/lib/credentials.cjs +7 -0
- package/dist/vendor/lib/environments/index.cjs +17 -0
- package/dist/vendor/lib/environments/poller.cjs +226 -0
- package/dist/vendor/lib/environments/worker.cjs +609 -0
- package/dist/vendor/lib/helper-client.cjs +57 -0
- package/dist/vendor/lib/middleware.cjs +779 -0
- package/dist/vendor/lib/parser.cjs +65 -0
- package/dist/vendor/lib/sessions/accumulate.cjs +44 -0
- package/dist/vendor/lib/standard-schema.cjs +44 -0
- package/dist/vendor/lib/tools/BetaRunnableTool.cjs +30 -0
- package/dist/vendor/lib/tools/BetaToolRunner.cjs +500 -0
- package/dist/vendor/lib/tools/CompactionControl.cjs +27 -0
- package/dist/vendor/lib/tools/SessionToolRunner.cjs +740 -0
- package/dist/vendor/lib/tools/ToolError.cjs +46 -0
- package/dist/vendor/lib/transform-json-schema.cjs +113 -0
- package/dist/vendor/pagination.cjs +18 -0
- package/dist/vendor/resource.cjs +18 -0
- package/dist/vendor/resources/beta/agents/agents.cjs +159 -0
- package/dist/vendor/resources/beta/agents/index.cjs +8 -0
- package/dist/vendor/resources/beta/agents/versions.cjs +35 -0
- package/dist/vendor/resources/beta/agents.cjs +18 -0
- package/dist/vendor/resources/beta/beta.cjs +105 -0
- package/dist/vendor/resources/beta/deployment-runs.cjs +54 -0
- package/dist/vendor/resources/beta/deployments.cjs +195 -0
- package/dist/vendor/resources/beta/dreams.cjs +115 -0
- package/dist/vendor/resources/beta/environments/environments.cjs +178 -0
- package/dist/vendor/resources/beta/environments/index.cjs +8 -0
- package/dist/vendor/resources/beta/environments/work.cjs +256 -0
- package/dist/vendor/resources/beta/environments.cjs +18 -0
- package/dist/vendor/resources/beta/files.cjs +123 -0
- package/dist/vendor/resources/beta/index.cjs +38 -0
- package/dist/vendor/resources/beta/memory-stores/index.cjs +10 -0
- package/dist/vendor/resources/beta/memory-stores/memories.cjs +129 -0
- package/dist/vendor/resources/beta/memory-stores/memory-stores.cjs +173 -0
- package/dist/vendor/resources/beta/memory-stores/memory-versions.cjs +80 -0
- package/dist/vendor/resources/beta/memory-stores.cjs +18 -0
- package/dist/vendor/resources/beta/messages/batches.cjs +206 -0
- package/dist/vendor/resources/beta/messages/index.cjs +11 -0
- package/dist/vendor/resources/beta/messages/messages.cjs +189 -0
- package/dist/vendor/resources/beta/messages.cjs +18 -0
- package/dist/vendor/resources/beta/models.cjs +59 -0
- package/dist/vendor/resources/beta/organization/api-keys.cjs +55 -0
- package/dist/vendor/resources/beta/organization/compliance-settings.cjs +51 -0
- package/dist/vendor/resources/beta/organization/external-keys.cjs +118 -0
- package/dist/vendor/resources/beta/organization/federation/federation.cjs +49 -0
- package/dist/vendor/resources/beta/organization/federation/index.cjs +10 -0
- package/dist/vendor/resources/beta/organization/federation/issuers.cjs +168 -0
- package/dist/vendor/resources/beta/organization/federation/rules/index.cjs +8 -0
- package/dist/vendor/resources/beta/organization/federation/rules/rules.cjs +226 -0
- package/dist/vendor/resources/beta/organization/federation/rules/workspaces.cjs +113 -0
- package/dist/vendor/resources/beta/organization/federation/rules.cjs +18 -0
- package/dist/vendor/resources/beta/organization/federation.cjs +18 -0
- package/dist/vendor/resources/beta/organization/index.cjs +24 -0
- package/dist/vendor/resources/beta/organization/invites.cjs +75 -0
- package/dist/vendor/resources/beta/organization/organization.cjs +90 -0
- package/dist/vendor/resources/beta/organization/rate-limits.cjs +30 -0
- package/dist/vendor/resources/beta/organization/service-accounts/index.cjs +8 -0
- package/dist/vendor/resources/beta/organization/service-accounts/service-accounts.cjs +202 -0
- package/dist/vendor/resources/beta/organization/service-accounts/workspaces.cjs +124 -0
- package/dist/vendor/resources/beta/organization/service-accounts.cjs +18 -0
- package/dist/vendor/resources/beta/organization/users.cjs +66 -0
- package/dist/vendor/resources/beta/organization/workspaces/index.cjs +12 -0
- package/dist/vendor/resources/beta/organization/workspaces/members.cjs +101 -0
- package/dist/vendor/resources/beta/organization/workspaces/rate-limits.cjs +33 -0
- package/dist/vendor/resources/beta/organization/workspaces/service-accounts.cjs +188 -0
- package/dist/vendor/resources/beta/organization/workspaces/workspaces.cjs +140 -0
- package/dist/vendor/resources/beta/organization/workspaces.cjs +18 -0
- package/dist/vendor/resources/beta/organization.cjs +18 -0
- package/dist/vendor/resources/beta/sessions/events.cjs +119 -0
- package/dist/vendor/resources/beta/sessions/index.cjs +12 -0
- package/dist/vendor/resources/beta/sessions/resources.cjs +131 -0
- package/dist/vendor/resources/beta/sessions/sessions.cjs +186 -0
- package/dist/vendor/resources/beta/sessions/threads/events.cjs +60 -0
- package/dist/vendor/resources/beta/sessions/threads/index.cjs +8 -0
- package/dist/vendor/resources/beta/sessions/threads/threads.cjs +116 -0
- package/dist/vendor/resources/beta/sessions/threads.cjs +18 -0
- package/dist/vendor/resources/beta/sessions.cjs +18 -0
- package/dist/vendor/resources/beta/skills/index.cjs +8 -0
- package/dist/vendor/resources/beta/skills/skills.cjs +132 -0
- package/dist/vendor/resources/beta/skills/versions.cjs +128 -0
- package/dist/vendor/resources/beta/skills.cjs +18 -0
- package/dist/vendor/resources/beta/tunnels/certificates.cjs +128 -0
- package/dist/vendor/resources/beta/tunnels/index.cjs +8 -0
- package/dist/vendor/resources/beta/tunnels/tunnels.cjs +209 -0
- package/dist/vendor/resources/beta/tunnels.cjs +18 -0
- package/dist/vendor/resources/beta/user-profiles.cjs +117 -0
- package/dist/vendor/resources/beta/vaults/credentials.cjs +176 -0
- package/dist/vendor/resources/beta/vaults/index.cjs +8 -0
- package/dist/vendor/resources/beta/vaults/vaults.cjs +177 -0
- package/dist/vendor/resources/beta/vaults.cjs +18 -0
- package/dist/vendor/resources/beta/webhooks.cjs +32 -0
- package/dist/vendor/resources/beta.cjs +18 -0
- package/dist/vendor/resources/completions.cjs +22 -0
- package/dist/vendor/resources/files.cjs +51 -0
- package/dist/vendor/resources/index.cjs +31 -0
- package/dist/vendor/resources/messages/batches.cjs +160 -0
- package/dist/vendor/resources/messages/index.cjs +8 -0
- package/dist/vendor/resources/messages/messages.cjs +159 -0
- package/dist/vendor/resources/messages.cjs +18 -0
- package/dist/vendor/resources/models.cjs +44 -0
- package/dist/vendor/resources/shared.cjs +3 -0
- package/dist/vendor/resources/skills/index.cjs +8 -0
- package/dist/vendor/resources/skills/skills.cjs +72 -0
- package/dist/vendor/resources/skills/versions.cjs +40 -0
- package/dist/vendor/resources/skills.cjs +18 -0
- package/dist/vendor/resources/top-level.cjs +3 -0
- package/dist/vendor/resources.cjs +17 -0
- package/dist/vendor/streaming.cjs +18 -0
- package/dist/vendor/tools/agent-toolset/fs-util.cjs +193 -0
- package/dist/vendor/tools/agent-toolset/memories.cjs +916 -0
- package/dist/vendor/tools/agent-toolset/node.browser.cjs +147 -0
- package/dist/vendor/tools/agent-toolset/node.cjs +939 -0
- package/dist/vendor/tools/agent-toolset/skills.cjs +325 -0
- package/dist/vendor/tools/agent-toolset/sync-interval.cjs +28 -0
- package/dist/vendor/tools/memory/node.browser.cjs +48 -0
- package/dist/vendor/tools/memory/node.cjs +364 -0
- package/dist/vendor/uploads.cjs +18 -0
- package/dist/vendor/version.cjs +4 -0
- package/package.json +12 -13
- package/sdk.cjs +0 -14271
- package/sdk.cjs.map +0 -149
- package/sdk.d.ts +0 -10866
- package/sdk.mjs +0 -68
- package/sdk.mjs.map +0 -149
|
@@ -0,0 +1,80 @@
|
|
|
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.APIPromise = void 0;
|
|
5
|
+
const parse_1 = require("../internal/parse");
|
|
6
|
+
/**
|
|
7
|
+
* A subclass of `Promise` providing additional helper methods
|
|
8
|
+
* for interacting with the SDK.
|
|
9
|
+
*/
|
|
10
|
+
class APIPromise extends Promise {
|
|
11
|
+
responsePromise;
|
|
12
|
+
parseResponse;
|
|
13
|
+
parsedPromise;
|
|
14
|
+
#client;
|
|
15
|
+
constructor(client, responsePromise, parseResponse = parse_1.defaultParseResponse) {
|
|
16
|
+
super((resolve) => {
|
|
17
|
+
// this is maybe a bit weird but this has to be a no-op to not implicitly
|
|
18
|
+
// parse the response body; instead .then, .catch, .finally are overridden
|
|
19
|
+
// to parse the response
|
|
20
|
+
resolve(null);
|
|
21
|
+
});
|
|
22
|
+
this.responsePromise = responsePromise;
|
|
23
|
+
this.parseResponse = parseResponse;
|
|
24
|
+
this.#client = client;
|
|
25
|
+
}
|
|
26
|
+
_thenUnwrap(transform) {
|
|
27
|
+
return new APIPromise(this.#client, this.responsePromise, async (client, props) => (0, parse_1.addResponseIDs)(transform(await this.parseResponse(client, props), props), props.response));
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Gets the raw `Response` instance instead of parsing the response
|
|
31
|
+
* data.
|
|
32
|
+
*
|
|
33
|
+
* If you want to parse the response body but still get the `Response`
|
|
34
|
+
* instance, you can use {@link withResponse()}.
|
|
35
|
+
*
|
|
36
|
+
* 👋 Getting the wrong TypeScript type for `Response`?
|
|
37
|
+
* Try setting `"moduleResolution": "NodeNext"` or add `"lib": ["DOM"]`
|
|
38
|
+
* to your `tsconfig.json`.
|
|
39
|
+
*/
|
|
40
|
+
asResponse() {
|
|
41
|
+
return this.responsePromise.then((p) => p.response);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Gets the parsed response data, the raw `Response` instance and the ID of the request,
|
|
45
|
+
* returned via the `request-id` header which is useful for debugging requests and resporting
|
|
46
|
+
* issues to PukuAI.
|
|
47
|
+
*
|
|
48
|
+
* If you just want to get the raw `Response` instance without parsing it,
|
|
49
|
+
* you can use {@link asResponse()}.
|
|
50
|
+
*
|
|
51
|
+
* 👋 Getting the wrong TypeScript type for `Response`?
|
|
52
|
+
* Try setting `"moduleResolution": "NodeNext"` or add `"lib": ["DOM"]`
|
|
53
|
+
* to your `tsconfig.json`.
|
|
54
|
+
*/
|
|
55
|
+
async withResponse() {
|
|
56
|
+
const [data, response] = await Promise.all([this.parse(), this.asResponse()]);
|
|
57
|
+
return {
|
|
58
|
+
data,
|
|
59
|
+
response,
|
|
60
|
+
request_id: response.headers.get('request-id'),
|
|
61
|
+
workspace_id: response.headers.get('puku-workspace-id'),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
parse() {
|
|
65
|
+
if (!this.parsedPromise) {
|
|
66
|
+
this.parsedPromise = this.responsePromise.then((data) => this.parseResponse(this.#client, data));
|
|
67
|
+
}
|
|
68
|
+
return this.parsedPromise;
|
|
69
|
+
}
|
|
70
|
+
then(onfulfilled, onrejected) {
|
|
71
|
+
return this.parse().then(onfulfilled, onrejected);
|
|
72
|
+
}
|
|
73
|
+
catch(onrejected) {
|
|
74
|
+
return this.parse().catch(onrejected);
|
|
75
|
+
}
|
|
76
|
+
finally(onfinally) {
|
|
77
|
+
return this.parse().finally(onfinally);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.APIPromise = APIPromise;
|
|
@@ -0,0 +1,313 @@
|
|
|
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.getCredentialsPath = exports.loadCredentials = exports.loadConfigWithSource = exports.loadConfig = exports.CREDENTIALS_FILE_VERSION = exports.CONFIG_FILE_VERSION = void 0;
|
|
37
|
+
const detect_platform_1 = require("../internal/detect-platform");
|
|
38
|
+
const utils_1 = require("../internal/utils");
|
|
39
|
+
/** Current schema version written to `configs/<profile>.json`. Absent on read ⇒ "1.0". */
|
|
40
|
+
exports.CONFIG_FILE_VERSION = '1.0';
|
|
41
|
+
/** Current schema version written to `credentials/<profile>.json`. Absent on read ⇒ "1.0". */
|
|
42
|
+
exports.CREDENTIALS_FILE_VERSION = '1.0';
|
|
43
|
+
const PROFILE_NAME_PATTERN = /^[A-Za-z0-9_.-]+$/;
|
|
44
|
+
function validateProfileName(name) {
|
|
45
|
+
if (!name) {
|
|
46
|
+
throw new Error('profile name is empty');
|
|
47
|
+
}
|
|
48
|
+
if (name === '.' || name === '..') {
|
|
49
|
+
throw new Error(`profile name "${name}" is not allowed`);
|
|
50
|
+
}
|
|
51
|
+
if (name.includes('/') || name.includes('\\')) {
|
|
52
|
+
throw new Error(`profile name "${name}" must not contain path separators`);
|
|
53
|
+
}
|
|
54
|
+
if (!PROFILE_NAME_PATTERN.test(name)) {
|
|
55
|
+
throw new Error(`profile name "${name}" contains disallowed characters (allowed: letters, digits, '_', '.', '-')`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Loads the PukuAI configuration for the given (or active) profile.
|
|
60
|
+
*
|
|
61
|
+
* Returns `null` when running in a browser or no configuration can be resolved.
|
|
62
|
+
* Otherwise, returns the configuration based on the config file and environment variables.
|
|
63
|
+
*
|
|
64
|
+
* **Profile resolution** (first match wins):
|
|
65
|
+
* 1. Explicit `profile` argument
|
|
66
|
+
* 2. `PUKU_PROFILE` environment variable
|
|
67
|
+
* 3. Contents of `<config_dir>/active_config` file
|
|
68
|
+
* 4. `"default"`
|
|
69
|
+
*
|
|
70
|
+
* **Config resolution:**
|
|
71
|
+
* - If `<config_dir>/configs/<profile>.json` exists, it is loaded and
|
|
72
|
+
* missing fields are filled from environment variables. Values present
|
|
73
|
+
* in the file take precedence — env vars only fill gaps:
|
|
74
|
+
* - `PUKU_BASE_URL` → `base_url`
|
|
75
|
+
* - `PUKU_ORGANIZATION_ID` → `organization_id`
|
|
76
|
+
* - `PUKU_WORKSPACE_ID` → `workspace_id`
|
|
77
|
+
* - `PUKU_SCOPE` → `authentication.scope`
|
|
78
|
+
* - `PUKU_FEDERATION_RULE_ID` → `authentication.federation_rule_id` (oidc_federation)
|
|
79
|
+
* - `PUKU_IDENTITY_TOKEN_FILE` → `authentication.identity_token` (oidc_federation)
|
|
80
|
+
* - `PUKU_SERVICE_ACCOUNT_ID` → `authentication.service_account_id` (oidc_federation)
|
|
81
|
+
* - If no config file exists, an `oidc_federation` config is synthesized
|
|
82
|
+
* entirely from environment variables when both `PUKU_FEDERATION_RULE_ID`
|
|
83
|
+
* and `PUKU_ORGANIZATION_ID` are set.
|
|
84
|
+
*/
|
|
85
|
+
const loadConfig = async (profile) => {
|
|
86
|
+
return (await (0, exports.loadConfigWithSource)(profile))?.config ?? null;
|
|
87
|
+
};
|
|
88
|
+
exports.loadConfig = loadConfig;
|
|
89
|
+
/**
|
|
90
|
+
* Same as {@link loadConfig}, but also reports whether the config was loaded
|
|
91
|
+
* from a profile file on disk (`fromFile: true`) or synthesized entirely from
|
|
92
|
+
* environment variables (`fromFile: false`).
|
|
93
|
+
*/
|
|
94
|
+
const loadConfigWithSource = async (profile) => {
|
|
95
|
+
const rootConfigPath = await getRootConfigPath();
|
|
96
|
+
if (rootConfigPath === null) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
const profileName = profile ?? (await getActiveProfileName());
|
|
100
|
+
if (profileName === null) {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
validateProfileName(profileName);
|
|
104
|
+
const { fs, path } = await Promise.resolve().then(() => __importStar(require('../internal/node')));
|
|
105
|
+
const configPath = path.join(rootConfigPath, 'configs', `${profileName}.json`);
|
|
106
|
+
let configRaw;
|
|
107
|
+
try {
|
|
108
|
+
configRaw = await fs.promises.readFile(configPath, 'utf-8');
|
|
109
|
+
}
|
|
110
|
+
catch (err) {
|
|
111
|
+
if (err?.code !== 'ENOENT') {
|
|
112
|
+
throw new Error(`failed to read config file ${configPath}: ${err}`);
|
|
113
|
+
}
|
|
114
|
+
configRaw = null;
|
|
115
|
+
}
|
|
116
|
+
if (configRaw === null) {
|
|
117
|
+
const organizationId = (0, utils_1.readEnv)('PUKU_ORGANIZATION_ID');
|
|
118
|
+
const identityTokenFile = (0, utils_1.readEnv)('PUKU_IDENTITY_TOKEN_FILE');
|
|
119
|
+
const federationRuleId = (0, utils_1.readEnv)('PUKU_FEDERATION_RULE_ID');
|
|
120
|
+
if (federationRuleId && organizationId) {
|
|
121
|
+
return {
|
|
122
|
+
fromFile: false,
|
|
123
|
+
config: {
|
|
124
|
+
organization_id: organizationId,
|
|
125
|
+
// A defaulted-but-empty CI variable (`PUKU_WORKSPACE_ID=""`) is
|
|
126
|
+
// treated as unset — readEnv coerces empty to undefined, and the body
|
|
127
|
+
// builder's truthy check skips it — so `"workspace_id": ""` never goes
|
|
128
|
+
// on the wire.
|
|
129
|
+
workspace_id: (0, utils_1.readEnv)('PUKU_WORKSPACE_ID'),
|
|
130
|
+
base_url: (0, utils_1.readEnv)('PUKU_BASE_URL'),
|
|
131
|
+
authentication: {
|
|
132
|
+
type: 'oidc_federation',
|
|
133
|
+
federation_rule_id: federationRuleId,
|
|
134
|
+
service_account_id: (0, utils_1.readEnv)('PUKU_SERVICE_ACCOUNT_ID'),
|
|
135
|
+
identity_token: identityTokenFile ? { source: 'file', path: identityTokenFile } : undefined,
|
|
136
|
+
scope: (0, utils_1.readEnv)('PUKU_SCOPE'),
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
let config;
|
|
144
|
+
try {
|
|
145
|
+
config = JSON.parse(configRaw);
|
|
146
|
+
}
|
|
147
|
+
catch (err) {
|
|
148
|
+
throw new Error(`failed to parse config file ${configPath}: ${err}`);
|
|
149
|
+
}
|
|
150
|
+
if (!config.authentication) {
|
|
151
|
+
throw new Error(`config file ${configPath} is missing "authentication"`);
|
|
152
|
+
}
|
|
153
|
+
const authType = config.authentication.type;
|
|
154
|
+
if (authType !== 'oidc_federation' && authType !== 'user_oauth') {
|
|
155
|
+
throw new Error(`authentication.type "${authType}" is not a known authentication type`);
|
|
156
|
+
}
|
|
157
|
+
// File values are authoritative; env vars only fill fields the file left unset.
|
|
158
|
+
config.organization_id ??= (0, utils_1.readEnv)('PUKU_ORGANIZATION_ID');
|
|
159
|
+
config.workspace_id ??= (0, utils_1.readEnv)('PUKU_WORKSPACE_ID');
|
|
160
|
+
config.base_url ??= (0, utils_1.readEnv)('PUKU_BASE_URL');
|
|
161
|
+
config.authentication.scope ??= (0, utils_1.readEnv)('PUKU_SCOPE');
|
|
162
|
+
if (config.authentication.type === 'oidc_federation') {
|
|
163
|
+
if (!config.authentication.identity_token) {
|
|
164
|
+
const identityTokenFile = (0, utils_1.readEnv)('PUKU_IDENTITY_TOKEN_FILE');
|
|
165
|
+
if (identityTokenFile) {
|
|
166
|
+
config.authentication.identity_token = {
|
|
167
|
+
source: 'file',
|
|
168
|
+
path: identityTokenFile,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
// Unlike siblings using `??= readEnv()` (which leaves `undefined`), coerce
|
|
173
|
+
// to '' so the type stays `string` (always set). The downstream required
|
|
174
|
+
// check in credential-chain rejects empty, so semantics match but types are
|
|
175
|
+
// cleaner.
|
|
176
|
+
if (!config.authentication.federation_rule_id) {
|
|
177
|
+
config.authentication.federation_rule_id = (0, utils_1.readEnv)('PUKU_FEDERATION_RULE_ID') ?? '';
|
|
178
|
+
}
|
|
179
|
+
config.authentication.service_account_id ??= (0, utils_1.readEnv)('PUKU_SERVICE_ACCOUNT_ID');
|
|
180
|
+
}
|
|
181
|
+
return { config, fromFile: true };
|
|
182
|
+
};
|
|
183
|
+
exports.loadConfigWithSource = loadConfigWithSource;
|
|
184
|
+
/**
|
|
185
|
+
* Loads the credential material for the active profile.
|
|
186
|
+
*
|
|
187
|
+
* Returns the parsed credentials or `null` when running in a browser or
|
|
188
|
+
* no credentials file can be found.
|
|
189
|
+
*
|
|
190
|
+
* **Profile resolution** (first match wins):
|
|
191
|
+
* 1. `PUKU_PROFILE` environment variable
|
|
192
|
+
* 2. Contents of `<config_dir>/active_config` file
|
|
193
|
+
* 3. `"default"`
|
|
194
|
+
*
|
|
195
|
+
* **Credentials path resolution** (first match wins):
|
|
196
|
+
* 1. `authentication.credentials_path` from the active profile's config (via {@link loadConfig})
|
|
197
|
+
* 2. `<config_dir>/credentials/<profile>.json`
|
|
198
|
+
*/
|
|
199
|
+
const loadCredentials = async () => {
|
|
200
|
+
const config = await (0, exports.loadConfig)();
|
|
201
|
+
const credentialsPath = await (0, exports.getCredentialsPath)(config);
|
|
202
|
+
if (!credentialsPath) {
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
205
|
+
const { fs } = await Promise.resolve().then(() => __importStar(require('../internal/node')));
|
|
206
|
+
let raw;
|
|
207
|
+
try {
|
|
208
|
+
raw = await fs.promises.readFile(credentialsPath, 'utf-8');
|
|
209
|
+
}
|
|
210
|
+
catch (err) {
|
|
211
|
+
if (err?.code !== 'ENOENT') {
|
|
212
|
+
throw new Error(`failed to read credentials file ${credentialsPath}: ${err}`);
|
|
213
|
+
}
|
|
214
|
+
return null;
|
|
215
|
+
}
|
|
216
|
+
let creds;
|
|
217
|
+
try {
|
|
218
|
+
creds = JSON.parse(raw);
|
|
219
|
+
}
|
|
220
|
+
catch (err) {
|
|
221
|
+
throw new Error(`failed to parse credentials file ${credentialsPath}: ${err}`);
|
|
222
|
+
}
|
|
223
|
+
if (creds.type && creds.type !== 'oauth_token') {
|
|
224
|
+
throw new Error(`credentials file ${credentialsPath} has unsupported type "${creds.type}" (want "oauth_token")`);
|
|
225
|
+
}
|
|
226
|
+
return creds;
|
|
227
|
+
};
|
|
228
|
+
exports.loadCredentials = loadCredentials;
|
|
229
|
+
/**
|
|
230
|
+
* Resolves the credentials file path for the given config.
|
|
231
|
+
*
|
|
232
|
+
* Uses `authentication.credentials_path` from the config if set, otherwise
|
|
233
|
+
* falls back to `<config_dir>/credentials/<profile>.json`.
|
|
234
|
+
*
|
|
235
|
+
* Returns `null` when running in a browser or the path cannot be resolved.
|
|
236
|
+
*/
|
|
237
|
+
const getCredentialsPath = async (config, profile) => {
|
|
238
|
+
if (config?.authentication.credentials_path) {
|
|
239
|
+
return config.authentication.credentials_path;
|
|
240
|
+
}
|
|
241
|
+
const rootConfigPath = await getRootConfigPath();
|
|
242
|
+
if (!rootConfigPath) {
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
const profileName = profile ?? (await getActiveProfileName());
|
|
246
|
+
if (!profileName) {
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
validateProfileName(profileName);
|
|
250
|
+
const { path } = await Promise.resolve().then(() => __importStar(require('../internal/node')));
|
|
251
|
+
return path.join(rootConfigPath, 'credentials', `${profileName}.json`);
|
|
252
|
+
};
|
|
253
|
+
exports.getCredentialsPath = getCredentialsPath;
|
|
254
|
+
const getRootConfigPath = async () => {
|
|
255
|
+
if (!supportsLocalConfigFiles()) {
|
|
256
|
+
return null;
|
|
257
|
+
}
|
|
258
|
+
const { path } = await Promise.resolve().then(() => __importStar(require('../internal/node')));
|
|
259
|
+
// PUKU_CONFIG_DIR is treated as a trusted path: it is set by the
|
|
260
|
+
// process operator, not by remote input, so it is not validated.
|
|
261
|
+
const configDir = (0, utils_1.readEnv)('PUKU_CONFIG_DIR');
|
|
262
|
+
if (configDir) {
|
|
263
|
+
return configDir;
|
|
264
|
+
}
|
|
265
|
+
const os = (0, detect_platform_1.getPlatformHeaders)()['X-Stainless-OS'];
|
|
266
|
+
if (os === 'Windows') {
|
|
267
|
+
const appData = (0, utils_1.readEnv)('APPDATA');
|
|
268
|
+
if (appData) {
|
|
269
|
+
return path.join(appData, 'PukuAI');
|
|
270
|
+
}
|
|
271
|
+
const userProfile = (0, utils_1.readEnv)('USERPROFILE');
|
|
272
|
+
if (userProfile) {
|
|
273
|
+
return path.join(userProfile, 'AppData', 'Roaming', 'PukuAI');
|
|
274
|
+
}
|
|
275
|
+
// No usable Windows config root — return null so callers fall through to
|
|
276
|
+
// "no config available" rather than silently writing under C:\.
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
const xdgConfigHome = (0, utils_1.readEnv)('XDG_CONFIG_HOME');
|
|
280
|
+
if (xdgConfigHome) {
|
|
281
|
+
return path.join(xdgConfigHome, 'puku');
|
|
282
|
+
}
|
|
283
|
+
const home = (0, utils_1.readEnv)('HOME');
|
|
284
|
+
if (home) {
|
|
285
|
+
return path.join(home, '.config', 'puku');
|
|
286
|
+
}
|
|
287
|
+
return null;
|
|
288
|
+
};
|
|
289
|
+
const supportsLocalConfigFiles = () => {
|
|
290
|
+
const runtime = (0, detect_platform_1.getPlatformHeaders)()['X-Stainless-Runtime'];
|
|
291
|
+
return runtime === 'node' || runtime === 'deno';
|
|
292
|
+
};
|
|
293
|
+
const getActiveProfileName = async () => {
|
|
294
|
+
const rootConfigPath = await getRootConfigPath();
|
|
295
|
+
if (!rootConfigPath) {
|
|
296
|
+
return null;
|
|
297
|
+
}
|
|
298
|
+
const profileName = (0, utils_1.readEnv)('PUKU_PROFILE');
|
|
299
|
+
if (profileName) {
|
|
300
|
+
return profileName;
|
|
301
|
+
}
|
|
302
|
+
const { fs, path } = await Promise.resolve().then(() => __importStar(require('../internal/node')));
|
|
303
|
+
const filePath = path.join(rootConfigPath, 'active_config');
|
|
304
|
+
try {
|
|
305
|
+
return (await fs.promises.readFile(filePath, 'utf-8')).trim() || 'default';
|
|
306
|
+
}
|
|
307
|
+
catch (err) {
|
|
308
|
+
if (err?.code !== 'ENOENT') {
|
|
309
|
+
throw new Error(`failed to read ${filePath}: ${err}`);
|
|
310
|
+
}
|
|
311
|
+
return 'default';
|
|
312
|
+
}
|
|
313
|
+
};
|
|
@@ -0,0 +1,156 @@
|
|
|
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.InternalServerError = exports.RateLimitError = exports.UnprocessableEntityError = exports.ConflictError = exports.NotFoundError = exports.PermissionDeniedError = exports.AuthenticationError = exports.BadRequestError = exports.RetryableError = exports.APIConnectionTimeoutError = exports.APIConnectionError = exports.APIUserAbortError = exports.APIError = exports.PukuError = void 0;
|
|
5
|
+
const errors_1 = require("../internal/errors");
|
|
6
|
+
/**
|
|
7
|
+
* Branded base error class for the Puku SDK. Every error the SDK throws
|
|
8
|
+
* is an instance of `PukuError`, so `err.toString()` and stack traces
|
|
9
|
+
* report `PukuError: …` consistently.
|
|
10
|
+
*
|
|
11
|
+
* `instanceof PukuError` is the canonical check. The class itself is
|
|
12
|
+
* re-exported from `@puku-ai/sdk` under both `PukuError` and the legacy
|
|
13
|
+
* `PukuError` name; both refer to the same constructor.
|
|
14
|
+
*/
|
|
15
|
+
class PukuError extends Error {
|
|
16
|
+
name = 'PukuError';
|
|
17
|
+
constructor(message) {
|
|
18
|
+
super(message);
|
|
19
|
+
this.name = 'PukuError';
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.PukuError = PukuError;
|
|
23
|
+
class APIError extends PukuError {
|
|
24
|
+
/** HTTP status for the response that caused the error */
|
|
25
|
+
status;
|
|
26
|
+
/** HTTP headers for the response that caused the error */
|
|
27
|
+
headers;
|
|
28
|
+
/** JSON body of the response that caused the error */
|
|
29
|
+
error;
|
|
30
|
+
requestID;
|
|
31
|
+
workspaceID;
|
|
32
|
+
/** The `error.type` from the API response body, e.g. `"rate_limit_error"` */
|
|
33
|
+
type;
|
|
34
|
+
constructor(status, error, message, headers, type) {
|
|
35
|
+
super(`${APIError.makeMessage(status, error, message)}`);
|
|
36
|
+
this.status = status;
|
|
37
|
+
this.headers = headers;
|
|
38
|
+
this.requestID = headers?.get('request-id');
|
|
39
|
+
this.workspaceID = headers?.get('puku-workspace-id');
|
|
40
|
+
this.error = error;
|
|
41
|
+
this.type = type ?? null;
|
|
42
|
+
}
|
|
43
|
+
static makeMessage(status, error, message) {
|
|
44
|
+
const msg = error?.message ?
|
|
45
|
+
typeof error.message === 'string' ?
|
|
46
|
+
error.message
|
|
47
|
+
: JSON.stringify(error.message)
|
|
48
|
+
: error ? JSON.stringify(error)
|
|
49
|
+
: message;
|
|
50
|
+
if (status && msg) {
|
|
51
|
+
return `${status} ${msg}`;
|
|
52
|
+
}
|
|
53
|
+
if (status) {
|
|
54
|
+
return `${status} status code (no body)`;
|
|
55
|
+
}
|
|
56
|
+
if (msg) {
|
|
57
|
+
return msg;
|
|
58
|
+
}
|
|
59
|
+
return '(no status code or body)';
|
|
60
|
+
}
|
|
61
|
+
static generate(status, errorResponse, message, headers) {
|
|
62
|
+
if (!status || !headers) {
|
|
63
|
+
return new APIConnectionError({ message, cause: (0, errors_1.castToError)(errorResponse) });
|
|
64
|
+
}
|
|
65
|
+
const error = errorResponse;
|
|
66
|
+
const type = error?.['error']?.['type'];
|
|
67
|
+
if (status === 400) {
|
|
68
|
+
return new BadRequestError(status, error, message, headers, type);
|
|
69
|
+
}
|
|
70
|
+
if (status === 401) {
|
|
71
|
+
return new AuthenticationError(status, error, message, headers, type);
|
|
72
|
+
}
|
|
73
|
+
if (status === 403) {
|
|
74
|
+
return new PermissionDeniedError(status, error, message, headers, type);
|
|
75
|
+
}
|
|
76
|
+
if (status === 404) {
|
|
77
|
+
return new NotFoundError(status, error, message, headers, type);
|
|
78
|
+
}
|
|
79
|
+
if (status === 409) {
|
|
80
|
+
return new ConflictError(status, error, message, headers, type);
|
|
81
|
+
}
|
|
82
|
+
if (status === 422) {
|
|
83
|
+
return new UnprocessableEntityError(status, error, message, headers, type);
|
|
84
|
+
}
|
|
85
|
+
if (status === 429) {
|
|
86
|
+
return new RateLimitError(status, error, message, headers, type);
|
|
87
|
+
}
|
|
88
|
+
if (status >= 500) {
|
|
89
|
+
return new InternalServerError(status, error, message, headers, type);
|
|
90
|
+
}
|
|
91
|
+
return new APIError(status, error, message, headers, type);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.APIError = APIError;
|
|
95
|
+
class APIUserAbortError extends APIError {
|
|
96
|
+
constructor({ message } = {}) {
|
|
97
|
+
super(undefined, undefined, message || 'Request was aborted.', undefined);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.APIUserAbortError = APIUserAbortError;
|
|
101
|
+
class APIConnectionError extends APIError {
|
|
102
|
+
constructor({ message, cause }) {
|
|
103
|
+
super(undefined, undefined, message || 'Connection error.', undefined);
|
|
104
|
+
// in some environments the 'cause' property is already declared
|
|
105
|
+
// @ts-ignore
|
|
106
|
+
if (cause)
|
|
107
|
+
this.cause = cause;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.APIConnectionError = APIConnectionError;
|
|
111
|
+
class APIConnectionTimeoutError extends APIConnectionError {
|
|
112
|
+
constructor({ message } = {}) {
|
|
113
|
+
super({ message: message ?? 'Request timed out.' });
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
exports.APIConnectionTimeoutError = APIConnectionTimeoutError;
|
|
117
|
+
/**
|
|
118
|
+
* An error that opts into the SDK's retry policy: throw it (e.g. from
|
|
119
|
+
* middleware) to have the attempt retried.
|
|
120
|
+
*
|
|
121
|
+
* Note that the request will only be retried when `maxRetries` has not been exhausted.
|
|
122
|
+
*/
|
|
123
|
+
class RetryableError extends PukuError {
|
|
124
|
+
constructor(message, { cause } = {}) {
|
|
125
|
+
super(message ?? 'Retryable error.');
|
|
126
|
+
// in some environments the 'cause' property is already declared
|
|
127
|
+
// @ts-ignore
|
|
128
|
+
if (cause !== undefined)
|
|
129
|
+
this.cause = cause;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
exports.RetryableError = RetryableError;
|
|
133
|
+
class BadRequestError extends APIError {
|
|
134
|
+
}
|
|
135
|
+
exports.BadRequestError = BadRequestError;
|
|
136
|
+
class AuthenticationError extends APIError {
|
|
137
|
+
}
|
|
138
|
+
exports.AuthenticationError = AuthenticationError;
|
|
139
|
+
class PermissionDeniedError extends APIError {
|
|
140
|
+
}
|
|
141
|
+
exports.PermissionDeniedError = PermissionDeniedError;
|
|
142
|
+
class NotFoundError extends APIError {
|
|
143
|
+
}
|
|
144
|
+
exports.NotFoundError = NotFoundError;
|
|
145
|
+
class ConflictError extends APIError {
|
|
146
|
+
}
|
|
147
|
+
exports.ConflictError = ConflictError;
|
|
148
|
+
class UnprocessableEntityError extends APIError {
|
|
149
|
+
}
|
|
150
|
+
exports.UnprocessableEntityError = UnprocessableEntityError;
|
|
151
|
+
class RateLimitError extends APIError {
|
|
152
|
+
}
|
|
153
|
+
exports.RateLimitError = RateLimitError;
|
|
154
|
+
class InternalServerError extends APIError {
|
|
155
|
+
}
|
|
156
|
+
exports.InternalServerError = InternalServerError;
|