tjs-lang 0.8.0 → 0.8.2
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.
- package/CLAUDE.md +15 -5
- package/CONTEXT.md +4 -0
- package/demo/docs.json +12 -690
- package/demo/examples.test.ts +6 -2
- package/demo/src/playground-shared.ts +48 -16
- package/demo/src/playground-test-results.test.ts +112 -0
- package/demo/src/tjs-playground.ts +11 -5
- package/dist/eslint.config.d.ts +2 -0
- package/dist/index.js +146 -141
- package/dist/index.js.map +4 -4
- package/dist/src/lang/core.d.ts +1 -1
- package/dist/src/lang/dialect.d.ts +35 -0
- package/dist/src/lang/emitters/ast.d.ts +1 -1
- package/dist/src/lang/emitters/js-tests.d.ts +7 -0
- package/dist/src/lang/emitters/js-wasm.d.ts +5 -1
- package/dist/src/lang/emitters/js.d.ts +21 -0
- package/dist/src/lang/index.d.ts +3 -1
- package/dist/src/lang/module-loader.d.ts +125 -0
- package/dist/src/lang/parser-transforms.d.ts +79 -0
- package/dist/src/lang/parser-types.d.ts +50 -0
- package/dist/src/lang/parser.d.ts +18 -0
- package/dist/src/lang/transpiler.d.ts +1 -0
- package/dist/src/lang/types.d.ts +18 -0
- package/dist/src/lang/wasm.d.ts +67 -1
- package/dist/src/vm/runtime.d.ts +18 -0
- package/dist/src/vm/vm.d.ts +15 -1
- package/dist/tjs-batteries.js +2 -2
- package/dist/tjs-batteries.js.map +2 -2
- package/dist/tjs-eval.js +43 -41
- package/dist/tjs-eval.js.map +3 -3
- package/dist/tjs-from-ts.js +2 -2
- package/dist/tjs-from-ts.js.map +2 -2
- package/dist/tjs-lang.js +107 -104
- package/dist/tjs-lang.js.map +4 -4
- package/dist/tjs-vm.js +53 -51
- package/dist/tjs-vm.js.map +3 -3
- package/docs/README.md +2 -0
- package/docs/lm-studio-setup.md +143 -0
- package/docs/universal-endpoint.md +122 -0
- package/llms.txt +9 -2
- package/package.json +24 -4
- package/src/batteries/audit.ts +6 -5
- package/src/batteries/llm.ts +8 -3
- package/src/builder.ts +0 -3
- package/src/cli/commands/check.ts +3 -2
- package/src/cli/commands/emit.ts +4 -2
- package/src/cli/commands/run.ts +6 -2
- package/src/cli/commands/test.ts +1 -1
- package/src/cli/commands/types.ts +2 -2
- package/src/lang/codegen.test.ts +4 -1
- package/src/lang/core.ts +6 -4
- package/src/lang/dialect.test.ts +63 -0
- package/src/lang/dialect.ts +50 -0
- package/src/lang/docs.test.ts +0 -1
- package/src/lang/emitters/ast.ts +145 -2
- package/src/lang/emitters/from-ts.ts +1 -1
- package/src/lang/emitters/js-tests.ts +46 -37
- package/src/lang/emitters/js.ts +19 -3
- package/src/lang/features.test.ts +6 -5
- package/src/lang/index.ts +18 -5
- package/src/lang/linter.ts +1 -1
- package/src/lang/module-loader.test.ts +9 -5
- package/src/lang/module-loader.ts +4 -5
- package/src/lang/parser-params.ts +1 -1
- package/src/lang/parser-transforms.ts +12 -18
- package/src/lang/parser-types.ts +17 -0
- package/src/lang/parser.test.ts +12 -6
- package/src/lang/parser.ts +113 -3
- package/src/lang/perf.test.ts +10 -4
- package/src/lang/runtime.ts +0 -1
- package/src/lang/subset-invariant.test.ts +90 -0
- package/src/lang/transpiler.ts +8 -0
- package/src/lang/types.ts +18 -0
- package/src/lang/wasm.test.ts +22 -16
- package/src/linalg/linalg.test.ts +16 -4
- package/src/linalg/vector-search.bench.test.ts +31 -10
- package/src/types/Type.ts +6 -6
- package/src/use-cases/asymmetric-client-server.test.ts +0 -2
- package/src/use-cases/batteries.test.ts +4 -0
- package/src/use-cases/client-server.test.ts +1 -1
- package/src/use-cases/local-helpers.test.ts +219 -0
- package/src/use-cases/timeout-overrides.test.ts +169 -0
- package/src/use-cases/unbundled-imports.test.ts +0 -1
- package/src/vm/atoms/batteries.ts +17 -3
- package/src/vm/runtime.ts +92 -7
- package/src/vm/vm.ts +50 -10
package/src/vm/vm.ts
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
type RunResult,
|
|
5
5
|
type RuntimeContext,
|
|
6
6
|
type CostOverride,
|
|
7
|
+
type TimeoutOverride,
|
|
7
8
|
coreAtoms,
|
|
8
9
|
AgentError,
|
|
9
10
|
isProcedureToken,
|
|
@@ -13,16 +14,49 @@ import { TypedBuilder, type BaseNode, type BuilderType } from '../builder'
|
|
|
13
14
|
import { validate } from 'tosijs-schema'
|
|
14
15
|
import { transpile } from '../lang/core'
|
|
15
16
|
|
|
16
|
-
/**
|
|
17
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Floor for the run-level default timeout. The actual default is derived from
|
|
19
|
+
* the registered atoms (slowest atom × 2 — see `defaultRunTimeout`), but never
|
|
20
|
+
* drops below this for a VM whose atoms are all fast.
|
|
21
|
+
*/
|
|
22
|
+
const MIN_DEFAULT_RUN_TIMEOUT_MS = 60_000
|
|
18
23
|
|
|
19
24
|
export class AgentVM<M extends Record<string, Atom<any, any>>> {
|
|
20
25
|
readonly atoms: typeof coreAtoms & M
|
|
21
26
|
|
|
27
|
+
private _defaultRunTimeout?: number
|
|
28
|
+
|
|
22
29
|
constructor(customAtoms: M = {} as M) {
|
|
23
30
|
this.atoms = { ...coreAtoms, ...customAtoms }
|
|
24
31
|
}
|
|
25
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Default run-level wall-clock timeout when `run()` is given no explicit
|
|
35
|
+
* `timeoutMs`. Derived as `max(per-atom timeoutMs) × 2` over the registered
|
|
36
|
+
* atoms (with headroom for an agent that chains a couple of slow calls), so
|
|
37
|
+
* the run-level backstop can never be shorter than the slowest single atom's
|
|
38
|
+
* own budget — otherwise that per-atom budget would be dead config (e.g.
|
|
39
|
+
* `llmVision`/`llmPredictBattery` are 120s; a fixed 60s run default would kill
|
|
40
|
+
* them mid-call). Atoms with `timeoutMs: 0` (no timeout, e.g. `seq`) are
|
|
41
|
+
* excluded; the result is floored at {@link MIN_DEFAULT_RUN_TIMEOUT_MS}.
|
|
42
|
+
* Self-adjusting: registering a slower custom atom raises the default.
|
|
43
|
+
*/
|
|
44
|
+
get defaultRunTimeout(): number {
|
|
45
|
+
if (this._defaultRunTimeout === undefined) {
|
|
46
|
+
let slowest = 0
|
|
47
|
+
for (const atom of Object.values(this.atoms)) {
|
|
48
|
+
// undefined timeoutMs means the per-atom default (1000ms); 0 means none.
|
|
49
|
+
const t = (atom as any).timeoutMs ?? 1000
|
|
50
|
+
if (t > 0 && t > slowest) slowest = t
|
|
51
|
+
}
|
|
52
|
+
this._defaultRunTimeout = Math.max(
|
|
53
|
+
MIN_DEFAULT_RUN_TIMEOUT_MS,
|
|
54
|
+
slowest * 2
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
return this._defaultRunTimeout
|
|
58
|
+
}
|
|
59
|
+
|
|
26
60
|
get builder(): BuilderType<typeof coreAtoms & M> {
|
|
27
61
|
return new TypedBuilder(this.atoms) as any
|
|
28
62
|
}
|
|
@@ -77,9 +111,10 @@ export class AgentVM<M extends Record<string, Atom<any, any>>> {
|
|
|
77
111
|
fuel?: number
|
|
78
112
|
capabilities?: Capabilities
|
|
79
113
|
trace?: boolean
|
|
80
|
-
timeoutMs?: number //
|
|
114
|
+
timeoutMs?: number // Wall-clock cap on the whole run (default: slowest atom × 2, min 60s — see defaultRunTimeout)
|
|
81
115
|
signal?: AbortSignal // External abort signal (e.g., from caller)
|
|
82
116
|
costOverrides?: Record<string, CostOverride> // Per-atom fuel cost overrides
|
|
117
|
+
timeoutOverrides?: Record<string, TimeoutOverride> // Per-atom timeout overrides (ms, 0 disables)
|
|
83
118
|
context?: Record<string, any> // Request-scoped metadata (auth, permissions, etc.)
|
|
84
119
|
} = {}
|
|
85
120
|
): Promise<RunResult> {
|
|
@@ -94,7 +129,9 @@ export class AgentVM<M extends Record<string, Atom<any, any>>> {
|
|
|
94
129
|
try {
|
|
95
130
|
ast = transpile(astOrToken).ast as BaseNode
|
|
96
131
|
} catch (e: any) {
|
|
97
|
-
throw new Error(`AJS transpilation failed: ${e.message}
|
|
132
|
+
throw new Error(`AJS transpilation failed: ${e.message}`, {
|
|
133
|
+
cause: e,
|
|
134
|
+
})
|
|
98
135
|
}
|
|
99
136
|
}
|
|
100
137
|
} else {
|
|
@@ -103,9 +140,10 @@ export class AgentVM<M extends Record<string, Atom<any, any>>> {
|
|
|
103
140
|
|
|
104
141
|
const startFuel = options.fuel ?? 1000
|
|
105
142
|
|
|
106
|
-
//
|
|
107
|
-
//
|
|
108
|
-
|
|
143
|
+
// Run-level wall-clock timeout. Agents are typically IO-bound; the default
|
|
144
|
+
// is derived from the registered atoms (slowest × 2) so it always covers the
|
|
145
|
+
// slowest atom's own budget. See `defaultRunTimeout`.
|
|
146
|
+
const timeoutMs = options.timeoutMs ?? this.defaultRunTimeout
|
|
109
147
|
|
|
110
148
|
// Default Capabilities
|
|
111
149
|
const capabilities = options.capabilities ?? {}
|
|
@@ -158,8 +196,10 @@ export class AgentVM<M extends Record<string, Atom<any, any>>> {
|
|
|
158
196
|
output: undefined,
|
|
159
197
|
signal: controller.signal,
|
|
160
198
|
costOverrides: options.costOverrides,
|
|
199
|
+
timeoutOverrides: options.timeoutOverrides,
|
|
161
200
|
context: options.context,
|
|
162
201
|
warnings, // Shared warnings array
|
|
202
|
+
helpers: (ast as any).helpers, // Local helper bodies, called by name via callLocal
|
|
163
203
|
}
|
|
164
204
|
|
|
165
205
|
if (options.trace) {
|
|
@@ -195,7 +235,7 @@ export class AgentVM<M extends Record<string, Atom<any, any>>> {
|
|
|
195
235
|
controller.signal.addEventListener('abort', () => {
|
|
196
236
|
reject(
|
|
197
237
|
new Error(
|
|
198
|
-
`Execution timeout after ${timeoutMs}ms
|
|
238
|
+
`Execution timeout after ${timeoutMs}ms. Pass a higher \`timeoutMs\` to vm.run() or set per-atom \`timeoutOverrides\` for slow IO atoms.`
|
|
199
239
|
)
|
|
200
240
|
)
|
|
201
241
|
})
|
|
@@ -203,7 +243,7 @@ export class AgentVM<M extends Record<string, Atom<any, any>>> {
|
|
|
203
243
|
if (controller.signal.aborted) {
|
|
204
244
|
reject(
|
|
205
245
|
new Error(
|
|
206
|
-
`Execution timeout after ${timeoutMs}ms
|
|
246
|
+
`Execution timeout after ${timeoutMs}ms. Pass a higher \`timeoutMs\` to vm.run() or set per-atom \`timeoutOverrides\` for slow IO atoms.`
|
|
207
247
|
)
|
|
208
248
|
)
|
|
209
249
|
}
|
|
@@ -217,7 +257,7 @@ export class AgentVM<M extends Record<string, Atom<any, any>>> {
|
|
|
217
257
|
controller.signal.aborted
|
|
218
258
|
) {
|
|
219
259
|
ctx.error = new AgentError(
|
|
220
|
-
`Execution timeout after ${timeoutMs}ms
|
|
260
|
+
`Execution timeout after ${timeoutMs}ms. Pass a higher \`timeoutMs\` to vm.run() or set per-atom \`timeoutOverrides\` for slow IO atoms.`,
|
|
221
261
|
'vm.run'
|
|
222
262
|
)
|
|
223
263
|
} else {
|