@deepraxis/sdk 0.1.1-dev.ff9de03 → 0.2.0-dev.0ea50e2

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 (34) hide show
  1. package/METHODS.md +690 -113
  2. package/README.md +5 -4
  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 +16 -6
  6. package/dist/core/credentials.js +24 -5
  7. package/dist/core/deprecation.d.ts +11 -0
  8. package/dist/core/deprecation.js +20 -0
  9. package/dist/core/retry.js +2 -0
  10. package/dist/core/transport.d.ts +4 -0
  11. package/dist/core/transport.js +26 -7
  12. package/dist/generated/binary-operations.gen.d.ts +3 -0
  13. package/dist/generated/binary-operations.gen.js +14 -0
  14. package/dist/generated/index.d.ts +2 -2
  15. package/dist/generated/index.js +1 -1
  16. package/dist/generated/sdk.gen.d.ts +1446 -328
  17. package/dist/generated/sdk.gen.js +6623 -3571
  18. package/dist/generated/types.gen.d.ts +70804 -49562
  19. package/dist/helpers/application-publish.js +16 -2
  20. package/dist/helpers/browser-connect-error.d.ts +28 -0
  21. package/dist/helpers/browser-connect-error.js +74 -0
  22. package/dist/helpers/browser-connect.d.ts +2 -0
  23. package/dist/helpers/browser-connect.js +36 -42
  24. package/dist/helpers/browser-decisions.d.ts +13 -0
  25. package/dist/helpers/browser-decisions.js +11 -0
  26. package/dist/helpers/browser-documentation.d.ts +1 -1
  27. package/dist/helpers/browser-documentation.js +12 -2
  28. package/dist/index.d.ts +3 -0
  29. package/dist/index.js +2 -0
  30. package/dist/operations.generated.d.ts +1 -0
  31. package/dist/operations.generated.js +18762 -12713
  32. package/dist/resources.generated.d.ts +2853 -348
  33. package/dist/resources.generated.js +611 -121
  34. package/package.json +1 -1
