@deepraxis/sdk 0.1.0-dev.ff6425a → 0.1.1-dev.00d37b3
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/METHODS.md +1930 -210
- package/README.md +10 -9
- package/dist/automation.d.ts +61 -0
- package/dist/core/binary-operations.d.ts +3 -0
- package/dist/core/binary-operations.js +14 -0
- package/dist/core/client.d.ts +11 -1
- package/dist/core/client.js +13 -0
- package/dist/core/credentials.d.ts +22 -3
- package/dist/core/credentials.js +44 -5
- package/dist/core/deprecation.d.ts +11 -0
- package/dist/core/deprecation.js +20 -0
- package/dist/core/errors.d.ts +6 -0
- package/dist/core/errors.js +8 -0
- package/dist/core/transport.d.ts +14 -1
- package/dist/core/transport.js +24 -6
- package/dist/generated/binary-operations.gen.d.ts +3 -0
- package/dist/generated/binary-operations.gen.js +14 -0
- package/dist/generated/index.d.ts +2 -2
- package/dist/generated/index.js +1 -1
- package/dist/generated/sdk.gen.d.ts +4271 -792
- package/dist/generated/sdk.gen.js +12187 -2292
- package/dist/generated/types.gen.d.ts +106455 -44658
- package/dist/helpers/application-build.d.ts +10 -0
- package/dist/helpers/application-build.js +98 -0
- package/dist/helpers/application-publish.d.ts +8 -0
- package/dist/helpers/application-publish.js +42 -11
- package/dist/helpers/browser-actions.d.ts +102 -0
- package/dist/helpers/browser-actions.js +146 -0
- package/dist/helpers/browser-connect-error.d.ts +28 -0
- package/dist/helpers/browser-connect-error.js +74 -0
- package/dist/helpers/browser-connect.d.ts +111 -0
- package/dist/helpers/browser-connect.js +396 -0
- package/dist/helpers/browser-decisions.d.ts +101 -0
- package/dist/helpers/browser-decisions.js +148 -0
- package/dist/helpers/browser-documentation.d.ts +2 -0
- package/dist/helpers/browser-documentation.js +66 -0
- package/dist/helpers/file-upload.d.ts +2 -2
- package/dist/helpers/sandbox-templates.d.ts +121 -0
- package/dist/helpers/sandbox-templates.js +60 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +5 -0
- package/dist/operations.generated.d.ts +37 -12918
- package/dist/operations.generated.js +27251 -6825
- package/dist/resources.generated.d.ts +3885 -264
- package/dist/resources.generated.js +1237 -47
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
|
|
5
5
|
**Models, agents, sandboxes, search, data and automation, typed end to end.**
|
|
6
6
|
|
|
7
|
-
The official TypeScript SDK for [
|
|
7
|
+
The official TypeScript SDK for [Praxis](https://deepraxis.com), the cloud where AI agents are built, run and hosted.
|
|
8
8
|
|
|
9
9
|
[](https://www.npmjs.com/package/@deepraxis/sdk)
|
|
10
10
|
[](https://bundlephobia.com/package/@deepraxis/sdk)
|
|
11
11
|
[](https://www.apache.org/licenses/LICENSE-2.0)
|
|
12
12
|
|
|
13
|
-
[Website](https://deepraxis.com) · [Documentation](https://docs.deepraxis.com) · [API reference](https://docs.deepraxis.com/
|
|
13
|
+
[Website](https://deepraxis.com) · [Documentation](https://docs.deepraxis.com) · [API reference](https://docs.deepraxis.com/api) · [Console](https://console.deepraxis.com)
|
|
14
14
|
|
|
15
15
|
</div>
|
|
16
16
|
|
|
@@ -33,7 +33,7 @@ console.log(completion.choices[0]?.message.content);
|
|
|
33
33
|
## Why this SDK
|
|
34
34
|
|
|
35
35
|
- **The whole platform, one client.** About 350 operations across models, agents, sandboxes,
|
|
36
|
-
|
|
36
|
+
browsers, web search, databases, knowledge bases, files, media, automation and hosted
|
|
37
37
|
applications, generated from the same contract as the API.
|
|
38
38
|
- **Types from the contract.** Every path, query, body and response is typed, including the
|
|
39
39
|
events of each stream, so your editor knows what comes back.
|
|
@@ -55,7 +55,7 @@ server. You need a Praxis account; sign up at [deepraxis.com](https://deepraxis.
|
|
|
55
55
|
const praxis = new Praxis({
|
|
56
56
|
apiKey: process.env.PRAXIS_API_KEY!,
|
|
57
57
|
baseUrl: 'https://api.deepraxis.com', // default
|
|
58
|
-
timeoutMs:
|
|
58
|
+
timeoutMs: 600_000, // default (10 minutes, as the OpenAI and Anthropic SDKs); the whole call, body included
|
|
59
59
|
maxRetries: 2, // default
|
|
60
60
|
// fetch: customFetch, // bring your own fetch
|
|
61
61
|
});
|
|
@@ -122,7 +122,7 @@ conversation with it, on its own machine.
|
|
|
122
122
|
```ts
|
|
123
123
|
const { sandboxes } = praxis.sandbox;
|
|
124
124
|
const sandbox = await sandboxes.create({
|
|
125
|
-
body: { templateID: 'base' },
|
|
125
|
+
body: { templateID: 'base', autoPause: false }, // ends at its timeout; autoPause: true keeps a long-lived computer
|
|
126
126
|
});
|
|
127
127
|
const result = await sandboxes.commands.run({
|
|
128
128
|
path: { sandbox_id: sandbox.sandboxID },
|
|
@@ -262,13 +262,14 @@ export default async (input: { prompt: string }) => {
|
|
|
262
262
|
|
|
263
263
|
Keep your code and point the official SDK at Praxis by changing `baseURL`, for example
|
|
264
264
|
`https://api.deepraxis.com/openai/v1` for the OpenAI SDK. The
|
|
265
|
-
[
|
|
266
|
-
Anthropic
|
|
265
|
+
[OpenAI-compatible](https://docs.deepraxis.com/en/developers/model/guides/openai-compatible) and
|
|
266
|
+
[Anthropic-compatible](https://docs.deepraxis.com/en/developers/model/guides/anthropic-compatible)
|
|
267
|
+
guides have the details. This SDK covers what those don't: agents,
|
|
267
268
|
sandboxes, search, data, automation and the rest of the platform.
|
|
268
269
|
|
|
269
270
|
## Resources
|
|
270
271
|
|
|
271
|
-
- [Documentation](https://docs.deepraxis.com) and [API reference](https://docs.deepraxis.com/
|
|
272
|
+
- [Documentation](https://docs.deepraxis.com) and [API reference](https://docs.deepraxis.com/api)
|
|
272
273
|
- [METHODS.md](https://unpkg.com/@deepraxis/sdk/METHODS.md): every method, its HTTP route, and whether it streams or paginates
|
|
273
274
|
- [Praxis CLI](https://www.npmjs.com/package/@deepraxis/cli): the same API from your terminal
|
|
274
275
|
|
|
@@ -276,5 +277,5 @@ sandboxes, search, data, automation and the rest of the platform.
|
|
|
276
277
|
|
|
277
278
|
[Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0). Copyright 2026 南京深度实践人工智能科技有限公司 (Deepractice).
|
|
278
279
|
|
|
279
|
-
"Praxis"
|
|
280
|
+
"Praxis" and "Deepraxis" are trademarks of Deepractice; the license does not grant
|
|
280
281
|
rights to use them.
|
package/dist/automation.d.ts
CHANGED
|
@@ -23,6 +23,13 @@ export declare function createAutomationClient(options: PraxisOptions): {
|
|
|
23
23
|
hooks: {
|
|
24
24
|
send: (options: import("./core/transport.js").CallOptions<import("./generated/types.gen.js").AutomationHooksReceiveData>) => Promise<import("./generated/types.gen.js").AutomationFiring>;
|
|
25
25
|
};
|
|
26
|
+
humanTasks: {
|
|
27
|
+
cancel: (options: import("./core/transport.js").CallOptions<import("./generated/types.gen.js").AutomationHumanTasksCancelData>) => Promise<import("./generated/types.gen.js").AutomationHumanTask>;
|
|
28
|
+
delegate: (options: import("./core/transport.js").CallOptions<import("./generated/types.gen.js").AutomationHumanTasksDelegateData>) => Promise<import("./generated/types.gen.js").AutomationHumanTask>;
|
|
29
|
+
list: (options?: import("./core/transport.js").CallOptions<import("./generated/types.gen.js").AutomationHumanTasksListData> | undefined) => Promise<import("./automation.js").Page<import("./generated/types.gen.js").AutomationHumanTask>>;
|
|
30
|
+
respond: (options: import("./core/transport.js").CallOptions<import("./generated/types.gen.js").AutomationHumanTasksRespondData>) => Promise<import("./generated/types.gen.js").AutomationHumanTask>;
|
|
31
|
+
retrieve: (options: import("./core/transport.js").CallOptions<import("./generated/types.gen.js").AutomationHumanTasksGetData>) => Promise<import("./generated/types.gen.js").AutomationHumanTask>;
|
|
32
|
+
};
|
|
26
33
|
resolve: {
|
|
27
34
|
retrieve: (options: import("./core/transport.js").CallOptions<import("./generated/types.gen.js").AutomationResolveResolveData>) => Promise<import("./generated/types.gen.js").AutomationResolveResult>;
|
|
28
35
|
};
|
|
@@ -89,6 +96,33 @@ export declare function createAutomationClient(options: PraxisOptions): {
|
|
|
89
96
|
restore: (options: import("./core/transport.js").CallOptions<import("./generated/types.gen.js").AutomationScriptsRestoreData>) => Promise<import("./generated/types.gen.js").AutomationDefinition>;
|
|
90
97
|
retrieve: (options: import("./core/transport.js").CallOptions<import("./generated/types.gen.js").AutomationScriptsGetData>) => Promise<import("./generated/types.gen.js").AutomationDefinitionDetail>;
|
|
91
98
|
update: (options: import("./core/transport.js").CallOptions<import("./generated/types.gen.js").AutomationScriptsPatchData>) => Promise<import("./generated/types.gen.js").AutomationDefinitionDetail>;
|
|
99
|
+
vaults: {
|
|
100
|
+
delete: (options: import("./core/transport.js").CallOptions<import("./generated/types.gen.js").AutomationScriptsVaultsDeleteData>) => Promise<void>;
|
|
101
|
+
list: (options: import("./core/transport.js").CallOptions<import("./generated/types.gen.js").AutomationScriptsVaultsListData>) => Promise<{
|
|
102
|
+
data: Array<{
|
|
103
|
+
alias: string;
|
|
104
|
+
vault: {
|
|
105
|
+
id: string;
|
|
106
|
+
name: string;
|
|
107
|
+
};
|
|
108
|
+
secrets: Array<{
|
|
109
|
+
name: string;
|
|
110
|
+
}>;
|
|
111
|
+
secrets_unavailable?: true;
|
|
112
|
+
}>;
|
|
113
|
+
}>;
|
|
114
|
+
set: (options: import("./core/transport.js").CallOptions<import("./generated/types.gen.js").AutomationScriptsVaultsSetData>) => Promise<{
|
|
115
|
+
alias: string;
|
|
116
|
+
vault: {
|
|
117
|
+
id: string;
|
|
118
|
+
name: string;
|
|
119
|
+
};
|
|
120
|
+
secrets: Array<{
|
|
121
|
+
name: string;
|
|
122
|
+
}>;
|
|
123
|
+
secrets_unavailable?: true;
|
|
124
|
+
}>;
|
|
125
|
+
};
|
|
92
126
|
versions: {
|
|
93
127
|
create: (options: import("./core/transport.js").CallOptions<import("./generated/types.gen.js").AutomationScriptsPublishData>) => Promise<import("./generated/types.gen.js").AutomationVersion>;
|
|
94
128
|
deprecate: (options: import("./core/transport.js").CallOptions<import("./generated/types.gen.js").AutomationScriptsDeprecateData>) => Promise<import("./generated/types.gen.js").AutomationVersion>;
|
|
@@ -136,6 +170,33 @@ export declare function createAutomationClient(options: PraxisOptions): {
|
|
|
136
170
|
restore: (options: import("./core/transport.js").CallOptions<import("./generated/types.gen.js").AutomationWorkflowsRestoreData>) => Promise<import("./generated/types.gen.js").AutomationDefinition>;
|
|
137
171
|
retrieve: (options: import("./core/transport.js").CallOptions<import("./generated/types.gen.js").AutomationWorkflowsGetData>) => Promise<import("./generated/types.gen.js").AutomationDefinitionDetail>;
|
|
138
172
|
update: (options: import("./core/transport.js").CallOptions<import("./generated/types.gen.js").AutomationWorkflowsPatchData>) => Promise<import("./generated/types.gen.js").AutomationDefinitionDetail>;
|
|
173
|
+
vaults: {
|
|
174
|
+
delete: (options: import("./core/transport.js").CallOptions<import("./generated/types.gen.js").AutomationWorkflowsVaultsDeleteData>) => Promise<void>;
|
|
175
|
+
list: (options: import("./core/transport.js").CallOptions<import("./generated/types.gen.js").AutomationWorkflowsVaultsListData>) => Promise<{
|
|
176
|
+
data: Array<{
|
|
177
|
+
alias: string;
|
|
178
|
+
vault: {
|
|
179
|
+
id: string;
|
|
180
|
+
name: string;
|
|
181
|
+
};
|
|
182
|
+
secrets: Array<{
|
|
183
|
+
name: string;
|
|
184
|
+
}>;
|
|
185
|
+
secrets_unavailable?: true;
|
|
186
|
+
}>;
|
|
187
|
+
}>;
|
|
188
|
+
set: (options: import("./core/transport.js").CallOptions<import("./generated/types.gen.js").AutomationWorkflowsVaultsSetData>) => Promise<{
|
|
189
|
+
alias: string;
|
|
190
|
+
vault: {
|
|
191
|
+
id: string;
|
|
192
|
+
name: string;
|
|
193
|
+
};
|
|
194
|
+
secrets: Array<{
|
|
195
|
+
name: string;
|
|
196
|
+
}>;
|
|
197
|
+
secrets_unavailable?: true;
|
|
198
|
+
}>;
|
|
199
|
+
};
|
|
139
200
|
versions: {
|
|
140
201
|
create: (options: import("./core/transport.js").CallOptions<import("./generated/types.gen.js").AutomationWorkflowsPublishData>) => Promise<import("./generated/types.gen.js").AutomationVersion>;
|
|
141
202
|
deprecate: (options: import("./core/transport.js").CallOptions<import("./generated/types.gen.js").AutomationWorkflowsDeprecateData>) => Promise<import("./generated/types.gen.js").AutomationVersion>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as sdk from "../generated/sdk.gen.js";
|
|
2
|
+
import { binaryOperations } from "../generated/binary-operations.gen.js";
|
|
3
|
+
/**
|
|
4
|
+
* The generated SDK operations whose success response the OpenAPI declares as binary bytes
|
|
5
|
+
* (generated from the spec into `binary-operations.gen.ts`). Resolved by function identity, so
|
|
6
|
+
* wrapping, renaming or minification cannot change the answer.
|
|
7
|
+
*/
|
|
8
|
+
const binary = new Set(binaryOperations
|
|
9
|
+
.map(name => sdk[name])
|
|
10
|
+
.filter((operation) => typeof operation === 'function'));
|
|
11
|
+
/** Whether this operation's 200 response is the declared bytes of the resource, not a JSON body. */
|
|
12
|
+
export function isBinaryOperation(operation) {
|
|
13
|
+
return binary.has(operation);
|
|
14
|
+
}
|
package/dist/core/client.d.ts
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
|
+
import { type SandboxTemplateBuildInput, type SandboxTemplateBuildResult } from "../helpers/sandbox-templates.js";
|
|
1
2
|
import { type UploadFileOptions, type UploadedFile } from '../helpers/file-upload.js';
|
|
2
3
|
import { resourceFactories } from '../resources.generated.js';
|
|
3
4
|
import { type PraxisOptions } from './transport.js';
|
|
4
5
|
import { type PublishInput, type PublishResult } from '../helpers/application-publish.js';
|
|
6
|
+
import { type BrowserConnectOptions, type PraxisBrowser } from '../helpers/browser-connect.js';
|
|
5
7
|
import { type CountInput, type CountResult } from '../helpers/database-count.js';
|
|
6
8
|
type Resources = {
|
|
7
9
|
readonly [K in keyof typeof resourceFactories]: ReturnType<(typeof resourceFactories)[K]>;
|
|
8
10
|
};
|
|
9
|
-
export interface Praxis extends Omit<Resources, 'application' | 'database' | 'file'> {
|
|
11
|
+
export interface Praxis extends Omit<Resources, 'application' | 'browser' | 'database' | 'file' | 'sandbox'> {
|
|
12
|
+
readonly sandbox: Omit<Resources['sandbox'], 'templates'> & {
|
|
13
|
+
templates: Resources['sandbox']['templates'] & {
|
|
14
|
+
build(input: SandboxTemplateBuildInput): Promise<SandboxTemplateBuildResult>;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
readonly browser: Resources['browser'] & {
|
|
18
|
+
connect(options?: BrowserConnectOptions): Promise<PraxisBrowser>;
|
|
19
|
+
};
|
|
10
20
|
readonly file: Resources['file'] & {
|
|
11
21
|
uploadFile(file: Blob | File, options: UploadFileOptions): Promise<UploadedFile>;
|
|
12
22
|
};
|
package/dist/core/client.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { buildSandboxTemplate } from "../helpers/sandbox-templates.js";
|
|
1
2
|
import { uploadFile } from "../helpers/file-upload.js";
|
|
2
3
|
import { resourceFactories } from "../resources.generated.js";
|
|
3
4
|
import { Transport } from "./transport.js";
|
|
4
5
|
import { publish } from "../helpers/application-publish.js";
|
|
6
|
+
import { connectBrowser } from "../helpers/browser-connect.js";
|
|
5
7
|
import { count } from "../helpers/database-count.js";
|
|
6
8
|
export class Praxis {
|
|
7
9
|
constructor(options) {
|
|
@@ -9,10 +11,21 @@ export class Praxis {
|
|
|
9
11
|
for (const [name, create] of Object.entries(resourceFactories)) {
|
|
10
12
|
const resource = create(transport);
|
|
11
13
|
// Assemble before sealing the resource property; never replace a readonly SDK resource.
|
|
14
|
+
if (name === 'sandbox')
|
|
15
|
+
Object.assign(resource.templates, { build: (input) => buildSandboxTemplate(this, input) });
|
|
12
16
|
if (name === 'file')
|
|
13
17
|
Object.assign(resource, { uploadFile: (file, options) => uploadFile(this, file, options) });
|
|
14
18
|
if (name === 'database')
|
|
15
19
|
Object.assign(resource, { count: (input) => count(transport, input) });
|
|
20
|
+
if (name === 'browser') {
|
|
21
|
+
// The npm build has no Node globals in scope; name the process shape this helper reads.
|
|
22
|
+
const host = globalThis.process;
|
|
23
|
+
Object.assign(resource, { connect: (options) => connectBrowser({
|
|
24
|
+
contexts: resource.contexts,
|
|
25
|
+
env: host?.env ?? {},
|
|
26
|
+
builtin: host?.getBuiltinModule?.bind(host),
|
|
27
|
+
}, options) });
|
|
28
|
+
}
|
|
16
29
|
if (name === 'application')
|
|
17
30
|
Object.assign(resource, { publish: (input) => publish(this, input) });
|
|
18
31
|
Object.defineProperty(this, name, { value: resource, enumerable: true });
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Default credential chain
|
|
3
|
-
* PRAXIS_API_TOKEN environment variable
|
|
4
|
-
*
|
|
2
|
+
* Default credential chain (ticket-5367, ADR-098 §2, ADR-157), the same rule as the `praxis` CLI:
|
|
3
|
+
* 1. the PRAXIS_API_TOKEN environment variable;
|
|
4
|
+
* 2. PRAXIS_CWD set: `$PRAXIS_CWD/.praxis/credentials/<env>.json` and nothing else — no file there means no token,
|
|
5
|
+
* never the home's login and never a parent directory's;
|
|
6
|
+
* 3. otherwise the home: `~/.praxis/credentials/<env>.json`, and while that file is absent the legacy
|
|
7
|
+
* `~/.praxis/cli/<env>.json` that `praxis login` wrote before ADR-157 and the platform still writes for a
|
|
8
|
+
* managed login.
|
|
9
|
+
* Resolved at call time so a token the platform renewed in the file is picked up by an already-running process.
|
|
5
10
|
*/
|
|
6
11
|
export interface ResolvedCredentials {
|
|
7
12
|
token?: string;
|
|
@@ -9,6 +14,20 @@ export interface ResolvedCredentials {
|
|
|
9
14
|
}
|
|
10
15
|
type Env = Record<string, string | undefined>;
|
|
11
16
|
type ReadFile = (path: string) => string | null;
|
|
17
|
+
/**
|
|
18
|
+
* Which environment's login file applies: PRAXIS_ENV when it names one, otherwise a `-develop.` host in
|
|
19
|
+
* PRAXIS_API_URL means develop and any other host production — the rule apps/cli/src/config/env.ts
|
|
20
|
+
* applies. A PRAXIS_ENV that is not a plain name is no environment at all and is ignored. Pure.
|
|
21
|
+
*/
|
|
22
|
+
export declare function credentialsEnv(env: Env): string;
|
|
23
|
+
/** The credential file of one directory: `<dir>/.praxis/credentials/<env>.json`. Pure. */
|
|
24
|
+
export declare function credentialsFileIn(dir: string, env: Env): string;
|
|
25
|
+
/**
|
|
26
|
+
* The credential files this process reads, in order (ADR-157): a PRAXIS_CWD directory is the only one when named;
|
|
27
|
+
* otherwise the home's file and then its legacy login file. Empty without a home directory. Pure.
|
|
28
|
+
*/
|
|
29
|
+
export declare function credentialsPaths(env: Env): string[];
|
|
30
|
+
/** The first file this process would read (the one `praxis login` writes). Null without a home directory. Pure. */
|
|
12
31
|
export declare function credentialsPath(env: Env): string | null;
|
|
13
32
|
export declare function resolveDefaultCredentials(env?: Env, readFile?: ReadFile): ResolvedCredentials;
|
|
14
33
|
export {};
|
package/dist/core/credentials.js
CHANGED
|
@@ -8,22 +8,61 @@ function defaultReadFile(path) {
|
|
|
8
8
|
return null;
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Which environment's login file applies: PRAXIS_ENV when it names one, otherwise a `-develop.` host in
|
|
13
|
+
* PRAXIS_API_URL means develop and any other host production — the rule apps/cli/src/config/env.ts
|
|
14
|
+
* applies. A PRAXIS_ENV that is not a plain name is no environment at all and is ignored. Pure.
|
|
15
|
+
*/
|
|
16
|
+
export function credentialsEnv(env) {
|
|
17
|
+
const declared = nonEmpty(env.PRAXIS_ENV);
|
|
18
|
+
if (declared && /^[A-Za-z0-9_-]+$/.test(declared))
|
|
19
|
+
return declared;
|
|
20
|
+
const apiUrl = nonEmpty(env.PRAXIS_API_URL);
|
|
21
|
+
if (apiUrl) {
|
|
22
|
+
try {
|
|
23
|
+
if (new URL(apiUrl).hostname.includes('-develop.'))
|
|
24
|
+
return 'develop';
|
|
25
|
+
}
|
|
26
|
+
catch { /* a malformed URL is not evidence of develop */ }
|
|
27
|
+
}
|
|
28
|
+
return 'production';
|
|
29
|
+
}
|
|
30
|
+
const trimSlashes = (path) => path.replace(/[/\\]+$/, '') || path;
|
|
31
|
+
/** The credential file of one directory: `<dir>/.praxis/credentials/<env>.json`. Pure. */
|
|
32
|
+
export function credentialsFileIn(dir, env) {
|
|
33
|
+
return `${trimSlashes(dir)}/.praxis/credentials/${credentialsEnv(env)}.json`;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The credential files this process reads, in order (ADR-157): a PRAXIS_CWD directory is the only one when named;
|
|
37
|
+
* otherwise the home's file and then its legacy login file. Empty without a home directory. Pure.
|
|
38
|
+
*/
|
|
39
|
+
export function credentialsPaths(env) {
|
|
40
|
+
const named = nonEmpty(env.PRAXIS_CWD);
|
|
41
|
+
if (named)
|
|
42
|
+
return [credentialsFileIn(named, env)];
|
|
12
43
|
const home = nonEmpty(env.HOME) ?? nonEmpty(env.USERPROFILE);
|
|
13
|
-
return home ? `${home
|
|
44
|
+
return home ? [credentialsFileIn(home, env), `${trimSlashes(home)}/.praxis/cli/${credentialsEnv(env)}.json`] : [];
|
|
45
|
+
}
|
|
46
|
+
/** The first file this process would read (the one `praxis login` writes). Null without a home directory. Pure. */
|
|
47
|
+
export function credentialsPath(env) {
|
|
48
|
+
return credentialsPaths(env)[0] ?? null;
|
|
14
49
|
}
|
|
15
50
|
export function resolveDefaultCredentials(env = globalThis.process?.env ?? {}, readFile = defaultReadFile) {
|
|
16
51
|
const envToken = nonEmpty(env.PRAXIS_API_TOKEN);
|
|
17
52
|
const envUrl = nonEmpty(env.PRAXIS_API_URL);
|
|
18
53
|
if (envToken)
|
|
19
54
|
return { token: envToken, ...(envUrl ? { apiUrl: envUrl } : {}) };
|
|
20
|
-
|
|
21
|
-
const
|
|
55
|
+
let text = null;
|
|
56
|
+
for (const path of credentialsPaths(env)) {
|
|
57
|
+
text = readFile(path);
|
|
58
|
+
if (text)
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
22
61
|
if (!text)
|
|
23
62
|
return envUrl ? { apiUrl: envUrl } : {};
|
|
24
63
|
try {
|
|
25
64
|
const file = JSON.parse(text);
|
|
26
|
-
const token = nonEmpty(file.
|
|
65
|
+
const token = nonEmpty(file.access_token);
|
|
27
66
|
const apiUrl = envUrl ?? nonEmpty(file.api_url);
|
|
28
67
|
return { ...(token ? { token } : {}), ...(apiUrl ? { apiUrl } : {}) };
|
|
29
68
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Deprecated SDK methods warn once per process per method (ticket-4078). The table is generated from the
|
|
2
|
+
* OpenAPI `deprecated: true` operations; this is the single call path every deprecated binding goes through. */
|
|
3
|
+
export interface DeprecationNotice {
|
|
4
|
+
readonly replacement: string;
|
|
5
|
+
readonly sunset: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function deprecationMessage(method: string, notice: DeprecationNotice): string;
|
|
8
|
+
/** Test seam: forget which methods already warned. */
|
|
9
|
+
export declare function resetDeprecationWarnings(): void;
|
|
10
|
+
export declare function envSilencesDeprecations(): boolean;
|
|
11
|
+
export declare function deprecate<F extends (...args: any[]) => any>(silenced: () => boolean, method: string, notice: DeprecationNotice, fn: F): F;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const warned = new Set();
|
|
2
|
+
export function deprecationMessage(method, notice) {
|
|
3
|
+
return `${method} is deprecated and stops working on ${notice.sunset}; use ${notice.replacement} instead.`;
|
|
4
|
+
}
|
|
5
|
+
/** Test seam: forget which methods already warned. */
|
|
6
|
+
export function resetDeprecationWarnings() { warned.clear(); }
|
|
7
|
+
export function envSilencesDeprecations() {
|
|
8
|
+
const env = globalThis.process?.env;
|
|
9
|
+
const value = env?.PRAXIS_SDK_SILENCE_DEPRECATIONS;
|
|
10
|
+
return value !== undefined && value !== '' && value !== '0' && value !== 'false';
|
|
11
|
+
}
|
|
12
|
+
export function deprecate(silenced, method, notice, fn) {
|
|
13
|
+
return ((...args) => {
|
|
14
|
+
if (!warned.has(method) && !silenced()) {
|
|
15
|
+
warned.add(method);
|
|
16
|
+
console.warn(deprecationMessage(method, notice));
|
|
17
|
+
}
|
|
18
|
+
return fn(...args);
|
|
19
|
+
});
|
|
20
|
+
}
|
package/dist/core/errors.d.ts
CHANGED
|
@@ -9,6 +9,9 @@ export interface ProblemDetails {
|
|
|
9
9
|
requestId?: string;
|
|
10
10
|
message?: string;
|
|
11
11
|
param?: string | null;
|
|
12
|
+
/** ticket-681 — the documentation page the failure points at, and the exact section to read. */
|
|
13
|
+
docUrl?: string;
|
|
14
|
+
describe?: string;
|
|
12
15
|
raw?: unknown;
|
|
13
16
|
}
|
|
14
17
|
/** Pure normalization shared by HTTP clients and the automation call ledger.
|
|
@@ -26,6 +29,9 @@ export declare class PraxisError extends Error {
|
|
|
26
29
|
readonly errors: unknown[];
|
|
27
30
|
readonly requestId?: string;
|
|
28
31
|
readonly param?: string | null;
|
|
32
|
+
/** ticket-681 — the documented page and the exact section an agent should read to fix the call. */
|
|
33
|
+
readonly docUrl?: string;
|
|
34
|
+
readonly describe?: string;
|
|
29
35
|
readonly raw?: unknown;
|
|
30
36
|
constructor(problem?: ProblemDetails, options?: ErrorOptions);
|
|
31
37
|
static fromResponse(response: Response, body: unknown): PraxisError;
|
package/dist/core/errors.js
CHANGED
|
@@ -16,6 +16,9 @@ export function problemFrom(status, headers, body, statusText) {
|
|
|
16
16
|
param: typeof param === 'string' ? param : param === null || nested.param === null ? null : undefined,
|
|
17
17
|
errors: Array.isArray(value.errors) ? value.errors : [],
|
|
18
18
|
requestId: headers.get('x-request-id') ?? string(value.requestId) ?? string(value.request_id),
|
|
19
|
+
// Both spellings reach here: the own face writes snake_case, an in-process problem keeps docUrl.
|
|
20
|
+
docUrl: string(nested.doc_url) ?? string(value.doc_url) ?? string(nested.docUrl) ?? string(value.docUrl),
|
|
21
|
+
describe: string(nested.describe) ?? string(value.describe),
|
|
19
22
|
raw: body,
|
|
20
23
|
};
|
|
21
24
|
}
|
|
@@ -28,6 +31,9 @@ export class PraxisError extends Error {
|
|
|
28
31
|
errors;
|
|
29
32
|
requestId;
|
|
30
33
|
param;
|
|
34
|
+
/** ticket-681 — the documented page and the exact section an agent should read to fix the call. */
|
|
35
|
+
docUrl;
|
|
36
|
+
describe;
|
|
31
37
|
raw;
|
|
32
38
|
constructor(problem = {}, options) {
|
|
33
39
|
super(problem.message ?? problem.detail ?? problem.title ?? `Praxis request failed${problem.status ? ` (${problem.status})` : ''}`, options);
|
|
@@ -40,6 +46,8 @@ export class PraxisError extends Error {
|
|
|
40
46
|
this.errors = problem.errors ?? [];
|
|
41
47
|
this.requestId = problem.requestId;
|
|
42
48
|
this.param = problem.param;
|
|
49
|
+
this.docUrl = problem.docUrl;
|
|
50
|
+
this.describe = problem.describe;
|
|
43
51
|
this.raw = problem.raw;
|
|
44
52
|
}
|
|
45
53
|
static fromResponse(response, body) {
|
package/dist/core/transport.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { type SSEEvent } from './sse.js';
|
|
2
2
|
export interface PraxisOptions {
|
|
3
|
-
/** Explicit key. Omitted on a Praxis computer: PRAXIS_API_TOKEN, then
|
|
3
|
+
/** Explicit key. Omitted on a Praxis computer: PRAXIS_API_TOKEN, then the login file `~/.praxis/cli/<env>.json`, are used. */
|
|
4
4
|
apiKey?: string;
|
|
5
5
|
baseUrl?: string;
|
|
6
6
|
timeoutMs?: number;
|
|
7
7
|
maxRetries?: number;
|
|
8
8
|
fetch?: typeof globalThis.fetch;
|
|
9
|
+
/** Silence the once-per-method warning a deprecated method prints. PRAXIS_SDK_SILENCE_DEPRECATIONS=1 does the same. */
|
|
10
|
+
silenceDeprecations?: boolean;
|
|
9
11
|
}
|
|
10
12
|
export interface RequestOptions {
|
|
11
13
|
headers?: Record<string, string>;
|
|
@@ -25,9 +27,20 @@ type InternalOptions = RequestOptions & {
|
|
|
25
27
|
query?: unknown;
|
|
26
28
|
lastEventId?: string;
|
|
27
29
|
};
|
|
30
|
+
/** Margin over a server-side execution deadline: the response still has to travel back after it. */
|
|
31
|
+
export declare const SERVER_DEADLINE_MARGIN_MS = 30000;
|
|
32
|
+
/**
|
|
33
|
+
* A request body that carries its own execution deadline (`timeoutMs`, as in sandbox commands.run) is
|
|
34
|
+
* waited for at least that long plus a margin, so the client never gives up before the server answers.
|
|
35
|
+
*/
|
|
36
|
+
export declare function serverDeadlineMs(options: {
|
|
37
|
+
body?: unknown;
|
|
38
|
+
}): number;
|
|
28
39
|
export declare class Transport {
|
|
29
40
|
private readonly config;
|
|
30
41
|
constructor(options: PraxisOptions);
|
|
42
|
+
/** Whether deprecated-method warnings are off (client option or PRAXIS_SDK_SILENCE_DEPRECATIONS). */
|
|
43
|
+
readonly silenced: () => boolean;
|
|
31
44
|
private validate;
|
|
32
45
|
private scope;
|
|
33
46
|
request<R>(operation: Operation, options?: InternalOptions): Promise<R>;
|
package/dist/core/transport.js
CHANGED
|
@@ -3,6 +3,8 @@ import { PraxisError, PraxisTimeoutError } from "./errors.js";
|
|
|
3
3
|
import { abortable, fetchWithRetry } from "./retry.js";
|
|
4
4
|
import { parseSSE } from "./sse.js";
|
|
5
5
|
import { resolveDefaultCredentials } from "./credentials.js";
|
|
6
|
+
import { isBinaryOperation } from "./binary-operations.js";
|
|
7
|
+
import { envSilencesDeprecations } from "./deprecation.js";
|
|
6
8
|
/** Our own per-call keys, beyond what the generated hey-api client accepts. */
|
|
7
9
|
const SDK_OPTION_KEYS = ['timeoutMs', 'maxRetries', 'stream', 'lastEventId'];
|
|
8
10
|
/** Every key of the generated client's per-call RequestOptions (request parts, fetch/RequestInit, serializers,
|
|
@@ -32,21 +34,34 @@ function assertKnownOptions(options) {
|
|
|
32
34
|
detail: `Unrecognised option ${stray.length > 1 ? 'keys' : 'key'} ${names}. Request parameters are not flat: put each under \`query\` (GET/DELETE: filters, pagination), \`path\` (URL segments) or \`body\` (POST/PATCH/PUT payload), e.g. call({ query: { ${stray[0]} } }) or call({ body: { ${stray[0]} } }). Common top-level keys: path, query, body, headers, signal, timeoutMs, maxRetries.`,
|
|
33
35
|
});
|
|
34
36
|
}
|
|
37
|
+
/** Margin over a server-side execution deadline: the response still has to travel back after it. */
|
|
38
|
+
export const SERVER_DEADLINE_MARGIN_MS = 30_000;
|
|
39
|
+
/**
|
|
40
|
+
* A request body that carries its own execution deadline (`timeoutMs`, as in sandbox commands.run) is
|
|
41
|
+
* waited for at least that long plus a margin, so the client never gives up before the server answers.
|
|
42
|
+
*/
|
|
43
|
+
export function serverDeadlineMs(options) {
|
|
44
|
+
const body = options.body;
|
|
45
|
+
const deadline = body && typeof body === 'object' ? body.timeoutMs : undefined;
|
|
46
|
+
return typeof deadline === 'number' && Number.isFinite(deadline) && deadline > 0 ? deadline + SERVER_DEADLINE_MARGIN_MS : 0;
|
|
47
|
+
}
|
|
35
48
|
export class Transport {
|
|
36
49
|
config;
|
|
37
50
|
constructor(options) {
|
|
38
|
-
this.config = { timeoutMs:
|
|
51
|
+
this.config = { timeoutMs: 600_000, maxRetries: 2, fetch: globalThis.fetch, ...options };
|
|
39
52
|
this.validate(this.config.timeoutMs, this.config.maxRetries);
|
|
40
53
|
}
|
|
54
|
+
/** Whether deprecated-method warnings are off (client option or PRAXIS_SDK_SILENCE_DEPRECATIONS). */
|
|
55
|
+
silenced = () => this.config.silenceDeprecations === true || envSilencesDeprecations();
|
|
41
56
|
validate(timeout, retries) {
|
|
42
57
|
if (!Number.isFinite(timeout) || timeout <= 0)
|
|
43
58
|
throw new RangeError('timeoutMs must be positive and finite');
|
|
44
59
|
if (!Number.isSafeInteger(retries) || retries < 0)
|
|
45
60
|
throw new RangeError('maxRetries must be a non-negative integer');
|
|
46
61
|
}
|
|
47
|
-
scope(options, streaming) {
|
|
62
|
+
scope(operation, options, streaming) {
|
|
48
63
|
assertKnownOptions(options);
|
|
49
|
-
const timeoutMs = options.timeoutMs ?? this.config.timeoutMs;
|
|
64
|
+
const timeoutMs = options.timeoutMs ?? Math.max(this.config.timeoutMs, serverDeadlineMs(options));
|
|
50
65
|
const maxRetries = options.maxRetries ?? this.config.maxRetries;
|
|
51
66
|
this.validate(timeoutMs, maxRetries);
|
|
52
67
|
const controller = new AbortController();
|
|
@@ -87,7 +102,10 @@ export class Transport {
|
|
|
87
102
|
}
|
|
88
103
|
return {
|
|
89
104
|
signal,
|
|
90
|
-
|
|
105
|
+
// A binary operation is parsed as a Blob whatever the server says in Content-Type: the runtime
|
|
106
|
+
// value must match the declared `Blob | File`, and JSON bytes must survive as bytes.
|
|
107
|
+
options: { ...options, headers: Object.fromEntries(headers), client, signal, throwOnError: true, responseStyle: 'fields',
|
|
108
|
+
...(streaming ? { parseAs: 'stream' } : isBinaryOperation(operation) ? { parseAs: 'blob' } : {}) },
|
|
91
109
|
close() { clearTimeout(timer); external?.removeEventListener('abort', abort); },
|
|
92
110
|
};
|
|
93
111
|
}
|
|
@@ -96,7 +114,7 @@ export class Transport {
|
|
|
96
114
|
}
|
|
97
115
|
/** Internal helper access to response metadata, with the same request policy. */
|
|
98
116
|
async requestWithResponse(operation, options = {}) {
|
|
99
|
-
const scope = this.scope(options, false);
|
|
117
|
+
const scope = this.scope(operation, options, false);
|
|
100
118
|
try {
|
|
101
119
|
const result = await abortable(operation(scope.options), scope.signal);
|
|
102
120
|
return { data: result.data, response: result.response };
|
|
@@ -106,7 +124,7 @@ export class Transport {
|
|
|
106
124
|
}
|
|
107
125
|
}
|
|
108
126
|
async *stream(operation, options = {}) {
|
|
109
|
-
const scope = this.scope(options, true);
|
|
127
|
+
const scope = this.scope(operation, options, true);
|
|
110
128
|
try {
|
|
111
129
|
const result = await abortable(operation(scope.options), scope.signal);
|
|
112
130
|
if (!result.response.headers.get('content-type')?.split(';')[0]?.trim().toLowerCase().includes('text/event-stream')) {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Generated by scripts/resources.ts. DO NOT EDIT.
|
|
2
|
+
/** Exported SDK operations whose 2xx response the OpenAPI declares as binary bytes: the core
|
|
3
|
+
* transport resolves them to a Blob whatever the response Content-Type says. */
|
|
4
|
+
export const binaryOperations = [
|
|
5
|
+
'browserGetSessionFrame',
|
|
6
|
+
'computersFilesContent',
|
|
7
|
+
'createAudioSpeech',
|
|
8
|
+
'downloadVideoContent',
|
|
9
|
+
'fileRetrieveFileContent',
|
|
10
|
+
'registryGitFilesRetrieve',
|
|
11
|
+
'registryPackagesVersionsArchive',
|
|
12
|
+
'registryPackagesVersionsFilesRetrieve',
|
|
13
|
+
'skillsVersionsDownload',
|
|
14
|
+
];
|