@jigs.design/ai-sdk 0.1.1 → 0.2.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/README.md +17 -17
- package/dist/chat.d.ts +16 -16
- package/dist/chat.js +16 -16
- package/dist/client.d.ts +2 -2
- package/dist/index.d.ts +4 -4
- package/dist/index.js +3 -3
- package/dist/model.d.ts +1 -1
- package/dist/model.js +1 -1
- package/dist/schemas.d.ts +4 -5
- package/dist/schemas.js +7 -12
- package/dist/stored.d.ts +22 -22
- package/dist/stored.js +8 -8
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
# @jigs.design/ai-sdk
|
|
2
2
|
|
|
3
|
-
Optional. Connects
|
|
3
|
+
Optional. Connects Jigs to the [AI SDK](https://ai-sdk.dev) in two ways:
|
|
4
4
|
|
|
5
|
-
- `aiSdkModel(model, settings?)` is a `model` for `
|
|
6
|
-
- `
|
|
5
|
+
- `aiSdkModel(model, settings?)` is a `model` for `createJigsServer`. It passes the host's prompt as `instructions`, streams the text through `streamText`, and reports token usage to `onTurn`. It takes a gateway id such as `"anthropic/claude-sonnet-5.5"` or any provider's `LanguageModel`.
|
|
6
|
+
- `jigsChat(jigs, { request, messages })` runs chat mode on a `useChat` conversation. The assistant answers in Markdown, and each fenced `jigs` block becomes a `data-jigs` part you draw with `JigsView`.
|
|
7
7
|
|
|
8
8
|
```ts
|
|
9
9
|
import { aiSdkModel } from "@jigs.design/ai-sdk";
|
|
10
|
-
import {
|
|
10
|
+
import { createJigsServer } from "@jigs.design/server";
|
|
11
11
|
|
|
12
|
-
export const
|
|
12
|
+
export const jigs = createJigsServer({
|
|
13
13
|
host,
|
|
14
14
|
context,
|
|
15
15
|
run,
|
|
@@ -21,24 +21,24 @@ Import the root entry from server code. The browser imports `@jigs.design/ai-sdk
|
|
|
21
21
|
|
|
22
22
|
## Exports
|
|
23
23
|
|
|
24
|
-
| Export
|
|
25
|
-
|
|
|
26
|
-
| `aiSdkModel`, `ModelSettings`
|
|
27
|
-
| `
|
|
28
|
-
| `
|
|
29
|
-
| `
|
|
30
|
-
| `withoutPrograms`
|
|
31
|
-
| `recentMessages`
|
|
32
|
-
| `
|
|
33
|
-
| `
|
|
34
|
-
| `@jigs.design/ai-sdk/client`
|
|
24
|
+
| Export | What it is |
|
|
25
|
+
| ---------------------------------------- | -------------------------------------------------------------------------------- |
|
|
26
|
+
| `aiSdkModel`, `ModelSettings` | The model function and the `streamText` settings it applies to every call |
|
|
27
|
+
| `jigsChat` | One chat turn: the system prompt, the history converter and the stream transform |
|
|
28
|
+
| `jigsDataSchemas` | Schemas for `validateUIMessages`. They drop each jig's `program` |
|
|
29
|
+
| `reviveJigs` | Compiles a stored conversation's jigs again, typed from the messages passed |
|
|
30
|
+
| `withoutPrograms` | Strips programs from messages, for the request body and for storage |
|
|
31
|
+
| `recentMessages` | The recent turns of a long conversation, after every earlier jig |
|
|
32
|
+
| `JigsUIMessage`, `JigsBlockData` | Types for `useChat` and for one `data-jigs` part, generic over your metadata |
|
|
33
|
+
| `StoredJigsUIMessage`, `StoredJigsBlock` | The same without programs: what the server receives and what you store |
|
|
34
|
+
| `@jigs.design/ai-sdk/client` | The browser entry: `withoutPrograms`, `recentMessages` and the types |
|
|
35
35
|
|
|
36
36
|
## Source
|
|
37
37
|
|
|
38
38
|
- `src/model.ts`: `aiSdkModel`.
|
|
39
39
|
- `src/chat.ts`: chat mode on `useChat`.
|
|
40
40
|
- `src/stored.ts`, `src/client.ts`: the message types, `withoutPrograms`, `recentMessages`, and the browser entry. No Zod here.
|
|
41
|
-
- `src/schemas.ts`: `
|
|
41
|
+
- `src/schemas.ts`: `jigsDataSchemas`, server only.
|
|
42
42
|
|
|
43
43
|
## Docs
|
|
44
44
|
|
package/dist/chat.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ChatTurn,
|
|
1
|
+
import { JigsBlockData, JigsUIMessage, WithJigsBlocks } from "./stored.js";
|
|
2
|
+
import { ChatTurn, JigsServer } from "@jigs.design/server";
|
|
3
3
|
import { InferUIMessageChunk, UIMessage, UIMessageChunk } from "ai";
|
|
4
4
|
//#region src/chat.d.ts
|
|
5
|
-
export interface
|
|
5
|
+
export interface JigsChat {
|
|
6
6
|
/**
|
|
7
7
|
* For `convertToModelMessages(messages, { convertDataPart })`: writes each
|
|
8
|
-
*
|
|
8
|
+
* jigs back as the fenced block the model wrote, so it sees its UIs.
|
|
9
9
|
* Returns `undefined` for other data parts; chain your own after it.
|
|
10
10
|
*/
|
|
11
11
|
convertDataPart: (part: {
|
|
@@ -24,35 +24,35 @@ export interface PickleChat {
|
|
|
24
24
|
systemPrefix: string;
|
|
25
25
|
/**
|
|
26
26
|
* Turns a UI message stream, e.g. `result.toUIMessageStream()`, into one
|
|
27
|
-
* where
|
|
27
|
+
* where jigs are `data-jigs` parts. Prose stays in text parts, in the
|
|
28
28
|
* reply's order; a block's part updates in place as it streams and when it
|
|
29
29
|
* is repaired, and the stream finishes after every repair. Cancelling it
|
|
30
30
|
* stops the repairs. `TMessage` is the app's message type, for
|
|
31
|
-
* `createUIMessageStream`; its `
|
|
32
|
-
* `
|
|
31
|
+
* `createUIMessageStream`; its `jigs` data part must be a
|
|
32
|
+
* `JigsBlockData` or a `StoredJigsBlock`.
|
|
33
33
|
*/
|
|
34
|
-
toUIMessageStream: <TMessage extends UIMessage =
|
|
34
|
+
toUIMessageStream: <TMessage extends UIMessage = JigsUIMessage>(stream: ReadableStream<UIMessageChunk>) => ReadableStream<InferUIMessageChunk<TMessage>>;
|
|
35
35
|
/** The chat turn under it, for anything the stream transform does not cover. */
|
|
36
36
|
turn: ChatTurn;
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
39
39
|
* Starts one chat reply on the AI SDK. Runs the server's `context` for
|
|
40
|
-
* `request` (a
|
|
41
|
-
* conversation's earlier
|
|
40
|
+
* `request` (a JigsError it throws rejects, as on a call) and reads the
|
|
41
|
+
* conversation's earlier jigs from `messages`, so edits and versions
|
|
42
42
|
* continue from them.
|
|
43
43
|
*/
|
|
44
|
-
export declare function
|
|
44
|
+
export declare function jigsChat<TContext, TSpecName extends string>(jigs: JigsServer<TContext, TSpecName>, input: {
|
|
45
45
|
messages: ReadonlyArray<UIMessage>;
|
|
46
46
|
/** App options for the server's `options` schema, passed to repairs. */
|
|
47
47
|
options?: unknown;
|
|
48
48
|
request: Request;
|
|
49
|
-
}): Promise<
|
|
49
|
+
}): Promise<JigsChat>;
|
|
50
50
|
/**
|
|
51
|
-
* Compiles the
|
|
51
|
+
* Compiles the jigs of a stored conversation again, for showing it after
|
|
52
52
|
* a reload. Programs are rebuilt from each block's `source` here, never read
|
|
53
53
|
* back from storage. Other parts and the metadata pass through as they are,
|
|
54
|
-
* so a `
|
|
55
|
-
* message type, comes back with `
|
|
54
|
+
* so a `StoredJigsUIMessage<Metadata>`, or the stored form of your own
|
|
55
|
+
* message type, comes back with `JigsBlockData` in its `data-jigs` parts.
|
|
56
56
|
*/
|
|
57
|
-
export declare function
|
|
57
|
+
export declare function reviveJigs<TMessage extends UIMessage>(jigs: Pick<JigsServer<unknown>, "compile">, messages: ReadonlyArray<TMessage>): Promise<Array<WithJigsBlocks<TMessage, JigsBlockData>>>;
|
|
58
58
|
//#endregion
|
package/dist/chat.js
CHANGED
|
@@ -6,13 +6,13 @@ const blockSource = z.object({
|
|
|
6
6
|
id: z.string(),
|
|
7
7
|
source: z.string()
|
|
8
8
|
});
|
|
9
|
-
/** The conversation's blocks, oldest first, read from its `data-
|
|
9
|
+
/** The conversation's blocks, oldest first, read from its `data-jigs` parts. */
|
|
10
10
|
function blocksIn(messages) {
|
|
11
11
|
const blocks = [];
|
|
12
12
|
for (const message of messages) {
|
|
13
13
|
if (message.role !== "assistant") continue;
|
|
14
14
|
for (const part of message.parts) {
|
|
15
|
-
if (part.type !== "data-
|
|
15
|
+
if (part.type !== "data-jigs" || !("data" in part)) continue;
|
|
16
16
|
const parsed = blockSource.safeParse(part.data);
|
|
17
17
|
if (parsed.success) blocks.push(parsed.data);
|
|
18
18
|
}
|
|
@@ -26,13 +26,13 @@ function lastPrompt(messages) {
|
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
28
|
* Starts one chat reply on the AI SDK. Runs the server's `context` for
|
|
29
|
-
* `request` (a
|
|
30
|
-
* conversation's earlier
|
|
29
|
+
* `request` (a JigsError it throws rejects, as on a call) and reads the
|
|
30
|
+
* conversation's earlier jigs from `messages`, so edits and versions
|
|
31
31
|
* continue from them.
|
|
32
32
|
*/
|
|
33
|
-
async function
|
|
33
|
+
async function jigsChat(jigs, input) {
|
|
34
34
|
const stop = new AbortController();
|
|
35
|
-
const turn = await
|
|
35
|
+
const turn = await jigs.chat(input.request, {
|
|
36
36
|
blocks: blocksIn(input.messages),
|
|
37
37
|
options: input.options,
|
|
38
38
|
prompt: lastPrompt(input.messages),
|
|
@@ -40,7 +40,7 @@ async function pickleChat(pickle, input) {
|
|
|
40
40
|
});
|
|
41
41
|
return {
|
|
42
42
|
convertDataPart: (part) => {
|
|
43
|
-
if (part.type !== "data-
|
|
43
|
+
if (part.type !== "data-jigs") return;
|
|
44
44
|
const parsed = blockSource.safeParse(part.data);
|
|
45
45
|
return parsed.success ? {
|
|
46
46
|
text: chatBlockText(parsed.data),
|
|
@@ -56,7 +56,7 @@ async function pickleChat(pickle, input) {
|
|
|
56
56
|
/** What a block that was still open says when its reply stops. */
|
|
57
57
|
const STOPPED = {
|
|
58
58
|
code: "INTERNAL",
|
|
59
|
-
message: "The reply stopped before this
|
|
59
|
+
message: "The reply stopped before this jig was finished."
|
|
60
60
|
};
|
|
61
61
|
function transform(turn, stream, stop) {
|
|
62
62
|
const reader = stream.getReader();
|
|
@@ -88,7 +88,7 @@ function transform(turn, stream, stop) {
|
|
|
88
88
|
send({
|
|
89
89
|
data: block,
|
|
90
90
|
id: block.key,
|
|
91
|
-
type: "data-
|
|
91
|
+
type: "data-jigs"
|
|
92
92
|
});
|
|
93
93
|
};
|
|
94
94
|
const repair = (block) => {
|
|
@@ -193,19 +193,19 @@ function transform(turn, stream, stop) {
|
|
|
193
193
|
});
|
|
194
194
|
}
|
|
195
195
|
/**
|
|
196
|
-
* Compiles the
|
|
196
|
+
* Compiles the jigs of a stored conversation again, for showing it after
|
|
197
197
|
* a reload. Programs are rebuilt from each block's `source` here, never read
|
|
198
198
|
* back from storage. Other parts and the metadata pass through as they are,
|
|
199
|
-
* so a `
|
|
200
|
-
* message type, comes back with `
|
|
199
|
+
* so a `StoredJigsUIMessage<Metadata>`, or the stored form of your own
|
|
200
|
+
* message type, comes back with `JigsBlockData` in its `data-jigs` parts.
|
|
201
201
|
*/
|
|
202
|
-
async function
|
|
202
|
+
async function reviveJigs(jigs, messages) {
|
|
203
203
|
return await Promise.all(messages.map(async (message) => ({
|
|
204
204
|
...message,
|
|
205
205
|
parts: await Promise.all(message.parts.map(async (part) => {
|
|
206
|
-
if (part.type !== "data-
|
|
206
|
+
if (part.type !== "data-jigs" || !("data" in part)) return part;
|
|
207
207
|
const stored = storedBlock.parse(part.data);
|
|
208
|
-
const compiled = await
|
|
208
|
+
const compiled = await jigs.compile(stored.source, { strict: false });
|
|
209
209
|
const data = {
|
|
210
210
|
...stored,
|
|
211
211
|
diagnostics: compiled.diagnostics,
|
|
@@ -220,4 +220,4 @@ async function revivePickles(pickle, messages) {
|
|
|
220
220
|
})));
|
|
221
221
|
}
|
|
222
222
|
//#endregion
|
|
223
|
-
export {
|
|
223
|
+
export { jigsChat, reviveJigs };
|
package/dist/client.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { type
|
|
1
|
+
import { JigsBlockData, JigsDataTypes, JigsUIMessage, StoredJigsBlock, StoredJigsUIMessage, recentMessages, withoutPrograms } from "./stored.js";
|
|
2
|
+
export { type JigsBlockData, type JigsDataTypes, type JigsUIMessage, type StoredJigsBlock, type StoredJigsUIMessage, recentMessages, withoutPrograms };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { JigsBlockData, JigsDataTypes, JigsUIMessage, StoredJigsBlock, StoredJigsUIMessage, recentMessages, withoutPrograms } from "./stored.js";
|
|
2
|
+
import { JigsChat, jigsChat, reviveJigs } from "./chat.js";
|
|
3
3
|
import { ModelSettings, aiSdkModel, cachedInstructions } from "./model.js";
|
|
4
|
-
import {
|
|
5
|
-
export { type
|
|
4
|
+
import { jigsDataSchemas } from "./schemas.js";
|
|
5
|
+
export { type JigsBlockData, type JigsChat, type JigsDataTypes, type JigsUIMessage, type ModelSettings, type StoredJigsBlock, type StoredJigsUIMessage, aiSdkModel, cachedInstructions, jigsChat, jigsDataSchemas, recentMessages, reviveJigs, withoutPrograms };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { jigsDataSchemas } from "./schemas.js";
|
|
2
|
+
import { jigsChat, reviveJigs } from "./chat.js";
|
|
3
3
|
import { aiSdkModel, cachedInstructions } from "./model.js";
|
|
4
4
|
import { recentMessages, withoutPrograms } from "./stored.js";
|
|
5
|
-
export { aiSdkModel, cachedInstructions,
|
|
5
|
+
export { aiSdkModel, cachedInstructions, jigsChat, jigsDataSchemas, recentMessages, reviveJigs, withoutPrograms };
|
package/dist/model.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export type ModelSettings = Omit<Parameters<typeof streamText>[0], "abortSignal"
|
|
|
12
12
|
*/
|
|
13
13
|
export declare function cachedInstructions(system: string, prefix: string): Instructions;
|
|
14
14
|
/**
|
|
15
|
-
* A `model` for `
|
|
15
|
+
* A `model` for `createJigsServer` from an AI SDK model: document-mode
|
|
16
16
|
* sessions and chat repairs stream through `streamText`, and token usage
|
|
17
17
|
* reaches `onTurn`. The prompt's stable start is marked for the provider's
|
|
18
18
|
* cache (`cachedInstructions`).
|
package/dist/model.js
CHANGED
|
@@ -19,7 +19,7 @@ function cachedInstructions(system, prefix) {
|
|
|
19
19
|
}];
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
|
-
* A `model` for `
|
|
22
|
+
* A `model` for `createJigsServer` from an AI SDK model: document-mode
|
|
23
23
|
* sessions and chat repairs stream through `streamText`, and token usage
|
|
24
24
|
* reaches `onTurn`. The prompt's stable start is marked for the provider's
|
|
25
25
|
* cache (`cachedInstructions`).
|
package/dist/schemas.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
//#region src/schemas.d.ts
|
|
3
3
|
/**
|
|
4
|
-
* Schemas for `validateUIMessages<
|
|
4
|
+
* Schemas for `validateUIMessages<StoredJigsUIMessage>({ messages,
|
|
5
5
|
* dataSchemas })`, to check a conversation the browser sent or one read
|
|
6
|
-
* from storage. A
|
|
6
|
+
* from storage. A jig's program is dropped, never checked: the server
|
|
7
7
|
* reads only `id` and `source`, and a source is only ever compiled.
|
|
8
8
|
*/
|
|
9
|
-
export declare const
|
|
10
|
-
|
|
9
|
+
export declare const jigsDataSchemas: {
|
|
10
|
+
jigs: z.ZodObject<{
|
|
11
11
|
diagnostics: z.ZodArray<z.ZodObject<{
|
|
12
12
|
code: z.ZodString;
|
|
13
13
|
fix: z.ZodExactOptional<z.ZodObject<{
|
|
@@ -25,7 +25,6 @@ export declare const pickleDataSchemas: {
|
|
|
25
25
|
message: z.ZodString;
|
|
26
26
|
severity: z.ZodEnum<{
|
|
27
27
|
error: "error";
|
|
28
|
-
hint: "hint";
|
|
29
28
|
info: "info";
|
|
30
29
|
warning: "warning";
|
|
31
30
|
}>;
|
package/dist/schemas.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import {
|
|
2
|
+
import { jigsErrorCodes, severities } from "@jigs.design/protocol";
|
|
3
3
|
//#region src/schemas.ts
|
|
4
4
|
const span = z.object({
|
|
5
5
|
column: z.number().exactOptional(),
|
|
@@ -18,16 +18,11 @@ const storedBlock = z.object({
|
|
|
18
18
|
title: z.string()
|
|
19
19
|
}).exactOptional(),
|
|
20
20
|
message: z.string(),
|
|
21
|
-
severity: z.enum(
|
|
22
|
-
"error",
|
|
23
|
-
"hint",
|
|
24
|
-
"info",
|
|
25
|
-
"warning"
|
|
26
|
-
]),
|
|
21
|
+
severity: z.enum(severities),
|
|
27
22
|
span
|
|
28
23
|
})),
|
|
29
24
|
error: z.object({
|
|
30
|
-
code: z.enum(
|
|
25
|
+
code: z.enum(jigsErrorCodes),
|
|
31
26
|
message: z.string()
|
|
32
27
|
}).exactOptional(),
|
|
33
28
|
id: z.string(),
|
|
@@ -41,11 +36,11 @@ const storedBlock = z.object({
|
|
|
41
36
|
version: z.number()
|
|
42
37
|
});
|
|
43
38
|
/**
|
|
44
|
-
* Schemas for `validateUIMessages<
|
|
39
|
+
* Schemas for `validateUIMessages<StoredJigsUIMessage>({ messages,
|
|
45
40
|
* dataSchemas })`, to check a conversation the browser sent or one read
|
|
46
|
-
* from storage. A
|
|
41
|
+
* from storage. A jig's program is dropped, never checked: the server
|
|
47
42
|
* reads only `id` and `source`, and a source is only ever compiled.
|
|
48
43
|
*/
|
|
49
|
-
const
|
|
44
|
+
const jigsDataSchemas = { jigs: storedBlock };
|
|
50
45
|
//#endregion
|
|
51
|
-
export {
|
|
46
|
+
export { jigsDataSchemas, storedBlock };
|
package/dist/stored.d.ts
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
import { ChatBlock } from "@jigs.design/
|
|
1
|
+
import { ChatBlock } from "@jigs.design/protocol";
|
|
2
2
|
import { UIMessage } from "ai";
|
|
3
3
|
//#region src/stored.d.ts
|
|
4
|
-
/** A
|
|
5
|
-
export type
|
|
4
|
+
/** A jig's `data-jigs` part: one fenced block of a reply, compiled. */
|
|
5
|
+
export type JigsBlockData = ChatBlock;
|
|
6
6
|
/**
|
|
7
|
-
* A
|
|
8
|
-
* the program. Only `
|
|
7
|
+
* A jig as the browser sends it back and as you store it: everything but
|
|
8
|
+
* the program. Only `reviveJigs` turns it back into a `JigsBlockData`,
|
|
9
9
|
* by compiling `source` again.
|
|
10
10
|
*/
|
|
11
|
-
export type
|
|
11
|
+
export type StoredJigsBlock = Omit<JigsBlockData, "program">;
|
|
12
12
|
/**
|
|
13
13
|
* The data parts chat mode adds to a message. A type, not an interface: the
|
|
14
14
|
* AI SDK's data types need an implicit index signature.
|
|
15
15
|
*/
|
|
16
|
-
export type
|
|
17
|
-
|
|
16
|
+
export type JigsDataTypes = {
|
|
17
|
+
jigs: JigsBlockData;
|
|
18
18
|
};
|
|
19
|
-
/** A `useChat` message whose replies may hold
|
|
20
|
-
export type
|
|
19
|
+
/** A `useChat` message whose replies may hold jigs. */
|
|
20
|
+
export type JigsUIMessage<TMetadata = unknown> = UIMessage<TMetadata, JigsDataTypes>;
|
|
21
21
|
/**
|
|
22
|
-
* A conversation as the server receives it and as you store it: its
|
|
23
|
-
* carry no programs. `validateUIMessages` with `
|
|
22
|
+
* A conversation as the server receives it and as you store it: its jigs
|
|
23
|
+
* carry no programs. `validateUIMessages` with `jigsDataSchemas` returns
|
|
24
24
|
* this shape.
|
|
25
25
|
*/
|
|
26
|
-
export type
|
|
27
|
-
|
|
26
|
+
export type StoredJigsUIMessage<TMetadata = unknown> = UIMessage<TMetadata, {
|
|
27
|
+
jigs: StoredJigsBlock;
|
|
28
28
|
}>;
|
|
29
|
-
/** A message part, with a `data-
|
|
29
|
+
/** A message part, with a `data-jigs` part's data replaced by `TBlock`. */
|
|
30
30
|
type WithBlock<TPart, TBlock> = TPart extends {
|
|
31
|
-
type: "data-
|
|
31
|
+
type: "data-jigs";
|
|
32
32
|
} ? Omit<TPart, "data"> & {
|
|
33
33
|
data: TBlock;
|
|
34
34
|
} : TPart;
|
|
35
35
|
/**
|
|
36
|
-
* `TMessage` with each
|
|
36
|
+
* `TMessage` with each jig's data replaced by `TBlock`, and every other
|
|
37
37
|
* part, the metadata included, as it was.
|
|
38
38
|
*/
|
|
39
|
-
export type
|
|
39
|
+
export type WithJigsBlocks<TMessage extends UIMessage, TBlock> = Omit<TMessage, "parts"> & {
|
|
40
40
|
parts: Array<WithBlock<TMessage["parts"][number], TBlock>>;
|
|
41
41
|
};
|
|
42
42
|
/**
|
|
43
|
-
* The messages without their
|
|
43
|
+
* The messages without their jigs' programs: for the body `useChat`
|
|
44
44
|
* posts (`prepareSendMessagesRequest`), and for storing a conversation. The
|
|
45
45
|
* server reads only each block's `id` and `source`. Every other part, and
|
|
46
46
|
* every other field of a block, is kept as it is.
|
|
47
47
|
*/
|
|
48
|
-
export declare function withoutPrograms<TMessage extends UIMessage>(messages: ReadonlyArray<TMessage>): Array<
|
|
48
|
+
export declare function withoutPrograms<TMessage extends UIMessage>(messages: ReadonlyArray<TMessage>): Array<WithJigsBlocks<TMessage, StoredJigsBlock>>;
|
|
49
49
|
/**
|
|
50
50
|
* The end of a long conversation, for the body `useChat` posts: the last
|
|
51
|
-
* `keep` messages, from a user message on. Every earlier
|
|
52
|
-
* in one assistant message of their `data-
|
|
51
|
+
* `keep` messages, from a user message on. Every earlier jig comes first,
|
|
52
|
+
* in one assistant message of their `data-jigs` parts, so the model still
|
|
53
53
|
* sees each one and edits and versions continue from them; earlier prose is
|
|
54
54
|
* left out. A conversation no longer than `keep` is returned as it is.
|
|
55
55
|
*/
|
package/dist/stored.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
//#region src/stored.ts
|
|
2
|
-
/** Whether `part` is a
|
|
2
|
+
/** Whether `part` is a jig whose block still holds its program. */
|
|
3
3
|
function hasProgram(part) {
|
|
4
|
-
return part.type === "data-
|
|
4
|
+
return part.type === "data-jigs" && "data" in part && typeof part.data === "object" && part.data !== null && "program" in part.data;
|
|
5
5
|
}
|
|
6
6
|
/**
|
|
7
|
-
* The messages without their
|
|
7
|
+
* The messages without their jigs' programs: for the body `useChat`
|
|
8
8
|
* posts (`prepareSendMessagesRequest`), and for storing a conversation. The
|
|
9
9
|
* server reads only each block's `id` and `source`. Every other part, and
|
|
10
10
|
* every other field of a block, is kept as it is.
|
|
@@ -26,8 +26,8 @@ function withoutPrograms(messages) {
|
|
|
26
26
|
const RECENT = 20;
|
|
27
27
|
/**
|
|
28
28
|
* The end of a long conversation, for the body `useChat` posts: the last
|
|
29
|
-
* `keep` messages, from a user message on. Every earlier
|
|
30
|
-
* in one assistant message of their `data-
|
|
29
|
+
* `keep` messages, from a user message on. Every earlier jig comes first,
|
|
30
|
+
* in one assistant message of their `data-jigs` parts, so the model still
|
|
31
31
|
* sees each one and edits and versions continue from them; earlier prose is
|
|
32
32
|
* left out. A conversation no longer than `keep` is returned as it is.
|
|
33
33
|
*/
|
|
@@ -37,13 +37,13 @@ function recentMessages(messages, keep = RECENT) {
|
|
|
37
37
|
const nextUser = messages.findIndex((message, index) => index >= start && message.role === "user");
|
|
38
38
|
if (nextUser !== -1) start = nextUser;
|
|
39
39
|
const earlier = messages.slice(0, start).filter((message) => message.role === "assistant");
|
|
40
|
-
const
|
|
40
|
+
const jigs = earlier.flatMap((message) => message.parts.filter((part) => part.type === "data-jigs"));
|
|
41
41
|
const recent = messages.slice(start);
|
|
42
42
|
const [first] = earlier;
|
|
43
|
-
if (first === void 0 ||
|
|
43
|
+
if (first === void 0 || jigs.length === 0) return recent;
|
|
44
44
|
return [{
|
|
45
45
|
...first,
|
|
46
|
-
parts:
|
|
46
|
+
parts: jigs
|
|
47
47
|
}, ...recent];
|
|
48
48
|
}
|
|
49
49
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jigs.design/ai-sdk",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Jigs on the AI SDK: a model function for createJigsServer, and chat mode for useChat.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "git+https://github.com/yoamomonstruos/
|
|
8
|
+
"url": "git+https://github.com/yoamomonstruos/jigs.git",
|
|
9
9
|
"directory": "packages/ai-sdk"
|
|
10
10
|
},
|
|
11
11
|
"type": "module",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@jigs.design/
|
|
33
|
-
"@jigs.design/
|
|
32
|
+
"@jigs.design/server": "0.2.0",
|
|
33
|
+
"@jigs.design/protocol": "0.2.0"
|
|
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/
|
|
44
|
-
"@jigs.design/
|
|
43
|
+
"@jigs.design/catalog": "0.2.0",
|
|
44
|
+
"@jigs.design/host": "0.2.0"
|
|
45
45
|
}
|
|
46
46
|
}
|