tjs-lang 0.6.20 → 0.6.26

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 (109) hide show
  1. package/CLAUDE.md +29 -24
  2. package/bin/dev.ts +9 -0
  3. package/demo/docs.json +49 -1
  4. package/demo/src/playground-shared.ts +8 -39
  5. package/demo/src/tjs-playground.ts +8 -0
  6. package/demo/src/tjs-runtime-iframe.ts +10 -0
  7. package/demo/src/ts-playground.ts +8 -0
  8. package/package.json +1 -1
  9. package/src/cli/commands/run.ts +4 -1
  10. package/src/cli/tjs.ts +1 -1
  11. package/src/lang/codegen.test.ts +26 -27
  12. package/src/lang/emitters/js-tests.ts +13 -19
  13. package/src/lang/emitters/js.ts +39 -7
  14. package/src/lang/parser-transforms.ts +18 -5
  15. package/src/lang/roundtrip.test.ts +1 -1
  16. package/src/lang/runtime.ts +88 -2
  17. package/src/lang/wasm.ts +1 -1
  18. package/dist/bin/benchmarks.d.ts +0 -9
  19. package/dist/bin/dev.d.ts +0 -1
  20. package/dist/bin/docs.d.ts +0 -1
  21. package/dist/bin/select-local-models.d.ts +0 -1
  22. package/dist/examples/modules/dist/main.d.ts +0 -34
  23. package/dist/examples/modules/dist/math.d.ts +0 -120
  24. package/dist/index.js +0 -426
  25. package/dist/index.js.map +0 -45
  26. package/dist/scripts/build-demo.d.ts +0 -2
  27. package/dist/scripts/build.d.ts +0 -11
  28. package/dist/scripts/seed-blog-rules.d.ts +0 -2
  29. package/dist/scripts/seed-stored-function.d.ts +0 -2
  30. package/dist/src/atoms/batteries.d.ts +0 -4
  31. package/dist/src/atoms/browser.d.ts +0 -4
  32. package/dist/src/atoms/index.d.ts +0 -4
  33. package/dist/src/batteries/audit.d.ts +0 -9
  34. package/dist/src/batteries/index.d.ts +0 -28
  35. package/dist/src/batteries/llm.d.ts +0 -18
  36. package/dist/src/batteries/models.d.ts +0 -19
  37. package/dist/src/batteries/store.d.ts +0 -13
  38. package/dist/src/builder.d.ts +0 -127
  39. package/dist/src/bun-plugin/tjs-plugin.d.ts +0 -12
  40. package/dist/src/cli/commands/check.d.ts +0 -4
  41. package/dist/src/cli/commands/convert.d.ts +0 -20
  42. package/dist/src/cli/commands/emit.d.ts +0 -34
  43. package/dist/src/cli/commands/run.d.ts +0 -6
  44. package/dist/src/cli/commands/test.d.ts +0 -21
  45. package/dist/src/cli/commands/types.d.ts +0 -4
  46. package/dist/src/cli/create-app.d.ts +0 -9
  47. package/dist/src/cli/playground.d.ts +0 -9
  48. package/dist/src/cli/tjs.d.ts +0 -15
  49. package/dist/src/cli/tjsx.d.ts +0 -16
  50. package/dist/src/index.d.ts +0 -11
  51. package/dist/src/inference.types.d.ts +0 -1
  52. package/dist/src/lang/core.d.ts +0 -56
  53. package/dist/src/lang/docs.d.ts +0 -69
  54. package/dist/src/lang/emitters/ast.d.ts +0 -24
  55. package/dist/src/lang/emitters/dts.d.ts +0 -48
  56. package/dist/src/lang/emitters/from-ts.d.ts +0 -94
  57. package/dist/src/lang/emitters/js-tests.d.ts +0 -70
  58. package/dist/src/lang/emitters/js-wasm.d.ts +0 -15
  59. package/dist/src/lang/emitters/js.d.ts +0 -175
  60. package/dist/src/lang/eval.d.ts +0 -63
  61. package/dist/src/lang/index.d.ts +0 -216
  62. package/dist/src/lang/inference.d.ts +0 -40
  63. package/dist/src/lang/linter.d.ts +0 -53
  64. package/dist/src/lang/metadata-cache.d.ts +0 -172
  65. package/dist/src/lang/parser-params.d.ts +0 -37
  66. package/dist/src/lang/parser-transforms.d.ts +0 -281
  67. package/dist/src/lang/parser-types.d.ts +0 -175
  68. package/dist/src/lang/parser.d.ts +0 -56
  69. package/dist/src/lang/runtime.d.ts +0 -454
  70. package/dist/src/lang/schema.d.ts +0 -35
  71. package/dist/src/lang/tests.d.ts +0 -94
  72. package/dist/src/lang/transpiler.d.ts +0 -25
  73. package/dist/src/lang/types.d.ts +0 -147
  74. package/dist/src/lang/wasm.d.ts +0 -83
  75. package/dist/src/rbac/index.d.ts +0 -85
  76. package/dist/src/rbac/rules.d.ts +0 -184
  77. package/dist/src/runtime.d.ts +0 -4
  78. package/dist/src/store/index.d.ts +0 -3
  79. package/dist/src/store/indexeddb.d.ts +0 -6
  80. package/dist/src/store/interface.d.ts +0 -90
  81. package/dist/src/store/memory.d.ts +0 -10
  82. package/dist/src/test-examples.d.ts +0 -41
  83. package/dist/src/test-utils.d.ts +0 -86
  84. package/dist/src/transpiler/index.d.ts +0 -6
  85. package/dist/src/transpiler/parser.d.ts +0 -4
  86. package/dist/src/transpiler/transformer.d.ts +0 -4
  87. package/dist/src/transpiler/type-system/inference.d.ts +0 -1
  88. package/dist/src/transpiler/types.d.ts +0 -4
  89. package/dist/src/types/LegalDate.d.ts +0 -241
  90. package/dist/src/types/Timestamp.d.ts +0 -233
  91. package/dist/src/types/Type.d.ts +0 -234
  92. package/dist/src/types/index.d.ts +0 -8
  93. package/dist/src/vm/atoms/batteries.d.ts +0 -6
  94. package/dist/src/vm/atoms/browser.d.ts +0 -18
  95. package/dist/src/vm/atoms/index.d.ts +0 -10
  96. package/dist/src/vm/index.d.ts +0 -12
  97. package/dist/src/vm/runtime.d.ts +0 -333
  98. package/dist/src/vm/vm.d.ts +0 -28
  99. package/dist/src/vm.d.ts +0 -4
  100. package/dist/test-preprocess.d.ts +0 -1
  101. package/dist/tjs-batteries.js +0 -4
  102. package/dist/tjs-batteries.js.map +0 -15
  103. package/dist/tjs-full.js +0 -426
  104. package/dist/tjs-full.js.map +0 -45
  105. package/dist/tjs-src/runtime.d.ts +0 -1
  106. package/dist/tjs-transpiler.js +0 -3
  107. package/dist/tjs-transpiler.js.map +0 -11
  108. package/dist/tjs-vm.js +0 -54
  109. package/dist/tjs-vm.js.map +0 -22
