@mycadet/assistant 0.12.10 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/node_modules/@mycadet/ces-client/node_modules/@mycadet/service-contracts/src/__tests__/ingress.test.ts +10 -10
- package/node_modules/@mycadet/ces-client/node_modules/@mycadet/service-contracts/src/ingress.ts +3 -3
- package/node_modules/@mycadet/ces-client/src/http-credentials.ts +18 -1
- package/node_modules/@mycadet/gateway-client/node_modules/@mycadet/service-contracts/src/__tests__/ingress.test.ts +10 -10
- package/node_modules/@mycadet/gateway-client/node_modules/@mycadet/service-contracts/src/ingress.ts +3 -3
- package/node_modules/@mycadet/gateway-client/src/gateway-ipc-contracts.ts +0 -20
- package/node_modules/@mycadet/service-contracts/src/__tests__/ingress.test.ts +10 -10
- package/node_modules/@mycadet/service-contracts/src/ingress.ts +3 -3
- package/openapi.yaml +2 -708
- package/package.json +2 -3
- package/scripts/sync-web-search-catalog.ts +1 -2
- package/src/__tests__/cloud-profile-guard.test.ts +41 -5
- package/src/__tests__/config-schema.test.ts +6 -38
- package/src/__tests__/conversation-queue.test.ts +45 -6
- package/src/__tests__/db-readiness-http-gate.test.ts +0 -6
- package/src/__tests__/persist-onboarding-artifacts.test.ts +0 -1
- package/src/__tests__/persona-resolver.test.ts +0 -51
- package/src/__tests__/provider-cloud-proxy-integration.test.ts +2 -110
- package/src/__tests__/run-due-schedules.test.ts +0 -4
- package/src/__tests__/schedule-store.test.ts +0 -12
- package/src/__tests__/stt-stream-session.test.ts +4 -4
- package/src/__tests__/telephony-tts-guard.test.ts +2 -50
- package/src/__tests__/voice-config-update.test.ts +12 -167
- package/src/__tests__/web-search-catalog-parity.test.ts +0 -2
- package/src/__tests__/workspace-migration-130-speech-mode-to-provider.test.ts +9 -7
- package/src/__tests__/workspace-migration-132-web-search-mode-to-provider.test.ts +6 -6
- package/src/calls/__tests__/voice-session-bridge.test.ts +1 -4
- package/src/calls/resolve-call-tts-provider.ts +6 -25
- package/src/calls/telephony-credential-preflight.ts +0 -10
- package/src/calls/telephony-tts-capability.ts +1 -17
- package/src/cli/commands/tts.ts +1 -2
- package/src/cli/index.help.ts +0 -2
- package/src/cli/program.ts +0 -2
- package/src/config/bundled-skills/settings/tools/voice-config-update.ts +4 -42
- package/src/config/schemas/__tests__/stt.test.ts +10 -14
- package/src/config/schemas/llm.ts +3 -5
- package/src/config/schemas/services.ts +5 -6
- package/src/config/schemas/stt.ts +1 -3
- package/src/config/schemas/tts.ts +1 -30
- package/src/daemon/daemon-readiness.ts +4 -29
- package/src/daemon/lifecycle.ts +0 -31
- package/src/daemon/providers-setup.ts +0 -8
- package/src/heartbeat/__tests__/heartbeat-service.test.ts +0 -1
- package/src/heartbeat/heartbeat-service.ts +1 -66
- package/src/ipc/__tests__/db-readiness-ipc-gate.test.ts +1 -9
- package/src/live-voice/__tests__/live-voice-credential-preflight.test.ts +0 -44
- package/src/live-voice/__tests__/live-voice-flux-turn-end.test.ts +4 -6
- package/src/live-voice/__tests__/live-voice-stt.test.ts +1 -1
- package/src/live-voice/live-voice-credential-preflight.ts +9 -33
- package/src/live-voice/live-voice-session.ts +10 -6
- package/src/live-voice/live-voice-tts.ts +1 -8
- package/src/plugins/defaults/memory/worker.ts +3 -3
- package/src/prompts/persona-resolver.ts +0 -35
- package/src/providers/__tests__/search-provider-catalog.test.ts +5 -8
- package/src/providers/__tests__/voice-error-copy.test.ts +9 -10
- package/src/providers/search-provider-catalog.ts +7 -39
- package/src/providers/speech-to-text/__tests__/provider-catalog.test.ts +3 -47
- package/src/providers/speech-to-text/__tests__/resolve.test.ts +6 -372
- package/src/providers/speech-to-text/provider-catalog.ts +2 -73
- package/src/providers/speech-to-text/resolve.ts +3 -120
- package/src/runtime/http-router-types.ts +1 -3
- package/src/runtime/http-server.ts +1 -1
- package/src/runtime/routes/__tests__/conversation-query-routes.test.ts +13 -11
- package/src/runtime/routes/__tests__/tts-routes.test.ts +2 -6
- package/src/runtime/routes/conversation-query-routes.ts +0 -96
- package/src/runtime/routes/inbound-stages/transcribe-audio.test.ts +7 -7
- package/src/runtime/routes/index.ts +0 -4
- package/src/runtime/routes/live-voice-routes.test.ts +4 -11
- package/src/runtime/routes/live-voice-routes.ts +8 -11
- package/src/runtime/routes/secret-routes.ts +0 -6
- package/src/runtime/routes/tts-routes.ts +0 -38
- package/src/schedule/__tests__/plugin-schedule-reconciler.test.ts +1 -7
- package/src/schedule/__tests__/worker-mcp-readiness.test.ts +0 -4
- package/src/schedule/schedule-store.ts +0 -7
- package/src/schedule/scheduler.ts +0 -5
- package/src/schedule/worker.ts +1 -1
- package/src/stt/__tests__/daemon-batch-transcriber.test.ts +2 -10
- package/src/stt/daemon-batch-transcriber.ts +4 -38
- package/src/stt/types.ts +1 -9
- package/src/tools/network/__tests__/web-search.test.ts +3 -250
- package/src/tools/network/web-search.ts +4 -165
- package/src/tts/__tests__/provider-resolution.test.ts +0 -5
- package/src/tts/provider-catalog.ts +0 -4
- package/src/tts/types.ts +0 -1
- package/src/__tests__/cloud-speech-defaults.test.ts +0 -330
- package/src/__tests__/migration-cross-version-compatibility.test.ts +0 -1708
- package/src/__tests__/migration-export-http.test.ts +0 -557
- package/src/__tests__/migration-export-streaming.test.ts +0 -350
- package/src/__tests__/migration-export-to-gcs.test.ts +0 -706
- package/src/__tests__/migration-import-commit-http.test.ts +0 -1176
- package/src/__tests__/migration-import-from-gcs.test.ts +0 -534
- package/src/__tests__/migration-import-from-path.test.ts +0 -324
- package/src/__tests__/migration-import-from-url.test.ts +0 -588
- package/src/__tests__/migration-import-preflight-http.test.ts +0 -739
- package/src/__tests__/migration-jobs-status.test.ts +0 -139
- package/src/__tests__/migration-parity-persistence.test.ts +0 -1891
- package/src/__tests__/migration-transport.test.ts +0 -1089
- package/src/__tests__/migration-validate-http.test.ts +0 -634
- package/src/__tests__/migration-wizard.test.ts +0 -1395
- package/src/__tests__/rebind-secrets-screen.test.ts +0 -876
- package/src/__tests__/sanitize-config-for-transfer.test.ts +0 -259
- package/src/__tests__/transfer-progress-screen.test.ts +0 -1217
- package/src/__tests__/validation-results-screen.test.ts +0 -1130
- package/src/__tests__/vbundle-pax-and-symlink.test.ts +0 -147
- package/src/background-wake/background-wake-routes.test.ts +0 -906
- package/src/background-wake/cloud-client.test.ts +0 -328
- package/src/background-wake/cloud-client.ts +0 -196
- package/src/background-wake/next-wake.test.ts +0 -335
- package/src/background-wake/next-wake.ts +0 -188
- package/src/background-wake/publisher.ts +0 -93
- package/src/background-wake/wake-intent-hooks.test.ts +0 -234
- package/src/cli/commands/__tests__/backup.test.ts +0 -363
- package/src/cli/commands/backup.help.ts +0 -180
- package/src/cli/commands/backup.ts +0 -398
- package/src/cloud/cloud-speech.test.ts +0 -335
- package/src/cloud/cloud-speech.ts +0 -300
- package/src/config/cloud-speech-defaults.ts +0 -300
- package/src/config/sanitize-for-transfer.ts +0 -111
- package/src/live-voice/__tests__/live-voice-cloud-speech-fallback.test.ts +0 -250
- package/src/providers/speech-to-text/__tests__/cadet-cloud-realtime.test.ts +0 -457
- package/src/providers/speech-to-text/__tests__/cadet-cloud.test.ts +0 -271
- package/src/providers/speech-to-text/__tests__/cadet-speech-relay-connection.test.ts +0 -126
- package/src/providers/speech-to-text/cadet-cloud-flux-realtime.ts +0 -309
- package/src/providers/speech-to-text/cadet-cloud-realtime.ts +0 -315
- package/src/providers/speech-to-text/cadet-cloud.ts +0 -108
- package/src/providers/speech-to-text/cadet-speech-relay-connection.ts +0 -176
- package/src/runtime/migrations/__tests__/gcs-signed-url.test.ts +0 -254
- package/src/runtime/migrations/__tests__/job-registry.test.ts +0 -346
- package/src/runtime/migrations/__tests__/origin-mode.test.ts +0 -62
- package/src/runtime/migrations/__tests__/rebind-secrets-credentials.test.ts +0 -184
- package/src/runtime/migrations/__tests__/staged-import-path.test.ts +0 -110
- package/src/runtime/migrations/__tests__/v1-test-helpers.ts +0 -112
- package/src/runtime/migrations/__tests__/vbundle-builder-credentials.test.ts +0 -285
- package/src/runtime/migrations/__tests__/vbundle-builder-fd-leak.test.ts +0 -126
- package/src/runtime/migrations/__tests__/vbundle-builder-v1-shape.test.ts +0 -253
- package/src/runtime/migrations/__tests__/vbundle-import-credentials.test.ts +0 -208
- package/src/runtime/migrations/__tests__/vbundle-import-parity.test.ts +0 -485
- package/src/runtime/migrations/__tests__/vbundle-import-policy.test.ts +0 -349
- package/src/runtime/migrations/__tests__/vbundle-import-version-compat.test.ts +0 -196
- package/src/runtime/migrations/__tests__/vbundle-legacy-user-md.test.ts +0 -551
- package/src/runtime/migrations/__tests__/vbundle-metadata-merge-integration.test.ts +0 -428
- package/src/runtime/migrations/__tests__/vbundle-metadata-merge.test.ts +0 -220
- package/src/runtime/migrations/__tests__/vbundle-streaming-importer.test.ts +0 -1823
- package/src/runtime/migrations/__tests__/vbundle-streaming-validator.test.ts +0 -598
- package/src/runtime/migrations/__tests__/vbundle-symlink-importer.test.ts +0 -463
- package/src/runtime/migrations/__tests__/vbundle-symlink-streaming-importer.test.ts +0 -538
- package/src/runtime/migrations/__tests__/vbundle-symlink-streaming.test.ts +0 -515
- package/src/runtime/migrations/__tests__/vbundle-symlink-tar.test.ts +0 -453
- package/src/runtime/migrations/__tests__/vbundle-symlink-walker.test.ts +0 -319
- package/src/runtime/migrations/__tests__/vbundle-tar-stream.test.ts +0 -240
- package/src/runtime/migrations/__tests__/vbundle-validator-v1-schema.test.ts +0 -473
- package/src/runtime/migrations/gcs-signed-url.ts +0 -190
- package/src/runtime/migrations/job-registry.ts +0 -297
- package/src/runtime/migrations/migration-transport.ts +0 -612
- package/src/runtime/migrations/migration-wizard.ts +0 -747
- package/src/runtime/migrations/origin-mode.ts +0 -42
- package/src/runtime/migrations/rebind-secrets-screen.ts +0 -412
- package/src/runtime/migrations/staged-import-path.ts +0 -116
- package/src/runtime/migrations/transfer-progress-screen.ts +0 -323
- package/src/runtime/migrations/validation-results-screen.ts +0 -469
- package/src/runtime/migrations/vbundle-builder.ts +0 -1382
- package/src/runtime/migrations/vbundle-import-analyzer.ts +0 -405
- package/src/runtime/migrations/vbundle-import-policy.ts +0 -241
- package/src/runtime/migrations/vbundle-importer.ts +0 -826
- package/src/runtime/migrations/vbundle-metadata-merge.ts +0 -113
- package/src/runtime/migrations/vbundle-streaming-importer.ts +0 -2844
- package/src/runtime/migrations/vbundle-streaming-validator.ts +0 -426
- package/src/runtime/migrations/vbundle-tar-stream.ts +0 -244
- package/src/runtime/migrations/vbundle-validator.ts +0 -724
- package/src/runtime/routes/__tests__/migration-cadet-metadata-reconcile.test.ts +0 -227
- package/src/runtime/routes/__tests__/migration-export-secrets-redacted.test.ts +0 -54
- package/src/runtime/routes/__tests__/migration-import-allowed-hosts-env.test.ts +0 -70
- package/src/runtime/routes/__tests__/migration-import-credential-filter.test.ts +0 -257
- package/src/runtime/routes/background-wake-routes.ts +0 -387
- package/src/runtime/routes/migration-routes.ts +0 -2584
- package/src/tools/network/__tests__/cloud-search-proxy.test.ts +0 -282
- package/src/tools/network/cloud-search-proxy.ts +0 -211
- package/src/tts/__tests__/cadet-provider.test.ts +0 -253
- package/src/tts/providers/cadet-provider.ts +0 -244
- package/src/types/tar-stream.d.ts +0 -66
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Origin-mode derivation for vbundle exports.
|
|
3
|
-
*
|
|
4
|
-
* The vbundle manifest v1 schema's `origin.mode` enum captures the deployment
|
|
5
|
-
* shape that produced the bundle. The runtime's two underlying signals are:
|
|
6
|
-
*
|
|
7
|
-
* - `getIsCloud()` — true when the daemon runs as a cloud-managed
|
|
8
|
-
* deployment (`IS_CLOUD`, set only on cloud pods).
|
|
9
|
-
* - `getIsContainerized()` — true when the daemon runs inside a container
|
|
10
|
-
* (`IS_CONTAINERIZED`), identifying where the daemon process is running.
|
|
11
|
-
*
|
|
12
|
-
* Deliberately NOT keyed on cloud-proxy prerequisites: any logged-in
|
|
13
|
-
* local assistant holds a cloud URL and `assistant_api_key` (to use the
|
|
14
|
-
* platform LLM proxy), so proxy-prereq presence does not distinguish a
|
|
15
|
-
* managed deployment from a local one. Stamping a local export as
|
|
16
|
-
* "managed" would trip the importer's `secrets_redacted must be true when
|
|
17
|
-
* origin.mode is 'managed'` rule and break local→platform teleport for
|
|
18
|
-
* every logged-in local assistant.
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
import { getIsCloud, getIsContainerized } from "../../config/env-registry.js";
|
|
22
|
-
|
|
23
|
-
export type VBundleOriginMode =
|
|
24
|
-
| "managed"
|
|
25
|
-
| "self-hosted-remote"
|
|
26
|
-
| "self-hosted-local";
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Returns the origin mode for the current daemon.
|
|
30
|
-
*
|
|
31
|
-
* Platform-managed deployments win first; otherwise containerized →
|
|
32
|
-
* "self-hosted-remote", bare-metal → "self-hosted-local".
|
|
33
|
-
*/
|
|
34
|
-
export async function getOriginMode(): Promise<VBundleOriginMode> {
|
|
35
|
-
if (getIsCloud()) {
|
|
36
|
-
return "managed";
|
|
37
|
-
}
|
|
38
|
-
if (getIsContainerized()) {
|
|
39
|
-
return "self-hosted-remote";
|
|
40
|
-
}
|
|
41
|
-
return "self-hosted-local";
|
|
42
|
-
}
|
|
@@ -1,412 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Rebind secrets screen -- view model for the rebind-secrets step.
|
|
3
|
-
*
|
|
4
|
-
* Derives display state from the migration wizard state machine for rendering
|
|
5
|
-
* a post-migration task checklist UI. Usable from macOS/iOS web views, CLI,
|
|
6
|
-
* or any TypeScript consumer.
|
|
7
|
-
*
|
|
8
|
-
* After a successful transfer, secrets (API keys, tokens) are redacted in
|
|
9
|
-
* exported bundles and communication channels (Slack, Telegram, etc.) need
|
|
10
|
-
* to be re-bound to the new instance. This screen presents a checklist of
|
|
11
|
-
* tasks the operator must complete before the migration is considered done.
|
|
12
|
-
*
|
|
13
|
-
* View model states:
|
|
14
|
-
* - disabled: step is not yet accessible (earlier steps incomplete)
|
|
15
|
-
* - active: checklist is displayed with tasks to complete
|
|
16
|
-
* - complete: all required tasks are done, migration can be finalized
|
|
17
|
-
*
|
|
18
|
-
* Task categories:
|
|
19
|
-
* - re-enter-secrets: Re-enter API keys/secrets (redacted in bundles)
|
|
20
|
-
* - rebind-channels: Re-bind communication channels (Slack, Telegram, etc.)
|
|
21
|
-
* - reconfigure-auth: Re-configure identity/auth settings
|
|
22
|
-
* - verify-webhooks: Verify webhook URLs point to new instance
|
|
23
|
-
*
|
|
24
|
-
* Operator notes:
|
|
25
|
-
* Setup: Ensure the destination instance is running and reachable before
|
|
26
|
-
* starting the checklist. Secrets must be re-entered manually since
|
|
27
|
-
* they are never included in export bundles.
|
|
28
|
-
* Rollback: If a task cannot be completed, navigate back to transfer
|
|
29
|
-
* to re-import the bundle or start a new migration.
|
|
30
|
-
* Expected signals: Each task toggles between pending/complete. The
|
|
31
|
-
* "Complete Migration" action is only available when all required
|
|
32
|
-
* tasks are marked complete.
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
import type { MigrationWizardState } from "./migration-wizard.js";
|
|
36
|
-
import {
|
|
37
|
-
completeRebindSecrets,
|
|
38
|
-
goBackTo,
|
|
39
|
-
isStepAccessible,
|
|
40
|
-
} from "./migration-wizard.js";
|
|
41
|
-
|
|
42
|
-
// ---------------------------------------------------------------------------
|
|
43
|
-
// View model types
|
|
44
|
-
// ---------------------------------------------------------------------------
|
|
45
|
-
|
|
46
|
-
/** Unique identifier for each rebind task. */
|
|
47
|
-
export type RebindTaskId =
|
|
48
|
-
| "re-enter-secrets"
|
|
49
|
-
| "rebind-channels"
|
|
50
|
-
| "reconfigure-auth"
|
|
51
|
-
| "verify-webhooks";
|
|
52
|
-
|
|
53
|
-
/** Status of an individual checklist task. */
|
|
54
|
-
export type RebindTaskStatus = "pending" | "complete";
|
|
55
|
-
|
|
56
|
-
/** A single task in the rebind checklist. */
|
|
57
|
-
export interface RebindTask {
|
|
58
|
-
id: RebindTaskId;
|
|
59
|
-
title: string;
|
|
60
|
-
description: string;
|
|
61
|
-
status: RebindTaskStatus;
|
|
62
|
-
required: boolean;
|
|
63
|
-
helpText?: string;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/** Snapshot of which tasks have been marked complete. */
|
|
67
|
-
export type RebindTaskCompletionState = Record<RebindTaskId, boolean>;
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Discriminated union representing the current display state of the
|
|
71
|
-
* rebind secrets screen.
|
|
72
|
-
*/
|
|
73
|
-
export type RebindSecretsScreenState =
|
|
74
|
-
| { phase: "disabled" }
|
|
75
|
-
| {
|
|
76
|
-
phase: "active";
|
|
77
|
-
tasks: RebindTask[];
|
|
78
|
-
allRequiredComplete: boolean;
|
|
79
|
-
completedCount: number;
|
|
80
|
-
totalCount: number;
|
|
81
|
-
requiredCount: number;
|
|
82
|
-
requiredCompletedCount: number;
|
|
83
|
-
}
|
|
84
|
-
| {
|
|
85
|
-
phase: "complete";
|
|
86
|
-
tasks: RebindTask[];
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
// ---------------------------------------------------------------------------
|
|
90
|
-
// Task definitions
|
|
91
|
-
// ---------------------------------------------------------------------------
|
|
92
|
-
|
|
93
|
-
interface TaskDefinition {
|
|
94
|
-
id: RebindTaskId;
|
|
95
|
-
title: string;
|
|
96
|
-
description: string;
|
|
97
|
-
required: boolean;
|
|
98
|
-
helpText?: string;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const TASK_DEFINITIONS: readonly TaskDefinition[] = [
|
|
102
|
-
{
|
|
103
|
-
id: "re-enter-secrets",
|
|
104
|
-
title: "Re-enter API keys and secrets",
|
|
105
|
-
description:
|
|
106
|
-
"Secrets are redacted in export bundles for security. Re-enter all API keys, tokens, and credentials in the destination instance.",
|
|
107
|
-
required: true,
|
|
108
|
-
helpText:
|
|
109
|
-
"Navigate to Settings > Models & Services to re-enter provider API keys (e.g., Anthropic, OpenAI). Check Settings > Models & Services for any custom secrets used by skills.",
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
id: "rebind-channels",
|
|
113
|
-
title: "Re-bind communication channels",
|
|
114
|
-
description:
|
|
115
|
-
"Communication channel bindings (Slack, Telegram, etc.) are instance-specific. Re-configure each channel to point to the new instance.",
|
|
116
|
-
required: true,
|
|
117
|
-
helpText:
|
|
118
|
-
"For Slack: re-install the Slack app in your workspace. For Telegram: update the bot webhook URL.",
|
|
119
|
-
},
|
|
120
|
-
{
|
|
121
|
-
id: "reconfigure-auth",
|
|
122
|
-
title: "Re-configure identity and auth settings",
|
|
123
|
-
description:
|
|
124
|
-
"Authentication settings, OAuth tokens, and identity provider configurations may need to be re-established on the new instance.",
|
|
125
|
-
required: true,
|
|
126
|
-
helpText:
|
|
127
|
-
"Check guardian settings, OAuth app registrations, and any SSO configurations. Re-authorize connected services if needed.",
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
id: "verify-webhooks",
|
|
131
|
-
title: "Verify webhook URLs",
|
|
132
|
-
description:
|
|
133
|
-
"Ensure all webhook URLs registered with external services point to the new instance's public ingress URL.",
|
|
134
|
-
required: false,
|
|
135
|
-
helpText:
|
|
136
|
-
"Review the public ingress URL in Settings > Developer. Update any external services (GitHub, calendar providers, etc.) that send webhooks to this assistant.",
|
|
137
|
-
},
|
|
138
|
-
] as const;
|
|
139
|
-
|
|
140
|
-
// ---------------------------------------------------------------------------
|
|
141
|
-
// Task completion state management
|
|
142
|
-
// ---------------------------------------------------------------------------
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Create a fresh task completion state with all tasks pending.
|
|
146
|
-
*/
|
|
147
|
-
export function createTaskCompletionState(): RebindTaskCompletionState {
|
|
148
|
-
const state = {} as RebindTaskCompletionState;
|
|
149
|
-
for (const def of TASK_DEFINITIONS) {
|
|
150
|
-
state[def.id] = false;
|
|
151
|
-
}
|
|
152
|
-
return state;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Toggle a task's completion status.
|
|
157
|
-
*
|
|
158
|
-
* Returns a new state object (immutable update).
|
|
159
|
-
*/
|
|
160
|
-
export function toggleTaskCompletion(
|
|
161
|
-
state: RebindTaskCompletionState,
|
|
162
|
-
taskId: RebindTaskId,
|
|
163
|
-
): RebindTaskCompletionState {
|
|
164
|
-
return { ...state, [taskId]: !state[taskId] };
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Mark a specific task as complete.
|
|
169
|
-
*
|
|
170
|
-
* Returns a new state object (immutable update).
|
|
171
|
-
*/
|
|
172
|
-
export function markTaskComplete(
|
|
173
|
-
state: RebindTaskCompletionState,
|
|
174
|
-
taskId: RebindTaskId,
|
|
175
|
-
): RebindTaskCompletionState {
|
|
176
|
-
return { ...state, [taskId]: true };
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Mark a specific task as pending (incomplete).
|
|
181
|
-
*
|
|
182
|
-
* Returns a new state object (immutable update).
|
|
183
|
-
*/
|
|
184
|
-
export function markTaskPending(
|
|
185
|
-
state: RebindTaskCompletionState,
|
|
186
|
-
taskId: RebindTaskId,
|
|
187
|
-
): RebindTaskCompletionState {
|
|
188
|
-
return { ...state, [taskId]: false };
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
// ---------------------------------------------------------------------------
|
|
192
|
-
// State derivation
|
|
193
|
-
// ---------------------------------------------------------------------------
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Build the task list from definitions and completion state.
|
|
197
|
-
*
|
|
198
|
-
* When credential import results are provided:
|
|
199
|
-
* - If all credentials were imported successfully, the re-enter-secrets task
|
|
200
|
-
* is marked as auto-completed with an updated description.
|
|
201
|
-
* - If some credentials failed, the description is updated to list only the
|
|
202
|
-
* failed credentials that need manual re-entry.
|
|
203
|
-
* - If no credentials were in the bundle (legacy), the original behavior is kept.
|
|
204
|
-
*/
|
|
205
|
-
function buildTasks(
|
|
206
|
-
completionState: RebindTaskCompletionState,
|
|
207
|
-
credentialsImported?: MigrationWizardState["credentialsImported"],
|
|
208
|
-
): RebindTask[] {
|
|
209
|
-
return TASK_DEFINITIONS.map((def) => {
|
|
210
|
-
// Apply credential import awareness to the re-enter-secrets task
|
|
211
|
-
if (def.id === "re-enter-secrets" && credentialsImported) {
|
|
212
|
-
if (credentialsImported.failed === 0 && credentialsImported.total > 0) {
|
|
213
|
-
// All credentials imported successfully — auto-complete this task
|
|
214
|
-
return {
|
|
215
|
-
id: def.id,
|
|
216
|
-
title: "API keys and secrets transferred",
|
|
217
|
-
description: `All ${credentialsImported.total} credential(s) were automatically imported from the bundle. No manual re-entry needed.`,
|
|
218
|
-
status: "complete" as const,
|
|
219
|
-
required: def.required,
|
|
220
|
-
helpText:
|
|
221
|
-
"Credentials were securely transferred as part of the migration bundle. You can verify them in Settings > Models & Services.",
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
if (credentialsImported.failed > 0) {
|
|
226
|
-
// Partial failure — show only the failed credentials
|
|
227
|
-
const failedList = credentialsImported.failedAccounts
|
|
228
|
-
.map((a) => `"${a}"`)
|
|
229
|
-
.join(", ");
|
|
230
|
-
return {
|
|
231
|
-
id: def.id,
|
|
232
|
-
title: "Re-enter failed credentials",
|
|
233
|
-
description: `${credentialsImported.succeeded} of ${credentialsImported.total} credential(s) were imported automatically. The following failed and need manual re-entry: ${failedList}.`,
|
|
234
|
-
status: completionState[def.id]
|
|
235
|
-
? ("complete" as const)
|
|
236
|
-
: ("pending" as const),
|
|
237
|
-
required: def.required,
|
|
238
|
-
helpText: `Navigate to Settings > Models & Services to re-enter the failed credential(s): ${failedList}.`,
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
return {
|
|
244
|
-
id: def.id,
|
|
245
|
-
title: def.title,
|
|
246
|
-
description: def.description,
|
|
247
|
-
status: completionState[def.id]
|
|
248
|
-
? ("complete" as const)
|
|
249
|
-
: ("pending" as const),
|
|
250
|
-
required: def.required,
|
|
251
|
-
...(def.helpText !== undefined ? { helpText: def.helpText } : {}),
|
|
252
|
-
};
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* Check whether all required tasks are complete.
|
|
258
|
-
*/
|
|
259
|
-
export function areAllRequiredTasksComplete(
|
|
260
|
-
completionState: RebindTaskCompletionState,
|
|
261
|
-
): boolean {
|
|
262
|
-
return TASK_DEFINITIONS.filter((d) => d.required).every(
|
|
263
|
-
(d) => completionState[d.id],
|
|
264
|
-
);
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
* Derive the current rebind secrets screen state from the wizard state
|
|
269
|
-
* and the local task completion state.
|
|
270
|
-
*
|
|
271
|
-
* This is a pure function -- no side effects. Call it whenever the wizard
|
|
272
|
-
* state or task completion state changes to get the latest display state.
|
|
273
|
-
*
|
|
274
|
-
* The `completionState` parameter tracks which tasks the operator has
|
|
275
|
-
* marked complete. It is managed separately from the wizard state because
|
|
276
|
-
* individual task toggles are a UI concern, not a wizard transition.
|
|
277
|
-
*/
|
|
278
|
-
export function deriveRebindSecretsScreenState(
|
|
279
|
-
wizardState: MigrationWizardState,
|
|
280
|
-
completionState: RebindTaskCompletionState,
|
|
281
|
-
): RebindSecretsScreenState {
|
|
282
|
-
const rebindStep = wizardState.steps["rebind-secrets"];
|
|
283
|
-
const credInfo = wizardState.credentialsImported;
|
|
284
|
-
|
|
285
|
-
// Not yet accessible -- earlier steps incomplete
|
|
286
|
-
if (
|
|
287
|
-
wizardState.currentStep !== "rebind-secrets" &&
|
|
288
|
-
rebindStep.status !== "success"
|
|
289
|
-
) {
|
|
290
|
-
if (!isStepAccessible(wizardState, "rebind-secrets")) {
|
|
291
|
-
return { phase: "disabled" };
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
// Apply credential-aware completion state: if all credentials imported
|
|
296
|
-
// successfully, treat re-enter-secrets as auto-completed.
|
|
297
|
-
let effectiveCompletion = completionState;
|
|
298
|
-
if (credInfo && credInfo.total > 0 && credInfo.failed === 0) {
|
|
299
|
-
effectiveCompletion = markTaskComplete(completionState, "re-enter-secrets");
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
// Already completed (viewing from a later step or after completion)
|
|
303
|
-
if (rebindStep.status === "success") {
|
|
304
|
-
const tasks = buildTasks(effectiveCompletion, credInfo);
|
|
305
|
-
return { phase: "complete", tasks };
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
// Active -- show the checklist
|
|
309
|
-
if (wizardState.currentStep === "rebind-secrets") {
|
|
310
|
-
const tasks = buildTasks(effectiveCompletion, credInfo);
|
|
311
|
-
const requiredTasks = tasks.filter((t) => t.required);
|
|
312
|
-
const completedTasks = tasks.filter((t) => t.status === "complete");
|
|
313
|
-
const requiredCompletedTasks = requiredTasks.filter(
|
|
314
|
-
(t) => t.status === "complete",
|
|
315
|
-
);
|
|
316
|
-
|
|
317
|
-
return {
|
|
318
|
-
phase: "active",
|
|
319
|
-
tasks,
|
|
320
|
-
allRequiredComplete: areAllRequiredTasksComplete(effectiveCompletion),
|
|
321
|
-
completedCount: completedTasks.length,
|
|
322
|
-
totalCount: tasks.length,
|
|
323
|
-
requiredCount: requiredTasks.length,
|
|
324
|
-
requiredCompletedCount: requiredCompletedTasks.length,
|
|
325
|
-
};
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
return { phase: "disabled" };
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
// ---------------------------------------------------------------------------
|
|
332
|
-
// Actions -- delegate to wizard state machine
|
|
333
|
-
// ---------------------------------------------------------------------------
|
|
334
|
-
|
|
335
|
-
/**
|
|
336
|
-
* Complete the rebind-secrets step and advance to the complete step.
|
|
337
|
-
*
|
|
338
|
-
* This should only be called when all required tasks are marked complete.
|
|
339
|
-
* Throws if called when required tasks are incomplete.
|
|
340
|
-
*/
|
|
341
|
-
export function completeMigration(
|
|
342
|
-
wizardState: MigrationWizardState,
|
|
343
|
-
completionState: RebindTaskCompletionState,
|
|
344
|
-
): MigrationWizardState {
|
|
345
|
-
// Apply credential-aware effective completion: if all credentials were
|
|
346
|
-
// imported successfully, treat re-enter-secrets as auto-completed
|
|
347
|
-
// (mirrors the logic in deriveRebindSecretsScreenState).
|
|
348
|
-
let effectiveCompletion = completionState;
|
|
349
|
-
const credInfo = wizardState?.credentialsImported;
|
|
350
|
-
if (credInfo && credInfo.total > 0 && credInfo.failed === 0) {
|
|
351
|
-
effectiveCompletion = { ...completionState, "re-enter-secrets": true };
|
|
352
|
-
}
|
|
353
|
-
if (!areAllRequiredTasksComplete(effectiveCompletion)) {
|
|
354
|
-
throw new Error(
|
|
355
|
-
"Cannot complete migration: not all required tasks are done",
|
|
356
|
-
);
|
|
357
|
-
}
|
|
358
|
-
return completeRebindSecrets(wizardState);
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
/**
|
|
362
|
-
* Navigate back to the transfer step and reset the rebind checklist.
|
|
363
|
-
*
|
|
364
|
-
* Returns both the rewound wizard state and a fresh completion state so
|
|
365
|
-
* callers clear stale task progress from a previous transfer attempt.
|
|
366
|
-
*/
|
|
367
|
-
export function goBackToTransfer(state: MigrationWizardState): {
|
|
368
|
-
wizardState: MigrationWizardState;
|
|
369
|
-
completionState: RebindTaskCompletionState;
|
|
370
|
-
} {
|
|
371
|
-
return {
|
|
372
|
-
wizardState: goBackTo(state, "transfer"),
|
|
373
|
-
completionState: createTaskCompletionState(),
|
|
374
|
-
};
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
// ---------------------------------------------------------------------------
|
|
378
|
-
// Query helpers
|
|
379
|
-
// ---------------------------------------------------------------------------
|
|
380
|
-
|
|
381
|
-
/**
|
|
382
|
-
* Check if the rebind secrets screen is accessible from the current state.
|
|
383
|
-
*/
|
|
384
|
-
export function isRebindSecretsScreenAccessible(
|
|
385
|
-
state: MigrationWizardState,
|
|
386
|
-
): boolean {
|
|
387
|
-
return (
|
|
388
|
-
isStepAccessible(state, "rebind-secrets") ||
|
|
389
|
-
state.currentStep === "rebind-secrets"
|
|
390
|
-
);
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
/**
|
|
394
|
-
* Get the list of all task IDs in display order.
|
|
395
|
-
*/
|
|
396
|
-
export function getTaskIds(): readonly RebindTaskId[] {
|
|
397
|
-
return TASK_DEFINITIONS.map((d) => d.id);
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
/**
|
|
401
|
-
* Get the count of required tasks.
|
|
402
|
-
*/
|
|
403
|
-
export function getRequiredTaskCount(): number {
|
|
404
|
-
return TASK_DEFINITIONS.filter((d) => d.required).length;
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
/**
|
|
408
|
-
* Get the count of total tasks.
|
|
409
|
-
*/
|
|
410
|
-
export function getTotalTaskCount(): number {
|
|
411
|
-
return TASK_DEFINITIONS.length;
|
|
412
|
-
}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Resolve a caller-supplied staged-bundle path for local restore.
|
|
3
|
-
*
|
|
4
|
-
* The daemon only opens files that realpath into
|
|
5
|
-
* `${workspaceDir}/.restore-staging/`. Absolute host paths, `..`
|
|
6
|
-
* traversal, and symlink escapes are rejected.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { existsSync, lstatSync, realpathSync, statSync } from "node:fs";
|
|
10
|
-
import { relative, resolve, sep } from "node:path";
|
|
11
|
-
|
|
12
|
-
export const RESTORE_STAGING_DIRNAME = ".restore-staging";
|
|
13
|
-
|
|
14
|
-
export type StagedImportPathErrorCode =
|
|
15
|
-
| "empty"
|
|
16
|
-
| "not_found"
|
|
17
|
-
| "not_file"
|
|
18
|
-
| "symlink"
|
|
19
|
-
| "outside"
|
|
20
|
-
| "extension";
|
|
21
|
-
|
|
22
|
-
export class StagedImportPathError extends Error {
|
|
23
|
-
public readonly code: StagedImportPathErrorCode;
|
|
24
|
-
|
|
25
|
-
constructor(code: StagedImportPathErrorCode, message: string) {
|
|
26
|
-
super(message);
|
|
27
|
-
this.name = "StagedImportPathError";
|
|
28
|
-
this.code = code;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Resolve `requestedPath` to a regular `.vbundle` file inside the
|
|
34
|
-
* workspace restore-staging directory.
|
|
35
|
-
*/
|
|
36
|
-
export function resolveStagedImportPath(
|
|
37
|
-
requestedPath: string,
|
|
38
|
-
workspaceDir: string,
|
|
39
|
-
): string {
|
|
40
|
-
if (typeof requestedPath !== "string" || requestedPath.trim().length === 0) {
|
|
41
|
-
throw new StagedImportPathError("empty", "Staged bundle path is empty");
|
|
42
|
-
}
|
|
43
|
-
if (requestedPath.includes("\0")) {
|
|
44
|
-
throw new StagedImportPathError(
|
|
45
|
-
"empty",
|
|
46
|
-
"Staged bundle path is not a valid file path",
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (!existsSync(workspaceDir)) {
|
|
51
|
-
throw new StagedImportPathError(
|
|
52
|
-
"not_found",
|
|
53
|
-
"Staged bundle file not found",
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const workspaceReal = realpathSync(workspaceDir);
|
|
58
|
-
const stagingRoot = resolve(workspaceReal, RESTORE_STAGING_DIRNAME);
|
|
59
|
-
const candidate = requestedPath.startsWith("/")
|
|
60
|
-
? resolve(requestedPath)
|
|
61
|
-
: resolve(workspaceReal, requestedPath);
|
|
62
|
-
|
|
63
|
-
if (!existsSync(candidate)) {
|
|
64
|
-
throw new StagedImportPathError(
|
|
65
|
-
"not_found",
|
|
66
|
-
"Staged bundle file not found",
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const linkStat = lstatSync(candidate);
|
|
71
|
-
if (linkStat.isSymbolicLink()) {
|
|
72
|
-
throw new StagedImportPathError(
|
|
73
|
-
"symlink",
|
|
74
|
-
"Staged bundle path must not be a symlink",
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const realFile = realpathSync(candidate);
|
|
79
|
-
if (!existsSync(stagingRoot)) {
|
|
80
|
-
throw new StagedImportPathError(
|
|
81
|
-
"outside",
|
|
82
|
-
"Staged bundle path is not inside the restore staging directory",
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const realStaging = realpathSync(stagingRoot);
|
|
87
|
-
const rel = relative(realStaging, realFile);
|
|
88
|
-
if (
|
|
89
|
-
rel === "" ||
|
|
90
|
-
rel.startsWith(`..${sep}`) ||
|
|
91
|
-
rel === ".." ||
|
|
92
|
-
rel.split(sep).includes("..")
|
|
93
|
-
) {
|
|
94
|
-
throw new StagedImportPathError(
|
|
95
|
-
"outside",
|
|
96
|
-
"Staged bundle path is not inside the restore staging directory",
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const fileStat = statSync(realFile);
|
|
101
|
-
if (!fileStat.isFile()) {
|
|
102
|
-
throw new StagedImportPathError(
|
|
103
|
-
"not_file",
|
|
104
|
-
"Staged bundle path is not a file",
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
if (!realFile.endsWith(".vbundle")) {
|
|
109
|
-
throw new StagedImportPathError(
|
|
110
|
-
"extension",
|
|
111
|
-
"Staged bundle must be a .vbundle file",
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
return realFile;
|
|
116
|
-
}
|