@locusgraph/loop 0.4.0 → 0.5.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
CHANGED
|
@@ -33,6 +33,6 @@ import { Chat, Composer, Turn } from "@locusgraph/loop";
|
|
|
33
33
|
| Memory | `Cite`, `Sources`, `Recall`, `Memorized` |
|
|
34
34
|
| Cost | `Context`, `Cost`, `CostSteps`, `ModelPicker` |
|
|
35
35
|
|
|
36
|
-
`Turn` renders reasoning, tool and source parts with `Thinking`, `Tool` and `Sources`; pass `renderReasoning`, `renderTool` or `renderSources` to replace them. A tool part in the `approval-requested` state is where `Approval` goes: wire its `onApprove` and `onDeny` to the AI SDK's tool approval response.
|
|
36
|
+
`Turn` renders reasoning, tool and source parts with `Thinking`, `Tool` and `Sources`; pass `renderReasoning`, `renderTool` or `renderSources` to replace them. Data parts (`data-*`, such as a json-render `data-spec`) render only through `renderData`; without it they are skipped. A tool part in the `approval-requested` state is where `Approval` goes: wire its `onApprove` and `onDeny` to the AI SDK's tool approval response.
|
|
37
37
|
|
|
38
38
|
Approvals follow one rule: tools that only read run without asking; tools that write, pay, send or delete pause and show exactly what is being approved, with stronger warnings for destructive ones. Money is integer micro-USD, formatted with `@locusgraph/utils`.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { FilePart, MessagePart, ReasoningPart, SourceUrlPart, TextPart, ToolPart } from "../../types.js";
|
|
1
|
+
import type { DataPart, FilePart, MessagePart, ReasoningPart, SourceUrlPart, TextPart, ToolPart } from "../../types.js";
|
|
2
2
|
export type PartSegment = {
|
|
3
3
|
kind: "text";
|
|
4
4
|
key: string;
|
|
@@ -11,6 +11,10 @@ export type PartSegment = {
|
|
|
11
11
|
kind: "tool";
|
|
12
12
|
key: string;
|
|
13
13
|
part: ToolPart;
|
|
14
|
+
} | {
|
|
15
|
+
kind: "data";
|
|
16
|
+
key: string;
|
|
17
|
+
part: DataPart;
|
|
14
18
|
} | {
|
|
15
19
|
kind: "files";
|
|
16
20
|
key: string;
|
|
@@ -22,4 +26,5 @@ export type PartSegment = {
|
|
|
22
26
|
firstIndex: number;
|
|
23
27
|
};
|
|
24
28
|
export declare function isToolPart(part: MessagePart): part is ToolPart;
|
|
29
|
+
export declare function isDataPart(part: MessagePart): part is DataPart;
|
|
25
30
|
export declare function groupParts(parts: MessagePart[]): PartSegment[];
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export function isToolPart(part) {
|
|
2
2
|
return part.type === "dynamic-tool" || part.type.startsWith("tool-");
|
|
3
3
|
}
|
|
4
|
+
export function isDataPart(part) {
|
|
5
|
+
return part.type.startsWith("data-");
|
|
6
|
+
}
|
|
4
7
|
function appendToRun(segments, kind, part, key, firstIndex = 1) {
|
|
5
8
|
const previous = segments.at(-1);
|
|
6
9
|
if (previous?.kind === kind) {
|
|
@@ -46,6 +49,12 @@ export function groupParts(parts) {
|
|
|
46
49
|
key: part.toolCallId,
|
|
47
50
|
part
|
|
48
51
|
});
|
|
52
|
+
} else if (isDataPart(part)) {
|
|
53
|
+
segments.push({
|
|
54
|
+
kind: "data",
|
|
55
|
+
key: part.id ?? key,
|
|
56
|
+
part
|
|
57
|
+
});
|
|
49
58
|
}
|
|
50
59
|
});
|
|
51
60
|
return segments;
|
package/dist/chat/turn/turn.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type * as React from "react";
|
|
2
|
-
import type { AgentMessage, ReasoningPart, SourceUrlPart, ToolPart } from "../../types.js";
|
|
2
|
+
import type { AgentMessage, DataPart, ReasoningPart, SourceUrlPart, ToolPart } from "../../types.js";
|
|
3
3
|
export type TurnProps = Omit<React.ComponentProps<"div">, "children"> & {
|
|
4
4
|
message: AgentMessage;
|
|
5
5
|
avatar?: React.ReactNode;
|
|
@@ -7,5 +7,6 @@ export type TurnProps = Omit<React.ComponentProps<"div">, "children"> & {
|
|
|
7
7
|
renderReasoning?: (part: ReasoningPart) => React.ReactNode;
|
|
8
8
|
renderTool?: (part: ToolPart) => React.ReactNode;
|
|
9
9
|
renderSources?: (parts: SourceUrlPart[]) => React.ReactNode;
|
|
10
|
+
renderData?: (part: DataPart) => React.ReactNode;
|
|
10
11
|
};
|
|
11
|
-
export declare function Turn({ message, avatar, footer, renderReasoning, renderTool, renderSources, className, ...props }: TurnProps): React.JSX.Element;
|
|
12
|
+
export declare function Turn({ message, avatar, footer, renderReasoning, renderTool, renderSources, renderData, className, ...props }: TurnProps): React.JSX.Element;
|
package/dist/chat/turn/turn.js
CHANGED
|
@@ -61,6 +61,8 @@ function renderSegment(segment, isUser, renderers) {
|
|
|
61
61
|
sources: segment.parts,
|
|
62
62
|
firstIndex: segment.firstIndex
|
|
63
63
|
});
|
|
64
|
+
case "data":
|
|
65
|
+
return renderers.renderData?.(segment.part);
|
|
64
66
|
case "files":
|
|
65
67
|
return /*#__PURE__*/_jsx(Files, {
|
|
66
68
|
items: segment.parts.map(fileFromFilePart),
|
|
@@ -75,6 +77,7 @@ export function Turn({
|
|
|
75
77
|
renderReasoning,
|
|
76
78
|
renderTool,
|
|
77
79
|
renderSources,
|
|
80
|
+
renderData,
|
|
78
81
|
className,
|
|
79
82
|
...props
|
|
80
83
|
}) {
|
|
@@ -82,8 +85,10 @@ export function Turn({
|
|
|
82
85
|
const renderers = {
|
|
83
86
|
renderReasoning,
|
|
84
87
|
renderTool,
|
|
85
|
-
renderSources
|
|
88
|
+
renderSources,
|
|
89
|
+
renderData
|
|
86
90
|
};
|
|
91
|
+
const segments = groupParts(message.parts).filter(segment => segment.kind !== "data" || renderData);
|
|
87
92
|
return /*#__PURE__*/_jsxs(MessageRow, {
|
|
88
93
|
"data-role": message.role,
|
|
89
94
|
align: isUser ? "end" : "start",
|
|
@@ -96,7 +101,7 @@ export function Turn({
|
|
|
96
101
|
children: avatar
|
|
97
102
|
}), /*#__PURE__*/_jsxs(MessageContent, {
|
|
98
103
|
className: cn("gap-4", isUser && "items-end gap-2"),
|
|
99
|
-
children: [
|
|
104
|
+
children: [segments.map((segment, position) => /*#__PURE__*/_jsx("div", {
|
|
100
105
|
"data-slot": "message-part",
|
|
101
106
|
"data-kind": segment.kind,
|
|
102
107
|
"data-follows-line": followsLine(segments, position) || undefined,
|
package/dist/types.d.ts
CHANGED
|
@@ -33,7 +33,12 @@ export type FilePart = {
|
|
|
33
33
|
url: string;
|
|
34
34
|
filename?: string;
|
|
35
35
|
};
|
|
36
|
-
export type
|
|
36
|
+
export type DataPart = {
|
|
37
|
+
type: `data-${string}`;
|
|
38
|
+
id?: string;
|
|
39
|
+
data: unknown;
|
|
40
|
+
};
|
|
41
|
+
export type MessagePart = TextPart | ReasoningPart | ToolPart | SourceUrlPart | FilePart | DataPart;
|
|
37
42
|
export type AgentMessage = {
|
|
38
43
|
id: string;
|
|
39
44
|
role: AgentRole;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@locusgraph/loop",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Agent components for LocusGraph apps: chat, agent steps, human-in-the-loop approvals, memory and cost. Takes Vercel AI SDK UIMessage parts; never calls a model.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"provenance": true
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"@locusgraph/components": "^0.
|
|
32
|
+
"@locusgraph/components": "^0.5.0",
|
|
33
33
|
"react": "^19.2.0",
|
|
34
34
|
"react-dom": "^19.2.0"
|
|
35
35
|
},
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"shiki": "^4.5.0"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"@locusgraph/components": "0.
|
|
46
|
+
"@locusgraph/components": "0.5.0",
|
|
47
47
|
"@locusgraph/config": "0.1.1",
|
|
48
48
|
"@types/node": "^22.0.0",
|
|
49
49
|
"@types/react": "^19.2.0",
|