feat: optimize prompt
This commit is contained in:
@@ -172,9 +172,22 @@ function readExact(input: JsonValue | undefined, field: string): string | undefi
|
||||
type LiveSlotNode = ReturnType<SlotRegistry['snapshot']>[number]
|
||||
|
||||
const SLOT_CATALOG = new Map(CLIENT_SLOT_API.map(entry => [entry.key, entry]))
|
||||
const GUARDED_SLOT_KEYS = new Map<string, {
|
||||
description: string
|
||||
values: readonly { value: string; description: string }[]
|
||||
}>([
|
||||
['tool.view.cordis', {
|
||||
description: 'fixed by the dynamic Client Guard',
|
||||
values: [{
|
||||
value: 'self',
|
||||
description: 'The only accepted key. The Guard binds it to this Package\'s pluginId and packageId.',
|
||||
}],
|
||||
}],
|
||||
])
|
||||
|
||||
function compactSlotTree(node: LiveSlotNode): JsonValue {
|
||||
const catalog = SLOT_CATALOG.get(node.name)
|
||||
const guardedKeys = catalog === undefined ? undefined : GUARDED_SLOT_KEYS.get(catalog.key)
|
||||
return {
|
||||
name: node.name,
|
||||
kind: node.kind,
|
||||
@@ -189,7 +202,10 @@ function compactSlotTree(node: LiveSlotNode): JsonValue {
|
||||
required: option.requirement === 'required',
|
||||
})),
|
||||
},
|
||||
...catalog.keyDomain === '' ? {} : { keyDomain: catalog.keyDomain },
|
||||
...catalog.keyDomain === '' ? {} : {
|
||||
keyDomain: guardedKeys?.description ?? catalog.keyDomain,
|
||||
...guardedKeys === undefined ? {} : { allowedKeys: guardedKeys.values.map(value => ({ ...value })) },
|
||||
},
|
||||
},
|
||||
children: node.children.map(compactSlotTree),
|
||||
}
|
||||
@@ -208,6 +224,7 @@ function inspectLiveSlot(node: LiveSlotNode): JsonValue {
|
||||
}
|
||||
|
||||
function inspectSlotCatalog(entry: ClientSlotEntry): JsonValue {
|
||||
const guardedKeys = GUARDED_SLOT_KEYS.get(entry.key)
|
||||
return {
|
||||
description: entry.doc,
|
||||
registration: entry.registerOptions.map(option => ({
|
||||
@@ -219,7 +236,8 @@ function inspectSlotCatalog(entry: ClientSlotEntry): JsonValue {
|
||||
ownerProps: [...entry.ownerProps],
|
||||
ownerPropsReferences: [...entry.ownerPropsReferences],
|
||||
standardProps: [...entry.standardProps],
|
||||
keyDomain: entry.keyDomain,
|
||||
keyDomain: guardedKeys?.description ?? entry.keyDomain,
|
||||
...guardedKeys === undefined ? {} : { allowedKeys: guardedKeys.values.map(value => ({ ...value })) },
|
||||
hookContext: entry.hookContext,
|
||||
slotInject: entry.slotInject,
|
||||
replaceRisk: entry.replaceRisk,
|
||||
|
||||
@@ -1680,8 +1680,8 @@ export const CLIENT_SLOT_API: readonly ClientSlotEntry[] = [
|
||||
key: 'tool.view.cordis',
|
||||
kind: 'keyed',
|
||||
scope: 'session',
|
||||
summary: 'Package-owned interactive UI hosted by the latest successful Run card.',
|
||||
doc: 'Package-owned interactive UI hosted by the latest successful Run card.',
|
||||
summary: 'Interactive Package-owned region rendered inside the latest eligible `cordis_run` card in the conversation flow.',
|
||||
doc: 'Interactive Package-owned region rendered inside the latest eligible\n`cordis_run` card in the conversation flow. Use it for controls and other\nUI the user can interact with. Dynamic Client code registers with\n`key: \'self\'`; the Guard binds that key to the current Plugin and Package.',
|
||||
registerOptions: [
|
||||
{
|
||||
name: 'key',
|
||||
@@ -1714,7 +1714,7 @@ export const CLIENT_SLOT_API: readonly ClientSlotEntry[] = [
|
||||
occupants: [],
|
||||
replaceRisk: 'none',
|
||||
example: 'return {\n inject: [\'slots\'],\n apply(ctx) {\n ctx.slots.inject(\'tool.view.cordis\', () => ctx.slots.register(\n { name: \'tool.view.cordis\', key: \'<one key the owner dispatches>\' },\n () => React.createElement(\'div\', null, \'hello\'),\n ))\n },\n}',
|
||||
source: 'packages/extensions/ui-cordis/src/client/slots.ts:26',
|
||||
source: 'packages/extensions/ui-cordis/src/client/slots.ts:31',
|
||||
},
|
||||
]
|
||||
/* jscpd:ignore-end */
|
||||
|
||||
Reference in New Issue
Block a user