@ran-sh/dsh-crew 1.0.1 → 1.0.3
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/README.md +28 -20
- package/README.zh.md +25 -18
- package/lib/client.js +336 -16
- package/official-web-bridge/lib/client.js +336 -16
- package/package.json +166 -166
- package/src/client/index.tsx +853 -716
- package/src/credential-reference.mjs +38 -0
- package/src/hub/index.mjs +890 -65
- package/src/install/install-legacy.mjs +184 -185
- package/src/install/npx-lifecycle.mjs +456 -398
- package/src/model-catalog.mjs +8 -1
- package/src/policy-legacy.mjs +2 -2
- package/src/provider-delete-adapters.mjs +1934 -451
- package/src/provider-inventory.mjs +184 -132
- package/src/provider-layer-migration-adapters.mjs +759 -0
- package/src/provider-layer-migration.mjs +198 -0
- package/src/provider-lifecycle-state.mjs +103 -95
- package/src/provider-lifecycle.mjs +252 -214
- package/src/provider-profile-store.mjs +378 -171
- package/src/provider-settings-store.mjs +291 -0
- package/src/provider-store-lock.mjs +67 -0
- package/src/runtime-identity.mjs +73 -72
|
@@ -1,132 +1,184 @@
|
|
|
1
|
-
// Secret-free inventory projection for Harness providers.
|
|
2
|
-
//
|
|
3
|
-
// Harness owns the live provider/model catalog; Crew owns the routing policy
|
|
4
|
-
// and (where explicitly marked) profile provenance. This module only joins
|
|
5
|
-
// those observations into a bounded record set for lifecycle/readiness UIs.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
function
|
|
15
|
-
return
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
1
|
+
// Secret-free inventory projection for Harness providers.
|
|
2
|
+
//
|
|
3
|
+
// Harness owns the live provider/model catalog; Crew owns the routing policy
|
|
4
|
+
// and (where explicitly marked) profile provenance. This module only joins
|
|
5
|
+
// those observations into a bounded record set for lifecycle/readiness UIs.
|
|
6
|
+
|
|
7
|
+
import { classifyCredentialReference } from './credential-reference.mjs';
|
|
8
|
+
|
|
9
|
+
const LIFECYCLE_ORIGINS = new Set(['builtin', 'profile-managed', 'dynamic', 'unknown']);
|
|
10
|
+
const OWNERSHIPS = new Set(['harness', 'crew-managed-profile', 'user-managed-profile', 'dynamic-user', 'unknown']);
|
|
11
|
+
const MUTABLE_AUTHORITY_KINDS = new Set(['crew-profile', 'harness-settings']);
|
|
12
|
+
export const IMMUTABLE_HARNESS_PROVIDER_IDS = Object.freeze(['deepseek-official']);
|
|
13
|
+
|
|
14
|
+
function text(value) {
|
|
15
|
+
return typeof value === 'string' && value.trim() ? value.trim() : null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function normalizeProviderId(value) {
|
|
19
|
+
return text(value);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function normalizeCredentialRefs(declarations) {
|
|
23
|
+
const entries = Array.isArray(declarations) ? declarations : [declarations];
|
|
24
|
+
const seen = new Map();
|
|
25
|
+
const refs = [];
|
|
26
|
+
let redacted = false;
|
|
27
|
+
for (const declaration of entries) {
|
|
28
|
+
const raw = declaration?.credential_refs ?? declaration?.credential_ref;
|
|
29
|
+
const values = Array.isArray(raw) ? raw : raw === undefined ? [] : [raw];
|
|
30
|
+
for (const candidate of values) {
|
|
31
|
+
const kind = text(typeof candidate === 'object' ? candidate.kind : null) ?? 'env';
|
|
32
|
+
const classified = classifyCredentialReference(candidate, { kind });
|
|
33
|
+
if (classified.redacted) redacted = true;
|
|
34
|
+
const name = classified.value;
|
|
35
|
+
const ownership = text(typeof candidate === 'object' ? candidate.ownership : null) ?? 'crew';
|
|
36
|
+
const normalized = {
|
|
37
|
+
kind: ['env', 'crew-store', 'harness-store', 'unknown'].includes(kind) ? kind : 'unknown',
|
|
38
|
+
name_or_handle: name,
|
|
39
|
+
ownership: ['crew', 'user', 'external', 'unknown'].includes(ownership) ? ownership : 'unknown',
|
|
40
|
+
};
|
|
41
|
+
if (!name) continue;
|
|
42
|
+
const key = `${normalized.kind}:${normalized.name_or_handle}`;
|
|
43
|
+
const existing = seen.get(key);
|
|
44
|
+
if (existing) {
|
|
45
|
+
if (existing.ownership !== normalized.ownership) existing.ownership = 'unknown';
|
|
46
|
+
} else {
|
|
47
|
+
seen.set(key, normalized);
|
|
48
|
+
refs.push(normalized);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return { refs, redacted };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function findPriorityIndex(policy, key, providerId) {
|
|
56
|
+
const list = Array.isArray(policy?.[key]) ? policy[key] : [];
|
|
57
|
+
const index = list.findIndex((entry) => normalizeProviderId(entry?.provider) === providerId);
|
|
58
|
+
return index >= 0 ? index : null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function declarationsFor(declarations, id) {
|
|
62
|
+
return declarations.filter((entry) => normalizeProviderId(entry?.id) === id);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function normalizeAuthority(value) {
|
|
66
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) return null;
|
|
67
|
+
const kind = text(value.kind);
|
|
68
|
+
const locator = text(value.locator);
|
|
69
|
+
return kind && locator ? { kind, locator } : null;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function catalogFor(providers, id) {
|
|
73
|
+
return providers.find((entry) => normalizeProviderId(entry?.id) === id) ?? null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function normalizeOrigin(value) {
|
|
77
|
+
const origin = text(value) ?? 'unknown';
|
|
78
|
+
return LIFECYCLE_ORIGINS.has(origin) ? origin : 'unknown';
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function normalizeOwnership(value) {
|
|
82
|
+
const ownership = text(value) ?? 'unknown';
|
|
83
|
+
return OWNERSHIPS.has(ownership) ? ownership : 'unknown';
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function modelIds(provider) {
|
|
87
|
+
if (!Array.isArray(provider?.models)) return [];
|
|
88
|
+
return [...new Set(provider.models.map((model) => text(typeof model === 'object' ? model?.id : model)).filter(Boolean))];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Build a secret-free provider inventory from live Harness and Crew-owned
|
|
93
|
+
* observations. No credential value is accepted or copied into the result.
|
|
94
|
+
*/
|
|
95
|
+
export function buildProviderInventory({ catalog = {}, declarations = [], policy = {}, tombstones = {}, activeJobs = [], multimodalRefs = {}, additionalProviderIds = [] } = {}) {
|
|
96
|
+
const catalogProviders = Array.isArray(catalog?.providers) ? catalog.providers : [];
|
|
97
|
+
const safeDeclarations = Array.isArray(declarations) ? declarations : [];
|
|
98
|
+
const ids = [];
|
|
99
|
+
const seen = new Set();
|
|
100
|
+
for (const source of [catalogProviders, safeDeclarations, Array.isArray(additionalProviderIds) ? additionalProviderIds.map((id) => ({ id })) : []]) {
|
|
101
|
+
for (const entry of source) {
|
|
102
|
+
const id = normalizeProviderId(entry?.id);
|
|
103
|
+
if (!id || seen.has(id)) continue;
|
|
104
|
+
seen.add(id);
|
|
105
|
+
ids.push(id);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const harnessDefault = normalizeProviderId(catalog?.harness_default?.provider);
|
|
110
|
+
const records = ids.map((id) => {
|
|
111
|
+
const catalogEntry = catalogFor(catalogProviders, id);
|
|
112
|
+
const providerDeclarations = declarationsFor(safeDeclarations, id);
|
|
113
|
+
const baseDeclarations = providerDeclarations.filter((entry) => normalizeAuthority(entry?.declaration_authority)?.kind === 'crew-profile');
|
|
114
|
+
const userDeclarations = providerDeclarations.filter((entry) => normalizeAuthority(entry?.declaration_authority)?.kind === 'harness-settings');
|
|
115
|
+
const declaration = providerDeclarations[0] ?? null;
|
|
116
|
+
const declared = declaration !== null;
|
|
117
|
+
const catalogued = catalogEntry !== null;
|
|
118
|
+
const tombstoned = tombstones?.[id] === 'absent';
|
|
119
|
+
const configured = declared;
|
|
120
|
+
const active = Array.isArray(activeJobs)
|
|
121
|
+
? activeJobs.filter((job) => normalizeProviderId(job?.provider) === id
|
|
122
|
+
&& !['done', 'failed', 'cancelled'].includes(job?.status)).length
|
|
123
|
+
: Number.isInteger(activeJobs?.[id]) ? Math.max(0, activeJobs[id]) : 0;
|
|
124
|
+
const multimodal = Array.isArray(multimodalRefs?.[id]) ? multimodalRefs[id].length : Number.isInteger(multimodalRefs?.[id]) ? Math.max(0, multimodalRefs[id]) : 0;
|
|
125
|
+
const declarationFile = text(declaration?.file);
|
|
126
|
+
const locator = text(declaration?.locator);
|
|
127
|
+
|
|
128
|
+
const authorities = providerDeclarations.map((entry) => normalizeAuthority(entry.declaration_authority)).filter(Boolean);
|
|
129
|
+
const uniqueAuthorities = [...new Map(authorities.map((authority) => [`${authority.kind}:${authority.locator}`, authority])).values()];
|
|
130
|
+
const mutableAuthorities = uniqueAuthorities.filter((authority) => MUTABLE_AUTHORITY_KINDS.has(authority.kind));
|
|
131
|
+
const immutable = IMMUTABLE_HARNESS_PROVIDER_IDS.includes(id);
|
|
132
|
+
const allAuthoritiesKnown = providerDeclarations.length > 0
|
|
133
|
+
&& uniqueAuthorities.length === providerDeclarations.length
|
|
134
|
+
&& uniqueAuthorities.every((authority) => MUTABLE_AUTHORITY_KINDS.has(authority.kind));
|
|
135
|
+
const deleteCapability = immutable ? 'immutable-builtin' : allAuthoritiesKnown && mutableAuthorities.length > 0 ? 'supported' : 'source-unresolved';
|
|
136
|
+
const deleteBlocker = immutable ? 'PROVIDER_BUILTIN_IMMUTABLE' : deleteCapability === 'supported' ? null : 'PROVIDER_DELETE_SOURCE_UNRESOLVED';
|
|
137
|
+
const origin = normalizeOrigin(declaration?.origin ?? (immutable ? 'builtin' : declared ? 'profile-managed' : 'unknown'));
|
|
138
|
+
const ownership = normalizeOwnership(declaration?.ownership ?? (immutable ? 'harness' : declared ? 'crew-managed-profile' : 'unknown'));
|
|
139
|
+
const credentialProjection = normalizeCredentialRefs(providerDeclarations);
|
|
140
|
+
return {
|
|
141
|
+
id,
|
|
142
|
+
display_name: text(declaration?.display_name) ?? text(declaration?.name) ?? text(catalogEntry?.name) ?? id,
|
|
143
|
+
origin,
|
|
144
|
+
ownership,
|
|
145
|
+
declaration: {
|
|
146
|
+
...(declarationFile ? { file: declarationFile } : {}),
|
|
147
|
+
...(locator ? { locator } : {}),
|
|
148
|
+
...(normalizeAuthority(declaration?.declaration_authority) ? { authority: normalizeAuthority(declaration.declaration_authority) } : {}),
|
|
149
|
+
present: declared,
|
|
150
|
+
},
|
|
151
|
+
declaration_authorities: uniqueAuthorities,
|
|
152
|
+
layers: {
|
|
153
|
+
base: [...new Set(baseDeclarations.map((entry) => normalizeAuthority(entry.declaration_authority)?.kind).filter(Boolean))],
|
|
154
|
+
user: [...new Set(userDeclarations.map((entry) => normalizeAuthority(entry.declaration_authority)?.kind).filter(Boolean))],
|
|
155
|
+
},
|
|
156
|
+
native_removable: userDeclarations.length > 0 && baseDeclarations.length === 0,
|
|
157
|
+
delete_capability: deleteCapability,
|
|
158
|
+
...(deleteBlocker ? { delete_blocker: deleteBlocker } : {}),
|
|
159
|
+
models: modelIds(catalogEntry),
|
|
160
|
+
lifecycle: {
|
|
161
|
+
installed: declared || catalogued,
|
|
162
|
+
configured,
|
|
163
|
+
enabled: !tombstoned && declaration?.enabled !== false,
|
|
164
|
+
catalogued,
|
|
165
|
+
},
|
|
166
|
+
credential_refs: credentialProjection.refs,
|
|
167
|
+
...(credentialProjection.redacted ? { credential_status: 'present-redacted' } : {}),
|
|
168
|
+
references: {
|
|
169
|
+
harness_default: harnessDefault === id,
|
|
170
|
+
...(harnessDefault === id && normalizeAuthority(catalog?.harness_default_authority) ? { harness_default_authority: normalizeAuthority(catalog.harness_default_authority) } : {}),
|
|
171
|
+
worker_priority: findPriorityIndex(policy?.worker, 'priority', id),
|
|
172
|
+
worker_escalation: findPriorityIndex(policy?.worker, 'escalation_priority', id),
|
|
173
|
+
reviewer_priority: findPriorityIndex(policy?.reviewer ?? policy?.review, 'priority', id),
|
|
174
|
+
reviewer_escalation: findPriorityIndex(policy?.reviewer ?? policy?.review, 'escalation_priority', id),
|
|
175
|
+
active_jobs: active,
|
|
176
|
+
multimodal_refs: multimodal,
|
|
177
|
+
},
|
|
178
|
+
desired_state: tombstoned ? 'absent' : 'present',
|
|
179
|
+
activation: declared ? 'restart-required' : 'live',
|
|
180
|
+
};
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
return { schema_version: 1, records, harness_default: catalog?.harness_default ?? null };
|
|
184
|
+
}
|