feat(platform): complete the Gelios external data loop
This commit is contained in:
@@ -393,6 +393,20 @@ function safeEntity(value) {
|
||||
status: stringList(value?.status),
|
||||
authority: cleanString(value?.authority, 240),
|
||||
summary: cleanString(value?.summary, 2000),
|
||||
...(value?.valueContract ? { valueContract: safeValueContract(value.valueContract) } : {}),
|
||||
}
|
||||
}
|
||||
|
||||
function safeValueContract(value) {
|
||||
return {
|
||||
field: cleanString(value?.field, 120),
|
||||
values: (Array.isArray(value?.values) ? value.values : []).map((item) => ({
|
||||
value: cleanString(item?.value, 120),
|
||||
label: cleanString(item?.label, 240),
|
||||
sourceLabel: cleanString(item?.sourceLabel, 240),
|
||||
})),
|
||||
sourcePaths: stringList(value?.sourcePaths),
|
||||
rules: stringList(value?.rules),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,10 +37,10 @@ try {
|
||||
|
||||
const search = await rpc(baseUrl, TOKEN, 3, 'tools/call', {
|
||||
name: 'ontology_search',
|
||||
arguments: { query: 'трайк', limit: 10 },
|
||||
arguments: { query: 'юнит гелиос', limit: 10 },
|
||||
})
|
||||
assert.equal(search.result.isError, undefined)
|
||||
assert.equal(search.result.structuredContent.query, 'трайк')
|
||||
assert.equal(search.result.structuredContent.query, 'юнит гелиос')
|
||||
assert.equal(search.result.structuredContent.results.some((item) => item.entity?.id === 'gelios.unit'), true)
|
||||
|
||||
const entity = await rpc(baseUrl, TOKEN, 4, 'tools/call', {
|
||||
@@ -50,6 +50,16 @@ try {
|
||||
assert.equal(entity.result.structuredContent.entity.id, 'gelios.integration')
|
||||
assert.equal(JSON.stringify(entity.result.structuredContent).includes('/Users/'), false)
|
||||
|
||||
const signalState = await rpc(baseUrl, TOKEN, 41, 'tools/call', {
|
||||
name: 'ontology_get_entity',
|
||||
arguments: { entityId: 'gelios.signal_state' },
|
||||
})
|
||||
assert.equal(signalState.result.structuredContent.entity.valueContract.field, 'signal_state')
|
||||
assert.deepEqual(
|
||||
signalState.result.structuredContent.entity.valueContract.values.map((item) => item.value),
|
||||
['active', 'inactive'],
|
||||
)
|
||||
|
||||
const guardrails = await rpc(baseUrl, TOKEN, 5, 'tools/call', {
|
||||
name: 'ontology_get_guardrails',
|
||||
arguments: { entityId: 'gelios.command_dispatch' },
|
||||
@@ -70,6 +80,7 @@ try {
|
||||
'mcp_initialize',
|
||||
'read_only_tool_catalog',
|
||||
'gelios_alias_resolution',
|
||||
'gelios_value_contract_visible',
|
||||
'gelios_command_guardrail_visible',
|
||||
'evidence_paths_not_exposed',
|
||||
'internal_bearer_required',
|
||||
|
||||
@@ -5,6 +5,7 @@ import { loadCatalog, serviceRoot } from './catalog.mjs'
|
||||
const ID_RE = /^[a-z][a-z0-9]*(?:\.[a-z][a-z0-9_]*)+$/
|
||||
const RULE_ID_RE = /^[a-z][a-z0-9_]*(?:\.[a-z][a-z0-9_]*)+$/
|
||||
const ROLE_ID_RE = /^[a-z][a-z0-9_]*$/
|
||||
const FIELD_ID_RE = /^[a-z][a-z0-9_]*$/
|
||||
const ALLOWED_RELATION_STATUSES = new Set([
|
||||
'source-confirmed',
|
||||
'source-evidenced',
|
||||
@@ -92,6 +93,7 @@ export async function validateCatalog() {
|
||||
for (const status of entity.status || []) {
|
||||
assert(statusVocabulary.has(status), `entity ${entity.id} uses unknown status: ${status}`, errors)
|
||||
}
|
||||
validateValueContract(entity.valueContract, entity.id, errors)
|
||||
}
|
||||
|
||||
assertUnique(relations.relations.map((relation) => relation.id), 'relation', errors)
|
||||
@@ -354,6 +356,32 @@ export async function validateCatalog() {
|
||||
}
|
||||
}
|
||||
|
||||
function validateValueContract(valueContract, entityId, errors) {
|
||||
if (valueContract === undefined) return
|
||||
const label = `entity ${entityId}.valueContract`
|
||||
assert(valueContract && typeof valueContract === 'object' && !Array.isArray(valueContract), `${label} must be object`, errors)
|
||||
if (!valueContract || typeof valueContract !== 'object' || Array.isArray(valueContract)) return
|
||||
assert(FIELD_ID_RE.test(valueContract.field || ''), `${label}.field invalid`, errors)
|
||||
assert(Array.isArray(valueContract.values) && valueContract.values.length > 0, `${label}.values must be non-empty array`, errors)
|
||||
const values = []
|
||||
for (const [index, item] of (valueContract.values || []).entries()) {
|
||||
const itemLabel = `${label}.values[${index}]`
|
||||
assert(item && typeof item === 'object' && !Array.isArray(item), `${itemLabel} must be object`, errors)
|
||||
if (!item || typeof item !== 'object' || Array.isArray(item)) continue
|
||||
assert(FIELD_ID_RE.test(item.value || ''), `${itemLabel}.value invalid`, errors)
|
||||
assert(typeof item.label === 'string' && item.label.trim(), `${itemLabel}.label required`, errors)
|
||||
assert(typeof item.sourceLabel === 'string' && item.sourceLabel.trim(), `${itemLabel}.sourceLabel required`, errors)
|
||||
values.push(item.value)
|
||||
}
|
||||
assert(new Set(values).size === values.length, `${label}.values duplicate value`, errors)
|
||||
for (const key of ['sourcePaths', 'rules']) {
|
||||
assert(Array.isArray(valueContract[key]) && valueContract[key].length > 0, `${label}.${key} must be non-empty array`, errors)
|
||||
for (const item of valueContract[key] || []) {
|
||||
assert(typeof item === 'string' && item.trim(), `${label}.${key} contains empty item`, errors)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (import.meta.url === `file://${process.argv[1]}`) {
|
||||
const result = await validateCatalog()
|
||||
if (!result.ok) {
|
||||
|
||||
Reference in New Issue
Block a user