@aiworker/sdk 1.24.0

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 (77) hide show
  1. package/API.md +575 -0
  2. package/DOCUMENTATION.md +120 -0
  3. package/GUEST_SERVICES.md +166 -0
  4. package/LICENSE +21 -0
  5. package/README.md +249 -0
  6. package/dist/api-version.d.ts +6 -0
  7. package/dist/api-version.js +5 -0
  8. package/dist/contract.d.ts +504 -0
  9. package/dist/contract.js +256 -0
  10. package/dist/host-version.d.ts +16 -0
  11. package/dist/host-version.js +50 -0
  12. package/dist/host.d.ts +107 -0
  13. package/dist/host.js +639 -0
  14. package/dist/index.d.ts +13 -0
  15. package/dist/index.js +8 -0
  16. package/dist/manifest.d.ts +303 -0
  17. package/dist/manifest.js +222 -0
  18. package/dist/parse.d.ts +293 -0
  19. package/dist/parse.js +398 -0
  20. package/dist/protocol.d.ts +1148 -0
  21. package/dist/protocol.js +473 -0
  22. package/dist/schemas.d.ts +4 -0
  23. package/dist/schemas.js +6 -0
  24. package/dist/scrollbar-style.d.ts +2 -0
  25. package/dist/scrollbar-style.js +32 -0
  26. package/dist/ui/badge.d.ts +10 -0
  27. package/dist/ui/badge.js +26 -0
  28. package/dist/ui/banner.d.ts +13 -0
  29. package/dist/ui/banner.js +48 -0
  30. package/dist/ui/button.d.ts +14 -0
  31. package/dist/ui/button.js +49 -0
  32. package/dist/ui/checkbox.d.ts +12 -0
  33. package/dist/ui/checkbox.js +45 -0
  34. package/dist/ui/dom.d.ts +15 -0
  35. package/dist/ui/dom.js +60 -0
  36. package/dist/ui/empty.d.ts +11 -0
  37. package/dist/ui/empty.js +44 -0
  38. package/dist/ui/field.d.ts +18 -0
  39. package/dist/ui/field.js +49 -0
  40. package/dist/ui/icons.d.ts +10 -0
  41. package/dist/ui/icons.js +23 -0
  42. package/dist/ui/index.d.ts +35 -0
  43. package/dist/ui/index.js +17 -0
  44. package/dist/ui/list.d.ts +26 -0
  45. package/dist/ui/list.js +90 -0
  46. package/dist/ui/menu.d.ts +20 -0
  47. package/dist/ui/menu.js +115 -0
  48. package/dist/ui/navigation.d.ts +18 -0
  49. package/dist/ui/navigation.js +38 -0
  50. package/dist/ui/option.d.ts +16 -0
  51. package/dist/ui/option.js +35 -0
  52. package/dist/ui/popup.d.ts +5 -0
  53. package/dist/ui/popup.js +43 -0
  54. package/dist/ui/progress.d.ts +11 -0
  55. package/dist/ui/progress.js +44 -0
  56. package/dist/ui/search.d.ts +11 -0
  57. package/dist/ui/search.js +62 -0
  58. package/dist/ui/select.d.ts +22 -0
  59. package/dist/ui/select.js +168 -0
  60. package/dist/ui/separator.d.ts +6 -0
  61. package/dist/ui/separator.js +26 -0
  62. package/dist/ui/spinner.d.ts +8 -0
  63. package/dist/ui/spinner.js +29 -0
  64. package/dist/ui/style.d.ts +1 -0
  65. package/dist/ui/style.js +202 -0
  66. package/dist/ui/tabs.d.ts +15 -0
  67. package/dist/ui/tabs.js +61 -0
  68. package/dist/ui/text.d.ts +23 -0
  69. package/dist/ui/text.js +89 -0
  70. package/dist/ui/theme.d.ts +22 -0
  71. package/dist/ui/theme.js +79 -0
  72. package/dist/workspace-schemas.d.ts +136 -0
  73. package/dist/workspace-schemas.js +44 -0
  74. package/dist/workspace.d.ts +109 -0
  75. package/dist/workspace.js +4 -0
  76. package/package.json +55 -0
  77. package/scripts/bundle-guest.ts +44 -0
