@modular-prompt/process 0.1.11

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 (111) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +166 -0
  3. package/dist/index.d.ts +3 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +5 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/modules/dialogue.d.ts +39 -0
  8. package/dist/modules/dialogue.d.ts.map +1 -0
  9. package/dist/modules/dialogue.js +106 -0
  10. package/dist/modules/dialogue.js.map +1 -0
  11. package/dist/modules/index.d.ts +9 -0
  12. package/dist/modules/index.d.ts.map +1 -0
  13. package/dist/modules/index.js +5 -0
  14. package/dist/modules/index.js.map +1 -0
  15. package/dist/modules/material.d.ts +21 -0
  16. package/dist/modules/material.d.ts.map +1 -0
  17. package/dist/modules/material.js +41 -0
  18. package/dist/modules/material.js.map +1 -0
  19. package/dist/modules/stream-processing.d.ts +26 -0
  20. package/dist/modules/stream-processing.d.ts.map +1 -0
  21. package/dist/modules/stream-processing.js +128 -0
  22. package/dist/modules/stream-processing.js.map +1 -0
  23. package/dist/modules/summarize.d.ts +32 -0
  24. package/dist/modules/summarize.d.ts.map +1 -0
  25. package/dist/modules/summarize.js +97 -0
  26. package/dist/modules/summarize.js.map +1 -0
  27. package/dist/workflows/agent-workflow.d.ts +55 -0
  28. package/dist/workflows/agent-workflow.d.ts.map +1 -0
  29. package/dist/workflows/agent-workflow.js +337 -0
  30. package/dist/workflows/agent-workflow.js.map +1 -0
  31. package/dist/workflows/agentic-workflow/agentic-workflow.d.ts +13 -0
  32. package/dist/workflows/agentic-workflow/agentic-workflow.d.ts.map +1 -0
  33. package/dist/workflows/agentic-workflow/agentic-workflow.js +235 -0
  34. package/dist/workflows/agentic-workflow/agentic-workflow.js.map +1 -0
  35. package/dist/workflows/agentic-workflow/index.d.ts +4 -0
  36. package/dist/workflows/agentic-workflow/index.d.ts.map +1 -0
  37. package/dist/workflows/agentic-workflow/index.js +5 -0
  38. package/dist/workflows/agentic-workflow/index.js.map +1 -0
  39. package/dist/workflows/agentic-workflow/modules/agentic.d.ts +12 -0
  40. package/dist/workflows/agentic-workflow/modules/agentic.d.ts.map +1 -0
  41. package/dist/workflows/agentic-workflow/modules/agentic.js +22 -0
  42. package/dist/workflows/agentic-workflow/modules/agentic.js.map +1 -0
  43. package/dist/workflows/agentic-workflow/modules/execution-freeform.d.ts +15 -0
  44. package/dist/workflows/agentic-workflow/modules/execution-freeform.d.ts.map +1 -0
  45. package/dist/workflows/agentic-workflow/modules/execution-freeform.js +140 -0
  46. package/dist/workflows/agentic-workflow/modules/execution-freeform.js.map +1 -0
  47. package/dist/workflows/agentic-workflow/modules/execution.d.ts +11 -0
  48. package/dist/workflows/agentic-workflow/modules/execution.d.ts.map +1 -0
  49. package/dist/workflows/agentic-workflow/modules/execution.js +180 -0
  50. package/dist/workflows/agentic-workflow/modules/execution.js.map +1 -0
  51. package/dist/workflows/agentic-workflow/modules/index.d.ts +6 -0
  52. package/dist/workflows/agentic-workflow/modules/index.d.ts.map +1 -0
  53. package/dist/workflows/agentic-workflow/modules/index.js +7 -0
  54. package/dist/workflows/agentic-workflow/modules/index.js.map +1 -0
  55. package/dist/workflows/agentic-workflow/modules/integration.d.ts +11 -0
  56. package/dist/workflows/agentic-workflow/modules/integration.d.ts.map +1 -0
  57. package/dist/workflows/agentic-workflow/modules/integration.js +85 -0
  58. package/dist/workflows/agentic-workflow/modules/integration.js.map +1 -0
  59. package/dist/workflows/agentic-workflow/modules/planning.d.ts +11 -0
  60. package/dist/workflows/agentic-workflow/modules/planning.d.ts.map +1 -0
  61. package/dist/workflows/agentic-workflow/modules/planning.js +103 -0
  62. package/dist/workflows/agentic-workflow/modules/planning.js.map +1 -0
  63. package/dist/workflows/agentic-workflow/types.d.ts +60 -0
  64. package/dist/workflows/agentic-workflow/types.d.ts.map +1 -0
  65. package/dist/workflows/agentic-workflow/types.js +2 -0
  66. package/dist/workflows/agentic-workflow/types.js.map +1 -0
  67. package/dist/workflows/concat-process-workflow.d.ts +29 -0
  68. package/dist/workflows/concat-process-workflow.d.ts.map +1 -0
  69. package/dist/workflows/concat-process-workflow.js +121 -0
  70. package/dist/workflows/concat-process-workflow.js.map +1 -0
  71. package/dist/workflows/dialogue-workflow.d.ts +25 -0
  72. package/dist/workflows/dialogue-workflow.d.ts.map +1 -0
  73. package/dist/workflows/dialogue-workflow.js +139 -0
  74. package/dist/workflows/dialogue-workflow.js.map +1 -0
  75. package/dist/workflows/index.d.ts +14 -0
  76. package/dist/workflows/index.d.ts.map +1 -0
  77. package/dist/workflows/index.js +13 -0
  78. package/dist/workflows/index.js.map +1 -0
  79. package/dist/workflows/self-prompting-workflow/index.d.ts +12 -0
  80. package/dist/workflows/self-prompting-workflow/index.d.ts.map +1 -0
  81. package/dist/workflows/self-prompting-workflow/index.js +11 -0
  82. package/dist/workflows/self-prompting-workflow/index.js.map +1 -0
  83. package/dist/workflows/self-prompting-workflow/modules/integration.d.ts +11 -0
  84. package/dist/workflows/self-prompting-workflow/modules/integration.d.ts.map +1 -0
  85. package/dist/workflows/self-prompting-workflow/modules/integration.js +82 -0
  86. package/dist/workflows/self-prompting-workflow/modules/integration.js.map +1 -0
  87. package/dist/workflows/self-prompting-workflow/modules/planning.d.ts +11 -0
  88. package/dist/workflows/self-prompting-workflow/modules/planning.d.ts.map +1 -0
  89. package/dist/workflows/self-prompting-workflow/modules/planning.js +108 -0
  90. package/dist/workflows/self-prompting-workflow/modules/planning.js.map +1 -0
  91. package/dist/workflows/self-prompting-workflow/self-prompting-workflow.d.ts +14 -0
  92. package/dist/workflows/self-prompting-workflow/self-prompting-workflow.d.ts.map +1 -0
  93. package/dist/workflows/self-prompting-workflow/self-prompting-workflow.js +250 -0
  94. package/dist/workflows/self-prompting-workflow/self-prompting-workflow.js.map +1 -0
  95. package/dist/workflows/self-prompting-workflow/types.d.ts +56 -0
  96. package/dist/workflows/self-prompting-workflow/types.d.ts.map +1 -0
  97. package/dist/workflows/self-prompting-workflow/types.js +2 -0
  98. package/dist/workflows/self-prompting-workflow/types.js.map +1 -0
  99. package/dist/workflows/stream-workflow.d.ts +17 -0
  100. package/dist/workflows/stream-workflow.d.ts.map +1 -0
  101. package/dist/workflows/stream-workflow.js +119 -0
  102. package/dist/workflows/stream-workflow.js.map +1 -0
  103. package/dist/workflows/summarize-workflow.d.ts +39 -0
  104. package/dist/workflows/summarize-workflow.d.ts.map +1 -0
  105. package/dist/workflows/summarize-workflow.js +152 -0
  106. package/dist/workflows/summarize-workflow.js.map +1 -0
  107. package/dist/workflows/types.d.ts +37 -0
  108. package/dist/workflows/types.d.ts.map +1 -0
  109. package/dist/workflows/types.js +25 -0
  110. package/dist/workflows/types.js.map +1 -0
  111. package/package.json +72 -0
