@lssm/lib.contracts 1.7.3 → 1.9.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/README.md +62 -325
- package/dist/app-config/contracts.d.ts +51 -49
- package/dist/app-config/contracts.d.ts.map +1 -1
- package/dist/app-config/contracts.js +1 -1
- package/dist/app-config/contracts.js.map +1 -1
- package/dist/app-config/events.d.ts +28 -26
- package/dist/app-config/events.d.ts.map +1 -1
- package/dist/app-config/events.js +1 -1
- package/dist/app-config/events.js.map +1 -1
- package/dist/app-config/lifecycle-contracts.d.ts +81 -79
- package/dist/app-config/lifecycle-contracts.d.ts.map +1 -1
- package/dist/app-config/lifecycle-contracts.js +1 -1
- package/dist/app-config/lifecycle-contracts.js.map +1 -1
- package/dist/app-config/runtime.d.ts.map +1 -1
- package/dist/app-config/runtime.js.map +1 -1
- package/dist/app-config/spec.d.ts +2 -2
- package/dist/app-config/spec.d.ts.map +1 -1
- package/dist/app-config/spec.js.map +1 -1
- package/dist/app-config/validation.d.ts.map +1 -1
- package/dist/app-config/validation.js.map +1 -1
- package/dist/capabilities/openbanking.d.ts.map +1 -1
- package/dist/capabilities/openbanking.js.map +1 -1
- package/dist/capabilities.d.ts +2 -1
- package/dist/capabilities.d.ts.map +1 -1
- package/dist/capabilities.js +1 -1
- package/dist/capabilities.js.map +1 -1
- package/dist/client/react/form-render.d.ts +1 -0
- package/dist/client/react/form-render.d.ts.map +1 -1
- package/dist/contracts-adapter-input.d.ts +1 -0
- package/dist/contracts-adapter-input.d.ts.map +1 -1
- package/dist/data-views/query-generator.d.ts +40 -0
- package/dist/data-views/query-generator.d.ts.map +1 -0
- package/dist/data-views/query-generator.js +2 -0
- package/dist/data-views/query-generator.js.map +1 -0
- package/dist/data-views/runtime.d.ts +27 -0
- package/dist/data-views/runtime.d.ts.map +1 -0
- package/dist/data-views/runtime.js +2 -0
- package/dist/data-views/runtime.js.map +1 -0
- package/dist/data-views.js.map +1 -1
- package/dist/events.d.ts +1 -0
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +1 -1
- package/dist/events.js.map +1 -1
- package/dist/experiments/evaluator.d.ts.map +1 -1
- package/dist/experiments/evaluator.js.map +1 -1
- package/dist/experiments/spec-resolver.d.ts +17 -0
- package/dist/experiments/spec-resolver.d.ts.map +1 -0
- package/dist/experiments/spec-resolver.js +0 -0
- package/dist/experiments/spec.js.map +1 -1
- package/dist/forms.d.ts +1 -0
- package/dist/forms.d.ts.map +1 -1
- package/dist/graphql-federation/dist/index.js +2 -0
- package/dist/graphql-federation/dist/index.js.map +1 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.js +1 -1
- package/dist/install.d.ts +1 -0
- package/dist/install.d.ts.map +1 -1
- package/dist/integrations/connection.d.ts.map +1 -1
- package/dist/integrations/contracts.d.ts +103 -101
- package/dist/integrations/contracts.d.ts.map +1 -1
- package/dist/integrations/contracts.js +1 -1
- package/dist/integrations/contracts.js.map +1 -1
- package/dist/integrations/health.d.ts.map +1 -1
- package/dist/integrations/health.js.map +1 -1
- package/dist/integrations/openbanking/contracts/accounts.d.ts +67 -65
- package/dist/integrations/openbanking/contracts/accounts.d.ts.map +1 -1
- package/dist/integrations/openbanking/contracts/accounts.js +1 -1
- package/dist/integrations/openbanking/contracts/accounts.js.map +1 -1
- package/dist/integrations/openbanking/contracts/balances.d.ts +35 -33
- package/dist/integrations/openbanking/contracts/balances.d.ts.map +1 -1
- package/dist/integrations/openbanking/contracts/balances.js +1 -1
- package/dist/integrations/openbanking/contracts/balances.js.map +1 -1
- package/dist/integrations/openbanking/contracts/index.js.map +1 -1
- package/dist/integrations/openbanking/contracts/transactions.d.ts +49 -47
- package/dist/integrations/openbanking/contracts/transactions.d.ts.map +1 -1
- package/dist/integrations/openbanking/contracts/transactions.js +1 -1
- package/dist/integrations/openbanking/contracts/transactions.js.map +1 -1
- package/dist/integrations/openbanking/guards.js.map +1 -1
- package/dist/integrations/openbanking/models.d.ts +57 -54
- package/dist/integrations/openbanking/models.d.ts.map +1 -1
- package/dist/integrations/openbanking/models.js +1 -1
- package/dist/integrations/openbanking/models.js.map +1 -1
- package/dist/integrations/openbanking/telemetry.js.map +1 -1
- package/dist/integrations/providers/elevenlabs.d.ts.map +1 -1
- package/dist/integrations/providers/elevenlabs.js.map +1 -1
- package/dist/integrations/providers/gcs-storage.js.map +1 -1
- package/dist/integrations/providers/gmail.d.ts.map +1 -1
- package/dist/integrations/providers/gmail.js.map +1 -1
- package/dist/integrations/providers/google-calendar.js.map +1 -1
- package/dist/integrations/providers/impls/elevenlabs-voice.js.map +1 -1
- package/dist/integrations/providers/impls/gcs-storage.js.map +1 -1
- package/dist/integrations/providers/impls/gmail-inbound.js.map +1 -1
- package/dist/integrations/providers/impls/gmail-outbound.d.ts.map +1 -1
- package/dist/integrations/providers/impls/gmail-outbound.js.map +1 -1
- package/dist/integrations/providers/impls/google-calendar.d.ts.map +1 -1
- package/dist/integrations/providers/impls/google-calendar.js.map +1 -1
- package/dist/integrations/providers/impls/mistral-embedding.js.map +1 -1
- package/dist/integrations/providers/impls/mistral-llm.js.map +1 -1
- package/dist/integrations/providers/impls/postmark-email.js.map +1 -1
- package/dist/integrations/providers/impls/powens-client.d.ts.map +1 -1
- package/dist/integrations/providers/impls/powens-client.js.map +1 -1
- package/dist/integrations/providers/impls/powens-openbanking.d.ts.map +1 -1
- package/dist/integrations/providers/impls/powens-openbanking.js.map +1 -1
- package/dist/integrations/providers/impls/provider-factory.d.ts.map +1 -1
- package/dist/integrations/providers/impls/provider-factory.js.map +1 -1
- package/dist/integrations/providers/impls/qdrant-vector.d.ts.map +1 -1
- package/dist/integrations/providers/impls/qdrant-vector.js.map +1 -1
- package/dist/integrations/providers/impls/stripe-payments.d.ts.map +1 -1
- package/dist/integrations/providers/impls/stripe-payments.js.map +1 -1
- package/dist/integrations/providers/impls/twilio-sms.js.map +1 -1
- package/dist/integrations/providers/llm.d.ts.map +1 -1
- package/dist/integrations/providers/mistral.d.ts.map +1 -1
- package/dist/integrations/providers/mistral.js.map +1 -1
- package/dist/integrations/providers/payments.d.ts.map +1 -1
- package/dist/integrations/providers/postmark.d.ts.map +1 -1
- package/dist/integrations/providers/postmark.js.map +1 -1
- package/dist/integrations/providers/powens.js.map +1 -1
- package/dist/integrations/providers/qdrant.d.ts.map +1 -1
- package/dist/integrations/providers/qdrant.js.map +1 -1
- package/dist/integrations/providers/stripe.js.map +1 -1
- package/dist/integrations/providers/twilio-sms.js.map +1 -1
- package/dist/integrations/runtime.d.ts.map +1 -1
- package/dist/integrations/runtime.js.map +1 -1
- package/dist/integrations/secrets/env-secret-provider.js.map +1 -1
- package/dist/integrations/secrets/gcp-secret-manager.d.ts.map +1 -1
- package/dist/integrations/secrets/gcp-secret-manager.js.map +1 -1
- package/dist/integrations/secrets/manager.d.ts +2 -2
- package/dist/integrations/secrets/manager.d.ts.map +1 -1
- package/dist/integrations/secrets/manager.js.map +1 -1
- package/dist/integrations/secrets/provider.js.map +1 -1
- package/dist/integrations/spec.d.ts.map +1 -1
- package/dist/integrations/spec.js.map +1 -1
- package/dist/jobs/gcp-cloud-tasks.js.map +1 -1
- package/dist/jobs/gcp-pubsub.d.ts.map +1 -1
- package/dist/jobs/gcp-pubsub.js.map +1 -1
- package/dist/jobs/handlers/gmail-sync-handler.js.map +1 -1
- package/dist/jobs/handlers/storage-document-handler.js.map +1 -1
- package/dist/jobs/memory-queue.d.ts.map +1 -1
- package/dist/jobs/memory-queue.js.map +1 -1
- package/dist/jobs/queue.d.ts.map +1 -1
- package/dist/jsonschema.d.ts +1 -1
- package/dist/jsonschema.d.ts.map +1 -1
- package/dist/knowledge/contracts.d.ts +67 -65
- package/dist/knowledge/contracts.d.ts.map +1 -1
- package/dist/knowledge/contracts.js +1 -1
- package/dist/knowledge/contracts.js.map +1 -1
- package/dist/knowledge/ingestion/document-processor.js.map +1 -1
- package/dist/knowledge/ingestion/embedding-service.d.ts.map +1 -1
- package/dist/knowledge/ingestion/embedding-service.js.map +1 -1
- package/dist/knowledge/ingestion/gmail-adapter.d.ts.map +1 -1
- package/dist/knowledge/ingestion/gmail-adapter.js.map +1 -1
- package/dist/knowledge/ingestion/storage-adapter.js.map +1 -1
- package/dist/knowledge/ingestion/vector-indexer.js.map +1 -1
- package/dist/knowledge/query/service.d.ts +2 -2
- package/dist/knowledge/query/service.d.ts.map +1 -1
- package/dist/knowledge/query/service.js.map +1 -1
- package/dist/knowledge/runtime.d.ts.map +1 -1
- package/dist/knowledge/runtime.js.map +1 -1
- package/dist/knowledge/spaces/email-threads.js.map +1 -1
- package/dist/knowledge/spaces/financial-docs.js.map +1 -1
- package/dist/knowledge/spaces/financial-overview.js.map +1 -1
- package/dist/knowledge/spaces/product-canon.js.map +1 -1
- package/dist/knowledge/spaces/support-faq.js.map +1 -1
- package/dist/knowledge/spaces/uploaded-docs.js.map +1 -1
- package/dist/knowledge/spec.js.map +1 -1
- package/dist/migrations.d.ts.map +1 -1
- package/dist/migrations.js.map +1 -1
- package/dist/onboarding-base.d.ts +30 -28
- package/dist/onboarding-base.d.ts.map +1 -1
- package/dist/onboarding-base.js +1 -1
- package/dist/onboarding-base.js.map +1 -1
- package/dist/policy/engine.js.map +1 -1
- package/dist/policy/opa-adapter.d.ts.map +1 -1
- package/dist/policy/opa-adapter.js.map +1 -1
- package/dist/policy/spec.d.ts.map +1 -1
- package/dist/policy/spec.js.map +1 -1
- package/dist/presentations.d.ts +1 -0
- package/dist/presentations.d.ts.map +1 -1
- package/dist/presentations.v2.d.ts +1 -0
- package/dist/presentations.v2.d.ts.map +1 -1
- package/dist/regenerator/executor.d.ts.map +1 -1
- package/dist/regenerator/executor.js.map +1 -1
- package/dist/regenerator/service.d.ts.map +1 -1
- package/dist/regenerator/service.js.map +1 -1
- package/dist/regenerator/sinks.d.ts.map +1 -1
- package/dist/regenerator/sinks.js.map +1 -1
- package/dist/regenerator/types.d.ts.map +1 -1
- package/dist/regenerator/utils.js.map +1 -1
- package/dist/registry.d.ts +37 -9
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +1 -1
- package/dist/registry.js.map +1 -1
- package/dist/schema/dist/FieldType.js +2 -0
- package/dist/schema/dist/FieldType.js.map +1 -0
- package/dist/schema/dist/ScalarTypeEnum.js +2 -0
- package/dist/schema/dist/ScalarTypeEnum.js.map +1 -0
- package/dist/schema/{src → dist}/SchemaModel.js +1 -1
- package/dist/schema/dist/SchemaModel.js.map +1 -0
- package/dist/schema/dist/index.js +1 -0
- package/dist/server/graphql-pothos.d.ts +15 -2
- package/dist/server/graphql-pothos.d.ts.map +1 -1
- package/dist/server/graphql-pothos.js.map +1 -1
- package/dist/server/graphql-schema-export.js +1 -1
- package/dist/server/graphql-schema-export.js.map +1 -1
- package/dist/server/provider-mcp.d.ts +22 -4
- package/dist/server/provider-mcp.d.ts.map +1 -1
- package/dist/server/provider-mcp.js.map +1 -1
- package/dist/server/rest-next-app.d.ts +23 -3
- package/dist/server/rest-next-app.d.ts.map +1 -1
- package/dist/server/rest-next-app.js.map +1 -1
- package/dist/spec.d.ts +23 -0
- package/dist/spec.d.ts.map +1 -1
- package/dist/spec.js.map +1 -1
- package/dist/telemetry/anomaly.js.map +1 -1
- package/dist/telemetry/spec.d.ts.map +1 -1
- package/dist/telemetry/spec.js.map +1 -1
- package/dist/telemetry/tracker.d.ts.map +1 -1
- package/dist/telemetry/tracker.js.map +1 -1
- package/dist/tests/runner.js.map +1 -1
- package/dist/tests/spec.js.map +1 -1
- package/dist/themes.d.ts.map +1 -1
- package/dist/themes.js.map +1 -1
- package/dist/types/all.d.ts +2 -2
- package/dist/types.d.ts +3 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/workflow/adapters/db-adapter.d.ts +30 -10
- package/dist/workflow/adapters/db-adapter.d.ts.map +1 -1
- package/dist/workflow/adapters/db-adapter.js +1 -1
- package/dist/workflow/adapters/db-adapter.js.map +1 -1
- package/dist/workflow/adapters/file-adapter.js.map +1 -1
- package/dist/workflow/adapters/index.d.ts +2 -2
- package/dist/workflow/adapters/index.js +1 -1
- package/dist/workflow/adapters/memory-store.d.ts.map +1 -1
- package/dist/workflow/adapters/memory-store.js.map +1 -1
- package/dist/workflow/expression.js.map +1 -1
- package/dist/workflow/index.d.ts +2 -2
- package/dist/workflow/index.js +1 -1
- package/dist/workflow/runner.d.ts +1 -0
- package/dist/workflow/runner.d.ts.map +1 -1
- package/dist/workflow/runner.js +1 -1
- package/dist/workflow/runner.js.map +1 -1
- package/dist/workflow/sla-monitor.d.ts +21 -0
- package/dist/workflow/sla-monitor.d.ts.map +1 -0
- package/dist/workflow/sla-monitor.js +2 -0
- package/dist/workflow/sla-monitor.js.map +1 -0
- package/dist/workflow/spec.d.ts.map +1 -1
- package/dist/workflow/spec.js.map +1 -1
- package/dist/workflow/state.d.ts +1 -0
- package/dist/workflow/state.d.ts.map +1 -1
- package/dist/workflow/validation.d.ts.map +1 -1
- package/dist/workflow/validation.js.map +1 -1
- package/package.json +181 -177
- package/dist/graphql-federation/src/index.js +0 -2
- package/dist/graphql-federation/src/index.js.map +0 -1
- package/dist/schema/src/FieldType.js +0 -2
- package/dist/schema/src/FieldType.js.map +0 -1
- package/dist/schema/src/ScalarTypeEnum.js +0 -2
- package/dist/schema/src/ScalarTypeEnum.js.map +0 -1
- package/dist/schema/src/SchemaModel.js.map +0 -1
- package/dist/schema/src/index.js +0 -1
- /package/dist/schema/{src → dist}/EnumType.js +0 -0
|
@@ -9,24 +9,42 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
|
9
9
|
//#region src/server/provider-mcp.d.ts
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
12
|
+
* Creates a unified Model Context Protocol (MCP) server exposing operations, resources, and prompts.
|
|
13
|
+
*
|
|
14
|
+
* This function takes registries for operations, resources, and prompts, and exposes them as
|
|
15
|
+
* MCP Tools, Resources, and Prompts respectively. It enables AI agents to discover and interact
|
|
16
|
+
* with the application's capabilities.
|
|
17
|
+
*
|
|
18
|
+
* Features:
|
|
19
|
+
* - **Tools**: Exposes `command` operations as executable tools.
|
|
20
|
+
* - **Resources**: Exposes `ResourceRegistry` entries and `PresentationSpec`s (Markdown/JSON) as read-only resources.
|
|
21
|
+
* - **Prompts**: Exposes `PromptRegistry` entries as templated prompts.
|
|
22
|
+
*
|
|
23
|
+
* @param server - The `McpServer` instance to populate.
|
|
24
|
+
* @param ops - Registry containing operations (tools).
|
|
25
|
+
* @param resources - Registry containing data resources.
|
|
26
|
+
* @param prompts - Registry containing prompt templates.
|
|
27
|
+
* @param ctxFactories - Factories to create context for tools, resources, and prompts execution.
|
|
28
|
+
* @returns The populated `McpServer` instance.
|
|
16
29
|
*/
|
|
17
30
|
declare function createMcpServer(server: McpServer, ops: SpecRegistry, resources: ResourceRegistry, prompts: PromptRegistry, ctxFactories: {
|
|
31
|
+
/** Factory for tool execution context (e.g., system actor) */
|
|
18
32
|
toolCtx: () => HandlerCtx;
|
|
33
|
+
/** Factory for prompt rendering context */
|
|
19
34
|
promptCtx: () => {
|
|
20
35
|
userId?: string | null;
|
|
21
36
|
orgId?: string | null;
|
|
22
37
|
locale?: string;
|
|
23
38
|
};
|
|
39
|
+
/** Factory for resource resolution context */
|
|
24
40
|
resourceCtx: () => {
|
|
25
41
|
userId?: string | null;
|
|
26
42
|
orgId?: string | null;
|
|
27
43
|
locale?: string;
|
|
28
44
|
};
|
|
45
|
+
/** Optional registry for V1 presentations */
|
|
29
46
|
presentations?: PresentationRegistry;
|
|
47
|
+
/** Optional list of V2 presentation descriptors */
|
|
30
48
|
presentationsV2?: PresentationDescriptorV2[];
|
|
31
49
|
}): McpServer;
|
|
32
50
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-mcp.d.ts","names":[],"sources":["../../src/server/provider-mcp.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"provider-mcp.d.ts","names":[],"sources":["../../src/server/provider-mcp.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;AA6CA;;;;;;;;;;;;;;;;;iBAAgB,eAAA,SACN,gBACH,yBACM,2BACF;;iBAGQ;;;;;;;;;;;;;;kBAcC;;oBAEE;IACnB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-mcp.js","names":["z"],"sources":["../../src/server/provider-mcp.ts"],"sourcesContent":["import {\n McpServer,\n ResourceTemplate,\n} from '@modelcontextprotocol/sdk/server/mcp.js';\nimport type { SpecRegistry } from '../registry';\nimport type { ResourceRegistry } from '../resources';\nimport type { AnySchemaModel } from '@lssm/lib.schema';\nimport type { ContractSpec } from '../spec';\nimport type { PresentationRegistry } from '../presentations';\nimport { jsonSchemaForPresentation } from '../presentations';\nimport {\n createDefaultTransformEngine,\n type PresentationDescriptorV2,\n registerBasicValidation,\n registerDefaultReactRenderer,\n} from '../presentations.v2';\nimport type { PromptRegistry } from '../promptRegistry';\nimport type { HandlerCtx } from '../types';\nimport { defaultMcpTool, jsonSchemaForSpec } from '../jsonschema';\nimport type {\n CallToolResult,\n GetPromptResult,\n} from '@modelcontextprotocol/sdk/types.js';\nimport { zodToJsonSchema } from 'zod-to-json-schema';\nimport z from 'zod';\n\n/**\n * Build a unified MCP server exposing:\n * - tools: all command specs from SpecRegistry\n * - resources: list/read via ResourceRegistry\n * - prompts: list/get via PromptRegistry\n */\nexport function createMcpServer(\n server: McpServer,\n ops: SpecRegistry,\n resources: ResourceRegistry,\n prompts: PromptRegistry,\n ctxFactories: {\n toolCtx: () => HandlerCtx;\n promptCtx: () => {\n userId?: string | null;\n orgId?: string | null;\n locale?: string;\n };\n resourceCtx: () => {\n userId?: string | null;\n orgId?: string | null;\n locale?: string;\n };\n presentations?: PresentationRegistry; // optional extra carrier without breaking call sites\n presentationsV2?: PresentationDescriptorV2[]; // unified descriptors\n }\n) {\n /* ---------- Tools (commands) ---------- */\n for (const spec of ops.listSpecs()) {\n if (spec.meta.kind !== 'command') continue; // expose only commands as tools\n const { input } = jsonSchemaForSpec(\n spec as unknown as ContractSpec<AnySchemaModel, AnySchemaModel>\n );\n const toolName =\n spec.transport?.mcp?.toolName ??\n defaultMcpTool(spec.meta.name, spec.meta.version);\n\n server.registerTool(\n toolName,\n {\n // name: toolName,\n description: spec.meta.description,\n inputSchema: input as any,\n },\n async (args: any, _req: any): Promise<CallToolResult> => {\n const result = await ops.execute(\n spec.meta.name,\n spec.meta.version,\n args ?? {},\n ctxFactories.toolCtx()\n );\n // return { content: [{ type: 'json', json: result }] };\n return {\n content: [{ type: 'text', text: JSON.stringify(result, null, 4) }],\n };\n }\n );\n }\n\n /* ---------- Resources (queries/views) ---------- */\n for (const resource of resources.listTemplates()) {\n // server.registerPrompt(\n // 'review-code',\n // {\n // title: 'Code Review',\n // description: 'Review code for best practices and potential issues',\n // argsSchema: { code: z.string() as any },\n // },\n // ({ code }: { code?: string }) => ({\n // messages: [\n // {\n // role: 'user',\n // content: {\n // type: 'text',\n // text: `Please review this code:\\n\\n${code}`,\n // },\n // },\n // ],\n // })\n // );\n\n (server as any).registerResource(\n resource.meta.uriTemplate.split(':')[0]!,\n new ResourceTemplate(resource.meta.uriTemplate, {} as any),\n {\n // name: resource.meta.title,\n description: resource.meta.description,\n inputSchema: zodToJsonSchema(resource.input, {\n // metadata: `${op.meta.name}.input.v${op.meta.version}`,\n }),\n },\n async (_uri: any, args: any, _req: any) => {\n const ctx = ctxFactories.resourceCtx();\n const out = await resource.resolve(args, ctx);\n if (typeof out.data === 'string') {\n return {\n contents: [\n {\n uri: out.uri,\n mimeType: out.mimeType ?? resource.meta.mimeType,\n text: out.data,\n },\n ],\n };\n }\n return {\n contents: [\n {\n uri: out.uri,\n mimeType: out.mimeType ?? resource.meta.mimeType,\n blob: out.data.toString(),\n },\n ],\n };\n }\n );\n }\n\n /* ---------- Presentations as resources (markdown/data) with content negotiation ---------- */\n const __presentations = ctxFactories.presentations;\n const __presentationsV2 = ctxFactories.presentationsV2;\n if (__presentations) {\n const engine = registerBasicValidation(\n registerDefaultReactRenderer(createDefaultTransformEngine())\n );\n for (const p of __presentations.list()) {\n const baseKey = `presentation.${p.meta.name.replace(/\\./g, '_')}.v${p.meta.version}`;\n const baseUri = `presentation://${p.meta.name}/v${p.meta.version}`;\n\n // Generic metadata\n (server as any).registerResource(\n baseKey,\n new ResourceTemplate(baseUri, {} as any),\n {\n description: p.meta.description ?? 'Presentation',\n inputSchema: z.toJSONSchema(z.object({})),\n },\n async (_uri: any, _args: any, _req: any) => {\n if (p.content.kind === 'markdown') {\n const text = p.content.content\n ? p.content.content\n : `See resource: ${p.content.resourceUri ?? ''}`;\n return {\n contents: [\n {\n uri: baseUri,\n mimeType: 'text/markdown',\n text,\n },\n ],\n };\n }\n if (p.content.kind === 'data') {\n const schema = jsonSchemaForPresentation(p);\n return {\n contents: [\n {\n uri: baseUri,\n mimeType: 'application/json',\n text: JSON.stringify(schema, null, 2),\n },\n ],\n };\n }\n // web_component: metadata only for now\n const metaOnly = {\n name: p.meta.name,\n version: p.meta.version,\n kind: p.content.kind,\n description: p.meta.description ?? '',\n };\n return {\n contents: [\n {\n uri: baseUri,\n mimeType: 'application/json',\n text: JSON.stringify(metaOnly, null, 2),\n },\n ],\n };\n }\n );\n\n // Negotiated variants\n const variants: {\n ext: string;\n target: 'markdown' | 'application/json' | 'application/xml';\n }[] = [\n { ext: '.md', target: 'markdown' },\n { ext: '.json', target: 'application/json' },\n { ext: '.xml', target: 'application/xml' },\n ];\n for (const v of variants) {\n const key = `${baseKey}${v.ext}`;\n const uri = `${baseUri}${v.ext}`;\n (server as any).registerResource(\n key,\n new ResourceTemplate(uri, {} as any),\n {\n description: `${p.meta.description ?? 'Presentation'} (${v.ext})`,\n inputSchema: z.toJSONSchema(z.object({})),\n },\n async () => {\n // Use V2 engine to render a normalized JSON snapshot; if p is V1, fallback to jsonSchemaForPresentation\n if (p.content.kind === 'markdown' && v.target === 'markdown') {\n const text =\n p.content.content ??\n `See resource: ${p.content.resourceUri ?? ''}`;\n return { contents: [{ uri, mimeType: 'text/markdown', text }] };\n }\n if (p.content.kind === 'data' && v.target === 'application/json') {\n return {\n contents: [\n {\n uri,\n mimeType: 'application/json',\n text: JSON.stringify(jsonSchemaForPresentation(p), null, 2),\n },\n ],\n };\n }\n // Default: represent as JSON snapshot\n const jsonText = JSON.stringify(\n { meta: p.meta, content: p.content },\n null,\n 2\n );\n if (v.target === 'application/json') {\n return {\n contents: [\n { uri, mimeType: 'application/json', text: jsonText },\n ],\n };\n }\n if (v.target === 'application/xml') {\n const xml = `<presentation name=\"${p.meta.name}\" version=\"${p.meta.version}\"><json>${encodeURIComponent(jsonText)}</json></presentation>`;\n return {\n contents: [{ uri, mimeType: 'application/xml', text: xml }],\n };\n }\n // markdown fallback\n return {\n contents: [\n {\n uri,\n mimeType: 'text/markdown',\n text: 'Unsupported presentation for markdown',\n },\n ],\n };\n }\n );\n }\n }\n }\n\n // V2: register descriptors using transform engine (same scheme/negotiation)\n if (__presentationsV2 && __presentationsV2.length) {\n const engine = registerBasicValidation(\n registerDefaultReactRenderer(createDefaultTransformEngine())\n );\n for (const d of __presentationsV2) {\n const baseKey = `presentation.${d.meta.name.replace(/\\./g, '_')}.v${d.meta.version}`;\n const baseUri = `presentation://${d.meta.name}/v${d.meta.version}`;\n\n (server as any).registerResource(\n baseKey,\n new ResourceTemplate(baseUri, {} as any),\n {\n description: d.meta.description ?? 'Presentation',\n inputSchema: z.toJSONSchema(z.object({})),\n },\n async () => {\n const jsonText = JSON.stringify(\n { meta: d.meta, source: d.source, targets: d.targets },\n null,\n 2\n );\n return {\n contents: [\n { uri: baseUri, mimeType: 'application/json', text: jsonText },\n ],\n };\n }\n );\n\n const variants: {\n ext: string;\n target: 'markdown' | 'application/json' | 'application/xml';\n }[] = [\n { ext: '.md', target: 'markdown' },\n { ext: '.json', target: 'application/json' },\n { ext: '.xml', target: 'application/xml' },\n ];\n for (const v of variants) {\n const key = `${baseKey}${v.ext}`;\n const uri = `${baseUri}${v.ext}`;\n (server as any).registerResource(\n key,\n new ResourceTemplate(uri, {} as any),\n {\n description: `${d.meta.description ?? 'Presentation'} (${v.ext})`,\n inputSchema: z.toJSONSchema(z.object({})),\n },\n async () => {\n const out = await engine.render(v.target, d);\n return {\n contents: [\n {\n uri,\n mimeType:\n (out as any).mimeType ??\n (v.target === 'markdown' ? 'text/markdown' : v.target),\n text: (out as any).body ?? String(out),\n },\n ],\n };\n }\n );\n }\n }\n }\n\n /* ---------- Prompts ---------- */\n // for (const prompt of prompts.list()) {\n for (const prompt of prompts.list()) {\n server.registerPrompt(\n prompt.meta.name,\n {\n title: prompt.meta.title,\n description: prompt.meta.title,\n argsSchema: zodToJsonSchema(prompt.input) as any,\n },\n async (args: any, _extra: any): Promise<GetPromptResult> => {\n const link = (tpl: string, vars: Record<string, string | number>) => {\n let out = tpl;\n for (const [k, v] of Object.entries(vars))\n out = out.replace(\n new RegExp(`\\\\{${k}\\\\}`, 'g'),\n encodeURIComponent(String(v))\n );\n return out;\n };\n\n const parts = await prompt.render(prompt.input.parse(args), {\n ...ctxFactories.promptCtx(),\n link,\n });\n\n // MCP prompt shape: messages[{role, content[]}]; we return a single \"system\" text chunk + referenced resources\n const contents: GetPromptResult['messages'][number]['content'][] =\n parts.map(\n (p) =>\n p.type === 'text'\n ? { type: 'text', text: p.text }\n : {\n type: 'text',\n text: `See resource: ${p.title ?? p.uri}\\nURI: ${p.uri}`,\n } // simple way to reference; clients may fetch resources directly\n );\n\n return {\n messages: [{ role: 'assistant', content: contents[0]! }],\n description: prompt.meta.description,\n };\n }\n );\n }\n\n return server;\n}\n"],"mappings":"gbAgCA,SAAgB,EACd,EACA,EACA,EACA,EACA,EAeA,CAEA,IAAK,IAAM,KAAQ,EAAI,WAAW,CAAE,CAClC,GAAI,EAAK,KAAK,OAAS,UAAW,SAClC,GAAM,CAAE,SAAU,EAChB,EACD,CACK,EACJ,EAAK,WAAW,KAAK,UACrB,EAAe,EAAK,KAAK,KAAM,EA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AAC,EAIM,IACH,GACC,EAAE,OAAS,OACP,CAAE,KAAM,OAAQ,KAAM,EAAE,KAAM,CAC9B,CACE,KAAM,OACN,KAAM,iBAAiB,EAAE,OAAS,EAAE,IAAI,SAAS,EAAE,MACpD,CACR,CAGiD,GAAK,CAAC,CACxD,YAAa,EAAO,KAAK,YAC1B,EAEJ,CAGH,OAAO"}
|
|
1
|
+
{"version":3,"file":"provider-mcp.js","names":["z"],"sources":["../../src/server/provider-mcp.ts"],"sourcesContent":["import {\n McpServer,\n ResourceTemplate,\n} from '@modelcontextprotocol/sdk/server/mcp.js';\nimport type { SpecRegistry } from '../registry';\nimport type { ResourceRegistry } from '../resources';\nimport type { AnySchemaModel } from '@lssm/lib.schema';\nimport type { ContractSpec } from '../spec';\nimport type { PresentationRegistry } from '../presentations';\nimport { jsonSchemaForPresentation } from '../presentations';\nimport {\n createDefaultTransformEngine,\n type PresentationDescriptorV2,\n registerBasicValidation,\n registerDefaultReactRenderer,\n} from '../presentations.v2';\nimport type { PromptRegistry } from '../promptRegistry';\nimport type { HandlerCtx } from '../types';\nimport { defaultMcpTool, jsonSchemaForSpec } from '../jsonschema';\nimport type {\n CallToolResult,\n GetPromptResult,\n} from '@modelcontextprotocol/sdk/types.js';\nimport { zodToJsonSchema } from 'zod-to-json-schema';\nimport z from 'zod';\n\n/**\n * Creates a unified Model Context Protocol (MCP) server exposing operations, resources, and prompts.\n *\n * This function takes registries for operations, resources, and prompts, and exposes them as\n * MCP Tools, Resources, and Prompts respectively. It enables AI agents to discover and interact\n * with the application's capabilities.\n *\n * Features:\n * - **Tools**: Exposes `command` operations as executable tools.\n * - **Resources**: Exposes `ResourceRegistry` entries and `PresentationSpec`s (Markdown/JSON) as read-only resources.\n * - **Prompts**: Exposes `PromptRegistry` entries as templated prompts.\n *\n * @param server - The `McpServer` instance to populate.\n * @param ops - Registry containing operations (tools).\n * @param resources - Registry containing data resources.\n * @param prompts - Registry containing prompt templates.\n * @param ctxFactories - Factories to create context for tools, resources, and prompts execution.\n * @returns The populated `McpServer` instance.\n */\nexport function createMcpServer(\n server: McpServer,\n ops: SpecRegistry,\n resources: ResourceRegistry,\n prompts: PromptRegistry,\n ctxFactories: {\n /** Factory for tool execution context (e.g., system actor) */\n toolCtx: () => HandlerCtx;\n /** Factory for prompt rendering context */\n promptCtx: () => {\n userId?: string | null;\n orgId?: string | null;\n locale?: string;\n };\n /** Factory for resource resolution context */\n resourceCtx: () => {\n userId?: string | null;\n orgId?: string | null;\n locale?: string;\n };\n /** Optional registry for V1 presentations */\n presentations?: PresentationRegistry;\n /** Optional list of V2 presentation descriptors */\n presentationsV2?: PresentationDescriptorV2[];\n }\n) {\n /* ---------- Tools (commands) ---------- */\n for (const spec of ops.listSpecs()) {\n if (spec.meta.kind !== 'command') continue; // expose only commands as tools\n const { input } = jsonSchemaForSpec(\n spec as unknown as ContractSpec<AnySchemaModel, AnySchemaModel>\n );\n const toolName =\n spec.transport?.mcp?.toolName ??\n defaultMcpTool(spec.meta.name, spec.meta.version);\n\n server.registerTool(\n toolName,\n {\n // name: toolName,\n description: spec.meta.description,\n inputSchema: input as any,\n },\n async (args: any, _req: any): Promise<CallToolResult> => {\n const result = await ops.execute(\n spec.meta.name,\n spec.meta.version,\n args ?? {},\n ctxFactories.toolCtx()\n );\n // return { content: [{ type: 'json', json: result }] };\n return {\n content: [{ type: 'text', text: JSON.stringify(result, null, 4) }],\n };\n }\n );\n }\n\n /* ---------- Resources (queries/views) ---------- */\n for (const resource of resources.listTemplates()) {\n // server.registerPrompt(\n // 'review-code',\n // {\n // title: 'Code Review',\n // description: 'Review code for best practices and potential issues',\n // argsSchema: { code: z.string() as any },\n // },\n // ({ code }: { code?: string }) => ({\n // messages: [\n // {\n // role: 'user',\n // content: {\n // type: 'text',\n // text: `Please review this code:\\n\\n${code}`,\n // },\n // },\n // ],\n // })\n // );\n\n (server as any).registerResource(\n resource.meta.uriTemplate.split(':')[0]!,\n new ResourceTemplate(resource.meta.uriTemplate, {} as any),\n {\n // name: resource.meta.title,\n description: resource.meta.description,\n inputSchema: zodToJsonSchema(resource.input, {\n // metadata: `${op.meta.name}.input.v${op.meta.version}`,\n }),\n },\n async (_uri: any, args: any, _req: any) => {\n const ctx = ctxFactories.resourceCtx();\n const out = await resource.resolve(args, ctx);\n if (typeof out.data === 'string') {\n return {\n contents: [\n {\n uri: out.uri,\n mimeType: out.mimeType ?? resource.meta.mimeType,\n text: out.data,\n },\n ],\n };\n }\n return {\n contents: [\n {\n uri: out.uri,\n mimeType: out.mimeType ?? resource.meta.mimeType,\n blob: out.data.toString(),\n },\n ],\n };\n }\n );\n }\n\n /* ---------- Presentations as resources (markdown/data) with content negotiation ---------- */\n const __presentations = ctxFactories.presentations;\n const __presentationsV2 = ctxFactories.presentationsV2;\n if (__presentations) {\n const engine = registerBasicValidation(\n registerDefaultReactRenderer(createDefaultTransformEngine())\n );\n for (const p of __presentations.list()) {\n const baseKey = `presentation.${p.meta.name.replace(/\\./g, '_')}.v${p.meta.version}`;\n const baseUri = `presentation://${p.meta.name}/v${p.meta.version}`;\n\n // Generic metadata\n (server as any).registerResource(\n baseKey,\n new ResourceTemplate(baseUri, {} as any),\n {\n description: p.meta.description ?? 'Presentation',\n inputSchema: z.toJSONSchema(z.object({})),\n },\n async (_uri: any, _args: any, _req: any) => {\n if (p.content.kind === 'markdown') {\n const text = p.content.content\n ? p.content.content\n : `See resource: ${p.content.resourceUri ?? ''}`;\n return {\n contents: [\n {\n uri: baseUri,\n mimeType: 'text/markdown',\n text,\n },\n ],\n };\n }\n if (p.content.kind === 'data') {\n const schema = jsonSchemaForPresentation(p);\n return {\n contents: [\n {\n uri: baseUri,\n mimeType: 'application/json',\n text: JSON.stringify(schema, null, 2),\n },\n ],\n };\n }\n // web_component: metadata only for now\n const metaOnly = {\n name: p.meta.name,\n version: p.meta.version,\n kind: p.content.kind,\n description: p.meta.description ?? '',\n };\n return {\n contents: [\n {\n uri: baseUri,\n mimeType: 'application/json',\n text: JSON.stringify(metaOnly, null, 2),\n },\n ],\n };\n }\n );\n\n // Negotiated variants\n const variants: {\n ext: string;\n target: 'markdown' | 'application/json' | 'application/xml';\n }[] = [\n { ext: '.md', target: 'markdown' },\n { ext: '.json', target: 'application/json' },\n { ext: '.xml', target: 'application/xml' },\n ];\n for (const v of variants) {\n const key = `${baseKey}${v.ext}`;\n const uri = `${baseUri}${v.ext}`;\n (server as any).registerResource(\n key,\n new ResourceTemplate(uri, {} as any),\n {\n description: `${p.meta.description ?? 'Presentation'} (${v.ext})`,\n inputSchema: z.toJSONSchema(z.object({})),\n },\n async () => {\n // Use V2 engine to render a normalized JSON snapshot; if p is V1, fallback to jsonSchemaForPresentation\n if (p.content.kind === 'markdown' && v.target === 'markdown') {\n const text =\n p.content.content ??\n `See resource: ${p.content.resourceUri ?? ''}`;\n return { contents: [{ uri, mimeType: 'text/markdown', text }] };\n }\n if (p.content.kind === 'data' && v.target === 'application/json') {\n return {\n contents: [\n {\n uri,\n mimeType: 'application/json',\n text: JSON.stringify(jsonSchemaForPresentation(p), null, 2),\n },\n ],\n };\n }\n // Default: represent as JSON snapshot\n const jsonText = JSON.stringify(\n { meta: p.meta, content: p.content },\n null,\n 2\n );\n if (v.target === 'application/json') {\n return {\n contents: [\n { uri, mimeType: 'application/json', text: jsonText },\n ],\n };\n }\n if (v.target === 'application/xml') {\n const xml = `<presentation name=\"${p.meta.name}\" version=\"${p.meta.version}\"><json>${encodeURIComponent(jsonText)}</json></presentation>`;\n return {\n contents: [{ uri, mimeType: 'application/xml', text: xml }],\n };\n }\n // markdown fallback\n return {\n contents: [\n {\n uri,\n mimeType: 'text/markdown',\n text: 'Unsupported presentation for markdown',\n },\n ],\n };\n }\n );\n }\n }\n }\n\n // V2: register descriptors using transform engine (same scheme/negotiation)\n if (__presentationsV2 && __presentationsV2.length) {\n const engine = registerBasicValidation(\n registerDefaultReactRenderer(createDefaultTransformEngine())\n );\n for (const d of __presentationsV2) {\n const baseKey = `presentation.${d.meta.name.replace(/\\./g, '_')}.v${d.meta.version}`;\n const baseUri = `presentation://${d.meta.name}/v${d.meta.version}`;\n\n (server as any).registerResource(\n baseKey,\n new ResourceTemplate(baseUri, {} as any),\n {\n description: d.meta.description ?? 'Presentation',\n inputSchema: z.toJSONSchema(z.object({})),\n },\n async () => {\n const jsonText = JSON.stringify(\n { meta: d.meta, source: d.source, targets: d.targets },\n null,\n 2\n );\n return {\n contents: [\n { uri: baseUri, mimeType: 'application/json', text: jsonText },\n ],\n };\n }\n );\n\n const variants: {\n ext: string;\n target: 'markdown' | 'application/json' | 'application/xml';\n }[] = [\n { ext: '.md', target: 'markdown' },\n { ext: '.json', target: 'application/json' },\n { ext: '.xml', target: 'application/xml' },\n ];\n for (const v of variants) {\n const key = `${baseKey}${v.ext}`;\n const uri = `${baseUri}${v.ext}`;\n (server as any).registerResource(\n key,\n new ResourceTemplate(uri, {} as any),\n {\n description: `${d.meta.description ?? 'Presentation'} (${v.ext})`,\n inputSchema: z.toJSONSchema(z.object({})),\n },\n async () => {\n const out = await engine.render(v.target, d);\n return {\n contents: [\n {\n uri,\n mimeType:\n (out as any).mimeType ??\n (v.target === 'markdown' ? 'text/markdown' : v.target),\n text: (out as any).body ?? String(out),\n },\n ],\n };\n }\n );\n }\n }\n }\n\n /* ---------- Prompts ---------- */\n // for (const prompt of prompts.list()) {\n for (const prompt of prompts.list()) {\n server.registerPrompt(\n prompt.meta.name,\n {\n title: prompt.meta.title,\n description: prompt.meta.title,\n argsSchema: zodToJsonSchema(prompt.input) as any,\n },\n async (args: any, _extra: any): Promise<GetPromptResult> => {\n const link = (tpl: string, vars: Record<string, string | number>) => {\n let out = tpl;\n for (const [k, v] of Object.entries(vars))\n out = out.replace(\n new RegExp(`\\\\{${k}\\\\}`, 'g'),\n encodeURIComponent(String(v))\n );\n return out;\n };\n\n const parts = await prompt.render(prompt.input.parse(args), {\n ...ctxFactories.promptCtx(),\n link,\n });\n\n // MCP prompt shape: messages[{role, content[]}]; we return a single \"system\" text chunk + referenced resources\n const contents: GetPromptResult['messages'][number]['content'][] =\n parts.map(\n (p) =>\n p.type === 'text'\n ? { type: 'text', text: p.text }\n : {\n type: 'text',\n text: `See resource: ${p.title ?? p.uri}\\nURI: ${p.uri}`,\n } // simple way to reference; clients may fetch resources directly\n );\n\n return {\n messages: [{ role: 'assistant', content: contents[0]! }],\n description: prompt.meta.description,\n };\n }\n );\n }\n\n return server;\n}\n"],"mappings":"gbA6CA,SAAgB,EACd,EACA,EACA,EACA,EACA,EAoBA,CAEA,IAAK,IAAM,KAAQ,EAAI,WAAW,CAAE,CAClC,GAAI,EAAK,KAAK,OAAS,UAAW,SAClC,GAAM,CAAE,SAAU,EAChB,EACD,CACK,EACJ,EAAK,WAAW,KAAK,UACrB,EAAe,EAAK,KAAK,KAAM,EAAK,KAAK,QAAQ,CAEnD,EAAO,aACL,EACA,CAEE,YAAa,EAAK,KAAK,YACvB,YAAa,EACd,CACD,MAAO,EAAW,IAAuC,CACvD,IAAM,EAAS,MAAM,EAAI,QACvB,EAAK,KAAK,KACV,EAAK,KAAK,QACV,GAAQ,EAAE,CACV,EAAa,SAAS,CACvB,CAED,MAAO,CACL,QAAS,CAAC,CAAE,KAAM,OAAQ,KAAM,KAAK,UAAU,EAAQ,KAAM,EAAE,CAAE,CAAC,CACnE,EAEJ,CAIH,IAAK,IAAM,KAAY,EAAU,eAAe,CAqB7C,EAAe,iBACd,EAAS,KAAK,YAAY,MAAM,IAAI,CAAC,GACrC,IAAI,EAAiB,EAAS,KAAK,YAAa,EAAE,CAAQ,CAC1D,CAEE,YAAa,EAAS,KAAK,YAC3B,YAAa,EAAgB,EAAS,MAAO,EAE5C,CAAC,CACH,CACD,MAAO,EAAW,EAAW,IAAc,CACzC,IAAM,EAAM,EAAa,aAAa,CAChC,EAAM,MAAM,EAAS,QAAQ,EAAM,EAAI,CAY7C,OAXI,OAAO,EAAI,MAAS,SACf,CACL,SAAU,CACR,CACE,IAAK,EAAI,IACT,SAAU,EAAI,UAAY,EAAS,KAAK,SAC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O,KAAK,KACZ,CACE,MAAO,EAAO,KAAK,MACnB,YAAa,EAAO,KAAK,MACzB,WAAY,EAAgB,EAAO,MAAM,CAC1C,CACD,MAAO,EAAW,IAA0C,CAC1D,IAAM,GAAQ,EAAa,IAA0C,CACnE,IAAI,EAAM,EACV,IAAK,GAAM,CAAC,EAAG,KAAM,OAAO,QAAQ,EAAK,CACvC,EAAM,EAAI,QACJ,OAAO,MAAM,EAAE,KAAM,IAAI,CAC7B,mBAAmB,OAAO,EAAE,CAAC,CAC9B,CACH,OAAO,GAoBT,MAAO,CACL,SAAU,CAAC,CAAE,KAAM,YAAa,SAlBpB,MAAM,EAAO,OAAO,EAAO,MAAM,MAAM,EAAK,CAAE,CAC1D,GAAG,EAAa,WAAW,CAC3B,OACD,CAAC,EAIM,IACH,GACC,EAAE,OAAS,OACP,CAAE,KAAM,OAAQ,KAAM,EAAE,KAAM,CAC9B,CACE,KAAM,OACN,KAAM,iBAAiB,EAAE,OAAS,EAAE,IAAI,SAAS,EAAE,MACpD,CACR,CAGiD,GAAK,CAAC,CACxD,YAAa,EAAO,KAAK,YAC1B,EAEJ,CAGH,OAAO"}
|
|
@@ -5,10 +5,30 @@ import { RestOptions } from "./rest-generic.js";
|
|
|
5
5
|
//#region src/server/rest-next-app.d.ts
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
* app/api/[...all]/route.ts
|
|
8
|
+
* Creates a Next.js App Router route handler for ContractSpec operations.
|
|
10
9
|
*
|
|
11
|
-
*
|
|
10
|
+
* This function returns a handler suitable for `export const { GET, POST }` in a `route.ts` file.
|
|
11
|
+
* It handles:
|
|
12
|
+
* - Path parsing to determine the operation name and version.
|
|
13
|
+
* - Body parsing (JSON).
|
|
14
|
+
* - Context creation via `ctxFactory`.
|
|
15
|
+
* - Execution via `SpecRegistry`.
|
|
16
|
+
* - Response formatting (JSON success/error).
|
|
17
|
+
*
|
|
18
|
+
* @param reg - The SpecRegistry containing the operations.
|
|
19
|
+
* @param ctxFactory - A factory function to build the `HandlerCtx` (e.g., auth, tenant) from the request.
|
|
20
|
+
* @param options - Optional configuration for the REST handler.
|
|
21
|
+
* @returns A function `(req: Request) => Promise<Response>`.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* // app/api/[...route]/route.ts
|
|
26
|
+
* import { makeNextAppHandler } from '@lssm/lib.contracts/server/rest-next-app';
|
|
27
|
+
* import { registry } from '@/lib/registry';
|
|
28
|
+
*
|
|
29
|
+
* const handler = makeNextAppHandler(registry, (req) => ({ actor: 'anonymous' }));
|
|
30
|
+
* export { handler as GET, handler as POST };
|
|
31
|
+
* ```
|
|
12
32
|
*/
|
|
13
33
|
declare function makeNextAppHandler(reg: SpecRegistry, ctxFactory: (req: Request) => HandlerCtx, options?: RestOptions): (req: Request) => Promise<Response>;
|
|
14
34
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rest-next-app.d.ts","names":[],"sources":["../../src/server/rest-next-app.ts"],"sourcesContent":[],"mappings":";;;;;;;;
|
|
1
|
+
{"version":3,"file":"rest-next-app.d.ts","names":[],"sources":["../../src/server/rest-next-app.ts"],"sourcesContent":[],"mappings":";;;;;;;;AA8BA;;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,kBAAA,MACT,gCACa,YAAY,sBACpB,oBAGgC,YAAO,QAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rest-next-app.js","names":[],"sources":["../../src/server/rest-next-app.ts"],"sourcesContent":["import { createFetchHandler, type RestOptions } from './rest-generic';\nimport type { SpecRegistry } from '../registry';\nimport type { HandlerCtx } from '../types';\n\n/**\n *
|
|
1
|
+
{"version":3,"file":"rest-next-app.js","names":[],"sources":["../../src/server/rest-next-app.ts"],"sourcesContent":["import { createFetchHandler, type RestOptions } from './rest-generic';\nimport type { SpecRegistry } from '../registry';\nimport type { HandlerCtx } from '../types';\n\n/**\n * Creates a Next.js App Router route handler for ContractSpec operations.\n *\n * This function returns a handler suitable for `export const { GET, POST }` in a `route.ts` file.\n * It handles:\n * - Path parsing to determine the operation name and version.\n * - Body parsing (JSON).\n * - Context creation via `ctxFactory`.\n * - Execution via `SpecRegistry`.\n * - Response formatting (JSON success/error).\n *\n * @param reg - The SpecRegistry containing the operations.\n * @param ctxFactory - A factory function to build the `HandlerCtx` (e.g., auth, tenant) from the request.\n * @param options - Optional configuration for the REST handler.\n * @returns A function `(req: Request) => Promise<Response>`.\n *\n * @example\n * ```ts\n * // app/api/[...route]/route.ts\n * import { makeNextAppHandler } from '@lssm/lib.contracts/server/rest-next-app';\n * import { registry } from '@/lib/registry';\n *\n * const handler = makeNextAppHandler(registry, (req) => ({ actor: 'anonymous' }));\n * export { handler as GET, handler as POST };\n * ```\n */\nexport function makeNextAppHandler(\n reg: SpecRegistry,\n ctxFactory: (req: Request) => HandlerCtx,\n options?: RestOptions\n) {\n const handler = createFetchHandler(reg, ctxFactory, options);\n return async function requestHandler(req: Request) {\n return handler(req);\n };\n}\n"],"mappings":"uDA8BA,SAAgB,EACd,EACA,EACA,EACA,CACA,IAAM,EAAU,EAAmB,EAAK,EAAY,EAAQ,CAC5D,OAAO,eAA8B,EAAc,CACjD,OAAO,EAAQ,EAAI"}
|
package/dist/spec.d.ts
CHANGED
|
@@ -3,9 +3,13 @@ import { EventSpec } from "./events.js";
|
|
|
3
3
|
import { ResourceRefDescriptor } from "./resources.js";
|
|
4
4
|
import { PolicyRef } from "./policy/spec.js";
|
|
5
5
|
import { TestSpecRef } from "./tests/spec.js";
|
|
6
|
+
import { AnySchemaModel } from "@lssm/lib.schema";
|
|
6
7
|
|
|
7
8
|
//#region src/spec.d.ts
|
|
8
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Distinguishes between state-changing operations (command) and read-only operations (query).
|
|
12
|
+
*/
|
|
9
13
|
type OpKind = 'command' | 'query';
|
|
10
14
|
interface EmitDeclRef {
|
|
11
15
|
ref: EventSpec<AnySchemaModel>;
|
|
@@ -17,6 +21,10 @@ interface EmitDeclInline {
|
|
|
17
21
|
when: string;
|
|
18
22
|
payload: AnySchemaModel;
|
|
19
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Declaration of an event that an operation may emit.
|
|
26
|
+
* Can be a reference to an `EventSpec` or an inline definition.
|
|
27
|
+
*/
|
|
20
28
|
type EmitDecl = EmitDeclRef | EmitDeclInline;
|
|
21
29
|
declare const isEmitDeclRef: (e: EmitDecl) => e is EmitDeclRef;
|
|
22
30
|
interface TelemetryTrigger {
|
|
@@ -30,6 +38,13 @@ interface TelemetryTrigger {
|
|
|
30
38
|
error?: unknown;
|
|
31
39
|
}) => Record<string, unknown>;
|
|
32
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* The core specification interface for any operation (Command or Query).
|
|
43
|
+
*
|
|
44
|
+
* @template Input - The Zod-backed schema model for the input payload.
|
|
45
|
+
* @template Output - The Zod-backed schema model for the output payload, or a resource reference.
|
|
46
|
+
* @template Events - Tuple of events that this operation may emit.
|
|
47
|
+
*/
|
|
33
48
|
interface ContractSpec<Input extends AnySchemaModel, Output extends AnySchemaModel | ResourceRefDescriptor<boolean>, Events extends readonly EmitDecl[] | undefined = readonly EmitDecl[] | undefined> {
|
|
34
49
|
meta: {
|
|
35
50
|
/** Fully-qualified op name (e.g., "sigil.beginSignup") */
|
|
@@ -136,10 +151,18 @@ interface ContractSpec<Input extends AnySchemaModel, Output extends AnySchemaMod
|
|
|
136
151
|
};
|
|
137
152
|
}
|
|
138
153
|
type AnyContractSpec = ContractSpec<AnySchemaModel, AnySchemaModel | ResourceRefDescriptor<boolean>>;
|
|
154
|
+
/**
|
|
155
|
+
* Helper to define a Command (write operation).
|
|
156
|
+
* Sets `kind: 'command'` and defaults `idempotent: false`.
|
|
157
|
+
*/
|
|
139
158
|
declare const defineCommand: <I extends AnySchemaModel, O extends AnySchemaModel | ResourceRefDescriptor<boolean>, E extends readonly EmitDecl[] | undefined = undefined>(spec: Omit<ContractSpec<I, O, E>, "meta" | "policy"> & {
|
|
140
159
|
meta: Omit<ContractSpec<I, O, E>["meta"], "kind">;
|
|
141
160
|
policy: Omit<ContractSpec<I, O, E>["policy"], "idempotent">;
|
|
142
161
|
}) => ContractSpec<I, O, E>;
|
|
162
|
+
/**
|
|
163
|
+
* Helper to define a Query (read-only operation).
|
|
164
|
+
* Sets `kind: 'query'` and forces `idempotent: true`.
|
|
165
|
+
*/
|
|
143
166
|
declare const defineQuery: <I extends AnySchemaModel, O extends AnySchemaModel | ResourceRefDescriptor<boolean>, E extends readonly EmitDecl[] | undefined = undefined>(spec: Omit<ContractSpec<I, O, E>, "meta" | "policy"> & {
|
|
144
167
|
meta: Omit<ContractSpec<I, O, E>["meta"], "kind">;
|
|
145
168
|
policy: Omit<ContractSpec<I, O, E>["policy"], "idempotent">;
|
package/dist/spec.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spec.d.ts","names":[],"sources":["../src/spec.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"spec.d.ts","names":[],"sources":["../src/spec.ts"],"sourcesContent":[],"mappings":";;;;;;;;;AAsBA;AAUA;AACA;AAEiB,KArBL,MAAA,GAqBK,SAAgB,GAAA,OAMzB;AAUS,UAlCA,WAAA,CAkCY;EACb,GAAA,EAlCT,SAkCS,CAlCC,cAkCD,CAAA;EACC,IAAA,EAAA,MAAA;;AACS,UAhCT,cAAA,CAgCS;EACX,IAAA,EAAA,MAAA;EASL,OAAA,EAAA,MAAA;EAEK,IAAA,EAAA,MAAA;EAEH,OAAA,EA1CD,cA0CC;;;;;;AA+CG,KAnFH,QAAA,GAAW,WAmFR,GAnFsB,cAmFtB;AAMH,cAxFC,aAwFD,EAAA,CAAA,CAAA,EAxFqB,QAwFrB,EAAA,GAAA,CAAA,IAxFqC,WAwFrC;AAQE,UA9FG,gBAAA,CA8FH;EACA,KAAA,EAAA;IAGJ,IAAA,EAAA,MAAA;IAAW,OA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ApGA;;;;;eAKA;;;;;YAMH;;;;;;;cAQE;cACA;;UAGJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAmCE,eAAA,GAAkB,aAC5B,gBACA,iBAAiB;;;;;cAON,0BACD,0BACA,iBAAiB,mDACR,0CAEb,KAAK,aAAa,GAAG,GAAG;QACtB,KAAK,aAAa,GAAG,GAAG;UACtB,KAAK,aAAa,GAAG,GAAG;MAEjC,aAAa,GAAG,GAAG;;;;;cAeT,wBACD,0BACA,iBAAiB,mDACR,0CAEb,KAAK,aAAa,GAAG,GAAG;QACtB,KAAK,aAAa,GAAG,GAAG;UACtB,KAAK,aAAa,GAAG,GAAG;MAEjC,aAAa,GAAG,GAAG"}
|
package/dist/spec.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spec.js","names":[],"sources":["../src/spec.ts"],"sourcesContent":["/**\n * ContractSpec: a single source of truth describing one operation (command/query).\n * It carries narrative context for humans/agents AND machine-typed input/output/policy.\n */\nimport type { EventSpec } from './events';\nimport type { AnySchemaModel } from '@lssm/lib.schema';\nimport type { ResourceRefDescriptor } from './resources';\nimport type { Owner, Stability, Tag } from './ownership';\nimport type { PolicyRef } from './policy/spec';\nimport type { TestSpecRef } from './tests/spec';\n\nexport type OpKind = 'command' | 'query';\n\n// preferred: reference a declared event\nexport interface EmitDeclRef {\n ref: EventSpec<AnySchemaModel>;\n when: string;\n}\n// inline (fallback)\nexport interface EmitDeclInline {\n name: string;\n version: number;\n when: string;\n payload: AnySchemaModel;\n}\nexport type EmitDecl = EmitDeclRef | EmitDeclInline;\nexport const isEmitDeclRef = (e: EmitDecl): e is EmitDeclRef => 'ref' in e;\n\nexport interface TelemetryTrigger {\n event: { name: string; version?: number };\n properties?: (args: {\n input: unknown;\n output?: unknown;\n error?: unknown;\n }) => Record<string, unknown>;\n}\n\nexport interface ContractSpec<\n Input extends AnySchemaModel,\n Output extends AnySchemaModel | ResourceRefDescriptor<boolean>,\n Events extends readonly EmitDecl[] | undefined =\n | readonly EmitDecl[]\n | undefined,\n> {\n meta: {\n /** Fully-qualified op name (e.g., \"sigil.beginSignup\") */\n name: string;\n /** Breaking changes => bump version */\n version: number;\n /** \"command\" changes state; \"query\" is read-only/idempotent */\n kind: OpKind;\n /** Lifecycle marker for comms & tooling */\n stability: Stability;\n /** Owners for CODEOWNERS / on-call / approvals */\n owners: Owner[];\n /** Search tags, grouping, docs navigation */\n tags: Tag[];\n /** Short human-friendly summary */\n description: string;\n /** Business goal: why this exists */\n goal: string;\n /** Background, constraints, scope edges (feeds docs & LLM context) */\n context: string;\n };\n\n io: {\n /** Zod schema for input payload */\n input: Input | null;\n /** Zod schema for output payload */\n output: Output;\n /** Named, typed errors this op may throw (optional) */\n errors?: Record<\n string,\n {\n description: string;\n http?: number; // suggested HTTP status if surfaced over REST\n gqlCode?: string; // suggested GraphQL error code\n when: string; // human-readable condition\n }\n >;\n };\n\n policy: {\n /** Minimal auth category allowed to call this op */\n auth: 'anonymous' | 'user' | 'admin';\n /** Idempotency hint. Queries default true; commands default false. */\n idempotent?: boolean;\n /** Soft rate limit suggestion; adapter enforces via limiter */\n rateLimit?: { rpm: number; key: 'user' | 'org' | 'global' };\n /** Feature flags that must be ON for this op to run */\n flags?: string[];\n /** Whether a human must approve before action (e.g., risky commands) */\n escalate?: 'human_review' | null;\n /** JSONPath-like pointers to redact from logs/prompts */\n pii?: string[];\n /** Referenced policy specs governing access */\n policies?: PolicyRef[];\n /** Field-level overrides referencing policy specs */\n fieldPolicies?: {\n field: string;\n actions: ('read' | 'write')[];\n policy?: PolicyRef;\n }[];\n };\n\n sideEffects?: {\n /** Declared events this op may emit; runtime will guard against others */\n emits?: Events;\n /** Analytics intents (names); the service decides the sink */\n analytics?: string[];\n /** Audit intents (labels); the service decides storage */\n audit?: string[];\n };\n\n telemetry?: {\n success?: TelemetryTrigger;\n failure?: TelemetryTrigger;\n };\n\n tests?: TestSpecRef[];\n\n transport?: {\n rest?: {\n /** Override HTTP method (default: POST for commands, GET for queries) */\n method?: 'GET' | 'POST';\n /** Override path (default derived from meta.name/version) */\n path?: string;\n };\n gql?: {\n /** Override field name (default: dots→underscores + _vN) */\n field?: string;\n returns?: string;\n // byIdField?: string;\n // resource?: string;\n };\n mcp?: {\n /** Override tool identifier (default: \"<name>.v<version>\") */\n toolName?: string;\n };\n };\n\n acceptance?: {\n /** Gherkin-lite scenarios for docs & auto tests */\n scenarios?: {\n name: string;\n given: string[];\n when: string[];\n then: string[];\n }[];\n /** Request/response examples (used for docs & snapshot tests) */\n examples?: { name: string; input: unknown; output: unknown }[];\n };\n}\n\nexport type AnyContractSpec = ContractSpec<\n AnySchemaModel,\n AnySchemaModel | ResourceRefDescriptor<boolean>\n>;\n\nexport const defineCommand = <\n I extends AnySchemaModel,\n O extends AnySchemaModel | ResourceRefDescriptor<boolean>,\n E extends readonly EmitDecl[] | undefined = undefined,\n>(\n spec: Omit<ContractSpec<I, O, E>, 'meta' | 'policy'> & {\n meta: Omit<ContractSpec<I, O, E>['meta'], 'kind'>;\n policy: Omit<ContractSpec<I, O, E>['policy'], 'idempotent'>;\n }\n): ContractSpec<I, O, E> => ({\n ...spec,\n meta: { ...spec.meta, kind: 'command' as const },\n policy: {\n ...spec.policy,\n idempotent:\n (spec.policy as never as ContractSpec<never, never, never>)?.['policy']\n ?.idempotent ?? false,\n },\n});\n\nexport const defineQuery = <\n I extends AnySchemaModel,\n O extends AnySchemaModel | ResourceRefDescriptor<boolean>,\n E extends readonly EmitDecl[] | undefined = undefined,\n>(\n spec: Omit<ContractSpec<I, O, E>, 'meta' | 'policy'> & {\n meta: Omit<ContractSpec<I, O, E>['meta'], 'kind'>;\n policy: Omit<ContractSpec<I, O, E>['policy'], 'idempotent'>;\n }\n): ContractSpec<I, O, E> => ({\n ...spec,\n meta: { ...spec.meta, kind: 'query' as const },\n policy: { ...spec.policy, idempotent: true },\n});\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"spec.js","names":[],"sources":["../src/spec.ts"],"sourcesContent":["/**\n * ContractSpec: a single source of truth describing one operation (command/query).\n * It carries narrative context for humans/agents AND machine-typed input/output/policy.\n */\nimport type { EventSpec } from './events';\nimport type { AnySchemaModel } from '@lssm/lib.schema';\nimport type { ResourceRefDescriptor } from './resources';\nimport type { Owner, Stability, Tag } from './ownership';\nimport type { PolicyRef } from './policy/spec';\nimport type { TestSpecRef } from './tests/spec';\n\n/**\n * Distinguishes between state-changing operations (command) and read-only operations (query).\n */\nexport type OpKind = 'command' | 'query';\n\n// preferred: reference a declared event\nexport interface EmitDeclRef {\n ref: EventSpec<AnySchemaModel>;\n when: string;\n}\n// inline (fallback)\nexport interface EmitDeclInline {\n name: string;\n version: number;\n when: string;\n payload: AnySchemaModel;\n}\n/**\n * Declaration of an event that an operation may emit.\n * Can be a reference to an `EventSpec` or an inline definition.\n */\nexport type EmitDecl = EmitDeclRef | EmitDeclInline;\nexport const isEmitDeclRef = (e: EmitDecl): e is EmitDeclRef => 'ref' in e;\n\nexport interface TelemetryTrigger {\n event: { name: string; version?: number };\n properties?: (args: {\n input: unknown;\n output?: unknown;\n error?: unknown;\n }) => Record<string, unknown>;\n}\n\n/**\n * The core specification interface for any operation (Command or Query).\n *\n * @template Input - The Zod-backed schema model for the input payload.\n * @template Output - The Zod-backed schema model for the output payload, or a resource reference.\n * @template Events - Tuple of events that this operation may emit.\n */\nexport interface ContractSpec<\n Input extends AnySchemaModel,\n Output extends AnySchemaModel | ResourceRefDescriptor<boolean>,\n Events extends readonly EmitDecl[] | undefined =\n | readonly EmitDecl[]\n | undefined,\n> {\n meta: {\n /** Fully-qualified op name (e.g., \"sigil.beginSignup\") */\n name: string;\n /** Breaking changes => bump version */\n version: number;\n /** \"command\" changes state; \"query\" is read-only/idempotent */\n kind: OpKind;\n /** Lifecycle marker for comms & tooling */\n stability: Stability;\n /** Owners for CODEOWNERS / on-call / approvals */\n owners: Owner[];\n /** Search tags, grouping, docs navigation */\n tags: Tag[];\n /** Short human-friendly summary */\n description: string;\n /** Business goal: why this exists */\n goal: string;\n /** Background, constraints, scope edges (feeds docs & LLM context) */\n context: string;\n };\n\n io: {\n /** Zod schema for input payload */\n input: Input | null;\n /** Zod schema for output payload */\n output: Output;\n /** Named, typed errors this op may throw (optional) */\n errors?: Record<\n string,\n {\n description: string;\n http?: number; // suggested HTTP status if surfaced over REST\n gqlCode?: string; // suggested GraphQL error code\n when: string; // human-readable condition\n }\n >;\n };\n\n policy: {\n /** Minimal auth category allowed to call this op */\n auth: 'anonymous' | 'user' | 'admin';\n /** Idempotency hint. Queries default true; commands default false. */\n idempotent?: boolean;\n /** Soft rate limit suggestion; adapter enforces via limiter */\n rateLimit?: { rpm: number; key: 'user' | 'org' | 'global' };\n /** Feature flags that must be ON for this op to run */\n flags?: string[];\n /** Whether a human must approve before action (e.g., risky commands) */\n escalate?: 'human_review' | null;\n /** JSONPath-like pointers to redact from logs/prompts */\n pii?: string[];\n /** Referenced policy specs governing access */\n policies?: PolicyRef[];\n /** Field-level overrides referencing policy specs */\n fieldPolicies?: {\n field: string;\n actions: ('read' | 'write')[];\n policy?: PolicyRef;\n }[];\n };\n\n sideEffects?: {\n /** Declared events this op may emit; runtime will guard against others */\n emits?: Events;\n /** Analytics intents (names); the service decides the sink */\n analytics?: string[];\n /** Audit intents (labels); the service decides storage */\n audit?: string[];\n };\n\n telemetry?: {\n success?: TelemetryTrigger;\n failure?: TelemetryTrigger;\n };\n\n tests?: TestSpecRef[];\n\n transport?: {\n rest?: {\n /** Override HTTP method (default: POST for commands, GET for queries) */\n method?: 'GET' | 'POST';\n /** Override path (default derived from meta.name/version) */\n path?: string;\n };\n gql?: {\n /** Override field name (default: dots→underscores + _vN) */\n field?: string;\n returns?: string;\n // byIdField?: string;\n // resource?: string;\n };\n mcp?: {\n /** Override tool identifier (default: \"<name>.v<version>\") */\n toolName?: string;\n };\n };\n\n acceptance?: {\n /** Gherkin-lite scenarios for docs & auto tests */\n scenarios?: {\n name: string;\n given: string[];\n when: string[];\n then: string[];\n }[];\n /** Request/response examples (used for docs & snapshot tests) */\n examples?: { name: string; input: unknown; output: unknown }[];\n };\n}\n\nexport type AnyContractSpec = ContractSpec<\n AnySchemaModel,\n AnySchemaModel | ResourceRefDescriptor<boolean>\n>;\n\n/**\n * Helper to define a Command (write operation).\n * Sets `kind: 'command'` and defaults `idempotent: false`.\n */\nexport const defineCommand = <\n I extends AnySchemaModel,\n O extends AnySchemaModel | ResourceRefDescriptor<boolean>,\n E extends readonly EmitDecl[] | undefined = undefined,\n>(\n spec: Omit<ContractSpec<I, O, E>, 'meta' | 'policy'> & {\n meta: Omit<ContractSpec<I, O, E>['meta'], 'kind'>;\n policy: Omit<ContractSpec<I, O, E>['policy'], 'idempotent'>;\n }\n): ContractSpec<I, O, E> => ({\n ...spec,\n meta: { ...spec.meta, kind: 'command' as const },\n policy: {\n ...spec.policy,\n idempotent:\n (spec.policy as never as ContractSpec<never, never, never>)?.['policy']\n ?.idempotent ?? false,\n },\n});\n\n/**\n * Helper to define a Query (read-only operation).\n * Sets `kind: 'query'` and forces `idempotent: true`.\n */\nexport const defineQuery = <\n I extends AnySchemaModel,\n O extends AnySchemaModel | ResourceRefDescriptor<boolean>,\n E extends readonly EmitDecl[] | undefined = undefined,\n>(\n spec: Omit<ContractSpec<I, O, E>, 'meta' | 'policy'> & {\n meta: Omit<ContractSpec<I, O, E>['meta'], 'kind'>;\n policy: Omit<ContractSpec<I, O, E>['policy'], 'idempotent'>;\n }\n): ContractSpec<I, O, E> => ({\n ...spec,\n meta: { ...spec.meta, kind: 'query' as const },\n policy: { ...spec.policy, idempotent: true },\n});\n"],"mappings":"AAiCA,MAAa,EAAiB,GAAkC,QAAS,EAgJ5D,EAKX,IAI2B,CAC3B,GAAG,EACH,KAAM,CAAE,GAAG,EAAK,KAAM,KAAM,UAAoB,CAChD,OAAQ,CACN,GAAG,EAAK,OACR,WACG,EAAK,QAAwD,QAC1D,YAAc,GACrB,CACF,EAMY,EAKX,IAI2B,CAC3B,GAAG,EACH,KAAM,CAAE,GAAG,EAAK,KAAM,KAAM,QAAkB,CAC9C,OAAQ,CAAE,GAAG,EAAK,OAAQ,WAAY,GAAM,CAC7C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anomaly.js","names":[],"sources":["../../src/telemetry/anomaly.ts"],"sourcesContent":["import type { TelemetryDispatch } from './tracker';\nimport type { TelemetryAnomalyDetectionConfig } from './spec';\n\nexport interface TelemetryAnomalyEvent {\n dispatch: TelemetryDispatch;\n threshold: TelemetryAnomalyDetectionConfig;\n metric: string;\n value: number | undefined;\n type: 'min' | 'max';\n}\n\nexport interface TelemetryAnomalyMonitorOptions {\n onAnomaly?: (event: TelemetryAnomalyEvent) => void;\n now?: () => Date;\n}\n\nexport class TelemetryAnomalyMonitor {\n private readonly onAnomaly?: (event: TelemetryAnomalyEvent) => void;\n private readonly now: () => Date;\n private readonly samples = new Map<string, number>();\n\n constructor(options: TelemetryAnomalyMonitorOptions = {}) {\n this.onAnomaly = options.onAnomaly;\n this.now = options.now ?? (() => new Date());\n }\n\n observe(dispatch: TelemetryDispatch) {\n const anomalyConfig = dispatch.definition.anomalyDetection;\n if (!anomalyConfig?.enabled) return;\n if (!anomalyConfig.thresholds?.length) return;\n\n const eventKey = `${dispatch.name}.v${dispatch.version}`;\n const count = this.samples.get(eventKey) ?? 0;\n const newCount = count + 1;\n this.samples.set(eventKey, newCount);\n\n if (\n typeof anomalyConfig.minimumSample === 'number' &&\n newCount < anomalyConfig.minimumSample\n ) {\n return;\n }\n\n for (const threshold of anomalyConfig.thresholds) {\n const value = this.extractMetric(dispatch, threshold.metric);\n if (typeof value !== 'number') continue;\n if (typeof threshold.min === 'number' && value < threshold.min) {\n this.emit(dispatch, anomalyConfig, threshold.metric, value, 'min');\n }\n if (typeof threshold.max === 'number' && value > threshold.max) {\n this.emit(dispatch, anomalyConfig, threshold.metric, value, 'max');\n }\n }\n }\n\n private extractMetric(dispatch: TelemetryDispatch, metric: string) {\n const value = dispatch.properties[metric];\n if (typeof value === 'number') return value;\n if (typeof value === 'object' && value !== null && 'value' in value) {\n const maybeNumber = (value as Record<string, unknown>).value;\n return typeof maybeNumber === 'number' ? maybeNumber : undefined;\n }\n return undefined;\n }\n\n private emit(\n dispatch: TelemetryDispatch,\n threshold: TelemetryAnomalyDetectionConfig,\n metric: string,\n value: number,\n type: 'min' | 'max'\n ) {\n this.onAnomaly?.({\n dispatch,\n threshold,\n metric,\n value,\n type,\n });\n }\n\n reset() {\n this.samples.clear();\n }\n}\n
|
|
1
|
+
{"version":3,"file":"anomaly.js","names":[],"sources":["../../src/telemetry/anomaly.ts"],"sourcesContent":["import type { TelemetryDispatch } from './tracker';\nimport type { TelemetryAnomalyDetectionConfig } from './spec';\n\nexport interface TelemetryAnomalyEvent {\n dispatch: TelemetryDispatch;\n threshold: TelemetryAnomalyDetectionConfig;\n metric: string;\n value: number | undefined;\n type: 'min' | 'max';\n}\n\nexport interface TelemetryAnomalyMonitorOptions {\n onAnomaly?: (event: TelemetryAnomalyEvent) => void;\n now?: () => Date;\n}\n\nexport class TelemetryAnomalyMonitor {\n private readonly onAnomaly?: (event: TelemetryAnomalyEvent) => void;\n private readonly now: () => Date;\n private readonly samples = new Map<string, number>();\n\n constructor(options: TelemetryAnomalyMonitorOptions = {}) {\n this.onAnomaly = options.onAnomaly;\n this.now = options.now ?? (() => new Date());\n }\n\n observe(dispatch: TelemetryDispatch) {\n const anomalyConfig = dispatch.definition.anomalyDetection;\n if (!anomalyConfig?.enabled) return;\n if (!anomalyConfig.thresholds?.length) return;\n\n const eventKey = `${dispatch.name}.v${dispatch.version}`;\n const count = this.samples.get(eventKey) ?? 0;\n const newCount = count + 1;\n this.samples.set(eventKey, newCount);\n\n if (\n typeof anomalyConfig.minimumSample === 'number' &&\n newCount < anomalyConfig.minimumSample\n ) {\n return;\n }\n\n for (const threshold of anomalyConfig.thresholds) {\n const value = this.extractMetric(dispatch, threshold.metric);\n if (typeof value !== 'number') continue;\n if (typeof threshold.min === 'number' && value < threshold.min) {\n this.emit(dispatch, anomalyConfig, threshold.metric, value, 'min');\n }\n if (typeof threshold.max === 'number' && value > threshold.max) {\n this.emit(dispatch, anomalyConfig, threshold.metric, value, 'max');\n }\n }\n }\n\n private extractMetric(dispatch: TelemetryDispatch, metric: string) {\n const value = dispatch.properties[metric];\n if (typeof value === 'number') return value;\n if (typeof value === 'object' && value !== null && 'value' in value) {\n const maybeNumber = (value as Record<string, unknown>).value;\n return typeof maybeNumber === 'number' ? maybeNumber : undefined;\n }\n return undefined;\n }\n\n private emit(\n dispatch: TelemetryDispatch,\n threshold: TelemetryAnomalyDetectionConfig,\n metric: string,\n value: number,\n type: 'min' | 'max'\n ) {\n this.onAnomaly?.({\n dispatch,\n threshold,\n metric,\n value,\n type,\n });\n }\n\n reset() {\n this.samples.clear();\n }\n}\n"],"mappings":"AAgBA,IAAa,EAAb,KAAqC,CACnC,UACA,IACA,QAA2B,IAAI,IAE/B,YAAY,EAA0C,EAAE,CAAE,CACxD,KAAK,UAAY,EAAQ,UACzB,KAAK,IAAM,EAAQ,UAAc,IAAI,MAGvC,QAAQ,EAA6B,CACnC,IAAM,EAAgB,EAAS,WAAW,iBAE1C,GADI,CAAC,GAAe,SAChB,CAAC,EAAc,YAAY,OAAQ,OAEvC,IAAM,EAAW,GAAG,EAAS,KAAK,IAAI,EAAS,UAEzC,GADQ,KAAK,QAAQ,IAAI,EAAS,EAAI,GACnB,EACzB,QAAK,QAAQ,IAAI,EAAU,EAAS,CAGlC,SAAO,EAAc,eAAkB,UACvC,EAAW,EAAc,eAK3B,IAAK,IAAM,KAAa,EAAc,WAAY,CAChD,IAAM,EAAQ,KAAK,cAAc,EAAU,EAAU,OAAO,CACxD,OAAO,GAAU,WACjB,OAAO,EAAU,KAAQ,UAAY,EAAQ,EAAU,KACzD,KAAK,KAAK,EAAU,EAAe,EAAU,OAAQ,EAAO,MAAM,CAEhE,OAAO,EAAU,KAAQ,UAAY,EAAQ,EAAU,KACzD,KAAK,KAAK,EAAU,EAAe,EAAU,OAAQ,EAAO,MAAM,GAKxE,cAAsB,EAA6B,EAAgB,CACjE,IAAM,EAAQ,EAAS,WAAW,GAClC,GAAI,OAAO,GAAU,SAAU,OAAO,EACtC,GAAI,OAAO,GAAU,UAAY,GAAkB,UAAW,EAAO,CACnE,IAAM,EAAe,EAAkC,MACvD,OAAO,OAAO,GAAgB,SAAW,EAAc,IAAA,IAK3D,KACE,EACA,EACA,EACA,EACA,EACA,CACA,KAAK,YAAY,CACf,WACA,YACA,SACA,QACA,OACD,CAAC,CAGJ,OAAQ,CACN,KAAK,QAAQ,OAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spec.d.ts","names":[],"sources":["../../src/telemetry/spec.ts"],"sourcesContent":[],"mappings":";;;KAGY,qBAAA;
|
|
1
|
+
{"version":3,"file":"spec.d.ts","names":[],"sources":["../../src/telemetry/spec.ts"],"sourcesContent":[],"mappings":";;;KAGY,qBAAA;UAEK,aAAA,SAAsB;EAF3B;EAEK,IAAA,EAAA,MAAA;EASA;EAQA,OAAA,EAAA,MAAA;EAML;EAEK,MAAA,EAAA,MAAA;AAWjB;AAKiB,UAhCA,oBAAA,CAgCwB;EAKxB,IAAA,EAAA,QAAA,GAAA,QAAiB,GAAA,SAAA,GAAA,WAAA,GAAA,MAAA;EAYL,QAAA,CAAA,EAAA,OAAA;EAAf,GAAA,CAAA,EAAA,OAAA;EAEH,MAAA,CAAA,EAAA,OAAA;EAEG,WAAA,CAAA,EAAA,MAAA;;AAIO,UAjDJ,yBAAA,CAiDI;EAA+B,MAAA,EAAA,MAAA;EAKnC,GAAA,CAAA,EAAA,MAAA;EAKA,GAAA,CAAA,EAAA,MAAA;AAUjB;AACQ,KAhEI,sBAAA,GAgEJ,OAAA,GAAA,KAAA,GAAA,eAAA;AACE,UA/DO,+BAAA,CA+DP;EACC,OAAA,EAAA,OAAA;EAAe,UAAA,CAAA,EA9DX,yBA8DW,EAAA;EAKb,OAAA,CAAA,EAlED,sBAkEkB,EAAA;EAKb;;;;EAmDkC,aAAA,CAAA,EAAA,MAAA;;AAmBnC,UArIC,uBAAA,CAqIsB;;;;UAhItB,wBAAA;;;;UAKA,iBAAA;;;;;;;;;;;;cAYH,eAAe;;WAElB;;cAEG;;aAED;;qBAEQ;;;;UAKJ,uBAAA;;UAEP;;UAGO,eAAA;;;cAGH;;;;;;UAOG,aAAA;QACT;UACE;WACC;;cAKE,iBAAA;;;;iBAKI;UAaP;uCAI6B;gDAgBS;mDAkBG;;iBAmBnC,gBAAA,OAAuB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spec.js","names":["latest: TelemetrySpec | undefined","latest: TelemetryEventDef | undefined"],"sources":["../../src/telemetry/spec.ts"],"sourcesContent":["import type { OwnerShipMeta } from '../ownership';\nimport type { EventKey } from '../events';\n\nexport type TelemetryPrivacyLevel
|
|
1
|
+
{"version":3,"file":"spec.js","names":["latest: TelemetrySpec | undefined","latest: TelemetryEventDef | undefined"],"sources":["../../src/telemetry/spec.ts"],"sourcesContent":["import type { OwnerShipMeta } from '../ownership';\nimport type { EventKey } from '../events';\n\nexport type TelemetryPrivacyLevel = 'public' | 'internal' | 'pii' | 'sensitive';\n\nexport interface TelemetryMeta extends OwnerShipMeta {\n /** Fully-qualified telemetry spec name (e.g., \"sigil.core\"). */\n name: string;\n /** Incremented when telemetry definitions change in a breaking way. */\n version: number;\n /** Optional domain or bounded-context hint (e.g., \"onboarding\"). */\n domain: string;\n}\n\nexport interface TelemetryPropertyDef {\n type: 'string' | 'number' | 'boolean' | 'timestamp' | 'json';\n required?: boolean;\n pii?: boolean;\n redact?: boolean;\n description?: string;\n}\n\nexport interface TelemetryAnomalyThreshold {\n metric: string;\n min?: number;\n max?: number;\n}\n\nexport type TelemetryAnomalyAction = 'alert' | 'log' | 'trigger_regen';\n\nexport interface TelemetryAnomalyDetectionConfig {\n enabled: boolean;\n thresholds?: TelemetryAnomalyThreshold[];\n actions?: TelemetryAnomalyAction[];\n /**\n * Minimum sample size before evaluating thresholds.\n * Helps avoid false positives on small sample sizes.\n */\n minimumSample?: number;\n}\n\nexport interface TelemetrySamplingConfig {\n rate: number;\n conditions?: string[];\n}\n\nexport interface TelemetryRetentionConfig {\n days: number;\n policy?: 'archive' | 'delete';\n}\n\nexport interface TelemetryEventDef {\n /** Name of the event (should match EventSpec.name for cross-reference). */\n name: string;\n /** Version of the underlying event. */\n version: number;\n /** High-level semantics for docs/analyzers. */\n semantics: {\n who?: string;\n what: string;\n why?: string;\n };\n /** Detailed property metadata keyed by property name. */\n properties: Record<string, TelemetryPropertyDef>;\n /** Privacy level for the entire event. */\n privacy: TelemetryPrivacyLevel;\n /** Retention policy overrides. */\n retention?: TelemetryRetentionConfig;\n /** Sampling rules, defaulting to spec.config defaults. */\n sampling?: TelemetrySamplingConfig;\n /** Anomaly detection overrides. */\n anomalyDetection?: TelemetryAnomalyDetectionConfig;\n /** Optional tags for analytics/AI hints. */\n tags?: string[];\n}\n\nexport interface TelemetryProviderConfig {\n type: 'posthog' | 'segment' | 'opentelemetry' | 'internal';\n config: Record<string, unknown>;\n}\n\nexport interface TelemetryConfig {\n defaultRetentionDays?: number;\n defaultSamplingRate?: number;\n providers?: TelemetryProviderConfig[];\n anomalyDetection?: {\n enabled: boolean;\n checkIntervalMs?: number;\n };\n}\n\nexport interface TelemetrySpec {\n meta: TelemetryMeta;\n events: TelemetryEventDef[];\n config?: TelemetryConfig;\n}\n\nconst telemetryKey = (meta: TelemetryMeta) => `${meta.name}.v${meta.version}`;\n\nexport class TelemetryRegistry {\n private readonly items = new Map<string, TelemetrySpec>();\n private readonly eventsByKey = new Map<EventKey, TelemetryEventDef>();\n private readonly specByEventKey = new Map<EventKey, TelemetrySpec>();\n\n register(spec: TelemetrySpec): this {\n const key = telemetryKey(spec.meta);\n if (this.items.has(key)) {\n throw new Error(`Duplicate TelemetrySpec registration for ${key}`);\n }\n this.items.set(key, spec);\n for (const event of spec.events) {\n this.eventsByKey.set(`${event.name}.v${event.version}`, event);\n this.specByEventKey.set(`${event.name}.v${event.version}`, spec);\n }\n return this;\n }\n\n list(): TelemetrySpec[] {\n return [...this.items.values()];\n }\n\n get(name: string, version?: number): TelemetrySpec | undefined {\n if (version != null) {\n return this.items.get(`${name}.v${version}`);\n }\n let latest: TelemetrySpec | undefined;\n let maxVersion = -Infinity;\n for (const item of this.items.values()) {\n if (item.meta.name !== name) continue;\n if (item.meta.version > maxVersion) {\n maxVersion = item.meta.version;\n latest = item;\n }\n }\n return latest;\n }\n\n findEventDef(name: string, version?: number): TelemetryEventDef | undefined {\n if (version != null) {\n return this.eventsByKey.get(`${name}.v${version}`);\n }\n let latest: TelemetryEventDef | undefined;\n let maxVersion = -Infinity;\n for (const [key, event] of this.eventsByKey.entries()) {\n const [eventName, versionPart] = key.split('.v');\n if (eventName !== name) continue;\n const ver = Number(versionPart);\n if (Number.isFinite(ver) && ver > maxVersion) {\n maxVersion = ver;\n latest = event;\n }\n }\n return latest;\n }\n\n getSpecForEvent(name: string, version?: number): TelemetrySpec | undefined {\n if (version != null) {\n return this.specByEventKey.get(`${name}.v${version}`);\n }\n let latest: TelemetrySpec | undefined;\n let maxVersion = -Infinity;\n for (const [key, spec] of this.specByEventKey.entries()) {\n const [eventName, versionPart] = key.split('.v');\n if (eventName !== name) continue;\n const ver = Number(versionPart);\n if (Number.isFinite(ver) && ver > maxVersion) {\n maxVersion = ver;\n latest = spec;\n }\n }\n return latest;\n }\n}\n\nexport function makeTelemetryKey(meta: TelemetryMeta) {\n return telemetryKey(meta);\n}\n"],"mappings":"AAiGA,MAAM,EAAgB,GAAwB,GAAG,EAAK,KAAK,IAAI,EAAK,UAEpE,IAAa,EAAb,KAA+B,CAC7B,MAAyB,IAAI,IAC7B,YAA+B,IAAI,IACnC,eAAkC,IAAI,IAEtC,SAAS,EAA2B,CAClC,IAAM,EAAM,EAAa,EAAK,KAAK,CACnC,GAAI,KAAK,MAAM,IAAI,EAAI,CACrB,MAAU,MA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EAAM,IAChC,EAAa,EACb,EAAS,GAGb,OAAO,IAIX,SAAgB,EAAiB,EAAqB,CACpD,OAAO,EAAa,EAAK"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tracker.d.ts","names":[],"sources":["../../src/telemetry/tracker.ts"],"sourcesContent":[],"mappings":";;;;UASiB,qBAAA;;EAAA,cAAA,CAAA,EAAA,MAAA,GAAqB,IAAA;EAUrB,MAAA,CAAA,EAAA,MAAA,GAAA,IAAiB;EAKpB,SAAA,CAAA,EAAA,MAAA,GAAA,IAAA;EACH,KAAA,CAAA,EAAA,WAAA,GAAA,MAAA,GAAA,OAAA;EACA,OAAA,CAAA,EAAA,KAAA,GAAA,QAAA,GAAA,KAAA,GAAA,OAAA;EAEH,QAAA,CAAA,EAZK,MAYL,CAAA,MAAA,EAAA,OAAA,CAAA;;AACuB,UAVd,iBAAA,CAUc;EAGd,EAAA,EAAA,MAAA;EAKA,IAAA,EAAA,MAAA;EACL,OAAA,EAAA,MAAA;EACE,UAAA,EAAA,MAAA;EACK,UAAA,EAhBL,MAgBK,CAAA,MAAA,EAAA,OAAA,CAAA;EAEH,OAAA,EAjBL,iBAiBK,CAAA,SAAA,CAAA;EAAI,OAAA,EAhBT,qBAgBS;
|
|
1
|
+
{"version":3,"file":"tracker.d.ts","names":[],"sources":["../../src/telemetry/tracker.ts"],"sourcesContent":[],"mappings":";;;;UASiB,qBAAA;;EAAA,cAAA,CAAA,EAAA,MAAA,GAAqB,IAAA;EAUrB,MAAA,CAAA,EAAA,MAAA,GAAA,IAAiB;EAKpB,SAAA,CAAA,EAAA,MAAA,GAAA,IAAA;EACH,KAAA,CAAA,EAAA,WAAA,GAAA,MAAA,GAAA,OAAA;EACA,OAAA,CAAA,EAAA,KAAA,GAAA,QAAA,GAAA,KAAA,GAAA,OAAA;EAEH,QAAA,CAAA,EAZK,MAYL,CAAA,MAAA,EAAA,OAAA,CAAA;;AACuB,UAVd,iBAAA,CAUc;EAGd,EAAA,EAAA,MAAA;EAKA,IAAA,EAAA,MAAA;EACL,OAAA,EAAA,MAAA;EACE,UAAA,EAAA,MAAA;EACK,UAAA,EAhBL,MAgBK,CAAA,MAAA,EAAA,OAAA,CAAA;EAEH,OAAA,EAjBL,iBAiBK,CAAA,SAAA,CAAA;EAAI,OAAA,EAhBT,qBAgBS;EAoBP,IAAA,CAAA,EAAA,MAAA,EAAA;EAOU,IAAA,EAzCf,aAyCe;EAWM,UAAA,EAnDf,iBAmDe;;AAYhB,UA5DI,wBAAA,CA4DJ;EACR,EAAA,EAAA,MAAA;EAAO,IAAA,CAAA,KAAA,EA3DE,iBA2DF,CAAA,EA3DsB,OA2DtB,CAAA,IAAA,CAAA;;UAxDK,uBAAA;YACL;cACE;mBACK;;gBAEH;;cAoBH,gBAAA;;;;;;uBAOU;6BAWM;;mDAWb,mCACH,wBACR"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tracker.js","names":["dispatch: TelemetryDispatch","result: Record<string, unknown>"],"sources":["../../src/telemetry/tracker.ts"],"sourcesContent":["import { randomUUID } from 'crypto';\nimport type { TelemetryAnomalyMonitor } from './anomaly';\nimport type {\n TelemetryEventDef,\n TelemetryRegistry,\n TelemetrySamplingConfig,\n TelemetrySpec,\n} from './spec';\n\nexport interface TelemetryEventContext {\n tenantId?: string;\n organizationId?: string | null;\n userId?: string | null;\n sessionId?: string | null;\n actor?: 'anonymous' | 'user' | 'admin';\n channel?: 'web' | 'mobile' | 'job' | 'agent';\n metadata?: Record<string, unknown>;\n}\n\nexport interface TelemetryDispatch {\n id: string;\n name: string;\n version: number;\n occurredAt: string;\n properties: Record<string, unknown>;\n privacy: TelemetryEventDef['privacy'];\n context: TelemetryEventContext;\n tags?: string[];\n spec: TelemetrySpec;\n definition: TelemetryEventDef;\n}\n\nexport interface RuntimeTelemetryProvider {\n id: string;\n send(event: TelemetryDispatch): Promise<void>;\n}\n\nexport interface TelemetryTrackerOptions {\n registry: TelemetryRegistry;\n providers?: RuntimeTelemetryProvider[];\n anomalyMonitor?: TelemetryAnomalyMonitor;\n random?: () => number;\n clock?: () => Date;\n}\n\nconst maskValue = (value: unknown) => {\n if (value == null) return value;\n if (typeof value === 'string') return 'REDACTED';\n if (typeof value === 'number') return 0;\n if (typeof value === 'boolean') return false;\n if (Array.isArray(value)) return value.map(() => 'REDACTED');\n if (typeof value === 'object') {\n return Object.fromEntries(\n Object.keys(value as Record<string, unknown>).map((key) => [key
|
|
1
|
+
{"version":3,"file":"tracker.js","names":["dispatch: TelemetryDispatch","result: Record<string, unknown>"],"sources":["../../src/telemetry/tracker.ts"],"sourcesContent":["import { randomUUID } from 'crypto';\nimport type { TelemetryAnomalyMonitor } from './anomaly';\nimport type {\n TelemetryEventDef,\n TelemetryRegistry,\n TelemetrySamplingConfig,\n TelemetrySpec,\n} from './spec';\n\nexport interface TelemetryEventContext {\n tenantId?: string;\n organizationId?: string | null;\n userId?: string | null;\n sessionId?: string | null;\n actor?: 'anonymous' | 'user' | 'admin';\n channel?: 'web' | 'mobile' | 'job' | 'agent';\n metadata?: Record<string, unknown>;\n}\n\nexport interface TelemetryDispatch {\n id: string;\n name: string;\n version: number;\n occurredAt: string;\n properties: Record<string, unknown>;\n privacy: TelemetryEventDef['privacy'];\n context: TelemetryEventContext;\n tags?: string[];\n spec: TelemetrySpec;\n definition: TelemetryEventDef;\n}\n\nexport interface RuntimeTelemetryProvider {\n id: string;\n send(event: TelemetryDispatch): Promise<void>;\n}\n\nexport interface TelemetryTrackerOptions {\n registry: TelemetryRegistry;\n providers?: RuntimeTelemetryProvider[];\n anomalyMonitor?: TelemetryAnomalyMonitor;\n random?: () => number;\n clock?: () => Date;\n}\n\nconst maskValue = (value: unknown) => {\n if (value == null) return value;\n if (typeof value === 'string') return 'REDACTED';\n if (typeof value === 'number') return 0;\n if (typeof value === 'boolean') return false;\n if (Array.isArray(value)) return value.map(() => 'REDACTED');\n if (typeof value === 'object') {\n return Object.fromEntries(\n Object.keys(value as Record<string, unknown>).map((key) => [\n key,\n 'REDACTED',\n ])\n );\n }\n return 'REDACTED';\n};\n\nexport class TelemetryTracker {\n private readonly providers = new Map<string, RuntimeTelemetryProvider>();\n private readonly registry: TelemetryRegistry;\n private readonly anomalyMonitor?: TelemetryAnomalyMonitor;\n private readonly random: () => number;\n private readonly clock: () => Date;\n\n constructor(options: TelemetryTrackerOptions) {\n this.registry = options.registry;\n this.anomalyMonitor = options.anomalyMonitor;\n this.random = options.random ?? Math.random;\n this.clock = options.clock ?? (() => new Date());\n\n for (const provider of options.providers ?? []) {\n this.providers.set(provider.id, provider);\n }\n }\n\n registerProvider(provider: RuntimeTelemetryProvider) {\n this.providers.set(provider.id, provider);\n }\n\n unregisterProvider(providerId: string) {\n this.providers.delete(providerId);\n }\n\n async track(\n name: string,\n version: number,\n properties: Record<string, unknown>,\n context: TelemetryEventContext = {}\n ): Promise<boolean> {\n const definition = this.registry.findEventDef(name, version);\n if (!definition) return false;\n\n const spec = this.registry.getSpecForEvent(\n definition.name,\n definition.version\n );\n if (!spec) return false;\n\n if (\n !this.shouldSample(\n definition.sampling ?? spec.config?.defaultSamplingRate\n )\n ) {\n return false;\n }\n\n const redactedProperties = this.redactProperties(definition, properties);\n const dispatch: TelemetryDispatch = {\n id: randomUUID(),\n name: definition.name,\n version: definition.version,\n occurredAt: this.clock().toISOString(),\n properties: redactedProperties,\n privacy: definition.privacy,\n context,\n tags: definition.tags,\n spec,\n definition,\n };\n\n await Promise.all(\n [...this.providers.values()].map((provider) => provider.send(dispatch))\n );\n\n this.anomalyMonitor?.observe(dispatch);\n return true;\n }\n\n private shouldSample(\n sampling: TelemetrySamplingConfig | number | undefined\n ): boolean {\n if (typeof sampling === 'number') {\n return this.random() < sampling;\n }\n if (!sampling) return true;\n return this.random() < sampling.rate;\n }\n\n private redactProperties(\n definition: TelemetryEventDef,\n properties: Record<string, unknown>\n ): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n for (const [key, value] of Object.entries(properties)) {\n const def = definition.properties[key];\n if (!def) {\n result[key] = value;\n continue;\n }\n if (def.redact || def.pii || definition.privacy === 'sensitive') {\n result[key] = maskValue(value);\n } else {\n result[key] = value;\n }\n }\n return result;\n }\n}\n"],"mappings":"oCA6CA,MAAM,EAAa,GACb,GAAS,KAAa,EACtB,OAAO,GAAU,SAAiB,WAClC,OAAO,GAAU,SAAiB,EAClC,OAAO,GAAU,UAAkB,GACnC,MAAM,QAAQ,EAAM,CAAS,EAAM,QAAU,WAAW,CACxD,OAAO,GAAU,SACZ,OAAO,YACZ,OAAO,KAAK,EAAiC,CAAC,IAAK,GAAQ,CACzD,EACA,WACD,CAAC,CACH,CAEI,WAGT,IAAa,EAAb,KAA8B,CAC5B,UAA6B,IAAI,IACjC,SACA,eACA,OACA,MAEA,YAAY,EAAkC,CAC5C,KAAK,SAAW,EAAQ,SACxB,KAAK,eAAiB,EAAQ,eAC9B,KAAK,OAAS,EAAQ,QAAU,KAAK,OACrC,KAAK,MAAQ,EAAQ,YAAgB,IAAI,MAEzC,IAAK,IAAM,KAAY,EAAQ,WAAa,EAAE,CAC5C,KAAK,UAAU,IAAI,EAAS,GAAI,EAAS,CAI7C,iBAAiB,EAAoC,CACnD,KAAK,UAAU,IAAI,EAAS,GAAI,EAAS,CAG3C,mBAAmB,EAAoB,CACrC,KAAK,UAAU,OAAO,EAAW,CAGnC,MAAM,MACJ,EACA,EACA,EACA,EAAiC,EAAE,CACjB,CAClB,IAAM,EAAa,KAAK,SAAS,aAAa,EAAM,EAAQ,CAC5D,GAAI,CAAC,EAAY,MAAO,GAExB,IAAM,EAAO,KAAK,SAAS,gBACzB,EAAW,KACX,EAAW,QACZ,CAGD,GAFI,CAAC,GAGH,CAAC,KAAK,aACJ,EAAW,UAAY,EAAK,QAAQ,oBACrC,CAED,MAAO,GAGT,IAAM,EAAqB,KAAK,iBAAiB,EAAY,EAAW,CAClEA,EAA8B,CAClC,GAAI,GAAY,CAChB,KAAM,EAAW,KACjB,QAAS,EAAW,QACpB,WAAY,KAAK,OAAO,CAAC,aAAa,CACtC,WAAY,EACZ,QAAS,EAAW,QACpB,UACA,KAAM,EAAW,KACjB,OACA,aACD,CAOD,OALA,MAAM,QAAQ,IACZ,CAAC,GAAG,KAAK,UAAU,QAAQ,CAAC,CAAC,IAAK,GAAa,EAAS,KAAK,EAAS,CAAC,CACxE,CAED,KAAK,gBAAgB,QAAQ,EAAS,CAC/B,GAGT,aACE,EACS,CAKT,OAJI,OAAO,GAAa,SACf,KAAK,QAAQ,CAAG,EAEpB,EACE,KAAK,QAAQ,CAAG,EAAS,KADV,GAIxB,iBACE,EACA,EACyB,CACzB,IAAMC,EAAkC,EAAE,CAC1C,IAAK,GAAM,CAAC,EAAK,KAAU,OAAO,QAAQ,EAAW,CAAE,CACrD,IAAM,EAAM,EAAW,WAAW,GAClC,GAAI,CAAC,EAAK,CACR,EAAO,GAAO,EACd,SAEE,EAAI,QAAU,EAAI,KAAO,EAAW,UAAY,YAClD,EAAO,GAAO,EAAU,EAAM,CAE9B,EAAO,GAAO,EAGlB,OAAO"}
|
package/dist/tests/runner.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.js","names":["config: TestRunnerConfig","scenarios: ScenarioRunResult[]","assertionResults: AssertionResult[]","events: RecordedEvent[]","ctx: HandlerCtx","failures: string[]"],"sources":["../../src/tests/runner.ts"],"sourcesContent":["import { deepStrictEqual } from 'node:assert';\nimport { SpecRegistry } from '../index';\nimport type { HandlerCtx } from '../types';\nimport type {\n Action,\n Assertion,\n ExpectErrorAssertion,\n ExpectEventsAssertion,\n ExpectOutputAssertion,\n Fixture,\n TestScenario,\n TestSpec,\n} from './spec';\n\nexport interface ScenarioRunResult {\n scenario: TestScenario;\n status: 'passed' | 'failed';\n error?: Error;\n assertionResults: AssertionResult[];\n}\n\nexport interface AssertionResult {\n assertion: Assertion;\n status: 'passed' | 'failed';\n message?: string;\n}\n\nexport interface TestRunResult {\n spec: TestSpec;\n scenarios: ScenarioRunResult[];\n passed: number;\n failed: number;\n}\n\nexport interface TestRunnerConfig {\n registry: SpecRegistry;\n createContext?: () => HandlerCtx | Promise<HandlerCtx>;\n beforeEach?: (scenario: TestScenario) => void | Promise<void>;\n afterEach?: (\n scenario: TestScenario,\n result: ScenarioRunResult\n ) => void | Promise<void>;\n}\n\ninterface OperationResult {\n output?: unknown;\n error?: Error;\n events: RecordedEvent[];\n}\n\ninterface RecordedEvent {\n name: string;\n version: number;\n payload: unknown;\n}\n\nexport class TestRunner {\n constructor(private readonly config: TestRunnerConfig) {}\n\n async run(spec: TestSpec): Promise<TestRunResult> {\n const scenarios: ScenarioRunResult[] = [];\n let passed = 0;\n let failed = 0;\n\n for (const scenario of spec.scenarios) {\n await this.config.beforeEach?.(scenario);\n\n const result = await this.runScenario(spec, scenario);\n scenarios.push(result);\n if (result.status === 'passed') passed += 1;\n else failed += 1;\n\n await this.config.afterEach?.(scenario, result);\n }\n\n return {\n spec,\n scenarios,\n passed,\n failed,\n };\n }\n\n private async runScenario(\n spec: TestSpec,\n scenario: TestScenario\n ): Promise<ScenarioRunResult> {\n const assertionResults: AssertionResult[] = [];\n\n try {\n const context = await this.createContext();\n const fixtures = [...(spec.fixtures ?? []), ...(scenario.given ?? [])];\n const events: RecordedEvent[] = [];\n\n for (const fixture of fixtures) {\n await this.executeOperation(fixture, context, events);\n }\n\n const actionResult = await this.executeOperation(\n scenario.when,\n context,\n events\n );\n\n const assertions = scenario.then ?? [];\n for (const assertion of assertions) {\n const assertionResult = this.evaluateAssertion(\n assertion,\n actionResult,\n events\n );\n assertionResults.push(assertionResult);\n }\n\n const hasFailure = assertionResults.some(\n (assertion) => assertion.status === 'failed'\n );\n return {\n scenario,\n status: hasFailure ? 'failed' : 'passed',\n assertionResults,\n };\n } catch (error) {\n return {\n scenario,\n status: 'failed',\n error: error as Error,\n assertionResults,\n };\n }\n }\n\n private async createContext(): Promise<HandlerCtx> {\n const baseCtx = (await this.config.createContext?.()) ?? {};\n return { ...baseCtx };\n }\n\n private async executeOperation(\n action: Action | Fixture,\n baseCtx: HandlerCtx,\n recordedEvents: RecordedEvent[]\n ): Promise<OperationResult> {\n const ctx: HandlerCtx = {\n ...baseCtx,\n eventPublisher: async (event) => {\n recordedEvents.push({\n name: event.name,\n version: event.version,\n payload: event.payload,\n });\n await baseCtx.eventPublisher?.(event);\n },\n };\n\n try {\n const output = await this.config.registry.execute(\n action.operation.name,\n action.operation.version,\n action.input ?? null,\n ctx\n );\n return { output, events: recordedEvents };\n } catch (error) {\n return { error: error as Error, events: recordedEvents };\n }\n }\n\n private evaluateAssertion(\n assertion: Assertion,\n result: OperationResult,\n events: RecordedEvent[]\n ): AssertionResult {\n switch (assertion.type) {\n case 'expectOutput':\n return this.evaluateOutputAssertion(assertion, result);\n case 'expectError':\n return this.evaluateErrorAssertion(assertion, result);\n case 'expectEvents':\n return this.evaluateEventsAssertion(assertion, events);\n default:\n return {\n assertion,\n status: 'failed',\n message: `Unknown assertion type ${(assertion as Assertion).type}`,\n };\n }\n }\n\n private evaluateOutputAssertion(\n assertion: ExpectOutputAssertion,\n result: OperationResult\n ): AssertionResult {\n if (result.error) {\n return {\n assertion,\n status: 'failed',\n message: `Expected output but operation threw error: ${result.error.message}`,\n };\n }\n try {\n deepStrictEqual(result.output, assertion.match);\n return { assertion, status: 'passed' };\n } catch (error) {\n return {\n assertion,\n status: 'failed',\n message:\n error instanceof Error ? error.message : 'Output assertion failed',\n };\n }\n }\n\n private evaluateErrorAssertion(\n assertion: ExpectErrorAssertion,\n result: OperationResult\n ): AssertionResult {\n if (!result.error) {\n return {\n assertion,\n status: 'failed',\n message: 'Expected an error but operation completed successfully',\n };\n }\n if (\n assertion.messageIncludes &&\n !result.error.message.includes(assertion.messageIncludes)\n ) {\n return {\n assertion,\n status: 'failed',\n message: `Error message \"${result.error.message}\" did not include expected substring \"${assertion.messageIncludes}\"`,\n };\n }\n return { assertion, status: 'passed' };\n }\n\n private evaluateEventsAssertion(\n assertion: ExpectEventsAssertion,\n events: RecordedEvent[]\n ): AssertionResult {\n const failures: string[] = [];\n\n for (const expected of assertion.events) {\n const matches = events.filter(\n (event) =>\n event.name === expected.name && event.version === expected.version\n );\n const count = matches.length;\n if (\n (typeof expected.min === 'number' && count < expected.min) ||\n (typeof expected.max === 'number' && count > expected.max)\n ) {\n failures.push(\n `Event ${expected.name}.v${expected.version} occurred ${count} times (expected ${expected.min ?? 0} - ${expected.max ?? '∞'})`\n );\n } else if (\n typeof expected.min === 'undefined' &&\n typeof expected.max === 'undefined' &&\n count === 0\n ) {\n failures.push(\n `Event ${expected.name}.v${expected.version} did not occur`\n );\n }\n }\n\n if (failures.length > 0) {\n return {\n assertion,\n status: 'failed',\n message: failures.join('; '),\n };\n }\n return { assertion, status: 'passed' };\n }\n}\n\n"],"mappings":"kEAwDA,IAAa,EAAb,KAAwB,CACtB,YAAY,EAA2C,CAA1B,KAAA,OAAA,EAE7B,MAAM,IAAI,EAAwC,CAChD,IAAMC,EAAiC,EAAE,CACrC,EAAS,EACT,EAAS,EAEb,IAAK,IAAM,KAAY,EAAK,UAAW,CACrC,MAAM,KAAK,OAAO,aAAa,EAAS,CAExC,IAAM,EAAS,MAAM,KAAK,YAAY,EAAM,EAAS,CACrD,EAAU,KAAK,EAAO,CAClB,EAAO,SAAW,SAAU,GAAU,EACrC,GAAU,EAEf,MAAM,KAAK,OAAO,YAAY,EAAU,EAAO,CAGjD,MAAO,CACL,OACA,YACA,SACA,SACD,CAGH,MAAc,YACZ,EACA,EAC4B,CAC5B,IAAMC,EAAsC,EAAE,CAE9C,GAAI,CACF,IAAM,EAAU,MAAM,KAAK,eAAe,CACpC,EAAW,CAAC,GAAI,EAAK,UAAY,EAAE,CAAG,GAAI,EAAS,OAAS,EAAE,CAAE,CAChEC,EAA0B,EAAE,CAElC,IAAK,IAAM,KAAW,EACpB,MAAM,KAAK,iBAAiB,EAAS,EAAS,EAAO,CAGvD,IAAM,EAAe,MAAM,KAAK,iBAC9B,EAAS,KACT,EACA,EACD,CAE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,SAAU,OAC/B,EAAO,CACd,MAAO,CACL,YACA,OAAQ,SACR,QACE,aAAiB,MAAQ,EAAM,QAAU,0BAC5C,EAIL,uBACE,EACA,EACiB,CAkBjB,OAjBK,EAAO,MAQV,EAAU,iBACV,CAAC,EAAO,MAAM,QAAQ,SAAS,EAAU,gBAAgB,CAElD,CACL,YACA,OAAQ,SACR,QAAS,kBAAkB,EAAO,MAAM,QAAQ,wCAAwC,EAAU,gBAAgB,GACnH,CAEI,CAAE,YAAW,OAAQ,SAAU,CAhB7B,CACL,YACA,OAAQ,SACR,QAAS,yDACV,CAeL,wBACE,EACA,EACiB,CACjB,IAAMC,EAAqB,EAAE,CAE7B,IAAK,IAAM,KAAY,EAAU,OAAQ,CAKvC,IAAM,EAJU,EAAO,OACpB,GACC,EAAM,OAAS,EAAS,MAAQ,EAAM,UAAY,EAAS,QAC9D,CACqB,OAEnB,OAAO,EAAS,KAAQ,UAAY,EAAQ,EAAS,KACrD,OAAO,EAAS,KAAQ,UAAY,EAAQ,EAAS,IAEtD,EAAS,KACP,SAAS,EAAS,KAAK,IAAI,EAAS,QAAQ,YAAY,EAAM,mBAAmB,EAAS,KAAO,EAAE,KAAK,EAAS,KAAO,IAAI,GAC7H,CAEM,EAAS,MAAQ,QACjB,EAAS,MAAQ,QACxB,IAAU,GAEV,EAAS,KACP,SAAS,EAAS,KAAK,IAAI,EAAS,QAAQ,gBAC7C,CAWL,OAPI,EAAS,OAAS,EACb,CACL,YACA,OAAQ,SACR,QAAS,EAAS,KAAK,KAAK,CAC7B,CAEI,CAAE,YAAW,OAAQ,SAAU"}
|
|
1
|
+
{"version":3,"file":"runner.js","names":["config: TestRunnerConfig","scenarios: ScenarioRunResult[]","assertionResults: AssertionResult[]","events: RecordedEvent[]","ctx: HandlerCtx","failures: string[]"],"sources":["../../src/tests/runner.ts"],"sourcesContent":["import { deepStrictEqual } from 'node:assert';\nimport { SpecRegistry } from '../index';\nimport type { HandlerCtx } from '../types';\nimport type {\n Action,\n Assertion,\n ExpectErrorAssertion,\n ExpectEventsAssertion,\n ExpectOutputAssertion,\n Fixture,\n TestScenario,\n TestSpec,\n} from './spec';\n\nexport interface ScenarioRunResult {\n scenario: TestScenario;\n status: 'passed' | 'failed';\n error?: Error;\n assertionResults: AssertionResult[];\n}\n\nexport interface AssertionResult {\n assertion: Assertion;\n status: 'passed' | 'failed';\n message?: string;\n}\n\nexport interface TestRunResult {\n spec: TestSpec;\n scenarios: ScenarioRunResult[];\n passed: number;\n failed: number;\n}\n\nexport interface TestRunnerConfig {\n registry: SpecRegistry;\n createContext?: () => HandlerCtx | Promise<HandlerCtx>;\n beforeEach?: (scenario: TestScenario) => void | Promise<void>;\n afterEach?: (\n scenario: TestScenario,\n result: ScenarioRunResult\n ) => void | Promise<void>;\n}\n\ninterface OperationResult {\n output?: unknown;\n error?: Error;\n events: RecordedEvent[];\n}\n\ninterface RecordedEvent {\n name: string;\n version: number;\n payload: unknown;\n}\n\nexport class TestRunner {\n constructor(private readonly config: TestRunnerConfig) {}\n\n async run(spec: TestSpec): Promise<TestRunResult> {\n const scenarios: ScenarioRunResult[] = [];\n let passed = 0;\n let failed = 0;\n\n for (const scenario of spec.scenarios) {\n await this.config.beforeEach?.(scenario);\n\n const result = await this.runScenario(spec, scenario);\n scenarios.push(result);\n if (result.status === 'passed') passed += 1;\n else failed += 1;\n\n await this.config.afterEach?.(scenario, result);\n }\n\n return {\n spec,\n scenarios,\n passed,\n failed,\n };\n }\n\n private async runScenario(\n spec: TestSpec,\n scenario: TestScenario\n ): Promise<ScenarioRunResult> {\n const assertionResults: AssertionResult[] = [];\n\n try {\n const context = await this.createContext();\n const fixtures = [...(spec.fixtures ?? []), ...(scenario.given ?? [])];\n const events: RecordedEvent[] = [];\n\n for (const fixture of fixtures) {\n await this.executeOperation(fixture, context, events);\n }\n\n const actionResult = await this.executeOperation(\n scenario.when,\n context,\n events\n );\n\n const assertions = scenario.then ?? [];\n for (const assertion of assertions) {\n const assertionResult = this.evaluateAssertion(\n assertion,\n actionResult,\n events\n );\n assertionResults.push(assertionResult);\n }\n\n const hasFailure = assertionResults.some(\n (assertion) => assertion.status === 'failed'\n );\n return {\n scenario,\n status: hasFailure ? 'failed' : 'passed',\n assertionResults,\n };\n } catch (error) {\n return {\n scenario,\n status: 'failed',\n error: error as Error,\n assertionResults,\n };\n }\n }\n\n private async createContext(): Promise<HandlerCtx> {\n const baseCtx = (await this.config.createContext?.()) ?? {};\n return { ...baseCtx };\n }\n\n private async executeOperation(\n action: Action | Fixture,\n baseCtx: HandlerCtx,\n recordedEvents: RecordedEvent[]\n ): Promise<OperationResult> {\n const ctx: HandlerCtx = {\n ...baseCtx,\n eventPublisher: async (event) => {\n recordedEvents.push({\n name: event.name,\n version: event.version,\n payload: event.payload,\n });\n await baseCtx.eventPublisher?.(event);\n },\n };\n\n try {\n const output = await this.config.registry.execute(\n action.operation.name,\n action.operation.version,\n action.input ?? null,\n ctx\n );\n return { output, events: recordedEvents };\n } catch (error) {\n return { error: error as Error, events: recordedEvents };\n }\n }\n\n private evaluateAssertion(\n assertion: Assertion,\n result: OperationResult,\n events: RecordedEvent[]\n ): AssertionResult {\n switch (assertion.type) {\n case 'expectOutput':\n return this.evaluateOutputAssertion(assertion, result);\n case 'expectError':\n return this.evaluateErrorAssertion(assertion, result);\n case 'expectEvents':\n return this.evaluateEventsAssertion(assertion, events);\n default:\n return {\n assertion,\n status: 'failed',\n message: `Unknown assertion type ${(assertion as Assertion).type}`,\n };\n }\n }\n\n private evaluateOutputAssertion(\n assertion: ExpectOutputAssertion,\n result: OperationResult\n ): AssertionResult {\n if (result.error) {\n return {\n assertion,\n status: 'failed',\n message: `Expected output but operation threw error: ${result.error.message}`,\n };\n }\n try {\n deepStrictEqual(result.output, assertion.match);\n return { assertion, status: 'passed' };\n } catch (error) {\n return {\n assertion,\n status: 'failed',\n message:\n error instanceof Error ? error.message : 'Output assertion failed',\n };\n }\n }\n\n private evaluateErrorAssertion(\n assertion: ExpectErrorAssertion,\n result: OperationResult\n ): AssertionResult {\n if (!result.error) {\n return {\n assertion,\n status: 'failed',\n message: 'Expected an error but operation completed successfully',\n };\n }\n if (\n assertion.messageIncludes &&\n !result.error.message.includes(assertion.messageIncludes)\n ) {\n return {\n assertion,\n status: 'failed',\n message: `Error message \"${result.error.message}\" did not include expected substring \"${assertion.messageIncludes}\"`,\n };\n }\n return { assertion, status: 'passed' };\n }\n\n private evaluateEventsAssertion(\n assertion: ExpectEventsAssertion,\n events: RecordedEvent[]\n ): AssertionResult {\n const failures: string[] = [];\n\n for (const expected of assertion.events) {\n const matches = events.filter(\n (event) =>\n event.name === expected.name && event.version === expected.version\n );\n const count = matches.length;\n if (\n (typeof expected.min === 'number' && count < expected.min) ||\n (typeof expected.max === 'number' && count > expected.max)\n ) {\n failures.push(\n `Event ${expected.name}.v${expected.version} occurred ${count} times (expected ${expected.min ?? 0} - ${expected.max ?? '∞'})`\n );\n } else if (\n typeof expected.min === 'undefined' &&\n typeof expected.max === 'undefined' &&\n count === 0\n ) {\n failures.push(\n `Event ${expected.name}.v${expected.version} did not occur`\n );\n }\n }\n\n if (failures.length > 0) {\n return {\n assertion,\n status: 'failed',\n message: failures.join('; '),\n };\n }\n return { assertion, status: 'passed' };\n }\n}\n"],"mappings":"kEAwDA,IAAa,EAAb,KAAwB,CACtB,YAAY,EAA2C,CAA1B,KAAA,OAAA,EAE7B,MAAM,IAAI,EAAwC,CAChD,IAAMC,EAAiC,EAAE,CACrC,EAAS,EACT,EAAS,EAEb,IAAK,IAAM,KAAY,EAAK,UAAW,CACrC,MAAM,KAAK,OAAO,aAAa,EAAS,CAExC,IAAM,EAAS,MAAM,KAAK,YAAY,EAAM,EAAS,CACrD,EAAU,KAAK,EAAO,CAClB,EAAO,SAAW,SAAU,GAAU,EACrC,GAAU,EAEf,MAAM,KAAK,OAAO,YAAY,EAAU,EAAO,CAGjD,MAAO,CACL,OACA,YACA,SACA,SACD,CAGH,MAAc,YACZ,EACA,EAC4B,CAC5B,IAAMC,E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,KAAK,CAC7B,CAEI,CAAE,YAAW,OAAQ,SAAU"}
|
package/dist/tests/spec.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spec.js","names":["latest: TestSpec | undefined"],"sources":["../../src/tests/spec.ts"],"sourcesContent":["import type { Owner, Stability, Tag } from '../ownership';\n\nexport interface OperationTargetRef {\n name: string;\n version?: number;\n}\n\nexport interface WorkflowTargetRef {\n name: string;\n version?: number;\n}\n\nexport type TestTarget =\n | { type: 'contract'; operation: OperationTargetRef }\n | { type: 'workflow'; workflow: WorkflowTargetRef };\n\nexport interface Fixture {\n description?: string;\n operation: OperationTargetRef;\n input?: unknown;\n}\n\nexport interface Action {\n operation: OperationTargetRef;\n input?: unknown;\n}\n\nexport interface ExpectOutputAssertion {\n type: 'expectOutput';\n match: unknown;\n}\n\nexport interface ExpectErrorAssertion {\n type: 'expectError';\n messageIncludes?: string;\n}\n\nexport interface ExpectedEvent {\n name: string;\n version: number;\n min?: number;\n max?: number;\n}\n\nexport interface ExpectEventsAssertion {\n type: 'expectEvents';\n events: ExpectedEvent[];\n}\n\nexport type Assertion =\n | ExpectOutputAssertion\n | ExpectErrorAssertion\n | ExpectEventsAssertion;\n\nexport interface TestScenario {\n name: string;\n description?: string;\n given?: Fixture[];\n when: Action;\n then?: Assertion[];\n}\n\nexport interface CoverageRequirement {\n statements?: number;\n branches?: number;\n functions?: number;\n lines?: number;\n mutations?: number;\n}\n\nexport interface TestSpecMeta {\n name: string;\n version: number;\n title: string;\n description?: string;\n owners: Owner[];\n tags: Tag[];\n stability: Stability;\n}\n\nexport interface TestSpec {\n meta: TestSpecMeta;\n target: TestTarget;\n fixtures?: Fixture[];\n scenarios: TestScenario[];\n coverage?: CoverageRequirement;\n}\n\nexport interface TestSpecRef {\n name: string;\n version?: number;\n}\n\nconst testKey = (meta: TestSpecMeta) => `${meta.name}.v${meta.version}`;\n\nexport class TestRegistry {\n private readonly items = new Map<string, TestSpec>();\n\n register(spec: TestSpec): this {\n const key = testKey(spec.meta);\n if (this.items.has(key)) {\n throw new Error(`Duplicate TestSpec registration for ${key}`);\n }\n this.items.set(key, spec);\n return this;\n }\n\n list(): TestSpec[] {\n return [...this.items.values()];\n }\n\n get(name: string, version?: number): TestSpec | undefined {\n if (version != null) {\n return this.items.get(`${name}.v${version}`);\n }\n let latest: TestSpec | undefined;\n let maxVersion = -Infinity;\n for (const spec of this.items.values()) {\n if (spec.meta.name !== name) continue;\n if (spec.meta.version > maxVersion) {\n maxVersion = spec.meta.version;\n latest = spec;\n }\n }\n return latest;\n }\n}\n\nexport function makeTestKey(meta: TestSpecMeta) {\n return testKey(meta);\n}\n
|
|
1
|
+
{"version":3,"file":"spec.js","names":["latest: TestSpec | undefined"],"sources":["../../src/tests/spec.ts"],"sourcesContent":["import type { Owner, Stability, Tag } from '../ownership';\n\nexport interface OperationTargetRef {\n name: string;\n version?: number;\n}\n\nexport interface WorkflowTargetRef {\n name: string;\n version?: number;\n}\n\nexport type TestTarget =\n | { type: 'contract'; operation: OperationTargetRef }\n | { type: 'workflow'; workflow: WorkflowTargetRef };\n\nexport interface Fixture {\n description?: string;\n operation: OperationTargetRef;\n input?: unknown;\n}\n\nexport interface Action {\n operation: OperationTargetRef;\n input?: unknown;\n}\n\nexport interface ExpectOutputAssertion {\n type: 'expectOutput';\n match: unknown;\n}\n\nexport interface ExpectErrorAssertion {\n type: 'expectError';\n messageIncludes?: string;\n}\n\nexport interface ExpectedEvent {\n name: string;\n version: number;\n min?: number;\n max?: number;\n}\n\nexport interface ExpectEventsAssertion {\n type: 'expectEvents';\n events: ExpectedEvent[];\n}\n\nexport type Assertion =\n | ExpectOutputAssertion\n | ExpectErrorAssertion\n | ExpectEventsAssertion;\n\nexport interface TestScenario {\n name: string;\n description?: string;\n given?: Fixture[];\n when: Action;\n then?: Assertion[];\n}\n\nexport interface CoverageRequirement {\n statements?: number;\n branches?: number;\n functions?: number;\n lines?: number;\n mutations?: number;\n}\n\nexport interface TestSpecMeta {\n name: string;\n version: number;\n title: string;\n description?: string;\n owners: Owner[];\n tags: Tag[];\n stability: Stability;\n}\n\nexport interface TestSpec {\n meta: TestSpecMeta;\n target: TestTarget;\n fixtures?: Fixture[];\n scenarios: TestScenario[];\n coverage?: CoverageRequirement;\n}\n\nexport interface TestSpecRef {\n name: string;\n version?: number;\n}\n\nconst testKey = (meta: TestSpecMeta) => `${meta.name}.v${meta.version}`;\n\nexport class TestRegistry {\n private readonly items = new Map<string, TestSpec>();\n\n register(spec: TestSpec): this {\n const key = testKey(spec.meta);\n if (this.items.has(key)) {\n throw new Error(`Duplicate TestSpec registration for ${key}`);\n }\n this.items.set(key, spec);\n return this;\n }\n\n list(): TestSpec[] {\n return [...this.items.values()];\n }\n\n get(name: string, version?: number): TestSpec | undefined {\n if (version != null) {\n return this.items.get(`${name}.v${version}`);\n }\n let latest: TestSpec | undefined;\n let maxVersion = -Infinity;\n for (const spec of this.items.values()) {\n if (spec.meta.name !== name) continue;\n if (spec.meta.version > maxVersion) {\n maxVersion = spec.meta.version;\n latest = spec;\n }\n }\n return latest;\n }\n}\n\nexport function makeTestKey(meta: TestSpecMeta) {\n return testKey(meta);\n}\n"],"mappings":"AA6FA,MAAM,EAAW,GAAuB,GAAG,EAAK,KAAK,IAAI,EAAK,UAE9D,IAAa,EAAb,KAA0B,CACxB,MAAyB,IAAI,IAE7B,SAAS,EAAsB,CAC7B,IAAM,EAAM,EAAQ,EAAK,KAAK,CAC9B,GAAI,KAAK,MAAM,IAAI,EAAI,CACrB,MAAU,MAAM,uCAAuC,IAAM,CAG/D,OADA,KAAK,MAAM,IAAI,EAAK,EAAK,CAClB,KAGT,MAAmB,CACjB,MAAO,CAAC,GAAG,KAAK,MAAM,QAAQ,CAAC,CAGjC,IAAI,EAAc,EAAwC,CACxD,GAAI,GAAW,KACb,OAAO,KAAK,MAAM,IAAI,GAAG,EAAK,IAAI,IAAU,CAE9C,IAAIA,EACA,EAAa,KACjB,IAAK,IAAM,KAAQ,KAAK,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B,UAAA,CAAA,EAHF,oBAGY,EAAA;;AAIhB,UAJM,SAAA,SAAkB,aAIxB,CAAA;EAJwB,IAAA,EAAA,MAAA;EAAa,OAAA,EAAA,MAAA;EAO/B,OAAA,CAAA,EAJL,QAIc;EAClB,MAAA,CAAA,EAJG,UAIH,EAAA;;AAEO,UAHE,SAAA,CAGF;EACD,IAAA,EAHN,SAGM;EAAa,MAAA,EAFjB,WAEiB;EAGV,UAAA,CAAQ,EAJV,oBAIU,EAAA;EAOZ,SAAA,CAAA,EAVC,aAUY,EAAA;;AAUhB,UAjBO,QAAA,CAiBP;EAI6B,IAAA,EAAA,MAAA;EAAS,OAAA,EAAA,MAAA;AAehD;cA7Ba,aAAA;;iBAGI;UAOP;uCAI6B;;iBAevB,YAAA,OAAmB,YAAY"}
|
package/dist/themes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"themes.js","names":["candidate: ThemeSpec | undefined"],"sources":["../src/themes.ts"],"sourcesContent":["import type { OwnerShipMeta } from './ownership';\n\nexport type ThemeScope = 'global' | 'tenant' | 'user';\n\nexport interface ThemeToken<T> {\n value: T;\n description?: string;\n}\n\nexport interface ThemeTokens {\n colors?: Record<string, ThemeToken<string>>;\n radii?: Record<string, ThemeToken<number>>;\n space?: Record<string, ThemeToken<number>>;\n typography?: Record<string, ThemeToken<number>>;\n shadows?: Record<string, ThemeToken<string>>;\n motion?: Record<string, ThemeToken<string>>;\n}\n\nexport interface ComponentVariantDefinition {\n props?: Record<string, unknown>;\n tokens?: ThemeTokens;\n}\n\nexport interface ComponentVariantSpec {\n component: string;\n variants: Record<string, ComponentVariantDefinition>;\n}\n\nexport interface ThemeOverride {\n scope: ThemeScope;\n target: string;\n tokens?: ThemeTokens;\n components?: ComponentVariantSpec[];\n}\n\nexport interface ThemeMeta extends OwnerShipMeta {\n name: string;\n version: number;\n extends?: ThemeRef;\n scopes?: ThemeScope[];\n}\n\nexport interface ThemeSpec {\n meta: ThemeMeta;\n tokens: ThemeTokens;\n components?: ComponentVariantSpec[];\n overrides?: ThemeOverride[];\n}\n\nexport interface ThemeRef {\n name: string;\n version: number;\n}\n\nconst themeKey = (ref: ThemeRef | ThemeMeta)
|
|
1
|
+
{"version":3,"file":"themes.js","names":["candidate: ThemeSpec | undefined"],"sources":["../src/themes.ts"],"sourcesContent":["import type { OwnerShipMeta } from './ownership';\n\nexport type ThemeScope = 'global' | 'tenant' | 'user';\n\nexport interface ThemeToken<T> {\n value: T;\n description?: string;\n}\n\nexport interface ThemeTokens {\n colors?: Record<string, ThemeToken<string>>;\n radii?: Record<string, ThemeToken<number>>;\n space?: Record<string, ThemeToken<number>>;\n typography?: Record<string, ThemeToken<number>>;\n shadows?: Record<string, ThemeToken<string>>;\n motion?: Record<string, ThemeToken<string>>;\n}\n\nexport interface ComponentVariantDefinition {\n props?: Record<string, unknown>;\n tokens?: ThemeTokens;\n}\n\nexport interface ComponentVariantSpec {\n component: string;\n variants: Record<string, ComponentVariantDefinition>;\n}\n\nexport interface ThemeOverride {\n scope: ThemeScope;\n target: string;\n tokens?: ThemeTokens;\n components?: ComponentVariantSpec[];\n}\n\nexport interface ThemeMeta extends OwnerShipMeta {\n name: string;\n version: number;\n extends?: ThemeRef;\n scopes?: ThemeScope[];\n}\n\nexport interface ThemeSpec {\n meta: ThemeMeta;\n tokens: ThemeTokens;\n components?: ComponentVariantSpec[];\n overrides?: ThemeOverride[];\n}\n\nexport interface ThemeRef {\n name: string;\n version: number;\n}\n\nconst themeKey = (ref: ThemeRef | ThemeMeta) => `${ref.name}.v${ref.version}`;\n\nexport class ThemeRegistry {\n private readonly items = new Map<string, ThemeSpec>();\n\n register(spec: ThemeSpec): this {\n const key = themeKey(spec.meta);\n if (this.items.has(key)) throw new Error(`Duplicate theme ${key}`);\n this.items.set(key, spec);\n return this;\n }\n\n list(): ThemeSpec[] {\n return [...this.items.values()];\n }\n\n get(name: string, version?: number): ThemeSpec | undefined {\n if (version != null) return this.items.get(themeKey({ name, version }));\n let candidate: ThemeSpec | undefined;\n let max = -Infinity;\n for (const spec of this.items.values()) {\n if (spec.meta.name !== name) continue;\n if (spec.meta.version > max) {\n max = spec.meta.version;\n candidate = spec;\n }\n }\n return candidate;\n }\n}\n\nexport function makeThemeRef(spec: ThemeSpec): ThemeRef {\n return { name: spec.meta.name, version: spec.meta.version };\n}\n"],"mappings":"AAsDA,MAAM,EAAY,GAA8B,GAAG,EAAI,KAAK,IAAI,EAAI,UAEpE,IAAa,EAAb,KAA2B,CACzB,MAAyB,IAAI,IAE7B,SAAS,EAAuB,CAC9B,IAAM,EAAM,EAAS,EAAK,KAAK,CAC/B,GAAI,KAAK,MAAM,IAAI,EAAI,CAAE,MAAU,MAAM,mBAAmB,IAAM,CAElE,OADA,KAAK,MAAM,IAAI,EAAK,EAAK,CAClB,KAGT,MAAoB,CAClB,MAAO,CAAC,GAAG,KAAK,MAAM,QAAQ,CAAC,CAGjC,IAAI,EAAc,EAAyC,CACzD,GAAI,GAAW,KAAM,OAAO,KAAK,MAAM,IAAI,EAAS,CAAE,OAAM,UAAS,CAAC,CAAC,CACvE,IAAIA,EACA,EAAM,KACV,IAAK,IAAM,KAAQ,KAAK,MAAM,QAAQ,CAChC,EAAK,KAAK,OAAS,GACnB,EAAK,KAAK,QAAU,IACtB,EAAM,EAAK,KAAK,QAChB,EAAY,GAGhB,OAAO,IAIX,SAAgB,EAAa,EAA2B,CACtD,MAAO,CAAE,KAAM,EAAK,KAAK,KAAM,QAAS,EAAK,KAAK,QAAS"}
|
package/dist/types/all.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { AnyContractSpec, ContractSpec, EmitDecl, EmitDeclInline, EmitDeclRef, O
|
|
|
8
8
|
import { TelemetryAnomalyAction, TelemetryAnomalyDetectionConfig, TelemetryAnomalyThreshold, TelemetryConfig, TelemetryEventDef, TelemetryMeta, TelemetryPrivacyLevel, TelemetryPropertyDef, TelemetryProviderConfig, TelemetryRegistry, TelemetryRetentionConfig, TelemetrySamplingConfig, TelemetrySpec, makeTelemetryKey } from "../telemetry/spec.js";
|
|
9
9
|
import { TelemetryAnomalyEvent, TelemetryAnomalyMonitor, TelemetryAnomalyMonitorOptions } from "../telemetry/anomaly.js";
|
|
10
10
|
import { RuntimeTelemetryProvider, TelemetryDispatch, TelemetryEventContext, TelemetryTracker, TelemetryTrackerOptions } from "../telemetry/tracker.js";
|
|
11
|
-
import { CapabilityKind, CapabilityMeta, CapabilityRef, CapabilityRegistry, CapabilityRequirement, CapabilitySpec, CapabilitySurface, CapabilitySurfaceRef, capabilityKey } from "../capabilities.js";
|
|
11
|
+
import { CapabilityKind, CapabilityMeta, CapabilityRef, CapabilityRegistry, CapabilityRequirement, CapabilitySpec, CapabilitySurface, CapabilitySurfaceRef, capabilityKey, defineCapability } from "../capabilities.js";
|
|
12
12
|
import { DataPresentation, MarkdownPresentation, PresentationContent, PresentationKind, PresentationMeta, PresentationPolicy, PresentationRegistry, PresentationSpec, WebComponentPresentation, jsonSchemaForPresentation } from "../presentations.js";
|
|
13
13
|
import { PresentationDescriptorV2, PresentationRenderer, PresentationSource, PresentationSourceBlocknotejs, PresentationSourceComponentReact, PresentationTarget, PresentationV2Meta, PresentationValidator, ReactRenderDescriptor, RenderContext, TransformEngine, createDefaultTransformEngine, registerBasicValidation, registerDefaultReactRenderer } from "../presentations.v2.js";
|
|
14
14
|
import { AllocationStrategy, ExperimentMeta, ExperimentOverride, ExperimentOverrideType, ExperimentRef, ExperimentRegistry, ExperimentSpec, ExperimentVariant, MetricAggregation, SuccessMetric, TargetingRule, makeExperimentKey } from "../experiments/spec.js";
|
|
@@ -57,4 +57,4 @@ import { VectorIndexConfig, VectorIndexer } from "../knowledge/ingestion/vector-
|
|
|
57
57
|
import { StorageIngestionAdapter } from "../knowledge/ingestion/storage-adapter.js";
|
|
58
58
|
import { KnowledgeAnswer, KnowledgeQueryConfig, KnowledgeQueryService } from "../knowledge/query/service.js";
|
|
59
59
|
import { KnowledgeAccessContext, KnowledgeAccessGuard, KnowledgeAccessGuardOptions, KnowledgeAccessResult } from "../knowledge/runtime.js";
|
|
60
|
-
export { Action, ActionExecutionResult, Actor, AllocationStrategy, AnyContractSpec, AppBlueprintMeta, AppBlueprintRegistry, AppBlueprintSpec, AppComposition, AppCompositionDeps, AppIntegrationBinding, AppIntegrationSlot, AppKnowledgeBinding, AppRouteConfig, AppThemeBinding, ArrayFieldSpec, Assertion, AssertionResult, AttributeMatcher, BaseFieldSpec, BehaviorSignal, BehaviorSignalEnvelope, BehaviorSignalProvider, BlueprintTranslationCatalog, BlueprintUpdater, BrandingAssetRef, BrandingDefaults, CapabilityKind, CapabilityMeta, CapabilityRef, CapabilityRegistry, CapabilityRequirement, CapabilitySpec, CapabilitySurface, CapabilitySurfaceRef, Channel, CheckboxFieldSpec, CompensationStep, CompensationStrategy, ComponentVariantDefinition, ComponentVariantSpec, ComposeOptions, ConnectionStatus, ConsentDefinition, ConstraintDecl, ConstraintHandler, ContractSpec, CoverageRequirement, CreateTenantConfigDraftCommand, DataMigrationStep, DataPresentation, DataViewAction, DataViewBaseConfig, DataViewConfig, DataViewDetailConfig, DataViewField, DataViewFieldFormat, DataViewFilter, DataViewGridConfig, DataViewKind, DataViewListConfig, DataViewMeta, DataViewRegistry, DataViewSections, DataViewSource, DataViewSpec, DataViewStates, DataViewTableColumn, DataViewTableConfig, DecisionContext, DocumentFragment, DocumentProcessor, EmbeddingService, EmitDecl, EmitDeclInline, EmitDeclRef, EnhanceFields, ErrorSignal, ErrorSignalEnvelope, ErrorSignalProvider, EventEnvelope, EventKey, EventPublisher, EventRef, EventSpec, ExecutionStatus, ExecutorProposalSink, ExecutorResultPayload, ExecutorSinkLogger, ExecutorSinkOptions, ExpectErrorAssertion, ExpectEventsAssertion, ExpectOutputAssertion, ExpectedEvent, ExperimentMeta, ExperimentOverride, ExperimentOverrideType, ExperimentRef, ExperimentRegistry, ExperimentSpec, ExperimentVariant, ExpressionContext, FeatureFlagState, FeatureModuleMeta, FeatureModuleSpec, FeatureRef, FeatureRegistry, FieldLevelDecision, FieldPolicyRule, FieldSpec, Fixture, FormAction, FormOption, FormRef, FormRegistry, FormSpec, FormValuesFor, GetResolvedBrandingQuery, GetTenantConfigVersionQuery, GroupFieldSpec, GuardCondition, GuardConditionKind, HandlerCtx, IntegrationByokSetup, IntegrationCallContext, IntegrationCallError, IntegrationCallGuard, IntegrationCallGuardOptions, IntegrationCallResult, IntegrationCapabilityMapping, IntegrationCategory, IntegrationConfigSchema, IntegrationConnection, IntegrationConnectionHealth, IntegrationConnectionMeta, IntegrationContext, IntegrationHealthCheck, IntegrationInvocationStatus, IntegrationMeta, IntegrationOwnershipMode, IntegrationSecretSchema, IntegrationSpec, IntegrationSpecRegistry, IntegrationTelemetryEmitter, IntegrationTelemetryEvent, IntegrationTraceMetadata, IntegrationUsageMetrics, KnowledgeAccessContext, KnowledgeAccessGuard, KnowledgeAccessGuardOptions, KnowledgeAccessPolicy, KnowledgeAccessResult, KnowledgeAnswer, KnowledgeCategory, KnowledgeIndexingConfig, KnowledgeQueryConfig, KnowledgeQueryService, KnowledgeRetentionPolicy, KnowledgeSourceConfig, KnowledgeSourceMeta, KnowledgeSourceType, KnowledgeSpaceMeta, KnowledgeSpaceRegistry, KnowledgeSpaceSpec, ListTenantConfigVersionsQuery, Locale, MarkdownPresentation, MessageKey, MetricAggregation, MigrationCheck, MigrationExecutor, MigrationMeta, MigrationPlan, MigrationRegistry, MigrationSpec, MigrationStep, MigrationStepBase, MigrationStepKind, MissingReference, OpKind, OpRef, OperationTargetRef, OptionsSource, Owner, OwnerShipMeta, Owners, OwnersEnum, PIIPolicy, PlatformTranslationCatalog, PolicyCondition, PolicyDecider, PolicyDeciderInput, PolicyDecision, PolicyEffect, PolicyEngine, PolicyMeta, PolicyOPAConfig, PolicyRef, PolicyRegistry, PolicyRule, PolicySpec, Predicate, PredicateOp, PresentationContent, PresentationDescriptorV2, PresentationKind, PresentationMeta, PresentationPolicy, PresentationRef, PresentationRegistry, PresentationRenderer, PresentationSource, PresentationSourceBlocknotejs, PresentationSourceComponentReact, PresentationSpec, PresentationTarget, PresentationV2Meta, PresentationValidator, PromoteTenantConfigToPreviewCommand, ProposalAction, ProposalBlocker, ProposalConfidence, ProposalExecutionResult, ProposalExecutor, ProposalExecutorDeps, ProposalExecutorOptions, ProposalSink, ProposalTarget, PublishTenantConfigCommand, RadioFieldSpec, RateLimitDefinition, RateLimiter, RawDocument, ReactRenderDescriptor, RegenerationContext, RegenerationRule, RegenerationTrigger, RegeneratorOptions, RegeneratorService, RegeneratorSignal, RelationshipDefinition, RelationshipMatcher, RenderContext, ResolveAppConfigDeps, ResolveMessageQuery, ResolvedAppConfig, ResolvedBranding, ResolvedIntegration, ResolvedKnowledge, ResolvedTranslation, ResourceContext, ResourceMatcher, ResourceMeta, ResourceRefDescriptor, ResourceRegistry, ResourceTemplateSpec, RetryPolicy, RollbackTenantConfigCommand, RunMigrationsAction, RunTestsAction, RuntimeTelemetryProvider, SLA, ScenarioRunResult, SchemaMigrationStep, SelectFieldSpec, SignalAdapters, SpecChangeProposal, SpecPointer, Stability, StabilityEnum, StateStore, Step, StepAction, StepExecution, StepType, StorageIngestionAdapter, SubjectContext, SubjectMatcher, SubjectRelationship, SuccessMetric, SwitchFieldSpec, Tag, Tags, TagsEnum, TargetingRule, TelemetryAnomalyAction, TelemetryAnomalyDetectionConfig, TelemetryAnomalyEvent, TelemetryAnomalyMonitor, TelemetryAnomalyMonitorOptions, TelemetryAnomalyThreshold, TelemetryBinding, TelemetryConfig, TelemetryDispatch, TelemetryEventContext, TelemetryEventDef, TelemetryMeta, TelemetryPrivacyLevel, TelemetryPropertyDef, TelemetryProviderConfig, TelemetryRegistry, TelemetryRetentionConfig, TelemetrySamplingConfig, TelemetrySignal, TelemetrySignalEnvelope, TelemetrySignalProvider, TelemetrySpec, TelemetryTracker, TelemetryTrackerOptions, TelemetryTrigger, TenantAppConfig, TenantAppConfigMeta, TenantBrandingAsset, TenantBrandingConfig, TenantConfigUpdater, TenantRouteOverride, TenantSpecOverride, TestExecutor, TestRegistry, TestRunResult, TestRunner, TestRunnerConfig, TestScenario, TestSpec, TestSpecMeta, TestSpecRef, TestTarget, TextFieldSpec, TextareaFieldSpec, ThemeMeta, ThemeOverride, ThemeRef, ThemeRegistry, ThemeScope, ThemeSpec, ThemeToken, ThemeTokens, TransformEngine, Transition, TranslationCatalogMeta, TranslationCatalogPointer, TranslationEntry, TranslationResolver, TriggerRegenerationAction, TypedOptionsSource, TypedPredicate, TypedWhenClause, UpdateBlueprintAction, UpdateBlueprintTranslationCatalogCommand, UpdateTenantBrandingCommand, UpdateTenantConfigAction, UpdateTenantTranslationOverridesCommand, ValidateWorkflowSpecOptions, ValidationContext, ValidationIssue, ValidationMigrationStep, ValidationResult, ValidationSeverity, VectorIndexConfig, VectorIndexer, VerifyCustomDomainCommand, WebComponentPresentation, WhenClause, WorkflowDefinition, WorkflowMeta, WorkflowRegistry, WorkflowSpec, WorkflowState, WorkflowStateFilters, WorkflowStatus, WorkflowTargetRef, WorkflowValidationError, WorkflowValidationIssue, WorkflowValidationLevel, appConfigContracts, assertWorkflowSpecValid, behaviorToEnvelope, buildZodWithRelations, capabilityKey, composeAppConfig, connectionStatusLabel, createDefaultTransformEngine, dataViewKey, defaultGqlField, defaultMcpTool, defaultRestPath, defineCommand, defineEvent, defineFormSpec, defineQuery, defineResourceTemplate, emailThreadsKnowledgeSpace, ensureConnectionReady, errorToEnvelope, evalPredicate, evaluateExpression, eventKey, financialDocsKnowledgeSpace, financialOverviewKnowledgeSpace, installFeature, isEmitDeclRef, isResourceRef, jsonSchemaForPresentation, jsonSchemaForSpec, lifecycleContracts, makeAppBlueprintKey, makeExperimentKey, makeIntegrationSpecKey, makeKnowledgeSpaceKey, makePolicyKey, makeTelemetryKey, makeTestKey, makeThemeRef, productCanonKnowledgeSpace, registerAppConfigContracts, registerAppConfigLifecycleContracts, registerBasicValidation, registerDefaultReactRenderer, registerEmailThreadsKnowledgeSpace, registerFinancialDocsKnowledgeSpace, registerFinancialOverviewKnowledgeSpace, registerProductCanonKnowledgeSpace, registerSupportFaqKnowledgeSpace, registerUploadedDocsKnowledgeSpace, resolveAppConfig, resourceRef, supportFaqKnowledgeSpace, telemetryToEnvelope, toV2FromV1, uploadedDocsKnowledgeSpace, validateBlueprint, validateConfig, validateFeatureTargetsV2, validateResolvedConfig, validateTenantConfig, validateWorkflowSpec };
|
|
60
|
+
export { Action, ActionExecutionResult, Actor, AllocationStrategy, AnyContractSpec, AppBlueprintMeta, AppBlueprintRegistry, AppBlueprintSpec, AppComposition, AppCompositionDeps, AppIntegrationBinding, AppIntegrationSlot, AppKnowledgeBinding, AppRouteConfig, AppThemeBinding, ArrayFieldSpec, Assertion, AssertionResult, AttributeMatcher, BaseFieldSpec, BehaviorSignal, BehaviorSignalEnvelope, BehaviorSignalProvider, BlueprintTranslationCatalog, BlueprintUpdater, BrandingAssetRef, BrandingDefaults, CapabilityKind, CapabilityMeta, CapabilityRef, CapabilityRegistry, CapabilityRequirement, CapabilitySpec, CapabilitySurface, CapabilitySurfaceRef, Channel, CheckboxFieldSpec, CompensationStep, CompensationStrategy, ComponentVariantDefinition, ComponentVariantSpec, ComposeOptions, ConnectionStatus, ConsentDefinition, ConstraintDecl, ConstraintHandler, ContractSpec, CoverageRequirement, CreateTenantConfigDraftCommand, DataMigrationStep, DataPresentation, DataViewAction, DataViewBaseConfig, DataViewConfig, DataViewDetailConfig, DataViewField, DataViewFieldFormat, DataViewFilter, DataViewGridConfig, DataViewKind, DataViewListConfig, DataViewMeta, DataViewRegistry, DataViewSections, DataViewSource, DataViewSpec, DataViewStates, DataViewTableColumn, DataViewTableConfig, DecisionContext, DocumentFragment, DocumentProcessor, EmbeddingService, EmitDecl, EmitDeclInline, EmitDeclRef, EnhanceFields, ErrorSignal, ErrorSignalEnvelope, ErrorSignalProvider, EventEnvelope, EventKey, EventPublisher, EventRef, EventSpec, ExecutionStatus, ExecutorProposalSink, ExecutorResultPayload, ExecutorSinkLogger, ExecutorSinkOptions, ExpectErrorAssertion, ExpectEventsAssertion, ExpectOutputAssertion, ExpectedEvent, ExperimentMeta, ExperimentOverride, ExperimentOverrideType, ExperimentRef, ExperimentRegistry, ExperimentSpec, ExperimentVariant, ExpressionContext, FeatureFlagState, FeatureModuleMeta, FeatureModuleSpec, FeatureRef, FeatureRegistry, FieldLevelDecision, FieldPolicyRule, FieldSpec, Fixture, FormAction, FormOption, FormRef, FormRegistry, FormSpec, FormValuesFor, GetResolvedBrandingQuery, GetTenantConfigVersionQuery, GroupFieldSpec, GuardCondition, GuardConditionKind, HandlerCtx, IntegrationByokSetup, IntegrationCallContext, IntegrationCallError, IntegrationCallGuard, IntegrationCallGuardOptions, IntegrationCallResult, IntegrationCapabilityMapping, IntegrationCategory, IntegrationConfigSchema, IntegrationConnection, IntegrationConnectionHealth, IntegrationConnectionMeta, IntegrationContext, IntegrationHealthCheck, IntegrationInvocationStatus, IntegrationMeta, IntegrationOwnershipMode, IntegrationSecretSchema, IntegrationSpec, IntegrationSpecRegistry, IntegrationTelemetryEmitter, IntegrationTelemetryEvent, IntegrationTraceMetadata, IntegrationUsageMetrics, KnowledgeAccessContext, KnowledgeAccessGuard, KnowledgeAccessGuardOptions, KnowledgeAccessPolicy, KnowledgeAccessResult, KnowledgeAnswer, KnowledgeCategory, KnowledgeIndexingConfig, KnowledgeQueryConfig, KnowledgeQueryService, KnowledgeRetentionPolicy, KnowledgeSourceConfig, KnowledgeSourceMeta, KnowledgeSourceType, KnowledgeSpaceMeta, KnowledgeSpaceRegistry, KnowledgeSpaceSpec, ListTenantConfigVersionsQuery, Locale, MarkdownPresentation, MessageKey, MetricAggregation, MigrationCheck, MigrationExecutor, MigrationMeta, MigrationPlan, MigrationRegistry, MigrationSpec, MigrationStep, MigrationStepBase, MigrationStepKind, MissingReference, OpKind, OpRef, OperationTargetRef, OptionsSource, Owner, OwnerShipMeta, Owners, OwnersEnum, PIIPolicy, PlatformTranslationCatalog, PolicyCondition, PolicyDecider, PolicyDeciderInput, PolicyDecision, PolicyEffect, PolicyEngine, PolicyMeta, PolicyOPAConfig, PolicyRef, PolicyRegistry, PolicyRule, PolicySpec, Predicate, PredicateOp, PresentationContent, PresentationDescriptorV2, PresentationKind, PresentationMeta, PresentationPolicy, PresentationRef, PresentationRegistry, PresentationRenderer, PresentationSource, PresentationSourceBlocknotejs, PresentationSourceComponentReact, PresentationSpec, PresentationTarget, PresentationV2Meta, PresentationValidator, PromoteTenantConfigToPreviewCommand, ProposalAction, ProposalBlocker, ProposalConfidence, ProposalExecutionResult, ProposalExecutor, ProposalExecutorDeps, ProposalExecutorOptions, ProposalSink, ProposalTarget, PublishTenantConfigCommand, RadioFieldSpec, RateLimitDefinition, RateLimiter, RawDocument, ReactRenderDescriptor, RegenerationContext, RegenerationRule, RegenerationTrigger, RegeneratorOptions, RegeneratorService, RegeneratorSignal, RelationshipDefinition, RelationshipMatcher, RenderContext, ResolveAppConfigDeps, ResolveMessageQuery, ResolvedAppConfig, ResolvedBranding, ResolvedIntegration, ResolvedKnowledge, ResolvedTranslation, ResourceContext, ResourceMatcher, ResourceMeta, ResourceRefDescriptor, ResourceRegistry, ResourceTemplateSpec, RetryPolicy, RollbackTenantConfigCommand, RunMigrationsAction, RunTestsAction, RuntimeTelemetryProvider, SLA, ScenarioRunResult, SchemaMigrationStep, SelectFieldSpec, SignalAdapters, SpecChangeProposal, SpecPointer, Stability, StabilityEnum, StateStore, Step, StepAction, StepExecution, StepType, StorageIngestionAdapter, SubjectContext, SubjectMatcher, SubjectRelationship, SuccessMetric, SwitchFieldSpec, Tag, Tags, TagsEnum, TargetingRule, TelemetryAnomalyAction, TelemetryAnomalyDetectionConfig, TelemetryAnomalyEvent, TelemetryAnomalyMonitor, TelemetryAnomalyMonitorOptions, TelemetryAnomalyThreshold, TelemetryBinding, TelemetryConfig, TelemetryDispatch, TelemetryEventContext, TelemetryEventDef, TelemetryMeta, TelemetryPrivacyLevel, TelemetryPropertyDef, TelemetryProviderConfig, TelemetryRegistry, TelemetryRetentionConfig, TelemetrySamplingConfig, TelemetrySignal, TelemetrySignalEnvelope, TelemetrySignalProvider, TelemetrySpec, TelemetryTracker, TelemetryTrackerOptions, TelemetryTrigger, TenantAppConfig, TenantAppConfigMeta, TenantBrandingAsset, TenantBrandingConfig, TenantConfigUpdater, TenantRouteOverride, TenantSpecOverride, TestExecutor, TestRegistry, TestRunResult, TestRunner, TestRunnerConfig, TestScenario, TestSpec, TestSpecMeta, TestSpecRef, TestTarget, TextFieldSpec, TextareaFieldSpec, ThemeMeta, ThemeOverride, ThemeRef, ThemeRegistry, ThemeScope, ThemeSpec, ThemeToken, ThemeTokens, TransformEngine, Transition, TranslationCatalogMeta, TranslationCatalogPointer, TranslationEntry, TranslationResolver, TriggerRegenerationAction, TypedOptionsSource, TypedPredicate, TypedWhenClause, UpdateBlueprintAction, UpdateBlueprintTranslationCatalogCommand, UpdateTenantBrandingCommand, UpdateTenantConfigAction, UpdateTenantTranslationOverridesCommand, ValidateWorkflowSpecOptions, ValidationContext, ValidationIssue, ValidationMigrationStep, ValidationResult, ValidationSeverity, VectorIndexConfig, VectorIndexer, VerifyCustomDomainCommand, WebComponentPresentation, WhenClause, WorkflowDefinition, WorkflowMeta, WorkflowRegistry, WorkflowSpec, WorkflowState, WorkflowStateFilters, WorkflowStatus, WorkflowTargetRef, WorkflowValidationError, WorkflowValidationIssue, WorkflowValidationLevel, appConfigContracts, assertWorkflowSpecValid, behaviorToEnvelope, buildZodWithRelations, capabilityKey, composeAppConfig, connectionStatusLabel, createDefaultTransformEngine, dataViewKey, defaultGqlField, defaultMcpTool, defaultRestPath, defineCapability, defineCommand, defineEvent, defineFormSpec, defineQuery, defineResourceTemplate, emailThreadsKnowledgeSpace, ensureConnectionReady, errorToEnvelope, evalPredicate, evaluateExpression, eventKey, financialDocsKnowledgeSpace, financialOverviewKnowledgeSpace, installFeature, isEmitDeclRef, isResourceRef, jsonSchemaForPresentation, jsonSchemaForSpec, lifecycleContracts, makeAppBlueprintKey, makeExperimentKey, makeIntegrationSpecKey, makeKnowledgeSpaceKey, makePolicyKey, makeTelemetryKey, makeTestKey, makeThemeRef, productCanonKnowledgeSpace, registerAppConfigContracts, registerAppConfigLifecycleContracts, registerBasicValidation, registerDefaultReactRenderer, registerEmailThreadsKnowledgeSpace, registerFinancialDocsKnowledgeSpace, registerFinancialOverviewKnowledgeSpace, registerProductCanonKnowledgeSpace, registerSupportFaqKnowledgeSpace, registerUploadedDocsKnowledgeSpace, resolveAppConfig, resourceRef, supportFaqKnowledgeSpace, telemetryToEnvelope, toV2FromV1, uploadedDocsKnowledgeSpace, validateBlueprint, validateConfig, validateFeatureTargetsV2, validateResolvedConfig, validateTenantConfig, validateWorkflowSpec };
|