diff --git a/CHANGELOG.md b/CHANGELOG.md index 778012a..b0a0898 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,14 @@ All `@seamscript/*` packages and `create-seamscript` are released together, with one version number. Releases are on GitHub: https://github.com/Shogo256/SeamScript/releases -## Unreleased +## 0.1.2 + +### Added + +- **Deadlines for `latest` calls: `f.within(ms)(...args)`.** A call that has not settled `ms` milliseconds after it started aborts its `AbortSignal` and resolves to `Timeout` (`{ ok: false, error: { kind: "timeout", ms } }`), or to `Stale` if a newer call started meanwhile. It shares the line with plain calls, on a function and on a fork. Before, a deadline meant a `setTimeout` race written by hand, which neither aborted the request nor kept the latest-wins guarantee. Found by an app whose server calls an AI with a 2-second budget (CS Pro's chat widget). +- **SEAM1403: a `fetch` in a latest function that does not take the function's signal.** Such a request keeps running after the call is superseded, cancelled or out of time, so the server keeps working (and paying) for an answer nobody reads. The quick fix passes `signal`. An init object that is not a literal, or that spreads another object, is left alone. +- **`poll(read, { every, maxEvery?, onResult })`** in `@seamscript/runtime`: reads one at a time, `every` ms apart after each read ends, doubles the wait after failures up to `maxEvery`, starts no read while the page is hidden (and reads at once when it is shown if one fell due), and stops for good on `stop()`, aborting a read in flight. For state a page must notice changing on the server, such as a switch that turns a feature off. + ### Fixed diff --git a/DECISIONS.md b/DECISIONS.md index c95ed13..61675cf 100644 --- a/DECISIONS.md +++ b/DECISIONS.md @@ -85,6 +85,7 @@ In development builds the compiler doesn't import `@seamscript/core`, so during | SEAM1301 | A Text other than `Text` / `Text` | | SEAM1401 | A latest function can't be a generator | | SEAM1402 | The type of a latest function's AbortSignal parameter isn't written as `AbortSignal` | +| SEAM1403 | A `fetch` in a latest function doesn't take the function's signal | | SEAM2001 | Unknown flows to an exit other than decode | | SEAM2002 | A call that takes Unknown and returns any / unknown | | SEAM2003 | A source method is referenced without being called | @@ -357,6 +358,14 @@ The goal was to let the frontend of a real-time voice interpretation app be writ - **`file.readJson` rejects malformed JSON with a SyntaxError naming only the path**: `JSON.parse`'s own message quotes the text. To get malformed JSON back as a DecodeError, `decode T from json await file.readText(path)`. - **Found on the way: spreading Unknown into an object literal or JSX props is SEAM2001 everywhere.** The copy's type has only the brand's symbol key, which TypeScript lets pass as `Record` and the like, so `{ ...JSON.parse(s) }` let the fields out unchecked. An object spread can never keep data Unknown, so it is always reported (an array spread is still allowed where the destination keeps Unknown). +## Deadlines, polling and fetch signals (0.1.2) + +Found by the first production app (CS Pro's chat widget), which asks a server that asks an AI, with a 2-second budget: it raced `fetch` against a `setTimeout` by hand, so a late request kept running on the client and, through the server, at the AI, and a reply arriving after the user had moved on could still be shown. Three small additions, each the least that removes that class of bug: + +- **`within(ms)` on a latest line, not a new keyword.** A deadline is a property of one call site (the same function is called with 2 s from a text box and 10 s from a chat), so it is a method that returns a call, not part of the declaration. It shares the generation line: a newer call still makes it `Stale`, which wins over `Timeout`, so a screen never shows a timeout for a question the user has already replaced. On expiry it aborts only its own signal, never a newer call's. `Timeout` is a separate `Err` kind rather than `Stale`, because the caller acts on it (falls back), whereas `Stale` is to be ignored. The TLA+ model is unchanged: a timeout is one more way for the current call to settle, delivered under the same generation check. +- **SEAM1403 checks only what it can see.** A `fetch` in a latest function's body (including nested callbacks) with no init, or with an object-literal init without `signal`, is reported. An init in a variable, or a literal with a spread, is not: the checker can't tell what is in it, and a false error would teach people to silence the check. Any `signal` property counts (`AbortSignal.any([signal, ...])` is legitimate). +- **`poll` is a runtime function, not language.** Polling has no data that needs the compiler: the reads are ordinary (decode, Result). It runs one read at a time instead of on a fixed timer, so a slow server is never hit by overlapping reads; backs off only on failure; and pauses while the page is hidden, because a background tab polling every few minutes, in every tab a user keeps open, is load nobody sees. Long polling, SSE and debounce stay out: no app here needs them yet. + ## Open questions ### From the demonstration diff --git a/demo/seamscript/package.json b/demo/seamscript/package.json index de3a1b8..6d5a425 100644 --- a/demo/seamscript/package.json +++ b/demo/seamscript/package.json @@ -8,10 +8,10 @@ "test": "vitest run" }, "dependencies": { - "@seamscript/runtime": "0.1.1" + "@seamscript/runtime": "0.1.2" }, "devDependencies": { - "@seamscript/compiler": "0.1.1", + "@seamscript/compiler": "0.1.2", "typescript": "5.9.3", "vite": "8.3.4", "vitest": "5.0.3" diff --git a/packages/compiler/README.md b/packages/compiler/README.md index 88811ae..bf84f98 100644 --- a/packages/compiler/README.md +++ b/packages/compiler/README.md @@ -71,6 +71,7 @@ A declared method that returns a promise gives `Promise`. `seamc`, the | SEAM1302 | `Pcm` / `Planar` with arguments they don't take (`Pcm`, a rate that isn't a positive whole number, `Planar`) | | SEAM1401 | A latest function can't be a generator | | SEAM1402 | The type of a latest function's AbortSignal parameter isn't written as `AbortSignal` | +| SEAM1403 | A `fetch` in a latest function doesn't take the function's signal | | SEAM2001 | Unknown flows to an exit other than decode (`as`, assignment to `unknown` or `any`, templates, `+`, `in`, `throw`, and so on) | | SEAM2002 | A call that takes Unknown and returns any / unknown | | SEAM2003 | A method that is a source of outside data is referenced without being called | @@ -80,7 +81,7 @@ A declared method that returns a promise gives `Promise`. `seamc`, the | SEAM2201 | A value containing a bigint is passed to `JSON.stringify` (pass `Order.encode(o)` instead) | | SEAM9001 | Editor plugin only, a warning: the editor's TypeScript is not the version `seamc` checks with (5.9), so the type errors it shows can differ from `seamc check` | -Every message says how to fix the problem. In the editor, the mechanical fixes are quick fixes: SEAM2001, SEAM2005 and TypeScript's assignment errors on a typed variable (`const o: Order = JSON.parse(s)` becomes `const o = decode Order from JSON.parse(s)`), SEAM2101 (`Text.length(t)`, `Text.at(t, i)`), SEAM2201 (`Order.encode(o)`, `orders.map(Order.encode)`) and SEAM1402 (write `AbortSignal`). +Every message says how to fix the problem. In the editor, the mechanical fixes are quick fixes: SEAM2001, SEAM2005 and TypeScript's assignment errors on a typed variable (`const o: Order = JSON.parse(s)` becomes `const o = decode Order from JSON.parse(s)`), SEAM2101 (`Text.length(t)`, `Text.at(t, i)`), SEAM2201 (`Order.encode(o)`, `orders.map(Order.encode)`) SEAM1402 (write `AbortSignal`) and SEAM1403 (pass `signal`). ## Bundlers diff --git a/packages/compiler/package.json b/packages/compiler/package.json index d99ac2b..c49fece 100644 --- a/packages/compiler/package.json +++ b/packages/compiler/package.json @@ -1,6 +1,6 @@ { "name": "@seamscript/compiler", - "version": "0.1.1", + "version": "0.1.2", "description": "SeamScript compiler: expands .seam.ts into plain TypeScript and checks boundaries", "keywords": [ "seamscript", @@ -69,13 +69,13 @@ "dependencies": { "@babel/types": "8.0.6", "@jridgewell/trace-mapping": "0.3.31", - "@seamscript/parser": "0.1.1", + "@seamscript/parser": "0.1.2", "magic-string": "1.4.3", "typescript": "5.9.3", "unplugin": "3.4.0" }, "devDependencies": { - "@seamscript/runtime": "0.1.1", + "@seamscript/runtime": "0.1.2", "@types/node": "24.19.2", "rollup": "4.64.6", "vite": "8.3.4", diff --git a/packages/compiler/src/checker.ts b/packages/compiler/src/checker.ts index 5b60222..d6bec4e 100644 --- a/packages/compiler/src/checker.ts +++ b/packages/compiler/src/checker.ts @@ -670,6 +670,52 @@ export function createChecker(ts: typeof import("typescript"), options: CheckerO } }; + // A latest function hands each call an AbortSignal and aborts it when the call is + // superseded, cancelled (fork().cancel()) or out of time (within(ms)). A fetch in its body + // that does not take the signal keeps running after the call is dropped: the server keeps + // working, and pays, for an answer nobody reads. + const fetchChecked = new Set(); + const isFetch = (callee: ts.Expression): boolean => { + if (!ts.isIdentifier(callee) || callee.text !== "fetch") return false; + let symbol = checker.getSymbolAtLocation(callee); + if (symbol && symbol.flags & ts.SymbolFlags.Alias) symbol = checker.getAliasedSymbol(symbol); + return (symbol?.declarations ?? []).some((d) => program.isSourceFileDefaultLibrary(d.getSourceFile()) || runtime?.isRuntimeDeclaration(d) === true); + }; + const checkLatestFetch = (call: ts.CallExpression) => { + if (call.arguments.length !== 2 || !ts.isIdentifier(call.expression) || call.expression.text !== "__latestFor") return; + const target = call.arguments[0]!; + const name = ts.isExpressionWithTypeArguments(target) ? target.expression : target; + const decl = checker.getSymbolAtLocation(name)?.valueDeclaration; + if (decl === undefined || !ts.isFunctionDeclaration(decl) || decl.body === undefined || fetchChecked.has(decl)) return; + fetchChecked.add(decl); + const signal = decl.parameters.at(-1)?.name; + if (signal === undefined || !ts.isIdentifier(signal)) return; + const walk = (node: ts.Node): void => { + if (ts.isCallExpression(node) && isFetch(node.expression)) { + const init = node.arguments[1]; + const missing = + init === undefined + ? true + : ts.isObjectLiteralExpression(init) && + !init.properties.some((p) => ts.isSpreadAssignment(p) || (p.name !== undefined && ts.isIdentifier(p.name) && p.name.text === "signal")); + if (missing) { + const edits = + init === undefined + ? [{ pos: node.arguments[0]!.getEnd(), end: node.arguments[0]!.getEnd(), text: `, { signal: ${signal.text} }` }] + : [{ pos: (init as ts.ObjectLiteralExpression).getStart(file) + 1, end: (init as ts.ObjectLiteralExpression).getStart(file) + 1, text: ` signal: ${signal.text},` }]; + report( + node, + Codes.latestFetchSignal, + `This fetch is in a latest function but does not take its signal, so it keeps running after the call is superseded, cancelled or out of time: pass \`signal: ${signal.text}\`.`, + { description: `Pass the latest function's signal (${signal.text})`, edits }, + ); + } + } + ts.forEachChild(node, walk); + }; + ts.forEachChild(decl.body, walk); + }; + /** Whether a type written in a declaration is `any`, or a type parameter that defaults to `any` (`AxiosResponse`). */ const declaredAny = (type: ts.TypeNode | undefined): boolean => { if (type === undefined) return false; @@ -719,7 +765,10 @@ export function createChecker(ts: typeof import("typescript"), options: CheckerO }; const visit = (node: ts.Node): void => { - if (ts.isCallExpression(node)) checkLatestSignal(node); + if (ts.isCallExpression(node)) { + checkLatestSignal(node); + checkLatestFetch(node); + } if (ts.isCallExpression(node) || ts.isNewExpression(node)) { const args = node.arguments ?? ts.factory.createNodeArray(); const unknownArgs = args.map((arg) => (ts.isSpreadElement(arg) ? arg.expression : arg)).filter((value) => !PRIMITIVE_EXPRESSIONS.has(value.kind) && hasUnknown(value)); diff --git a/packages/compiler/src/diagnostics.ts b/packages/compiler/src/diagnostics.ts index 90076a3..50302a9 100644 --- a/packages/compiler/src/diagnostics.ts +++ b/packages/compiler/src/diagnostics.ts @@ -27,6 +27,7 @@ export const Codes = { audioType: "SEAM1302", latestShape: "SEAM1401", latestSignal: "SEAM1402", + latestFetchSignal: "SEAM1403", unknownFlow: "SEAM2001", unknownLaunder: "SEAM2002", sourceReference: "SEAM2003", diff --git a/packages/compiler/src/transform.ts b/packages/compiler/src/transform.ts index 9f906f2..cf36e13 100644 --- a/packages/compiler/src/transform.ts +++ b/packages/compiler/src/transform.ts @@ -313,8 +313,9 @@ export function transform(source: string, fileName: string, options: TransformOp `}\n` + // A fork of a generic function fixes its type arguments: f.fork(). (tp - ? `${name}.fork = function ${typeParams}() { return __latestFor(${implRef}${options}).fork(); };\n` - : `${name}.fork = () => __latestFor(${impl}${options}).fork();\n`) + + ? `${name}.fork = function ${typeParams}() { return __latestFor(${implRef}${options}).fork(); };\n` + + `${name}.within = function ${typeParams}(ms: number) { return __latestFor(${implRef}${options}).within(ms); };\n` + : `${name}.fork = () => __latestFor(${impl}${options}).fork();\n` + `${name}.within = (ms: number) => __latestFor(${impl}${options}).within(ms);\n`) + `async function ${impl}`, ); helpers.add("__latestFor"); diff --git a/packages/compiler/test/checker.test.ts b/packages/compiler/test/checker.test.ts index 7548006..27e8cc3 100644 --- a/packages/compiler/test/checker.test.ts +++ b/packages/compiler/test/checker.test.ts @@ -255,4 +255,34 @@ export latest async function optional(q: string, signal?: Sig | undefined): Prom [8, "SEAM1402"], ]); }); + + it("reports a fetch in a latest function that does not take the function's signal", () => { + const source = `export latest async function search(q: string, signal: AbortSignal): Promise> { + await fetch("/a"); + await fetch("/b", { method: "POST" }); + await fetch("/c", { signal }); + await fetch("/d", { method: "POST", signal: AbortSignal.any([signal]) }); + const init = { signal }; + await fetch("/e", init); + await fetch("/f", { ...init }); + const inner = async () => fetch("/g"); + await inner(); + return { ok: true, value: q }; +} +export latest async function noSignal(q: string): Promise> { + await fetch("/h"); + return { ok: true, value: q }; +} +export async function notLatest(q: string) { + await fetch("/i"); + return q; +} +search.within(1000)("x"); +`; + expect(codesByLine(source)).toEqual([ + [2, "SEAM1403"], + [3, "SEAM1403"], + [9, "SEAM1403"], + ]); + }); }); diff --git a/packages/compiler/test/golden/expected/cases/errors-declarations.seam.ts.golden b/packages/compiler/test/golden/expected/cases/errors-declarations.seam.ts.golden index d617158..5658f9f 100644 --- a/packages/compiler/test/golden/expected/cases/errors-declarations.seam.ts.golden +++ b/packages/compiler/test/golden/expected/cases/errors-declarations.seam.ts.golden @@ -51,6 +51,7 @@ export function withAlias(...args: __LatestArgs): return __latestFor(withAlias__impl).apply(undefined, args); } withAlias.fork = () => __latestFor(withAlias__impl).fork(); +withAlias.within = (ms: number) => __latestFor(withAlias__impl).within(ms); async function withAlias__impl(q: string, signal: Signal) { void signal; return ok(q); diff --git a/packages/compiler/test/golden/expected/cases/latest.seam.ts.golden b/packages/compiler/test/golden/expected/cases/latest.seam.ts.golden index 979fa4b..6c65e7a 100644 --- a/packages/compiler/test/golden/expected/cases/latest.seam.ts.golden +++ b/packages/compiler/test/golden/expected/cases/latest.seam.ts.golden @@ -7,6 +7,7 @@ export function search(...args: __LatestArgs): __Late return __latestFor(search__impl, { signal: 1 }).apply(undefined, args); } search.fork = () => __latestFor(search__impl, { signal: 1 }).fork(); +search.within = (ms: number) => __latestFor(search__impl, { signal: 1 }).within(ms); async function search__impl(q: Text<"NFC">, signal: AbortSignal) { const res = await fetch(`/search?q=${encodeURIComponent(q)}`, { signal }); return __decode(__b.array(Order), await res.json()); @@ -16,6 +17,7 @@ export function count(...args: __LatestArgs): __Lates return __latestFor(count__impl).apply(undefined, args); } count.fork = () => __latestFor(count__impl).fork(); +count.within = (ms: number) => __latestFor(count__impl).within(ms); async function count__impl(n: number) { return ok(n + 1); } @@ -24,6 +26,7 @@ export function get(...args: __LatestArgs, return __latestFor(get__impl, { signal: 1 }).apply(undefined, args); } get.fork = function () { return __latestFor(get__impl, { signal: 1 }).fork(); }; +get.within = function (ms: number) { return __latestFor(get__impl, { signal: 1 }).within(ms); }; async function get__impl(key: string, signal: AbortSignal): Promise> { void key; void signal; diff --git a/packages/compiler/test/golden/expected/demo/src/search.seam.ts.golden b/packages/compiler/test/golden/expected/demo/src/search.seam.ts.golden index a1f47a9..a74200e 100644 --- a/packages/compiler/test/golden/expected/demo/src/search.seam.ts.golden +++ b/packages/compiler/test/golden/expected/demo/src/search.seam.ts.golden @@ -7,6 +7,7 @@ function search(...args: __LatestArgs): __LatestRetu return __latestFor(search__impl).apply(undefined, args); } search.fork = () => __latestFor(search__impl).fork(); +search.within = (ms: number) => __latestFor(search__impl).within(ms); async function search__impl(query: string) { const res = await fetch(`/api/search?q=${encodeURIComponent(query)}`); return __decode(SearchResult, await res.json()); diff --git a/packages/compiler/test/golden/expected/sandbox-app/src/feed.seam.ts.golden b/packages/compiler/test/golden/expected/sandbox-app/src/feed.seam.ts.golden index 028beff..e25e8e3 100644 --- a/packages/compiler/test/golden/expected/sandbox-app/src/feed.seam.ts.golden +++ b/packages/compiler/test/golden/expected/sandbox-app/src/feed.seam.ts.golden @@ -85,6 +85,7 @@ function loadSnapshot(...args: __LatestArgs): _ return __latestFor(loadSnapshot__impl, { signal: 0 }).apply(undefined, args); } loadSnapshot.fork = () => __latestFor(loadSnapshot__impl, { signal: 0 }).fork(); +loadSnapshot.within = (ms: number) => __latestFor(loadSnapshot__impl, { signal: 0 }).within(ms); async function loadSnapshot__impl(signal: AbortSignal) { const r = await getJson("/api/snapshot", signal); if (!r.ok) return r; diff --git a/packages/compiler/test/golden/expected/sandbox-app/src/orders.seam.ts.golden b/packages/compiler/test/golden/expected/sandbox-app/src/orders.seam.ts.golden index 949a645..99073ff 100644 --- a/packages/compiler/test/golden/expected/sandbox-app/src/orders.seam.ts.golden +++ b/packages/compiler/test/golden/expected/sandbox-app/src/orders.seam.ts.golden @@ -9,6 +9,7 @@ export function searchInstruments(...args: __LatestArgs __latestFor(searchInstruments__impl, { signal: 1 }).fork(); +searchInstruments.within = (ms: number) => __latestFor(searchInstruments__impl, { signal: 1 }).within(ms); async function searchInstruments__impl(query: Text<"NFC">, signal: AbortSignal) { const r = await getJson(`/api/instruments?q=${encodeURIComponent(query)}`, signal); if (!r.ok) return r; @@ -20,6 +21,7 @@ export function loadOrderDetail(...args: __LatestArgs __latestFor(loadOrderDetail__impl, { signal: 1 }).fork(); +loadOrderDetail.within = (ms: number) => __latestFor(loadOrderDetail__impl, { signal: 1 }).within(ms); async function loadOrderDetail__impl(id: Int64, signal: AbortSignal) { const r = await getJson(`/api/orders/${id}`, signal); if (!r.ok) return r; diff --git a/packages/compiler/test/transform.test.ts b/packages/compiler/test/transform.test.ts index 11ff224..5f06f69 100644 --- a/packages/compiler/test/transform.test.ts +++ b/packages/compiler/test/transform.test.ts @@ -265,6 +265,7 @@ describe("latest", () => { " return __latestFor(search__impl).apply(undefined, args);\n" + "}\n" + "search.fork = () => __latestFor(search__impl).fork();\n" + + "search.within = (ms: number) => __latestFor(search__impl).within(ms);\n" + "async function search__impl(q: string) {\n return ok(q);\n}", ); }); @@ -292,6 +293,7 @@ describe("latest", () => { " return __latestFor(get__impl, { signal: 1 }).apply(undefined, args);\n" + "}\n" + "get.fork = function () { return __latestFor(get__impl, { signal: 1 }).fork(); };\n" + + "get.within = function (ms: number) { return __latestFor(get__impl, { signal: 1 }).within(ms); };\n" + "async function get__impl(key: K, signal: AbortSignal): Promise>> {}", ); expect(out).toContain("type Stale as __Stale"); diff --git a/packages/core/package.json b/packages/core/package.json index 14c25ae..9b6444e 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@seamscript/core", - "version": "0.1.1", + "version": "0.1.2", "description": "WASM core for SeamScript's Text: grapheme segmentation and normalization at a pinned Unicode version", "keywords": [ "seamscript", @@ -43,7 +43,7 @@ "access": "public" }, "devDependencies": { - "@seamscript/runtime": "0.1.1", + "@seamscript/runtime": "0.1.2", "@types/node": "24.19.2", "fast-check": "4.10.2", "typescript": "5.9.3", @@ -51,7 +51,7 @@ "vitest": "5.0.3" }, "peerDependencies": { - "@seamscript/runtime": "0.1.1" + "@seamscript/runtime": "0.1.2" }, "engines": { "node": ">=20" diff --git a/packages/create-seamscript/package.json b/packages/create-seamscript/package.json index 6d69bc6..0796531 100644 --- a/packages/create-seamscript/package.json +++ b/packages/create-seamscript/package.json @@ -1,6 +1,6 @@ { "name": "create-seamscript", - "version": "0.1.1", + "version": "0.1.2", "description": "Start a SeamScript app: `npm create seamscript my-app` sets up Vite, seamc check, the WASM core and editor support", "keywords": [ "seamscript", diff --git a/packages/parser/package.json b/packages/parser/package.json index 6368a3a..9adb689 100644 --- a/packages/parser/package.json +++ b/packages/parser/package.json @@ -1,6 +1,6 @@ { "name": "@seamscript/parser", - "version": "0.1.1", + "version": "0.1.2", "description": "Fork of @babel/parser 8.0.7 that adds SeamScript syntax: boundary, decode … from, latest", "keywords": [ "seamscript", diff --git a/packages/react/package.json b/packages/react/package.json index 07c9ef8..3d23d5b 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -1,6 +1,6 @@ { "name": "@seamscript/react", - "version": "0.1.1", + "version": "0.1.2", "description": "React bindings for SeamScript: useFork gives a component its own line of a latest function, cancelled on unmount", "keywords": [ "seamscript", @@ -36,11 +36,11 @@ "access": "public" }, "peerDependencies": { - "@seamscript/runtime": "0.1.1", + "@seamscript/runtime": "0.1.2", "react": ">=18" }, "devDependencies": { - "@seamscript/runtime": "0.1.1", + "@seamscript/runtime": "0.1.2", "@types/react": "19.3.0", "@types/react-dom": "19.3.0", "happy-dom": "20.14.5", diff --git a/packages/runtime/README.md b/packages/runtime/README.md index 90e5cb6..fa01474 100644 --- a/packages/runtime/README.md +++ b/packages/runtime/README.md @@ -107,6 +107,21 @@ if (!r.ok && r.error.kind === "stale") return; // a newer search has started `search.fork()` returns a copy with its own, independent generation. Keep one per component and call `cancel()` on unmount; every call made through that copy then becomes `Stale`. In React, `useFork(search)` from `@seamscript/react` does both. For a generic function, fix the type arguments, as in `search.fork()`. The guarantee holds only when you apply the result in the first continuation right after `await` (don't put another `await` in between). +`search.within(2000)(q)` is the same call with a deadline: if it has not settled 2 seconds after it started, its signal is aborted and it resolves to `Timeout` (`{ ok: false, error: { kind: "timeout", ms: 2000 } }`); if a newer call started meanwhile, it is `Stale` as usual. Calls through `within` and plain calls share one line, on a function and on a fork. Pass the signal on to `fetch` (the compiler reports a fetch that doesn't take it, SEAM1403), or the request goes on after the deadline. + +```ts +const r = await choose.within(2000)(input); +if (!r.ok && r.error.kind === "timeout") return fallback(input); +``` + +## poll + +`poll(read, { every, maxEvery?, onResult })` reads again and again, for state that can change on the server while a page is open. One read runs at a time; the next starts `every` ms after the previous one ended. After a failure (an `Err`, or a throw) the wait doubles, up to `maxEvery` (default `every * 8`), and a success brings it back. While the page is hidden no read starts, and when it is shown a read that fell due starts at once. `read` gets an `AbortSignal`; `stop()` aborts a read in flight and drops its result; `now()` reads at once, or right after a read in flight. + +```ts +const status = poll((signal) => readStatus(signal), { every: 5 * 60_000, onResult: (r) => r.ok && r.value.stopped && unmount() }); +``` + ## Unknown and fetch `Unknown` is the type of data from outside, and its only exits are `decode` and `Unknown.log(v)` (for debugging; it only prints the value). Which values are outside data is decided by the compiler: the web APIs that deliver it (`Body.json`, `text`, `arrayBuffer` and `bytes`, `Blob.arrayBuffer` and `bytes`, `MediaStreamTrack.getSettings`, an AudioWorklet's `process` inputs, `JSON.parse`, `Storage.getItem`, `URLSearchParams.get`, `MessageEvent.data`, `IDBRequest.result`, `Clipboard.readText`, `Blob.text`, `FileReader.result`, `Location.hash`, `History.state`, `Document.cookie`, and others), plus whatever the project declares in `tsconfig.json` (see `@seamscript/compiler`). Inside `.seam.ts`, `fetch` comes from this package: underneath it is the global `fetch`, but `res.json()` has the type `Promise`. diff --git a/packages/runtime/package.json b/packages/runtime/package.json index cf366de..b57c883 100644 --- a/packages/runtime/package.json +++ b/packages/runtime/package.json @@ -1,6 +1,6 @@ { "name": "@seamscript/runtime", - "version": "0.1.1", + "version": "0.1.2", "description": "Runtime library for SeamScript: boundary decoders, latest, Text / Int64 / Decimal / Zoned", "keywords": [ "seamscript", diff --git a/packages/runtime/src/index.ts b/packages/runtime/src/index.ts index 19945b1..03aa0cb 100644 --- a/packages/runtime/src/index.ts +++ b/packages/runtime/src/index.ts @@ -1,4 +1,4 @@ -export { type Ok, type Err, type Result, type DecodeError, type DecodeRule, type Stale, ok, err } from "./result.js"; +export { type Ok, type Err, type Result, type DecodeError, type DecodeRule, type Stale, type Timeout, ok, err } from "./result.js"; export { Pcm, type Bytes, type Planar, type SampleFormat, type Samples, type ChannelArrays } from "./audio.js"; export { Unknown, UnknownAccess, __unknown, __unknownAsync, __unknownEach, __box, __unbox } from "./unknown.js"; export { Int64 } from "./int64.js"; @@ -29,4 +29,5 @@ export { type LatestReturn, } from "./latest.js"; export { fetch, type SeamResponse } from "./fetch.js"; +export { poll, type PollOptions, type Poller } from "./poll.js"; export { ChunkStream, type StreamPolicy, type StreamEvent, type StreamStats, type StreamAction } from "./stream.js"; diff --git a/packages/runtime/src/latest.ts b/packages/runtime/src/latest.ts index b475951..9fb92b3 100644 --- a/packages/runtime/src/latest.ts +++ b/packages/runtime/src/latest.ts @@ -1,10 +1,16 @@ -import { type Result, type Stale, STALE } from "./result.js"; +import { type Result, type Stale, STALE, type Timeout, timeout } from "./result.js"; export type LatestCall = (...args: A) => Promise; export type Latest = LatestCall & { /** A copy with its own generation line: its calls never make other lines' calls stale. */ fork(): LatestFork; + /** + * The same line with a deadline: a call that has not settled `ms` milliseconds after it + * started aborts its `AbortSignal` and resolves to `Timeout` (or `Stale`, if a newer call + * started meanwhile). Calls through `within` and plain calls share one generation line. + */ + within(ms: number): LatestCall; }; export type LatestFork = Latest & { @@ -40,7 +46,7 @@ export function __latest ): Latest; export function __latest(fn: AnyFn, options?: LatestOptions): Latest> { const root = line(fn, options?.signal); - return Object.assign(root.call, { fork: root.fork }); + return Object.assign(root.call, { fork: root.fork, within: root.within }); } const declared = new WeakMap>>(); @@ -61,7 +67,7 @@ export function __latestFor(fn: AnyFn, options?: LatestOptions): Latest + (...args: unknown[]): Promise | Stale | Timeout> => { + if (!(Number.isFinite(ms) && ms >= 0)) throw new RangeError(`within: the deadline must be a finite number of milliseconds >= 0, not ${ms}`); + const settled = call(...args); + const gen = generation; + const mine = controller; + return new Promise((resolve, reject) => { + const timer = setTimeout(() => { + if (gen !== generation) return resolve(STALE); + // Only this call's signal: a newer call has its own controller. + if (controller === mine) { + mine?.abort(); + controller = undefined; + } + resolve(timeout(ms)); + }, ms); + // Once the timer has resolved this promise, the later settlement is ignored, including + // the AbortError the abort above causes, so nothing goes unhandled. + settled.then( + (value) => { + clearTimeout(timer); + resolve(value); + }, + (error: unknown) => { + clearTimeout(timer); + reject(error); + }, + ); + }); + }; + const fork = (): LatestFork> => { const l = line(fn, signalIndex); - return Object.assign(l.call, { fork: l.fork, cancel: l.cancel }); + return Object.assign(l.call, { fork: l.fork, cancel: l.cancel, within: l.within }); }; - return { call, cancel, fork }; + return { call, cancel, fork, within }; } diff --git a/packages/runtime/src/poll.ts b/packages/runtime/src/poll.ts new file mode 100644 index 0000000..b669646 --- /dev/null +++ b/packages/runtime/src/poll.ts @@ -0,0 +1,105 @@ +import type { Result } from "./result.js"; + +export interface PollOptions { + /** Milliseconds from the end of one read to the start of the next, while reads succeed. */ + readonly every: number; + /** + * After a failed read (an `Err`, or a throw) the wait doubles, up to this many milliseconds; + * the next success brings it back to `every`. Defaults to `every * 8`. + */ + readonly maxEvery?: number; + /** Each read's `Result`, in order. Never called after `stop()`. */ + readonly onResult: (result: R) => void; +} + +export interface Poller { + /** Reads now instead of at the next tick; if a read is in flight, reads again right after it. */ + now(): void; + /** Stops for good: aborts a read in flight (its result is dropped) and clears the timer. */ + stop(): void; +} + +/** + * Reads `read` again and again: one read at a time, `every` ms apart, backing off after + * failures. While the page is hidden (`document.visibilityState`) no read starts; when it is + * shown again, a read that fell due meanwhile starts at once. The first read starts at once. + * + * A read that throws counts as a failure for the backoff but has no `Result` to deliver; + * return an `Err` for failures the caller should see. + */ +export function poll>(read: (signal: AbortSignal) => Promise, options: PollOptions): Poller { + const every = options.every; + const maxEvery = options.maxEvery ?? every * 8; + if (!(Number.isFinite(every) && every > 0)) throw new RangeError(`poll: every must be a finite number of milliseconds > 0, not ${every}`); + if (!(Number.isFinite(maxEvery) && maxEvery >= every)) throw new RangeError(`poll: maxEvery must be a finite number >= every, not ${maxEvery}`); + + const page = typeof document === "undefined" ? undefined : document; + let wait = every; + let timer: ReturnType | undefined; + let controller: AbortController | undefined; + let due = false; + let again = false; + let stopped = false; + + const hidden = () => page?.visibilityState === "hidden"; + + const schedule = (ms: number) => { + timer = setTimeout(() => { + timer = undefined; + tick(); + }, ms); + }; + + const tick = () => { + if (stopped) return; + if (hidden()) { + due = true; + return; + } + due = false; + const c = (controller = new AbortController()); + const settle = (result: R | undefined) => { + if (stopped || c !== controller) return; + controller = undefined; + const failed = result === undefined || !result.ok; + wait = failed ? Math.min(maxEvery, wait * 2) : every; + if (result !== undefined) options.onResult(result); + if (stopped) return; + if (again) { + again = false; + tick(); + } else { + schedule(wait); + } + }; + new Promise((resolve) => resolve(read(c.signal))).then(settle, () => settle(undefined)); + }; + + const onVisibility = () => { + if (!hidden() && due && controller === undefined) tick(); + }; + page?.addEventListener("visibilitychange", onVisibility); + + tick(); + + return { + now() { + if (stopped) return; + if (controller !== undefined) { + again = true; + return; + } + if (timer !== undefined) clearTimeout(timer); + timer = undefined; + tick(); + }, + stop() { + stopped = true; + if (timer !== undefined) clearTimeout(timer); + timer = undefined; + controller?.abort(); + controller = undefined; + page?.removeEventListener("visibilitychange", onVisibility); + }, + }; +} diff --git a/packages/runtime/src/result.ts b/packages/runtime/src/result.ts index b1c77da..d8af92d 100644 --- a/packages/runtime/src/result.ts +++ b/packages/runtime/src/result.ts @@ -41,6 +41,13 @@ export type DecodeError = { export type Stale = Err<{ kind: "stale" }>; +/** A `latest` call that did not settle before its deadline (`f.within(ms)`). */ +export type Timeout = Err<{ kind: "timeout"; ms: number }>; + +export function timeout(ms: number): Timeout { + return Object.freeze({ ok: false, error: Object.freeze({ kind: "timeout", ms }) } as const); +} + export function ok(value: T): Ok { return { ok: true, value }; } diff --git a/packages/runtime/test/latest.test.ts b/packages/runtime/test/latest.test.ts index 78e2bd7..96adef0 100644 --- a/packages/runtime/test/latest.test.ts +++ b/packages/runtime/test/latest.test.ts @@ -245,3 +245,103 @@ describe("errors from the function's own Result", () => { expect(await fn(-1)).toEqual({ ok: false, error: { kind: "negative" } }); }); }); + +describe("within (deadlines)", () => { + afterEach(() => vi.useRealTimers()); + + /** A latest function with a signal that settles only when the test says so, or rejects on abort. */ + function slow() { + const pending: ReturnType>>[] = []; + const signals: AbortSignal[] = []; + const fn = __latest( + async (q: string, signal: AbortSignal) => { + const d = deferred>(); + pending.push(d); + signals.push(signal); + signal.addEventListener("abort", () => d.reject(signal.reason)); + const r = await d.promise; + return r.ok ? ok(`${q}:${r.value}`) : r; + }, + { signal: 1 }, + ); + return { fn, pending, signals }; + } + + it("delivers a call that settles before its deadline", async () => { + vi.useFakeTimers(); + const { fn, pending } = slow(); + const call = fn.within(2000)("a"); + pending[0]!.resolve(ok("1")); + expect(await call).toEqual({ ok: true, value: "a:1" }); + }); + + it("aborts a call that misses its deadline and resolves it to Timeout, without an unhandled AbortError", async () => { + vi.useFakeTimers(); + const { fn, signals } = slow(); + const call = fn.within(2000)("a"); + await vi.advanceTimersByTimeAsync(1999); + expect(signals[0]!.aborted).toBe(false); + await vi.advanceTimersByTimeAsync(1); + expect(await call).toEqual({ ok: false, error: { kind: "timeout", ms: 2000 } }); + expect(signals[0]!.aborted).toBe(true); + }); + + it("ignores a result that arrives after the deadline", async () => { + vi.useFakeTimers(); + const fn = __latest(async (q: string) => { + await new Promise((r) => setTimeout(r, 3000)); + return ok(q); + }); + const call = fn.within(1000)("late"); + await vi.advanceTimersByTimeAsync(3000); + expect(await call).toEqual({ ok: false, error: { kind: "timeout", ms: 1000 } }); + }); + + it("makes a call Stale, not Timeout, when a newer call started before its deadline", async () => { + vi.useFakeTimers(); + const { fn, pending, signals } = slow(); + const first = fn.within(2000)("a"); + const second = fn.within(2000)("ab"); + expect(signals[0]!.aborted).toBe(true); + await vi.advanceTimersByTimeAsync(2000); + expect(await first).toEqual(STALE); + expect(await second).toEqual({ ok: false, error: { kind: "timeout", ms: 2000 } }); + expect(pending).toHaveLength(2); + }); + + it("does not abort a newer plain call when an older call's deadline passes", async () => { + vi.useFakeTimers(); + const { fn, pending, signals } = slow(); + const first = fn.within(1000)("a"); + const second = fn("ab"); + await vi.advanceTimersByTimeAsync(1000); + expect(await first).toEqual(STALE); + expect(signals[1]!.aborted).toBe(false); + pending[1]!.resolve(ok("2")); + expect(await second).toEqual({ ok: true, value: "ab:2" }); + }); + + it("shares a fork's line, and a fork's cancel makes a pending deadline call Stale", async () => { + vi.useFakeTimers(); + const { fn, signals } = slow(); + const line = fn.fork(); + const call = line.within(5000)("a"); + line.cancel(); + expect(signals[0]!.aborted).toBe(true); + expect(await call).toEqual(STALE); + }); + + it("propagates the latest call's own rejection before its deadline", async () => { + vi.useFakeTimers(); + const fn = __latest(async () => { + throw new Error("boom"); + }); + await expect(fn.within(1000)()).rejects.toThrow("boom"); + }); + + it("refuses a deadline that is not a finite number of milliseconds", () => { + const fn = __latest(async () => ok(1)); + expect(() => fn.within(Number.NaN)()).toThrow(RangeError); + expect(() => fn.within(-1)()).toThrow(RangeError); + }); +}); diff --git a/packages/runtime/test/poll.test.ts b/packages/runtime/test/poll.test.ts new file mode 100644 index 0000000..303e4ca --- /dev/null +++ b/packages/runtime/test/poll.test.ts @@ -0,0 +1,142 @@ +import { afterEach, describe, expect, it, vi } from "vitest"; +import { err, ok, poll, type Result } from "../src/index.js"; + +type R = Result; + +/** A read whose calls the test settles one by one. */ +function reads() { + const pending: { resolve: (r: R) => void; reject: (e: unknown) => void; signal: AbortSignal }[] = []; + const read = (signal: AbortSignal) => + new Promise((resolve, reject) => { + pending.push({ resolve, reject, signal }); + }); + return { read, pending }; +} + +/** A stand-in for `document` with a visibility the test can flip. */ +function fakeDocument() { + const target = new EventTarget(); + const doc = Object.assign(target, { visibilityState: "visible" as DocumentVisibilityState }); + vi.stubGlobal("document", doc); + return (state: DocumentVisibilityState) => { + doc.visibilityState = state; + target.dispatchEvent(new Event("visibilitychange")); + }; +} + +afterEach(() => { + vi.useRealTimers(); + vi.unstubAllGlobals(); +}); + +describe("poll", () => { + it("reads at once, then every ms after each read ends, one read at a time", async () => { + vi.useFakeTimers(); + const { read, pending } = reads(); + const seen: R[] = []; + const p = poll(read, { every: 1000, onResult: (r) => seen.push(r) }); + expect(pending).toHaveLength(1); + await vi.advanceTimersByTimeAsync(5000); + expect(pending).toHaveLength(1); // the first read is still in flight + pending[0]!.resolve(ok(1)); + await vi.advanceTimersByTimeAsync(999); + expect(pending).toHaveLength(1); + await vi.advanceTimersByTimeAsync(1); + expect(pending).toHaveLength(2); + expect(seen).toEqual([ok(1)]); + p.stop(); + }); + + it("doubles the wait after failures up to maxEvery, and goes back to every after a success", async () => { + vi.useFakeTimers(); + const { read, pending } = reads(); + const seen: R[] = []; + const p = poll(read, { every: 100, maxEvery: 300, onResult: (r) => seen.push(r) }); + const gaps: number[] = []; + let last = Date.now(); + const settleNext = async (r: R | "throw") => { + const current = pending[pending.length - 1]!; + if (r === "throw") current.reject(new Error("network")); + else current.resolve(r); + const before = pending.length; + while (pending.length === before) await vi.advanceTimersByTimeAsync(10); + gaps.push(Date.now() - last); + last = Date.now(); + }; + await settleNext(err("a")); // 200 + await settleNext("throw"); // 300 (capped) + await settleNext(err("b")); // 300 + await settleNext(ok(1)); // 100 + expect(gaps).toEqual([200, 300, 300, 100]); + // A throw has no Result to deliver. + expect(seen).toEqual([err("a"), err("b"), ok(1)]); + p.stop(); + }); + + it("starts no read while the page is hidden, and reads at once when it is shown if one fell due", async () => { + vi.useFakeTimers(); + const show = fakeDocument(); + const { read, pending } = reads(); + const p = poll(read, { every: 1000, onResult: () => {} }); + pending[0]!.resolve(ok(1)); + await vi.advanceTimersByTimeAsync(0); + show("hidden"); + await vi.advanceTimersByTimeAsync(10_000); + expect(pending).toHaveLength(1); + show("visible"); + expect(pending).toHaveLength(2); + p.stop(); + }); + + it("does not read on being shown when no read fell due", async () => { + vi.useFakeTimers(); + const show = fakeDocument(); + const { read, pending } = reads(); + const p = poll(read, { every: 1000, onResult: () => {} }); + pending[0]!.resolve(ok(1)); + await vi.advanceTimersByTimeAsync(0); + show("hidden"); + show("visible"); + expect(pending).toHaveLength(1); + await vi.advanceTimersByTimeAsync(1000); + expect(pending).toHaveLength(2); + p.stop(); + }); + + it("now() reads at once, or right after a read in flight", async () => { + vi.useFakeTimers(); + const { read, pending } = reads(); + const p = poll(read, { every: 60_000, onResult: () => {} }); + p.now(); // a read is in flight: queue one more + expect(pending).toHaveLength(1); + pending[0]!.resolve(ok(1)); + await vi.advanceTimersByTimeAsync(0); + expect(pending).toHaveLength(2); + pending[1]!.resolve(ok(2)); + await vi.advanceTimersByTimeAsync(0); + p.now(); // idle: read at once instead of in a minute + expect(pending).toHaveLength(3); + p.stop(); + }); + + it("stop() aborts the read in flight, drops its result and reads no more", async () => { + vi.useFakeTimers(); + const { read, pending } = reads(); + const seen: R[] = []; + const p = poll(read, { every: 100, onResult: (r) => seen.push(r) }); + p.stop(); + expect(pending[0]!.signal.aborted).toBe(true); + pending[0]!.resolve(ok(1)); + await vi.advanceTimersByTimeAsync(1000); + expect(seen).toEqual([]); + expect(pending).toHaveLength(1); + p.now(); + expect(pending).toHaveLength(1); + }); + + it("refuses intervals that are not positive finite milliseconds", () => { + const { read } = reads(); + expect(() => poll(read, { every: 0, onResult: () => {} })).toThrow(RangeError); + expect(() => poll(read, { every: 100, maxEvery: 50, onResult: () => {} })).toThrow(RangeError); + }); +}); diff --git a/packages/runtime/test/types.check.ts b/packages/runtime/test/types.check.ts index 6b26154..967e13e 100644 --- a/packages/runtime/test/types.check.ts +++ b/packages/runtime/test/types.check.ts @@ -178,3 +178,23 @@ search.cancel(); // @ts-expect-error latest functions must return a Result __latest(async () => 1); + +// within: the deadline adds Timeout to what a call can resolve to, and keeps the caller's arguments. +async function useWithin() { + const res = await withSignal.within(2000)("q"); + if (res.ok) { + const s: string = res.value; + void s; + } else { + const kind: "stale" | "timeout" = res.error.kind; + void kind; + if (res.error.kind === "timeout") { + const ms: number = res.error.ms; + void ms; + } + } + // @ts-expect-error a deadline call still takes no signal from the caller + void withSignal.within(2000)("q", new AbortController().signal); + void forked.within(10)("abc"); +} +void useWithin; diff --git a/packages/ts-plugin/README.md b/packages/ts-plugin/README.md index 2171caf..4bbef60 100644 --- a/packages/ts-plugin/README.md +++ b/packages/ts-plugin/README.md @@ -12,6 +12,7 @@ Each fix is offered on the diagnostic it repairs, and the fixed code checks clea | SEAM2101 | `t.length` becomes `Text.length(t)`; `t[i]` becomes `Text.at(t, i)` | | SEAM2201 | `JSON.stringify(order)` becomes `JSON.stringify(Order.encode(order))`; an array of a boundary becomes `orders.map(Order.encode)` | | SEAM1402 | The signal parameter's type becomes `AbortSignal` | +| SEAM1403 | `signal` is passed to the fetch | ## Usage diff --git a/packages/ts-plugin/package.json b/packages/ts-plugin/package.json index 8098c5d..85d0b18 100644 --- a/packages/ts-plugin/package.json +++ b/packages/ts-plugin/package.json @@ -1,6 +1,6 @@ { "name": "@seamscript/ts-plugin", - "version": "0.1.1", + "version": "0.1.2", "description": "TypeScript language service plugin for SeamScript: completions, hover, navigation, rename and SeamScript's diagnostics for .seam.ts files in any editor that runs tsserver", "keywords": [ "seamscript", @@ -30,7 +30,7 @@ "access": "public" }, "devDependencies": { - "@seamscript/compiler": "0.1.1", + "@seamscript/compiler": "0.1.2", "@types/node": "24.19.2", "@volar/language-core": "2.4.28", "@volar/typescript": "2.4.28", diff --git a/packages/vscode/package.json b/packages/vscode/package.json index 859ddfe..2dea50a 100644 --- a/packages/vscode/package.json +++ b/packages/vscode/package.json @@ -41,7 +41,7 @@ "test": "vitest run" }, "devDependencies": { - "@seamscript/ts-plugin": "0.1.1", + "@seamscript/ts-plugin": "0.1.2", "@vscode/vsce": "4.0.0", "tm-grammars": "1.32.22", "vitest": "5.0.3", diff --git a/sandbox/app/package.json b/sandbox/app/package.json index fee2ea1..504fa58 100644 --- a/sandbox/app/package.json +++ b/sandbox/app/package.json @@ -10,14 +10,14 @@ "check": "seamc check -p tsconfig.json" }, "dependencies": { - "@seamscript/core": "0.1.1", - "@seamscript/react": "0.1.1", - "@seamscript/runtime": "0.1.1", + "@seamscript/core": "0.1.2", + "@seamscript/react": "0.1.2", + "@seamscript/runtime": "0.1.2", "react": "19.3.0", "react-dom": "19.3.0" }, "devDependencies": { - "@seamscript/compiler": "0.1.1", + "@seamscript/compiler": "0.1.2", "@types/react": "19.3.0", "@types/react-dom": "19.3.0", "@vitejs/plugin-react": "6.1.2", diff --git a/sandbox/backend/package.json b/sandbox/backend/package.json index 75eadcc..7c38fd3 100644 --- a/sandbox/backend/package.json +++ b/sandbox/backend/package.json @@ -13,8 +13,8 @@ "test": "tsc -p tsconfig.json && node --test test/*.test.ts" }, "dependencies": { - "@seamscript/core": "0.1.1", - "@seamscript/runtime": "0.1.1", + "@seamscript/core": "0.1.2", + "@seamscript/runtime": "0.1.2", "ws": "8.22.0" }, "devDependencies": { diff --git a/sandbox/bench/package.json b/sandbox/bench/package.json index 7b1ca5b..47fae43 100644 --- a/sandbox/bench/package.json +++ b/sandbox/bench/package.json @@ -9,13 +9,13 @@ "budgets": "node scripts/check-budgets.ts" }, "dependencies": { - "@seamscript/core": "0.1.1", - "@seamscript/runtime": "0.1.1", + "@seamscript/core": "0.1.2", + "@seamscript/runtime": "0.1.2", "zod": "4.6.6" }, "devDependencies": { "@playwright/test": "1.61.1", - "@seamscript/compiler": "0.1.1", + "@seamscript/compiler": "0.1.2", "@types/node": "24.19.2", "typescript": "5.9.3", "vite": "8.3.4" diff --git a/sandbox/voice/package.json b/sandbox/voice/package.json index cb4b9d0..70aa6f2 100644 --- a/sandbox/voice/package.json +++ b/sandbox/voice/package.json @@ -10,10 +10,10 @@ "check": "seamc check -p tsconfig.json" }, "dependencies": { - "@seamscript/runtime": "0.1.1" + "@seamscript/runtime": "0.1.2" }, "devDependencies": { - "@seamscript/compiler": "0.1.1", + "@seamscript/compiler": "0.1.2", "typescript": "5.9.3", "vite": "8.3.4" }