@deepraxis/sdk 0.1.1-dev.07df50c → 0.1.1-dev.1046919
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 +19 -1
- package/README.md +1 -1
- package/dist/automation.d.ts +7 -0
- package/dist/core/transport.js +1 -1
- package/dist/generated/index.d.ts +2 -2
- package/dist/generated/index.js +1 -1
- package/dist/generated/sdk.gen.d.ts +56 -14
- package/dist/generated/sdk.gen.js +128 -13
- package/dist/generated/types.gen.d.ts +1426 -140
- 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 +26 -9
- package/dist/helpers/file-upload.d.ts +2 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/operations.generated.d.ts +207 -27
- package/dist/operations.generated.js +257 -29
- package/dist/resources.generated.d.ts +70 -6
- package/dist/resources.generated.js +11 -0
- package/package.json +1 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PublishInput } from './application-publish.js';
|
|
2
|
+
/** A vite/vinext build read into memory: paths are relative to dist/server and dist/client. */
|
|
3
|
+
export interface BuildOutput {
|
|
4
|
+
serverFiles: Record<string, Uint8Array>;
|
|
5
|
+
clientFiles: Record<string, Uint8Array>;
|
|
6
|
+
/** Parsed dist/server/wrangler.json. */
|
|
7
|
+
wranglerJson: unknown;
|
|
8
|
+
}
|
|
9
|
+
/** Pure mapping from a vite/vinext build (dist/server + dist/client + wrangler.json) to `praxis.application.publish` input. No fs, no network. */
|
|
10
|
+
export declare function publishInputFromBuild(build: BuildOutput, name: string): PublishInput;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { PraxisError } from "../core/errors.js";
|
|
2
|
+
// wrangler.json keys that declare a binding the platform does not accept (it answers UNSUPPORTED).
|
|
3
|
+
const UNSUPPORTED_BINDING_KEYS = ['services', 'queues', 'durable_objects', 'ai', 'analytics_engine_datasets', 'vectorize', 'hyperdrive',
|
|
4
|
+
'browser', 'send_email', 'mtls_certificates', 'dispatch_namespaces', 'unsafe', 'version_metadata', 'images', 'workflows', 'pipelines',
|
|
5
|
+
'secrets_store_secrets', 'ratelimits', 'vpc_services', 'media', 'tail_consumers', 'worker_loaders'];
|
|
6
|
+
// A key declares something only if it holds a value somewhere inside: vite's generated wrangler.json writes
|
|
7
|
+
// empty containers such as `queues: { producers: [], consumers: [] }` and `durable_objects: { bindings: [] }`.
|
|
8
|
+
const isPresent = (value) => {
|
|
9
|
+
if (value === undefined || value === null)
|
|
10
|
+
return false;
|
|
11
|
+
if (Array.isArray(value))
|
|
12
|
+
return value.some(isPresent);
|
|
13
|
+
if (typeof value === 'object')
|
|
14
|
+
return Object.values(value).some(isPresent);
|
|
15
|
+
return true;
|
|
16
|
+
};
|
|
17
|
+
/** Compile one .assetsignore line (gitignore subset: names, `*`, `**`, leading /, trailing /) to a matcher over a relative path. */
|
|
18
|
+
function ignoreMatcher(line) {
|
|
19
|
+
let pattern = line.trim();
|
|
20
|
+
if (!pattern || pattern.startsWith('#') || pattern.startsWith('!'))
|
|
21
|
+
return null;
|
|
22
|
+
const anchored = pattern.startsWith('/') || pattern.slice(0, -1).includes('/');
|
|
23
|
+
pattern = pattern.replace(/^\//, '').replace(/\/$/, '');
|
|
24
|
+
const source = pattern.split('**').map(part => part.split('*').map(piece => piece.replace(/[.+?^${}()|[\]\\]/g, '\\$&')).join('[^/]*')).join('.*');
|
|
25
|
+
const regex = new RegExp(`^${source}$`);
|
|
26
|
+
return path => {
|
|
27
|
+
const segments = path.split('/');
|
|
28
|
+
// The path or any of its parent directories matches, as in gitignore.
|
|
29
|
+
for (let end = 1; end <= segments.length; end++) {
|
|
30
|
+
if (anchored ? regex.test(segments.slice(0, end).join('/')) : regex.test(segments[end - 1]))
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function bindingsFrom(wrangler) {
|
|
37
|
+
const bindings = [];
|
|
38
|
+
const fromList = (key, type) => {
|
|
39
|
+
const list = wrangler[key];
|
|
40
|
+
if (!isPresent(list))
|
|
41
|
+
return;
|
|
42
|
+
if (!Array.isArray(list))
|
|
43
|
+
throw new PraxisError({ code: 'INVALID_PARAMS', message: `wrangler.json ${key} must be an array` });
|
|
44
|
+
for (const entry of list) {
|
|
45
|
+
if (typeof entry?.binding !== 'string')
|
|
46
|
+
throw new PraxisError({ code: 'INVALID_PARAMS', message: `wrangler.json ${key} entry has no binding name` });
|
|
47
|
+
bindings.push({ type, name: entry.binding });
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
fromList('d1_databases', 'd1');
|
|
51
|
+
fromList('kv_namespaces', 'kv_namespace');
|
|
52
|
+
fromList('r2_buckets', 'r2_bucket');
|
|
53
|
+
for (const [name, value] of Object.entries((wrangler.vars ?? {}))) {
|
|
54
|
+
bindings.push((typeof value === 'string' ? { type: 'plain_text', name, text: value } : { type: 'json', name, json: value }));
|
|
55
|
+
}
|
|
56
|
+
if (typeof wrangler.assets?.binding === 'string')
|
|
57
|
+
bindings.push({ type: 'assets', name: wrangler.assets.binding });
|
|
58
|
+
return bindings;
|
|
59
|
+
}
|
|
60
|
+
/** Pure mapping from a vite/vinext build (dist/server + dist/client + wrangler.json) to `praxis.application.publish` input. No fs, no network. */
|
|
61
|
+
export function publishInputFromBuild(build, name) {
|
|
62
|
+
const wrangler = build.wranglerJson;
|
|
63
|
+
if (!wrangler || typeof wrangler !== 'object' || Array.isArray(wrangler)) {
|
|
64
|
+
throw new PraxisError({ code: 'INVALID_PARAMS', message: 'wranglerJson must be the parsed dist/server/wrangler.json object' });
|
|
65
|
+
}
|
|
66
|
+
const offending = UNSUPPORTED_BINDING_KEYS.filter(key => isPresent(wrangler[key]));
|
|
67
|
+
if (offending.length) {
|
|
68
|
+
throw new PraxisError({ code: 'UNSUPPORTED', message: `wrangler.json declares bindings the platform does not support: ${offending.join(', ')}` });
|
|
69
|
+
}
|
|
70
|
+
const modules = Object.entries(build.serverFiles)
|
|
71
|
+
.filter(([path]) => path.endsWith('.js'))
|
|
72
|
+
.map(([path, content]) => ({ name: path, content, content_type: 'application/javascript+module' }));
|
|
73
|
+
if (typeof wrangler.main !== 'string')
|
|
74
|
+
throw new PraxisError({ code: 'INVALID_PARAMS', message: 'wrangler.json has no main entry' });
|
|
75
|
+
if (!modules.some(module => module.name === wrangler.main)) {
|
|
76
|
+
throw new PraxisError({ code: 'INVALID_PARAMS', message: `wrangler.json main ${wrangler.main} is not a .js file under dist/server` });
|
|
77
|
+
}
|
|
78
|
+
const ignored = new TextDecoder().decode(build.clientFiles['.assetsignore'] ?? new Uint8Array()).split(/\r?\n/)
|
|
79
|
+
.map(ignoreMatcher).filter((matcher) => matcher !== null);
|
|
80
|
+
const files = {};
|
|
81
|
+
for (const [path, content] of Object.entries(build.clientFiles)) {
|
|
82
|
+
if (path === '.assetsignore' || ignored.some(matches => matches(path)))
|
|
83
|
+
continue;
|
|
84
|
+
files[`/${path}`] = content;
|
|
85
|
+
}
|
|
86
|
+
const { binding: _binding, directory: _directory, ...assetsConfig } = (wrangler.assets ?? {});
|
|
87
|
+
const bindings = bindingsFrom(wrangler);
|
|
88
|
+
return {
|
|
89
|
+
name,
|
|
90
|
+
files,
|
|
91
|
+
modules,
|
|
92
|
+
main_module: wrangler.main,
|
|
93
|
+
...(typeof wrangler.compatibility_date === 'string' ? { compatibility_date: wrangler.compatibility_date } : {}),
|
|
94
|
+
...(Array.isArray(wrangler.compatibility_flags) ? { compatibility_flags: wrangler.compatibility_flags } : {}),
|
|
95
|
+
...(bindings.length ? { bindings } : {}),
|
|
96
|
+
...(Object.keys(assetsConfig).length ? { assets_config: assetsConfig } : {}),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
@@ -12,6 +12,14 @@ export interface PublishInput {
|
|
|
12
12
|
content: string;
|
|
13
13
|
content_type?: string;
|
|
14
14
|
};
|
|
15
|
+
/** Multi-module Worker (e.g. a vite/vinext build). Names pass through unchanged; relative paths with / are legal. Mutually exclusive with main. */
|
|
16
|
+
modules?: {
|
|
17
|
+
name: string;
|
|
18
|
+
content: string | Uint8Array;
|
|
19
|
+
content_type?: string;
|
|
20
|
+
}[];
|
|
21
|
+
/** Entry module name; defaults to the first module and must name one of modules. */
|
|
22
|
+
main_module?: string;
|
|
15
23
|
/** 运行时兼容日期,默认当天 UTC(YYYY-MM-DD)。 */
|
|
16
24
|
compatibility_date?: string;
|
|
17
25
|
/** 运行时兼容标志,原样传递;平台固定附加 global_fetch_strictly_public。 */
|
|
@@ -21,11 +21,30 @@ export async function publish(client, input) {
|
|
|
21
21
|
const timeout = input.timeout_ms ?? 120_000;
|
|
22
22
|
if (!Number.isFinite(timeout) || timeout < 0)
|
|
23
23
|
throw new RangeError('timeout_ms must be non-negative and finite');
|
|
24
|
-
const
|
|
25
|
-
'text/plain', 'application/wasm', 'application/octet-stream', 'application/x-python']
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
const moduleTypes = ['application/javascript+module', 'text/javascript', 'application/javascript', 'application/json',
|
|
25
|
+
'text/plain', 'application/wasm', 'application/octet-stream', 'application/x-python'];
|
|
26
|
+
const moduleType = (type) => {
|
|
27
|
+
const found = moduleTypes.find(candidate => candidate === (type ?? 'application/javascript+module'));
|
|
28
|
+
if (!found)
|
|
29
|
+
throw new PraxisError({ code: 'INVALID_PARAMS', message: `Unsupported module content_type: ${type}` });
|
|
30
|
+
return found;
|
|
31
|
+
};
|
|
32
|
+
if (input.main && input.modules)
|
|
33
|
+
throw new PraxisError({ code: 'INVALID_PARAMS', message: 'Pass either main or modules, not both' });
|
|
34
|
+
if (input.main_module !== undefined && !input.modules)
|
|
35
|
+
throw new PraxisError({ code: 'INVALID_PARAMS', message: 'main_module requires modules; with main the entry is main.name' });
|
|
36
|
+
if (input.modules && input.modules.length === 0)
|
|
37
|
+
throw new PraxisError({ code: 'INVALID_PARAMS', message: 'modules must not be empty' });
|
|
38
|
+
const entryModules = input.main
|
|
39
|
+
? [{ name: input.main.name, content_type: moduleType(input.main.content_type), content_base64: base64(new TextEncoder().encode(input.main.content)) }]
|
|
40
|
+
: input.modules?.map(module => ({ name: module.name, content_type: moduleType(module.content_type),
|
|
41
|
+
content_base64: base64(typeof module.content === 'string' ? new TextEncoder().encode(module.content) : module.content) }));
|
|
42
|
+
if (new Set(entryModules?.map(module => module.name)).size !== (entryModules?.length ?? 0))
|
|
43
|
+
throw new PraxisError({ code: 'INVALID_PARAMS', message: 'Duplicate module name' });
|
|
44
|
+
const mainModule = input.main ? input.main.name : input.modules ? (input.main_module ?? input.modules[0].name) : undefined;
|
|
45
|
+
if (input.modules && !input.modules.some(module => module.name === mainModule)) {
|
|
46
|
+
throw new PraxisError({ code: 'INVALID_PARAMS', message: `main_module ${mainModule} is not among modules` });
|
|
47
|
+
}
|
|
29
48
|
const files = Object.entries(input.files);
|
|
30
49
|
if (files.length > 100_000)
|
|
31
50
|
throw new PraxisError({ code: 'LIMIT_EXCEEDED', message: 'At most 100000 asset paths can be published' });
|
|
@@ -80,7 +99,7 @@ export async function publish(client, input) {
|
|
|
80
99
|
const removed = Object.keys(previous).filter(key => !Object.hasOwn(manifest, key));
|
|
81
100
|
const digest = new Uint8Array(await crypto.subtle.digest('SHA-256', new TextEncoder().encode(JSON.stringify(manifest))));
|
|
82
101
|
const manifestHash = Array.from(digest, byte => byte.toString(16).padStart(2, '0')).join('');
|
|
83
|
-
const staticOnly = !['main', 'bindings', 'compatibility_date', 'compatibility_flags', 'assets_config'].some(key => Object.hasOwn(input, key));
|
|
102
|
+
const staticOnly = !['main', 'modules', 'main_module', 'bindings', 'compatibility_date', 'compatibility_flags', 'assets_config'].some(key => Object.hasOwn(input, key));
|
|
84
103
|
const unchanged = staticOnly && !!currentVersion && manifestHash === currentVersion.praxis.assets_manifest?.manifest_hash;
|
|
85
104
|
const hashes = new Set(Object.values(manifest).map(entry => entry.hash));
|
|
86
105
|
const currentResult = { url: worker.subdomain.url, worker_id: worker.id, version_id: currentVersion?.id ?? null,
|
|
@@ -127,9 +146,7 @@ export async function publish(client, input) {
|
|
|
127
146
|
assets: versionAssets,
|
|
128
147
|
...(input.compatibility_flags ? { compatibility_flags: input.compatibility_flags } : {}),
|
|
129
148
|
...(input.bindings ? { bindings: input.bindings } : {}),
|
|
130
|
-
...(
|
|
131
|
-
content_type: contentType,
|
|
132
|
-
content_base64: base64(new TextEncoder().encode(input.main.content)) }] } : {}),
|
|
149
|
+
...(entryModules ? { main_module: mainModule, modules: entryModules } : {}),
|
|
133
150
|
} });
|
|
134
151
|
let deployment = result.deployment;
|
|
135
152
|
if (!deployment)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Praxis } from '../core/client.js';
|
|
2
2
|
import type { OwnFileOpenAiFile } from '../generated/types.gen.js';
|
|
3
3
|
export interface UploadFileOptions {
|
|
4
|
-
/** user_data for conversation attachments
|
|
5
|
-
purpose: 'user_data' | '
|
|
4
|
+
/** user_data for conversation attachments and documents; vision for PNG/JPEG/GIF/WebP. */
|
|
5
|
+
purpose: 'user_data' | 'vision';
|
|
6
6
|
/** Defaults to File.name, or upload for a Blob. */
|
|
7
7
|
filename?: string;
|
|
8
8
|
/** Fixed part size in bytes, 5 MiB–64 MB; defaults to 50 MiB. */
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ export { parseSSE } from './core/sse.js';
|
|
|
7
7
|
export type { SSEEvent, SSEOptions } from './core/sse.js';
|
|
8
8
|
export { publish } from './helpers/application-publish.js';
|
|
9
9
|
export type { PublishInput, PublishResult, AssetsConfig } from './helpers/application-publish.js';
|
|
10
|
+
export { publishInputFromBuild } from './helpers/application-build.js';
|
|
11
|
+
export type { BuildOutput } from './helpers/application-build.js';
|
|
10
12
|
export { count } from './helpers/database-count.js';
|
|
11
13
|
export type { CountInput, CountResult } from './helpers/database-count.js';
|
|
12
14
|
export { uploadFile } from './helpers/file-upload.js';
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ export { PraxisError, PraxisConnectionError, PraxisTimeoutError } from "./core/e
|
|
|
3
3
|
export { Page } from "./core/pagination.js";
|
|
4
4
|
export { parseSSE } from "./core/sse.js";
|
|
5
5
|
export { publish } from "./helpers/application-publish.js";
|
|
6
|
+
export { publishInputFromBuild } from "./helpers/application-build.js";
|
|
6
7
|
export { count } from "./helpers/database-count.js";
|
|
7
8
|
export { uploadFile } from "./helpers/file-upload.js";
|
|
8
9
|
export { connectBrowser } from "./helpers/browser-connect.js";
|