@ddse/acm-examples 0.5.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.
Files changed (182) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +113 -0
  3. package/bin/acm-demo.ts +495 -0
  4. package/data/coaching/agents.json +16 -0
  5. package/data/coaching/transcripts.json +37 -0
  6. package/data/documents.json +72 -0
  7. package/data/entitlement/customers.json +38 -0
  8. package/data/entitlement/policies.json +38 -0
  9. package/data/incidents/incidents.json +30 -0
  10. package/data/incidents/routing_rules.json +36 -0
  11. package/data/invoices/invoices.json +38 -0
  12. package/data/invoices/purchase-orders.json +38 -0
  13. package/data/issues.json +99 -0
  14. package/data/knowledge/docs/kb-001.md +7 -0
  15. package/data/knowledge/docs/kb-002.md +7 -0
  16. package/data/knowledge/docs/kb-003.md +9 -0
  17. package/data/knowledge/index.json +25 -0
  18. package/data/orders.json +106 -0
  19. package/dist/bin/acm-demo.d.ts +3 -0
  20. package/dist/bin/acm-demo.d.ts.map +1 -0
  21. package/dist/bin/acm-demo.js +392 -0
  22. package/dist/bin/acm-demo.js.map +1 -0
  23. package/dist/src/context/directives.d.ts +3 -0
  24. package/dist/src/context/directives.d.ts.map +1 -0
  25. package/dist/src/context/directives.js +325 -0
  26. package/dist/src/context/directives.js.map +1 -0
  27. package/dist/src/context/index.d.ts +2 -0
  28. package/dist/src/context/index.d.ts.map +1 -0
  29. package/dist/src/context/index.js +2 -0
  30. package/dist/src/context/index.js.map +1 -0
  31. package/dist/src/data/coaching.d.ts +19 -0
  32. package/dist/src/data/coaching.d.ts.map +1 -0
  33. package/dist/src/data/coaching.js +22 -0
  34. package/dist/src/data/coaching.js.map +1 -0
  35. package/dist/src/data/entitlement.d.ts +25 -0
  36. package/dist/src/data/entitlement.d.ts.map +1 -0
  37. package/dist/src/data/entitlement.js +26 -0
  38. package/dist/src/data/entitlement.js.map +1 -0
  39. package/dist/src/data/incidents.d.ts +23 -0
  40. package/dist/src/data/incidents.d.ts.map +1 -0
  41. package/dist/src/data/incidents.js +37 -0
  42. package/dist/src/data/incidents.js.map +1 -0
  43. package/dist/src/data/invoices.d.ts +34 -0
  44. package/dist/src/data/invoices.d.ts.map +1 -0
  45. package/dist/src/data/invoices.js +49 -0
  46. package/dist/src/data/invoices.js.map +1 -0
  47. package/dist/src/data/knowledge.d.ts +11 -0
  48. package/dist/src/data/knowledge.d.ts.map +1 -0
  49. package/dist/src/data/knowledge.js +57 -0
  50. package/dist/src/data/knowledge.js.map +1 -0
  51. package/dist/src/data/loader.d.ts +4 -0
  52. package/dist/src/data/loader.d.ts.map +1 -0
  53. package/dist/src/data/loader.js +69 -0
  54. package/dist/src/data/loader.js.map +1 -0
  55. package/dist/src/examples/scenarios.d.ts +23 -0
  56. package/dist/src/examples/scenarios.d.ts.map +1 -0
  57. package/dist/src/examples/scenarios.js +609 -0
  58. package/dist/src/examples/scenarios.js.map +1 -0
  59. package/dist/src/goals/index.d.ts +8 -0
  60. package/dist/src/goals/index.d.ts.map +1 -0
  61. package/dist/src/goals/index.js +12 -0
  62. package/dist/src/goals/index.js.map +1 -0
  63. package/dist/src/policy.d.ts +5 -0
  64. package/dist/src/policy.d.ts.map +1 -0
  65. package/dist/src/policy.js +24 -0
  66. package/dist/src/policy.js.map +1 -0
  67. package/dist/src/registries.d.ts +18 -0
  68. package/dist/src/registries.d.ts.map +1 -0
  69. package/dist/src/registries.js +38 -0
  70. package/dist/src/registries.js.map +1 -0
  71. package/dist/src/renderer.d.ts +9 -0
  72. package/dist/src/renderer.d.ts.map +1 -0
  73. package/dist/src/renderer.js +76 -0
  74. package/dist/src/renderer.js.map +1 -0
  75. package/dist/src/search/bm25.d.ts +68 -0
  76. package/dist/src/search/bm25.d.ts.map +1 -0
  77. package/dist/src/search/bm25.js +131 -0
  78. package/dist/src/search/bm25.js.map +1 -0
  79. package/dist/src/search/index.d.ts +2 -0
  80. package/dist/src/search/index.d.ts.map +1 -0
  81. package/dist/src/search/index.js +3 -0
  82. package/dist/src/search/index.js.map +1 -0
  83. package/dist/src/tasks/coaching.d.ts +30 -0
  84. package/dist/src/tasks/coaching.d.ts.map +1 -0
  85. package/dist/src/tasks/coaching.js +143 -0
  86. package/dist/src/tasks/coaching.js.map +1 -0
  87. package/dist/src/tasks/entitlement.d.ts +29 -0
  88. package/dist/src/tasks/entitlement.d.ts.map +1 -0
  89. package/dist/src/tasks/entitlement.js +135 -0
  90. package/dist/src/tasks/entitlement.js.map +1 -0
  91. package/dist/src/tasks/incidents.d.ts +42 -0
  92. package/dist/src/tasks/incidents.d.ts.map +1 -0
  93. package/dist/src/tasks/incidents.js +189 -0
  94. package/dist/src/tasks/incidents.js.map +1 -0
  95. package/dist/src/tasks/index.d.ts +7 -0
  96. package/dist/src/tasks/index.d.ts.map +1 -0
  97. package/dist/src/tasks/index.js +7 -0
  98. package/dist/src/tasks/index.js.map +1 -0
  99. package/dist/src/tasks/invoices.d.ts +40 -0
  100. package/dist/src/tasks/invoices.d.ts.map +1 -0
  101. package/dist/src/tasks/invoices.js +180 -0
  102. package/dist/src/tasks/invoices.js.map +1 -0
  103. package/dist/src/tasks/knowledge.d.ts +23 -0
  104. package/dist/src/tasks/knowledge.d.ts.map +1 -0
  105. package/dist/src/tasks/knowledge.js +115 -0
  106. package/dist/src/tasks/knowledge.js.map +1 -0
  107. package/dist/src/tasks/legacy.d.ts +50 -0
  108. package/dist/src/tasks/legacy.d.ts.map +1 -0
  109. package/dist/src/tasks/legacy.js +85 -0
  110. package/dist/src/tasks/legacy.js.map +1 -0
  111. package/dist/src/tools/coaching/index.d.ts +49 -0
  112. package/dist/src/tools/coaching/index.d.ts.map +1 -0
  113. package/dist/src/tools/coaching/index.js +119 -0
  114. package/dist/src/tools/coaching/index.js.map +1 -0
  115. package/dist/src/tools/entitlement/index.d.ts +52 -0
  116. package/dist/src/tools/entitlement/index.d.ts.map +1 -0
  117. package/dist/src/tools/entitlement/index.js +120 -0
  118. package/dist/src/tools/entitlement/index.js.map +1 -0
  119. package/dist/src/tools/incidents/index.d.ts +55 -0
  120. package/dist/src/tools/incidents/index.d.ts.map +1 -0
  121. package/dist/src/tools/incidents/index.js +109 -0
  122. package/dist/src/tools/incidents/index.js.map +1 -0
  123. package/dist/src/tools/index.d.ts +90 -0
  124. package/dist/src/tools/index.d.ts.map +1 -0
  125. package/dist/src/tools/index.js +109 -0
  126. package/dist/src/tools/index.js.map +1 -0
  127. package/dist/src/tools/invoices/index.d.ts +56 -0
  128. package/dist/src/tools/invoices/index.d.ts.map +1 -0
  129. package/dist/src/tools/invoices/index.js +85 -0
  130. package/dist/src/tools/invoices/index.js.map +1 -0
  131. package/dist/src/tools/knowledge/index.d.ts +52 -0
  132. package/dist/src/tools/knowledge/index.d.ts.map +1 -0
  133. package/dist/src/tools/knowledge/index.js +120 -0
  134. package/dist/src/tools/knowledge/index.js.map +1 -0
  135. package/dist/tests/bm25.test.d.ts +2 -0
  136. package/dist/tests/bm25.test.d.ts.map +1 -0
  137. package/dist/tests/bm25.test.js +98 -0
  138. package/dist/tests/bm25.test.js.map +1 -0
  139. package/dist/tests/integration.test.d.ts +2 -0
  140. package/dist/tests/integration.test.d.ts.map +1 -0
  141. package/dist/tests/integration.test.js +126 -0
  142. package/dist/tests/integration.test.js.map +1 -0
  143. package/dist/tests/plan-hydration.test.d.ts +2 -0
  144. package/dist/tests/plan-hydration.test.d.ts.map +1 -0
  145. package/dist/tests/plan-hydration.test.js +28 -0
  146. package/dist/tests/plan-hydration.test.js.map +1 -0
  147. package/dist/tsconfig.tsbuildinfo +1 -0
  148. package/docs/examples-architecture.md +144 -0
  149. package/docs/successrun.md +1022 -0
  150. package/package.json +33 -0
  151. package/src/context/directives.ts +366 -0
  152. package/src/context/index.ts +1 -0
  153. package/src/data/coaching.ts +50 -0
  154. package/src/data/entitlement.ts +60 -0
  155. package/src/data/incidents.ts +78 -0
  156. package/src/data/invoices.ts +103 -0
  157. package/src/data/knowledge.ts +77 -0
  158. package/src/data/loader.ts +80 -0
  159. package/src/examples/scenarios.ts +724 -0
  160. package/src/goals/index.ts +18 -0
  161. package/src/policy.ts +30 -0
  162. package/src/registries.ts +48 -0
  163. package/src/renderer.ts +82 -0
  164. package/src/search/bm25.ts +173 -0
  165. package/src/search/index.ts +2 -0
  166. package/src/tasks/coaching.ts +217 -0
  167. package/src/tasks/entitlement.ts +197 -0
  168. package/src/tasks/incidents.ts +277 -0
  169. package/src/tasks/index.ts +6 -0
  170. package/src/tasks/invoices.ts +269 -0
  171. package/src/tasks/knowledge.ts +169 -0
  172. package/src/tasks/legacy.ts +112 -0
  173. package/src/tools/coaching/index.ts +197 -0
  174. package/src/tools/entitlement/index.ts +199 -0
  175. package/src/tools/incidents/index.ts +185 -0
  176. package/src/tools/index.ts +192 -0
  177. package/src/tools/invoices/index.ts +165 -0
  178. package/src/tools/knowledge/index.ts +203 -0
  179. package/tests/bm25.test.ts +129 -0
  180. package/tests/integration.test.ts +163 -0
  181. package/tests/plan-hydration.test.ts +33 -0
  182. package/tsconfig.json +18 -0