@@ -0,0 +1,44 @@
1
+ import { z } from 'zod';
2
+ import { GUEST_STORAGE_KEY_MAX, GUEST_STORAGE_VALUE_BYTES, GUEST_STORAGE_KEYS_MAX } from "./workspace.js";
3
+ const identity = z.string().trim().min(1).max(1024);
4
+ const state = z.enum(['loading', 'ready', 'error']);
5
+ const worktree = z.object({
6
+ directory: identity, name: z.string(), branch: z.string(),
7
+ status: z.enum(['ready', 'pending', 'invalid', 'missing']),
8
+ });
9
+ export const guestWorkspaceQuerySchema = z.discriminatedUnion('kind', [
10
+ z.object({ kind: z.literal('projects') }).strict(),
11
+ z.object({ kind: z.literal('worktrees'), projectId: identity }).strict(),
12
+ z.object({ kind: z.literal('sessions'), projectId: identity }).strict(),
13
+ ]);
14
+ export const guestWorkspaceSnapshotSchema = z.discriminatedUnion('kind', [
15
+ z.object({ kind: z.literal('projects'), state, projects: z.array(z.object({ id: identity, name: z.string(), directory: identity })) }),
16
+ z.object({ kind: z.literal('worktrees'), projectId: identity, state, worktrees: z.array(worktree) }),
17
+ z.object({ kind: z.literal('sessions'), projectId: identity, state,
18
+ coverage: z.array(z.object({ directory: identity, state })),
19
+ sessions: z.array(z.object({
20
+ id: identity, title: z.string(), projectId: identity, directory: identity, parentId: identity.nullable(),
21
+ createdAt: z.number(), updatedAt: z.number(), archivedAt: z.number().nullable(), worktree: worktree.nullable(),
22
+ activity: z.enum(['unknown', 'idle', 'running', 'retrying', 'waiting-permission', 'waiting-question']),
23
+ outcome: z.enum(['completed', 'failed']).nullable(), items: z.array(z.object({ id: identity, data: z.json().optional() })),
24
+ })),
25
+ }),
26
+ ]);
27
+ export const guestSessionWorktreeSchema = z.union([
28
+ z.boolean(),
29
+ z.object({ kind: z.literal('existing'), directory: identity }).strict(),
30
+ z.object({ kind: z.literal('new'), name: z.string().trim().min(1).max(200).optional(), baseBranch: z.string().trim().min(1).max(200).optional() }).strict(),
31
+ ]);
32
+ const storageKey = z.string().min(1).max(GUEST_STORAGE_KEY_MAX);
33
+ export const guestStorageRequestSchema = z.discriminatedUnion('op', [
34
+ z.object({ op: z.literal('get'), key: storageKey }).strict(),
35
+ z.object({ op: z.literal('delete'), key: storageKey }).strict(),
36
+ z.object({ op: z.literal('set'), key: storageKey, value: z.json().refine((value) => new TextEncoder().encode(JSON.stringify(value)).length <= GUEST_STORAGE_VALUE_BYTES) }).strict(),
37
+ z.object({ op: z.literal('keys') }).strict(),
38
+ ]);
39
+ export const guestStorageResultSchema = z.union([
40
+ z.object({ storage: z.literal(true), op: z.literal('get'), found: z.literal(false) }),
41
+ z.object({ storage: z.literal(true), op: z.literal('get'), found: z.literal(true), value: z.json() }),
42
+ z.object({ storage: z.literal(true), op: z.enum(['set', 'delete']) }),
43
+ z.object({ storage: z.literal(true), op: z.literal('keys'), keys: z.array(storageKey).max(GUEST_STORAGE_KEYS_MAX) }),
44
+ ]);
@@ -0,0 +1,109 @@
1
+ import type { JsonValue } from './contract.ts';
2
+ export type GuestLoadState = 'loading' | 'ready' | 'error';
3
+ export type GuestProject = {
4
+ id: string;
5
+ name: string;
6
+ directory: string;
7
+ };
8
+ export type GuestWorktree = {
9
+ directory: string;
10
+ name: string;
11
+ branch: string;
12
+ status: 'ready' | 'pending' | 'invalid' | 'missing';
13
+ };
14
+ export type GuestSessionActivity = 'unknown' | 'idle' | 'running' | 'retrying' | 'waiting-permission' | 'waiting-question';
15
+ export type GuestSessionRecord = {
16
+ id: string;
17
+ title: string;
18
+ projectId: string;
19
+ directory: string;
20
+ parentId: string | null;
21
+ createdAt: number;
22
+ updatedAt: number;
23
+ archivedAt: number | null;
24
+ worktree: GuestWorktree | null;
25
+ activity: GuestSessionActivity;
26
+ /** Observed turn outcome, never a task status. Unknown history stays null. */
27
+ outcome: 'completed' | 'failed' | null;
28
+ items: {
29
+ id: string;
30
+ data?: JsonValue;
31
+ }[];
32
+ };
33
+ export type GuestDirectoryCoverage = {
34
+ directory: string;
35
+ state: GuestLoadState;
36
+ };
37
+ export type GuestProjectsSnapshot = {
38
+ kind: 'projects';
39
+ state: GuestLoadState;
40
+ projects: GuestProject[];
41
+ };
42
+ export type GuestWorktreesSnapshot = {
43
+ kind: 'worktrees';
44
+ projectId: string;
45
+ state: GuestLoadState;
46
+ worktrees: GuestWorktree[];
47
+ };
48
+ export type GuestSessionsSnapshot = {
49
+ kind: 'sessions';
50
+ projectId: string;
51
+ state: GuestLoadState;
52
+ coverage: GuestDirectoryCoverage[];
53
+ sessions: GuestSessionRecord[];
54
+ };
55
+ export type GuestWorkspaceSnapshot = GuestProjectsSnapshot | GuestWorktreesSnapshot | GuestSessionsSnapshot;
56
+ export type GuestWorkspaceQuery = {
57
+ kind: 'projects';
58
+ } | {
59
+ kind: 'worktrees';
60
+ projectId: string;
61
+ } | {
62
+ kind: 'sessions';
63
+ projectId: string;
64
+ };
65
+ export type GuestWorkspaceSubscription = {
66
+ subscriptionId: string;
67
+ query: GuestWorkspaceQuery;
68
+ };
69
+ export type GuestWorkspaceUpdate = {
70
+ subscriptionId: string;
71
+ snapshot: GuestWorkspaceSnapshot;
72
+ };
73
+ export declare const GUEST_STORAGE_KEY_MAX = 128;
74
+ export declare const GUEST_STORAGE_VALUE_BYTES = 65536;
75
+ export declare const GUEST_STORAGE_TOTAL_BYTES = 2097152;
76
+ export declare const GUEST_STORAGE_KEYS_MAX = 2000;
77
+ export type GuestStorageRequest = {
78
+ op: 'get' | 'delete';
79
+ key: string;
80
+ } | {
81
+ op: 'set';
82
+ key: string;
83
+ value: JsonValue;
84
+ } | {
85
+ op: 'keys';
86
+ };
87
+ export type GuestStorageResult = {
88
+ storage: true;
89
+ } & ({
90
+ op: 'get';
91
+ found: false;
92
+ } | {
93
+ op: 'get';
94
+ found: true;
95
+ value: JsonValue;
96
+ } | {
97
+ op: 'set' | 'delete';
98
+ } | {
99
+ op: 'keys';
100
+ keys: string[];
101
+ });
102
+ export type GuestSessionWorktree = boolean | {
103
+ kind: 'existing';
104
+ directory: string;
105
+ } | {
106
+ kind: 'new';
107
+ name?: string;
108
+ baseBranch?: string;
109
+ };
@@ -0,0 +1,4 @@
1
+ export const GUEST_STORAGE_KEY_MAX = 128;
2
+ export const GUEST_STORAGE_VALUE_BYTES = 65_536;
3
+ export const GUEST_STORAGE_TOTAL_BYTES = 2_097_152;
4
+ export const GUEST_STORAGE_KEYS_MAX = 2_000;
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@aiworker/sdk",
3
+ "version": "1.24.0",
4
+ "description": "Contract for AiWorker guests: manifest parse and iframe host bridge.",
5
+ "private": false,
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://roweb.cn/roweb/aihander.git",
10
+ "directory": "packages/sdk"
11
+ },
12
+ "type": "module",
13
+ "main": "dist/index.js",
14
+ "types": "dist/index.d.ts",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/index.d.ts",
18
+ "default": "./dist/index.js"
19
+ },
20
+ "./ui": {
21
+ "types": "./dist/ui/index.d.ts",
22
+ "default": "./dist/ui/index.js"
23
+ },
24
+ "./schemas": {
25
+ "types": "./dist/schemas.d.ts",
26
+ "default": "./dist/schemas.js"
27
+ }
28
+ },
29
+ "bin": {
30
+ "openchamber-guest-bundle": "./scripts/bundle-guest.ts"
31
+ },
32
+ "publishConfig": {
33
+ "access": "public"
34
+ },
35
+ "scripts": {
36
+ "build": "tsc -p tsconfig.build.json",
37
+ "type-check": "tsc --noEmit",
38
+ "lint": "eslint \"./{src,examples}/**/*.ts\" --config ../../eslint.config.js",
39
+ "bundle": "bun scripts/bundle-guest.ts",
40
+ "test": "node ../../scripts/run-isolated-tests.mjs src scripts",
41
+ "clean": "node -e \"require('fs').rmSync('dist',{recursive:true,force:true})\""
42
+ },
43
+ "files": [
44
+ "dist",
45
+ "scripts/bundle-guest.ts",
46
+ "README.md",
47
+ "API.md",
48
+ "DOCUMENTATION.md",
49
+ "GUEST_SERVICES.md",
50
+ "LICENSE"
51
+ ],
52
+ "dependencies": {
53
+ "zod": "^4.3.6"
54
+ }
55
+ }
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env bun
2
+ import { writeFile } from 'node:fs/promises';
3
+ import { resolve } from 'node:path';
4
+
5
+ const usage = 'Usage: openchamber-guest-bundle [--node] <entry.ts> <outfile.js>';
6
+
7
+ const args = process.argv.slice(2);
8
+ const nodeTarget = args.includes('--node');
9
+ const [entry, outfile] = args.filter((arg) => arg !== '--node');
10
+ if (!entry || !outfile) {
11
+ console.error(usage);
12
+ process.exit(1);
13
+ }
14
+
15
+ const bun = globalThis.Bun;
16
+ if (!bun?.build) {
17
+ console.error('This bundle command needs Bun.');
18
+ process.exit(1);
19
+ }
20
+
21
+ // A panel runs in a sandboxed iframe that cannot load ESM, so it gets a
22
+ // browser IIFE. A local service runs under Node, so `--node` keeps ESM and
23
+ // leaves the Node built-ins external.
24
+ const result = await bun.build({
25
+ entrypoints: [resolve(entry)],
26
+ format: nodeTarget ? 'esm' : 'iife',
27
+ target: nodeTarget ? 'node' : 'browser',
28
+ minify: !nodeTarget,
29
+ write: false,
30
+ });
31
+
32
+ if (!result.success) {
33
+ const message = result.logs.map((log) => log.message).join('\n');
34
+ console.error(message || 'Guest script build failed');
35
+ process.exit(1);
36
+ }
37
+
38
+ const artifact = result.outputs[0];
39
+ if (!artifact) {
40
+ console.error('Guest script build produced no output');
41
+ process.exit(1);
42
+ }
43
+
44
+ await writeFile(resolve(outfile), await artifact.text());