@@ -1,94 +0,0 @@
1
- /**
2
- * TypeScript to TJS Transpiler
3
- *
4
- * Converts TypeScript source to TJS (or directly to JS + metadata).
5
- *
6
- * Two modes:
7
- * 1. TS → TJS (for inspection/migration)
8
- * 2. TS → JS + __tjs metadata (for production)
9
- *
10
- * @example
11
- * ```typescript
12
- * // Input TypeScript:
13
- * function greet(name: string, age?: number): string {
14
- * return `Hello, ${name}!`
15
- * }
16
- *
17
- * // Output TJS:
18
- * function greet(name: '', age = 0) -> '' {
19
- * return `Hello, ${name}!`
20
- * }
21
- *
22
- * // Output JS + metadata:
23
- * function greet(name, age) {
24
- * return `Hello, ${name}!`
25
- * }
26
- * greet.__tjs = {
27
- * params: { name: { type: 'string', required: true }, age: { type: 'number', required: false } },
28
- * returns: { type: 'string' }
29
- * }
30
- * ```
31
- */
32
- export interface FromTSOptions {
33
- /** Emit TJS intermediate instead of JS + metadata */
34
- emitTJS?: boolean;
35
- /** Include sourcemap */
36
- sourceMap?: boolean;
37
- /** Filename for error messages */
38
- filename?: string;
39
- }
40
- export interface FromTSResult {
41
- /** The transpiled code (TJS or JS depending on options) */
42
- code: string;
43
- /** Function type metadata (only when emitting JS) */
44
- types?: Record<string, FunctionTypeInfo>;
45
- /** Class type metadata (only when emitting JS) */
46
- classes?: Record<string, ClassTypeInfo>;
47
- /** Any warnings during transpilation */
48
- warnings?: string[];
49
- }
50
- export interface TypeParamInfo {
51
- /** Constraint schema (from `extends`) - example-based */
52
- constraint?: string | Record<string, any>;
53
- /** Default schema (from `= Type`) - example-based */
54
- default?: string | Record<string, any>;
55
- }
56
- export interface FunctionTypeInfo {
57
- name: string;
58
- params: Record<string, ParamTypeInfo>;
59
- returns?: TypeInfo;
60
- description?: string;
61
- /** Generic type parameters with constraints/defaults */
62
- typeParams?: Record<string, TypeParamInfo>;
63
- /** Overload signatures (when function has TS overloads) */
64
- overloads?: FunctionTypeInfo[];
65
- }
66
- export interface ClassTypeInfo {
67
- name: string;
68
- /** Constructor parameters - also serves as the type shape */
69
- constructor?: {
70
- params: Record<string, ParamTypeInfo>;
71
- };
72
- /** Instance methods */
73
- methods: Record<string, FunctionTypeInfo>;
74
- /** Static methods */
75
- staticMethods: Record<string, FunctionTypeInfo>;
76
- /** Generic type parameters */
77
- typeParams?: Record<string, TypeParamInfo>;
78
- }
79
- export interface ParamTypeInfo {
80
- type: TypeInfo;
81
- required: boolean;
82
- default?: any;
83
- description?: string;
84
- }
85
- export interface TypeInfo {
86
- kind: 'string' | 'number' | 'boolean' | 'null' | 'undefined' | 'array' | 'tuple' | 'object' | 'union' | 'any';
87
- items?: TypeInfo;
88
- /** For tuples: element types in order */
89
- elements?: TypeInfo[];
90
- shape?: Record<string, TypeInfo>;
91
- members?: TypeInfo[];
92
- nullable?: boolean;
93
- }
94
- export declare function fromTS(source: string, options?: FromTSOptions): FromTSResult;
@@ -1,70 +0,0 @@
1
- /**
2
- * TJS Test Execution
3
- *
4
- * Handles transpile-time test execution, signature validation, and test utilities.
5
- */
6
- import type { ExtractedTest, ExtractedMock } from '../tests';
7
- export interface TestResult {
8
- /** Test description */
9
- description: string;
10
- /** Whether the test passed */
11
- passed: boolean;
12
- /** Error message if failed */
13
- error?: string;
14
- /** Whether this was an implicit signature test */
15
- isSignatureTest?: boolean;
16
- /** Source line number (1-indexed) where the test or error occurred */
17
- line?: number;
18
- /** Source column number (1-indexed) */
19
- column?: number;
20
- }
21
- /**
22
- * Strip import/export syntax for test execution context
23
- * Tests run in new Function() which doesn't support ES modules
24
- *
25
- * Useful for:
26
- * - Running tests in new Function() context
27
- * - CLI test runners
28
- * - Bundler plugins that need to extract module code
29
- */
30
- export declare function stripModuleSyntax(code: string): string;
31
- /**
32
- * Strip the __tjs runtime preamble from transpiled code
33
- * This is needed when injecting resolved imports into a test context
34
- * that already has its own __tjs stub
35
- *
36
- * Useful for:
37
- * - Combining multiple TJS modules into a single execution context
38
- * - Test runners that provide their own __tjs runtime
39
- * - Bundlers that need to deduplicate runtime setup
40
- */
41
- export declare function stripTjsPreamble(code: string): string;
42
- /**
43
- * Info about a signature test (extracted but not yet executed)
44
- */
45
- interface SignatureTestInfo {
46
- funcName: string;
47
- args: unknown[];
48
- expected: unknown;
49
- defaults?: Record<string, unknown>;
50
- line: number;
51
- isAsync?: boolean;
52
- }
53
- /**
54
- * Extract signature test info from source without executing
55
- */
56
- export declare function extractSignatureTestInfos(originalSource: string): SignatureTestInfo[];
57
- /**
58
- * Run all tests (explicit blocks + signature tests) in a single execution context
59
- * This executes the module only once, then runs all tests against that context
60
- */
61
- export declare function runAllTests(tests: ExtractedTest[], mocks: ExtractedMock[], sigTestInfos: SignatureTestInfo[], transpiledCode: string, resolvedImports?: Record<string, string>, extensions?: Map<string, Set<string>>): TestResult[];
62
- /**
63
- * Extract return type example from source, handling nested braces
64
- */
65
- export declare function extractReturnExampleFromSource(source: string): string | null;
66
- export {};
67
- /**
68
- * Compile WASM blocks and generate bootstrap code that embeds the compiled bytes
69
- * and instantiates them on load.
70
- */
@@ -1,15 +0,0 @@
1
- /**
2
- * TJS WASM Bootstrap Generation
3
- *
4
- * Compiles inline WASM blocks and generates JavaScript bootstrap code.
5
- */
6
- import type { WasmBlock } from '../parser';
7
- export declare function generateWasmBootstrap(blocks: WasmBlock[]): {
8
- code: string;
9
- results: {
10
- id: string;
11
- success: boolean;
12
- error?: string;
13
- byteLength?: number;
14
- }[];
15
- };
@@ -1,175 +0,0 @@
1
- /**
2
- * TJS to JavaScript Emitter
3
- *
4
- * Transforms TJS source into standard JavaScript with runtime type metadata.
5
- * Unlike the AST emitter (for AgentJS), this outputs executable JS code.
6
- *
7
- * Input:
8
- * function greet(name: 'world') -> '' {
9
- * return `Hello, ${name}!`
10
- * }
11
- *
12
- * Output:
13
- * function greet(name = 'world') {
14
- * return `Hello, ${name}!`
15
- * }
16
- * greet.__tjs = {
17
- * params: { name: { type: 'string', required: true, example: 'world' } },
18
- * returns: { type: 'string' }
19
- * }
20
- *
21
- * TODO: Self-contained output (no runtime dependency)
22
- * =====================================================
23
- * Currently, transpiled code references `globalThis.__tjs` for:
24
- * - __tjs.pushStack() / popStack() - debug stack traces
25
- * - __tjs.typeError() - monadic error creation
26
- * - __tjs.Is() / IsNot() - structural equality (when == / != used)
27
- *
28
- * This requires either:
29
- * 1. The runtime to be installed via installRuntime()
30
- * 2. A stub to be provided (e.g., playground's inline stub)
31
- *
32
- * The ideal is that TJS produces completely independent code that only needs
33
- * things it semantically needs (like fetch for HTTP calls). The runtime
34
- * functions above are ~30 lines and could be inlined when used:
35
- *
36
- * - typeError: Create a simple Error with extra properties
37
- * - pushStack/popStack: Could be no-ops in production, or inline array ops
38
- * - Is/IsNot: ~20 lines for deep structural equality
39
- *
40
- * Options to explore:
41
- * 1. Inline minimal runtime when needed (adds ~1KB unminified per output)
42
- * 2. Add transpile option: { standalone: true } to emit self-contained code
43
- * 3. Tree-shake: only inline the specific functions actually referenced
44
- *
45
- * See also: demo/src/tjs-playground.ts which has a manual __tjs stub that
46
- * must stay in sync with the runtime - a symptom of this leaky abstraction.
47
- */
48
- import type { TypeDescriptor, ParameterDescriptor } from '../types';
49
- export { stripModuleSyntax, stripTjsPreamble } from './js-tests';
50
- export interface TJSTranspileOptions {
51
- /** Filename for error messages */
52
- filename?: string;
53
- /** Include source map comment */
54
- sourceMap?: boolean;
55
- /** Mode: 'dev' | 'strict' | 'production' */
56
- mode?: 'dev' | 'strict' | 'production';
57
- /**
58
- * Test execution mode:
59
- * - true (default): run tests at transpile time, throw on failure
60
- * - false: skip tests entirely (production build)
61
- * - 'only': only run tests, don't emit code (CI/test runner)
62
- * - 'report': run tests, report results in testResults, don't throw
63
- * (caller decides whether to use the code based on results)
64
- */
65
- runTests?: boolean | 'only' | 'report';
66
- /**
67
- * Debug mode: include source locations in __tjs metadata
68
- * Enables better error messages with file:line:column info
69
- */
70
- debug?: boolean;
71
- /**
72
- * Pre-resolved import code for test execution.
73
- * Map of import specifier to compiled JavaScript code.
74
- * Used when tests depend on imported modules.
75
- */
76
- resolvedImports?: Record<string, string>;
77
- }
78
- /** Result of running tests at transpile time */
79
- export type { TestResult } from './js-tests';
80
- import type { TestResult } from './js-tests';
81
- export interface TJSTranspileResult {
82
- /** The transpiled JavaScript code */
83
- code: string;
84
- /** Type information for the function(s) - Record of function name to type info */
85
- types: Record<string, TJSTypeInfo>;
86
- /** Function metadata (alias for types, used by runtime) */
87
- metadata: Record<string, TJSTypeInfo>;
88
- /** Any warnings during transpilation */
89
- warnings?: string[];
90
- /** Generated test runner code (if tests were present) - DEPRECATED, tests now run at transpile time */
91
- testRunner?: string;
92
- /** Number of tests extracted */
93
- testCount?: number;
94
- /** Test results (when runTests is true or 'only') */
95
- testResults?: TestResult[];
96
- /** WASM compilation results (for debugging/inspection) */
97
- wasmCompiled?: {
98
- id: string;
99
- success: boolean;
100
- error?: string;
101
- byteLength?: number;
102
- }[];
103
- }
104
- export interface TJSTypeInfo {
105
- /** Function name */
106
- name: string;
107
- /** Parameter types */
108
- params: Record<string, ParameterDescriptor>;
109
- /** Return type */
110
- returns?: TypeDescriptor;
111
- /** TDoc description */
112
- description?: string;
113
- /** True if function uses destructured object param (the fast path) */
114
- isDestructuredParam?: boolean;
115
- /** The shape of the destructured param (for inline validation) */
116
- destructuredShape?: Record<string, TypeDescriptor>;
117
- /** Which fields in destructuredShape are required */
118
- destructuredRequired?: Set<string>;
119
- }
120
- /**
121
- * Transpile TJS source to JavaScript
122
- *
123
- * This function handles:
124
- * - Files with no functions (just statements/tests)
125
- * - Files with multiple functions
126
- * - Inline validation (no wrappers)
127
- * - __tjs metadata inserted immediately after each function
128
- */
129
- export declare function transpileToJS(source: string, options?: TJSTranspileOptions): TJSTranspileResult;
130
- /**
131
- * Safety options for metadata generation
132
- */
133
- interface SafetyOptions {
134
- /** Function marked with (!) - never validate inputs */
135
- unsafe?: boolean;
136
- /** Function marked with (?) - always validate inputs */
137
- safe?: boolean;
138
- /** Return type safety: 'safe' (-?) or 'unsafe' (-!) */
139
- returnSafety?: 'safe' | 'unsafe';
140
- }
141
- /**
142
- * Generate inline validation code for single-arg object types
143
- *
144
- * This is ~20x faster than schema-based validation because:
145
- * 1. No schema interpretation at runtime
146
- * 2. No object iteration
147
- * 3. JIT can inline the checks
148
- *
149
- * Generated code looks like:
150
- * if (typeof input !== 'object' || input === null ||
151
- * typeof input.x !== 'number' ||
152
- * typeof input.y !== 'number') {
153
- * return __tjs.typeError('funcName.input', 'object', input)
154
- * }
155
- */
156
- export declare function generateInlineValidation(funcName: string, paramName: string, shape: Record<string, TypeDescriptor>, requiredFields: Set<string>): string;
157
- /**
158
- * Generate the complete function wrapper with inline validation
159
- *
160
- * For destructured object params, this generates:
161
- *
162
- * const _original_funcName = funcName
163
- * funcName = function(__input) {
164
- * if (typeof __input !== 'object' || __input === null || ...) {
165
- * return __tjs.typeError('funcName.input', 'object', __input)
166
- * }
167
- * return _original_funcName.call(this, __input)
168
- * }
169
- *
170
- * For single named object params, same pattern with the actual param name.
171
- */
172
- export declare function generateInlineWrapper(funcName: string, types: TJSTypeInfo, safety?: SafetyOptions): string | null;
173
- /**
174
- * Fuzzy comparison for floating point numbers
175
- */
@@ -1,63 +0,0 @@
1
- /**
2
- * Safe Eval and SafeFunction - VM-backed dynamic code execution
3
- *
4
- * Import this module explicitly when you need to execute code dynamically.
5
- * This pulls in the AJS transpiler and VM (~50KB gzipped).
6
- *
7
- * For static code (pre-transpiled), use the lite runtime instead.
8
- */
9
- /** Capabilities that can be injected into SafeFunction/Eval */
10
- export interface SafeCapabilities {
11
- /** Fetch function for HTTP requests */
12
- fetch?: typeof globalThis.fetch;
13
- /** Console for logging */
14
- console?: Pick<typeof console, 'log' | 'warn' | 'error'>;
15
- /** Additional capabilities to expose */
16
- [key: string]: unknown;
17
- }
18
- /** Options for Eval */
19
- export interface EvalOptions {
20
- /** Code to evaluate (expression or statements with return) */
21
- code: string;
22
- /** Context variables available to the code */
23
- context?: Record<string, unknown>;
24
- /** Fuel budget (default: 1000) */
25
- fuel?: number;
26
- /** Timeout in milliseconds (default: fuel * 10) */
27
- timeoutMs?: number;
28
- /** Capabilities to inject (fetch, console, etc.) */
29
- capabilities?: SafeCapabilities;
30
- }
31
- /**
32
- * Safely evaluate code in a sandboxed VM with fuel metering
33
- */
34
- export declare function Eval(options: EvalOptions): Promise<{
35
- result: unknown;
36
- fuelUsed: number;
37
- error?: {
38
- message: string;
39
- };
40
- }>;
41
- /** Options for SafeFunction */
42
- export interface SafeFunctionOptions {
43
- /** Function body code */
44
- body: string;
45
- /** Parameter names (in order) */
46
- params?: string[];
47
- /** Fuel budget per invocation (default: 1000) */
48
- fuel?: number;
49
- /** Timeout in milliseconds (default: fuel * 10) */
50
- timeoutMs?: number;
51
- /** Capabilities to inject (fetch, console, etc.) */
52
- capabilities?: SafeCapabilities;
53
- }
54
- /**
55
- * Create a reusable sandboxed function with fuel metering
56
- */
57
- export declare function SafeFunction(options: SafeFunctionOptions): Promise<(...args: unknown[]) => Promise<{
58
- result: unknown;
59
- fuelUsed: number;
60
- error?: {
61
- message: string;
62
- };
63
- }>>;
@@ -1,216 +0,0 @@
1
- /**
2
- * AsyncJS Transpiler
3
- *
4
- * Transforms AsyncJS ("Better JavaScript") into tjs-lang AST.
5
- *
6
- * @example
7
- * ```typescript
8
- * import { ajs, transpile } from 'tjs-lang'
9
- *
10
- * // Simple function
11
- * const ast = ajs(`
12
- * function greet({ name }) {
13
- * let msg = template({ tmpl: 'Hello {{name}}', vars: { name } })
14
- * return { msg }
15
- * }
16
- * `)
17
- *
18
- * // Execute
19
- * const vm = new AgentVM()
20
- * await vm.run(ast, { name: 'World' })
21
- * ```
22
- */
23
- import type { SeqNode } from '../builder';
24
- import type { TranspileOptions, TranspileResult, FunctionSignature } from './types';
25
- export * from './types';
26
- export { parse, preprocess, extractTDoc } from './parser';
27
- export { transformFunction } from './emitters/ast';
28
- export { transpileToJS, stripModuleSyntax, stripTjsPreamble, type TJSTranspileOptions, type TJSTranspileResult, type TJSTypeInfo, } from './emitters/js';
29
- export { generateDTS, typeDescriptorToTS, type GenerateDTSOptions, } from './emitters/dts';
30
- export { fromTS, type FromTSOptions, type FromTSResult, } from './emitters/from-ts';
31
- export * from './inference';
32
- export { Schema } from './schema';
33
- export { MetadataCache, getGlobalCache, setGlobalCache } from './metadata-cache';
34
- export { lint, type LintResult, type LintDiagnostic, type LintOptions, } from './linter';
35
- export { generateDocs, generateDocsMarkdown, type DocResult, type DocItem, type FunctionTypeInfo, type ParamTypeInfo, } from './docs';
36
- export { extractTests, assertFunction, expectFunction, testUtils, type ExtractedTest, type ExtractedMock, type TestExtractionResult, } from './tests';
37
- export { runtime, installRuntime, isError, error, typeOf, checkType, validateArgs, wrap, emitRuntimeWrapper, TJS_VERSION, type TJSError, } from './runtime';
38
- export { compileToWasm, instantiateWasm, registerWasmBlock, compileWasmBlocks, type WasmCompileResult, } from './wasm';
39
- export type { WasmBlock } from './parser';
40
- export { Eval, SafeFunction, type EvalOptions, type SafeFunctionOptions, } from './eval';
41
- export { hashSource, hashSourceSync, type CacheEntry, type CachedTranspileResult, type CachedTJSResult, type CacheStats, } from './metadata-cache';
42
- import { MetadataCache } from './metadata-cache';
43
- /**
44
- * Transpile JavaScript source code to Agent99 AST
45
- *
46
- * @param source - JavaScript source code containing a single function
47
- * @param options - Transpilation options
48
- * @returns The AST, signature, and any warnings
49
- *
50
- * @example
51
- * ```typescript
52
- * const result = transpile(`
53
- * function search(query: 'string', limit = 10) {
54
- * let results = storeSearch({ query, limit })
55
- * return { results }
56
- * }
57
- * `)
58
- *
59
- * console.log(result.signature)
60
- * // {
61
- * // name: 'search',
62
- * // parameters: {
63
- * // query: { type: 'string', required: true },
64
- * // limit: { type: 'number', required: false, default: 10 }
65
- * // }
66
- * // }
67
- * ```
68
- */
69
- export declare function transpile(source: string, options?: TranspileOptions): TranspileResult;
70
- /**
71
- * Transpile AsyncJS source and return just the AST.
72
- * Works as both a function and a tagged template literal.
73
- *
74
- * @example
75
- * ```typescript
76
- * // As a function
77
- * const ast = ajs(`
78
- * function agent({ topic }) {
79
- * let results = search({ query: topic })
80
- * return { results }
81
- * }
82
- * `)
83
- *
84
- * // As a tagged template literal
85
- * const ast2 = ajs`
86
- * function greet({ name }) {
87
- * let msg = template({ tmpl: 'Hello {{name}}', vars: { name } })
88
- * return { msg }
89
- * }
90
- * `
91
- * ```
92
- */
93
- export declare function ajs(strings: TemplateStringsArray, ...values: any[]): SeqNode;
94
- export declare function ajs(source: string): SeqNode;
95
- /**
96
- * Transpile TJS source to JavaScript with type metadata.
97
- * Works as both a function and a tagged template literal.
98
- *
99
- * @example
100
- * ```typescript
101
- * // As a function
102
- * const result = tjs(`
103
- * function greet(name: 'world') -> '' {
104
- * return \`Hello, \${name}!\`
105
- * }
106
- * `)
107
- * console.log(result.code)
108
- * // function greet(name = 'world') { return \`Hello, \${name}!\` }
109
- * // greet.__tjs = { params: { name: { type: 'string', required: true } }, returns: { type: 'string' } }
110
- *
111
- * // As a tagged template literal
112
- * const result2 = tjs`
113
- * function add(a: 0, b: 0) -> 0 {
114
- * return a + b
115
- * }
116
- * `
117
- * ```
118
- */
119
- import { type TJSTranspileResult, type TJSTranspileOptions } from './emitters/js';
120
- export declare function tjs(strings: TemplateStringsArray, ...values: any[]): TJSTranspileResult;
121
- export declare function tjs(source: string, options?: TJSTranspileOptions): TJSTranspileResult;
122
- /**
123
- * Transpile with caching support
124
- *
125
- * Uses IndexedDB to cache transpilation results. On cache hit,
126
- * returns immediately without re-parsing. Particularly useful for
127
- * playground editors and development workflows.
128
- *
129
- * @example
130
- * ```typescript
131
- * const cache = new MetadataCache()
132
- * await cache.open()
133
- *
134
- * // First call: parses and caches
135
- * const result1 = await transpileWithCache(source, {}, cache)
136
- *
137
- * // Second call: returns from cache
138
- * const result2 = await transpileWithCache(source, {}, cache)
139
- * ```
140
- */
141
- export declare function transpileWithCache(source: string, options?: TranspileOptions, cache?: MetadataCache): Promise<TranspileResult>;
142
- /**
143
- * Transpile TJS to JavaScript with caching support
144
- *
145
- * @example
146
- * ```typescript
147
- * const cache = new MetadataCache()
148
- * await cache.open()
149
- *
150
- * // First call: transpiles and caches
151
- * const result1 = await tjsWithCache(source, {}, cache)
152
- *
153
- * // Second call: returns from cache
154
- * const result2 = await tjsWithCache(source, {}, cache)
155
- * ```
156
- */
157
- export declare function tjsWithCache(source: string, options?: import('./emitters/js').TJSTranspileOptions, cache?: MetadataCache): Promise<import('./emitters/js').TJSTranspileResult>;
158
- /**
159
- * Create a function with attached signature for introspection
160
- *
161
- * This wraps the transpiled AST in a callable that includes
162
- * the .signature property for self-documentation.
163
- *
164
- * @example
165
- * ```typescript
166
- * const search = createAgent(`
167
- * function search(query: 'string', limit = 10) {
168
- * let results = storeSearch({ query, limit })
169
- * return { results }
170
- * }
171
- * `, vm)
172
- *
173
- * // Introspect
174
- * console.log(search.signature.parameters)
175
- *
176
- * // Execute
177
- * const result = await search({ query: 'hello' })
178
- * ```
179
- */
180
- export declare function createAgent(source: string, vm: {
181
- run: (ast: any, args: any, options?: any) => Promise<any>;
182
- }, runOptions?: {
183
- fuel?: number;
184
- capabilities?: any;
185
- }): ((args: Record<string, any>) => Promise<any>) & {
186
- signature: FunctionSignature;
187
- ast: SeqNode;
188
- };
189
- /**
190
- * Get tool definitions from a set of agent functions
191
- *
192
- * This converts function signatures to OpenAI-compatible tool definitions.
193
- *
194
- * @example
195
- * ```typescript
196
- * const search = createAgent(searchSource, vm)
197
- * const summarize = createAgent(summarizeSource, vm)
198
- *
199
- * const tools = getToolDefinitions({ search, summarize })
200
- * // Ready to pass to LLM API
201
- * ```
202
- */
203
- export declare function getToolDefinitions(agents: Record<string, {
204
- signature: FunctionSignature;
205
- }>): Array<{
206
- type: 'function';
207
- function: {
208
- name: string;
209
- description?: string;
210
- parameters: {
211
- type: 'object';
212
- properties: Record<string, any>;
213
- required: string[];
214
- };
215
- };
216
- }>;
@@ -1,40 +0,0 @@
1
- /**
2
- * Type inference from value patterns
3
- *
4
- * Extracts types from example values:
5
- * 'string' -> { kind: 'string' }
6
- * 10 -> { kind: 'number' }
7
- * ['string'] -> { kind: 'array', items: { kind: 'string' } }
8
- * { name: 'string' } -> { kind: 'object', shape: { name: { kind: 'string' } } }
9
- * 'string' | null -> { kind: 'string', nullable: true }
10
- * 'string' | 0 -> { kind: 'union', members: [{ kind: 'string' }, { kind: 'number' }] }
11
- */
12
- import type { Expression, Pattern } from 'acorn';
13
- import type { TypeDescriptor, ParameterDescriptor } from './types';
14
- /**
15
- * Infer type from a value expression (example value)
16
- */
17
- export declare function inferTypeFromValue(node: Expression): TypeDescriptor;
18
- /**
19
- * Parse a parameter and extract its type and default value
20
- *
21
- * @param param - The AST node for the parameter
22
- * @param requiredParams - Optional set of parameter names that are required (from colon syntax)
23
- */
24
- export declare function parseParameter(param: Pattern, requiredParams?: Set<string>): ParameterDescriptor;
25
- /**
26
- * Extract a literal value from an expression for default values
27
- */
28
- export declare function extractLiteralValue(node: Expression): any;
29
- /**
30
- * Parse return type from a type annotation expression
31
- */
32
- export declare function parseReturnType(typeExpr: string): TypeDescriptor;
33
- /**
34
- * Convert TypeDescriptor to a human-readable string
35
- */
36
- export declare function typeToString(type: TypeDescriptor): string;
37
- /**
38
- * Check if a value matches a type descriptor
39
- */
40
- export declare function checkType(value: any, type: TypeDescriptor): boolean;