@polyxd/runtime 0.4.0
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/LICENSE +202 -0
- package/NOTICE +224 -0
- package/README.md +85 -0
- package/dist/adapters/anthropic.d.ts +22 -0
- package/dist/adapters/anthropic.js +48 -0
- package/dist/adapters/anthropic.js.map +1 -0
- package/dist/adapters/gemini.d.ts +14 -0
- package/dist/adapters/gemini.js +42 -0
- package/dist/adapters/gemini.js.map +1 -0
- package/dist/adapters/http.d.ts +25 -0
- package/dist/adapters/http.js +92 -0
- package/dist/adapters/http.js.map +1 -0
- package/dist/adapters/openai.d.ts +31 -0
- package/dist/adapters/openai.js +89 -0
- package/dist/adapters/openai.js.map +1 -0
- package/dist/audit.d.ts +17 -0
- package/dist/audit.js +48 -0
- package/dist/audit.js.map +1 -0
- package/dist/catalog.generated.d.ts +4 -0
- package/dist/catalog.generated.js +618 -0
- package/dist/catalog.generated.js.map +1 -0
- package/dist/direction.d.ts +22 -0
- package/dist/direction.js +95 -0
- package/dist/direction.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/memory.d.ts +25 -0
- package/dist/memory.js +38 -0
- package/dist/memory.js.map +1 -0
- package/dist/parse.d.ts +15 -0
- package/dist/parse.js +35 -0
- package/dist/parse.js.map +1 -0
- package/dist/prompt.d.ts +47 -0
- package/dist/prompt.js +242 -0
- package/dist/prompt.js.map +1 -0
- package/dist/runtime.d.ts +131 -0
- package/dist/runtime.js +190 -0
- package/dist/runtime.js.map +1 -0
- package/dist/types.d.ts +104 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +42 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Capability, CatalogPattern, Direction, Rule } from "./types.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Every rule a Direction holds a surface to: its explicit rules plus its voice compiled into
|
|
4
|
+
* checks. The same result as `directionRules` in `@polyxd/spec`, whose root entry reads files and
|
|
5
|
+
* so can't run in a browser; a test holds the two to each other.
|
|
6
|
+
*/
|
|
7
|
+
export declare function directionRules(direction: Direction | undefined): Rule[];
|
|
8
|
+
/** Lower-case words without the common ones, lightly stemmed. `money.send` gives `money`, `send`. */
|
|
9
|
+
export declare function words(text: string): Set<string>;
|
|
10
|
+
/** The words an ask brings: what was asked, the intent key, and what the offered capabilities do. */
|
|
11
|
+
export declare function askWords(ask: string, intent: string, capabilities?: Record<string, Capability>): Set<string>;
|
|
12
|
+
/**
|
|
13
|
+
* The Direction's preferred patterns that fit this ask, best first. A pattern fits when it shares
|
|
14
|
+
* words with the ask, or when it's written for the risk of a capability on offer (a consequential
|
|
15
|
+
* one points at `confirm-destructive`; one with an undo at `undo-over-confirm`). Ties keep the
|
|
16
|
+
* Direction's order, so the result is the same every time.
|
|
17
|
+
*/
|
|
18
|
+
export declare function relevantPatterns(preferred: string[], catalog: CatalogPattern[], ask: string, intent: string, capabilities?: Record<string, Capability>): CatalogPattern[];
|
|
19
|
+
/** The exemplars whose request shares the most words with this ask, best first, at most `limit`. */
|
|
20
|
+
export declare function relevantExemplars<T extends {
|
|
21
|
+
request: string;
|
|
22
|
+
}>(exemplars: T[], ask: string, intent: string, limit: number): T[];
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every rule a Direction holds a surface to: its explicit rules plus its voice compiled into
|
|
3
|
+
* checks. The same result as `directionRules` in `@polyxd/spec`, whose root entry reads files and
|
|
4
|
+
* so can't run in a browser; a test holds the two to each other.
|
|
5
|
+
*/
|
|
6
|
+
export function directionRules(direction) {
|
|
7
|
+
const v = direction?.voice ?? {};
|
|
8
|
+
const rules = [];
|
|
9
|
+
const add = (id, description, rule, severity = "warning") => rules.push({ id: `voice-${id}`, description, severity, rule });
|
|
10
|
+
if (v.casing)
|
|
11
|
+
add("casing", `Use ${v.casing} case for titles, labels and buttons`, { check: "casing", style: v.casing });
|
|
12
|
+
if (v.punctuation?.exclamation === "never")
|
|
13
|
+
add("no-exclamation", "No exclamation marks", { check: "noLabelMatches", pattern: "!" });
|
|
14
|
+
if (v.punctuation?.emoji === "never")
|
|
15
|
+
add("no-emoji", "No emoji", { check: "noEmoji" });
|
|
16
|
+
if (v.labels?.maxWords)
|
|
17
|
+
add("label-length", `Button labels of at most ${v.labels.maxWords} words`, { check: "maxWords", max: v.labels.maxWords });
|
|
18
|
+
if (v.readingLevel?.maxGrade)
|
|
19
|
+
add("reading-level", `Running text at reading grade ${v.readingLevel.maxGrade} or below`, { check: "readingLevel", maxGrade: v.readingLevel.maxGrade });
|
|
20
|
+
if (v.spelling)
|
|
21
|
+
add("spelling", `${v.spelling} spelling`, { check: "spelling", variant: v.spelling });
|
|
22
|
+
if (v.person && v.person !== "we-and-you")
|
|
23
|
+
add("person", v.person === "you" ? 'Address people as "you"; the product doesn\'t say "we"' : "Impersonal: neither you nor we", { check: "person", style: v.person });
|
|
24
|
+
if (Array.isArray(v.avoid) && v.avoid.length)
|
|
25
|
+
add("avoid", `Never say: ${v.avoid.join(", ")}`, { check: "avoidTerms", terms: v.avoid });
|
|
26
|
+
for (const g of v.glossary ?? []) {
|
|
27
|
+
if (g.insteadOf?.length)
|
|
28
|
+
add(`glossary-${g.use.toLowerCase().replace(/[^a-z0-9]+/g, "-")}`, `Say "${g.use}", not ${g.insteadOf.map((x) => `"${x}"`).join(" or ")}`, { check: "avoidTerms", terms: g.insteadOf, suggest: g.use });
|
|
29
|
+
}
|
|
30
|
+
return [...(direction?.rules ?? []), ...rules];
|
|
31
|
+
}
|
|
32
|
+
const STOP = new Set("a an and any are as at be by can do for from get has have i in is it its me my of on or our please show that the their them this to up use want we what when where which with you your".split(" "));
|
|
33
|
+
function stem(w) {
|
|
34
|
+
return w.length > 4 ? w.replace(/ies$/, "y").replace(/(ing|ed|es|s)$/, "") : w;
|
|
35
|
+
}
|
|
36
|
+
/** Lower-case words without the common ones, lightly stemmed. `money.send` gives `money`, `send`. */
|
|
37
|
+
export function words(text) {
|
|
38
|
+
return new Set(text
|
|
39
|
+
.toLowerCase()
|
|
40
|
+
.split(/[^a-z0-9£$€]+/)
|
|
41
|
+
.filter((w) => w && !STOP.has(w))
|
|
42
|
+
.map(stem));
|
|
43
|
+
}
|
|
44
|
+
function shared(a, b) {
|
|
45
|
+
let n = 0;
|
|
46
|
+
for (const w of a)
|
|
47
|
+
if (b.has(w))
|
|
48
|
+
n++;
|
|
49
|
+
return n;
|
|
50
|
+
}
|
|
51
|
+
/** The words an ask brings: what was asked, the intent key, and what the offered capabilities do. */
|
|
52
|
+
export function askWords(ask, intent, capabilities = {}) {
|
|
53
|
+
const parts = [ask, intent];
|
|
54
|
+
for (const [name, c] of Object.entries(capabilities))
|
|
55
|
+
parts.push(name, c.description ?? "");
|
|
56
|
+
return words(parts.join(" "));
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The Direction's preferred patterns that fit this ask, best first. A pattern fits when it shares
|
|
60
|
+
* words with the ask, or when it's written for the risk of a capability on offer (a consequential
|
|
61
|
+
* one points at `confirm-destructive`; one with an undo at `undo-over-confirm`). Ties keep the
|
|
62
|
+
* Direction's order, so the result is the same every time.
|
|
63
|
+
*/
|
|
64
|
+
export function relevantPatterns(preferred, catalog, ask, intent, capabilities = {}) {
|
|
65
|
+
const query = askWords(ask, intent, capabilities);
|
|
66
|
+
const risks = new Set(Object.values(capabilities).map((c) => c.risk).filter((r) => r === "consequential" || r === "destructive"));
|
|
67
|
+
const undoable = Object.values(capabilities).some((c) => c.undo);
|
|
68
|
+
const scored = [];
|
|
69
|
+
preferred.forEach((id, index) => {
|
|
70
|
+
const p = catalog.find((x) => x.id === id);
|
|
71
|
+
if (!p)
|
|
72
|
+
return;
|
|
73
|
+
const text = [p.id, p.name, p.summary, ...p.whenToUse].join(" ");
|
|
74
|
+
let score = shared(query, words(text));
|
|
75
|
+
for (const r of risks)
|
|
76
|
+
if (text.includes(r))
|
|
77
|
+
score += 2;
|
|
78
|
+
if (undoable && /\bundo\b/i.test(text))
|
|
79
|
+
score += 1;
|
|
80
|
+
if (score > 0)
|
|
81
|
+
scored.push({ p, score, index });
|
|
82
|
+
});
|
|
83
|
+
return scored.sort((a, b) => b.score - a.score || a.index - b.index).map((s) => s.p);
|
|
84
|
+
}
|
|
85
|
+
/** The exemplars whose request shares the most words with this ask, best first, at most `limit`. */
|
|
86
|
+
export function relevantExemplars(exemplars, ask, intent, limit) {
|
|
87
|
+
const query = words(`${ask} ${intent}`);
|
|
88
|
+
return exemplars
|
|
89
|
+
.map((e, index) => ({ e, index, score: shared(query, words(e.request)) }))
|
|
90
|
+
.filter((s) => s.score > 0)
|
|
91
|
+
.sort((a, b) => b.score - a.score || a.index - b.index)
|
|
92
|
+
.slice(0, Math.max(0, limit))
|
|
93
|
+
.map((s) => s.e);
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=direction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"direction.js","sourceRoot":"","sources":["../src/direction.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,SAAgC;IAC7D,MAAM,CAAC,GAAG,SAAS,EAAE,KAAK,IAAI,EAAE,CAAC;IACjC,MAAM,KAAK,GAAW,EAAE,CAAC;IACzB,MAAM,GAAG,GAAG,CAAC,EAAU,EAAE,WAAmB,EAAE,IAAkB,EAAE,QAAQ,GAAqB,SAAS,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE,WAAW,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;IAC5K,IAAI,CAAC,CAAC,MAAM;QAAE,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,MAAM,sCAAsC,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;IACzH,IAAI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AC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACvF,CAAC;AAED,oGAAoG;AACpG,MAAM,UAAU,iBAAiB,CAAgC,SAAc,EAAE,GAAW,EAAE,MAAc,EAAE,KAAa;IACzH,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,GAAG,IAAI,MAAM,EAAE,CAAC,CAAC;IACxC,OAAO,SAAS;SACb,GAAG,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC;SACzE,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC;SAC1B,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC;SACtD,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;SAC5B,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACrB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { createRuntime, type Runtime, type RuntimeOptions, type Ask, type Result, type Progress, type RuntimeEvent, type ErrorReason } from "./runtime.ts";
|
|
2
|
+
export { systemPrompt, userPrompt, repairPrompt, dataPaths, type SystemPromptOptions, type PromptInput } from "./prompt.ts";
|
|
3
|
+
export { parseDocument, extractJson, type Parsed } from "./parse.ts";
|
|
4
|
+
export { checkDocument } from "./audit.ts";
|
|
5
|
+
export { memoryStore, storageStore, type MemoryStore, type StorageLike } from "./memory.ts";
|
|
6
|
+
export { anthropic, type AnthropicOptions } from "./adapters/anthropic.ts";
|
|
7
|
+
export { openai, local, type OpenAIOptions, type LocalOptions } from "./adapters/openai.ts";
|
|
8
|
+
export { gemini, type GeminiOptions } from "./adapters/gemini.ts";
|
|
9
|
+
export { GeneratorError, type HttpOptions } from "./adapters/http.ts";
|
|
10
|
+
export type { Generator, GenerateRequest, GeneratorOutput, Message, Usage, Finding, Report, Audit, AuditOptions, Direction, Exemplar, UIDocument, Capability, CapabilityRegistry, Rule } from "./types.ts";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { createRuntime } from "./runtime.js";
|
|
2
|
+
export { systemPrompt, userPrompt, repairPrompt, dataPaths } from "./prompt.js";
|
|
3
|
+
export { parseDocument, extractJson } from "./parse.js";
|
|
4
|
+
export { checkDocument } from "./audit.js";
|
|
5
|
+
export { memoryStore, storageStore } from "./memory.js";
|
|
6
|
+
export { anthropic } from "./adapters/anthropic.js";
|
|
7
|
+
export { openai, local } from "./adapters/openai.js";
|
|
8
|
+
export { gemini } from "./adapters/gemini.js";
|
|
9
|
+
export { GeneratorError } from "./adapters/http.js";
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAgH,MAAM,cAAc,CAAC;AAC3J,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAA8C,MAAM,aAAa,CAAC;AAC5H,OAAO,EAAE,aAAa,EAAE,WAAW,EAAe,MAAM,YAAY,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,YAAY,EAAsC,MAAM,aAAa,CAAC;AAC5F,OAAO,EAAE,SAAS,EAAyB,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAE,MAAM,EAAE,KAAK,EAAyC,MAAM,sBAAsB,CAAC;AAC5F,OAAO,EAAE,MAAM,EAAsB,MAAM,sBAAsB,CAAC;AAClE,OAAO,EAAE,cAAc,EAAoB,MAAM,oBAAoB,CAAC"}
|
package/dist/memory.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { UIDocument } from "./types.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Interface memory: the document last shown for each intent, kept on the client. The runtime reads
|
|
4
|
+
* it before generating, gives it to the model as the screen to keep recognisable, and writes the
|
|
5
|
+
* new one back once it passes the checks. Documents are stored without their data snapshot.
|
|
6
|
+
*/
|
|
7
|
+
export interface MemoryStore {
|
|
8
|
+
get(intent: string): UIDocument | undefined | Promise<UIDocument | undefined>;
|
|
9
|
+
set(intent: string, document: UIDocument): void | Promise<void>;
|
|
10
|
+
delete(intent: string): void | Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
/** The part of the Web Storage API a store needs: `localStorage`, `sessionStorage`, or your own. */
|
|
13
|
+
export interface StorageLike {
|
|
14
|
+
getItem(key: string): string | null;
|
|
15
|
+
setItem(key: string, value: string): void;
|
|
16
|
+
removeItem(key: string): void;
|
|
17
|
+
}
|
|
18
|
+
/** A store that lives as long as the page or process does. */
|
|
19
|
+
export declare function memoryStore(): MemoryStore;
|
|
20
|
+
/** A store on `localStorage` or anything shaped like it. A corrupt entry reads as nothing. */
|
|
21
|
+
export declare function storageStore(storage: StorageLike, options?: {
|
|
22
|
+
prefix?: string;
|
|
23
|
+
}): MemoryStore;
|
|
24
|
+
/** A document as memory keeps it: without the data it was shown with. */
|
|
25
|
+
export declare function forMemory(document: UIDocument): UIDocument;
|
package/dist/memory.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** A store that lives as long as the page or process does. */
|
|
2
|
+
export function memoryStore() {
|
|
3
|
+
const map = new Map();
|
|
4
|
+
return {
|
|
5
|
+
get: (intent) => {
|
|
6
|
+
const json = map.get(intent);
|
|
7
|
+
return json === undefined ? undefined : JSON.parse(json);
|
|
8
|
+
},
|
|
9
|
+
set: (intent, document) => void map.set(intent, JSON.stringify(document)),
|
|
10
|
+
delete: (intent) => void map.delete(intent),
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/** A store on `localStorage` or anything shaped like it. A corrupt entry reads as nothing. */
|
|
14
|
+
export function storageStore(storage, options = {}) {
|
|
15
|
+
const prefix = options.prefix ?? "polyxd:memory:";
|
|
16
|
+
return {
|
|
17
|
+
get: (intent) => {
|
|
18
|
+
const json = storage.getItem(prefix + intent);
|
|
19
|
+
if (json === null)
|
|
20
|
+
return undefined;
|
|
21
|
+
try {
|
|
22
|
+
const doc = JSON.parse(json);
|
|
23
|
+
return doc && typeof doc === "object" && !Array.isArray(doc) ? doc : undefined;
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
set: (intent, document) => storage.setItem(prefix + intent, JSON.stringify(document)),
|
|
30
|
+
delete: (intent) => storage.removeItem(prefix + intent),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/** A document as memory keeps it: without the data it was shown with. */
|
|
34
|
+
export function forMemory(document) {
|
|
35
|
+
const { data: _data, ...rest } = document;
|
|
36
|
+
return rest;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=memory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.js","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":"AAoBA,8DAA8D;AAC9D,MAAM,UAAU,WAAW;IACzB,MAAM,GAAG,GAAG,IAAI,GAAG,EAAkB,CAAC;IACtC,OAAO;QACL,GAAG,EAAE,CAAC,MAAM,EAAE,EAAE;YACd,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YAC7B,OAAO,IAAI,KAAK,SAAS,CAAC,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MAAM,CAAC;KACxD,CAAC;AACJ,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,SAAS,CAAC,QAAoB;IAC5C,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,IAAI,EAAE,GAAG,QAAQ,CAAC;IAC1C,OAAO,IAAkB,CAAC;AAC5B,CAAC"}
|
package/dist/parse.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The JSON inside a model's answer. Models wrap it in a code fence, or put a sentence before it,
|
|
3
|
+
* however firmly they're told not to: take the first fenced block that holds an object, else
|
|
4
|
+
* everything from the first `{` to the last `}`.
|
|
5
|
+
*/
|
|
6
|
+
export declare function extractJson(text: string): string;
|
|
7
|
+
export type Parsed = {
|
|
8
|
+
document: Record<string, unknown>;
|
|
9
|
+
error?: undefined;
|
|
10
|
+
} | {
|
|
11
|
+
document?: undefined;
|
|
12
|
+
error: string;
|
|
13
|
+
};
|
|
14
|
+
/** Parses a model's answer into a JSON object, or says why it couldn't. */
|
|
15
|
+
export declare function parseDocument(text: string): Parsed;
|
package/dist/parse.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The JSON inside a model's answer. Models wrap it in a code fence, or put a sentence before it,
|
|
3
|
+
* however firmly they're told not to: take the first fenced block that holds an object, else
|
|
4
|
+
* everything from the first `{` to the last `}`.
|
|
5
|
+
*/
|
|
6
|
+
export function extractJson(text) {
|
|
7
|
+
for (const m of text.matchAll(/```[a-zA-Z]*[ \t]*\r?\n?([\s\S]*?)```/g)) {
|
|
8
|
+
const inner = m[1].trim();
|
|
9
|
+
if (inner.startsWith("{"))
|
|
10
|
+
return inner;
|
|
11
|
+
}
|
|
12
|
+
// An opening fence the answer never closed (it ran out of tokens, or the stream was cut).
|
|
13
|
+
const open = /```[a-zA-Z]*[ \t]*\r?\n/.exec(text);
|
|
14
|
+
const body = open ? text.slice(open.index + open[0].length) : text;
|
|
15
|
+
const start = body.indexOf("{");
|
|
16
|
+
const end = body.lastIndexOf("}");
|
|
17
|
+
return start >= 0 && end > start ? body.slice(start, end + 1) : body.trim();
|
|
18
|
+
}
|
|
19
|
+
/** Parses a model's answer into a JSON object, or says why it couldn't. */
|
|
20
|
+
export function parseDocument(text) {
|
|
21
|
+
const json = extractJson(text);
|
|
22
|
+
if (!json)
|
|
23
|
+
return { error: "the answer was empty" };
|
|
24
|
+
let value;
|
|
25
|
+
try {
|
|
26
|
+
value = JSON.parse(json);
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
return { error: `the answer is not valid JSON (${e.message})` };
|
|
30
|
+
}
|
|
31
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
32
|
+
return { error: "the answer is JSON, but not one object" };
|
|
33
|
+
return { document: value };
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=parse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,wCAAwC,CAAC,EAAE,CAAC;QACxE,MAAM,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAC1B,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC;YAAE,OAAO,KAAK,CAAC;IAC1C,CAAC;IACD,0FAA0F;IAC1F,MAAM,IAAI,GAAG,yBAAyB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAClD,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACnE,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAChC,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IAClC,OAAO,KAAK,IAAI,CAAC,IAAI,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;AAC9E,CAAC;AAID,2EAA2E;AAC3E,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,MAAM,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;IAC/B,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,KAAK,EAAE,sBAAsB,EAAE,CAAC;IACpD,IAAI,KAAc,CAAC;IACnB,IAAI,CAAC;QACH,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,EAAE,KAAK,EAAE,iCAAkC,CAAW,CAAC,OAAO,GAAG,EAAE,CAAC;IAC7E,CAAC;IACD,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,KAAK,EAAE,wCAAwC,EAAE,CAAC;IAC5H,OAAO,EAAE,QAAQ,EAAE,KAAgC,EAAE,CAAC;AACxD,CAAC"}
|
package/dist/prompt.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Capability, Direction, Exemplar, Finding, UIDocument } from "./types.ts";
|
|
2
|
+
export interface SystemPromptOptions {
|
|
3
|
+
/**
|
|
4
|
+
* The components generated screens may use. Leave it out for every component the spec defines
|
|
5
|
+
* for surfaces. Shell components are never offered either way.
|
|
6
|
+
*/
|
|
7
|
+
components?: string[];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The generator's system prompt, built from the spec: the document shape, the rules a generated
|
|
11
|
+
* document must follow, every component it may use with its props, and the patterns. The same
|
|
12
|
+
* text for every ask, so a provider's prompt cache can hold it.
|
|
13
|
+
*/
|
|
14
|
+
export declare function systemPrompt(options?: SystemPromptOptions): string;
|
|
15
|
+
/** Everything the user turn is built from. */
|
|
16
|
+
export interface PromptInput {
|
|
17
|
+
/** What the person asked, in their words. */
|
|
18
|
+
ask: string;
|
|
19
|
+
/** A stable key for what they're trying to do, such as `money.send`. */
|
|
20
|
+
intent: string;
|
|
21
|
+
/** A spec pattern the surface should follow, when the host already knows. */
|
|
22
|
+
pattern?: string;
|
|
23
|
+
/** The capabilities this surface may trigger, by name. */
|
|
24
|
+
capabilities?: Record<string, Capability>;
|
|
25
|
+
/** The host data the surface binds to by JSON Pointer. */
|
|
26
|
+
data?: unknown;
|
|
27
|
+
direction?: Direction;
|
|
28
|
+
/** Exemplars already chosen for this ask. */
|
|
29
|
+
exemplars?: Exemplar[];
|
|
30
|
+
/** The document shown last time for this intent. */
|
|
31
|
+
previous?: UIDocument;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* The pointers a surface can bind to, one per line. A list is described once, with the fields its
|
|
35
|
+
* items have, since a repeated item binds to them with relative paths.
|
|
36
|
+
*/
|
|
37
|
+
export declare function dataPaths(data: unknown): string[];
|
|
38
|
+
/** A Design Direction as instructions: profile, voice and rules. */
|
|
39
|
+
export declare function directionLines(d: Direction): string[];
|
|
40
|
+
/**
|
|
41
|
+
* The host's turn: the ask, the capabilities it offers, the data to bind to, the Direction, the
|
|
42
|
+
* patterns that fit, a few exemplars and the screen shown last time. The same input always gives
|
|
43
|
+
* the same text.
|
|
44
|
+
*/
|
|
45
|
+
export declare function userPrompt(input: PromptInput): string;
|
|
46
|
+
/** The turn that sends a failed document's problems back to the model. */
|
|
47
|
+
export declare function repairPrompt(findings: Finding[]): string;
|
package/dist/prompt.js
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { COMPONENTS, PATTERNS, SPEC_VERSION } from "./catalog.generated.js";
|
|
2
|
+
import { relevantPatterns } from "./direction.js";
|
|
3
|
+
const EXAMPLE = {
|
|
4
|
+
specVersion: SPEC_VERSION,
|
|
5
|
+
surface: { id: "add-task", title: "New task", intent: "tasks.create" },
|
|
6
|
+
root: "form",
|
|
7
|
+
components: [
|
|
8
|
+
{ id: "form", component: "Form", children: ["title", "due", "priority"], submit: { label: "Add task", action: { event: { name: "task.save", context: { title: { path: "/draft/title" }, due: { path: "/draft/due" }, priority: { path: "/draft/priority" } } } } } },
|
|
9
|
+
{ id: "title", component: "TextInput", key: "title", label: "Task", value: { path: "/draft/title" }, required: true },
|
|
10
|
+
{ id: "due", component: "DateInput", key: "due", label: "Due", value: { path: "/draft/due" } },
|
|
11
|
+
{ id: "priority", component: "Choice", key: "priority", label: "Priority", value: { path: "/draft/priority" }, options: [{ value: "low", label: "Low" }, { value: "normal", label: "Normal" }, { value: "high", label: "High" }] },
|
|
12
|
+
],
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* The generator's system prompt, built from the spec: the document shape, the rules a generated
|
|
16
|
+
* document must follow, every component it may use with its props, and the patterns. The same
|
|
17
|
+
* text for every ask, so a provider's prompt cache can hold it.
|
|
18
|
+
*/
|
|
19
|
+
export function systemPrompt(options = {}) {
|
|
20
|
+
const allowed = options.components ? new Set(options.components) : undefined;
|
|
21
|
+
const components = COMPONENTS.filter((c) => !c.shell && (!allowed || allowed.has(c.name)));
|
|
22
|
+
const shellNames = COMPONENTS.filter((c) => c.shell)
|
|
23
|
+
.map((c) => c.name)
|
|
24
|
+
.join(", ")
|
|
25
|
+
.replace(/, ([^,]*)$/, " or $1");
|
|
26
|
+
const rules = [
|
|
27
|
+
'Data comes from the host. Bind values with {"path":"/json/pointer"}; pointers start at the root of the DATA object (DATA {"card":{"id":"c1"}} → {"path":"/card/id"}, never "/data/card/id"). Never type numbers, prices, names or dates from the data as literal text; never invent data.',
|
|
28
|
+
'Inside a repeated item (Collection items template, Table columns, Chart series, Comparison attributes) use paths RELATIVE to the item, e.g. {"path":"amount"}.',
|
|
29
|
+
'Actions: {"event":{"name":"<capability>","context":{...}}}. Use ONLY the capabilities listed. "ui.dismiss" closes the surface.',
|
|
30
|
+
"Destructive capabilities must be triggered from a Confirm. Consequential ones need a Confirm or a review step first.",
|
|
31
|
+
"At most one primary action visible at a time (a Form's submit counts). At most 6 inputs per view; use Steps for more.",
|
|
32
|
+
'Labels say what happens ("Send £20", "Freeze card"), in sentence case. Give every component that represents a thing from the data a stable "key" in lower_snake_case (e.g. "card_status").',
|
|
33
|
+
'Collections and Tables need an "empty" Status when the list may be empty.',
|
|
34
|
+
"If no listed capability can do what was asked, show a Status explaining that instead of a fake interface.",
|
|
35
|
+
'Format numbers, money and dates with "format", never by writing them into strings.',
|
|
36
|
+
'A "percent" format takes a fraction: 0.12 shows as "12%", and 12 would show as "1,200%". Store 12% as 0.12, including a change\'s value.',
|
|
37
|
+
'There is no template engine. Text is either literal or a binding; "{{budget}}" or "${spent}" in a string reaches the screen exactly as written.',
|
|
38
|
+
'Bind text to a field that holds text. A pointer at an object or a list prints as "[object Object]"; point at the string inside it.',
|
|
39
|
+
'Show people names, not internal ids. If a record has both "id" and "name", the screen gets "name"; the id belongs in an action\'s context.',
|
|
40
|
+
`Never use ${shellNames}: the product's shell is authored, and your surface renders inside it. Never draw navigation, a header or a footer around a surface.`,
|
|
41
|
+
];
|
|
42
|
+
if (allowed)
|
|
43
|
+
rules.push("Use only the components listed below.");
|
|
44
|
+
return `You generate just-in-time user interfaces as JSON, in the Polyxd UI document format. Output ONE JSON object and nothing else.
|
|
45
|
+
|
|
46
|
+
Document shape: {"specVersion":"${SPEC_VERSION}","surface":{"id","title","intent","pattern"?},"root":"<id>","components":[...]}.
|
|
47
|
+
Components are a FLAT list; each has a unique "id" and "component" (its type). Containers reference children by id STRINGS ("children": ["a","b"]); never nest component objects inside other components.
|
|
48
|
+
|
|
49
|
+
Rules:
|
|
50
|
+
${rules.map((r, i) => `${i + 1}. ${r}`).join("\n")}
|
|
51
|
+
|
|
52
|
+
Components (* = required):
|
|
53
|
+
${components.map((c) => c.line).join("\n")}
|
|
54
|
+
|
|
55
|
+
Patterns (set surface.pattern when one applies):
|
|
56
|
+
${PATTERNS.map((p) => `- ${p.id}: ${p.summary} Structure: ${p.structure.join(" → ")}`).join("\n")}
|
|
57
|
+
|
|
58
|
+
Example:
|
|
59
|
+
${JSON.stringify(EXAMPLE)}`;
|
|
60
|
+
}
|
|
61
|
+
const MAX_PATHS = 80;
|
|
62
|
+
/** RFC 6901: `~` and `/` inside a key are escaped. */
|
|
63
|
+
const escapeKey = (k) => k.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
64
|
+
function kind(v) {
|
|
65
|
+
if (v === null)
|
|
66
|
+
return "null";
|
|
67
|
+
if (Array.isArray(v))
|
|
68
|
+
return "list";
|
|
69
|
+
return typeof v;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The pointers a surface can bind to, one per line. A list is described once, with the fields its
|
|
73
|
+
* items have, since a repeated item binds to them with relative paths.
|
|
74
|
+
*/
|
|
75
|
+
export function dataPaths(data) {
|
|
76
|
+
const out = [];
|
|
77
|
+
const walk = (value, at) => {
|
|
78
|
+
if (Array.isArray(value)) {
|
|
79
|
+
const objects = value.filter((v) => v && typeof v === "object" && !Array.isArray(v)).slice(0, 5);
|
|
80
|
+
const fields = [...new Set(objects.flatMap((o) => Object.keys(o)))];
|
|
81
|
+
const itemKinds = [...new Set(value.slice(0, 5).map(kind))].join("|") || "empty";
|
|
82
|
+
out.push(`${at} (list of ${value.length}${fields.length ? `; each item has ${fields.join(", ")}` : `; items: ${itemKinds}`})`);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (value && typeof value === "object") {
|
|
86
|
+
for (const [k, v] of Object.entries(value))
|
|
87
|
+
walk(v, `${at}/${escapeKey(k)}`);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (at)
|
|
91
|
+
out.push(`${at} (${kind(value)})`);
|
|
92
|
+
};
|
|
93
|
+
walk(data, "");
|
|
94
|
+
return out.length > MAX_PATHS ? [...out.slice(0, MAX_PATHS), `… and ${out.length - MAX_PATHS} more`] : out;
|
|
95
|
+
}
|
|
96
|
+
/** A document as the model reads it: no data snapshot, no `$schema`, on one line. */
|
|
97
|
+
function compact(doc) {
|
|
98
|
+
const { data: _data, ...rest } = doc;
|
|
99
|
+
delete rest.$schema;
|
|
100
|
+
return JSON.stringify(rest);
|
|
101
|
+
}
|
|
102
|
+
function capabilityLines(capabilities) {
|
|
103
|
+
const names = Object.keys(capabilities);
|
|
104
|
+
if (!names.length)
|
|
105
|
+
return ["- (none)"];
|
|
106
|
+
return names.map((name) => {
|
|
107
|
+
const c = capabilities[name];
|
|
108
|
+
const required = new Set(c.inputs?.required ?? []);
|
|
109
|
+
const inputs = Object.keys(c.inputs?.properties ?? {}).map((k) => (required.has(k) ? `${k}*` : k));
|
|
110
|
+
const facts = [`risk: ${c.risk ?? "unknown"}`, `inputs: ${inputs.join(", ") || "none"}`];
|
|
111
|
+
if (c.undo)
|
|
112
|
+
facts.push(`undo: ${c.undo}`);
|
|
113
|
+
return `- ${name} (${facts.join("; ")}): ${c.description ?? ""}`;
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
const DENSITY = {
|
|
117
|
+
compact: "Density: compact. Fit more on one screen.",
|
|
118
|
+
comfortable: "Density: comfortable.",
|
|
119
|
+
spacious: "Density: spacious. Show fewer things on one screen.",
|
|
120
|
+
};
|
|
121
|
+
const DATA_DISPLAY = {
|
|
122
|
+
"prefer-charts": "Show numbers over time, or parts of a whole, as a Chart where it helps.",
|
|
123
|
+
"prefer-tables": "Show lists of records as a Table.",
|
|
124
|
+
"prefer-metrics": "Lead with the key figures as Metric components.",
|
|
125
|
+
};
|
|
126
|
+
const DISCLOSURE = {
|
|
127
|
+
progressive: "Put secondary detail behind a Disclosure.",
|
|
128
|
+
"show-everything": "Show detail directly; don't hide it behind a Disclosure.",
|
|
129
|
+
};
|
|
130
|
+
const FREEDOM = {
|
|
131
|
+
strict: "Freedom: strict. Stay close to the preferred patterns and the examples; don't invent new kinds of layout.",
|
|
132
|
+
guided: "Freedom: guided. New layouts are fine, built from the listed components.",
|
|
133
|
+
open: "Freedom: open. Any layout is fine if it passes the checks.",
|
|
134
|
+
};
|
|
135
|
+
/** A Design Direction as instructions: profile, voice and rules. */
|
|
136
|
+
export function directionLines(d) {
|
|
137
|
+
const out = [`Design direction: ${d.name}${d.designSystem ? ` (design system: ${d.designSystem})` : ""}`];
|
|
138
|
+
const p = d.profile ?? {};
|
|
139
|
+
const profile = [];
|
|
140
|
+
if (p.density && DENSITY[p.density])
|
|
141
|
+
profile.push(DENSITY[p.density]);
|
|
142
|
+
if (p.emphasisBudget)
|
|
143
|
+
profile.push(`At most ${p.emphasisBudget} primary action${p.emphasisBudget === 1 ? "" : "s"} visible at a time.`);
|
|
144
|
+
if (p.dataDisplay && DATA_DISPLAY[p.dataDisplay])
|
|
145
|
+
profile.push(DATA_DISPLAY[p.dataDisplay]);
|
|
146
|
+
if (p.disclosure && DISCLOSURE[p.disclosure])
|
|
147
|
+
profile.push(DISCLOSURE[p.disclosure]);
|
|
148
|
+
if (p.freedom && FREEDOM[p.freedom])
|
|
149
|
+
profile.push(FREEDOM[p.freedom]);
|
|
150
|
+
if (profile.length)
|
|
151
|
+
out.push("Profile:", ...profile.map((x) => `- ${x}`));
|
|
152
|
+
const v = d.voice ?? {};
|
|
153
|
+
const voice = [];
|
|
154
|
+
if (v.guidelines?.length)
|
|
155
|
+
voice.push("Guidelines: " + v.guidelines.join(" "));
|
|
156
|
+
if (v.tone)
|
|
157
|
+
voice.push("Tone: " + Object.entries(v.tone).map(([k, val]) => `${k} ${val}`).join(", "));
|
|
158
|
+
const person = { you: 'address the user as "you"; never say "we"', "we-and-you": 'the product may say "we"', impersonal: 'don\'t say "you" or "we"' }[v.person];
|
|
159
|
+
if (person)
|
|
160
|
+
voice.push(`Person: ${person}`);
|
|
161
|
+
const style = [];
|
|
162
|
+
if (v.casing)
|
|
163
|
+
style.push(`${v.casing} case`);
|
|
164
|
+
if (v.spelling)
|
|
165
|
+
style.push(`${v.spelling} spelling`);
|
|
166
|
+
if (v.readingLevel?.maxGrade)
|
|
167
|
+
style.push(`reading grade ${v.readingLevel.maxGrade} or below`);
|
|
168
|
+
if (v.punctuation?.exclamation === "never")
|
|
169
|
+
style.push("no exclamation marks");
|
|
170
|
+
if (v.punctuation?.emoji === "never")
|
|
171
|
+
style.push("no emoji");
|
|
172
|
+
if (v.labels?.maxWords)
|
|
173
|
+
style.push(`button labels of at most ${v.labels.maxWords} words`);
|
|
174
|
+
if (v.labels && v.labels.verbFirst !== false)
|
|
175
|
+
style.push("buttons start with a verb");
|
|
176
|
+
if (style.length)
|
|
177
|
+
voice.push("Style: " + style.join("; "));
|
|
178
|
+
const glossary = (v.glossary ?? []).filter((g) => g.insteadOf?.length).map((g) => `say "${g.use}", not ${g.insteadOf.map((x) => JSON.stringify(x)).join(" or ")}`);
|
|
179
|
+
if (glossary.length)
|
|
180
|
+
voice.push("Words: " + glossary.join("; "));
|
|
181
|
+
if (v.avoid?.length)
|
|
182
|
+
voice.push("Never use: " + v.avoid.map((x) => JSON.stringify(x)).join(", "));
|
|
183
|
+
for (const [moment, guidance] of Object.entries(v.situations ?? {}))
|
|
184
|
+
voice.push(`For ${moment} states: ${guidance}`);
|
|
185
|
+
if (voice.length)
|
|
186
|
+
out.push("Voice:", ...voice.map((x) => `- ${x}`));
|
|
187
|
+
const rules = (d.rules ?? []).map((r) => r.description);
|
|
188
|
+
if (rules.length)
|
|
189
|
+
out.push("Rules (each one is checked):", ...rules.map((x) => `- ${x}`));
|
|
190
|
+
return out;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* The host's turn: the ask, the capabilities it offers, the data to bind to, the Direction, the
|
|
194
|
+
* patterns that fit, a few exemplars and the screen shown last time. The same input always gives
|
|
195
|
+
* the same text.
|
|
196
|
+
*/
|
|
197
|
+
export function userPrompt(input) {
|
|
198
|
+
const capabilities = input.capabilities ?? {};
|
|
199
|
+
const lines = [`Request: ${input.ask}`, `Intent: ${input.intent}`];
|
|
200
|
+
if (input.pattern)
|
|
201
|
+
lines.push(`Pattern: ${input.pattern}`);
|
|
202
|
+
lines.push("", "Capabilities you may use:", ...capabilityLines(capabilities));
|
|
203
|
+
if (input.data !== undefined) {
|
|
204
|
+
lines.push("", "DATA (bind to it with JSON Pointers; do not copy values into text):", JSON.stringify(input.data));
|
|
205
|
+
const paths = dataPaths(input.data);
|
|
206
|
+
if (paths.length)
|
|
207
|
+
lines.push("", "Paths you can bind to:", ...paths.map((p) => `- ${p}`));
|
|
208
|
+
}
|
|
209
|
+
const d = input.direction;
|
|
210
|
+
if (d)
|
|
211
|
+
lines.push("", ...directionLines(d));
|
|
212
|
+
const preferred = d ? relevantPatterns(d.patterns?.prefer ?? [], PATTERNS, input.ask, input.intent, capabilities) : [];
|
|
213
|
+
const named = input.pattern ? PATTERNS.filter((p) => p.id === input.pattern) : [];
|
|
214
|
+
const patterns = [...named, ...preferred.filter((p) => p.id !== input.pattern)];
|
|
215
|
+
if (patterns.length) {
|
|
216
|
+
lines.push("", "Patterns for this request (set surface.pattern to the one you follow):");
|
|
217
|
+
for (const p of patterns)
|
|
218
|
+
lines.push(`- ${p.id}: ${p.summary} Structure: ${p.structure.join(" → ")}`);
|
|
219
|
+
}
|
|
220
|
+
if (d?.patterns?.disallow?.length)
|
|
221
|
+
lines.push("", `Never use these patterns: ${d.patterns.disallow.join(", ")}.`);
|
|
222
|
+
if (input.exemplars?.length) {
|
|
223
|
+
lines.push("", "Examples of how this product does it (follow their structure, keys and wording where they fit):");
|
|
224
|
+
for (const e of input.exemplars)
|
|
225
|
+
lines.push(`Request: ${e.request}`, `Document: ${compact(e.document)}`);
|
|
226
|
+
}
|
|
227
|
+
if (input.previous) {
|
|
228
|
+
lines.push("", "Last time, this intent showed the screen below. Keep its keys, structure, order and labels so the person recognises it; change only what this request needs:", compact(input.previous));
|
|
229
|
+
}
|
|
230
|
+
lines.push("", "Output the JSON document now.");
|
|
231
|
+
return lines.join("\n");
|
|
232
|
+
}
|
|
233
|
+
const MAX_FINDINGS = 20;
|
|
234
|
+
/** The turn that sends a failed document's problems back to the model. */
|
|
235
|
+
export function repairPrompt(findings) {
|
|
236
|
+
const ordered = [...findings.filter((f) => f.severity === "error"), ...findings.filter((f) => f.severity !== "error")];
|
|
237
|
+
const shown = ordered.slice(0, MAX_FINDINGS).map((f) => `- [${f.check}] ${f.message}`);
|
|
238
|
+
if (ordered.length > MAX_FINDINGS)
|
|
239
|
+
shown.push(`- … and ${ordered.length - MAX_FINDINGS} more`);
|
|
240
|
+
return ["The document you wrote has these problems:", ...shown, "", "Fix every one and output the whole corrected JSON document again, and nothing else."].join("\n");
|
|
241
|
+
}
|
|
242
|
+
//# sourceMappingURL=prompt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../src/prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAWlD,MAAM,OAAO,GAAG;IACd,WAAW,EAAE,YAAY;IACzB,OAAO,EAAE,EAAE,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,cAAc,EAAE;IACtE,IAAI,EAAE,MAAM;IACZ,UAAU,EAAE;QACV,EAAE,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,OAAO,EAAE,KAAK,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,EA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