@@ -0,0 +1,77 @@
1
+ import { loadJson, loadText } from './loader.js';
2
+
3
+ export interface KnowledgeSnippetMeta {
4
+ id: string;
5
+ title: string;
6
+ tags: string[];
7
+ path: string;
8
+ summary: string;
9
+ }
10
+
11
+ interface KnowledgeIndex {
12
+ snippets: KnowledgeSnippetMeta[];
13
+ }
14
+
15
+ let cachedIndex: KnowledgeIndex | null = null;
16
+
17
+ async function loadIndex(): Promise<KnowledgeIndex> {
18
+ if (cachedIndex) {
19
+ return cachedIndex;
20
+ }
21
+
22
+ cachedIndex = await loadJson<KnowledgeIndex>('data/knowledge/index.json');
23
+ return cachedIndex;
24
+ }
25
+
26
+ export async function searchSnippets(query: string): Promise<KnowledgeSnippetMeta[]> {
27
+ const index = await loadIndex();
28
+ const lower = query.toLowerCase();
29
+ return index.snippets
30
+ .map(snippet => ({
31
+ snippet,
32
+ score: scoreSnippet(snippet, lower),
33
+ }))
34
+ .filter(entry => entry.score > 0)
35
+ .sort((a, b) => b.score - a.score)
36
+ .map(entry => entry.snippet);
37
+ }
38
+
39
+ function scoreSnippet(snippet: KnowledgeSnippetMeta, query: string): number {
40
+ const haystack = `${snippet.title} ${snippet.tags.join(' ')} ${snippet.summary}`.toLowerCase();
41
+ let score = 0;
42
+ for (const term of query.split(/\s+/)) {
43
+ if (!term) continue;
44
+ if (haystack.includes(term)) {
45
+ score += 2;
46
+ }
47
+ for (const tag of snippet.tags) {
48
+ if (tag.toLowerCase() === term) {
49
+ score += 3;
50
+ }
51
+ }
52
+ }
53
+ return score;
54
+ }
55
+
56
+ export async function loadSnippetContent(docId: string): Promise<string | undefined> {
57
+ const index = await loadIndex();
58
+ const snippet = index.snippets.find(item => item.id === docId);
59
+ if (!snippet) {
60
+ return undefined;
61
+ }
62
+
63
+ return loadText(pathForSnippet(snippet.path));
64
+ }
65
+
66
+ function pathForSnippet(relative: string): string {
67
+ return pathNormalize(`data/knowledge/${relative}`);
68
+ }
69
+
70
+ function pathNormalize(relative: string): string {
71
+ return relative.replace(/\\/g, '/');
72
+ }
73
+
74
+ export async function getSnippetMeta(docId: string): Promise<KnowledgeSnippetMeta | undefined> {
75
+ const index = await loadIndex();
76
+ return index.snippets.find(item => item.id === docId);
77
+ }
@@ -0,0 +1,80 @@
1
+ import { readFile } from 'fs/promises';
2
+ import { fileURLToPath } from 'url';
3
+ import * as path from 'path';
4
+
5
+ const __filename = fileURLToPath(import.meta.url);
6
+ const __dirname = path.dirname(__filename);
7
+
8
+ const jsonCache = new Map<string, unknown>();
9
+ const textCache = new Map<string, string>();
10
+ const pathCache = new Map<string, string>();
11
+
12
+ function candidatePaths(relativePath: string): string[] {
13
+ return [
14
+ path.resolve(process.cwd(), relativePath),
15
+ path.resolve(__dirname, '..', '..', relativePath),
16
+ path.resolve(__dirname, '..', '..', '..', relativePath),
17
+ ];
18
+ }
19
+
20
+ async function readDataFile(relativePath: string): Promise<{ absolute: string; content: string }> {
21
+ if (pathCache.has(relativePath)) {
22
+ const absolute = pathCache.get(relativePath)!;
23
+ const content = await readFile(absolute, 'utf-8');
24
+ return { absolute, content };
25
+ }
26
+
27
+ const candidates = candidatePaths(relativePath);
28
+ let lastError: unknown;
29
+
30
+ for (const absolute of candidates) {
31
+ try {
32
+ const content = await readFile(absolute, 'utf-8');
33
+ pathCache.set(relativePath, absolute);
34
+ return { absolute, content };
35
+ } catch (error) {
36
+ lastError = error;
37
+ }
38
+ }
39
+
40
+ throw lastError instanceof Error
41
+ ? lastError
42
+ : new Error(`Unable to read data file ${relativePath}`);
43
+ }
44
+
45
+ export async function loadJson<T>(relativePath: string): Promise<T> {
46
+ if (pathCache.has(relativePath)) {
47
+ const absolute = pathCache.get(relativePath)!;
48
+ if (jsonCache.has(absolute)) {
49
+ return jsonCache.get(absolute) as T;
50
+ }
51
+ }
52
+
53
+ const { absolute, content } = await readDataFile(relativePath);
54
+ if (jsonCache.has(absolute)) {
55
+ return jsonCache.get(absolute) as T;
56
+ }
57
+
58
+ const parsed = JSON.parse(content) as T;
59
+ jsonCache.set(absolute, parsed);
60
+ return parsed;
61
+ }
62
+
63
+ export async function loadText(relativePath: string): Promise<string> {
64
+ if (pathCache.has(relativePath)) {
65
+ const absolute = pathCache.get(relativePath)!;
66
+ if (textCache.has(absolute)) {
67
+ return textCache.get(absolute)!;
68
+ }
69
+ }
70
+
71
+ const { absolute, content } = await readDataFile(relativePath);
72
+ textCache.set(absolute, content);
73
+ return content;
74
+ }
75
+
76
+ export function clearDataCaches(): void {
77
+ jsonCache.clear();
78
+ textCache.clear();
79
+ pathCache.clear();
80
+ }