@x12i/ai 0.0.0-stage → 1.0.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 +21 -0
- package/README.md +40 -3
- package/dist/index.d.ts +87 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/package.json +34 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 x12i
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,40 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# @x12i/ai
|
|
2
|
+
|
|
3
|
+
Neutral message shape and store contracts for the Unified UI Kit AI chat set.
|
|
4
|
+
|
|
5
|
+
> **Status: foundation.** This package ships the typed message parts and the
|
|
6
|
+
> `ThreadStore` contract. The chat components (`ChatThread`, `PromptInput`,
|
|
7
|
+
> `ToolCall`, `ApprovalPrompt`, ...) and the provider adapters are not built yet.
|
|
8
|
+
|
|
9
|
+
Components read a neutral message with typed parts (`text`, `reasoning`, `tool`,
|
|
10
|
+
`source`, `file`, `data`), so they never import a provider SDK. Adapters convert
|
|
11
|
+
provider formats, such as Vercel AI SDK message parts, into this shape.
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { messageText, type Message } from "@x12i/ai";
|
|
15
|
+
|
|
16
|
+
const message: Message = {
|
|
17
|
+
id: "m1",
|
|
18
|
+
role: "assistant",
|
|
19
|
+
parts: [{ type: "text", text: "Hello" }],
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
messageText(message); // "Hello"
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Contracts
|
|
26
|
+
|
|
27
|
+
- `MessageAdapter<Input>`: converts a provider message into a `Message`.
|
|
28
|
+
- `ThreadStore`: the thread component is stateless, so storage and history belong
|
|
29
|
+
to the app. `@x12i/flowix-ui` has one that keeps each thread as a Flowix fact
|
|
30
|
+
(`createFlowixThreadStore`), so a conversation survives a reload and every save
|
|
31
|
+
stays in Flowix's revision history.
|
|
32
|
+
- `DataPart`: structured data a component can render. Tool input and output, and
|
|
33
|
+
any JSON you attach, can be painted with `@x12i/records`' `RecordView`, which
|
|
34
|
+
lays out undescribed JSON from its shape.
|
|
35
|
+
|
|
36
|
+
## References
|
|
37
|
+
|
|
38
|
+
The kit adopts structure and naming from Vercel AI Elements (Apache-2.0),
|
|
39
|
+
assistant-ui (MIT) and prompt-kit (MIT), restyled through tokens, and does not
|
|
40
|
+
depend on any of them at runtime.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The neutral message shape (spec section 6). Components read typed parts and
|
|
3
|
+
* never import a provider SDK; adapters convert provider formats into this
|
|
4
|
+
* shape.
|
|
5
|
+
*/
|
|
6
|
+
type MessageRole = "user" | "assistant" | "system";
|
|
7
|
+
interface TextPart {
|
|
8
|
+
type: "text";
|
|
9
|
+
text: string;
|
|
10
|
+
}
|
|
11
|
+
interface ReasoningPart {
|
|
12
|
+
type: "reasoning";
|
|
13
|
+
text: string;
|
|
14
|
+
/** How long the model thought, for the "Thought for 4s" line. */
|
|
15
|
+
durationMs?: number;
|
|
16
|
+
}
|
|
17
|
+
type ToolState = "queued" | "running" | "succeeded" | "failed" | "needs-approval";
|
|
18
|
+
interface ToolPart {
|
|
19
|
+
type: "tool";
|
|
20
|
+
id: string;
|
|
21
|
+
name: string;
|
|
22
|
+
state: ToolState;
|
|
23
|
+
input?: unknown;
|
|
24
|
+
output?: unknown;
|
|
25
|
+
/** A human-readable cause when `state` is `failed`. */
|
|
26
|
+
error?: string;
|
|
27
|
+
durationMs?: number;
|
|
28
|
+
}
|
|
29
|
+
interface SourcePart {
|
|
30
|
+
type: "source";
|
|
31
|
+
id: string;
|
|
32
|
+
title: string;
|
|
33
|
+
url: string;
|
|
34
|
+
/** Shown in the source list next to the title and domain. */
|
|
35
|
+
snippet?: string;
|
|
36
|
+
}
|
|
37
|
+
interface FilePart {
|
|
38
|
+
type: "file";
|
|
39
|
+
name: string;
|
|
40
|
+
mediaType: string;
|
|
41
|
+
url: string;
|
|
42
|
+
size?: number;
|
|
43
|
+
}
|
|
44
|
+
/** Structured data a component can render, for example an artifact or a chart spec. */
|
|
45
|
+
interface DataPart {
|
|
46
|
+
type: "data";
|
|
47
|
+
/** Identifies the shape of `data`, such as `chart` or `diagram`. */
|
|
48
|
+
kind: string;
|
|
49
|
+
data: unknown;
|
|
50
|
+
}
|
|
51
|
+
type MessagePart = TextPart | ReasoningPart | ToolPart | SourcePart | FilePart | DataPart;
|
|
52
|
+
type MessageStatus = "streaming" | "complete" | "error" | "stopped";
|
|
53
|
+
interface Message {
|
|
54
|
+
id: string;
|
|
55
|
+
role: MessageRole;
|
|
56
|
+
parts: MessagePart[];
|
|
57
|
+
status?: MessageStatus;
|
|
58
|
+
createdAt?: string;
|
|
59
|
+
/** The message this one replaces or follows, for branches between versions. */
|
|
60
|
+
parentId?: string;
|
|
61
|
+
metadata?: Record<string, unknown>;
|
|
62
|
+
}
|
|
63
|
+
interface Thread {
|
|
64
|
+
id: string;
|
|
65
|
+
title?: string;
|
|
66
|
+
messages: Message[];
|
|
67
|
+
updatedAt?: string;
|
|
68
|
+
}
|
|
69
|
+
/** Converts a provider's message format into the neutral shape. */
|
|
70
|
+
type MessageAdapter<Input> = (input: Input) => Message;
|
|
71
|
+
/**
|
|
72
|
+
* The thread component is stateless. Storage and history belong to the app,
|
|
73
|
+
* through this small interface.
|
|
74
|
+
*/
|
|
75
|
+
interface ThreadStore {
|
|
76
|
+
load(threadId: string): Promise<Thread | null>;
|
|
77
|
+
save(thread: Thread): Promise<void>;
|
|
78
|
+
list?(): Promise<Array<Pick<Thread, "id" | "title" | "updatedAt">>>;
|
|
79
|
+
delete?(threadId: string): Promise<void>;
|
|
80
|
+
}
|
|
81
|
+
/** The text of a message: its text parts, joined. Reasoning and tool output are left out. */
|
|
82
|
+
declare function messageText(message: Message): string;
|
|
83
|
+
/** Tool calls that are waiting for a human decision. */
|
|
84
|
+
declare function pendingApprovals(message: Message): ToolPart[];
|
|
85
|
+
|
|
86
|
+
export { messageText, pendingApprovals };
|
|
87
|
+
export type { DataPart, FilePart, Message, MessageAdapter, MessagePart, MessageRole, MessageStatus, ReasoningPart, SourcePart, TextPart, Thread, ThreadStore, ToolPart, ToolState };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
function messageText(message) {
|
|
3
|
+
return message.parts.filter((part) => part.type === "text").map((part) => part.text).join("");
|
|
4
|
+
}
|
|
5
|
+
function pendingApprovals(message) {
|
|
6
|
+
return message.parts.filter(
|
|
7
|
+
(part) => part.type === "tool" && part.state === "needs-approval"
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export { messageText, pendingApprovals };
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";AAgGO,SAAS,YAAY,OAAA,EAA0B;AACpD,EAAA,OAAO,QAAQ,KAAA,CACZ,MAAA,CAAO,CAAC,IAAA,KAA2B,KAAK,IAAA,KAAS,MAAM,CAAA,CACvD,GAAA,CAAI,CAAC,IAAA,KAAS,IAAA,CAAK,IAAI,CAAA,CACvB,KAAK,EAAE,CAAA;AACZ;AAGO,SAAS,iBAAiB,OAAA,EAA8B;AAC7D,EAAA,OAAO,QAAQ,KAAA,CAAM,MAAA;AAAA,IACnB,CAAC,IAAA,KAA2B,IAAA,CAAK,IAAA,KAAS,MAAA,IAAU,KAAK,KAAA,KAAU;AAAA,GACrE;AACF","file":"index.js","sourcesContent":["/**\r\n * The neutral message shape (spec section 6). Components read typed parts and\r\n * never import a provider SDK; adapters convert provider formats into this\r\n * shape.\r\n */\r\n\r\nexport type MessageRole = \"user\" | \"assistant\" | \"system\";\r\n\r\nexport interface TextPart {\r\n type: \"text\";\r\n text: string;\r\n}\r\n\r\nexport interface ReasoningPart {\r\n type: \"reasoning\";\r\n text: string;\r\n /** How long the model thought, for the \"Thought for 4s\" line. */\r\n durationMs?: number;\r\n}\r\n\r\nexport type ToolState = \"queued\" | \"running\" | \"succeeded\" | \"failed\" | \"needs-approval\";\r\n\r\nexport interface ToolPart {\r\n type: \"tool\";\r\n id: string;\r\n name: string;\r\n state: ToolState;\r\n input?: unknown;\r\n output?: unknown;\r\n /** A human-readable cause when `state` is `failed`. */\r\n error?: string;\r\n durationMs?: number;\r\n}\r\n\r\nexport interface SourcePart {\r\n type: \"source\";\r\n id: string;\r\n title: string;\r\n url: string;\r\n /** Shown in the source list next to the title and domain. */\r\n snippet?: string;\r\n}\r\n\r\nexport interface FilePart {\r\n type: \"file\";\r\n name: string;\r\n mediaType: string;\r\n url: string;\r\n size?: number;\r\n}\r\n\r\n/** Structured data a component can render, for example an artifact or a chart spec. */\r\nexport interface DataPart {\r\n type: \"data\";\r\n /** Identifies the shape of `data`, such as `chart` or `diagram`. */\r\n kind: string;\r\n data: unknown;\r\n}\r\n\r\nexport type MessagePart = TextPart | ReasoningPart | ToolPart | SourcePart | FilePart | DataPart;\r\n\r\nexport type MessageStatus = \"streaming\" | \"complete\" | \"error\" | \"stopped\";\r\n\r\nexport interface Message {\r\n id: string;\r\n role: MessageRole;\r\n parts: MessagePart[];\r\n status?: MessageStatus;\r\n createdAt?: string;\r\n /** The message this one replaces or follows, for branches between versions. */\r\n parentId?: string;\r\n metadata?: Record<string, unknown>;\r\n}\r\n\r\nexport interface Thread {\r\n id: string;\r\n title?: string;\r\n messages: Message[];\r\n updatedAt?: string;\r\n}\r\n\r\n/** Converts a provider's message format into the neutral shape. */\r\nexport type MessageAdapter<Input> = (input: Input) => Message;\r\n\r\n/**\r\n * The thread component is stateless. Storage and history belong to the app,\r\n * through this small interface.\r\n */\r\nexport interface ThreadStore {\r\n load(threadId: string): Promise<Thread | null>;\r\n save(thread: Thread): Promise<void>;\r\n list?(): Promise<Array<Pick<Thread, \"id\" | \"title\" | \"updatedAt\">>>;\r\n delete?(threadId: string): Promise<void>;\r\n}\r\n\r\n/** The text of a message: its text parts, joined. Reasoning and tool output are left out. */\r\nexport function messageText(message: Message): string {\r\n return message.parts\r\n .filter((part): part is TextPart => part.type === \"text\")\r\n .map((part) => part.text)\r\n .join(\"\");\r\n}\r\n\r\n/** Tool calls that are waiting for a human decision. */\r\nexport function pendingApprovals(message: Message): ToolPart[] {\r\n return message.parts.filter(\r\n (part): part is ToolPart => part.type === \"tool\" && part.state === \"needs-approval\",\r\n );\r\n}\r\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@x12i/ai",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Neutral message shape and store contracts for the Unified UI Kit AI chat set. Components and provider adapters are planned.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/x12i/unified-ui-kit.git",
|
|
9
|
+
"directory": "packages/ai"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/x12i/unified-ui-kit/tree/main/packages/ai#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/x12i/unified-ui-kit/issues"
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"README.md"
|
|
20
|
+
],
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"default": "./dist/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./package.json": "./package.json"
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsup",
|
|
33
|
+
"typecheck": "tsc --noEmit",
|
|
34
|
+
"lint": "eslint .",
|
|
35
|
+
"test": "vitest run --passWithNoTests"
|
|
36
|
+
}
|
|
6
37
|
}
|