@deepseek-ai/dsh-cordis-client-runner 0.2.2-rc.1 → 0.2.2-rc.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/lib/client.js +2411 -7959
- package/lib/client.js.map +1 -0
- package/lib/types/client/api-catalog.d.ts.map +1 -0
- package/lib/types/client/api-catalog.js.map +1 -0
- package/lib/types/client/evaluator.d.ts.map +1 -0
- package/lib/types/client/evaluator.js.map +1 -0
- package/lib/types/client/guard.d.ts.map +1 -0
- package/lib/types/client/guard.js.map +1 -0
- package/lib/types/client/index.d.ts.map +1 -0
- package/lib/types/client/index.js.map +1 -0
- package/lib/types/client/inspect-registry.d.ts.map +1 -0
- package/lib/types/client/inspect-registry.js.map +1 -0
- package/lib/types/client/orchestrator.d.ts.map +1 -0
- package/lib/types/client/orchestrator.js.map +1 -0
- package/lib/types/client/providers.d.ts.map +1 -0
- package/lib/types/client/providers.js.map +1 -0
- package/lib/types/client/runtime.d.ts.map +1 -0
- package/lib/types/client/runtime.js.map +1 -0
- package/lib/types/client/slot-catalog.d.ts +6 -2
- package/lib/types/client/slot-catalog.d.ts.map +1 -0
- package/lib/types/client/slot-catalog.js.map +1 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js.map +1 -0
- package/package.json +10 -7
- package/src/client/api-catalog.ts +1208 -0
- package/src/client/evaluator.ts +222 -0
- package/src/client/guard.ts +245 -0
- package/src/client/index.ts +308 -0
- package/src/client/inspect-registry.ts +150 -0
- package/src/client/orchestrator.ts +458 -0
- package/src/client/providers.ts +263 -0
- package/src/client/runtime.ts +512 -0
- package/src/client/slot-catalog.ts +5782 -0
- package/src/index.ts +9 -0
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
/** Built-in Client inspect providers over live Client-owned services. */
|
|
2
|
+
|
|
3
|
+
import type { Context } from '@deepseek-ai/cordis'
|
|
4
|
+
import type { JsonValue } from '@deepseek-ai/dsh-util-values'
|
|
5
|
+
import type { SlotRegistry } from '@deepseek-ai/dsh-client-ui-renderer/client'
|
|
6
|
+
import type {} from '@deepseek-ai/dsh-client-ui-theme/client'
|
|
7
|
+
import { queryEventApi, queryServiceApi } from './api-catalog.ts'
|
|
8
|
+
import type { ClientCordisInspectProviderRegistration } from './inspect-registry.ts'
|
|
9
|
+
import { CLIENT_SLOT_API } from './slot-catalog.ts'
|
|
10
|
+
import type { ClientSlotEntry } from './slot-catalog.ts'
|
|
11
|
+
|
|
12
|
+
/* jscpd:ignore-start */
|
|
13
|
+
const EMPTY_INPUT = { type: 'object', properties: {}, additionalProperties: false } as const
|
|
14
|
+
const ANY_OUTPUT = { description: 'JSON data owned by this inspect provider.' } as const
|
|
15
|
+
const SERVICE_INPUT = exactInput('service', 'Exact Service key. Omit it for the compact Service and method-signature directory.')
|
|
16
|
+
const EVENT_INPUT = exactInput('event', 'Exact Event name. Omit it for the compact Event and listener-signature directory.')
|
|
17
|
+
const SERVICE_OUTPUT = {
|
|
18
|
+
description: 'Compact Service directory, or one exact Service contract with only its referenced type declarations.',
|
|
19
|
+
} as const
|
|
20
|
+
const EVENT_OUTPUT = {
|
|
21
|
+
description: 'Compact Event directory, or one exact Event contract with only its referenced type declarations.',
|
|
22
|
+
} as const
|
|
23
|
+
/* jscpd:ignore-end */
|
|
24
|
+
const SUBTREE_OUTPUT = {
|
|
25
|
+
description: 'Compact topology trees. An exact Slot includes its catalog and occupants; an exact Factory includes identity, scope, and registrant.',
|
|
26
|
+
} as const
|
|
27
|
+
const SUBTREE_INPUT = {
|
|
28
|
+
type: 'object',
|
|
29
|
+
properties: {
|
|
30
|
+
root: {
|
|
31
|
+
type: 'string',
|
|
32
|
+
description: 'Exact live Slot key or factory:<name>. When supplied, selected contains that declaration.',
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
additionalProperties: false,
|
|
36
|
+
} as const
|
|
37
|
+
|
|
38
|
+
/** Exact Client closure symbols exposed by the evaluator and guard. */
|
|
39
|
+
export const CLIENT_BUILTIN_INSPECTION: readonly JsonValue[] = [
|
|
40
|
+
{
|
|
41
|
+
name: 'ctx',
|
|
42
|
+
description: 'Restricted Cordis Context. Prefer ctx.get(name) with an undefined check; use inject only for hard dependencies.',
|
|
43
|
+
signatures: [
|
|
44
|
+
'ctx.get(name: string): unknown | undefined',
|
|
45
|
+
'ctx.on(name: string, listener: Function): () => void',
|
|
46
|
+
'ctx.provide(name: string, value: unknown): () => void',
|
|
47
|
+
'ctx.effect(callback: Function, label?: string): () => void',
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: 'React',
|
|
52
|
+
description: 'React runtime exposed without JSX transformation.',
|
|
53
|
+
signatures: ['React.createElement(type, props, ...children): ReactElement', 'React.useState(initial)', 'React.useEffect(effect, deps)'],
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
name: 'host',
|
|
57
|
+
description: 'Package-private JSON RPC from Client to this Package\'s Host half.',
|
|
58
|
+
signatures: ['host.call(method: string, args?: JsonValue): Promise<JsonValue>'],
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: 'styles',
|
|
62
|
+
description: 'Package-owned stylesheet insertion cleaned up with the Client run.',
|
|
63
|
+
signatures: ['styles.insert(css: string): () => void'],
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
name: 'console',
|
|
67
|
+
description: 'Package-tagged browser logging.',
|
|
68
|
+
signatures: ['console.log(...values): void', 'console.error(...values): void'],
|
|
69
|
+
},
|
|
70
|
+
]
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Construct the first-party Client provider registrations.
|
|
74
|
+
* @param ctx - Client context used for live Service-backed queries.
|
|
75
|
+
* @returns registrations for static catalogs and live Client capabilities.
|
|
76
|
+
*/
|
|
77
|
+
export function clientInspectProviders(ctx: Context): ClientCordisInspectProviderRegistration[] {
|
|
78
|
+
return [
|
|
79
|
+
registration(
|
|
80
|
+
'Service',
|
|
81
|
+
'Progressive Client Service discovery: compact capability/signature directory, then one exact coding contract.',
|
|
82
|
+
'listService',
|
|
83
|
+
input => queryServiceApi(readExact(input, 'service')) as unknown as JsonValue,
|
|
84
|
+
SERVICE_INPUT,
|
|
85
|
+
SERVICE_OUTPUT,
|
|
86
|
+
),
|
|
87
|
+
registration(
|
|
88
|
+
'Event',
|
|
89
|
+
'Progressive Client Event discovery: compact listener directory, then one exact event contract.',
|
|
90
|
+
'listEvents',
|
|
91
|
+
input => queryEventApi(readExact(input, 'event')) as unknown as JsonValue,
|
|
92
|
+
EVENT_INPUT,
|
|
93
|
+
EVENT_OUTPUT,
|
|
94
|
+
),
|
|
95
|
+
registration('Builtin', 'Plain-JavaScript symbols available to a dynamic Client half.', 'listBuiltins', () => ({
|
|
96
|
+
builtins: [...CLIENT_BUILTIN_INSPECTION],
|
|
97
|
+
referencedTypes: [],
|
|
98
|
+
})),
|
|
99
|
+
{
|
|
100
|
+
manifest: {
|
|
101
|
+
id: 'Slots',
|
|
102
|
+
description: 'Progressive live Slot inspection with explicit Slot and Factory topology nodes.',
|
|
103
|
+
methods: [{
|
|
104
|
+
name: 'listSubTree',
|
|
105
|
+
description: 'Return compact live Slot and Factory trees, plus available detail for one exact root.',
|
|
106
|
+
inputSchema: SUBTREE_INPUT,
|
|
107
|
+
outputSchema: SUBTREE_OUTPUT,
|
|
108
|
+
}],
|
|
109
|
+
},
|
|
110
|
+
query(method, input) {
|
|
111
|
+
if (method !== 'listSubTree') throw new Error(`unknown Slots inspect method "${method}"`)
|
|
112
|
+
const slots = ctx.get('slots')
|
|
113
|
+
if (slots === undefined) throw new Error('Client Slots service is not running')
|
|
114
|
+
const root = typeof input === 'object' && input !== null && !Array.isArray(input)
|
|
115
|
+
&& typeof input.root === 'string' ? input.root : undefined
|
|
116
|
+
const trees = slots.snapshot(root)
|
|
117
|
+
const selected = trees[0]
|
|
118
|
+
return Promise.resolve({
|
|
119
|
+
...root === undefined ? {} : { requestedRoot: { name: root, available: trees.length > 0 } },
|
|
120
|
+
trees: trees.map(compactSlotTree),
|
|
121
|
+
...root === undefined || selected === undefined ? {} : { selected: inspectLiveSlot(selected) },
|
|
122
|
+
referencedTypes: [],
|
|
123
|
+
})
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
registration('Theme', 'Current theme token names and light/dark override requirements.', 'listTokens', () => {
|
|
127
|
+
const theme = ctx.get('theme')
|
|
128
|
+
if (theme === undefined) throw new Error('Client Theme service is not running')
|
|
129
|
+
return { tokens: theme.exportInspectTokens(), referencedTypes: [] } as unknown as JsonValue
|
|
130
|
+
}),
|
|
131
|
+
]
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/* jscpd:ignore-start */
|
|
135
|
+
function registration(
|
|
136
|
+
id: string,
|
|
137
|
+
description: string,
|
|
138
|
+
method: string,
|
|
139
|
+
query: (input: JsonValue | undefined) => JsonValue | Promise<JsonValue>,
|
|
140
|
+
inputSchema: JsonValue = EMPTY_INPUT,
|
|
141
|
+
outputSchema: JsonValue = ANY_OUTPUT,
|
|
142
|
+
): ClientCordisInspectProviderRegistration {
|
|
143
|
+
return {
|
|
144
|
+
manifest: {
|
|
145
|
+
id,
|
|
146
|
+
description,
|
|
147
|
+
methods: [{
|
|
148
|
+
name: method,
|
|
149
|
+
description,
|
|
150
|
+
inputSchema,
|
|
151
|
+
outputSchema,
|
|
152
|
+
}],
|
|
153
|
+
},
|
|
154
|
+
async query(requested, input) {
|
|
155
|
+
if (requested !== method) throw new Error(`unknown ${id} inspect method "${requested}"`)
|
|
156
|
+
return await query(input)
|
|
157
|
+
},
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function exactInput(field: string, description: string): JsonValue {
|
|
162
|
+
return { type: 'object', properties: { [field]: { type: 'string', description } }, additionalProperties: false }
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function readExact(input: JsonValue | undefined, field: string): string | undefined {
|
|
166
|
+
if (input === undefined || input === null || Array.isArray(input) || typeof input !== 'object') return undefined
|
|
167
|
+
const value = input[field]
|
|
168
|
+
return typeof value === 'string' ? value : undefined
|
|
169
|
+
}
|
|
170
|
+
/* jscpd:ignore-end */
|
|
171
|
+
|
|
172
|
+
type LiveCompositionNode = ReturnType<SlotRegistry['snapshot']>[number]
|
|
173
|
+
|
|
174
|
+
const SLOT_CATALOG = new Map(CLIENT_SLOT_API.map(entry => [entry.key, entry]))
|
|
175
|
+
const GUARDED_SLOT_KEYS = new Map<string, {
|
|
176
|
+
description: string
|
|
177
|
+
values: readonly { value: string; description: string }[]
|
|
178
|
+
}>([
|
|
179
|
+
['tool.view.cordis', {
|
|
180
|
+
description: 'fixed by the dynamic Client Guard',
|
|
181
|
+
values: [{
|
|
182
|
+
value: 'self',
|
|
183
|
+
description: 'The only accepted key. The Guard binds it to this Package\'s pluginId and packageId.',
|
|
184
|
+
}],
|
|
185
|
+
}],
|
|
186
|
+
])
|
|
187
|
+
|
|
188
|
+
function compactSlotTree(node: LiveCompositionNode): JsonValue {
|
|
189
|
+
if (node.type === 'factory') {
|
|
190
|
+
return {
|
|
191
|
+
type: node.type,
|
|
192
|
+
name: node.name,
|
|
193
|
+
scope: node.scope,
|
|
194
|
+
children: node.children.map(compactSlotTree),
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
const catalog = SLOT_CATALOG.get(node.name)
|
|
198
|
+
const guardedKeys = catalog === undefined ? undefined : GUARDED_SLOT_KEYS.get(catalog.key)
|
|
199
|
+
return {
|
|
200
|
+
type: node.type,
|
|
201
|
+
name: node.name,
|
|
202
|
+
kind: node.kind,
|
|
203
|
+
scope: node.scope,
|
|
204
|
+
...catalog === undefined ? {} : {
|
|
205
|
+
purpose: catalog.summary,
|
|
206
|
+
replaceRisk: catalog.replaceRisk,
|
|
207
|
+
...catalog.registerOptions.length === 0 ? {} : {
|
|
208
|
+
registration: catalog.registerOptions.map(option => ({
|
|
209
|
+
name: option.name,
|
|
210
|
+
type: option.type,
|
|
211
|
+
required: option.requirement === 'required',
|
|
212
|
+
})),
|
|
213
|
+
},
|
|
214
|
+
...catalog.keyDomain === '' ? {} : {
|
|
215
|
+
keyDomain: guardedKeys?.description ?? catalog.keyDomain,
|
|
216
|
+
...guardedKeys === undefined ? {} : { allowedKeys: guardedKeys.values.map(value => ({ ...value })) },
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
children: node.children.map(compactSlotTree),
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function inspectLiveSlot(node: LiveCompositionNode): JsonValue {
|
|
224
|
+
if (node.type === 'factory') {
|
|
225
|
+
return {
|
|
226
|
+
type: node.type,
|
|
227
|
+
name: node.name,
|
|
228
|
+
scope: node.scope,
|
|
229
|
+
...node.registrant === undefined ? {} : { registrant: node.registrant },
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
const catalog = SLOT_CATALOG.get(node.name)
|
|
233
|
+
return {
|
|
234
|
+
type: node.type,
|
|
235
|
+
name: node.name,
|
|
236
|
+
kind: node.kind,
|
|
237
|
+
scope: node.scope,
|
|
238
|
+
...node.declaredBy === undefined ? {} : { declaredBy: node.declaredBy },
|
|
239
|
+
occupants: node.occupants.map(occupant => ({ ...occupant })),
|
|
240
|
+
...catalog === undefined ? {} : { catalog: inspectSlotCatalog(catalog) },
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function inspectSlotCatalog(entry: ClientSlotEntry): JsonValue {
|
|
245
|
+
const guardedKeys = GUARDED_SLOT_KEYS.get(entry.key)
|
|
246
|
+
return {
|
|
247
|
+
description: entry.doc,
|
|
248
|
+
registration: entry.registerOptions.map(option => ({
|
|
249
|
+
name: option.name,
|
|
250
|
+
type: option.type,
|
|
251
|
+
required: option.requirement === 'required',
|
|
252
|
+
description: option.doc,
|
|
253
|
+
})),
|
|
254
|
+
ownerProps: [...entry.ownerProps],
|
|
255
|
+
ownerPropsReferences: [...entry.ownerPropsReferences],
|
|
256
|
+
standardProps: [...entry.standardProps],
|
|
257
|
+
keyDomain: guardedKeys?.description ?? entry.keyDomain,
|
|
258
|
+
...guardedKeys === undefined ? {} : { allowedKeys: guardedKeys.values.map(value => ({ ...value })) },
|
|
259
|
+
hookContext: entry.hookContext,
|
|
260
|
+
slotInject: entry.slotInject,
|
|
261
|
+
replaceRisk: entry.replaceRisk,
|
|
262
|
+
}
|
|
263
|
+
}
|