camox 0.38.0 → 0.40.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.
@@ -1,200 +0,0 @@
1
- //#region src/features/agent-chat/agent-chat-labels.ts
2
- const TOOL_LABELS = {
3
- listPages: "List pages",
4
- getPage: "Inspect page",
5
- getBlock: "Inspect block",
6
- getBlocks: "Inspect blocks",
7
- listBlockTypes: "List block types",
8
- describeBlockTypes: "Describe block types",
9
- listLayouts: "List layouts",
10
- createBlock: "Create block",
11
- editBlock: "Edit block",
12
- moveBlock: "Move block",
13
- deleteBlock: "Delete block",
14
- createPage: "Create page",
15
- updatePage: "Update page",
16
- setPageLayout: "Set page layout",
17
- setPageMetaTitle: "Set meta title",
18
- setPageMetaDescription: "Set meta description",
19
- deletePage: "Delete page",
20
- publishPage: "Publish page",
21
- unpublishPage: "Unpublish page",
22
- discardPageChanges: "Discard page changes"
23
- };
24
- function getToolLabel(name) {
25
- return TOOL_LABELS[name] ?? name;
26
- }
27
- function isRecord(value) {
28
- return !!value && typeof value === "object" && !Array.isArray(value);
29
- }
30
- function getNumber(value) {
31
- return typeof value === "number" && Number.isFinite(value) ? value : null;
32
- }
33
- function getString(value) {
34
- return typeof value === "string" && value.trim().length > 0 ? value : null;
35
- }
36
- function getToolCallInput(part) {
37
- const input = part.input;
38
- if (isRecord(input)) return input;
39
- const args = part.arguments;
40
- if (isRecord(args)) return args;
41
- if (typeof args !== "string") return {};
42
- try {
43
- const parsed = JSON.parse(args);
44
- return isRecord(parsed) ? parsed : {};
45
- } catch {
46
- return {};
47
- }
48
- }
49
- function getToolOutput(part) {
50
- if (part.type === "tool-call") return part.output;
51
- if (part.type !== "tool-result") return void 0;
52
- return part.output ?? part.result;
53
- }
54
- function rememberPage(value, maps) {
55
- if (!isRecord(value)) return;
56
- const fullPath = getString(value.fullPath);
57
- if (!fullPath) return;
58
- const id = getNumber(value.id) ?? void 0;
59
- if (id !== void 0) maps.pagesById.set(id, {
60
- id,
61
- fullPath
62
- });
63
- }
64
- function rememberBlock(value, maps) {
65
- if (!isRecord(value)) return;
66
- const id = getNumber(value.id);
67
- if (id === null) return;
68
- const summary = getString(value.summary);
69
- const type = getString(value.type);
70
- const typeTitle = type ? maps.blockTypeTitlesByType.get(type) : null;
71
- const label = summary ?? typeTitle ?? type;
72
- if (label) maps.blockLabelsById.set(id, label);
73
- }
74
- function rememberBlockType(value, maps) {
75
- if (!isRecord(value)) return;
76
- const type = getString(value.type) ?? getString(value.blockId);
77
- const title = getString(value.title);
78
- if (type && title) maps.blockTypeTitlesByType.set(type, title);
79
- }
80
- function rememberToolOutput(part, output, maps) {
81
- if (part.name === "listPages" && Array.isArray(output)) {
82
- output.forEach((page) => rememberPage(page, maps));
83
- return;
84
- }
85
- if ((part.name === "listBlockTypes" || part.name === "describeBlockTypes") && isRecord(output)) {
86
- const blockTypes = output.blockTypes;
87
- if (Array.isArray(blockTypes)) blockTypes.forEach((type) => rememberBlockType(type, maps));
88
- return;
89
- }
90
- if (part.name === "getBlocks" && Array.isArray(output)) {
91
- output.forEach((item) => {
92
- if (isRecord(item)) rememberBlock(item.block, maps);
93
- });
94
- return;
95
- }
96
- if (!isRecord(output)) return;
97
- rememberPage(output.page, maps);
98
- rememberBlock(output.block, maps);
99
- rememberBlock(output, maps);
100
- const blocks = output.blocks;
101
- if (Array.isArray(blocks)) blocks.forEach((block) => rememberBlock(block, maps));
102
- }
103
- function getPageFromInput(input, context) {
104
- const id = getNumber(input.id);
105
- if (id !== null) return context.pagesById.get(id) ?? {
106
- id,
107
- fullPath: `#${id}`
108
- };
109
- const path = getString(input.path);
110
- return path ? { fullPath: path } : null;
111
- }
112
- function formatPageTarget(page, currentPath) {
113
- if (!page) return "page";
114
- if (page.fullPath === currentPath) return "current page";
115
- if (page.fullPath.startsWith("/")) return `${page.fullPath} page`;
116
- return `page ${page.fullPath}`;
117
- }
118
- function formatBlockTarget(id, context) {
119
- if (id === null) return "block";
120
- const label = context.blockLabelsById.get(id);
121
- return label ? `${label} block` : `block #${id}`;
122
- }
123
- function getSourcePrefix(input, runContext) {
124
- return input.source === "live" || runContext.source === "live" ? "live " : "";
125
- }
126
- function getCreatePageTarget(input) {
127
- const pathSegment = getString(input.pathSegment);
128
- const nickname = getString(input.nickname);
129
- if (pathSegment) return `/${pathSegment} page`;
130
- if (nickname) return `${nickname} page`;
131
- return "page";
132
- }
133
- function getBlockTypeTarget(input, context) {
134
- const type = getString(input.type);
135
- if (!type) return "block";
136
- return `${context.blockTypeTitlesByType.get(type) ?? type} block`;
137
- }
138
- function buildAgentChatToolLabelContext(params) {
139
- const maps = {
140
- pagesById: /* @__PURE__ */ new Map(),
141
- blockLabelsById: /* @__PURE__ */ new Map(),
142
- blockTypeTitlesByType: /* @__PURE__ */ new Map()
143
- };
144
- const toolCallsById = /* @__PURE__ */ new Map();
145
- for (const message of params.messages) for (const part of message.parts) {
146
- if (part.type === "tool-call") {
147
- toolCallsById.set(part.id, part);
148
- const output = getToolOutput(part);
149
- if (output !== void 0) rememberToolOutput(part, output, maps);
150
- continue;
151
- }
152
- if (part.type !== "tool-result") continue;
153
- const toolCallId = part.toolCallId;
154
- if (typeof toolCallId !== "string") continue;
155
- const toolCall = toolCallsById.get(toolCallId);
156
- if (!toolCall) continue;
157
- const output = getToolOutput(part);
158
- if (output !== void 0) rememberToolOutput(toolCall, output, maps);
159
- }
160
- return {
161
- currentPath: params.currentPath,
162
- source: params.source,
163
- toolCallContextById: params.toolCallContextById ?? /* @__PURE__ */ new Map(),
164
- pagesById: maps.pagesById,
165
- blockLabelsById: maps.blockLabelsById,
166
- blockTypeTitlesByType: maps.blockTypeTitlesByType
167
- };
168
- }
169
- function getToolCallLabel(part, context) {
170
- const input = getToolCallInput(part);
171
- const runContext = context.toolCallContextById.get(part.id) ?? {
172
- currentPath: context.currentPath,
173
- source: context.source
174
- };
175
- switch (part.name) {
176
- case "getPage": return `Inspect ${getSourcePrefix(input, runContext)}${formatPageTarget(getPageFromInput(input, context), runContext.currentPath)}`;
177
- case "getBlock": return `Inspect ${getSourcePrefix(input, runContext)}${formatBlockTarget(getNumber(input.id), context)}`;
178
- case "getBlocks": {
179
- const ids = Array.isArray(input.ids) ? input.ids : [];
180
- return `Inspect ${getSourcePrefix(input, runContext)}${ids.length || "multiple"} blocks`;
181
- }
182
- case "createBlock": return `Create ${getBlockTypeTarget(input, context)}`;
183
- case "editBlock": return `Edit ${formatBlockTarget(getNumber(input.id), context)}`;
184
- case "moveBlock": return `Move ${formatBlockTarget(getNumber(input.id), context)}`;
185
- case "deleteBlock": return `Delete ${formatBlockTarget(getNumber(input.id), context)}`;
186
- case "createPage": return `Create ${getCreatePageTarget(input)}`;
187
- case "updatePage": return `Update ${formatPageTarget(getPageFromInput(input, context), runContext.currentPath)}`;
188
- case "setPageLayout": return `Set layout for ${formatPageTarget(getPageFromInput(input, context), runContext.currentPath)}`;
189
- case "setPageMetaTitle": return `Set meta title for ${formatPageTarget(getPageFromInput(input, context), runContext.currentPath)}`;
190
- case "setPageMetaDescription": return `Set meta description for ${formatPageTarget(getPageFromInput(input, context), runContext.currentPath)}`;
191
- case "deletePage": return `Delete ${formatPageTarget(getPageFromInput(input, context), runContext.currentPath)}`;
192
- case "publishPage": return `Publish ${formatPageTarget(getPageFromInput(input, context), runContext.currentPath)}`;
193
- case "unpublishPage": return `Unpublish ${formatPageTarget(getPageFromInput(input, context), runContext.currentPath)}`;
194
- case "discardPageChanges": return `Discard changes to ${formatPageTarget(getPageFromInput(input, context), runContext.currentPath)}`;
195
- default: return getToolLabel(part.name);
196
- }
197
- }
198
-
199
- //#endregion
200
- export { buildAgentChatToolLabelContext, getToolCallLabel };
@@ -1,172 +0,0 @@
1
- import { useLocation } from "../../navigation/navigation.js";
2
- import { useProjectSlug } from "../../../lib/auth.js";
3
- import { projectQueries } from "../../../lib/queries.js";
4
- import { previewStore } from "../../preview/previewStore.js";
5
- import { AgentChatThread } from "./AgentChatThread.js";
6
- import { c } from "react/compiler-runtime";
7
- import { useQuery } from "@tanstack/react-query";
8
- import * as React from "react";
9
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
10
- import { useSelector } from "@xstate/store-react";
11
- import { Button } from "@camox/ui/button";
12
- import { Lock, Plus, X } from "lucide-react";
13
- import { Alert, AlertDescription, AlertTitle } from "@camox/ui/alert";
14
-
15
- //#region src/features/agent-chat/components/AgentChatSidebar.tsx
16
- const AgentChatSidebar = () => {
17
- const $ = c(20);
18
- if ($[0] !== "0cd25adb7637781b4a21ccdb22bb01ea44234579d0d340e1a833455c0506f264") {
19
- for (let $i = 0; $i < 20; $i += 1) $[$i] = Symbol.for("react.memo_cache_sentinel");
20
- $[0] = "0cd25adb7637781b4a21ccdb22bb01ea44234579d0d340e1a833455c0506f264";
21
- }
22
- const previewSource = useSelector(previewStore, _temp);
23
- const pageScaffoldContext = useSelector(previewStore, _temp2);
24
- const [agentChatKey, setAgentChatKey] = React.useState(0);
25
- const [composerFocusKey, setComposerFocusKey] = React.useState(0);
26
- const { pathname } = useLocation();
27
- const projectSlug = useProjectSlug();
28
- let t0;
29
- if ($[1] !== projectSlug) {
30
- t0 = projectQueries.getBySlug(projectSlug);
31
- $[1] = projectSlug;
32
- $[2] = t0;
33
- } else t0 = $[2];
34
- const { data: project } = useQuery(t0);
35
- const isLiveSource = previewSource === "live";
36
- let t1;
37
- let t2;
38
- if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
39
- t1 = () => {
40
- setComposerFocusKey(_temp3);
41
- };
42
- t2 = [];
43
- $[3] = t1;
44
- $[4] = t2;
45
- } else {
46
- t1 = $[3];
47
- t2 = $[4];
48
- }
49
- React.useEffect(t1, t2);
50
- let t3;
51
- if ($[5] === Symbol.for("react.memo_cache_sentinel")) {
52
- t3 = /* @__PURE__ */ jsx("p", {
53
- className: "flex-1 text-base font-semibold",
54
- children: "Agent Chat"
55
- });
56
- $[5] = t3;
57
- } else t3 = $[5];
58
- let t4;
59
- if ($[6] === Symbol.for("react.memo_cache_sentinel")) {
60
- t4 = /* @__PURE__ */ jsx(Button, {
61
- type: "button",
62
- variant: "ghost",
63
- size: "icon-sm",
64
- "aria-label": "Start a new Agent Chat",
65
- onClick: () => {
66
- previewStore.send({ type: "clearAgentChatPageScaffoldContext" });
67
- setAgentChatKey(_temp4);
68
- setComposerFocusKey(_temp5);
69
- },
70
- children: /* @__PURE__ */ jsx(Plus, { className: "size-4" })
71
- });
72
- $[6] = t4;
73
- } else t4 = $[6];
74
- let t5;
75
- if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
76
- t5 = /* @__PURE__ */ jsxs("div", {
77
- className: "flex items-center gap-1 p-2",
78
- children: [
79
- t3,
80
- t4,
81
- /* @__PURE__ */ jsx(Button, {
82
- type: "button",
83
- variant: "ghost",
84
- size: "icon-sm",
85
- "aria-label": "Close",
86
- onClick: _temp6,
87
- children: /* @__PURE__ */ jsx(X, { className: "size-4" })
88
- })
89
- ]
90
- });
91
- $[7] = t5;
92
- } else t5 = $[7];
93
- let t6;
94
- if ($[8] !== isLiveSource) {
95
- t6 = isLiveSource && /* @__PURE__ */ jsx("div", {
96
- className: "p-2 pb-0",
97
- children: /* @__PURE__ */ jsxs(Alert, { children: [
98
- /* @__PURE__ */ jsx(Lock, { className: "size-4" }),
99
- /* @__PURE__ */ jsx(AlertTitle, { children: "Live Source is read-only" }),
100
- /* @__PURE__ */ jsxs(AlertDescription, {
101
- className: "space-y-3",
102
- children: [/* @__PURE__ */ jsx("p", { children: "Agent Chat can inspect live content, but edits require switching to Draft Source." }), /* @__PURE__ */ jsx(Button, {
103
- type: "button",
104
- size: "sm",
105
- onClick: _temp7,
106
- children: "Switch to draft"
107
- })]
108
- })
109
- ] })
110
- });
111
- $[8] = isLiveSource;
112
- $[9] = t6;
113
- } else t6 = $[9];
114
- let t7;
115
- if ($[10] !== agentChatKey || $[11] !== composerFocusKey || $[12] !== pageScaffoldContext || $[13] !== pathname || $[14] !== previewSource || $[15] !== project) {
116
- t7 = project ? /* @__PURE__ */ jsx(AgentChatThread, {
117
- projectId: project.id,
118
- currentPath: pathname,
119
- source: previewSource,
120
- focusKey: composerFocusKey,
121
- pageScaffoldContext: pageScaffoldContext ?? void 0
122
- }, `${agentChatKey}:${pageScaffoldContext?.id ?? 0}`) : /* @__PURE__ */ jsx("div", {
123
- className: "text-muted-foreground flex flex-1 items-center justify-center p-6 text-sm",
124
- children: "Loading project…"
125
- });
126
- $[10] = agentChatKey;
127
- $[11] = composerFocusKey;
128
- $[12] = pageScaffoldContext;
129
- $[13] = pathname;
130
- $[14] = previewSource;
131
- $[15] = project;
132
- $[16] = t7;
133
- } else t7 = $[16];
134
- let t8;
135
- if ($[17] !== t6 || $[18] !== t7) {
136
- t8 = /* @__PURE__ */ jsxs(Fragment, { children: [t5, /* @__PURE__ */ jsxs("div", {
137
- className: "flex min-h-0 flex-1 flex-col",
138
- children: [t6, t7]
139
- })] });
140
- $[17] = t6;
141
- $[18] = t7;
142
- $[19] = t8;
143
- } else t8 = $[19];
144
- return t8;
145
- };
146
- function _temp(state) {
147
- return state.context.previewSource;
148
- }
149
- function _temp2(state_0) {
150
- return state_0.context.agentChatPageScaffoldContext;
151
- }
152
- function _temp3(key) {
153
- return key + 1;
154
- }
155
- function _temp4(key_0) {
156
- return key_0 + 1;
157
- }
158
- function _temp5(key_1) {
159
- return key_1 + 1;
160
- }
161
- function _temp6() {
162
- return previewStore.send({ type: "closeAgentChatSidebar" });
163
- }
164
- function _temp7() {
165
- return previewStore.send({
166
- type: "setPreviewSource",
167
- source: "draft"
168
- });
169
- }
170
-
171
- //#endregion
172
- export { AgentChatSidebar };