dsh-subagent-dispatch-control 0.0.0-stage → 1.0.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/LICENSE +21 -0
- package/README.md +183 -2
- package/client.js +9781 -0
- package/cordis.patch.yml +13 -0
- package/docs/BOOST-EVIDENCE.md +259 -0
- package/docs/CONFORMANCE.md +236 -0
- package/docs/FACTS-CONTRACT.md +368 -0
- package/docs/FLOW-COVERAGE.md +215 -0
- package/docs/PACKAGE-README.md +858 -0
- package/docs/RANGE-PLAN.md +357 -0
- package/docs/SECURITY-NOTES.md +110 -0
- package/docs/SPLIT-PLAN.md +604 -0
- package/docs/STAGE3-CONTRACT.md +287 -0
- package/docs/TIER-ROUTING.md +275 -0
- package/docs/badge/CONFORMANCE.md +246 -0
- package/docs/badge/DETAIL.md +319 -0
- package/docs/badge/PROJECTIONS.md +264 -0
- package/docs/badge/TEST-PLAN.md +252 -0
- package/docs/images/badge-menu.png +0 -0
- package/docs/images/dispatch.png +0 -0
- package/docs/images/header.png +0 -0
- package/docs/images/pair-header.png +0 -0
- package/docs/images/pair-panel.png +0 -0
- package/docs/images/panel.png +0 -0
- package/docs/wiki/Home.md +43 -0
- package/docs/wiki//344/275/277/347/224/250/346/214/207/345/215/227.md +97 -0
- package/docs/wiki//345/256/211/350/243/205/344/270/216/345/215/207/347/272/247.md +87 -0
- package/docs/wiki//346/225/205/351/232/234/346/216/222/346/237/245.md +94 -0
- package/icon.svg +12 -0
- package/lib/badge-policy.mjs +502 -0
- package/lib/badge-sync.mjs +385 -0
- package/lib/command.mjs +490 -0
- package/lib/completion.mjs +288 -0
- package/lib/concurrency.mjs +2555 -0
- package/lib/dispatch-command.mjs +181 -0
- package/lib/dispatch-gate.mjs +924 -0
- package/lib/facts-store.mjs +183 -0
- package/lib/gate-state.mjs +465 -0
- package/lib/gate.mjs +886 -0
- package/lib/index.js +309 -0
- package/lib/inject.mjs +195 -0
- package/lib/interrupt.mjs +376 -0
- package/lib/ledger.mjs +948 -0
- package/lib/lifecycle.mjs +274 -0
- package/lib/messages.mjs +532 -0
- package/lib/notice.mjs +769 -0
- package/lib/plan-gate.mjs +385 -0
- package/lib/projection.mjs +978 -0
- package/lib/report.mjs +290 -0
- package/lib/route.mjs +346 -0
- package/lib/run-registry.mjs +402 -0
- package/lib/services.mjs +293 -0
- package/lib/stuck.mjs +567 -0
- package/lib/tier-config.mjs +212 -0
- package/lib/tier-policy.mjs +167 -0
- package/lib/tier-state.mjs +137 -0
- package/lib/todo-gate.mjs +1672 -0
- package/lib/tools.mjs +2912 -0
- package/locale/en.json +9 -0
- package/locale/zh.json +9 -0
- package/package.json +83 -4
- package/vendor/node_modules/@deepseek-ai/cosmokit/LICENSE +21 -0
- package/vendor/node_modules/@deepseek-ai/cosmokit/README.md +30 -0
- package/vendor/node_modules/@deepseek-ai/cosmokit/lib/index.js +418 -0
- package/vendor/node_modules/@deepseek-ai/cosmokit/package.json +32 -0
- package/vendor/node_modules/@deepseek-ai/cosmokit/src/array.ts +42 -0
- package/vendor/node_modules/@deepseek-ai/cosmokit/src/index.ts +12 -0
- package/vendor/node_modules/@deepseek-ai/cosmokit/src/misc.ts +78 -0
- package/vendor/node_modules/@deepseek-ai/cosmokit/src/string.ts +113 -0
- package/vendor/node_modules/@deepseek-ai/cosmokit/src/time.ts +92 -0
- package/vendor/node_modules/@deepseek-ai/cosmokit/src/types.ts +168 -0
- package/vendor/node_modules/@deepseek-ai/cosmokit/src/volatile.ts +86 -0
- package/vendor/node_modules/@deepseek-ai/schemastery/LICENSE +21 -0
- package/vendor/node_modules/@deepseek-ai/schemastery/README.md +393 -0
- package/vendor/node_modules/@deepseek-ai/schemastery/lib/index.cjs +635 -0
- package/vendor/node_modules/@deepseek-ai/schemastery/lib/index.mjs +635 -0
- package/vendor/node_modules/@deepseek-ai/schemastery/package.json +39 -0
- package/vendor/node_modules/@deepseek-ai/schemastery/src/index.ts +962 -0
- package/vendor/node_modules/@standard-schema/spec/LICENSE +21 -0
- package/vendor/node_modules/@standard-schema/spec/README.md +198 -0
- package/vendor/node_modules/@standard-schema/spec/dist/index.cjs +18 -0
- package/vendor/node_modules/@standard-schema/spec/dist/index.js +0 -0
- package/vendor/node_modules/@standard-schema/spec/package.json +39 -0
package/locale/en.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"deepModel": "Deep-thinking model",
|
|
4
|
+
"notSet": "Not set",
|
|
5
|
+
"title": "Subagent route badge",
|
|
6
|
+
"description": "Switch which model a delegated subagent uses, right from the session header, without changing the main session model. Use it when you delegate via subagent or Team and want a cheaper model for one task and a stronger one for the next; skip it if you never delegate or never override the inherited route. Shows at a glance whether the selection is on this session's allowlist. Keywords: subagent model, delegation route, model switching, allowlist, inherit parent, reasoning effort, Team. The selection is applied to the actual delegation call by this package's host half (lib/badge-policy.mjs); no companion plugin needed. Turning it off removes the header dropdown and stops syncing the selection to the Host; existing selections stay in browser storage.",
|
|
7
|
+
"detail": "docs/badge/DETAIL.md"
|
|
8
|
+
}
|
|
9
|
+
}
|
package/locale/zh.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
"meta": {
|
|
3
|
+
"deepModel": "深度思考代理模型",
|
|
4
|
+
"notSet": "未设置",
|
|
5
|
+
"title": "子代理路由徽标",
|
|
6
|
+
"description": "在会话头部一键切换下一次委派使用的子代理模型,不改变主会话模型。当你用 subagent 或 Team 派活、希望这次用便宜模型下次用强模型时使用;不委派、或不需要覆盖继承路由时无需安装。徽标实时显示所选路由是否命中本会话白名单。关键词:子代理模型、委派路由、模型切换、白名单、继承父代理、思考强度、Team。该选择由本包 Host 半边(lib/badge-policy.mjs)落到实际委派参数上,无需另装插件。关闭后会话头部下拉消失、不再同步选择到 Host,但浏览器里已保存的选择会保留。",
|
|
7
|
+
"detail": "docs/badge/DETAIL.md"
|
|
8
|
+
}
|
|
9
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,85 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-subagent-dispatch-control",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "单包子代理派发管控:会话头部子代理路由徽标(order 11)+ 常驻动画进度面板(order 12),并发建议与用户确认(suggest_concurrency)、硬叫停(send_interrupt)、共享任务/轮次进度与磁盘台账。合并自 01-route-badge v1.3.1 + 02-team-preflight v1.4.3。",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./lib/index.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": "./lib/index.js",
|
|
10
|
+
"./client": "./client.js",
|
|
11
|
+
"./locale/*.json": "./locale/*.json",
|
|
12
|
+
"./icon": "./icon.svg",
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"lib",
|
|
17
|
+
"client.js",
|
|
18
|
+
"cordis.patch.yml",
|
|
19
|
+
"vendor",
|
|
20
|
+
"locale",
|
|
21
|
+
"docs",
|
|
22
|
+
"icon.svg",
|
|
23
|
+
"README.md",
|
|
24
|
+
"LICENSE"
|
|
25
|
+
],
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=24.9.0",
|
|
28
|
+
"dsh": ">=0.2.2-0 <0.3.0"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"@deepseek-ai/dsh": ">=0.2.2-0 <0.3.0"
|
|
32
|
+
},
|
|
33
|
+
"peerDependenciesMeta": {
|
|
34
|
+
"@deepseek-ai/dsh": {
|
|
35
|
+
"optional": true
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"dsh": {
|
|
39
|
+
"manifestVersion": 1,
|
|
40
|
+
"kind": "plugin",
|
|
41
|
+
"capabilities": [
|
|
42
|
+
"tools:register",
|
|
43
|
+
"system-prompt:write"
|
|
44
|
+
],
|
|
45
|
+
"labels": [
|
|
46
|
+
"prompt-modification"
|
|
47
|
+
],
|
|
48
|
+
"client": {
|
|
49
|
+
"platform": "web",
|
|
50
|
+
"immediately": true,
|
|
51
|
+
"inject": [
|
|
52
|
+
"@deepseek-ai/dsh-client-locale",
|
|
53
|
+
"@deepseek-ai/dsh-client-ui-conversation"
|
|
54
|
+
]
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"scripts": {
|
|
58
|
+
"test": "node test/test.mjs",
|
|
59
|
+
"test:client": "node test/test-client.mjs",
|
|
60
|
+
"test:integration": "node test/test-integration.mjs",
|
|
61
|
+
"test:functional": "node test/test-functional.mjs",
|
|
62
|
+
"test:contract": "node test/test-contract.mjs",
|
|
63
|
+
"test:late-service": "node test/test-late-service.mjs",
|
|
64
|
+
"test:notice-cap": "node test/test-notice-cap.mjs",
|
|
65
|
+
"test:agent-error": "node test/test-agent-error.mjs",
|
|
66
|
+
"test:badge-sync": "node test/test-badge-sync.mjs",
|
|
67
|
+
"test:badge-client": "node test/test-badge-client.mjs",
|
|
68
|
+
"test:badge-integration": "node test/test-badge-integration.mjs",
|
|
69
|
+
"test:concurrency-count": "node test/test-concurrency-count.mjs",
|
|
70
|
+
"test:plan-gate": "node test/test-plan-gate.mjs",
|
|
71
|
+
"test:resume": "node test/test-resume.mjs",
|
|
72
|
+
"test:tier-card": "node test/test-tier-card.mjs",
|
|
73
|
+
"test:tier-command": "node test/test-tier-command.mjs",
|
|
74
|
+
"test:tier-config": "node test/test-tier-config.mjs",
|
|
75
|
+
"test:tier-inject": "node test/test-tier-inject.mjs",
|
|
76
|
+
"test:tier-ledger": "node test/test-tier-ledger.mjs",
|
|
77
|
+
"test:tier-policy": "node test/test-tier-policy.mjs",
|
|
78
|
+
"test:dispatch": "node test/test-command-dispatch.mjs",
|
|
79
|
+
"test:mutation": "node test/test-mutation.mjs",
|
|
80
|
+
"test:effects": "node scripts/effect-probe.mjs",
|
|
81
|
+
"test:fast": "node test/test.mjs && node test/test-client.mjs && node test/test-badge-client.mjs && node test/test-badge-integration.mjs && node test/test-integration.mjs && node test/test-functional.mjs && node test/test-contract.mjs && node test/test-late-service.mjs && node test/test-notice-cap.mjs && node test/test-agent-error.mjs && node test/test-badge-sync.mjs && node test/test-concurrency-count.mjs && node test/test-plan-gate.mjs && node test/test-resume.mjs && node test/test-tier-card.mjs && node test/test-tier-command.mjs && node test/test-tier-config.mjs && node test/test-tier-inject.mjs && node test/test-tier-ledger.mjs && node test/test-tier-policy.mjs && node test/test-command-dispatch.mjs && node scripts/effect-probe.mjs",
|
|
82
|
+
"test:all": "npm run test:fast && npm run test:mutation",
|
|
83
|
+
"test:counts": "node scripts/test-counts.mjs"
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021-present Shigma
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# cosmokit
|
|
2
|
+
|
|
3
|
+
[](https://codecov.io/gh/shigma/cosmokit)
|
|
4
|
+
[](https://www.npmjs.com/package/cosmokit)
|
|
5
|
+
|
|
6
|
+
A collection of common utilities.
|
|
7
|
+
|
|
8
|
+
## Usage
|
|
9
|
+
|
|
10
|
+
### Node.js
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
npm install cosmokit
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import cosmokit from 'cosmokit'
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### Deno
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import cosmokit from 'npm:cosmokit@latest'
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Config references
|
|
27
|
+
|
|
28
|
+
`Volatile<T>` exposes `get()` for immutable data snapshots. `createVolatile()` copies and freezes validated data; framework-owned `updateVolatile()` transfers a candidate snapshot into an existing reference. Framework-owned `volatileEntries()` enumerates references and their paths through plain config containers, stopping at snapshots and opaque objects. The shared symbol protocol recognizes references across ESM/CJS copies. Plugin consumers import the type from Cordis and retain the reference rather than caching values between operations.
|
|
29
|
+
|
|
30
|
+
`deepEqual()` treats two volatile references as equal regardless of their snapshots. Strict comparisons distinguish null from undefined recursively, compare URLs by normalized `href` and other opaque objects by identity, and treat distinct cyclic structures as unequal. Array comparison visits every index and treats holes as undefined. Snapshot-change detection must compare `.get()` results separately.
|
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
//#region lib/types/misc.js
|
|
2
|
+
/** No-op callback returning `undefined` at runtime and `any` at type level. */
|
|
3
|
+
function noop() {}
|
|
4
|
+
/** Return true when a value is `null` or `undefined`. */
|
|
5
|
+
function isNullable(value) {
|
|
6
|
+
return value === null || value === void 0;
|
|
7
|
+
}
|
|
8
|
+
/** Return true when a value is neither `null` nor `undefined`. */
|
|
9
|
+
function isNonNullable(value) {
|
|
10
|
+
return !isNullable(value);
|
|
11
|
+
}
|
|
12
|
+
/** Return true for non-array object values. */
|
|
13
|
+
function isPlainObject(data) {
|
|
14
|
+
return data && typeof data === "object" && !Array.isArray(data);
|
|
15
|
+
}
|
|
16
|
+
/** Filter object entries and return a new object. */
|
|
17
|
+
function filterKeys(object, filter) {
|
|
18
|
+
return Object.fromEntries(Object.entries(object).filter(([key, value]) => filter(key, value)));
|
|
19
|
+
}
|
|
20
|
+
/** Map object values while preserving the original key set. */
|
|
21
|
+
function mapValues(object, transform) {
|
|
22
|
+
return Object.fromEntries(Object.entries(object).map(([key, value]) => [key, transform(value, key)]));
|
|
23
|
+
}
|
|
24
|
+
/** Pick selected keys from an object, optionally including `undefined` values. */
|
|
25
|
+
function pick(source, keys, forced) {
|
|
26
|
+
if (!keys) return { ...source };
|
|
27
|
+
const result = {};
|
|
28
|
+
for (const key of keys) if (forced || source[key] !== void 0) result[key] = source[key];
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
/** Omit selected keys from a shallow object copy. */
|
|
32
|
+
function omit(source, keys) {
|
|
33
|
+
if (!keys) return { ...source };
|
|
34
|
+
const result = { ...source };
|
|
35
|
+
for (const key of keys) Reflect.deleteProperty(result, key);
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
/** Define a non-enumerable writable property and return the object. */
|
|
39
|
+
function defineProperty(object, key, value) {
|
|
40
|
+
return Object.defineProperty(object, key, {
|
|
41
|
+
writable: true,
|
|
42
|
+
value,
|
|
43
|
+
enumerable: false
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region lib/types/array.js
|
|
48
|
+
/** Return true when every item in `array2` is present in `array1`. */
|
|
49
|
+
function contain(array1, array2) {
|
|
50
|
+
return array2.every((item) => array1.includes(item));
|
|
51
|
+
}
|
|
52
|
+
/** Return items that appear in both arrays. */
|
|
53
|
+
function intersection(array1, array2) {
|
|
54
|
+
return array1.filter((item) => array2.includes(item));
|
|
55
|
+
}
|
|
56
|
+
/** Return items from `array1` that do not appear in `array2`. */
|
|
57
|
+
function difference(array1, array2) {
|
|
58
|
+
return array1.filter((item) => !array2.includes(item));
|
|
59
|
+
}
|
|
60
|
+
/** Return the set-union of two arrays while preserving first occurrence order. */
|
|
61
|
+
function union(array1, array2) {
|
|
62
|
+
return Array.from(new Set([...array1, ...array2]));
|
|
63
|
+
}
|
|
64
|
+
/** Remove duplicate values while preserving first occurrence order. */
|
|
65
|
+
function deduplicate(array) {
|
|
66
|
+
return [...new Set(array)];
|
|
67
|
+
}
|
|
68
|
+
/** Remove one item from an array and report whether it was found. */
|
|
69
|
+
function remove(list, item) {
|
|
70
|
+
const index = list?.indexOf(item);
|
|
71
|
+
if (index >= 0) {
|
|
72
|
+
list.splice(index, 1);
|
|
73
|
+
return true;
|
|
74
|
+
} else return false;
|
|
75
|
+
}
|
|
76
|
+
/** Normalize nullish, scalar, or array input to an array. */
|
|
77
|
+
function makeArray(source) {
|
|
78
|
+
return Array.isArray(source) ? source : isNullable(source) ? [] : [source];
|
|
79
|
+
}
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region lib/types/volatile.js
|
|
82
|
+
/** Shared config references used by schema validators and plugin runtimes. */
|
|
83
|
+
const write = Symbol.for("cosmokit.volatile.write");
|
|
84
|
+
function snapshot(value, ancestors = /* @__PURE__ */ new Set()) {
|
|
85
|
+
if (typeof value === "function") throw new TypeError("volatile config cannot contain functions");
|
|
86
|
+
if (value === null || typeof value !== "object") return value;
|
|
87
|
+
if (ancestors.has(value)) throw new TypeError("volatile config cannot contain cycles");
|
|
88
|
+
ancestors.add(value);
|
|
89
|
+
try {
|
|
90
|
+
if (Array.isArray(value)) return Object.freeze(value.map((item) => snapshot(item, ancestors)));
|
|
91
|
+
if (Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) throw new TypeError("volatile config objects must be plain objects or arrays");
|
|
92
|
+
return Object.freeze(Object.fromEntries(Object.entries(value).map(([key, item]) => [key, snapshot(item, ancestors)])));
|
|
93
|
+
} finally {
|
|
94
|
+
ancestors.delete(value);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Create a detached reference containing an immutable copy of the supplied data.
|
|
99
|
+
* @param value - validated config data; class instances and functions are unsupported.
|
|
100
|
+
* @returns a reference whose value is updated only by its owning runtime.
|
|
101
|
+
*/
|
|
102
|
+
function createVolatile(value) {
|
|
103
|
+
let current = snapshot(value);
|
|
104
|
+
return Object.freeze({
|
|
105
|
+
get: () => current,
|
|
106
|
+
[write]: (value) => {
|
|
107
|
+
current = value;
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Identify references across ESM/CJS copies of the shared library.
|
|
113
|
+
* @param value - a parsed config value.
|
|
114
|
+
* @returns whether the value implements the shared reference protocol.
|
|
115
|
+
*/
|
|
116
|
+
function isVolatile(value) {
|
|
117
|
+
return typeof value === "object" && value !== null && write in value;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Collect config references without descending into their snapshots or opaque objects.
|
|
121
|
+
* @internal
|
|
122
|
+
* @param value - parsed config; cyclic ordinary fields are visited once per path.
|
|
123
|
+
* @returns references and their object-key paths, including an empty path for a root reference.
|
|
124
|
+
*/
|
|
125
|
+
function volatileEntries(value) {
|
|
126
|
+
const ancestors = /* @__PURE__ */ new Set();
|
|
127
|
+
function visit(value, path) {
|
|
128
|
+
if (isVolatile(value)) return [{
|
|
129
|
+
path,
|
|
130
|
+
ref: value
|
|
131
|
+
}];
|
|
132
|
+
if (!value || typeof value !== "object" || ancestors.has(value)) return [];
|
|
133
|
+
if (!Array.isArray(value) && Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) return [];
|
|
134
|
+
ancestors.add(value);
|
|
135
|
+
try {
|
|
136
|
+
return Object.entries(value).flatMap(([key, child]) => visit(child, [...path, key]));
|
|
137
|
+
} finally {
|
|
138
|
+
ancestors.delete(value);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return visit(value, []);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Commit an already validated immutable snapshot from another reference.
|
|
145
|
+
* @internal
|
|
146
|
+
* @param target - the owning plugin's stable reference.
|
|
147
|
+
* @param source - a newly parsed candidate reference.
|
|
148
|
+
*/
|
|
149
|
+
function updateVolatile(target, source) {
|
|
150
|
+
target[write](source.get());
|
|
151
|
+
}
|
|
152
|
+
//#endregion
|
|
153
|
+
//#region lib/types/types.js
|
|
154
|
+
/** Test values using `instanceof` with a `toStringTag` fallback. */
|
|
155
|
+
function is(type, value) {
|
|
156
|
+
if (arguments.length === 1) return (value) => is(type, value);
|
|
157
|
+
return type in globalThis && value instanceof globalThis[type] || Object.prototype.toString.call(value).slice(8, -1) === type;
|
|
158
|
+
}
|
|
159
|
+
function isArrayBufferLike(value) {
|
|
160
|
+
return is("ArrayBuffer", value) || is("SharedArrayBuffer", value);
|
|
161
|
+
}
|
|
162
|
+
function isArrayBufferSource(value) {
|
|
163
|
+
return isArrayBufferLike(value) || ArrayBuffer.isView(value);
|
|
164
|
+
}
|
|
165
|
+
/** Binary source detection and base64/hex conversion helpers. */
|
|
166
|
+
var Binary;
|
|
167
|
+
(function(Binary) {
|
|
168
|
+
Binary.is = isArrayBufferLike;
|
|
169
|
+
Binary.isSource = isArrayBufferSource;
|
|
170
|
+
function fromSource(source) {
|
|
171
|
+
if (ArrayBuffer.isView(source)) return source.buffer.slice(source.byteOffset, source.byteOffset + source.byteLength);
|
|
172
|
+
else return source;
|
|
173
|
+
}
|
|
174
|
+
Binary.fromSource = fromSource;
|
|
175
|
+
function toBase64(source) {
|
|
176
|
+
source = fromSource(source);
|
|
177
|
+
if (typeof Buffer !== "undefined") return Buffer.from(source).toString("base64");
|
|
178
|
+
let binary = "";
|
|
179
|
+
const bytes = new Uint8Array(source);
|
|
180
|
+
for (let i = 0; i < bytes.byteLength; i++) binary += String.fromCharCode(bytes[i]);
|
|
181
|
+
return btoa(binary);
|
|
182
|
+
}
|
|
183
|
+
Binary.toBase64 = toBase64;
|
|
184
|
+
function fromBase64(source) {
|
|
185
|
+
if (typeof Buffer !== "undefined") return fromSource(Buffer.from(source, "base64"));
|
|
186
|
+
return Uint8Array.from(atob(source), (c) => c.charCodeAt(0));
|
|
187
|
+
}
|
|
188
|
+
Binary.fromBase64 = fromBase64;
|
|
189
|
+
function toHex(source) {
|
|
190
|
+
source = fromSource(source);
|
|
191
|
+
if (typeof Buffer !== "undefined") return Buffer.from(source).toString("hex");
|
|
192
|
+
return Array.from(new Uint8Array(source), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
193
|
+
}
|
|
194
|
+
Binary.toHex = toHex;
|
|
195
|
+
function fromHex(source) {
|
|
196
|
+
if (typeof Buffer !== "undefined") return fromSource(Buffer.from(source, "hex"));
|
|
197
|
+
const hex = source.length % 2 === 0 ? source : source.slice(0, source.length - 1);
|
|
198
|
+
const buffer = [];
|
|
199
|
+
for (let i = 0; i < hex.length; i += 2) buffer.push(parseInt(`${hex[i]}${hex[i + 1]}`, 16));
|
|
200
|
+
return Uint8Array.from(buffer).buffer;
|
|
201
|
+
}
|
|
202
|
+
Binary.fromHex = fromHex;
|
|
203
|
+
})(Binary || (Binary = {}));
|
|
204
|
+
/** Decode a base64 string into binary data. */
|
|
205
|
+
const base64ToArrayBuffer = Binary.fromBase64;
|
|
206
|
+
/** Encode binary data as base64. */
|
|
207
|
+
const arrayBufferToBase64 = Binary.toBase64;
|
|
208
|
+
/** Decode a hex string into binary data. */
|
|
209
|
+
const hexToArrayBuffer = Binary.fromHex;
|
|
210
|
+
/** Encode binary data as hex. */
|
|
211
|
+
const arrayBufferToHex = Binary.toHex;
|
|
212
|
+
/** Deep-clone common JavaScript values while preserving prototypes and cycles. */
|
|
213
|
+
function clone(source, refs = /* @__PURE__ */ new Map()) {
|
|
214
|
+
if (!source || typeof source !== "object") return source;
|
|
215
|
+
if (is("Date", source)) return new Date(source.valueOf());
|
|
216
|
+
if (is("RegExp", source)) return new RegExp(source.source, source.flags);
|
|
217
|
+
if (isArrayBufferLike(source)) return source.slice(0);
|
|
218
|
+
if (ArrayBuffer.isView(source)) return source.buffer.slice(source.byteOffset, source.byteOffset + source.byteLength);
|
|
219
|
+
const cached = refs.get(source);
|
|
220
|
+
if (cached) return cached;
|
|
221
|
+
if (Array.isArray(source)) {
|
|
222
|
+
const result = [];
|
|
223
|
+
refs.set(source, result);
|
|
224
|
+
source.forEach((value, index) => {
|
|
225
|
+
result[index] = Reflect.apply(clone, null, [value, refs]);
|
|
226
|
+
});
|
|
227
|
+
return result;
|
|
228
|
+
}
|
|
229
|
+
const result = Object.create(Object.getPrototypeOf(source));
|
|
230
|
+
refs.set(source, result);
|
|
231
|
+
for (const key of Reflect.ownKeys(source)) {
|
|
232
|
+
const descriptor = { ...Reflect.getOwnPropertyDescriptor(source, key) };
|
|
233
|
+
if ("value" in descriptor) descriptor.value = Reflect.apply(clone, null, [descriptor.value, refs]);
|
|
234
|
+
Reflect.defineProperty(result, key, descriptor);
|
|
235
|
+
}
|
|
236
|
+
return result;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Compare values recursively, treating two volatile references as equal regardless of value.
|
|
240
|
+
* Strict comparison distinguishes null/undefined, treats opaque objects by identity,
|
|
241
|
+
* compares URLs by normalized href, treats array holes as undefined, and considers distinct cyclic structures unequal.
|
|
242
|
+
* @param a - first value.
|
|
243
|
+
* @param b - second value.
|
|
244
|
+
* @param strict - whether to require strict data equality outside volatile references.
|
|
245
|
+
* @returns whether the values compare equal.
|
|
246
|
+
*/
|
|
247
|
+
function deepEqual(a, b, strict) {
|
|
248
|
+
const ancestors = /* @__PURE__ */ new Set();
|
|
249
|
+
function compare(a, b) {
|
|
250
|
+
if (a === b) return true;
|
|
251
|
+
if (isVolatile(a) || isVolatile(b)) return isVolatile(a) && isVolatile(b);
|
|
252
|
+
if (!strict && isNullable(a) && isNullable(b)) return true;
|
|
253
|
+
if (typeof a !== typeof b || typeof a !== "object" || !a || !b) return false;
|
|
254
|
+
if (ancestors.has(a)) return false;
|
|
255
|
+
function check(test, then) {
|
|
256
|
+
return test(a) ? test(b) ? then(a, b) : false : test(b) ? false : void 0;
|
|
257
|
+
}
|
|
258
|
+
ancestors.add(a);
|
|
259
|
+
try {
|
|
260
|
+
return check(Array.isArray, (a, b) => {
|
|
261
|
+
if (a.length !== b.length) return false;
|
|
262
|
+
for (let index = 0; index < a.length; index++) if (!compare(a[index], b[index])) return false;
|
|
263
|
+
return true;
|
|
264
|
+
}) ?? check(is("Date"), (a, b) => a.valueOf() === b.valueOf()) ?? check(is("URL"), (a, b) => a.href === b.href) ?? check(is("RegExp"), (a, b) => a.source === b.source && a.flags === b.flags) ?? check(isArrayBufferLike, (a, b) => {
|
|
265
|
+
if (a.byteLength !== b.byteLength) return false;
|
|
266
|
+
const viewA = new Uint8Array(a);
|
|
267
|
+
const viewB = new Uint8Array(b);
|
|
268
|
+
for (let i = 0; i < viewA.length; i++) if (viewA[i] !== viewB[i]) return false;
|
|
269
|
+
return true;
|
|
270
|
+
}) ?? ((!strict || [a, b].every((value) => Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null)) && Object.keys({
|
|
271
|
+
...a,
|
|
272
|
+
...b
|
|
273
|
+
}).every((key) => compare(a[key], b[key])));
|
|
274
|
+
} finally {
|
|
275
|
+
ancestors.delete(a);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return compare(a, b);
|
|
279
|
+
}
|
|
280
|
+
//#endregion
|
|
281
|
+
//#region lib/types/string.js
|
|
282
|
+
/** Uppercase the first character of a string. */
|
|
283
|
+
function capitalize(source) {
|
|
284
|
+
return source.charAt(0).toUpperCase() + source.slice(1);
|
|
285
|
+
}
|
|
286
|
+
/** Lowercase the first character of a string. */
|
|
287
|
+
function uncapitalize(source) {
|
|
288
|
+
return source.charAt(0).toLowerCase() + source.slice(1);
|
|
289
|
+
}
|
|
290
|
+
/** Convert dash or underscore delimited text to camelCase. */
|
|
291
|
+
function camelCase(source) {
|
|
292
|
+
return source.replace(/[_-][a-z]/g, (str) => str.slice(1).toUpperCase());
|
|
293
|
+
}
|
|
294
|
+
function tokenize(source, delimiters, delimiter) {
|
|
295
|
+
const output = [];
|
|
296
|
+
let state = 0;
|
|
297
|
+
for (let i = 0; i < source.length; i++) {
|
|
298
|
+
const code = source.charCodeAt(i);
|
|
299
|
+
if (code >= 65 && code <= 90) {
|
|
300
|
+
if (state === 1) {
|
|
301
|
+
const next = source.charCodeAt(i + 1);
|
|
302
|
+
if (next >= 97 && next <= 122) output.push(delimiter);
|
|
303
|
+
output.push(code + 32);
|
|
304
|
+
} else {
|
|
305
|
+
if (state !== 0) output.push(delimiter);
|
|
306
|
+
output.push(code + 32);
|
|
307
|
+
}
|
|
308
|
+
state = 1;
|
|
309
|
+
} else if (code >= 97 && code <= 122) {
|
|
310
|
+
output.push(code);
|
|
311
|
+
state = 2;
|
|
312
|
+
} else if (delimiters.includes(code)) {
|
|
313
|
+
if (state !== 0) output.push(delimiter);
|
|
314
|
+
state = 0;
|
|
315
|
+
} else output.push(code);
|
|
316
|
+
}
|
|
317
|
+
return String.fromCharCode(...output);
|
|
318
|
+
}
|
|
319
|
+
/** Convert text to dash-delimited parameter case. */
|
|
320
|
+
function paramCase(source) {
|
|
321
|
+
return tokenize(source, [45, 95], 45);
|
|
322
|
+
}
|
|
323
|
+
/** Convert text to underscore-delimited snake case. */
|
|
324
|
+
function snakeCase(source) {
|
|
325
|
+
return tokenize(source, [45, 95], 95);
|
|
326
|
+
}
|
|
327
|
+
/** Runtime alias for `camelCase`. */
|
|
328
|
+
const camelize = camelCase;
|
|
329
|
+
/** Runtime alias for `paramCase`. */
|
|
330
|
+
const hyphenate = paramCase;
|
|
331
|
+
/** Format a property key as a JavaScript member access suffix. */
|
|
332
|
+
function formatProperty(key) {
|
|
333
|
+
if (typeof key !== "string") return `[${key.toString()}]`;
|
|
334
|
+
return /^[a-z_$][\w$]*$/i.test(key) ? `.${key}` : `[${JSON.stringify(key)}]`;
|
|
335
|
+
}
|
|
336
|
+
/** Remove one trailing slash from a path string. */
|
|
337
|
+
function trimSlash(source) {
|
|
338
|
+
return source.replace(/\/$/, "");
|
|
339
|
+
}
|
|
340
|
+
/** Ensure a path starts with `/` and has no trailing slash. */
|
|
341
|
+
function sanitize(source) {
|
|
342
|
+
if (!source.startsWith("/")) source = "/" + source;
|
|
343
|
+
return trimSlash(source);
|
|
344
|
+
}
|
|
345
|
+
//#endregion
|
|
346
|
+
//#region lib/types/time.js
|
|
347
|
+
/** Time constants plus parsing and formatting helpers. */
|
|
348
|
+
var Time;
|
|
349
|
+
(function(Time) {
|
|
350
|
+
Time.millisecond = 1;
|
|
351
|
+
Time.second = 1e3;
|
|
352
|
+
Time.minute = Time.second * 60;
|
|
353
|
+
Time.hour = Time.minute * 60;
|
|
354
|
+
Time.day = Time.hour * 24;
|
|
355
|
+
Time.week = Time.day * 7;
|
|
356
|
+
let timezoneOffset = (/* @__PURE__ */ new Date()).getTimezoneOffset();
|
|
357
|
+
function setTimezoneOffset(offset) {
|
|
358
|
+
timezoneOffset = offset;
|
|
359
|
+
}
|
|
360
|
+
Time.setTimezoneOffset = setTimezoneOffset;
|
|
361
|
+
function getTimezoneOffset() {
|
|
362
|
+
return timezoneOffset;
|
|
363
|
+
}
|
|
364
|
+
Time.getTimezoneOffset = getTimezoneOffset;
|
|
365
|
+
function getDateNumber(date = /* @__PURE__ */ new Date(), offset) {
|
|
366
|
+
if (typeof date === "number") date = new Date(date);
|
|
367
|
+
if (offset === void 0) offset = timezoneOffset;
|
|
368
|
+
return Math.floor((date.valueOf() / Time.minute - offset) / 1440);
|
|
369
|
+
}
|
|
370
|
+
Time.getDateNumber = getDateNumber;
|
|
371
|
+
function fromDateNumber(value, offset) {
|
|
372
|
+
const date = new Date(value * Time.day);
|
|
373
|
+
if (offset === void 0) offset = timezoneOffset;
|
|
374
|
+
return new Date(+date + offset * Time.minute);
|
|
375
|
+
}
|
|
376
|
+
Time.fromDateNumber = fromDateNumber;
|
|
377
|
+
const numeric = /\d+(?:\.\d+)?/.source;
|
|
378
|
+
const timeRegExp = new RegExp(`^${[
|
|
379
|
+
"w(?:eek(?:s)?)?",
|
|
380
|
+
"d(?:ay(?:s)?)?",
|
|
381
|
+
"h(?:our(?:s)?)?",
|
|
382
|
+
"m(?:in(?:ute)?(?:s)?)?",
|
|
383
|
+
"s(?:ec(?:ond)?(?:s)?)?"
|
|
384
|
+
].map((unit) => `(${numeric}${unit})?`).join("")}$`);
|
|
385
|
+
function parseTime(source) {
|
|
386
|
+
const capture = timeRegExp.exec(source);
|
|
387
|
+
if (!capture) return 0;
|
|
388
|
+
return (parseFloat(capture[1]) * Time.week || 0) + (parseFloat(capture[2]) * Time.day || 0) + (parseFloat(capture[3]) * Time.hour || 0) + (parseFloat(capture[4]) * Time.minute || 0) + (parseFloat(capture[5]) * Time.second || 0);
|
|
389
|
+
}
|
|
390
|
+
Time.parseTime = parseTime;
|
|
391
|
+
function parseDate(date) {
|
|
392
|
+
const parsed = parseTime(date);
|
|
393
|
+
if (parsed) date = Date.now() + parsed;
|
|
394
|
+
else if (/^\d{1,2}(:\d{1,2}){1,2}$/.test(date)) date = `${(/* @__PURE__ */ new Date()).toLocaleDateString()}-${date}`;
|
|
395
|
+
else if (/^\d{1,2}-\d{1,2}-\d{1,2}(:\d{1,2}){1,2}$/.test(date)) date = `${(/* @__PURE__ */ new Date()).getFullYear()}-${date}`;
|
|
396
|
+
return date ? new Date(date) : /* @__PURE__ */ new Date();
|
|
397
|
+
}
|
|
398
|
+
Time.parseDate = parseDate;
|
|
399
|
+
function format(ms) {
|
|
400
|
+
const abs = Math.abs(ms);
|
|
401
|
+
if (abs >= Time.day - Time.hour / 2) return Math.round(ms / Time.day) + "d";
|
|
402
|
+
else if (abs >= Time.hour - Time.minute / 2) return Math.round(ms / Time.hour) + "h";
|
|
403
|
+
else if (abs >= Time.minute - Time.second / 2) return Math.round(ms / Time.minute) + "m";
|
|
404
|
+
else if (abs >= Time.second) return Math.round(ms / Time.second) + "s";
|
|
405
|
+
return ms + "ms";
|
|
406
|
+
}
|
|
407
|
+
Time.format = format;
|
|
408
|
+
function toDigits(source, length = 2) {
|
|
409
|
+
return source.toString().padStart(length, "0");
|
|
410
|
+
}
|
|
411
|
+
Time.toDigits = toDigits;
|
|
412
|
+
function template(template, time = /* @__PURE__ */ new Date()) {
|
|
413
|
+
return template.replace("yyyy", time.getFullYear().toString()).replace("yy", time.getFullYear().toString().slice(2)).replace("MM", toDigits(time.getMonth() + 1)).replace("dd", toDigits(time.getDate())).replace("hh", toDigits(time.getHours())).replace("mm", toDigits(time.getMinutes())).replace("ss", toDigits(time.getSeconds())).replace("SSS", toDigits(time.getMilliseconds(), 3));
|
|
414
|
+
}
|
|
415
|
+
Time.template = template;
|
|
416
|
+
})(Time || (Time = {}));
|
|
417
|
+
//#endregion
|
|
418
|
+
export { Binary, Time, arrayBufferToBase64, arrayBufferToHex, base64ToArrayBuffer, camelCase, camelize, capitalize, clone, contain, createVolatile, deduplicate, deepEqual, defineProperty, difference, filterKeys, formatProperty, hexToArrayBuffer, hyphenate, intersection, is, isNonNullable, isNullable, isPlainObject, isVolatile, makeArray, mapValues, mapValues as valueMap, noop, omit, paramCase, pick, remove, sanitize, snakeCase, trimSlash, uncapitalize, union, updateVolatile, volatileEntries };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@deepseek-ai/cosmokit",
|
|
3
|
+
"description": "A collection of common utilities",
|
|
4
|
+
"version": "1.9.0",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/deepseek-ai/deepseek-harness.git",
|
|
11
|
+
"directory": "vendor/cosmokit"
|
|
12
|
+
},
|
|
13
|
+
"type": "module",
|
|
14
|
+
"main": "lib/index.js",
|
|
15
|
+
"types": "lib/types/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./lib/types/index.d.ts",
|
|
19
|
+
"default": "./lib/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./src/*": "./src/*",
|
|
22
|
+
"./package.json": "./package.json"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"lib/index.js",
|
|
26
|
+
"lib/types/**/*.d.ts",
|
|
27
|
+
"lib/types/**/*.d.ts.map",
|
|
28
|
+
"src"
|
|
29
|
+
],
|
|
30
|
+
"author": "Shigma <shigma10826@gmail.com>",
|
|
31
|
+
"license": "MIT"
|
|
32
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { isNullable } from './misc.ts'
|
|
2
|
+
|
|
3
|
+
/** Return true when every item in `array2` is present in `array1`. */
|
|
4
|
+
export function contain(array1: readonly any[], array2: readonly any[]) {
|
|
5
|
+
return array2.every(item => array1.includes(item))
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/** Return items that appear in both arrays. */
|
|
9
|
+
export function intersection<T>(array1: readonly T[], array2: readonly T[]) {
|
|
10
|
+
return array1.filter(item => array2.includes(item))
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Return items from `array1` that do not appear in `array2`. */
|
|
14
|
+
export function difference<S>(array1: readonly S[], array2: readonly any[]) {
|
|
15
|
+
return array1.filter(item => !array2.includes(item))
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Return the set-union of two arrays while preserving first occurrence order. */
|
|
19
|
+
export function union<T>(array1: readonly T[], array2: readonly T[]) {
|
|
20
|
+
return Array.from(new Set([...array1, ...array2]))
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Remove duplicate values while preserving first occurrence order. */
|
|
24
|
+
export function deduplicate<T>(array: readonly T[]) {
|
|
25
|
+
return [...new Set(array)]
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Remove one item from an array and report whether it was found. */
|
|
29
|
+
export function remove<T>(list: T[], item: T) {
|
|
30
|
+
const index = list?.indexOf(item)
|
|
31
|
+
if (index >= 0) {
|
|
32
|
+
list.splice(index, 1)
|
|
33
|
+
return true
|
|
34
|
+
} else {
|
|
35
|
+
return false
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Normalize nullish, scalar, or array input to an array. */
|
|
40
|
+
export function makeArray<T>(source: null | undefined | T | T[]) {
|
|
41
|
+
return Array.isArray(source) ? source : isNullable(source) ? [] : [source]
|
|
42
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Array set and normalization helpers. */
|
|
2
|
+
export * from './array.ts'
|
|
3
|
+
/** Runtime type, binary, clone, and equality helpers. */
|
|
4
|
+
export * from './types.ts'
|
|
5
|
+
/** Shared utility types and object helpers. */
|
|
6
|
+
export * from './misc.ts'
|
|
7
|
+
/** String case, path, and property formatting helpers. */
|
|
8
|
+
export * from './string.ts'
|
|
9
|
+
/** Time constants, parsing, and formatting helpers. */
|
|
10
|
+
export * from './time.ts'
|
|
11
|
+
/** Immutable config references shared by schema validators and runtimes. */
|
|
12
|
+
export * from './volatile.ts'
|