@jigs.design/server 0.3.1 → 0.3.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/dist/chat.js +6 -2
- package/dist/compile.js +5 -2
- package/dist/core.js +22 -6
- package/dist/model-server.js +13 -3
- package/dist/tool-results.js +20 -0
- package/dist/types.d.ts +17 -0
- package/package.json +6 -6
package/dist/chat.js
CHANGED
|
@@ -218,6 +218,7 @@ function createReplyParser(deps, history) {
|
|
|
218
218
|
};
|
|
219
219
|
if (error !== void 0) block.error = error;
|
|
220
220
|
if (compiled.ref !== null) block.ref = compiled.ref;
|
|
221
|
+
if (compiled.toolKeys !== null && compiled.toolKeys !== void 0) block.toolKeys = compiled.toolKeys;
|
|
221
222
|
return block;
|
|
222
223
|
};
|
|
223
224
|
const emit = (block) => {
|
|
@@ -615,15 +616,18 @@ async function* repairBlock(deps, block) {
|
|
|
615
616
|
else if (event.type === "done") {
|
|
616
617
|
const body = splitPragma(event.source).body;
|
|
617
618
|
deps.parser.remember(block.name, body);
|
|
619
|
+
const { toolKeys: _before, ...rest } = block;
|
|
618
620
|
const repaired = {
|
|
619
|
-
...
|
|
621
|
+
...rest,
|
|
620
622
|
diagnostics: event.diagnostics,
|
|
621
623
|
program: program ?? block.program,
|
|
622
624
|
source: event.source,
|
|
623
625
|
status: "done"
|
|
624
626
|
};
|
|
625
|
-
const
|
|
627
|
+
const compiled = deps.session.checker.compile(body);
|
|
628
|
+
const { ref } = compiled;
|
|
626
629
|
if (ref !== null) repaired.ref = ref;
|
|
630
|
+
if (compiled.toolKeys !== null) repaired.toolKeys = compiled.toolKeys;
|
|
627
631
|
if (result !== void 0) {
|
|
628
632
|
result.status = "done";
|
|
629
633
|
if (ref !== null) result.ref = ref;
|
package/dist/compile.js
CHANGED
|
@@ -4,6 +4,7 @@ import { inputDiagnostics } from "./inputs.js";
|
|
|
4
4
|
import { outputDiagnostics } from "./outputs.js";
|
|
5
5
|
import { splitPragma, versionDiagnostics } from "./pragma.js";
|
|
6
6
|
import { compileJigs, compileLibrary, spanIn } from "@jigs.design/compiler";
|
|
7
|
+
import { TOOL_RESULTS } from "@jigs.design/prompt";
|
|
7
8
|
import { componentSchema } from "@jigs.design/host";
|
|
8
9
|
import { PROGRAM_FORMAT } from "@jigs.design/protocol";
|
|
9
10
|
//#region src/compile.ts
|
|
@@ -270,6 +271,7 @@ function createChecker(host) {
|
|
|
270
271
|
let ref = diagnostics.some((diagnostic) => diagnostic.severity === "error") ? null : refOf(result.program.tree, pages);
|
|
271
272
|
const define = ref === null ? void 0 : fullLibrary.get(ref.name);
|
|
272
273
|
if (ref !== null && (define === void 0 || pagePropsProblem(define, ref.props) !== null)) ref = null;
|
|
274
|
+
const procedures = procedureTable(host, [...own, ...reached.uses]);
|
|
273
275
|
return {
|
|
274
276
|
advise: (placement) => designChecks({
|
|
275
277
|
catalog: host.components,
|
|
@@ -282,10 +284,11 @@ function createChecker(host) {
|
|
|
282
284
|
components: Object.fromEntries(host.components.components.filter((component) => reached.tags.has(component.name)).map((component) => [component.name, componentSchema(component)])),
|
|
283
285
|
format: PROGRAM_FORMAT,
|
|
284
286
|
imageHosts: host.imageHosts,
|
|
285
|
-
procedures
|
|
287
|
+
procedures,
|
|
286
288
|
prose: result.output.constants
|
|
287
289
|
},
|
|
288
|
-
ref
|
|
290
|
+
ref,
|
|
291
|
+
toolKeys: !Object.hasOwn(procedures, TOOL_RESULTS) ? null : reached.uses.some((use) => use.name === TOOL_RESULTS) ? "all" : result.fields[TOOL_RESULTS] ?? []
|
|
289
292
|
};
|
|
290
293
|
};
|
|
291
294
|
const compile = (body) => compileWith(body, tagLibrary, tagFacts);
|
package/dist/core.js
CHANGED
|
@@ -7,6 +7,7 @@ import { confirmMessage, createConfirmer, memoryConfirmations } from "./confirm.
|
|
|
7
7
|
import { processCompileCache, sha256 } from "./compile-cache.js";
|
|
8
8
|
import { eventStream } from "./events.js";
|
|
9
9
|
import { invalidationsOf } from "./invalidation.js";
|
|
10
|
+
import { withToolResults } from "./tool-results.js";
|
|
10
11
|
import { createModelServer } from "./model-server.js";
|
|
11
12
|
import { systemPromptParts } from "@jigs.design/prompt";
|
|
12
13
|
import { isCallPolicy } from "@jigs.design/host";
|
|
@@ -115,17 +116,26 @@ function defineRun(procedures, handlers) {
|
|
|
115
116
|
return handlers;
|
|
116
117
|
}
|
|
117
118
|
function createJigsServer(options) {
|
|
118
|
-
const
|
|
119
|
+
const tools = options.toolResults === true;
|
|
120
|
+
const host = tools ? withToolResults(options.host) : options.host;
|
|
119
121
|
checkMarkdownElements(host.components);
|
|
120
122
|
for (const [name, procedure] of Object.entries(host.procedures)) if (procedure.kind !== "action" && procedure.kind !== "data" && !Object.hasOwn(options.run, name)) throw new Error(`createJigsServer has no run function for "${name}"`);
|
|
121
123
|
const confirmer = confirmerFor(options);
|
|
122
124
|
const checker = createChecker(host);
|
|
123
|
-
const promptOptions = (mode) => options.instructions === void 0 ? {
|
|
125
|
+
const promptOptions = (mode) => options.instructions === void 0 ? {
|
|
126
|
+
mode,
|
|
127
|
+
toolResults: tools
|
|
128
|
+
} : {
|
|
124
129
|
instructions: options.instructions,
|
|
125
|
-
mode
|
|
130
|
+
mode,
|
|
131
|
+
toolResults: tools
|
|
126
132
|
};
|
|
127
|
-
const documentParts = systemPromptParts(host,
|
|
133
|
+
const documentParts = systemPromptParts(options.host, {
|
|
134
|
+
...promptOptions("document"),
|
|
135
|
+
toolResults: false
|
|
136
|
+
});
|
|
128
137
|
const chatParts = systemPromptParts(host, promptOptions("chat"));
|
|
138
|
+
const toolParts = tools ? systemPromptParts(host, promptOptions("document")) : null;
|
|
129
139
|
const system = `${documentParts.stable}\n\n${documentParts.variable}`;
|
|
130
140
|
const chatSystem = `${chatParts.stable}\n\n${chatParts.variable}`;
|
|
131
141
|
const allowedOrigins = new Set((options.allowedOrigins ?? []).map((entry) => originOf(entry)));
|
|
@@ -365,11 +375,13 @@ function createJigsServer(options) {
|
|
|
365
375
|
const stored = splitPragma(source);
|
|
366
376
|
const compiled = checker.compile(stored.body);
|
|
367
377
|
const prefix = source.slice(0, source.length - stored.body.length);
|
|
368
|
-
|
|
378
|
+
const result = {
|
|
369
379
|
advice: belowPrefix(compiled.advise(placement), prefix),
|
|
370
380
|
diagnostics: [...versionDiagnostics(stored.versions, host.components.version), ...belowPrefix(compiled.diagnostics, prefix)],
|
|
371
381
|
program: compiled.program
|
|
372
382
|
};
|
|
383
|
+
if (compiled.toolKeys !== null) result.toolKeys = compiled.toolKeys;
|
|
384
|
+
return result;
|
|
373
385
|
};
|
|
374
386
|
/**
|
|
375
387
|
* `compile` through the process's cache, keyed by what this server
|
|
@@ -713,7 +725,11 @@ function createJigsServer(options) {
|
|
|
713
725
|
handlerDeps,
|
|
714
726
|
host,
|
|
715
727
|
onError,
|
|
716
|
-
prepareSession
|
|
728
|
+
prepareSession,
|
|
729
|
+
toolPrompt: toolParts === null ? null : {
|
|
730
|
+
system: `${toolParts.stable}\n\n${toolParts.variable}`,
|
|
731
|
+
systemPrefix: toolParts.stable
|
|
732
|
+
}
|
|
717
733
|
}, core, modelOptions)
|
|
718
734
|
};
|
|
719
735
|
return core;
|
package/dist/model-server.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { INTERNAL_MESSAGE, JigsError, isJigsError } from "./errors.js";
|
|
2
|
+
import { splitPragma } from "./pragma.js";
|
|
2
3
|
import { createHandler, issuesText, parseBounded } from "./handler.js";
|
|
3
4
|
import { MAX_CONTENT, runSession } from "./session.js";
|
|
4
5
|
import { createReplyParser, repairBlock, streamChat } from "./chat.js";
|
|
6
|
+
import { TOOL_RESULTS } from "@jigs.design/prompt";
|
|
5
7
|
import { z } from "zod";
|
|
6
8
|
//#region src/model-server.ts
|
|
7
9
|
/**
|
|
@@ -54,6 +56,14 @@ function createModelServer(internals, core, options) {
|
|
|
54
56
|
system,
|
|
55
57
|
systemPrefix: core.promptPrefix("document")
|
|
56
58
|
};
|
|
59
|
+
const toolPrompt = internals.toolPrompt;
|
|
60
|
+
const toolSessionDeps = toolPrompt === null ? sessionDeps : {
|
|
61
|
+
...sessionDeps,
|
|
62
|
+
system: toolPrompt.system,
|
|
63
|
+
systemPrefix: toolPrompt.systemPrefix
|
|
64
|
+
};
|
|
65
|
+
/** A session's deps: the slot's prompt when its document reads `toolResults`. */
|
|
66
|
+
const depsFor = (turn) => toolPrompt !== null && turn.document !== null && Object.hasOwn(internals.checker.compile(splitPragma(turn.document).body).program.procedures, TOOL_RESULTS) ? toolSessionDeps : sessionDeps;
|
|
57
67
|
const chat = async (request, chatOptions) => {
|
|
58
68
|
const refused = internals.handlerDeps.http.refusal(request);
|
|
59
69
|
if (refused !== null) throw new JigsError(refused.code, refused.message);
|
|
@@ -98,7 +108,7 @@ function createModelServer(internals, core, options) {
|
|
|
98
108
|
parser,
|
|
99
109
|
prompt: input.data.prompt,
|
|
100
110
|
session: {
|
|
101
|
-
...
|
|
111
|
+
...toolSessionDeps,
|
|
102
112
|
kind: "chat-repair",
|
|
103
113
|
maxRepairs: repairRounds
|
|
104
114
|
}
|
|
@@ -130,7 +140,7 @@ function createModelServer(internals, core, options) {
|
|
|
130
140
|
session: async (body, call) => {
|
|
131
141
|
const prepared = await prepareSession(body, call);
|
|
132
142
|
if ("error" in prepared) return prepared;
|
|
133
|
-
return { turn: (turnCall) => runSession(
|
|
143
|
+
return { turn: (turnCall) => runSession(depsFor(prepared.turn), prepared.turn, prepared.options, turnCall) };
|
|
134
144
|
}
|
|
135
145
|
}),
|
|
136
146
|
maxBodyBytes: core.maxBodyBytes,
|
|
@@ -146,7 +156,7 @@ function createModelServer(internals, core, options) {
|
|
|
146
156
|
};
|
|
147
157
|
return;
|
|
148
158
|
}
|
|
149
|
-
yield* runSession(
|
|
159
|
+
yield* runSession(depsFor(prepared.turn), prepared.turn, prepared.options, context);
|
|
150
160
|
},
|
|
151
161
|
version: core.version
|
|
152
162
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { TOOL_RESULTS, toolResultsSlot } from "@jigs.design/prompt";
|
|
2
|
+
//#region src/tool-results.ts
|
|
3
|
+
/**
|
|
4
|
+
* `host` with the `toolResults` slot added, for a server with
|
|
5
|
+
* `toolResults: true`: the checker, the calls and the prompts that list it
|
|
6
|
+
* see one more provided slot. Throws when the host already has a procedure
|
|
7
|
+
* of that name.
|
|
8
|
+
*/
|
|
9
|
+
function withToolResults(host) {
|
|
10
|
+
if (Object.hasOwn(host.procedures, TOOL_RESULTS)) throw new Error(`The host has a procedure named "${TOOL_RESULTS}", which toolResults: true adds; rename it`);
|
|
11
|
+
return {
|
|
12
|
+
...host,
|
|
13
|
+
procedures: {
|
|
14
|
+
...host.procedures,
|
|
15
|
+
[TOOL_RESULTS]: toolResultsSlot
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { withToolResults };
|
package/dist/types.d.ts
CHANGED
|
@@ -391,6 +391,18 @@ export interface JigsServerOptions<TProcedures extends Procedures, TCatalog exte
|
|
|
391
391
|
* "confirm": the server refuses to start without it.
|
|
392
392
|
*/
|
|
393
393
|
secret?: string;
|
|
394
|
+
/**
|
|
395
|
+
* Adds a provided slot, `toolResults`, for a chat whose agent calls
|
|
396
|
+
* tools: the page passes each block the results of the tools called
|
|
397
|
+
* before it, by tool name (`toolData` in `@jigs.design/ai-sdk/client`),
|
|
398
|
+
* and the block reads them with `useQuery("toolResults")` instead of the
|
|
399
|
+
* model copying them into its source. The chat prompt lists the slot and
|
|
400
|
+
* says how to read it, as do chat repairs and a session on a block's
|
|
401
|
+
* source; a plain session's prompt is unchanged. Fixed for the server's
|
|
402
|
+
* life, so the prompt's cached start never changes per turn. A host
|
|
403
|
+
* procedure of that name throws. Default false.
|
|
404
|
+
*/
|
|
405
|
+
toolResults?: boolean;
|
|
394
406
|
}
|
|
395
407
|
/**
|
|
396
408
|
* What `withModel` takes: everything that exists only because a model does.
|
|
@@ -644,6 +656,11 @@ export interface JigsServer<TContext, TPageName extends string = never> {
|
|
|
644
656
|
advice: ReadonlyArray<Advice>;
|
|
645
657
|
diagnostics: ReadonlyArray<Diagnostic>;
|
|
646
658
|
program: Program;
|
|
659
|
+
/**
|
|
660
|
+
* With `toolResults: true`, for a source that reads the slot: the tool
|
|
661
|
+
* names it reads, or `"all"` (`ChatBlock.toolKeys`).
|
|
662
|
+
*/
|
|
663
|
+
toolKeys?: ReadonlyArray<string> | "all";
|
|
647
664
|
}>;
|
|
648
665
|
/**
|
|
649
666
|
* `value` parsed with the schema of provided slot `name`, for a page
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jigs.design/server",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
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/
|
|
34
|
-
"@jigs.design/
|
|
35
|
-
"@jigs.design/
|
|
36
|
-
"@jigs.design/
|
|
32
|
+
"@jigs.design/compiler": "0.3.2",
|
|
33
|
+
"@jigs.design/prompt": "0.3.2",
|
|
34
|
+
"@jigs.design/host": "0.3.2",
|
|
35
|
+
"@jigs.design/protocol": "0.3.2",
|
|
36
|
+
"@jigs.design/runtime": "0.3.2"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"zod": "^4.0.0"
|