@jigs.design/ai-sdk 0.3.4 → 0.3.6
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/changes.d.ts +46 -0
- package/dist/changes.js +72 -0
- package/dist/chat.d.ts +15 -4
- package/dist/chat.js +12 -1
- package/dist/client.d.ts +2 -1
- package/dist/client.js +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/model.d.ts +15 -12
- package/dist/model.js +24 -15
- package/dist/schemas.d.ts +19 -0
- package/dist/schemas.js +13 -2
- package/dist/stored.d.ts +6 -2
- package/package.json +5 -5
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { JigsErrorCode, JsonValue, MutationResult } from "@jigs.design/protocol";
|
|
2
|
+
//#region src/changes.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* What the user changed in a jig since the model's last reply: a
|
|
5
|
+
* `data-jigs-change` part on their next message, which `jigsChat`'s
|
|
6
|
+
* `convertDataPart` writes as one sentence for the model.
|
|
7
|
+
*/
|
|
8
|
+
export interface JigsChange {
|
|
9
|
+
/** How many calls it stands for: `addJigsChange` keeps the latest of a run. */
|
|
10
|
+
count: number;
|
|
11
|
+
/** Why the last call failed, `DECLINED` when the user said no; null on a success. */
|
|
12
|
+
error: JigsErrorCode | null;
|
|
13
|
+
/** What the last call passed, as JSON. */
|
|
14
|
+
input: JsonValue;
|
|
15
|
+
/** The block's key, `id@version`. */
|
|
16
|
+
key: string;
|
|
17
|
+
/** The mutation. */
|
|
18
|
+
name: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* `changes` with one more settled mutation from the block `key`, as
|
|
22
|
+
* `JigsView`'s `onMutation` gives it. It replaces an earlier change to the
|
|
23
|
+
* same block, mutation and input once its number fields are left out, and
|
|
24
|
+
* counts it, so a field that mutates on every change sends one line. At
|
|
25
|
+
* most the latest ten are kept.
|
|
26
|
+
*/
|
|
27
|
+
export declare function addJigsChange(changes: ReadonlyArray<JigsChange>, key: string, mutation: {
|
|
28
|
+
input: unknown;
|
|
29
|
+
name: string;
|
|
30
|
+
result: MutationResult;
|
|
31
|
+
}): Array<JigsChange>;
|
|
32
|
+
/**
|
|
33
|
+
* A change as the model reads it: one sentence for the user's message,
|
|
34
|
+
* before their text. `jigsChat`'s `convertDataPart` writes each
|
|
35
|
+
* `data-jigs-change` part with it; a chat on another stack can call it.
|
|
36
|
+
*/
|
|
37
|
+
export declare function jigsChangeText(change: JigsChange): string;
|
|
38
|
+
/**
|
|
39
|
+
* The parts to send `changes` with, before the message's text:
|
|
40
|
+
* `sendMessage({ parts: [...jigsChangeParts(changes), { text, type: "text" }] })`.
|
|
41
|
+
*/
|
|
42
|
+
export declare function jigsChangeParts(changes: ReadonlyArray<JigsChange>): Array<{
|
|
43
|
+
data: JigsChange;
|
|
44
|
+
type: "data-jigs-change";
|
|
45
|
+
}>;
|
|
46
|
+
//#endregion
|
package/dist/changes.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
//#region src/changes.ts
|
|
2
|
+
function isObject(value) {
|
|
3
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4
|
+
}
|
|
5
|
+
function isNumber(value) {
|
|
6
|
+
return typeof value === "number";
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* What makes two calls the same change: the input with its number fields
|
|
10
|
+
* left out, so a field stepped from 300 to 340 is one change and another
|
|
11
|
+
* category or row is its own.
|
|
12
|
+
*/
|
|
13
|
+
function identity(input) {
|
|
14
|
+
if (isNumber(input)) return "";
|
|
15
|
+
if (!isObject(input)) return JSON.stringify(input);
|
|
16
|
+
return JSON.stringify(Object.keys(input).toSorted().flatMap((name) => {
|
|
17
|
+
const value = input[name];
|
|
18
|
+
return value === void 0 || isNumber(value) ? [] : [[name, value]];
|
|
19
|
+
}));
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* `changes` with one more settled mutation from the block `key`, as
|
|
23
|
+
* `JigsView`'s `onMutation` gives it. It replaces an earlier change to the
|
|
24
|
+
* same block, mutation and input once its number fields are left out, and
|
|
25
|
+
* counts it, so a field that mutates on every change sends one line. At
|
|
26
|
+
* most the latest ten are kept.
|
|
27
|
+
*/
|
|
28
|
+
function addJigsChange(changes, key, mutation) {
|
|
29
|
+
let input = null;
|
|
30
|
+
try {
|
|
31
|
+
const text = JSON.stringify(mutation.input ?? null);
|
|
32
|
+
if (text !== void 0) input = JSON.parse(text);
|
|
33
|
+
} catch {
|
|
34
|
+
input = null;
|
|
35
|
+
}
|
|
36
|
+
const same = (change) => change.key === key && change.name === mutation.name && identity(change.input) === identity(input);
|
|
37
|
+
const change = {
|
|
38
|
+
count: (changes.find(same)?.count ?? 0) + 1,
|
|
39
|
+
error: mutation.result.status === "success" ? null : mutation.result.error.code,
|
|
40
|
+
input,
|
|
41
|
+
key,
|
|
42
|
+
name: mutation.name
|
|
43
|
+
};
|
|
44
|
+
return [...changes.filter((entry) => !same(entry)), change].slice(-10);
|
|
45
|
+
}
|
|
46
|
+
/** The most of a change's input the model reads, in characters of JSON. */
|
|
47
|
+
const MAX_CHANGE_INPUT_CHARS = 500;
|
|
48
|
+
/**
|
|
49
|
+
* A change as the model reads it: one sentence for the user's message,
|
|
50
|
+
* before their text. `jigsChat`'s `convertDataPart` writes each
|
|
51
|
+
* `data-jigs-change` part with it; a chat on another stack can call it.
|
|
52
|
+
*/
|
|
53
|
+
function jigsChangeText(change) {
|
|
54
|
+
const json = JSON.stringify(change.input);
|
|
55
|
+
const input = json.length > MAX_CHANGE_INPUT_CHARS ? `${json.slice(0, MAX_CHANGE_INPUT_CHARS)}… (cut at ${MAX_CHANGE_INPUT_CHARS} characters)` : json;
|
|
56
|
+
const ran = change.count > 1 ? `ran \`${change.name}\` ${change.count} times, the last with ${input}` : `ran \`${change.name}\` with ${input}`;
|
|
57
|
+
const call = change.count > 1 ? "the last call" : "it";
|
|
58
|
+
const outcome = change.error === null ? `${call} succeeded` : change.error === "DECLINED" ? `they declined ${call} when asked to confirm` : `${call} failed with ${change.error}`;
|
|
59
|
+
return `Since your last reply, in the \`${change.key}\` UI the user ${ran}: ${outcome}.`;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The parts to send `changes` with, before the message's text:
|
|
63
|
+
* `sendMessage({ parts: [...jigsChangeParts(changes), { text, type: "text" }] })`.
|
|
64
|
+
*/
|
|
65
|
+
function jigsChangeParts(changes) {
|
|
66
|
+
return changes.map((data) => ({
|
|
67
|
+
data,
|
|
68
|
+
type: "data-jigs-change"
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
72
|
+
export { addJigsChange, jigsChangeParts, jigsChangeText };
|
package/dist/chat.d.ts
CHANGED
|
@@ -5,7 +5,8 @@ import { InferUIMessageChunk, UIMessage, UIMessageChunk } from "ai";
|
|
|
5
5
|
export interface JigsChat {
|
|
6
6
|
/**
|
|
7
7
|
* For `convertToModelMessages(messages, { convertDataPart })`: writes each
|
|
8
|
-
* jigs back as the fenced block the model wrote, so it sees its UIs
|
|
8
|
+
* jigs back as the fenced block the model wrote, so it sees its UIs, and
|
|
9
|
+
* each `data-jigs-change` as one sentence saying what the user changed.
|
|
9
10
|
* Returns `undefined` for other data parts; chain your own after it.
|
|
10
11
|
*/
|
|
11
12
|
convertDataPart: (part: {
|
|
@@ -15,13 +16,21 @@ export interface JigsChat {
|
|
|
15
16
|
text: string;
|
|
16
17
|
type: "text";
|
|
17
18
|
} | undefined;
|
|
18
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* The chat-mode prompt for this request: the server's host, then the
|
|
21
|
+
* caller's saved tags (`systemTail`). Add your instructions to it.
|
|
22
|
+
*/
|
|
19
23
|
system: string;
|
|
20
24
|
/**
|
|
21
|
-
* The start of `system` that is the same on every turn. Pass
|
|
22
|
-
* `cachedInstructions` so the provider caches it.
|
|
25
|
+
* The start of `system` that is the same on every turn. Pass it, with
|
|
26
|
+
* `systemTail`, to `cachedInstructions` so the provider caches it.
|
|
23
27
|
*/
|
|
24
28
|
systemPrefix: string;
|
|
29
|
+
/**
|
|
30
|
+
* The end of `system` that differs per user: the `## Saved tags` section
|
|
31
|
+
* when the server's `resolveTags` returned any, or "".
|
|
32
|
+
*/
|
|
33
|
+
systemTail: string;
|
|
25
34
|
/**
|
|
26
35
|
* Turns a UI message stream, e.g. `result.toUIMessageStream()`, into one
|
|
27
36
|
* where jigs are `data-jigs` parts. Prose stays in text parts, in the
|
|
@@ -53,6 +62,8 @@ export declare function jigsChat<TContext, TPageName extends string>(jigs: JigsM
|
|
|
53
62
|
* back from storage. Other parts and the metadata pass through as they are,
|
|
54
63
|
* so a `StoredJigsUIMessage<Metadata>`, or the stored form of your own
|
|
55
64
|
* message type, comes back with `JigsBlockData` in its `data-jigs` parts.
|
|
65
|
+
* Pass `jigs.forUser({ ctx })` rather than the server to compile in the
|
|
66
|
+
* caller's scope, so blocks that use their saved tags draw them.
|
|
56
67
|
*/
|
|
57
68
|
export declare function reviveJigs<TMessage extends UIMessage>(jigs: Pick<JigsServer<unknown>, "compile">, messages: ReadonlyArray<TMessage>): Promise<Array<WithJigsBlocks<TMessage, JigsBlockData>>>;
|
|
58
69
|
//#endregion
|
package/dist/chat.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jigsChangeText } from "./changes.js";
|
|
2
|
+
import { storedBlock, storedChange } from "./schemas.js";
|
|
2
3
|
import { chatBlockText } from "@jigs.design/server";
|
|
3
4
|
import { z } from "zod";
|
|
4
5
|
//#region src/chat.ts
|
|
@@ -40,6 +41,13 @@ async function jigsChat(jigs, input) {
|
|
|
40
41
|
});
|
|
41
42
|
return {
|
|
42
43
|
convertDataPart: (part) => {
|
|
44
|
+
if (part.type === "data-jigs-change") {
|
|
45
|
+
const change = storedChange.safeParse(part.data);
|
|
46
|
+
return change.success ? {
|
|
47
|
+
text: jigsChangeText(change.data),
|
|
48
|
+
type: "text"
|
|
49
|
+
} : void 0;
|
|
50
|
+
}
|
|
43
51
|
if (part.type !== "data-jigs") return;
|
|
44
52
|
const parsed = blockSource.safeParse(part.data);
|
|
45
53
|
return parsed.success ? {
|
|
@@ -49,6 +57,7 @@ async function jigsChat(jigs, input) {
|
|
|
49
57
|
},
|
|
50
58
|
system: turn.system,
|
|
51
59
|
systemPrefix: turn.systemPrefix,
|
|
60
|
+
systemTail: turn.systemTail,
|
|
52
61
|
toUIMessageStream: (stream) => transform(turn, stream, stop),
|
|
53
62
|
turn
|
|
54
63
|
};
|
|
@@ -198,6 +207,8 @@ function transform(turn, stream, stop) {
|
|
|
198
207
|
* back from storage. Other parts and the metadata pass through as they are,
|
|
199
208
|
* so a `StoredJigsUIMessage<Metadata>`, or the stored form of your own
|
|
200
209
|
* message type, comes back with `JigsBlockData` in its `data-jigs` parts.
|
|
210
|
+
* Pass `jigs.forUser({ ctx })` rather than the server to compile in the
|
|
211
|
+
* caller's scope, so blocks that use their saved tags draw them.
|
|
201
212
|
*/
|
|
202
213
|
async function reviveJigs(jigs, messages) {
|
|
203
214
|
return await Promise.all(messages.map(async (message) => ({
|
package/dist/client.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { JigsChange, addJigsChange, jigsChangeParts, jigsChangeText } from "./changes.js";
|
|
1
2
|
import { JigsBlockData, JigsDataTypes, JigsUIMessage, StoredJigsBlock, StoredJigsUIMessage, recentMessages, withoutPrograms } from "./stored.js";
|
|
2
3
|
import { ToolDataOptions, ToolPart, toolData, toolValue } from "./tool-data.js";
|
|
3
|
-
export { type JigsBlockData, type JigsDataTypes, type JigsUIMessage, type StoredJigsBlock, type StoredJigsUIMessage, type ToolDataOptions, type ToolPart, recentMessages, toolData, toolValue, withoutPrograms };
|
|
4
|
+
export { type JigsBlockData, type JigsChange, type JigsDataTypes, type JigsUIMessage, type StoredJigsBlock, type StoredJigsUIMessage, type ToolDataOptions, type ToolPart, addJigsChange, jigsChangeParts, jigsChangeText, recentMessages, toolData, toolValue, withoutPrograms };
|
package/dist/client.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { addJigsChange, jigsChangeParts, jigsChangeText } from "./changes.js";
|
|
1
2
|
import { recentMessages, withoutPrograms } from "./stored.js";
|
|
2
3
|
import { toolData, toolValue } from "./tool-data.js";
|
|
3
|
-
export { recentMessages, toolData, toolValue, withoutPrograms };
|
|
4
|
+
export { addJigsChange, jigsChangeParts, jigsChangeText, recentMessages, toolData, toolValue, withoutPrograms };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { JigsChange, addJigsChange, jigsChangeParts, jigsChangeText } from "./changes.js";
|
|
1
2
|
import { JigsBlockData, JigsDataTypes, JigsUIMessage, StoredJigsBlock, StoredJigsUIMessage, recentMessages, withoutPrograms } from "./stored.js";
|
|
2
3
|
import { ToolDataOptions, ToolPart, toolData, toolValue } from "./tool-data.js";
|
|
3
4
|
import { JigsChat, jigsChat, reviveJigs } from "./chat.js";
|
|
4
5
|
import { ModelSettings, aiSdkModel, cachedInstructions } from "./model.js";
|
|
5
6
|
import { jigsDataSchemas } from "./schemas.js";
|
|
6
|
-
export { type JigsBlockData, type JigsChat, type JigsDataTypes, type JigsUIMessage, type ModelSettings, type StoredJigsBlock, type StoredJigsUIMessage, type ToolDataOptions, type ToolPart, aiSdkModel, cachedInstructions, jigsChat, jigsDataSchemas, recentMessages, reviveJigs, toolData, toolValue, withoutPrograms };
|
|
7
|
+
export { type JigsBlockData, type JigsChange, type JigsChat, type JigsDataTypes, type JigsUIMessage, type ModelSettings, type StoredJigsBlock, type StoredJigsUIMessage, type ToolDataOptions, type ToolPart, addJigsChange, aiSdkModel, cachedInstructions, jigsChangeParts, jigsChangeText, jigsChat, jigsDataSchemas, recentMessages, reviveJigs, toolData, toolValue, withoutPrograms };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { addJigsChange, jigsChangeParts, jigsChangeText } from "./changes.js";
|
|
1
2
|
import { jigsDataSchemas } from "./schemas.js";
|
|
2
3
|
import { jigsChat, reviveJigs } from "./chat.js";
|
|
3
4
|
import { aiSdkModel, cachedInstructions } from "./model.js";
|
|
4
5
|
import { recentMessages, withoutPrograms } from "./stored.js";
|
|
5
6
|
import { toolData, toolValue } from "./tool-data.js";
|
|
6
|
-
export { aiSdkModel, cachedInstructions, jigsChat, jigsDataSchemas, recentMessages, reviveJigs, toolData, toolValue, withoutPrograms };
|
|
7
|
+
export { addJigsChange, aiSdkModel, cachedInstructions, jigsChangeParts, jigsChangeText, jigsChat, jigsDataSchemas, recentMessages, reviveJigs, toolData, toolValue, withoutPrograms };
|
package/dist/model.d.ts
CHANGED
|
@@ -4,22 +4,25 @@ import { Instructions, LanguageModel, streamText } from "ai";
|
|
|
4
4
|
/** `streamText` settings that apply to every call, such as `temperature`. */
|
|
5
5
|
export type ModelSettings = Omit<Parameters<typeof streamText>[0], "abortSignal" | "instructions" | "messages" | "model" | "prompt" | "system">;
|
|
6
6
|
/**
|
|
7
|
-
* `system` as instructions a provider may cache:
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
7
|
+
* `system` as instructions a provider may cache: its first part `prefix`,
|
|
8
|
+
* the rest, and with a `tail` the end that differs per user, each a system
|
|
9
|
+
* message marked as a cache breakpoint for providers that need one
|
|
10
|
+
* (Anthropic). The first mark keeps the prefix cached when the rest
|
|
11
|
+
* changes; the second caches the rest too while it does not, as it does
|
|
12
|
+
* not for a host whose procedures and instructions are fixed; the third,
|
|
13
|
+
* one user's saved tags (`systemTail`), keeps the host's part before it the
|
|
14
|
+
* same for every user. Two of Anthropic's four breakpoints, or three with a
|
|
15
|
+
* tail. Providers that cache a repeated prefix on their own (OpenAI,
|
|
16
|
+
* DeepSeek, Google) read them as one. Without a prefix that `system` starts
|
|
17
|
+
* with, `system` alone; a tail it does not end with is part of the rest.
|
|
16
18
|
*/
|
|
17
|
-
export declare function cachedInstructions(system: string, prefix: string): Instructions;
|
|
19
|
+
export declare function cachedInstructions(system: string, prefix: string, tail?: string): Instructions;
|
|
18
20
|
/**
|
|
19
21
|
* A `model` for `withModel` from an AI SDK model: document-mode
|
|
20
22
|
* sessions and chat repairs stream through `streamText`, and token usage
|
|
21
|
-
* reaches `onTurn`. The prompt's stable start
|
|
22
|
-
* the provider's cache
|
|
23
|
+
* reaches `onTurn`. The prompt's stable start, the host's rest and the
|
|
24
|
+
* caller's saved tags are marked for the provider's cache
|
|
25
|
+
* (`cachedInstructions`).
|
|
23
26
|
*/
|
|
24
27
|
export declare function aiSdkModel(model: LanguageModel, settings?: ModelSettings): ModelFunction<unknown, unknown>;
|
|
25
28
|
//#endregion
|
package/dist/model.js
CHANGED
|
@@ -7,33 +7,42 @@ const cachedMessage = (content) => ({
|
|
|
7
7
|
role: "system"
|
|
8
8
|
});
|
|
9
9
|
/**
|
|
10
|
-
* `system` as instructions a provider may cache:
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
10
|
+
* `system` as instructions a provider may cache: its first part `prefix`,
|
|
11
|
+
* the rest, and with a `tail` the end that differs per user, each a system
|
|
12
|
+
* message marked as a cache breakpoint for providers that need one
|
|
13
|
+
* (Anthropic). The first mark keeps the prefix cached when the rest
|
|
14
|
+
* changes; the second caches the rest too while it does not, as it does
|
|
15
|
+
* not for a host whose procedures and instructions are fixed; the third,
|
|
16
|
+
* one user's saved tags (`systemTail`), keeps the host's part before it the
|
|
17
|
+
* same for every user. Two of Anthropic's four breakpoints, or three with a
|
|
18
|
+
* tail. Providers that cache a repeated prefix on their own (OpenAI,
|
|
19
|
+
* DeepSeek, Google) read them as one. Without a prefix that `system` starts
|
|
20
|
+
* with, `system` alone; a tail it does not end with is part of the rest.
|
|
19
21
|
*/
|
|
20
|
-
function cachedInstructions(system, prefix) {
|
|
22
|
+
function cachedInstructions(system, prefix, tail = "") {
|
|
21
23
|
if (prefix === "" || !system.startsWith(prefix)) return system;
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
+
const ending = tail === "" ? "" : `\n\n${tail}`;
|
|
25
|
+
const tailed = ending !== "" && system.endsWith(ending) && system.length >= prefix.length + ending.length;
|
|
26
|
+
const rest = system.slice(prefix.length, tailed ? system.length - ending.length : system.length);
|
|
27
|
+
return [
|
|
28
|
+
cachedMessage(prefix),
|
|
29
|
+
...rest === "" ? [] : [cachedMessage(rest)],
|
|
30
|
+
...tailed ? [cachedMessage(ending)] : []
|
|
31
|
+
];
|
|
24
32
|
}
|
|
25
33
|
/**
|
|
26
34
|
* A `model` for `withModel` from an AI SDK model: document-mode
|
|
27
35
|
* sessions and chat repairs stream through `streamText`, and token usage
|
|
28
|
-
* reaches `onTurn`. The prompt's stable start
|
|
29
|
-
* the provider's cache
|
|
36
|
+
* reaches `onTurn`. The prompt's stable start, the host's rest and the
|
|
37
|
+
* caller's saved tags are marked for the provider's cache
|
|
38
|
+
* (`cachedInstructions`).
|
|
30
39
|
*/
|
|
31
40
|
function aiSdkModel(model, settings = {}) {
|
|
32
41
|
return async function* (request) {
|
|
33
42
|
const result = streamText({
|
|
34
43
|
...settings,
|
|
35
44
|
abortSignal: request.signal,
|
|
36
|
-
instructions: cachedInstructions(request.system, request.systemPrefix),
|
|
45
|
+
instructions: cachedInstructions(request.system, request.systemPrefix, request.systemTail),
|
|
37
46
|
messages: request.messages.map((message) => ({
|
|
38
47
|
content: message.content,
|
|
39
48
|
role: message.role
|
package/dist/schemas.d.ts
CHANGED
|
@@ -66,5 +66,24 @@ export declare const jigsDataSchemas: {
|
|
|
66
66
|
toolKeys: z.ZodExactOptional<z.ZodUnion<readonly [z.ZodArray<z.ZodString>, z.ZodLiteral<"all">]>>;
|
|
67
67
|
version: z.ZodNumber;
|
|
68
68
|
}, z.core.$strip>;
|
|
69
|
+
"jigs-change": z.ZodObject<{
|
|
70
|
+
count: z.ZodNumber;
|
|
71
|
+
error: z.ZodNullable<z.ZodEnum<{
|
|
72
|
+
BAD_INPUT: "BAD_INPUT";
|
|
73
|
+
CONFLICT: "CONFLICT";
|
|
74
|
+
DECLINED: "DECLINED";
|
|
75
|
+
FORBIDDEN: "FORBIDDEN";
|
|
76
|
+
INTERNAL: "INTERNAL";
|
|
77
|
+
NETWORK: "NETWORK";
|
|
78
|
+
NOT_FOUND: "NOT_FOUND";
|
|
79
|
+
RATE_LIMITED: "RATE_LIMITED";
|
|
80
|
+
UNAUTHORIZED: "UNAUTHORIZED";
|
|
81
|
+
UNAVAILABLE: "UNAVAILABLE";
|
|
82
|
+
UNKNOWN_PROCEDURE: "UNKNOWN_PROCEDURE";
|
|
83
|
+
}>>;
|
|
84
|
+
input: z.ZodJSONSchema;
|
|
85
|
+
key: z.ZodString;
|
|
86
|
+
name: z.ZodString;
|
|
87
|
+
}, z.core.$strip>;
|
|
69
88
|
};
|
|
70
89
|
//#endregion
|
package/dist/schemas.js
CHANGED
|
@@ -44,12 +44,23 @@ const storedBlock = z.object({
|
|
|
44
44
|
toolKeys: z.union([z.array(z.string()), z.literal("all")]).exactOptional(),
|
|
45
45
|
version: z.number()
|
|
46
46
|
});
|
|
47
|
+
/** A `data-jigs-change` part: what the user changed in a jig. */
|
|
48
|
+
const storedChange = z.object({
|
|
49
|
+
count: z.number().int().min(1),
|
|
50
|
+
error: z.enum(jigsErrorCodes).nullable(),
|
|
51
|
+
input: z.json(),
|
|
52
|
+
key: z.string(),
|
|
53
|
+
name: z.string()
|
|
54
|
+
});
|
|
47
55
|
/**
|
|
48
56
|
* Schemas for `validateUIMessages<StoredJigsUIMessage>({ messages,
|
|
49
57
|
* dataSchemas })`, to check a conversation the browser sent or one read
|
|
50
58
|
* from storage. A jig's program is dropped, never checked: the server
|
|
51
59
|
* reads only `name` and `source`, and a source is only ever compiled.
|
|
52
60
|
*/
|
|
53
|
-
const jigsDataSchemas = {
|
|
61
|
+
const jigsDataSchemas = {
|
|
62
|
+
jigs: storedBlock,
|
|
63
|
+
"jigs-change": storedChange
|
|
64
|
+
};
|
|
54
65
|
//#endregion
|
|
55
|
-
export { jigsDataSchemas, storedBlock };
|
|
66
|
+
export { jigsDataSchemas, storedBlock, storedChange };
|
package/dist/stored.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { JigsChange } from "./changes.js";
|
|
1
2
|
import { ChatBlock } from "@jigs.design/protocol";
|
|
2
3
|
import { UIMessage } from "ai";
|
|
3
4
|
//#region src/stored.d.ts
|
|
@@ -10,11 +11,13 @@ export type JigsBlockData = ChatBlock;
|
|
|
10
11
|
*/
|
|
11
12
|
export type StoredJigsBlock = Omit<JigsBlockData, "program">;
|
|
12
13
|
/**
|
|
13
|
-
* The data parts chat mode adds to a message
|
|
14
|
-
*
|
|
14
|
+
* The data parts chat mode adds to a message: jigs on a reply, and what the
|
|
15
|
+
* user changed in them on the next user message. A type, not an interface:
|
|
16
|
+
* the AI SDK's data types need an implicit index signature.
|
|
15
17
|
*/
|
|
16
18
|
export type JigsDataTypes = {
|
|
17
19
|
jigs: JigsBlockData;
|
|
20
|
+
"jigs-change": JigsChange;
|
|
18
21
|
};
|
|
19
22
|
/** A `useChat` message whose replies may hold jigs. */
|
|
20
23
|
export type JigsUIMessage<TMetadata = unknown> = UIMessage<TMetadata, JigsDataTypes>;
|
|
@@ -25,6 +28,7 @@ export type JigsUIMessage<TMetadata = unknown> = UIMessage<TMetadata, JigsDataTy
|
|
|
25
28
|
*/
|
|
26
29
|
export type StoredJigsUIMessage<TMetadata = unknown> = UIMessage<TMetadata, {
|
|
27
30
|
jigs: StoredJigsBlock;
|
|
31
|
+
"jigs-change": JigsChange;
|
|
28
32
|
}>;
|
|
29
33
|
/** A message part, with a `data-jigs` part's data replaced by `TBlock`. */
|
|
30
34
|
type WithBlock<TPart, TBlock> = TPart extends {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jigs.design/ai-sdk",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.6",
|
|
4
4
|
"description": "Jigs on the AI SDK: a model function for createJigsServer, and chat mode for useChat.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@jigs.design/protocol": "0.3.
|
|
33
|
-
"@jigs.design/server": "0.3.
|
|
32
|
+
"@jigs.design/protocol": "0.3.6",
|
|
33
|
+
"@jigs.design/server": "0.3.6"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
36
|
"ai": "^7.0.0",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@ai-sdk/provider": "4.0.27",
|
|
41
41
|
"ai": "7.0.140",
|
|
42
42
|
"zod": "4.6.7",
|
|
43
|
-
"@jigs.design/catalog": "0.3.
|
|
44
|
-
"@jigs.design/host": "0.3.
|
|
43
|
+
"@jigs.design/catalog": "0.3.6",
|
|
44
|
+
"@jigs.design/host": "0.3.6"
|
|
45
45
|
}
|
|
46
46
|
}
|