@dotit/core 1.0.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 (59) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +229 -0
  3. package/dist/aliases.d.ts +1 -0
  4. package/dist/aliases.js +8 -0
  5. package/dist/ask.d.ts +7 -0
  6. package/dist/ask.js +55 -0
  7. package/dist/browser.d.ts +12 -0
  8. package/dist/browser.js +32 -0
  9. package/dist/diff.d.ts +17 -0
  10. package/dist/diff.js +179 -0
  11. package/dist/document-css.d.ts +1 -0
  12. package/dist/document-css.js +290 -0
  13. package/dist/executor.d.ts +40 -0
  14. package/dist/executor.js +501 -0
  15. package/dist/history.d.ts +10 -0
  16. package/dist/history.js +297 -0
  17. package/dist/html-to-it.d.ts +1 -0
  18. package/dist/html-to-it.js +288 -0
  19. package/dist/index-builder.d.ts +62 -0
  20. package/dist/index-builder.js +228 -0
  21. package/dist/index.d.ts +39 -0
  22. package/dist/index.js +94 -0
  23. package/dist/language-registry.d.ts +39 -0
  24. package/dist/language-registry.js +530 -0
  25. package/dist/markdown.d.ts +1 -0
  26. package/dist/markdown.js +123 -0
  27. package/dist/merge.d.ts +6 -0
  28. package/dist/merge.js +255 -0
  29. package/dist/parser.d.ts +29 -0
  30. package/dist/parser.js +1562 -0
  31. package/dist/query.d.ts +32 -0
  32. package/dist/query.js +293 -0
  33. package/dist/renderer.d.ts +16 -0
  34. package/dist/renderer.js +1286 -0
  35. package/dist/schema.d.ts +47 -0
  36. package/dist/schema.js +574 -0
  37. package/dist/source.d.ts +3 -0
  38. package/dist/source.js +223 -0
  39. package/dist/theme.d.ts +49 -0
  40. package/dist/theme.js +113 -0
  41. package/dist/themes/corporate.json +86 -0
  42. package/dist/themes/dark.json +64 -0
  43. package/dist/themes/editorial.json +54 -0
  44. package/dist/themes/legal.json +57 -0
  45. package/dist/themes/minimal.json +50 -0
  46. package/dist/themes/print.json +54 -0
  47. package/dist/themes/technical.json +59 -0
  48. package/dist/themes/warm.json +53 -0
  49. package/dist/trust.d.ts +66 -0
  50. package/dist/trust.js +200 -0
  51. package/dist/types.d.ts +234 -0
  52. package/dist/types.js +19 -0
  53. package/dist/utils.d.ts +2 -0
  54. package/dist/utils.js +13 -0
  55. package/dist/validate.d.ts +13 -0
  56. package/dist/validate.js +711 -0
  57. package/dist/workflow.d.ts +18 -0
  58. package/dist/workflow.js +160 -0
  59. package/package.json +51 -0
