@contractspec/example.knowledge-canon 0.0.0-canary-20260113162409

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.
Files changed (44) hide show
  1. package/.turbo/turbo-build$colon$bundle.log +37 -0
  2. package/.turbo/turbo-build.log +38 -0
  3. package/CHANGELOG.md +293 -0
  4. package/LICENSE +21 -0
  5. package/README.md +27 -0
  6. package/dist/agent.d.ts +25 -0
  7. package/dist/agent.d.ts.map +1 -0
  8. package/dist/agent.js +35 -0
  9. package/dist/agent.js.map +1 -0
  10. package/dist/blueprint.d.ts +7 -0
  11. package/dist/blueprint.d.ts.map +1 -0
  12. package/dist/blueprint.js +29 -0
  13. package/dist/blueprint.js.map +1 -0
  14. package/dist/docs/index.d.ts +1 -0
  15. package/dist/docs/index.js +1 -0
  16. package/dist/docs/knowledge-canon.docblock.d.ts +1 -0
  17. package/dist/docs/knowledge-canon.docblock.js +29 -0
  18. package/dist/docs/knowledge-canon.docblock.js.map +1 -0
  19. package/dist/example.d.ts +7 -0
  20. package/dist/example.d.ts.map +1 -0
  21. package/dist/example.js +47 -0
  22. package/dist/example.js.map +1 -0
  23. package/dist/index.d.ts +6 -0
  24. package/dist/index.js +8 -0
  25. package/dist/source.sample.d.ts +7 -0
  26. package/dist/source.sample.d.ts.map +1 -0
  27. package/dist/source.sample.js +30 -0
  28. package/dist/source.sample.js.map +1 -0
  29. package/dist/tenant.d.ts +7 -0
  30. package/dist/tenant.d.ts.map +1 -0
  31. package/dist/tenant.js +33 -0
  32. package/dist/tenant.js.map +1 -0
  33. package/package.json +62 -0
  34. package/src/agent.ts +47 -0
  35. package/src/blueprint.ts +26 -0
  36. package/src/docs/index.ts +1 -0
  37. package/src/docs/knowledge-canon.docblock.ts +29 -0
  38. package/src/example.ts +32 -0
  39. package/src/index.ts +6 -0
  40. package/src/source.sample.ts +27 -0
  41. package/src/tenant.ts +32 -0
  42. package/tsconfig.json +11 -0
  43. package/tsconfig.tsbuildinfo +1 -0
  44. package/tsdown.config.js +6 -0
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ import { answerWithKnowledge, selectKnowledgeBindings } from "./agent.js";
2
+ import { artisanKnowledgeBlueprint } from "./blueprint.js";
3
+ import example_default from "./example.js";
4
+ import { artisanKnowledgeTenantConfig } from "./tenant.js";
5
+ import { productCanonNotionSource } from "./source.sample.js";
6
+ import "./docs/index.js";
7
+
8
+ export { answerWithKnowledge, artisanKnowledgeBlueprint, artisanKnowledgeTenantConfig, example_default as example, productCanonNotionSource, selectKnowledgeBindings };
@@ -0,0 +1,7 @@
1
+ import { KnowledgeSourceConfig } from "@contractspec/lib.contracts/knowledge/source";
2
+
3
+ //#region src/source.sample.d.ts
4
+ declare const productCanonNotionSource: KnowledgeSourceConfig;
5
+ //#endregion
6
+ export { productCanonNotionSource };
7
+ //# sourceMappingURL=source.sample.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source.sample.d.ts","names":[],"sources":["../src/source.sample.ts"],"sourcesContent":[],"mappings":";;;cAEa,0BAA0B"}
@@ -0,0 +1,30 @@
1
+ //#region src/source.sample.ts
2
+ const productCanonNotionSource = {
3
+ meta: {
4
+ id: "source-canon-notion",
5
+ tenantId: "artisan-co",
6
+ spaceKey: "knowledge.product-canon",
7
+ spaceVersion: "1.0.0",
8
+ label: "Product Canon (Notion)",
9
+ sourceType: "notion",
10
+ createdAt: "2026-01-01T00:00:00.000Z",
11
+ updatedAt: "2026-01-01T00:00:00.000Z"
12
+ },
13
+ config: {
14
+ notionDatabaseId: "xxxxxxxxxxxxxxxx",
15
+ apiKey: "secret_notion_token"
16
+ },
17
+ syncSchedule: {
18
+ enabled: true,
19
+ cron: "0 * * * *"
20
+ },
21
+ lastSync: {
22
+ timestamp: /* @__PURE__ */ new Date("2026-01-01T00:00:00.000Z"),
23
+ success: true,
24
+ itemsProcessed: 128
25
+ }
26
+ };
27
+
28
+ //#endregion
29
+ export { productCanonNotionSource };
30
+ //# sourceMappingURL=source.sample.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source.sample.js","names":[],"sources":["../src/source.sample.ts"],"sourcesContent":["import type { KnowledgeSourceConfig } from '@contractspec/lib.contracts/knowledge/source';\n\nexport const productCanonNotionSource: KnowledgeSourceConfig = {\n meta: {\n id: 'source-canon-notion',\n tenantId: 'artisan-co',\n spaceKey: 'knowledge.product-canon',\n spaceVersion: '1.0.0',\n label: 'Product Canon (Notion)',\n sourceType: 'notion',\n createdAt: '2026-01-01T00:00:00.000Z',\n updatedAt: '2026-01-01T00:00:00.000Z',\n },\n config: {\n notionDatabaseId: 'xxxxxxxxxxxxxxxx',\n apiKey: 'secret_notion_token',\n },\n syncSchedule: {\n enabled: true,\n cron: '0 * * * *',\n },\n lastSync: {\n timestamp: new Date('2026-01-01T00:00:00.000Z'),\n success: true,\n itemsProcessed: 128,\n },\n};\n"],"mappings":";AAEA,MAAa,2BAAkD;CAC7D,MAAM;EACJ,IAAI;EACJ,UAAU;EACV,UAAU;EACV,cAAc;EACd,OAAO;EACP,YAAY;EACZ,WAAW;EACX,WAAW;EACZ;CACD,QAAQ;EACN,kBAAkB;EAClB,QAAQ;EACT;CACD,cAAc;EACZ,SAAS;EACT,MAAM;EACP;CACD,UAAU;EACR,2BAAW,IAAI,KAAK,2BAA2B;EAC/C,SAAS;EACT,gBAAgB;EACjB;CACF"}
@@ -0,0 +1,7 @@
1
+ import { TenantAppConfig } from "@contractspec/lib.contracts/app-config/spec";
2
+
3
+ //#region src/tenant.d.ts
4
+ declare const artisanKnowledgeTenantConfig: TenantAppConfig;
5
+ //#endregion
6
+ export { artisanKnowledgeTenantConfig };
7
+ //# sourceMappingURL=tenant.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tenant.d.ts","names":[],"sources":["../src/tenant.ts"],"sourcesContent":[],"mappings":";;;cAEa,8BAA8B"}
package/dist/tenant.js ADDED
@@ -0,0 +1,33 @@
1
+ //#region src/tenant.ts
2
+ const artisanKnowledgeTenantConfig = {
3
+ meta: {
4
+ id: "tenant-config-artisan-knowledge",
5
+ tenantId: "artisan-co",
6
+ appId: "artisan",
7
+ blueprintName: "artisan.knowledge.product",
8
+ blueprintVersion: "1.0.0",
9
+ environment: "production",
10
+ version: "1.0.0",
11
+ status: "published",
12
+ createdAt: "2026-01-01T00:00:00.000Z",
13
+ updatedAt: "2026-01-01T00:00:00.000Z"
14
+ },
15
+ knowledge: [{
16
+ spaceKey: "knowledge.product-canon",
17
+ spaceVersion: "1.0.0",
18
+ scope: {
19
+ workflows: ["answerFaq"],
20
+ agents: ["productSupportAssistant"]
21
+ },
22
+ constraints: {
23
+ maxTokensPerQuery: 4096,
24
+ maxQueriesPerMinute: 30
25
+ }
26
+ }],
27
+ integrations: [],
28
+ notes: "Product Canon knowledge space bound for production assistants."
29
+ };
30
+
31
+ //#endregion
32
+ export { artisanKnowledgeTenantConfig };
33
+ //# sourceMappingURL=tenant.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tenant.js","names":[],"sources":["../src/tenant.ts"],"sourcesContent":["import type { TenantAppConfig } from '@contractspec/lib.contracts/app-config/spec';\n\nexport const artisanKnowledgeTenantConfig: TenantAppConfig = {\n meta: {\n id: 'tenant-config-artisan-knowledge',\n tenantId: 'artisan-co',\n appId: 'artisan',\n blueprintName: 'artisan.knowledge.product',\n blueprintVersion: '1.0.0',\n environment: 'production',\n version: '1.0.0',\n status: 'published',\n createdAt: '2026-01-01T00:00:00.000Z',\n updatedAt: '2026-01-01T00:00:00.000Z',\n },\n knowledge: [\n {\n spaceKey: 'knowledge.product-canon',\n spaceVersion: '1.0.0',\n scope: {\n workflows: ['answerFaq'],\n agents: ['productSupportAssistant'],\n },\n constraints: {\n maxTokensPerQuery: 4096,\n maxQueriesPerMinute: 30,\n },\n },\n ],\n integrations: [],\n notes: 'Product Canon knowledge space bound for production assistants.',\n};\n"],"mappings":";AAEA,MAAa,+BAAgD;CAC3D,MAAM;EACJ,IAAI;EACJ,UAAU;EACV,OAAO;EACP,eAAe;EACf,kBAAkB;EAClB,aAAa;EACb,SAAS;EACT,QAAQ;EACR,WAAW;EACX,WAAW;EACZ;CACD,WAAW,CACT;EACE,UAAU;EACV,cAAc;EACd,OAAO;GACL,WAAW,CAAC,YAAY;GACxB,QAAQ,CAAC,0BAA0B;GACpC;EACD,aAAa;GACX,mBAAmB;GACnB,qBAAqB;GACtB;EACF,CACF;CACD,cAAc,EAAE;CAChB,OAAO;CACR"}
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@contractspec/example.knowledge-canon",
3
+ "version": "0.0.0-canary-20260113162409",
4
+ "description": "Knowledge example – Product Canon space (blueprint + tenant config + source sample + runtime helper).",
5
+ "type": "module",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": "./dist/index.js",
9
+ "./agent": "./dist/agent.js",
10
+ "./blueprint": "./dist/blueprint.js",
11
+ "./docs": "./dist/docs/index.js",
12
+ "./docs/knowledge-canon.docblock": "./dist/docs/knowledge-canon.docblock.js",
13
+ "./example": "./dist/example.js",
14
+ "./source.sample": "./dist/source.sample.js",
15
+ "./tenant": "./dist/tenant.js",
16
+ "./*": "./*"
17
+ },
18
+ "scripts": {
19
+ "publish:pkg": "bun publish --tolerate-republish --ignore-scripts --verbose",
20
+ "publish:pkg:canary": "bun publish:pkg --tag canary",
21
+ "build": "bun build:types && bun build:bundle",
22
+ "build:bundle": "tsdown",
23
+ "build:types": "tsc --noEmit",
24
+ "dev": "bun build:bundle --watch",
25
+ "clean": "rimraf dist .turbo",
26
+ "lint": "bun lint:fix",
27
+ "lint:fix": "eslint src --fix",
28
+ "lint:check": "eslint src",
29
+ "test": "bun test"
30
+ },
31
+ "dependencies": {
32
+ "@contractspec/lib.contracts": "0.0.0-canary-20260113162409"
33
+ },
34
+ "devDependencies": {
35
+ "@contractspec/tool.tsdown": "0.0.0-canary-20260113162409",
36
+ "@contractspec/tool.typescript": "0.0.0-canary-20260113162409",
37
+ "tsdown": "^0.19.0",
38
+ "typescript": "^5.9.3"
39
+ },
40
+ "publishConfig": {
41
+ "access": "public",
42
+ "exports": {
43
+ ".": "./dist/index.js",
44
+ "./agent": "./dist/agent.js",
45
+ "./blueprint": "./dist/blueprint.js",
46
+ "./docs": "./dist/docs/index.js",
47
+ "./docs/knowledge-canon.docblock": "./dist/docs/knowledge-canon.docblock.js",
48
+ "./example": "./dist/example.js",
49
+ "./source.sample": "./dist/source.sample.js",
50
+ "./tenant": "./dist/tenant.js",
51
+ "./*": "./*"
52
+ },
53
+ "registry": "https://registry.npmjs.org/"
54
+ },
55
+ "license": "MIT",
56
+ "repository": {
57
+ "type": "git",
58
+ "url": "https://github.com/lssm-tech/contractspec.git",
59
+ "directory": "packages/examples/knowledge-canon"
60
+ },
61
+ "homepage": "https://contractspec.io"
62
+ }
package/src/agent.ts ADDED
@@ -0,0 +1,47 @@
1
+ import type { ResolvedAppConfig } from '@contractspec/lib.contracts/app-config/runtime';
2
+
3
+ /**
4
+ * Selects knowledge bindings that apply to a workflow or agent identifier.
5
+ */
6
+ export function selectKnowledgeBindings(
7
+ resolved: ResolvedAppConfig,
8
+ options: { workflowId?: string; agentId?: string }
9
+ ) {
10
+ return resolved.knowledge.filter(({ binding }) => {
11
+ if (!binding.scope) return true;
12
+ if (
13
+ options.workflowId &&
14
+ binding.scope.workflows?.includes(options.workflowId)
15
+ )
16
+ return true;
17
+ if (options.agentId && binding.scope.agents?.includes(options.agentId))
18
+ return true;
19
+ return false;
20
+ });
21
+ }
22
+
23
+ /**
24
+ * Pseudo implementation of an assistant lookup that routes prompts to the appropriate
25
+ * knowledge sources. In a real system this would call the ingestion/search services.
26
+ */
27
+ export async function answerWithKnowledge(
28
+ resolved: ResolvedAppConfig,
29
+ question: string,
30
+ { workflowId, agentId }: { workflowId?: string; agentId?: string }
31
+ ): Promise<string> {
32
+ const bindings = selectKnowledgeBindings(resolved, { workflowId, agentId });
33
+ if (bindings.length === 0) {
34
+ return 'No knowledge space available for this request.';
35
+ }
36
+
37
+ const summaries = bindings.map(
38
+ ({ space }) => `• ${space.meta.title || space.meta.description}`
39
+ );
40
+ return [
41
+ `Q: ${question}`,
42
+ 'Routed to knowledge spaces:',
43
+ ...summaries,
44
+ '',
45
+ 'TODO: invoke knowledge search service and synthesize response.',
46
+ ].join('\n');
47
+ }
@@ -0,0 +1,26 @@
1
+ import type { AppBlueprintSpec } from '@contractspec/lib.contracts/app-config/spec';
2
+ import {
3
+ OwnersEnum,
4
+ StabilityEnum,
5
+ TagsEnum,
6
+ } from '@contractspec/lib.contracts/ownership';
7
+
8
+ export const artisanKnowledgeBlueprint: AppBlueprintSpec = {
9
+ meta: {
10
+ key: 'artisan.knowledge.product',
11
+ version: '1.0.0',
12
+ appId: 'artisan',
13
+ title: 'ArtisanOS Knowledge – Product Canon',
14
+ description:
15
+ 'Blueprint that surfaces canonical product knowledge to agents and workflows.',
16
+ domain: 'knowledge',
17
+ owners: [OwnersEnum.PlatformContent],
18
+ tags: ['knowledge', 'product-canon', TagsEnum.Guide],
19
+ stability: StabilityEnum.Experimental,
20
+ },
21
+ workflows: {
22
+ answerFaq: { key: 'artisan.knowledge.answerFaq', version: '1.0.0' },
23
+ },
24
+ notes:
25
+ 'Workflows and assistants running on this blueprint should bind the Product Canon knowledge space.',
26
+ };
@@ -0,0 +1 @@
1
+ import './knowledge-canon.docblock';
@@ -0,0 +1,29 @@
1
+ import type { DocBlock } from '@contractspec/lib.contracts/docs';
2
+ import { registerDocBlocks } from '@contractspec/lib.contracts/docs';
3
+
4
+ const blocks: DocBlock[] = [
5
+ {
6
+ id: 'docs.examples.knowledge-canon',
7
+ title: 'Knowledge Example — Product Canon Space',
8
+ summary:
9
+ 'Bind the Product Canon KnowledgeSpaceSpec to a tenant and expose it to agents/workflows via ResolvedAppConfig.',
10
+ kind: 'reference',
11
+ visibility: 'public',
12
+ route: '/docs/examples/knowledge-canon',
13
+ tags: ['knowledge', 'canon', 'example'],
14
+ body: `## Included assets\n- Blueprint referencing a workflow depending on the Product Canon space.\n- Tenant app config binding the space to a workflow and agent scope.\n- Sample knowledge source configuration.\n- Helper to pick knowledge bindings from ResolvedAppConfig.\n\n## Guardrails\n- Keep sources scoped per tenant.\n- Keep secret fields out of config (use secret providers).\n- Enforce scope restrictions before answering.`,
15
+ },
16
+ {
17
+ id: 'docs.examples.knowledge-canon.usage',
18
+ title: 'Knowledge Canon — Usage',
19
+ summary:
20
+ 'How to register the space, configure sources, and route requests.',
21
+ kind: 'usage',
22
+ visibility: 'public',
23
+ route: '/docs/examples/knowledge-canon/usage',
24
+ tags: ['knowledge', 'usage'],
25
+ body: `## Usage\n1) Register the knowledge space spec in your KnowledgeSpaceRegistry.\n2) Persist the source config through knowledge CRUD operations.\n3) Compose ResolvedAppConfig and pass it to your workflow/agent runtime.\n4) Use helpers like \`selectKnowledgeBindings\` before dispatching to search/embedding.\n\n## Notes\n- Avoid logging PII.\n- Keep search results auditable and cite sources.`,
26
+ },
27
+ ];
28
+
29
+ registerDocBlocks(blocks);
package/src/example.ts ADDED
@@ -0,0 +1,32 @@
1
+ import { defineExample } from '@contractspec/lib.contracts';
2
+
3
+ const example = defineExample({
4
+ meta: {
5
+ key: 'knowledge-canon',
6
+ version: '1.0.0',
7
+ title: 'Knowledge Canon (Product Canon space)',
8
+ description:
9
+ 'Bind a canonical knowledge space to a tenant and route assistant/workflow requests to the right sources (blueprint + app config pattern).',
10
+ kind: 'knowledge',
11
+ visibility: 'public',
12
+ stability: 'experimental',
13
+ owners: ['@platform.core'],
14
+ tags: ['knowledge', 'canon', 'app-config', 'agents', 'workflows'],
15
+ },
16
+ docs: {
17
+ rootDocId: 'docs.examples.knowledge-canon',
18
+ usageDocId: 'docs.examples.knowledge-canon.usage',
19
+ },
20
+ entrypoints: {
21
+ packageName: '@contractspec/example.knowledge-canon',
22
+ docs: './docs',
23
+ },
24
+ surfaces: {
25
+ templates: true,
26
+ sandbox: { enabled: true, modes: ['markdown', 'specs'] },
27
+ studio: { enabled: true, installable: true },
28
+ mcp: { enabled: true },
29
+ },
30
+ });
31
+
32
+ export default example;
package/src/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ export * from './agent';
2
+ export * from './blueprint';
3
+ export * from './tenant';
4
+ export * from './source.sample';
5
+ export { default as example } from './example';
6
+ import './docs';
@@ -0,0 +1,27 @@
1
+ import type { KnowledgeSourceConfig } from '@contractspec/lib.contracts/knowledge/source';
2
+
3
+ export const productCanonNotionSource: KnowledgeSourceConfig = {
4
+ meta: {
5
+ id: 'source-canon-notion',
6
+ tenantId: 'artisan-co',
7
+ spaceKey: 'knowledge.product-canon',
8
+ spaceVersion: '1.0.0',
9
+ label: 'Product Canon (Notion)',
10
+ sourceType: 'notion',
11
+ createdAt: '2026-01-01T00:00:00.000Z',
12
+ updatedAt: '2026-01-01T00:00:00.000Z',
13
+ },
14
+ config: {
15
+ notionDatabaseId: 'xxxxxxxxxxxxxxxx',
16
+ apiKey: 'secret_notion_token',
17
+ },
18
+ syncSchedule: {
19
+ enabled: true,
20
+ cron: '0 * * * *',
21
+ },
22
+ lastSync: {
23
+ timestamp: new Date('2026-01-01T00:00:00.000Z'),
24
+ success: true,
25
+ itemsProcessed: 128,
26
+ },
27
+ };
package/src/tenant.ts ADDED
@@ -0,0 +1,32 @@
1
+ import type { TenantAppConfig } from '@contractspec/lib.contracts/app-config/spec';
2
+
3
+ export const artisanKnowledgeTenantConfig: TenantAppConfig = {
4
+ meta: {
5
+ id: 'tenant-config-artisan-knowledge',
6
+ tenantId: 'artisan-co',
7
+ appId: 'artisan',
8
+ blueprintName: 'artisan.knowledge.product',
9
+ blueprintVersion: '1.0.0',
10
+ environment: 'production',
11
+ version: '1.0.0',
12
+ status: 'published',
13
+ createdAt: '2026-01-01T00:00:00.000Z',
14
+ updatedAt: '2026-01-01T00:00:00.000Z',
15
+ },
16
+ knowledge: [
17
+ {
18
+ spaceKey: 'knowledge.product-canon',
19
+ spaceVersion: '1.0.0',
20
+ scope: {
21
+ workflows: ['answerFaq'],
22
+ agents: ['productSupportAssistant'],
23
+ },
24
+ constraints: {
25
+ maxTokensPerQuery: 4096,
26
+ maxQueriesPerMinute: 30,
27
+ },
28
+ },
29
+ ],
30
+ integrations: [],
31
+ notes: 'Product Canon knowledge space bound for production assistants.',
32
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "@contractspec/tool.typescript/react-library.json",
3
+ "include": ["src"],
4
+ "exclude": ["node_modules", "dist"],
5
+ "compilerOptions": {
6
+ "rootDir": "src",
7
+ "outDir": "dist"
8
+ }
9
+ }
10
+
11
+