openworkgraph 0.2.12

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 (178) hide show
  1. package/README.md +64 -0
  2. package/dist/api-image-agent.d.ts +32 -0
  3. package/dist/api-image-agent.js +132 -0
  4. package/dist/api-image-output.d.ts +8 -0
  5. package/dist/api-image-output.js +41 -0
  6. package/dist/api.d.ts +35 -0
  7. package/dist/api.js +153 -0
  8. package/dist/auth.d.ts +58 -0
  9. package/dist/auth.js +273 -0
  10. package/dist/backend/adapter.d.ts +35 -0
  11. package/dist/backend/adapter.js +439 -0
  12. package/dist/backend/capabilities.d.ts +23 -0
  13. package/dist/backend/capabilities.js +75 -0
  14. package/dist/backend/diagnostics.d.ts +9 -0
  15. package/dist/backend/diagnostics.js +80 -0
  16. package/dist/backend/index.d.ts +6 -0
  17. package/dist/backend/index.js +7 -0
  18. package/dist/backend/models.d.ts +15 -0
  19. package/dist/backend/models.js +43 -0
  20. package/dist/backend/paths.d.ts +6 -0
  21. package/dist/backend/paths.js +69 -0
  22. package/dist/backend/stdio.d.ts +66 -0
  23. package/dist/backend/stdio.js +172 -0
  24. package/dist/backend/types.d.ts +90 -0
  25. package/dist/backend/types.js +11 -0
  26. package/dist/backup-api.d.ts +10 -0
  27. package/dist/backup-api.js +40 -0
  28. package/dist/blob-store.d.ts +40 -0
  29. package/dist/blob-store.js +218 -0
  30. package/dist/cli-help.d.ts +1 -0
  31. package/dist/cli-help.js +63 -0
  32. package/dist/cli-output.d.ts +4 -0
  33. package/dist/cli-output.js +130 -0
  34. package/dist/cli.d.ts +2 -0
  35. package/dist/cli.js +284 -0
  36. package/dist/client-pairing.d.ts +8 -0
  37. package/dist/client-pairing.js +30 -0
  38. package/dist/directories.d.ts +14 -0
  39. package/dist/directories.js +34 -0
  40. package/dist/errors.d.ts +12 -0
  41. package/dist/errors.js +7 -0
  42. package/dist/events.d.ts +22 -0
  43. package/dist/events.js +155 -0
  44. package/dist/execution-chains.d.ts +24 -0
  45. package/dist/execution-chains.js +231 -0
  46. package/dist/execution-settings.d.ts +10 -0
  47. package/dist/execution-settings.js +38 -0
  48. package/dist/graph-document-history.d.ts +43 -0
  49. package/dist/graph-document-history.js +275 -0
  50. package/dist/graph-files.d.ts +14 -0
  51. package/dist/graph-files.js +59 -0
  52. package/dist/graph-transfer.d.ts +53 -0
  53. package/dist/graph-transfer.js +501 -0
  54. package/dist/graphs.d.ts +68 -0
  55. package/dist/graphs.js +771 -0
  56. package/dist/history.d.ts +20 -0
  57. package/dist/history.js +61 -0
  58. package/dist/http.d.ts +2 -0
  59. package/dist/http.js +42 -0
  60. package/dist/image-credentials.d.ts +11 -0
  61. package/dist/image-credentials.js +130 -0
  62. package/dist/image-providers.d.ts +51 -0
  63. package/dist/image-providers.js +271 -0
  64. package/dist/input-materialization.d.ts +17 -0
  65. package/dist/input-materialization.js +95 -0
  66. package/dist/inputs.d.ts +74 -0
  67. package/dist/inputs.js +301 -0
  68. package/dist/local-control.d.ts +13 -0
  69. package/dist/local-control.js +37 -0
  70. package/dist/network.d.ts +11 -0
  71. package/dist/network.js +48 -0
  72. package/dist/openai-image-driver.d.ts +42 -0
  73. package/dist/openai-image-driver.js +368 -0
  74. package/dist/operations/backups.d.ts +40 -0
  75. package/dist/operations/backups.js +391 -0
  76. package/dist/operations/capacity.d.ts +7 -0
  77. package/dist/operations/capacity.js +35 -0
  78. package/dist/operations/cli-context.d.ts +7 -0
  79. package/dist/operations/cli-context.js +58 -0
  80. package/dist/operations/daemon.d.ts +36 -0
  81. package/dist/operations/daemon.js +159 -0
  82. package/dist/operations/files.d.ts +12 -0
  83. package/dist/operations/files.js +84 -0
  84. package/dist/operations/lifecycle.d.ts +28 -0
  85. package/dist/operations/lifecycle.js +155 -0
  86. package/dist/operations/local-admin.d.ts +6 -0
  87. package/dist/operations/local-admin.js +38 -0
  88. package/dist/operations/logs.d.ts +16 -0
  89. package/dist/operations/logs.js +37 -0
  90. package/dist/operations/plugins.d.ts +10 -0
  91. package/dist/operations/plugins.js +11 -0
  92. package/dist/operations/snapshot-worker.d.ts +1 -0
  93. package/dist/operations/snapshot-worker.js +18 -0
  94. package/dist/operations/snapshot.d.ts +1 -0
  95. package/dist/operations/snapshot.js +14 -0
  96. package/dist/operations/update.d.ts +26 -0
  97. package/dist/operations/update.js +216 -0
  98. package/dist/persistence/asset-business-schema.d.ts +2 -0
  99. package/dist/persistence/asset-business-schema.js +36 -0
  100. package/dist/persistence/database.d.ts +7 -0
  101. package/dist/persistence/database.js +91 -0
  102. package/dist/persistence/plugin-schema.d.ts +9 -0
  103. package/dist/persistence/plugin-schema.js +38 -0
  104. package/dist/persistence/repositories.d.ts +20 -0
  105. package/dist/persistence/repositories.js +106 -0
  106. package/dist/persistence/resource-schema.d.ts +2 -0
  107. package/dist/persistence/resource-schema.js +44 -0
  108. package/dist/persistence/schema.d.ts +6 -0
  109. package/dist/persistence/schema.js +236 -0
  110. package/dist/persistence/workflow-schema.d.ts +2 -0
  111. package/dist/persistence/workflow-schema.js +19 -0
  112. package/dist/plugin-api.d.ts +10 -0
  113. package/dist/plugin-api.js +40 -0
  114. package/dist/plugin-management.d.ts +36 -0
  115. package/dist/plugin-management.js +112 -0
  116. package/dist/plugins.d.ts +55 -0
  117. package/dist/plugins.js +239 -0
  118. package/dist/project-discovery.d.ts +3 -0
  119. package/dist/project-discovery.js +57 -0
  120. package/dist/project-files-api.d.ts +16 -0
  121. package/dist/project-files-api.js +243 -0
  122. package/dist/project-files.d.ts +97 -0
  123. package/dist/project-files.js +557 -0
  124. package/dist/project-lock.d.ts +4 -0
  125. package/dist/project-lock.js +35 -0
  126. package/dist/project-probe-worker.d.ts +1 -0
  127. package/dist/project-probe-worker.js +17 -0
  128. package/dist/project-probe.d.ts +22 -0
  129. package/dist/project-probe.js +67 -0
  130. package/dist/projects.d.ts +29 -0
  131. package/dist/projects.js +219 -0
  132. package/dist/publication.d.ts +31 -0
  133. package/dist/publication.js +642 -0
  134. package/dist/resource-api.d.ts +15 -0
  135. package/dist/resource-api.js +256 -0
  136. package/dist/resources-orphans.d.ts +41 -0
  137. package/dist/resources-orphans.js +235 -0
  138. package/dist/resources.d.ts +246 -0
  139. package/dist/resources.js +714 -0
  140. package/dist/run-api.d.ts +10 -0
  141. package/dist/run-api.js +308 -0
  142. package/dist/run-context.d.ts +54 -0
  143. package/dist/run-context.js +137 -0
  144. package/dist/runs.d.ts +82 -0
  145. package/dist/runs.js +506 -0
  146. package/dist/runtime-backend.d.ts +24 -0
  147. package/dist/runtime-backend.js +214 -0
  148. package/dist/runtime.d.ts +97 -0
  149. package/dist/runtime.js +553 -0
  150. package/dist/scheduler.d.ts +85 -0
  151. package/dist/scheduler.js +344 -0
  152. package/dist/service.d.ts +29 -0
  153. package/dist/service.js +515 -0
  154. package/dist/skills-api.d.ts +18 -0
  155. package/dist/skills-api.js +120 -0
  156. package/dist/storage-api.d.ts +21 -0
  157. package/dist/storage-api.js +92 -0
  158. package/dist/transfer-api.d.ts +10 -0
  159. package/dist/transfer-api.js +60 -0
  160. package/dist/vendor/protocol/contracts.typecheck.d.ts +1 -0
  161. package/dist/vendor/protocol/contracts.typecheck.js +35 -0
  162. package/dist/vendor/protocol/execution-chain.d.ts +6 -0
  163. package/dist/vendor/protocol/execution-chain.js +26 -0
  164. package/dist/vendor/protocol/graph-binary.d.ts +15 -0
  165. package/dist/vendor/protocol/graph-binary.js +121 -0
  166. package/dist/vendor/protocol/graph-title.d.ts +2 -0
  167. package/dist/vendor/protocol/graph-title.js +23 -0
  168. package/dist/vendor/protocol/index.d.ts +617 -0
  169. package/dist/vendor/protocol/index.js +20 -0
  170. package/dist/vendor/protocol/pairing.d.ts +29 -0
  171. package/dist/vendor/protocol/pairing.js +71 -0
  172. package/dist/vendor/protocol/preview.d.ts +2 -0
  173. package/dist/vendor/protocol/preview.js +9 -0
  174. package/dist/vendor/protocol/resource-mime.d.ts +2 -0
  175. package/dist/vendor/protocol/resource-mime.js +35 -0
  176. package/dist/video-thumbnail.d.ts +2 -0
  177. package/dist/video-thumbnail.js +34 -0
  178. package/package.json +9 -0