@@ -0,0 +1,18 @@
1
+ import { IntentDocument, IntentBlock } from "./types.js";
2
+ export interface WorkflowStep {
3
+ block: IntentBlock;
4
+ dependsOn: string[];
5
+ dependedOnBy: string[];
6
+ isGate: boolean;
7
+ isTerminal: boolean;
8
+ isParallel: boolean;
9
+ }
10
+ export interface WorkflowGraph {
11
+ entryPoints: string[];
12
+ steps: Record<string, WorkflowStep>;
13
+ executionOrder: string[][];
14
+ gatePositions: number[];
15
+ hasTerminal: boolean;
16
+ warnings: string[];
17
+ }
18
+ export declare function extractWorkflow(doc: IntentDocument): WorkflowGraph;
@@ -0,0 +1,160 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extractWorkflow = extractWorkflow;
4
+ const WORKFLOW_TYPES = new Set([
5
+ "step",
6
+ "gate",
7
+ "decision",
8
+ "parallel",
9
+ "wait",
10
+ "result",
11
+ "checkpoint",
12
+ "retry",
13
+ "call",
14
+ "handoff",
15
+ "trigger",
16
+ "loop",
17
+ "signal",
18
+ "error",
19
+ "audit",
20
+ ]);
21
+ function collectWorkflowBlocks(blocks) {
22
+ const result = [];
23
+ for (const block of blocks) {
24
+ if (WORKFLOW_TYPES.has(block.type)) {
25
+ result.push(block);
26
+ }
27
+ if (block.children) {
28
+ result.push(...collectWorkflowBlocks(block.children));
29
+ }
30
+ }
31
+ return result;
32
+ }
33
+ function getStepId(block) {
34
+ return block.properties?.id || block.id;
35
+ }
36
+ function isInsideParallel(block, doc) {
37
+ function search(blocks, insideParallel) {
38
+ for (const b of blocks) {
39
+ const inP = insideParallel || b.type === "parallel";
40
+ if (b === block)
41
+ return inP;
42
+ if (b.children) {
43
+ const found = search(b.children, inP);
44
+ if (found)
45
+ return true;
46
+ }
47
+ }
48
+ return false;
49
+ }
50
+ return search(doc.blocks, false);
51
+ }
52
+ function extractWorkflow(doc) {
53
+ if (!doc || !doc.blocks) {
54
+ return {
55
+ entryPoints: [],
56
+ steps: {},
57
+ executionOrder: [],
58
+ gatePositions: [],
59
+ hasTerminal: false,
60
+ warnings: ["Empty or invalid document"],
61
+ };
62
+ }
63
+ const warnings = [];
64
+ const workflowBlocks = collectWorkflowBlocks(doc.blocks);
65
+ if (workflowBlocks.length === 0) {
66
+ return {
67
+ entryPoints: [],
68
+ steps: {},
69
+ executionOrder: [],
70
+ gatePositions: [],
71
+ hasTerminal: false,
72
+ warnings: ["No workflow blocks found"],
73
+ };
74
+ }
75
+ const steps = {};
76
+ const idMap = new Map();
77
+ for (const block of workflowBlocks) {
78
+ const stepId = getStepId(block);
79
+ if (steps[stepId]) {
80
+ warnings.push(`Duplicate step ID: ${stepId}`);
81
+ continue;
82
+ }
83
+ idMap.set(stepId, block);
84
+ steps[stepId] = {
85
+ block,
86
+ dependsOn: [],
87
+ dependedOnBy: [],
88
+ isGate: block.type === "gate",
89
+ isTerminal: block.type === "result",
90
+ isParallel: isInsideParallel(block, doc),
91
+ };
92
+ }
93
+ for (const [stepId, step] of Object.entries(steps)) {
94
+ const depends = step.block.properties?.depends;
95
+ if (depends && typeof depends === "string") {
96
+ const deps = depends
97
+ .split(",")
98
+ .map((d) => d.trim())
99
+ .filter(Boolean);
100
+ for (const dep of deps) {
101
+ if (!steps[dep]) {
102
+ warnings.push(`Step "${stepId}" depends on unknown step "${dep}"`);
103
+ continue;
104
+ }
105
+ step.dependsOn.push(dep);
106
+ steps[dep].dependedOnBy.push(stepId);
107
+ }
108
+ }
109
+ }
110
+ const inDegree = {};
111
+ for (const id of Object.keys(steps)) {
112
+ inDegree[id] = steps[id].dependsOn.length;
113
+ }
114
+ const executionOrder = [];
115
+ const processed = new Set();
116
+ let iterationGuard = 0;
117
+ const maxIterations = Object.keys(steps).length + 1;
118
+ while (processed.size < Object.keys(steps).length &&
119
+ iterationGuard < maxIterations) {
120
+ iterationGuard++;
121
+ const batch = [];
122
+ for (const id of Object.keys(steps)) {
123
+ if (!processed.has(id) && inDegree[id] === 0) {
124
+ batch.push(id);
125
+ }
126
+ }
127
+ if (batch.length === 0) {
128
+ const remaining = Object.keys(steps).filter((id) => !processed.has(id));
129
+ warnings.push(`Cycle detected involving: ${remaining.join(", ")}`);
130
+ executionOrder.push(remaining);
131
+ for (const id of remaining) {
132
+ processed.add(id);
133
+ }
134
+ break;
135
+ }
136
+ executionOrder.push(batch);
137
+ for (const id of batch) {
138
+ processed.add(id);
139
+ for (const dependent of steps[id].dependedOnBy) {
140
+ inDegree[dependent]--;
141
+ }
142
+ }
143
+ }
144
+ const entryPoints = Object.keys(steps).filter((id) => steps[id].dependsOn.length === 0);
145
+ const gatePositions = [];
146
+ for (let i = 0; i < executionOrder.length; i++) {
147
+ if (executionOrder[i].some((id) => steps[id]?.isGate)) {
148
+ gatePositions.push(i);
149
+ }
150
+ }
151
+ const hasTerminal = Object.values(steps).some((s) => s.isTerminal);
152
+ return {
153
+ entryPoints,
154
+ steps,
155
+ executionOrder,
156
+ gatePositions,
157
+ hasTerminal,
158
+ warnings,
159
+ };
160
+ }
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@dotit/core",
3
+ "version": "1.0.0",
4
+ "description": "IntentText Parser, HTML Renderer, and Converters",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist",
9
+ "README.md"
10
+ ],
11
+ "keywords": [
12
+ "intenttext",
13
+ "parser",
14
+ "markdown",
15
+ "semantic",
16
+ "ai"
17
+ ],
18
+ "author": "IntentText Team",
19
+ "license": "MIT",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/intenttext/IntentText.git",
23
+ "directory": "packages/core"
24
+ },
25
+ "homepage": "https://github.com/intenttext/IntentText#readme",
26
+ "bugs": {
27
+ "url": "https://github.com/intenttext/IntentText/issues"
28
+ },
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "devDependencies": {
33
+ "@types/node": "^20.0.0",
34
+ "typescript": "^5.0.0",
35
+ "vitest": "^1.0.0"
36
+ },
37
+ "dependencies": {
38
+ "node-html-parser": "^7.0.2"
39
+ },
40
+ "scripts": {
41
+ "build": "rm -rf dist && tsc",
42
+ "test": "vitest run",
43
+ "size:report": "node scripts/report-package-size.cjs",
44
+ "size:check": "node scripts/check-package-size.cjs",
45
+ "pack:check": "node scripts/check-pack-footprint.cjs",
46
+ "keywords:check": "node scripts/check-keyword-consistency.cjs",
47
+ "parity:check": "node scripts/check-consumer-parity.cjs",
48
+ "check": "pnpm build && pnpm test && pnpm keywords:check && pnpm parity:check && pnpm pack:check",
49
+ "dev": "tsc --watch"
50
+ }
51
+ }