@touchine-ai/ojo 0.0.0-stage → 2.0.0-beta.1
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/LICENSE +21 -0
- package/README.md +245 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +313 -0
- package/package.json +84 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nexight
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,246 @@
|
|
|
1
|
-
#
|
|
1
|
+
# OJO CLI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`@touchine-ai/ojo` is the official command-line tool for OJO. The package name is `@touchine-ai/ojo`, the command is `ojo`, and it lets you log in, manage projects, chat with the AI agent, check run status, fetch the latest project screen, and sync your workspace from the terminal.
|
|
4
|
+
|
|
5
|
+
Install the next-generation CLI from npm:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g @touchine-ai/ojo@latest
|
|
9
|
+
ojo --version
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
To work on the CLI from a repository checkout:
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pnpm --filter @touchine-ai/ojo build
|
|
16
|
+
(cd apps/cli && pnpm link --global)
|
|
17
|
+
node apps/cli/dist/index.js capabilities --json
|
|
18
|
+
node apps/cli/dist/index.js --help
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
`link --global` only exposes this checkout as the local `ojo` command. It does not publish the package.
|
|
22
|
+
|
|
23
|
+
Use `ojo capabilities --json` to verify the next CLI:
|
|
24
|
+
|
|
25
|
+
```json
|
|
26
|
+
{
|
|
27
|
+
"schemaVersion": 2,
|
|
28
|
+
"generation": "next",
|
|
29
|
+
"webOrigin": "https://ojo.dev",
|
|
30
|
+
"serviceApi": "server.v1",
|
|
31
|
+
"pluginInteraction": "local-browser-client",
|
|
32
|
+
"pluginSse": false,
|
|
33
|
+
"canvasSource": "local-workspace",
|
|
34
|
+
"browserClientProtocol": 1,
|
|
35
|
+
"workspaceSyncProtocol": 1,
|
|
36
|
+
"browserDevProtocol": 3,
|
|
37
|
+
"canvasExportProtocol": 1,
|
|
38
|
+
"localCanvasStorageProtocol": 2,
|
|
39
|
+
"browserAuthProtocol": 1,
|
|
40
|
+
"localPrototypeUpdateProtocol": 1,
|
|
41
|
+
"localPrototypeBuildGateProtocol": 1,
|
|
42
|
+
"localPrototypePublishProtocol": 1,
|
|
43
|
+
"localResourcePublishProtocol": 2
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
All new remote operations use `https://staging.ojo.dev/api/server/v1` by default. Override the complete API base with `OJO_SERVER_API_BASE` for local development.
|
|
48
|
+
|
|
49
|
+
For the Irise Web Codex plugin, the built-in Browser operates the local canvas URL and the CLI-issued staging login page when export authentication is required. The plugin does not consume SSE. The canvas skill uses `workspace dev` and the narrow web-login preflight; the build skill additionally uses the local-only `prototype validate` and `prototype build` commands. Explicit user-authorized uploads use only `prototype publish` or `workspace publish-resources` for their corresponding artifact class.
|
|
50
|
+
|
|
51
|
+
Recommended plugin flow: `auth login` → `workspace dev /path/to/irise-web --project-id <projectId> --prototype-dist /path/to/prototype/dist`
|
|
52
|
+
|
|
53
|
+
## Local Prototype Build Gate
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
# Check manifest, source, and prepared dependencies before compiling
|
|
57
|
+
ojo prototype validate /path/to/ojo-prototype --prebuild --json
|
|
58
|
+
|
|
59
|
+
# Build into staging, validate the final package, then atomically promote dist
|
|
60
|
+
ojo prototype build /path/to/ojo-prototype --dist /path/to/ojo-prototype/prototype/dist --json
|
|
61
|
+
|
|
62
|
+
# Validate an existing compiled dist without rebuilding
|
|
63
|
+
ojo prototype validate /path/to/ojo-prototype --dist /path/to/ojo-prototype/prototype/dist --json
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
The result uses `generate-prototype-build-gate.v1` and reports structured `manifest`, `source`, `dependencies`, `typecheck`, `bundle`, `package`, and `promote` phases. Build failures leave the previous stable dist unchanged, so a running local canvas never consumes a partially compiled version. These commands are local-only and do not upload or call the server.
|
|
67
|
+
|
|
68
|
+
## Authentication
|
|
69
|
+
|
|
70
|
+
New CLI login links explicitly select `framework=irise`. Deploy the matching gateway CLI-auth routing and web continuation changes before releasing this CLI. Browser login failures return their original error and never start device authorization; select `--mode device` explicitly when that flow is wanted.
|
|
71
|
+
|
|
72
|
+
Authentication is stored separately for each normalized server.v1 API base under `~/.ojo/auth/server-v1/`. Existing unscoped CLI credentials cannot be identified reliably and are not imported: sign in again after upgrading. Project history stays in its existing database. Login and logout affect only the selected API environment; modern CLI and IDE clients still share credentials within that environment.
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
ojo auth login # Web login (opens browser automatically)
|
|
76
|
+
ojo auth login --mode web # Explicitly use web mode
|
|
77
|
+
ojo auth login --mode device # Device code flow (scan / approve on another device)
|
|
78
|
+
ojo auth login --mode access-key --access-key <token> # AccessKey login
|
|
79
|
+
ojo auth login --no-open # Print the login URL without opening the browser
|
|
80
|
+
ojo auth login --mode device --json # JSON output for automation / agents
|
|
81
|
+
|
|
82
|
+
ojo auth logout # Log out and clear local credentials
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
`auth login --json` emits JSON Lines lifecycle events. `login_required` is written as soon as the browser URL or device code is ready, before the command waits for completion; `authenticated` is written after credentials have been stored. This lets a client such as the Codex plugin open the exact `loginUrl` in its own browser surface without asking the user to run a terminal command.
|
|
86
|
+
|
|
87
|
+
Need an AccessKey for `--mode access-key`? Open the AccessKey manager directly: `https://staging.ojo.dev/dashboard?openAccessKeyManager=1`
|
|
88
|
+
|
|
89
|
+
## Projects
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
ojo project create --name "Import target" --json # Create an empty server.v1 project
|
|
93
|
+
ojo project list # List your projects (default 20 per page)
|
|
94
|
+
ojo project list --page-size 50 # Set page size
|
|
95
|
+
ojo project list --page-token <token> # Go to next page
|
|
96
|
+
ojo project list --favorite # Show only favorited projects
|
|
97
|
+
ojo project list --json # JSON output
|
|
98
|
+
ojo project team list --json # New-framework Team catalog
|
|
99
|
+
ojo project team set <projectId> --name "原型设计团队" --sync-skills --json
|
|
100
|
+
ojo project team get <projectId> --json # Verify saved project Team
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Screen
|
|
104
|
+
|
|
105
|
+
Fetch the current prototype preview image for a project.
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
ojo screen --project-id <projectId>
|
|
109
|
+
ojo screen --project-id <projectId> --json
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
`screen` returns `projectId`, `projectUrl`, `status`, and when available `resourceId`, `resourceMeta`, and `url`.
|
|
113
|
+
|
|
114
|
+
## Chat
|
|
115
|
+
|
|
116
|
+
Sends a message to the OJO agent and waits for it to finish before returning the result.
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
# Create a new project automatically and send a message
|
|
120
|
+
ojo chat --message "Build me a landing page"
|
|
121
|
+
|
|
122
|
+
# Continue an existing project's session
|
|
123
|
+
ojo chat --project-id <projectId> --message "Add a dark mode toggle"
|
|
124
|
+
|
|
125
|
+
# Send via stdin
|
|
126
|
+
echo "Build me a landing page" | ojo chat
|
|
127
|
+
|
|
128
|
+
# JSON output
|
|
129
|
+
ojo chat --project-id <projectId> --message "..." --json
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Response fields: `projectId`, `projectUrl`, `status` (`completed` | `waiting_input`)
|
|
133
|
+
|
|
134
|
+
## Query Run Status
|
|
135
|
+
|
|
136
|
+
Check the latest run status for a project.
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
ojo query --project-id <projectId>
|
|
140
|
+
ojo query --project-id <projectId> --json
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
| Field | Description |
|
|
144
|
+
| ------------ | ----------------------------------------------------- |
|
|
145
|
+
| `projectId` | Project ID |
|
|
146
|
+
| `projectUrl` | Project URL (`https://staging.ojo.dev/p/<projectId>`) |
|
|
147
|
+
| `status` | `running` \| `success` \| `fail` |
|
|
148
|
+
| `statusText` | Progress description (when `running`) |
|
|
149
|
+
| `failure` | Structured error details (when `fail`) |
|
|
150
|
+
|
|
151
|
+
## Workspace Sync
|
|
152
|
+
|
|
153
|
+
Pull the remote project workspace to your local machine.
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
# Sync the project bound to the current directory
|
|
157
|
+
ojo workspace sync
|
|
158
|
+
|
|
159
|
+
# Sync by project ID or URL
|
|
160
|
+
ojo workspace sync <projectId>
|
|
161
|
+
ojo workspace sync https://staging.ojo.dev/p/<projectId>
|
|
162
|
+
|
|
163
|
+
# Write to a specific parent directory
|
|
164
|
+
ojo workspace sync <projectId> --path ./my-projects
|
|
165
|
+
|
|
166
|
+
# JSON output
|
|
167
|
+
ojo workspace sync <projectId> --json
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
Artifacts are extracted to `<project-name>/ojo-prototype` inside the target directory.
|
|
171
|
+
|
|
172
|
+
JSON response fields: `projectId`, `path`, `workspaceHash`
|
|
173
|
+
|
|
174
|
+
## Local Frontend Dev Server
|
|
175
|
+
|
|
176
|
+
Start the synced frontend workspace and keep the process attached to the CLI:
|
|
177
|
+
|
|
178
|
+
```bash
|
|
179
|
+
# Start the Irise Web local canvas orchestrator
|
|
180
|
+
ojo workspace dev /path/to/irise-web --project-id <projectId> --json
|
|
181
|
+
ojo workspace dev /path/to/irise-web/apps/canvas --project-id <projectId> --json
|
|
182
|
+
|
|
183
|
+
# Overlay and watch a locally compiled prototype
|
|
184
|
+
ojo workspace dev /path/to/irise-web --project-id <projectId> --prototype-dist /path/to/prototype/dist --json
|
|
185
|
+
|
|
186
|
+
# Start from an explicit path returned by workspace sync
|
|
187
|
+
ojo workspace dev ./Demo-Project/ojo-prototype --project-id <projectId>
|
|
188
|
+
|
|
189
|
+
# Start the current OJO project's ojo-prototype directory
|
|
190
|
+
ojo workspace dev --project-id <projectId>
|
|
191
|
+
|
|
192
|
+
# Stable lifecycle events for Codex and other agents
|
|
193
|
+
ojo workspace dev ./Demo-Project/ojo-prototype --project-id <projectId> --json
|
|
194
|
+
|
|
195
|
+
# Fixed port or a non-default package.json script
|
|
196
|
+
ojo workspace dev ./Demo-Project/ojo-prototype --project-id <projectId> --port 4173 --script dev
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
The command:
|
|
200
|
+
|
|
201
|
+
- requires a project id and calls the authorized server.v1 canvas-export endpoint;
|
|
202
|
+
- downloads the project draft, resources, state-page revision, and prototype-dist files into an isolated local snapshot;
|
|
203
|
+
- stores that snapshot under exactly two artifact prefixes: compiled files in `prototype/`, and canvas resources in `resource/<type>/`, mirroring the S3 resource-type partition inside a project-scoped local root; compiled files are served canonically at `/__ojo_local__/prototype-dist/`, with the old `/__ojo_local__/prototype/` route retained by Irise Web for compatibility;
|
|
204
|
+
- lets the localhost canvas upload by copying the file into `resource/<type>/` and atomically updating `canvas-export.json`; each file has a stable content-derived local id, checksum, typed path, and empty server-binding slots, while this path never requests an OSS signature or writes to the server;
|
|
205
|
+
- optionally overlays `--prototype-dist`, watches later builds, and emits online-compatible `set_prototype` refresh events over a one-way loopback channel;
|
|
206
|
+
- resolves an Irise Web repository root or `apps/canvas` path to the local canvas orchestrator and runs it non-interactively without a proxy;
|
|
207
|
+
- detects npm, pnpm, Yarn, or Bun;
|
|
208
|
+
- installs dependencies when `node_modules` is missing, unless `--no-install` is used;
|
|
209
|
+
- configures Vite, Rspack, Next.js, Astro, and Nuxt with an explicit host and port;
|
|
210
|
+
- waits until the TCP port is reachable before reporting `ready`;
|
|
211
|
+
- keeps the frontend process alive until the CLI receives `Ctrl+C` or a termination signal;
|
|
212
|
+
- never opens the system browser itself.
|
|
213
|
+
|
|
214
|
+
With `--json`, stdout is JSON Lines. Frontend logs are written to stderr so agents can parse lifecycle events reliably:
|
|
215
|
+
|
|
216
|
+
```json
|
|
217
|
+
{"event":"exporting","projectId":"project-1"}
|
|
218
|
+
{"event":"prototype_updated","sequence":1,"workspaceHash":"...","fileCount":12,"frameCount":5,"entryPath":"home.html"}
|
|
219
|
+
{"event":"watching_prototype","path":"/path/to/prototype/dist","protocol":1}
|
|
220
|
+
{"event":"starting","path":"/path/to/irise-web","packageManager":"pnpm","framework":"irise-canvas","script":"dev","host":"127.0.0.1","port":4173}
|
|
221
|
+
{"event":"ready","source":"local-workspace","path":"/path/to/irise-web","packageManager":"pnpm","framework":"irise-canvas","script":"dev","host":"127.0.0.1","port":4173,"healthUrl":"http://127.0.0.1:4173/","url":"http://127.0.0.1:4173/p/project-1?mode=codex","projectId":"project-1","localExportPath":"/tmp/ojo-canvas-project-1-abc123","resourceCount":6,"prototypeDistFileCount":12,"prototypeDistPath":"/path/to/prototype/dist","localPrototypeUpdateProtocol":1,"pid":12345}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
For an Irise Web canvas checkout, `healthUrl` remains the listener root while `url` is the exact `http://127.0.0.1:<port>/p/<projectId>?mode=codex` canvas. The Codex surface keeps Irise Web's chat panel hidden because the Codex task is the conversation surface. The local frontend reads the exported files from `localExportPath`; `/` and `/dashboard` are not project-canvas handoff URLs.
|
|
225
|
+
|
|
226
|
+
`workspace dev` requires an OJO login because it performs one authorized, read-only canvas export before startup. It does not overwrite the Irise Web checkout, and Browser rendering does not use remote artifact URLs.
|
|
227
|
+
|
|
228
|
+
The local update WebSocket is bound to loopback and only sends content-addressed artifact metadata. It is not SSE and does not carry canvas actions, chat, remote events, credentials, or cookies. After each successful rebuild, wait for a newer `prototype_updated` event and verify the existing Browser canvas.
|
|
229
|
+
|
|
230
|
+
The local snapshot is project-scoped, so it intentionally omits the remote S3 owner/project segments. The stable on-disk layout is `prototype/**`, `resource/{images,videos,audio,html,documents,archives,models,text,other}/**`, plus the root `canvas-export.json` index. The browser-facing compiled-artifact route is `/__ojo_local__/prototype-dist/**`; Irise Web maps it to the physical `prototype/**` directory and keeps `/__ojo_local__/prototype/**` as a legacy alias. Browser drops are loopback file copies into this layout, not remote uploads. Storage protocol 2 initializes `local_resources`; explicit `workspace publish-resources` validates each checksum and typed identity, records the Workspace-minted remote `resource_key` and `short_id`, then rewrites only the corresponding local draft mutations.
|
|
231
|
+
|
|
232
|
+
```bash
|
|
233
|
+
ojo workspace publish-resources <localExportPath> --project-id <projectId> --json
|
|
234
|
+
ojo workspace publish-resources <localExportPath> --project-id <projectId> --local-id <localId> --json
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
The command refuses unverified bytes and conflicting remote node identities. Without `--local-id`, it selects only unsynced resources referenced by local mutations. Uploading bytes, linking the project resource, and syncing normalized add-only resource nodes are separate retryable phases recorded in `canvas-export.json`; unrelated remote draft changes are rebased by the project-scoped sync endpoint.
|
|
238
|
+
|
|
239
|
+
The server may compact an `UpdateResourceNode` back into the canonical `CreateResourceNode` keyframe. Post-commit verification therefore waits for the new draft version and verifies the mapped resource identity on the same node instead of requiring byte-for-byte mutation equality. If the commit succeeded but its first readback was stale or interrupted, rerunning the command recognizes that canonical remote state, adopts it locally, and does not upload or commit again.
|
|
240
|
+
|
|
241
|
+
## Agent / Automation Notes
|
|
242
|
+
|
|
243
|
+
- `chat` has two modes: omit `--project-id` to auto-create a project; pass `--project-id` to continue an existing session.
|
|
244
|
+
- `query` only needs `--project-id`; it fetches the latest run automatically and returns `projectUrl`.
|
|
245
|
+
- Use `workspace sync` after `chat` / `query` to pull updated project files locally.
|
|
246
|
+
- Use `workspace dev <path> --project-id <projectId> --prototype-dist <distPath> --json` to obtain the exact localhost project URL and keep local rebuilds attached, then open that URL with Codex Browser.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { createRequire as __cliCreateRequire } from 'node:module';
|
|
4
|
+
const require = __cliCreateRequire(import.meta.url);
|
|
5
|
+
|
|
6
|
+
var Xi=Object.defineProperty;var Kn=(e,t)=>{for(var r in t)Xi(e,r,{get:t[r],enumerable:!0})};import{createHash as na}from"crypto";import{mkdir as oa,readFile as sa,rename as ia,writeFile as aa}from"fs/promises";import{createRequire as ca}from"module";import{homedir as ro}from"os";import{dirname as ua,join as tt}from"path";import da from"sql.js";var qn="OJO_SERVER_API_BASE",Qn="OJO_API_BASE",Yn="IRISE_API_BASE";function Xn(e){let t=new URL(e),r=t.pathname.replace(/\/+$/,"");return r.endsWith("/api/server/v1")||r.endsWith("/server/v1")?t.pathname=r:r.endsWith("/api")?t.pathname=`${r}/server/v1`:r?t.pathname=`${r}/api/server/v1`:t.pathname="/api/server/v1",t.search="",t.hash="",t.toString().replace(/\/$/,"")}var B=Xn(process.env[qn]??process.env[Qn]??process.env[Yn]??process.env.NEXIGHT_API_BASE??"https://ojo.art");var hr={productBriefDirty:!1,prototypeCodeDirty:!1,firstVersionCodeDirty:!1},Zi=new Set(["save_final_prd"]),ea=new Set(["sandbox_write_file","sandbox_write_files","sandbox_edit_file","sandbox_copy_file","sandbox_commit"]),ta=new Set(["write_code"]);function ra(e){let t=e.metadata?.sdk?.toolName;if(typeof t=="string"&&t.trim().length>0)return t.trim();let n=e.metadata?.toolName;return typeof n=="string"&&n.trim().length>0?n.trim():null}function Zn(e,t){if(!Array.isArray(e)||e.length===0)return{};let r={};for(let n of e){if(!n||n.role!=="tool")continue;let o=n.metadata?.runId;if(typeof o!="string"||o!==t)continue;let s=ra(n);if(s){if(Zi.has(s)){r.productBriefDirty=!0;continue}if(ea.has(s)){r.prototypeCodeDirty=!0;continue}ta.has(s)&&(r.firstVersionCodeDirty=!0)}}return r}function eo(e,t){return{productBriefDirty:e.productBriefDirty||t.productBriefDirty===!0,prototypeCodeDirty:e.prototypeCodeDirty||t.prototypeCodeDirty===!0,firstVersionCodeDirty:e.firstVersionCodeDirty||t.firstVersionCodeDirty===!0}}var wr=2,Ir="global",no=tt(ro(),".ojo"),pa=tt(ro(),".irise"),oo=tt(no,"ojo-state.sqlite"),la=tt(pa,"irise-state.sqlite"),Et=tt(no,"auth","server-v1",`${na("sha256").update(B).digest("hex")}.sqlite`),fa=ca(typeof __filename=="string"?__filename:import.meta.url),ma=fa.resolve("sql.js/dist/sql-wasm.wasm"),yr=null,to=Promise.resolve();function so(e){let t=e.trim();if(!t)throw new Error("projectId is required");return t}function ge(e){return typeof e!="string"?null:e.trim()||null}function ie(e){if(typeof e!="string")return null;let t=e.trim();return t.length>0?t:null}function Be(e){return typeof e!="number"||!Number.isFinite(e)?null:e}function ga(e){return{version:wr,projectId:e,updatedAt:Date.now(),threadId:null,latestRunId:null,artifacts:{...hr}}}function ha(e){return e?{productBriefDirty:e.product_brief_dirty===1,prototypeCodeDirty:e.prototype_code_dirty===1,firstVersionCodeDirty:e.first_version_code_dirty===1}:{...hr}}function io(e,t){return t?{version:wr,projectId:e,updatedAt:Number.isFinite(t.updated_at)?t.updated_at:Date.now(),threadId:ge(t.thread_id),latestRunId:ge(t.latest_run_id),artifacts:ha(t)}:ga(e)}function ao(e){return e?{sessionId:ge(e.session_id),cookie:ie(e.cookie),userId:ie(e.user_id),createdAtMs:Be(e.created_at_ms),expiresAtMs:Be(e.expires_at_ms),source:ie(e.source),accessKeyToken:ie(e.pat_token),updatedAt:Number.isFinite(e.updated_at)?e.updated_at:Date.now()}:null}function ya(e){return{sessionId:ge(e.sessionId),cookie:ie(e.cookie),userId:ie(e.userId),createdAtMs:Be(e.createdAtMs),expiresAtMs:Be(e.expiresAtMs),source:ie(e.source),accessKeyToken:ie(e.accessKeyToken),updatedAt:typeof e.updatedAt=="number"&&Number.isFinite(e.updatedAt)?e.updatedAt:Date.now()}}function _a(e,t){return{sessionId:t.sessionId===void 0?e?.sessionId??null:ge(t.sessionId),cookie:t.cookie===void 0?e?.cookie??null:ie(t.cookie),userId:t.userId===void 0?e?.userId??null:ie(t.userId),createdAtMs:t.createdAtMs===void 0?e?.createdAtMs??null:Be(t.createdAtMs),expiresAtMs:t.expiresAtMs===void 0?e?.expiresAtMs??null:Be(t.expiresAtMs),source:t.source===void 0?e?.source??null:ie(t.source),accessKeyToken:t.accessKeyToken===void 0?e?.accessKeyToken??null:ie(t.accessKeyToken),updatedAt:typeof t.updatedAt=="number"&&Number.isFinite(t.updatedAt)?t.updatedAt:Date.now()}}function wa(e){return e.sessionId===null&&e.cookie===null&&e.userId===null&&e.createdAtMs===null&&e.expiresAtMs===null&&e.source===null&&e.accessKeyToken===null}async function Ia(){return yr||(yr=da({locateFile:()=>ma})),yr}function Sa(e){e.run(`
|
|
7
|
+
CREATE TABLE IF NOT EXISTS project_session_state (
|
|
8
|
+
project_id TEXT PRIMARY KEY,
|
|
9
|
+
thread_id TEXT,
|
|
10
|
+
latest_run_id TEXT,
|
|
11
|
+
updated_at INTEGER NOT NULL
|
|
12
|
+
);
|
|
13
|
+
`),e.run(`
|
|
14
|
+
CREATE TABLE IF NOT EXISTS project_artifact_state (
|
|
15
|
+
project_id TEXT PRIMARY KEY,
|
|
16
|
+
product_brief_dirty INTEGER NOT NULL DEFAULT 0,
|
|
17
|
+
prototype_code_dirty INTEGER NOT NULL DEFAULT 0,
|
|
18
|
+
first_version_code_dirty INTEGER NOT NULL DEFAULT 0,
|
|
19
|
+
updated_at INTEGER NOT NULL,
|
|
20
|
+
FOREIGN KEY(project_id) REFERENCES project_session_state(project_id) ON DELETE CASCADE
|
|
21
|
+
);
|
|
22
|
+
`),e.run(`
|
|
23
|
+
CREATE TABLE IF NOT EXISTS global_auth_state (
|
|
24
|
+
scope TEXT PRIMARY KEY,
|
|
25
|
+
session_id TEXT,
|
|
26
|
+
cookie TEXT,
|
|
27
|
+
user_id TEXT,
|
|
28
|
+
created_at_ms INTEGER,
|
|
29
|
+
expires_at_ms INTEGER,
|
|
30
|
+
source TEXT,
|
|
31
|
+
pat_token TEXT,
|
|
32
|
+
updated_at INTEGER NOT NULL
|
|
33
|
+
);
|
|
34
|
+
`)}async function xt(e=[oo,la]){let t=await Ia(),r;for(let o of e)try{r=new Uint8Array(await sa(o));break}catch(s){if(s.code!=="ENOENT")throw s}let n=r?new t.Database(r):new t.Database;return Sa(n),n}async function _r(e,t=oo){await oa(ua(t),{recursive:!0});let r=`${t}.${process.pid}.${Date.now()}.tmp`,n=Buffer.from(e.export());await aa(r,n,{mode:384}),await ia(r,t)}function co(e,t){let r=e.prepare(`
|
|
35
|
+
SELECT
|
|
36
|
+
s.project_id,
|
|
37
|
+
s.thread_id,
|
|
38
|
+
s.latest_run_id,
|
|
39
|
+
s.updated_at,
|
|
40
|
+
COALESCE(a.product_brief_dirty, 0) AS product_brief_dirty,
|
|
41
|
+
COALESCE(a.prototype_code_dirty, 0) AS prototype_code_dirty,
|
|
42
|
+
COALESCE(a.first_version_code_dirty, 0) AS first_version_code_dirty
|
|
43
|
+
FROM project_session_state s
|
|
44
|
+
LEFT JOIN project_artifact_state a ON a.project_id = s.project_id
|
|
45
|
+
WHERE s.project_id = ?;
|
|
46
|
+
`);try{return r.bind([t]),r.step()?r.getAsObject():void 0}finally{r.free()}}function uo(e){let t=e.prepare(`
|
|
47
|
+
SELECT
|
|
48
|
+
scope,
|
|
49
|
+
session_id,
|
|
50
|
+
cookie,
|
|
51
|
+
user_id,
|
|
52
|
+
created_at_ms,
|
|
53
|
+
expires_at_ms,
|
|
54
|
+
source,
|
|
55
|
+
pat_token,
|
|
56
|
+
updated_at
|
|
57
|
+
FROM global_auth_state
|
|
58
|
+
WHERE scope = ?;
|
|
59
|
+
`);try{return t.bind([Ir]),t.step()?t.getAsObject():void 0}finally{t.free()}}function Pa(e,t){e.run(`
|
|
60
|
+
INSERT INTO project_session_state (project_id, thread_id, latest_run_id, updated_at)
|
|
61
|
+
VALUES (?, ?, ?, ?)
|
|
62
|
+
ON CONFLICT(project_id) DO UPDATE SET
|
|
63
|
+
thread_id = excluded.thread_id,
|
|
64
|
+
latest_run_id = excluded.latest_run_id,
|
|
65
|
+
updated_at = excluded.updated_at;
|
|
66
|
+
`,[t.projectId,t.threadId,t.latestRunId,t.updatedAt]),e.run(`
|
|
67
|
+
INSERT INTO project_artifact_state (
|
|
68
|
+
project_id,
|
|
69
|
+
product_brief_dirty,
|
|
70
|
+
prototype_code_dirty,
|
|
71
|
+
first_version_code_dirty,
|
|
72
|
+
updated_at
|
|
73
|
+
)
|
|
74
|
+
VALUES (?, ?, ?, ?, ?)
|
|
75
|
+
ON CONFLICT(project_id) DO UPDATE SET
|
|
76
|
+
product_brief_dirty = excluded.product_brief_dirty,
|
|
77
|
+
prototype_code_dirty = excluded.prototype_code_dirty,
|
|
78
|
+
first_version_code_dirty = excluded.first_version_code_dirty,
|
|
79
|
+
updated_at = excluded.updated_at;
|
|
80
|
+
`,[t.projectId,t.artifacts.productBriefDirty?1:0,t.artifacts.prototypeCodeDirty?1:0,t.artifacts.firstVersionCodeDirty?1:0,t.updatedAt])}function Ra(e,t){e.run(`
|
|
81
|
+
INSERT INTO global_auth_state (
|
|
82
|
+
scope,
|
|
83
|
+
session_id,
|
|
84
|
+
cookie,
|
|
85
|
+
user_id,
|
|
86
|
+
created_at_ms,
|
|
87
|
+
expires_at_ms,
|
|
88
|
+
source,
|
|
89
|
+
pat_token,
|
|
90
|
+
updated_at
|
|
91
|
+
)
|
|
92
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
93
|
+
ON CONFLICT(scope) DO UPDATE SET
|
|
94
|
+
session_id = excluded.session_id,
|
|
95
|
+
cookie = excluded.cookie,
|
|
96
|
+
user_id = excluded.user_id,
|
|
97
|
+
created_at_ms = excluded.created_at_ms,
|
|
98
|
+
expires_at_ms = excluded.expires_at_ms,
|
|
99
|
+
source = excluded.source,
|
|
100
|
+
pat_token = excluded.pat_token,
|
|
101
|
+
updated_at = excluded.updated_at;
|
|
102
|
+
`,[Ir,t.sessionId,t.cookie,t.userId,t.createdAtMs,t.expiresAtMs,t.source,t.accessKeyToken,t.updatedAt])}function va(e){e.run("DELETE FROM global_auth_state WHERE scope = ?;",[Ir])}function Ct(e){let t=to.then(e,e);return to=t.then(()=>{},()=>{}),t}async function ka(e,t){return Ct(async()=>{let r=so(e),n=await xt();try{let o=io(r,co(n,r)),s=await t(o),i={version:wr,projectId:r,updatedAt:Number.isFinite(s.updatedAt)?s.updatedAt:Date.now(),threadId:ge(s.threadId),latestRunId:ge(s.latestRunId),artifacts:{productBriefDirty:s.artifacts.productBriefDirty===!0,prototypeCodeDirty:s.artifacts.prototypeCodeDirty===!0,firstVersionCodeDirty:s.artifacts.firstVersionCodeDirty===!0}};return Pa(n,i),await _r(n),i}finally{n.close()}})}async function Sr(e){return Ct(async()=>{let t=await xt([Et]);try{let r=ao(uo(t)),n=await e(r);return!n||wa(n)?(va(t),await _r(t,Et),null):(Ra(t,n),await _r(t,Et),n)}finally{t.close()}})}async function Tt(e){return Ct(async()=>{let t=so(e),r=await xt();try{return io(t,co(r,t))}finally{r.close()}})}async function bt(e,t){return ka(e,r=>({...r,updatedAt:Date.now(),threadId:t.threadId===void 0?r.threadId:ge(t.threadId),latestRunId:t.latestRunId===void 0?r.latestRunId:ge(t.latestRunId),artifacts:t.dirtyPatch?eo(r.artifacts,t.dirtyPatch):r.artifacts}))}async function We(e,t){return bt(e,{threadId:t})}async function rt(e,t,r){let n=ge(t);if(!n)throw new Error("runId is required");return bt(e,{threadId:r?.threadId,latestRunId:n,dirtyPatch:r?.dirtyPatch})}async function Ce(){return Ct(async()=>{let e=await xt([Et]);try{return ao(uo(e))}finally{e.close()}})}async function po(e){return Sr(async()=>ya(e))}async function nt(e){return Sr(async t=>_a(t,e))}async function lo(){await Sr(async()=>null)}import{AxiosError as Aa}from"axios";var fo=768,Ea=/^(authorization|cookie|set-cookie|token|access_token|refresh_token|access_key|access_key_token|access_key_id|session_id|sessionid|x-ojo-session-id)$/i,xa=/^(authorization|cookie|token|access_token|refresh_token|access_key|access_key_token|access_key_id|session_id|sessionid|x-ojo-session-id|code|state|sig|signature|x-amz-credential|x-amz-date|x-amz-expires|x-amz-security-token|x-amz-signature|x-amz-signedheaders)$/i,Ca=/((authorization|cookie|set-cookie|token|access_token|refresh_token|access_key(_token|_id)?|session_?id|x-ojo-session-id)\s*["'=:\s]+\s*(?:Bearer\s+)?)([^"',\s}]+)/gi,Ta=/https?:\/\/[^\s"'<>]+/gi,m=class extends Error{code;status;cause;details;source;constructor(t,r,n){super(r),this.name="CommonError",this.code=t,this.status=n?.status,this.cause=n?.cause,this.details=n?.details,this.source=n?.source??"internal"}};function mo(e){let t=e.trim();return t.length<=fo?t:`${t.slice(0,fo)}...`}function go(e){return e.replace(Ca,(t,r)=>`${r}[REDACTED]`)}function Ot(e){if(typeof e!="string")return;let t=e.trim();return t?t.toUpperCase():void 0}function Se(e){let t=e.trim();if(!t)return e;try{let r=/^[a-z][a-z0-9+.-]*:\/\//i.test(t),n=r?new URL(t):new URL(t,"https://ojo.invalid");n.username&&(n.username="[REDACTED]"),n.password&&(n.password="[REDACTED]");let o=new Set;for(let i of n.searchParams.keys())o.add(i);for(let i of o)xa.test(i)&&n.searchParams.set(i,"[REDACTED]");return r?n.toString():`${n.pathname}${n.search}${n.hash}`}catch{return go(t)}}function ho(e){return go(e).replace(Ta,t=>Se(t))}function J(e,t){if(typeof e!="string")return;let r=e.trim();if(r){if(typeof t=="string"&&t.trim())try{if(/^[a-z][a-z\d+.-]*:\/\//i.test(r))return Se(new URL(r).toString());let n=`${t.trim().replace(/\/+$/,"")}/${r.replace(/^\/+/,"")}`;return Se(n)}catch{return Se(r)}return Se(r)}}function Pr(e){if(typeof e=="string")return ho(e);if(Array.isArray(e))return e.map(r=>Pr(r));if(!e||typeof e!="object")return e;let t={};for(let[r,n]of Object.entries(e))t[r]=Ea.test(r)?"[REDACTED]":Pr(n);return t}function Te(e){if(e!=null){if(typeof e=="string"){let t=ho(e);return t.trim()?mo(t):void 0}try{let t=JSON.stringify(Pr(e));return t?mo(t):void 0}catch{return}}}function vr(e,t){for(let r of t){let n=e[r];if(typeof n=="string"&&n.trim().length>0)return n.trim()}}function yo(e){if(!e||typeof e!="object"||!("cause"in e))return{};let t=e.cause;if(!t||typeof t!="object")return typeof t=="string"?{causeMessage:Te(t)}:{};let r=t,n=r.code,o=typeof n=="string"?n.trim()||void 0:typeof n=="number"?String(n):void 0,s=Te(vr(r,["message","errmsg","error","msg"])??(t instanceof Error?t.message:void 0));return{causeCode:o,causeMessage:s}}function ze(e){return!e||typeof e!="object"?void 0:vr(e,["x-request-id","x-ojo-request-id","request-id"])}function kr(e){if(!e||typeof e!="object"||Array.isArray(e))return{bodySnippet:Te(e)};let t=e,r=vr(t,["message","errmsg","error","msg"]),n=t.code;return{upstreamCode:typeof n=="string"?n:typeof n=="number"?String(n):void 0,upstreamMessage:r,bodySnippet:Te(e)}}function jt(e,t){if(!t)return e;let r=Ot(t.method),n=typeof t.endpoint=="string"?Se(t.endpoint):void 0;if(!r&&!n)return e;let o=[r,n].filter(Boolean).join(" ");return`${e} (${o})`}function Rr(e){if(!e)return;let t={...e},r=Ot(e.method),n=typeof e.endpoint=="string"?Se(e.endpoint):void 0,o=typeof e.requestId=="string"&&e.requestId.trim()||void 0,s=Te(e.bodySnippet);return r&&(t.method=r),n&&(t.endpoint=n),o&&(t.requestId=o),s&&(t.bodySnippet=s),t}function ba(e){if(!e)return;let t=Ot(e.method),r=typeof e.endpoint=="string"?Se(e.endpoint):void 0,n=typeof e.statusText=="string"?e.statusText:void 0,o=typeof e.upstreamCode=="string"?e.upstreamCode:void 0,s=typeof e.upstreamMessage=="string"?e.upstreamMessage:void 0,i=typeof e.requestId=="string"&&e.requestId.trim()||void 0,a=typeof e.causeCode=="string"&&e.causeCode.trim()||void 0,c=Te(e.causeMessage),u=Te(e.bodySnippet);if(!(!t&&!r&&!n&&!o&&!s&&!i&&!a&&!c&&!u))return{method:t,endpoint:r,statusText:n,upstreamCode:o,upstreamMessage:s,requestId:i,causeCode:a,causeMessage:c,bodySnippet:u}}function ja(e,t,r,n){let o=e.response?.status??n?.status,s=J(e.config?.url,e.config?.baseURL),i=kr(e.response?.data),a=ze(e.response?.headers),c=yo(e),u=i.upstreamMessage??e.message??r;return new m(t,jt(u,{method:e.config?.method,endpoint:s}),{...n,status:o,cause:n?.cause??e,details:{...n?.details,method:Ot(e.config?.method),endpoint:s,statusText:e.response?.statusText,requestId:a,...c,...i}})}function Pe(e,t,r){let n=Rr(r.details);return new m(e,jt(t,n),{...r,details:n})}function be(e,t="INTERNAL_ERROR",r="Unexpected error",n){if(e instanceof m)return e;if(e instanceof Aa)return ja(e,t,r,n);if(e instanceof Error){let s=e.message||r,i=Rr(n?.details),a=yo(e);return new m(t,jt(s,i),{...n,details:{...i,...a},cause:n?.cause??e})}let o=Rr(n?.details);return new m(t,jt(r,o),{...n,details:o,cause:n?.cause??e})}function Oa(e){let t=be(e);return{code:t.code,message:t.message,status:t.status,source:t.source,debug:ba(t.details)}}function _o(e){return{ok:!1,error:Oa(e)}}import ec,{AxiosHeaders as Mo}from"axios";function Nt(e){return e&&e.match(/(?:^|;\s*)session_id=([^;]+)/)?.[1]?.trim()||null}var Na=1,wo=Number.MAX_SAFE_INTEGER;function Je(e){if(typeof e!="string")return;let t=e.trim();return t.length>0?t:void 0}function Lt(e){return typeof e=="number"&&Number.isFinite(e)?e:void 0}function Io(e,t){let r=Je(t);return r?/(?:^|;\s*)session_id=/.test(r)?r.replace(/((?:^|;\s*)session_id=)[^;]*/g,`$1${e}`):`${r}; session_id=${e}`:`session_id=${e}`}function So(e){if(!e)return null;let t=Je(e.sessionId)??Nt(Je(e.cookie))??void 0;if(!t)return null;let r=Lt(e.updatedAt)??Lt(e.createdAtMs)??0,n=Io(t,Je(e.cookie));return{version:Na,origin:new URL(B).origin,apiBase:B,sessionId:t,updatedAt:r,cookie:n,session_id:t,user_id:Je(e.userId)??"unknown",created_at_ms:Lt(e.createdAtMs)??r,expires_at_ms:Lt(e.expiresAtMs)??wo,source:Je(e.source)??"ojo-session"}}async function Ar(){return So(await Ce())}async function je(e){let t=e.sessionId.trim();if(!t)throw new Error("sessionId is required");let r=Date.now(),n=await Ce(),o=n?.sessionId===t?n:null,s=await po({sessionId:t,cookie:Io(t,e.cookie??o?.cookie??n?.cookie??void 0),userId:o?.userId??"unknown",createdAtMs:o?.createdAtMs??r,expiresAtMs:o?.expiresAtMs??wo,source:e.source??o?.source??"ojo-session",accessKeyToken:e.accessKeyToken===void 0?n?.accessKeyToken??null:e.accessKeyToken,updatedAt:r}),i=So(s);if(!i)throw new Error("failed to persist auth session");return i}function ot(e){if(!e)return null;let r=(Array.isArray(e)?e:[e]).map(n=>{let o=n.indexOf(";");return o>=0?n.slice(0,o).trim():n.trim()}).filter(n=>n.includes("="));return r.length>0?r.join("; "):null}async function Ve(){let e=await Ce();return typeof e?.cookie=="string"&&e.cookie.trim().length>0?e.cookie.trim():typeof e?.sessionId=="string"&&e.sessionId.trim().length>0?`session_id=${e.sessionId.trim()}`:null}async function Mt(e){let t=e.trim();if(!t){await Er();return}let r=Nt(t);if(r){await je({sessionId:r,cookie:t});return}await nt({cookie:t})}async function Er(){await nt({cookie:null})}import{promises as Wf}from"fs";function Cr(e){return`session_id=${e}`}var xr=class{async getSessionCredentials(){let t=await Ve();if(t)return{cookie:t,source:"ojo-cookie"};let r=await Ar();return r?.sessionId?{cookie:Cr(r.sessionId),sessionId:r.sessionId,source:"ojo-session"}:null}};var La=new xr;function Ma(){return La}async function ue(e=Ma()){return e.getSessionCredentials()}import{randomUUID as Da}from"crypto";import{mkdir as Ua,readFile as $a,rename as Fa,writeFile as Ga}from"fs/promises";import{homedir as vo}from"os";import{dirname as Ha,join as ko}from"path";var br=1,Ao=ko(vo(),".ojo","device.json"),Ba=ko(vo(),".irise","device.json"),Eo=null,Tr=null,Wa=null;function za(e){return e==="cli"||e==="ide"?e:null}function Ja(){return Wa??Ao}async function Po(e){try{let t=await $a(e,"utf8"),r=JSON.parse(t);return r?.version!==br||typeof r.deviceId!="string"||!r.deviceId.trim()?null:{version:br,deviceId:r.deviceId.trim()}}catch{return null}}async function Ro(e,t){await Ua(Ha(e),{recursive:!0});let r=`${e}.${process.pid}.${Date.now()}.tmp`;await Ga(r,`${JSON.stringify(t,null,2)}
|
|
103
|
+
`,"utf8"),await Fa(r,e)}async function Va(){let e=Ja(),t=await Po(e);if(t)return t.deviceId;let r=e===Ao?await Po(Ba):null;if(r)return await Ro(e,r),r.deviceId;let n=Da();return await Ro(e,{version:br,deviceId:n}),n}function jr(e){Eo=za(e)}function xo(){return Eo}async function Co(){return Tr||(Tr=Va()),Tr}function Ka(e){if(!e)return;let t=e.trim();return t.length>0?t:void 0}function qa(e){if(!e)return;let r=e.match(/(?:^|;\s*)session_id=([^;]+)/)?.[1]?.trim();return r&&r.length>0?r:void 0}function Qa(e,t){return e?`${e}; ${t}`:t}function de(e){let t=Ka(e?.cookie),r=qa(t),n=e?.sessionId?.trim(),o=r??(n&&n.length>0?n:void 0),s=r?t:o?Qa(t,`session_id=${o}`):t,i={};return s&&(i.Cookie=s),o&&(i["X-Ojo-Session-Id"]=o,i.Authorization=`Bearer ${o}`),{headers:i,cookie:s,sessionId:o}}var To={},Ya={async flush(){},flushSync(){}};function W(e){return e instanceof m?e.code:be(e).code||"UNKNOWN_ERROR"}function bo(e){To={...To,...e}}var Or=class{reportBusinessEvent(t,r,n={}){}reportDevEvent(t,r,n={}){}track(t,r={},n={}){}},Xa=new Or;function q(){return Xa}function jo(){return Ya}function Za(e){let t=e.searchParams;return t.has("X-Amz-Algorithm")||t.has("X-Amz-Signature")||t.has("AWSAccessKeyId")&&t.has("Signature")}function Oe(e){try{return!Za(new URL(e))}catch{return!0}}var Oo="X-Ojo-Platform",No="X-Ojo-Device-ID",Nr=q();function Ke(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function pe(e,...t){if(Ke(e))for(let r of t){let n=e[r];if(typeof n=="string"&&n.trim())return n.trim()}}function Do(e,...t){if(Ke(e))for(let r of t){let n=e[r];if(typeof n=="number"&&Number.isFinite(n))return n;if(typeof n=="string"&&n.trim()){let o=Number(n);if(Number.isFinite(o))return o}}}function tc(e,...t){if(!Ke(e))return!1;for(let r of t)if(typeof e[r]=="boolean")return e[r];return!1}function rc(e,...t){if(Ke(e))for(let r of t){let n=e[r];if(Ke(n))return n}}function Lo(e){if(typeof e=="number"&&Number.isFinite(e))return e;if(typeof e!="string"||!e.trim())return 0;let t=Date.parse(e);return Number.isFinite(t)?t:0}function nc(e){return{project_id:pe(e,"project_id","projectId")??"",name:pe(e,"project_name","projectName","name")??"",created_at:Lo(e.created_at??e.createdAt),updated_at:Lo(e.updated_at??e.updatedAt),creator_uid:pe(e,"owner_user_id","ownerUserId","creator_uid","creatorUid")??"",cover_res_id:pe(e,"cover_resource_id","coverResourceId","cover_res_id","coverResId"),status:Do(e,"project_status","projectStatus","status"),is_favorite:tc(e,"is_favorited","isFavorited","is_favorite","isFavorite")}}function oc(e,t){let r=e._reportStartMs,n=typeof r=="number"?Date.now()-r:void 0,o=J(e.url,e.baseURL);Nr.track("perf_api_request",{transport:"axios",endpoint:o??e.url??"unknown",method:(e.method??"GET").toUpperCase(),statusCode:t,durationMs:n})}function sc(e){let t=e.config??{},r=t._reportStartMs,n=typeof r=="number"?Date.now()-r:void 0,o=J(t.url,t.baseURL),s=(t.method??"GET").toUpperCase(),i=e.response?.status;if(e.code==="ECONNABORTED"){let c=typeof t.timeout=="number"?t.timeout:void 0;Nr.track("perf_api_timeout",{transport:"axios",endpoint:o??t.url??"unknown",method:s,timeoutMs:c,durationMs:n});return}Nr.track("perf_api_error",{transport:"axios",endpoint:o??t.url??"unknown",method:s,statusCode:i,durationMs:n,errorCode:W(e),errorMsg:e.message})}function ic(e){e.interceptors.request.use(async t=>{let r=await cc(t);return r._reportStartMs=Date.now(),r}),e.interceptors.response.use(t=>(oc(t.config,t.status),t),t=>(sc(t),Promise.reject(t)))}async function ac(e){let t=xo();if(!t)return e;let r=Mo.from(e.headers??{});return r.has(Oo)||r.set(Oo,t),r.has(No)||r.set(No,await Co()),e.headers=r,e}async function cc(e){e=await ac(e);let t=await ue(),r=Mo.from(e.headers??{}),n=r.get("Cookie"),o=de({cookie:typeof n=="string"?n:t?.cookie,sessionId:t?.sessionId});return o.cookie&&r.set("Cookie",o.cookie),o.sessionId&&!r.has("X-Ojo-Session-Id")&&r.set("X-Ojo-Session-Id",o.sessionId),o.sessionId&&!r.has("Authorization")&&r.set("Authorization",`Bearer ${o.sessionId}`),e.headers=r,e}function uc(){let e=ec.create({baseURL:B,withCredentials:!0,headers:{"Content-Type":"application/json"}});return ic(e),e.interceptors.response.use(t=>t,t=>t.response?.status===401?Promise.reject(new m("AUTH_REQUIRED","\u767B\u5F55\u5DF2\u8FC7\u671F\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55 OJO",{status:401,cause:t,source:"auth"})):Promise.reject(be(t,"API_REQUEST_FAILED","\u63A5\u53E3\u8C03\u7528\u5931\u8D25",{source:"api"}))),e}var j=uc(),Dt=j;async function Uo(e){let t=Math.max(1,Math.min(100,Math.trunc(e.page_size||20))),r=Number.parseInt(e.page_token??"1",10),n=Number.isFinite(r)&&r>0?r:1,o=e.is_favorite?"/users/me/favorite-projects":"/projects",s=await Dt.get(o,{params:{page:n,page_size:t}}),i=(s.data.projects??[]).map(c=>nc(c)),a=Number(s.data.total??i.length);return{projects:i,next_page_token:n*t<a?String(n+1):null,total:a}}async function $o(e={}){let t=await Dt.post("/projects",{project_name:e.name});return{project_id:t.data.project_id??t.data.projectId??""}}async function st(e){let t=await Dt.get(`/projects/${encodeURIComponent(e.project_id)}`),r=pe(t.data,"workspace_hash","workspaceHash");return{...t.data,name:pe(t.data,"project_name","projectName"),workspace_hash:r,version:Do(t.data,"draft_version","draftVersion"),draft:{...Ke(t.data.draft)?t.data.draft:{},...r?{workspace_hash:r}:{}},cover_resource_id:pe(t.data,"cover_resource_id","coverResourceId"),cover_resource_meta:rc(t.data,"cover_resource_meta","coverResourceMeta")}}async function Fo(e){let t=await st({project_id:e.project_id}),r=t.cover_resource_meta,n=pe(r,"resource_url","resourceUrl","url"),o=t.cover_resource_id??pe(r,"resource_key","resourceKey","key");return!n&&!o?{}:{prototype_screenshot:{resource_id:o,resource_meta:{key:pe(r,"resource_key","resourceKey","key")??o,url:n,exists:!!n,content_type:pe(r,"resource_mime_type","resourceMimeType","content_type","contentType")}}}}async function Go(e){let t=await Dt.get(`/projects/${encodeURIComponent(e.project_id)}/workspace-zip-credential`,{params:{workspace_hash:e.workspace_hash,...e.expire_seconds!==void 0?{expire_seconds:e.expire_seconds}:{}},validateStatus:n=>n>=200&&n<300||n===404});if(t.status===404)return{url:"",exists:!1,expire_at:0};let r=t.data.download_url??t.data.downloadUrl??"";return{url:r,exists:!!r,expire_at:t.data.expires_at_unix??t.data.expiresAtUnix??0}}function dc(e,t=600){if(typeof e!="string"||!e.trim())return t;let r=Date.parse(e);return Number.isFinite(r)?Math.max(1,Math.floor((r-Date.now())/1e3)):t}function pc(e){let t=typeof e=="string"?e.trim().toLowerCase():"";return t==="authorized"||t==="complete"||t==="completed"?"approved":t||"pending"}async function Lr(e){let t=await j.post("/auth/firebase/session",{firebase_id_token:e},{maxRedirects:0,validateStatus:()=>!0}),r=t.data.session_token??t.data.sessionToken;if(t.status>=200&&t.status<300&&!r)throw Pe("API_REQUEST_FAILED","server.v1 \u767B\u5F55\u6210\u529F\uFF0C\u4F46\u672A\u8FD4\u56DE session_token",{status:t.status,source:"auth"});let n=t;return n.data={code:t.status>=200&&t.status<300?0:t.status,data:{is_new_user:!!(t.data.is_new_user??t.data.isNewUser)}},r&&(n.headers["set-cookie"]=[`session_id=${r}`]),n}async function Mr(e){throw Pe("EMAIL_AUTH_UNAVAILABLE","\u65B0 CLI \u6682\u4E0D\u652F\u6301\u90AE\u7BB1\u9A8C\u8BC1\u7801\u767B\u5F55\uFF0C\u8BF7\u4F7F\u7528 Web\u3001Device \u6216 AccessKey \u767B\u5F55",{status:501,source:"auth"})}async function lc(e,t){throw Pe("EMAIL_AUTH_UNAVAILABLE","\u65B0 CLI \u6682\u4E0D\u652F\u6301\u90AE\u7BB1\u9A8C\u8BC1\u7801\u767B\u5F55",{status:501,source:"auth"})}async function Dr(e,t){return lc(e,t)}async function Ho(e){let t=await j.post("/auth/device-flow/code",{client_info_json:JSON.stringify({client:"ojo-cli",client_name:e.clientName,client_version:e.clientVersion,hostname:e.hostname})}),r=t.data.device_code??t.data.deviceCode??"",n=t.data.credential_user_code??t.data.credentialUserCode??"",o=t.data.verification_uri??t.data.verificationUri??"";if(!r||!n||!o)throw Pe("API_REQUEST_FAILED","server.v1 \u8FD4\u56DE\u4E86\u4E0D\u5B8C\u6574\u7684\u8BBE\u5907\u767B\u5F55\u4FE1\u606F",{status:t.status,source:"auth",details:{method:t.config.method,endpoint:J(t.config.url,t.config.baseURL),statusText:t.statusText,requestId:ze(t.headers)}});return{deviceCode:r,userCode:n,verificationUri:o,expiresIn:dc(t.data.credential_expires_at??t.data.credentialExpiresAt),interval:t.data.poll_interval_seconds??t.data.pollIntervalSeconds??5}}async function Bo(e){let t=await j.post("/auth/device-flow/poll",{device_code:e});return{status:pc(t.data.credential_device_state??t.data.credentialDeviceState),interval:5,sessionId:t.data.session_token??t.data.sessionToken}}async function Wo(e){let t=await j.post("/auth/access-keys/session",{credential_token:e}),r=t.data.session_token??t.data.sessionToken;if(!r)throw Pe("API_REQUEST_FAILED","AccessKey \u767B\u5F55\u6210\u529F\uFF0C\u4F46 server.v1 \u672A\u8FD4\u56DE session_token",{status:t.status,source:"auth",details:{method:t.config.method,endpoint:J(t.config.url,t.config.baseURL),statusText:t.statusText,requestId:ze(t.headers),bodySnippet:t.data}});return{sessionId:r}}function fc(e){return e.endsWith("/")?e.slice(0,-1):e}var mc="OJO_AUTH_WEB_ORIGIN",gc="IRISE_AUTH_WEB_ORIGIN",hc="OJO_LOGIN_PAGE",yc="IRISE_LOGIN_PAGE",_c="OJO_OAUTH_REDIRECT_URI",wc="IRISE_OAUTH_REDIRECT_URI",Re=fc(process.env[mc]??process.env[gc]??process.env.NEXIGHT_AUTH_WEB_ORIGIN??"https://ojo.art"),it=process.env[hc]??process.env[yc]??process.env.NEXIGHT_LOGIN_PAGE??`${Re}/login/cli`,Ne=`${Re}/dashboard?openAccessKeyManager=1`,Ic=process.env[_c]??process.env[wc]??process.env.NEXIGHT_OAUTH_REDIRECT_URI??Re;function Ur(e){try{let t=new URL(e,`${Re}/`),r=new URL(Re);return t.protocol=r.protocol,t.host=r.host,(t.pathname==="/login/cli"||t.pathname==="/login/cli/device")&&t.searchParams.set("framework","irise"),t.toString()}catch{return e}}var Ut=q();async function zo(e,t){await je({sessionId:e,cookie:Cr(e),accessKeyToken:t?.accessKeyToken})}function $r(e){let t=new URL(it);return t.searchParams.set("redirect_uri",e.redirectUri),t.searchParams.set("state",e.state),t.searchParams.set("framework","irise"),t.toString()}async function Fr(e){let t=await Ho(e);return{...t,verificationUri:Ur(t.verificationUri)}}async function Gr(e){let t=await Bo(e);return t.status==="approved"&&t.sessionId&&await zo(t.sessionId),t}async function Hr(e){let t=e.trim();if(!t)throw Ut.track("sys_auth_login_failed",{mode:"access-key",errorCode:"INVALID_REQUEST"}),new Error(`AccessKey \u4E0D\u80FD\u4E3A\u7A7A\u3002\u8BF7\u524D\u5F80 ${Ne} \u83B7\u53D6 AccessKey\u3002`);try{let r=await Wo(t);return await zo(r.sessionId,{accessKeyToken:t}),Ut.track("sys_auth_login",{mode:"access-key"}),r}catch(r){throw Ut.track("sys_auth_login_failed",{mode:"access-key",errorCode:W(r)}),r}}async function Br(){return await lo(),Ut.track("sys_auth_logout"),{success:!0}}import*as Qo from"fs/promises";import*as Kr from"path";import{existsSync as Wr,mkdirSync as Pc,readFileSync as Rc,writeFileSync as vc}from"fs";import{dirname as $t,join as Jo,resolve as Ft}from"path";var kc=".ojo",Ac=".irise";var zr="project.json",at="\u672A\u627E\u5230\u9879\u76EE\u6839 .ojo/project.json\uFF0C\u8BF7\u5148\u6267\u884C OJO workspace sync <projectId|projectUrl> \u5EFA\u7ACB\u672C\u5730\u9879\u76EE\u76EE\u5F55",Gt="WORKSPACE_NOT_INITIALIZED",Vo="\u5F53\u524D\u76EE\u5F55\u4E0D\u662F\u5DE5\u4F5C\u533A\u57DF\uFF0C\u8BF7\u5148\u6267\u884C OJO workspace sync <projectId|projectUrl> \u5EFA\u7ACB\u672C\u5730\u9879\u76EE\u76EE\u5F55";function qe(e){if(typeof e!="string")return null;let t=e.trim();return t.length>0?t:null}function Ec(e){if(!e||typeof e!="object")return{};let t=e,r=qe(t.workspace_hash)??void 0,n=qe(t.source_task_id)??void 0,o=qe(t.downloaded_at)??void 0;return{workspace_hash:r,source_task_id:n,downloaded_at:o}}function Jr(e){if(!e||typeof e!="object")return null;let t=e;if(t.version!==1)return null;let r=qe(t.project_id),n=qe(t.project_name);if(!r||!n)return null;let o=t.thread_id,s=o==null?null:qe(o);return o!=null&&s===null?null:{version:1,project_id:r,project_name:n,thread_id:s,workspace:Ec(t.workspace)}}function Ht(e){return Jo(Ft(e),kc,zr)}function Ko(e){return Jo(Ft(e),Ac,zr)}function Vr(e){let t=Ht(e);if(Wr(t))return t;let r=Ko(e);return Wr(r)?r:t}function ct(e){let t=Rc(e,"utf-8"),r=Jr(JSON.parse(t));if(!r)throw new Error(at);return{rootDir:$t($t(e)),filePath:e,data:r}}function ve(e=process.cwd()){let t=Ft(e);for(;;){let r=[Ht(t),Ko(t)];for(let o of r)if(Wr(o))try{return ct(o)}catch{return null}let n=$t(t);if(n===t)return null;t=n}}function ut(e,t){let r=Ft(e),n=Ht(r);return Pc($t(n),{recursive:!0}),vc(n,`${JSON.stringify(t,null,2)}
|
|
104
|
+
`,"utf8"),{rootDir:r,filePath:n,data:t}}function dt(e,t){let r=ct(Vr(e)),n=Jr(t(r.data));if(!n)throw new Error(at);return ut(r.rootDir,n)}function qo(e=process.cwd()){let t=ve(e);if(t)return t;throw new m(Gt,Vo,{status:400,details:{cwd:e}})}var qr={};Kn(qr,{JsonPatchError:()=>O,_areEquals:()=>ft,applyOperation:()=>Le,applyPatch:()=>qt,applyReducer:()=>Oc,deepClone:()=>bc,getValueByPointer:()=>Vt,validate:()=>Xo,validator:()=>Kt});var Cc=(function(){var e=function(t,r){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,o){n.__proto__=o}||function(n,o){for(var s in o)o.hasOwnProperty(s)&&(n[s]=o[s])},e(t,r)};return function(t,r){e(t,r);function n(){this.constructor=t}t.prototype=r===null?Object.create(r):(n.prototype=r.prototype,new n)}})(),Tc=Object.prototype.hasOwnProperty;function Wt(e,t){return Tc.call(e,t)}function zt(e){if(Array.isArray(e)){for(var t=new Array(e.length),r=0;r<t.length;r++)t[r]=""+r;return t}if(Object.keys)return Object.keys(e);var n=[];for(var o in e)Wt(e,o)&&n.push(o);return n}function F(e){switch(typeof e){case"object":return JSON.parse(JSON.stringify(e));case"undefined":return null;default:return e}}function Jt(e){for(var t=0,r=e.length,n;t<r;){if(n=e.charCodeAt(t),n>=48&&n<=57){t++;continue}return!1}return!0}function he(e){return e.indexOf("/")===-1&&e.indexOf("~")===-1?e:e.replace(/~/g,"~0").replace(/\//g,"~1")}function pt(e){return e.replace(/~1/g,"/").replace(/~0/g,"~")}function Bt(e){if(e===void 0)return!0;if(e){if(Array.isArray(e)){for(var t=0,r=e.length;t<r;t++)if(Bt(e[t]))return!0}else if(typeof e=="object"){for(var n=zt(e),o=n.length,s=0;s<o;s++)if(Bt(e[n[s]]))return!0}}return!1}function Yo(e,t){var r=[e];for(var n in t){var o=typeof t[n]=="object"?JSON.stringify(t[n],null,2):t[n];typeof o<"u"&&r.push(n+": "+o)}return r.join(`
|
|
105
|
+
`)}var lt=(function(e){Cc(t,e);function t(r,n,o,s,i){var a=this.constructor,c=e.call(this,Yo(r,{name:n,index:o,operation:s,tree:i}))||this;return c.name=n,c.index=o,c.operation=s,c.tree=i,Object.setPrototypeOf(c,a.prototype),c.message=Yo(r,{name:n,index:o,operation:s,tree:i}),c}return t})(Error);var O=lt,bc=F,Qe={add:function(e,t,r){return e[t]=this.value,{newDocument:r}},remove:function(e,t,r){var n=e[t];return delete e[t],{newDocument:r,removed:n}},replace:function(e,t,r){var n=e[t];return e[t]=this.value,{newDocument:r,removed:n}},move:function(e,t,r){var n=Vt(r,this.path);n&&(n=F(n));var o=Le(r,{op:"remove",path:this.from}).removed;return Le(r,{op:"add",path:this.path,value:o}),{newDocument:r,removed:n}},copy:function(e,t,r){var n=Vt(r,this.from);return Le(r,{op:"add",path:this.path,value:F(n)}),{newDocument:r}},test:function(e,t,r){return{newDocument:r,test:ft(e[t],this.value)}},_get:function(e,t,r){return this.value=e[t],{newDocument:r}}},jc={add:function(e,t,r){return Jt(t)?e.splice(t,0,this.value):e[t]=this.value,{newDocument:r,index:t}},remove:function(e,t,r){var n=e.splice(t,1);return{newDocument:r,removed:n[0]}},replace:function(e,t,r){var n=e[t];return e[t]=this.value,{newDocument:r,removed:n}},move:Qe.move,copy:Qe.copy,test:Qe.test,_get:Qe._get};function Vt(e,t){if(t=="")return e;var r={op:"_get",path:t};return Le(e,r),r.value}function Le(e,t,r,n,o,s){if(r===void 0&&(r=!1),n===void 0&&(n=!0),o===void 0&&(o=!0),s===void 0&&(s=0),r&&(typeof r=="function"?r(t,0,e,t.path):Kt(t,0)),t.path===""){var i={newDocument:e};if(t.op==="add")return i.newDocument=t.value,i;if(t.op==="replace")return i.newDocument=t.value,i.removed=e,i;if(t.op==="move"||t.op==="copy")return i.newDocument=Vt(e,t.from),t.op==="move"&&(i.removed=e),i;if(t.op==="test"){if(i.test=ft(e,t.value),i.test===!1)throw new O("Test operation failed","TEST_OPERATION_FAILED",s,t,e);return i.newDocument=e,i}else{if(t.op==="remove")return i.removed=e,i.newDocument=null,i;if(t.op==="_get")return t.value=e,i;if(r)throw new O("Operation `op` property is not one of operations defined in RFC-6902","OPERATION_OP_INVALID",s,t,e);return i}}else{n||(e=F(e));var a=t.path||"",c=a.split("/"),u=e,d=1,p=c.length,f=void 0,l=void 0,h=void 0;for(typeof r=="function"?h=r:h=Kt;;){if(l=c[d],l&&l.indexOf("~")!=-1&&(l=pt(l)),o&&(l=="__proto__"||l=="prototype"&&d>0&&c[d-1]=="constructor"))throw new TypeError("JSON-Patch: modifying `__proto__` or `constructor/prototype` prop is banned for security reasons, if this was on purpose, please set `banPrototypeModifications` flag false and pass it to this function. More info in fast-json-patch README");if(r&&f===void 0&&(u[l]===void 0?f=c.slice(0,d).join("/"):d==p-1&&(f=t.path),f!==void 0&&h(t,0,e,f)),d++,Array.isArray(u)){if(l==="-")l=u.length;else{if(r&&!Jt(l))throw new O("Expected an unsigned base-10 integer value, making the new referenced value the array element with the zero-based index","OPERATION_PATH_ILLEGAL_ARRAY_INDEX",s,t,e);Jt(l)&&(l=~~l)}if(d>=p){if(r&&t.op==="add"&&l>u.length)throw new O("The specified index MUST NOT be greater than the number of elements in the array","OPERATION_VALUE_OUT_OF_BOUNDS",s,t,e);var i=jc[t.op].call(t,u,l,e);if(i.test===!1)throw new O("Test operation failed","TEST_OPERATION_FAILED",s,t,e);return i}}else if(d>=p){var i=Qe[t.op].call(t,u,l,e);if(i.test===!1)throw new O("Test operation failed","TEST_OPERATION_FAILED",s,t,e);return i}if(u=u[l],r&&d<p&&(!u||typeof u!="object"))throw new O("Cannot perform operation at the desired path","OPERATION_PATH_UNRESOLVABLE",s,t,e)}}}function qt(e,t,r,n,o){if(n===void 0&&(n=!0),o===void 0&&(o=!0),r&&!Array.isArray(t))throw new O("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");n||(e=F(e));for(var s=new Array(t.length),i=0,a=t.length;i<a;i++)s[i]=Le(e,t[i],r,!0,o,i),e=s[i].newDocument;return s.newDocument=e,s}function Oc(e,t,r){var n=Le(e,t);if(n.test===!1)throw new O("Test operation failed","TEST_OPERATION_FAILED",r,t,e);return n.newDocument}function Kt(e,t,r,n){if(typeof e!="object"||e===null||Array.isArray(e))throw new O("Operation is not an object","OPERATION_NOT_AN_OBJECT",t,e,r);if(Qe[e.op]){if(typeof e.path!="string")throw new O("Operation `path` property is not a string","OPERATION_PATH_INVALID",t,e,r);if(e.path.indexOf("/")!==0&&e.path.length>0)throw new O('Operation `path` property must start with "/"',"OPERATION_PATH_INVALID",t,e,r);if((e.op==="move"||e.op==="copy")&&typeof e.from!="string")throw new O("Operation `from` property is not present (applicable in `move` and `copy` operations)","OPERATION_FROM_REQUIRED",t,e,r);if((e.op==="add"||e.op==="replace"||e.op==="test")&&e.value===void 0)throw new O("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_REQUIRED",t,e,r);if((e.op==="add"||e.op==="replace"||e.op==="test")&&Bt(e.value))throw new O("Operation `value` property is not present (applicable in `add`, `replace` and `test` operations)","OPERATION_VALUE_CANNOT_CONTAIN_UNDEFINED",t,e,r);if(r){if(e.op=="add"){var o=e.path.split("/").length,s=n.split("/").length;if(o!==s+1&&o!==s)throw new O("Cannot perform an `add` operation at the desired path","OPERATION_PATH_CANNOT_ADD",t,e,r)}else if(e.op==="replace"||e.op==="remove"||e.op==="_get"){if(e.path!==n)throw new O("Cannot perform the operation at a path that does not exist","OPERATION_PATH_UNRESOLVABLE",t,e,r)}else if(e.op==="move"||e.op==="copy"){var i={op:"_get",path:e.from,value:void 0},a=Xo([i],r);if(a&&a.name==="OPERATION_PATH_UNRESOLVABLE")throw new O("Cannot perform the operation from a path that does not exist","OPERATION_FROM_UNRESOLVABLE",t,e,r)}}}else throw new O("Operation `op` property is not one of operations defined in RFC-6902","OPERATION_OP_INVALID",t,e,r)}function Xo(e,t,r){try{if(!Array.isArray(e))throw new O("Patch sequence must be an array","SEQUENCE_NOT_AN_ARRAY");if(t)qt(F(t),F(e),r||!0);else{r=r||Kt;for(var n=0;n<e.length;n++)r(e[n],n,t,void 0)}}catch(o){if(o instanceof O)return o;throw o}}function ft(e,t){if(e===t)return!0;if(e&&t&&typeof e=="object"&&typeof t=="object"){var r=Array.isArray(e),n=Array.isArray(t),o,s,i;if(r&&n){if(s=e.length,s!=t.length)return!1;for(o=s;o--!==0;)if(!ft(e[o],t[o]))return!1;return!0}if(r!=n)return!1;var a=Object.keys(e);if(s=a.length,s!==Object.keys(t).length)return!1;for(o=s;o--!==0;)if(!t.hasOwnProperty(a[o]))return!1;for(o=s;o--!==0;)if(i=a[o],!ft(e[i],t[i]))return!1;return!0}return e!==e&&t!==t}var Zr={};Kn(Zr,{compare:()=>Gc,generate:()=>Qr,observe:()=>Fc,unobserve:()=>$c});var Yr=new WeakMap,Nc=(function(){function e(t){this.observers=new Map,this.obj=t}return e})(),Lc=(function(){function e(t,r){this.callback=t,this.observer=r}return e})();function Mc(e){return Yr.get(e)}function Dc(e,t){return e.observers.get(t)}function Uc(e,t){e.observers.delete(t.callback)}function $c(e,t){t.unobserve()}function Fc(e,t){var r=[],n,o=Mc(e);if(!o)o=new Nc(e),Yr.set(e,o);else{var s=Dc(o,t);n=s&&s.observer}if(n)return n;if(n={},o.value=F(e),t){n.callback=t,n.next=null;var i=function(){Qr(n)},a=function(){clearTimeout(n.next),n.next=setTimeout(i)};typeof window<"u"&&(window.addEventListener("mouseup",a),window.addEventListener("keyup",a),window.addEventListener("mousedown",a),window.addEventListener("keydown",a),window.addEventListener("change",a))}return n.patches=r,n.object=e,n.unobserve=function(){Qr(n),clearTimeout(n.next),Uc(o,n),typeof window<"u"&&(window.removeEventListener("mouseup",a),window.removeEventListener("keyup",a),window.removeEventListener("mousedown",a),window.removeEventListener("keydown",a),window.removeEventListener("change",a))},o.observers.set(t,new Lc(t,n)),n}function Qr(e,t){t===void 0&&(t=!1);var r=Yr.get(e.object);Xr(r.value,e.object,e.patches,"",t),e.patches.length&&qt(r.value,e.patches);var n=e.patches;return n.length>0&&(e.patches=[],e.callback&&e.callback(n)),n}function Xr(e,t,r,n,o){if(t!==e){typeof t.toJSON=="function"&&(t=t.toJSON());for(var s=zt(t),i=zt(e),a=!1,c=!1,u=i.length-1;u>=0;u--){var d=i[u],p=e[d];if(Wt(t,d)&&!(t[d]===void 0&&p!==void 0&&Array.isArray(t)===!1)){var f=t[d];typeof p=="object"&&p!=null&&typeof f=="object"&&f!=null&&Array.isArray(p)===Array.isArray(f)?Xr(p,f,r,n+"/"+he(d),o):p!==f&&(a=!0,o&&r.push({op:"test",path:n+"/"+he(d),value:F(p)}),r.push({op:"replace",path:n+"/"+he(d),value:F(f)}))}else Array.isArray(e)===Array.isArray(t)?(o&&r.push({op:"test",path:n+"/"+he(d),value:F(p)}),r.push({op:"remove",path:n+"/"+he(d)}),c=!0):(o&&r.push({op:"test",path:n,value:e}),r.push({op:"replace",path:n,value:t}),a=!0)}if(!(!c&&s.length==i.length))for(var u=0;u<s.length;u++){var d=s[u];!Wt(e,d)&&t[d]!==void 0&&r.push({op:"add",path:n+"/"+he(d),value:F(t[d])})}}}function Gc(e,t,r){r===void 0&&(r=!1);var n=[];return Xr(e,t,n,"",r),n}var Zo=Object.assign({},qr,Zr,{JsonPatchError:lt,deepClone:F,escapePathComponent:he,unescapePathComponent:pt});function G(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:{}}function M(...e){return e.find(t=>typeof t=="string"&&t.length>0)??""}function tn(e){if(typeof e!="string")return e;try{return JSON.parse(e)}catch{return e}}function en(e,t){let r=Array.isArray(e.content)?[...e.content]:typeof e.content=="string"&&e.content?[{type:"answer",text:e.content}]:[],n=r.findIndex(o=>o?.type===t.type);if(n<0)r.push(t);else{let o=r[n];r[n]={...o,...t,...t.text===void 0?{}:{text:(o.text??"")+t.text}}}e.content=r}function Qt(e,t,r,n=!1){let o=G(t),s=G(o.metadata),i=M(o.id,s.messageId),a=M(o.role);!i||!a||!n&&e.has(i)||e.set(i,{...e.get(i),...o,id:i,role:a,content:o.content??e.get(i)?.content??"",metadata:{runId:r,...e.get(i)?.metadata,...s}})}function Hc(e,t,r,n){let o=new Map;for(let s of t){let i=G(s);if(!(i.role!=="assistant"||!Array.isArray(i.toolCalls)))for(let a of i.toolCalls){let c=G(a),u=M(c.id);u&&o.set(u,G(c.function))}}for(let s of t){let i=G(s);if(i.role==="system"||n&&i.role==="activity")continue;let a=o.get(M(i.toolCallId));if(i.role==="tool"&&a){let c=G(i.metadata);Qt(e,{...i,metadata:{...c,sdk:{toolName:M(a.name)||"tool",arguments:tn(a.arguments),...G(c.sdk)}}},r)}else Qt(e,i,r)}}function Bc(e,t,r,n){let o=M(r.messageId,r.message_id,r.id);if(!o)return;let s=e.get(o);if(!s&&t.endsWith("_END")&&r.content===void 0)return;let i=s?.role??(M(r.role)||"assistant"),a=s??{id:o,role:i,content:"",metadata:{runId:n}};if(a.metadata={...a.metadata,...G(r.metadata)},t==="INSPIRE_QUESTION_CONTENT"){let c=G(r.content).questions??r.questions;if(!Array.isArray(c))return;en(a,{type:"inspire_questions",questions:c.filter(u=>typeof u=="string")})}else if(t==="MEMORY_CONFIRM_CONTENT"){let c=G(r.content),u=G(c.memory);if(typeof u.displayText!="string")return;en(a,{type:"memory_confirm",memory:u,status:M(c.status)||"pending"})}else if(t==="TEXT_MESSAGE_START"&&!s)a.content=r.content??"";else if(t.endsWith("_CONTENT")||t.endsWith("_CHUNK")){let c=M(r.delta,r.content,r.text);if(i==="assistant"){let u=t.startsWith("REASONING_")?"thinking":t.startsWith("ASK_TO_CONTINUE_")?"ask_to_continue":"answer";u==="answer"&&typeof a.content=="string"?a.content+=c:c&&en(a,{type:u,text:c})}else c&&(a.content=M(a.content)+c)}else t==="TEXT_MESSAGE_END"&&!a.content&&r.content!==void 0&&(a.content=r.content);e.set(o,a)}function Wc(e,t,r,n,o){let s=M(n.toolCallId,n.tool_call_id,n.id);if(!s)return;let i=e.get(`tool_${s}`)??[...e.values()].find(f=>f.toolCallId===s&&f.role==="tool"),a=i?.id??`tool_${s}`,c=i??{id:a,role:"tool",content:"",toolCallId:s,metadata:{runId:o}},u={...c.metadata?.sdk},d=M(n.toolName,n.toolCallName,n.name,u.toolName),p=M(n.parentMessageId,c.parentMessageId);if(d&&(u.toolName=d),r==="TOOL_CALL_START")u.status??="init",u.arguments=n.arguments??n.args??u.arguments;else if(r==="TOOL_CALL_ARGS"||r==="TOOL_CALL_CHUNK"){let f=(t.get(a)??"")+M(n.delta);t.set(a,f);let l=tn(f);u.arguments=n.arguments??n.args??(typeof l=="string"?u.arguments:l)}else if(r==="TOOL_CALL_RESULT"||r==="TOOL_CALL_END"&&n.result!==void 0){let f=n.result??n.content;f!==void 0&&(c.content=f,u.result=tn(f)),u.status=n.isError===!0||n.is_error===!0||G(u.result).status==="error"?"error":"completed"}else r==="TOOL_CALL_END"&&(u.status==="init"||!u.status)&&(u.status="running");e.set(a,{...c,...p?{parentMessageId:p}:{},metadata:{...c.metadata,...G(n.metadata),sdk:u}})}function zc(e,t){let r=M(t.messageId,t.message_id),n=e.get(r);if(!(n?.role!=="activity"||!Array.isArray(t.patch)))try{let o=Zo.applyPatch(structuredClone(n.content??{}),t.patch,!0).newDocument;o!=null&&e.set(r,{...n,content:o})}catch{}}var Jc=/^(TEXT_MESSAGE|REASONING_MESSAGE|ASK_TO_CONTINUE)_(START|CONTENT|CHUNK|END)$/;function mt(e){let t=new Map,r=new Map;for(let n of e.items){let o=n.some(s=>M(s.eventType,G(s.payload).type)==="RUN_ERROR");for(let s of n){let i=G(s.payload),a=M(s.runId,i.runId,i.run_id),c=M(s.eventType,i.type);if(c==="MESSAGES_SNAPSHOT"||c==="RUN_FINISHED"){let u=i.messages??G(i.snapshot).messages;Array.isArray(u)&&Hc(t,u,a,o)}else Jc.test(c)||c==="INSPIRE_QUESTION_CONTENT"||c==="MEMORY_CONFIRM_CONTENT"?Bc(t,c,i,a):c.startsWith("TOOL_CALL_")?Wc(t,r,c,i,a):c==="ACTIVITY_SNAPSHOT"?Qt(t,{id:M(i.messageId,i.message_id),role:"activity",content:i.content??{},activityType:i.activityType??"unknown"},a,i.replace!==!1):c==="ACTIVITY_DELTA"?zc(t,i):Qt(t,s.message??i,a)}}return[...t.values()]}import{Readable as on}from"stream";import nu from"axios";import{createHash as mg,randomBytes as Vc}from"crypto";function Yt(){return Vc(16).toString("base64url")}import{createServer as Kc}from"http";import{parse as qc}from"url";var es=38473,Qc=38492,gt="127.0.0.1",Yc=es,Xc=Qc-es+1,Zc=gt,eu=`<svg aria-hidden="true" focusable="false" width="800" height="500" viewBox="0 0 800 500" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
106
|
+
<path d="M627.303 387.656C606.1 387.656 586.548 383.938 568.649 376.503C550.75 369.068 535.054 358.742 521.561 345.524C508.343 332.031 498.154 316.197 490.995 298.023C483.835 279.573 480.255 259.609 480.255 238.13C480.255 216.375 483.835 196.549 490.995 178.649C498.154 160.475 508.343 144.641 521.561 131.148C535.054 117.655 550.75 107.191 568.649 99.7557C586.548 92.3207 606.1 88.6032 627.303 88.6032C648.782 88.6032 668.333 92.3207 685.957 99.7557C703.856 107.191 719.415 117.655 732.632 131.148C746.126 144.641 756.452 160.475 763.612 178.649C770.771 196.824 774.351 216.651 774.351 238.13C774.351 259.609 770.771 279.435 763.612 297.61C756.452 315.784 746.126 331.618 732.632 345.111C719.415 358.604 703.856 369.068 685.957 376.503C668.333 383.938 648.782 387.656 627.303 387.656ZM627.303 329.002C639.419 329.002 650.572 326.799 660.761 322.393C671.225 317.987 680.174 311.654 687.609 303.392C695.044 295.131 700.827 285.493 704.958 274.479C709.364 263.464 711.567 251.347 711.567 238.13C711.567 224.912 709.364 212.795 704.958 201.781C700.827 190.766 695.044 181.266 687.609 173.28C680.174 165.019 671.225 158.685 660.761 154.279C650.572 149.598 639.419 147.257 627.303 147.257C615.187 147.257 604.034 149.598 593.846 154.279C583.657 158.685 574.707 165.019 566.997 173.28C559.287 181.266 553.366 190.766 549.236 201.781C545.38 212.795 543.453 224.912 543.453 238.13C543.453 251.347 545.38 263.464 549.236 274.479C553.366 285.493 559.287 295.131 566.997 303.392C574.707 311.654 583.657 317.987 593.846 322.393C604.034 326.799 615.187 329.002 627.303 329.002Z" fill="black"/>
|
|
107
|
+
<path d="M345.668 468.615L323.776 423.179C335.617 423.179 345.118 421.527 352.277 418.222C359.437 414.918 364.531 409.41 367.56 401.7C370.865 394.265 372.517 384.352 372.517 371.96V165.019H431.171V386.004C431.171 404.178 427.729 419.324 420.845 431.44C414.236 443.556 404.598 452.781 391.931 459.115C379.264 465.448 363.843 468.615 345.668 468.615Z" fill="black"/>
|
|
108
|
+
<path d="M172.698 387.656C151.495 387.656 131.943 383.938 114.044 376.503C96.1451 369.068 80.4489 358.742 66.9558 345.524C53.738 332.031 43.5492 316.197 36.3896 298.023C29.23 279.573 25.6501 259.609 25.6501 238.13C25.6501 216.375 29.23 196.549 36.3896 178.649C43.5492 160.475 53.738 144.641 66.9558 131.148C80.4489 117.655 96.1451 107.191 114.044 99.7557C131.943 92.3207 151.495 88.6032 172.698 88.6032C194.177 88.6032 213.728 92.3207 231.352 99.7557C249.251 107.191 264.81 117.655 278.027 131.148C291.521 144.641 301.847 160.475 309.007 178.649C316.166 196.824 319.746 216.651 319.746 238.13C319.746 259.609 316.166 279.435 309.007 297.61C301.847 315.784 291.521 331.618 278.027 345.111C264.81 358.604 249.251 369.068 231.352 376.503C213.728 383.938 194.177 387.656 172.698 387.656ZM172.698 329.002C184.814 329.002 195.967 326.799 206.156 322.393C216.62 317.987 225.569 311.654 233.004 303.392C240.439 295.131 246.222 285.493 250.353 274.479C254.759 263.464 256.962 251.347 256.962 238.13C256.962 224.912 254.759 212.795 250.353 201.781C246.222 190.766 240.439 181.266 233.004 173.28C225.569 165.019 216.62 158.685 206.156 154.279C195.967 149.598 184.814 147.257 172.698 147.257C160.582 147.257 149.429 149.598 139.241 154.279C129.052 158.685 120.102 165.019 112.392 173.28C104.682 181.266 98.7611 190.766 94.6305 201.781C90.7754 212.795 88.8478 224.912 88.8478 238.13C88.8478 251.347 90.7754 263.464 94.6305 274.479C98.7611 285.493 104.682 295.131 112.392 303.392C120.102 311.654 129.052 317.987 139.241 322.393C149.429 326.799 160.582 329.002 172.698 329.002Z" fill="black"/>
|
|
109
|
+
<path d="M396.014 18.7749C397.383 15.075 402.617 15.075 403.986 18.7749L410.227 35.6428C415.393 49.6017 426.398 60.6074 440.357 65.7727L457.225 72.0144C460.925 73.3835 460.925 78.6165 457.225 79.9856L440.357 86.2273C426.398 91.3926 415.393 102.398 410.227 116.357L403.986 133.225C402.617 136.925 397.383 136.925 396.014 133.225L389.773 116.357C384.607 102.398 373.602 91.3926 359.643 86.2273L342.775 79.9856C339.075 78.6165 339.075 73.3835 342.775 72.0144L359.643 65.7727C373.602 60.6074 384.607 49.6017 389.773 35.6428L396.014 18.7749Z" fill="black"/>
|
|
110
|
+
</svg>`,Ig=`
|
|
111
|
+
<!DOCTYPE html>
|
|
112
|
+
<html lang="zh-CN">
|
|
113
|
+
<head><meta charset="utf-8"><title>\u767B\u5F55\u6210\u529F</title></head>
|
|
114
|
+
<body>
|
|
115
|
+
<style>
|
|
116
|
+
:root {
|
|
117
|
+
color-scheme: light;
|
|
118
|
+
--bg: #f5f6f8;
|
|
119
|
+
--panel: rgba(255, 255, 255, 0.86);
|
|
120
|
+
--panel-border: rgba(17, 24, 39, 0.08);
|
|
121
|
+
--shadow: 0 24px 60px rgba(15, 23, 42, 0.12);
|
|
122
|
+
--text: #111111;
|
|
123
|
+
--muted: #667085;
|
|
124
|
+
--accent: #111111;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
* {
|
|
128
|
+
box-sizing: border-box;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
body {
|
|
132
|
+
margin: 0;
|
|
133
|
+
min-height: 100vh;
|
|
134
|
+
display: grid;
|
|
135
|
+
place-items: center;
|
|
136
|
+
padding: 32px 20px;
|
|
137
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
|
138
|
+
color: var(--text);
|
|
139
|
+
background:
|
|
140
|
+
radial-gradient(circle at top, rgba(17, 17, 17, 0.06), transparent 30%),
|
|
141
|
+
linear-gradient(180deg, #fafafa 0%, var(--bg) 100%);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.shell {
|
|
145
|
+
width: min(100%, 560px);
|
|
146
|
+
padding: 40px 36px;
|
|
147
|
+
border: 1px solid rgba(17, 24, 39, 0.06);
|
|
148
|
+
border-radius: 26px;
|
|
149
|
+
background: var(--panel);
|
|
150
|
+
box-shadow: var(--shadow);
|
|
151
|
+
text-align: center;
|
|
152
|
+
backdrop-filter: blur(18px);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
.logo-box {
|
|
156
|
+
width: 80px;
|
|
157
|
+
height: 80px;
|
|
158
|
+
margin: 0 auto 20px;
|
|
159
|
+
display: grid;
|
|
160
|
+
place-items: center;
|
|
161
|
+
border-radius: 22px;
|
|
162
|
+
background: #ffffff;
|
|
163
|
+
box-shadow:
|
|
164
|
+
inset 0 1px 0 rgba(255, 255, 255, 0.9),
|
|
165
|
+
0 10px 30px rgba(17, 24, 39, 0.08);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
.logo {
|
|
169
|
+
width: 48px;
|
|
170
|
+
display: flex;
|
|
171
|
+
justify-content: center;
|
|
172
|
+
align-items: center;
|
|
173
|
+
margin: 0 auto;
|
|
174
|
+
color: var(--accent);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
.logo svg {
|
|
178
|
+
display: block;
|
|
179
|
+
width: 100%;
|
|
180
|
+
height: auto;
|
|
181
|
+
max-width: 100%;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
h1 {
|
|
185
|
+
margin: 0;
|
|
186
|
+
font-size: clamp(28px, 4vw, 36px);
|
|
187
|
+
line-height: 1.12;
|
|
188
|
+
letter-spacing: -0.04em;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
.subtitle {
|
|
192
|
+
margin: 16px auto 0;
|
|
193
|
+
max-width: 420px;
|
|
194
|
+
font-size: 16px;
|
|
195
|
+
line-height: 1.75;
|
|
196
|
+
color: var(--muted);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
@media (max-width: 640px) {
|
|
200
|
+
.shell {
|
|
201
|
+
padding: 32px 24px;
|
|
202
|
+
border-radius: 24px;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
.subtitle {
|
|
206
|
+
font-size: 16px;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
</style>
|
|
210
|
+
<main class="shell">
|
|
211
|
+
<div class="logo-box">
|
|
212
|
+
<div class="logo">${eu}</div>
|
|
213
|
+
</div>
|
|
214
|
+
<h1>\u5DF2\u767B\u5F55 OJO</h1>
|
|
215
|
+
<p class="subtitle">
|
|
216
|
+
\u5F53\u524D\u8D26\u53F7\u5DF2\u5B8C\u6210\u6388\u6743\u3002
|
|
217
|
+
\u4F60\u53EF\u4EE5\u76F4\u63A5\u56DE\u5230\u7F16\u8F91\u5668\u6216\u7EC8\u7AEF\uFF0C\u7EE7\u7EED\u4F7F\u7528 OJO \u8BBF\u95EE\u9879\u76EE\u3001\u53D1\u8D77\u4F1A\u8BDD\u548C\u67E5\u770B\u5386\u53F2\u8BB0\u5F55\u3002
|
|
218
|
+
</p>
|
|
219
|
+
</main>
|
|
220
|
+
</body>
|
|
221
|
+
</html>
|
|
222
|
+
`;function rn(e,t){let r={"Access-Control-Allow-Origin":e,"Access-Control-Allow-Methods":"GET, POST, OPTIONS","Access-Control-Allow-Headers":"Content-Type","Access-Control-Allow-Credentials":"true",Vary:"Origin"};return t?.["access-control-request-private-network"]==="true"&&(r["Access-Control-Allow-Private-Network"]="true",r.Vary="Origin, Access-Control-Request-Private-Network"),r}function V(e,t,r,n,o){e.writeHead(t,{...rn(n,o),"Content-Type":"application/json"}),e.end(JSON.stringify(r))}async function tu(e,t,r,n,o){let s=e.headers["set-cookie"]??null,i=ot(s);i&&(await Mt(i),n?.());let a=typeof e.data=="string"?e.data:JSON.stringify(e.data),c=e.status;t.writeHead(c,{...rn(r,o),"Content-Type":e.headers["content-type"]??"application/json"}),t.end(a)}function ru(e){return e&&e.match(/(?:^|;\s*)session_id=([^;]+)/)?.[1]?.trim()||null}function nn(e){return new Promise((t,r)=>{let n=Yc,o=0,s=()=>{let i=Kc(async(a,c)=>{let d=qc(a.url??"",!0).pathname??"/";e.logger?.info(`${a.method} ${d}`);let p=a.headers.origin??e.corsOrigin;if(a.method==="OPTIONS"){c.writeHead(204,rn(p,a.headers)),c.end();return}if(d==="/proxy/auth/firebase/login"&&a.method==="POST"){let f="";for await(let l of a)f+=l;try{let{idToken:l,state:h}=JSON.parse(f||"{}");if(!l||!h){V(c,400,{error:"Missing idToken or state"},p,a.headers);return}if(e.validateState&&!e.validateState(h)){V(c,400,{error:"Invalid state"},p,a.headers);return}let I=await e.onFirebaseLogin(l),y=I.data;if(y==null){V(c,500,{error:I.status>=200&&I.status<300?"Invalid response":`Request failed: ${I.status}`},p,a.headers);return}let _=ot(I.headers["set-cookie"]??null),b=ru(_);if(y.code!==0){V(c,I.status>=400?I.status:400,y,p,a.headers);return}if(!_||!b){V(c,500,{error:"Firebase login succeeded without session cookie"},p,a.headers);return}await je({sessionId:b,cookie:_}),e.onCallbackComplete?.(),V(c,I.status||200,y,p,a.headers)}catch(l){V(c,500,{error:l instanceof Error?l.message:"Firebase login failed"},p,a.headers)}return}if(d==="/proxy/auth/email/send-code"&&a.method==="POST"&&e.onEmailSendCode){let f="";for await(let l of a)f+=l;try{let{email:l}=JSON.parse(f||"{}");if(!l){V(c,400,{error:"Missing email"},p,a.headers);return}let h=await e.onEmailSendCode(l);await tu(h,c,p,void 0,a.headers)}catch(l){V(c,500,{error:l instanceof Error?l.message:"Send code failed"},p,a.headers)}return}if(d==="/proxy/auth/email/verify"&&a.method==="POST"&&e.onEmailVerify){let f="";for await(let l of a)f+=l;try{let{email:l,code:h}=JSON.parse(f||"{}");if(!l||!h){V(c,400,{error:"Missing email or code"},p,a.headers);return}let I=await e.onEmailVerify(l,h),y=I.data;if(y==null){V(c,500,{error:I.status>=200&&I.status<300?"Invalid response":`Request failed: ${I.status}`},p,a.headers);return}let _=y.data?.sessionId??y.data?.session_id;if(y.code!==0||!_){V(c,400,{error:y.errmsg??"Verify failed"},p,a.headers);return}await je({sessionId:_,cookie:`session_id=${_}`}),e.onCallbackComplete?.(),V(c,200,y,p,a.headers)}catch(l){V(c,500,{error:l instanceof Error?l.message:"Verify failed"},p,a.headers)}return}V(c,404,{error:"Not found"},p,a.headers)});i.on("error",a=>{a.code==="EADDRINUSE"&&o<Xc-1?(o++,n++,s()):r(a)}),i.listen(n,Zc,()=>{t({server:i,port:n})})};s()})}function ou(e){return typeof Request<"u"&&e instanceof Request}function ns(e){return!["GET","HEAD"].includes(e.toUpperCase())}function su(e){return(e.get("Accept")??e.get("accept")??"").toLowerCase().includes("text/event-stream")}function iu(e){return!e||typeof e!="object"?null:e instanceof on?e:typeof e[Symbol.asyncIterator]=="function"?on.from(e):null}function au(e){let t=iu(e);return t?on.toWeb(t):null}function cu(e){let t=new Headers;if(!e)return t;for(let[r,n]of Object.entries(e))if(n!=null){if(Array.isArray(n)){for(let o of n)t.append(r,String(o));continue}t.set(r,String(n))}return t}function ts(e,t){try{Object.defineProperty(e,"url",{configurable:!0,enumerable:!0,value:t})}catch{return e}return e}async function uu(e,t){if(!ns(t)||e.body==null)return;let n=await e.clone().arrayBuffer();return Buffer.from(n)}async function du(e,t){if(ou(e)){let s=t?new Request(e,t):e,i=(s.method||"GET").toUpperCase(),a=new Headers(s.headers),c=t?.body!==void 0?t.body:await uu(s,i);return{url:s.url,method:i,headers:a,body:c}}let r=e instanceof URL?e.toString():String(e),n=(t?.method??"GET").toUpperCase(),o=new Headers(t?.headers??{});return{url:r,method:n,headers:o,body:ns(n)?t?.body:void 0}}async function pu(e,t,r){if(!Oe(e))return t;let n=await r(),o=de({cookie:t.get("Cookie")??n?.cookie,sessionId:n?.sessionId});return o.cookie&&t.set("Cookie",o.cookie),o.sessionId&&!t.has("X-Ojo-Session-Id")&&t.set("X-Ojo-Session-Id",o.sessionId),o.sessionId&&!t.has("Authorization")&&t.set("Authorization",`Bearer ${o.sessionId}`),t}function lu(e){let t={};return e.forEach((r,n)=>{t[n]=r}),t}function rs(e){let t=new Uint8Array(e.byteLength);return t.set(e),t.buffer}function fu(e,t,r){let n=cu(e.headers);if(r){let i=au(e.data),a=new Response(i,{status:e.status,statusText:e.statusText,headers:n});return ts(a,t)}let o=e.data==null?null:Buffer.isBuffer(e.data)?rs(new Uint8Array(e.data)):e.data instanceof ArrayBuffer?e.data:ArrayBuffer.isView(e.data)?rs(new Uint8Array(e.data.buffer,e.data.byteOffset,e.data.byteLength)):typeof e.data=="string"?e.data:JSON.stringify(e.data),s=new Response(o,{status:e.status,statusText:e.statusText,headers:n});return ts(s,t)}function os(e={}){let t=e.httpClient??nu,r=e.timeoutMs,n=e.resolveCredentials??(()=>ue()),o=q();return async(s,i)=>{let a=await du(s,i),c=await pu(a.url,a.headers,n),u=su(c),d=Date.now(),p=J(a.url)??a.url,f=a.method.toUpperCase();try{let l=await t.request({url:a.url,method:a.method,headers:lu(c),data:a.body,responseType:u?"stream":"arraybuffer",timeout:r,validateStatus:()=>!0,withCredentials:!0,transitional:{forcedJSONParsing:!1}}),h=Date.now()-d;return l.status>=400?o.track("perf_api_error",{transport:"fetch-adapter",endpoint:p,method:f,statusCode:l.status,durationMs:h,errorCode:"HTTP_STATUS_ERROR",errorMsg:l.statusText}):o.track("perf_api_request",{transport:"fetch-adapter",endpoint:p,method:f,statusCode:l.status,durationMs:h}),fu(l,a.url,u)}catch(l){let h=Date.now()-d,I=W(l);throw(l&&typeof l=="object"&&"code"in l&&typeof l.code=="string"?l.code:void 0)==="ECONNABORTED"?o.track("perf_api_timeout",{transport:"fetch-adapter",endpoint:p,method:f,timeoutMs:r,durationMs:h}):o.track("perf_api_error",{transport:"fetch-adapter",endpoint:p,method:f,durationMs:h,errorCode:I,errorMsg:l instanceof Error?l.message:String(l)}),l}}}var mu=12e4,ae=process.env.OJO_AGENT_API_BASE??process.env.IRISE_AGENT_ENGINE_BASE??process.env.NEXIGHT_AGENT_ENGINE_BASE??B,gu={actorUserId:"actor_user_id",threadId:"thread_id",runId:"run_id",parentRunId:"parent_run_id",agentMode:"agent_mode",runKind:"run_kind",runProfileKey:"run_profile_key",runAttemptNumber:"run_attempt_number",teamId:"team_id",skillIds:"skill_ids",dynamicToolIds:"dynamic_tool_ids"},ss={projectId:"project_id",workspaceHash:"workspace_hash",referenceWorkspaceHash:"reference_workspace_hash",workspaceKey:"workspace_key",workspacePath:"workspace_path",workspaceZipPath:"workspace_zip_path",parentRunId:"parent_run_id"},hu=["selectedSkills","selected_skills","selectedSkillIds","selected_skill_ids","selectedTeamIds","selected_team_ids","dynamicSkillIds","dynamic_skill_ids","targetAgentId","target_agent_id"];function yu(){return os({timeoutMs:mu})}async function _u(e,t,r){let n,o=e.headers.get("content-type")??"";try{n=o.includes("application/json")?await e.json():await e.text()}catch{n=void 0}let s=kr(n);return Pe("AGENT_RUNTIME_REQUEST_FAILED",s.upstreamMessage??`Request failed: ${e.status} ${e.statusText}`,{status:e.status,source:"agent-runtime",details:{method:r?.method??"GET",endpoint:J(e.url)??as(t),statusText:e.statusText,requestId:ze({"x-request-id":e.headers.get("x-request-id"),"x-ojo-request-id":e.headers.get("x-ojo-request-id"),"request-id":e.headers.get("request-id")}),...s}})}function as(e){if(typeof e=="string")return J(e);if(e instanceof URL)return J(e.toString());if(typeof Request<"u"&&e instanceof Request)return J(e.url);if(e&&typeof e=="object"&&"url"in e&&typeof e.url=="string")return J(e.url)}async function Zt(e,t){let r=t?.method??"GET",n=as(e),o;try{o=await yu()(e,t)}catch(s){throw be(s,"AGENT_RUNTIME_REQUEST_FAILED","Agent runtime request failed",{source:"agent-runtime",details:{method:r,endpoint:n}})}if(!o.ok)throw await _u(o,e,t);return await o.json()}async function sn(e,t=20){let r=ae.endsWith("/")?ae.slice(0,-1):ae,n=new URLSearchParams({filter_project_id:e,page:"1",page_size:String(t)}),o=await Zt(`${r}/threads?${n.toString()}`,{method:"GET",headers:{"Content-Type":"application/json"}});return(Array.isArray(o.threads)?o.threads:Array.isArray(o.items)?o.items:[]).map(i=>Iu(i))}async function Ye(e,t){let r=ae.endsWith("/")?ae.slice(0,-1):ae,n=new URLSearchParams({limit:String(t.limit)});t.runId&&n.set("runId",t.runId);let o=await Zt(`${r}/threads/${encodeURIComponent(e)}/events?${n.toString()}`,{method:"GET",headers:{"Content-Type":"application/json"}});return Tu(o)}async function er(e){let t=e.trim();if(!t)throw new Error("runId is required");let r=ae.endsWith("/")?ae.slice(0,-1):ae,n=await Zt(`${r}/runs/${encodeURIComponent(t)}`,{method:"GET",headers:{"Content-Type":"application/json"}});return Ru(Pu(n))}async function cs(e){let t=ae.endsWith("/")?ae.slice(0,-1):ae,r=await Zt(`${t}/chats`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(xu(e))}),n=E(r,"run_id","runId"),o=E(r,"thread_id","threadId");if(!n||!o)throw new Error("CreateChat returned an incomplete server.v1 run");return{runId:n,threadId:o,status:"running"}}function ye(e){return!!e&&typeof e=="object"&&!Array.isArray(e)}function E(e,...t){if(ye(e))for(let r of t){let n=e[r];if(typeof n=="string"&&n.trim())return n.trim()}}function wu(e,...t){if(!ye(e))return 0;for(let r of t){let n=e[r];if(typeof n=="number"&&Number.isFinite(n))return n;if(typeof n=="string"&&n.trim()){let o=Number(n);if(Number.isFinite(o))return o}}return 0}function is(e,...t){if(ye(e))for(let r of t){let n=e[r];if(ye(n))return n}}function Iu(e){return{threadId:E(e,"thread_id","threadId")??"",projectId:E(e,"project_id","projectId")??"",title:E(e,"thread_title","threadTitle","title")??null,createdAt:E(e,"created_at","createdAt")??"",updatedAt:E(e,"updated_at","updatedAt","thread_last_activity_at","threadLastActivityAt")??""}}function Su(e){let t=typeof e=="string"?e.toUpperCase():e;return t===1||t===2||t==="RUN_STATUS_QUEUED"||t==="RUN_STATUS_RUNNING"?"running":t===3||t==="RUN_STATUS_SUCCEEDED"?"completed":t===5||t==="RUN_STATUS_CANCELLED"?"cancelled":"error"}function Pu(e){let t=E(e,"run_id","runId")??"",r=E(e,"thread_id","threadId")??"",n=Su(e.run_status??e.runStatus??e.status),o=E(e,"run_error_code","runErrorCode"),s=E(e,"run_error_message","runErrorMessage"),i=is(e,"run_output_json","runOutputJson"),a=E(i,"final_text","finalText","message","text"),c=is(i,"interrupt","agent_interrupt","agentInterrupt"),u=E(c,"id","interrupt_id","interruptId"),d=E(c,"reason")??"interrupt",p=E(c,"message")??a??"Run interrupted";return{runId:t,threadId:r,status:n,...n==="completed"?{outcome:c?"interrupt":"success"}:{},...a?{messages:[{id:`${t}:assistant-output`,role:"assistant",content:a}]}:{},...n==="error"&&(o||s)?{error:{code:o??"RUN_FAILED",message:s??"Run failed"}}:{},...c?{interrupt:{id:u??`${t}:interrupt`,reason:d,message:p,payload:c.payload}}:{},...E(i,"trace_url","traceUrl")?{traceUrl:E(i,"trace_url","traceUrl")}:{}}}async function Ru(e){if(e.status==="running"||!e.threadId||!e.runId)return e;try{let r=(await Ye(e.threadId,{limit:50})).items.find(o=>o[0]?.runId===e.runId);if(!r)return e;let n=mt({items:[r],hasMore:!1});return n.length>0?{...e,messages:n}:e}catch{return e}}function Xt(e,t){if(Array.isArray(e))return e.map(n=>Xt(n,t));if(!ye(e))return e;let r={};for(let[n,o]of Object.entries(e))r[n]=Xt(o,t);for(let[n,o]of Object.entries(t))r[o]===void 0&&r[n]!==void 0&&(r[o]=r[n]),delete r[n];return r}function vu(e,t){let r={...e};for(let[n,o]of Object.entries(t))r[o]===void 0&&r[n]!==void 0&&(r[o]=r[n]),delete r[n];return r}function ku(e){if(typeof e!="string"||!e.trim())return Xt(e,ss);try{let t=JSON.parse(e);return JSON.stringify(Xt(t,ss))}catch{return e}}function Au(e){let t={...e},r=Array.isArray(t.context)?t.context.map(o=>ye(o)&&"value"in o?{...o,value:ku(o.value)}:o):t.context;t.context=r;let n=vu(t,gu);for(let o of hu)delete n[o];return n}function Eu(e){for(let t of Array.isArray(e.context)?e.context:[]){if(!ye(t)||!("value"in t))continue;let r=t.value,n=r;if(typeof r=="string")try{n=JSON.parse(r)}catch{continue}let o=E(n,"workspace_hash","workspaceHash");if(o)return o}}function xu(e){let t=Au(e),r=e,n=Eu(e),o=E(t,"agent_mode")?.toLowerCase();return{thread_id:e.threadId,run_input_json:t,...e.parentRunId?{run_parent_run_id:e.parentRunId}:{},...n?{workspace_hash:n}:{},...o==="thinking"||o==="direct"?{agent_mode:o}:{},...typeof r.runKind=="number"?{run_kind:r.runKind}:{},...typeof r.runProfileKey=="string"?{run_profile_key:r.runProfileKey}:{},...typeof r.runAttemptNumber=="number"?{run_attempt_number:r.runAttemptNumber}:{}}}function Cu(e){if(!ye(e))return null;let t=E(e,"runId","run_id"),r=wu(e,"sequence","eventSeq","event_seq"),n=e.payload??e.eventPayloadJson??e.event_payload_json,o=ye(n)?{...n}:{},s=E(e,"eventType","event_type")??E(o,"type");return!t||r<=0||!s?null:{eventId:E(e,"eventId","event_id")??`${t}:${r}`,runId:t,sequence:r,eventType:s,payload:{...o,type:E(o,"type")??s,runId:E(o,"runId","run_id")??t,threadId:E(o,"threadId","thread_id")??E(e,"threadId","thread_id")??""},createdAt:E(e,"createdAt","created_at")??""}}function Tu(e){let t=ye(e)?e:{};if(Array.isArray(t.items))return{items:t.items,hasMore:!!(t.hasMore??t.has_more)};let r=[];for(let n of(Array.isArray(t.events)?t.events:[]).map(Cu).filter(Boolean)){let o=r[r.length-1];o?.[0]?.runId===n.runId?o.push(n):r.push([n])}return{items:r,hasMore:!!(t.hasMore??t.has_more)}}async function us(e={}){return Uo({page_size:e.pageSize??20,page_token:e.pageToken,is_favorite:e.favorite})}async function tr(e){return $o({name:e||void 0})}function bu(e){switch(e){case 1:return"generating";case 2:return"ready";case 3:return"unavailable";default:return"unspecified"}}function ju(e){let t=typeof e?.resource_meta?.url=="string"?e.resource_meta.url.trim():"";return{status:bu(e?.status),...typeof e?.resource_id=="string"&&e.resource_id.trim()?{resourceId:e.resource_id.trim()}:{},...e?.resource_meta?{resourceMeta:e.resource_meta}:{},...t?{url:t}:{}}}function ds(e){return`/p/${encodeURIComponent(e.trim())}`}function le(e,t=new URL(B).origin){return new URL(ds(e),t).toString()}function Ou(e,t={}){let r=e.trim();if(!r)throw new m("INVALID_REQUEST","\u8BF7\u63D0\u4F9B projectId",{status:400});let n=ds(r);return{projectId:r,targetPath:n,url:le(r,t.webOrigin)}}async function ps(e){let t=Ou(e),r=await Fo({project_id:t.projectId});return{projectId:t.projectId,projectUrl:t.url,...ju(r.prototype_screenshot)}}import{randomUUID as an}from"crypto";var Nu="main/claude-cli";function ls(e){if(typeof e=="string")return e;if(e==null)return"";try{return JSON.stringify(e,null,2)}catch{return String(e)}}function Lu(e){return{description:"project",value:JSON.stringify({projectId:e})}}function Mu(){return{description:"agent-config",value:JSON.stringify({mainAgent:{profileId:Nu}})}}function Du(e){return[Lu(e),Mu()]}function Uu(e){if(typeof e=="string")return e.trim();if(!Array.isArray(e))return ls(e).trim();let t=e.filter(r=>r&&typeof r=="object"&&"text"in r&&(r.type==="answer"||r.type==="ask_to_continue")).map(r=>String(r.text??"").trim()).filter(Boolean);return t.length>0?t.join(`
|
|
223
|
+
|
|
224
|
+
`):e.map(r=>r&&typeof r=="object"&&"text"in r?String(r.text??"").trim():ls(r).trim()).filter(Boolean).join(`
|
|
225
|
+
|
|
226
|
+
`)}function $u(e){if(!(!Array.isArray(e)||e.length===0))for(let t=e.length-1;t>=0;t-=1){let r=e[t];if(r?.role==="assistant")return r}}function fs(e){let t=$u(e);return t?Uu(t.content).trim():""}function Fu(e,t){return{threadId:t,projectId:e,title:null,createdAt:"",updatedAt:""}}async function Gu(e){return e.threadId?[(await sn(e.projectId,Math.max(e.threadLimit,50))).find(o=>o.threadId===e.threadId)??Fu(e.projectId,e.threadId)]:(await sn(e.projectId,e.threadLimit)).slice().sort((r,n)=>{let o=Date.parse(r.updatedAt||r.createdAt||""),s=Date.parse(n.updatedAt||n.createdAt||"");return(Number.isNaN(s)?0:s)-(Number.isNaN(o)?0:o)})}async function Hu(e,t=50){return(await Gu({projectId:e,threadLimit:t}))[0]??null}function ms(e){return!!(e&&typeof e=="object"&&"status"in e&&e.status===404)}async function gs(e){let t=await Ye(e,{limit:1});for(let r of t.items){let n=r[0]?.runId;if(typeof n=="string"&&n.trim().length>0)return n}}async function hs(e,t=50){let n=(await Tt(e)).threadId?.trim()||void 0;if(n)try{return await Ye(n,{limit:1}),n}catch(s){if(!ms(s))throw s}let o=await Hu(e,t);if(!o){n&&await We(e,null);return}return await We(e,o.threadId),o.threadId}async function ys(e){let r=(e.threadId?.trim()||void 0)??await hs(e.projectId,e.discoveryLimit??50);if(!r)throw new m("PROJECT_THREAD_NOT_FOUND","\u9879\u76EE\u4E0B\u6CA1\u6709\u53EF\u7528\u4F1A\u8BDD\uFF0C\u65E0\u6CD5\u67E5\u8BE2\u72B6\u6001",{status:404,source:"session",details:{projectId:e.projectId}});let s=((await Tt(e.projectId)).latestRunId?.trim()||void 0)??await gs(r);if(!s)throw new m("PROJECT_RUN_NOT_FOUND","\u76EE\u6807\u4F1A\u8BDD\u4E0B\u6CA1\u6709\u53EF\u67E5\u8BE2\u7684\u5386\u53F2\u8F6E\u6B21",{status:404,source:"session",details:{projectId:e.projectId,threadId:r}});return await bt(e.projectId,{threadId:r,latestRunId:s}),{threadId:r,runId:s}}async function Bu(e){let r=(await Tt(e)).latestRunId?.trim()||void 0;if(!r)return;if((await er(r)).status==="running")throw new m("PROJECT_RUN_ACTIVE","\u5F53\u524D\u9879\u76EE\u4ECD\u6709\u4EFB\u52A1\u5728\u6267\u884C\uFF0C\u8BF7\u7B49\u5F85\u672C\u8F6E\u7ED3\u675F\u540E\u518D\u53D1\u9001\u65B0\u6D88\u606F",{status:409,source:"session",details:{projectId:e}})}async function _s(e){let t=e.message.trim();if(!t)throw new Error("Message content cannot be empty");await Bu(e.projectId);let r=e.createNewThread===!0?void 0:e.threadId?.trim()||await hs(e.projectId),n=e.createNewThread||!r?an():r,o=!e.createNewThread&&r?await gs(r).catch(u=>{if(!ms(u))throw u}):void 0,s=an(),i=an(),a={threadId:n,runId:s,...o?{parentRunId:o}:{},messages:[{id:i,role:"user",content:t}],tools:[],context:Du(e.projectId)},c=await cs(a);return e.onThreadIdResolved?.(c.threadId),await rt(e.projectId,c.runId,{threadId:c.threadId}),{threadId:c.threadId,runId:c.runId,parentRunId:c.runId,status:"running"}}var Wu=50,zu=100,Ju=160,Vu={activate_skill:{title:"\u6280\u80FD\u6FC0\u6D3B",runningText:"\u6B63\u5728\u6FC0\u6D3B\u6280\u80FD",completedText:"\u6280\u80FD\u6FC0\u6D3B \u5DF2\u5B8C\u6210",errorText:"\u6FC0\u6D3B\u6280\u80FD\u65F6\u5361\u4F4F\u4E86"},unsplash_search:{title:"\u56FE\u7247\u641C\u7D22",runningText:"\u6B63\u5728\u641C\u5BFB\u5408\u9002\u7684\u7D20\u6750\u56FE",completedText:"\u56FE\u7247\u641C\u7D22 \u5DF2\u5B8C\u6210",errorText:"\u627E\u56FE\u7247\u7D20\u6750\u65F6\u5361\u4F4F\u4E86"},sandbox_list_directory:{title:"\u76EE\u5F55\u6D4F\u89C8",runningText:"\u6B63\u5728\u6D4F\u89C8\u76EE\u5F55\u7ED3\u6784",completedText:"\u76EE\u5F55\u6D4F\u89C8 \u5DF2\u5B8C\u6210",errorText:"\u770B\u6587\u4EF6\u65F6\u5361\u4F4F\u4E86"},sandbox_read_file:{title:"\u6587\u4EF6\u8BFB\u53D6",runningText:"\u6B63\u5728\u8BFB\u53D6\u6587\u4EF6\u5185\u5BB9",completedText:"\u6587\u4EF6\u8BFB\u53D6 \u5DF2\u5B8C\u6210",errorText:"\u8BFB\u53D6\u6587\u4EF6\u65F6\u5361\u4F4F\u4E86"},sandbox_write_file:{title:"\u5185\u5BB9\u4FEE\u6539",runningText:"\u6B63\u5728\u7F16\u5199\u6587\u4EF6\u4EE3\u7801",completedText:"\u5185\u5BB9\u4FEE\u6539 \u5DF2\u5B8C\u6210",errorText:"\u4FEE\u6539\u5185\u5BB9\u65F6\u5361\u4F4F\u4E86"},sandbox_edit_file:{title:"\u5185\u5BB9\u4FEE\u6539",runningText:"\u6B63\u5728\u4FEE\u6539\u6587\u4EF6\u5185\u5BB9",completedText:"\u5185\u5BB9\u4FEE\u6539 \u5DF2\u5B8C\u6210",errorText:"\u4FEE\u6539\u5185\u5BB9\u65F6\u5361\u4F4F\u4E86"},sandbox_build:{title:"\u9879\u76EE\u6784\u5EFA",runningText:"\u6B63\u5728\u6267\u884C\u9879\u76EE\u6784\u5EFA\u6D41\u7A0B",completedText:"\u9879\u76EE\u6784\u5EFA \u5DF2\u5B8C\u6210",errorText:"\u6784\u5EFA\u9879\u76EE\u65F6\u5361\u4F4F\u4E86"},sandbox_review:{title:"\u4EE3\u7801\u5BA1\u67E5",runningText:"\u6B63\u5728\u5BA1\u67E5\u4EE3\u7801\u8D28\u91CF",completedText:"\u4EE3\u7801\u5BA1\u67E5 \u5DF2\u5B8C\u6210",errorText:"\u5BA1\u67E5\u4EE3\u7801\u65F6\u5361\u4F4F\u4E86"},websearch:{title:"\u8D44\u6599\u641C\u7D22",runningText:"\u6B63\u5728\u8054\u7F51\u641C\u7D22\u76F8\u5173\u8D44\u6599",completedText:"\u8D44\u6599\u641C\u7D22 \u5DF2\u5B8C\u6210",errorText:"\u641C\u7D22\u8D44\u6599\u65F6\u5361\u4F4F\u4E86"}},ws={"write-code":{title:"\u5B9E\u73B0\u539F\u578B\u4EE3\u7801",runningText:"\u6B63\u5728\u5B9E\u73B0\u539F\u578B\u4EE3\u7801",completedText:"\u539F\u578B\u4EE3\u7801\u6784\u5EFA \u5DF2\u5B8C\u6210",completedLabel:"\u539F\u578B\u4EE3\u7801\u6784\u5EFA"},"design-dna":{title:"\u8F93\u51FA\u89C6\u89C9\u89C4\u8303",runningText:"\u6B63\u5728\u8F93\u51FA\u89C6\u89C9\u89C4\u8303",completedText:"\u89C6\u89C9\u89C4\u8303\u8F93\u51FA \u5DF2\u5B8C\u6210",completedLabel:"\u89C6\u89C9\u89C4\u8303\u8F93\u51FA"},"visual-direction":{title:"\u8F93\u51FA\u89C6\u89C9\u65B9\u5411",runningText:"\u6B63\u5728\u8F93\u51FA\u89C6\u89C9\u65B9\u5411",completedText:"\u89C6\u89C9\u65B9\u5411\u8F93\u51FA \u5DF2\u5B8C\u6210",completedLabel:"\u89C6\u89C9\u65B9\u5411\u8F93\u51FA"}},Ku=new Set(["figma_to_html"]),qu=[{pattern:/(search|grep|find|glob)/i,copy:{title:"\u4EE3\u7801\u68C0\u7D22",runningText:"\u6B63\u5728\u5BFB\u627E\u76F8\u5173\u7684\u4EE3\u7801",completedText:"\u4EE3\u7801\u68C0\u7D22 \u5DF2\u5B8C\u6210",errorText:"\u5BFB\u627E\u4EE3\u7801\u65F6\u5361\u4F4F\u4E86"}}];function ht(e){if(typeof e!="string")return;let t=e.trim();if(t)switch(t){case"sandbox_write_files":return"sandbox_write_file";case"sandbox_read_image":return"sandbox_read_file";case"wireframe_preview":return"generate_image";default:return t}}function Ps(e){let t=ht(e);if(!t)return null;let r=Vu[t];if(r)return r;for(let n of qu)if(n.pattern.test(t))return n.copy;return null}function Rs(e,t=Ju){let r=e.replace(/\s+/g," ").trim();return r?r.length>t?`${r.slice(0,t-1)}...`:r:""}function Qu(e){if(typeof e=="string")return e;if(e==null)return"";try{return JSON.stringify(e,null,2)}catch{return String(e)}}function Yu(e){return Rs(Qu(e))||void 0}function Xu(e){return Rs(fs(e))||void 0}function D(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:null}function Zu(e){let t=D(e);return t?typeof t.id=="string"&&typeof t.kind=="string"&&typeof t.status=="string"&&typeof t.title=="string"&&(t.children===void 0||Array.isArray(t.children)):!1}function yt(e){for(let t of e){if(typeof t!="string")continue;let r=t.trim();if(r)return r}}function un(e,t){let r=e?.meta?.[t];return typeof r=="string"&&r.trim()?r:void 0}function ed(e){let t=D(e),r=Zu(t?.node)?t.node:void 0;return{phase:typeof t?.phase=="string"?t.phase:void 0,node:r,activeTool:typeof t?.activeTool=="string"?t.activeTool:void 0}}function td(e){return e.role==="activity"&&e.activityType==="SUBAGENT"}function Is(e){let t=ht(e);return t?Ku.has(t):!1}function rd(e,t){if(e&&ws[e])return ws[e];let r=t?.trim()||"\u5904\u7406\u5B50\u4EFB\u52A1";return{title:r,runningText:r.includes("\u6B63\u5728")?r:`\u6B63\u5728${r}`,completedText:`${r} \u5DF2\u5B8C\u6210`,completedLabel:r}}function cn(e,t,r){let n=ht(e);if(!n)return null;if(n==="write_code_preview")return{title:"\u9884\u89C8\u9875\u6784\u5EFA",runningText:"\u6B63\u5728\u6784\u5EFA\u9884\u89C8\u9875",completedText:"\u9884\u89C8\u9875\u6784\u5EFA\u5B8C\u6210",errorText:"\u6784\u5EFA\u9884\u89C8\u9875\u65F6\u5361\u4F4F\u4E86"};if((r==="design-dna"||r==="visual-direction")&&/^(sandbox_read_file|sandbox_list_directory)$/.test(n))return{title:"\u8BBE\u8BA1\u51C6\u5219\u67E5\u9605",runningText:"\u6B63\u5728\u67E5\u9605\u8BBE\u8BA1\u51C6\u5219",completedText:"\u8BBE\u8BA1\u51C6\u5219\u67E5\u9605",errorText:"\u67E5\u9605\u8BBE\u8BA1\u51C6\u5219\u65F6\u5361\u4F4F\u4E86"};let o=Ps(n);if(o)return o;let s=n.replace(/[_-]+/g," ").trim();return s?{title:s,runningText:s.includes("\u6B63\u5728")?s:`\u6B63\u5728${s}`,completedText:`${s} \u5DF2\u5B8C\u6210`,errorText:`${s} \u6267\u884C\u5931\u8D25`}:null}function nd(e){switch(un(e,"reason")??un(e,"error")){case"cancelled":return"\u8FD9\u6B21\u6267\u884C\u88AB\u4E2D\u6B62\u4E86";case"execution_failed":return"\u8FD9\u6B65\u6267\u884C\u9047\u5230\u4E86\u4E00\u70B9\u72B6\u51B5";case"nesting_depth_exceeded":return"\u4EFB\u52A1\u5D4C\u5957\u592A\u6DF1\uFF0C\u6211\u6709\u70B9\u8F6C\u4E0D\u8FC7\u6765\u4E86";case"max_subagents_exceeded":return"\u52A9\u624B\u6570\u91CF\u5DF2\u8FBE\u4E0A\u9650\uFF0C\u8BF7\u5148\u7A0D\u7B49";default:return}}function rr(e,t){for(let r=(e.children?.length??0)-1;r>=0;r-=1){let n=e.children?.[r];if(!n)continue;let o=rr(n,t);if(o)return o}return e.kind==="tool"&&e.status===t?e:void 0}function Ss(e){if(e)return rr(e,"error")??rr(e,"running")??rr(e,"completed")}function vs(e,t){if(!td(e))return null;let r=D(e.content),n=ed(e.content),o=un(n.node,"subAgentType"),s=rd(o,n.node?.title),i=dn(n.phase??n.node?.status,t),a=yt([r?.title,r?.name,r?.summary,r?.info])??s.title,c=yt([r?.info,r?.summary,r?.title,r?.name])??s.runningText;if(i==="completed")return{title:n.node?s.completedLabel:a,statusText:n.node?s.completedText:c};if(i==="error"){let p=Ss(n.node),f=cn(p?.title,p?.status??"error",o);return{title:f?.title??a,statusText:nd(n.node)??f?.errorText??`${a} \u6267\u884C\u5931\u8D25`}}let u=n.activeTool&&!Is(n.activeTool)?cn(n.activeTool,"running",o):null;if(u)return{title:u.title,statusText:u.runningText};let d=Ss(n.node);if(d&&!Is(d.title)){let p=cn(d.title,d.status,o);if(p)return{title:p.title,statusText:d.status==="completed"?p.completedText:p.runningText}}return{title:n.node?s.title:a,statusText:n.node?s.runningText:c}}function od(e){let t=D(e);if(t)return yt([t.status,t.phase,t.state,D(t.node)?.status,D(t.node)?.phase,D(t.latest)?.status,D(t.latest)?.phase])}function dn(e,t){let r=e?.trim().toLowerCase();return r==="start"||r==="progress"||r==="running"?"running":r==="end"||r==="completed"||r==="done"||r==="success"||r==="succeeded"?"completed":r==="error"||r==="failed"||r==="failure"||r==="cancelled"||t==="error"||t==="cancelled"?"error":t==="completed"?"completed":"running"}function ks(e,t){if(e.role!=="tool")return"running";let r=e.metadata?.sdk?.status;return r==="completed"||r==="error"||r==="running"?r:r==="init"?"running":e.metadata?.sdk?.result!==void 0?"completed":dn(void 0,t)}function As(e,t){return e.role!=="activity"?"running":dn(od(e.content),t)}function sd(e){if(e.role!=="activity")return"activity";let t=D(e.content);return yt([t?.title,t?.info,t?.summary,t?.name,D(t?.node)?.title,D(t?.node)?.info,D(t?.latest)?.title,D(t?.latest)?.info])??e.activityType??"activity"}function id(e,t){if(e.role!=="activity")return;let r=vs(e,t);if(r)return r.statusText;let n=D(e.content);return Yu(yt([n?.info,n?.summary,n?.title,D(n?.node)?.info,D(n?.node)?.summary,D(n?.latest)?.info,D(n?.latest)?.summary])??e.content)}function ad(e,t){let r=e.role==="tool"?ht(e.metadata?.sdk?.toolName)??ht(e.name):void 0,n=Ps(r),o=n?.title??r??"\u5DE5\u5177\u8C03\u7528",s=ks(e,t);return s==="completed"?{title:o,statusText:n?.completedText??`${o} \u5DF2\u5B8C\u6210`}:s==="error"?{title:o,statusText:n?.errorText??`${o} \u6267\u884C\u5931\u8D25`}:{title:o,statusText:n?.runningText??`\u6B63\u5728\u6267\u884C ${o}`}}function cd(e,t){let r=vs(e,t);if(r)return r;let n=sd(e),o=As(e,t),s=id(e,t);return o==="completed"?{title:n,statusText:s??`${n} \u5DF2\u5B8C\u6210`}:o==="error"?{title:n,statusText:s??`${n} \u6267\u884C\u5931\u8D25`}:{title:n,statusText:s??(n.includes("\u6B63\u5728")?n:`\u6B63\u5728${n}`)}}function ud(e,t){let r=[];for(let n of e){let o=null;if(n.role==="tool"){let i=ad(n,t),a=n.parentMessageId??(typeof n.metadata?.parentMessageId=="string"?n.metadata.parentMessageId:void 0);o={id:n.toolCallId||n.id,kind:"tool",title:i.title,status:ks(n,t),detail:i.statusText,parentMessageId:a}}else if(n.role==="activity"){let i=cd(n,t);o={id:n.id,kind:"activity",title:i.title,status:As(n,t),detail:i.statusText,parentMessageId:n.parentMessageId}}if(!o)continue;let s=r[r.length-1];if(s&&s.kind===o.kind&&s.title===o.title&&s.status===o.status&&s.parentMessageId===o.parentMessageId){s.count=(s.count??1)+1,s.detail=o.detail??s.detail;continue}r.push(o)}return r}function dd(e){let t=[...e.groupedSteps].reverse().find(n=>n.kind==="activity"&&n.status==="running");if(t)return t.detail??t.title;let r=[...e.groupedSteps].reverse().find(n=>n.kind==="tool"&&n.status==="running");if(r)return r.detail??r.title;if(e.runStatus==="error")return e.runError?.message||"\u6267\u884C\u5931\u8D25";if(e.runStatus==="cancelled")return"\u5DF2\u53D6\u6D88";if(e.runStatus==="completed")return e.assistantSummary??[...e.groupedSteps].reverse().find(n=>n.status==="completed")?.detail}async function pd(e){let t;for(let r=0;r<zu;r+=1){let n=await Ye(e.threadId,{limit:Wu,runId:t});for(let s of n.items)if(s[0]?.runId===e.runId)return mt({items:[s],hasMore:!1});if(!n.hasMore)break;let o=n.items[0]?.[0]?.runId;if(!o)break;t=o}return e.messages}async function ld(e){try{return await pd(e)??[]}catch{return e.messages??[]}}async function Es(e){let t=await ld(e.result),r=ud(t,e.result.status),n=e.result.status==="running"?dd({runStatus:e.result.status,runError:e.result.error,assistantSummary:Xu(t),groupedSteps:r}):void 0,o=e.result.status==="error"?{code:e.result.error?.code??"RUN_FAILED",message:e.result.error?.message??"\u8FD0\u884C\u5931\u8D25",source:"run",retriable:!1,details:{rawStatus:"error",...e.result.traceUrl?{traceUrl:e.result.traceUrl}:{},...e.result.error?.code?{rawErrorCode:e.result.error.code}:{},...e.result.error?.message?{rawErrorMessage:e.result.error.message}:{}}}:e.result.status==="cancelled"?{code:"RUN_CANCELLED",message:"\u8FD0\u884C\u5DF2\u53D6\u6D88",source:"run",retriable:!1,details:{rawStatus:"cancelled",...e.result.traceUrl?{traceUrl:e.result.traceUrl}:{}}}:void 0;return{projectId:e.projectId,projectUrl:le(e.projectId),status:e.result.status==="running"?"running":e.result.status==="completed"?"success":"fail",...n?{statusText:n}:{},...o?{failure:o}:{}}}var fd=new Set(["completed","error","cancelled"]);function md(e){return fd.has(e)}async function gd(e,t){let r=await er(t),n=r.status==="completed"?Zn(r.messages,r.runId):void 0,o=await rt(e,t,{remove:md(r.status),dirtyPatch:n});return{result:r,state:o}}async function hd(e,t){let r=typeof t=="string"?t.trim():"";return r||(await ys({projectId:e})).runId}async function yd(e,t){let r=await hd(e,t);return await rt(e,r),gd(e,r)}async function _d(e,t){let{result:r,state:n}=await yd(e,t);return{query:await Es({projectId:e,result:r,state:n}),result:r,state:n}}async function xs(e,t){return(await _d(e,t)).query}import _h from"crypto";import Sh,{AxiosError as Ph}from"axios";import{execFile as bd}from"child_process";import*as fe from"fs";import*as Us from"os";import*as re from"path";import{Readable as jd}from"stream";import{pipeline as Od}from"stream/promises";import{promisify as Nd}from"util";import Ld from"axios";import{createHash as Ts}from"crypto";import*as Me from"fs";import*as bs from"os";import*as Xe from"path";import js from"axios";var Os="/__ojo_local__",wd=`${Os}/prototype-dist`,Id=[0,250,750,1500,3e3],Sd=new Set(["EAI_AGAIN","ECONNABORTED","ECONNREFUSED","ECONNRESET","EHOSTUNREACH","ENETUNREACH","ENOTFOUND","EPIPE","ERR_NETWORK","ERR_SOCKET_CONNECTION_TIMEOUT","ETIMEDOUT","UND_ERR_CONNECT_TIMEOUT","UND_ERR_HEADERS_TIMEOUT","UND_ERR_SOCKET"]),Pd=new Set([408,425,429,500,502,503,504]);function Rd(e){let t=e,r=new Set;for(;t&&typeof t=="object"&&!r.has(t);){r.add(t);let n=t.code;if(typeof n=="string"&&n.trim())return n.trim().toUpperCase();t=t.cause}return""}function vd(e){return js.isAxiosError(e)&&e.response?Pd.has(e.response.status):Sd.has(Rd(e))}async function kd(e){e>0&&await new Promise(t=>setTimeout(t,e))}async function Ns(e,t=kd){let r;for(let n of Id){n>0&&await t(n);try{return await e()}catch(o){if(r=o,!vd(o))throw o}}throw r}async function _t(e){let t=e.trim();if(!t)throw new m("PROJECT_ID_REQUIRED","project id \u4E0D\u80FD\u4E3A\u7A7A",{status:400,source:"workspace"});return(await j.get(`/projects/${encodeURIComponent(t)}/canvas-export`)).data}async function Ad(e){let t=Oe(e)?await ue():void 0,r=t?de(t).headers:void 0,n=await js.get(e,{responseType:"arraybuffer",headers:r,maxRedirects:5,maxContentLength:Number.POSITIVE_INFINITY,maxBodyLength:Number.POSITIVE_INFINITY});return Buffer.from(n.data)}function Ed(e){switch(e?.split(";",1)[0]?.trim().toLowerCase()){case"text/html":return".html";case"text/css":return".css";case"application/javascript":case"text/javascript":return".js";case"application/json":return".json";case"image/png":return".png";case"image/jpeg":return".jpg";case"image/webp":return".webp";case"image/gif":return".gif";case"image/svg+xml":return".svg";case"application/pdf":return".pdf";case"text/markdown":case"text/x-markdown":return".md";case"text/plain":return".txt";case"application/msword":return".doc";case"application/vnd.openxmlformats-officedocument.wordprocessingml.document":return".docx";case"application/zip":case"application/x-zip-compressed":return".zip";case"audio/mpeg":return".mp3";case"audio/wav":case"audio/x-wav":return".wav";case"video/mp4":return".mp4";case"video/webm":return".webm";default:return".bin"}}function xd(e){let t=e?.split(";",1)[0]?.trim().toLowerCase()??"";return t.startsWith("image/")?"images":t.startsWith("video/")?"videos":t.startsWith("audio/")?"audio":t==="text/html"?"html":t==="application/pdf"||t==="application/msword"||t.startsWith("application/vnd.openxmlformats-officedocument.")?"documents":t==="application/zip"||t==="application/x-zip-compressed"||t.endsWith("+zip")?"archives":t.includes("model")||t.endsWith("/gltf-binary")||t.endsWith("/obj")?"models":t.startsWith("text/")||t==="application/json"||t.endsWith("+json")||t==="application/xml"||t.endsWith("+xml")?"text":"other"}function Cd(e,t){let n=e.trim().replace(/[^a-zA-Z0-9._-]+/g,"_").replace(/^\.+/,"")||Ts("sha256").update(e).digest("hex").slice(0,24),o=Ed(t),s=o!==".bin"&&n.toLowerCase().endsWith(o)?"":o;return`resource/${xd(t)}/${n}${s}`}function pn(e){let t=e.trim().replace(/^\/+/,"");if(!t||t.includes("\\"))throw new m("CANVAS_EXPORT_PATH_INVALID",`\u65E0\u6548\u7684 prototype dist \u8DEF\u5F84: ${e}`,{status:502,source:"workspace"});let r=t.split("/");if(r.some(n=>!n||n==="."||n===".."))throw new m("CANVAS_EXPORT_PATH_INVALID",`\u65E0\u6548\u7684 prototype dist \u8DEF\u5F84: ${e}`,{status:502,source:"workspace"});return r.join("/")}async function Cs(e,t,r,n,o,s){let i=await Ns(()=>n(r),s);if(o?.trim()&&Ts("sha256").update(i).digest("hex").toLowerCase()!==o.trim().toLowerCase())throw new m("CANVAS_EXPORT_CHECKSUM_MISMATCH",`\u753B\u5E03\u4EA7\u7269\u6821\u9A8C\u5931\u8D25: ${t}`,{status:502,source:"workspace"});let a=Xe.join(e,t);await Me.promises.mkdir(Xe.dirname(a),{recursive:!0}),await Me.promises.writeFile(a,i)}function Td(e,t){let r=JSON.parse(JSON.stringify(e)),n=r.resources;if(!n||typeof n!="object"||Array.isArray(n))return r;for(let[o,s]of Object.entries(n)){if(!s||typeof s!="object"||Array.isArray(s))continue;let i=s,a=typeof i.key=="string"&&i.key.trim()?i.key.trim():o,c=t.get(a)??t.get(o);c&&(i.url=`${Os}/${c}`,i.exists=!0,delete i.expire_at,delete i.expires_at_unix)}return r}async function Ls(e,t={}){let r=e.trim();if(!r)throw new m("PROJECT_ID_REQUIRED","project id \u4E0D\u80FD\u4E3A\u7A7A",{status:400,source:"workspace"});let n=t.fetchExport??_t,o=t.download??Ad,s=await Ns(()=>n(r),t.retryDelay);if(s.schema_version!==1||s.project_id!==r)throw new m("CANVAS_EXPORT_PROTOCOL_MISMATCH","\u540E\u7AEF\u8FD4\u56DE\u4E86\u4E0D\u517C\u5BB9\u7684\u753B\u5E03\u5BFC\u51FA\u534F\u8BAE",{status:502,source:"workspace"});let i=t.baseDirectory??bs.tmpdir();await Me.promises.mkdir(i,{recursive:!0});let a=await Me.promises.mkdtemp(Xe.join(i,`ojo-canvas-${r.replace(/[^a-zA-Z0-9_-]/g,"-")}-`));try{let c=new Map;for(let f of s.resource_files??[]){let l=f.resource_key?.trim(),h=f.url?.trim();if(!l||!h)continue;let I=Cd(l,f.content_type);await Cs(a,I,h,o,void 0,t.retryDelay),c.set(l,I);for(let y of f.aliases??[])y.trim()&&c.set(y.trim(),I)}let u=0;for(let f of s.prototype_dist?.files??[]){let h=`prototype/${pn(f.path)}`;await Cs(a,h,f.url,o,f.sha256,t.retryDelay),u+=1}let d={schema_version:1,project_id:r,exported_at:s.exported_at,local_resource_schema_version:1,local_resources:{},project:Td(s.project,c),state_page_revision:s.state_page_revision,prototype_dist:s.prototype_dist?{manifest_resource_key:s.prototype_dist.manifest_resource_key,entry_path:s.prototype_dist.entry_path,files:s.prototype_dist.files.map(f=>({path:pn(f.path),resource_key:f.resource_key,local_url:`${wd}/${pn(f.path)}`,content_type:f.content_type}))}:void 0},p=Xe.join(a,"canvas-export.json");return await Me.promises.writeFile(p,`${JSON.stringify(d,null,2)}
|
|
227
|
+
`,"utf8"),{projectId:r,directory:a,manifestPath:p,resourceCount:new Set(c.values()).size,prototypeDistFileCount:u}}catch(c){throw await Me.promises.rm(a,{recursive:!0,force:!0}),c}}var Md=Nd(bd),Ms="ojo-prototype",Dd="irise-prototype";function $s(e){return typeof e?.source_task_id=="string"&&e.source_task_id.trim()?e.source_task_id:"unknown"}async function Ud(e,t){await Md("/usr/bin/unzip",["-o",e,"-d",t])}function fn(e,t=process.cwd()){if(typeof e=="string"){let r=e.trim();if(r)return re.resolve(r)}return re.resolve(t)}function wt(e){let t=re.resolve(e),r=re.basename(t);return r===Ms||r===Dd?t:re.join(t,Ms)}async function Fs(e){await fe.promises.mkdir(e,{recursive:!0})}async function $d(e){await Fs(e);let t=await fe.promises.readdir(e);await Promise.all(t.map(r=>fe.promises.rm(re.join(e,r),{recursive:!0,force:!0})))}async function Fd(e){let t=await st({project_id:e}),r=t.workspace_hash??t.draft?.workspace_hash??t.prototype?.workspace_hash??"";if(r.trim())return r.trim();let o=(await _t(e)).project?.prototype;if(!o||typeof o!="object"||Array.isArray(o))return"";let s=o.workspace_hash;return typeof s=="string"?s.trim():""}function ln(e){if(typeof e!="string")return null;let t=e.trim();return t.length>0?t:null}function Gd(e){return ln(e.name)}var Hd=new RegExp('[<>:"/\\\\|?*\\x00-\\x1f]',"g");function Ds(e){return e.trim().replace(/\s+/g,"-").replace(Hd,"-").replace(/\.+/g,".").replace(/-+/g,"-").replace(/^[-.]+|[-.]+$/g,"")}function Bd(e){let t=ln(e);if(!t)throw new m("PROJECT_REF_INVALID","projectRef \u4E0D\u80FD\u4E3A\u7A7A",{status:400});if(t.startsWith("http://")||t.startsWith("https://")){let r;try{r=new URL(t)}catch{throw new m("PROJECT_REF_INVALID",`\u65E0\u6548\u7684\u9879\u76EE\u94FE\u63A5: ${t}`,{status:400})}let n=/^\/p\/([^/]+?)\/?$/.exec(r.pathname);if(!n)throw new m("PROJECT_REF_INVALID",`\u9879\u76EE\u94FE\u63A5\u683C\u5F0F\u4E0D\u6B63\u786E\uFF0C\u4EC5\u652F\u6301 /p/<projectId>: ${t}`,{status:400});let o=ln(decodeURIComponent(n[1]));if(!o)throw new m("PROJECT_REF_INVALID",`\u9879\u76EE\u94FE\u63A5\u7F3A\u5C11 projectId: ${t}`,{status:400});return o}if(/[/?#]/.test(t))throw new m("PROJECT_REF_INVALID",`\u65E0\u6548\u7684 projectId \u6216\u9879\u76EE\u94FE\u63A5: ${t}`,{status:400});return t}async function Wd(e,t){try{if(!(await fe.promises.stat(e)).isDirectory())throw new m("PROJECT_ROOT_CONFLICT",`\u76EE\u6807\u8DEF\u5F84\u5DF2\u5B58\u5728\u4E14\u4E0D\u662F\u76EE\u5F55: ${e}`,{status:409})}catch(o){if(o.code==="ENOENT")return;throw o}let r=Vr(e);if(!fe.existsSync(r))throw new m("PROJECT_ROOT_CONFLICT",`\u76EE\u6807\u76EE\u5F55\u5DF2\u5B58\u5728\u4F46\u4E0D\u662F OJO \u9879\u76EE\u76EE\u5F55: ${e}`,{status:409});let n;try{n=ct(r)}catch{throw new m("PROJECT_ROOT_CONFLICT",`\u76EE\u6807\u76EE\u5F55\u5DF2\u5B58\u5728\u4F46\u9879\u76EE\u5143\u6570\u636E\u65E0\u6548: ${e}`,{status:409})}if(n.data.project_id!==t)throw new m("PROJECT_ROOT_CONFLICT",`\u76EE\u6807\u76EE\u5F55\u5DF2\u7ED1\u5B9A\u5176\u4ED6\u9879\u76EE: ${e} (current=${n.data.project_id}, expected=${t})`,{status:409});return n}async function zd(e,t){let r=Oe(e)?de(await ue()).headers:void 0,n=await Ld.get(e,{responseType:"stream",headers:r,maxRedirects:5});await Od(jd.from(n.data),fe.createWriteStream(t))}async function Gs(e,t,r,n){let s=(n?.workspace_hash??n?.draft?.workspace_hash??n?.prototype?.workspace_hash??"").trim()||await Fd(e);if(!s)throw new m("WORKSPACE_NOT_AVAILABLE","\u9879\u76EE\u6682\u65E0 workspace\uFF0C\u65E0\u6CD5\u4E0B\u8F7D",{status:404});let{url:i,exists:a}=await Go({project_id:e,workspace_hash:s,expire_seconds:3600});if(!a)throw new m("WORKSPACE_ZIP_NOT_FOUND","workspace zip \u4E0D\u5B58\u5728",{status:404});let c=await fe.promises.mkdtemp(re.join(Us.tmpdir(),`ojo-download-${e}-`)),u=re.join(c,`${e}.zip`);try{if(await zd(i,u),await $d(t),await Fs(t),await Ud(u,t),r){let d=$s(r.data.workspace),p=dt(r.rootDir,f=>({...f,workspace:{workspace_hash:s,source_task_id:d,downloaded_at:new Date().toISOString()}}));p.data.thread_id&&await We(e,p.data.thread_id)}return{project_id:e,path:t,workspace_hash:s}}finally{await fe.promises.rm(c,{recursive:!0,force:!0})}}async function mn(e,t=process.cwd()){let r=ve(t);if(!r)throw new m("PROJECT_METADATA_MISSING","\u672A\u627E\u5230\u9879\u76EE\u6839 .ojo/project.json\uFF0C\u8BF7\u5148\u6267\u884C OJO workspace sync <projectId|projectUrl> \u5EFA\u7ACB\u672C\u5730\u9879\u76EE\u76EE\u5F55",{status:400});let n=wt(e);return Gs(r.data.project_id,n,r)}async function gn(e){let t=Bd(e.projectRef),r=await st({project_id:t}),n=Gd(r)??t,o=Ds(n)||Ds(t)||t,s=re.resolve(e.parentDir),i=re.join(s,o),a=await Wd(i,t),c=wt(i),u=await Gs(t,c,a,r),d=new Date().toISOString(),p=$s(a?.data.workspace);if(a){let f=dt(i,l=>({...l,project_name:n,workspace:{...l.workspace,workspace_hash:u.workspace_hash,source_task_id:p,downloaded_at:d}}));return f.data.thread_id&&await We(t,f.data.thread_id),u}return ut(i,{version:1,project_id:t,project_name:n,thread_id:null,workspace:{workspace_hash:u.workspace_hash,source_task_id:p,downloaded_at:d}}),u}var hn={enabled:!0,showOnFirstSession:!0,showOnFirstProjectThread:!0,variant:"short",userPromptFull:`\u6B22\u8FCE\u6765\u5230 OJO\u3002
|
|
228
|
+
|
|
229
|
+
\u4F60\u53EF\u4EE5\u628A\u8FD9\u91CC\u5F53\u6210\u4E00\u4E2A AI Native \u7684\u4EA7\u54C1\u6784\u5EFA\u7A7A\u95F4\u3002
|
|
230
|
+
\u4E0D\u9700\u8981\u4E00\u5F00\u59CB\u5C31\u60F3\u6E05\u695A\u5168\u90E8\u7EC6\u8282\uFF0C\u4F60\u53EA\u9700\u8981\u7ED9\u51FA\u4E00\u4E2A\u65B9\u5411\u3001\u4E00\u4E2A\u95EE\u9898\u3001\u4E00\u4E2A\u573A\u666F\uFF0C\u751A\u81F3\u53EA\u662F\u4E00\u4E2A\u6A21\u7CCA\u7684\u5FF5\u5934\uFF0C\u6211\u4EEC\u53EF\u4EE5\u4E00\u8D77\u628A\u5B83\u9010\u6B65\u63A8\u8FDB\u6210\u53EF\u843D\u5730\u7684\u4E1C\u897F\u3002
|
|
231
|
+
|
|
232
|
+
\u901A\u5E38\u6211\u4EEC\u4F1A\u8FD9\u6837\u534F\u4F5C\uFF1A
|
|
233
|
+
|
|
234
|
+
1. \u4ECE\u60F3\u6CD5\u5F00\u59CB
|
|
235
|
+
\u5148\u804A\u4F60\u60F3\u505A\u4EC0\u4E48\uFF0C\u6211\u4F1A\u5E2E\u4F60\u4E00\u8D77\u53D1\u6563\u3001\u8865\u5145\u548C\u6536\u655B\uFF0C\u9010\u6B65\u660E\u786E\u4EA7\u54C1\u76EE\u6807\u3001\u7528\u6237\u3001\u6838\u5FC3\u80FD\u529B\u548C\u4F53\u9A8C\u65B9\u5411\u3002
|
|
236
|
+
|
|
237
|
+
2. \u6C89\u6DC0\u6210 brief
|
|
238
|
+
\u5F53\u60F3\u6CD5\u9010\u6E10\u6E05\u6670\u540E\uFF0C\u6211\u53EF\u4EE5\u5E2E\u4F60\u6574\u7406\u6210 product brief\uFF0C\u4F5C\u4E3A\u540E\u7EED\u539F\u578B\u751F\u6210\u548C\u8FED\u4EE3\u7684\u57FA\u7840\u3002
|
|
239
|
+
|
|
240
|
+
3. \u751F\u6210\u5E76\u8FED\u4EE3\u539F\u578B
|
|
241
|
+
\u5728 brief \u8DB3\u591F\u6E05\u695A\u540E\uFF0C\u6211\u53EF\u4EE5\u7EE7\u7EED\u63A8\u8FDB\u5230\u539F\u578B\u4EE3\u7801\u751F\u6210\u3002\u4F60\u53EF\u4EE5\u7EE7\u7EED\u901A\u8FC7\u5BF9\u8BDD\u8C03\u6574\uFF0C\u4E5F\u53EF\u4EE5\u8FDB\u5165\u7F16\u8F91\u9875\u505A\u5FAE\u8C03\u3002
|
|
242
|
+
|
|
243
|
+
4. \u540C\u6B65\u5230\u672C\u5730\u7EE7\u7EED\u5F00\u53D1
|
|
244
|
+
\u5F53\u539F\u578B\u8FBE\u5230\u9884\u671F\u540E\uFF0C\u53EF\u4EE5\u5C06\u6E90\u7801\u540C\u6B65\u5230\u672C\u5730\u3002\u4E4B\u540E\u8FD8\u53EF\u4EE5\u901A\u8FC7\u672C\u5730 agent\uFF0C\u8FDB\u4E00\u6B65\u8F6C\u6362\u6210\u66F4\u9002\u5408\u771F\u5B9E\u4E1A\u52A1\u5F00\u53D1\u7684\u4EE3\u7801\u3002
|
|
245
|
+
|
|
246
|
+
5. \u6309\u8282\u594F\u6301\u7EED\u8FED\u4EE3
|
|
247
|
+
\u8FD9\u91CC\u4E0D\u662F\u56FA\u5B9A\u6B7B\u677F\u7684\u6D41\u7A0B\u3002
|
|
248
|
+
\u5373\u4F7F\u5DF2\u7ECF\u6709\u4E86 brief \u6216 prototype\uFF0C\u6211\u4EEC\u4E5F\u53EF\u4EE5\u968F\u65F6\u7EE7\u7EED\u56DE\u5230\u8BA8\u8BBA\uFF0C\u8865\u5145\u60F3\u6CD5\u3001\u8C03\u6574\u65B9\u5411\uFF0C\u518D\u7EE7\u7EED\u751F\u6210\u65B0\u7684\u7ED3\u679C\u3002
|
|
249
|
+
|
|
250
|
+
\u4F60\u53EF\u4EE5\u76F4\u63A5\u5F00\u59CB\uFF0C\u6BD4\u5982\u544A\u8BC9\u6211\uFF1A
|
|
251
|
+
- \u4F60\u60F3\u505A\u4E00\u4E2A\u4EC0\u4E48\u4EA7\u54C1
|
|
252
|
+
- \u5B83\u60F3\u89E3\u51B3\u4EC0\u4E48\u95EE\u9898
|
|
253
|
+
- \u4F60\u5E0C\u671B\u7528\u6237\u83B7\u5F97\u4EC0\u4E48\u4F53\u9A8C
|
|
254
|
+
- \u6216\u8005\u4F60\u5DF2\u7ECF\u6709\u4E00\u4E9B\u60F3\u6CD5\uFF0C\u60F3\u8BA9\u6211\u5E2E\u4F60\u4E00\u8D77\u628A\u5B83\u53D8\u5F97\u66F4\u5B8C\u6574`,userPromptShort:`\u6B22\u8FCE\u6765\u5230 OJO\u3002\u4F60\u53EF\u4EE5\u4ECE\u4E00\u4E2A\u6A21\u7CCA\u60F3\u6CD5\u5F00\u59CB\uFF0C\u548C\u6211\u4E00\u8D77\u628A\u5B83\u63A8\u8FDB\u6210 brief\u3001prototype\uFF0C\u518D\u540C\u6B65\u5230\u672C\u5730\u7EE7\u7EED\u6F14\u8FDB\u6210\u66F4\u9002\u5408\u4E1A\u52A1\u5F00\u53D1\u7684\u4EE3\u7801\u3002\u8FD9\u91CC\u4E0D\u662F\u56FA\u5B9A\u6D41\u7A0B\uFF0C\u5373\u4F7F\u5DF2\u7ECF\u6709\u4E86 brief \u6216 prototype\uFF0C\u6211\u4EEC\u4E5F\u53EF\u4EE5\u968F\u65F6\u7EE7\u7EED\u8BA8\u8BBA\u3001\u8865\u5145\u60F3\u6CD5\u3001\u8C03\u6574\u65B9\u5411\u3002
|
|
255
|
+
|
|
256
|
+
\u4ECE\u4F60\u7684\u60F3\u6CD5\u5F00\u59CB\u5C31\u884C\u3002\u4F60\u73B0\u5728\u60F3\u505A\u4EC0\u4E48\uFF1F`,agentPrompt:["OJO \u91C7\u7528 artifact-driven \u7684\u534F\u4F5C\u65B9\u5F0F\uFF0C\u4E0D\u662F\u4E25\u683C\u7EBF\u6027\u6D41\u7A0B\u3002","\u5E38\u89C1\u8DEF\u5F84\u662F\uFF1Aidea -> brief -> prototype -> local sync -> business code\u3002","\u5373\u4F7F\u5DF2\u6709 brief \u6216 prototype\uFF0C\u4E5F\u5141\u8BB8\u7EE7\u7EED\u8865\u5145 ide \u548C\u8C03\u6574\u65B9\u5411\u3002","\u9996\u8F6E\u4F18\u5148\u7406\u89E3\u7528\u6237\u60F3\u505A\u4EC0\u4E48\uFF0C\u5E2E\u52A9\u6F84\u6E05\u4E0E\u6536\u655B\uFF0C\u4E0D\u8981\u8FC7\u65E9\u63A8\u52A8\u5230 prototype \u751F\u6210\u3002","\u5982\u679C\u7528\u6237\u8FFD\u95EE\u6D41\u7A0B\u6216\u4E0B\u4E00\u6B65\uFF0C\u660E\u786E\u8BF4\u660E\u6D41\u7A0B\u662F\u7075\u6D3B\u7684\uFF0C\u53EF\u4EE5\u968F\u65F6\u7EE7\u7EED\u8BA8\u8BBA\u518D\u63A8\u8FDB\u3002","\u8FD4\u56DE OJO \u63A5\u53E3\u5BF9\u8BDD\u5185\u5BB9\u65F6\u5FC5\u987B\u539F\u5C01\u4E0D\u52A8\uFF0C\u4E0D\u5F97\u6539\u5199\u3001\u6458\u8981\u6216\u6DA6\u8272\u3002","\u8FD4\u56DE\u7ED3\u679C\u540E\u9ED8\u8BA4\u5148\u4EA4\u7ED9\u7528\u6237\uFF0C\u7531\u7528\u6237\u51B3\u5B9A\u4E0B\u4E00\u6B65\uFF0C\u4E0D\u8981\u81EA\u884C\u51B3\u7B56\u3002"].join(`
|
|
257
|
+
`)},iy=hn.userPromptShort,Jd=hn.agentPrompt.split(`
|
|
258
|
+
`).map(e=>`- ${e}`).join(`
|
|
259
|
+
`),Vd=["\u7528\u6237\u5F15\u5BFC\uFF08\u5B8C\u6574\uFF09:",hn.userPromptFull,"Agent \u884C\u4E3A\u8981\u6C42\uFF08\u5B8C\u6574\uFF09:",Jd,"MCP \u884C\u4E3A\u8865\u5145:","- \u4F7F\u7528 OJO MCP \u65F6\uFF0C\u53EA\u57FA\u4E8E\u5F53\u524D\u771F\u5B9E\u5B58\u5728\u7684\u5DE5\u5177\u540D\u548C\u53C2\u6570\u540D\u5DE5\u4F5C\uFF0C\u4E0D\u8981\u5047\u8BBE\u65E7\u5DE5\u5177\u3002","- `open_editor` \u4E0E `workspace_sync` \u4F9D\u8D56 `.ojo/project.json` \u7684\u672C\u5730\u5DE5\u4F5C\u533A\u4E0A\u4E0B\u6587\uFF0C\u4E0D\u80FD\u7528 `projectId` \u66FF\u4EE3\u3002","- \u8FD4\u56DE OJO \u63A5\u53E3\u7ED3\u679C\u540E\uFF0C\u9ED8\u8BA4\u5148\u4EA4\u7ED9\u7528\u6237\u51B3\u5B9A\u4E0B\u4E00\u6B65\u3002"].join(`
|
|
260
|
+
|
|
261
|
+
`),ay=Vd.split(`
|
|
262
|
+
`);import{isDeepStrictEqual as yn}from"util";function De(e){if(!e||typeof e!="object"||Array.isArray(e))throw new Error("\u670D\u52A1\u7AEF\u8FD4\u56DE\u4E86\u65E0\u6548\u7684 Team \u6216 workspace context");return e}function _e(e){return typeof e=="string"?e.trim():""}function Kd(e){let t=De(e),r=t.teamDisplayNameI18n??t.team_display_name_i18n??{},n=Object.fromEntries(Object.entries(De(r)).filter(s=>typeof s[1]=="string")),o=t.teamSkillIds??t.team_skill_ids;return{displaySkillIds:Array.isArray(o)?o.map(_e).filter(Boolean):null,teamId:_e(t.teamId??t.team_id),name:_e(t.teamName??t.team_name),displayName:_e(t.teamDisplayName??t.team_display_name),localizedNames:n}}async function nr(){let e=new Map,t=new Set,r="";do{if(t.has(r))throw new Error("Team \u76EE\u5F55\u8FD4\u56DE\u4E86\u91CD\u590D\u7684\u5206\u9875\u4EE4\u724C");t.add(r);let n=await j.get("/display-teams",{params:{page_size:100,...r?{page_token:r}:{}}}),o=De(n.data),s=o.teams??o.displayTeams??o.display_teams;if(!Array.isArray(s))throw new Error("\u670D\u52A1\u7AEF\u672A\u8FD4\u56DE Team \u76EE\u5F55");for(let i of s){let a=Kd(i);if(!a.teamId.startsWith("team-id-"))throw new Error("Team \u76EE\u5F55\u7F3A\u5C11\u89C4\u8303\u7684 teamId");e.set(a.teamId,a)}r=_e(o.nextPageToken??o.next_page_token)}while(r);return{teams:[...e.values()]}}async function qd(e){if(!e.displaySkillIds)throw new Error("Team \u76EE\u5F55\u672A\u63D0\u4F9B\u5173\u8054 Skill\uFF0C\u8BF7\u5148\u6838\u5BF9\u76EE\u5F55");if(!e.displaySkillIds.length)return[];let t=new Map,r=new Set,n="";do{if(r.has(n))throw new Error("Skill \u76EE\u5F55\u8FD4\u56DE\u4E86\u91CD\u590D\u7684\u5206\u9875\u4EE4\u724C");r.add(n);let s=await j.get("/display-skills",{params:{page_size:100,...n?{page_token:n}:{}}}),i=De(s.data),a=i.skills??i.displaySkills??i.display_skills;if(!Array.isArray(a))throw new Error("\u670D\u52A1\u7AEF\u672A\u8FD4\u56DE Skill \u76EE\u5F55");for(let c of a){let u=De(c),d=_e(u.skillId??u.skill_id),p=_e(u.runtimeCapabilityId??u.runtime_capability_id)||_e(u.skillName??u.skill_name)||d;d&&p&&(t.set(d,p),t.set(p,p))}n=_e(i.nextPageToken??i.next_page_token)}while(n);let o=e.displaySkillIds.map(s=>{let i=t.get(s);if(!i)throw new Error(`Team \u5173\u8054 Skill \u65E0\u6CD5\u5728\u76EE\u5F55\u4E2D\u89E3\u6790: ${s}`);return i});return[...new Set(o)]}async function _n(e){let t=await j.get(`/projects/${encodeURIComponent(e)}`),r=De(t.data);return De(r.workspaceContext??r.workspace_context??{})}async function Hs(e){let t=e.trim();if(!t)throw new Error("\u5FC5\u987B\u63D0\u4F9B projectId");let r=await _n(t),n=_e(r.teamId)||null,{teams:o}=await nr();return{projectId:t,teamId:n,team:o.find(s=>s.teamId===n)??null,workspaceContext:r}}async function Bs(e){let t=e.projectId.trim(),r=e.teamId?.trim(),n=e.name?.trim();if(!t||!!r==!!n)throw new Error("\u5FC5\u987B\u63D0\u4F9B projectId\uFF0C\u5E76\u4E14\u53EA\u6307\u5B9A --team-id \u6216 --name \u5176\u4E2D\u4E00\u9879");let{teams:o}=await nr(),s=o.filter(f=>r?f.teamId===r:[f.name,f.displayName,...Object.values(f.localizedNames)].includes(n));if(s.length!==1)throw new Error("Team \u5FC5\u987B\u552F\u4E00\u5339\u914D\u76EE\u5F55\uFF0C\u8BF7\u4F7F\u7528 --team-id \u660E\u786E\u9009\u62E9");let i=s[0],a=e.syncSkills?await qd(i):void 0,c=await _n(t),u={...c,teamId:i.teamId,...a?{skillIds:a}:{}},d=!yn(c,u);d&&await j.patch(`/projects/${encodeURIComponent(t)}`,{project_id:t,workspace_context:u});let p=await _n(t);if(p.teamId!==i.teamId)throw new Error("Team \u4FDD\u5B58\u540E\u56DE\u8BFB\u4E0D\u4E00\u81F4\uFF0C\u8BF7\u5148\u6838\u5BF9\u9879\u76EE\u914D\u7F6E");if(a&&!yn(p.skillIds,a))throw new Error("Team Skill \u4FDD\u5B58\u540E\u56DE\u8BFB\u4E0D\u4E00\u81F4");for(let[f,l]of Object.entries(c))if(!(f==="skillIds"&&e.syncSkills)&&f!=="teamId"&&!yn(p[f],l))throw new Error(`Team \u56DE\u8BFB\u53D1\u73B0\u5DF2\u6709\u914D\u7F6E\u53D1\u751F\u53D8\u5316: ${f}`);return{ok:!0,projectId:t,teamId:i.teamId,teamName:i.displayName||i.name,changed:d,skillIds:p.skillIds??[],skillsSynced:!!e.syncSkills,verified:!0,verificationScope:"project-workspace-context",workspaceContext:p}}import{Command as He}from"commander";import{open as Yd}from"fs/promises";var Qd=["react","vue","angular","svelte","other","unknown"],Ws={ready:["none"],adaptation_required:["navigation_adapter_required","state_lifetime_unresolved","api_auth_adaptation_required","build_adapter_required","missing_evidence"],unsupported:["framework_adapter_missing","server_runtime_required","router_unsupported","build_unsupported","target_runtime_incompatible","browser_capability_unsupported"]};function zs(e,t=Date.now()){if(!e||typeof e!="object"||Array.isArray(e))throw new Error("INVALID_EVENT");let r=e,n=["schemaVersion","eventId","occurredAt","framework","decision","reason"];if(Object.keys(r).length!==n.length||Object.keys(r).some(s=>!n.includes(s)))throw new Error("INVALID_EVENT");if(r.schemaVersion!==1||typeof r.eventId!="string"||!/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/.test(r.eventId))throw new Error("INVALID_EVENT");if(typeof r.occurredAt!="string"||!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/.test(r.occurredAt))throw new Error("INVALID_EVENT");let o=Date.parse(r.occurredAt);if(!Number.isFinite(o)||new Date(o).toISOString()!==r.occurredAt||o>t+6e4||o<=t-6048e5)throw new Error("INVALID_EVENT");if(!Qd.includes(r.framework)||typeof r.decision!="string"||!Object.hasOwn(Ws,r.decision))throw new Error("INVALID_EVENT");if(!Ws[r.decision].includes(r.reason))throw new Error("INVALID_EVENT");return{schemaVersion:1,eventId:r.eventId,occurredAt:r.occurredAt,framework:r.framework,decision:r.decision,reason:r.reason}}function Xd(e){let t=e.OJO_AGENT_API_BASE??e.IRISE_AGENT_ENGINE_BASE??e.NEXIGHT_AGENT_ENGINE_BASE??`${new URL(B).origin}/api/agent-engine`,r=new URL(t),n=["localhost","127.0.0.1","[::1]"].includes(r.hostname);if(r.protocol!=="https:"&&!(r.protocol==="http:"&&n)||r.username||r.password||r.search||r.hash)throw new Error("INVALID_ENDPOINT");return`${r.toString().replace(/\/+$/,"")}/v2/conversion-preflights`}async function Vs(e,t={}){let r=t.env??process.env;if(["0","off","false"].includes((r.OJO_CONVERSION_TELEMETRY??"").toLowerCase())||r.DO_NOT_TRACK==="1")return{status:"skipped",code:"DISABLED"};try{let n=Xd(r),o=await Yd(e,"r"),s;try{if(!(await o.stat()).isFile())return{status:"skipped",code:"INVALID_EVENT"};let d=Buffer.alloc(4097),{bytesRead:p}=await o.read(d,0,d.length,0);if(p>4096)return{status:"skipped",code:"INVALID_EVENT"};s=zs(JSON.parse(d.subarray(0,p).toString("utf8")))}catch{return{status:"skipped",code:"INVALID_EVENT"}}finally{await o.close()}let i=await(t.credentials??ue)(),a=de(i);if(!a.sessionId)return{status:"skipped",code:"AUTH_REQUIRED"};let c=await(t.fetch??fetch)(n,{method:"POST",redirect:"error",signal:AbortSignal.timeout(t.timeoutMs??2e3),headers:{...a.headers,"Content-Type":"application/json","X-Ojo-Platform":"cli"},body:JSON.stringify(s)});if(!c.ok)return{status:"failed",code:`HTTP_${c.status}`};let u=await c.json();return u.accepted!==!0||typeof u.duplicate!="boolean"?{status:"failed",code:"INVALID_RESPONSE"}:{status:"sent",duplicate:u.duplicate}}catch{return{status:"failed",code:"REPORT_UNAVAILABLE"}}}function Ks(e){e.command("conversion").description("OJO \u8F6C\u6362\u524D\u7F6E\u68C0\u67E5\u9065\u6D4B").command("report").argument("<eventFile>","\u4EC5\u5305\u542B\u56FA\u5B9A\u679A\u4E3E\u7684\u524D\u7F6E\u68C0\u67E5\u4E8B\u4EF6 JSON \u6587\u4EF6").option("--json","\u8F93\u51FA\u4E0A\u62A5\u72B6\u6001\uFF1B\u5931\u8D25\u4E0D\u963B\u585E\u8F6C\u6362").description("\u901A\u8FC7\u5F53\u524D\u767B\u5F55\u6001\u4E0A\u62A5\u4E00\u6B21\u524D\u7F6E\u68C0\u67E5\uFF1BOJO_CONVERSION_TELEMETRY=off \u53EF\u5173\u95ED").action(async(t,r)=>{let n=await Vs(t);console.log(r.json?JSON.stringify(n):`Conversion telemetry: ${n.status}${n.code?` (${n.code})`:""}`)})}var U={schemaVersion:2,generation:"next",webOrigin:Re,serviceApi:"server.v1",pluginInteraction:"local-browser-client",pluginSse:!1,canvasSource:"local-workspace",browserClientProtocol:1,workspaceSyncProtocol:1,browserDevProtocol:3,canvasExportProtocol:1,localCanvasStorageProtocol:2,browserAuthProtocol:1,localPrototypeUpdateProtocol:1,localPrototypeBuildGateProtocol:1,localPrototypePublishProtocol:1,localResourcePublishProtocol:2,conversionPreflightTelemetryProtocol:1};async function wn(e={}){if(e.json){process.stdout.write(`${JSON.stringify(U)}
|
|
263
|
+
`);return}process.stdout.write(`${[`generation: ${U.generation}`,`webOrigin: ${U.webOrigin}`,`serviceApi: ${U.serviceApi}`,`pluginInteraction: ${U.pluginInteraction}`,`pluginSse: ${U.pluginSse}`,`canvasSource: ${U.canvasSource}`,`browserClientProtocol: ${U.browserClientProtocol}`,`workspaceSyncProtocol: ${U.workspaceSyncProtocol}`,`browserDevProtocol: ${U.browserDevProtocol}`,`canvasExportProtocol: ${U.canvasExportProtocol}`,`localCanvasStorageProtocol: ${U.localCanvasStorageProtocol}`,`browserAuthProtocol: ${U.browserAuthProtocol}`,`localPrototypeUpdateProtocol: ${U.localPrototypeUpdateProtocol}`,`localPrototypeBuildGateProtocol: ${U.localPrototypeBuildGateProtocol}`,`localPrototypePublishProtocol: ${U.localPrototypePublishProtocol}`,`localResourcePublishProtocol: ${U.localResourcePublishProtocol}`,`conversionPreflightTelemetryProtocol: ${U.conversionPreflightTelemetryProtocol}`].join(`
|
|
264
|
+
`)}
|
|
265
|
+
`)}import*as qs from"readline";function Q(e,t){return new m(t?.code??"CLI_ERROR",e,{status:t?.status,source:t?.source??"internal"})}function It(e){process.stderr.write(`${JSON.stringify(_o(e))}
|
|
266
|
+
`)}function z(e){It(e),process.exit(1)}async function Zd(){if(!process.stdin.isTTY&&process.stdin.readable){let e=qs.createInterface({input:process.stdin}),t=[];for await(let r of e)t.push(r);return t.join(`
|
|
267
|
+
`).trim()||null}return null}function ep(e,t){if(t){process.stdout.write(`${JSON.stringify(e)}
|
|
268
|
+
`);return}process.stdout.write(`projectId: ${e.projectId}
|
|
269
|
+
`),process.stdout.write(`projectUrl: ${e.projectUrl}
|
|
270
|
+
`),process.stdout.write(`status: ${e.status}
|
|
271
|
+
`)}async function tp(e){e.message||z(Q("\u8BF7\u901A\u8FC7 --message \u6216 stdin \u63D0\u4F9B\u6D88\u606F\u5185\u5BB9",{code:"CLI_USAGE_ERROR",status:400}));let t=await _s({projectId:e.projectId,createNewThread:!1,message:e.message});ep({projectId:e.projectId,projectUrl:le(e.projectId),status:t.status},e.json)}async function In(e){let t=typeof e.options.projectId=="string"&&e.options.projectId.trim().length>0?e.options.projectId.trim():null,r=e.options.message??"";if(!r){let n=await Zd();n&&(r=n)}r||z(Q("\u8BF7\u901A\u8FC7 --message \u6216 stdin \u63D0\u4F9B\u6D88\u606F\u5185\u5BB9",{code:"CLI_USAGE_ERROR",status:400}));try{t||(t=(await tr()).project_id);let o={projectId:t,message:r,json:!!e.options.json};await tp(o)}catch(n){if(n instanceof Error&&/^exit:\d+$/.test(n.message))throw n;z(n)}}async function Sn(e){await In(e)}import{spawn as ni}from"child_process";import{existsSync as we,readFileSync as yp,rmSync as ti,statSync as _p}from"fs";import{createConnection as wp,createServer as Ip}from"net";import{basename as oi,dirname as Sp,join as Y,resolve as Ie}from"path";import{createHash as Zs}from"crypto";import*as $ from"fs";import{createServer as rp}from"http";import*as x from"path";import{watch as np}from"chokidar";import{WebSocket as Qs,WebSocketServer as op}from"ws";var sp="/__ojo_local__",Pn=`${sp}/prototype-dist`,ip="/__ojo_local_updates__/";function ap(e){return Zs("sha256").update(e).digest("hex")}function cp(e){let t=e.split(x.sep).join("/").replace(/^\/+/,"");if(!t||t.includes("\\"))throw new m("LOCAL_PROTOTYPE_PATH_INVALID",`\u65E0\u6548\u7684\u539F\u578B\u4EA7\u7269\u8DEF\u5F84: ${e}`,{status:400,source:"workspace"});let r=t.split("/");if(r.some(n=>!n||n==="."||n===".."))throw new m("LOCAL_PROTOTYPE_PATH_INVALID",`\u65E0\u6548\u7684\u539F\u578B\u4EA7\u7269\u8DEF\u5F84: ${e}`,{status:400,source:"workspace"});return r.join("/")}function up(e){switch(x.extname(e).toLowerCase()){case".html":case".htm":return"text/html; charset=utf-8";case".css":return"text/css; charset=utf-8";case".js":case".mjs":case".cjs":return"application/javascript; charset=utf-8";case".json":case".map":return"application/json; charset=utf-8";case".svg":return"image/svg+xml";case".png":return"image/png";case".jpg":case".jpeg":return"image/jpeg";case".webp":return"image/webp";case".gif":return"image/gif";case".ico":return"image/x-icon";case".woff":return"font/woff";case".woff2":return"font/woff2";case".ttf":return"font/ttf";case".wasm":return"application/wasm";default:return"application/octet-stream"}}async function dp(e){let t=[];async function r(n){let o=await $.promises.readdir(n,{withFileTypes:!0});o.sort((s,i)=>s.name.localeCompare(i.name));for(let s of o){if(s.name===".DS_Store")continue;let i=x.join(n,s.name);s.isDirectory()?await r(i):s.isFile()&&t.push({relativePath:cp(x.relative(e,i)),absolutePath:i})}}return await r(e),Promise.all(t.map(async({relativePath:n,absolutePath:o})=>{let s=await $.promises.readFile(o),i=ap(s);return{path:n,data:s,sha256:i,resourceKey:`local_dist_${i.slice(0,24)}`,contentType:up(n)}}))}function pp(e){let t=Zs("sha256");for(let r of e)t.update(r.path),t.update("\0"),t.update(r.sha256),t.update("\0");return t.digest("hex")}function Ze(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:void 0}function Rn(e){return typeof e=="string"?e.trim():""}function lp(e){let t=new Map,r=Ze(e.prototype),n=Array.isArray(r?.frames)?r.frames:[];for(let o of n){let s=Ze(o),i=Rn(s?.name),a=Rn(s?.dist_path)||(i?`${i}.html`:"");i&&a&&t.set(a,i)}return t}function fp(e,t){let r=lp(t),n=new Set;return e.filter(o=>o.path.toLowerCase().endsWith(".html")||o.path.toLowerCase().endsWith(".htm")).map(o=>{let s=x.posix.basename(o.path,x.posix.extname(o.path)),i=x.posix.basename(x.posix.dirname(o.path)),a=r.get(o.path)||(s==="index"&&i!=="."?i:s)||"frame",c=a,u=2;for(;n.has(c);)c=`${a}_${u++}`;return n.add(c),{name:c,content_id:o.resourceKey,dist_path:o.path}})}function mp(e,t,r){let n=new Set(e.map(s=>s.path)),o=Rn(Ze(t.prototype)?.entry_path);if(o&&n.has(o))return o;for(let s of["index.html","home.html"])if(n.has(s))return s;return r[0]?.dist_path??""}async function gp(e,t){let r=x.join(e,"prototype"),n=x.join(e,`.prototype-next-${process.pid}-${Date.now()}`),o=x.join(e,`.prototype-old-${process.pid}-${Date.now()}`);await $.promises.mkdir(n,{recursive:!0});try{for(let i of t){let a=x.join(n,...i.path.split("/"));await $.promises.mkdir(x.dirname(a),{recursive:!0}),await $.promises.writeFile(a,i.data)}let s=!1;try{await $.promises.rename(r,o),s=!0}catch(i){if(i.code!=="ENOENT")throw i}try{await $.promises.rename(n,r)}catch(i){throw s&&await $.promises.rename(o,r).catch(()=>{}),i}await $.promises.rm(o,{recursive:!0,force:!0})}finally{await $.promises.rm(n,{recursive:!0,force:!0})}}async function Ys(e,t){let r=`${e}.next-${process.pid}-${Date.now()}`;await $.promises.writeFile(r,`${JSON.stringify(t,null,2)}
|
|
272
|
+
`,"utf8"),await $.promises.rename(r,e)}async function Xs(e,t){let r=x.join(e.exportDirectory,"canvas-export.json"),n=JSON.parse(await $.promises.readFile(r,"utf8"));if(n.schema_version!==1||n.project_id!==e.projectId||!Ze(n.project))throw new m("LOCAL_PROTOTYPE_EXPORT_INVALID","\u672C\u5730\u753B\u5E03\u5BFC\u51FA\u4E0E\u5F53\u524D\u9879\u76EE\u4E0D\u5339\u914D",{status:500,source:"workspace"});let o=await dp(e.prototypeDistPath),s=n.project,i=fp(o,s),a=mp(o,s,i);if(!o.length||!i.length||!a)throw new m("LOCAL_PROTOTYPE_DIST_EMPTY",`\u539F\u578B\u4EA7\u7269\u76EE\u5F55\u4E2D\u6CA1\u6709\u53EF\u6E32\u67D3\u7684 HTML: ${e.prototypeDistPath}`,{status:400,source:"workspace"});let c=pp(o),u=`local_manifest_${c.slice(0,24)}`,d=o.find(g=>g.path===a)?.resourceKey??i[0].content_id,p=Date.now(),f=Ze(s.prototype)??{},l={...Ze(s.resources)??{}};for(let g of o)l[g.resourceKey]={key:g.resourceKey,url:`${Pn}/${g.path}`,content_type:g.contentType,exists:!0};l[u]={key:u,url:`${Pn}/manifest.json`,content_type:"application/json; charset=utf-8",exists:!0};let h=Math.max(Number(s.version)||0,0)+1,I={...f,updated_at:p,workspace_hash:c,prototype_commit_sha:c,prototype_dist_id:`local_${c.slice(0,24)}`,manifest_resource_key:u,entry_path:a,entry_resource_key:d,dist_storage_prefix:"",frames:i},y={...s,version:h,resources:l,prototype:I},_={schema_version:1,kind:"prototype_dist_manifest",workspace_hash:c,entry_path:a,files:o.map(g=>({path:g.path,resource_key:g.resourceKey,sha256:g.sha256,size_bytes:g.data.byteLength,content_type:g.contentType}))},b={...n,exported_at:new Date(p).toISOString(),project:y,prototype_dist:{manifest_resource_key:u,entry_path:a,files:o.map(g=>({path:g.path,resource_key:g.resourceKey,local_url:`${Pn}/${g.path}`,content_type:g.contentType}))}};await gp(e.exportDirectory,o),await Ys(x.join(e.exportDirectory,"prototype","manifest.json"),_),await Ys(r,b);let v={mutation:"set_prototype",new_version:h,workspace_hash:c,manifest_resource_key:u,entry_path:a,entry_resource_key:d,frames:i,resources:l},te={type:"IRISE_PROJECT_DRAFT_MUTATION_REQUESTED",mutation:"set_prototype",project_id:e.projectId,draft_version:h,workspace_hash:c,manifest_resource_key:u,entry_path:a,entry_resource_key:d,frames:i,project_draft_mutation:v,content:{mutation:"set_prototype",target:v}};return{result:{sequence:t,workspaceHash:c,fileCount:o.length,frameCount:i.length,entryPath:a},envelope:{schema_version:1,sequence:t,event:te}}}function hp(e){return`${ip}${encodeURIComponent(e)}`}async function ei(e){let t=x.resolve(e.prototypeDistPath),r=x.resolve(e.exportDirectory);if(!$.existsSync(t)||!$.statSync(t).isDirectory())throw new m("LOCAL_PROTOTYPE_DIST_MISSING",`\u539F\u578B\u4EA7\u7269\u76EE\u5F55\u4E0D\u5B58\u5728: ${t}`,{status:404,source:"workspace"});if(t===x.join(r,"prototype")||t.startsWith(`${r}${x.sep}`))throw new m("LOCAL_PROTOTYPE_DIST_INVALID","\u539F\u578B\u4EA7\u7269\u76EE\u5F55\u4E0D\u80FD\u4F4D\u4E8E\u4E34\u65F6\u753B\u5E03\u5BFC\u51FA\u76EE\u5F55\u4E2D",{status:400,source:"workspace"});let n={...e,prototypeDistPath:t,exportDirectory:r},o=1,s=await Xs(n,o);e.onUpdate?.(s.result);let i=rp(),a=hp(e.projectId),c=new op({noServer:!0});i.on("upgrade",(_,b,v)=>{if(new URL(_.url??"/","http://127.0.0.1").pathname!==a){b.destroy();return}c.handleUpgrade(_,b,v,g=>c.emit("connection",g,_))}),c.on("connection",_=>{_.readyState===Qs.OPEN&&_.send(JSON.stringify(s.envelope))}),await new Promise((_,b)=>{i.once("error",b),i.listen({host:"127.0.0.1",port:0,exclusive:!0},()=>{i.off("error",b),_()})});let u=i.address();if(!u||typeof u=="string")throw new m("LOCAL_PROTOTYPE_UPDATE_LISTEN_FAILED","\u65E0\u6CD5\u542F\u52A8\u672C\u5730\u539F\u578B\u66F4\u65B0\u901A\u9053",{status:500,source:"workspace"});let d=!1,p=!1,f=!1,l,h=_=>{let b=JSON.stringify(_);for(let v of c.clients)v.readyState===Qs.OPEN&&v.send(b)},I=async()=>{if(!d){if(p){f=!0;return}p=!0;try{do f=!1,s=await Xs(n,++o),e.onUpdate?.(s.result),h(s.envelope);while(f&&!d)}catch(_){e.onError?.(_ instanceof Error?_:new Error(String(_)))}finally{p=!1}}},y=np(t,{ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:300,pollInterval:50}});return await new Promise((_,b)=>{let v=()=>{y.off("error",te),_()},te=g=>{y.off("ready",v),b(g)};y.once("ready",v),y.once("error",te)}),y.on("all",()=>{l&&clearTimeout(l),l=setTimeout(()=>{I()},150)}),y.on("error",_=>e.onError?.(_ instanceof Error?_:new Error(String(_)))),{url:`ws://127.0.0.1:${u.port}${a}`,prototypeDistPath:t,initial:s.result,stop:async()=>{if(!d){d=!0,l&&clearTimeout(l),await y.close();for(let _ of c.clients)_.terminate();await new Promise(_=>c.close(()=>_())),await new Promise(_=>i.close(()=>_()))}}}}function Pp(e){try{return _p(e).isDirectory()}catch{return!1}}function et(e){return Pp(e)&&we(Y(e,"package.json"))}function Rp(e){let t=Ie(e);for(;;){if(et(t))return t;let r=Sp(t);if(r===t)return null;t=r}}function or(e){let t=vp(e);if(t)return t;if(et(e))return Ie(e);let r=Y(e,"prototype");if(et(r))return Ie(r);let n=Y(e,"ojo-prototype");return et(n)?Ie(n):null}function vp(e){let t=Ie(e);if(et(t)&&we(Y(t,"apps/canvas/dev.manifest.json")))return t;if(oi(t)==="canvas"&&we(Y(t,"dev.manifest.json"))){let r=Ie(t,"../..");if(et(r)&&we(Y(r,"apps/canvas/dev.manifest.json")))return r}return null}function kp(e,t=process.cwd()){let r=e?.trim();if(r){let i=Ie(t,r),a=or(i);if(a)return a;throw new m("WORKSPACE_DEV_PACKAGE_MISSING",`\u524D\u7AEF\u76EE\u5F55\u7F3A\u5C11 package.json: ${i}`,{status:404,source:"workspace"})}let n=ve(t);if(n){let i=or(Y(n.rootDir,"ojo-prototype"));if(i)return i}if(oi(Ie(t))==="ojo-prototype"){let i=or(t);if(i)return i}let o=Rp(t);if(o)return o;let s=or(Ie(t));if(s)return s;throw new m("WORKSPACE_DEV_PACKAGE_MISSING","\u672A\u627E\u5230\u53EF\u542F\u52A8\u7684\u524D\u7AEF package.json\uFF1B\u8BF7\u4F20\u5165 workspace \u8DEF\u5F84\uFF0C\u6216\u5148\u6267\u884C ojo workspace sync <projectId|projectUrl>",{status:404,source:"workspace"})}function Ap(e){let t=Y(e,"package.json");try{return JSON.parse(yp(t,"utf8"))}catch(r){throw new m("WORKSPACE_DEV_PACKAGE_INVALID",`\u65E0\u6CD5\u8BFB\u53D6\u524D\u7AEF package.json: ${t}`,{status:400,source:"workspace",cause:r})}}function Ep(e){let t=e?.trim().split("@")[0];return t==="pnpm"||t==="npm"||t==="yarn"||t==="bun"?t:null}function xp(e,t){let r=Ep(t.packageManager);return r||(we(Y(e,"pnpm-lock.yaml"))?"pnpm":we(Y(e,"yarn.lock"))?"yarn":we(Y(e,"bun.lock"))||we(Y(e,"bun.lockb"))?"bun":"npm")}function Cp(e,t,r){let n=e.scripts?.[t]??"",o=new Set([...Object.keys(e.dependencies??{}),...Object.keys(e.devDependencies??{})]);return r&&t==="dev"&&n.includes("tooling/dev/run-dev.mjs")&&we(Y(r,"apps/canvas/dev.manifest.json"))?"irise-canvas":o.has("vite")||/(^|\s|&&)vite(\s|$)/.test(n)?"vite":o.has("@rspack/core")||o.has("@rspack/cli")||o.has("@rspack/dev-server")||/(^|\s|&&)rspack\s+serve(\s|$)/.test(n)?"rspack":o.has("next")||/(^|\s|&&)next\s+dev(\s|$)/.test(n)?"next":o.has("astro")||/(^|\s|&&)astro\s+dev(\s|$)/.test(n)?"astro":o.has("nuxt")||/(^|\s|&&)nuxt\s+dev(\s|$)/.test(n)?"nuxt":"generic"}function Tp(e,t,r){switch(e){case"irise-canvas":return["--apps","canvas","--no-interactive","--no-proxy"];case"vite":return["--host",t,"--port",String(r),"--strictPort"];case"rspack":return["--host",t,"--port",String(r)];case"next":return["--hostname",t,"--port",String(r)];case"astro":case"nuxt":return["--host",t,"--port",String(r)];case"generic":return[]}}function bp(e,t,r,n,o){let s=Tp(r,n,o);switch(e){case"pnpm":return{command:e,args:["run",t,...s]};case"npm":return{command:e,args:["run",t,"--",...s]};case"yarn":return{command:"yarn",args:["run",t,...s]};case"bun":return{command:"bun",args:["run",t,...s]}}}function jp(e){return{command:e,args:["install"]}}function Op(e,t,r){return new Promise((n,o)=>{let s=ni(e,t,{cwd:r.cwd,env:r.env,stdio:["inherit","pipe","pipe"]});s.stdout?.on("data",i=>r.onOutput?.(i.toString(),"stdout")),s.stderr?.on("data",i=>r.onOutput?.(i.toString(),"stderr")),s.once("error",i=>{o(new m("WORKSPACE_DEV_COMMAND_FAILED",`\u65E0\u6CD5\u6267\u884C ${e}: ${i.message}`,{status:500,source:"workspace",cause:i}))}),s.once("exit",(i,a)=>{if(i===0){n();return}o(new m("WORKSPACE_DEV_COMMAND_FAILED",`${e} ${t.join(" ")} \u6267\u884C\u5931\u8D25 (code=${String(i)}, signal=${String(a)})`,{status:500,source:"workspace"}))})})}async function Np(e,t){return new Promise((r,n)=>{let o=Ip();o.unref(),o.once("error",s=>{n(new m("WORKSPACE_DEV_PORT_UNAVAILABLE",`\u65E0\u6CD5\u76D1\u542C ${e}:${t||"auto"}`,{status:409,source:"workspace",cause:s}))}),o.listen({host:e,port:t,exclusive:!0},()=>{let s=o.address(),i=typeof s=="object"&&s?s.port:t;o.close(a=>{if(a){n(a);return}r(i)})})})}function si(e){return e==="0.0.0.0"?"127.0.0.1":e==="::"||e==="[::]"?"::1":e}function ri(e,t,r,n){let o=si(e),s=o.includes(":")&&!o.startsWith("[")?`[${o}]`:o,i=n?.trim(),a=r==="irise-canvas"&&i?`/p/${encodeURIComponent(i)}`:"/";return`http://${s}:${t}${a}${r==="irise-canvas"&&i?"?mode=codex":""}`}function Lp(e,t){return new Promise(r=>{let n=wp({host:e,port:t}),o=s=>{n.removeAllListeners(),n.destroy(),r(s)};n.setTimeout(300),n.once("connect",()=>o(!0)),n.once("timeout",()=>o(!1)),n.once("error",()=>o(!1))})}function ii(e){return new Promise(t=>setTimeout(t,e))}function vn(e,t){if(e.pid&&process.platform!=="win32")try{return process.kill(-e.pid,t),!0}catch(r){if(r.code==="ESRCH")return!1}return e.kill(t)}async function Mp(e,t,r,n,o){let s=Date.now()+r;for(;Date.now()<s;){if(await Lp(si(e),t))return;let i=await Promise.race([n.then(a=>({exit:a})),ii(100).then(()=>null)]);if(i){let a=o().trim();throw new m("WORKSPACE_DEV_EARLY_EXIT",`\u524D\u7AEF\u670D\u52A1\u5728\u5C31\u7EEA\u524D\u9000\u51FA (code=${String(i.exit.code)}, signal=${String(i.exit.signal)})${a?`: ${a}`:""}`,{status:500,source:"workspace"})}}throw new m("WORKSPACE_DEV_TIMEOUT",`\u524D\u7AEF\u670D\u52A1\u672A\u5728 ${Math.ceil(r/1e3)} \u79D2\u5185\u76D1\u542C ${e}:${t}\uFF1B\u8BF7\u786E\u8BA4 dev script \u652F\u6301 HOST/PORT \u6216\u4F7F\u7528 Vite\u3001Rspack\u3001Next\u3001Astro\u3001Nuxt`,{status:504,source:"workspace"})}async function Dp(e,t){if(e.exitCode!==null||e.signalCode!==null)return;vn(e,"SIGTERM"),!await Promise.race([t.then(()=>!0,()=>!0),ii(1e3).then(()=>!1)])&&e.exitCode===null&&e.signalCode===null&&vn(e,"SIGKILL")}function Up(e){let t=e.host?.trim()||"127.0.0.1",r=e.port??0,n=e.script?.trim()||"dev",o=e.timeoutMs??6e4;if(!Number.isInteger(r)||r<0||r>65535)throw new m("WORKSPACE_DEV_PORT_INVALID",`\u65E0\u6548\u7AEF\u53E3: ${String(r)}`,{status:400,source:"workspace"});if(!n)throw new m("WORKSPACE_DEV_SCRIPT_INVALID","dev script \u4E0D\u80FD\u4E3A\u7A7A",{status:400,source:"workspace"});if(!Number.isFinite(o)||o<=0)throw new m("WORKSPACE_DEV_TIMEOUT_INVALID",`\u65E0\u6548\u542F\u52A8\u8D85\u65F6: ${String(o)}`,{status:400,source:"workspace"});return{host:t,port:r,script:n,timeoutMs:o}}async function ai(e={}){let{host:t,port:r,script:n,timeoutMs:o}=Up(e),s=e.cwd??process.cwd(),i=kp(e.workspacePath,s),a=Ap(i);if(!a.scripts?.[n]?.trim())throw new m("WORKSPACE_DEV_SCRIPT_MISSING",`package.json \u672A\u5B9A\u4E49 scripts.${n}: ${i}`,{status:400,source:"workspace"});let c=xp(i,a),u=Cp(a,n,i),d=e.projectId?.trim();if(u==="irise-canvas"&&!d)throw new m("WORKSPACE_DEV_PROJECT_ID_REQUIRED","\u542F\u52A8 Irise Web \u9879\u76EE\u753B\u5E03\u5FC5\u987B\u63D0\u4F9B project id",{status:400,source:"workspace"});let p={...process.env,...e.env},f;if(u==="irise-canvas"&&d&&(e.onEvent?.({event:"exporting",projectId:d}),f=await(e.materializeCanvasExport??Ls)(d)),(e.install??!0)&&!we(Y(i,"node_modules"))){e.onEvent?.({event:"installing",path:i,packageManager:c});let v=jp(c);await Op(v.command,v.args,{cwd:i,env:p,onOutput:e.onOutput})}let l;f&&e.prototypeDistPath?.trim()&&(l=await ei({projectId:f.projectId,exportDirectory:f.directory,prototypeDistPath:Ie(s,e.prototypeDistPath.trim()),onUpdate:v=>e.onEvent?.({event:"prototype_updated",...v}),onError:v=>e.onOutput?.(`[ojo] \u672C\u5730\u539F\u578B\u66F4\u65B0\u5931\u8D25: ${v.message}
|
|
273
|
+
`,"stderr")}),e.onEvent?.({event:"watching_prototype",path:l.prototypeDistPath,protocol:1}));let h=await Np(t,r),I=bp(c,n,u,t,h);e.onEvent?.({event:"starting",path:i,packageManager:c,framework:u,script:n,host:t,port:h});let y="",_=ni(I.command,I.args,{cwd:i,detached:process.platform!=="win32",env:{...p,HOST:t,PORT:String(h),BROWSER:"none",...f?{OJO_LOCAL_CANVAS_EXPORT_DIR:f.directory,OJO_LOCAL_CANVAS_PROJECT_ID:f.projectId,...l?{OJO_LOCAL_CANVAS_UPDATE_URL:l.url}:{}}:{}},stdio:["inherit","pipe","pipe"]});_.stdout?.on("data",v=>e.onOutput?.(v.toString(),"stdout")),_.stderr?.on("data",v=>{y=`${y}${v.toString()}`.slice(-4096),e.onOutput?.(v.toString(),"stderr")});let b=new Promise((v,te)=>{_.once("error",g=>{te(new m("WORKSPACE_DEV_COMMAND_FAILED",`\u65E0\u6CD5\u6267\u884C ${I.command}: ${g.message}`,{status:500,source:"workspace",cause:g}))}),_.once("exit",(g,A)=>v({code:g,signal:A}))});try{await Mp(t,h,o,b,()=>y)}catch(v){throw await Dp(_,b),await l?.stop(),f&&ti(f.directory,{recursive:!0,force:!0}),v}if(f){let v=async()=>{await l?.stop(),ti(f.directory,{recursive:!0,force:!0})};b.then(v,v)}return{result:{source:"local-workspace",path:i,packageManager:c,framework:u,script:n,host:t,port:h,healthUrl:ri(t,h,"generic"),url:ri(t,h,u,d),...d?{projectId:d}:{},...f?{localExportPath:f.directory,resourceCount:f.resourceCount,prototypeDistFileCount:f.prototypeDistFileCount,...l?{prototypeDistPath:l.prototypeDistPath,prototypeDistFileCount:l.initial.fileCount,localPrototypeUpdateProtocol:1}:{}}:{},..._.pid?{pid:_.pid}:{}},closed:b,stop:(v="SIGTERM")=>(l?.stop(),vn(_,v))}}import sr from"chalk";var S={info:e=>console.log(sr.blue(e)),error:e=>console.error(sr.red(e)),success:e=>console.log(sr.green(e)),warn:e=>console.warn(sr.yellow(e))};function St(e){return typeof e!="string"?void 0:e.trim()||void 0}function ci(e,t,r){let n=typeof e=="string"?e.trim():String(e??"");if(!/^\d+$/.test(n))throw Q(`${t} \u5FC5\u987B\u662F\u6574\u6570`,{code:"CLI_USAGE_ERROR",status:400,source:"workspace"});let o=Number.parseInt(n,10);if(o<r.min||o>r.max)throw Q(`${t} \u5FC5\u987B\u5728 ${r.min}-${r.max} \u4E4B\u95F4`,{code:"CLI_USAGE_ERROR",status:400,source:"workspace"});return o}function $p(e,t){if(t){process.stdout.write(`${JSON.stringify(e)}
|
|
274
|
+
`);return}if(e.event==="installing"){S.info(`\u6B63\u5728\u4F7F\u7528 ${e.packageManager} \u5B89\u88C5\u524D\u7AEF\u4F9D\u8D56: ${e.path}`);return}if(e.event==="exporting"){S.info(`\u6B63\u5728\u5BFC\u51FA\u9879\u76EE\u753B\u5E03\u5230\u672C\u5730: ${e.projectId}`);return}if(e.event==="watching_prototype"){S.info(`\u6B63\u5728\u76D1\u542C\u672C\u5730\u539F\u578B\u4EA7\u7269: ${e.path}`);return}if(e.event==="prototype_updated"){S.info(`\u672C\u5730\u539F\u578B\u5DF2\u66F4\u65B0: ${e.frameCount} \u4E2A\u753B\u5E03\u9875\u9762\uFF0C${e.fileCount} \u4E2A\u6587\u4EF6`);return}S.info(`\u6B63\u5728\u542F\u52A8 ${e.framework} \u524D\u7AEF\u670D\u52A1: ${e.path}`)}async function kn(e){let t=!!e.options.json;try{let r=ci(e.options.port??"0","--port",{min:0,max:65535}),n=ci(e.options.timeout??"60","--timeout",{min:1,max:600}),o=St(e.options.projectId);if(!o)throw Q("--project-id \u662F\u5FC5\u586B\u9879",{code:"CLI_USAGE_ERROR",status:400,source:"workspace"});let s=await ai({workspacePath:St(e.args.workspacePath),projectId:o,prototypeDistPath:St(e.options.prototypeDist),host:St(e.options.host),port:r,script:St(e.options.script),install:e.options.install!==!1,timeoutMs:n*1e3,onEvent:p=>$p(p,t),onOutput:p=>process.stderr.write(p)}),i={event:"ready",...s.result};t?process.stdout.write(`${JSON.stringify(i)}
|
|
275
|
+
`):(S.success(`\u524D\u7AEF\u670D\u52A1\u5DF2\u542F\u52A8: ${i.url}`),S.info("\u4FDD\u6301\u6B64\u547D\u4EE4\u8FD0\u884C\uFF1B\u7ED3\u675F\u65F6\u6309 Ctrl+C\u3002"));let a=!1,c=p=>{a=!0,s.stop(p)},u=()=>c("SIGINT"),d=()=>c("SIGTERM");process.once("SIGINT",u),process.once("SIGTERM",d);try{let p=await s.closed;if(!a&&p.code!==0)throw new m("WORKSPACE_DEV_SERVER_EXITED",`\u524D\u7AEF\u670D\u52A1\u5F02\u5E38\u9000\u51FA (code=${String(p.code)}, signal=${String(p.signal)})`,{status:500,source:"workspace"})}finally{process.off("SIGINT",u),process.off("SIGTERM",d)}}catch(r){z(r)}}function Fp(e,t){if(e.options.mode!==void 0)throw Q(`workspace ${t} \u4E0D\u652F\u6301 --mode\uFF1B\u56FA\u5B9A\u8986\u76D6\u5199\u5165 <path>/ojo-prototype`,{code:"CLI_USAGE_ERROR",status:400});if(e.options.historyId!==void 0)throw Q(`workspace ${t} \u4E0D\u652F\u6301 --history-id\uFF1B\u56FA\u5B9A\u8986\u76D6\u5199\u5165 <path>/ojo-prototype`,{code:"CLI_USAGE_ERROR",status:400})}function Gp(e,t){if(t.json){let r={projectId:e.project_id,path:e.path,workspaceHash:e.workspace_hash,...t.updated?{updated:!0}:{}};process.stdout.write(`${JSON.stringify(r)}
|
|
276
|
+
`);return}S.success(`workspace \u5DF2\u540C\u6B65\u5230: ${e.path}`)}function Hp(e){if(typeof e!="string")return null;let t=e.trim();return t.length>0?t:null}async function Bp(e){let t=!!e.options.json,r=fn(e.options.path,process.cwd()),n=Hp(e.args.projectRef);try{Fp(e,"sync");let o=n?await gn({projectRef:n,parentDir:r}):await mn(wt(r),process.cwd());Gp(o,{json:t})}catch(o){let s=o instanceof Error?o.message:String(o);z(s.includes(".ojo/project.json")?new m("PROJECT_METADATA_MISSING",at,{status:404,source:"workspace"}):o)}}async function An(e){await Bp(e)}import Wp from"cli-table3";import zp from"terminal-link";function Jp(e){if(e==null||e===0)return"-";let t=e<1e10?e*1e3:e,r=new Date(t);return Number.isNaN(r.getTime())?"-":r.toISOString()}function Vp(e){return zp("\u6253\u5F00",e,{fallback:(t,r)=>r})}async function En(e){let t=e.options.json??!1,r=Number(e.options.pageSize??20),n=e.options.pageToken,o=e.options.favorite,s=await us({pageSize:r,pageToken:n,favorite:o});if(t){console.log(JSON.stringify(s,null,0));return}if(s.projects.length===0){S.info("\u6682\u65E0\u9879\u76EE");return}let i=Math.max(10,...s.projects.map(d=>le(d.project_id).length)),a=new Wp({head:["Project ID","Name","\u66F4\u65B0\u65F6\u95F4","\u94FE\u63A5"],colWidths:[40,32,26,i+2]});for(let d of s.projects){let p=le(d.project_id);a.push([d.project_id,d.name||"-",Jp(d.updated_at),Vp(p)])}console.log(a.toString());let c=s.total??0,u=c>0?`\u672C\u9875 ${s.projects.length} \u6761\uFF0C\u5171 ${c} \u6761`:`\u672C\u9875 ${s.projects.length} \u6761`;S.info(u),s.next_page_token&&S.info(`\u4F7F\u7528 --page-token ${s.next_page_token} \u67E5\u770B\u4E0B\u4E00\u9875`)}import{hostname as Xp}from"os";import fi from"open";import{existsSync as Kp,readFileSync as ui}from"fs";import xn from"path";import{fileURLToPath as qp}from"url";var Qp="unknown",ir="@touchine-ai/ojo",ke;function Yp(){let e=xn.dirname(qp(import.meta.url));for(;;){let t=xn.join(e,"package.json");if(Kp(t))try{let n=JSON.parse(ui(t,"utf8"));if(n.name===ir&&typeof n.version=="string"&&n.version.trim())return t}catch{}let r=xn.dirname(e);if(r===e)return;e=r}}function Ae(){if(ke)return ke;let e=process.env.npm_package_version?.trim();if(e)return ke=e,ke;try{let t=Yp();if(!t)throw new Error("Unable to locate CLI package.json");let r=JSON.parse(ui(t,"utf8"));if(typeof r.version=="string"&&r.version.trim())return ke=r.version.trim(),ke}catch{}return ke=Qp,ke}var Zp=process.env.NEXIGHT_CORS_ORIGIN??new URL(it).origin,di=600*1e3,el="OJO CLI",mi=Ae(),pi=q();function li(e){return new Promise(t=>setTimeout(t,e))}function tl(e){if(e<=0)return"\u4E0D\u8DB3 1 \u5206\u949F";if(e<60)return`${e} \u79D2`;let t=Math.floor(e/60),r=e%60;return r===0?`${t} \u5206\u949F`:`${t} \u5206 ${r} \u79D2`}async function rl(e){return await Hr(e),{event:"authenticated",ok:!0,mode:"access-key"}}function nl(e,t){console.log(`Starting local login server on http://${gt}:${e}.`),console.log("If your browser did not open, navigate to this URL to authenticate:"),console.log(""),console.log(t),console.log(""),console.log("On a remote or headless machine? Use `ojo auth login --mode device` instead."),console.log("")}function ol(e,t,r){console.log(`Welcome to OJO CLI [v${mi}]`),console.log("Aneway's command-line agent"),console.log(""),console.log("Follow these steps to sign in using device code authorization:"),console.log(""),console.log("1. Open this link in your browser and sign in to your account"),console.log(` ${e}`),console.log(""),console.log(`2. Enter this device code when prompted (expires in ${tl(r)})`),console.log(` ${t}`),console.log(""),console.log("Device codes are a common phishing target. Never share this code."),console.log("")}async function sl(e,t=!1,r){let n=Yt(),o=new Set([n]),s,i=new Promise(p=>{s=p}),{server:a,port:c}=await nn({apiBase:B,corsOrigin:Zp,validateState:p=>o.has(p)?(o.delete(p),!0):!1,onFirebaseLogin:p=>Lr(p),onCallbackComplete:()=>s(),onEmailSendCode:Mr,onEmailVerify:Dr}),u=`http://${gt}:${c}/callback`,d=$r({redirectUri:u,state:n});try{t?r?.({event:"login_required",mode:"web",loginUrl:d,expiresIn:di/1e3}):nl(c,d),e?t||S.info("\u5DF2\u8DF3\u8FC7\u81EA\u52A8\u6253\u5F00\u6D4F\u89C8\u5668\u3002"):await fi(d);let p,f=new Promise((l,h)=>{p=setTimeout(()=>h(new Error("\u767B\u5F55\u8D85\u65F6\uFF0C\u8BF7\u91CD\u8BD5")),di)});return await Promise.race([i,f]).finally(()=>{p&&clearTimeout(p)}),{event:"authenticated",ok:!0,mode:"web",loginUrl:d}}finally{a.close()}}async function il(e,t=!1,r){let n=(()=>{try{return Xp()}catch{return}})(),o=await Fr({clientName:el,clientVersion:mi,hostname:n}),s=o.verificationUri;if(t?r?.({event:"login_required",mode:"device",verificationUri:s,userCode:o.userCode,expiresIn:o.expiresIn}):ol(s,o.userCode,o.expiresIn),!e)try{await fi(s)}catch(c){t||S.warn(`\u81EA\u52A8\u6253\u5F00\u6388\u6743\u9875\u5931\u8D25\uFF0C\u8BF7\u624B\u52A8\u8BBF\u95EE\u4E0A\u65B9\u94FE\u63A5: ${c instanceof Error?c.message:String(c)}`)}t||S.info("\u7B49\u5F85\u6388\u6743\u5B8C\u6210...");let i=Math.max(1,o.interval)*1e3,a=Date.now()+Math.max(1,o.expiresIn)*1e3;for(;Date.now()<=a;){let c=await Gr(o.deviceCode),u=Math.max(1,c.interval||o.interval)*1e3;switch(c.status){case"approved":{if(!c.sessionId)throw new Error("\u6388\u6743\u6210\u529F\uFF0C\u4F46\u670D\u52A1\u7AEF\u672A\u8FD4\u56DE session_id");return t||console.log("Successfully logged in"),{event:"authenticated",ok:!0,mode:"device",verificationUri:s,userCode:o.userCode,expiresIn:o.expiresIn}}case"pending":i=u,await li(i);continue;case"slow_down":i=u,t||S.info(`\u6388\u6743\u5904\u7406\u4E2D\uFF0C\u5DF2\u8C03\u6574\u8F6E\u8BE2\u95F4\u9694\u4E3A ${Math.floor(i/1e3)} \u79D2`),await li(i);continue;case"denied":throw new Error("\u6388\u6743\u88AB\u62D2\u7EDD\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C ojo auth login");case"expired":throw new Error("\u8BBE\u5907\u7801\u5DF2\u8FC7\u671F\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C ojo auth login");case"consumed":throw new Error("\u672C\u6B21\u6388\u6743\u5DF2\u88AB\u6D88\u8D39\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C ojo auth login");default:throw new Error(`\u672A\u77E5\u7684\u8BBE\u5907\u767B\u5F55\u72B6\u6001: ${c.status}`)}}throw new Error("\u8BBE\u5907\u7801\u767B\u5F55\u8D85\u65F6\uFF0C\u8BF7\u91CD\u65B0\u6267\u884C ojo auth login")}async function Cn(e={}){let t=typeof e.mode=="string"?e.mode.trim().toLowerCase():void 0,r=(()=>{if(!t)return typeof e.accessKey=="string"&&e.accessKey.trim().length>0?"access-key":e.device?"device":"web";if(t==="web"||t==="device"||t==="access-key")return t;throw new Error(`\u4E0D\u652F\u6301\u7684\u767B\u5F55\u6A21\u5F0F: ${e.mode}`)})(),n=e.noOpen??!1,o=typeof e.accessKey=="string"?e.accessKey:"",s=e.json??!1,i=a=>{process.stdout.write(`${JSON.stringify(a)}
|
|
277
|
+
`)};if(r==="access-key"){!s&&o.trim().length===0&&S.info(`\u8BF7\u5148\u524D\u5F80 ${Ne} \u83B7\u53D6 AccessKey\u3002`);let a=await rl(o);if(s){i(a);return}S.success("\u767B\u5F55\u6210\u529F");return}if(r==="device"){let a=await il(n,s,i);s&&i(a);return}try{let a=await sl(n,s,i);pi.track("sys_auth_login",{mode:"web"}),s?i(a):S.success("\u767B\u5F55\u6210\u529F")}catch(a){throw pi.track("sys_auth_login_failed",{mode:"web",errorCode:W(a)}),a}}async function Tn(e={}){let t=await Br();if(e.json){process.stdout.write(`${JSON.stringify(t)}
|
|
278
|
+
`);return}S.success("\u5DF2\u9000\u51FA\u767B\u5F55")}import{execFile as al}from"child_process";import*as k from"fs";import*as P from"path";import{promisify as cl}from"util";import{parse as ul}from"parse5";var dl=cl(al),pl=1,ll="generate-prototype-build-gate.v1",fl=["page_id","stage_id","route_path","title","role","platform","split_reason","navigation","sections","responsive","functionality_hint","visual_hint","user_intent","not_owned"],ml=new Set(["single_page_entry","top_level_navigation","distinct_route","acceptance_critical_task","detail_drilldown","workflow_step"]),gl=new Set(["mobile","tablet","desktop"]),hl=["entry.page.tsx","index.page.tsx"];function X(){return Date.now()}function w(e,t,r){return{code:e,message:t,...r?{path:r}:{}}}function N(e){return typeof e!="string"?null:e.trim()||null}function $e(e){try{return{value:JSON.parse(k.readFileSync(e,"utf8"))}}catch(t){return{error:w("json.invalid",t instanceof Error?t.message:String(t),e)}}}function yl(e){return k.existsSync(P.join(e,"package.json"))&&k.existsSync(P.join(e,"rspack.config.ts"))}function ar(e,t=process.cwd()){let r=P.resolve(e?.trim()||t),n=[r,P.join(r,"prototype")];for(let o of n)if(yl(o))return o;throw new Error(`\u672A\u627E\u5230\u670D\u52A1\u7AEF\u539F\u578B workspace\uFF08\u9700\u8981 prototype/package.json \u4E0E prototype/rspack.config.ts\uFF09: ${r}`)}function _l(e){return k.existsSync(P.join(e,"delivery","artifacts","page-manifests"))}function wl(e,t=process.cwd()){let r=P.resolve(e?.trim()||t),n=[r,P.join(r,"prototype")];for(let o of n)if(_l(o))return o;throw new Error(`\u672A\u627E\u5230\u539F\u578B manifest\uFF08\u9700\u8981 prototype/delivery/artifacts/page-manifests\uFF09: ${r}`)}function hi(e,t){return t?.trim()?P.resolve(e,t.trim()):P.join(e,"dist")}function ne(e,t){return P.relative(e,t).replaceAll(P.sep,"/")}function Il(e){let t=[],r=[],n=P.join(e,"delivery","artifacts","page-manifests");if(!k.existsSync(n))return{pages:[],pageIds:[],errors:[w("manifest.directory_missing","\u7F3A\u5C11 delivery/artifacts/page-manifests \u76EE\u5F55",ne(e,n))],warnings:r};let o=k.readdirSync(n,{withFileTypes:!0}).filter(d=>d.isFile()&&d.name.endsWith(".json")).map(d=>P.join(n,d.name)).sort();o.length===0&&t.push(w("manifest.empty","page-manifests \u5FC5\u987B\u81F3\u5C11\u5305\u542B\u4E00\u4E2A\u9875\u9762 manifest",ne(e,n)));let s=[];for(let d of o){let p=$e(d);if(p.error){t.push(p.error);continue}if(!p.value||typeof p.value!="object"||Array.isArray(p.value)){t.push(w("manifest.object_required","\u9875\u9762 manifest \u6839\u8282\u70B9\u5FC5\u987B\u662F\u5BF9\u8C61",ne(e,d)));continue}s.push({filePath:d,value:p.value})}let i=[],a=new Set,c=new Set;for(let d of s){let p=ne(e,d.filePath),f=N(d.value.page_id);for(let I of fl){let y=d.value[I];(y==null||y===""||Array.isArray(y)&&y.length===0&&I!=="not_owned")&&t.push(w("manifest.required_field",`\u7F3A\u5C11\u5FC5\u586B\u5B57\u6BB5 ${I}`,p))}if(!f||!/^[a-z0-9][a-z0-9_-]*$/.test(f)){t.push(w("manifest.page_id","page_id \u5FC5\u987B\u662F\u5C0F\u5199\u4E14\u53EF\u5B89\u5168\u7528\u4E8E URL/\u6587\u4EF6\u540D",p));continue}P.basename(d.filePath,".json")!==f&&t.push(w("manifest.filename",`\u6587\u4EF6\u540D\u5FC5\u987B\u4E0E page_id \u4E00\u81F4: ${f}.json`,p)),i.includes(f)&&t.push(w("manifest.duplicate_page_id",`\u91CD\u590D page_id: ${f}`,p)),i.push(f);let l=N(d.value.stage_id);!l||!/^M\d+$/.test(l)?t.push(w("manifest.stage_id","stage_id \u5FC5\u987B\u4F7F\u7528\u7A33\u5B9A\u7684 M1\u3001M2\u2026 \u683C\u5F0F",p)):a.has(l)?t.push(w("manifest.duplicate_stage_id",`\u91CD\u590D stage_id: ${l}`,p)):a.add(l);let h=N(d.value.route_path);!h||!h.startsWith("/")||h.includes("#")?t.push(w("manifest.route_path","route_path \u5FC5\u987B\u4EE5 / \u5F00\u5934\u4E14\u4E0D\u80FD\u4F7F\u7528 hash \u8DEF\u7531",p)):c.has(h)?t.push(w("manifest.duplicate_route",`\u91CD\u590D route_path: ${h}`,p)):c.add(h),gl.has(N(d.value.platform)??"")||t.push(w("manifest.platform","platform \u53EA\u80FD\u662F mobile\u3001tablet \u6216 desktop",p)),ml.has(N(d.value.split_reason)??"")||t.push(w("manifest.split_reason","split_reason \u4E0D\u7B26\u5408 generate_prototype \u9875\u9762\u62C6\u5206\u5951\u7EA6",p)),Array.isArray(d.value.sections)||t.push(w("manifest.sections","sections \u5FC5\u987B\u662F\u6570\u7EC4",p)),(!d.value.navigation||typeof d.value.navigation!="object"||Array.isArray(d.value.navigation))&&t.push(w("manifest.navigation","navigation \u5FC5\u987B\u662F\u5BF9\u8C61",p))}let u=[...s].sort((d,p)=>{let f=Number.parseInt(N(d.value.stage_id)?.slice(1)??"999999",10),l=Number.parseInt(N(p.value.stage_id)?.slice(1)??"999999",10);return f-l});return u.length>0&&N(u[0].value.split_reason)!=="single_page_entry"&&t.push(w("manifest.entry_page","\u6700\u65E9 stage \u5FC5\u987B\u662F single_page_entry\uFF0C\u670D\u52A1\u7AEF\u4F7F\u7528\u9875\u9762\u8BA1\u5212\u987A\u5E8F\u9009\u62E9\u9ED8\u8BA4\u5165\u53E3",ne(e,u[0].filePath))),{pages:s,pageIds:i,errors:t,warnings:r}}function Sl(e,t){let r=new Set(t.pageIds),n=new Map,o=new Set;for(let a of t.pages){let c=N(a.value.page_id)??"",u=ne(e,a.filePath),d=new Set;if(Array.isArray(a.value.sections))for(let p of a.value.sections){if(!p||typeof p!="object"||Array.isArray(p)){t.errors.push(w("manifest.section_object","sections[] \u6BCF\u9879\u5FC5\u987B\u662F\u5BF9\u8C61",u));continue}let f=N(p.section_id);f?d.has(f)?t.errors.push(w("manifest.duplicate_section",`\u91CD\u590D section_id: ${f}`,u)):d.add(f):t.errors.push(w("manifest.section_id","\u6BCF\u4E2A section \u5FC5\u987B\u5305\u542B section_id",u))}n.set(c,d)}for(let a of t.pages){let c=ne(e,a.filePath),u=a.value.navigation,d=u?.uses_components;if(d!==void 0&&!Array.isArray(d))t.errors.push(w("manifest.uses_components","navigation.uses_components \u5FC5\u987B\u662F\u6570\u7EC4",c));else for(let f of d??[]){let l=N(f);l?o.add(l):t.errors.push(w("manifest.component_id","uses_components \u53EA\u80FD\u5305\u542B\u975E\u7A7A\u7EC4\u4EF6 id",c))}let p=u?.targets;if(p!==void 0&&!Array.isArray(p)){t.errors.push(w("manifest.navigation_targets","navigation.targets \u5FC5\u987B\u662F\u6570\u7EC4",c));continue}for(let f of p??[]){if(!f||typeof f!="object"||Array.isArray(f)){t.errors.push(w("manifest.navigation_target","navigation.targets[] \u6BCF\u9879\u5FC5\u987B\u662F\u5BF9\u8C61",c));continue}let l=f,h=N(l.target_type);if(h==="page"){let I=N(l.target_page_id);(!I||!r.has(I))&&t.errors.push(w("manifest.navigation_page",`\u9875\u9762\u8DF3\u8F6C\u76EE\u6807\u4E0D\u5B58\u5728: ${I??"(missing)"}`,c))}else if(h==="section"){let I=N(l.owner_page_id),y=N(l.section_id);!I||!r.has(I)?t.errors.push(w("manifest.navigation_section_owner",`section owner \u9875\u9762\u4E0D\u5B58\u5728: ${I??"(missing)"}`,c)):(!y||!n.get(I)?.has(y))&&t.errors.push(w("manifest.navigation_section",`section \u8DF3\u8F6C\u76EE\u6807\u4E0D\u5B58\u5728: ${I}/${y??"(missing)"}`,c))}else t.errors.push(w("manifest.navigation_type","target_type \u53EA\u80FD\u662F page \u6216 section\uFF1B\u5916\u90E8\u8DF3\u8F6C\u4E0D\u5C5E\u4E8E\u539F\u578B\u5BFC\u822A",c))}}let s=P.join(e,"delivery","artifacts","component-requirements.json"),i=new Set;if(k.existsSync(s)){let a=$e(s);if(a.error)t.errors.push(a.error);else if(!a.value||typeof a.value!="object"||Array.isArray(a.value))t.errors.push(w("manifest.component_requirements","component-requirements.json \u6839\u8282\u70B9\u5FC5\u987B\u662F\u5BF9\u8C61",ne(e,s)));else{let c=a.value;for(let u of["components","usage_by_page","page_component_requirements"])u in c||t.errors.push(w("manifest.component_required_field",`component-requirements.json \u7F3A\u5C11 ${u}`,ne(e,s)));if(!Array.isArray(c.components))t.errors.push(w("manifest.components","component-requirements.json components \u5FC5\u987B\u662F\u6570\u7EC4",ne(e,s)));else for(let u of c.components){if(!u||typeof u!="object"||Array.isArray(u))continue;let d=N(u.component_id);d&&i.add(d)}}}for(let a of o)i.has(a)||t.errors.push(w("manifest.unknown_component",`\u9875\u9762\u5F15\u7528\u4E86\u672A\u58F0\u660E\u7684\u5171\u4EAB\u7EC4\u4EF6: ${a}`,ne(e,s)))}function yi(e){let t=X(),r=Il(e);return Sl(e,r),{phase:{name:"manifest",status:r.errors.length>0?"failed":"passed",durationMs:X()-t,errors:r.errors,warnings:r.warnings},context:r}}function _i(e,t){let r=X(),n=[],o=[],s=["package.json","rspack.config.ts","tsconfig.json","src/data/app.json","delivery/artifacts/theme.json"];for(let u of s){let d=P.join(e,u);k.existsSync(d)||n.push(w("source.required_file",`\u7F3A\u5C11\u670D\u52A1\u7AEF\u539F\u578B\u6784\u5EFA\u6587\u4EF6: ${u}`,u))}let i=P.join(e,"package.json");if(k.existsSync(i)){let u=$e(i);if(u.error)n.push(u.error);else{let d=u.value,p=d.scripts;N(p?.build)||n.push(w("source.build_script","package.json \u5FC5\u987B\u5B9A\u4E49 scripts.build","package.json")),N(p?.typecheck)||n.push(w("source.typecheck_script","package.json \u5FC5\u987B\u5B9A\u4E49 scripts.typecheck","package.json")),N(d.packageManager)?.startsWith("pnpm@")||n.push(w("source.package_manager","\u670D\u52A1\u7AEF generate_prototype workspace \u5FC5\u987B\u58F0\u660E pnpm packageManager","package.json"))}}for(let u of t.pageIds){let d=P.join(e,"src","pages",u),p=hl.some(l=>k.existsSync(P.join(d,l))),f=k.existsSync(P.join(e,"src","pages",`${u}.page.tsx`));!p&&!f&&n.push(w("source.page_entry",`\u9875\u9762 ${u} \u7F3A\u5C11 entry.page.tsx\u3001index.page.tsx \u6216 ${u}.page.tsx`,ne(e,d)))}let a=P.join(e,"src","data","app.json");if(k.existsSync(a)){let u=$e(a);if(u.error)n.push(u.error);else if(!u.value||typeof u.value!="object"||Array.isArray(u.value))n.push(w("source.app_json","src/data/app.json \u5FC5\u987B\u662F\u5BF9\u8C61","src/data/app.json"));else{let d=u.value,p=N(d.entryPage);(!p||!t.pageIds.includes(p))&&n.push(w("source.entry_page",`app.json entryPage \u5FC5\u987B\u5F15\u7528\u5DF2\u58F0\u660E\u9875\u9762: ${p??"(missing)"}`,"src/data/app.json")),(!Array.isArray(d.pages)||!p||!d.pages.includes(p))&&n.push(w("source.app_pages","app.json pages \u5FC5\u987B\u5305\u542B entryPage\uFF1B\u5176\u4ED6\u9875\u9762\u7531 Rspack entry \u4E0E manifest \u96C6\u5408\u53D1\u73B0","src/data/app.json"))}}let c=P.join(e,"delivery","artifacts","theme.json");if(k.existsSync(c)){let u=$e(c);u.error?n.push(u.error):(!u.value||typeof u.value!="object"||Array.isArray(u.value))&&n.push(w("source.theme_json","delivery/artifacts/theme.json \u5FC5\u987B\u662F\u5BF9\u8C61","delivery/artifacts/theme.json"))}return{name:"source",status:n.length>0?"failed":"passed",durationMs:X()-r,errors:n,warnings:o}}function wi(e){let t=X(),r=["tsc","rspack"].filter(n=>!k.existsSync(P.join(e,"node_modules",".bin",n)));return{name:"dependencies",status:r.length>0?"failed":"passed",durationMs:X()-t,errors:r.map(n=>w("dependencies.missing_binary",`\u7F3A\u5C11 node_modules/.bin/${n}\uFF1B\u5148\u6309 lockfile \u5B89\u88C5\u4F9D\u8D56`,`node_modules/.bin/${n}`)),warnings:[]}}async function gi(e,t,r){let n=X(),o=e==="typecheck"?["exec","tsc","--noEmit"]:["exec","rspack","build"],s=`pnpm ${o.join(" ")}`;try{let i=await dl("pnpm",o,{cwd:t,env:{...process.env,CI:"true",COREPACK_ENABLE_DOWNLOAD_PROMPT:"0",PNPM_CONFIG_CONFIRM_MODULES_PURGE:"false",...e==="bundle"?{IRISE_BUILD_OUTPUT_DIR:r}:{}},timeout:3e5,maxBuffer:8388608});return{name:e,status:"passed",durationMs:X()-n,errors:[],warnings:[],command:s,stdout:i.stdout,stderr:i.stderr}}catch(i){let a=i;return{name:e,status:"failed",durationMs:X()-n,errors:[w(`compile.${e}`,`${e} \u5931\u8D25${a.code!==void 0?` (code=${String(a.code)})`:""}: ${a.message}`)],warnings:[],command:s,stdout:a.stdout,stderr:a.stderr}}}function Pl(e){if(!k.existsSync(e))return[];let t=[],r=n=>{for(let o of k.readdirSync(n,{withFileTypes:!0})){let s=P.join(n,o.name);o.isDirectory()?r(s):o.isFile()&&t.push(s)}};return r(e),t}function Rl(e){let t=new Set,r=!1,n=!1,o=i=>{for(let a of i.matchAll(/url\(\s*["']?([^"')]+)["']?\s*\)/gi))t.add(a[1].trim())},s=[ul(e,{sourceCodeLocationInfo:!0})];for(;s.length>0;){let i=s.pop();if(!i)break;if("childNodes"in i)for(let c of i.childNodes)s.push(c);if(!("tagName"in i))continue;i.tagName==="template"&&s.push(i.content),i.sourceCodeLocation?.startTag&&/^(html|body|div|main|section)$/.test(i.tagName)&&(r=!0);for(let{name:c,value:u}of i.attrs)c==="src"||c==="href"?t.add(u.trim()):c==="style"&&o(u);let a=i.tagName==="script"&&i.attrs.some(({name:c,value:u})=>c==="type"&&u.trim().toLowerCase()==="module");if(i.tagName==="style"||a){let c=i.childNodes.map(u=>"value"in u?u.value:"").join("");i.tagName==="style"?o(c):/^\s*import\s/u.test(c)&&(n=!0)}}return{refs:t,hasRenderSurface:r,hasUncompiledModule:n}}function Ii(e,t,r){let n=X(),o=[],s=[];if(!k.existsSync(t))o.push(w("package.dist_missing","\u6784\u5EFA\u672A\u4EA7\u751F dist \u76EE\u5F55",ne(e,t)));else{let i=new Set(Pl(t).map(c=>P.relative(t,c).replaceAll(P.sep,"/")));for(let c of r.pageIds){let u=`${c}.html`;i.has(u)||o.push(w("package.frame_missing",`\u6700\u7EC8\u5305\u7F3A\u5C11\u9875\u9762 frame: ${u}`,u))}for(let c of["data/theme.json","data/store.json"])if(!i.has(c))o.push(w("package.data_missing",`\u6700\u7EC8\u5305\u7F3A\u5C11 ${c}`,c));else if(c.endsWith(".json")){let u=$e(P.join(t,c));u.error&&o.push({...u.error,path:c})}for(let c of[...i].filter(u=>u.endsWith(".html"))){let u=k.readFileSync(P.join(t,c),"utf8"),{refs:d,hasRenderSurface:p,hasUncompiledModule:f}=Rl(u);p||o.push(w("package.render_surface",`${c} \u6CA1\u6709\u53EF\u6E32\u67D3 HTML surface`,c)),[...d].some(l=>l.startsWith("/")&&!l.startsWith("//"))&&o.push(w("package.root_absolute_ref",`${c} \u4F7F\u7528\u4E86\u6839\u7EDD\u5BF9\u8D44\u6E90\u8DEF\u5F84`,c)),f&&o.push(w("package.uncompiled_module",`${c} \u4ECD\u5305\u542B\u672A\u7F16\u8BD1 module import`,c));for(let l of d){if(!l||/^(?:#|data:|blob:|javascript:|mailto:|tel:|https?:|\/)/i.test(l))continue;let h=P.posix.normalize(P.posix.join(P.posix.dirname(c),l.split(/[?#]/,1)[0]));i.has(h)||o.push(w("package.asset_missing",`${c} \u5F15\u7528\u4E86\u4E0D\u5B58\u5728\u7684\u5305\u5185\u8D44\u6E90: ${l}`,c))}}let a=P.join(t,"data","blueprint.json");if(k.existsSync(a)){let c=$e(a);if(c.error)o.push({...c.error,path:"data/blueprint.json"});else if(!c.value||typeof c.value!="object"||Array.isArray(c.value))o.push(w("package.blueprint_object","blueprint \u6839\u8282\u70B9\u5FC5\u987B\u662F\u5BF9\u8C61","data/blueprint.json"));else{let u=c.value,d=N(u.entryPage??u.entry_page);(!d||!r.pageIds.includes(d))&&o.push(w("package.blueprint_entry",`blueprint entryPage \u5FC5\u987B\u5F15\u7528\u5DF2\u53D1\u5E03\u9875\u9762: ${d??"(missing)"}`,"data/blueprint.json")),Array.isArray(u.snapshots)||o.push(w("package.blueprint_snapshots","blueprint.snapshots \u5FC5\u987B\u662F\u6570\u7EC4","data/blueprint.json"))}}}return{name:"package",status:o.length>0?"failed":"passed",durationMs:X()-n,errors:o,warnings:s}}async function vl(e,t){let r=X(),n=P.dirname(t),o=P.join(n,`.${P.basename(t)}.ojo-backup-${process.pid}-${Date.now()}`);try{await k.promises.mkdir(n,{recursive:!0}),k.existsSync(t)&&await k.promises.rename(t,o);try{await k.promises.rename(e,t)}catch(s){throw k.existsSync(o)&&await k.promises.rename(o,t),s}return await k.promises.rm(o,{recursive:!0,force:!0}),{name:"promote",status:"passed",durationMs:X()-r,errors:[],warnings:[]}}catch(s){return{name:"promote",status:"failed",durationMs:X()-r,errors:[w("promote.failed",s instanceof Error?s.message:String(s),t)],warnings:[]}}}function Ue(e,t,r,n,o,s){let i=s.every(a=>a.status!=="failed");return{ok:i,status:i?"passed":"failed",protocol:ll,protocolVersion:pl,mode:e,workspacePath:t,prototypeRoot:r,distPath:n,pageIds:o,phases:s}}async function Si(e={}){let t=P.resolve(e.workspacePath?.trim()||e.cwd||process.cwd());if(e.manifestOnly&&e.prebuild)throw new Error("--manifest-only \u4E0E --prebuild \u4E0D\u80FD\u540C\u65F6\u4F7F\u7528");let r=e.manifestOnly?wl(e.workspacePath,e.cwd):ar(e.workspacePath,e.cwd),n=hi(r,e.distPath),o=yi(r);if(e.manifestOnly)return Ue("validate",t,r,n,o.context.pageIds,[o.phase]);let s=_i(r,o.context);if(e.prebuild){let a=wi(r);return Ue("validate",t,r,n,o.context.pageIds,[o.phase,s,a])}let i=Ii(r,n,o.context);return Ue("validate",t,r,n,o.context.pageIds,[o.phase,s,i])}async function cr(e={}){let t=P.resolve(e.workspacePath?.trim()||e.cwd||process.cwd()),r=ar(e.workspacePath,e.cwd),n=hi(r,e.distPath),o=P.join(P.dirname(n),`.${P.basename(n)}.ojo-build-${process.pid}-${Date.now()}`),s=[],i=yi(r);s.push(i.phase);let a=_i(r,i.context);s.push(a);let c=wi(r);if(s.push(c),s.some(u=>u.status==="failed"))return Ue("build",t,r,n,i.context.pageIds,s);await k.promises.rm(o,{recursive:!0,force:!0});try{let[u,d]=await Promise.all([gi("typecheck",r,o),gi("bundle",r,o)]);if(s.push(u,d),u.status==="failed"||d.status==="failed")return Ue("build",t,r,n,i.context.pageIds,s);let p=Ii(r,o,i.context);return s.push(p),p.status==="failed"||s.push(await vl(o,n)),Ue("build",t,r,n,i.context.pageIds,s)}finally{await k.promises.rm(o,{recursive:!0,force:!0})}}import{createHash as Ri}from"crypto";import*as Ee from"fs";import*as L from"path";import kl from"jszip";var Al=new Set(["node_modules",".git",".rspack-cache",".temp-entries"]),El=new Date("2000-01-01T00:00:00.000Z");function Pi(e){return Ri("sha256").update(e).digest("hex")}function bn(e){switch(L.extname(e).toLowerCase()){case".html":return"text/html; charset=utf-8";case".json":case".map":return"application/json";case".js":case".mjs":return"application/javascript";case".css":return"text/css; charset=utf-8";case".svg":return"image/svg+xml";case".png":return"image/png";case".jpg":case".jpeg":return"image/jpeg";case".webp":return"image/webp";case".woff2":return"font/woff2";case".woff":return"font/woff";default:return"application/octet-stream"}}function vi(e,t=!1){let r=[],n=o=>{for(let s of Ee.readdirSync(o,{withFileTypes:!0}).sort((i,a)=>i.name.localeCompare(a.name))){if(t&&s.isDirectory()&&Al.has(s.name))continue;let i=L.join(o,s.name);s.isDirectory()?n(i):s.isFile()&&r.push(L.relative(e,i).replaceAll(L.sep,"/"))}};return n(e),r.sort(ki)}function ki(e,t){return Buffer.compare(Buffer.from(e,"utf8"),Buffer.from(t,"utf8"))}function Ai(e){let t=Ri("sha256");for(let r of[...e].sort((n,o)=>ki(n.path,o.path)))t.update(r.content),t.update(r.path);return t.digest("hex")}async function xl(e){let t=new kl,r=vi(e,!0).map(n=>({path:n,content:Ee.readFileSync(L.join(e,n))}));for(let n of r)t.file(n.path,n.content,{date:El});return{content:await t.generateAsync({type:"nodebuffer",compression:"DEFLATE",compressionOptions:{level:6}}),hash:Ai(r)}}function Cl(e,t){let r=`<base href="${t.replaceAll("&","&").replaceAll('"',""")}">`,n=e.toString("utf8");return/<base\b[^>]*>/i.test(n)?n=n.replace(/<base\b[^>]*>/i,r):/<head\b[^>]*>/i.test(n)?n=n.replace(/<head\b[^>]*>/i,o=>o+r):/<html\b[^>]*>/i.test(n)?n=n.replace(/<html\b[^>]*>/i,o=>`${o}<head>${r}</head>`):n=`<head>${r}</head>${n}`,Buffer.from(n,"utf8")}function Tl(e,t){let r=L.join(e,"data","app.json");if(Ee.existsSync(r))try{let o=JSON.parse(Ee.readFileSync(r,"utf8"));if(typeof o.entryPage=="string"&&t.includes(`${o.entryPage}.html`))return`${o.entryPage}.html`}catch{}for(let o of["index.html","home.html"])if(t.includes(o))return o;let n=t.find(o=>o.toLowerCase().endsWith(".html"));if(!n)throw new Error("\u6784\u5EFA\u4EA7\u7269\u6CA1\u6709 HTML frame");return n}function Z(e,t,r){let n=e.find(o=>o.role===t&&(r===void 0||o.path===r));if(!n?.resource_key)throw new Error(`\u670D\u52A1\u7AEF\u672A\u8FD4\u56DE\u4E0A\u4F20\u76EE\u6807: ${t}${r?`/${r}`:""}`);return n}async function bl(e,t,r){if(!e.exists){if(!e.upload_url||!e.upload_object_key)throw new Error(`\u4E0A\u4F20\u51ED\u8BC1\u4E0D\u5B8C\u6574: ${e.role}/${e.path??""}`);let n=new Blob([new Uint8Array(t)],{type:r});if(e.upload_provider==="local"){let o=await fetch(e.upload_url,{method:"PUT",headers:{"Content-Type":r},body:n});if(!o.ok)throw new Error(`\u672C\u5730\u5BF9\u8C61\u4E0A\u4F20\u5931\u8D25 (${o.status}): ${e.role}/${e.path??""}`)}else{let o=new FormData;o.append("key",e.upload_object_key);let s=e.upload_headers??{};o.append("Content-Type",s["Content-Type"]||r||"application/octet-stream");for(let[a,c]of Object.entries(s))a!=="Content-Type"&&!o.has(a)&&o.append(a,c);o.append("file",n,L.basename(e.path||e.upload_object_key));let i=await fetch(e.upload_url,{method:"POST",body:o});if(!i.ok)throw new Error(`\u5BF9\u8C61\u4E0A\u4F20\u5931\u8D25 (${i.status}): ${e.role}/${e.path??""}`)}}await j.post(`/resources/${encodeURIComponent(e.resource_key)}/ready`,{resourceKey:e.resource_key,resourceActualSizeBytes:t.length})}async function jl(e,t,r){let n=0;await Promise.all(Array.from({length:Math.min(t,e.length)},async()=>{for(;n<e.length;){let o=e[n++];await r(o)}}))}async function Ei(e){let t=e.projectId.trim();if(!t)throw new Error("prototype publish \u5FC5\u987B\u63D0\u4F9B --project-id");let r=await cr({workspacePath:e.workspacePath,distPath:e.distPath});if(!r.ok)throw new Error("\u672C\u5730\u539F\u578B build \u95E8\u7981\u672A\u901A\u8FC7\uFF0C\u62D2\u7EDD\u4E0A\u4F20");let n=ar(e.workspacePath),o=L.resolve(e.workspacePath?.trim()||process.cwd()),s=n===L.join(o,"prototype")?o:n,i=L.resolve(r.distPath),a=L.relative(s,i);if(a.startsWith("..")||L.isAbsolute(a))throw new Error("\u7F16\u8BD1\u4EA7\u7269\u5FC5\u987B\u4F4D\u4E8E\u5F53\u524D\u672C\u5730 workspace \u5185");let c=vi(i).filter(R=>R!=="manifest.json").map(R=>({path:R,content:Ee.readFileSync(L.join(i,R))})).filter(R=>R.content.length>0),u=c.map(R=>R.path),d=Tl(i,u),p=c.map(R=>({path:R.path,content_type:bn(R.path),size_bytes:R.content.length,sha256:Pi(R.content)})),f=await xl(s),l=await _t(t),h=Number(l.project?.version??0),y=(await j.post(`/projects/${encodeURIComponent(t)}/prototype-publish:prepare`,{workspace_hash:f.hash,entry_path:d,files:p,has_blueprint:u.includes("data/blueprint.json")})).data;if(y.schema_version!==1||!y.dist_base_href)throw new Error("\u670D\u52A1\u7AEF\u8FD4\u56DE\u4E86\u4E0D\u517C\u5BB9\u7684 prototype publish \u534F\u8BAE");let _=c.map(R=>({path:R.path,content:R.path.toLowerCase().endsWith(".html")?Cl(R.content,y.dist_base_href):R.content})),b=_.map(R=>{let xe=Z(y.uploads,"dist",R.path);return{path:R.path,resource_key:xe.resource_key,object_key:xe.upload_object_key,content_type:bn(R.path),size_bytes:R.content.length,sha256:Pi(R.content)}}),v=Ai(_),te=Z(y.uploads,"manifest"),g=Buffer.from(`${JSON.stringify({schema_version:1,kind:"prototype_dist_manifest",workspace_hash:f.hash,dist_hash:v,entry_path:d,files:b})}
|
|
279
|
+
`,"utf8"),A=Buffer.from(`${JSON.stringify(r)}
|
|
280
|
+
`,"utf8"),oe=new Map(_.map(R=>[R.path,R.content])),se=[{credential:Z(y.uploads,"workspace"),content:f.content,type:"application/zip"},..._.map(R=>({credential:Z(y.uploads,"dist",R.path),content:R.content,type:bn(R.path)})),{credential:te,content:g,type:"application/json"},{credential:Z(y.uploads,"theme"),content:oe.get("data/theme.json"),type:"application/json"},{credential:Z(y.uploads,"store"),content:oe.get("data/store.json"),type:"application/json"},{credential:Z(y.uploads,"acceptance"),content:A,type:"application/json"}];u.includes("data/blueprint.json")&&se.push({credential:Z(y.uploads,"blueprint"),content:oe.get("data/blueprint.json"),type:"application/json"}),await jl(se,4,R=>bl(R.credential,R.content,R.type));let K=await j.post(`/projects/${encodeURIComponent(t)}/prototype-publish:commit`,{base_version:Number.isFinite(h)?h:0,workspace_hash:f.hash,dist_hash:v,entry_path:d,dist_storage_prefix:y.dist_storage_prefix,source_zip_resource_key:Z(y.uploads,"workspace").resource_key,manifest_resource_key:te.resource_key,theme_resource_key:Z(y.uploads,"theme").resource_key,blueprint_resource_key:u.includes("data/blueprint.json")?Z(y.uploads,"blueprint").resource_key:"",store_resource_key:Z(y.uploads,"store").resource_key,acceptance_resource_key:Z(y.uploads,"acceptance").resource_key,files:b});return{ok:!0,projectId:t,publishId:y.publish_id,workspacePath:s,distPath:i,workspaceHash:f.hash,distHash:v,manifestResourceKey:te.resource_key,sourceZipResourceKey:Z(y.uploads,"workspace").resource_key,newVersion:Number(K.data.new_version??0),fileCount:b.length,build:r}}function Pt(e){return typeof e!="string"?void 0:e.trim()||void 0}function xi(e,t){if(t)process.stdout.write(`${JSON.stringify(e)}
|
|
281
|
+
`);else if(e.ok)S.success(`\u539F\u578B ${e.mode==="build"?"\u6784\u5EFA":"\u6821\u9A8C"}\u95E8\u7981\u901A\u8FC7: ${e.distPath}`);else{S.error(`\u539F\u578B ${e.mode==="build"?"\u6784\u5EFA":"\u6821\u9A8C"}\u95E8\u7981\u5931\u8D25`);for(let r of e.phases)for(let n of r.errors)S.error(`[${r.name}] ${n.message}`)}e.ok||(process.exitCode=1)}function Ci(e){return{workspacePath:Pt(e.args.workspacePath),distPath:Pt(e.options.dist),prebuild:!!e.options.prebuild,manifestOnly:!!e.options.manifestOnly}}async function jn(e){let t=await Si(Ci(e));xi(t,!!e.options.json)}async function On(e){let t=Ci(e),r=await cr({workspacePath:t.workspacePath,distPath:t.distPath});xi(r,!!e.options.json)}async function Nn(e){let t=Pt(e.options.projectId);if(!t)throw new Error("prototype publish \u5FC5\u987B\u63D0\u4F9B --project-id");let r=await Ei({projectId:t,workspacePath:Pt(e.args.workspacePath),distPath:Pt(e.options.dist)});e.options.json?process.stdout.write(`${JSON.stringify(r)}
|
|
282
|
+
`):S.success(`\u672C\u5730\u539F\u578B\u5DF2\u4E0A\u4F20\u5E76\u5207\u6362\u5230\u9879\u76EE ${r.projectId}\uFF08draft v${r.newVersion}\uFF09`)}import{createHash as Ti}from"crypto";import*as me from"fs";import*as H from"path";var Ln={image:"images",pdf:"documents",markdown:"text",html:"html",docx:"documents"};function T(e){return e&&typeof e=="object"&&!Array.isArray(e)?e:void 0}function C(e){return typeof e=="string"?e.trim():""}function Ol(e){let t=Number(e.draft_version??e.draftVersion??0);if(!Number.isSafeInteger(t)||t<0)throw new Error("\u670D\u52A1\u7AEF\u8FD4\u56DE\u4E86\u65E0\u6548\u7684 draft version");return t}function Nl(e){let t=T(e);return Array.isArray(t?.mutations)?t.mutations:[]}function Ll(e){let t=T(e.project.draft),r=T(t?.keyframe);if(!Array.isArray(r?.mutations))throw new Error("canvas-export.json \u7F3A\u5C11 project.draft.keyframe.mutations");return r.mutations}function pr(e,t){if(typeof e=="string"){t(e);return}if(Array.isArray(e)){for(let n of e)pr(n,t);return}let r=T(e);if(r)for(let n of Object.values(r))pr(n,t)}function Ge(e,t){let r=!1;return pr(e,n=>{t.has(n)&&(r=!0)}),r}function Mn(e,t){if(typeof e=="string")return t.get(e)??e;if(Array.isArray(e))return e.map(n=>Mn(n,t));let r=T(e);return r?Object.fromEntries(Object.entries(r).map(([n,o])=>[n,Mn(o,t)])):e}function Oi(e){return new Set([e.local_id,e.resource_key,e.short_id])}function lr(e){let t=Oi(e),r=C(e.upload.remote_resource_key),n=C(e.upload.remote_short_id);return r&&t.add(r),n&&t.add(n),t}function dr(e,t,r){let n=T(e);return T(n?.[t])??T(n?.[r])}function bi(e){for(let[t,r]of[["create_resource_node","createResourceNode"],["update_resource_node","updateResourceNode"],["update_node_layout","updateNodeLayout"]]){let n=dr(e,t,r),o=C(n?.node_id??n?.nodeId);if(o)return o}return""}function Fe(e,t,r){return e?.[t]??e?.[r]}function Ml(e,t,r){let n=lr(e),o=new Set(t.filter(s=>Ge(s,n)).map(bi).filter(Boolean));if(o.size===0)throw new Error(`\u672C\u5730\u8D44\u6E90\u6CA1\u6709\u5BF9\u5E94\u7684\u753B\u5E03\u8282\u70B9 mutation: ${e.local_id}`);return[...o].map(s=>{let i="1",a=e.kind,c=e.original_name,u="",d="local-upload",p;for(let f of t){if(bi(f)!==s)continue;let l=dr(f,"create_resource_node","createResourceNode")??dr(f,"update_resource_node","updateResourceNode"),h=dr(f,"update_node_layout","updateNodeLayout");if(l){i=C(Fe(l,"version","version"))||i;let I=C(Fe(l,"kind","kind"));Object.hasOwn(Ln,I)&&(a=I),c=C(Fe(l,"name","name"))||c,u=C(Fe(l,"parent_group_id","parentGroupId"))||u,d=C(Fe(l,"creation_source","creationSource"))||d,p=Fe(l,"layout_property","layoutProperty")??p}p=Fe(h,"layout_property","layoutProperty")??p}if(!p)throw new Error(`\u672C\u5730\u8D44\u6E90\u8282\u70B9\u7F3A\u5C11\u5E03\u5C40\u4FE1\u606F: ${s}`);return{type:"CreateResourceNode",create_resource_node:{version:i,node_id:s,kind:a,layout_property:p,resource_short_id:r,name:c,parent_group_id:u,creation_source:d}}})}function fr(e,t,r){if(Array.isArray(e)){for(let o of e)fr(o,t,r);return}let n=T(e);if(n)for(let[o,s]of Object.entries(n))o===t&&typeof s=="string"&&s.trim()&&r.add(s.trim()),fr(s,t,r)}function Ni(e,t){let r=[];for(let n of e){let o=new Set;if(pr(n,i=>{t.has(i)&&o.add(i)}),o.size===0)continue;let s=new Set;fr(n,"node_id",s),r.push({localAliases:o,remoteAliases:new Set([...o].map(i=>t.get(i)).filter(Boolean)),nodeIds:s})}return r}function Li(e,t){let r=new Set(t.flatMap(n=>[...n.localAliases]));return e.some(n=>Ge(n,r))?!1:t.every(n=>[...n.remoteAliases].every(o=>e.some(s=>{if(!Ge(s,new Set([o])))return!1;if(n.nodeIds.size===0)return!0;let i=new Set;return fr(s,"node_id",i),[...n.nodeIds].some(a=>i.has(a))})))}function Dl(e){return e.kind==="image"?{resourcePrefix:"ojo_img",shortPrefix:"image"}:e.kind==="pdf"?{resourcePrefix:"pdf",shortPrefix:"pdf"}:e.kind==="docx"?{resourcePrefix:"doc",shortPrefix:"docx"}:e.kind==="html"?{resourcePrefix:"txt",shortPrefix:"html"}:{resourcePrefix:"txt",shortPrefix:e.content_type.split(";",1)[0]?.trim().toLowerCase()==="text/plain"?"txt":"markdown"}}function Ul(e){let t=H.resolve(e),r=H.basename(t)==="canvas-export.json"?t:H.join(t,"canvas-export.json");return{root:H.dirname(r),manifestPath:r}}function Dn(e,t){let r=JSON.parse(me.readFileSync(e,"utf8"));if(r.schema_version!==1||r.project_id!==t||r.local_resource_schema_version!==1||!T(r.project)||!T(r.local_resources))throw new Error("\u672C\u5730 canvas export \u4E0E\u6307\u5B9A\u9879\u76EE\u6216 local resource schema \u4E0D\u5339\u914D");return r}function Mi(e,t,r){if(t!==r.local_id||r.identity_scope!=="local")throw new Error(`\u672C\u5730\u8D44\u6E90\u8EAB\u4EFD\u65E0\u6548: ${t}`);if(!Object.hasOwn(Ln,r.kind)||Ln[r.kind]!==r.type_path)throw new Error(`\u672C\u5730\u8D44\u6E90\u7C7B\u578B\u76EE\u5F55\u65E0\u6548: ${r.local_id}`);let n=`resource/${r.type_path}/`;if(!r.relative_path.startsWith(n)||H.posix.normalize(r.relative_path)!==r.relative_path)throw new Error(`\u672C\u5730\u8D44\u6E90\u8DEF\u5F84\u8D8A\u754C: ${r.local_id}`);let o=H.resolve(e,...r.relative_path.split("/")),s=H.resolve(e,"resource");if(!o.startsWith(`${s}${H.sep}`))throw new Error(`\u672C\u5730\u8D44\u6E90\u8DEF\u5F84\u8D8A\u754C: ${r.local_id}`);let i=me.lstatSync(o);if(!i.isFile()||i.isSymbolicLink())throw new Error(`\u672C\u5730\u8D44\u6E90\u5FC5\u987B\u662F\u666E\u901A\u6587\u4EF6: ${r.local_id}`);let a=me.realpathSync(s);if(!me.realpathSync(o).startsWith(`${a}${H.sep}`))throw new Error(`\u672C\u5730\u8D44\u6E90\u8DEF\u5F84\u8D8A\u754C: ${r.local_id}`);let u=me.readFileSync(o),d=Ti("sha256").update(u).digest("hex");if(u.byteLength!==r.size_bytes||d!==r.sha256)throw new Error(`\u672C\u5730\u8D44\u6E90\u6821\u9A8C\u548C\u6216\u5B57\u8282\u6570\u4E0D\u5339\u914D: ${r.local_id}`);let p=r.content_type.split(";",1)[0]?.trim().toLowerCase()||"application/octet-stream",f=Ti("sha256").update(r.kind).update("\0").update(p).update("\0").update(d).digest("hex"),l=Dl(r);if(r.local_id!==`local_${r.kind}_${f.slice(0,24)}`)throw new Error(`\u672C\u5730\u8D44\u6E90 local_id \u4E0E\u5185\u5BB9\u4E0D\u5339\u914D: ${r.local_id}`);if(r.resource_key!==`${l.resourcePrefix}_${f.slice(0,12)}`)throw new Error(`\u672C\u5730\u8D44\u6E90 key \u4E0E\u5185\u5BB9\u4E0D\u5339\u914D: ${r.local_id}`);if(!r.short_id.startsWith(`${l.shortPrefix}-${f.slice(0,4)}`))throw new Error(`\u672C\u5730\u8D44\u6E90 short_id \u4E0E\u5185\u5BB9\u4E0D\u5339\u914D: ${r.local_id}`);return u}async function $l(e,t){let r=`${e}.next-${process.pid}-${Date.now()}`;await me.promises.writeFile(r,`${JSON.stringify(t,null,2)}
|
|
283
|
+
`,"utf8"),await me.promises.rename(r,e)}async function mr(e,t,r){let n=Dn(e,t);return r(n),await $l(e,n),n}function Di(e){return(e instanceof Error?e.message:String(e)).slice(0,500)}async function ji(e,t,r,n){await mr(e,t,o=>{let s=o.local_resources?.[r];if(!s)throw new Error(`\u672C\u5730\u8D44\u6E90\u5DF2\u4ECE manifest \u6D88\u5931: ${r}`);s.upload={...s.upload,...n},s.updated_at=new Date().toISOString()})}function ur(e,t,r){return C(e[t])||C(e[r])}async function Fl(e,t,r){let n=ur(e,"resource_key","resourceKey"),o=ur(e,"upload_url","uploadUrl"),s=ur(e,"upload_object_key","uploadObjectKey"),i=ur(e,"upload_provider","uploadProvider"),a=e.upload_headers??e.uploadHeaders??{};if(!n||!o||!s)throw new Error(`\u670D\u52A1\u7AEF\u672A\u8FD4\u56DE\u5B8C\u6574\u4E0A\u4F20\u51ED\u8BC1: ${t.local_id}`);let c=new Blob([new Uint8Array(r)],{type:t.content_type}),u;if(i==="local")u=await fetch(o,{method:"PUT",headers:{"Content-Type":t.content_type},body:c});else{let d=new FormData,p=Object.entries(a),f=i==="s3"||p.some(([l])=>l.toLowerCase().startsWith("x-amz-"));d.append("key",s),f&&d.append("Content-Type",a["Content-Type"]||t.content_type||"application/octet-stream");for(let[l,h]of p)l!=="Content-Type"&&!d.has(l)&&d.append(l,h);d.append("file",c,H.basename(t.relative_path)),u=await fetch(o,{method:"POST",body:d})}if(!u.ok)throw new Error(`\u5BF9\u8C61\u5B58\u50A8\u4E0A\u4F20\u5931\u8D25 (${u.status}): ${t.local_id}`);return await j.post(`/resources/${encodeURIComponent(n)}/ready`,{resource_key:n,resource_actual_size_bytes:r.byteLength}),n}function Gl(e,t){let r=T(T(e)?.results),n=C(r?.[t]);if(n)return n;for(let[o,s]of Object.entries(r??{})){let i=T(s);if(C(i?.resource_id??i?.resourceId)===t)return C(i?.short_id??i?.shortId??i?.id)||o}throw new Error(`\u670D\u52A1\u7AEF\u6CA1\u6709\u8FD4\u56DE\u9879\u76EE short id: ${t}`)}async function Hl(e,t,r){let n=await j.post("/project-resources/link",{project_id:e,resources:[{resource_id:r,source:1,name:t.original_name,visibility:1}]});return Gl(n.data,r)}async function Un(e,t,r){let n=await j.post("/project-resources/list-by-short",{project_id:e,short_ids:[r]}),o=T(T(n.data)?.resources)?.[r],s=T(o);if(C(s?.key??s?.resource_key??s?.resourceKey)!==t)throw new Error(`\u8FDC\u7A0B\u9879\u76EE\u8D44\u6E90\u6838\u9A8C\u5931\u8D25: ${r}`)}function $n(e,t,r,n){let o={...T(e.project.resources)??{}},s={...T(e.project.resource_tasks)??{}},a={...T(o[t.resource_key])??T(o[t.short_id])??{},key:r,remote_resource_key:r,remote_short_id:n,upload_status:"uploaded"};o[r]=a,o[n]=a;let c=T(s[t.short_id])??{};s[n]={...c,resource_id:r,short_id:n,local_resource_id:t.local_id},e.project={...e.project,resources:o,resource_tasks:s}}async function Ui(e){let t=await j.get(`/projects/${encodeURIComponent(e)}/draft`);return{version:Ol(t.data),mutations:Nl(t.data.draft_data_json??t.data.draftDataJson)}}async function Bl(e,t,r){let n=await j.post(`/projects/${encodeURIComponent(e)}/local-resources:sync`,{base_version:t,resources:r});if(Number(n.data.schema_version??n.data.schemaVersion??0)!==1)throw new Error("\u670D\u52A1\u7AEF\u8FD4\u56DE\u4E86\u4E0D\u652F\u6301\u7684 local resource sync schema");let s=Number(n.data.new_version??n.data.newVersion??0);if(!Number.isSafeInteger(s)||s<0)throw new Error("\u670D\u52A1\u7AEF\u8FD4\u56DE\u4E86\u65E0\u6548\u7684 local resource sync draft version");return s}async function Wl(e,t,r){let n=[0,200,400,800,1200,2e3],o;for(let s of n){s>0&&await new Promise(i=>setTimeout(i,s));try{let i=await Ui(e);if(i.version===t&&Li(i.mutations,r))return i;o=new Error(`draft \u5C1A\u672A\u6536\u655B: version=${i.version}, expected=${t}`)}catch(i){o=i}}throw new Error(`\u8FDC\u7A0B draft \u63D0\u4EA4\u540E\u7684\u56DE\u8BFB\u6821\u9A8C\u5931\u8D25: ${Di(o)}`)}async function zl(e){let t=e.manifest.local_resources??{},r=Object.values(t).filter(d=>d.upload.status==="uploaded"&&!C(d.upload.draft_synced_at)&&C(d.upload.remote_resource_key)&&C(d.upload.remote_short_id));if(r.length===0)return;let n=new Map;for(let d of r)n.set(d.resource_key,C(d.upload.remote_resource_key)),n.set(d.short_id,C(d.upload.remote_short_id));let o=Ni(e.localMutations,n);if(o.length===0||!Li(e.remoteDraft.mutations,o))return;let s=e.requestedIds.length?e.requestedIds.map(d=>t[d]).filter(Boolean):r.filter(d=>e.localMutations.some(p=>Ge(p,lr(d))));if(s.length===0||s.some(d=>d.upload.status!=="uploaded"||!C(d.upload.remote_resource_key)||!C(d.upload.remote_short_id)))return;let i=[],a=new Set;for(let d of s){Mi(e.root,d.local_id,d);let p=C(d.upload.remote_resource_key),f=C(d.upload.remote_short_id);await Un(e.projectId,p,f);for(let l of lr(d))a.add(l);i.push({localId:d.local_id,remoteResourceKey:p,remoteShortId:f,sha256:d.sha256,sizeBytes:d.size_bytes,uploaded:!1})}let c=e.localMutations.filter(d=>Ge(d,a)).length,u=new Date().toISOString();return await mr(e.manifestPath,e.projectId,d=>{let p=T(d.project.draft)??{},f=T(p.keyframe)??{};d.project={...d.project,version:e.remoteDraft.version,draft:{...p,keyframe:{...f,mutations:e.remoteDraft.mutations}}};for(let l of i){let h=d.local_resources?.[l.localId];h&&(h.upload={...h.upload,status:"uploaded",draft_synced_at:c>0?u:null,last_error:null},$n(d,h,l.remoteResourceKey,l.remoteShortId))}}),{ok:!0,protocol:"local-resource-publish.v2",projectId:e.projectId,snapshotPath:e.root,resourceCount:i.length,uploadedCount:0,reusedCount:i.length,mutationCount:c,newVersion:e.remoteDraft.version,resources:i}}async function $i(e){let t=e.projectId.trim();if(!t)throw new Error("workspace publish-resources \u5FC5\u987B\u63D0\u4F9B --project-id");let{root:r,manifestPath:n}=Ul(e.snapshotPath),o=Dn(n,t),s=o.local_resources??{},i=Ll(o),a=await Ui(t),c=[...new Set((e.localIds??[]).map(g=>g.trim()).filter(Boolean))];for(let g of c)if(!s[g])throw new Error(`manifest \u4E2D\u4E0D\u5B58\u5728\u6307\u5B9A\u672C\u5730\u8D44\u6E90: ${g}`);let u=await zl({projectId:t,root:r,manifestPath:n,manifest:o,localMutations:i,remoteDraft:a,requestedIds:c});if(u)return u;let d=c.length?c:Object.values(s).filter(g=>!C(g.upload.draft_synced_at)&&i.some(A=>Ge(A,lr(g)))).map(g=>g.local_id);if(d.length===0)throw new Error("\u6CA1\u6709\u53D1\u73B0\u88AB\u672C\u5730\u753B\u5E03 mutation \u5F15\u7528\u7684\u5F85\u4E0A\u4F20\u8D44\u6E90");let p=new Map;for(let g of d)p.set(g,Mi(r,g,s[g]));let f=[];for(let g of d){let A=Dn(n,t).local_resources?.[g];if(!A)throw new Error(`\u672C\u5730\u8D44\u6E90\u5DF2\u4ECE manifest \u6D88\u5931: ${g}`);let oe=C(A.upload.remote_resource_key),se=C(A.upload.remote_short_id);if(A.upload.status==="uploaded"&&oe&&se){await Un(t,oe,se),f.push({localId:g,remoteResourceKey:oe,remoteShortId:se,sha256:A.sha256,sizeBytes:A.size_bytes,uploaded:!1});continue}await ji(n,t,g,{status:"uploading",last_error:null});try{let K=await j.post("/resources/upload-credential",{project_id:t,resource_file_name:H.basename(A.relative_path),resource_mime_type:A.content_type,resource_size_bytes:A.size_bytes,resource_kind:A.kind}),R=await Fl(K.data,A,p.get(g)),xe=await Hl(t,A,R);await Un(t,R,xe);let Yi=new Date().toISOString();await mr(n,t,Vn=>{let At=Vn.local_resources?.[g];if(!At)throw new Error(`\u672C\u5730\u8D44\u6E90\u5DF2\u4ECE manifest \u6D88\u5931: ${g}`);At.upload={...At.upload,status:"uploaded",remote_resource_key:R,remote_short_id:xe,uploaded_at:Yi,draft_synced_at:null,last_error:null},$n(Vn,At,R,xe)}),f.push({localId:g,remoteResourceKey:R,remoteShortId:xe,sha256:A.sha256,sizeBytes:A.size_bytes,uploaded:!0})}catch(K){throw await ji(n,t,g,{status:"failed",last_error:Di(K)}),K}}let l=new Map,h=[],I=[];for(let g of f){let A=s[g.localId];l.set(A.resource_key,g.remoteResourceKey),l.set(A.short_id,g.remoteShortId);let oe=Ml(A,i,A.short_id);I.push(...oe);for(let se of oe){let K=Mn(se,l);if(Ge(K,Oi(A)))throw new Error("\u672C\u5730 mutation \u4ECD\u5305\u542B\u65E0\u6CD5\u6620\u5C04\u7684 local resource identity");h.push({local_id:g.localId,remote_resource_key:g.remoteResourceKey,remote_short_id:g.remoteShortId,mutation:K})}}if(h.length===0)throw new Error("\u6CA1\u6709\u53D1\u73B0\u53EF\u540C\u6B65\u7684\u672C\u5730\u8D44\u6E90\u8282\u70B9");let y=Ni(I,l),_=await Bl(t,a.version,h),v=(await Wl(t,_,y)).mutations,te=new Date().toISOString();return await mr(n,t,g=>{let A=T(g.project.draft)??{},oe=T(A.keyframe)??{};g.project={...g.project,version:_,draft:{...A,keyframe:{...oe,mutations:v}}};for(let se of f){let K=g.local_resources?.[se.localId];K&&(K.upload={...K.upload,status:"uploaded",draft_synced_at:te},$n(g,K,se.remoteResourceKey,se.remoteShortId))}}),{ok:!0,protocol:"local-resource-publish.v2",projectId:t,snapshotPath:r,resourceCount:f.length,uploadedCount:f.filter(g=>g.uploaded).length,reusedCount:f.filter(g=>!g.uploaded).length,mutationCount:h.length,newVersion:_,resources:f}}function Fi(e){return typeof e!="string"?void 0:e.trim()||void 0}function Jl(e){if(typeof e=="string")return e.trim()?[e.trim()]:void 0;if(!Array.isArray(e))return;let t=e.flatMap(r=>typeof r=="string"&&r.trim()?[r.trim()]:[]);return t.length>0?t:void 0}async function Fn(e){let t=Fi(e.options.projectId),r=Fi(e.args.snapshotPath);if(!t)throw new Error("workspace publish-resources \u5FC5\u987B\u63D0\u4F9B --project-id");if(!r)throw new Error("workspace publish-resources \u5FC5\u987B\u63D0\u4F9B\u672C\u5730 canvas export \u8DEF\u5F84");let n=await $i({projectId:t,snapshotPath:r,localIds:Jl(e.options.localId)});e.options.json?process.stdout.write(`${JSON.stringify(n)}
|
|
284
|
+
`):S.success(`\u5DF2\u4E0A\u4F20 ${n.resourceCount} \u4E2A\u672C\u5730\u8D44\u6E90\u5E76\u540C\u6B65 ${n.mutationCount} \u6761\u753B\u5E03 mutation\uFF08draft v${n.newVersion}\uFF09`)}function Vl(e){if(typeof e!="string")return null;let t=e.trim();return t.length>0?t:null}function Kl(e){let t=Vl(e.options.projectId);if(!t)throw Q("\u8BF7\u901A\u8FC7 --project-id \u6307\u5B9A\u9879\u76EE ID",{code:"CLI_USAGE_ERROR",status:400});return{projectId:t,json:!!e.options.json}}function ql(e,t){return{projectId:e,projectUrl:t.projectUrl,status:t.status,...t.statusText?{statusText:t.statusText}:{},...t.failure?{failure:t.failure}:{}}}function Ql(e){S.info(`projectId: ${e.projectId}`),S.info(`projectUrl: ${e.projectUrl}`),S.info(`status: ${e.status}`),e.statusText&&S.info(`statusText: ${e.statusText}`),e.failure&&S.warn(`failure: ${e.failure.code} ${e.failure.message}`)}function Yl(e,t){if(t){process.stdout.write(`${JSON.stringify(e)}
|
|
285
|
+
`);return}Ql(e)}async function Gn(e){try{let t=Kl(e),r=await xs(t.projectId);Yl(ql(t.projectId,r),t.json)}catch(t){z(t)}}function Xl(e){if(typeof e!="string")return null;let t=e.trim();return t.length>0?t:null}function Zl(e,t){if(t){process.stdout.write(`${JSON.stringify(e)}
|
|
286
|
+
`);return}S.info(`projectId: ${e.projectId}`),S.info(`projectUrl: ${e.projectUrl}`),S.info(`status: ${e.status}`),e.resourceId&&S.info(`resourceId: ${e.resourceId}`),e.url&&S.info(`url: ${e.url}`)}async function Hn(e){try{let t=Xl(e.options.projectId);if(!t)throw Q("\u8BF7\u901A\u8FC7 --project-id \u6307\u5B9A\u9879\u76EE ID",{code:"CLI_USAGE_ERROR",status:400});let r=await ps(t);Zl(r,!!e.options.json)}catch(t){z(t)}}async function Bn(e){let t=typeof e.options.name=="string"?e.options.name.trim():"";if(!t)throw new Error("project create \u5FC5\u987B\u63D0\u4F9B\u975E\u7A7A --name");let n=(await tr(t)).project_id?.trim();if(!n)throw new Error("server.v1 \u521B\u5EFA\u9879\u76EE\u540E\u672A\u8FD4\u56DE project_id\uFF0C\u8BF7\u6838\u5BF9\u9879\u76EE\u5217\u8868\u540E\u91CD\u8BD5");let o={ok:!0,projectId:n,projectUrl:le(n),serviceApi:"server.v1"};e.options.json?console.log(JSON.stringify(o)):S.success(`\u5DF2\u521B\u5EFA\u9879\u76EE ${n}
|
|
287
|
+
${o.projectUrl}`)}async function Rt(e){let t=typeof e.args.projectId=="string"?e.args.projectId:"",r;switch(e.command){case"project:team:list":r=await nr();break;case"project:team:get":r=await Hs(t);break;case"project:team:set":r=await Bs({projectId:t,teamId:e.options.teamId,name:e.options.name,syncSkills:!!e.options.syncSkills});break;default:throw new Error("\u672A\u77E5\u7684 project team \u547D\u4EE4")}e.options.json?console.log(JSON.stringify(r)):S.info(JSON.stringify(r,null,2))}var ef=["auth:login","auth:logout","capabilities","help","version"];function tf(){return{id:"local",name:"User"}}var Gi=async(e,t)=>{if(ef.includes(e.command))return t();let r=await Ve();return(!r||r.length===0)&&z(new m("AUTH_REQUIRED","\u8BF7\u5148\u767B\u5F55: ojo auth login",{status:401,source:"auth"})),e.cookie=r,e.user=tf(),t()};import{existsSync as rf,mkdirSync as II,readFileSync as nf,writeFileSync as SI}from"fs";import{homedir as of}from"os";import{dirname as vI,join as sf}from"path";var Hi=sf(of(),".ojo","config.json");function Bi(){if(!rf(Hi))return{};try{let e=nf(Hi,"utf-8"),t=JSON.parse(e);return t&&typeof t=="object"?t:{}}catch{return{}}}var Wi=async(e,t)=>(e.config=Bi(),t());function zi(e){return(t,r)=>{let n=0,o=()=>n<e.length?e[n++](t,o):r();return o()}}var Wn=q(),Ji=async(e,t)=>{let r=Date.now();Wn.track("cli_command_start",{commandName:e.command,source:"cli"});try{await t(),Wn.track("cli_command_success",{commandName:e.command,source:"cli",durationMs:Date.now()-r})}catch(n){throw Wn.track("cli_command_error",{commandName:e.command,source:"cli",durationMs:Date.now()-r,errorCode:W(n)}),n}};var af=new Set(["workspace:sync"]);function cf(e){return af.has(e)}function uf(e){return typeof e=="string"&&e.trim().length>0}var Vi=async(e,t)=>{if(!cf(e.command)||e.command==="workspace:sync"&&uf(e.args.projectRef))return t();try{qo(process.cwd())}catch(r){throw r instanceof m&&r.code===Gt&&z(r),r}return t()};import zn from"semver";var df=`https://registry.npmjs.org/${encodeURIComponent(ir)}/latest`,pf=1500,lf=`npm install -g ${ir}@latest`;function ff(){return typeof globalThis.fetch!="function"?null:globalThis.fetch.bind(globalThis)}function Ki(e){let t=e.slice(2);return t.includes("--json")||t.includes("-V")||t.includes("--version")?!1:t.length===0||t.length===1&&(t[0]==="-h"||t[0]==="--help"||t[0]==="help")}function mf(e,t){return[`\u6709\u53EF\u7528\u7684\u65B0\u7248\u672C OJO CLI\uFF1Av${e} -> v${t}`,`\u8FD0\u884C \`${lf}\` \u5373\u53EF\u66F4\u65B0\u3002`].join(`
|
|
288
|
+
`)}async function gf(e=ff()){if(!e)return null;let t=new AbortController,r=setTimeout(()=>t.abort(),pf);try{let n=await e(df,{headers:{accept:"application/json"},signal:t.signal});if(!n.ok)return null;let o=await n.json();if(!o||typeof o!="object")return null;let s=o.version;return typeof s=="string"&&s.trim().length>0?s.trim():null}catch{return null}finally{clearTimeout(r)}}async function qi(e){let t=Ae(),r=zn.valid(t);if(!r)return;let n=await gf(e?.fetchImpl),o=n?zn.valid(n):null;if(!o||!zn.gt(o,r))return;(e?.write??(i=>process.stdout.write(`${i}
|
|
289
|
+
`)))(mf(r,o))}var ce=zi([Ji,Vi,Gi,Wi]),hf=Ae(),Jn=q(),yf=`
|
|
290
|
+
\u63D0\u793A\uFF1A\u5982\u679C\u662F agent \u8C03\u7528\uFF0C\u8BF7\u8BE2\u95EE\u7528\u6237\u5E0C\u671B\u4F7F\u7528\u4EC0\u4E48\u767B\u5F55\u6D41\u7A0B\u3002
|
|
291
|
+
\u5982\u679C\u4F7F\u7528 AccessKey \u767B\u5F55\uFF0C\u53EF\u524D\u5F80 ${Ne} \u76F4\u8FBE AccessKey \u7BA1\u7406\u9875\u9762\u3002
|
|
292
|
+
`;function ee(e,t,r){return{command:e,args:t,options:r}}async function vt(e,t){let r=Date.now();Jn.track("cli_command_start",{commandName:e,source:"cli"});try{await t(),Jn.track("cli_command_success",{commandName:e,source:"cli",durationMs:Date.now()-r})}catch(n){throw Jn.track("cli_command_error",{commandName:e,source:"cli",durationMs:Date.now()-r,errorCode:W(n)}),n}}async function Qi(e){jr("cli"),Ki(e)&&await qi();let t=new He;Ks(t),t.name("ojo").description("OJO CLI\uFF1A\u7528\u4E8E\u767B\u5F55\u3001\u9879\u76EE\u67E5\u8BE2\u3001\u53D1\u9001\u5BF9\u8BDD\u3001\u67E5\u8BE2\u8FD0\u884C\u72B6\u6001\u3001\u540C\u6B65 workspace\uFF0C\u4EE5\u53CA\u542F\u52A8\u672C\u5730\u524D\u7AEF\u670D\u52A1").version(hf);let r=t.command("auth").description("\u767B\u5F55\u6216\u9000\u51FA\u5F53\u524D OJO \u8D26\u53F7");t.command("capabilities").description("\u8F93\u51FA\u5F53\u524D CLI \u7684\u670D\u52A1\u4EE3\u9645\u4E0E\u81EA\u52A8\u5316\u534F\u8BAE\u80FD\u529B").option("--json","\u8F93\u51FA JSON").action(async s=>{await vt("capabilities",()=>wn({json:!!s?.json}))}),r.command("login").description("\u767B\u5F55").addHelpText("after",yf).option("--mode <mode>","\u767B\u5F55\u6A21\u5F0F\uFF1Aweb | device | access-key","web").option("--access-key <token>","\u8BBE\u7F6E AccessKey \u5E76\u767B\u5F55\uFF1Bmode=access-key \u65F6\u5FC5\u586B").option("--no-open","\u4E0D\u81EA\u52A8\u6253\u5F00\u6D4F\u89C8\u5668\uFF0C\u4EC5\u8F93\u51FA\u767B\u5F55\u94FE\u63A5").option("--json","\u8F93\u51FA JSON").action(async s=>{await vt("auth:login",async()=>{await Cn({mode:typeof s?.mode=="string"?s.mode:void 0,noOpen:!!s?.noOpen,accessKey:typeof s?.accessKey=="string"?s.accessKey:void 0,json:!!s?.json})})});let n=t.command("prototype").description("\u6309 generate_prototype \u670D\u52A1\u7AEF\u95E8\u7981\u6821\u9A8C\u6216\u6784\u5EFA\u672C\u5730\u539F\u578B");n.command("validate").argument("[workspacePath]","\u9879\u76EE workspace \u6216 prototype \u76EE\u5F55").description("\u6821\u9A8C\u9875\u9762 manifest\u3001\u6E90\u7801\u4E0E\u73B0\u6709 dist \u662F\u5426\u7B26\u5408\u670D\u52A1\u7AEF\u95E8\u7981").option("--dist <path>","\u5F85\u6821\u9A8C dist\uFF1B\u76F8\u5BF9\u8DEF\u5F84\u57FA\u4E8E prototype \u76EE\u5F55","dist").option("--manifest-only","\u53EA\u6821\u9A8C\u9875\u9762 manifest \u4E0E\u5171\u4EAB\u7EC4\u4EF6\u5143\u6570\u636E\uFF0C\u4E0D\u8981\u6C42\u6E90\u7801\u3001\u4F9D\u8D56\u6216 dist").option("--prebuild","\u53EA\u6821\u9A8C manifest\u3001\u6E90\u7801\u4E0E\u4F9D\u8D56\uFF0C\u4E0D\u8981\u6C42\u5DF2\u6709 dist").option("--json","\u8F93\u51FA\u673A\u5668\u53EF\u8BFB\u95E8\u7981\u7ED3\u679C").action(async(s,i)=>{let a=ee("prototype:validate",{workspacePath:s},i??{});await vt("prototype:validate",()=>jn(a))}),n.command("build").argument("[workspacePath]","\u9879\u76EE workspace \u6216 prototype \u76EE\u5F55").description("\u5E76\u884C\u6267\u884C TypeScript \u4E0E Rspack \u95E8\u7981\uFF0C\u901A\u8FC7\u540E\u539F\u5B50\u53D1\u5E03 dist").option("--dist <path>","\u7A33\u5B9A dist \u8F93\u51FA\uFF1B\u76F8\u5BF9\u8DEF\u5F84\u57FA\u4E8E prototype \u76EE\u5F55","dist").option("--json","\u8F93\u51FA\u673A\u5668\u53EF\u8BFB\u95E8\u7981\u7ED3\u679C").action(async(s,i)=>{let a=ee("prototype:build",{workspacePath:s},i??{});await vt("prototype:build",()=>On(a))}),n.command("publish").argument("[workspacePath]","\u9879\u76EE workspace \u6216 prototype \u76EE\u5F55").description("\u91CD\u65B0\u6784\u5EFA\u5E76\u6821\u9A8C\u672C\u5730\u539F\u578B\uFF0C\u6309\u670D\u52A1\u7AEF generate_prototype \u4EA7\u7269\u534F\u8BAE\u4E0A\u4F20\u5E76\u539F\u5B50\u5207\u6362\u753B\u5E03").requiredOption("--project-id <projectId>","\u76EE\u6807 OJO \u9879\u76EE ID").option("--dist <path>","\u7A33\u5B9A dist \u8F93\u51FA\uFF1B\u76F8\u5BF9\u8DEF\u5F84\u57FA\u4E8E prototype \u76EE\u5F55","dist").option("--json","\u8F93\u51FA\u673A\u5668\u53EF\u8BFB\u4E0A\u4F20\u7ED3\u679C").action(async(s,i)=>{let a=ee("prototype:publish",{workspacePath:s},i??{});return ce(a,()=>Nn(a))}),r.command("logout").description("\u9000\u51FA\u767B\u5F55\uFF08\u5E76\u6E05\u9664\u672C\u5730 AccessKey\uFF09").option("--json","\u8F93\u51FA JSON").action(async s=>{await vt("auth:logout",async()=>{await Tn({json:!!s?.json})})}),t.command("project").description("\u521B\u5EFA\u548C\u67E5\u770B\u65B0\u6846\u67B6\u9879\u76EE").addCommand(new He("team").description("\u67E5\u8BE2\u548C\u8BBE\u7F6E\u65B0\u6846\u67B6\u9879\u76EE Team").addCommand(new He("list").option("--json","\u8F93\u51FA JSON").action(async s=>{let i=ee("project:team:list",{},s);return ce(i,()=>Rt(i))})).addCommand(new He("get").argument("<projectId>").option("--json","\u8F93\u51FA JSON").action(async(s,i)=>{let a=ee("project:team:get",{projectId:s},i);return ce(a,()=>Rt(a))})).addCommand(new He("set").argument("<projectId>").option("--sync-skills","\u540C\u6B65 Team \u5173\u8054\u7684\u8FD0\u884C\u65F6 Skill \u9009\u62E9").option("--team-id <id>","Team \u76EE\u5F55 ID").option("--name <name>","Team \u7CBE\u786E\u540D\u79F0").option("--json","\u8F93\u51FA JSON").action(async(s,i)=>{let a=ee("project:team:set",{projectId:s},i);return ce(a,()=>Rt(a))}))).addCommand(new He("create").description("\u901A\u8FC7 server.v1 \u521B\u5EFA\u7A7A\u9879\u76EE").requiredOption("--name <name>","\u9879\u76EE\u540D\u79F0").option("--json","\u8F93\u51FA JSON").action(async s=>{let i=ee("project:create",{},s??{});return ce(i,()=>Bn(i))})).addCommand(new He("list").description("\u83B7\u53D6\u5F53\u524D\u7528\u6237\u9879\u76EE\u5217\u8868").option("--json","\u8F93\u51FA JSON").option("--page-size <n>","\u6BCF\u9875\u6570\u91CF","20").option("--page-token <token>","\u5206\u9875\u4EE4\u724C").option("--favorite","\u4EC5\u6536\u85CF").action(async s=>{let i=ee("project:list",{},s??{});return ce(i,()=>En(i))})),t.command("screen").description("\u83B7\u53D6\u9879\u76EE\u539F\u578B\u9884\u89C8\u56FE").option("--project-id <projectId>","OJO \u9879\u76EE ID").option("--json","\u8F93\u51FA JSON").action(async s=>{let i=ee("screen",{},s??{});return ce(i,()=>Hn(i))}),t.command("chat").description("\u53D1\u9001\u5355\u6761\u6D88\u606F\u5E76\u7ACB\u5373\u8FD4\u56DE\u9879\u76EE\u7EA7\u8FD0\u884C\u72B6\u6001\uFF1B\u652F\u6301\u81EA\u52A8\u65B0\u5EFA\u9879\u76EE\uFF0C\u6216\u7EE7\u7EED\u5DF2\u6709\u9879\u76EE\u4F1A\u8BDD").option("--message <msg>","\u6D88\u606F\u5185\u5BB9").option("--project-id <projectId>","OJO \u9879\u76EE ID").option("--json","\u8F93\u51FA JSON").addHelpText("after",`
|
|
293
|
+
\u793A\u4F8B:
|
|
294
|
+
ojo chat --message "\u5E2E\u6211\u6574\u7406\u4E00\u4E0B\u5F53\u524D\u4EA7\u54C1\u65B9\u5411"
|
|
295
|
+
ojo chat --project-id <projectId> --message "\u7EE7\u7EED\u4E0A\u4E00\u6B21\u8BA8\u8BBA"
|
|
296
|
+
ojo query --project-id <projectId>
|
|
297
|
+
`).action(async s=>{let i=ee("chat",{},s??{});return ce(i,()=>Sn(i))});let o=t.command("workspace").description("\u540C\u6B65\u8FDC\u7AEF workspace\uFF0C\u6216\u542F\u52A8\u672C\u5730\u524D\u7AEF\u670D\u52A1");o.command("sync").argument("[projectRef]","\u9879\u76EE ID \u6216\u9879\u76EE\u9875\u94FE\u63A5").description("\u540C\u6B65 workspace\uFF1B\u652F\u6301\u5F53\u524D\u9879\u76EE\u3001project ID \u6216\u9879\u76EE\u9875\u94FE\u63A5").option("--path <dir>","\u8F93\u51FA\u7236\u76EE\u5F55\uFF1BprojectRef \u6A21\u5F0F\u4E0B\u4F1A\u5199\u5165 <dir>/<project-name>/ojo-prototype").option("--json","\u8F93\u51FA JSON").action(async(s,i)=>{let a=ee("workspace:sync",{projectRef:s},i??{});return ce(a,()=>An(a))}),o.command("dev").argument("[workspacePath]","\u524D\u7AEF workspace \u8DEF\u5F84\uFF1B\u53EF\u76F4\u63A5\u4F20 workspace sync \u8FD4\u56DE\u7684 path").description("\u5BFC\u51FA\u6307\u5B9A\u9879\u76EE\u753B\u5E03\u5E76\u542F\u52A8\u672C\u5730\u524D\u7AEF\u670D\u52A1\uFF0C\u8F93\u51FA\u4F9B Codex Browser \u6253\u5F00\u7684 localhost URL").option("--project-id <projectId>","\u8981\u5BFC\u51FA\u5E76\u6253\u5F00\u7684 OJO \u9879\u76EE ID\uFF08\u5FC5\u586B\uFF09").option("--prototype-dist <path>","\u672C\u5730\u7F16\u8BD1\u540E\u7684\u539F\u578B\u4EA7\u7269\u76EE\u5F55\uFF1B\u53D8\u66F4\u540E\u81EA\u52A8\u5237\u65B0\u9879\u76EE\u753B\u5E03").option("--host <host>","\u76D1\u542C\u5730\u5740","127.0.0.1").option("--port <port>","\u76D1\u542C\u7AEF\u53E3\uFF1B0 \u8868\u793A\u81EA\u52A8\u9009\u62E9","0").option("--script <name>","package.json scripts \u4E2D\u7684\u542F\u52A8\u811A\u672C","dev").option("--timeout <seconds>","\u7B49\u5F85\u670D\u52A1\u5C31\u7EEA\u7684\u79D2\u6570","60").option("--no-install","node_modules \u4E0D\u5B58\u5728\u65F6\u4E0D\u81EA\u52A8\u5B89\u88C5\u4F9D\u8D56").option("--json","\u8F93\u51FA JSON Lines \u751F\u547D\u5468\u671F\u4E8B\u4EF6").action(async(s,i)=>{let a=ee("workspace:dev",{workspacePath:s},i??{});return ce(a,()=>kn(a))}),o.command("publish-resources").argument("<snapshotPath>","workspace dev \u8FD4\u56DE\u7684 localExportPath \u6216\u5176\u4E2D\u7684 canvas-export.json").description("\u6821\u9A8C\u672C\u5730 resource \u6587\u4EF6\uFF0C\u4E0A\u4F20\u5E76\u5173\u8054\u5230\u540C\u4E00\u9879\u76EE\uFF0C\u518D\u540C\u6B65\u5F15\u7528\u8FD9\u4E9B\u8D44\u6E90\u7684\u753B\u5E03 mutation").requiredOption("--project-id <projectId>","\u76EE\u6807 OJO \u9879\u76EE ID").option("--local-id <localId...>","\u53EA\u4E0A\u4F20\u6307\u5B9A local_resources identity\uFF1B\u9ED8\u8BA4\u4E0A\u4F20\u672C\u5730 mutation \u5F15\u7528\u7684\u8D44\u6E90").option("--json","\u8F93\u51FA\u673A\u5668\u53EF\u8BFB\u4E0A\u4F20\u7ED3\u679C").action(async(s,i)=>{let a=ee("workspace:publish-resources",{snapshotPath:s},i??{});return ce(a,()=>Fn(a))}),t.command("query").description("\u67E5\u8BE2\u6307\u5B9A\u9879\u76EE\u6700\u8FD1\u4E00\u8F6E\u8FD0\u884C\u72B6\u6001").option("--project-id <projectId>","OJO \u9879\u76EE ID").option("--json","\u8F93\u51FA JSON").action(async s=>{let i=ee("query",{},s??{});return ce(i,()=>Gn(i))});try{await t.parseAsync(e)}catch(s){It(s),process.exit(1)}}var _f=Date.now(),gr=q(),kt=jo();bo({platform:"cli",appVersion:Ae()});process.on("uncaughtException",e=>{gr.track("sys_process_uncaught_exception",{errorCode:W(e),errorMessage:e instanceof Error?e.message:String(e),source:"cli"}),kt.flushSync()});process.on("unhandledRejection",e=>{gr.track("sys_process_uncaught_exception",{errorCode:W(e),errorMessage:e instanceof Error?e.message:String(e),source:"cli"}),kt.flushSync()});process.on("beforeExit",()=>{kt.flushSync()});process.on("SIGINT",()=>{kt.flushSync(),process.exit(0)});Qi(process.argv).catch(e=>{gr.track("sys_process_uncaught_exception",{errorCode:W(e),errorMessage:e instanceof Error?e.message:String(e),source:"cli"}),It(e),kt.flushSync(),process.exit(1)});gr.track("perf_cli_startup",{startupMs:Date.now()-_f});
|
|
298
|
+
/*! Bundled license information:
|
|
299
|
+
|
|
300
|
+
fast-json-patch/module/helpers.mjs:
|
|
301
|
+
(*!
|
|
302
|
+
* https://github.com/Starcounter-Jack/JSON-Patch
|
|
303
|
+
* (c) 2017-2022 Joachim Wester
|
|
304
|
+
* MIT licensed
|
|
305
|
+
*)
|
|
306
|
+
|
|
307
|
+
fast-json-patch/module/duplex.mjs:
|
|
308
|
+
(*!
|
|
309
|
+
* https://github.com/Starcounter-Jack/JSON-Patch
|
|
310
|
+
* (c) 2017-2021 Joachim Wester
|
|
311
|
+
* MIT license
|
|
312
|
+
*)
|
|
313
|
+
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,86 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@touchine-ai/ojo",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "2.0.0-beta.1",
|
|
4
|
+
"description": "Next-generation OJO CLI for the irise-server v1 API, workspace sync, and local frontend preview",
|
|
5
|
+
"packageManager": "pnpm@9.15.0",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"bin": {
|
|
9
|
+
"ojo": "dist/index.js"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/irise-studio/irise-extension",
|
|
17
|
+
"directory": "apps/cli"
|
|
18
|
+
},
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public",
|
|
21
|
+
"registry": "https://registry.npmjs.org/"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsup --config tsup.config.ts",
|
|
25
|
+
"release": "node scripts/release.js",
|
|
26
|
+
"release:check": "node ../../tooling/release/check-cli-release.mjs",
|
|
27
|
+
"changelog": "conventional-changelog -p conventionalcommits -r 1 --stdout",
|
|
28
|
+
"prepublishOnly": "pnpm run build",
|
|
29
|
+
"dev": "tsup --config tsup.config.ts --watch",
|
|
30
|
+
"start": "pnpm run build && node dist/index.js",
|
|
31
|
+
"debug": "pnpm run build && node --inspect-brk dist/index.js",
|
|
32
|
+
"test": "vitest run",
|
|
33
|
+
"type-check": "tsc --noEmit",
|
|
34
|
+
"lint": "eslint .",
|
|
35
|
+
"lint:fix": "eslint . --fix",
|
|
36
|
+
"format": "prettier --write .",
|
|
37
|
+
"format:check": "prettier --check ."
|
|
38
|
+
},
|
|
39
|
+
"keywords": [
|
|
40
|
+
"ojo",
|
|
41
|
+
"ai",
|
|
42
|
+
"cli",
|
|
43
|
+
"agent",
|
|
44
|
+
"workspace",
|
|
45
|
+
"mcp"
|
|
46
|
+
],
|
|
47
|
+
"author": "touchine.ai",
|
|
48
|
+
"license": "ISC",
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"axios": "^1.13.6",
|
|
51
|
+
"chalk": "^5.6.2",
|
|
52
|
+
"chokidar": "^5.0.0",
|
|
53
|
+
"cli-table3": "^0.6.5",
|
|
54
|
+
"commander": "^14.0.3",
|
|
55
|
+
"ink": "^5.1.0",
|
|
56
|
+
"inquirer": "^13.3.0",
|
|
57
|
+
"jszip": "3.10.1",
|
|
58
|
+
"open": "^11.0.0",
|
|
59
|
+
"ora": "^9.3.0",
|
|
60
|
+
"parse5": "8.0.0",
|
|
61
|
+
"react": "^18.3.1",
|
|
62
|
+
"semver": "^7.7.4",
|
|
63
|
+
"sql.js": "^1.13.0",
|
|
64
|
+
"terminal-link": "^5.0.0",
|
|
65
|
+
"ws": "^8.21.1",
|
|
66
|
+
"zod": "^4.3.6"
|
|
67
|
+
},
|
|
68
|
+
"devDependencies": {
|
|
69
|
+
"@eslint/js": "^9.17.0",
|
|
70
|
+
"@touchine/common": "workspace:*",
|
|
71
|
+
"@types/node": "^25.3.3",
|
|
72
|
+
"@types/react": "^18.3.18",
|
|
73
|
+
"@types/semver": "^7.7.1",
|
|
74
|
+
"@types/ws": "^8.18.1",
|
|
75
|
+
"conventional-changelog": "^7.2.0",
|
|
76
|
+
"conventional-changelog-conventionalcommits": "^9.2.0",
|
|
77
|
+
"eslint": "^9.17.0",
|
|
78
|
+
"eslint-config-prettier": "^10.0.1",
|
|
79
|
+
"ink-testing-library": "^3.0.0",
|
|
80
|
+
"prettier": "^3.4.2",
|
|
81
|
+
"tsup": "^8.5.1",
|
|
82
|
+
"typescript": "^5.9.3",
|
|
83
|
+
"typescript-eslint": "^8.18.0",
|
|
84
|
+
"vitest": "^3.2.4"
|
|
85
|
+
}
|
|
86
|
+
}
|