package/README.md CHANGED
@@ -10,7 +10,7 @@ The official TypeScript SDK for [Praxis](https://deepraxis.com), the cloud where
10
10
  [![Bundle size](https://img.shields.io/bundlephobia/minzip/@deepraxis/sdk?color=2e8555)](https://bundlephobia.com/package/@deepraxis/sdk)
11
11
  [![License](https://img.shields.io/badge/license-Apache--2.0-2e8555)](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/docs/api) · [Console](https://console.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
 
@@ -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
- [SDK cookbook](https://docs.deepraxis.com/docs/cookbook/sdk) has the details for OpenAI,
266
- Anthropic, the Vercel AI SDK and LangChain. This SDK covers what those don't: agents,
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/docs/api)
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
 
@@ -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,9 +1,12 @@
1
1
  /**
2
- * Default credential chain for code running on a Praxis computer (ticket-5367, ADR-098 §2):
3
- * the PRAXIS_API_TOKEN environment variable, then the login file of the environment,
4
- * `~/.praxis/cli/<env>.json` — the one file `praxis login` writes for a person and the platform writes
5
- * for a managed login. Resolved at call time so a token the platform renewed in the file is picked up
6
- * 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.
7
10
  */
8
11
  export interface ResolvedCredentials {
9
12
  token?: string;
@@ -17,7 +20,14 @@ type ReadFile = (path: string) => string | null;
17
20
  * applies. A PRAXIS_ENV that is not a plain name is no environment at all and is ignored. Pure.
18
21
  */
19
22
  export declare function credentialsEnv(env: Env): string;
20
- /** The one login file, the same path the CLI reads for this environment. Null without a home directory. Pure. */
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. */
21
31
  export declare function credentialsPath(env: Env): string | null;
22
32
  export declare function resolveDefaultCredentials(env?: Env, readFile?: ReadFile): ResolvedCredentials;
23
33
  export {};
@@ -27,18 +27,37 @@ export function credentialsEnv(env) {
27
27
  }
28
28
  return 'production';
29
29
  }
30
- /** The one login file, the same path the CLI reads for this environment. Null without a home directory. Pure. */
31
- export function credentialsPath(env) {
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)];
32
43
  const home = nonEmpty(env.HOME) ?? nonEmpty(env.USERPROFILE);
33
- return home ? `${home.replace(/[/\\]+$/, '')}/.praxis/cli/${credentialsEnv(env)}.json` : 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;
34
49
  }
35
50
  export function resolveDefaultCredentials(env = globalThis.process?.env ?? {}, readFile = defaultReadFile) {
36
51
  const envToken = nonEmpty(env.PRAXIS_API_TOKEN);
37
52
  const envUrl = nonEmpty(env.PRAXIS_API_URL);
38
53
  if (envToken)
39
54
  return { token: envToken, ...(envUrl ? { apiUrl: envUrl } : {}) };
40
- const path = credentialsPath(env);
41
- 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
+ }
42
61
  if (!text)
43
62
  return envUrl ? { apiUrl: envUrl } : {};
44
63
  try {
@@ -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
+ }
@@ -37,6 +37,8 @@ export async function fetchWithRetry(request, fetcher, options) {
37
37
  let response;
38
38
  try {
39
39
  // Preserve a replayable request; never reuse a consumed body on the next attempt.
40
+ // `Request` is generic over the request-init type (`Request<CfHostMetadata, Cf>` under the Workers types), which
41
+ // `RequestInfo` does not name; the clone is still the same request the platform accepts.
40
42
  response = await abortable(fetcher(request.clone()), options.signal);
41
43
  }
42
44
  catch (cause) {
@@ -6,6 +6,8 @@ export interface PraxisOptions {
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>;
@@ -37,6 +39,8 @@ export declare function serverDeadlineMs(options: {
37
39
  export declare class Transport {
38
40
  private readonly config;
39
41
  constructor(options: PraxisOptions);
42
+ /** Whether deprecated-method warnings are off (client option or PRAXIS_SDK_SILENCE_DEPRECATIONS). */
43
+ readonly silenced: () => boolean;
40
44
  private validate;
41
45
  private scope;
42
46
  request<R>(operation: Operation, options?: InternalOptions): Promise<R>;
@@ -3,11 +3,21 @@ 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
- /** Every key of the generated client's per-call RequestOptions (request parts, fetch/RequestInit, serializers,
9
- * auth, SSE hooks, ...). Typed as a total record so a regenerated client that adds a key fails to typecheck here
10
- * until the key is classified, instead of being rejected at runtime by the guard below. */
10
+ /**
11
+ * Every key of the generated client's per-call RequestOptions (request parts, fetch/RequestInit, serializers,
12
+ * auth, SSE hooks, ...), classified by whether the guard below should accept it. The exhaustiveness check after the
13
+ * literal is what keeps this true: a regenerated client that adds a key leaves it out of `HeyApiOptionKey` and fails
14
+ * to typecheck here, instead of being rejected at runtime by the guard.
15
+ *
16
+ * Written as a plain literal plus a mapped assertion rather than as a `Record<keyof GeneratedRequestOptions, true>`:
17
+ * the generated type's key set differs with the compiler's lib (the Workers types add `cf`, hey-api's Config adds
18
+ * `fetcher` and `encodeResponseBody`), so a total Record literal is rejected as excess in one configuration and as
19
+ * incomplete in the other.
20
+ */
11
21
  const HEY_API_OPTION_KEYS = {
12
22
  body: true, path: true, query: true, headers: true, security: true, baseUrl: true, fetch: true, parseAs: true,
13
23
  responseStyle: true, throwOnError: true, auth: true, bodySerializer: true, querySerializer: true,
@@ -16,7 +26,11 @@ const HEY_API_OPTION_KEYS = {
16
26
  // Config extends RequestInit (minus body/headers/method).
17
27
  signal: true, cache: true, credentials: true, integrity: true, keepalive: true, mode: true, priority: true,
18
28
  redirect: true, referrer: true, referrerPolicy: true, window: true,
29
+ // hey-api's own transport hooks: the fetch implementation, the Workers `cf` bag and the body encoder.
30
+ fetcher: true, cf: true, encodeResponseBody: true,
19
31
  };
32
+ const classified = {};
33
+ void classified;
20
34
  const OPTION_KEYS = new Set([...Object.keys(HEY_API_OPTION_KEYS), ...SDK_OPTION_KEYS]);
21
35
  /** Client-side guard: flat params like `{ limit: 20 }` would otherwise be silently dropped by the generated client. */
22
36
  function assertKnownOptions(options) {
@@ -49,13 +63,15 @@ export class Transport {
49
63
  this.config = { timeoutMs: 600_000, maxRetries: 2, fetch: globalThis.fetch, ...options };
50
64
  this.validate(this.config.timeoutMs, this.config.maxRetries);
51
65
  }
66
+ /** Whether deprecated-method warnings are off (client option or PRAXIS_SDK_SILENCE_DEPRECATIONS). */
67
+ silenced = () => this.config.silenceDeprecations === true || envSilencesDeprecations();
52
68
  validate(timeout, retries) {
53
69
  if (!Number.isFinite(timeout) || timeout <= 0)
54
70
  throw new RangeError('timeoutMs must be positive and finite');
55
71
  if (!Number.isSafeInteger(retries) || retries < 0)
56
72
  throw new RangeError('maxRetries must be a non-negative integer');
57
73
  }
58
- scope(options, streaming) {
74
+ scope(operation, options, streaming) {
59
75
  assertKnownOptions(options);
60
76
  const timeoutMs = options.timeoutMs ?? Math.max(this.config.timeoutMs, serverDeadlineMs(options));
61
77
  const maxRetries = options.maxRetries ?? this.config.maxRetries;
@@ -98,7 +114,10 @@ export class Transport {
98
114
  }
99
115
  return {
100
116
  signal,
101
- options: { ...options, headers: Object.fromEntries(headers), client, signal, throwOnError: true, responseStyle: 'fields', ...(streaming ? { parseAs: 'stream' } : {}) },
117
+ // A binary operation is parsed as a Blob whatever the server says in Content-Type: the runtime
118
+ // value must match the declared `Blob | File`, and JSON bytes must survive as bytes.
119
+ options: { ...options, headers: Object.fromEntries(headers), client, signal, throwOnError: true, responseStyle: 'fields',
120
+ ...(streaming ? { parseAs: 'stream' } : isBinaryOperation(operation) ? { parseAs: 'blob' } : {}) },
102
121
  close() { clearTimeout(timer); external?.removeEventListener('abort', abort); },
103
122
  };
104
123
  }
@@ -107,7 +126,7 @@ export class Transport {
107
126
  }
108
127
  /** Internal helper access to response metadata, with the same request policy. */
109
128
  async requestWithResponse(operation, options = {}) {
110
- const scope = this.scope(options, false);
129
+ const scope = this.scope(operation, options, false);
111
130
  try {
112
131
  const result = await abortable(operation(scope.options), scope.signal);
113
132
  return { data: result.data, response: result.response };
@@ -117,7 +136,7 @@ export class Transport {
117
136
  }
118
137
  }
119
138
  async *stream(operation, options = {}) {
120
- const scope = this.scope(options, true);
139
+ const scope = this.scope(operation, options, true);
121
140
  try {
122
141
  const result = await abortable(operation(scope.options), scope.signal);
123
142
  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
+ ];