@seaveyon/harness-switch 0.31.0 → 0.32.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/dist/harness-switch.js +2756 -294
- package/package.json +1 -1
- package/public/assets/38.12ddaa3e.js +1 -0
- package/public/assets/main.2a32cf81.js +63 -0
- package/public/assets/main.729e43ad.css +2 -0
- package/public/index.html +1 -1
- package/public/assets/38.4f37f008.js +0 -1
- package/public/assets/main.2ceb3f63.js +0 -62
- package/public/assets/main.ffeca79a.css +0 -2
package/dist/harness-switch.js
CHANGED
|
@@ -8604,7 +8604,7 @@ var Hono2 = class extends Hono {
|
|
|
8604
8604
|
};
|
|
8605
8605
|
|
|
8606
8606
|
// src/http/assets.ts
|
|
8607
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
8607
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
8608
8608
|
import { extname, join, relative, resolve } from "node:path";
|
|
8609
8609
|
function registerAssetRoutes(app, publicDir) {
|
|
8610
8610
|
app.get("*", async (c, next) => {
|
|
@@ -8612,10 +8612,14 @@ function registerAssetRoutes(app, publicDir) {
|
|
|
8612
8612
|
return next();
|
|
8613
8613
|
}
|
|
8614
8614
|
const assetPath = resolve(publicDir, c.req.path.replace(/^\//, ""));
|
|
8615
|
-
if (c.req.path !== "/" && isPublicAsset(publicDir, assetPath) && existsSync(assetPath)) {
|
|
8615
|
+
if (c.req.path !== "/" && isPublicAsset(publicDir, assetPath) && existsSync(assetPath) && statSync(assetPath).isFile()) {
|
|
8616
8616
|
c.header("Content-Type", contentType(assetPath));
|
|
8617
8617
|
return c.body(readFileSync(assetPath));
|
|
8618
8618
|
}
|
|
8619
|
+
if (c.req.path.startsWith("/assets/") || extname(c.req.path)) {
|
|
8620
|
+
c.header("Cache-Control", "no-store");
|
|
8621
|
+
return c.notFound();
|
|
8622
|
+
}
|
|
8619
8623
|
const index = join(publicDir, "index.html");
|
|
8620
8624
|
if (existsSync(index)) {
|
|
8621
8625
|
c.header("Cache-Control", "no-store");
|
|
@@ -8649,6 +8653,29 @@ function contentType(path) {
|
|
|
8649
8653
|
|
|
8650
8654
|
// ../../packages/shared/src/errors.ts
|
|
8651
8655
|
var ERROR_CODES = {
|
|
8656
|
+
favoriteNotFound: "favoriteNotFound",
|
|
8657
|
+
favoriteRevisionRequired: "favoriteRevisionRequired",
|
|
8658
|
+
favoriteRevisionConflict: "favoriteRevisionConflict",
|
|
8659
|
+
favoriteInUse: "favoriteInUse",
|
|
8660
|
+
favoriteConnectionInUse: "favoriteConnectionInUse",
|
|
8661
|
+
favoriteEndpointMissing: "favoriteEndpointMissing",
|
|
8662
|
+
favoriteProtocolUnsupported: "favoriteProtocolUnsupported",
|
|
8663
|
+
favoriteProjectionUnsupported: "favoriteProjectionUnsupported",
|
|
8664
|
+
favoriteProfileDiverged: "favoriteProfileDiverged",
|
|
8665
|
+
favoriteRawOverrideConflict: "favoriteRawOverrideConflict",
|
|
8666
|
+
favoriteActiveUpdateRequiresApply: "favoriteActiveUpdateRequiresApply",
|
|
8667
|
+
favoritePlanStale: "favoritePlanStale",
|
|
8668
|
+
favoritePlanExpired: "favoritePlanExpired",
|
|
8669
|
+
favoriteIdempotencyConflict: "favoriteIdempotencyConflict",
|
|
8670
|
+
favoriteUndoConflict: "favoriteUndoConflict",
|
|
8671
|
+
favoritePreferenceNotRepresented: "favoritePreferenceNotRepresented",
|
|
8672
|
+
favoriteEffortUnverified: "favoriteEffortUnverified",
|
|
8673
|
+
favoriteStoreInvalid: "favoriteStoreInvalid",
|
|
8674
|
+
favoriteBackupInvalid: "favoriteBackupInvalid",
|
|
8675
|
+
favoriteBackupStale: "favoriteBackupStale",
|
|
8676
|
+
favoriteBackupRecoveryFailed: "favoriteBackupRecoveryFailed",
|
|
8677
|
+
favoriteLimitReached: "favoriteLimitReached",
|
|
8678
|
+
favoriteCredentialConsentRequired: "favoriteCredentialConsentRequired",
|
|
8652
8679
|
requestFailed: "http.requestFailed",
|
|
8653
8680
|
invalidRequest: "http.invalidRequest",
|
|
8654
8681
|
internalServerError: "http.internalServerError",
|
|
@@ -8805,12 +8832,14 @@ var USER_BLOCK_CODES = {
|
|
|
8805
8832
|
function catalogKey(code) {
|
|
8806
8833
|
return DIRECT_NAMESPACES.some((namespace) => code.startsWith(namespace)) ? code : `error.${code}`;
|
|
8807
8834
|
}
|
|
8808
|
-
var
|
|
8835
|
+
var FAVORITE_CODES = { result: "favorite.result" };
|
|
8836
|
+
var DIRECT_NAMESPACES = ["warning.", "doctor.check.", "scan.note.", "favorite."];
|
|
8809
8837
|
function isMessageCode(value) {
|
|
8810
8838
|
return typeof value === "string" && MESSAGE_CODES.has(value);
|
|
8811
8839
|
}
|
|
8812
8840
|
var MESSAGE_CODES = new Set([
|
|
8813
8841
|
ERROR_CODES,
|
|
8842
|
+
FAVORITE_CODES,
|
|
8814
8843
|
WARNING_CODES,
|
|
8815
8844
|
DOCTOR_CODES,
|
|
8816
8845
|
SCAN_NOTE_CODES,
|
|
@@ -9529,7 +9558,30 @@ var en_default = {
|
|
|
9529
9558
|
completionUnsupported: "The endpoint accepts none of the known completion protocols",
|
|
9530
9559
|
completionHttpError: "Model {{model}} returned HTTP {{status}} for a completion: the catalog lists it, but it cannot answer",
|
|
9531
9560
|
completionInvalid: "The completion response is not a recognized format, so the model cannot be confirmed to have answered"
|
|
9532
|
-
}
|
|
9561
|
+
},
|
|
9562
|
+
favoriteNotFound: "Favorite not found.",
|
|
9563
|
+
favoriteRevisionRequired: "Favorite revision required.",
|
|
9564
|
+
favoriteRevisionConflict: "Favorite revision conflict.",
|
|
9565
|
+
favoriteInUse: "Favorite in use.",
|
|
9566
|
+
favoriteConnectionInUse: "Favorite connection in use.",
|
|
9567
|
+
favoriteEndpointMissing: "Favorite endpoint missing.",
|
|
9568
|
+
favoriteProtocolUnsupported: "Favorite protocol unsupported.",
|
|
9569
|
+
favoriteProjectionUnsupported: "Favorite projection unsupported.",
|
|
9570
|
+
favoriteProfileDiverged: "Favorite profile diverged.",
|
|
9571
|
+
favoriteRawOverrideConflict: "Favorite raw override conflict.",
|
|
9572
|
+
favoriteActiveUpdateRequiresApply: "Favorite active update requires apply.",
|
|
9573
|
+
favoritePlanStale: "Favorite plan stale.",
|
|
9574
|
+
favoritePlanExpired: "Favorite plan expired.",
|
|
9575
|
+
favoriteIdempotencyConflict: "Favorite idempotency conflict.",
|
|
9576
|
+
favoriteUndoConflict: "Favorite undo conflict.",
|
|
9577
|
+
favoritePreferenceNotRepresented: "Confirm ignoring the reasoning preference this harness cannot express.",
|
|
9578
|
+
favoriteEffortUnverified: "The connection reasoning effort levels are unverified.",
|
|
9579
|
+
favoriteStoreInvalid: "Favorite store invalid.",
|
|
9580
|
+
favoriteLimitReached: "Favorite limit reached.",
|
|
9581
|
+
favoriteCredentialConsentRequired: "Favorite credential consent required.",
|
|
9582
|
+
favoriteBackupInvalid: "The backup is invalid, damaged or belongs to different configuration paths. Nothing was restored.",
|
|
9583
|
+
favoriteBackupRecoveryFailed: "Restore rollback is incomplete. Configuration operations are paused to protect data. Check file permissions and retry.",
|
|
9584
|
+
favoriteBackupStale: "Configuration changed after preview. Check the restore impact again."
|
|
9533
9585
|
},
|
|
9534
9586
|
warning: {
|
|
9535
9587
|
activation: {
|
|
@@ -9785,6 +9837,302 @@ var en_default = {
|
|
|
9785
9837
|
completionFailedCached: "cached {{at}}",
|
|
9786
9838
|
catalogHint: "Fetched {{count}} models; model fields can now use the dropdown.",
|
|
9787
9839
|
missingBaseUrl: "Add an endpoint URL before testing."
|
|
9840
|
+
},
|
|
9841
|
+
favorites: {
|
|
9842
|
+
linked: "Linked template",
|
|
9843
|
+
sourceMissing: "Template source is missing",
|
|
9844
|
+
connectionMissing: "Source connection is missing",
|
|
9845
|
+
importCount: "{{count}} templates",
|
|
9846
|
+
retryFailed: "Preview failed items again",
|
|
9847
|
+
saveFavorite: "Save template",
|
|
9848
|
+
authentication: "Authentication mode",
|
|
9849
|
+
liveState: "Native file state",
|
|
9850
|
+
preserved: "These existing fields keep their values; fixed model slots continue using their existing models",
|
|
9851
|
+
exportVersion: "Default exports use payload v2; the receiving version must support model favorites.",
|
|
9852
|
+
legacyExport: "Legacy export (omits favorites and source links)",
|
|
9853
|
+
catalog: "Fetch model catalog (no completion request)",
|
|
9854
|
+
catalogModel: "Choose a model ID from the catalog",
|
|
9855
|
+
noCatalog: "Catalog unavailable or empty; you can still enter a model ID.",
|
|
9856
|
+
title: "Templates",
|
|
9857
|
+
subtitle: "Save templates, choose connections, configure your tools.",
|
|
9858
|
+
add: "New template",
|
|
9859
|
+
edit: "Edit template",
|
|
9860
|
+
name: "Template name",
|
|
9861
|
+
notes: "Notes",
|
|
9862
|
+
save: "Save configuration only",
|
|
9863
|
+
delete: "Delete template",
|
|
9864
|
+
connections: "Connections",
|
|
9865
|
+
connection: "Select connection",
|
|
9866
|
+
label: "Connection label",
|
|
9867
|
+
endpoint: "Vault endpoint",
|
|
9868
|
+
protocol: "Protocol",
|
|
9869
|
+
model: "Exact request model ID",
|
|
9870
|
+
addConnection: "+ Add channel",
|
|
9871
|
+
removeConnection: "Remove connection",
|
|
9872
|
+
contextWindow: "Context window",
|
|
9873
|
+
maxOutputTokens: "Maximum output tokens",
|
|
9874
|
+
reasoningSupported: "Reasoning capability",
|
|
9875
|
+
reasoningEffort: "Preferred reasoning effort",
|
|
9876
|
+
supportedReasoningEfforts: "Supported reasoning efforts",
|
|
9877
|
+
effortsHint: "Comma-separated: none,minimal,low,medium,high,xhigh,max,ultra",
|
|
9878
|
+
unknown: "Unknown / unset",
|
|
9879
|
+
true: "Yes",
|
|
9880
|
+
false: "No",
|
|
9881
|
+
declared: "User-declared values; capabilities are not verified.",
|
|
9882
|
+
inherited: "Inherited from template",
|
|
9883
|
+
overridden: "Connection override; blank clears inheritance",
|
|
9884
|
+
inherit: "Inherit",
|
|
9885
|
+
invalid: "Check the name, connections and capability declarations.",
|
|
9886
|
+
configure: "Configure tools",
|
|
9887
|
+
saveOnlyHint: "Saving alone does not change native files. Choose activation to apply to a tool.",
|
|
9888
|
+
target: "Target profile",
|
|
9889
|
+
newProfile: "New profile",
|
|
9890
|
+
profileName: "Profile name (blank for automatic naming)",
|
|
9891
|
+
mode: "Operation",
|
|
9892
|
+
activate: "Save and activate",
|
|
9893
|
+
ignorePreference: "Ignore unsupported reasoning preference",
|
|
9894
|
+
overwriteDiverged: "Overwrite diverged controlled fields from template",
|
|
9895
|
+
preview: "Preview",
|
|
9896
|
+
appliedToast: "Applied the template to {{count}} tools.",
|
|
9897
|
+
confirm: "Apply reviewed plan",
|
|
9898
|
+
rendererDefault: "Renderer default",
|
|
9899
|
+
notRepresented: "Fields not represented",
|
|
9900
|
+
nativeFiles: "Native write targets",
|
|
9901
|
+
none: "None",
|
|
9902
|
+
applied: "Applied",
|
|
9903
|
+
unchanged: "Unchanged",
|
|
9904
|
+
failed: "Failed; preview again",
|
|
9905
|
+
skipped: "Skipped; preview again",
|
|
9906
|
+
capture: "Capture existing profile",
|
|
9907
|
+
extractCredential: "Store inline credential in the vault for reuse",
|
|
9908
|
+
linkSource: "Link the source profile",
|
|
9909
|
+
search: "Search names, models or connections",
|
|
9910
|
+
loading: "Loading favorites…",
|
|
9911
|
+
empty: "No favorites yet. Capture a profile or add one manually.",
|
|
9912
|
+
pending: "Not connected",
|
|
9913
|
+
generated: "Generated profiles",
|
|
9914
|
+
needsUpdate: "Update available",
|
|
9915
|
+
diverged: "Local divergence",
|
|
9916
|
+
detach: "Detach, keep profile",
|
|
9917
|
+
harnesses: "Harness profiles",
|
|
9918
|
+
autoName: "Use the model name when empty",
|
|
9919
|
+
modelAdvanced: "Advanced: capabilities, reasoning and notes",
|
|
9920
|
+
channelName: "Customize channel name",
|
|
9921
|
+
channelAdvanced: "Advanced: channel overrides",
|
|
9922
|
+
targetAdvanced: "Change target profile or name",
|
|
9923
|
+
changeDetails: "View parameter changes",
|
|
9924
|
+
fileDetails: "View native file changes",
|
|
9925
|
+
activateSelected: "Activate in selected tools after saving",
|
|
9926
|
+
noCompatibleChannel: "No compatible channel",
|
|
9927
|
+
updateProfile: "Update existing profile",
|
|
9928
|
+
backups: "Backup and restore",
|
|
9929
|
+
backupHint: "Back up this user’s favorites, profiles, credentials and native tool files. The last 20 automatic checkpoints before favorite changes and one manual checkpoint are kept, encrypted locally.",
|
|
9930
|
+
backupNow: "Back up current state",
|
|
9931
|
+
backupCreated: "Checkpoint created",
|
|
9932
|
+
backupRestored: "Restored. The previous state was also backed up, so you can revert this restore.",
|
|
9933
|
+
backupEmpty: "No checkpoints yet. One will be created before the first change.",
|
|
9934
|
+
restoreScope: "Restore all favorites, profiles, provider credentials, active records and native configuration for the five tools to this time, replacing later changes. The current state will be backed up first. Manager sign-in and password stay unchanged.",
|
|
9935
|
+
restore: "Review restore impact",
|
|
9936
|
+
restoreConfirm: "Confirm restore",
|
|
9937
|
+
cancel: "Cancel",
|
|
9938
|
+
backupReason: {
|
|
9939
|
+
manual: "Manual checkpoint",
|
|
9940
|
+
change: "Before favorite change",
|
|
9941
|
+
apply: "Before applying to tools",
|
|
9942
|
+
restore: "Before restore"
|
|
9943
|
+
},
|
|
9944
|
+
workflow: "Configuration steps",
|
|
9945
|
+
chooseTools: "Choose tools",
|
|
9946
|
+
reviewChanges: "Review changes",
|
|
9947
|
+
chooseHint: "Choose tools to configure. Existing linked profiles are selected automatically.",
|
|
9948
|
+
reviewHint: "Review the changes below. Nothing is written until you confirm.",
|
|
9949
|
+
targetTools: "Target tools",
|
|
9950
|
+
activateCount: "Activate now",
|
|
9951
|
+
changedFiles: "Native file changes",
|
|
9952
|
+
autoBackupNotice: "A checkpoint is created before applying. Restore it from the global Recovery timeline.",
|
|
9953
|
+
resolveBeforeApply: "Go back to resolve the conflicts, then generate a new preview.",
|
|
9954
|
+
selectedCount: "{{count}} tools selected",
|
|
9955
|
+
compatibleCount: "{{count}} compatible channels",
|
|
9956
|
+
selected: "Selected",
|
|
9957
|
+
backToSelection: "Back to selection",
|
|
9958
|
+
done: "Done",
|
|
9959
|
+
confirmSave: "Save profiles",
|
|
9960
|
+
confirmActivate: "Save and activate",
|
|
9961
|
+
parameter: "Parameter",
|
|
9962
|
+
before: "Before",
|
|
9963
|
+
after: "After",
|
|
9964
|
+
noParameterChanges: "No parameter changes",
|
|
9965
|
+
mappingDetails: "Mapping and preserved settings",
|
|
9966
|
+
redactedDiffHint: "Only credentials such as API keys and tokens are hidden; models and ordinary settings remain visible. Files are shown in a normalized structure.",
|
|
9967
|
+
modeLabel: {
|
|
9968
|
+
save: "Save only",
|
|
9969
|
+
activate: "Save and activate"
|
|
9970
|
+
},
|
|
9971
|
+
toolNames: {
|
|
9972
|
+
claude: "Claude Code",
|
|
9973
|
+
codex: "Codex",
|
|
9974
|
+
kimi: "Kimi Code",
|
|
9975
|
+
pi: "Pi",
|
|
9976
|
+
dsh: "DeepSeek Harness"
|
|
9977
|
+
},
|
|
9978
|
+
liveComparison: "Current tool configuration → after applying",
|
|
9979
|
+
liveComparisonHint: "Compare the current native files on disk with what will be written. Only credentials such as API keys and tokens are hidden.",
|
|
9980
|
+
previewBlocked: "Native file preview is unavailable. Resolve the blocking issues first.",
|
|
9981
|
+
savedComparison: "View saved profile changes",
|
|
9982
|
+
savedComparisonHint: "This compares the saved target profile with the profile to be saved, not the configuration currently used by the tool.",
|
|
9983
|
+
savedUnchanged: "Saved profile unchanged · View details",
|
|
9984
|
+
savedUnchangedHint: "The target profile already contains these settings. Switching to it may still change the tool's native files.",
|
|
9985
|
+
savedBefore: "Saved profile",
|
|
9986
|
+
savedAfter: "After saving",
|
|
9987
|
+
batchSummary: "{{count}} tools · Switch {{activate}} · Change {{files}} native files",
|
|
9988
|
+
confirmBatchSave: "Confirm save to {{count}} tools",
|
|
9989
|
+
confirmBatchActivate: "Confirm save and switch {{count}} tools",
|
|
9990
|
+
tabBlocked: "Needs attention",
|
|
9991
|
+
tabChanges: "{{count}} changed files",
|
|
9992
|
+
restoreReview: "Confirm global restore",
|
|
9993
|
+
restoreReviewHint: "Review the impact on the current state before restoring.",
|
|
9994
|
+
restoreChecking: "Working, please wait…",
|
|
9995
|
+
restoreRecheck: "Check impact again",
|
|
9996
|
+
restoreImpact: "{{count}} items will change",
|
|
9997
|
+
restoreNoChanges: "Current contents match this restore point. No restore is needed.",
|
|
9998
|
+
restoreUnchanged: "{{count}} unchanged items",
|
|
9999
|
+
restoreArea: {
|
|
10000
|
+
favorites: "All model favorites",
|
|
10001
|
+
profiles: "Profiles for all tools",
|
|
10002
|
+
vault: "Providers and credential vault",
|
|
10003
|
+
active: "Active configuration records",
|
|
10004
|
+
env: "Environment file"
|
|
10005
|
+
},
|
|
10006
|
+
restoreAction: {
|
|
10007
|
+
create: "Restore missing file",
|
|
10008
|
+
replace: "Replace with backup contents",
|
|
10009
|
+
delete: "Delete file absent from backup"
|
|
10010
|
+
},
|
|
10011
|
+
backupAction: {
|
|
10012
|
+
create: "Before adding favorite “{{name}}”",
|
|
10013
|
+
update: "Before editing favorite “{{name}}”",
|
|
10014
|
+
delete: "Before deleting favorite “{{name}}”",
|
|
10015
|
+
capture: "Before capturing “{{name}}” from {{tools}}",
|
|
10016
|
+
detach: "Before detaching “{{name}}” from {{tools}}",
|
|
10017
|
+
apply: "Before configuring “{{name}}” for {{tools}}",
|
|
10018
|
+
restore: "Before global restore to {{name}}"
|
|
10019
|
+
},
|
|
10020
|
+
channelNumber: "Channel {{count}}",
|
|
10021
|
+
channelHint: "Choose a provider and the model to use",
|
|
10022
|
+
channelProvider: "Provider / endpoint",
|
|
10023
|
+
chooseProvider: "Choose a provider endpoint",
|
|
10024
|
+
removeChannelNamed: "Remove channel: {{name}}",
|
|
10025
|
+
modelPicker: "Model",
|
|
10026
|
+
modelPickerHint: "Choose from the catalog or enter a custom model ID.",
|
|
10027
|
+
modelPlaceholder: "Choose or enter a model ID",
|
|
10028
|
+
modelSearch: "Search or enter a model ID",
|
|
10029
|
+
modelEmpty: "Enter a model ID to add it, or load the provider catalog first.",
|
|
10030
|
+
modelCustom: "Use “{{value}}”",
|
|
10031
|
+
catalogLoad: "Load catalog",
|
|
10032
|
+
catalogRefresh: "Refresh catalog",
|
|
10033
|
+
catalogLoading: "Loading",
|
|
10034
|
+
catalogCount: "{{count}} catalog models available to search above.",
|
|
10035
|
+
noCatalogManual: "No catalog available. You can still enter a model ID."
|
|
10036
|
+
},
|
|
10037
|
+
favorite: {
|
|
10038
|
+
result: "Operation completed"
|
|
10039
|
+
},
|
|
10040
|
+
templates: {
|
|
10041
|
+
tag: "Template"
|
|
10042
|
+
},
|
|
10043
|
+
workspace: {
|
|
10044
|
+
fileDiffTab: "File changes",
|
|
10045
|
+
navigation: "Main navigation",
|
|
10046
|
+
breadcrumb: "Breadcrumb",
|
|
10047
|
+
nav: {
|
|
10048
|
+
workspace: "Workspace",
|
|
10049
|
+
favorites: "Templates",
|
|
10050
|
+
history: "Recovery timeline"
|
|
10051
|
+
},
|
|
10052
|
+
eyebrow: "CONFIGURATION WORKSPACE",
|
|
10053
|
+
title: "What are your tools using?",
|
|
10054
|
+
subtitle: "Choose a tool and inspect the configuration currently in use.",
|
|
10055
|
+
homeSubtitle: "Home shows only live configuration; switching and management stay in each tool's configuration workspace.",
|
|
10056
|
+
manageFavorites: "Manage templates",
|
|
10057
|
+
switchTool: "Switch {{name}}",
|
|
10058
|
+
configureTool: "Configure and switch",
|
|
10059
|
+
configureSwitch: "Configure and switch",
|
|
10060
|
+
switcherEyebrow: "CONFIGURE AND SWITCH",
|
|
10061
|
+
switcherTitle: "Configure and switch {{name}}",
|
|
10062
|
+
switcherHint: "Create a candidate from a configuration or template, compare its route and file changes, then confirm the write.",
|
|
10063
|
+
configurations: "Configurations",
|
|
10064
|
+
useConfiguration: "Use this configuration",
|
|
10065
|
+
newConfiguration: "New configuration",
|
|
10066
|
+
noProfiles: "No local configuration is available to switch to yet.",
|
|
10067
|
+
noTemplates: "No template yet.",
|
|
10068
|
+
manageConfigurations: "Manage configuration entries",
|
|
10069
|
+
mappedModels: "Role-based mapping",
|
|
10070
|
+
toolDefaultModel: "Default model selected by the tool",
|
|
10071
|
+
currentConfigurationManagement: "Current configuration and advanced management",
|
|
10072
|
+
chooseTemplate: "Choose a template",
|
|
10073
|
+
pickTemplate: "Search and select a template",
|
|
10074
|
+
pickTemplateHint: "Choose a template to see its connections and preview the switch.",
|
|
10075
|
+
newFromTemplate: "Create configuration from template",
|
|
10076
|
+
manageTemplates: "Manage templates",
|
|
10077
|
+
noMatches: "No matching models.",
|
|
10078
|
+
startTitle: "Save a model once. Use it across your tools.",
|
|
10079
|
+
startHint: "Start from an existing tool profile to reuse its provider and model ID. Then choose a tool to preview a switch without entering credentials again.",
|
|
10080
|
+
noTools: "No tool information available.",
|
|
10081
|
+
lastBackup: "Latest recovery point: {{time}}",
|
|
10082
|
+
historyHint: "Save a checkpoint or explore automatic backups before favorite operations.",
|
|
10083
|
+
openHistory: "View timeline",
|
|
10084
|
+
relationship: "Configuration connections",
|
|
10085
|
+
provider: "Provider",
|
|
10086
|
+
tool: "Tool",
|
|
10087
|
+
missingProvider: "Provider missing",
|
|
10088
|
+
relationshipHint: "Connections show configuration sources and writes. Tools send model requests directly.",
|
|
10089
|
+
currentChain: "Current route",
|
|
10090
|
+
configuration: "Configuration",
|
|
10091
|
+
currentChainHint: "This route is active in the current tool.",
|
|
10092
|
+
currentForTool: "{{name}} is currently using",
|
|
10093
|
+
currentForToolHint: "Home only shows active configuration, never an unconfirmed candidate.",
|
|
10094
|
+
activeNow: "Active",
|
|
10095
|
+
switchMap: "Current and new routes",
|
|
10096
|
+
candidateChain: "New route",
|
|
10097
|
+
appliesAfterConfirm: "Active after apply",
|
|
10098
|
+
notWritten: "Not written",
|
|
10099
|
+
switchTarget: "Switching {{name}} in this preview",
|
|
10100
|
+
switchTargetHint: "This is a preview target for {{name}} and has not been written. Other tools keep their own current configuration.",
|
|
10101
|
+
checking: "Checking available channels…",
|
|
10102
|
+
chooseChannel: "Choose a channel for this switch",
|
|
10103
|
+
current: "Current",
|
|
10104
|
+
currentToolModel: "Current {{name}} model",
|
|
10105
|
+
targetToolModel: "{{name}} will switch to",
|
|
10106
|
+
preview: "Preview switch",
|
|
10107
|
+
previewHint: "Takes effect after confirmation. An automatic backup is available in the recovery timeline.",
|
|
10108
|
+
captureHint: "Reuse the model and provider from an existing profile.",
|
|
10109
|
+
favoriteEyebrow: "MODELS CONNECTED TO TOOLS",
|
|
10110
|
+
favoriteHint: "Choose a model to see its channels and linked tools. Click a tool to configure it.",
|
|
10111
|
+
favoriteDetail: "Connections reflect actual channels and tool profiles.",
|
|
10112
|
+
graphHint: "Choose a channel on the left, then a tool on the right.",
|
|
10113
|
+
manageLinks: "Manage generated profiles and favorite",
|
|
10114
|
+
inUse: "In use",
|
|
10115
|
+
saved: "Saved",
|
|
10116
|
+
available: "Available",
|
|
10117
|
+
linkMissing: "Linked source missing",
|
|
10118
|
+
back: "Back to workspace",
|
|
10119
|
+
captureCurrent: "Favorite the current profile"
|
|
10120
|
+
},
|
|
10121
|
+
timeline: {
|
|
10122
|
+
title: "Recovery timeline",
|
|
10123
|
+
eyebrow: "YOUR CONFIGURATION THROUGH TIME",
|
|
10124
|
+
subtitle: "Return to a working configuration. Select a checkpoint to review its impact.",
|
|
10125
|
+
points: "Recovery points",
|
|
10126
|
+
current: "Current state",
|
|
10127
|
+
currentHint: "Models currently used by your tools",
|
|
10128
|
+
snapshot: "Historical snapshot",
|
|
10129
|
+
snapshotHint: "Automatic checkpoints preserve the state before the named operation. Review the file changes needed to restore it from the current state.",
|
|
10130
|
+
older: "Older",
|
|
10131
|
+
newer: "Newer",
|
|
10132
|
+
restore: "Restore all to this point",
|
|
10133
|
+
protection: "Your current state is backed up before restoring.",
|
|
10134
|
+
currentDescription: "These are your tools' active configurations. Save a manual checkpoint or choose a historical recovery point.",
|
|
10135
|
+
selectHint: "Select a recovery point to review files that will be replaced, deleted, or created."
|
|
9788
10136
|
}
|
|
9789
10137
|
};
|
|
9790
10138
|
// ../../packages/shared/src/locales/zh-CN.json
|
|
@@ -10487,7 +10835,30 @@ var zh_CN_default = {
|
|
|
10487
10835
|
completionUnsupported: "端点不接受任何已知的补全协议",
|
|
10488
10836
|
completionHttpError: "模型 {{model}} 的补全请求返回 HTTP {{status}}:目录里有这个模型,但它无法作答",
|
|
10489
10837
|
completionInvalid: "补全响应不是已知的格式,无法确认模型真的作答"
|
|
10490
|
-
}
|
|
10838
|
+
},
|
|
10839
|
+
favoriteNotFound: "收藏不存在",
|
|
10840
|
+
favoriteRevisionRequired: "请提供当前收藏版本",
|
|
10841
|
+
favoriteRevisionConflict: "收藏版本已变化,请重新加载",
|
|
10842
|
+
favoriteInUse: "收藏仍被引用,请先解除关联",
|
|
10843
|
+
favoriteConnectionInUse: "渠道仍被引用,请先解除关联",
|
|
10844
|
+
favoriteEndpointMissing: "渠道引用的供应商端点不存在",
|
|
10845
|
+
favoriteProtocolUnsupported: "此工具不支持所选渠道协议",
|
|
10846
|
+
favoriteProjectionUnsupported: "无法无损表达模型设置",
|
|
10847
|
+
favoriteProfileDiverged: "配置已发生分歧,请明确选择覆盖或解除关联",
|
|
10848
|
+
favoriteRawOverrideConflict: "请先移除原始文件覆盖",
|
|
10849
|
+
favoriteActiveUpdateRequiresApply: "激活配置的变更必须同时应用",
|
|
10850
|
+
favoritePlanStale: "计划已过期或输入已变化,请重新预览",
|
|
10851
|
+
favoritePlanExpired: "计划已过期,请重新预览",
|
|
10852
|
+
favoriteIdempotencyConflict: "请求标识已用于其他批准内容",
|
|
10853
|
+
favoriteUndoConflict: "后续修改阻止撤销,请重新规划",
|
|
10854
|
+
favoritePreferenceNotRepresented: "此工具无法设置默认思考偏好,需要确认忽略",
|
|
10855
|
+
favoriteEffortUnverified: "渠道的可选思考档位未经验证",
|
|
10856
|
+
favoriteStoreInvalid: "收藏文件损坏或版本不受支持",
|
|
10857
|
+
favoriteLimitReached: "收藏数量已达上限",
|
|
10858
|
+
favoriteCredentialConsentRequired: "需要明确同意将内联密钥存入凭据库",
|
|
10859
|
+
favoriteBackupInvalid: "备份无效、已损坏或配置目录已改变,未恢复。",
|
|
10860
|
+
favoriteBackupRecoveryFailed: "恢复回滚未完成,已暂停配置操作以保护数据。请检查文件权限后重试。",
|
|
10861
|
+
favoriteBackupStale: "配置在预览后发生变化,请重新检查恢复影响。"
|
|
10491
10862
|
},
|
|
10492
10863
|
warning: {
|
|
10493
10864
|
activation: {
|
|
@@ -10743,6 +11114,302 @@ var zh_CN_default = {
|
|
|
10743
11114
|
completionFailedCached: "缓存于 {{at}}",
|
|
10744
11115
|
catalogHint: "已获取 {{count}} 个模型,模型字段现可从下拉列表选择。",
|
|
10745
11116
|
missingBaseUrl: "请先填写至少一个 endpoint URL 再测试。"
|
|
11117
|
+
},
|
|
11118
|
+
favorites: {
|
|
11119
|
+
linked: "关联模板",
|
|
11120
|
+
sourceMissing: "模板来源不存在",
|
|
11121
|
+
connectionMissing: "来源渠道不存在",
|
|
11122
|
+
importCount: "{{count}} 个模板",
|
|
11123
|
+
retryFailed: "仅重新预览失败项",
|
|
11124
|
+
saveFavorite: "保存模板",
|
|
11125
|
+
authentication: "认证方式",
|
|
11126
|
+
liveState: "原生文件状态",
|
|
11127
|
+
preserved: "这些现有字段保留原值;固定模型档位继续使用原模型",
|
|
11128
|
+
exportVersion: "默认使用 payload v2,目标版本必须支持模型收藏夹。",
|
|
11129
|
+
legacyExport: "兼容旧版导出(不迁移收藏和来源关联)",
|
|
11130
|
+
catalog: "获取模型目录(不发送补全请求)",
|
|
11131
|
+
catalogModel: "从目录选择模型 ID",
|
|
11132
|
+
noCatalog: "目录不可用或为空,仍可手工输入模型 ID。",
|
|
11133
|
+
title: "模板库",
|
|
11134
|
+
subtitle: "保存模板,选择渠道,配置到工具。",
|
|
11135
|
+
add: "新建模板",
|
|
11136
|
+
edit: "编辑模板",
|
|
11137
|
+
name: "模板名称",
|
|
11138
|
+
notes: "备注",
|
|
11139
|
+
save: "仅保存配置",
|
|
11140
|
+
delete: "删除模板",
|
|
11141
|
+
connections: "渠道",
|
|
11142
|
+
connection: "选择渠道",
|
|
11143
|
+
label: "渠道标签",
|
|
11144
|
+
endpoint: "凭据库端点",
|
|
11145
|
+
protocol: "协议",
|
|
11146
|
+
model: "精确请求模型 ID",
|
|
11147
|
+
addConnection: "+ 添加渠道",
|
|
11148
|
+
removeConnection: "移除此渠道",
|
|
11149
|
+
contextWindow: "上下文窗口",
|
|
11150
|
+
maxOutputTokens: "最大输出 token",
|
|
11151
|
+
reasoningSupported: "支持推理",
|
|
11152
|
+
reasoningEffort: "默认思考偏好",
|
|
11153
|
+
supportedReasoningEfforts: "支持的思考档位",
|
|
11154
|
+
effortsHint: "逗号分隔:none,minimal,low,medium,high,xhigh,max,ultra",
|
|
11155
|
+
unknown: "未知 / 未设置",
|
|
11156
|
+
true: "是",
|
|
11157
|
+
false: "否",
|
|
11158
|
+
declared: "填写值:由你声明,不代表实测能力。",
|
|
11159
|
+
inherited: "继承模板",
|
|
11160
|
+
overridden: "此渠道覆写;留空表示清除继承",
|
|
11161
|
+
inherit: "恢复继承",
|
|
11162
|
+
invalid: "请检查名称、渠道和能力声明是否完整且一致。",
|
|
11163
|
+
configure: "配置到工具",
|
|
11164
|
+
saveOnlyHint: "仅保存不会修改原生文件。选择同时激活后才会应用到工具。",
|
|
11165
|
+
target: "目标配置",
|
|
11166
|
+
newProfile: "新建配置",
|
|
11167
|
+
profileName: "配置名称(留空自动生成)",
|
|
11168
|
+
mode: "操作方式",
|
|
11169
|
+
activate: "保存并激活",
|
|
11170
|
+
ignorePreference: "确认忽略无法表达的思考偏好",
|
|
11171
|
+
overwriteDiverged: "以模板覆盖已分歧的受控字段",
|
|
11172
|
+
preview: "生成预览",
|
|
11173
|
+
appliedToast: "已将模板应用到 {{count}} 个工具。",
|
|
11174
|
+
confirm: "确认执行计划",
|
|
11175
|
+
rendererDefault: "工具渲染默认值",
|
|
11176
|
+
notRepresented: "无法表达的字段",
|
|
11177
|
+
nativeFiles: "原生写入目标",
|
|
11178
|
+
none: "无",
|
|
11179
|
+
applied: "已完成",
|
|
11180
|
+
unchanged: "无变化",
|
|
11181
|
+
failed: "失败,请重新预览",
|
|
11182
|
+
skipped: "未执行,请重新预览",
|
|
11183
|
+
capture: "从已有配置收藏",
|
|
11184
|
+
extractCredential: "同意将内联密钥存入凭据库并复用",
|
|
11185
|
+
linkSource: "关联来源配置",
|
|
11186
|
+
search: "搜索名称、模型或渠道",
|
|
11187
|
+
loading: "正在加载收藏…",
|
|
11188
|
+
empty: "还没有收藏。可从已有配置收藏,或手动添加。",
|
|
11189
|
+
pending: "待连接",
|
|
11190
|
+
generated: "已生成配置",
|
|
11191
|
+
needsUpdate: "有更新",
|
|
11192
|
+
diverged: "有本地分歧",
|
|
11193
|
+
detach: "解除关联,保留配置",
|
|
11194
|
+
harnesses: "工具配置",
|
|
11195
|
+
autoName: "留空使用模型名称",
|
|
11196
|
+
modelAdvanced: "高级设置:能力、思考与备注",
|
|
11197
|
+
channelName: "自定义渠道名称",
|
|
11198
|
+
channelAdvanced: "高级设置:渠道参数覆盖",
|
|
11199
|
+
targetAdvanced: "更改目标配置或名称",
|
|
11200
|
+
changeDetails: "查看参数差异",
|
|
11201
|
+
fileDetails: "查看原生文件差异",
|
|
11202
|
+
activateSelected: "保存后立即激活到所选工具",
|
|
11203
|
+
noCompatibleChannel: "暂无兼容渠道",
|
|
11204
|
+
updateProfile: "更新已有配置",
|
|
11205
|
+
backups: "备份与恢复",
|
|
11206
|
+
backupHint: "备份当前用户的收藏、配置、凭据和工具原生文件。收藏变更前自动保留最近 20 次备份,另可保留一个手动恢复点。备份加密保存在本机。",
|
|
11207
|
+
backupNow: "备份当前状态",
|
|
11208
|
+
backupCreated: "已创建恢复点",
|
|
11209
|
+
backupRestored: "已恢复;恢复前的状态也已备份,可随时撤回",
|
|
11210
|
+
backupEmpty: "还没有恢复点,首次变更前会自动创建。",
|
|
11211
|
+
restoreScope: "将当前用户的全部收藏、配置档案、凭据库、激活记录和五种工具的原生配置恢复到此时刻,覆盖此后修改。恢复前会再次备份当前状态;管理后台的登录会话和密码不变。",
|
|
11212
|
+
restore: "查看恢复影响",
|
|
11213
|
+
restoreConfirm: "确认恢复",
|
|
11214
|
+
cancel: "取消",
|
|
11215
|
+
backupReason: {
|
|
11216
|
+
manual: "手动恢复点",
|
|
11217
|
+
change: "收藏变更前",
|
|
11218
|
+
apply: "应用到工具前",
|
|
11219
|
+
restore: "恢复前的状态"
|
|
11220
|
+
},
|
|
11221
|
+
workflow: "配置步骤",
|
|
11222
|
+
chooseTools: "选择工具",
|
|
11223
|
+
reviewChanges: "预览并确认",
|
|
11224
|
+
chooseHint: "选择要配置的工具,已有配置会自动沿用。",
|
|
11225
|
+
reviewHint: "核对本次变更,确认后才会写入。",
|
|
11226
|
+
targetTools: "目标工具",
|
|
11227
|
+
activateCount: "立即激活",
|
|
11228
|
+
changedFiles: "原生文件变更",
|
|
11229
|
+
autoBackupNotice: "应用前自动备份,可从全局「恢复时间线」回退。",
|
|
11230
|
+
resolveBeforeApply: "请返回上一步处理冲突,再重新生成预览。",
|
|
11231
|
+
selectedCount: "已选择 {{count}} 个工具",
|
|
11232
|
+
compatibleCount: "{{count}} 个可用渠道",
|
|
11233
|
+
selected: "已选",
|
|
11234
|
+
backToSelection: "返回选择",
|
|
11235
|
+
done: "完成",
|
|
11236
|
+
confirmSave: "确认保存配置",
|
|
11237
|
+
confirmActivate: "确认保存并激活",
|
|
11238
|
+
parameter: "参数",
|
|
11239
|
+
before: "变更前",
|
|
11240
|
+
after: "变更后",
|
|
11241
|
+
noParameterChanges: "参数保持不变",
|
|
11242
|
+
mappingDetails: "映射依据与保留设置",
|
|
11243
|
+
redactedDiffHint: "仅隐藏 API key、token 等凭据,保留模型与普通配置;以下以统一结构展示文件差异。",
|
|
11244
|
+
modeLabel: {
|
|
11245
|
+
save: "仅保存",
|
|
11246
|
+
activate: "保存并激活"
|
|
11247
|
+
},
|
|
11248
|
+
toolNames: {
|
|
11249
|
+
claude: "Claude Code",
|
|
11250
|
+
codex: "Codex",
|
|
11251
|
+
kimi: "Kimi Code",
|
|
11252
|
+
pi: "Pi",
|
|
11253
|
+
dsh: "DeepSeek Harness"
|
|
11254
|
+
},
|
|
11255
|
+
liveComparison: "工具当前配置 → 应用后",
|
|
11256
|
+
liveComparisonHint: "以下比较磁盘上的当前原生文件与本次将写入的内容;仅隐藏密钥、token 等凭据。",
|
|
11257
|
+
previewBlocked: "尚未生成原生文件预览,请先处理阻止应用的问题。",
|
|
11258
|
+
savedComparison: "查看保存档案的变更",
|
|
11259
|
+
savedComparisonHint: "这里比较已保存的目标档案与本次保存结果,不代表工具当前使用的配置。",
|
|
11260
|
+
savedUnchanged: "保存档案无变化 · 查看详情",
|
|
11261
|
+
savedUnchangedHint: "目标档案已经包含这些参数;切换到该档案时,工具的原生文件仍可能变化。",
|
|
11262
|
+
savedBefore: "已保存的档案",
|
|
11263
|
+
savedAfter: "本次保存后",
|
|
11264
|
+
batchSummary: "本次处理 {{count}} 个工具 · 切换 {{activate}} 个 · 改动 {{files}} 个原生文件",
|
|
11265
|
+
confirmBatchSave: "确认保存到 {{count}} 个工具",
|
|
11266
|
+
confirmBatchActivate: "确认保存并切换 {{count}} 个工具",
|
|
11267
|
+
tabBlocked: "需处理",
|
|
11268
|
+
tabChanges: "{{count}} 个文件变化",
|
|
11269
|
+
restoreReview: "确认全局恢复",
|
|
11270
|
+
restoreReviewHint: "先核对当前状态将受到的影响,再决定是否恢复。",
|
|
11271
|
+
restoreChecking: "正在处理,请稍候…",
|
|
11272
|
+
restoreRecheck: "重新检查影响",
|
|
11273
|
+
restoreImpact: "将更改 {{count}} 项",
|
|
11274
|
+
restoreNoChanges: "当前内容与此恢复点相同,无需恢复。",
|
|
11275
|
+
restoreUnchanged: "{{count}} 项内容相同",
|
|
11276
|
+
restoreArea: {
|
|
11277
|
+
favorites: "全部模型收藏",
|
|
11278
|
+
profiles: "全部工具的配置档案",
|
|
11279
|
+
vault: "供应商与凭据库",
|
|
11280
|
+
active: "当前激活记录",
|
|
11281
|
+
env: "环境变量文件"
|
|
11282
|
+
},
|
|
11283
|
+
restoreAction: {
|
|
11284
|
+
create: "还原缺失文件",
|
|
11285
|
+
replace: "还原为备份内容",
|
|
11286
|
+
delete: "删除备份时不存在的文件"
|
|
11287
|
+
},
|
|
11288
|
+
backupAction: {
|
|
11289
|
+
create: "添加收藏「{{name}}」前",
|
|
11290
|
+
update: "修改收藏「{{name}}」前",
|
|
11291
|
+
delete: "删除收藏「{{name}}」前",
|
|
11292
|
+
capture: "从 {{tools}} 收藏「{{name}}」前",
|
|
11293
|
+
detach: "解除 {{tools}} 配置「{{name}}」的关联前",
|
|
11294
|
+
apply: "将「{{name}}」配置到 {{tools}} 前",
|
|
11295
|
+
restore: "全局恢复到 {{name}} 前"
|
|
11296
|
+
},
|
|
11297
|
+
channelNumber: "渠道 {{count}}",
|
|
11298
|
+
channelHint: "选择供应商,再设置要使用的模型",
|
|
11299
|
+
channelProvider: "供应商 / 入口",
|
|
11300
|
+
chooseProvider: "选择供应商入口",
|
|
11301
|
+
removeChannelNamed: "移除渠道:{{name}}",
|
|
11302
|
+
modelPicker: "模型",
|
|
11303
|
+
modelPickerHint: "从目录选择,或输入自定义模型 ID。",
|
|
11304
|
+
modelPlaceholder: "选择或输入模型 ID",
|
|
11305
|
+
modelSearch: "搜索或输入模型 ID",
|
|
11306
|
+
modelEmpty: "输入模型 ID 即可添加,也可以先加载供应商目录。",
|
|
11307
|
+
modelCustom: "使用「{{value}}」",
|
|
11308
|
+
catalogLoad: "加载目录",
|
|
11309
|
+
catalogRefresh: "刷新目录",
|
|
11310
|
+
catalogLoading: "加载中",
|
|
11311
|
+
catalogCount: "目录中有 {{count}} 个模型,可在上方搜索选择。",
|
|
11312
|
+
noCatalogManual: "暂无可用目录,仍可手动输入模型 ID。"
|
|
11313
|
+
},
|
|
11314
|
+
favorite: {
|
|
11315
|
+
result: "操作完成"
|
|
11316
|
+
},
|
|
11317
|
+
templates: {
|
|
11318
|
+
tag: "模板"
|
|
11319
|
+
},
|
|
11320
|
+
workspace: {
|
|
11321
|
+
fileDiffTab: "文件差异",
|
|
11322
|
+
navigation: "主导航",
|
|
11323
|
+
breadcrumb: "路径导航",
|
|
11324
|
+
nav: {
|
|
11325
|
+
workspace: "工作台",
|
|
11326
|
+
favorites: "模板",
|
|
11327
|
+
history: "恢复时间线"
|
|
11328
|
+
},
|
|
11329
|
+
eyebrow: "配置工作台",
|
|
11330
|
+
title: "你的工具,现在用什么",
|
|
11331
|
+
subtitle: "选择工具,查看当前正在使用的配置。",
|
|
11332
|
+
homeSubtitle: "首页只展示真实生效的配置;切换和管理集中到工具的配置工作区。",
|
|
11333
|
+
manageFavorites: "管理模板",
|
|
11334
|
+
switchTool: "切换 {{name}}",
|
|
11335
|
+
configureTool: "配置与切换",
|
|
11336
|
+
configureSwitch: "配置与切换",
|
|
11337
|
+
switcherEyebrow: "配置与切换",
|
|
11338
|
+
switcherTitle: "{{name}} 配置与切换",
|
|
11339
|
+
switcherHint: "从配置或模板创建候选,先比较链路与文件差异,再确认写入。",
|
|
11340
|
+
configurations: "配置",
|
|
11341
|
+
useConfiguration: "使用此配置",
|
|
11342
|
+
newConfiguration: "新建配置",
|
|
11343
|
+
noProfiles: "还没有可用于切换的本地配置。",
|
|
11344
|
+
noTemplates: "还没有模板。",
|
|
11345
|
+
manageConfigurations: "管理配置条目",
|
|
11346
|
+
mappedModels: "按角色映射",
|
|
11347
|
+
toolDefaultModel: "由工具选择默认模型",
|
|
11348
|
+
currentConfigurationManagement: "当前配置与高级管理",
|
|
11349
|
+
chooseTemplate: "选择模板",
|
|
11350
|
+
pickTemplate: "搜索并选择模板",
|
|
11351
|
+
pickTemplateHint: "选一个模板,即可查看配置关系和切换影响。",
|
|
11352
|
+
newFromTemplate: "从模板创建配置",
|
|
11353
|
+
manageTemplates: "管理模板",
|
|
11354
|
+
noMatches: "没有找到匹配的模型。",
|
|
11355
|
+
startTitle: "把常用模型收藏起来,一次配置,多处使用",
|
|
11356
|
+
startHint: "从已有工具配置收藏模型,供应商和模型 ID 会自动带入。之后选一个工具就能预览切换,无需重复填写凭据。",
|
|
11357
|
+
noTools: "暂无工具信息。",
|
|
11358
|
+
lastBackup: "最近恢复点:{{time}}",
|
|
11359
|
+
historyHint: "手动保存恢复点,或查看收藏操作前的自动备份。",
|
|
11360
|
+
openHistory: "查看时间线",
|
|
11361
|
+
relationship: "配置关系",
|
|
11362
|
+
provider: "供应商",
|
|
11363
|
+
tool: "工具",
|
|
11364
|
+
missingProvider: "供应商已缺失",
|
|
11365
|
+
relationshipHint: "连线表示配置来源与写入关系;模型请求由工具直接发出。",
|
|
11366
|
+
currentChain: "当前链路",
|
|
11367
|
+
configuration: "配置",
|
|
11368
|
+
currentChainHint: "这条链路已经在当前工具中生效。",
|
|
11369
|
+
currentForTool: "{{name}} 当前正在使用",
|
|
11370
|
+
currentForToolHint: "首页只展示已经生效的配置,不包含未确认的候选。",
|
|
11371
|
+
activeNow: "生效中",
|
|
11372
|
+
switchMap: "当前与新链路",
|
|
11373
|
+
candidateChain: "新链路",
|
|
11374
|
+
appliesAfterConfirm: "应用后生效",
|
|
11375
|
+
notWritten: "未写入",
|
|
11376
|
+
switchTarget: "本次将切换到 {{name}}",
|
|
11377
|
+
switchTargetHint: "这是 {{name}} 的预览目标,尚未写入;其他工具保持各自当前配置。",
|
|
11378
|
+
checking: "正在检查可用渠道…",
|
|
11379
|
+
chooseChannel: "请选择本次使用的渠道",
|
|
11380
|
+
current: "当前",
|
|
11381
|
+
currentToolModel: "{{name}} 当前",
|
|
11382
|
+
targetToolModel: "{{name}} 将切换为",
|
|
11383
|
+
preview: "预览切换",
|
|
11384
|
+
previewHint: "确认后生效;应用前自动备份,可在恢复时间线回退。",
|
|
11385
|
+
captureHint: "复用已有配置中的模型和供应商,无需重新填写。",
|
|
11386
|
+
favoriteEyebrow: "模型与工具的连接",
|
|
11387
|
+
favoriteHint: "选中模型,查看它的渠道和已关联工具;点击工具即可配置。",
|
|
11388
|
+
favoriteDetail: "渠道与工具之间的关系由实际配置生成。",
|
|
11389
|
+
graphHint: "选择左侧渠道,再点击右侧工具。",
|
|
11390
|
+
manageLinks: "管理已生成配置与收藏",
|
|
11391
|
+
inUse: "正在使用",
|
|
11392
|
+
saved: "已保存",
|
|
11393
|
+
available: "可配置",
|
|
11394
|
+
linkMissing: "关联来源缺失",
|
|
11395
|
+
back: "返回工作台",
|
|
11396
|
+
captureCurrent: "收藏当前配置"
|
|
11397
|
+
},
|
|
11398
|
+
timeline: {
|
|
11399
|
+
title: "恢复时间线",
|
|
11400
|
+
eyebrow: "配置的时间回廊",
|
|
11401
|
+
subtitle: "回到配置正常的那一刻。选中恢复点,先查看实际影响。",
|
|
11402
|
+
points: "恢复时间点",
|
|
11403
|
+
current: "当前状态",
|
|
11404
|
+
currentHint: "查看工具当前使用的模型",
|
|
11405
|
+
snapshot: "查看历史快照",
|
|
11406
|
+
snapshotHint: "自动恢复点保存的是所列操作发生前的状态。下面列出从当前状态恢复到这里的文件影响。",
|
|
11407
|
+
older: "更早",
|
|
11408
|
+
newer: "较新",
|
|
11409
|
+
restore: "全局恢复到此时",
|
|
11410
|
+
protection: "恢复前会自动保存当前状态。",
|
|
11411
|
+
currentDescription: "这里展示当前生效的工具配置。可以先手动备份,也可以从时间线选择一个历史恢复点。",
|
|
11412
|
+
selectHint: "选择左侧恢复点,即可查看覆盖、删除和新增的文件。"
|
|
10746
11413
|
}
|
|
10747
11414
|
};
|
|
10748
11415
|
|
|
@@ -25027,6 +25694,175 @@ function date4(params) {
|
|
|
25027
25694
|
|
|
25028
25695
|
// ../../node_modules/zod/v4/classic/external.js
|
|
25029
25696
|
config(en_default2());
|
|
25697
|
+
// ../../packages/shared/src/model-favorites.ts
|
|
25698
|
+
var favoriteProtocolSchema = exports_external.enum([
|
|
25699
|
+
"openai-chat",
|
|
25700
|
+
"openai-responses",
|
|
25701
|
+
"anthropic-messages"
|
|
25702
|
+
]);
|
|
25703
|
+
var favoriteEffortSchema = exports_external.enum([
|
|
25704
|
+
"none",
|
|
25705
|
+
"minimal",
|
|
25706
|
+
"low",
|
|
25707
|
+
"medium",
|
|
25708
|
+
"high",
|
|
25709
|
+
"xhigh",
|
|
25710
|
+
"max",
|
|
25711
|
+
"ultra"
|
|
25712
|
+
]);
|
|
25713
|
+
var capacity = exports_external.number().int().positive().max(1e8);
|
|
25714
|
+
var efforts = exports_external.array(favoriteEffortSchema).max(8).refine((values) => new Set(values).size === values.length);
|
|
25715
|
+
var modelFactsSchema = exports_external.object({
|
|
25716
|
+
contextWindow: capacity.optional(),
|
|
25717
|
+
maxOutputTokens: capacity.optional(),
|
|
25718
|
+
reasoningSupported: exports_external.boolean().optional(),
|
|
25719
|
+
supportedReasoningEfforts: efforts.optional()
|
|
25720
|
+
});
|
|
25721
|
+
var preferencesSchema = exports_external.object({ reasoningEffort: favoriteEffortSchema.optional() });
|
|
25722
|
+
var favoriteConnectionSchema = exports_external.object({
|
|
25723
|
+
id: exports_external.uuid(),
|
|
25724
|
+
label: exports_external.string().trim().min(1).max(120),
|
|
25725
|
+
providerId: exports_external.string().min(1).max(120),
|
|
25726
|
+
endpointKey: exports_external.string().min(1).max(60),
|
|
25727
|
+
protocol: favoriteProtocolSchema,
|
|
25728
|
+
requestModelId: exports_external.string().trim().min(1).max(120),
|
|
25729
|
+
factOverrides: exports_external.object({
|
|
25730
|
+
contextWindow: capacity.nullable().optional(),
|
|
25731
|
+
maxOutputTokens: capacity.nullable().optional(),
|
|
25732
|
+
reasoningSupported: exports_external.boolean().nullable().optional(),
|
|
25733
|
+
supportedReasoningEfforts: efforts.nullable().optional()
|
|
25734
|
+
}).default({}),
|
|
25735
|
+
preferenceOverrides: exports_external.object({ reasoningEffort: favoriteEffortSchema.nullable().optional() }).default({})
|
|
25736
|
+
});
|
|
25737
|
+
var favoriteFields = exports_external.object({
|
|
25738
|
+
name: exports_external.string().trim().min(1).max(120),
|
|
25739
|
+
notes: exports_external.string().max(4096).default(""),
|
|
25740
|
+
defaults: modelFactsSchema.default({}),
|
|
25741
|
+
preferences: preferencesSchema.default({}),
|
|
25742
|
+
connections: exports_external.array(favoriteConnectionSchema).max(50).default([])
|
|
25743
|
+
});
|
|
25744
|
+
function resolveFavorite(favorite, connection) {
|
|
25745
|
+
const facts = { ...favorite.defaults };
|
|
25746
|
+
const sources = {};
|
|
25747
|
+
for (const field of Object.keys(modelFactsSchema.shape)) {
|
|
25748
|
+
const override = connection.factOverrides[field];
|
|
25749
|
+
if (override === null) {
|
|
25750
|
+
delete facts[field];
|
|
25751
|
+
} else if (override !== undefined) {
|
|
25752
|
+
Object.assign(facts, { [field]: override });
|
|
25753
|
+
}
|
|
25754
|
+
sources[field] = override === null ? "unknown" : override !== undefined ? "connection" : facts[field] !== undefined ? "favorite" : "unknown";
|
|
25755
|
+
}
|
|
25756
|
+
const effort = connection.preferenceOverrides.reasoningEffort;
|
|
25757
|
+
const preferences = effort === null ? {} : effort === undefined ? { ...favorite.preferences } : { reasoningEffort: effort };
|
|
25758
|
+
sources.reasoningEffort = effort === null ? "unknown" : effort !== undefined ? "connection" : preferences.reasoningEffort ? "favorite" : "unknown";
|
|
25759
|
+
return { facts, preferences, sources };
|
|
25760
|
+
}
|
|
25761
|
+
function validateFavorite(value, ctx) {
|
|
25762
|
+
const identities = new Set;
|
|
25763
|
+
const ids = new Set;
|
|
25764
|
+
const check2 = (facts, preferences, path) => {
|
|
25765
|
+
const effort = preferences.reasoningEffort;
|
|
25766
|
+
if (facts.reasoningSupported === false && ((facts.supportedReasoningEfforts?.length ?? 0) > 0 || effort && effort !== "none") || effort && facts.supportedReasoningEfforts && !facts.supportedReasoningEfforts.includes(effort)) {
|
|
25767
|
+
ctx.addIssue({ code: "custom", path, message: "favoriteInvalidFacts" });
|
|
25768
|
+
}
|
|
25769
|
+
};
|
|
25770
|
+
check2(value.defaults, value.preferences, ["defaults"]);
|
|
25771
|
+
value.connections.forEach((connection, index) => {
|
|
25772
|
+
const identity = JSON.stringify([
|
|
25773
|
+
connection.providerId,
|
|
25774
|
+
connection.endpointKey,
|
|
25775
|
+
connection.protocol,
|
|
25776
|
+
connection.requestModelId
|
|
25777
|
+
]);
|
|
25778
|
+
if (identities.has(identity) || ids.has(connection.id)) {
|
|
25779
|
+
ctx.addIssue({
|
|
25780
|
+
code: "custom",
|
|
25781
|
+
path: ["connections", index],
|
|
25782
|
+
message: "favoriteDuplicateConnection"
|
|
25783
|
+
});
|
|
25784
|
+
}
|
|
25785
|
+
identities.add(identity);
|
|
25786
|
+
ids.add(connection.id);
|
|
25787
|
+
const resolved = resolveFavorite(value, connection);
|
|
25788
|
+
check2(resolved.facts, resolved.preferences, ["connections", index]);
|
|
25789
|
+
});
|
|
25790
|
+
}
|
|
25791
|
+
var createFavoriteRequestSchema = favoriteFields.superRefine(validateFavorite);
|
|
25792
|
+
var modelFavoriteSchema = favoriteFields.extend({
|
|
25793
|
+
id: exports_external.uuid(),
|
|
25794
|
+
revision: exports_external.number().int().positive(),
|
|
25795
|
+
createdAt: exports_external.iso.datetime(),
|
|
25796
|
+
updatedAt: exports_external.iso.datetime()
|
|
25797
|
+
}).superRefine(validateFavorite);
|
|
25798
|
+
var favoriteStoreSchema = exports_external.object({ schemaVersion: exports_external.literal(1), favorites: exports_external.array(modelFavoriteSchema).max(1000) }).refine((value) => new Set(value.favorites.map((favorite) => favorite.id)).size === value.favorites.length);
|
|
25799
|
+
var updateFavoriteRequestSchema = exports_external.object({
|
|
25800
|
+
name: favoriteFields.shape.name.optional(),
|
|
25801
|
+
notes: exports_external.string().max(4096).optional(),
|
|
25802
|
+
defaults: modelFactsSchema.optional(),
|
|
25803
|
+
preferences: preferencesSchema.optional(),
|
|
25804
|
+
connections: exports_external.array(favoriteConnectionSchema).max(50).optional(),
|
|
25805
|
+
expectedRevision: exports_external.number().int().positive().optional()
|
|
25806
|
+
});
|
|
25807
|
+
var favoriteRevisionRequestSchema = exports_external.object({
|
|
25808
|
+
expectedRevision: exports_external.number().int().positive().optional()
|
|
25809
|
+
});
|
|
25810
|
+
var ownedExtraSchema = exports_external.enum([
|
|
25811
|
+
"api",
|
|
25812
|
+
"providerType",
|
|
25813
|
+
"contextWindow",
|
|
25814
|
+
"maxContextSize",
|
|
25815
|
+
"maxTokens",
|
|
25816
|
+
"reasoning",
|
|
25817
|
+
"reasoningEfforts",
|
|
25818
|
+
"reasoningEffort"
|
|
25819
|
+
]);
|
|
25820
|
+
var favoriteProjectionSchema = exports_external.object({
|
|
25821
|
+
harness: exports_external.enum(HARNESS_IDS),
|
|
25822
|
+
model: exports_external.string().max(120),
|
|
25823
|
+
providerId: exports_external.string().max(120),
|
|
25824
|
+
providerEndpoint: exports_external.string().max(60),
|
|
25825
|
+
extras: exports_external.partialRecord(ownedExtraSchema, exports_external.string().max(4096).nullable())
|
|
25826
|
+
});
|
|
25827
|
+
var modelFavoriteLinkSchema = exports_external.object({
|
|
25828
|
+
favoriteId: exports_external.uuid(),
|
|
25829
|
+
connectionId: exports_external.uuid(),
|
|
25830
|
+
appliedRevision: exports_external.number().int().positive(),
|
|
25831
|
+
projectionVersion: exports_external.number().int().positive(),
|
|
25832
|
+
baseline: favoriteProjectionSchema
|
|
25833
|
+
});
|
|
25834
|
+
var favoriteCaptureRequestSchema = exports_external.object({
|
|
25835
|
+
harness: exports_external.enum(HARNESS_IDS),
|
|
25836
|
+
name: exports_external.string().min(1).max(120),
|
|
25837
|
+
sourceFingerprint: exports_external.string().length(64),
|
|
25838
|
+
favoriteName: exports_external.string().trim().min(1).max(120),
|
|
25839
|
+
extractCredential: exports_external.boolean().optional(),
|
|
25840
|
+
linkSource: exports_external.boolean().optional()
|
|
25841
|
+
});
|
|
25842
|
+
var favoriteDetachRequestSchema = exports_external.object({ sourceFingerprint: exports_external.string().length(64) });
|
|
25843
|
+
var favoritePlanRequestSchema = exports_external.object({
|
|
25844
|
+
favoriteId: exports_external.uuid(),
|
|
25845
|
+
expectedRevision: exports_external.number().int().positive(),
|
|
25846
|
+
items: exports_external.array(exports_external.object({
|
|
25847
|
+
harness: exports_external.enum(HARNESS_IDS),
|
|
25848
|
+
connectionId: exports_external.uuid(),
|
|
25849
|
+
profile: exports_external.string().trim().min(1).max(120).refine((name) => !/[\\/]/.test(name)).optional(),
|
|
25850
|
+
existing: exports_external.boolean().default(false),
|
|
25851
|
+
mode: exports_external.enum(["save", "activate"]).default("save"),
|
|
25852
|
+
overwriteDiverged: exports_external.boolean().default(false),
|
|
25853
|
+
allowAuthOverwrite: exports_external.boolean().optional(),
|
|
25854
|
+
ignorePreference: exports_external.boolean().default(false)
|
|
25855
|
+
})).min(1).max(5).refine((items) => new Set(items.map((item) => item.harness)).size === items.length)
|
|
25856
|
+
});
|
|
25857
|
+
var favoriteApplyRequestSchema = exports_external.object({ requestId: exports_external.uuid() });
|
|
25858
|
+
var favoriteBackupContextSchema = exports_external.object({
|
|
25859
|
+
action: exports_external.enum(["create", "update", "delete", "capture", "detach", "apply", "restore"]),
|
|
25860
|
+
name: exports_external.string().optional(),
|
|
25861
|
+
tools: exports_external.array(exports_external.enum(HARNESS_IDS)).optional()
|
|
25862
|
+
});
|
|
25863
|
+
var favoriteRestoreRequestSchema = exports_external.object({
|
|
25864
|
+
fingerprint: exports_external.string().optional()
|
|
25865
|
+
});
|
|
25030
25866
|
// ../../packages/shared/src/schemas.ts
|
|
25031
25867
|
var MAX_NAME = 120;
|
|
25032
25868
|
var MAX_ENDPOINT_KEY = 60;
|
|
@@ -25102,6 +25938,7 @@ var transferEnvelopeSchema = exports_external.object({
|
|
|
25102
25938
|
})
|
|
25103
25939
|
});
|
|
25104
25940
|
var portableProfileSchema = exports_external.object({
|
|
25941
|
+
modelFavorite: modelFavoriteLinkSchema.optional(),
|
|
25105
25942
|
harness: harnessIdSchema,
|
|
25106
25943
|
name: entityName,
|
|
25107
25944
|
baseUrl: optionalText(MAX_URL),
|
|
@@ -25133,7 +25970,8 @@ var portableActiveSchema = exports_external.object({
|
|
|
25133
25970
|
var MAX_PORTABLE_ITEMS = 1e4;
|
|
25134
25971
|
var portablePayloadSchema = exports_external.object({
|
|
25135
25972
|
format: exports_external.literal("harness-switch-portable-config"),
|
|
25136
|
-
version: exports_external.literal(1),
|
|
25973
|
+
version: exports_external.union([exports_external.literal(1), exports_external.literal(2)]),
|
|
25974
|
+
favorites: exports_external.array(modelFavoriteSchema).max(1000).optional(),
|
|
25137
25975
|
exportedAt: exports_external.string(),
|
|
25138
25976
|
profiles: exports_external.array(portableProfileSchema).max(MAX_PORTABLE_ITEMS),
|
|
25139
25977
|
providers: exports_external.array(portableProviderSchema).max(MAX_PORTABLE_ITEMS).optional(),
|
|
@@ -25141,6 +25979,7 @@ var portablePayloadSchema = exports_external.object({
|
|
|
25141
25979
|
codexLoginCache: exports_external.string().optional()
|
|
25142
25980
|
});
|
|
25143
25981
|
var transferExportRequestSchema = exports_external.object({
|
|
25982
|
+
legacy: exports_external.boolean().optional(),
|
|
25144
25983
|
passphrase: optionalText(MAX_KEY),
|
|
25145
25984
|
includeCodexLoginCache: exports_external.boolean().optional()
|
|
25146
25985
|
});
|
|
@@ -25742,6 +26581,7 @@ class EnvironmentService {
|
|
|
25742
26581
|
env: join3(dataDir, "env.sh"),
|
|
25743
26582
|
sessions: join3(dataDir, "sessions.json"),
|
|
25744
26583
|
vault: join3(dataDir, "vault.json"),
|
|
26584
|
+
favorites: join3(dataDir, "model-favorites.json"),
|
|
25745
26585
|
github: join3(dataDir, "github.json"),
|
|
25746
26586
|
probeCache: join3(dataDir, "probe-cache.json")
|
|
25747
26587
|
};
|
|
@@ -25816,7 +26656,7 @@ import {
|
|
|
25816
26656
|
readFileSync as readFileSync2,
|
|
25817
26657
|
renameSync,
|
|
25818
26658
|
rmSync,
|
|
25819
|
-
statSync,
|
|
26659
|
+
statSync as statSync2,
|
|
25820
26660
|
writeFileSync
|
|
25821
26661
|
} from "node:fs";
|
|
25822
26662
|
import { basename as basename2, dirname as dirname3 } from "node:path";
|
|
@@ -25988,14 +26828,14 @@ class FileService {
|
|
|
25988
26828
|
}
|
|
25989
26829
|
modeOf(file2) {
|
|
25990
26830
|
try {
|
|
25991
|
-
return
|
|
26831
|
+
return statSync2(file2).mode & 511;
|
|
25992
26832
|
} catch {
|
|
25993
26833
|
return 384;
|
|
25994
26834
|
}
|
|
25995
26835
|
}
|
|
25996
26836
|
ownerOf(file2) {
|
|
25997
26837
|
try {
|
|
25998
|
-
const stat =
|
|
26838
|
+
const stat = statSync2(file2);
|
|
25999
26839
|
return { uid: stat.uid, gid: stat.gid };
|
|
26000
26840
|
} catch {
|
|
26001
26841
|
return { uid: this.environment.currentUser.uid, gid: this.environment.currentUser.gid };
|
|
@@ -26281,196 +27121,180 @@ function digest(kind, value) {
|
|
|
26281
27121
|
return createHash("sha256").update(`${kind}:${value}`).digest("base64url");
|
|
26282
27122
|
}
|
|
26283
27123
|
|
|
26284
|
-
// src/services/
|
|
26285
|
-
import {
|
|
26286
|
-
|
|
26287
|
-
var _dec = [
|
|
26288
|
-
inject(IEnvironmentService)
|
|
26289
|
-
];
|
|
26290
|
-
var _init = __decoratorStart(undefined);
|
|
27124
|
+
// src/services/favorite-backup.ts
|
|
27125
|
+
import { createHash as createHash2, randomUUID } from "node:crypto";
|
|
27126
|
+
import { join as join9 } from "node:path";
|
|
26291
27127
|
|
|
26292
|
-
|
|
26293
|
-
|
|
26294
|
-
|
|
26295
|
-
|
|
26296
|
-
|
|
26297
|
-
|
|
26298
|
-
|
|
26299
|
-
|
|
26300
|
-
|
|
26301
|
-
|
|
27128
|
+
// src/services/adapters/claude.ts
|
|
27129
|
+
import { join as join4 } from "node:path";
|
|
27130
|
+
|
|
27131
|
+
// src/services/adapters/favorites.ts
|
|
27132
|
+
var PROTOCOLS = ["openai-chat", "openai-responses", "anthropic-messages"];
|
|
27133
|
+
var FAVORITE_SUPPORT = {
|
|
27134
|
+
claude: ["anthropic-messages"],
|
|
27135
|
+
codex: ["openai-responses"],
|
|
27136
|
+
kimi: PROTOCOLS,
|
|
27137
|
+
pi: PROTOCOLS,
|
|
27138
|
+
dsh: PROTOCOLS
|
|
27139
|
+
};
|
|
27140
|
+
function projectFavorite(adapter, favorite, connection, previous) {
|
|
27141
|
+
const { id } = adapter;
|
|
27142
|
+
const resolved = resolveFavorite(favorite, connection);
|
|
27143
|
+
const { facts, preferences } = resolved;
|
|
27144
|
+
const extras = {};
|
|
27145
|
+
const represented = new Set;
|
|
27146
|
+
const put = (key, field) => {
|
|
27147
|
+
const value = facts[field];
|
|
27148
|
+
if (value !== undefined) {
|
|
27149
|
+
extras[key] = String(value);
|
|
27150
|
+
} else if (previous?.extras[key] !== undefined) {
|
|
27151
|
+
extras[key] = null;
|
|
27152
|
+
}
|
|
27153
|
+
represented.add(field);
|
|
27154
|
+
};
|
|
27155
|
+
const result = {
|
|
27156
|
+
projectionVersion: 1,
|
|
27157
|
+
projection: {
|
|
27158
|
+
harness: id,
|
|
27159
|
+
model: connection.requestModelId,
|
|
27160
|
+
providerId: connection.providerId,
|
|
27161
|
+
providerEndpoint: connection.endpointKey,
|
|
27162
|
+
extras
|
|
27163
|
+
},
|
|
27164
|
+
ownedFields: ["model", "providerId", "providerEndpoint"],
|
|
27165
|
+
set: {},
|
|
27166
|
+
remove: [],
|
|
27167
|
+
notRepresented: [],
|
|
27168
|
+
rendererDefaults: {},
|
|
27169
|
+
warnings: [],
|
|
27170
|
+
blockers: []
|
|
27171
|
+
};
|
|
27172
|
+
if (!FAVORITE_SUPPORT[id].includes(connection.protocol)) {
|
|
27173
|
+
result.blockers.push({ code: ERROR_CODES.favoriteProtocolUnsupported });
|
|
27174
|
+
}
|
|
27175
|
+
if (id === "kimi") {
|
|
27176
|
+
extras.providerType = {
|
|
27177
|
+
"openai-chat": "openai_legacy",
|
|
27178
|
+
"openai-responses": "openai_responses",
|
|
27179
|
+
"anthropic-messages": "anthropic"
|
|
27180
|
+
}[connection.protocol];
|
|
27181
|
+
put("maxContextSize", "contextWindow");
|
|
27182
|
+
}
|
|
27183
|
+
if (id === "pi" || id === "dsh") {
|
|
27184
|
+
extras.api = connection.protocol === "openai-chat" ? "openai-completions" : connection.protocol;
|
|
27185
|
+
put("contextWindow", "contextWindow");
|
|
27186
|
+
put("maxTokens", "maxOutputTokens");
|
|
27187
|
+
if (id === "pi") {
|
|
27188
|
+
put("reasoning", "reasoningSupported");
|
|
26302
27189
|
} else {
|
|
26303
|
-
|
|
26304
|
-
|
|
26305
|
-
|
|
26306
|
-
|
|
26307
|
-
|
|
26308
|
-
|
|
27190
|
+
extras.providerType = "custom";
|
|
27191
|
+
if (facts.reasoningSupported === false) {
|
|
27192
|
+
extras.reasoningEfforts = "false";
|
|
27193
|
+
} else if (facts.supportedReasoningEfforts?.length) {
|
|
27194
|
+
extras.reasoningEfforts = facts.supportedReasoningEfforts.join(",");
|
|
27195
|
+
} else if (previous?.extras.reasoningEfforts !== undefined) {
|
|
27196
|
+
extras.reasoningEfforts = null;
|
|
26309
27197
|
}
|
|
26310
|
-
|
|
26311
|
-
|
|
27198
|
+
represented.add("supportedReasoningEfforts");
|
|
27199
|
+
if (facts.reasoningSupported === false || facts.supportedReasoningEfforts?.length) {
|
|
27200
|
+
represented.add("reasoningSupported");
|
|
26312
27201
|
}
|
|
26313
|
-
return left.uid - right.uid || left.username.localeCompare(right.username);
|
|
26314
|
-
});
|
|
26315
|
-
}
|
|
26316
|
-
require(username) {
|
|
26317
|
-
const normalized = String(username ?? "").trim();
|
|
26318
|
-
const user = this.list().find((candidate) => candidate.username === normalized);
|
|
26319
|
-
if (!user) {
|
|
26320
|
-
throw new HttpError(404, `本地用户 ${normalized || "(empty)"} 不存在或未获准管理`, {
|
|
26321
|
-
code: ERROR_CODES.userNotManageable,
|
|
26322
|
-
params: { username: normalized || "(empty)" }
|
|
26323
|
-
});
|
|
26324
27202
|
}
|
|
26325
|
-
return user;
|
|
26326
27203
|
}
|
|
26327
|
-
|
|
26328
|
-
|
|
26329
|
-
|
|
26330
|
-
|
|
26331
|
-
|
|
26332
|
-
|
|
26333
|
-
|
|
26334
|
-
|
|
27204
|
+
if (id === "codex") {
|
|
27205
|
+
if (preferences.reasoningEffort) {
|
|
27206
|
+
const supported = adapter.fields.find((field) => field.key === "reasoningEffort")?.options?.some((option) => option.value === preferences.reasoningEffort);
|
|
27207
|
+
if (!supported) {
|
|
27208
|
+
result.blockers.push({ code: ERROR_CODES.favoriteProjectionUnsupported });
|
|
27209
|
+
} else {
|
|
27210
|
+
extras.reasoningEffort = preferences.reasoningEffort;
|
|
27211
|
+
}
|
|
27212
|
+
} else if (previous?.extras.reasoningEffort !== undefined) {
|
|
27213
|
+
extras.reasoningEffort = null;
|
|
27214
|
+
}
|
|
27215
|
+
} else if (preferences.reasoningEffort) {
|
|
27216
|
+
result.notRepresented.push("reasoningEffort");
|
|
27217
|
+
result.warnings.push({ code: ERROR_CODES.favoritePreferenceNotRepresented });
|
|
26335
27218
|
}
|
|
26336
|
-
|
|
26337
|
-
|
|
26338
|
-
text = readFileSync3("/etc/passwd", "utf8");
|
|
26339
|
-
} catch {
|
|
26340
|
-
return [];
|
|
27219
|
+
if (preferences.reasoningEffort && facts.supportedReasoningEfforts === undefined) {
|
|
27220
|
+
result.warnings.push({ code: ERROR_CODES.favoriteEffortUnverified });
|
|
26341
27221
|
}
|
|
26342
|
-
const
|
|
26343
|
-
|
|
26344
|
-
|
|
26345
|
-
`)) {
|
|
26346
|
-
if (!line || line.startsWith("#")) {
|
|
26347
|
-
continue;
|
|
27222
|
+
for (const field of Object.keys(facts)) {
|
|
27223
|
+
if (!represented.has(field)) {
|
|
27224
|
+
result.notRepresented.push(field);
|
|
26348
27225
|
}
|
|
26349
|
-
|
|
26350
|
-
|
|
26351
|
-
|
|
27226
|
+
}
|
|
27227
|
+
for (const field of adapter.fields) {
|
|
27228
|
+
if (["contextWindow", "maxContextSize", "maxTokens", "reasoning"].includes(field.key) && extras[field.key] == null && field.defaultValue) {
|
|
27229
|
+
result.rendererDefaults[field.key] = field.defaultValue;
|
|
26352
27230
|
}
|
|
26353
|
-
|
|
26354
|
-
|
|
26355
|
-
|
|
26356
|
-
|
|
26357
|
-
|
|
27231
|
+
}
|
|
27232
|
+
result.set = {
|
|
27233
|
+
model: connection.requestModelId,
|
|
27234
|
+
providerId: connection.providerId,
|
|
27235
|
+
providerEndpoint: connection.endpointKey
|
|
27236
|
+
};
|
|
27237
|
+
for (const [key, value] of Object.entries(extras)) {
|
|
27238
|
+
result.ownedFields.push(`extras.${key}`);
|
|
27239
|
+
if (value === null) {
|
|
27240
|
+
result.remove.push(`extras.${key}`);
|
|
27241
|
+
} else {
|
|
27242
|
+
result.set[`extras.${key}`] = value;
|
|
26358
27243
|
}
|
|
26359
|
-
users.push({ username, uid, gid, homeDir });
|
|
26360
27244
|
}
|
|
26361
|
-
return
|
|
27245
|
+
return result;
|
|
26362
27246
|
}
|
|
26363
|
-
function
|
|
26364
|
-
|
|
26365
|
-
|
|
26366
|
-
|
|
26367
|
-
|
|
26368
|
-
|
|
27247
|
+
function extractFavorite(adapter, profile) {
|
|
27248
|
+
const { id } = adapter;
|
|
27249
|
+
const protocol = adapter.completionProtocol?.(profile);
|
|
27250
|
+
if (!profile.model || !protocol || !FAVORITE_SUPPORT[id].includes(protocol) || id === "dsh" && profile.extras.providerType === "official" || id === "kimi" && (!profile.extras.providerType || profile.extras.providerType === "kimi") || id === "claude" && /\[[^\]]+\]/.test(profile.model)) {
|
|
27251
|
+
throw new HttpError(409, ERROR_CODES.favoriteProjectionUnsupported, {
|
|
27252
|
+
code: ERROR_CODES.favoriteProjectionUnsupported
|
|
27253
|
+
});
|
|
26369
27254
|
}
|
|
26370
|
-
}
|
|
26371
|
-
|
|
26372
|
-
|
|
26373
|
-
|
|
26374
|
-
}
|
|
26375
|
-
|
|
26376
|
-
// src/http/middleware.ts
|
|
26377
|
-
function createOriginGuard() {
|
|
26378
|
-
return async (c, next) => {
|
|
26379
|
-
if (c.req.method !== "GET" && c.req.method !== "HEAD" && c.req.method !== "OPTIONS") {
|
|
26380
|
-
const origin = c.req.header("origin");
|
|
26381
|
-
if (origin) {
|
|
26382
|
-
const host = c.req.header("host");
|
|
26383
|
-
const allowed = [`http://${host}`, `https://${host}`];
|
|
26384
|
-
if (!allowed.includes(origin)) {
|
|
26385
|
-
throw new HttpError(403, "cross-origin request denied", {
|
|
26386
|
-
code: ERROR_CODES.crossOriginDenied
|
|
26387
|
-
});
|
|
26388
|
-
}
|
|
26389
|
-
}
|
|
27255
|
+
const facts = {};
|
|
27256
|
+
const numeric = (field, key) => {
|
|
27257
|
+
if (profile.extras[key]) {
|
|
27258
|
+
facts[field] = Number(profile.extras[key]);
|
|
26390
27259
|
}
|
|
26391
|
-
await next();
|
|
26392
27260
|
};
|
|
26393
|
-
|
|
26394
|
-
|
|
26395
|
-
|
|
26396
|
-
|
|
26397
|
-
|
|
26398
|
-
|
|
26399
|
-
|
|
26400
|
-
|
|
26401
|
-
|
|
26402
|
-
|
|
26403
|
-
});
|
|
27261
|
+
if (id === "pi" || id === "dsh") {
|
|
27262
|
+
numeric("contextWindow", "contextWindow");
|
|
27263
|
+
numeric("maxOutputTokens", "maxTokens");
|
|
27264
|
+
if (id === "pi" && profile.extras.reasoning) {
|
|
27265
|
+
if (!["true", "false"].includes(profile.extras.reasoning)) {
|
|
27266
|
+
throw new HttpError(409, ERROR_CODES.favoriteProjectionUnsupported, {
|
|
27267
|
+
code: ERROR_CODES.favoriteProjectionUnsupported
|
|
27268
|
+
});
|
|
27269
|
+
}
|
|
27270
|
+
facts.reasoningSupported = profile.extras.reasoning === "true";
|
|
26404
27271
|
}
|
|
26405
|
-
|
|
26406
|
-
|
|
26407
|
-
|
|
26408
|
-
|
|
26409
|
-
|
|
26410
|
-
|
|
26411
|
-
// src/http/validate.ts
|
|
26412
|
-
async function readJsonBody(c, schema) {
|
|
26413
|
-
const raw2 = await c.req.json().catch(() => {
|
|
26414
|
-
throw new HttpError(400, "invalid json", { code: ERROR_CODES.invalidRequest });
|
|
26415
|
-
});
|
|
26416
|
-
return parseWith(schema, raw2);
|
|
26417
|
-
}
|
|
26418
|
-
async function readOptionalJsonBody(c, schema) {
|
|
26419
|
-
return parseWith(schema, await c.req.json().catch(() => ({})));
|
|
26420
|
-
}
|
|
26421
|
-
function parseWith(schema, value) {
|
|
26422
|
-
const result = schema.safeParse(value);
|
|
26423
|
-
if (!result.success) {
|
|
26424
|
-
throw new HttpError(400, formatSchemaError(result.error), {
|
|
26425
|
-
code: ERROR_CODES.invalidRequest,
|
|
26426
|
-
params: { fields: result.error.issues.map((issue2) => issue2.path.join(".")).join(", ") }
|
|
26427
|
-
});
|
|
26428
|
-
}
|
|
26429
|
-
return result.data;
|
|
26430
|
-
}
|
|
26431
|
-
|
|
26432
|
-
// src/http/routes/auth.ts
|
|
26433
|
-
function createAuthRoutes(services) {
|
|
26434
|
-
const app = new Hono2;
|
|
26435
|
-
const auth = services.get(IAuthService);
|
|
26436
|
-
const environment = services.get(IEnvironmentService);
|
|
26437
|
-
app.post("/login", async (c) => {
|
|
26438
|
-
const body = await readJsonBody(c, loginRequestSchema);
|
|
26439
|
-
const token = auth.login(body.password);
|
|
26440
|
-
if (!token) {
|
|
26441
|
-
throw new HttpError(401, "invalid password", { code: ERROR_CODES.invalidPassword });
|
|
27272
|
+
if (id === "dsh" && profile.extras.reasoningEfforts) {
|
|
27273
|
+
if (profile.extras.reasoningEfforts === "false") {
|
|
27274
|
+
facts.reasoningSupported = false;
|
|
27275
|
+
} else {
|
|
27276
|
+
facts.supportedReasoningEfforts = profile.extras.reasoningEfforts.split(",").map((effort2) => effort2.trim());
|
|
27277
|
+
}
|
|
26442
27278
|
}
|
|
26443
|
-
|
|
26444
|
-
|
|
26445
|
-
|
|
26446
|
-
|
|
26447
|
-
|
|
27279
|
+
}
|
|
27280
|
+
if (id === "kimi") {
|
|
27281
|
+
numeric("contextWindow", "maxContextSize");
|
|
27282
|
+
}
|
|
27283
|
+
const parsed = modelFactsSchema.safeParse(facts);
|
|
27284
|
+
const effort = favoriteEffortSchema.optional().safeParse(id === "codex" ? profile.extras.reasoningEffort || undefined : undefined);
|
|
27285
|
+
if (!parsed.success || !effort.success) {
|
|
27286
|
+
throw new HttpError(409, ERROR_CODES.favoriteProjectionUnsupported, {
|
|
27287
|
+
code: ERROR_CODES.favoriteProjectionUnsupported
|
|
26448
27288
|
});
|
|
26449
|
-
|
|
26450
|
-
|
|
26451
|
-
|
|
26452
|
-
|
|
26453
|
-
|
|
26454
|
-
|
|
26455
|
-
}
|
|
26456
|
-
app.get("/session", (c) => {
|
|
26457
|
-
const token = getCookie(c, environment.cookieName);
|
|
26458
|
-
if (!auth.isAuthenticated(token)) {
|
|
26459
|
-
throw new HttpError(401, "authentication required", {
|
|
26460
|
-
code: ERROR_CODES.authenticationRequired
|
|
26461
|
-
});
|
|
26462
|
-
}
|
|
26463
|
-
return c.json({ authenticated: true, currentUser: auth.userForToken(token) });
|
|
26464
|
-
});
|
|
26465
|
-
return app;
|
|
27289
|
+
}
|
|
27290
|
+
return {
|
|
27291
|
+
defaults: parsed.data,
|
|
27292
|
+
preferences: effort.data ? { reasoningEffort: effort.data } : {},
|
|
27293
|
+
protocol,
|
|
27294
|
+
requestModelId: profile.model
|
|
27295
|
+
};
|
|
26466
27296
|
}
|
|
26467
27297
|
|
|
26468
|
-
// src/services/backup.ts
|
|
26469
|
-
import { basename as basename3, join as join9, resolve as resolve3 } from "node:path";
|
|
26470
|
-
|
|
26471
|
-
// src/services/adapters/claude.ts
|
|
26472
|
-
import { join as join4 } from "node:path";
|
|
26473
|
-
|
|
26474
27298
|
// src/services/adapters/base.ts
|
|
26475
27299
|
var REQUIRED_CODES = {
|
|
26476
27300
|
model: ERROR_CODES.adapterModelRequired,
|
|
@@ -26483,10 +27307,22 @@ var REQUIRED_PROSE = {
|
|
|
26483
27307
|
|
|
26484
27308
|
class BaseAdapter {
|
|
26485
27309
|
environment;
|
|
27310
|
+
completionProtocol(_profile) {
|
|
27311
|
+
return;
|
|
27312
|
+
}
|
|
26486
27313
|
requires = [];
|
|
26487
27314
|
constructor(environment) {
|
|
26488
27315
|
this.environment = environment;
|
|
26489
27316
|
}
|
|
27317
|
+
get favoriteSupport() {
|
|
27318
|
+
return FAVORITE_SUPPORT[this.id];
|
|
27319
|
+
}
|
|
27320
|
+
projectFavorite(favorite, connection, previous) {
|
|
27321
|
+
return projectFavorite(this, favorite, connection, previous);
|
|
27322
|
+
}
|
|
27323
|
+
extractFavorite(profile) {
|
|
27324
|
+
return extractFavorite(this, profile);
|
|
27325
|
+
}
|
|
26490
27326
|
validate(profile) {
|
|
26491
27327
|
const harness = HARNESS_LABELS[this.id];
|
|
26492
27328
|
for (const value of this.requires) {
|
|
@@ -27819,6 +28655,18 @@ function tierFields(tier) {
|
|
|
27819
28655
|
}
|
|
27820
28656
|
|
|
27821
28657
|
class ClaudeAdapter extends BaseAdapter {
|
|
28658
|
+
validate(profile) {
|
|
28659
|
+
super.validate(profile);
|
|
28660
|
+
if (profile.favoriteManaged && parseEnvLines(profile.extras.extraEnv).some(([key]) => [MODEL_VAR, BASE_URL_VAR, ...AUTH_VARS].includes(key))) {
|
|
28661
|
+
throw new HttpError(409, ERROR_CODES.favoriteRawOverrideConflict, {
|
|
28662
|
+
code: ERROR_CODES.favoriteRawOverrideConflict
|
|
28663
|
+
});
|
|
28664
|
+
}
|
|
28665
|
+
}
|
|
28666
|
+
extractFavorite(profile) {
|
|
28667
|
+
this.validate({ ...profile, favoriteManaged: true });
|
|
28668
|
+
return super.extractFavorite(profile);
|
|
28669
|
+
}
|
|
27822
28670
|
id = "claude";
|
|
27823
28671
|
mode = "replace";
|
|
27824
28672
|
envVarNames = [
|
|
@@ -28363,7 +29211,14 @@ class DshAdapter extends BaseAdapter {
|
|
|
28363
29211
|
this.validate(profile);
|
|
28364
29212
|
const { official, providerId: providerId2, credentialRef } = this.route(profile);
|
|
28365
29213
|
const settings = parseYamlDocument(current[SETTINGS2]);
|
|
28366
|
-
|
|
29214
|
+
let models = this.models(profile, official);
|
|
29215
|
+
if (profile.favoriteManaged && !official) {
|
|
29216
|
+
const prior = settings.getIn(["llm-pi-ai", "providers", providerId2, "models"]);
|
|
29217
|
+
const parsed = exports_external.array(exports_external.object({ id: exports_external.string() }).passthrough()).safeParse(isYamlNode(prior) ? prior.toJSON() : prior);
|
|
29218
|
+
if (parsed.success) {
|
|
29219
|
+
models = models.map((model) => model.id === profile.model ? model : parsed.data.find((entry) => entry.id === model.id) ?? model);
|
|
29220
|
+
}
|
|
29221
|
+
}
|
|
28367
29222
|
if (official) {
|
|
28368
29223
|
settings.setIn(["llm-deepseek", "apiKeyEnv"], credentialRef);
|
|
28369
29224
|
settings.setIn(["llm-deepseek", "baseURL"], profile.baseUrl || "https://api.deepseek.com");
|
|
@@ -29004,16 +29859,410 @@ __runInitializers(_init, 1, AdapterRegistry);
|
|
|
29004
29859
|
__decoratorMetadata(_init, AdapterRegistry);
|
|
29005
29860
|
let _AdapterRegistry = AdapterRegistry;
|
|
29006
29861
|
|
|
29007
|
-
// src/services/backup.ts
|
|
29008
|
-
var
|
|
29009
|
-
|
|
29010
|
-
|
|
29011
|
-
|
|
29012
|
-
|
|
29013
|
-
|
|
29014
|
-
|
|
29015
|
-
|
|
29016
|
-
|
|
29862
|
+
// src/services/favorite-backup.ts
|
|
29863
|
+
var sealed = exports_external.object({ iv: exports_external.string(), tag: exports_external.string(), data: exports_external.string() });
|
|
29864
|
+
var entrySchema = exports_external.object({
|
|
29865
|
+
id: exports_external.uuid(),
|
|
29866
|
+
createdAt: exports_external.iso.datetime(),
|
|
29867
|
+
reason: exports_external.enum(["manual", "change", "apply", "restore"]),
|
|
29868
|
+
snapshot: sealed,
|
|
29869
|
+
context: sealed.optional()
|
|
29870
|
+
});
|
|
29871
|
+
var historySchema = exports_external.object({ version: exports_external.literal(1), entries: exports_external.array(entrySchema).max(21) });
|
|
29872
|
+
var snapshotSchema = exports_external.object({
|
|
29873
|
+
version: exports_external.literal(1),
|
|
29874
|
+
user: exports_external.string(),
|
|
29875
|
+
files: exports_external.array(exports_external.object({ key: exports_external.string(), path: exports_external.string(), content: exports_external.string().nullable() }))
|
|
29876
|
+
});
|
|
29877
|
+
var IFavoriteBackupService = createDecorator("favoriteBackupService");
|
|
29878
|
+
var _dec = [
|
|
29879
|
+
inject(IEnvironmentService, IFileService, ICryptoService, IAdapterRegistry)
|
|
29880
|
+
];
|
|
29881
|
+
var _init = __decoratorStart(undefined);
|
|
29882
|
+
|
|
29883
|
+
class FavoriteBackupService {
|
|
29884
|
+
environment;
|
|
29885
|
+
files;
|
|
29886
|
+
crypto;
|
|
29887
|
+
adapters;
|
|
29888
|
+
depth = 0;
|
|
29889
|
+
constructor(environment, files, crypto2, adapters) {
|
|
29890
|
+
this.environment = environment;
|
|
29891
|
+
this.files = files;
|
|
29892
|
+
this.crypto = crypto2;
|
|
29893
|
+
this.adapters = adapters;
|
|
29894
|
+
}
|
|
29895
|
+
list() {
|
|
29896
|
+
return this.history().entries.map((entry) => this.summary(entry));
|
|
29897
|
+
}
|
|
29898
|
+
create(reason = "manual", context) {
|
|
29899
|
+
const history = this.history();
|
|
29900
|
+
const entry = {
|
|
29901
|
+
id: randomUUID(),
|
|
29902
|
+
createdAt: new Date().toISOString(),
|
|
29903
|
+
reason,
|
|
29904
|
+
snapshot: this.crypto.encrypt(JSON.stringify(this.capture())),
|
|
29905
|
+
context: context ? this.crypto.encrypt(JSON.stringify(favoriteBackupContextSchema.parse(context))) : undefined
|
|
29906
|
+
};
|
|
29907
|
+
const prior = reason === "manual" ? history.entries.filter((item) => item.reason !== "manual") : history.entries;
|
|
29908
|
+
const entries = [entry, ...prior];
|
|
29909
|
+
const manual = entries.filter((item) => item.reason === "manual").slice(0, 1);
|
|
29910
|
+
const automatic = entries.filter((item) => item.reason !== "manual").slice(0, 20);
|
|
29911
|
+
this.files.writeJson(this.path("history.json"), {
|
|
29912
|
+
version: 1,
|
|
29913
|
+
entries: [...manual, ...automatic].toSorted((a, b) => b.createdAt.localeCompare(a.createdAt))
|
|
29914
|
+
});
|
|
29915
|
+
return this.summary(entry);
|
|
29916
|
+
}
|
|
29917
|
+
protect(reason, operation, context) {
|
|
29918
|
+
if (this.depth === 0) {
|
|
29919
|
+
this.create(reason, context);
|
|
29920
|
+
}
|
|
29921
|
+
this.depth++;
|
|
29922
|
+
try {
|
|
29923
|
+
return operation();
|
|
29924
|
+
} finally {
|
|
29925
|
+
this.depth--;
|
|
29926
|
+
}
|
|
29927
|
+
}
|
|
29928
|
+
preview(id) {
|
|
29929
|
+
const entry = this.history().entries.find((item) => item.id === id);
|
|
29930
|
+
if (!entry) {
|
|
29931
|
+
throw this.invalid();
|
|
29932
|
+
}
|
|
29933
|
+
const target = this.decode(entry.snapshot);
|
|
29934
|
+
const current = this.capture();
|
|
29935
|
+
return {
|
|
29936
|
+
id,
|
|
29937
|
+
fingerprint: createHash2("sha256").update(JSON.stringify({ id, current, target })).digest("hex"),
|
|
29938
|
+
files: target.files.map((file2, index) => ({
|
|
29939
|
+
key: file2.key,
|
|
29940
|
+
path: file2.path,
|
|
29941
|
+
action: file2.content === current.files[index].content ? "unchanged" : file2.content === null ? "delete" : current.files[index].content === null ? "create" : "replace"
|
|
29942
|
+
}))
|
|
29943
|
+
};
|
|
29944
|
+
}
|
|
29945
|
+
restore(id, fingerprint) {
|
|
29946
|
+
if (fingerprint && this.preview(id).fingerprint !== fingerprint) {
|
|
29947
|
+
throw new HttpError(409, ERROR_CODES.favoriteBackupStale, {
|
|
29948
|
+
code: ERROR_CODES.favoriteBackupStale
|
|
29949
|
+
});
|
|
29950
|
+
}
|
|
29951
|
+
const entry = this.history().entries.find((item) => item.id === id);
|
|
29952
|
+
if (!entry) {
|
|
29953
|
+
throw this.invalid();
|
|
29954
|
+
}
|
|
29955
|
+
const target = this.decode(entry.snapshot);
|
|
29956
|
+
const before = this.capture();
|
|
29957
|
+
this.create("restore", { action: "restore", name: entry.createdAt });
|
|
29958
|
+
this.files.writeJson(this.path("pending.json"), this.crypto.encrypt(JSON.stringify(before)));
|
|
29959
|
+
try {
|
|
29960
|
+
this.write(target);
|
|
29961
|
+
this.files.remove(this.path("pending.json"));
|
|
29962
|
+
} catch {
|
|
29963
|
+
this.recover();
|
|
29964
|
+
throw this.invalid();
|
|
29965
|
+
}
|
|
29966
|
+
}
|
|
29967
|
+
recover() {
|
|
29968
|
+
const raw2 = this.files.readRegularOptional(this.path("pending.json"));
|
|
29969
|
+
if (raw2 === undefined) {
|
|
29970
|
+
return;
|
|
29971
|
+
}
|
|
29972
|
+
try {
|
|
29973
|
+
this.write(this.decode(sealed.parse(JSON.parse(raw2))));
|
|
29974
|
+
this.files.remove(this.path("pending.json"));
|
|
29975
|
+
} catch {
|
|
29976
|
+
throw new HttpError(409, ERROR_CODES.favoriteBackupRecoveryFailed, {
|
|
29977
|
+
code: ERROR_CODES.favoriteBackupRecoveryFailed
|
|
29978
|
+
});
|
|
29979
|
+
}
|
|
29980
|
+
}
|
|
29981
|
+
destinations() {
|
|
29982
|
+
return [
|
|
29983
|
+
...["favorites", "profiles", "vault", "active", "env"].map((key) => ({
|
|
29984
|
+
key: `store/${key}`,
|
|
29985
|
+
path: this.environment.files[key]
|
|
29986
|
+
})),
|
|
29987
|
+
...this.adapters.all().flatMap((adapter) => adapter.targets().map((target) => ({
|
|
29988
|
+
key: `${adapter.id}/${target.key}`,
|
|
29989
|
+
path: target.path
|
|
29990
|
+
})))
|
|
29991
|
+
];
|
|
29992
|
+
}
|
|
29993
|
+
summary(entry) {
|
|
29994
|
+
const { snapshot: _snapshot, context, ...summary } = entry;
|
|
29995
|
+
try {
|
|
29996
|
+
return {
|
|
29997
|
+
...summary,
|
|
29998
|
+
context: context ? favoriteBackupContextSchema.parse(JSON.parse(this.crypto.decrypt(context))) : undefined
|
|
29999
|
+
};
|
|
30000
|
+
} catch {
|
|
30001
|
+
throw this.invalid();
|
|
30002
|
+
}
|
|
30003
|
+
}
|
|
30004
|
+
capture() {
|
|
30005
|
+
return {
|
|
30006
|
+
version: 1,
|
|
30007
|
+
user: this.environment.dataDir,
|
|
30008
|
+
files: this.destinations().map((target) => {
|
|
30009
|
+
this.files.assertManaged(target.path);
|
|
30010
|
+
return { ...target, content: this.files.readOptional(target.path) ?? null };
|
|
30011
|
+
})
|
|
30012
|
+
};
|
|
30013
|
+
}
|
|
30014
|
+
decode(value) {
|
|
30015
|
+
try {
|
|
30016
|
+
const snapshot = snapshotSchema.parse(JSON.parse(this.crypto.decrypt(value)));
|
|
30017
|
+
const destinations = this.destinations();
|
|
30018
|
+
if (snapshot.user !== this.environment.dataDir || snapshot.files.length !== destinations.length || destinations.some((target, index) => {
|
|
30019
|
+
const saved = snapshot.files[index];
|
|
30020
|
+
return saved.key !== target.key || saved.path !== target.path;
|
|
30021
|
+
})) {
|
|
30022
|
+
throw this.invalid();
|
|
30023
|
+
}
|
|
30024
|
+
return snapshot;
|
|
30025
|
+
} catch {
|
|
30026
|
+
throw this.invalid();
|
|
30027
|
+
}
|
|
30028
|
+
}
|
|
30029
|
+
write(snapshot) {
|
|
30030
|
+
const destinations = this.destinations();
|
|
30031
|
+
for (const target of destinations) {
|
|
30032
|
+
this.files.assertManaged(target.path);
|
|
30033
|
+
}
|
|
30034
|
+
for (const [index, target] of destinations.entries()) {
|
|
30035
|
+
const content = snapshot.files[index].content;
|
|
30036
|
+
if (content === null) {
|
|
30037
|
+
this.files.remove(target.path);
|
|
30038
|
+
} else {
|
|
30039
|
+
this.files.writeUserSecretFile(target.path, content);
|
|
30040
|
+
}
|
|
30041
|
+
}
|
|
30042
|
+
}
|
|
30043
|
+
history() {
|
|
30044
|
+
const raw2 = this.files.readRegularOptional(this.path("history.json"));
|
|
30045
|
+
if (raw2 === undefined) {
|
|
30046
|
+
return { version: 1, entries: [] };
|
|
30047
|
+
}
|
|
30048
|
+
try {
|
|
30049
|
+
return historySchema.parse(JSON.parse(raw2));
|
|
30050
|
+
} catch {
|
|
30051
|
+
throw this.invalid();
|
|
30052
|
+
}
|
|
30053
|
+
}
|
|
30054
|
+
path(file2) {
|
|
30055
|
+
return join9(this.environment.dataDir, "favorite-backups", file2);
|
|
30056
|
+
}
|
|
30057
|
+
invalid() {
|
|
30058
|
+
return new HttpError(409, ERROR_CODES.favoriteBackupInvalid, {
|
|
30059
|
+
code: ERROR_CODES.favoriteBackupInvalid
|
|
30060
|
+
});
|
|
30061
|
+
}
|
|
30062
|
+
}
|
|
30063
|
+
FavoriteBackupService = __decorateElement(_init, 0, "FavoriteBackupService", _dec, FavoriteBackupService);
|
|
30064
|
+
__runInitializers(_init, 1, FavoriteBackupService);
|
|
30065
|
+
__decoratorMetadata(_init, FavoriteBackupService);
|
|
30066
|
+
let _FavoriteBackupService = FavoriteBackupService;
|
|
30067
|
+
|
|
30068
|
+
// src/services/users.ts
|
|
30069
|
+
import { existsSync as existsSync4, readFileSync as readFileSync3 } from "node:fs";
|
|
30070
|
+
var IUserService = createDecorator("userService");
|
|
30071
|
+
var _dec = [
|
|
30072
|
+
inject(IEnvironmentService)
|
|
30073
|
+
];
|
|
30074
|
+
var _init = __decoratorStart(undefined);
|
|
30075
|
+
|
|
30076
|
+
class UserService {
|
|
30077
|
+
environment;
|
|
30078
|
+
constructor(environment) {
|
|
30079
|
+
this.environment = environment;
|
|
30080
|
+
}
|
|
30081
|
+
list() {
|
|
30082
|
+
const users = discoverUsers();
|
|
30083
|
+
const existing = users.find((user) => user.username === this.environment.defaultUser.username);
|
|
30084
|
+
if (existing) {
|
|
30085
|
+
Object.assign(existing, this.environment.defaultUser);
|
|
30086
|
+
} else {
|
|
30087
|
+
users.push(this.environment.defaultUser);
|
|
30088
|
+
}
|
|
30089
|
+
const allow = parseAllowList();
|
|
30090
|
+
return users.filter((user) => user.username === this.environment.defaultUser.username || !allow || allow.has(user.username)).toSorted((left, right) => {
|
|
30091
|
+
if (left.username === this.environment.defaultUser.username) {
|
|
30092
|
+
return -1;
|
|
30093
|
+
}
|
|
30094
|
+
if (right.username === this.environment.defaultUser.username) {
|
|
30095
|
+
return 1;
|
|
30096
|
+
}
|
|
30097
|
+
return left.uid - right.uid || left.username.localeCompare(right.username);
|
|
30098
|
+
});
|
|
30099
|
+
}
|
|
30100
|
+
require(username) {
|
|
30101
|
+
const normalized = String(username ?? "").trim();
|
|
30102
|
+
const user = this.list().find((candidate) => candidate.username === normalized);
|
|
30103
|
+
if (!user) {
|
|
30104
|
+
throw new HttpError(404, `本地用户 ${normalized || "(empty)"} 不存在或未获准管理`, {
|
|
30105
|
+
code: ERROR_CODES.userNotManageable,
|
|
30106
|
+
params: { username: normalized || "(empty)" }
|
|
30107
|
+
});
|
|
30108
|
+
}
|
|
30109
|
+
return user;
|
|
30110
|
+
}
|
|
30111
|
+
}
|
|
30112
|
+
UserService = __decorateElement(_init, 0, "UserService", _dec, UserService);
|
|
30113
|
+
__runInitializers(_init, 1, UserService);
|
|
30114
|
+
__decoratorMetadata(_init, UserService);
|
|
30115
|
+
let _UserService = UserService;
|
|
30116
|
+
function discoverUsers() {
|
|
30117
|
+
if (process.platform === "win32") {
|
|
30118
|
+
return [];
|
|
30119
|
+
}
|
|
30120
|
+
let text = "";
|
|
30121
|
+
try {
|
|
30122
|
+
text = readFileSync3("/etc/passwd", "utf8");
|
|
30123
|
+
} catch {
|
|
30124
|
+
return [];
|
|
30125
|
+
}
|
|
30126
|
+
const uidMin = readUidMin();
|
|
30127
|
+
const users = [];
|
|
30128
|
+
for (const line of text.split(`
|
|
30129
|
+
`)) {
|
|
30130
|
+
if (!line || line.startsWith("#")) {
|
|
30131
|
+
continue;
|
|
30132
|
+
}
|
|
30133
|
+
const fields = line.split(":");
|
|
30134
|
+
if (fields.length < 7) {
|
|
30135
|
+
continue;
|
|
30136
|
+
}
|
|
30137
|
+
const [username, , uidText, gidText, , homeDir, shell] = fields;
|
|
30138
|
+
const uid = Number(uidText);
|
|
30139
|
+
const gid = Number(gidText);
|
|
30140
|
+
if (!username || !homeDir?.startsWith("/") || !Number.isInteger(uid) || !Number.isInteger(gid) || uid !== 0 && uid < uidMin || /(?:nologin|false)$/.test(shell ?? "") || !existsSync4(homeDir)) {
|
|
30141
|
+
continue;
|
|
30142
|
+
}
|
|
30143
|
+
users.push({ username, uid, gid, homeDir });
|
|
30144
|
+
}
|
|
30145
|
+
return users;
|
|
30146
|
+
}
|
|
30147
|
+
function readUidMin() {
|
|
30148
|
+
try {
|
|
30149
|
+
const match2 = /^\s*UID_MIN\s+(\d+)/m.exec(readFileSync3("/etc/login.defs", "utf8"));
|
|
30150
|
+
return match2 ? Number(match2[1]) : 1000;
|
|
30151
|
+
} catch {
|
|
30152
|
+
return 1000;
|
|
30153
|
+
}
|
|
30154
|
+
}
|
|
30155
|
+
function parseAllowList() {
|
|
30156
|
+
const value = process.env.HSW_USERS?.trim();
|
|
30157
|
+
return value ? new Set(value.split(",").map((item) => item.trim()).filter(Boolean)) : undefined;
|
|
30158
|
+
}
|
|
30159
|
+
|
|
30160
|
+
// src/http/middleware.ts
|
|
30161
|
+
function createOriginGuard() {
|
|
30162
|
+
return async (c, next) => {
|
|
30163
|
+
if (c.req.method !== "GET" && c.req.method !== "HEAD" && c.req.method !== "OPTIONS") {
|
|
30164
|
+
const origin = c.req.header("origin");
|
|
30165
|
+
if (origin) {
|
|
30166
|
+
const host = c.req.header("host");
|
|
30167
|
+
const allowed = [`http://${host}`, `https://${host}`];
|
|
30168
|
+
if (!allowed.includes(origin)) {
|
|
30169
|
+
throw new HttpError(403, "cross-origin request denied", {
|
|
30170
|
+
code: ERROR_CODES.crossOriginDenied
|
|
30171
|
+
});
|
|
30172
|
+
}
|
|
30173
|
+
}
|
|
30174
|
+
}
|
|
30175
|
+
await next();
|
|
30176
|
+
};
|
|
30177
|
+
}
|
|
30178
|
+
function createAuthGuard(services) {
|
|
30179
|
+
const auth = services.get(IAuthService);
|
|
30180
|
+
const environment = services.get(IEnvironmentService);
|
|
30181
|
+
const users = services.get(IUserService);
|
|
30182
|
+
return async (c, next) => {
|
|
30183
|
+
const token = getCookie(c, environment.cookieName);
|
|
30184
|
+
if (!auth.isAuthenticated(token)) {
|
|
30185
|
+
throw new HttpError(401, "authentication required", {
|
|
30186
|
+
code: ERROR_CODES.authenticationRequired
|
|
30187
|
+
});
|
|
30188
|
+
}
|
|
30189
|
+
const username = auth.userForToken(token) ?? environment.defaultUser.username;
|
|
30190
|
+
const user = users.require(username);
|
|
30191
|
+
await environment.runAsUser(user, () => {
|
|
30192
|
+
services.get(IFavoriteBackupService).recover();
|
|
30193
|
+
return next();
|
|
30194
|
+
});
|
|
30195
|
+
};
|
|
30196
|
+
}
|
|
30197
|
+
|
|
30198
|
+
// src/http/validate.ts
|
|
30199
|
+
async function readJsonBody(c, schema) {
|
|
30200
|
+
const raw2 = await c.req.json().catch(() => {
|
|
30201
|
+
throw new HttpError(400, "invalid json", { code: ERROR_CODES.invalidRequest });
|
|
30202
|
+
});
|
|
30203
|
+
return parseWith(schema, raw2);
|
|
30204
|
+
}
|
|
30205
|
+
async function readOptionalJsonBody(c, schema) {
|
|
30206
|
+
return parseWith(schema, await c.req.json().catch(() => ({})));
|
|
30207
|
+
}
|
|
30208
|
+
function parseWith(schema, value) {
|
|
30209
|
+
const result = schema.safeParse(value);
|
|
30210
|
+
if (!result.success) {
|
|
30211
|
+
throw new HttpError(400, formatSchemaError(result.error), {
|
|
30212
|
+
code: ERROR_CODES.invalidRequest,
|
|
30213
|
+
params: { fields: result.error.issues.map((issue2) => issue2.path.join(".")).join(", ") }
|
|
30214
|
+
});
|
|
30215
|
+
}
|
|
30216
|
+
return result.data;
|
|
30217
|
+
}
|
|
30218
|
+
|
|
30219
|
+
// src/http/routes/auth.ts
|
|
30220
|
+
function createAuthRoutes(services) {
|
|
30221
|
+
const app = new Hono2;
|
|
30222
|
+
const auth = services.get(IAuthService);
|
|
30223
|
+
const environment = services.get(IEnvironmentService);
|
|
30224
|
+
app.post("/login", async (c) => {
|
|
30225
|
+
const body = await readJsonBody(c, loginRequestSchema);
|
|
30226
|
+
const token = auth.login(body.password);
|
|
30227
|
+
if (!token) {
|
|
30228
|
+
throw new HttpError(401, "invalid password", { code: ERROR_CODES.invalidPassword });
|
|
30229
|
+
}
|
|
30230
|
+
setCookie(c, environment.cookieName, token, {
|
|
30231
|
+
httpOnly: true,
|
|
30232
|
+
sameSite: "Lax",
|
|
30233
|
+
path: "/",
|
|
30234
|
+
maxAge: environment.sessionTtlMs / 1000
|
|
30235
|
+
});
|
|
30236
|
+
return c.json({ authenticated: true, currentUser: environment.defaultUser.username });
|
|
30237
|
+
});
|
|
30238
|
+
app.post("/logout", (c) => {
|
|
30239
|
+
auth.logout(getCookie(c, environment.cookieName));
|
|
30240
|
+
deleteCookie(c, environment.cookieName, { path: "/" });
|
|
30241
|
+
return c.json({ ok: true });
|
|
30242
|
+
});
|
|
30243
|
+
app.get("/session", (c) => {
|
|
30244
|
+
const token = getCookie(c, environment.cookieName);
|
|
30245
|
+
if (!auth.isAuthenticated(token)) {
|
|
30246
|
+
throw new HttpError(401, "authentication required", {
|
|
30247
|
+
code: ERROR_CODES.authenticationRequired
|
|
30248
|
+
});
|
|
30249
|
+
}
|
|
30250
|
+
return c.json({ authenticated: true, currentUser: auth.userForToken(token) });
|
|
30251
|
+
});
|
|
30252
|
+
return app;
|
|
30253
|
+
}
|
|
30254
|
+
|
|
30255
|
+
// src/services/backup.ts
|
|
30256
|
+
import { basename as basename3, join as join10, resolve as resolve3 } from "node:path";
|
|
30257
|
+
var manifestSchema = exports_external.object({
|
|
30258
|
+
createdAt: exports_external.string(),
|
|
30259
|
+
harness: harnessIdSchema,
|
|
30260
|
+
profile: exports_external.string(),
|
|
30261
|
+
files: exports_external.array(exports_external.object({
|
|
30262
|
+
key: exports_external.string().catch(""),
|
|
30263
|
+
existed: exports_external.boolean(),
|
|
30264
|
+
stored: exports_external.string().optional().catch(undefined),
|
|
30265
|
+
path: exports_external.string().optional().catch(undefined)
|
|
29017
30266
|
}).refine((file2) => file2.key !== "" || file2.path !== undefined))
|
|
29018
30267
|
});
|
|
29019
30268
|
var IBackupService = createDecorator("backupService");
|
|
@@ -29131,7 +30380,7 @@ class BackupService {
|
|
|
29131
30380
|
}
|
|
29132
30381
|
const targets = this.adapters.get(harness).targets();
|
|
29133
30382
|
const id = this.nextId(harness, profile);
|
|
29134
|
-
const dir =
|
|
30383
|
+
const dir = join10(this.environment.backupsDir, id);
|
|
29135
30384
|
this.files.ensureDir(dir);
|
|
29136
30385
|
const stored = snapshots.map((snapshot, index) => {
|
|
29137
30386
|
const target = targets.find((candidate) => candidate.key === snapshot.key);
|
|
@@ -29145,7 +30394,7 @@ class BackupService {
|
|
|
29145
30394
|
return { key: target.key, existed: false };
|
|
29146
30395
|
}
|
|
29147
30396
|
const name = `${index}-${basename3(target.path)}`;
|
|
29148
|
-
this.files.writeSecure(
|
|
30397
|
+
this.files.writeSecure(join10(dir, name), snapshot.content);
|
|
29149
30398
|
return { key: target.key, existed: true, stored: name };
|
|
29150
30399
|
});
|
|
29151
30400
|
const manifest = {
|
|
@@ -29154,7 +30403,7 @@ class BackupService {
|
|
|
29154
30403
|
profile,
|
|
29155
30404
|
files: stored
|
|
29156
30405
|
};
|
|
29157
|
-
this.files.writeJson(
|
|
30406
|
+
this.files.writeJson(join10(dir, MANIFEST), manifest);
|
|
29158
30407
|
this.rotate(keep);
|
|
29159
30408
|
return id;
|
|
29160
30409
|
}
|
|
@@ -29162,8 +30411,8 @@ class BackupService {
|
|
|
29162
30411
|
if (id !== basename3(id) || id === "." || id === ".." || id.includes("\\")) {
|
|
29163
30412
|
throw new HttpError(400, "invalid backup id", { code: ERROR_CODES.backupInvalidId });
|
|
29164
30413
|
}
|
|
29165
|
-
const dir =
|
|
29166
|
-
const manifest = this.parse(this.files.readJson(
|
|
30414
|
+
const dir = join10(this.environment.backupsDir, id);
|
|
30415
|
+
const manifest = this.parse(this.files.readJson(join10(dir, MANIFEST), null));
|
|
29167
30416
|
if (!manifest) {
|
|
29168
30417
|
throw new HttpError(404, "backup not found", { code: ERROR_CODES.backupNotFound });
|
|
29169
30418
|
}
|
|
@@ -29172,8 +30421,8 @@ class BackupService {
|
|
|
29172
30421
|
load() {
|
|
29173
30422
|
const backups = [];
|
|
29174
30423
|
for (const id of this.files.listDirectories(this.environment.backupsDir)) {
|
|
29175
|
-
const dir =
|
|
29176
|
-
const manifest = this.parse(this.files.readJson(
|
|
30424
|
+
const dir = join10(this.environment.backupsDir, id);
|
|
30425
|
+
const manifest = this.parse(this.files.readJson(join10(dir, MANIFEST), null));
|
|
29177
30426
|
if (!manifest) {
|
|
29178
30427
|
this.log.error(`ignoring unreadable backup manifest in ${id}`);
|
|
29179
30428
|
continue;
|
|
@@ -29225,7 +30474,7 @@ class BackupService {
|
|
|
29225
30474
|
code: ERROR_CODES.backupPayloadNameInvalid
|
|
29226
30475
|
});
|
|
29227
30476
|
}
|
|
29228
|
-
return
|
|
30477
|
+
return join10(dir, stored);
|
|
29229
30478
|
}
|
|
29230
30479
|
parse(value) {
|
|
29231
30480
|
const parsed = manifestSchema.safeParse(value);
|
|
@@ -29237,7 +30486,7 @@ class BackupService {
|
|
|
29237
30486
|
const base = `${stamp}-${slug}`;
|
|
29238
30487
|
let candidate = base;
|
|
29239
30488
|
let suffix = 1;
|
|
29240
|
-
while (this.files.exists(
|
|
30489
|
+
while (this.files.exists(join10(this.environment.backupsDir, candidate))) {
|
|
29241
30490
|
candidate = `${base}-${suffix}`;
|
|
29242
30491
|
suffix += 1;
|
|
29243
30492
|
}
|
|
@@ -29253,7 +30502,7 @@ class BackupService {
|
|
|
29253
30502
|
if (name === keep) {
|
|
29254
30503
|
continue;
|
|
29255
30504
|
}
|
|
29256
|
-
this.files.remove(
|
|
30505
|
+
this.files.remove(join10(this.environment.backupsDir, name));
|
|
29257
30506
|
excess -= 1;
|
|
29258
30507
|
}
|
|
29259
30508
|
}
|
|
@@ -29283,18 +30532,25 @@ function createBackupRoutes(services) {
|
|
|
29283
30532
|
|
|
29284
30533
|
// src/services/doctor.ts
|
|
29285
30534
|
import { spawnSync } from "node:child_process";
|
|
29286
|
-
import { accessSync, constants, statSync as
|
|
30535
|
+
import { accessSync, constants, statSync as statSync3 } from "node:fs";
|
|
30536
|
+
|
|
30537
|
+
// src/services/activation.ts
|
|
30538
|
+
import { createHash as createHash5 } from "node:crypto";
|
|
29287
30539
|
|
|
29288
30540
|
// src/services/journal.ts
|
|
29289
|
-
import {
|
|
30541
|
+
import { createHash as createHash3 } from "node:crypto";
|
|
30542
|
+
import { basename as basename4, join as join11 } from "node:path";
|
|
29290
30543
|
var RECEIPT = "receipt.json";
|
|
29291
30544
|
var METADATA_PREFIX = "meta-";
|
|
29292
30545
|
var METADATA_KEYS = [
|
|
29293
30546
|
"profiles",
|
|
29294
30547
|
"active",
|
|
29295
|
-
"vault"
|
|
30548
|
+
"vault",
|
|
30549
|
+
"favorites"
|
|
29296
30550
|
];
|
|
29297
30551
|
var OPERATION_KINDS = [
|
|
30552
|
+
"favorite-capture",
|
|
30553
|
+
"favorite-apply",
|
|
29298
30554
|
"activate",
|
|
29299
30555
|
"activate-official",
|
|
29300
30556
|
"revoke",
|
|
@@ -29311,6 +30567,19 @@ var OPERATION_STATES = [
|
|
|
29311
30567
|
"degraded"
|
|
29312
30568
|
];
|
|
29313
30569
|
var receiptSchema = exports_external.object({
|
|
30570
|
+
metadataGuardVersion: exports_external.literal(1).optional(),
|
|
30571
|
+
favoriteResult: exports_external.object({
|
|
30572
|
+
status: exports_external.enum(["applied", "unchanged", "failed", "skipped"]),
|
|
30573
|
+
code: exports_external.string().optional()
|
|
30574
|
+
}).optional(),
|
|
30575
|
+
favoriteRequest: exports_external.object({
|
|
30576
|
+
version: exports_external.literal(1),
|
|
30577
|
+
requestId: exports_external.uuid(),
|
|
30578
|
+
planId: exports_external.uuid(),
|
|
30579
|
+
item: exports_external.number().int().min(0).max(4),
|
|
30580
|
+
approvalHash: exports_external.string().length(64),
|
|
30581
|
+
targets: exports_external.array(exports_external.object({ harness: harnessIdSchema, profile: exports_external.string().max(120) })).max(5).optional()
|
|
30582
|
+
}).optional(),
|
|
29314
30583
|
state: exports_external.enum(OPERATION_STATES),
|
|
29315
30584
|
kind: exports_external.enum(OPERATION_KINDS),
|
|
29316
30585
|
harness: harnessIdSchema,
|
|
@@ -29349,16 +30618,19 @@ class JournalService {
|
|
|
29349
30618
|
}
|
|
29350
30619
|
begin(plan) {
|
|
29351
30620
|
const id = this.nextId(plan);
|
|
29352
|
-
const dir =
|
|
30621
|
+
const dir = join11(this.environment.journalDir, id);
|
|
29353
30622
|
this.files.ensureDir(dir);
|
|
29354
30623
|
for (const key of plan.metadata) {
|
|
29355
30624
|
const content = this.files.readOptional(this.environment.files[key]);
|
|
29356
|
-
this.files.writeSecure(
|
|
30625
|
+
this.files.writeSecure(join11(dir, `${METADATA_PREFIX}${key}`), content === undefined ? "" : content);
|
|
29357
30626
|
if (content === undefined) {
|
|
29358
|
-
this.files.writeSecure(
|
|
30627
|
+
this.files.writeSecure(join11(dir, `${METADATA_PREFIX}${key}.absent`), "");
|
|
29359
30628
|
}
|
|
29360
30629
|
}
|
|
29361
30630
|
const receipt = {
|
|
30631
|
+
metadataGuardVersion: plan.metadata.length ? 1 : undefined,
|
|
30632
|
+
favoriteResult: plan.favoriteResult,
|
|
30633
|
+
favoriteRequest: plan.favoriteRequest,
|
|
29362
30634
|
id,
|
|
29363
30635
|
state: "prepared",
|
|
29364
30636
|
kind: plan.kind,
|
|
@@ -29386,12 +30658,31 @@ class JournalService {
|
|
|
29386
30658
|
return {
|
|
29387
30659
|
id,
|
|
29388
30660
|
applying: () => advance("applying"),
|
|
29389
|
-
metadataCommitted: () =>
|
|
30661
|
+
metadataCommitted: () => {
|
|
30662
|
+
if (receipt.metadataGuardVersion === 1) {
|
|
30663
|
+
this.files.writeJson(join11(dir, "metadata-after.json"), Object.fromEntries(plan.metadata.map((key) => [key, this.metadataFingerprint(key)])));
|
|
30664
|
+
}
|
|
30665
|
+
advance("metadata-committed");
|
|
30666
|
+
},
|
|
29390
30667
|
committed: () => advance("committed"),
|
|
29391
|
-
rolledBack: () =>
|
|
30668
|
+
rolledBack: (code) => {
|
|
30669
|
+
if (receipt.favoriteRequest) {
|
|
30670
|
+
receipt.favoriteResult = { status: "failed", code };
|
|
30671
|
+
}
|
|
30672
|
+
advance("rolled-back");
|
|
30673
|
+
},
|
|
29392
30674
|
degraded: (note) => advance("degraded", note)
|
|
29393
30675
|
};
|
|
29394
30676
|
}
|
|
30677
|
+
metadataFingerprint(key) {
|
|
30678
|
+
return createHash3("sha256").update(JSON.stringify(this.files.readOptional(this.environment.files[key]) ?? null)).digest("hex");
|
|
30679
|
+
}
|
|
30680
|
+
setFavoriteResult(id, result) {
|
|
30681
|
+
const { dir, receipt } = this.require(id);
|
|
30682
|
+
if (receipt.favoriteRequest) {
|
|
30683
|
+
this.write(dir, { ...receipt, favoriteResult: result });
|
|
30684
|
+
}
|
|
30685
|
+
}
|
|
29395
30686
|
list() {
|
|
29396
30687
|
return this.load().map(({ receipt }) => this.withUndoable(receipt)).toSorted((left, right) => right.id.localeCompare(left.id));
|
|
29397
30688
|
}
|
|
@@ -29410,6 +30701,14 @@ class JournalService {
|
|
|
29410
30701
|
code: ERROR_CODES.operationIncomplete
|
|
29411
30702
|
});
|
|
29412
30703
|
}
|
|
30704
|
+
if (receipt.metadataGuardVersion === 1) {
|
|
30705
|
+
const after = exports_external.partialRecord(exports_external.enum(METADATA_KEYS), exports_external.string()).safeParse(this.files.readJson(join11(dir, "metadata-after.json"), null));
|
|
30706
|
+
if (!after.success || receipt.metadata.some((key) => after.data[key] !== this.metadataFingerprint(key))) {
|
|
30707
|
+
throw new HttpError(409, ERROR_CODES.favoriteUndoConflict, {
|
|
30708
|
+
code: ERROR_CODES.favoriteUndoConflict
|
|
30709
|
+
});
|
|
30710
|
+
}
|
|
30711
|
+
}
|
|
29413
30712
|
this.revert(dir, receipt);
|
|
29414
30713
|
const reverted = {
|
|
29415
30714
|
...receipt,
|
|
@@ -29480,11 +30779,11 @@ class JournalService {
|
|
|
29480
30779
|
});
|
|
29481
30780
|
}
|
|
29482
30781
|
const destination = this.environment.files[key];
|
|
29483
|
-
if (this.files.exists(
|
|
30782
|
+
if (this.files.exists(join11(dir, `${METADATA_PREFIX}${key}.absent`))) {
|
|
29484
30783
|
this.files.remove(destination);
|
|
29485
30784
|
continue;
|
|
29486
30785
|
}
|
|
29487
|
-
const snapshot = this.files.readRegularOptional(
|
|
30786
|
+
const snapshot = this.files.readRegularOptional(join11(dir, `${METADATA_PREFIX}${key}`));
|
|
29488
30787
|
if (snapshot === undefined) {
|
|
29489
30788
|
throw new HttpError(500, `操作 ${receipt.id} 缺少 ${key} 的快照`, {
|
|
29490
30789
|
code: ERROR_CODES.operationSnapshotMissing,
|
|
@@ -29513,8 +30812,8 @@ class JournalService {
|
|
|
29513
30812
|
if (id !== basename4(id) || id === "." || id === ".." || id.includes("\\")) {
|
|
29514
30813
|
throw new HttpError(400, "invalid operation id", { code: ERROR_CODES.operationInvalidId });
|
|
29515
30814
|
}
|
|
29516
|
-
const dir =
|
|
29517
|
-
const receipt = this.parse(id, this.files.readJson(
|
|
30815
|
+
const dir = join11(this.environment.journalDir, id);
|
|
30816
|
+
const receipt = this.parse(id, this.files.readJson(join11(dir, RECEIPT), null));
|
|
29518
30817
|
if (!receipt) {
|
|
29519
30818
|
throw new HttpError(404, "operation not found", { code: ERROR_CODES.operationNotFound });
|
|
29520
30819
|
}
|
|
@@ -29523,8 +30822,8 @@ class JournalService {
|
|
|
29523
30822
|
load(unfinishedOnly = false) {
|
|
29524
30823
|
const found = [];
|
|
29525
30824
|
for (const id of this.files.listDirectories(this.environment.journalDir)) {
|
|
29526
|
-
const dir =
|
|
29527
|
-
const receipt = this.parse(id, this.files.readJson(
|
|
30825
|
+
const dir = join11(this.environment.journalDir, id);
|
|
30826
|
+
const receipt = this.parse(id, this.files.readJson(join11(dir, RECEIPT), null));
|
|
29528
30827
|
if (!receipt) {
|
|
29529
30828
|
this.log.error(`ignoring unreadable operation record in ${id}`);
|
|
29530
30829
|
continue;
|
|
@@ -29537,7 +30836,7 @@ class JournalService {
|
|
|
29537
30836
|
return found;
|
|
29538
30837
|
}
|
|
29539
30838
|
write(dir, receipt) {
|
|
29540
|
-
this.files.writeJson(
|
|
30839
|
+
this.files.writeJson(join11(dir, RECEIPT), receipt);
|
|
29541
30840
|
}
|
|
29542
30841
|
parse(id, value) {
|
|
29543
30842
|
const parsed = receiptSchema.safeParse(value);
|
|
@@ -29549,7 +30848,7 @@ class JournalService {
|
|
|
29549
30848
|
const base = `${stamp}-${slug}`;
|
|
29550
30849
|
let candidate = base;
|
|
29551
30850
|
let suffix = 1;
|
|
29552
|
-
while (this.files.exists(
|
|
30851
|
+
while (this.files.exists(join11(this.environment.journalDir, candidate))) {
|
|
29553
30852
|
candidate = `${base}-${suffix}`;
|
|
29554
30853
|
suffix += 1;
|
|
29555
30854
|
}
|
|
@@ -29565,7 +30864,7 @@ class JournalService {
|
|
|
29565
30864
|
if (name === keep) {
|
|
29566
30865
|
continue;
|
|
29567
30866
|
}
|
|
29568
|
-
this.files.remove(
|
|
30867
|
+
this.files.remove(join11(this.environment.journalDir, name));
|
|
29569
30868
|
excess -= 1;
|
|
29570
30869
|
}
|
|
29571
30870
|
}
|
|
@@ -29581,7 +30880,7 @@ function isFinished(state) {
|
|
|
29581
30880
|
// src/services/live-write.ts
|
|
29582
30881
|
var ILiveWriteService = createDecorator("liveWriteService");
|
|
29583
30882
|
var _dec = [
|
|
29584
|
-
inject(IFileService, IBackupService, IJournalService, ILogService)
|
|
30883
|
+
inject(IFileService, IBackupService, IJournalService, ILogService, IEnvironmentService, IFavoriteBackupService)
|
|
29585
30884
|
];
|
|
29586
30885
|
var _init = __decoratorStart(undefined);
|
|
29587
30886
|
|
|
@@ -29590,11 +30889,15 @@ class LiveWriteService {
|
|
|
29590
30889
|
backups;
|
|
29591
30890
|
journal;
|
|
29592
30891
|
log;
|
|
29593
|
-
|
|
30892
|
+
environment;
|
|
30893
|
+
favoriteBackups;
|
|
30894
|
+
constructor(files, backups, journal, log, environment, favoriteBackups) {
|
|
29594
30895
|
this.files = files;
|
|
29595
30896
|
this.backups = backups;
|
|
29596
30897
|
this.journal = journal;
|
|
29597
30898
|
this.log = log;
|
|
30899
|
+
this.environment = environment;
|
|
30900
|
+
this.favoriteBackups = favoriteBackups;
|
|
29598
30901
|
}
|
|
29599
30902
|
apply(plan) {
|
|
29600
30903
|
this.transaction(plan, () => {
|
|
@@ -29602,11 +30905,21 @@ class LiveWriteService {
|
|
|
29602
30905
|
});
|
|
29603
30906
|
}
|
|
29604
30907
|
transaction(plan, operation) {
|
|
30908
|
+
if (plan.metadata?.includes("favorites")) {
|
|
30909
|
+
return this.favoriteBackups.protect("change", () => this.execute(plan, operation));
|
|
30910
|
+
}
|
|
30911
|
+
return this.execute(plan, operation);
|
|
30912
|
+
}
|
|
30913
|
+
execute(plan, operation) {
|
|
29605
30914
|
const { harness, profile, writes } = plan;
|
|
29606
30915
|
for (const write of writes) {
|
|
29607
30916
|
this.files.assertManaged(write.path);
|
|
29608
30917
|
assertParsable(write.format, write.path, write.content);
|
|
29609
30918
|
}
|
|
30919
|
+
const metadata = (plan.metadata ?? []).map((key) => ({
|
|
30920
|
+
path: this.environment.files[key],
|
|
30921
|
+
content: this.files.readOptional(this.environment.files[key])
|
|
30922
|
+
}));
|
|
29610
30923
|
const snapshots = writes.map((write) => ({
|
|
29611
30924
|
key: write.key,
|
|
29612
30925
|
path: write.path,
|
|
@@ -29623,11 +30936,14 @@ class LiveWriteService {
|
|
|
29623
30936
|
path: snapshot.path,
|
|
29624
30937
|
existed: snapshot.content !== undefined
|
|
29625
30938
|
})),
|
|
29626
|
-
metadata: plan.metadata ?? []
|
|
30939
|
+
metadata: plan.metadata ?? [],
|
|
30940
|
+
favoriteRequest: plan.favoriteRequest,
|
|
30941
|
+
favoriteResult: plan.favoriteResult
|
|
29627
30942
|
});
|
|
29628
30943
|
const written = [];
|
|
29629
30944
|
try {
|
|
29630
30945
|
entry.applying();
|
|
30946
|
+
plan.beforeWrites?.();
|
|
29631
30947
|
for (const [index, write] of writes.entries()) {
|
|
29632
30948
|
this.write(write);
|
|
29633
30949
|
written.push({ snapshot: snapshots[index], secret: write.secret === true });
|
|
@@ -29637,9 +30953,17 @@ class LiveWriteService {
|
|
|
29637
30953
|
entry.committed();
|
|
29638
30954
|
return result;
|
|
29639
30955
|
} catch (error51) {
|
|
29640
|
-
|
|
30956
|
+
let restored = this.rollback(written);
|
|
30957
|
+
for (const snapshot of metadata.toReversed()) {
|
|
30958
|
+
try {
|
|
30959
|
+
this.files.restore(snapshot.path, snapshot.content);
|
|
30960
|
+
} catch (restoreError) {
|
|
30961
|
+
restored = false;
|
|
30962
|
+
this.log.error("metadata rollback failed", restoreError);
|
|
30963
|
+
}
|
|
30964
|
+
}
|
|
29641
30965
|
if (restored) {
|
|
29642
|
-
entry.rolledBack();
|
|
30966
|
+
entry.rolledBack(error51 instanceof HttpError ? error51.code : ERROR_CODES.requestFailed);
|
|
29643
30967
|
} else {
|
|
29644
30968
|
entry.degraded("回滚过程中有文件未能恢复,请从备份手动恢复");
|
|
29645
30969
|
}
|
|
@@ -29679,6 +31003,9 @@ __runInitializers(_init, 1, LiveWriteService);
|
|
|
29679
31003
|
__decoratorMetadata(_init, LiveWriteService);
|
|
29680
31004
|
let _LiveWriteService = LiveWriteService;
|
|
29681
31005
|
|
|
31006
|
+
// src/services/profiles.ts
|
|
31007
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
31008
|
+
|
|
29682
31009
|
// src/services/registry.ts
|
|
29683
31010
|
var IHarnessRegistry = createDecorator("harnessRegistry");
|
|
29684
31011
|
|
|
@@ -29930,6 +31257,9 @@ class ProfileService {
|
|
|
29930
31257
|
}
|
|
29931
31258
|
return Object.entries(store[harness] ?? {}).map(([name, profile]) => this.toPublic(harness, name, profile));
|
|
29932
31259
|
}
|
|
31260
|
+
fingerprint(harness, name) {
|
|
31261
|
+
return createHash4("sha256").update(this.environment.dataDir).update(JSON.stringify(this.read()[harness]?.[name] ?? null)).digest("hex");
|
|
31262
|
+
}
|
|
29933
31263
|
get(harness, name) {
|
|
29934
31264
|
const stored = this.read()[harness]?.[name];
|
|
29935
31265
|
return stored ? this.toPublic(harness, name, stored) : undefined;
|
|
@@ -30005,6 +31335,7 @@ class ProfileService {
|
|
|
30005
31335
|
}
|
|
30006
31336
|
const baseUrl = this.resolveBaseUrl((input.baseUrl ?? inherited?.base_url ?? "").trim(), providerId2 || nextProviderId, providerEndpoint || nextProviderEndpoint);
|
|
30007
31337
|
const next = {
|
|
31338
|
+
model_favorite: prior?.model_favorite,
|
|
30008
31339
|
base_url: baseUrl,
|
|
30009
31340
|
api_key: this.crypto.encrypt(apiKey),
|
|
30010
31341
|
model: (input.model ?? inherited?.model ?? "").trim(),
|
|
@@ -30015,7 +31346,17 @@ class ProfileService {
|
|
|
30015
31346
|
provider_endpoint: nextProviderEndpoint,
|
|
30016
31347
|
updated_at: new Date().toISOString()
|
|
30017
31348
|
};
|
|
31349
|
+
if (prior?.model_favorite) {
|
|
31350
|
+
const link = modelFavoriteLinkSchema.safeParse(prior.model_favorite);
|
|
31351
|
+
const changed = !link.success || next.model !== prior.model || next.provider_id !== prior.provider_id || next.provider_endpoint !== prior.provider_endpoint || next.base_url !== prior.base_url || Object.keys(next.overrides ?? {}).length > 0 || Object.keys(link.data.baseline.extras).some((key) => next.extras?.[key] !== prior.extras?.[key]);
|
|
31352
|
+
if (changed) {
|
|
31353
|
+
throw new HttpError(409, ERROR_CODES.favoriteProfileDiverged, {
|
|
31354
|
+
code: ERROR_CODES.favoriteProfileDiverged
|
|
31355
|
+
});
|
|
31356
|
+
}
|
|
31357
|
+
}
|
|
30018
31358
|
this.adapters.get(harness).validate?.({
|
|
31359
|
+
favoriteManaged: next.model_favorite !== undefined,
|
|
30019
31360
|
name,
|
|
30020
31361
|
baseUrl: next.base_url,
|
|
30021
31362
|
apiKey,
|
|
@@ -30029,6 +31370,19 @@ class ProfileService {
|
|
|
30029
31370
|
this.files.writeJson(this.environment.files.profiles, store);
|
|
30030
31371
|
return this.toPublic(harness, name, next);
|
|
30031
31372
|
}
|
|
31373
|
+
setFavoriteLink(harness, name, link) {
|
|
31374
|
+
const store = this.read();
|
|
31375
|
+
const profile = store[harness]?.[name];
|
|
31376
|
+
if (!profile) {
|
|
31377
|
+
throw new HttpError(404, ERROR_CODES.profileNotFound, { code: ERROR_CODES.profileNotFound });
|
|
31378
|
+
}
|
|
31379
|
+
if (link) {
|
|
31380
|
+
profile.model_favorite = modelFavoriteLinkSchema.parse(link);
|
|
31381
|
+
} else {
|
|
31382
|
+
delete profile.model_favorite;
|
|
31383
|
+
}
|
|
31384
|
+
this.files.writeJson(this.environment.files.profiles, store);
|
|
31385
|
+
}
|
|
30032
31386
|
remove(harness, name) {
|
|
30033
31387
|
const store = this.read();
|
|
30034
31388
|
if (!store[harness]?.[name]) {
|
|
@@ -30042,8 +31396,16 @@ class ProfileService {
|
|
|
30042
31396
|
if (!stored) {
|
|
30043
31397
|
throw new HttpError(404, "profile not found", { code: ERROR_CODES.profileNotFound });
|
|
30044
31398
|
}
|
|
31399
|
+
if (stored.model_favorite) {
|
|
31400
|
+
if (!stored.provider_id || !stored.provider_endpoint || !this.vault.get(stored.provider_id).endpoints.some((endpoint) => endpoint.key === stored.provider_endpoint)) {
|
|
31401
|
+
throw new HttpError(409, ERROR_CODES.favoriteEndpointMissing, {
|
|
31402
|
+
code: ERROR_CODES.favoriteEndpointMissing
|
|
31403
|
+
});
|
|
31404
|
+
}
|
|
31405
|
+
}
|
|
30045
31406
|
return {
|
|
30046
31407
|
name,
|
|
31408
|
+
favoriteManaged: stored.model_favorite !== undefined,
|
|
30047
31409
|
baseUrl: this.resolveBaseUrl(stored.base_url || "", stored.provider_id, stored.provider_endpoint),
|
|
30048
31410
|
apiKey: this.resolveKey(stored),
|
|
30049
31411
|
model: stored.model || "",
|
|
@@ -30083,7 +31445,7 @@ class ProfileService {
|
|
|
30083
31445
|
const endpoint = stored.provider_endpoint !== undefined ? endpoints.find((candidate) => candidate.key === stored.provider_endpoint) : undefined;
|
|
30084
31446
|
if (endpoint) {
|
|
30085
31447
|
stored.base_url = endpoint.baseUrl;
|
|
30086
|
-
} else if (stored.provider_endpoint !== undefined && endpoints.length > 0) {
|
|
31448
|
+
} else if (!stored.model_favorite && stored.provider_endpoint !== undefined && endpoints.length > 0) {
|
|
30087
31449
|
stored.provider_endpoint = endpoints[0].key;
|
|
30088
31450
|
stored.base_url = endpoints[0].baseUrl;
|
|
30089
31451
|
}
|
|
@@ -30101,6 +31463,9 @@ class ProfileService {
|
|
|
30101
31463
|
repairEndpointReferences(store, harness) {
|
|
30102
31464
|
let changed = false;
|
|
30103
31465
|
for (const stored of Object.values(store[harness] ?? {})) {
|
|
31466
|
+
if (stored.model_favorite) {
|
|
31467
|
+
continue;
|
|
31468
|
+
}
|
|
30104
31469
|
if (!stored.provider_id || !stored.provider_endpoint) {
|
|
30105
31470
|
continue;
|
|
30106
31471
|
}
|
|
@@ -30124,6 +31489,7 @@ class ProfileService {
|
|
|
30124
31489
|
return {
|
|
30125
31490
|
harness,
|
|
30126
31491
|
name,
|
|
31492
|
+
modelFavorite: modelFavoriteLinkSchema.safeParse(profile.model_favorite).data,
|
|
30127
31493
|
baseUrl: profile.base_url || "",
|
|
30128
31494
|
model: profile.model || "",
|
|
30129
31495
|
notes: profile.notes || "",
|
|
@@ -30135,6 +31501,9 @@ class ProfileService {
|
|
|
30135
31501
|
};
|
|
30136
31502
|
}
|
|
30137
31503
|
resolveKey(stored) {
|
|
31504
|
+
if (stored.model_favorite && stored.provider_id) {
|
|
31505
|
+
return this.vault.decrypt(stored.provider_id);
|
|
31506
|
+
}
|
|
30138
31507
|
if (!stored.provider_id) {
|
|
30139
31508
|
return this.crypto.decrypt(stored.api_key);
|
|
30140
31509
|
}
|
|
@@ -30221,15 +31590,47 @@ class ActivationService {
|
|
|
30221
31590
|
official: stored.official === true
|
|
30222
31591
|
};
|
|
30223
31592
|
}
|
|
31593
|
+
fingerprint(harness) {
|
|
31594
|
+
return createHash5("sha256").update(JSON.stringify(this.read()[harness] ?? null)).digest("hex");
|
|
31595
|
+
}
|
|
31596
|
+
prepareFavorite(harness, profile) {
|
|
31597
|
+
const adapter = this.adapters.get(harness);
|
|
31598
|
+
adapter.validate?.(profile);
|
|
31599
|
+
const targets = adapter.targets();
|
|
31600
|
+
return this.toWrites(targets, adapter.render(profile, this.readCurrent(targets)));
|
|
31601
|
+
}
|
|
31602
|
+
commitFavorite(harness, profile) {
|
|
31603
|
+
const adapter = this.adapters.get(harness);
|
|
31604
|
+
const active = this.read();
|
|
31605
|
+
this.backfillPrevious(adapter, active[harness], profile.name, []);
|
|
31606
|
+
active[harness] = {
|
|
31607
|
+
name: profile.name,
|
|
31608
|
+
base_url: profile.baseUrl,
|
|
31609
|
+
api_key: profile.apiKey,
|
|
31610
|
+
model: profile.model,
|
|
31611
|
+
extras: profile.extras,
|
|
31612
|
+
official: false
|
|
31613
|
+
};
|
|
31614
|
+
this.files.writeJson(this.environment.files.active, active);
|
|
31615
|
+
}
|
|
31616
|
+
refreshEnv() {
|
|
31617
|
+
this.writeEnv(this.read());
|
|
31618
|
+
}
|
|
30224
31619
|
activate(harness, name) {
|
|
30225
31620
|
const adapter = this.adapters.get(harness);
|
|
30226
31621
|
const profile = this.profiles.decrypt(harness, name);
|
|
30227
31622
|
adapter.validate?.(profile);
|
|
30228
31623
|
const warnings = [];
|
|
30229
31624
|
const active = this.read();
|
|
30230
|
-
this.backfillPrevious(adapter, active[harness], name, warnings);
|
|
30231
31625
|
const writes = this.expectedNamedWrites(harness, name);
|
|
30232
|
-
this.liveWrite.transaction({
|
|
31626
|
+
this.liveWrite.transaction({
|
|
31627
|
+
kind: "activate",
|
|
31628
|
+
harness,
|
|
31629
|
+
profile: name,
|
|
31630
|
+
writes,
|
|
31631
|
+
metadata: ["active", "profiles"],
|
|
31632
|
+
beforeWrites: () => this.backfillPrevious(adapter, active[harness], name, warnings)
|
|
31633
|
+
}, () => {
|
|
30233
31634
|
active[harness] = {
|
|
30234
31635
|
name: profile.name,
|
|
30235
31636
|
base_url: profile.baseUrl,
|
|
@@ -30262,16 +31663,18 @@ class ActivationService {
|
|
|
30262
31663
|
const active = this.read();
|
|
30263
31664
|
const previous = active[harness];
|
|
30264
31665
|
const alreadyOfficial = previous?.official === true;
|
|
30265
|
-
if (!alreadyOfficial) {
|
|
30266
|
-
this.backfillPrevious(adapter, previous, "__official__", warnings);
|
|
30267
|
-
}
|
|
30268
31666
|
const writes = this.expectedOfficialWrites(harness);
|
|
30269
31667
|
this.liveWrite.transaction({
|
|
30270
31668
|
kind: "activate-official",
|
|
30271
31669
|
harness,
|
|
30272
31670
|
profile: "官方登录",
|
|
30273
31671
|
writes,
|
|
30274
|
-
metadata: ["active"]
|
|
31672
|
+
metadata: ["active", "profiles"],
|
|
31673
|
+
beforeWrites: () => {
|
|
31674
|
+
if (!alreadyOfficial) {
|
|
31675
|
+
this.backfillPrevious(adapter, previous, "__official__", warnings);
|
|
31676
|
+
}
|
|
31677
|
+
}
|
|
30275
31678
|
}, () => {
|
|
30276
31679
|
active[harness] = {
|
|
30277
31680
|
name: "官方登录",
|
|
@@ -31116,7 +32519,7 @@ function firstString(record2, keys) {
|
|
|
31116
32519
|
}
|
|
31117
32520
|
|
|
31118
32521
|
// src/services/probe-cache.ts
|
|
31119
|
-
import { createHash as
|
|
32522
|
+
import { createHash as createHash6 } from "node:crypto";
|
|
31120
32523
|
var IProbeCacheService = createDecorator("probeCacheService");
|
|
31121
32524
|
var OK_TTL_MS = 6 * 60 * 60 * 1000;
|
|
31122
32525
|
var FAILURE_TTL_MS = 5 * 60 * 1000;
|
|
@@ -31179,11 +32582,11 @@ __runInitializers(_init, 1, ProbeCacheService);
|
|
|
31179
32582
|
__decoratorMetadata(_init, ProbeCacheService);
|
|
31180
32583
|
let _ProbeCacheService = ProbeCacheService;
|
|
31181
32584
|
function fingerprint(key) {
|
|
31182
|
-
return
|
|
32585
|
+
return createHash6("sha256").update(JSON.stringify([
|
|
31183
32586
|
key.baseUrl,
|
|
31184
32587
|
key.model,
|
|
31185
32588
|
key.protocol ?? "",
|
|
31186
|
-
|
|
32589
|
+
createHash6("sha256").update(key.apiKey).digest("hex")
|
|
31187
32590
|
])).digest("hex");
|
|
31188
32591
|
}
|
|
31189
32592
|
|
|
@@ -31236,11 +32639,11 @@ let _ProbeProfileService = ProbeProfileService;
|
|
|
31236
32639
|
import { spawn } from "node:child_process";
|
|
31237
32640
|
import { mkdirSync as mkdirSync3, openSync } from "node:fs";
|
|
31238
32641
|
import { homedir as homedir2 } from "node:os";
|
|
31239
|
-
import { join as
|
|
32642
|
+
import { join as join13 } from "node:path";
|
|
31240
32643
|
|
|
31241
32644
|
// src/services/version.ts
|
|
31242
32645
|
import { readFile } from "node:fs/promises";
|
|
31243
|
-
import { dirname as dirname4, join as
|
|
32646
|
+
import { dirname as dirname4, join as join12, parse as parse7 } from "node:path";
|
|
31244
32647
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
31245
32648
|
var IVersionService = createDecorator("versionService");
|
|
31246
32649
|
var FALLBACK = { name: "harness-switch", version: "0.0.0" };
|
|
@@ -31262,7 +32665,7 @@ async function readManifest() {
|
|
|
31262
32665
|
let dir = dirname4(fileURLToPath2(import.meta.url));
|
|
31263
32666
|
const { root } = parse7(dir);
|
|
31264
32667
|
while (true) {
|
|
31265
|
-
const parsed = await readJson(
|
|
32668
|
+
const parsed = await readJson(join12(dir, "package.json"));
|
|
31266
32669
|
if (parsed) {
|
|
31267
32670
|
return {
|
|
31268
32671
|
name: typeof parsed.name === "string" ? parsed.name : FALLBACK.name,
|
|
@@ -31342,9 +32745,9 @@ class UpdateService {
|
|
|
31342
32745
|
return;
|
|
31343
32746
|
}
|
|
31344
32747
|
const name = await this.versions.name();
|
|
31345
|
-
const dataDir = process.env.HSW_DATA_DIR ||
|
|
32748
|
+
const dataDir = process.env.HSW_DATA_DIR || join13(homedir2(), ".harness-switch");
|
|
31346
32749
|
mkdirSync3(dataDir, { recursive: true, mode: 448 });
|
|
31347
|
-
const logFd = openSync(
|
|
32750
|
+
const logFd = openSync(join13(dataDir, "update.log"), "w");
|
|
31348
32751
|
const usingBun = Boolean(process.versions.bun);
|
|
31349
32752
|
const child = spawn(usingBun ? "bun" : "npx", usingBun ? ["x", `${name}@latest`] : ["-y", `${name}@latest`], {
|
|
31350
32753
|
detached: true,
|
|
@@ -31545,7 +32948,7 @@ class DoctorService {
|
|
|
31545
32948
|
}
|
|
31546
32949
|
modeOf(path) {
|
|
31547
32950
|
try {
|
|
31548
|
-
return
|
|
32951
|
+
return statSync3(path).mode & 511;
|
|
31549
32952
|
} catch {
|
|
31550
32953
|
return;
|
|
31551
32954
|
}
|
|
@@ -31614,9 +33017,12 @@ function createDriftRoutes(services) {
|
|
|
31614
33017
|
return app;
|
|
31615
33018
|
}
|
|
31616
33019
|
|
|
33020
|
+
// src/services/transfer.ts
|
|
33021
|
+
import { randomUUID as randomUUID3 } from "node:crypto";
|
|
33022
|
+
|
|
31617
33023
|
// src/services/codex-login-cache.ts
|
|
31618
33024
|
import { lstatSync as lstatSync2 } from "node:fs";
|
|
31619
|
-
import { join as
|
|
33025
|
+
import { join as join14 } from "node:path";
|
|
31620
33026
|
import { isDeepStrictEqual } from "node:util";
|
|
31621
33027
|
var AUTH_FILE = "auth.json";
|
|
31622
33028
|
var MAX_CACHE_BYTES = 1024 * 1024;
|
|
@@ -31676,7 +33082,7 @@ class CodexLoginCacheService {
|
|
|
31676
33082
|
prepareWrite(content) {
|
|
31677
33083
|
this.validate(content);
|
|
31678
33084
|
const directory = this.assertDirectory(true);
|
|
31679
|
-
const path =
|
|
33085
|
+
const path = join14(directory, AUTH_FILE);
|
|
31680
33086
|
this.assertRegularFile(path, false);
|
|
31681
33087
|
return { key: CODEX_AUTH_TARGET, path, content };
|
|
31682
33088
|
}
|
|
@@ -31685,7 +33091,7 @@ class CodexLoginCacheService {
|
|
|
31685
33091
|
this.files.writeUserSecretFile(write.path, write.content);
|
|
31686
33092
|
}
|
|
31687
33093
|
path() {
|
|
31688
|
-
return
|
|
33094
|
+
return join14(this.environment.harnessHomes.codex, AUTH_FILE);
|
|
31689
33095
|
}
|
|
31690
33096
|
assertDirectory(create) {
|
|
31691
33097
|
const directory = this.environment.harnessHomes.codex;
|
|
@@ -31744,13 +33150,108 @@ function isPlainObject3(value) {
|
|
|
31744
33150
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
31745
33151
|
}
|
|
31746
33152
|
|
|
33153
|
+
// src/services/model-favorite-store.ts
|
|
33154
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
33155
|
+
var IModelFavoriteStore = createDecorator("modelFavoriteStore");
|
|
33156
|
+
var _dec = [
|
|
33157
|
+
inject(IEnvironmentService, IFileService)
|
|
33158
|
+
];
|
|
33159
|
+
var _init = __decoratorStart(undefined);
|
|
33160
|
+
|
|
33161
|
+
class ModelFavoriteStore {
|
|
33162
|
+
environment;
|
|
33163
|
+
files;
|
|
33164
|
+
constructor(environment, files) {
|
|
33165
|
+
this.environment = environment;
|
|
33166
|
+
this.files = files;
|
|
33167
|
+
}
|
|
33168
|
+
list() {
|
|
33169
|
+
const content = this.files.readRegularOptional(this.environment.files.favorites);
|
|
33170
|
+
if (content === undefined) {
|
|
33171
|
+
return [];
|
|
33172
|
+
}
|
|
33173
|
+
try {
|
|
33174
|
+
return favoriteStoreSchema.parse(JSON.parse(content)).favorites;
|
|
33175
|
+
} catch {
|
|
33176
|
+
throw new HttpError(409, ERROR_CODES.favoriteStoreInvalid, {
|
|
33177
|
+
code: ERROR_CODES.favoriteStoreInvalid
|
|
33178
|
+
});
|
|
33179
|
+
}
|
|
33180
|
+
}
|
|
33181
|
+
get(id) {
|
|
33182
|
+
const favorite = this.list().find((item) => item.id === id);
|
|
33183
|
+
if (!favorite) {
|
|
33184
|
+
throw new HttpError(404, ERROR_CODES.favoriteNotFound, {
|
|
33185
|
+
code: ERROR_CODES.favoriteNotFound
|
|
33186
|
+
});
|
|
33187
|
+
}
|
|
33188
|
+
return favorite;
|
|
33189
|
+
}
|
|
33190
|
+
assertRevision(id, revision) {
|
|
33191
|
+
this.compare(this.get(id), revision);
|
|
33192
|
+
}
|
|
33193
|
+
create(input) {
|
|
33194
|
+
const favorites = this.list();
|
|
33195
|
+
if (favorites.length >= 1000) {
|
|
33196
|
+
throw new HttpError(409, ERROR_CODES.favoriteLimitReached, {
|
|
33197
|
+
code: ERROR_CODES.favoriteLimitReached
|
|
33198
|
+
});
|
|
33199
|
+
}
|
|
33200
|
+
const now = new Date().toISOString();
|
|
33201
|
+
const favorite = modelFavoriteSchema.parse({
|
|
33202
|
+
...createFavoriteRequestSchema.parse(input),
|
|
33203
|
+
id: randomUUID2(),
|
|
33204
|
+
revision: 1,
|
|
33205
|
+
createdAt: now,
|
|
33206
|
+
updatedAt: now
|
|
33207
|
+
});
|
|
33208
|
+
this.write([...favorites, favorite]);
|
|
33209
|
+
return favorite;
|
|
33210
|
+
}
|
|
33211
|
+
update(id, input, expectedRevision) {
|
|
33212
|
+
const previous = this.get(id);
|
|
33213
|
+
this.compare(previous, expectedRevision);
|
|
33214
|
+
const next = modelFavoriteSchema.parse({
|
|
33215
|
+
...previous,
|
|
33216
|
+
...createFavoriteRequestSchema.parse(input),
|
|
33217
|
+
revision: previous.revision + 1,
|
|
33218
|
+
updatedAt: new Date().toISOString()
|
|
33219
|
+
});
|
|
33220
|
+
this.write(this.list().map((favorite) => favorite.id === id ? next : favorite));
|
|
33221
|
+
return next;
|
|
33222
|
+
}
|
|
33223
|
+
remove(id, expectedRevision) {
|
|
33224
|
+
this.compare(this.get(id), expectedRevision);
|
|
33225
|
+
this.write(this.list().filter((favorite) => favorite.id !== id));
|
|
33226
|
+
}
|
|
33227
|
+
compare(favorite, revision) {
|
|
33228
|
+
if (revision === undefined) {
|
|
33229
|
+
throw new HttpError(428, ERROR_CODES.favoriteRevisionRequired, {
|
|
33230
|
+
code: ERROR_CODES.favoriteRevisionRequired
|
|
33231
|
+
});
|
|
33232
|
+
}
|
|
33233
|
+
if (favorite.revision !== revision) {
|
|
33234
|
+
throw new HttpError(409, ERROR_CODES.favoriteRevisionConflict, {
|
|
33235
|
+
code: ERROR_CODES.favoriteRevisionConflict
|
|
33236
|
+
});
|
|
33237
|
+
}
|
|
33238
|
+
}
|
|
33239
|
+
write(favorites) {
|
|
33240
|
+
this.files.writeJson(this.environment.files.favorites, favoriteStoreSchema.parse({ schemaVersion: 1, favorites }));
|
|
33241
|
+
}
|
|
33242
|
+
}
|
|
33243
|
+
ModelFavoriteStore = __decorateElement(_init, 0, "ModelFavoriteStore", _dec, ModelFavoriteStore);
|
|
33244
|
+
__runInitializers(_init, 1, ModelFavoriteStore);
|
|
33245
|
+
__decoratorMetadata(_init, ModelFavoriteStore);
|
|
33246
|
+
let _ModelFavoriteStore = ModelFavoriteStore;
|
|
33247
|
+
|
|
31747
33248
|
// src/services/transfer.ts
|
|
31748
33249
|
var FORMAT = "harness-switch-encrypted-export";
|
|
31749
33250
|
var VERSION = 1;
|
|
31750
33251
|
var MAX_ENCRYPTED_BYTES = 10 * 1024 * 1024;
|
|
31751
33252
|
var ITransferService = createDecorator("transferService");
|
|
31752
33253
|
var _dec = [
|
|
31753
|
-
inject(IEnvironmentService, IFileService, ICryptoService, ICodexLoginCacheService, ILiveWriteService, IAdapterRegistry, IActivationService, IVaultService)
|
|
33254
|
+
inject(IEnvironmentService, IFileService, ICryptoService, ICodexLoginCacheService, ILiveWriteService, IAdapterRegistry, IActivationService, IVaultService, IModelFavoriteStore)
|
|
31754
33255
|
];
|
|
31755
33256
|
var _init = __decoratorStart(undefined);
|
|
31756
33257
|
|
|
@@ -31763,7 +33264,8 @@ class TransferService {
|
|
|
31763
33264
|
adapters;
|
|
31764
33265
|
activation;
|
|
31765
33266
|
vault;
|
|
31766
|
-
|
|
33267
|
+
favorites;
|
|
33268
|
+
constructor(environment, files, crypto2, codexLoginCache, liveWrite, adapters, activation, vault, favorites) {
|
|
31767
33269
|
this.environment = environment;
|
|
31768
33270
|
this.files = files;
|
|
31769
33271
|
this.crypto = crypto2;
|
|
@@ -31772,11 +33274,12 @@ class TransferService {
|
|
|
31772
33274
|
this.adapters = adapters;
|
|
31773
33275
|
this.activation = activation;
|
|
31774
33276
|
this.vault = vault;
|
|
33277
|
+
this.favorites = favorites;
|
|
31775
33278
|
}
|
|
31776
33279
|
exportPreview() {
|
|
31777
33280
|
return { codexLoginCacheAvailable: this.codexLoginCache.exists() };
|
|
31778
33281
|
}
|
|
31779
|
-
exportAll(passphrase, includeCodexLoginCache = true) {
|
|
33282
|
+
exportAll(passphrase, includeCodexLoginCache = true, legacy = false) {
|
|
31780
33283
|
this.assertPassphrase(passphrase);
|
|
31781
33284
|
const codexLoginCache = includeCodexLoginCache ? this.codexLoginCache.readOptional() : undefined;
|
|
31782
33285
|
const store = this.readStore();
|
|
@@ -31792,6 +33295,7 @@ class TransferService {
|
|
|
31792
33295
|
for (const harness of HARNESS_IDS) {
|
|
31793
33296
|
for (const [name, stored] of Object.entries(store[harness] ?? {})) {
|
|
31794
33297
|
profiles.push({
|
|
33298
|
+
...!legacy && stored.model_favorite ? { modelFavorite: stored.model_favorite } : {},
|
|
31795
33299
|
harness,
|
|
31796
33300
|
name,
|
|
31797
33301
|
baseUrl: stored.base_url || "",
|
|
@@ -31819,7 +33323,8 @@ class TransferService {
|
|
|
31819
33323
|
});
|
|
31820
33324
|
return this.seal({
|
|
31821
33325
|
format: "harness-switch-portable-config",
|
|
31822
|
-
version:
|
|
33326
|
+
version: legacy ? 1 : 2,
|
|
33327
|
+
...!legacy ? { favorites: this.favorites.list() } : {},
|
|
31823
33328
|
exportedAt: new Date().toISOString(),
|
|
31824
33329
|
profiles,
|
|
31825
33330
|
providers,
|
|
@@ -31835,6 +33340,9 @@ class TransferService {
|
|
|
31835
33340
|
const targetCodexLoginCacheExists = this.codexLoginCache.exists();
|
|
31836
33341
|
return {
|
|
31837
33342
|
exportedAt: payload.exportedAt,
|
|
33343
|
+
payloadVersion: payload.version,
|
|
33344
|
+
favoriteCount: payload.favorites?.length ?? 0,
|
|
33345
|
+
unusedFavorites: (payload.favorites ?? []).filter((favorite) => !payload.profiles.some((profile) => profile.modelFavorite?.favoriteId === favorite.id && !(conflictPolicy === "skip" && existing[profile.harness]?.[profile.name]))).map((favorite) => favorite.name),
|
|
31838
33346
|
profileCount: payload.profiles.length,
|
|
31839
33347
|
providerCount: payload.providers?.length ?? 0,
|
|
31840
33348
|
harnesses: HARNESS_IDS.map((harness) => ({
|
|
@@ -31873,11 +33381,12 @@ class TransferService {
|
|
|
31873
33381
|
harness: "codex",
|
|
31874
33382
|
profile: "导入登录缓存",
|
|
31875
33383
|
writes: cacheWrite,
|
|
31876
|
-
metadata: ["profiles", "vault"]
|
|
33384
|
+
metadata: ["profiles", "vault", "favorites"]
|
|
31877
33385
|
}, () => {
|
|
31878
33386
|
try {
|
|
31879
33387
|
this.files.writeJson(vaultPath, plan.vault);
|
|
31880
33388
|
this.files.writeJson(profilesPath, plan.store);
|
|
33389
|
+
this.files.writeJson(this.environment.files.favorites, favoriteStoreSchema.parse({ schemaVersion: 1, favorites: plan.favorites }));
|
|
31881
33390
|
} catch (error52) {
|
|
31882
33391
|
this.restore(vaultPath, vaultSnapshot);
|
|
31883
33392
|
this.restore(profilesPath, profileSnapshot);
|
|
@@ -31940,6 +33449,39 @@ class TransferService {
|
|
|
31940
33449
|
}
|
|
31941
33450
|
}
|
|
31942
33451
|
validatePayload(payload) {
|
|
33452
|
+
if (payload.version === 1 && (payload.favorites?.length || payload.profiles.some((profile) => profile.modelFavorite))) {
|
|
33453
|
+
throw new HttpError(400, ERROR_CODES.favoriteStoreInvalid, {
|
|
33454
|
+
code: ERROR_CODES.favoriteStoreInvalid
|
|
33455
|
+
});
|
|
33456
|
+
}
|
|
33457
|
+
const favorites = payload.favorites ?? [];
|
|
33458
|
+
if (new Set(favorites.map((favorite) => favorite.id)).size !== favorites.length) {
|
|
33459
|
+
throw new HttpError(400, ERROR_CODES.favoriteStoreInvalid, {
|
|
33460
|
+
code: ERROR_CODES.favoriteStoreInvalid
|
|
33461
|
+
});
|
|
33462
|
+
}
|
|
33463
|
+
for (const favorite of favorites) {
|
|
33464
|
+
for (const connection of favorite.connections) {
|
|
33465
|
+
if (!payload.providers?.some((provider) => provider.id === connection.providerId && provider.endpoints.some((endpoint) => endpoint.key === connection.endpointKey))) {
|
|
33466
|
+
throw new HttpError(400, ERROR_CODES.favoriteEndpointMissing, {
|
|
33467
|
+
code: ERROR_CODES.favoriteEndpointMissing
|
|
33468
|
+
});
|
|
33469
|
+
}
|
|
33470
|
+
}
|
|
33471
|
+
}
|
|
33472
|
+
for (const profile of payload.profiles) {
|
|
33473
|
+
const link = profile.modelFavorite;
|
|
33474
|
+
if (!link) {
|
|
33475
|
+
continue;
|
|
33476
|
+
}
|
|
33477
|
+
const favorite = favorites.find((item) => item.id === link.favoriteId);
|
|
33478
|
+
const connection = favorite?.connections.find((item) => item.id === link.connectionId);
|
|
33479
|
+
if (!connection || !payload.providers?.some((provider) => provider.id === link.baseline.providerId) || link.baseline.harness !== profile.harness || !profile.providerId || !payload.providers?.some((provider) => provider.id === profile.providerId)) {
|
|
33480
|
+
throw new HttpError(400, ERROR_CODES.favoriteStoreInvalid, {
|
|
33481
|
+
code: ERROR_CODES.favoriteStoreInvalid
|
|
33482
|
+
});
|
|
33483
|
+
}
|
|
33484
|
+
}
|
|
31943
33485
|
const profileIds = new Set;
|
|
31944
33486
|
const providerIds = new Set;
|
|
31945
33487
|
for (const provider of payload.providers ?? []) {
|
|
@@ -32017,6 +33559,27 @@ class TransferService {
|
|
|
32017
33559
|
};
|
|
32018
33560
|
providerMap.set(provider.id, targetId);
|
|
32019
33561
|
}
|
|
33562
|
+
const favorites = this.favorites.list();
|
|
33563
|
+
const favoriteMap = new Map;
|
|
33564
|
+
const connectionMap = new Map;
|
|
33565
|
+
for (const favorite of payload.favorites ?? []) {
|
|
33566
|
+
const id = randomUUID3();
|
|
33567
|
+
favoriteMap.set(favorite.id, id);
|
|
33568
|
+
favorites.push({
|
|
33569
|
+
...favorite,
|
|
33570
|
+
id,
|
|
33571
|
+
connections: favorite.connections.map((connection) => {
|
|
33572
|
+
const connectionId = randomUUID3();
|
|
33573
|
+
connectionMap.set(`${favorite.id}/${connection.id}`, connectionId);
|
|
33574
|
+
return {
|
|
33575
|
+
...connection,
|
|
33576
|
+
id: connectionId,
|
|
33577
|
+
providerId: providerMap.get(connection.providerId)
|
|
33578
|
+
};
|
|
33579
|
+
})
|
|
33580
|
+
});
|
|
33581
|
+
}
|
|
33582
|
+
favoriteStoreSchema.parse({ schemaVersion: 1, favorites });
|
|
32020
33583
|
for (const profile of selected) {
|
|
32021
33584
|
store[profile.harness] ||= {};
|
|
32022
33585
|
const exists = store[profile.harness][profile.name] !== undefined;
|
|
@@ -32026,6 +33589,15 @@ class TransferService {
|
|
|
32026
33589
|
store[profile.harness][profile.name].provider_id = mappedProvider;
|
|
32027
33590
|
store[profile.harness][profile.name].provider_endpoint = profile.providerEndpoint;
|
|
32028
33591
|
}
|
|
33592
|
+
if (profile.modelFavorite) {
|
|
33593
|
+
const link = profile.modelFavorite;
|
|
33594
|
+
store[profile.harness][profile.name].model_favorite = {
|
|
33595
|
+
...link,
|
|
33596
|
+
favoriteId: favoriteMap.get(link.favoriteId),
|
|
33597
|
+
connectionId: connectionMap.get(`${link.favoriteId}/${link.connectionId}`),
|
|
33598
|
+
baseline: { ...link.baseline, providerId: providerMap.get(link.baseline.providerId) }
|
|
33599
|
+
};
|
|
33600
|
+
}
|
|
32029
33601
|
if (exists) {
|
|
32030
33602
|
overwritten++;
|
|
32031
33603
|
} else {
|
|
@@ -32035,6 +33607,7 @@ class TransferService {
|
|
|
32035
33607
|
return {
|
|
32036
33608
|
store,
|
|
32037
33609
|
vault,
|
|
33610
|
+
favorites,
|
|
32038
33611
|
imported,
|
|
32039
33612
|
overwritten,
|
|
32040
33613
|
skipped,
|
|
@@ -32142,11 +33715,11 @@ class TransferService {
|
|
|
32142
33715
|
}
|
|
32143
33716
|
open(envelope, passphrase) {
|
|
32144
33717
|
try {
|
|
32145
|
-
const
|
|
32146
|
-
if (
|
|
33718
|
+
const sealed2 = transferEnvelopeSchema.parse(envelope);
|
|
33719
|
+
if (sealed2.cipher.data.length > MAX_ENCRYPTED_BYTES) {
|
|
32147
33720
|
throw new Error("envelope too large");
|
|
32148
33721
|
}
|
|
32149
|
-
return JSON.parse(this.crypto.open({ salt:
|
|
33722
|
+
return JSON.parse(this.crypto.open({ salt: sealed2.kdf.salt, ...sealed2.cipher }, passphrase));
|
|
32150
33723
|
} catch {
|
|
32151
33724
|
throw new HttpError(400, "迁移密码错误或导出文件已损坏", {
|
|
32152
33725
|
code: ERROR_CODES.transferDecryptFailed
|
|
@@ -32756,31 +34329,210 @@ class HarnessService {
|
|
|
32756
34329
|
this.log.error(`edit rollback: failed to restore the profile store`, error52);
|
|
32757
34330
|
return;
|
|
32758
34331
|
}
|
|
32759
|
-
if (!wasActive) {
|
|
32760
|
-
return;
|
|
34332
|
+
if (!wasActive) {
|
|
34333
|
+
return;
|
|
34334
|
+
}
|
|
34335
|
+
try {
|
|
34336
|
+
this.activation.activate(harness, name);
|
|
34337
|
+
} catch (error52) {
|
|
34338
|
+
this.log.error(`edit rollback: failed to re-activate ${harness}/${name}`, error52);
|
|
34339
|
+
}
|
|
34340
|
+
}
|
|
34341
|
+
assertNoSecondOfficialDsh(harness, input) {
|
|
34342
|
+
if (harness !== "dsh") {
|
|
34343
|
+
return;
|
|
34344
|
+
}
|
|
34345
|
+
const copiedProviderType = input.copySourceName ? this.profiles.get(harness, input.copySourceName)?.extras.providerType : undefined;
|
|
34346
|
+
if ((input.extras?.providerType ?? copiedProviderType) === "official" && this.profiles.list("dsh").some((profile) => profile.extras.providerType === "official")) {
|
|
34347
|
+
throw new HttpError(409, "DeepSeek 官方配置已存在,请直接编辑现有官方配置", {
|
|
34348
|
+
code: ERROR_CODES.officialProfileAlreadyExists
|
|
34349
|
+
});
|
|
34350
|
+
}
|
|
34351
|
+
}
|
|
34352
|
+
}
|
|
34353
|
+
HarnessService = __decorateElement(_init, 0, "HarnessService", _dec, HarnessService);
|
|
34354
|
+
__runInitializers(_init, 1, HarnessService);
|
|
34355
|
+
__decoratorMetadata(_init, HarnessService);
|
|
34356
|
+
let _HarnessService = HarnessService;
|
|
34357
|
+
|
|
34358
|
+
// src/services/model-favorite.ts
|
|
34359
|
+
import { createHmac, randomUUID as randomUUID4 } from "node:crypto";
|
|
34360
|
+
var IModelFavoriteService = createDecorator("modelFavoriteService");
|
|
34361
|
+
var _dec = [
|
|
34362
|
+
inject(IModelFavoriteStore, IProfileService, IVaultService, IAdapterRegistry, ILiveWriteService, IFavoriteBackupService)
|
|
34363
|
+
];
|
|
34364
|
+
var _init = __decoratorStart(undefined);
|
|
34365
|
+
|
|
34366
|
+
class ModelFavoriteService {
|
|
34367
|
+
store;
|
|
34368
|
+
profiles;
|
|
34369
|
+
vault;
|
|
34370
|
+
adapters;
|
|
34371
|
+
liveWrite;
|
|
34372
|
+
backups;
|
|
34373
|
+
sourceSalt = randomUUID4();
|
|
34374
|
+
constructor(store, profiles, vault, adapters, liveWrite, backups) {
|
|
34375
|
+
this.store = store;
|
|
34376
|
+
this.profiles = profiles;
|
|
34377
|
+
this.vault = vault;
|
|
34378
|
+
this.adapters = adapters;
|
|
34379
|
+
this.liveWrite = liveWrite;
|
|
34380
|
+
this.backups = backups;
|
|
34381
|
+
}
|
|
34382
|
+
list() {
|
|
34383
|
+
return this.store.list().map((favorite) => ({ ...favorite, references: this.references(favorite.id) }));
|
|
34384
|
+
}
|
|
34385
|
+
references(id) {
|
|
34386
|
+
return HARNESS_IDS.flatMap((harness) => this.profiles.list(harness).flatMap((profile) => profile.modelFavorite?.favoriteId === id ? [{ harness, name: profile.name, link: profile.modelFavorite }] : []));
|
|
34387
|
+
}
|
|
34388
|
+
create(input) {
|
|
34389
|
+
const parsed = createFavoriteRequestSchema.parse(input);
|
|
34390
|
+
this.validateConnections(parsed);
|
|
34391
|
+
return this.backups.protect("change", () => this.store.create(parsed), {
|
|
34392
|
+
action: "create",
|
|
34393
|
+
name: parsed.name
|
|
34394
|
+
});
|
|
34395
|
+
}
|
|
34396
|
+
update(id, input) {
|
|
34397
|
+
this.store.assertRevision(id, input.expectedRevision);
|
|
34398
|
+
const current = this.store.get(id);
|
|
34399
|
+
const next = createFavoriteRequestSchema.parse({ ...current, ...input });
|
|
34400
|
+
this.validateConnections(next);
|
|
34401
|
+
if (this.references(id).some((ref) => !next.connections.some((connection) => connection.id === ref.link.connectionId))) {
|
|
34402
|
+
throw new HttpError(409, ERROR_CODES.favoriteConnectionInUse, {
|
|
34403
|
+
code: ERROR_CODES.favoriteConnectionInUse
|
|
34404
|
+
});
|
|
34405
|
+
}
|
|
34406
|
+
return this.backups.protect("change", () => this.store.update(id, next, input.expectedRevision), { action: "update", name: current.name });
|
|
34407
|
+
}
|
|
34408
|
+
remove(id, revision) {
|
|
34409
|
+
this.store.assertRevision(id, revision);
|
|
34410
|
+
if (this.references(id).length) {
|
|
34411
|
+
throw new HttpError(409, ERROR_CODES.favoriteInUse, { code: ERROR_CODES.favoriteInUse });
|
|
34412
|
+
}
|
|
34413
|
+
this.backups.protect("change", () => this.store.remove(id, revision), {
|
|
34414
|
+
action: "delete",
|
|
34415
|
+
name: this.store.get(id).name
|
|
34416
|
+
});
|
|
34417
|
+
}
|
|
34418
|
+
sourceFingerprint(harness, name) {
|
|
34419
|
+
const profile = this.profiles.get(harness, name);
|
|
34420
|
+
if (!profile) {
|
|
34421
|
+
throw new HttpError(404, ERROR_CODES.profileNotFound, { code: ERROR_CODES.profileNotFound });
|
|
34422
|
+
}
|
|
34423
|
+
return createHmac("sha256", this.sourceSalt).update(this.profiles.fingerprint(harness, name)).digest("hex");
|
|
34424
|
+
}
|
|
34425
|
+
capture(input) {
|
|
34426
|
+
if (this.sourceFingerprint(input.harness, input.name) !== input.sourceFingerprint) {
|
|
34427
|
+
throw new HttpError(409, ERROR_CODES.favoritePlanStale, {
|
|
34428
|
+
code: ERROR_CODES.favoritePlanStale
|
|
34429
|
+
});
|
|
34430
|
+
}
|
|
34431
|
+
const source = this.profiles.get(input.harness, input.name);
|
|
34432
|
+
if (source.overriddenTargets.length || source.modelFavorite) {
|
|
34433
|
+
throw new HttpError(409, ERROR_CODES.favoriteRawOverrideConflict, {
|
|
34434
|
+
code: ERROR_CODES.favoriteRawOverrideConflict
|
|
34435
|
+
});
|
|
32761
34436
|
}
|
|
32762
|
-
|
|
32763
|
-
|
|
32764
|
-
|
|
32765
|
-
|
|
34437
|
+
const decrypted = this.profiles.decrypt(input.harness, input.name);
|
|
34438
|
+
const adapter = this.adapters.get(input.harness);
|
|
34439
|
+
const extracted = adapter.extractFavorite(decrypted);
|
|
34440
|
+
if (!source.providerId && !input.extractCredential) {
|
|
34441
|
+
throw new HttpError(409, ERROR_CODES.favoriteCredentialConsentRequired, {
|
|
34442
|
+
code: ERROR_CODES.favoriteCredentialConsentRequired
|
|
34443
|
+
});
|
|
32766
34444
|
}
|
|
34445
|
+
return this.backups.protect("change", () => this.liveWrite.transaction({
|
|
34446
|
+
kind: "favorite-capture",
|
|
34447
|
+
harness: input.harness,
|
|
34448
|
+
profile: input.name,
|
|
34449
|
+
writes: [],
|
|
34450
|
+
metadata: ["profiles", "vault", "favorites"]
|
|
34451
|
+
}, () => {
|
|
34452
|
+
const provider = source.providerId ? this.vault.get(source.providerId) : this.vault.create({
|
|
34453
|
+
name: input.favoriteName,
|
|
34454
|
+
apiKey: decrypted.apiKey,
|
|
34455
|
+
endpoints: [{ key: "api", baseUrl: decrypted.baseUrl }]
|
|
34456
|
+
});
|
|
34457
|
+
const endpointKey = source.providerEndpoint ?? provider.endpoints.find((endpoint) => endpoint.baseUrl === decrypted.baseUrl)?.key;
|
|
34458
|
+
if (!endpointKey) {
|
|
34459
|
+
throw new HttpError(409, ERROR_CODES.favoriteEndpointMissing, {
|
|
34460
|
+
code: ERROR_CODES.favoriteEndpointMissing
|
|
34461
|
+
});
|
|
34462
|
+
}
|
|
34463
|
+
if (!source.providerId || !source.providerEndpoint) {
|
|
34464
|
+
this.profiles.upsert(input.harness, { name: input.name, providerId: provider.id, providerEndpoint: endpointKey }, false);
|
|
34465
|
+
}
|
|
34466
|
+
const favorite = this.create({
|
|
34467
|
+
name: input.favoriteName,
|
|
34468
|
+
notes: "",
|
|
34469
|
+
defaults: extracted.defaults,
|
|
34470
|
+
preferences: extracted.preferences,
|
|
34471
|
+
connections: [
|
|
34472
|
+
{
|
|
34473
|
+
id: randomUUID4(),
|
|
34474
|
+
label: provider.name,
|
|
34475
|
+
providerId: provider.id,
|
|
34476
|
+
endpointKey,
|
|
34477
|
+
protocol: extracted.protocol,
|
|
34478
|
+
requestModelId: extracted.requestModelId,
|
|
34479
|
+
factOverrides: {},
|
|
34480
|
+
preferenceOverrides: {}
|
|
34481
|
+
}
|
|
34482
|
+
]
|
|
34483
|
+
});
|
|
34484
|
+
if (input.linkSource) {
|
|
34485
|
+
const connection = favorite.connections[0];
|
|
34486
|
+
const projection = adapter.projectFavorite(favorite, connection);
|
|
34487
|
+
const current = this.profiles.get(input.harness, input.name);
|
|
34488
|
+
const baseline = {
|
|
34489
|
+
...projection.projection,
|
|
34490
|
+
model: current.model,
|
|
34491
|
+
providerId: current.providerId ?? "",
|
|
34492
|
+
providerEndpoint: current.providerEndpoint ?? "",
|
|
34493
|
+
extras: Object.fromEntries(Object.keys(projection.projection.extras).map((key) => [
|
|
34494
|
+
key,
|
|
34495
|
+
current.extras[key] ?? null
|
|
34496
|
+
]))
|
|
34497
|
+
};
|
|
34498
|
+
this.profiles.setFavoriteLink(input.harness, input.name, {
|
|
34499
|
+
favoriteId: favorite.id,
|
|
34500
|
+
connectionId: connection.id,
|
|
34501
|
+
appliedRevision: favorite.revision,
|
|
34502
|
+
projectionVersion: projection.projectionVersion,
|
|
34503
|
+
baseline
|
|
34504
|
+
});
|
|
34505
|
+
}
|
|
34506
|
+
return favorite;
|
|
34507
|
+
}), { action: "capture", name: input.favoriteName, tools: [input.harness] });
|
|
32767
34508
|
}
|
|
32768
|
-
|
|
32769
|
-
if (harness !==
|
|
32770
|
-
|
|
32771
|
-
|
|
32772
|
-
const copiedProviderType = input.copySourceName ? this.profiles.get(harness, input.copySourceName)?.extras.providerType : undefined;
|
|
32773
|
-
if ((input.extras?.providerType ?? copiedProviderType) === "official" && this.profiles.list("dsh").some((profile) => profile.extras.providerType === "official")) {
|
|
32774
|
-
throw new HttpError(409, "DeepSeek 官方配置已存在,请直接编辑现有官方配置", {
|
|
32775
|
-
code: ERROR_CODES.officialProfileAlreadyExists
|
|
34509
|
+
detach(harness, name, fingerprint2) {
|
|
34510
|
+
if (this.sourceFingerprint(harness, name) !== fingerprint2) {
|
|
34511
|
+
throw new HttpError(409, ERROR_CODES.favoritePlanStale, {
|
|
34512
|
+
code: ERROR_CODES.favoritePlanStale
|
|
32776
34513
|
});
|
|
32777
34514
|
}
|
|
34515
|
+
this.backups.protect("change", () => this.profiles.setFavoriteLink(harness, name, undefined), {
|
|
34516
|
+
action: "detach",
|
|
34517
|
+
name,
|
|
34518
|
+
tools: [harness]
|
|
34519
|
+
});
|
|
34520
|
+
}
|
|
34521
|
+
validateConnections(input) {
|
|
34522
|
+
for (const connection of input.connections) {
|
|
34523
|
+
const provider = this.vault.get(connection.providerId);
|
|
34524
|
+
if (!provider.endpoints.some((endpoint) => endpoint.key === connection.endpointKey)) {
|
|
34525
|
+
throw new HttpError(409, ERROR_CODES.favoriteEndpointMissing, {
|
|
34526
|
+
code: ERROR_CODES.favoriteEndpointMissing
|
|
34527
|
+
});
|
|
34528
|
+
}
|
|
34529
|
+
}
|
|
32778
34530
|
}
|
|
32779
34531
|
}
|
|
32780
|
-
|
|
32781
|
-
__runInitializers(_init, 1,
|
|
32782
|
-
__decoratorMetadata(_init,
|
|
32783
|
-
let
|
|
34532
|
+
ModelFavoriteService = __decorateElement(_init, 0, "ModelFavoriteService", _dec, ModelFavoriteService);
|
|
34533
|
+
__runInitializers(_init, 1, ModelFavoriteService);
|
|
34534
|
+
__decoratorMetadata(_init, ModelFavoriteService);
|
|
34535
|
+
let _ModelFavoriteService = ModelFavoriteService;
|
|
32784
34536
|
|
|
32785
34537
|
// src/http/routes/harnesses.ts
|
|
32786
34538
|
function createHarnessRoutes(services) {
|
|
@@ -32790,6 +34542,11 @@ function createHarnessRoutes(services) {
|
|
|
32790
34542
|
const profiles = services.get(IProfileService);
|
|
32791
34543
|
const activation = services.get(IActivationService);
|
|
32792
34544
|
const profileProbe = services.get(IProbeProfileService);
|
|
34545
|
+
app.post("/:harnessId/profiles/:name/detach-favorite", async (c) => {
|
|
34546
|
+
const body = await readJsonBody(c, favoriteDetachRequestSchema);
|
|
34547
|
+
services.get(IModelFavoriteService).detach(registry2.require(param(c, "harnessId")), param(c, "name"), body.sourceFingerprint);
|
|
34548
|
+
return c.json({ code: FAVORITE_CODES.result, data: { ok: true } });
|
|
34549
|
+
});
|
|
32793
34550
|
app.get("/", (c) => c.json(harnesses.overview()));
|
|
32794
34551
|
app.get("/:harnessId", (c) => c.json(harnesses.summary(registry2.require(c.req.param("harnessId")))));
|
|
32795
34552
|
app.post("/:harnessId/profiles", async (c) => {
|
|
@@ -32836,6 +34593,505 @@ function createHarnessRoutes(services) {
|
|
|
32836
34593
|
return app;
|
|
32837
34594
|
}
|
|
32838
34595
|
|
|
34596
|
+
// src/services/model-favorite-apply.ts
|
|
34597
|
+
import { createHash as createHash7, randomUUID as randomUUID5 } from "node:crypto";
|
|
34598
|
+
|
|
34599
|
+
// src/services/model-favorite-preview.ts
|
|
34600
|
+
var nativeValueSchema = exports_external.json();
|
|
34601
|
+
var CREDENTIAL_FIELD = /(?:api[_-]?key|(?:^|[_-])(?:key|token|secret|password|passwd|credentials?|authorization|cookie)$|^tokens$|accessToken$|refreshToken$|idToken$|authToken$|clientSecret$|privateKey$)/i;
|
|
34602
|
+
function favoriteNativePreview(format, content, credentials = []) {
|
|
34603
|
+
if (content === undefined) {
|
|
34604
|
+
return null;
|
|
34605
|
+
}
|
|
34606
|
+
const parsed = format === "json" ? parseJsonObject(content) : format === "toml" ? parseTomlObject(content) : format === "yaml" ? parseYamlDocument(content).toJSON() : null;
|
|
34607
|
+
const value = nativeValueSchema.parse(JSON.parse(JSON.stringify(parsed)));
|
|
34608
|
+
return JSON.stringify(redact(value, credentials), null, 2);
|
|
34609
|
+
}
|
|
34610
|
+
function redact(value, credentials, secret = false) {
|
|
34611
|
+
if (typeof value === "string") {
|
|
34612
|
+
if (secret || credentials.some((credential) => credential && value.includes(credential))) {
|
|
34613
|
+
return "[redacted]";
|
|
34614
|
+
}
|
|
34615
|
+
try {
|
|
34616
|
+
const url2 = new URL(value);
|
|
34617
|
+
if (url2.username || url2.password) {
|
|
34618
|
+
url2.username = "[redacted]";
|
|
34619
|
+
url2.password = "";
|
|
34620
|
+
}
|
|
34621
|
+
for (const key of url2.searchParams.keys()) {
|
|
34622
|
+
if (CREDENTIAL_FIELD.test(key)) {
|
|
34623
|
+
url2.searchParams.set(key, "[redacted]");
|
|
34624
|
+
}
|
|
34625
|
+
}
|
|
34626
|
+
return url2.href === new URL(value).href ? value : url2.href;
|
|
34627
|
+
} catch {
|
|
34628
|
+
return value;
|
|
34629
|
+
}
|
|
34630
|
+
}
|
|
34631
|
+
if (Array.isArray(value)) {
|
|
34632
|
+
return value.map((item) => redact(item, credentials, secret));
|
|
34633
|
+
}
|
|
34634
|
+
if (value && typeof value === "object") {
|
|
34635
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [
|
|
34636
|
+
key,
|
|
34637
|
+
redact(item, credentials, secret || CREDENTIAL_FIELD.test(key))
|
|
34638
|
+
]));
|
|
34639
|
+
}
|
|
34640
|
+
return secret && value !== null ? "[redacted]" : value;
|
|
34641
|
+
}
|
|
34642
|
+
|
|
34643
|
+
// src/services/model-favorite-apply.ts
|
|
34644
|
+
var IModelFavoriteApplyService = createDecorator("modelFavoriteApplyService");
|
|
34645
|
+
var _dec = [
|
|
34646
|
+
inject(IEnvironmentService, IFileService, IModelFavoriteStore, IProfileService, IVaultService, IAdapterRegistry, IActivationService, ILiveWriteService, IJournalService, IDriftService, IFavoriteBackupService)
|
|
34647
|
+
];
|
|
34648
|
+
var _init = __decoratorStart(undefined);
|
|
34649
|
+
|
|
34650
|
+
class ModelFavoriteApplyService {
|
|
34651
|
+
environment;
|
|
34652
|
+
files;
|
|
34653
|
+
favorites;
|
|
34654
|
+
profiles;
|
|
34655
|
+
vault;
|
|
34656
|
+
adapters;
|
|
34657
|
+
activation;
|
|
34658
|
+
liveWrite;
|
|
34659
|
+
journal;
|
|
34660
|
+
drift;
|
|
34661
|
+
backups;
|
|
34662
|
+
plans = new Map;
|
|
34663
|
+
constructor(environment, files, favorites, profiles, vault, adapters, activation, liveWrite, journal, drift, backups) {
|
|
34664
|
+
this.environment = environment;
|
|
34665
|
+
this.files = files;
|
|
34666
|
+
this.favorites = favorites;
|
|
34667
|
+
this.profiles = profiles;
|
|
34668
|
+
this.vault = vault;
|
|
34669
|
+
this.adapters = adapters;
|
|
34670
|
+
this.activation = activation;
|
|
34671
|
+
this.liveWrite = liveWrite;
|
|
34672
|
+
this.journal = journal;
|
|
34673
|
+
this.drift = drift;
|
|
34674
|
+
this.backups = backups;
|
|
34675
|
+
}
|
|
34676
|
+
state(profile) {
|
|
34677
|
+
const link = profile.modelFavorite;
|
|
34678
|
+
const favorite = link ? this.favorites.list().find((item) => item.id === link.favoriteId) : undefined;
|
|
34679
|
+
const connection = favorite?.connections.find((item) => item.id === link?.connectionId);
|
|
34680
|
+
const projected = favorite && connection ? this.adapters.get(profile.harness).projectFavorite(favorite, connection, link?.baseline) : undefined;
|
|
34681
|
+
return {
|
|
34682
|
+
sourceMissing: !!link && !favorite,
|
|
34683
|
+
connectionMissing: !!link && !connection,
|
|
34684
|
+
needsUpdate: !!link && !!projected && (link.projectionVersion !== projected.projectionVersion || hash2(link.baseline) !== hash2(projected.projection)),
|
|
34685
|
+
diverged: !!link && (profile.overriddenTargets.length > 0 || hash2(snapshot(profile, link.baseline)) !== hash2(link.baseline))
|
|
34686
|
+
};
|
|
34687
|
+
}
|
|
34688
|
+
plan(request, session) {
|
|
34689
|
+
const favorite = this.favorites.get(request.favoriteId);
|
|
34690
|
+
if (favorite.revision !== request.expectedRevision) {
|
|
34691
|
+
throw failure2(ERROR_CODES.favoriteRevisionConflict);
|
|
34692
|
+
}
|
|
34693
|
+
for (const [id, value] of this.plans) {
|
|
34694
|
+
if (Date.parse(value.public.expiresAt) < Date.now()) {
|
|
34695
|
+
this.plans.delete(id);
|
|
34696
|
+
}
|
|
34697
|
+
}
|
|
34698
|
+
if (this.plans.size >= 1000) {
|
|
34699
|
+
throw failure2(ERROR_CODES.favoriteLimitReached);
|
|
34700
|
+
}
|
|
34701
|
+
const items = request.items.toSorted((a, b) => HARNESS_IDS.indexOf(a.harness) - HARNESS_IDS.indexOf(b.harness)).map((selection) => {
|
|
34702
|
+
const connection = favorite.connections.find((item2) => item2.id === selection.connectionId);
|
|
34703
|
+
if (!connection) {
|
|
34704
|
+
throw failure2(ERROR_CODES.favoriteEndpointMissing);
|
|
34705
|
+
}
|
|
34706
|
+
const provider = this.vault.get(connection.providerId);
|
|
34707
|
+
const endpoint = provider.endpoints.find((item2) => item2.key === connection.endpointKey);
|
|
34708
|
+
if (!endpoint) {
|
|
34709
|
+
throw failure2(ERROR_CODES.favoriteEndpointMissing);
|
|
34710
|
+
}
|
|
34711
|
+
const adapter = this.adapters.get(selection.harness);
|
|
34712
|
+
let name = selection.profile ?? favorite.name.replace(/[\\/]/g, "-");
|
|
34713
|
+
if (!selection.existing && !selection.profile) {
|
|
34714
|
+
let suffix = 2;
|
|
34715
|
+
const base = name;
|
|
34716
|
+
while (this.profiles.get(selection.harness, name)) {
|
|
34717
|
+
name = `${base.slice(0, 110)}-${suffix++}`;
|
|
34718
|
+
}
|
|
34719
|
+
}
|
|
34720
|
+
const prior = this.profiles.get(selection.harness, name);
|
|
34721
|
+
if (selection.existing ? prior?.modelFavorite?.favoriteId !== favorite.id : !!prior) {
|
|
34722
|
+
throw failure2(ERROR_CODES.favoriteInUse);
|
|
34723
|
+
}
|
|
34724
|
+
if (prior?.overriddenTargets.length) {
|
|
34725
|
+
throw failure2(ERROR_CODES.favoriteRawOverrideConflict);
|
|
34726
|
+
}
|
|
34727
|
+
const projection = adapter.projectFavorite(favorite, connection, prior?.modelFavorite?.baseline);
|
|
34728
|
+
if (prior && this.state(prior).diverged && !selection.overwriteDiverged) {
|
|
34729
|
+
projection.blockers.push({ code: ERROR_CODES.favoriteProfileDiverged });
|
|
34730
|
+
}
|
|
34731
|
+
if (projection.notRepresented.includes("reasoningEffort") && !selection.ignorePreference) {
|
|
34732
|
+
projection.blockers.push({ code: ERROR_CODES.favoritePreferenceNotRepresented });
|
|
34733
|
+
}
|
|
34734
|
+
const extras = { ...prior?.extras };
|
|
34735
|
+
if (!prior && ["pi", "dsh", "codex", "kimi"].includes(selection.harness)) {
|
|
34736
|
+
extras.providerId = `hsw-mf-${randomUUID5()}`;
|
|
34737
|
+
}
|
|
34738
|
+
for (const [key, value] of Object.entries(projection.projection.extras)) {
|
|
34739
|
+
if (value === null) {
|
|
34740
|
+
delete extras[key];
|
|
34741
|
+
} else {
|
|
34742
|
+
extras[key] = value;
|
|
34743
|
+
}
|
|
34744
|
+
}
|
|
34745
|
+
for (const key of Object.keys(projection.rendererDefaults)) {
|
|
34746
|
+
if (extras[key]) {
|
|
34747
|
+
delete projection.rendererDefaults[key];
|
|
34748
|
+
}
|
|
34749
|
+
}
|
|
34750
|
+
const profile = {
|
|
34751
|
+
favoriteManaged: true,
|
|
34752
|
+
name,
|
|
34753
|
+
model: connection.requestModelId,
|
|
34754
|
+
extras,
|
|
34755
|
+
baseUrl: endpoint.baseUrl,
|
|
34756
|
+
apiKey: this.vault.decrypt(provider.id)
|
|
34757
|
+
};
|
|
34758
|
+
adapter.validate?.(profile);
|
|
34759
|
+
const input = {
|
|
34760
|
+
name,
|
|
34761
|
+
model: profile.model,
|
|
34762
|
+
extras,
|
|
34763
|
+
baseUrl: profile.baseUrl,
|
|
34764
|
+
providerId: provider.id,
|
|
34765
|
+
providerEndpoint: endpoint.key
|
|
34766
|
+
};
|
|
34767
|
+
const diff = projection.ownedFields.flatMap((field) => {
|
|
34768
|
+
const before = field.startsWith("extras.") ? prior?.extras[field.slice(7)] ?? null : field === "model" ? prior?.model ?? null : field === "providerId" ? prior?.providerId ?? null : prior?.providerEndpoint ?? null;
|
|
34769
|
+
const after = projection.set[field] ?? null;
|
|
34770
|
+
return before === after ? [] : [{ field, before, after }];
|
|
34771
|
+
});
|
|
34772
|
+
if (selection.mode === "save" && this.activation.getActive(selection.harness)?.name === name && (diff.length || prior?.baseUrl !== endpoint.baseUrl)) {
|
|
34773
|
+
projection.blockers.push({ code: ERROR_CODES.favoriteActiveUpdateRequiresApply });
|
|
34774
|
+
}
|
|
34775
|
+
if (selection.mode === "activate" && selection.harness === "codex" && extras.authMode === "openai_auth" && selection.allowAuthOverwrite !== true) {
|
|
34776
|
+
projection.blockers.push({ code: ERROR_CODES.favoriteProjectionUnsupported });
|
|
34777
|
+
}
|
|
34778
|
+
const current = Object.fromEntries(adapter.targets().map((target) => [target.key, this.files.readOptional(target.path)]));
|
|
34779
|
+
if (!prior && extras.providerId && Object.values(current).some((content) => content?.includes(extras.providerId))) {
|
|
34780
|
+
projection.blockers.push({ code: ERROR_CODES.favoriteInUse });
|
|
34781
|
+
}
|
|
34782
|
+
let writes = [];
|
|
34783
|
+
if (selection.mode === "activate" && projection.blockers.length === 0) {
|
|
34784
|
+
try {
|
|
34785
|
+
writes = this.activation.prepareFavorite(selection.harness, profile);
|
|
34786
|
+
} catch (error52) {
|
|
34787
|
+
projection.blockers.push({
|
|
34788
|
+
code: error52 instanceof HttpError ? error52.code : ERROR_CODES.nativeConfigInvalid
|
|
34789
|
+
});
|
|
34790
|
+
}
|
|
34791
|
+
}
|
|
34792
|
+
const item = {
|
|
34793
|
+
preservedFields: Object.keys(prior?.extras ?? {}).filter((key) => !Object.hasOwn(projection.projection.extras, key)),
|
|
34794
|
+
authMode: extras.authMode ?? extras.authVar ?? adapter.fields.find((field) => field.key === "authMode" || field.key === "authVar")?.defaultValue ?? "apiKey",
|
|
34795
|
+
liveState: selection.mode === "activate" ? this.drift.inspect(selection.harness).status : "unknown",
|
|
34796
|
+
...selection,
|
|
34797
|
+
profile: name,
|
|
34798
|
+
projection,
|
|
34799
|
+
resolved: resolveFavorite(favorite, connection),
|
|
34800
|
+
diff,
|
|
34801
|
+
nativeFiles: writes.map((write) => ({
|
|
34802
|
+
key: write.key,
|
|
34803
|
+
changed: current[write.key] !== write.content,
|
|
34804
|
+
before: favoriteNativePreview(write.format, current[write.key], [profile.apiKey]),
|
|
34805
|
+
after: favoriteNativePreview(write.format, write.content, [profile.apiKey])
|
|
34806
|
+
}))
|
|
34807
|
+
};
|
|
34808
|
+
return {
|
|
34809
|
+
public: item,
|
|
34810
|
+
input,
|
|
34811
|
+
profile,
|
|
34812
|
+
link: {
|
|
34813
|
+
favoriteId: favorite.id,
|
|
34814
|
+
connectionId: connection.id,
|
|
34815
|
+
appliedRevision: favorite.revision,
|
|
34816
|
+
projectionVersion: projection.projectionVersion,
|
|
34817
|
+
baseline: projection.projection
|
|
34818
|
+
},
|
|
34819
|
+
writes,
|
|
34820
|
+
fingerprint: this.fingerprint(favorite.id, item)
|
|
34821
|
+
};
|
|
34822
|
+
});
|
|
34823
|
+
const plan = {
|
|
34824
|
+
id: randomUUID5(),
|
|
34825
|
+
expiresAt: new Date(Date.now() + 600000).toISOString(),
|
|
34826
|
+
favoriteRevision: favorite.revision,
|
|
34827
|
+
items: items.map((item) => item.public)
|
|
34828
|
+
};
|
|
34829
|
+
this.plans.set(plan.id, {
|
|
34830
|
+
public: plan,
|
|
34831
|
+
items,
|
|
34832
|
+
user: this.environment.dataDir,
|
|
34833
|
+
session,
|
|
34834
|
+
favoriteId: favorite.id
|
|
34835
|
+
});
|
|
34836
|
+
return plan;
|
|
34837
|
+
}
|
|
34838
|
+
operation(requestId) {
|
|
34839
|
+
const receipts = this.journal.list().filter((receipt) => receipt.favoriteRequest?.requestId === requestId).toSorted((a, b) => a.favoriteRequest.item - b.favoriteRequest.item);
|
|
34840
|
+
return {
|
|
34841
|
+
requestId,
|
|
34842
|
+
items: [
|
|
34843
|
+
...receipts.map((receipt) => ({
|
|
34844
|
+
harness: receipt.harness,
|
|
34845
|
+
profile: receipt.profile,
|
|
34846
|
+
operationId: receipt.id,
|
|
34847
|
+
code: receipt.favoriteResult?.code,
|
|
34848
|
+
status: receipt.state === "committed" || receipt.state === "metadata-committed" ? receipt.favoriteResult?.status ?? "applied" : receipt.state === "rolled-back" || receipt.state === "degraded" ? "failed" : "skipped"
|
|
34849
|
+
})),
|
|
34850
|
+
...(receipts[0]?.favoriteRequest?.targets ?? []).filter((target) => !receipts.some((receipt) => receipt.harness === target.harness)).map((target) => ({
|
|
34851
|
+
...target,
|
|
34852
|
+
status: "skipped",
|
|
34853
|
+
code: ERROR_CODES.favoritePlanExpired
|
|
34854
|
+
}))
|
|
34855
|
+
]
|
|
34856
|
+
};
|
|
34857
|
+
}
|
|
34858
|
+
apply(id, requestId, session) {
|
|
34859
|
+
const receipts = this.journal.list().filter((receipt) => receipt.favoriteRequest?.requestId === requestId);
|
|
34860
|
+
if (receipts.length) {
|
|
34861
|
+
if (receipts.some((receipt) => receipt.favoriteRequest?.planId !== id)) {
|
|
34862
|
+
throw failure2(ERROR_CODES.favoriteIdempotencyConflict);
|
|
34863
|
+
}
|
|
34864
|
+
return this.operation(requestId);
|
|
34865
|
+
}
|
|
34866
|
+
const plan = this.plans.get(id);
|
|
34867
|
+
if (!plan || plan.user !== this.environment.dataDir || plan.session !== session || Date.parse(plan.public.expiresAt) < Date.now()) {
|
|
34868
|
+
throw failure2(ERROR_CODES.favoritePlanExpired);
|
|
34869
|
+
}
|
|
34870
|
+
for (const prepared of plan.items) {
|
|
34871
|
+
if (!this.matchesFingerprint(plan.favoriteId, prepared)) {
|
|
34872
|
+
throw failure2(ERROR_CODES.favoritePlanStale);
|
|
34873
|
+
}
|
|
34874
|
+
if (prepared.public.projection.blockers.length) {
|
|
34875
|
+
throw failure2(prepared.public.projection.blockers[0].code);
|
|
34876
|
+
}
|
|
34877
|
+
}
|
|
34878
|
+
this.backups.create("apply", {
|
|
34879
|
+
action: "apply",
|
|
34880
|
+
name: this.favorites.get(plan.favoriteId).name,
|
|
34881
|
+
tools: plan.items.map((item) => item.public.harness)
|
|
34882
|
+
});
|
|
34883
|
+
const result = { requestId, items: [] };
|
|
34884
|
+
for (const [index, prepared] of plan.items.entries()) {
|
|
34885
|
+
const item = prepared.public;
|
|
34886
|
+
if (!this.matchesFingerprint(plan.favoriteId, prepared)) {
|
|
34887
|
+
throw failure2(ERROR_CODES.favoritePlanStale);
|
|
34888
|
+
}
|
|
34889
|
+
if (item.projection.blockers.length) {
|
|
34890
|
+
throw failure2(item.projection.blockers[0].code);
|
|
34891
|
+
}
|
|
34892
|
+
const unchanged = item.existing && item.diff.length === 0 && (item.mode === "save" || this.activation.getActive(item.harness)?.name === item.profile && item.nativeFiles.every((file2) => !file2.changed));
|
|
34893
|
+
try {
|
|
34894
|
+
this.liveWrite.transaction({
|
|
34895
|
+
kind: "favorite-apply",
|
|
34896
|
+
harness: item.harness,
|
|
34897
|
+
profile: item.profile,
|
|
34898
|
+
writes: unchanged ? [] : prepared.writes,
|
|
34899
|
+
metadata: item.mode === "activate" && !unchanged ? ["profiles", "active"] : ["profiles"],
|
|
34900
|
+
favoriteRequest: {
|
|
34901
|
+
version: 1,
|
|
34902
|
+
requestId,
|
|
34903
|
+
planId: id,
|
|
34904
|
+
item: index,
|
|
34905
|
+
approvalHash: hash2(plan.public),
|
|
34906
|
+
targets: plan.items.map((entry) => ({
|
|
34907
|
+
harness: entry.public.harness,
|
|
34908
|
+
profile: entry.public.profile
|
|
34909
|
+
}))
|
|
34910
|
+
},
|
|
34911
|
+
favoriteResult: { status: unchanged ? "unchanged" : "applied" },
|
|
34912
|
+
beforeWrites: item.mode === "activate" && !unchanged ? () => this.activation.commitFavorite(item.harness, prepared.profile) : undefined
|
|
34913
|
+
}, () => {
|
|
34914
|
+
if (unchanged) {
|
|
34915
|
+
this.profiles.setFavoriteLink(item.harness, item.profile, prepared.link);
|
|
34916
|
+
return;
|
|
34917
|
+
}
|
|
34918
|
+
if (item.existing) {
|
|
34919
|
+
this.profiles.setFavoriteLink(item.harness, item.profile, undefined);
|
|
34920
|
+
}
|
|
34921
|
+
this.profiles.upsert(item.harness, prepared.input, !item.existing);
|
|
34922
|
+
this.profiles.setFavoriteLink(item.harness, item.profile, prepared.link);
|
|
34923
|
+
});
|
|
34924
|
+
if (item.mode === "activate" && !unchanged) {
|
|
34925
|
+
try {
|
|
34926
|
+
this.activation.refreshEnv();
|
|
34927
|
+
} catch {
|
|
34928
|
+
const receipt = this.journal.list().find((entry) => entry.favoriteRequest?.requestId === requestId && entry.favoriteRequest.item === index);
|
|
34929
|
+
if (receipt) {
|
|
34930
|
+
this.journal.setFavoriteResult(receipt.id, {
|
|
34931
|
+
status: unchanged ? "unchanged" : "applied",
|
|
34932
|
+
code: WARNING_CODES.envRebuildFailed
|
|
34933
|
+
});
|
|
34934
|
+
}
|
|
34935
|
+
}
|
|
34936
|
+
}
|
|
34937
|
+
} catch (error52) {
|
|
34938
|
+
result.items.push({
|
|
34939
|
+
harness: item.harness,
|
|
34940
|
+
profile: item.profile,
|
|
34941
|
+
status: "failed",
|
|
34942
|
+
code: error52 instanceof HttpError ? error52.code : ERROR_CODES.requestFailed
|
|
34943
|
+
});
|
|
34944
|
+
if (this.journal.list().some((receipt) => receipt.favoriteRequest?.requestId === requestId && receipt.state === "degraded") || !this.journal.list().some((receipt) => receipt.favoriteRequest?.requestId === requestId && receipt.favoriteRequest.item === index)) {
|
|
34945
|
+
break;
|
|
34946
|
+
}
|
|
34947
|
+
}
|
|
34948
|
+
}
|
|
34949
|
+
this.plans.delete(id);
|
|
34950
|
+
return {
|
|
34951
|
+
requestId,
|
|
34952
|
+
items: [
|
|
34953
|
+
...this.operation(requestId).items,
|
|
34954
|
+
...result.items.filter((item) => !this.operation(requestId).items.some((saved) => saved.harness === item.harness))
|
|
34955
|
+
]
|
|
34956
|
+
};
|
|
34957
|
+
}
|
|
34958
|
+
matchesFingerprint(favoriteId, prepared) {
|
|
34959
|
+
try {
|
|
34960
|
+
return prepared.fingerprint === this.fingerprint(favoriteId, prepared.public);
|
|
34961
|
+
} catch {
|
|
34962
|
+
return false;
|
|
34963
|
+
}
|
|
34964
|
+
}
|
|
34965
|
+
fingerprint(favoriteId, item) {
|
|
34966
|
+
const favorite = this.favorites.get(favoriteId);
|
|
34967
|
+
const connection = favorite.connections.find((entry) => entry.id === item.connectionId);
|
|
34968
|
+
return hash2({
|
|
34969
|
+
favorite,
|
|
34970
|
+
profile: this.profiles.fingerprint(item.harness, item.profile),
|
|
34971
|
+
credential: connection ? this.vault.decrypt(connection.providerId) : null,
|
|
34972
|
+
provider: connection ? this.vault.get(connection.providerId) : null,
|
|
34973
|
+
active: this.activation.fingerprint(item.harness),
|
|
34974
|
+
files: this.adapters.get(item.harness).targets().map((target) => [target.key, this.files.readOptional(target.path)])
|
|
34975
|
+
});
|
|
34976
|
+
}
|
|
34977
|
+
}
|
|
34978
|
+
ModelFavoriteApplyService = __decorateElement(_init, 0, "ModelFavoriteApplyService", _dec, ModelFavoriteApplyService);
|
|
34979
|
+
__runInitializers(_init, 1, ModelFavoriteApplyService);
|
|
34980
|
+
__decoratorMetadata(_init, ModelFavoriteApplyService);
|
|
34981
|
+
let _ModelFavoriteApplyService = ModelFavoriteApplyService;
|
|
34982
|
+
function hash2(value) {
|
|
34983
|
+
return createHash7("sha256").update(JSON.stringify(value)).digest("hex");
|
|
34984
|
+
}
|
|
34985
|
+
function failure2(code) {
|
|
34986
|
+
return new HttpError(409, code, { code });
|
|
34987
|
+
}
|
|
34988
|
+
function snapshot(profile, baseline) {
|
|
34989
|
+
return {
|
|
34990
|
+
harness: profile.harness,
|
|
34991
|
+
model: profile.model,
|
|
34992
|
+
providerId: profile.providerId ?? "",
|
|
34993
|
+
providerEndpoint: profile.providerEndpoint ?? "",
|
|
34994
|
+
extras: Object.fromEntries(Object.keys(baseline.extras).map((key) => [key, profile.extras[key] ?? null]))
|
|
34995
|
+
};
|
|
34996
|
+
}
|
|
34997
|
+
|
|
34998
|
+
// src/http/routes/model-favorites.ts
|
|
34999
|
+
function createModelFavoriteRoutes(services) {
|
|
35000
|
+
const app = new Hono2;
|
|
35001
|
+
const favorites = services.get(IModelFavoriteService);
|
|
35002
|
+
const store = services.get(IModelFavoriteStore);
|
|
35003
|
+
const apply = services.get(IModelFavoriteApplyService);
|
|
35004
|
+
const adapters = services.get(IAdapterRegistry);
|
|
35005
|
+
const profiles = services.get(IProfileService);
|
|
35006
|
+
const backups = services.get(IFavoriteBackupService);
|
|
35007
|
+
app.get("/backups", (c) => c.json({ code: FAVORITE_CODES.result, data: backups.list() }));
|
|
35008
|
+
app.post("/backups", (c) => c.json({ code: FAVORITE_CODES.result, data: backups.create() }, 201));
|
|
35009
|
+
app.get("/backups/:backupId/preview", (c) => c.json({ code: FAVORITE_CODES.result, data: backups.preview(param(c, "backupId")) }));
|
|
35010
|
+
app.post("/backups/:backupId/restore", async (c) => {
|
|
35011
|
+
const body = await readOptionalJsonBody(c, favoriteRestoreRequestSchema);
|
|
35012
|
+
backups.restore(param(c, "backupId"), body.fingerprint);
|
|
35013
|
+
return c.json({ code: FAVORITE_CODES.result, data: { ok: true } });
|
|
35014
|
+
});
|
|
35015
|
+
app.get("/", (c) => c.json({
|
|
35016
|
+
code: FAVORITE_CODES.result,
|
|
35017
|
+
data: favorites.list().map((favorite) => ({
|
|
35018
|
+
...favorite,
|
|
35019
|
+
references: favorite.references.map((ref) => ({
|
|
35020
|
+
...ref,
|
|
35021
|
+
...apply.state(profiles.get(ref.harness, ref.name))
|
|
35022
|
+
}))
|
|
35023
|
+
}))
|
|
35024
|
+
}));
|
|
35025
|
+
app.post("/", async (c) => c.json({
|
|
35026
|
+
code: FAVORITE_CODES.result,
|
|
35027
|
+
data: favorites.create(await readJsonBody(c, createFavoriteRequestSchema))
|
|
35028
|
+
}, 201));
|
|
35029
|
+
app.post("/from-profile", async (c) => c.json({
|
|
35030
|
+
code: FAVORITE_CODES.result,
|
|
35031
|
+
data: favorites.capture(await readJsonBody(c, favoriteCaptureRequestSchema))
|
|
35032
|
+
}, 201));
|
|
35033
|
+
app.get("/source/:harness/:name", (c) => c.json({
|
|
35034
|
+
code: FAVORITE_CODES.result,
|
|
35035
|
+
data: {
|
|
35036
|
+
sourceFingerprint: favorites.sourceFingerprint(harnessIdSchema.parse(param(c, "harness")), param(c, "name"))
|
|
35037
|
+
}
|
|
35038
|
+
}));
|
|
35039
|
+
app.post("/source/:harness/:name/detach", async (c) => {
|
|
35040
|
+
const body = await readJsonBody(c, favoriteDetachRequestSchema);
|
|
35041
|
+
favorites.detach(harnessIdSchema.parse(param(c, "harness")), param(c, "name"), body.sourceFingerprint);
|
|
35042
|
+
return c.json({ code: FAVORITE_CODES.result, data: { ok: true } });
|
|
35043
|
+
});
|
|
35044
|
+
app.patch("/:id", async (c) => c.json({
|
|
35045
|
+
code: FAVORITE_CODES.result,
|
|
35046
|
+
data: favorites.update(param(c, "id"), await readJsonBody(c, updateFavoriteRequestSchema))
|
|
35047
|
+
}));
|
|
35048
|
+
app.delete("/:id", async (c) => {
|
|
35049
|
+
const body = await readJsonBody(c, favoriteRevisionRequestSchema);
|
|
35050
|
+
favorites.remove(param(c, "id"), body.expectedRevision);
|
|
35051
|
+
return c.json({ code: FAVORITE_CODES.result, data: { ok: true } });
|
|
35052
|
+
});
|
|
35053
|
+
app.get("/:id/targets", (c) => {
|
|
35054
|
+
const favorite = store.get(param(c, "id"));
|
|
35055
|
+
return c.json({
|
|
35056
|
+
code: FAVORITE_CODES.result,
|
|
35057
|
+
data: HARNESS_IDS.map((harness) => ({
|
|
35058
|
+
harness,
|
|
35059
|
+
protocols: adapters.get(harness).favoriteSupport,
|
|
35060
|
+
connections: favorite.connections.map((connection) => ({
|
|
35061
|
+
id: connection.id,
|
|
35062
|
+
projection: adapters.get(harness).projectFavorite(favorite, connection)
|
|
35063
|
+
}))
|
|
35064
|
+
}))
|
|
35065
|
+
});
|
|
35066
|
+
});
|
|
35067
|
+
return app;
|
|
35068
|
+
}
|
|
35069
|
+
function createModelFavoritePlanRoutes(services) {
|
|
35070
|
+
const app = new Hono2;
|
|
35071
|
+
const apply = services.get(IModelFavoriteApplyService);
|
|
35072
|
+
const environment = services.get(IEnvironmentService);
|
|
35073
|
+
app.post("/", async (c) => c.json({
|
|
35074
|
+
code: FAVORITE_CODES.result,
|
|
35075
|
+
data: apply.plan(await readJsonBody(c, favoritePlanRequestSchema), getCookie(c, environment.cookieName))
|
|
35076
|
+
}));
|
|
35077
|
+
app.post("/:id/apply", async (c) => {
|
|
35078
|
+
const body = await readJsonBody(c, favoriteApplyRequestSchema);
|
|
35079
|
+
return c.json({
|
|
35080
|
+
code: FAVORITE_CODES.result,
|
|
35081
|
+
data: apply.apply(param(c, "id"), body.requestId, getCookie(c, environment.cookieName))
|
|
35082
|
+
});
|
|
35083
|
+
});
|
|
35084
|
+
return app;
|
|
35085
|
+
}
|
|
35086
|
+
function createModelFavoriteOperationRoutes(services) {
|
|
35087
|
+
const app = new Hono2;
|
|
35088
|
+
app.get("/:id", (c) => c.json({
|
|
35089
|
+
code: FAVORITE_CODES.result,
|
|
35090
|
+
data: services.get(IModelFavoriteApplyService).operation(param(c, "id"))
|
|
35091
|
+
}));
|
|
35092
|
+
return app;
|
|
35093
|
+
}
|
|
35094
|
+
|
|
32839
35095
|
// src/http/routes/operations.ts
|
|
32840
35096
|
function createOperationRoutes(services) {
|
|
32841
35097
|
const app = new Hono2;
|
|
@@ -32888,7 +35144,7 @@ function draftKey(vault, body) {
|
|
|
32888
35144
|
// src/services/provider.ts
|
|
32889
35145
|
var IProviderService = createDecorator("providerService");
|
|
32890
35146
|
var _dec = [
|
|
32891
|
-
inject(IVaultService, IProfileService, IActivationService, IProbeService, IHarnessRegistry, ILogService)
|
|
35147
|
+
inject(IVaultService, IProfileService, IActivationService, IProbeService, IHarnessRegistry, ILogService, IModelFavoriteStore)
|
|
32892
35148
|
];
|
|
32893
35149
|
var _init = __decoratorStart(undefined);
|
|
32894
35150
|
|
|
@@ -32899,15 +35155,23 @@ class ProviderService {
|
|
|
32899
35155
|
probes;
|
|
32900
35156
|
harnesses;
|
|
32901
35157
|
log;
|
|
32902
|
-
|
|
35158
|
+
favorites;
|
|
35159
|
+
constructor(vault, profiles, activation, probes, harnesses, log, favorites) {
|
|
32903
35160
|
this.vault = vault;
|
|
32904
35161
|
this.profiles = profiles;
|
|
32905
35162
|
this.activation = activation;
|
|
32906
35163
|
this.probes = probes;
|
|
32907
35164
|
this.harnesses = harnesses;
|
|
32908
35165
|
this.log = log;
|
|
35166
|
+
this.favorites = favorites;
|
|
32909
35167
|
}
|
|
32910
35168
|
update(id, input) {
|
|
35169
|
+
const references = this.favorites.list().flatMap((favorite) => favorite.connections.filter((connection) => connection.providerId === id));
|
|
35170
|
+
if (input.endpoints && references.some((connection) => !input.endpoints.some((endpoint) => endpoint.key === connection.endpointKey))) {
|
|
35171
|
+
throw new HttpError(409, ERROR_CODES.favoriteEndpointMissing, {
|
|
35172
|
+
code: ERROR_CODES.favoriteEndpointMissing
|
|
35173
|
+
});
|
|
35174
|
+
}
|
|
32911
35175
|
const { provider, affected } = this.vault.update(id, input);
|
|
32912
35176
|
this.profiles.sweepVaultCache(id, this.vault.decrypt(id), provider.endpoints);
|
|
32913
35177
|
const warnings = [];
|
|
@@ -32939,6 +35203,12 @@ class ProviderService {
|
|
|
32939
35203
|
}
|
|
32940
35204
|
return { provider, warnings };
|
|
32941
35205
|
}
|
|
35206
|
+
remove(id) {
|
|
35207
|
+
if (this.favorites.list().some((favorite) => favorite.connections.some((connection) => connection.providerId === id))) {
|
|
35208
|
+
throw new HttpError(409, ERROR_CODES.favoriteInUse, { code: ERROR_CODES.favoriteInUse });
|
|
35209
|
+
}
|
|
35210
|
+
this.vault.remove(id);
|
|
35211
|
+
}
|
|
32942
35212
|
async probe(id, options) {
|
|
32943
35213
|
const apiKey = this.vault.decrypt(id);
|
|
32944
35214
|
const baseUrl = endpointBaseUrl(this.vault.get(id), options.endpoint);
|
|
@@ -32996,7 +35266,7 @@ function createProviderRoutes(services) {
|
|
|
32996
35266
|
return c.json({ result: await providers.probe(id, body) });
|
|
32997
35267
|
});
|
|
32998
35268
|
app.delete("/:id", (c) => {
|
|
32999
|
-
|
|
35269
|
+
providers.remove(param(c, "id"));
|
|
33000
35270
|
return c.json({ ok: true });
|
|
33001
35271
|
});
|
|
33002
35272
|
return app;
|
|
@@ -33277,7 +35547,7 @@ function createTransferRoutes(services) {
|
|
|
33277
35547
|
app.get("/export/preview", (c) => c.json(transfer.exportPreview()));
|
|
33278
35548
|
app.post("/export", async (c) => {
|
|
33279
35549
|
const body = await readJsonBody(c, transferExportRequestSchema);
|
|
33280
|
-
return c.json(transfer.exportAll(body.passphrase, body.includeCodexLoginCache !== false));
|
|
35550
|
+
return c.json(transfer.exportAll(body.passphrase, body.includeCodexLoginCache !== false, body.legacy === true));
|
|
33281
35551
|
});
|
|
33282
35552
|
app.post("/preview", async (c) => {
|
|
33283
35553
|
const body = await readJsonBody(c, transferImportRequestSchema);
|
|
@@ -33304,7 +35574,7 @@ function createUpdateRoutes(services) {
|
|
|
33304
35574
|
|
|
33305
35575
|
// src/services/user-access.ts
|
|
33306
35576
|
import { accessSync as accessSync2, constants as constants2, existsSync as existsSync5, readFileSync as readFileSync4 } from "node:fs";
|
|
33307
|
-
import { join as
|
|
35577
|
+
import { join as join15 } from "node:path";
|
|
33308
35578
|
var IUserAccessService = createDecorator("userAccessService");
|
|
33309
35579
|
var _dec = [
|
|
33310
35580
|
inject(IEnvironmentService)
|
|
@@ -33348,7 +35618,7 @@ class UserAccessService {
|
|
|
33348
35618
|
return { ok: true };
|
|
33349
35619
|
}
|
|
33350
35620
|
storeDir(user) {
|
|
33351
|
-
return
|
|
35621
|
+
return join15(user.homeDir, ".harness-switch");
|
|
33352
35622
|
}
|
|
33353
35623
|
canOwnAs(user) {
|
|
33354
35624
|
const uid = process.getuid?.();
|
|
@@ -33401,10 +35671,11 @@ function readEffectiveCaps() {
|
|
|
33401
35671
|
}
|
|
33402
35672
|
|
|
33403
35673
|
// src/services/user-sync.ts
|
|
35674
|
+
import { randomUUID as randomUUID6 } from "node:crypto";
|
|
33404
35675
|
import { isDeepStrictEqual as isDeepStrictEqual2 } from "node:util";
|
|
33405
35676
|
var IUserSyncService = createDecorator("userSyncService");
|
|
33406
35677
|
var _dec = [
|
|
33407
|
-
inject(IEnvironmentService, IUserService, IFileService, ICryptoService, ICodexLoginCacheService, ILiveWriteService, IActivationService)
|
|
35678
|
+
inject(IEnvironmentService, IUserService, IFileService, ICryptoService, ICodexLoginCacheService, ILiveWriteService, IActivationService, IModelFavoriteStore)
|
|
33408
35679
|
];
|
|
33409
35680
|
var _init = __decoratorStart(undefined);
|
|
33410
35681
|
|
|
@@ -33416,7 +35687,8 @@ class UserSyncService {
|
|
|
33416
35687
|
codexLoginCache;
|
|
33417
35688
|
liveWrite;
|
|
33418
35689
|
activation;
|
|
33419
|
-
|
|
35690
|
+
favorites;
|
|
35691
|
+
constructor(environment, users, files, crypto2, codexLoginCache, liveWrite, activation, favorites) {
|
|
33420
35692
|
this.environment = environment;
|
|
33421
35693
|
this.users = users;
|
|
33422
35694
|
this.files = files;
|
|
@@ -33424,6 +35696,7 @@ class UserSyncService {
|
|
|
33424
35696
|
this.codexLoginCache = codexLoginCache;
|
|
33425
35697
|
this.liveWrite = liveWrite;
|
|
33426
35698
|
this.activation = activation;
|
|
35699
|
+
this.favorites = favorites;
|
|
33427
35700
|
}
|
|
33428
35701
|
preview(sourceUsername) {
|
|
33429
35702
|
const target = this.environment.currentUser;
|
|
@@ -33519,9 +35792,30 @@ class UserSyncService {
|
|
|
33519
35792
|
}
|
|
33520
35793
|
}
|
|
33521
35794
|
}
|
|
33522
|
-
const
|
|
35795
|
+
const selectedConnections = new Map;
|
|
35796
|
+
const requiredProviders = new Set;
|
|
33523
35797
|
for (const { profile } of selected) {
|
|
33524
|
-
|
|
35798
|
+
if (profile.provider_id) {
|
|
35799
|
+
requiredProviders.add(profile.provider_id);
|
|
35800
|
+
}
|
|
35801
|
+
if (profile.model_favorite) {
|
|
35802
|
+
const link = modelFavoriteLinkSchema.parse(profile.model_favorite);
|
|
35803
|
+
const favorite = portable.favorites.find((item) => item.id === link.favoriteId);
|
|
35804
|
+
const connection = favorite?.connections.find((item) => item.id === link.connectionId);
|
|
35805
|
+
if (!connection || !portable.providers[connection.providerId] || !portable.providers[link.baseline.providerId]) {
|
|
35806
|
+
throw new HttpError(409, ERROR_CODES.favoriteStoreInvalid, {
|
|
35807
|
+
code: ERROR_CODES.favoriteStoreInvalid
|
|
35808
|
+
});
|
|
35809
|
+
}
|
|
35810
|
+
const ids = selectedConnections.get(link.favoriteId) ?? new Set;
|
|
35811
|
+
ids.add(link.connectionId);
|
|
35812
|
+
selectedConnections.set(link.favoriteId, ids);
|
|
35813
|
+
requiredProviders.add(connection.providerId);
|
|
35814
|
+
requiredProviders.add(link.baseline.providerId);
|
|
35815
|
+
}
|
|
35816
|
+
}
|
|
35817
|
+
const providerMap = new Map;
|
|
35818
|
+
for (const sourceId of requiredProviders) {
|
|
33525
35819
|
if (!sourceId || providerMap.has(sourceId)) {
|
|
33526
35820
|
continue;
|
|
33527
35821
|
}
|
|
@@ -33541,6 +35835,31 @@ class UserSyncService {
|
|
|
33541
35835
|
synced_from: { username: source.username, provider_id: sourceId }
|
|
33542
35836
|
};
|
|
33543
35837
|
}
|
|
35838
|
+
const favorites = this.favorites.list();
|
|
35839
|
+
const favoriteMap = new Map;
|
|
35840
|
+
const connectionMap = new Map;
|
|
35841
|
+
for (const favorite of portable.favorites) {
|
|
35842
|
+
const ids = selectedConnections.get(favorite.id);
|
|
35843
|
+
if (!ids) {
|
|
35844
|
+
continue;
|
|
35845
|
+
}
|
|
35846
|
+
const id = randomUUID6();
|
|
35847
|
+
favoriteMap.set(favorite.id, id);
|
|
35848
|
+
favorites.push({
|
|
35849
|
+
...favorite,
|
|
35850
|
+
id,
|
|
35851
|
+
connections: favorite.connections.filter((connection) => ids.has(connection.id)).map((connection) => {
|
|
35852
|
+
const connectionId = randomUUID6();
|
|
35853
|
+
connectionMap.set(`${favorite.id}/${connection.id}`, connectionId);
|
|
35854
|
+
return {
|
|
35855
|
+
...connection,
|
|
35856
|
+
id: connectionId,
|
|
35857
|
+
providerId: providerMap.get(connection.providerId)
|
|
35858
|
+
};
|
|
35859
|
+
})
|
|
35860
|
+
});
|
|
35861
|
+
}
|
|
35862
|
+
favoriteStoreSchema.parse({ schemaVersion: 1, favorites });
|
|
33544
35863
|
for (const { harness, name, profile } of selected) {
|
|
33545
35864
|
targetProfiles[harness] ||= {};
|
|
33546
35865
|
const mappedProvider = profile.provider_id ? providerMap.get(profile.provider_id) : undefined;
|
|
@@ -33552,17 +35871,27 @@ class UserSyncService {
|
|
|
33552
35871
|
provider_endpoint: mappedProvider ? profile.provider_endpoint : undefined,
|
|
33553
35872
|
updated_at: new Date().toISOString()
|
|
33554
35873
|
};
|
|
35874
|
+
if (profile.model_favorite) {
|
|
35875
|
+
const link = profile.model_favorite;
|
|
35876
|
+
targetProfiles[harness][name].model_favorite = {
|
|
35877
|
+
...link,
|
|
35878
|
+
favoriteId: favoriteMap.get(link.favoriteId),
|
|
35879
|
+
connectionId: connectionMap.get(`${link.favoriteId}/${link.connectionId}`),
|
|
35880
|
+
baseline: { ...link.baseline, providerId: providerMap.get(link.baseline.providerId) }
|
|
35881
|
+
};
|
|
35882
|
+
}
|
|
33555
35883
|
}
|
|
33556
35884
|
this.liveWrite.transaction({
|
|
33557
35885
|
kind: "sync",
|
|
33558
35886
|
harness: "codex",
|
|
33559
35887
|
profile: `同步-${source.username}`,
|
|
33560
35888
|
writes: cacheWrite,
|
|
33561
|
-
metadata: ["vault", "profiles"]
|
|
35889
|
+
metadata: ["vault", "profiles", "favorites"]
|
|
33562
35890
|
}, () => {
|
|
33563
35891
|
try {
|
|
33564
35892
|
this.files.writeJson(vaultPath, targetVault);
|
|
33565
35893
|
this.files.writeJson(profilesPath, targetProfiles);
|
|
35894
|
+
this.files.writeJson(this.environment.files.favorites, favoriteStoreSchema.parse({ schemaVersion: 1, favorites }));
|
|
33566
35895
|
} catch (error52) {
|
|
33567
35896
|
this.restore(vaultPath, vaultSnapshot);
|
|
33568
35897
|
this.restore(profilesPath, profileSnapshot);
|
|
@@ -33623,7 +35952,11 @@ class UserSyncService {
|
|
|
33623
35952
|
};
|
|
33624
35953
|
}
|
|
33625
35954
|
}
|
|
33626
|
-
return {
|
|
35955
|
+
return {
|
|
35956
|
+
profiles: portableProfiles,
|
|
35957
|
+
providers: portableProviders,
|
|
35958
|
+
favorites: this.favorites.list()
|
|
35959
|
+
};
|
|
33627
35960
|
});
|
|
33628
35961
|
}
|
|
33629
35962
|
readProfiles() {
|
|
@@ -33633,7 +35966,12 @@ class UserSyncService {
|
|
|
33633
35966
|
return isDeepStrictEqual2(this.comparableProfile(source, sourceProviders), this.comparableProfile(target, targetProviders));
|
|
33634
35967
|
}
|
|
33635
35968
|
comparableProfile(profile, providers) {
|
|
33636
|
-
const {
|
|
35969
|
+
const {
|
|
35970
|
+
updated_at: _updatedAt,
|
|
35971
|
+
provider_id: providerId2,
|
|
35972
|
+
model_favorite: _favorite,
|
|
35973
|
+
...content
|
|
35974
|
+
} = profile;
|
|
33637
35975
|
const provider = providerId2 ? providers[providerId2] : undefined;
|
|
33638
35976
|
const comparableProvider = provider ? {
|
|
33639
35977
|
name: provider.name,
|
|
@@ -33667,12 +36005,12 @@ class UserSyncService {
|
|
|
33667
36005
|
}
|
|
33668
36006
|
return candidate;
|
|
33669
36007
|
}
|
|
33670
|
-
restore(path,
|
|
36008
|
+
restore(path, snapshot2) {
|
|
33671
36009
|
try {
|
|
33672
|
-
if (
|
|
36010
|
+
if (snapshot2 === undefined) {
|
|
33673
36011
|
this.files.remove(path);
|
|
33674
36012
|
} else {
|
|
33675
|
-
this.files.writeSecure(path,
|
|
36013
|
+
this.files.writeSecure(path, snapshot2);
|
|
33676
36014
|
}
|
|
33677
36015
|
} catch {}
|
|
33678
36016
|
}
|
|
@@ -33752,6 +36090,9 @@ function createApp(services) {
|
|
|
33752
36090
|
api2.use(`${path}/*`, createAuthGuard(services));
|
|
33753
36091
|
api2.route(path, routes);
|
|
33754
36092
|
};
|
|
36093
|
+
guarded("/model-favorites", createModelFavoriteRoutes(services));
|
|
36094
|
+
guarded("/model-favorite-plans", createModelFavoritePlanRoutes(services));
|
|
36095
|
+
guarded("/model-favorite-operations", createModelFavoriteOperationRoutes(services));
|
|
33755
36096
|
guarded("/users", createUserRoutes(services));
|
|
33756
36097
|
guarded("/harnesses", createHarnessRoutes(services));
|
|
33757
36098
|
guarded("/backups", createBackupRoutes(services));
|
|
@@ -33797,6 +36138,10 @@ function createServices() {
|
|
|
33797
36138
|
collection.set(IProbeCacheService, new SyncDescriptor(ProbeCacheService, [], DELAYED));
|
|
33798
36139
|
collection.set(IProbeProfileService, new SyncDescriptor(ProbeProfileService, [], DELAYED));
|
|
33799
36140
|
collection.set(IDriftService, new SyncDescriptor(DriftService, [], DELAYED));
|
|
36141
|
+
collection.set(IModelFavoriteService, new SyncDescriptor(ModelFavoriteService, [], DELAYED));
|
|
36142
|
+
collection.set(IModelFavoriteApplyService, new SyncDescriptor(ModelFavoriteApplyService, [], DELAYED));
|
|
36143
|
+
collection.set(IModelFavoriteStore, new SyncDescriptor(ModelFavoriteStore, [], DELAYED));
|
|
36144
|
+
collection.set(IFavoriteBackupService, new SyncDescriptor(FavoriteBackupService, [], DELAYED));
|
|
33800
36145
|
collection.set(IActivationService, new SyncDescriptor(ActivationService));
|
|
33801
36146
|
collection.set(IHarnessService, new SyncDescriptor(HarnessService));
|
|
33802
36147
|
collection.set(IProviderService, new SyncDescriptor(ProviderService, [], DELAYED));
|
|
@@ -33809,6 +36154,9 @@ function createServices() {
|
|
|
33809
36154
|
|
|
33810
36155
|
// src/cli/args.ts
|
|
33811
36156
|
var VALUE_FLAGS = new Set([
|
|
36157
|
+
"connection",
|
|
36158
|
+
"profile",
|
|
36159
|
+
"request-id",
|
|
33812
36160
|
"api-key",
|
|
33813
36161
|
"api-key-env",
|
|
33814
36162
|
"base-url",
|
|
@@ -33924,7 +36272,7 @@ import { createInterface } from "node:readline/promises";
|
|
|
33924
36272
|
|
|
33925
36273
|
// src/cli/client.ts
|
|
33926
36274
|
import { readFileSync as readFileSync6 } from "node:fs";
|
|
33927
|
-
import { join as
|
|
36275
|
+
import { join as join17 } from "node:path";
|
|
33928
36276
|
|
|
33929
36277
|
// src/daemon.ts
|
|
33930
36278
|
import { spawn as spawn2 } from "node:child_process";
|
|
@@ -33932,20 +36280,20 @@ import { randomBytes as randomBytes4 } from "node:crypto";
|
|
|
33932
36280
|
import { closeSync, mkdirSync as mkdirSync4, openSync as openSync2, readFileSync as readFileSync5, unlinkSync, writeFileSync as writeFileSync2 } from "node:fs";
|
|
33933
36281
|
import { readFile as readFile2 } from "node:fs/promises";
|
|
33934
36282
|
import { homedir as homedir3 } from "node:os";
|
|
33935
|
-
import { join as
|
|
36283
|
+
import { join as join16, resolve as resolve4 } from "node:path";
|
|
33936
36284
|
import { setTimeout as sleep } from "node:timers/promises";
|
|
33937
36285
|
var DEFAULT_HOST = "127.0.0.1";
|
|
33938
36286
|
var DEFAULT_PORT = 8787;
|
|
33939
36287
|
var STOP_TIMEOUT_MS = 5000;
|
|
33940
36288
|
var START_TIMEOUT_MS = 5000;
|
|
33941
36289
|
function daemonDataDir() {
|
|
33942
|
-
return process.env.HSW_DATA_DIR ||
|
|
36290
|
+
return process.env.HSW_DATA_DIR || join16(homedir3(), ".harness-switch");
|
|
33943
36291
|
}
|
|
33944
36292
|
function daemonPidFile() {
|
|
33945
|
-
return
|
|
36293
|
+
return join16(daemonDataDir(), "daemon.pid");
|
|
33946
36294
|
}
|
|
33947
36295
|
function daemonLogFile() {
|
|
33948
|
-
return
|
|
36296
|
+
return join16(daemonDataDir(), "daemon.log");
|
|
33949
36297
|
}
|
|
33950
36298
|
function readRecord() {
|
|
33951
36299
|
try {
|
|
@@ -34027,7 +36375,7 @@ async function printStatus() {
|
|
|
34027
36375
|
console.log(`harness-switch daemon: ${running ? `running (pid ${record2.pid})` : "not running"}`);
|
|
34028
36376
|
console.log(` url: ${httpOrigin(host, port)}`);
|
|
34029
36377
|
console.log(` log: ${daemonLogFile()}`);
|
|
34030
|
-
console.log(` password: ${
|
|
36378
|
+
console.log(` password: ${join16(daemonDataDir(), "web_password")}`);
|
|
34031
36379
|
console.log(` data: ${daemonDataDir()}`);
|
|
34032
36380
|
return running ? 0 : 1;
|
|
34033
36381
|
}
|
|
@@ -34085,7 +36433,7 @@ async function daemonize() {
|
|
|
34085
36433
|
console.log(` url: http://${host}:${port}`);
|
|
34086
36434
|
console.log(` log: ${logPath}`);
|
|
34087
36435
|
console.log(" manage: harness-switch status | harness-switch stop");
|
|
34088
|
-
console.log(` password (first run): ${
|
|
36436
|
+
console.log(` password (first run): ${join16(daemonDataDir(), "web_password")}`);
|
|
34089
36437
|
return 0;
|
|
34090
36438
|
}
|
|
34091
36439
|
async function isOwnedDaemon(record2) {
|
|
@@ -34157,6 +36505,12 @@ class CliClient {
|
|
|
34157
36505
|
baseUrl;
|
|
34158
36506
|
password;
|
|
34159
36507
|
cookie = "";
|
|
36508
|
+
session() {
|
|
36509
|
+
return this.cookie;
|
|
36510
|
+
}
|
|
36511
|
+
useSession(cookie) {
|
|
36512
|
+
this.cookie = cookie;
|
|
36513
|
+
}
|
|
34160
36514
|
constructor(baseUrl, password) {
|
|
34161
36515
|
this.baseUrl = baseUrl;
|
|
34162
36516
|
this.password = password;
|
|
@@ -34229,7 +36583,7 @@ function resolveBaseUrl() {
|
|
|
34229
36583
|
return process.env.HSW_URL || `http://127.0.0.1:${process.env.PORT || 8787}`;
|
|
34230
36584
|
}
|
|
34231
36585
|
function readWebPassword() {
|
|
34232
|
-
const file2 =
|
|
36586
|
+
const file2 = join17(daemonDataDir(), "web_password");
|
|
34233
36587
|
try {
|
|
34234
36588
|
return readFileSync6(file2, "utf8").trim();
|
|
34235
36589
|
} catch {
|
|
@@ -34257,6 +36611,10 @@ function isMessageParams2(value) {
|
|
|
34257
36611
|
return typeof value === "object" && value !== null && !Array.isArray(value) && Object.values(value).every((item) => typeof item === "string" || typeof item === "number" || typeof item === "boolean");
|
|
34258
36612
|
}
|
|
34259
36613
|
|
|
36614
|
+
// src/cli/favorites.ts
|
|
36615
|
+
import { existsSync as existsSync6, mkdirSync as mkdirSync5, readFileSync as readFileSync7, rmSync as rmSync2, writeFileSync as writeFileSync3 } from "node:fs";
|
|
36616
|
+
import { join as join18 } from "node:path";
|
|
36617
|
+
|
|
34260
36618
|
// src/cli/output.ts
|
|
34261
36619
|
function printJson(value) {
|
|
34262
36620
|
console.log(JSON.stringify(value, null, 2));
|
|
@@ -34372,6 +36730,10 @@ function cliUsage() {
|
|
|
34372
36730
|
" create <harness> <name> create a profile from command-line options",
|
|
34373
36731
|
" delete <harness> <profile> delete an inactive profile (confirmation required)",
|
|
34374
36732
|
" providers list Provider Vault entries",
|
|
36733
|
+
" favorites --json list model favorites",
|
|
36734
|
+
" favorite capture H PROFILE --name NAME [--extract-credential] [--link-source]",
|
|
36735
|
+
" favorite plan ID --harness H --connection ID [--profile NAME] [--activate]",
|
|
36736
|
+
" favorite apply PLAN --request-id UUID --yes",
|
|
34375
36737
|
" doctor [--probe] [--strict] run diagnostics; probe tests the active endpoint",
|
|
34376
36738
|
" plan <harness> <profile> show the exact content activation would write",
|
|
34377
36739
|
" activate <harness> <profile> activate a profile (add --yes to skip the prompt)",
|
|
@@ -34412,6 +36774,76 @@ function cliUsage() {
|
|
|
34412
36774
|
`);
|
|
34413
36775
|
}
|
|
34414
36776
|
|
|
36777
|
+
// src/cli/favorites.ts
|
|
36778
|
+
var sessionSchema = exports_external.object({ cookie: exports_external.string().min(1), expiresAt: exports_external.string() });
|
|
36779
|
+
var planIdSchema = exports_external.uuid();
|
|
36780
|
+
var cacheDir = () => join18(daemonDataDir(), "favorite-cli-plans");
|
|
36781
|
+
async function runFavoriteCli(client, positional, flags) {
|
|
36782
|
+
const [action, id, name] = positional;
|
|
36783
|
+
if (action === "capture") {
|
|
36784
|
+
const harness = exports_external.enum(HARNESS_IDS).parse(id);
|
|
36785
|
+
if (!name) {
|
|
36786
|
+
throw new CliError("favorite capture <harness> <profile> --name NAME");
|
|
36787
|
+
}
|
|
36788
|
+
const source = await client.get(`/api/model-favorites/source/${harness}/${encodeURIComponent(name)}`);
|
|
36789
|
+
printJson(await client.post("/api/model-favorites/from-profile", {
|
|
36790
|
+
harness,
|
|
36791
|
+
name,
|
|
36792
|
+
favoriteName: flagValue(flags, "name") || name,
|
|
36793
|
+
...source.data,
|
|
36794
|
+
extractCredential: hasFlag(flags, "extract-credential"),
|
|
36795
|
+
linkSource: hasFlag(flags, "link-source")
|
|
36796
|
+
}));
|
|
36797
|
+
return false;
|
|
36798
|
+
}
|
|
36799
|
+
if (action === "plan") {
|
|
36800
|
+
const favoriteId = planIdSchema.parse(id);
|
|
36801
|
+
const list = await client.get("/api/model-favorites");
|
|
36802
|
+
const favorite = list.data.find((item) => item.id === favoriteId);
|
|
36803
|
+
if (!favorite) {
|
|
36804
|
+
throw new CliError("favoriteNotFound");
|
|
36805
|
+
}
|
|
36806
|
+
const result = await client.post("/api/model-favorite-plans", {
|
|
36807
|
+
favoriteId,
|
|
36808
|
+
expectedRevision: favorite.revision,
|
|
36809
|
+
items: [
|
|
36810
|
+
{
|
|
36811
|
+
harness: flagValue(flags, "harness"),
|
|
36812
|
+
connectionId: flagValue(flags, "connection"),
|
|
36813
|
+
profile: flagValue(flags, "profile"),
|
|
36814
|
+
existing: hasFlag(flags, "existing"),
|
|
36815
|
+
mode: hasFlag(flags, "activate") ? "activate" : "save",
|
|
36816
|
+
ignorePreference: hasFlag(flags, "ignore-preference"),
|
|
36817
|
+
overwriteDiverged: hasFlag(flags, "overwrite-diverged"),
|
|
36818
|
+
allowAuthOverwrite: hasFlag(flags, "overwrite-login-cache")
|
|
36819
|
+
}
|
|
36820
|
+
]
|
|
36821
|
+
});
|
|
36822
|
+
mkdirSync5(cacheDir(), { recursive: true, mode: 448 });
|
|
36823
|
+
writeFileSync3(join18(cacheDir(), `${result.data.id}.json`), JSON.stringify({ cookie: client.session(), expiresAt: result.data.expiresAt }), { mode: 384, flag: "wx" });
|
|
36824
|
+
printJson(result);
|
|
36825
|
+
return true;
|
|
36826
|
+
}
|
|
36827
|
+
if (action === "apply") {
|
|
36828
|
+
const planId = planIdSchema.parse(id);
|
|
36829
|
+
if (!hasFlag(flags, "yes")) {
|
|
36830
|
+
throw new CliError("favorite apply <plan-id> --request-id UUID --yes");
|
|
36831
|
+
}
|
|
36832
|
+
const requestId = planIdSchema.parse(flagValue(flags, "request-id"));
|
|
36833
|
+
const cached2 = join18(cacheDir(), `${planId}.json`);
|
|
36834
|
+
if (existsSync6(cached2)) {
|
|
36835
|
+
const session = sessionSchema.parse(JSON.parse(readFileSync7(cached2, "utf8")));
|
|
36836
|
+
await client.logout();
|
|
36837
|
+
client.useSession(session.cookie);
|
|
36838
|
+
}
|
|
36839
|
+
const result = await client.post(`/api/model-favorite-plans/${planId}/apply`, { requestId });
|
|
36840
|
+
printJson(result);
|
|
36841
|
+
rmSync2(cached2, { force: true });
|
|
36842
|
+
return false;
|
|
36843
|
+
}
|
|
36844
|
+
throw new CliError("favorite capture|plan|apply");
|
|
36845
|
+
}
|
|
36846
|
+
|
|
34415
36847
|
// src/cli/commands.ts
|
|
34416
36848
|
async function runCli(command, positional, flags) {
|
|
34417
36849
|
const json2 = hasFlag(flags, "json") ? "json" : "human";
|
|
@@ -34427,12 +36859,19 @@ async function runCli(command, positional, flags) {
|
|
|
34427
36859
|
} catch (error52) {
|
|
34428
36860
|
return fail2(error52, json2);
|
|
34429
36861
|
}
|
|
36862
|
+
let retainSession = false;
|
|
34430
36863
|
try {
|
|
34431
36864
|
const selectedUser = flagValue(flags, "user");
|
|
34432
36865
|
if (selectedUser) {
|
|
34433
36866
|
await selectUser(client, selectedUser);
|
|
34434
36867
|
}
|
|
34435
36868
|
switch (command) {
|
|
36869
|
+
case "favorites":
|
|
36870
|
+
printJson(await client.get("/api/model-favorites"));
|
|
36871
|
+
return 0;
|
|
36872
|
+
case "favorite":
|
|
36873
|
+
retainSession = await runFavoriteCli(client, positional, flags);
|
|
36874
|
+
return 0;
|
|
34436
36875
|
case "list":
|
|
34437
36876
|
return await cmdList(client, json2);
|
|
34438
36877
|
case "profiles":
|
|
@@ -34470,13 +36909,36 @@ async function runCli(command, positional, flags) {
|
|
|
34470
36909
|
} catch (error52) {
|
|
34471
36910
|
return fail2(error52, json2);
|
|
34472
36911
|
} finally {
|
|
34473
|
-
|
|
34474
|
-
|
|
34475
|
-
|
|
36912
|
+
if (!retainSession) {
|
|
36913
|
+
await client.logout().catch(() => {
|
|
36914
|
+
return;
|
|
36915
|
+
});
|
|
36916
|
+
}
|
|
34476
36917
|
}
|
|
34477
36918
|
}
|
|
34478
36919
|
function validateCommand(command, positional, flags) {
|
|
34479
36920
|
const specs = {
|
|
36921
|
+
favorites: { min: 0, max: 0, usage: "favorites --json" },
|
|
36922
|
+
favorite: {
|
|
36923
|
+
flags: [
|
|
36924
|
+
"name",
|
|
36925
|
+
"harness",
|
|
36926
|
+
"connection",
|
|
36927
|
+
"profile",
|
|
36928
|
+
"existing",
|
|
36929
|
+
"activate",
|
|
36930
|
+
"extract-credential",
|
|
36931
|
+
"link-source",
|
|
36932
|
+
"ignore-preference",
|
|
36933
|
+
"overwrite-diverged",
|
|
36934
|
+
"overwrite-login-cache",
|
|
36935
|
+
"request-id",
|
|
36936
|
+
"yes"
|
|
36937
|
+
],
|
|
36938
|
+
min: 2,
|
|
36939
|
+
max: 3,
|
|
36940
|
+
usage: "favorite capture|plan|apply"
|
|
36941
|
+
},
|
|
34480
36942
|
list: { min: 0, max: 0, usage: "list [options]" },
|
|
34481
36943
|
profiles: { min: 0, max: 1, usage: "profiles [harness] [options]" },
|
|
34482
36944
|
create: {
|
|
@@ -34933,7 +37395,7 @@ if (command === "help" || command === "--help" || command === "-h") {
|
|
|
34933
37395
|
process.exitCode = await stopDaemon();
|
|
34934
37396
|
} else if (command === "status") {
|
|
34935
37397
|
process.exitCode = await printStatus();
|
|
34936
|
-
} else if (command === "list" || command === "profiles" || command === "create" || command === "delete" || command === "providers" || command === "doctor" || command === "plan" || command === "activate" || command === "official" || command === "users" || command === "sync" || command === "scan" || command === "import" || command === "operations" || command === "undo") {
|
|
37398
|
+
} else if (command === "list" || command === "profiles" || command === "create" || command === "delete" || command === "providers" || command === "favorites" || command === "favorite" || command === "doctor" || command === "plan" || command === "activate" || command === "official" || command === "users" || command === "sync" || command === "scan" || command === "import" || command === "operations" || command === "undo") {
|
|
34937
37399
|
try {
|
|
34938
37400
|
const { flags, positional } = parseArgs(rest);
|
|
34939
37401
|
process.exitCode = await runCli(command, positional, flags);
|