@deepraxis/sdk 0.1.1-dev.4786c3d → 0.1.1-dev.47b94f1

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 (33) hide show
  1. package/METHODS.md +1286 -228
  2. package/README.md +2 -2
  3. package/dist/core/binary-operations.d.ts +3 -0
  4. package/dist/core/binary-operations.js +14 -0
  5. package/dist/core/credentials.d.ts +22 -3
  6. package/dist/core/credentials.js +44 -5
  7. package/dist/core/errors.d.ts +6 -0
  8. package/dist/core/errors.js +8 -0
  9. package/dist/core/transport.d.ts +1 -1
  10. package/dist/core/transport.js +8 -4
  11. package/dist/generated/binary-operations.gen.d.ts +3 -0
  12. package/dist/generated/binary-operations.gen.js +14 -0
  13. package/dist/generated/index.d.ts +2 -2
  14. package/dist/generated/index.js +1 -1
  15. package/dist/generated/sdk.gen.d.ts +3251 -1250
  16. package/dist/generated/sdk.gen.js +8987 -3086
  17. package/dist/generated/types.gen.d.ts +87761 -51699
  18. package/dist/helpers/application-publish.js +16 -2
  19. package/dist/helpers/browser-actions.d.ts +102 -0
  20. package/dist/helpers/browser-actions.js +146 -0
  21. package/dist/helpers/browser-connect-error.d.ts +28 -0
  22. package/dist/helpers/browser-connect-error.js +74 -0
  23. package/dist/helpers/browser-connect.d.ts +35 -2
  24. package/dist/helpers/browser-connect.js +262 -27
  25. package/dist/helpers/browser-decisions.d.ts +57 -0
  26. package/dist/helpers/browser-decisions.js +64 -0
  27. package/dist/helpers/browser-documentation.d.ts +1 -1
  28. package/dist/helpers/browser-documentation.js +24 -13
  29. package/dist/operations.generated.d.ts +36 -17222
  30. package/dist/operations.generated.js +18330 -6398
  31. package/dist/resources.generated.d.ts +2621 -166
  32. package/dist/resources.generated.js +663 -20
  33. package/package.json +1 -1
package/README.md CHANGED
@@ -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
- cloud browsers, web search, databases, knowledge bases, files, media, automation and hosted
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.
@@ -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 },
@@ -0,0 +1,3 @@
1
+ import type { Operation } from './transport.js';
2
+ /** Whether this operation's 200 response is the declared bytes of the resource, not a JSON body. */
3
+ export declare function isBinaryOperation(operation: Operation): boolean;
@@ -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
+ }
@@ -1,7 +1,12 @@
1
1
  /**
2
- * Default credential chain for code running on a Praxis computer (ticket-5367):
3
- * PRAXIS_API_TOKEN environment variable, then ~/.praxis/credentials. Resolved at call time so a
4
- * token the platform renewed in the file is picked up by an already-running process.
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 {};
@@ -8,22 +8,61 @@ function defaultReadFile(path) {
8
8
  return null;
9
9
  }
10
10
  }
11
- export function credentialsPath(env) {
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.replace(/\/$/, '')}/.praxis/credentials` : null;
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
- const path = credentialsPath(env);
21
- const text = path ? readFile(path) : null;
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.token);
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
  }
@@ -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;
@@ -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) {
@@ -1,6 +1,6 @@
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 ~/.praxis/credentials, are used. */
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;
@@ -3,6 +3,7 @@ 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";
6
7
  /** Our own per-call keys, beyond what the generated hey-api client accepts. */
7
8
  const SDK_OPTION_KEYS = ['timeoutMs', 'maxRetries', 'stream', 'lastEventId'];
8
9
  /** Every key of the generated client's per-call RequestOptions (request parts, fetch/RequestInit, serializers,
@@ -55,7 +56,7 @@ export class Transport {
55
56
  if (!Number.isSafeInteger(retries) || retries < 0)
56
57
  throw new RangeError('maxRetries must be a non-negative integer');
57
58
  }
58
- scope(options, streaming) {
59
+ scope(operation, options, streaming) {
59
60
  assertKnownOptions(options);
60
61
  const timeoutMs = options.timeoutMs ?? Math.max(this.config.timeoutMs, serverDeadlineMs(options));
61
62
  const maxRetries = options.maxRetries ?? this.config.maxRetries;
@@ -98,7 +99,10 @@ export class Transport {
98
99
  }
99
100
  return {
100
101
  signal,
101
- options: { ...options, headers: Object.fromEntries(headers), client, signal, throwOnError: true, responseStyle: 'fields', ...(streaming ? { parseAs: 'stream' } : {}) },
102
+ // A binary operation is parsed as a Blob whatever the server says in Content-Type: the runtime
103
+ // value must match the declared `Blob | File`, and JSON bytes must survive as bytes.
104
+ options: { ...options, headers: Object.fromEntries(headers), client, signal, throwOnError: true, responseStyle: 'fields',
105
+ ...(streaming ? { parseAs: 'stream' } : isBinaryOperation(operation) ? { parseAs: 'blob' } : {}) },
102
106
  close() { clearTimeout(timer); external?.removeEventListener('abort', abort); },
103
107
  };
104
108
  }
@@ -107,7 +111,7 @@ export class Transport {
107
111
  }
108
112
  /** Internal helper access to response metadata, with the same request policy. */
109
113
  async requestWithResponse(operation, options = {}) {
110
- const scope = this.scope(options, false);
114
+ const scope = this.scope(operation, options, false);
111
115
  try {
112
116
  const result = await abortable(operation(scope.options), scope.signal);
113
117
  return { data: result.data, response: result.response };
@@ -117,7 +121,7 @@ export class Transport {
117
121
  }
118
122
  }
119
123
  async *stream(operation, options = {}) {
120
- const scope = this.scope(options, true);
124
+ const scope = this.scope(operation, options, true);
121
125
  try {
122
126
  const result = await abortable(operation(scope.options), scope.signal);
123
127
  if (!result.response.headers.get('content-type')?.split(';')[0]?.trim().toLowerCase().includes('text/event-stream')) {
@@ -0,0 +1,3 @@
1
+ /** Exported SDK operations whose 2xx response the OpenAPI declares as binary bytes: the core
2
+ * transport resolves them to a Blob whatever the response Content-Type says. */
3
+ export declare const binaryOperations: readonly string[];
@@ -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
+ ];