@deepseek-ai/dsh-plugin-package-inventory-deepseek 0.1.2-alpha.2

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 DeepSeek
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,6 @@
1
+ # Bilingual-pair consistency record (docs/i18n/README.md): the git blob hash of each
2
+ # side as of the last confirmed-consistent state. Both languages carry equal authority;
3
+ # after editing either side, bring the other along and re-record with:
4
+ # pnpm run verify-translation-pairing --write packages/llm/plugin-package-inventory-deepseek/README.md
5
+ README.md: 36fe380b8805a1b7af5d455e6309e62b2512eb0d
6
+ README.zh.md: 2d7bd12765499f4c00dcb5c4b8770ce5ff90f92d
package/README.md ADDED
@@ -0,0 +1,76 @@
1
+ ---
2
+ description: "Active Loader package inventory metadata for deployments sending official DeepSeek requests."
3
+ kind: "package-reference"
4
+ ---
5
+
6
+ # @deepseek-ai/dsh-plugin-package-inventory-deepseek
7
+
8
+ English | [中文](README.zh.md)
9
+
10
+ ## Summary
11
+
12
+ Complete active Loader-backed plugin package inventory for official DeepSeek LLM API requests. This function plugin injects the Loader, live Agent registry, and `ctx.deepseekLlmApiExtensions`, then owns the `dsh_plugin_packages` field. Enable it when the official API needs the active package list for request diagnostics.
13
+
14
+ ## Table of Contents
15
+
16
+ - [Configuration](#configuration)
17
+ - [Collection](#collection)
18
+ - [Model Experience](#model-experience)
19
+ - [Known Limitations and Deferred Work](#known-limitations-and-deferred-work)
20
+ - [Dev Note](#dev-note)
21
+
22
+ -----
23
+
24
+ <a id="configuration"></a>
25
+ ## Configuration
26
+
27
+ | Key | Default | Meaning |
28
+ |---|---:|---|
29
+ | `enabled` | `true` | Register the `dsh_plugin_packages` contribution. Set it to `false` to omit package metadata. |
30
+
31
+ Shipped profiles use the default, so every official DeepSeek request carries the package inventory when preparation succeeds.
32
+
33
+ <a id="collection"></a>
34
+ ## Collection
35
+
36
+ Every request re-reads active non-group entries from the host Loader tree. When optional `ctx.agentPresets` is present and `sessionId` resolves to a live Agent joined to a standing preset, that preset's separate Loader tree joins the same collection; deployments without the service report the host tree only. Entries are included only while their root fiber is `ACTIVE` and their effective Loader state is enabled.
37
+
38
+ Bare package and package-subpath specifiers resolve through Node's package search paths without requiring a `./package.json` export. Each ordinary entry uses its owning Loader tree base. A standing preset's root entries use the harness base, matching the preset Loader's deliberate bare-package override; nested includes retain their own bases. Relative and absolute modules walk to their nearest manifest; a manifest without `name` marks a loose module and contributes no package identity. A named package manifest must also declare a non-empty `version`, and malformed package metadata fails request preparation. Exact name/version pairs are deduplicated and sorted with a locale-independent comparison, while simultaneously active different versions remain separate.
39
+
40
+ The version-1 `dsh_plugin_packages` field contains only `{ name, version }` pairs. Disabled, pending, failed, disposed, unloading, structural `cordis:` rows, ordinary dependencies, loose files without an owning package identity, programmatically mounted child fibers, and in-memory dynamic plugins are excluded.
41
+
42
+ <a id="model-experience"></a>
43
+ ## Model Experience
44
+
45
+ ### Package inventory metadata
46
+
47
+ #### What the model sees
48
+
49
+ Nothing. `dsh_plugin_packages` is provider metadata outside the model's messages, system prompt, and tool schemas.
50
+
51
+ #### Token effect
52
+
53
+ Zero model-input tokens; the complete inventory adds only HTTP request bytes.
54
+
55
+ #### KV Cache effect
56
+
57
+ None; package lifecycle changes do not alter the model-visible prefix.
58
+
59
+ ## Known Limitations and Deferred Work
60
+
61
+ <a id="known-limitations-and-deferred-work"></a>
62
+
63
+ - **Loader package provenance only** — programmatic child fibers and in-memory dynamic plugins do not have authoritative npm name/version provenance and remain outside this inventory.
64
+ - **Loose modules are omitted** — a relative file without a named and versioned owning manifest is a plugin module, not a plugin package.
65
+ - **In-place package replacement requires restart** — manifest identities are cached for the process lifetime. Loader enable, disable, mount, unmount, and ordinary source HMR still refresh the active entry set, but replacing a mounted package's manifest with another version in the same process is not a supported upgrade path.
66
+
67
+
68
+ <a id="dev-note"></a>
69
+ ### Dev Note
70
+
71
+ <details>
72
+ <summary>Working context for maintainers — click to expand</summary>
73
+
74
+ None.
75
+
76
+ </details>
package/README.zh.md ADDED
@@ -0,0 +1,76 @@
1
+ ---
2
+ description: "面向发送官方 DeepSeek 请求的部署,说明活跃 Loader 包清单元数据。"
3
+ kind: "package-reference"
4
+ ---
5
+
6
+ # @deepseek-ai/dsh-plugin-package-inventory-deepseek
7
+
8
+ [English](README.md) | 中文
9
+
10
+ ## 概述
11
+
12
+ 用于 DeepSeek 官方 LLM API 请求的完整存活 Loader 插件包清单。该函数插件注入 Loader、存活 Agent 注册表与 `ctx.deepseekLlmApiExtensions`,并拥有 `dsh_plugin_packages` 字段。当官方 API 需要活动包清单进行请求诊断时,请启用它。
13
+
14
+ ## 目录
15
+
16
+ - [配置](#configuration)
17
+ - [收集](#collection)
18
+ - [模型体验](#model-experience)
19
+ - [已知限制与暂缓事项](#known-limitations-and-deferred-work)
20
+ - [开发备注](#dev-note)
21
+
22
+ -----
23
+
24
+ <a id="configuration"></a>
25
+ ## 配置
26
+
27
+ | 配置键 | 默认值 | 含义 |
28
+ |---|---:|---|
29
+ | `enabled` | `true` | 注册 `dsh_plugin_packages` 贡献。将其设为 `false` 可省略包元数据。 |
30
+
31
+ 随附 profile 使用该默认值,因此只要准备成功,每个 DeepSeek 官方请求都会携带包清单。
32
+
33
+ <a id="collection"></a>
34
+ ## 收集
35
+
36
+ 每次请求都会重读宿主 Loader 树中的存活非 group 配置项。存在可选 `ctx.agentPresets` 且 `sessionId` 解析到已加入 standing preset 的存活 Agent 时,该 preset 的独立 Loader 树也会加入同一次收集;未挂载该服务的部署只报告宿主树。只有根 fiber 处于 `ACTIVE` 且 Loader 有效状态为启用的配置项才会纳入。
37
+
38
+ 裸包与包子路径 specifier 通过 Node 包搜索路径解析,无需包导出 `./package.json`。每个普通配置项使用其所属 Loader 树的基址。standing preset 的根配置项使用宿主基址,与 preset Loader 对裸包的显式覆写保持一致;嵌套 include 仍使用自身基址。相对与绝对模块会向上查找最近的 manifest(元数据清单);没有 `name` 的 manifest 只标记松散模块,不贡献包身份。具名包 manifest 还必须声明非空 `version`,格式错误的包元数据会使请求准备失败。系统使用与 locale 无关的比较按确切名称/版本对去重并排序,同时存活的不同版本仍会分开保留。
39
+
40
+ 版本 1 的 `dsh_plugin_packages` 字段只包含 `{ name, version }` 对。系统会排除禁用、pending、failed、disposed、unloading 状态,结构性 `cordis:` 配置项,普通依赖,没有所属包身份的松散文件,以编程方式挂载的子 fiber,以及内存动态插件。
41
+
42
+ <a id="model-experience"></a>
43
+ ## 模型体验
44
+
45
+ ### 包清单元数据
46
+
47
+ #### 模型看到的内容
48
+
49
+ 无。`dsh_plugin_packages` 是位于模型消息、系统提示词与工具 schema 之外的提供方元数据。
50
+
51
+ #### Token 影响
52
+
53
+ 模型输入 token 为零;完整清单只会增加 HTTP 请求字节数。
54
+
55
+ #### KV Cache 影响
56
+
57
+ 无;包生命周期变化不会改变模型可见前缀。
58
+
59
+ ## 已知限制与暂缓事项
60
+
61
+ <a id="known-limitations-and-deferred-work"></a>
62
+
63
+ - **仅含 Loader 包来源**——以编程方式创建的子 fiber 与内存动态插件没有权威 NPM 名称/版本来源,因此不在该清单内。
64
+ - **省略松散模块**——没有具名且带版本所属 manifest 的相对文件是插件模块,不是插件包。
65
+ - **原地替换包需要重启**——manifest 身份会在进程存活期内缓存。Loader 的启用、禁用、挂载、卸载与普通源码 HMR 仍会刷新存活配置项集合,但在同一进程中把已挂载包的 manifest 替换为另一版本并不是受支持的升级路径。
66
+
67
+
68
+ <a id="dev-note"></a>
69
+ ### 开发备注
70
+
71
+ <details>
72
+ <summary>维护者工作上下文——点击展开</summary>
73
+
74
+ 无。
75
+
76
+ </details>
package/lib/index.js ADDED
@@ -0,0 +1,143 @@
1
+ import { createRequire } from "node:module";
2
+ import { existsSync, readFileSync } from "node:fs";
3
+ import { dirname, isAbsolute, join, parse } from "node:path";
4
+ import { fileURLToPath, pathToFileURL } from "node:url";
5
+ import z from "@deepseek-ai/schemastery";
6
+ import { brandString } from "@deepseek-ai/dsh-brand";
7
+ //#region lib/types/index.js
8
+ /**
9
+ * Active Loader-backed plugin package inventory for official DeepSeek requests.
10
+ * Host entries and the requesting agent's standing preset are resolved at request time;
11
+ * installed dependencies and plugin fibers without Loader package provenance are excluded.
12
+ * @module @deepseek-ai/dsh-plugin-package-inventory-deepseek
13
+ */
14
+ /** Cordis plugin name. */
15
+ const name = "plugin-package-inventory-deepseek";
16
+ /** Services required to locate host/requesting-agent entries and contribute the field. */
17
+ const inject = [
18
+ "agents",
19
+ "deepseekLlmApiExtensions",
20
+ "loader"
21
+ ];
22
+ /** Validated plugin-package request contribution configuration. */
23
+ const Config = z.object({ enabled: z.boolean().default(true) });
24
+ /** Parse a bare package or package-subpath specifier into its package name. */
25
+ function barePackageName(specifier) {
26
+ if (specifier.startsWith(".") || specifier.includes(":") || isAbsolute(specifier)) return void 0;
27
+ const [first = "", second = ""] = specifier.split("/");
28
+ return first.startsWith("@") ? `${first}/${second}` : first;
29
+ }
30
+ /** Read one manifest identity, optionally treating an absent name as a loose-module marker. */
31
+ function identityFromManifest(path, allowAnonymous) {
32
+ const manifest = JSON.parse(readFileSync(path, "utf8"));
33
+ if (allowAnonymous && manifest.name === void 0) return void 0;
34
+ if (typeof manifest.name !== "string" || manifest.name.length === 0 || typeof manifest.version !== "string" || manifest.version.length === 0) throw new Error(`plugin-package-inventory-deepseek: ${path} must declare non-empty name and version`);
35
+ return {
36
+ name: manifest.name,
37
+ version: manifest.version
38
+ };
39
+ }
40
+ /** Resolve a bare package without requiring it to export `./package.json`. */
41
+ function barePackageManifest(packageName, anchors) {
42
+ for (const anchor of anchors) {
43
+ const searchPaths = createRequire(anchor).resolve.paths(packageName);
44
+ /* v8 ignore next -- active non-builtin package entries always have Node package search paths */
45
+ if (searchPaths === null) continue;
46
+ for (const searchPath of searchPaths) {
47
+ const manifest = join(searchPath, packageName, "package.json");
48
+ if (existsSync(manifest)) return manifest;
49
+ }
50
+ }
51
+ }
52
+ /** Find the nearest owning manifest for a relative or absolute plugin module. */
53
+ function nearestManifest(modulePath) {
54
+ let current = dirname(modulePath);
55
+ const root = parse(current).root;
56
+ while (true) {
57
+ const manifest = join(current, "package.json");
58
+ if (existsSync(manifest)) return manifest;
59
+ if (current === root) return void 0;
60
+ current = dirname(current);
61
+ }
62
+ }
63
+ /** Exact package identity resolver with immutable per-process manifest caching. */
64
+ var PackageIdentityResolver = class {
65
+ hostBaseUrl;
66
+ cache = /* @__PURE__ */ new Map();
67
+ constructor(hostBaseUrl) {
68
+ this.hostBaseUrl = hostBaseUrl;
69
+ }
70
+ /** Resolve one Loader entry's owning package, or absence for a non-package loose module. */
71
+ resolve({ entry, bareBaseUrl }) {
72
+ /* v8 ignore next -- Loader entry trees inherit a base URL; the fallback supports direct embedders. */
73
+ const treeBase = entry.parent.tree.ctx.baseUrl ?? this.hostBaseUrl;
74
+ const anchors = [...new Set([
75
+ bareBaseUrl ?? treeBase,
76
+ treeBase,
77
+ this.hostBaseUrl,
78
+ import.meta.url
79
+ ])];
80
+ const key = `${anchors.join("\0")}\u0000${entry.options.name}`;
81
+ if (this.cache.has(key)) return this.cache.get(key);
82
+ const packageName = barePackageName(entry.options.name);
83
+ let manifest;
84
+ if (packageName !== void 0) {
85
+ manifest = barePackageManifest(packageName, anchors);
86
+ if (manifest === void 0) throw new Error(`plugin-package-inventory-deepseek: cannot resolve active package ${JSON.stringify(packageName)}`);
87
+ } else if (!entry.options.name.startsWith("cordis:")) {
88
+ const moduleUrl = isAbsolute(entry.options.name) ? pathToFileURL(entry.options.name) : new URL(entry.options.name, treeBase);
89
+ if (moduleUrl.protocol === "file:") manifest = nearestManifest(fileURLToPath(moduleUrl));
90
+ }
91
+ const identity = manifest === void 0 ? void 0 : identityFromManifest(manifest, packageName === void 0);
92
+ this.cache.set(key, identity);
93
+ return identity;
94
+ }
95
+ };
96
+ /** Yield active, non-structural entries from one Loader tree. */
97
+ function activeEntries(tree, rootBareBaseUrl) {
98
+ return [...tree.entries()].filter((entry) => !entry.options.group && !entry.disabled && entry.fiber?.state === 2).map((entry) => ({
99
+ entry,
100
+ ...entry.parent.tree === tree && rootBareBaseUrl !== void 0 ? { bareBaseUrl: rootBareBaseUrl } : {}
101
+ }));
102
+ }
103
+ /** Deterministic text order independent of the host's ICU data and locale. */
104
+ function compareWireText(left, right) {
105
+ return left < right ? -1 : left > right ? 1 : 0;
106
+ }
107
+ /** Collect the full active package set for one request. */
108
+ async function collectActivePluginPackages(ctx, resolver, hostBaseUrl, sessionId) {
109
+ const entries = activeEntries(ctx.loader);
110
+ if (sessionId !== void 0 && ctx.get("agentPresets") !== void 0) {
111
+ const agent = ctx.agents.get(brandString(sessionId));
112
+ if (agent !== void 0) {
113
+ const { standingMountFor } = await import("@deepseek-ai/dsh-agent-presets");
114
+ const presetTree = standingMountFor(agent.ctx)?.tree;
115
+ if (presetTree !== void 0) entries.push(...activeEntries(presetTree, hostBaseUrl));
116
+ }
117
+ }
118
+ const unique = /* @__PURE__ */ new Map();
119
+ for (const activeEntry of entries) {
120
+ const identity = resolver.resolve(activeEntry);
121
+ if (identity === void 0) continue;
122
+ unique.set(`${identity.name}\u0000${identity.version}`, identity);
123
+ }
124
+ return [...unique.values()].sort((left, right) => compareWireText(left.name, right.name) || compareWireText(left.version, right.version));
125
+ }
126
+ /**
127
+ * Register the complete `dsh_plugin_packages` request contribution when enabled.
128
+ * @param ctx - plugin context carrying Loader provenance and the DeepSeek request-extension registry.
129
+ * @param config - validated default-on configuration.
130
+ */
131
+ function apply(ctx, config) {
132
+ if (config.enabled === false) return;
133
+ const hostBaseUrl = ctx.baseUrl ?? import.meta.url;
134
+ const resolver = new PackageIdentityResolver(hostBaseUrl);
135
+ ctx.deepseekLlmApiExtensions.register("dsh_plugin_packages", { prepare: async (request) => {
136
+ return { value: {
137
+ version: 1,
138
+ packages: await collectActivePluginPackages(ctx, resolver, hostBaseUrl, request.sessionId)
139
+ } };
140
+ } });
141
+ }
142
+ //#endregion
143
+ export { Config, apply, inject, name };
@@ -0,0 +1,20 @@
1
+ //#region lib/types/invariant.js
2
+ /** Package-owned invariant companion for `@deepseek-ai/dsh-plugin-package-inventory-deepseek`. */
3
+ const PACKAGE_NAME = "@deepseek-ai/dsh-plugin-package-inventory-deepseek";
4
+ /** Cordis companion plugin name. */
5
+ const name = "plugin-package-inventory-deepseek-invariant";
6
+ /** Service required before the companion can reserve package ownership. */
7
+ const inject = ["invariants"];
8
+ /**
9
+ * No runtime invariant: each request reads authoritative Loader fiber state and
10
+ * package manifests directly; the plugin retains no independently mutable inventory.
11
+ */
12
+ const install = () => {};
13
+ /**
14
+ * Register this package's invariant companion.
15
+ * @param ctx - Cordis context carrying the invariant service.
16
+ * @returns the installed registration's disposer after setup succeeds.
17
+ */
18
+ const apply = (ctx) => Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install));
19
+ //#endregion
20
+ export { apply, inject, name };
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Active Loader-backed plugin package inventory for official DeepSeek requests.
3
+ * Host entries and the requesting agent's standing preset are resolved at request time;
4
+ * installed dependencies and plugin fibers without Loader package provenance are excluded.
5
+ * @module @deepseek-ai/dsh-plugin-package-inventory-deepseek
6
+ */
7
+ import { type Context } from '@deepseek-ai/cordis';
8
+ import z from '@deepseek-ai/schemastery';
9
+ export type * from './types.ts';
10
+ /** Cordis plugin name. */
11
+ export declare const name = "plugin-package-inventory-deepseek";
12
+ /** Services required to locate host/requesting-agent entries and contribute the field. */
13
+ export declare const inject: string[];
14
+ /** Plugin-package request contribution configuration. */
15
+ export interface Config {
16
+ /** Contribute `dsh_plugin_packages` to official DeepSeek requests. Defaults to `true`. */
17
+ enabled?: boolean;
18
+ }
19
+ /** Validated plugin-package request contribution configuration. */
20
+ export declare const Config: z<Config>;
21
+ /**
22
+ * Register the complete `dsh_plugin_packages` request contribution when enabled.
23
+ * @param ctx - plugin context carrying Loader provenance and the DeepSeek request-extension registry.
24
+ * @param config - validated default-on configuration.
25
+ */
26
+ export declare function apply(ctx: Context, config: Config): void;
27
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,166 @@
1
+ /**
2
+ * Active Loader-backed plugin package inventory for official DeepSeek requests.
3
+ * Host entries and the requesting agent's standing preset are resolved at request time;
4
+ * installed dependencies and plugin fibers without Loader package provenance are excluded.
5
+ * @module @deepseek-ai/dsh-plugin-package-inventory-deepseek
6
+ */
7
+ import { existsSync, readFileSync } from 'node:fs';
8
+ import { createRequire } from 'node:module';
9
+ import { dirname, isAbsolute, join, parse } from 'node:path';
10
+ import { fileURLToPath, pathToFileURL } from 'node:url';
11
+ import z from '@deepseek-ai/schemastery';
12
+ import { brandString } from '@deepseek-ai/dsh-brand';
13
+ /** Cordis plugin name. */
14
+ export const name = 'plugin-package-inventory-deepseek';
15
+ /** Services required to locate host/requesting-agent entries and contribute the field. */
16
+ export const inject = ['agents', 'deepseekLlmApiExtensions', 'loader'];
17
+ /** Validated plugin-package request contribution configuration. */
18
+ export const Config = z.object({
19
+ enabled: z.boolean().default(true),
20
+ });
21
+ /** Parse a bare package or package-subpath specifier into its package name. */
22
+ function barePackageName(specifier) {
23
+ if (specifier.startsWith('.') || specifier.includes(':') || isAbsolute(specifier))
24
+ return undefined;
25
+ const [first = '', second = ''] = specifier.split('/');
26
+ // An active Loader entry already passed module resolution, so a scoped bare name has its package segment.
27
+ return first.startsWith('@') ? `${first}/${second}` : first;
28
+ }
29
+ /** Read one manifest identity, optionally treating an absent name as a loose-module marker. */
30
+ function identityFromManifest(path, allowAnonymous) {
31
+ const manifest = JSON.parse(readFileSync(path, 'utf8'));
32
+ if (allowAnonymous && manifest.name === undefined)
33
+ return undefined;
34
+ if (typeof manifest.name !== 'string' || manifest.name.length === 0
35
+ || typeof manifest.version !== 'string' || manifest.version.length === 0) {
36
+ throw new Error(`plugin-package-inventory-deepseek: ${path} must declare non-empty name and version`);
37
+ }
38
+ return { name: manifest.name, version: manifest.version };
39
+ }
40
+ /** Resolve a bare package without requiring it to export `./package.json`. */
41
+ function barePackageManifest(packageName, anchors) {
42
+ for (const anchor of anchors) {
43
+ const searchPaths = createRequire(anchor).resolve.paths(packageName);
44
+ /* v8 ignore next -- active non-builtin package entries always have Node package search paths */
45
+ if (searchPaths === null)
46
+ continue;
47
+ for (const searchPath of searchPaths) {
48
+ const manifest = join(searchPath, packageName, 'package.json');
49
+ if (existsSync(manifest))
50
+ return manifest;
51
+ }
52
+ }
53
+ return undefined;
54
+ }
55
+ /** Find the nearest owning manifest for a relative or absolute plugin module. */
56
+ function nearestManifest(modulePath) {
57
+ let current = dirname(modulePath);
58
+ const root = parse(current).root;
59
+ while (true) {
60
+ const manifest = join(current, 'package.json');
61
+ if (existsSync(manifest))
62
+ return manifest;
63
+ if (current === root)
64
+ return undefined;
65
+ current = dirname(current);
66
+ }
67
+ }
68
+ /** Exact package identity resolver with immutable per-process manifest caching. */
69
+ class PackageIdentityResolver {
70
+ hostBaseUrl;
71
+ // TODO: Invalidate manifest identities if in-process package-version replacement becomes a supported upgrade path.
72
+ cache = new Map();
73
+ constructor(hostBaseUrl) {
74
+ this.hostBaseUrl = hostBaseUrl;
75
+ }
76
+ /** Resolve one Loader entry's owning package, or absence for a non-package loose module. */
77
+ resolve({ entry, bareBaseUrl }) {
78
+ /* v8 ignore next -- Loader entry trees inherit a base URL; the fallback supports direct embedders. */
79
+ const treeBase = entry.parent.tree.ctx.baseUrl ?? this.hostBaseUrl;
80
+ const anchors = [...new Set([bareBaseUrl ?? treeBase, treeBase, this.hostBaseUrl, import.meta.url])];
81
+ const key = `${anchors.join('\u0000')}\u0000${entry.options.name}`;
82
+ if (this.cache.has(key))
83
+ return this.cache.get(key);
84
+ const packageName = barePackageName(entry.options.name);
85
+ let manifest;
86
+ if (packageName !== undefined) {
87
+ manifest = barePackageManifest(packageName, anchors);
88
+ if (manifest === undefined) {
89
+ throw new Error(`plugin-package-inventory-deepseek: cannot resolve active package ${JSON.stringify(packageName)}`);
90
+ }
91
+ }
92
+ else if (!entry.options.name.startsWith('cordis:')) {
93
+ const moduleUrl = isAbsolute(entry.options.name)
94
+ ? pathToFileURL(entry.options.name)
95
+ : new URL(entry.options.name, treeBase);
96
+ if (moduleUrl.protocol === 'file:')
97
+ manifest = nearestManifest(fileURLToPath(moduleUrl));
98
+ }
99
+ const identity = manifest === undefined ? undefined : identityFromManifest(manifest, packageName === undefined);
100
+ this.cache.set(key, identity);
101
+ return identity;
102
+ }
103
+ }
104
+ /** Yield active, non-structural entries from one Loader tree. */
105
+ function activeEntries(tree, rootBareBaseUrl) {
106
+ return [...tree.entries()]
107
+ .filter(entry => !entry.options.group
108
+ && !entry.disabled
109
+ && entry.fiber?.state === 2 /* FiberState.ACTIVE */)
110
+ .map(entry => ({
111
+ entry,
112
+ ...entry.parent.tree === tree && rootBareBaseUrl !== undefined
113
+ ? { bareBaseUrl: rootBareBaseUrl }
114
+ : {},
115
+ }));
116
+ }
117
+ /** Deterministic text order independent of the host's ICU data and locale. */
118
+ function compareWireText(left, right) {
119
+ return left < right ? -1 : left > right ? 1 : 0;
120
+ }
121
+ /** Collect the full active package set for one request. */
122
+ async function collectActivePluginPackages(ctx, resolver, hostBaseUrl, sessionId) {
123
+ const entries = activeEntries(ctx.loader);
124
+ if (sessionId !== undefined && ctx.get('agentPresets') !== undefined) {
125
+ const agent = ctx.agents.get(brandString(sessionId));
126
+ if (agent !== undefined) {
127
+ // The optional peer is loaded only when its service is present. Its existing
128
+ // mount query keeps Loader internals off the public AgentPresets service.
129
+ const { standingMountFor } = await import('@deepseek-ai/dsh-agent-presets');
130
+ const presetTree = standingMountFor(agent.ctx)?.tree;
131
+ // PresetTree deliberately resolves its root bare rows from the harness;
132
+ // nested ordinary includes retain their own tree base.
133
+ if (presetTree !== undefined)
134
+ entries.push(...activeEntries(presetTree, hostBaseUrl));
135
+ }
136
+ }
137
+ const unique = new Map();
138
+ for (const activeEntry of entries) {
139
+ const identity = resolver.resolve(activeEntry);
140
+ if (identity === undefined)
141
+ continue;
142
+ unique.set(`${identity.name}\u0000${identity.version}`, identity);
143
+ }
144
+ return [...unique.values()].sort((left, right) => (compareWireText(left.name, right.name) || compareWireText(left.version, right.version)));
145
+ }
146
+ /**
147
+ * Register the complete `dsh_plugin_packages` request contribution when enabled.
148
+ * @param ctx - plugin context carrying Loader provenance and the DeepSeek request-extension registry.
149
+ * @param config - validated default-on configuration.
150
+ */
151
+ export function apply(ctx, config) {
152
+ if (config.enabled === false)
153
+ return;
154
+ const hostBaseUrl = ctx.baseUrl ?? import.meta.url;
155
+ const resolver = new PackageIdentityResolver(hostBaseUrl);
156
+ ctx.deepseekLlmApiExtensions.register('dsh_plugin_packages', {
157
+ prepare: async (request) => {
158
+ const value = {
159
+ version: 1,
160
+ packages: await collectActivePluginPackages(ctx, resolver, hostBaseUrl, request.sessionId),
161
+ };
162
+ return { value };
163
+ },
164
+ });
165
+ }
166
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,13 @@
1
+ /** Package-owned invariant companion for `@deepseek-ai/dsh-plugin-package-inventory-deepseek`. */
2
+ import type { Context } from '@deepseek-ai/cordis';
3
+ /** Cordis companion plugin name. */
4
+ export declare const name = "plugin-package-inventory-deepseek-invariant";
5
+ /** Service required before the companion can reserve package ownership. */
6
+ export declare const inject: string[];
7
+ /**
8
+ * Register this package's invariant companion.
9
+ * @param ctx - Cordis context carrying the invariant service.
10
+ * @returns the installed registration's disposer after setup succeeds.
11
+ */
12
+ export declare const apply: (ctx: Context) => Promise<() => void>;
13
+ //# sourceMappingURL=invariant.d.ts.map
@@ -0,0 +1,19 @@
1
+ /** Package-owned invariant companion for `@deepseek-ai/dsh-plugin-package-inventory-deepseek`. */
2
+ const PACKAGE_NAME = '@deepseek-ai/dsh-plugin-package-inventory-deepseek';
3
+ /** Cordis companion plugin name. */
4
+ export const name = 'plugin-package-inventory-deepseek-invariant';
5
+ /** Service required before the companion can reserve package ownership. */
6
+ export const inject = ['invariants'];
7
+ /**
8
+ * No runtime invariant: each request reads authoritative Loader fiber state and
9
+ * package manifests directly; the plugin retains no independently mutable inventory.
10
+ */
11
+ const install = () => { };
12
+ /**
13
+ * Register this package's invariant companion.
14
+ * @param ctx - Cordis context carrying the invariant service.
15
+ * @returns the installed registration's disposer after setup succeeds.
16
+ */
17
+ export const apply = (ctx) => Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install));
18
+ /* jscpd:ignore-end */
19
+ //# sourceMappingURL=invariant.js.map
@@ -0,0 +1,17 @@
1
+ /** Wire types for the active DeepSeek plugin package inventory. */
2
+ /** One exact active plugin package version. */
3
+ export interface DeepSeekPluginPackageIdentity {
4
+ readonly name: string;
5
+ readonly version: string;
6
+ }
7
+ /** Versioned full package inventory carried by each official DeepSeek request. */
8
+ export interface DeepSeekPluginPackageInventoryExtension {
9
+ readonly version: 1;
10
+ readonly packages: readonly DeepSeekPluginPackageIdentity[];
11
+ }
12
+ declare module '@deepseek-ai/dsh-deepseek-llm-api-extensions/types' {
13
+ interface DeepSeekLlmApiExtensionMap {
14
+ dsh_plugin_packages: DeepSeekPluginPackageInventoryExtension;
15
+ }
16
+ }
17
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,3 @@
1
+ /** Wire types for the active DeepSeek plugin package inventory. */
2
+ export {};
3
+ //# sourceMappingURL=types.js.map
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "@deepseek-ai/dsh-plugin-package-inventory-deepseek",
3
+ "description": "Active Loader-backed plugin package inventory for official DeepSeek LLM API requests",
4
+ "version": "0.1.2-alpha.2",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/deepseek-ai/deepseek-harness.git",
11
+ "directory": "packages/llm/plugin-package-inventory-deepseek"
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
+ "./invariant": {
22
+ "types": "./lib/types/invariant.d.ts",
23
+ "default": "./lib/invariant.js"
24
+ },
25
+ "./types": {
26
+ "types": "./lib/types/types.d.ts",
27
+ "default": "./lib/types/types.js"
28
+ },
29
+ "./src/*": "./src/*",
30
+ "./package.json": "./package.json"
31
+ },
32
+ "files": [
33
+ "lib/index.js",
34
+ "lib/invariant.js",
35
+ "lib/types/**/*.js",
36
+ "lib/types/**/*.d.ts"
37
+ ],
38
+ "license": "MIT",
39
+ "dependencies": {
40
+ "@deepseek-ai/schemastery": "^3.18.2",
41
+ "@deepseek-ai/dsh-brand": "^0.1.2-alpha.2"
42
+ },
43
+ "peerDependencies": {
44
+ "@deepseek-ai/cordis": "^4.0.2",
45
+ "@deepseek-ai/cordis-plugin-loader": "^1.0.3",
46
+ "@deepseek-ai/dsh-agent": "^0.1.2-alpha.2",
47
+ "@deepseek-ai/dsh-agent-presets": "^0.1.2-alpha.2",
48
+ "@deepseek-ai/dsh-deepseek-llm-api-extensions": "^0.1.2-alpha.2",
49
+ "@deepseek-ai/dsh-invariants": "^0.1.2-alpha.2",
50
+ "@deepseek-ai/dsh-session": "^0.1.2-alpha.2"
51
+ },
52
+ "peerDependenciesMeta": {
53
+ "@deepseek-ai/dsh-agent-presets": {
54
+ "optional": true
55
+ }
56
+ },
57
+ "devDependencies": {
58
+ "@deepseek-ai/cordis": "^4.0.2",
59
+ "@deepseek-ai/cordis-plugin-include": "^1.0.7",
60
+ "@deepseek-ai/cordis-plugin-loader": "^1.0.3",
61
+ "@deepseek-ai/dsh-agent": "^0.1.2-alpha.2",
62
+ "@deepseek-ai/dsh-agent-presets": "^0.1.2-alpha.2",
63
+ "@deepseek-ai/dsh-deepseek-llm-api-extensions": "^0.1.2-alpha.2",
64
+ "@deepseek-ai/dsh-session": "^0.1.2-alpha.2",
65
+ "@deepseek-ai/dsh-session-projection": "^0.1.2-alpha.2",
66
+ "@deepseek-ai/dsh-invariants": "^0.1.2-alpha.2",
67
+ "@deepseek-ai/dsh-scope": "^0.1.2-alpha.2"
68
+ }
69
+ }