@jigs.design/server 0.3.3 → 0.3.5
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/dist/compile.js +19 -13
- package/dist/types.d.ts +2 -2
- package/package.json +6 -6
package/dist/compile.js
CHANGED
|
@@ -3,7 +3,7 @@ import { JigsCompileError, JigsError, fatalDiagnostics } from "./errors.js";
|
|
|
3
3
|
import { inputDiagnostics } from "./inputs.js";
|
|
4
4
|
import { outputDiagnostics } from "./outputs.js";
|
|
5
5
|
import { splitPragma, versionDiagnostics } from "./pragma.js";
|
|
6
|
-
import { compileJigs, compileLibrary, spanIn } from "@jigs.design/compiler";
|
|
6
|
+
import { compileJigs, compileLibrary, nearest, spanIn } from "@jigs.design/compiler";
|
|
7
7
|
import { TOOL_RESULTS } from "@jigs.design/prompt";
|
|
8
8
|
import { componentSchema } from "@jigs.design/host";
|
|
9
9
|
import { PROGRAM_FORMAT } from "@jigs.design/protocol";
|
|
@@ -57,7 +57,6 @@ function compileCatalog(catalog) {
|
|
|
57
57
|
}
|
|
58
58
|
return out;
|
|
59
59
|
}
|
|
60
|
-
const TAG = /<([a-z][A-Za-z0-9]*)/g;
|
|
61
60
|
/** Each procedure kind as a diagnostic names it. */
|
|
62
61
|
const KIND_NAMES = {
|
|
63
62
|
action: "an action",
|
|
@@ -69,6 +68,18 @@ const KIND_NAMES = {
|
|
|
69
68
|
function hookFor(kind) {
|
|
70
69
|
return kind === "query" || kind === "data" ? "useQuery" : "useMutation";
|
|
71
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* The host's name nearest to `name`, for an unknown one: one `hook` can
|
|
73
|
+
* read first, so the fix is a rename and not a second error, else any.
|
|
74
|
+
*/
|
|
75
|
+
function nearestProcedure(host, name, hook) {
|
|
76
|
+
const names = Object.keys(host.procedures);
|
|
77
|
+
const fitting = names.filter((entry) => {
|
|
78
|
+
const procedure = host.procedures[entry];
|
|
79
|
+
return procedure !== void 0 && hookFor(procedure.kind) === hook;
|
|
80
|
+
});
|
|
81
|
+
return nearest(name, fitting, 1)[0] ?? nearest(name, names, 1)[0];
|
|
82
|
+
}
|
|
72
83
|
function procedureDiagnostics(host, source, uses) {
|
|
73
84
|
const diagnostics = [];
|
|
74
85
|
const report = (use, code, message) => {
|
|
@@ -95,7 +106,8 @@ function procedureDiagnostics(host, source, uses) {
|
|
|
95
106
|
}
|
|
96
107
|
const procedure = Object.hasOwn(host.procedures, use.name) ? host.procedures[use.name] : void 0;
|
|
97
108
|
if (procedure === void 0) {
|
|
98
|
-
|
|
109
|
+
const near = nearestProcedure(host, use.name, use.hook);
|
|
110
|
+
report(use, "unknown_procedure", `"${use.name}" is not a query, mutation, action or provided data on this host; its handle reports UNKNOWN_PROCEDURE${near === void 0 ? "" : `. Did you mean "${near}"?`}`);
|
|
99
111
|
continue;
|
|
100
112
|
}
|
|
101
113
|
const expected = hookFor(procedure.kind);
|
|
@@ -116,12 +128,6 @@ function procedureTable(host, uses) {
|
|
|
116
128
|
}
|
|
117
129
|
return Object.fromEntries(table);
|
|
118
130
|
}
|
|
119
|
-
/** Tag names written in a source. */
|
|
120
|
-
function tagsIn(source) {
|
|
121
|
-
const tags = /* @__PURE__ */ new Set();
|
|
122
|
-
for (const match of source.matchAll(TAG)) if (match[1] !== void 0) tags.add(match[1]);
|
|
123
|
-
return tags;
|
|
124
|
-
}
|
|
125
131
|
/** The longest canonical props, as JSON, a page accepts. */
|
|
126
132
|
const MAX_PAGE_PROPS = 4096;
|
|
127
133
|
/** A JavaScript identifier, as the compiler requires of a define prop. */
|
|
@@ -229,7 +235,7 @@ function createChecker(host) {
|
|
|
229
235
|
const problem = [...procedureDiagnostics(host, entry.body, uses), ...inputDiagnostics(host, entry.body)][0];
|
|
230
236
|
if (problem !== void 0) throw new Error(`Jig "${entry.name}" failed to compile: line ${problem.span.line}: ${problem.message}`);
|
|
231
237
|
allFacts.set(entry.name, {
|
|
232
|
-
tags:
|
|
238
|
+
tags: fullLibrary.get(entry.name)?.tags ?? /* @__PURE__ */ new Set(),
|
|
233
239
|
uses
|
|
234
240
|
});
|
|
235
241
|
}
|
|
@@ -237,10 +243,10 @@ function createChecker(host) {
|
|
|
237
243
|
const pages = new Set(host.jigs.filter((entry) => entry.page).map((entry) => entry.name));
|
|
238
244
|
const tags = /* @__PURE__ */ new Set([...host.components.components.map((component) => component.name), ...tagLibrary.keys()]);
|
|
239
245
|
/** The tags a source draws, through every jig it uses, and the procedures those jigs call. */
|
|
240
|
-
const reach = (
|
|
246
|
+
const reach = (written, facts) => {
|
|
241
247
|
const drawn = new Set(MARKDOWN_ELEMENTS);
|
|
242
248
|
const uses = [];
|
|
243
|
-
const pending = [...
|
|
249
|
+
const pending = [...written];
|
|
244
250
|
for (let tag = pending.pop(); tag !== void 0; tag = pending.pop()) {
|
|
245
251
|
if (drawn.has(tag)) continue;
|
|
246
252
|
drawn.add(tag);
|
|
@@ -261,7 +267,7 @@ function createChecker(host) {
|
|
|
261
267
|
library
|
|
262
268
|
});
|
|
263
269
|
const own = result.procedures;
|
|
264
|
-
const reached = reach(result.
|
|
270
|
+
const reached = reach(result.tags, facts);
|
|
265
271
|
const diagnostics = [
|
|
266
272
|
...result.diagnostics,
|
|
267
273
|
...procedureDiagnostics(host, body, own),
|
package/dist/types.d.ts
CHANGED
|
@@ -718,8 +718,8 @@ export interface JigsServer<TContext, TPageName extends string = never> {
|
|
|
718
718
|
/**
|
|
719
719
|
* The start of `prompt(mode)` that is the same on every turn: the
|
|
720
720
|
* language and the catalog, before the instructions and procedures. Mark
|
|
721
|
-
* it for a provider's prompt cache
|
|
722
|
-
* `@jigs.design/ai-sdk`).
|
|
721
|
+
* it, and the end of the prompt, for a provider's prompt cache
|
|
722
|
+
* (`cachedInstructions` in `@jigs.design/ai-sdk`).
|
|
723
723
|
*/
|
|
724
724
|
promptPrefix: (mode?: PromptMode) => string;
|
|
725
725
|
/** Changes whenever the compiler, the runtime or the host does. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jigs.design/server",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
4
4
|
"description": "createJigsServer: checks and streams programs, runs procedures, and serves the sandbox frame.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -29,11 +29,11 @@
|
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@jigs.design/
|
|
33
|
-
"@jigs.design/host": "0.3.
|
|
34
|
-
"@jigs.design/
|
|
35
|
-
"@jigs.design/protocol": "0.3.
|
|
36
|
-
"@jigs.design/runtime": "0.3.
|
|
32
|
+
"@jigs.design/compiler": "0.3.5",
|
|
33
|
+
"@jigs.design/host": "0.3.5",
|
|
34
|
+
"@jigs.design/prompt": "0.3.5",
|
|
35
|
+
"@jigs.design/protocol": "0.3.5",
|
|
36
|
+
"@jigs.design/runtime": "0.3.5"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"zod": "^4.0.0"
|