@@ -0,0 +1,71 @@
1
+ /** Versioned, bounded pairing envelopes. These are encodings, not encryption.
2
+ * Algorithms are fixed per version; never accept an algorithm from the caller. */
3
+ export const CLIENT_CODE_PREFIX = 'wgpc1_';
4
+ export const PAIR_AUTHORIZATION_PREFIX = 'wgpa1_';
5
+ /** Human-entered codes accept optional whitespace or a separator between groups. */
6
+ export function normalizeShortPairingCode(value) {
7
+ const compact = value.trim().replace(/[\s-]/g, '');
8
+ return /^\d{8}$/.test(compact) ? compact : undefined;
9
+ }
10
+ /** Display/copy exactly eight digits; separators are accepted only on input. */
11
+ export function formatShortPairingCode(value) {
12
+ const code = normalizeShortPairingCode(value);
13
+ if (!code)
14
+ throw new Error('短码必须为 8 位数字');
15
+ return code;
16
+ }
17
+ export function encodeBase64Url(bytes) {
18
+ return btoa(String.fromCharCode(...bytes)).replaceAll('+', '-').replaceAll('/', '_').replace(/=+$/, '');
19
+ }
20
+ export function decodeBase64Url(value, maxBytes) {
21
+ if (typeof value !== 'string' || !value || value.length > Math.ceil(maxBytes * 4 / 3) || !/^[A-Za-z0-9_-]+$/.test(value))
22
+ throw new Error('无效的配对编码');
23
+ const bytes = Uint8Array.from(atob(value.replaceAll('-', '+').replaceAll('_', '/')), c => c.charCodeAt(0));
24
+ if (bytes.length > maxBytes || encodeBase64Url(bytes) !== value)
25
+ throw new Error('无效的配对编码');
26
+ return bytes;
27
+ }
28
+ function encode(prefix, value) { return prefix + encodeBase64Url(new TextEncoder().encode(JSON.stringify(value))); }
29
+ function decode(prefix, code) {
30
+ if (typeof code !== 'string' || !code.startsWith(prefix))
31
+ throw new Error('配对码版本不支持');
32
+ const value = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(decodeBase64Url(code.slice(prefix.length), 2048)));
33
+ if (!value || typeof value !== 'object' || Array.isArray(value))
34
+ throw new Error('无效的配对码');
35
+ return value;
36
+ }
37
+ export function encodeClientCode(value) {
38
+ return encode(CLIENT_CODE_PREFIX, { version: value.version, origin: value.origin, publicKey: value.publicKey, nonce: value.nonce });
39
+ }
40
+ export function parseClientCode(code) {
41
+ const value = decode(CLIENT_CODE_PREFIX, code);
42
+ if (value.version !== 1 || typeof value.origin !== 'string' || value.origin.length > 512 || typeof value.publicKey !== 'string' || typeof value.nonce !== 'string')
43
+ throw new Error('无效的客户端码');
44
+ const origin = new URL(value.origin);
45
+ if (!['http:', 'https:'].includes(origin.protocol) || origin.origin !== value.origin || origin.hostname.includes('*'))
46
+ throw new Error('客户端码来源无效');
47
+ const key = decodeBase64Url(value.publicKey, 65);
48
+ if (key.length !== 65 || key[0] !== 4 || decodeBase64Url(value.nonce, 32).length !== 32)
49
+ throw new Error('客户端公钥或挑战无效');
50
+ const result = { version: 1, origin: value.origin, publicKey: value.publicKey, nonce: value.nonce };
51
+ if (encodeClientCode(result) !== code)
52
+ throw new Error('客户端码字段或格式无效');
53
+ return result;
54
+ }
55
+ export function encodePairAuthorization(value) {
56
+ return encode(PAIR_AUTHORIZATION_PREFIX, { version: value.version, serviceId: value.serviceId, code: value.code, clientHash: value.clientHash, expiresAt: value.expiresAt });
57
+ }
58
+ export function parsePairAuthorization(code) {
59
+ const value = decode(PAIR_AUTHORIZATION_PREFIX, code);
60
+ if (value.version !== 1 || typeof value.serviceId !== 'string' || !/^[A-Za-z0-9-]{1,100}$/.test(value.serviceId) || typeof value.code !== 'string' || !/^[A-F0-9]{32}$/.test(value.code) || typeof value.clientHash !== 'string' || !/^[a-f0-9]{64}$/.test(value.clientHash) || typeof value.expiresAt !== 'number' || !Number.isSafeInteger(value.expiresAt) || value.expiresAt <= 0)
61
+ throw new Error('无效的配对授权码');
62
+ const result = value;
63
+ if (encodePairAuthorization(result) !== code)
64
+ throw new Error('授权码字段或格式无效');
65
+ return result;
66
+ }
67
+ /** UTF-8 JSON array gives unambiguous domain-separated signing bytes. */
68
+ export function pairingProofMessage(serviceId, origin, authorization, clientCode, browserName) {
69
+ return new TextEncoder().encode(JSON.stringify(['openworkgraph:pair:v1', serviceId, origin, authorization, clientCode, browserName.trim()]));
70
+ }
71
+ //# sourceMappingURL=pairing.js.map
@@ -0,0 +1,2 @@
1
+ /** Shared topology rule for runtime, portable graphs and the browser. */
2
+ export declare function previewEdgeError(sourceType: string, targetType: string, incomingCount: number): string | undefined;
@@ -0,0 +1,9 @@
1
+ /** Shared topology rule for runtime, portable graphs and the browser. */
2
+ export function previewEdgeError(sourceType, targetType, incomingCount) {
3
+ if (sourceType === 'preview' && targetType === 'preview')
4
+ return '预览节点之间不能连接。';
5
+ if (targetType === 'preview' && incomingCount >= 1)
6
+ return '预览节点只能有一个前驱。';
7
+ return undefined;
8
+ }
9
+ //# sourceMappingURL=preview.js.map
@@ -0,0 +1,2 @@
1
+ /** Byte-based MIME detection shared by browser graph bundles and service storage. */
2
+ export declare function sniffResourceMime(bytes: Uint8Array): string;
@@ -0,0 +1,35 @@
1
+ /** Byte-based MIME detection shared by browser graph bundles and service storage. */
2
+ export function sniffResourceMime(bytes) {
3
+ const text = (start, end) => new TextDecoder().decode(bytes.subarray(start, end));
4
+ const starts = (signature) => signature.every((value, i) => bytes[i] === value);
5
+ if (starts([137, 80, 78, 71, 13, 10, 26, 10]))
6
+ return 'image/png';
7
+ if (starts([255, 216, 255]))
8
+ return 'image/jpeg';
9
+ if (/^GIF8[79]a/.test(text(0, 6)))
10
+ return 'image/gif';
11
+ if (text(0, 4) === 'RIFF' && text(8, 12) === 'WEBP')
12
+ return 'image/webp';
13
+ if (text(0, 5) === '%PDF-')
14
+ return 'application/pdf';
15
+ if (text(4, 8) === 'ftyp')
16
+ return 'video/mp4';
17
+ if (starts([26, 69, 223, 163]))
18
+ return 'video/webm';
19
+ try {
20
+ const content = new TextDecoder('utf-8', { fatal: true }).decode(bytes);
21
+ let printable = true;
22
+ for (const char of content) {
23
+ const n = char.charCodeAt(0);
24
+ if (n < 32 && n !== 9 && n !== 10 && n !== 13) {
25
+ printable = false;
26
+ break;
27
+ }
28
+ }
29
+ if (printable)
30
+ return 'text/plain';
31
+ }
32
+ catch { /* Binary data has no text representation. */ }
33
+ return 'application/octet-stream';
34
+ }
35
+ //# sourceMappingURL=resource-mime.js.map
@@ -0,0 +1,2 @@
1
+ /** Bound decoder work across all workspaces; only small frames reach Node. */
2
+ export declare function videoThumbnail(path: string, size: number): Promise<Buffer>;
@@ -0,0 +1,34 @@
1
+ import { execFile } from 'node:child_process';
2
+ import { promisify } from 'node:util';
3
+ import sharp from 'sharp';
4
+ import { ServiceError } from './errors.js';
5
+ const execute = promisify(execFile);
6
+ let active = 0;
7
+ const waiting = [];
8
+ /** Bound decoder work across all workspaces; only small frames reach Node. */
9
+ export async function videoThumbnail(path, size) {
10
+ if (active >= 2)
11
+ await new Promise(resolve => waiting.push(resolve));
12
+ else
13
+ active++;
14
+ try {
15
+ const { stdout } = await execute('ffmpeg', [
16
+ '-v', 'error', '-nostdin', '-protocol_whitelist', 'file,pipe', '-i', path,
17
+ '-map', '0:v:0', '-frames:v', '1', '-vf',
18
+ 'scale=' + size + ':' + size + ':force_original_aspect_ratio=decrease',
19
+ '-threads', '1', '-f', 'image2pipe', '-vcodec', 'png', 'pipe:1',
20
+ ], { encoding: 'buffer', timeout: 10_000, maxBuffer: 2 * 1024 * 1024, windowsHide: true });
21
+ return await sharp(stdout).webp({ quality: 75 }).toBuffer();
22
+ }
23
+ catch (cause) {
24
+ throw new ServiceError('INVALID_REQUEST', '无法生成视频封面,请确认工作空间可使用 FFmpeg。', { cause });
25
+ }
26
+ finally {
27
+ const next = waiting.shift();
28
+ if (next)
29
+ next();
30
+ else
31
+ active--;
32
+ }
33
+ }
34
+ //# sourceMappingURL=video-thumbnail.js.map
package/package.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "openworkgraph", "version": "0.2.12", "type": "module",
3
+ "publishConfig": { "access": "public" },
4
+ "engines": { "node": ">=24.0.0" },
5
+ "bin": { "openworkgraph": "dist/cli.js" },
6
+ "files": ["dist/**/*.js", "dist/**/*.d.ts", "README.md"],
7
+ "scripts": { "prebuild": "node ../scripts/check-versions.mjs --quiet", "build": "tsc -p tsconfig.json && node scripts/vendor-protocol.mjs", "prepack": "node scripts/prepare-pack.mjs", "typecheck": "tsc -p tsconfig.json --noEmit", "start": "node dist/cli.js", "test": "node --test test/*.test.mjs" },
8
+ "dependencies": { "sharp": "^0.35.4" }
9
+ }