@elevasis/core 0.45.0 → 0.47.0
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/dist/auth/index.d.ts +132 -0
- package/dist/knowledge/index.d.ts +14 -10
- package/dist/knowledge/index.js +23 -1
- package/dist/test-utils/index.d.ts +132 -0
- package/package.json +2 -1
- package/src/__tests__/observability-exports.test.ts +27 -22
- package/src/__tests__/published-artifact.test.ts +99 -0
- package/src/execution/engine/llm/__tests__/model-info.test.ts +82 -9
- package/src/execution/engine/llm/__tests__/model-validation.test.ts +82 -17
- package/src/execution/engine/llm/adapters/__tests__/anthropic-adapter.test.ts +108 -87
- package/src/execution/engine/llm/adapters/server/anthropic.ts +38 -24
- package/src/execution/engine/llm/model-info.ts +113 -43
- package/src/knowledge/__tests__/queries.test.ts +174 -0
- package/src/knowledge/format.ts +39 -0
- package/src/knowledge/index.ts +7 -2
- package/src/knowledge/queries.ts +269 -13
- package/src/operations/index.ts +18 -13
- package/src/operations/public-agent-chat/api-schemas.ts +40 -0
- package/src/operations/public-agent-chat/index.ts +12 -0
- package/src/operations/sessions/api-schemas.ts +31 -11
- package/src/operations/sessions/index.ts +14 -12
- package/src/platform/constants/versions.ts +1 -1
- package/src/supabase/database.types.ts +132 -0
package/src/knowledge/queries.ts
CHANGED
|
@@ -4,6 +4,30 @@ import { OntologyIdSchema, ontologyGraphNodeId } from '../organization-model/ont
|
|
|
4
4
|
import type { OrganizationModel } from '../organization-model/types'
|
|
5
5
|
import { listAllSystems } from '../organization-model/helpers'
|
|
6
6
|
|
|
7
|
+
// ---------------------------------------------------------------------------
|
|
8
|
+
// Domain-item constants
|
|
9
|
+
// ---------------------------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The six graph-projected domain-item kinds supported by `omDescribe`.
|
|
13
|
+
* Each maps to a collection on `OrganizationModel` and a graph node kind.
|
|
14
|
+
*/
|
|
15
|
+
export const DOMAIN_ITEM_KINDS = ['clients', 'roles', 'policies', 'customers', 'offerings', 'goals'] as const
|
|
16
|
+
export type DomainItemKind = (typeof DOMAIN_ITEM_KINDS)[number]
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Bare-id prefix to domain map used for back-compat resolution.
|
|
20
|
+
* e.g. `client:<uuid>` → `clients`
|
|
21
|
+
*/
|
|
22
|
+
const BARE_PREFIX_TO_DOMAIN: Record<string, DomainItemKind> = {
|
|
23
|
+
client: 'clients',
|
|
24
|
+
role: 'roles',
|
|
25
|
+
policy: 'policies',
|
|
26
|
+
customer: 'customers',
|
|
27
|
+
offering: 'offerings',
|
|
28
|
+
goal: 'goals'
|
|
29
|
+
}
|
|
30
|
+
|
|
7
31
|
// ---------------------------------------------------------------------------
|
|
8
32
|
// Internal helpers
|
|
9
33
|
// ---------------------------------------------------------------------------
|
|
@@ -265,6 +289,8 @@ export type KnowledgeMount =
|
|
|
265
289
|
| 'all-systems'
|
|
266
290
|
| 'all-resources'
|
|
267
291
|
| 'all-roles'
|
|
292
|
+
| 'by-domain'
|
|
293
|
+
| 'by-item'
|
|
268
294
|
|
|
269
295
|
/**
|
|
270
296
|
* The result of parsing a Knowledge Map path string.
|
|
@@ -272,15 +298,17 @@ export type KnowledgeMount =
|
|
|
272
298
|
* Shape: `{ mount: KnowledgeMount, args: string[] }`
|
|
273
299
|
*
|
|
274
300
|
* Per-mount arg arrays:
|
|
275
|
-
* - `by-system`: `[systemId]`
|
|
276
|
-
* - `by-ontology`: `[ontologyId]`
|
|
277
|
-
* - `by-kind`: `[kind]`
|
|
278
|
-
* - `by-owner`: `[ownerId]`
|
|
279
|
-
* - `graph`: `[nodeId, verb]`
|
|
280
|
-
* - `node`: `[nodeId]`
|
|
281
|
-
* - `all-systems`: `[]`
|
|
282
|
-
* - `all-resources`:`[]`
|
|
283
|
-
* - `all-roles`: `[]`
|
|
301
|
+
* - `by-system`: `[systemId]` (e.g. `['sales.crm']`)
|
|
302
|
+
* - `by-ontology`: `[ontologyId]` (e.g. `['sales.crm:object/deal']`)
|
|
303
|
+
* - `by-kind`: `[kind]` (e.g. `['playbook']`)
|
|
304
|
+
* - `by-owner`: `[ownerId]` (e.g. `['role.ops-lead']`)
|
|
305
|
+
* - `graph`: `[nodeId, verb]` where verb is `'governs'` or `'governed-by'`
|
|
306
|
+
* - `node`: `[nodeId]` (single node lookup, no sub-path)
|
|
307
|
+
* - `all-systems`: `[]` (no args — returns all systems flattened)
|
|
308
|
+
* - `all-resources`:`[]` (no args — returns all resources)
|
|
309
|
+
* - `all-roles`: `[]` (no args — returns all roles)
|
|
310
|
+
* - `by-domain`: `[domain]` (e.g. `['clients']`) — enumerate all items in domain
|
|
311
|
+
* - `by-item`: `[domain, itemId]` (e.g. `['clients', '<uuid>']`) — single domain-item
|
|
284
312
|
*/
|
|
285
313
|
export interface ParsedKnowledgePath {
|
|
286
314
|
mount: KnowledgeMount
|
|
@@ -301,6 +329,8 @@ export interface ParsedKnowledgePath {
|
|
|
301
329
|
* `/all-systems` -> `{ mount: ‘all-systems’, args: [] }`
|
|
302
330
|
* `/all-resources` -> `{ mount: ‘all-resources’,args: [] }`
|
|
303
331
|
* `/all-roles` -> `{ mount: ‘all-roles’, args: [] }`
|
|
332
|
+
* `/by-domain/<domain>` -> `{ mount: ‘by-domain’, args: [‘<domain>’] }`
|
|
333
|
+
* `/by-item/<domain>/<itemId>` -> `{ mount: ‘by-item’, args: [‘<domain>’, ‘<itemId>’] }`
|
|
304
334
|
*
|
|
305
335
|
* The path MUST start with `/`. Trailing slashes are stripped before parsing.
|
|
306
336
|
*
|
|
@@ -384,6 +414,31 @@ export function parsePath(pathString: string): ParsedKnowledgePath {
|
|
|
384
414
|
return { mount: 'all-roles', args: [] }
|
|
385
415
|
}
|
|
386
416
|
|
|
417
|
+
// /by-domain/<domain> — enumerate all items in a domain
|
|
418
|
+
if (first === 'by-domain') {
|
|
419
|
+
if (rest.length === 0) {
|
|
420
|
+
throw new Error(`parsePath: /by-domain requires a domain argument, got: "${pathString}"`)
|
|
421
|
+
}
|
|
422
|
+
const domain = rest[0]
|
|
423
|
+
if (!(DOMAIN_ITEM_KINDS as readonly string[]).includes(domain)) {
|
|
424
|
+
throw new Error(`parsePath: /by-domain unknown domain "${domain}". Supported: ${DOMAIN_ITEM_KINDS.join(', ')}`)
|
|
425
|
+
}
|
|
426
|
+
return { mount: 'by-domain', args: [domain] }
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
// /by-item/<domain>/<itemId> — single domain-item resolution
|
|
430
|
+
if (first === 'by-item') {
|
|
431
|
+
if (rest.length < 2) {
|
|
432
|
+
throw new Error(`parsePath: /by-item requires <domain>/<itemId>, got: "${pathString}"`)
|
|
433
|
+
}
|
|
434
|
+
const domain = rest[0]
|
|
435
|
+
if (!(DOMAIN_ITEM_KINDS as readonly string[]).includes(domain)) {
|
|
436
|
+
throw new Error(`parsePath: /by-item unknown domain "${domain}". Supported: ${DOMAIN_ITEM_KINDS.join(', ')}`)
|
|
437
|
+
}
|
|
438
|
+
const itemId = rest.slice(1).join('/')
|
|
439
|
+
return { mount: 'by-item', args: [domain, itemId] }
|
|
440
|
+
}
|
|
441
|
+
|
|
387
442
|
// /<nodeId> (single node)
|
|
388
443
|
// first must not be a recognized mount prefix
|
|
389
444
|
if (segments.length === 1) {
|
|
@@ -391,7 +446,7 @@ export function parsePath(pathString: string): ParsedKnowledgePath {
|
|
|
391
446
|
}
|
|
392
447
|
|
|
393
448
|
throw new Error(
|
|
394
|
-
`parsePath: unrecognized path pattern "${pathString}". Supported: /by-system/<id>, /by-kind/<kind>, /by-owner/<id>, /graph/<nodeId>/governs, /graph/<nodeId>/governed-by, /<nodeId>, /all-systems, /all-resources, /all-roles`
|
|
449
|
+
`parsePath: unrecognized path pattern "${pathString}". Supported: /by-system/<id>, /by-kind/<kind>, /by-owner/<id>, /by-domain/<domain>, /by-item/<domain>/<itemId>, /graph/<nodeId>/governs, /graph/<nodeId>/governed-by, /<nodeId>, /all-systems, /all-resources, /all-roles`
|
|
395
450
|
)
|
|
396
451
|
}
|
|
397
452
|
|
|
@@ -763,6 +818,58 @@ function collectOntologyEntries(scope: {
|
|
|
763
818
|
// omDescribe — neighborhood view for any OM node ID
|
|
764
819
|
// ---------------------------------------------------------------------------
|
|
765
820
|
|
|
821
|
+
/**
|
|
822
|
+
* Location context for a domain-item node in the organization graph.
|
|
823
|
+
*/
|
|
824
|
+
export interface OmDescribeDomainItemLocation {
|
|
825
|
+
/** Human-readable label for the domain (e.g. "Clients"). */
|
|
826
|
+
domainLabel: string
|
|
827
|
+
/** Graph node id for this item (e.g. `client:<uuid>`). */
|
|
828
|
+
graphNodeId: string
|
|
829
|
+
/** Parent graph node ids reachable via `contains` edges (e.g. `['organization-model']`). */
|
|
830
|
+
containsParentIds: string[]
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
/**
|
|
834
|
+
* A single governing knowledge node reference returned by domain-item describe.
|
|
835
|
+
*/
|
|
836
|
+
export interface OmDescribeDomainItemKnowledgeRef {
|
|
837
|
+
id: string
|
|
838
|
+
title: string
|
|
839
|
+
knowledgeKind: string
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
/**
|
|
843
|
+
* Structured neighborhood view of a domain-item node.
|
|
844
|
+
*
|
|
845
|
+
* Returned by `omDescribe` for `item:<domain>:<id>` and bare-id forms
|
|
846
|
+
* (e.g. `client:<uuid>`). Carries the full domain record payload, graph
|
|
847
|
+
* location, and any governing knowledge nodes.
|
|
848
|
+
*/
|
|
849
|
+
export interface OmDescribeDomainItem {
|
|
850
|
+
kind: 'domain-item'
|
|
851
|
+
/** The `item:<domain>:<id>` canonical reference string. */
|
|
852
|
+
id: string
|
|
853
|
+
/** The domain collection this item belongs to (e.g. `'clients'`). */
|
|
854
|
+
domain: DomainItemKind
|
|
855
|
+
/** Human-readable name or label for this item. */
|
|
856
|
+
name: string
|
|
857
|
+
/** Graph node location: graph id, domain label, and parentage. */
|
|
858
|
+
location: OmDescribeDomainItemLocation
|
|
859
|
+
/**
|
|
860
|
+
* Full domain record payload. Shape varies by domain:
|
|
861
|
+
* - `clients`: full `ClientProfile` (identity, branding, links, prompts, config, etc.)
|
|
862
|
+
* - `roles`: id, title, responsibilities, responsibleFor, reportsToId
|
|
863
|
+
* - `policies`: id, label, description, trigger, appliesTo, actions
|
|
864
|
+
* - `customers`: id, name, description, jobsToBeDone, pains, gains, firmographics
|
|
865
|
+
* - `offerings`: id, name, description, pricingModel, price, targetSegmentIds
|
|
866
|
+
* - `goals`: id, description, periodStart, periodEnd, keyResults
|
|
867
|
+
*/
|
|
868
|
+
record: Record<string, unknown>
|
|
869
|
+
/** Knowledge nodes that govern this domain item via `governs` edges. */
|
|
870
|
+
governingKnowledge: OmDescribeDomainItemKnowledgeRef[]
|
|
871
|
+
}
|
|
872
|
+
|
|
766
873
|
/**
|
|
767
874
|
* Structured neighborhood view of a single OM node.
|
|
768
875
|
*
|
|
@@ -778,6 +885,7 @@ export type OmDescribeResult =
|
|
|
778
885
|
| OmDescribeOntology
|
|
779
886
|
| OmDescribeRole
|
|
780
887
|
| OmDescribePolicy
|
|
888
|
+
| OmDescribeDomainItem
|
|
781
889
|
|
|
782
890
|
export interface OmDescribeSystem {
|
|
783
891
|
kind: 'system'
|
|
@@ -868,18 +976,40 @@ export interface OmDescribePolicy {
|
|
|
868
976
|
* Detection rules (highest priority first):
|
|
869
977
|
* - Contains `:<ontology-kind>/<local-id>` → ontology
|
|
870
978
|
* - Starts with `knowledge.` → knowledge
|
|
871
|
-
* - Starts with `role.` → role
|
|
872
|
-
* - Starts with `policy.` → policy
|
|
979
|
+
* - Starts with `role.` (dotted) → role (OM role, NOT domain-item bare form)
|
|
980
|
+
* - Starts with `policy.` (dotted) → policy (OM policy, NOT domain-item bare form)
|
|
981
|
+
* - Starts with `item:<domain>:` → domain-item (canonical form)
|
|
982
|
+
* - Starts with a bare domain prefix followed by `:` → domain-item (back-compat)
|
|
873
983
|
* - Resolves via `getSystem()` → system
|
|
874
984
|
* - Matches a key in `model.resources` → resource
|
|
875
985
|
*/
|
|
876
|
-
function detectKind(model: OrganizationModel, id: string): OmSearchHitKind | undefined {
|
|
986
|
+
function detectKind(model: OrganizationModel, id: string): OmSearchHitKind | 'domain-item' | undefined {
|
|
877
987
|
if (/:(object|action|event|catalog|link|interface|value-type|property|group|endpoint)\//.test(id)) {
|
|
878
988
|
return 'ontology'
|
|
879
989
|
}
|
|
880
990
|
if (id.startsWith('knowledge.')) return 'knowledge'
|
|
991
|
+
// Dotted role/policy forms (e.g. role.ops-lead, policy.approve-large-deals) — OM search kinds.
|
|
992
|
+
// These must be checked BEFORE the bare colon forms so 'role.' does not collide with 'role:'.
|
|
881
993
|
if (id.startsWith('role.')) return 'role'
|
|
882
994
|
if (id.startsWith('policy.')) return 'policy'
|
|
995
|
+
// Canonical domain-item form: item:<domain>:<id>
|
|
996
|
+
if (id.startsWith('item:')) {
|
|
997
|
+
const afterItem = id.slice('item:'.length)
|
|
998
|
+
const colonIdx = afterItem.indexOf(':')
|
|
999
|
+
if (colonIdx > 0) {
|
|
1000
|
+
const domain = afterItem.slice(0, colonIdx)
|
|
1001
|
+
if ((DOMAIN_ITEM_KINDS as readonly string[]).includes(domain)) return 'domain-item'
|
|
1002
|
+
}
|
|
1003
|
+
return undefined
|
|
1004
|
+
}
|
|
1005
|
+
// Bare domain-item prefix forms: client:<id>, role:<id>, policy:<id>,
|
|
1006
|
+
// customer:<id>, offering:<id>, goal:<id>.
|
|
1007
|
+
// These use a colon separator (NOT a dot), so 'role:' is distinct from 'role.'.
|
|
1008
|
+
const firstColon = id.indexOf(':')
|
|
1009
|
+
if (firstColon > 0) {
|
|
1010
|
+
const prefix = id.slice(0, firstColon)
|
|
1011
|
+
if (prefix in BARE_PREFIX_TO_DOMAIN) return 'domain-item'
|
|
1012
|
+
}
|
|
883
1013
|
if (model.systems && getSystemByPath(model.systems, id)) return 'system'
|
|
884
1014
|
if (model.resources?.[id]) return 'resource'
|
|
885
1015
|
return undefined
|
|
@@ -929,6 +1059,8 @@ export function omDescribe(model: OrganizationModel, id: string): OmDescribeResu
|
|
|
929
1059
|
return describeRole(model, id)
|
|
930
1060
|
case 'policy':
|
|
931
1061
|
return describePolicy(model, id)
|
|
1062
|
+
case 'domain-item':
|
|
1063
|
+
return describeDomainItem(model, id)
|
|
932
1064
|
}
|
|
933
1065
|
}
|
|
934
1066
|
|
|
@@ -1129,3 +1261,127 @@ function describePolicy(model: OrganizationModel, id: string): OmDescribePolicy
|
|
|
1129
1261
|
effectKinds: (policy.actions ?? []).map((a) => a.kind)
|
|
1130
1262
|
}
|
|
1131
1263
|
}
|
|
1264
|
+
|
|
1265
|
+
// ---------------------------------------------------------------------------
|
|
1266
|
+
// Domain-item describe helpers
|
|
1267
|
+
// ---------------------------------------------------------------------------
|
|
1268
|
+
|
|
1269
|
+
/**
|
|
1270
|
+
* Human-readable labels for each domain kind.
|
|
1271
|
+
*/
|
|
1272
|
+
const DOMAIN_LABEL: Record<DomainItemKind, string> = {
|
|
1273
|
+
clients: 'Clients',
|
|
1274
|
+
roles: 'Roles',
|
|
1275
|
+
policies: 'Policies',
|
|
1276
|
+
customers: 'Customers',
|
|
1277
|
+
offerings: 'Offerings',
|
|
1278
|
+
goals: 'Goals'
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1281
|
+
/**
|
|
1282
|
+
* Graph node id prefix for each domain kind. Mirrors the convention used by
|
|
1283
|
+
* `buildOrganizationGraph` in `organization-model/graph/build.ts`:
|
|
1284
|
+
* client:<id>, role:<id>, policy:<id>, customer-segment:<id>, offering:<id>, goal:<id>
|
|
1285
|
+
*/
|
|
1286
|
+
const DOMAIN_GRAPH_PREFIX: Record<DomainItemKind, string> = {
|
|
1287
|
+
clients: 'client',
|
|
1288
|
+
roles: 'role',
|
|
1289
|
+
policies: 'policy',
|
|
1290
|
+
customers: 'customer-segment',
|
|
1291
|
+
offerings: 'offering',
|
|
1292
|
+
goals: 'goal'
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
/**
|
|
1296
|
+
* Parse a domain-item ref (canonical `item:<domain>:<id>` or bare `<prefix>:<id>`)
|
|
1297
|
+
* into `{ domain, itemId }`. Returns `undefined` when the ref cannot be parsed.
|
|
1298
|
+
*/
|
|
1299
|
+
function parseDomainItemRef(id: string): { domain: DomainItemKind; itemId: string } | undefined {
|
|
1300
|
+
// Canonical: item:<domain>:<id>
|
|
1301
|
+
if (id.startsWith('item:')) {
|
|
1302
|
+
const afterItem = id.slice('item:'.length)
|
|
1303
|
+
const colonIdx = afterItem.indexOf(':')
|
|
1304
|
+
if (colonIdx <= 0) return undefined
|
|
1305
|
+
const domain = afterItem.slice(0, colonIdx) as DomainItemKind
|
|
1306
|
+
const itemId = afterItem.slice(colonIdx + 1)
|
|
1307
|
+
if (!(DOMAIN_ITEM_KINDS as readonly string[]).includes(domain) || !itemId) return undefined
|
|
1308
|
+
return { domain, itemId }
|
|
1309
|
+
}
|
|
1310
|
+
// Bare prefix: client:<id>, role:<id>, etc.
|
|
1311
|
+
const firstColon = id.indexOf(':')
|
|
1312
|
+
if (firstColon <= 0) return undefined
|
|
1313
|
+
const prefix = id.slice(0, firstColon)
|
|
1314
|
+
const domain = BARE_PREFIX_TO_DOMAIN[prefix]
|
|
1315
|
+
if (!domain) return undefined
|
|
1316
|
+
const itemId = id.slice(firstColon + 1)
|
|
1317
|
+
if (!itemId) return undefined
|
|
1318
|
+
return { domain, itemId }
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
/**
|
|
1322
|
+
* Build a structured neighborhood view of a domain-item node.
|
|
1323
|
+
*
|
|
1324
|
+
* Accepts canonical `item:<domain>:<id>` or bare back-compat forms
|
|
1325
|
+
* (`client:<uuid>`, `role:<id>`, etc.).
|
|
1326
|
+
*/
|
|
1327
|
+
function describeDomainItem(model: OrganizationModel, id: string): OmDescribeDomainItem | undefined {
|
|
1328
|
+
const parsed = parseDomainItemRef(id)
|
|
1329
|
+
if (!parsed) return undefined
|
|
1330
|
+
|
|
1331
|
+
const { domain, itemId } = parsed
|
|
1332
|
+
|
|
1333
|
+
// Look up the record in the appropriate domain collection.
|
|
1334
|
+
const collection = model[domain] as Record<string, Record<string, unknown>> | undefined
|
|
1335
|
+
const record = collection?.[itemId]
|
|
1336
|
+
if (!record) return undefined
|
|
1337
|
+
|
|
1338
|
+
// Derive the item's name. Each domain uses a different field for the display name.
|
|
1339
|
+
const name =
|
|
1340
|
+
domain === 'clients'
|
|
1341
|
+
? String((record['name'] as string | undefined) ?? itemId)
|
|
1342
|
+
: domain === 'roles'
|
|
1343
|
+
? String((record['title'] as string | undefined) ?? itemId)
|
|
1344
|
+
: domain === 'policies'
|
|
1345
|
+
? String((record['label'] as string | undefined) ?? itemId)
|
|
1346
|
+
: domain === 'goals'
|
|
1347
|
+
? String((record['description'] as string | undefined) ?? itemId)
|
|
1348
|
+
: String((record['name'] as string | undefined) ?? itemId)
|
|
1349
|
+
|
|
1350
|
+
// Graph node id follows the build.ts convention.
|
|
1351
|
+
const graphNodeId = `${DOMAIN_GRAPH_PREFIX[domain]}:${itemId}`
|
|
1352
|
+
|
|
1353
|
+
// Contains parentage — all domain items have a single `contains` edge from
|
|
1354
|
+
// `organization-model`. We derive this from the known convention without
|
|
1355
|
+
// building the full graph (avoids heavy dependency).
|
|
1356
|
+
const containsParentIds = ['organization-model']
|
|
1357
|
+
|
|
1358
|
+
// Governing knowledge: knowledge nodes whose links target this item's graph node.
|
|
1359
|
+
const governingKnowledge: OmDescribeDomainItemKnowledgeRef[] = []
|
|
1360
|
+
for (const node of Object.values(model.knowledge ?? {})) {
|
|
1361
|
+
const governs = (node.links ?? []).some((link) => link.nodeId === graphNodeId)
|
|
1362
|
+
if (governs) {
|
|
1363
|
+
governingKnowledge.push({
|
|
1364
|
+
id: node.id,
|
|
1365
|
+
title: node.title,
|
|
1366
|
+
knowledgeKind: node.kind
|
|
1367
|
+
})
|
|
1368
|
+
}
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1371
|
+
// Canonical id is always the `item:<domain>:<id>` form.
|
|
1372
|
+
const canonicalId = `item:${domain}:${itemId}`
|
|
1373
|
+
|
|
1374
|
+
return {
|
|
1375
|
+
kind: 'domain-item',
|
|
1376
|
+
id: canonicalId,
|
|
1377
|
+
domain,
|
|
1378
|
+
name,
|
|
1379
|
+
location: {
|
|
1380
|
+
domainLabel: DOMAIN_LABEL[domain],
|
|
1381
|
+
graphNodeId,
|
|
1382
|
+
containsParentIds
|
|
1383
|
+
},
|
|
1384
|
+
record: record as Record<string, unknown>,
|
|
1385
|
+
governingKnowledge
|
|
1386
|
+
}
|
|
1387
|
+
}
|
package/src/operations/index.ts
CHANGED
|
@@ -22,17 +22,19 @@ export type {
|
|
|
22
22
|
|
|
23
23
|
// Session validation schemas
|
|
24
24
|
export {
|
|
25
|
-
CreateSessionSchema,
|
|
26
|
-
ExecuteTurnSchema,
|
|
27
|
-
ListSessionsQuerySchema,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
type
|
|
33
|
-
type
|
|
34
|
-
type
|
|
35
|
-
|
|
25
|
+
CreateSessionSchema,
|
|
26
|
+
ExecuteTurnSchema,
|
|
27
|
+
ListSessionsQuerySchema,
|
|
28
|
+
SessionMessagesQuerySchema,
|
|
29
|
+
SessionIdParamSchema,
|
|
30
|
+
ExecutionIdParamsSchema,
|
|
31
|
+
WebSocketSessionTurnSchema,
|
|
32
|
+
type CreateSessionInput,
|
|
33
|
+
type ExecuteTurnInput,
|
|
34
|
+
type ListSessionsQuery,
|
|
35
|
+
type SessionMessagesQuery,
|
|
36
|
+
type WebSocketSessionTurnMessage
|
|
37
|
+
} from './sessions'
|
|
36
38
|
|
|
37
39
|
// Notification types and validation schemas
|
|
38
40
|
export * from './notifications/index'
|
|
@@ -46,5 +48,8 @@ export * from './activities/index'
|
|
|
46
48
|
// Triggers (includes webhook providers and trigger definitions)
|
|
47
49
|
export * from './triggers/index'
|
|
48
50
|
|
|
49
|
-
// Debug Logs
|
|
50
|
-
export * from './debug-logs/index'
|
|
51
|
+
// Debug Logs
|
|
52
|
+
export * from './debug-logs/index'
|
|
53
|
+
|
|
54
|
+
// Public agent chat route schemas
|
|
55
|
+
export * from './public-agent-chat'
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { z } from 'zod'
|
|
2
|
+
import { UuidSchema } from '../../platform/utils/validation'
|
|
3
|
+
|
|
4
|
+
export const PublicAgentChatSlugParamSchema = z
|
|
5
|
+
.object({
|
|
6
|
+
slug: z.string().min(1).max(120).regex(/^[a-zA-Z0-9._-]+$/)
|
|
7
|
+
})
|
|
8
|
+
.strict()
|
|
9
|
+
|
|
10
|
+
export const PublicAgentChatSessionParamSchema = z
|
|
11
|
+
.object({
|
|
12
|
+
sessionId: UuidSchema
|
|
13
|
+
})
|
|
14
|
+
.strict()
|
|
15
|
+
|
|
16
|
+
export const PublicAgentChatAuthorizeSchema = z
|
|
17
|
+
.object({
|
|
18
|
+
code: z.string().min(1).max(200).optional(),
|
|
19
|
+
visitorId: z.string().min(1).max(120).optional()
|
|
20
|
+
})
|
|
21
|
+
.strict()
|
|
22
|
+
|
|
23
|
+
export const PublicAgentChatCreateSessionSchema = z
|
|
24
|
+
.object({
|
|
25
|
+
capabilityToken: z.string().min(32).optional(),
|
|
26
|
+
metadata: z.record(z.string(), z.unknown()).optional()
|
|
27
|
+
})
|
|
28
|
+
.strict()
|
|
29
|
+
|
|
30
|
+
export const PublicAgentChatCapabilityQuerySchema = z
|
|
31
|
+
.object({
|
|
32
|
+
token: z.string().min(32)
|
|
33
|
+
})
|
|
34
|
+
.strict()
|
|
35
|
+
|
|
36
|
+
export type PublicAgentChatSlugParams = z.infer<typeof PublicAgentChatSlugParamSchema>
|
|
37
|
+
export type PublicAgentChatSessionParams = z.infer<typeof PublicAgentChatSessionParamSchema>
|
|
38
|
+
export type PublicAgentChatAuthorizeInput = z.infer<typeof PublicAgentChatAuthorizeSchema>
|
|
39
|
+
export type PublicAgentChatCreateSessionInput = z.infer<typeof PublicAgentChatCreateSessionSchema>
|
|
40
|
+
export type PublicAgentChatCapabilityQuery = z.infer<typeof PublicAgentChatCapabilityQuerySchema>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export {
|
|
2
|
+
PublicAgentChatSlugParamSchema,
|
|
3
|
+
PublicAgentChatSessionParamSchema,
|
|
4
|
+
PublicAgentChatAuthorizeSchema,
|
|
5
|
+
PublicAgentChatCreateSessionSchema,
|
|
6
|
+
PublicAgentChatCapabilityQuerySchema,
|
|
7
|
+
type PublicAgentChatSlugParams,
|
|
8
|
+
type PublicAgentChatSessionParams,
|
|
9
|
+
type PublicAgentChatAuthorizeInput,
|
|
10
|
+
type PublicAgentChatCreateSessionInput,
|
|
11
|
+
type PublicAgentChatCapabilityQuery
|
|
12
|
+
} from './api-schemas'
|
|
@@ -113,13 +113,32 @@ export const ExecuteTurnSchema = z
|
|
|
113
113
|
* - resourceId validated as string (resource identifiers)
|
|
114
114
|
* - Limit bounded (prevents DoS via large result sets)
|
|
115
115
|
*/
|
|
116
|
-
export const ListSessionsQuerySchema = z
|
|
117
|
-
.object({
|
|
118
|
-
userId: UuidSchema.optional(),
|
|
119
|
-
resourceId: z.string().optional(),
|
|
120
|
-
limit: z.coerce.number().int().min(1).max(100).default(20)
|
|
121
|
-
})
|
|
122
|
-
.strict()
|
|
116
|
+
export const ListSessionsQuerySchema = z
|
|
117
|
+
.object({
|
|
118
|
+
userId: UuidSchema.optional(),
|
|
119
|
+
resourceId: z.string().optional(),
|
|
120
|
+
limit: z.coerce.number().int().min(1).max(100).default(20)
|
|
121
|
+
})
|
|
122
|
+
.strict()
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Get session messages with cursor pagination
|
|
126
|
+
* GET /sessions/:sessionId/messages
|
|
127
|
+
*
|
|
128
|
+
* Cursor:
|
|
129
|
+
* - cursor is the last seen message_index
|
|
130
|
+
* - next page returns rows where message_index > cursor
|
|
131
|
+
*
|
|
132
|
+
* Security:
|
|
133
|
+
* - Limit bounded to prevent unbounded transcript reads
|
|
134
|
+
* - Cursor coerced and validated as a non-negative integer
|
|
135
|
+
*/
|
|
136
|
+
export const SessionMessagesQuerySchema = z
|
|
137
|
+
.object({
|
|
138
|
+
limit: z.coerce.number().int().min(1).max(100).default(100),
|
|
139
|
+
cursor: z.coerce.number().int().min(0).optional()
|
|
140
|
+
})
|
|
141
|
+
.strict()
|
|
123
142
|
|
|
124
143
|
// ============================================================================
|
|
125
144
|
// WebSocket Messages
|
|
@@ -160,7 +179,8 @@ export const WebSocketSessionTurnSchema = z
|
|
|
160
179
|
// ============================================================================
|
|
161
180
|
|
|
162
181
|
// Export inferred types for use in route handlers
|
|
163
|
-
export type CreateSessionInput = z.infer<typeof CreateSessionSchema>
|
|
164
|
-
export type ExecuteTurnInput = z.infer<typeof ExecuteTurnSchema>
|
|
165
|
-
export type ListSessionsQuery = z.infer<typeof ListSessionsQuerySchema>
|
|
166
|
-
export type
|
|
182
|
+
export type CreateSessionInput = z.infer<typeof CreateSessionSchema>
|
|
183
|
+
export type ExecuteTurnInput = z.infer<typeof ExecuteTurnSchema>
|
|
184
|
+
export type ListSessionsQuery = z.infer<typeof ListSessionsQuerySchema>
|
|
185
|
+
export type SessionMessagesQuery = z.infer<typeof SessionMessagesQuerySchema>
|
|
186
|
+
export type WebSocketSessionTurnMessage = z.infer<typeof WebSocketSessionTurnSchema>
|
|
@@ -12,15 +12,17 @@ export type {
|
|
|
12
12
|
|
|
13
13
|
// Export validation schemas
|
|
14
14
|
export {
|
|
15
|
-
CreateSessionSchema,
|
|
16
|
-
ExecuteTurnSchema,
|
|
17
|
-
ListSessionsQuerySchema,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
type
|
|
24
|
-
type
|
|
25
|
-
type
|
|
26
|
-
|
|
15
|
+
CreateSessionSchema,
|
|
16
|
+
ExecuteTurnSchema,
|
|
17
|
+
ListSessionsQuerySchema,
|
|
18
|
+
SessionMessagesQuerySchema,
|
|
19
|
+
SessionIdParamSchema,
|
|
20
|
+
ExecutionIdParamsSchema,
|
|
21
|
+
WebSocketSessionTurnSchema,
|
|
22
|
+
UuidSchema,
|
|
23
|
+
type CreateSessionInput,
|
|
24
|
+
type ExecuteTurnInput,
|
|
25
|
+
type ListSessionsQuery,
|
|
26
|
+
type SessionMessagesQuery,
|
|
27
|
+
type WebSocketSessionTurnMessage
|
|
28
|
+
} from './api-schemas'
|
|
@@ -2118,6 +2118,138 @@ export type Database = {
|
|
|
2118
2118
|
}
|
|
2119
2119
|
Relationships: []
|
|
2120
2120
|
}
|
|
2121
|
+
agent_access_grants: {
|
|
2122
|
+
Row: {
|
|
2123
|
+
allowed_origins: string[]
|
|
2124
|
+
branding: Json
|
|
2125
|
+
capture_fields: Json
|
|
2126
|
+
code_hash: string | null
|
|
2127
|
+
code_salt: string | null
|
|
2128
|
+
created_at: string
|
|
2129
|
+
disabled_at: string | null
|
|
2130
|
+
expires_at: string | null
|
|
2131
|
+
id: string
|
|
2132
|
+
max_sessions_per_visitor: number
|
|
2133
|
+
max_turns_per_session: number
|
|
2134
|
+
mode: string
|
|
2135
|
+
organization_id: string
|
|
2136
|
+
resource_id: string
|
|
2137
|
+
slug: string
|
|
2138
|
+
tool_policy: Json
|
|
2139
|
+
updated_at: string
|
|
2140
|
+
}
|
|
2141
|
+
Insert: {
|
|
2142
|
+
allowed_origins?: string[]
|
|
2143
|
+
branding?: Json
|
|
2144
|
+
capture_fields?: Json
|
|
2145
|
+
code_hash?: string | null
|
|
2146
|
+
code_salt?: string | null
|
|
2147
|
+
created_at?: string
|
|
2148
|
+
disabled_at?: string | null
|
|
2149
|
+
expires_at?: string | null
|
|
2150
|
+
id?: string
|
|
2151
|
+
max_sessions_per_visitor?: number
|
|
2152
|
+
max_turns_per_session?: number
|
|
2153
|
+
mode?: string
|
|
2154
|
+
organization_id: string
|
|
2155
|
+
resource_id: string
|
|
2156
|
+
slug: string
|
|
2157
|
+
tool_policy?: Json
|
|
2158
|
+
updated_at?: string
|
|
2159
|
+
}
|
|
2160
|
+
Update: {
|
|
2161
|
+
allowed_origins?: string[]
|
|
2162
|
+
branding?: Json
|
|
2163
|
+
capture_fields?: Json
|
|
2164
|
+
code_hash?: string | null
|
|
2165
|
+
code_salt?: string | null
|
|
2166
|
+
created_at?: string
|
|
2167
|
+
disabled_at?: string | null
|
|
2168
|
+
expires_at?: string | null
|
|
2169
|
+
id?: string
|
|
2170
|
+
max_sessions_per_visitor?: number
|
|
2171
|
+
max_turns_per_session?: number
|
|
2172
|
+
mode?: string
|
|
2173
|
+
organization_id?: string
|
|
2174
|
+
resource_id?: string
|
|
2175
|
+
slug?: string
|
|
2176
|
+
tool_policy?: Json
|
|
2177
|
+
updated_at?: string
|
|
2178
|
+
}
|
|
2179
|
+
Relationships: [
|
|
2180
|
+
{
|
|
2181
|
+
foreignKeyName: "agent_access_grants_organization_id_fkey"
|
|
2182
|
+
columns: ["organization_id"]
|
|
2183
|
+
isOneToOne: false
|
|
2184
|
+
referencedRelation: "organizations"
|
|
2185
|
+
referencedColumns: ["id"]
|
|
2186
|
+
},
|
|
2187
|
+
]
|
|
2188
|
+
}
|
|
2189
|
+
agent_chat_capabilities: {
|
|
2190
|
+
Row: {
|
|
2191
|
+
created_at: string
|
|
2192
|
+
expires_at: string
|
|
2193
|
+
grant_id: string
|
|
2194
|
+
id: string
|
|
2195
|
+
organization_id: string
|
|
2196
|
+
origin: string | null
|
|
2197
|
+
resource_id: string
|
|
2198
|
+
revoked_at: string | null
|
|
2199
|
+
session_id: string | null
|
|
2200
|
+
token_hash: string
|
|
2201
|
+
visitor_id: string | null
|
|
2202
|
+
}
|
|
2203
|
+
Insert: {
|
|
2204
|
+
created_at?: string
|
|
2205
|
+
expires_at: string
|
|
2206
|
+
grant_id: string
|
|
2207
|
+
id?: string
|
|
2208
|
+
organization_id: string
|
|
2209
|
+
origin?: string | null
|
|
2210
|
+
resource_id: string
|
|
2211
|
+
revoked_at?: string | null
|
|
2212
|
+
session_id?: string | null
|
|
2213
|
+
token_hash: string
|
|
2214
|
+
visitor_id?: string | null
|
|
2215
|
+
}
|
|
2216
|
+
Update: {
|
|
2217
|
+
created_at?: string
|
|
2218
|
+
expires_at?: string
|
|
2219
|
+
grant_id?: string
|
|
2220
|
+
id?: string
|
|
2221
|
+
organization_id?: string
|
|
2222
|
+
origin?: string | null
|
|
2223
|
+
resource_id?: string
|
|
2224
|
+
revoked_at?: string | null
|
|
2225
|
+
session_id?: string | null
|
|
2226
|
+
token_hash?: string
|
|
2227
|
+
visitor_id?: string | null
|
|
2228
|
+
}
|
|
2229
|
+
Relationships: [
|
|
2230
|
+
{
|
|
2231
|
+
foreignKeyName: "agent_chat_capabilities_grant_id_fkey"
|
|
2232
|
+
columns: ["grant_id"]
|
|
2233
|
+
isOneToOne: false
|
|
2234
|
+
referencedRelation: "agent_access_grants"
|
|
2235
|
+
referencedColumns: ["id"]
|
|
2236
|
+
},
|
|
2237
|
+
{
|
|
2238
|
+
foreignKeyName: "agent_chat_capabilities_organization_id_fkey"
|
|
2239
|
+
columns: ["organization_id"]
|
|
2240
|
+
isOneToOne: false
|
|
2241
|
+
referencedRelation: "organizations"
|
|
2242
|
+
referencedColumns: ["id"]
|
|
2243
|
+
},
|
|
2244
|
+
{
|
|
2245
|
+
foreignKeyName: "agent_chat_capabilities_session_id_fkey"
|
|
2246
|
+
columns: ["session_id"]
|
|
2247
|
+
isOneToOne: false
|
|
2248
|
+
referencedRelation: "sessions"
|
|
2249
|
+
referencedColumns: ["session_id"]
|
|
2250
|
+
},
|
|
2251
|
+
]
|
|
2252
|
+
}
|
|
2121
2253
|
organizations: {
|
|
2122
2254
|
Row: {
|
|
2123
2255
|
config: Json
|