@zhin.js/prompt-section 1.1.7 → 1.1.9

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 CHANGED
@@ -7,3 +7,5 @@ immutable capability slot 进入当前 generation。
7
7
  Prompt Section 只贡献模型上下文,不授予 Tool、文件、网络、审批或 Workroom 权限。
8
8
  `PromptSectionIndex.visible(owner, profile)` 按 Plugin owner 继承链解析,并固定到当前
9
9
  generation;HMR 原子发布新 projection,在途 Turn 继续使用旧 snapshot。
10
+
11
+ 平台插件可声明 `platforms` 与 `scopes: ['private' | 'group' | 'channel']`;Agent 在每轮入站按可信平台和场景筛选。未声明不限制;声明的场景列表必须非空且无重复,不使用用户消息正文推断权限。
@@ -17,6 +17,8 @@ export interface AgentPromptSectionDefinition {
17
17
  readonly maxChars?: number;
18
18
  readonly profiles: readonly PromptProfile[];
19
19
  readonly platforms?: readonly string[];
20
+ /** IM conversation kinds where this section applies; omitted means unrestricted. */
21
+ readonly scopes?: readonly ('private' | 'group' | 'channel')[];
20
22
  readonly metadata?: Readonly<Record<string, unknown>>;
21
23
  }
22
24
  export type AgentPromptSectionInput = Omit<AgentPromptSectionDefinition, '$feature' | 'layer' | 'order' | 'retention' | 'profiles'> & Partial<Pick<AgentPromptSectionDefinition, 'layer' | 'order' | 'retention' | 'profiles'>>;
package/lib/definition.js CHANGED
@@ -36,6 +36,10 @@ export function defineAgentPromptSection(input) {
36
36
  throw new TypeError('Prompt Section profiles cannot contain duplicates');
37
37
  }
38
38
  const platforms = input.platforms?.map((platform) => platform.trim());
39
+ if (input.scopes !== undefined && (!Array.isArray(input.scopes) || input.scopes.length === 0
40
+ || input.scopes.some(scope => !SCOPES.has(scope)) || new Set(input.scopes).size !== input.scopes.length)) {
41
+ throw new TypeError('Prompt Section scopes must contain unique private, group or channel values');
42
+ }
39
43
  if (platforms && (platforms.length === 0
40
44
  || platforms.some((platform) => !platform)
41
45
  || new Set(platforms).size !== platforms.length)) {
@@ -55,6 +59,7 @@ export function defineAgentPromptSection(input) {
55
59
  retention,
56
60
  profiles: Object.freeze([...profiles]),
57
61
  ...(platforms ? { platforms: Object.freeze(platforms) } : {}),
62
+ ...(input.scopes ? { scopes: Object.freeze([...input.scopes]) } : {}),
58
63
  ...(input.metadata ? { metadata: Object.freeze({ ...input.metadata }) } : {}),
59
64
  });
60
65
  }
@@ -94,6 +99,7 @@ export function parseAgentPromptSectionDefinition(value) {
94
99
  maxChars: definition.maxChars,
95
100
  profiles: definition.profiles,
96
101
  platforms: definition.platforms,
102
+ scopes: definition.scopes,
97
103
  metadata: definition.metadata,
98
104
  });
99
105
  }
@@ -102,6 +108,7 @@ const LAYERS = new Set([
102
108
  ]);
103
109
  const RETENTIONS = new Set(['required', 'preferred', 'opportunistic']);
104
110
  const PROFILES = new Set(['interactive', 'schedule']);
111
+ const SCOPES = new Set(['private', 'group', 'channel']);
105
112
  function invalidPromptSection() {
106
113
  return new TypeError('Prompt Section module must default-export defineAgentPromptSection(...)');
107
114
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhin.js/prompt-section",
3
- "version": "1.1.7",
3
+ "version": "1.1.9",
4
4
  "description": "Generation-owned Agent Prompt Section Feature for Zhin Plugin Runtime",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -16,8 +16,8 @@
16
16
  "src"
17
17
  ],
18
18
  "dependencies": {
19
- "@zhin.js/feature-kit": "1.1.7",
20
- "@zhin.js/plugin-runtime": "1.1.15"
19
+ "@zhin.js/plugin-runtime": "1.1.17",
20
+ "@zhin.js/feature-kit": "1.1.9"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@types/node": "^26.1.2",
package/src/definition.ts CHANGED
@@ -29,6 +29,8 @@ export interface AgentPromptSectionDefinition {
29
29
  readonly maxChars?: number;
30
30
  readonly profiles: readonly PromptProfile[];
31
31
  readonly platforms?: readonly string[];
32
+ /** IM conversation kinds where this section applies; omitted means unrestricted. */
33
+ readonly scopes?: readonly ('private' | 'group' | 'channel')[];
32
34
  readonly metadata?: Readonly<Record<string, unknown>>;
33
35
  }
34
36
 
@@ -79,6 +81,10 @@ export function defineAgentPromptSection(
79
81
  throw new TypeError('Prompt Section profiles cannot contain duplicates');
80
82
  }
81
83
  const platforms = input.platforms?.map((platform) => platform.trim());
84
+ if (input.scopes !== undefined && (!Array.isArray(input.scopes) || input.scopes.length === 0
85
+ || input.scopes.some(scope => !SCOPES.has(scope)) || new Set(input.scopes).size !== input.scopes.length)) {
86
+ throw new TypeError('Prompt Section scopes must contain unique private, group or channel values');
87
+ }
82
88
  if (platforms && (platforms.length === 0
83
89
  || platforms.some((platform) => !platform)
84
90
  || new Set(platforms).size !== platforms.length)) {
@@ -98,6 +104,7 @@ export function defineAgentPromptSection(
98
104
  retention,
99
105
  profiles: Object.freeze([...profiles]),
100
106
  ...(platforms ? { platforms: Object.freeze(platforms) } : {}),
107
+ ...(input.scopes ? { scopes: Object.freeze([...input.scopes]) } : {}),
101
108
  ...(input.metadata ? { metadata: Object.freeze({ ...input.metadata }) } : {}),
102
109
  });
103
110
  }
@@ -138,6 +145,7 @@ export function parseAgentPromptSectionDefinition(value: unknown): AgentPromptSe
138
145
  maxChars: definition.maxChars,
139
146
  profiles: definition.profiles,
140
147
  platforms: definition.platforms,
148
+ scopes: definition.scopes,
141
149
  metadata: definition.metadata,
142
150
  });
143
151
  }
@@ -147,6 +155,7 @@ const LAYERS = new Set<PromptSectionLayer>([
147
155
  ]);
148
156
  const RETENTIONS = new Set<PromptSectionRetention>(['required', 'preferred', 'opportunistic']);
149
157
  const PROFILES = new Set<PromptProfile>(['interactive', 'schedule']);
158
+ const SCOPES = new Set(['private', 'group', 'channel']);
150
159
 
151
160
  function invalidPromptSection(): TypeError {
152
161
  return new TypeError('Prompt Section module must default-export defineAgentPromptSection(...)');