@@ -0,0 +1,152 @@
1
+ import { compile, merge } from '@modular-prompt/core';
2
+ import { streamProcessing } from '../modules/stream-processing.js';
3
+ import { analyzeForSummary, contentSummarize } from '../modules/summarize.js';
4
+ import { WorkflowExecutionError } from './types.js';
5
+ /**
6
+ * Simple token estimation (roughly 4 characters per token)
7
+ */
8
+ function estimateTokens(text) {
9
+ return Math.ceil(text.length / 4);
10
+ }
11
+ /**
12
+ * Summarization workflow - performs analysis and summarization with stream processing
13
+ */
14
+ export async function summarizeProcess(driver, module, context, options) {
15
+ const { targetTokens, enableAnalysis = true } = options;
16
+ let currentContext = { ...context };
17
+ let analysisReport = currentContext.analysisReport || '';
18
+ // Require chunks to be provided by caller
19
+ if (!currentContext.chunks || currentContext.chunks.length === 0) {
20
+ throw new Error('No chunks provided. Chunks must be prepared before calling the workflow.');
21
+ }
22
+ // Phase 1: Analysis (optional)
23
+ if (enableAnalysis && !currentContext.analysisReport) {
24
+ currentContext.phase = 'analysis';
25
+ const analysisModule = merge(streamProcessing, analyzeForSummary);
26
+ // Process chunks for analysis
27
+ let analysisState = '';
28
+ for (let i = 0; i < currentContext.chunks.length; i += 3) {
29
+ const batchContext = {
30
+ ...currentContext,
31
+ state: { content: analysisState, usage: estimateTokens(analysisState) },
32
+ range: { start: i, end: Math.min(i + 3, currentContext.chunks.length) }
33
+ };
34
+ const prompt = compile(analysisModule, batchContext);
35
+ try {
36
+ const queryResult = await driver.query(prompt);
37
+ // Check finish reason for dynamic failures
38
+ if (queryResult.finishReason && queryResult.finishReason !== 'stop') {
39
+ throw new WorkflowExecutionError(`Query failed with reason: ${queryResult.finishReason}`, {
40
+ ...currentContext,
41
+ state: { content: analysisState, usage: estimateTokens(analysisState) },
42
+ range: { start: i, end: Math.min(i + 3, currentContext.chunks.length) },
43
+ analysisReport: analysisState
44
+ }, {
45
+ phase: 'analysis',
46
+ partialResult: analysisState,
47
+ finishReason: queryResult.finishReason
48
+ });
49
+ }
50
+ analysisState = queryResult.content;
51
+ }
52
+ catch (error) {
53
+ // If it's already a WorkflowExecutionError, re-throw
54
+ if (error instanceof WorkflowExecutionError) {
55
+ throw error;
56
+ }
57
+ // Preserve context and phase info on driver error
58
+ throw new WorkflowExecutionError(error, {
59
+ ...currentContext,
60
+ state: { content: analysisState, usage: estimateTokens(analysisState) },
61
+ range: { start: i, end: Math.min(i + 3, currentContext.chunks.length) },
62
+ analysisReport: analysisState
63
+ }, {
64
+ phase: 'analysis',
65
+ partialResult: analysisState
66
+ });
67
+ }
68
+ }
69
+ analysisReport = analysisState;
70
+ currentContext.preparationNote = { content: analysisReport };
71
+ currentContext.analysisReport = analysisReport;
72
+ }
73
+ // Phase 2: Summarization
74
+ currentContext.phase = 'summarization';
75
+ const summarizeModule = merge(streamProcessing, contentSummarize, module);
76
+ // Process chunks for summarization
77
+ let summaryState = currentContext.state?.content || '';
78
+ // Calculate starting position
79
+ const startPosition = currentContext.range?.end || 0;
80
+ for (let i = startPosition; i < currentContext.chunks.length; i += 3) {
81
+ const batchContext = {
82
+ ...currentContext,
83
+ state: {
84
+ content: summaryState,
85
+ usage: estimateTokens(summaryState)
86
+ },
87
+ range: {
88
+ start: i,
89
+ end: Math.min(i + 3, currentContext.chunks.length)
90
+ },
91
+ targetTokens,
92
+ preparationNote: currentContext.preparationNote
93
+ };
94
+ const prompt = compile(summarizeModule, batchContext);
95
+ try {
96
+ const queryResult = await driver.query(prompt);
97
+ // Check finish reason for dynamic failures
98
+ if (queryResult.finishReason && queryResult.finishReason !== 'stop') {
99
+ throw new WorkflowExecutionError(`Query failed with reason: ${queryResult.finishReason}`, {
100
+ ...currentContext,
101
+ state: { content: summaryState, usage: estimateTokens(summaryState) },
102
+ range: { start: i, end: Math.min(i + 3, currentContext.chunks.length) }
103
+ }, {
104
+ phase: 'summarization',
105
+ partialResult: summaryState,
106
+ finishReason: queryResult.finishReason
107
+ });
108
+ }
109
+ summaryState = queryResult.content;
110
+ }
111
+ catch (error) {
112
+ // If it's already a WorkflowExecutionError, re-throw
113
+ if (error instanceof WorkflowExecutionError) {
114
+ throw error;
115
+ }
116
+ // Preserve context and phase info on driver error
117
+ throw new WorkflowExecutionError(error, {
118
+ ...currentContext,
119
+ state: { content: summaryState, usage: estimateTokens(summaryState) },
120
+ range: { start: i, end: Math.min(i + 3, currentContext.chunks.length) }
121
+ }, {
122
+ phase: 'summarization',
123
+ partialResult: summaryState
124
+ });
125
+ }
126
+ // Check if we're approaching target size
127
+ if (estimateTokens(summaryState) > targetTokens * 4) { // Rough char to token estimate
128
+ // Aggressive reduction needed - will be handled by the module
129
+ }
130
+ }
131
+ // Final context
132
+ const finalContext = {
133
+ ...currentContext,
134
+ phase: 'complete',
135
+ state: {
136
+ content: summaryState,
137
+ usage: estimateTokens(summaryState)
138
+ },
139
+ analysisReport,
140
+ range: undefined // Processing complete
141
+ };
142
+ return {
143
+ output: summaryState,
144
+ context: finalContext,
145
+ metadata: {
146
+ analysisEnabled: enableAnalysis,
147
+ finalLength: estimateTokens(summaryState),
148
+ targetTokens
149
+ }
150
+ };
151
+ }
152
+ //# sourceMappingURL=summarize-workflow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"summarize-workflow.js","sourceRoot":"","s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AAK,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,EAAE,cAAc,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE;aACxE,EAAE;gBACD,KAAK,EAAE,eAAe;gBACtB,aAAa,EAAE,YAAY;aAC5B,CAAC,CAAC;QACL,CAAC;QAED,yCAAyC;QACzC,IAAI,cAAc,CAAC,YAAY,CAAC,GAAG,YAAY,GAAG,CAAC,EAAE,CAAC,CAAE,+BAA+B;YACrF,8DAA8D;QAChE,CAAC;IACH,CAAC;IAED,gBAAgB;IAChB,MAAM,YAAY,GAA6B;QAC7C,GAAG,cAAc;QACjB,KAAK,EAAE,UAAU;QACjB,KAAK,EAAE;YACL,OAAO,EAAE,YAAY;YACrB,KAAK,EAAE,cAAc,CAAC,YAAY,CAAC;SACpC;QACD,cAAc;QACd,KAAK,EAAE,SAAS,CAAC,sBAAsB;KACxC,CAAC;IAEF,OAAO;QACL,MAAM,EAAE,YAAY;QACpB,OAAO,EAAE,YAAY;QACrB,QAAQ,EAAE;YACR,eAAe,EAAE,cAAc;YAC/B,WAAW,EAAE,cAAc,CAAC,YAAY,CAAC;YACzC,YAAY;SACb;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,37 @@
1
+ export type { AIDriver, QueryResult } from '@modular-prompt/driver';
2
+ /**
3
+ * Result of workflow execution
4
+ */
5
+ export interface WorkflowResult<TContext> {
6
+ output: string;
7
+ context: TContext;
8
+ metadata?: {
9
+ iterations?: number;
10
+ tokensUsed?: number;
11
+ [key: string]: any;
12
+ };
13
+ }
14
+ /**
15
+ * Error with recoverable context
16
+ */
17
+ export interface WorkflowError<TContext> extends Error {
18
+ context: TContext;
19
+ partialResult?: string;
20
+ phase?: string;
21
+ finishReason?: 'stop' | 'length' | 'error';
22
+ }
23
+ /**
24
+ * Workflow error implementation with context preservation
25
+ */
26
+ export declare class WorkflowExecutionError<TContext = any> extends Error implements WorkflowError<TContext> {
27
+ context: TContext;
28
+ partialResult?: string;
29
+ phase?: string;
30
+ finishReason?: 'stop' | 'length' | 'error';
31
+ constructor(originalError: Error | string, context: TContext, options?: {
32
+ partialResult?: string;
33
+ phase?: string;
34
+ finishReason?: 'stop' | 'length' | 'error';
35
+ });
36
+ }
37
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/workflows/types.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAEpE;;GAEG;AACH,MAAM,WAAW,cAAc,CAAC,QAAQ;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,QAAQ,CAAC;IAClB,QAAQ,CAAC,EAAE;QACT,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,aAAa,CAAC,QAAQ,CAAE,SAAQ,KAAK;IACpD,OAAO,EAAE,QAAQ,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC;CAC5C;AAED;;GAEG;AACH,qBAAa,sBAAsB,CAAC,QAAQ,GAAG,GAAG,CAAE,SAAQ,KAAM,YAAW,aAAa,CAAC,QAAQ,CAAC;IAC3F,OAAO,EAAE,QAAQ,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC;gBAGhD,aAAa,EAAE,KAAK,GAAG,MAAM,EAC7B,OAAO,EAAE,QAAQ,EACjB,OAAO,CAAC,EAAE;QACR,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,YAAY,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC;KAC5C;CAkBJ"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Workflow error implementation with context preservation
3
+ */
4
+ export class WorkflowExecutionError extends Error {
5
+ context;
6
+ partialResult;
7
+ phase;
8
+ finishReason;
9
+ constructor(originalError, context, options) {
10
+ const message = typeof originalError === 'string'
11
+ ? originalError
12
+ : originalError.message;
13
+ super(message);
14
+ this.name = 'WorkflowExecutionError';
15
+ this.context = context;
16
+ this.partialResult = options?.partialResult;
17
+ this.phase = options?.phase;
18
+ this.finishReason = options?.finishReason;
19
+ // Preserve original stack trace if available
20
+ if (originalError instanceof Error && originalError.stack) {
21
+ this.stack = originalError.stack;
22
+ }
23
+ }
24
+ }
25
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/workflows/types.ts"],"names":[],"mappings":"AA0BA;;GAEG;AACH,MAAM,OAAO,sBAAuC,SAAQ,KAAK;IACxD,OAAO,CAAW;IAClB,aAAa,CAAU;IACvB,KAAK,CAAU;IACf,YAAY,CAA+B;IAElD,YACE,aAA6B,EAC7B,OAAiB,EACjB,OAIC;QAED,MAAM,OAAO,GAAG,OAAO,aAAa,KAAK,QAAQ;YAC/C,CAAC,CAAC,aAAa;YACf,CAAC,CAAC,aAAa,CAAC,OAAO,CAAC;QAE1B,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;QACrC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,aAAa,GAAG,OAAO,EAAE,aAAa,CAAC;QAC5C,IAAI,CAAC,KAAK,GAAG,OAAO,EAAE,KAAK,CAAC;QAC5B,IAAI,CAAC,YAAY,GAAG,OAAO,EAAE,YAAY,CAAC;QAE1C,6CAA6C;QAC7C,IAAI,aAAa,YAAY,KAAK,IAAI,aAAa,CAAC,KAAK,EAAE,CAAC;YAC1D,IAAI,CAAC,KAAK,GAAG,aAAa,CAAC,KAAK,CAAC;QACnC,CAAC;IACH,CAAC;CACF"}
package/package.json ADDED
@@ -0,0 +1,72 @@
1
+ {
2
+ "name": "@modular-prompt/process",
3
+ "version": "0.1.11",
4
+ "description": "Process module for modular prompt framework",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ },
13
+ "./modules": {
14
+ "types": "./dist/modules/index.d.ts",
15
+ "import": "./dist/modules/index.js"
16
+ },
17
+ "./workflows": {
18
+ "types": "./dist/workflows/index.d.ts",
19
+ "import": "./dist/workflows/index.js"
20
+ }
21
+ },
22
+ "files": [
23
+ "dist/**/*",
24
+ "README.md"
25
+ ],
26
+ "dependencies": {
27
+ "@modular-prompt/core": "0.1.9",
28
+ "@modular-prompt/driver": "0.4.5"
29
+ },
30
+ "devDependencies": {
31
+ "@eslint/js": "^9.34.0",
32
+ "@types/node": "^20.0.0",
33
+ "@typescript-eslint/eslint-plugin": "^8.42.0",
34
+ "@typescript-eslint/parser": "^8.42.0",
35
+ "@vitest/ui": "^3.2.4",
36
+ "eslint": "^9.34.0",
37
+ "typescript": "^5.0.0",
38
+ "vitest": "^3.2.4"
39
+ },
40
+ "engines": {
41
+ "node": ">=18.0.0"
42
+ },
43
+ "repository": {
44
+ "type": "git",
45
+ "url": "https://github.com/otolab/moduler-prompt.git",
46
+ "directory": "packages/process"
47
+ },
48
+ "keywords": [
49
+ "prompt",
50
+ "module",
51
+ "ai",
52
+ "llm",
53
+ "process",
54
+ "stream",
55
+ "workflow"
56
+ ],
57
+ "license": "MIT",
58
+ "publishConfig": {
59
+ "access": "public",
60
+ "registry": "https://registry.npmjs.org/"
61
+ },
62
+ "scripts": {
63
+ "build": "tsc -b --force",
64
+ "dev": "tsc --watch",
65
+ "test": "vitest",
66
+ "test:ui": "vitest --ui",
67
+ "test:run": "vitest run",
68
+ "clean": "rm -rf dist tsconfig.tsbuildinfo",
69
+ "lint": "eslint src",
70
+ "typecheck": "tsc --noEmit"
71
+ }
72
+ }