@minimax-ai/code 0.4.5 → 0.4.7
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/CHANGELOG.md +39 -0
- package/CHANGELOG.zh-CN.md +30 -0
- package/README.md +13 -0
- package/README.zh-CN.md +121 -77
- package/assets/agents/_default/prompt-base-all.md +35 -141
- package/assets/agents/_default/prompt-base-all.md.hbs +6 -4
- package/assets/agents/_default/prompt-base-worker.md +8 -19
- package/assets/agents/_default/prompt-session-branch.md +0 -1
- package/assets/agents/_default/prompt-session-root.md +4 -32
- package/assets/agents/_v2/AGENT_CONTEXT.md.hbs +222 -0
- package/assets/agents/_v2/coding/SYSTEM.md.hbs +161 -0
- package/assets/agents/_v2/explore.md.hbs +30 -0
- package/assets/agents/_v2/tui/SYSTEM.md.hbs +147 -0
- package/assets/agents/_v2/verifier.md.hbs +32 -0
- package/assets/agents/_v2/work/SYSTEM.md.hbs +173 -0
- package/assets/agents/_v2/worker.md.hbs +27 -0
- package/assets/agents/managed-prompts.json +8 -1
- package/assets/agents/mavis/PERSONA-zh.md +0 -13
- package/assets/agents/mavis/PERSONA.md +0 -13
- package/assets/agents/mavis/features/recoverable-deletion.md.hbs +10 -0
- package/assets/agents/mavis/modes/coding/online/SYSTEM.md.hbs +2 -0
- package/assets/agents/mavis/modes/work/online/SYSTEM.md.hbs +2 -0
- package/assets/agents/mavis/prompt-session-root.md +4 -46
- package/assets/agents/mavis/prompt-session-root.md.hbs +4 -46
- package/assets/agents/mavis/skills/control-in-app-browser/SKILL.md +0 -8
- package/assets/agents/mavis/skills/minimax-code-product/SKILL.md +2 -2
- package/assets/agents/mavis/system-prompt.md.hbs +47 -37
- package/assets/agents/prompt-exemptions.json +2 -12
- package/assets/agents/verifier/agent.md +3 -0
- package/assets/agents/worker/agent.md +3 -0
- package/chunks/{application-FCLZ6WHZ.js → application-OZ6YEJNG.js} +1 -1
- package/chunks/{auth-command-HEXCI24E.js → auth-command-TP25VHV4.js} +1 -1
- package/chunks/{azure-openai-responses-HOJR5DNA.js → azure-openai-responses-TBCJPIYA.js} +1 -1
- package/chunks/{chunk-AAJMOWWM.js → chunk-22LVIQ2T.js} +1 -1
- package/chunks/{chunk-6BYKHQOV.js → chunk-2SW3R5AB.js} +31 -17
- package/chunks/{chunk-E2J47VVN.js → chunk-AJSGEEWR.js} +1 -1
- package/chunks/{chunk-Y27DNFV2.js → chunk-B2NJMA4I.js} +32 -32
- package/chunks/{chunk-NF72FWAW.js → chunk-BNU46XHR.js} +1 -1
- package/chunks/{chunk-R7KEYFVA.js → chunk-C2OVBAOI.js} +1 -1
- package/chunks/{chunk-6TZEW2D4.js → chunk-KCTHWRGJ.js} +1 -1
- package/chunks/{chunk-FLEWADRD.js → chunk-KVMK6REW.js} +1 -1
- package/chunks/{chunk-OJA2IAQ6.js → chunk-NELAOQAA.js} +2 -2
- package/chunks/{chunk-WOISMRTU.js → chunk-OVLV6FQA.js} +863 -869
- package/chunks/{chunk-4NX3LPKA.js → chunk-QJWOGW27.js} +1 -1
- package/chunks/{chunk-V7D3N7GI.js → chunk-SYLCIHHV.js} +1 -1
- package/chunks/{chunk-MNN6EKX3.js → chunk-W7JHDTPW.js} +1 -1
- package/chunks/{chunk-LBDCGSPW.js → chunk-YBZTB54I.js} +804 -798
- package/chunks/{data-dir-LETCXX3O.js → data-dir-KTXCGPJZ.js} +1 -1
- package/chunks/{dist-3YCMECRL.js → dist-MM7GHB2J.js} +1 -1
- package/chunks/{dist-QF3JV3LN.js → dist-XS6VO2LU.js} +1 -1
- package/chunks/{install-source-4BFOZZBU.js → install-source-3CE52ZIN.js} +1 -1
- package/chunks/{launcher-2GOTCBNH.js → launcher-BNIFOBXD.js} +160 -160
- package/chunks/{lifecycle-I4FKLUH5.js → lifecycle-EKT5LQIE.js} +1 -1
- package/chunks/{main-ATLGUB2N.js → main-FAPYW7S4.js} +9 -9
- package/chunks/{openai-codex-responses-5BJTY4II.js → openai-codex-responses-2NQ6DV7M.js} +1 -1
- package/chunks/{openai-completions-JGZTYL5R.js → openai-completions-M3VJB7QY.js} +1 -1
- package/chunks/{openai-responses-FRXGNXAR.js → openai-responses-W2PNKCUZ.js} +1 -1
- package/chunks/{plugin-command-37F33YBS.js → plugin-command-TD3DWK7U.js} +1 -1
- package/chunks/{provider-command-QXHFS5QQ.js → provider-command-AQPDCWDR.js} +1 -1
- package/chunks/{run-acp-command-I4VY32ZG.js → run-acp-command-OPS4CBHL.js} +2 -2
- package/chunks/run-exec-command-QR3TWWDO.js +17 -0
- package/chunks/{update-4OXHCWOL.js → update-KWS4AOND.js} +1 -1
- package/cli.js +2 -2
- package/configs/data-minimal.yaml +0 -2
- package/embedded/mcode-tools/cli.mjs +19119 -4
- package/embedded/mcode-tools/manifest.json +27 -5
- package/embedded/mcode-tools/native/registry-js.LICENSE +21 -0
- package/embedded/mcode-tools/native/win32-arm64/registry.node +0 -0
- package/embedded/mcode-tools/native/win32-ia32/registry.node +0 -0
- package/embedded/mcode-tools/native/win32-x64/registry.node +0 -0
- package/image-preview-worker.js +2 -0
- package/package.json +2 -1
- package/assets/agents/_tui/prompt-base-all.md.hbs +0 -12
- package/assets/agents/_tui/prompt-base-windows.md.hbs +0 -45
- package/assets/agents/_tui/prompt-base-worker.md.hbs +0 -4
- package/assets/agents/_tui/prompt-session-branch.md.hbs +0 -13
- package/assets/agents/_tui/prompt-session-root.md.hbs +0 -4
- package/assets/agents/mavis/tui/PERSONA-zh.md.hbs +0 -17
- package/assets/agents/mavis/tui/PERSONA.md.hbs +0 -22
- package/assets/agents/mavis/tui/SYSTEM.md.hbs +0 -110
- package/assets/agents/mavis/tui/features/delegation.md.hbs +0 -54
- package/assets/agents/mavis/tui/features/task-management.md.hbs +0 -11
- package/assets/agents/mavis/tui/features/web-search.md.hbs +0 -7
- package/chunks/run-exec-command-TJEUBFQ5.js +0 -17
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{{#if tools.bash}}
|
|
2
|
+
## Recoverable Deletion
|
|
3
|
+
|
|
4
|
+
- Read the exact `activeDataDir` from the current `<runtime-data-context>`; never guess it or use
|
|
5
|
+
bare `mavis-trash`.
|
|
6
|
+
- macOS/Linux: `"<activeDataDir>/bin/mavis-trash" -- "<target1>" "<target2>"`.
|
|
7
|
+
- Windows: use one top-level `rm -- "<target1>" "<target2>"`; the runtime routes it through its
|
|
8
|
+
trusted launcher. If recoverable deletion fails, report it and never fall back to permanent
|
|
9
|
+
deletion.
|
|
10
|
+
{{/if}}
|
|
@@ -16,6 +16,8 @@ When making changes to code:
|
|
|
16
16
|
choices.
|
|
17
17
|
- **Security first.** Never introduce code that exposes or logs secrets.
|
|
18
18
|
|
|
19
|
+
{{{featurePrompts.recoverableDeletion}}}
|
|
20
|
+
|
|
19
21
|
## Response Style
|
|
20
22
|
|
|
21
23
|
- For a one-point explanation, use compact prose without a heading, bullet recap, or code excerpt unless the user asks for one.
|
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
- **Mimic existing patterns.** Look at neighboring files for naming, typing, and framework choices.
|
|
13
13
|
- **Route professional work to skills first.** When a task matches a specialized domain or artifact skill, use that skill and follow its workflow. Only when no matching skill applies should you use ad hoc code; in that case, prefer a temporary Python script for analysis, data processing, or lightweight automation.
|
|
14
14
|
|
|
15
|
+
{{{featurePrompts.recoverableDeletion}}}
|
|
16
|
+
|
|
15
17
|
## Response Style
|
|
16
18
|
|
|
17
19
|
- For a one-point explanation, use compact prose without a heading, bullet recap, or code excerpt unless the user asks for one.
|
|
@@ -1,46 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
move the work forward:
|
|
6
|
-
|
|
7
|
-
- **Direct execution**: handle tasks yourself when the user's goal is clear.
|
|
8
|
-
{{#if features.delegation}}
|
|
9
|
-
- **Delegation**: follow Task Routing when delegating work.
|
|
10
|
-
{{/if}}
|
|
11
|
-
|
|
12
|
-
{{#if features.mavis}}
|
|
13
|
-
## Reporting Coverage
|
|
14
|
-
|
|
15
|
-
The root session is the user's unified status board for the whole agent. **Whenever you judge the
|
|
16
|
-
user needs the latest cross-session progress, proactively give it.** Concretely:
|
|
17
|
-
|
|
18
|
-
1. The user explicitly asks ("what's the status", "how's it going", etc.).
|
|
19
|
-
2. The user has been away for a while and just resumed — open with a short status snapshot, even
|
|
20
|
-
before they ask, so they don't have to chase you.
|
|
21
|
-
3. A meaningful state change happened across sessions that the user clearly cares about (an MR was
|
|
22
|
-
merged, a long task finished or blocked, a CI verdict came in) — surface it once at the right
|
|
23
|
-
moment instead of waiting to be asked.
|
|
24
|
-
|
|
25
|
-
In all three cases, do **not** answer only from this session's perspective.
|
|
26
|
-
|
|
27
|
-
**Window** — only cover sessions whose `updatedAt` is later than:
|
|
28
|
-
|
|
29
|
-
> `max(timestamp of the user's previous message in this root session, now − 6h)`
|
|
30
|
-
|
|
31
|
-
The user's previous message anchors "since we last talked"; the 6-hour floor caps how far back you
|
|
32
|
-
go when the user has been away (avoids dumping a multi-day backlog on first contact). On top of
|
|
33
|
-
that, hard-cap the report at the **10 newest** entries — if more matched, mention "and N more older"
|
|
34
|
-
without listing them.
|
|
35
|
-
|
|
36
|
-
1. List recent sessions of this agent with the `mavis` tool:
|
|
37
|
-
`mavis({ command: "session list", args: { agent_name: "me" } })`.
|
|
38
|
-
2. Filter by the window above. For each match you don't already remember, peek at its tail with
|
|
39
|
-
`mavis({ command: "session messages", args: { session_id: "<sessionId>", limit: 5 } })` to
|
|
40
|
-
recover the outcome (deliverables, MR links, blockers).
|
|
41
|
-
3. Summarize each in one line, sorted newest-first. Keep it short — the user wants a status board,
|
|
42
|
-
not a transcript.
|
|
43
|
-
|
|
44
|
-
Skip the cross-session summary when the user clearly scopes the question to the current task (e.g.
|
|
45
|
-
"this MR" or "this plan").
|
|
46
|
-
{{/if}}
|
|
1
|
+
You are this agent's root session — the user's primary conversation entry point
|
|
2
|
+
and long-lived continuity owner. Maintain context across turns, understand the
|
|
3
|
+
user's goals, and move the work forward. Own request interpretation, integration,
|
|
4
|
+
and the final response and deliverables.
|
|
@@ -1,46 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
move the work forward:
|
|
6
|
-
|
|
7
|
-
- **Direct execution**: handle tasks yourself when the user's goal is clear.
|
|
8
|
-
{{#if features.delegation}}
|
|
9
|
-
- **Delegation**: follow Task Routing when delegating work.
|
|
10
|
-
{{/if}}
|
|
11
|
-
|
|
12
|
-
{{#if features.mavis}}
|
|
13
|
-
## Reporting Coverage
|
|
14
|
-
|
|
15
|
-
The root session is the user's unified status board for the whole agent. **Whenever you judge the
|
|
16
|
-
user needs the latest cross-session progress, proactively give it.** Concretely:
|
|
17
|
-
|
|
18
|
-
1. The user explicitly asks ("what's the status", "how's it going", etc.).
|
|
19
|
-
2. The user has been away for a while and just resumed — open with a short status snapshot, even
|
|
20
|
-
before they ask, so they don't have to chase you.
|
|
21
|
-
3. A meaningful state change happened across sessions that the user clearly cares about (an MR was
|
|
22
|
-
merged, a long task finished or blocked, a CI verdict came in) — surface it once at the right
|
|
23
|
-
moment instead of waiting to be asked.
|
|
24
|
-
|
|
25
|
-
In all three cases, do **not** answer only from this session's perspective.
|
|
26
|
-
|
|
27
|
-
**Window** — only cover sessions whose `updatedAt` is later than:
|
|
28
|
-
|
|
29
|
-
> `max(timestamp of the user's previous message in this root session, now − 6h)`
|
|
30
|
-
|
|
31
|
-
The user's previous message anchors "since we last talked"; the 6-hour floor caps how far back you
|
|
32
|
-
go when the user has been away (avoids dumping a multi-day backlog on first contact). On top of
|
|
33
|
-
that, hard-cap the report at the **10 newest** entries — if more matched, mention "and N more older"
|
|
34
|
-
without listing them.
|
|
35
|
-
|
|
36
|
-
1. List recent sessions of this agent with the `mavis` tool:
|
|
37
|
-
`mavis({ command: "session list", args: { agent_name: "me" } })`.
|
|
38
|
-
2. Filter by the window above. For each match you don't already remember, peek at its tail with
|
|
39
|
-
`mavis({ command: "session messages", args: { session_id: "<sessionId>", limit: 5 } })` to
|
|
40
|
-
recover the outcome (deliverables, MR links, blockers).
|
|
41
|
-
3. Summarize each in one line, sorted newest-first. Keep it short — the user wants a status board,
|
|
42
|
-
not a transcript.
|
|
43
|
-
|
|
44
|
-
Skip the cross-session summary when the user clearly scopes the question to the current task (e.g.
|
|
45
|
-
"this MR" or "this plan").
|
|
46
|
-
{{/if}}
|
|
1
|
+
You are this agent's root session — the user's primary conversation entry point
|
|
2
|
+
and long-lived continuity owner. Maintain context across turns, understand the
|
|
3
|
+
user's goals, and move the work forward. Own request interpretation, integration,
|
|
4
|
+
and the final response and deliverables.
|
|
@@ -89,14 +89,6 @@ capability, or UI work remains. For example, a Feishu URL alone should use the L
|
|
|
89
89
|
"read this in the right-side Browser" must use this Browser skill. If a larger workflow used Browser
|
|
90
90
|
earlier, continue later semantic operations through their purpose-built paths when available.
|
|
91
91
|
|
|
92
|
-
When a prior `web_fetch` result explicitly reports `browser_fallback_recommended: true`, Browser may
|
|
93
|
-
be used once as the rendered-page fallback only after the same purpose-built routing check. Outcomes
|
|
94
|
-
such as `not_found`, `non_text`, `invalid_request`, `http_error`, and `network_error` are terminal
|
|
95
|
-
and must not trigger Browser. After navigating the requested URL, choose exactly one rendered read:
|
|
96
|
-
use `inspect` when its element snapshot can contain the requested fact, otherwise use
|
|
97
|
-
`query(kind: "text")`. Do not call both for the same content. Never alternate repeatedly between
|
|
98
|
-
`web_fetch` and Browser.
|
|
99
|
-
|
|
100
92
|
## Browser Identity
|
|
101
93
|
|
|
102
94
|
The native `browser` tool controls the Browser provider owned by the current chat session. It is not
|
|
@@ -33,7 +33,7 @@ descriptions:
|
|
|
33
33
|
|
|
34
34
|
## Official source discovery
|
|
35
35
|
|
|
36
|
-
For every product question, first identify the runtime `region` from `<agent-context>`:
|
|
36
|
+
For every product question, first identify the runtime `region` from `Environment` or `<agent-context>`:
|
|
37
37
|
|
|
38
38
|
- `region: cn` means the current app/account is China. Prefer China-region MiniMax Code and Open
|
|
39
39
|
Platform official documentation.
|
|
@@ -43,7 +43,7 @@ For every product question, first identify the runtime `region` from `<agent-con
|
|
|
43
43
|
domains. If an official page links to another official domain, or the current-region documentation
|
|
44
44
|
does not contain the needed fact, continue with that official source and verify its product and
|
|
45
45
|
region.
|
|
46
|
-
- If `region` is missing or unknown, do not infer it from
|
|
46
|
+
- If `region` is missing or unknown, do not infer it from locale, language, IP, or URL.
|
|
47
47
|
State that regional routing is unknown and ask for or obtain a trusted runtime region before
|
|
48
48
|
making region-sensitive claims.
|
|
49
49
|
- Do not mix China-region and Global-region prices, plans, quotas, model access, or entitlements in
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
{{#if features.delegation}}
|
|
2
2
|
{{#if surface.interactive}}
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
# Task Routing
|
|
5
4
|
Default to handling the user's request yourself. The parent owns user-intent
|
|
6
5
|
interpretation, scope, decomposition, integration, and the final user answer.
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
## Work directly
|
|
10
8
|
- Conversation, clarification, explanation, or advice.
|
|
11
9
|
- A targeted read/search, one obvious command, or a small well-understood change.
|
|
12
10
|
- Any work where delegation costs more context than it saves.
|
|
@@ -15,8 +13,7 @@ When the current request explicitly instructs you to invoke `task` for a specifi
|
|
|
15
13
|
|
|
16
14
|
Do not launch a child merely to repeat work you are already doing.
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
## Delegate
|
|
20
17
|
Use `task` only for one concrete, bounded subtask:
|
|
21
18
|
|
|
22
19
|
{{ROLE_DIRECTORY}}
|
|
@@ -27,8 +24,7 @@ It does not authorize broader edits, new external side effects, or overlapping w
|
|
|
27
24
|
Use explore for bounded codebase mapping or evidence gathering, not to transfer
|
|
28
25
|
interpretation or final decision-making.
|
|
29
26
|
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
## Brief a fresh child
|
|
32
28
|
The child does not inherit this conversation. Provide:
|
|
33
29
|
- objective and why it matters;
|
|
34
30
|
- known facts, evidence, and paths already ruled out;
|
|
@@ -39,49 +35,63 @@ The child does not inherit this conversation. Provide:
|
|
|
39
35
|
|
|
40
36
|
Never say "continue the work above".
|
|
41
37
|
|
|
42
|
-
|
|
43
|
-
|
|
38
|
+
## Foreground and background
|
|
44
39
|
Use foreground when the result blocks your next decision. Use background only
|
|
45
40
|
for independent or long-running work. Continue only with non-overlapping work;
|
|
46
41
|
do not routinely poll. Parallel writers must have disjoint ownership. If work
|
|
47
42
|
cannot be split without overlapping writes, use one writer serially.
|
|
48
43
|
|
|
49
|
-
|
|
50
|
-
|
|
44
|
+
## After delegation
|
|
51
45
|
Treat child output as evidence, not the final user answer. Check important
|
|
52
46
|
claims or changes, integrate the result, and communicate it yourself.
|
|
53
47
|
{{/if}}
|
|
54
48
|
{{/if}}
|
|
55
|
-
- **Don't ask the user to clarify what you can figure out yourself** — if the task intent is clear,
|
|
56
|
-
start working; if you don't recognize something they mentioned, search first. Only ask when the
|
|
57
|
-
ambiguity would lead to fundamentally different outcomes and you can't resolve it on your own.
|
|
58
|
-
- **Fix collateral issues in-scope** — if you discover a clearly broken or outdated thing while
|
|
59
|
-
working (wrong docs, stale defaults, inconsistent config), fix it in the same work scope. Don't
|
|
60
|
-
come back asking "should I also fix this?" — that transfers decision burden back to the user for
|
|
61
|
-
something that has an obvious answer.
|
|
62
49
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
50
|
+
# Harness
|
|
51
|
+
- For unfamiliar project-specific concepts, search the workspace with `grep` or `glob` first.
|
|
52
|
+
- When changing code, use current source context to follow existing conventions, and check the project manifest before relying on a dependency. Read missing context before editing.
|
|
53
|
+
- Never introduce code that exposes or logs secrets.
|
|
66
54
|
|
|
67
|
-
|
|
68
|
-
|
|
55
|
+
# Core Judgment
|
|
56
|
+
- Use established context and decisions. When the goal is clear, move forward directly without repeated confirmations.
|
|
57
|
+
- Do the work the user actually asked for without quietly expanding, narrowing, or reshaping it.
|
|
58
|
+
- For questions, explanations, or exploratory discussion, provide the assessment; make changes only when requested.
|
|
59
|
+
- When faced with ambiguity, first complete everything that does not depend on the answer. Resolve discoverable uncertainty from context, files, tools, or a safe reversible default. Ask only about user decisions that materially change the outcome or make proceeding unsafe.
|
|
60
|
+
- For complex tasks, define scope, deliverable, and validation before breaking down the work; do not force planning onto simple tasks.
|
|
61
|
+
- If you disagree, state the concern briefly. If the user reaffirms the request, follow their decision within safety, permission, and other hard constraints.
|
|
62
|
+
- Base conclusions on available evidence; unfamiliarity alone does not prove non-existence.
|
|
69
63
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
suggestion backed by facts from memory.
|
|
74
|
-
3. **User agrees, then you act.** Only create agents or set up tooling when the user explicitly
|
|
75
|
-
agrees.
|
|
64
|
+
{{#if features.mavis}}
|
|
65
|
+
{{#if surface.interactive}}
|
|
66
|
+
- Help with the current task without requiring workspace setup or bootstrapping first.
|
|
76
67
|
{{/if}}
|
|
77
68
|
{{/if}}
|
|
78
69
|
|
|
79
|
-
|
|
70
|
+
# Communication & Delivery
|
|
71
|
+
## Response Style
|
|
72
|
+
- Correct yourself when an error changes the user's decision or the work's outcome. Be brief and continue; don't over-apologize or ruminate.
|
|
73
|
+
|
|
74
|
+
## Final response
|
|
75
|
+
Verify before declaring completion. Report results faithfully: say what succeeded, what failed, what was skipped, and what remains unverified.
|
|
76
|
+
|
|
77
|
+
Lead with the outcome, then provide the necessary evidence.
|
|
78
|
+
|
|
79
|
+
## Media Output
|
|
80
|
+
You MUST include file deliverables in the final response using the delivery format specified by the current surface, regardless of which tool created or changed them. Do not just print a local file path. The default media format is:
|
|
81
|
+
|
|
82
|
+
- Image URLs: use a bare URL or ``.
|
|
83
|
+
- Local files: wrap `<media />` tags in `<deliver-assets>...</deliver-assets>`:
|
|
80
84
|
|
|
81
|
-
|
|
85
|
+
```
|
|
86
|
+
<deliver-assets>
|
|
87
|
+
<media src="/absolute/path/to/image.png" />
|
|
88
|
+
<media type="file" src="/absolute/path/to/output.zip" caption="Generated archive" />
|
|
89
|
+
<media src="/absolute/path/to/deleted.txt" deleted="true" />
|
|
90
|
+
</deliver-assets>
|
|
91
|
+
```
|
|
82
92
|
|
|
83
|
-
-
|
|
84
|
-
-
|
|
85
|
-
-
|
|
86
|
-
|
|
87
|
-
-
|
|
93
|
+
- `src` is required and accepts a URL or absolute local path. `type` is optional (`image`, `file`, `audio`, or `video`; inferred from the extension), as is `caption`.
|
|
94
|
+
- Include only files actually created, modified, or deleted in this turn as deliverables; never send files merely read for context.
|
|
95
|
+
- Verify the current state before delivery: created or modified files must exist; `deleted="true"` requires that the file existed before this turn and is now absent. Use conclusive tool results or check the filesystem.
|
|
96
|
+
- Exclude planned, guessed, stale, or unverified paths. If creation or verification failed, report the failure instead of emitting a media tag.
|
|
97
|
+
- The client renders media tags as deliverables and removes the tags from the displayed text.
|
|
@@ -13,11 +13,6 @@
|
|
|
13
13
|
"_migration/general/PERSONA-zh.md": "Frozen migration-only Agent asset.",
|
|
14
14
|
"_migration/general/PERSONA.md": "Frozen migration-only Agent asset.",
|
|
15
15
|
"_migration/general/system-prompt.md.hbs": "Frozen migration-only Agent asset.",
|
|
16
|
-
"_tui/prompt-base-all.md.hbs": "TUI-only Prompt asset, locally bundled outside desktop_agent Prompt control.",
|
|
17
|
-
"_tui/prompt-base-windows.md.hbs": "TUI-only Prompt asset, locally bundled outside desktop_agent Prompt control.",
|
|
18
|
-
"_tui/prompt-base-worker.md.hbs": "TUI-only Prompt asset, locally bundled outside desktop_agent Prompt control.",
|
|
19
|
-
"_tui/prompt-session-branch.md.hbs": "TUI-only Prompt asset, locally bundled outside desktop_agent Prompt control.",
|
|
20
|
-
"_tui/prompt-session-root.md.hbs": "TUI-only Prompt asset, locally bundled outside desktop_agent Prompt control.",
|
|
21
16
|
"explore/agent.md": "Agent capability configuration, outside Prompt injection.",
|
|
22
17
|
"mavis/PERSONA-zh.md": "Legacy Agent-level fallback superseded by managed mode assets.",
|
|
23
18
|
"mavis/PERSONA.md": "Legacy Agent-level fallback superseded by managed mode assets.",
|
|
@@ -36,13 +31,8 @@
|
|
|
36
31
|
"mavis/skills/minimax-code-product/references/extensions.md": "Built-in Skill reference, outside Prompt injection.",
|
|
37
32
|
"mavis/skills/minimax-code-product/references/workflows.md": "Built-in Skill reference, outside Prompt injection.",
|
|
38
33
|
"mavis/system-prompt.md.hbs": "Legacy Agent-level fallback superseded by managed mode assets.",
|
|
39
|
-
"mavis/tui/PERSONA-zh.md.hbs": "TUI-only Prompt asset, locally bundled outside desktop_agent Prompt control.",
|
|
40
|
-
"mavis/tui/PERSONA.md.hbs": "TUI-only Prompt asset, locally bundled outside desktop_agent Prompt control.",
|
|
41
|
-
"mavis/tui/SYSTEM.md.hbs": "TUI-only Prompt asset, locally bundled outside desktop_agent Prompt control.",
|
|
42
|
-
"mavis/tui/features/delegation.md.hbs": "TUI-only Prompt asset, locally bundled outside desktop_agent Prompt control.",
|
|
43
|
-
"mavis/tui/features/task-management.md.hbs": "TUI-only Prompt asset, locally bundled outside desktop_agent Prompt control.",
|
|
44
|
-
"mavis/tui/features/web-search.md.hbs": "TUI-only Prompt asset, locally bundled outside desktop_agent Prompt control.",
|
|
45
34
|
"verifier/agent.md": "Agent capability configuration, outside Prompt injection.",
|
|
46
|
-
"worker/agent.md": "Agent capability configuration, outside Prompt injection."
|
|
35
|
+
"worker/agent.md": "Agent capability configuration, outside Prompt injection.",
|
|
36
|
+
"_v2/tui/SYSTEM.md.hbs": "V2 本地模式 Prompt,合并身份、规则与功能条件;不参与 desktop_agent 动态下发。"
|
|
47
37
|
}
|
|
48
38
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire as __mavis_cR } from "module"; import { basename as __mavis_basename, dirname as __mavis_dirname, join as __mavis_join } from "path"; import { fileURLToPath as __mavis_fileURLToPath, pathToFileURL as __mavis_pathToFileURL } from "url"; const __mavis_tuiCurrentModuleDir = __mavis_dirname(__mavis_fileURLToPath(import.meta.url)); const __mavis_tuiPackageRoot = __mavis_basename(__mavis_tuiCurrentModuleDir) === "chunks" ? __mavis_dirname(__mavis_tuiCurrentModuleDir) : __mavis_tuiCurrentModuleDir; const __mavis_tuiPackageEntryUrl = __mavis_pathToFileURL(__mavis_join(__mavis_tuiPackageRoot, "cli.js")).href; const require = __mavis_cR(__mavis_tuiPackageEntryUrl); const __dirname = __mavis_tuiPackageRoot;
|
|
2
|
-
import{c as a}from"./chunk-
|
|
2
|
+
import{c as a}from"./chunk-AJSGEEWR.js";import"./chunk-C3JRMX7L.js";import"./chunk-KVMK6REW.js";import"./chunk-W7JHDTPW.js";import"./chunk-O6RIRKRN.js";import"./chunk-HQ2U4QVQ.js";import"./chunk-B2NJMA4I.js";import"./chunk-CWWDVX6C.js";import"./chunk-D76SO2ME.js";export{a as McodeUpdateApplication};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createRequire as __mavis_cR } from "module"; import { basename as __mavis_basename, dirname as __mavis_dirname, join as __mavis_join } from "path"; import { fileURLToPath as __mavis_fileURLToPath, pathToFileURL as __mavis_pathToFileURL } from "url"; const __mavis_tuiCurrentModuleDir = __mavis_dirname(__mavis_fileURLToPath(import.meta.url)); const __mavis_tuiPackageRoot = __mavis_basename(__mavis_tuiCurrentModuleDir) === "chunks" ? __mavis_dirname(__mavis_tuiCurrentModuleDir) : __mavis_tuiCurrentModuleDir; const __mavis_tuiPackageEntryUrl = __mavis_pathToFileURL(__mavis_join(__mavis_tuiPackageRoot, "cli.js")).href; const require = __mavis_cR(__mavis_tuiPackageEntryUrl); const __dirname = __mavis_tuiPackageRoot;
|
|
2
|
-
import{a as o,b as l,c as u}from"./chunk-
|
|
2
|
+
import{a as o,b as l,c as u}from"./chunk-BNU46XHR.js";import"./chunk-QJWOGW27.js";import{d as p}from"./chunk-SYLCIHHV.js";import"./chunk-22LVIQ2T.js";import"./chunk-2SW3R5AB.js";import"./chunk-ZITT4GJK.js";import"./chunk-2ZG44JU6.js";import"./chunk-B2NJMA4I.js";import"./chunk-CWWDVX6C.js";import"./chunk-D76SO2ME.js";async function A(r={}){let a=r.createApplication?r.createApplication(r.region):await c(r.region,r.prepareDataDir),t=r.writeError??(e=>process.stderr.write(e));return(await a.login(e=>{let n=l(e.verificationUriComplete??e.verificationUri);if(t(`Open: ${n}
|
|
3
3
|
Code: ${e.userCode}
|
|
4
4
|
Waiting for authorization\u2026
|
|
5
5
|
`),r.openBrowser===!1)return;(r.openExternalTarget??o(process.cwd()))(n).catch(()=>{t(`Couldn't open the default browser. Open the authorization URL above manually.
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { createRequire as __mavis_cR } from "module"; import { basename as __mavis_basename, dirname as __mavis_dirname, join as __mavis_join } from "path"; import { fileURLToPath as __mavis_fileURLToPath, pathToFileURL as __mavis_pathToFileURL } from "url"; const __mavis_tuiCurrentModuleDir = __mavis_dirname(__mavis_fileURLToPath(import.meta.url)); const __mavis_tuiPackageRoot = __mavis_basename(__mavis_tuiCurrentModuleDir) === "chunks" ? __mavis_dirname(__mavis_tuiCurrentModuleDir) : __mavis_tuiCurrentModuleDir; const __mavis_tuiPackageEntryUrl = __mavis_pathToFileURL(__mavis_join(__mavis_tuiPackageRoot, "cli.js")).href; const require = __mavis_cR(__mavis_tuiPackageEntryUrl); const __dirname = __mavis_tuiPackageRoot;
|
|
2
|
-
import{a as R,b as g,c as h}from"./chunk-SD6SJL3L.js";import"./chunk-PWQHCWDV.js";import{
|
|
2
|
+
import{a as y}from"./chunk-SHXPTUWI.js";import{a as R,b as g,c as h}from"./chunk-SD6SJL3L.js";import"./chunk-PWQHCWDV.js";import{b as f}from"./chunk-IIHJNKC3.js";import"./chunk-2UWBSJDH.js";import{f as d,i as l,k as A,m as E}from"./chunk-GUFBGYOC.js";import{a as m}from"./chunk-CK62QLTS.js";import"./chunk-WFWSBUYD.js";import"./chunk-D76SO2ME.js";var w="v1",U=new Set(["openai","openai-codex","opencode","azure-openai-responses"]);function O(r){let t=new Map;if(!r)return t;for(let e of r.split(",")){let s=e.trim();if(!s)continue;let[a,n]=s.split("=",2);!a||!n||t.set(a.trim(),n.trim())}return t}function I(r,t){return t?.azureDeploymentName?t.azureDeploymentName:O(process.env.AZURE_OPENAI_DEPLOYMENT_NAME_MAP).get(r.id)||r.id}function z(r){if(r instanceof Error){let t=r.status,e=typeof t=="number"?t:void 0;return e!==void 0?`Azure OpenAI API error (${e}): ${r.message}`:r.message}try{return JSON.stringify(r)}catch{return String(r)}}var N=(r,t,e)=>{let s=new l;return(async()=>{let a=I(r,e),n={role:"assistant",content:[],api:"azure-openai-responses",provider:r.provider,model:r.id,usage:{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}},stopReason:"stop",timestamp:Date.now()};try{let o=e?.apiKey;if(!o)throw new Error(`No API key for provider: ${r.provider}`);let i=L(r,o,e),u=M(r,t,e,a),c=await e?.onPayload?.(u,r);c!==void 0&&(u=c);let _={...e?.signal?{signal:e.signal}:{},...e?.timeoutMs!==void 0?{timeout:e.timeoutMs}:{},maxRetries:e?.maxRetries??0},{data:v,response:p}=await i.responses.create(u,_).withResponse();if(await e?.onResponse?.({status:p.status,headers:m(p.headers)},r),s.push({type:"start",partial:n}),await h(v,n,s,r),e?.signal?.aborted)throw new Error("Request was aborted");if(n.stopReason==="aborted"||n.stopReason==="error")throw new Error("An unknown error occurred");s.push({type:"done",reason:n.stopReason,message:n}),s.end()}catch(o){A(e?.onProviderError,o,r);for(let i of n.content)delete i.index,delete i.partialJson;n.stopReason=e?.signal?.aborted?"aborted":"error",n.errorMessage=z(o),s.push({type:"error",reason:n.stopReason,error:n}),s.end()}})(),s},V=(r,t,e)=>{let s=e?.apiKey;if(!s)throw new Error(`No API key for provider: ${r.provider}`);let a=E(r,e,s),n=e?.reasoning?d(r,e.reasoning):void 0;return N(r,t,{...a,reasoningEffort:n==="off"?void 0:n})};function P(r){let t=r.trim().replace(/\/+$/,""),e;try{e=new URL(t)}catch{throw new Error(`Invalid Azure OpenAI base URL: ${r}`)}let s=e.hostname.endsWith(".openai.azure.com")||e.hostname.endsWith(".cognitiveservices.azure.com"),a=e.pathname.replace(/\/+$/,"");return s&&(a===""||a==="/"||a==="/openai")&&(e.pathname="/openai/v1",e.search=""),e.toString().replace(/\/+$/,"")}function b(r){return`https://${r}.openai.azure.com/openai/v1`}function S(r,t){let e=t?.azureApiVersion||process.env.AZURE_OPENAI_API_VERSION||w,s=t?.azureBaseUrl?.trim()||process.env.AZURE_OPENAI_BASE_URL?.trim()||void 0,a=t?.azureResourceName||process.env.AZURE_OPENAI_RESOURCE_NAME,n=s;if(!n&&a&&(n=b(a)),!n&&r.baseUrl&&(n=r.baseUrl),!n)throw new Error("Azure OpenAI base URL is required. Set AZURE_OPENAI_BASE_URL or AZURE_OPENAI_RESOURCE_NAME, or pass azureBaseUrl, azureResourceName, or model.baseUrl.");return{baseUrl:P(n),apiVersion:e}}function L(r,t,e){let s={...r.headers};e?.headers&&Object.assign(s,e.headers);let{baseUrl:a,apiVersion:n}=S(r,e);return new f({apiKey:t,apiVersion:n,dangerouslyAllowBrowser:!0,defaultHeaders:s,baseURL:a})}function M(r,t,e,s){let a=R(r,t,U),n={model:s,input:a,stream:!0,prompt_cache_key:y(e?.sessionId),store:!1};if(e?.maxTokens&&(n.max_output_tokens=e?.maxTokens),e?.temperature!==void 0&&(n.temperature=e?.temperature),t.tools&&t.tools.length>0&&(n.tools=g(t.tools)),r.reasoning)if(e?.reasoningEffort||e?.reasoningSummary){let o=e?.reasoningEffort?r.thinkingLevelMap?.[e.reasoningEffort]??e.reasoningEffort:"medium";n.reasoning={effort:o,summary:e?.reasoningSummary||"auto"},n.include=["reasoning.encrypted_content"]}else r.thinkingLevelMap?.off!==null&&(n.reasoning={effort:r.thinkingLevelMap?.off??"none"});return n}export{N as streamAzureOpenAIResponses,V as streamSimpleAzureOpenAIResponses};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createRequire as __mavis_cR } from "module"; import { basename as __mavis_basename, dirname as __mavis_dirname, join as __mavis_join } from "path"; import { fileURLToPath as __mavis_fileURLToPath, pathToFileURL as __mavis_pathToFileURL } from "url"; const __mavis_tuiCurrentModuleDir = __mavis_dirname(__mavis_fileURLToPath(import.meta.url)); const __mavis_tuiPackageRoot = __mavis_basename(__mavis_tuiCurrentModuleDir) === "chunks" ? __mavis_dirname(__mavis_tuiCurrentModuleDir) : __mavis_tuiCurrentModuleDir; const __mavis_tuiPackageEntryUrl = __mavis_pathToFileURL(__mavis_join(__mavis_tuiPackageRoot, "cli.js")).href; const require = __mavis_cR(__mavis_tuiPackageEntryUrl); const __dirname = __mavis_tuiPackageRoot;
|
|
2
|
-
import{Z as ne,pa as ie,qa as re}from"./chunk-
|
|
2
|
+
import{Z as ne,pa as ie,qa as re}from"./chunk-2SW3R5AB.js";import{a as Te}from"./chunk-2ZG44JU6.js";import{a as oe}from"./chunk-B2NJMA4I.js";import{e as Se}from"./chunk-D76SO2ME.js";var d="mcode-public",c=["agent.default"],p="agent-backend";var Me={cn:{dev:"https://account.minimax.cn",test:"https://account.minimax.cn",staging:"https://account.minimax.cn",prod:"https://account.minimax.cn"},en:{dev:"https://account.minimax.io",test:"https://account.minimax.io",staging:"https://account.minimax.io",prod:"https://account.minimax.io"}};function Mt(t,e){if([t.MCODE_OAUTH_DEVICE_AUTHORIZATION_ENDPOINT,t.MCODE_OAUTH_TOKEN_ENDPOINT,t.MCODE_OAUTH_REVOCATION_ENDPOINT].every(s=>!s?.trim())){let s=Me[e.region][e.buildEnv];return{deviceAuthorizationEndpoint:`${s}/oauth2/device/code`,...se(e.buildEnv),tokenEndpoint:`${s}/oauth2/token`,revocationEndpoint:`${s}/oauth2/revoke`}}let i=H(t.MCODE_OAUTH_DEVICE_AUTHORIZATION_ENDPOINT),r=H(t.MCODE_OAUTH_TOKEN_ENDPOINT),o=H(t.MCODE_OAUTH_REVOCATION_ENDPOINT);if(!i||!r||!o)throw new TypeError("Shared MCode OAuth requires all three public OAuth endpoints to be configured.");return{deviceAuthorizationEndpoint:i,...se(e.buildEnv),tokenEndpoint:r,revocationEndpoint:o}}function se(t){return t==="staging"?{deviceAuthorizationHeaders:{"X-User-Pre":"1"}}:{}}function H(t){if(t?.trim())try{let e=new URL(t);return e.protocol!=="https:"||e.username||e.password||e.hash?void 0:e.toString()}catch{return}}import{randomUUID as $}from"node:crypto";import{watchFile as Ke,unwatchFile as $e}from"node:fs";var ce=Se(Te(),1);import{open as be}from"node:fs/promises";import{chmod as ae,mkdir as Ie,open as Ce,rename as Oe,unlink as ke}from"node:fs/promises";import{dirname as Pe}from"node:path";async function O(t){await Ie(t,{recursive:!0,mode:448}),process.platform!=="win32"&&await ae(t,448)}async function b(t,e){let n=Pe(t);await O(n);let i=`${t}.${process.pid}.${Date.now()}.tmp`,r=await Ce(i,"wx",384);try{await r.writeFile(e,{encoding:"utf8"}),await r.sync()}finally{await r.close()}try{process.platform!=="win32"&&await ae(i,384),await Oe(i,t)}catch(o){throw await ke(i).catch(()=>{}),o}}import{dirname as xe}from"node:path";var w=class{lockPath;staleMs;retries;constructor(e,n={}){this.lockPath=e,this.staleMs=n.staleMs??3e4,this.retries=n.retries??120}async withLock(e){await O(xe(this.lockPath)),await(await be(this.lockPath,"a",384)).close();let i,r=await ce.default.lock(this.lockPath,{realpath:!1,stale:this.staleMs,retries:{retries:this.retries,factor:1.15,minTimeout:5,maxTimeout:250},onCompromised:o=>{i??=o}});try{return await e()}finally{try{await r()}catch(o){if(!i)throw o}if(i)throw i}}};import{createHash as Re,randomBytes as Ne}from"node:crypto";var Ue="urn:ietf:params:oauth:grant-type:device_code",l=class extends Error{code;httpStatus;constructor(e,n,i){super(n??`The OAuth server rejected the request (${e}${i?`, HTTP ${i}`:""}).`),this.code=e,this.httpStatus=i,this.name="OAuthProtocolError"}},j=class{options;fetchImpl;sleep;now;constructor(e){this.options=e,this.fetchImpl=e.fetchImpl??fetch,this.sleep=e.sleep??(n=>new Promise(i=>setTimeout(i,n))),this.now=e.now??Date.now}async startDeviceAuthorization(e={}){let n=Ne(32).toString("base64url"),i=Re("sha256").update(n,"ascii").digest("base64url"),r=await this.postForm(this.options.deviceAuthorizationEndpoint,{client_id:d,scope:c.join(" "),audience:p,code_challenge:i,code_challenge_method:"S256"},{headers:this.options.deviceAuthorizationHeaders,signal:e.signal}),o=u(r,"user_code"),s=u(r,"device_code"),a=R(r,"expired_in"),h=!s&&!!o&&a!==void 0,C=s??(h?o:void 0),B=u(r,"verification_uri")??u(r,"verification_url"),te=R(r,"expires_in")??ze(a,this.now()),V=R(r,"interval"),Ae=h&&V!==void 0?V/1e3:V??5;if(!C||!o||!B||!te)throw new l("invalid_device_authorization_response");return{deviceCode:C,codeVerifier:n,...h?{tokenPollingParameter:"user_code"}:{},userCode:o,verificationUri:B,...u(r,"verification_uri_complete")||h?{verificationUriComplete:u(r,"verification_uri_complete")??B}:{},expiresInSec:te,intervalSec:Ae}}async pollDeviceToken(e,n={}){let i=this.now()+e.expiresInSec*1e3,r=e.intervalSec*1e3;for(;this.now()<i;){n.signal?.throwIfAborted();let o=e.tokenPollingParameter==="user_code"?{user_code:e.userCode}:{device_code:e.deviceCode},s=await this.postFormAllowOAuthError(this.options.tokenEndpoint,{grant_type:Ue,...o,client_id:d,code_verifier:e.codeVerifier},{signal:n.signal}),a=u(s.body,"status");if(s.ok&&a==="pending"){await x(this.sleep,r,n.signal);continue}if(s.ok&&a==="slow_down"){r+=5e3,await x(this.sleep,r,n.signal);continue}if(s.ok&&(a==="denied"||a==="access_denied"))throw new l("access_denied");if(s.ok&&(a==="expired"||a==="expired_token"))throw new l("expired_token");if(s.ok)return ue(s.body);if(s.error==="authorization_pending"){await x(this.sleep,r,n.signal);continue}if(s.error==="slow_down"){r+=5e3,await x(this.sleep,r,n.signal);continue}throw new l(s.error??"device_authorization_failed",void 0,s.status)}throw new l("expired_token","The OAuth device authorization expired.")}async refreshToken(e){let n=await this.postForm(this.options.tokenEndpoint,{grant_type:"refresh_token",refresh_token:e,client_id:d,scope:c.join(" "),audience:p});return ue(n,e)}async revokeToken(e){let n=await this.postFormAllowOAuthError(this.options.revocationEndpoint,{token:e,token_type_hint:"refresh_token",client_id:d},{allowEmptySuccess:!0});if(!n.ok)throw new l(n.error??"oauth_request_failed",void 0,n.status)}async postForm(e,n,i={}){let r=await this.postFormAllowOAuthError(e,n,i);if(!r.ok)throw new l(r.error??"oauth_request_failed",void 0,r.status);return r.body}async postFormAllowOAuthError(e,n,i={}){let r=await this.fetchImpl(e,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/x-www-form-urlencoded",...i.headers},body:new URLSearchParams(n),signal:i.signal}),o=N(await r.json().catch(()=>{}));if(!o&&r.ok&&i.allowEmptySuccess)return{ok:!0,status:r.status,body:{}};if(!o)throw new l("invalid_json_response",void 0,r.status);let s=u(o,"error");return{ok:r.ok&&!s,status:r.status,body:o,...s?{error:s}:{}}}};async function x(t,e,n){if(!n){await t(e);return}n.throwIfAborted();let i,r=()=>i(n.reason),o=new Promise((s,a)=>{i=a});n.addEventListener("abort",r,{once:!0});try{await Promise.race([t(e),o])}finally{n.removeEventListener("abort",r)}}function ue(t,e){let n=u(t,"access_token"),i=u(t,"refresh_token")??e,r=u(t,"token_type"),o=R(t,"expires_in"),s=n?De(n):void 0,a=Le(t.scope??s?.scope??s?.scp);if(!n||!i||r?.toLowerCase()!=="bearer"||!o||!a.includes(c[0]))throw new l("invalid_token_response");return{accessToken:n,refreshToken:i,tokenType:"Bearer",scopes:a,audience:p,expiresInSec:o,...u(s,"sub")?{subject:u(s,"sub")}:{},...u(s,"account_id")?{accountId:u(s,"account_id")}:{}}}function De(t){let e=t.split(".");if(!(e.length!==3||!e[1]))try{return N(JSON.parse(Buffer.from(e[1],"base64url").toString("utf8")))}catch{return}}function Le(t){return typeof t=="string"?t.split(/\s+/u).filter(Boolean):Array.isArray(t)&&t.every(e=>typeof e=="string")?t:[]}function N(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)?t:void 0}function u(t,e){let i=N(t)?.[e];return typeof i=="string"&&i.trim()?i.trim():void 0}function R(t,e){let i=N(t)?.[e];return typeof i=="number"&&Number.isFinite(i)&&i>0?i:void 0}function ze(t,e){if(t===void 0)return;if(t<1e12)return t;let n=t-e;return n>0?Math.ceil(n/1e3):void 0}import{readFile as Be}from"node:fs/promises";var E=2,Ve=1,He=/access[_-]?token|refresh[_-]?token|device[_-]?code|code[_-]?verifier/iu;function he(t){if(!(typeof t!="object"||t===null))for(let[e,n]of Object.entries(t)){if(He.test(e))throw new TypeError("Sensitive OAuth fields cannot be persisted in auth-state.json.");he(n)}}function de(t){if(typeof t!="object"||t===null||Array.isArray(t))throw new TypeError("Invalid OAuth state.");let e=t;if(!(typeof e.schemaVersion=="number"&&Number.isInteger(e.schemaVersion)&&e.schemaVersion>=Ve&&e.schemaVersion<=E&&["anonymous","authorizing","authenticated","refreshing","scope_upgrade_required","logging_out","logout_pending","expired","error"].includes(e.status)&&(e.schemaVersion===1&&(e.storeKind==="os-keyring"||e.storeKind==="file")||e.schemaVersion===E&&e.storeKind==="file")&&e.clientId==="mcode-public"&&Array.isArray(e.scopes)&&e.scopes.every(i=>typeof i=="string")&&e.audience==="agent-backend"&&je(e.buildEnv,e.region)&&(e.expiresAtMs===void 0||typeof e.expiresAtMs=="number"&&Number.isFinite(e.expiresAtMs))&&Number.isSafeInteger(e.generation)&&e.generation>=0&&(e.authorization===void 0||Fe(e.authorization))))throw new TypeError("Invalid OAuth state.");return he(e),e}function je(t,e){return t===void 0&&e===void 0?!0:(t==="dev"||t==="test"||t==="staging"||t==="prod")&&(e==="cn"||e==="en")}function Fe(t){if(typeof t!="object"||t===null||Array.isArray(t))return!1;let e=t;return typeof e.leaseId=="string"&&e.leaseId.length>0&&typeof e.leaseExpiresAtMs=="number"&&Number.isFinite(e.leaseExpiresAtMs)&&F(e.userCode)&&F(e.verificationUri)&&F(e.verificationUriComplete)}function F(t){return t===void 0||typeof t=="string"}var y=class{path;constructor(e){this.path=e}async read(){let e;try{e=await Be(this.path,"utf8")}catch(n){if(n.code==="ENOENT")return null;throw n}try{return de(JSON.parse(e))}catch(n){throw n instanceof TypeError?n:new TypeError("Invalid OAuth state.")}}async write(e){let n=de(e);await b(this.path,`${JSON.stringify(n,null,2)}
|
|
3
3
|
`)}};var qe=600*1e3,Ge=250,f=class extends Error{code="AUTH_REQUIRED";constructor(e){super("MCode authentication is required.",e),this.name="AuthRequiredError"}},T=class extends Error{code="AUTH_LOGIN_CANCELLED";constructor(){super("MCode OAuth device authorization was cancelled."),this.name="AuthLoginCancelledError"}},U=class extends Error{code="AUTH_SESSION_CHANGED";constructor(){super("The login changed while this request was in progress."),this.name="AuthSessionChangedError"}};function Je(t,e){if(!t||t!==e)throw new U}var M=class extends Error{missingScopes;code="AUTH_SCOPE_UPGRADE_REQUIRED";constructor(e){super("The current MCode authorization does not include the required scope."),this.missingScopes=e,this.name="AuthScopeUpgradeRequiredError"}},I=class extends Error{code="AUTH_RESOURCE_CONTRACT_MISMATCH";constructor(){super("The stored credential does not match the MCode resource contract."),this.name="AuthResourceContractMismatchError"}};function le(t){return t instanceof f||t instanceof M||t instanceof I}var q=class extends Error{active;requested;code="AUTH_DOMAIN_CONFLICT";constructor(e,n){super(`MCode is signed in to ${e.buildEnv}/${e.region}; sign out before using ${n.buildEnv}/${n.region}.`),this.active=e,this.requested=n,this.name="AuthDomainConflictError"}},G=class{options;stateStore;lock;now;sleep;authorizationLeaseMs;statePollIntervalMs;createLeaseId;loginPromise;loginAbortController;initializePromise;constructor(e){this.options=e,this.stateStore=new y(e.namespace.statePath),this.lock=new w(e.namespace.lockPath),this.now=e.now??Date.now,this.sleep=e.sleep??(n=>new Promise(i=>setTimeout(i,n))),this.authorizationLeaseMs=e.authorizationLeaseMs??qe,this.statePollIntervalMs=e.statePollIntervalMs??Ge,this.createLeaseId=e.createLeaseId??$}async getStatus(){await this.initialize();let e=await this.stateStore.read();if(!e)return{status:"anonymous",generation:0,scopes:[]};if(e.status==="authorizing"||e.status==="refreshing"){let n=await this.recoverInterruptedCredentialCommit(e);return _(n)}if(e.status==="authenticated"||e.status==="expired"){let n=await this.options.credentialStore.get(this.options.namespace.credentialKey);if(!n||n.generation!==e.generation)return _({...e,status:"error"});try{S(n,[...c])}catch(r){if(r instanceof M)return _({...k(n,this.options.credentialStore.kind,this.options.namespace),status:"scope_upgrade_required"});if(r instanceof I)return _({...e,status:"error"});throw r}let i=k(n,this.options.credentialStore.kind,this.options.namespace);return e.status==="expired"||n.expiresAtMs<=this.now()?_({...i,status:"expired"}):_(i)}return _(e)}login(e={}){if(!this.loginPromise){let n=new AbortController,i=this.initialize().then(()=>this.runLogin(e,n.signal)).finally(()=>{this.loginPromise===i&&(this.loginPromise=void 0,this.loginAbortController=void 0)});this.loginAbortController=n,this.loginPromise=i}return this.loginPromise}async cancelLogin(){let e=this.loginAbortController,n=this.loginPromise;if(!(!e||!n)){e.abort();try{await n}catch(i){if(!(i instanceof T))throw i}}}async getAccessToken(e){await this.initialize(),Ye(e.requiredScopes);try{let n=await this.readUsableCredential(e.requiredScopes);if(this.satisfiesMinValidity(n,e.minValidityMs))return K(n.credential)}catch(n){if(!(n instanceof f))throw n}return this.lock.withLock(async()=>{let n=await this.readUsableCredential(e.requiredScopes);return this.satisfiesMinValidity(n,e.minValidityMs)?K(n.credential):this.refreshCredential(n)})}satisfiesMinValidity(e,n){if(e.state.status!=="authenticated")return!1;let i=e.credential.expiresAtMs-this.now();return i>0&&i>=n}async handleUnauthorized(e){await this.initialize();try{return await this.lock.withLock(async()=>{let n=await this.readUsableCredential([...c]);if(e.loginEpoch!==void 0)Je(e.loginEpoch,n.credential.loginEpoch);else if(n.credential.generation>e.generation)throw new U;return n.credential.generation>e.generation?"retry":n.credential.generation<e.generation?"logout":(await this.refreshCredential(n,{rejected:!0}),"retry")})}catch(n){if(le(n))return"logout";throw n}}async logout(e){return await this.initialize(),this.lock.withLock(async()=>{let n=await this.stateStore.read(),i=await this.options.credentialStore.get(this.options.namespace.credentialKey),r=Math.max(n?.generation??0,i?.generation??0);if(!i&&(!n||n.status==="anonymous"))return{status:"anonymous",generation:r};let o=r+1;if(await this.stateStore.write(A({status:"logging_out",generation:o,storeKind:this.options.credentialStore.kind},this.options.namespace)),e.revoke&&i)try{await this.options.oauthClient.revokeToken(i.refreshToken)}catch{return await this.stateStore.write(A({status:"logout_pending",generation:o,storeKind:this.options.credentialStore.kind},this.options.namespace)),{status:"logout_pending",generation:o}}return await this.options.credentialStore.delete(this.options.namespace.credentialKey),await this.stateStore.write(A({status:"anonymous",generation:o,storeKind:this.options.credentialStore.kind},this.options.namespace)),{status:"anonymous",generation:o}})}watch(e){let n=()=>{this.getStatus().then(e).catch(()=>{})};return Ke(this.options.namespace.statePath,{interval:this.statePollIntervalMs},n),()=>$e(this.options.namespace.statePath,n)}initialize(){return this.initializePromise??=(async()=>{await this.options.initialize?.(),await this.options.credentialStore.healthCheck()})().catch(e=>{throw this.initializePromise=void 0,e}),this.initializePromise}async runLogin(e,n){for(;;){v(n);let i=this.createLeaseId(),r=await this.lock.withLock(async()=>{let o=await this.stateStore.read();Xe(o,this.options.namespace);let s=await this.options.credentialStore.get(this.options.namespace.credentialKey);if(o&&s&&o.generation===s.generation&&(o.status==="authenticated"||o.status==="expired"||o.status==="refreshing"))try{return S(s,[...c]),o.status==="authenticated"&&s.expiresAtMs>this.now()?{kind:"authenticated",generation:s.generation}:{kind:"refresh",generation:s.generation}}catch(h){if(!(h instanceof M)&&!(h instanceof I))throw h}if(o?.status==="authorizing"&&o.authorization&&o.authorization.leaseExpiresAtMs>this.now())return{kind:"wait",leaseExpiresAtMs:o.authorization.leaseExpiresAtMs};let a=Math.max(o?.generation??0,s?.generation??0);return await this.stateStore.write({...A({status:"authorizing",generation:a,storeKind:this.options.credentialStore.kind},this.options.namespace),authorization:{leaseId:i,leaseExpiresAtMs:this.now()+this.authorizationLeaseMs}}),{kind:"owner"}});if(r.kind==="authenticated")return{status:"authenticated",generation:r.generation};if(r.kind==="refresh"){try{await this.lock.withLock(async()=>{let s=await this.readUsableCredential([...c]);s.credential.generation>r.generation&&this.satisfiesMinValidity(s,1)||await this.refreshCredential(s)})}catch(s){if(le(s))continue;throw s}let o=await this.stateStore.read();if(o?.status==="authenticated")return{status:"authenticated",generation:o.generation};continue}if(r.kind==="wait"){let o=await this.waitForAuthorization(r.leaseExpiresAtMs,e.onDeviceAuthorization,n);if(o)return o;continue}try{let o=await this.options.oauthClient.startDeviceAuthorization({signal:n});await this.publishAuthorizationProgress(i,o),e.onDeviceAuthorization?.(Qe(o));let s=await this.options.oauthClient.pollDeviceToken(o,{signal:n});return await this.commitLogin(i,s,n)}catch(o){let s=n.aborted;throw await this.releaseAuthorizationLease(i,s?"anonymous":"error"),s?new T:o}}}async commitLogin(e,n,i){return this.lock.withLock(async()=>{v(i);let r=await this.stateStore.read();if(r?.status!=="authorizing"||r.authorization?.leaseId!==e)throw new f;let o=await this.options.credentialStore.get(this.options.namespace.credentialKey);v(i);let s=Math.max(r.generation,o?.generation??0)+1,a=pe(n,s,this.now(),$());await this.options.credentialStore.put(this.options.namespace.credentialKey,a);try{v(i),await this.stateStore.write(k(a,this.options.credentialStore.kind,this.options.namespace)),v(i)}catch(h){throw h instanceof T&&(await this.stateStore.write(r),o?await this.options.credentialStore.put(this.options.namespace.credentialKey,o):await this.options.credentialStore.delete(this.options.namespace.credentialKey)),h}return{status:"authenticated",generation:s}})}async waitForAuthorization(e,n,i){let r=!1;for(;this.now()<e;){v(i);let o=await this.stateStore.read();if(!r&&o?.status==="authorizing"&&o.authorization?.userCode&&o.authorization.verificationUri&&(n?.({userCode:o.authorization.userCode,verificationUri:o.authorization.verificationUri,...o.authorization.verificationUriComplete?{verificationUriComplete:o.authorization.verificationUriComplete}:{},expiresInSec:Math.max(1,Math.ceil((o.authorization.leaseExpiresAtMs-this.now())/1e3))}),r=!0),o?.status==="authenticated"){let s=await this.options.credentialStore.get(this.options.namespace.credentialKey);if(s&&s.generation===o.generation)return S(s,[...c]),{status:"authenticated",generation:o.generation}}if(o?.status!=="authorizing")return;await Ze(this.sleep,this.statePollIntervalMs,i)}}async publishAuthorizationProgress(e,n){await this.lock.withLock(async()=>{let i=await this.stateStore.read();if(i?.status!=="authorizing"||i.authorization?.leaseId!==e)throw new f;await this.stateStore.write({...i,authorization:{...i.authorization,userCode:n.userCode,verificationUri:n.verificationUri,...n.verificationUriComplete?{verificationUriComplete:n.verificationUriComplete}:{}}})})}async releaseAuthorizationLease(e,n){await this.lock.withLock(async()=>{let i=await this.stateStore.read();i?.status!=="authorizing"||i.authorization?.leaseId!==e||await this.stateStore.write(A({status:n,generation:i.generation,storeKind:this.options.credentialStore.kind},this.options.namespace))})}async recoverInterruptedCredentialCommit(e){let n=await this.options.credentialStore.get(this.options.namespace.credentialKey);return!n||n.generation<=e.generation?e:(S(n,[...c]),this.lock.withLock(async()=>{let i=await this.stateStore.read(),r=await this.options.credentialStore.get(this.options.namespace.credentialKey);if(!i||!r||i.status!=="authorizing"&&i.status!=="refreshing"||r.generation<=i.generation)return i??e;S(r,[...c]);let o=k(r,this.options.credentialStore.kind,this.options.namespace);return await this.stateStore.write(o),o}))}async readUsableCredential(e){let n=await this.stateStore.read();if(!n||n.status!=="authenticated"&&n.status!=="expired"&&n.status!=="refreshing")throw new f;let i=await this.options.credentialStore.get(this.options.namespace.credentialKey);if(!i||n.generation!==i.generation)throw new f;return S(i,e),{state:n,credential:i}}async refreshCredential(e,n={}){await this.stateStore.write({...e.state,status:"refreshing"});let i;try{i=await this.options.oauthClient.refreshToken(e.credential.refreshToken)}catch(o){if(We(o))throw await this.stateStore.write(A({status:"anonymous",generation:e.credential.generation+1,storeKind:this.options.credentialStore.kind},this.options.namespace)),await this.options.credentialStore.delete(this.options.namespace.credentialKey),new f({cause:o});{let s=!n.rejected&&e.state.status==="authenticated"&&e.credential.expiresAtMs>this.now();await this.stateStore.write({...e.state,status:s?"authenticated":"expired"})}throw o}let r=pe(i,Math.max(e.state.generation,e.credential.generation)+1,this.now(),e.credential.loginEpoch);return await this.options.credentialStore.put(this.options.namespace.credentialKey,r),await this.stateStore.write(k(r,this.options.credentialStore.kind,this.options.namespace)),K(r)}};function v(t){if(t?.aborted)throw new T}function We(t){return t instanceof l&&t.code==="invalid_grant"&&t.httpStatus===400}async function Ze(t,e,n){if(!n){await t(e);return}v(n);let i,r=()=>i(new T),o=new Promise((s,a)=>{i=a});n.addEventListener("abort",r,{once:!0});try{await Promise.race([t(e),o])}finally{n.removeEventListener("abort",r)}}function Qe(t){return{userCode:t.userCode,verificationUri:t.verificationUri,...t.verificationUriComplete?{verificationUriComplete:t.verificationUriComplete}:{},expiresInSec:t.expiresInSec}}function A(t,e){return{schemaVersion:E,status:t.status,storeKind:t.storeKind,clientId:d,scopes:[...c],audience:p,buildEnv:e.buildEnv,region:e.region,generation:t.generation}}function k(t,e,n){return{...A({status:"authenticated",generation:t.generation,storeKind:e},n),scopes:t.scopes,expiresAtMs:t.expiresAtMs}}function pe(t,e,n,i=$()){let r={schemaVersion:1,accessToken:t.accessToken,refreshToken:t.refreshToken,tokenType:t.tokenType,clientId:d,scopes:t.scopes,audience:p,expiresAtMs:n+t.expiresInSec*1e3,generation:e,loginEpoch:i,...t.subject?{subject:t.subject}:{},...t.accountId?{accountId:t.accountId}:{}};if(S(r,[...c]),t.audience!==p)throw new I;return r}function Ye(t){let e=t.filter(n=>!c.includes(n));if(e.length>0)throw new M(e)}function S(t,e){if(t.clientId!==d||t.audience!==p||t.tokenType!=="Bearer")throw new I;let n=e.filter(i=>!t.scopes.includes(i));if(n.length>0)throw new M(n)}function _(t){return{status:t.status,generation:t.generation,scopes:t.scopes,...t.buildEnv===void 0?{}:{buildEnv:t.buildEnv},...t.region===void 0?{}:{region:t.region},...t.expiresAtMs===void 0?{}:{expiresAtMs:t.expiresAtMs}}}function Xe(t,e){if(!(!t||t.status==="anonymous"||t.buildEnv===void 0||t.region===void 0||t.buildEnv===e.buildEnv&&t.region===e.region))throw new q({buildEnv:t.buildEnv,region:t.region},{buildEnv:e.buildEnv,region:e.region})}function K(t){return{accessToken:t.accessToken,...t.loginEpoch?{loginEpoch:t.loginEpoch}:{},expiresAtMs:t.expiresAtMs,generation:t.generation,scopes:c,audience:p}}import{createHash as et}from"node:crypto";import{join as g,resolve as tt}from"node:path";function J(t){let e=g(tt(t.dataDir),"auth"),n=g(e,t.buildEnv,t.region,d),i=`com.minimax.mcode.oauth.${t.buildEnv}.${t.region}`,r=et("sha256").update(`${e}\0${d}`).digest("base64url");return{authHome:e,namespaceHome:n,lockPath:g(n,"auth.lock"),statePath:g(n,"auth-state.json"),credentialPath:g(n,"auth.json"),legacyLockPath:g(e,"auth.lock"),legacyStatePath:g(e,"auth-state.json"),legacyEncryptedCredentialPath:g(e,"credentials.enc"),buildEnv:t.buildEnv,region:t.region,credentialKey:{service:i,account:r}}}async function nt(t){let e=await it(t),n=new y(t.statePath);await new w(t.lockPath).withLock(async()=>{let r=await n.read();if(r?.schemaVersion===E)return;let o=r??e;o&&await n.write(ot(o,t))})}async function it(t){let e=new y(t.legacyStatePath);return new w(t.legacyLockPath).withLock(async()=>{let i=await e.read();if(!rt(i,t))return null;let{authorization:r,...o}=i;return await e.write({...o,status:"error"}),i})}function rt(t,e){return t!==null&&t.status!=="error"&&t.buildEnv===e.buildEnv&&t.region===e.region}function ot(t,e){return{schemaVersion:E,status:"anonymous",storeKind:"file",clientId:"mcode-public",scopes:["agent.default"],audience:"agent-backend",buildEnv:e.buildEnv,region:e.region,generation:t.generation+1}}import{readFile as ct,stat as fe}from"node:fs/promises";import{join as ut}from"node:path";var st=1,at=1,m=class extends Error{code="CREDENTIAL_RECORD_CORRUPT";constructor(){super("The stored OAuth credential record is invalid."),this.name="CredentialRecordCorruptError"}},D=class extends Error{code="AUTH_CREDENTIAL_STORE_PERMISSION";constructor(){super("The OAuth credential file permissions are not private."),this.name="CredentialStorePermissionError"}};function W(t){return t===void 0||typeof t=="string"}function Z(t){if(typeof t!="object"||t===null||Array.isArray(t))throw new m;let e=t,n=e.scopes,i=Array.isArray(n)&&n.every(o=>typeof o=="string");if(!(typeof e.schemaVersion=="number"&&Number.isInteger(e.schemaVersion)&&e.schemaVersion>=at&&e.schemaVersion<=st&&typeof e.accessToken=="string"&&e.accessToken.length>0&&typeof e.refreshToken=="string"&&e.refreshToken.length>0&&e.tokenType==="Bearer"&&e.clientId===d&&i&&e.audience===p&&typeof e.expiresAtMs=="number"&&Number.isFinite(e.expiresAtMs)&&Number.isSafeInteger(e.generation)&&e.generation>=0&&W(e.subject)&&W(e.accountId)&&W(e.loginEpoch)))throw new m;return e}var Y=1;function Q(t){return`${t.service}\0${t.account}`}function me(t){if(typeof t!="object"||t===null||Array.isArray(t))throw new m;let e=t;if(e.schemaVersion!==Y||typeof e.records!="object"||e.records===null||Array.isArray(e.records))throw new m;let n=Object.fromEntries(Object.entries(e.records).map(([i,r])=>[i,Z(r)]));return{schemaVersion:Y,records:n}}var L=class{kind="file";authHome;path;constructor(e){this.authHome=e.authHome,this.path=ut(e.authHome,"auth.json")}async get(e){return(await this.readPayload()).records[Q(e)]??null}async put(e,n){let i=await this.readPayload();i.records[Q(e)]=Z(n),await this.writePayload(i)}async delete(e){let n=await this.readPayload();delete n.records[Q(e)],await this.writePayload(n)}async healthCheck(){await O(this.authHome),await this.assertPrivatePermissions()}async readPayload(){let e;try{await this.assertPrivatePermissions(),e=await ct(this.path,"utf8")}catch(n){if(n.code==="ENOENT")return{schemaVersion:Y,records:{}};throw n}try{return me(JSON.parse(e))}catch(n){throw n instanceof m?n:new m}}async assertPrivatePermissions(){if(process.platform!=="win32")try{let[e,n]=await Promise.all([fe(this.authHome),fe(this.path)]);if((e.mode&63)!==0||(n.mode&63)!==0)throw new D}catch(e){if(e.code==="ENOENT")return;throw e}}async writePayload(e){let n=me(e);await b(this.path,`${JSON.stringify(n,null,2)}
|
|
4
4
|
`)}};function dt(t){return new L(t)}var X;function ge(t){X=t}function ht(t={}){let e=t.embeddedBuildEnvironment??we(),n=t.embeddedBuildVariant??lt(),i=t.runtimeBuildEnv??ne();return oe({buildEnv:e??pt(i),internalBuild:n==="internal"})}function z(t={}){let e=ht(t);return{region:t.runtimeRegion??"cn",buildEnv:X??e.buildEnv??"test"}}function zn(t=we()){return X??t??"dev"}function we(){return"prod"}function lt(){return"standard"}function pt(t){return t==="dev"?"test":t}import gt from"node:fs";import P from"node:fs";import Ee from"node:path";var ye="preferences",ft="mcode-region.json";function _e(t,e){try{let n=JSON.parse(P.readFileSync(ve(t),"utf8"));if(n.version!==1||!n.regions||typeof n.regions!="object")return;let i=n.regions[e];return i==="cn"||i==="en"?i:void 0}catch{return}}function jn(t,e){let n=Ee.join(t,ye);P.mkdirSync(n,{recursive:!0,mode:448});let i=ve(t),o={version:1,regions:{...mt(i),[e.buildEnv]:e.region},updatedAtMs:Date.now()},s=`${i}.${process.pid}.${Date.now()}.tmp`;return P.writeFileSync(s,`${JSON.stringify(o,null,2)}
|
|
5
5
|
`,{encoding:"utf8",mode:384}),P.renameSync(s,i),i}function ve(t){return Ee.join(t,ye,ft)}function mt(t){try{let e=JSON.parse(P.readFileSync(t,"utf8"));return e.version!==1||!e.regions||typeof e.regions!="object"?{}:Object.fromEntries(Object.entries(e.regions).filter(([n,i])=>(n==="dev"||n==="test"||n==="staging"||n==="prod")&&(i==="cn"||i==="en")))}catch{return{}}}var wt=/^[A-Za-z0-9._-]+$/u,ee="--env",Et=new Set(["--lane","--resume","--tui-mode"]),yt=Object.freeze({test:"test",pre:"staging",staging:"staging",prod:"prod"});function Wn(t={}){ie(!1),re(!1);let{target:e=process.env,dataDir:n,startupBuildEnvironment:i,...r}=t;i&&ge(i);let o=z(r),s=n?_e(n,o.buildEnv):void 0,a=n?vt(n,o.buildEnv):void 0,h=St(e.MAVIS_REGION),C=z({...r,runtimeRegion:r.runtimeRegion??h??s??a?.region??"cn"});return n&&(e.MINIMAX_DATA_DIR=n,e.MAVIS_DATA_DIR=n),e.MAVIS_REGION=C.region,e.MAVIS_BUILD_ENV=C.buildEnv,e.__MAVIS_RUNTIME_MANAGED="1",C}function _t(t){let e=yt[t.trim()];if(!e)throw new Error("--env must be test, staging, pre, or prod.");return e}function Zn(t,e){let n=[];for(let i=0;i<t.length;i+=1){let r=t[i];if(r!==void 0){if(r==="--")break;if(r===ee){let o=t[i+1];if(!o||o.startsWith("-"))throw new Error("--env requires a value.");n.push(o),i+=1;continue}if(r.startsWith(`${ee}=`)){n.push(r.slice(ee.length+1));continue}if(Et.has(r)){i+=1;continue}if(r==="--session"&&t[i+1]&&!t[i+1]?.startsWith("-")){i+=1;continue}if(!r.startsWith("-"))break}}if(n.length!==0){if(!e)throw new Error("--env is only available in the internal MCode package.");if(n.length>1)throw new Error("--env may only be specified once.");return _t(n[0]??"")}}function Qn(t,e=z().buildEnv){if(t===void 0)return;if(e!=="test"&&e!=="staging")throw new Error("--lane is only supported in test or staging builds.");let n=t.trim();if(!wt.test(n))throw new Error("--lane only accepts letters, numbers, dot, underscore, and hyphen.");return n}function vt(t,e){let n=["cn","en"].filter(r=>{try{let o=J({dataDir:t,buildEnv:e,region:r}),s=JSON.parse(gt.readFileSync(o.statePath,"utf8"));return s.buildEnv===e&&s.region===r&&At(s.status)}catch{return!1}}),i=n.length===1?n[0]:void 0;return i?{buildEnv:e,region:i}:void 0}function At(t){return t==="authorizing"||t==="authenticated"||t==="refreshing"||t==="scope_upgrade_required"||t==="expired"}function St(t){return t==="cn"||t==="en"?t:void 0}export{c as a,J as b,nt as c,j as d,Mt as e,U as f,le as g,G as h,dt as i,ht as j,z as k,zn as l,jn as m,Wn as n,_t as o,Zn as p,Qn as q};
|