@ai-matrx/content-ir-react 0.14.0 → 0.15.1
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/CHANGELOG.md +30 -0
- package/dist/{directive-host-DLp5QFI2.d.cts → directive-host-DJfF35FD.d.cts} +39 -9
- package/dist/{directive-host-DLp5QFI2.d.ts → directive-host-DJfF35FD.d.ts} +39 -9
- package/dist/directives.cjs +59 -15
- package/dist/directives.cjs.map +1 -1
- package/dist/directives.d.cts +9 -2
- package/dist/directives.d.ts +9 -2
- package/dist/directives.js +59 -15
- package/dist/directives.js.map +1 -1
- package/dist/{host-types-DHKFg06S.d.ts → host-types-9NfBeqrG.d.ts} +1 -1
- package/dist/{host-types-BpmKg07p.d.cts → host-types-DVIaaGR_.d.cts} +1 -1
- package/dist/host.cjs +1 -0
- package/dist/host.cjs.map +1 -1
- package/dist/host.d.cts +3 -3
- package/dist/host.d.ts +3 -3
- package/dist/host.js +1 -0
- package/dist/host.js.map +1 -1
- package/dist/index.cjs +58 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -3
- package/dist/index.d.ts +10 -3
- package/dist/index.js +58 -14
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +56 -14
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +2 -2
- package/dist/react.d.ts +2 -2
- package/dist/react.js +56 -14
- package/dist/react.js.map +1 -1
- package/dist/{route-Bf-kciHw.d.cts → route-BCtPhF7W.d.cts} +39 -9
- package/dist/{route-ymqupVjr.d.ts → route-DDbgc-ID.d.ts} +39 -9
- package/dist/route.d.cts +1 -1
- package/dist/route.d.ts +1 -1
- package/package.json +3 -3
package/dist/react.cjs
CHANGED
|
@@ -54,6 +54,16 @@ var import_react2 = require("react");
|
|
|
54
54
|
var import_react = require("react");
|
|
55
55
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
56
56
|
var DirectiveHostContext = (0, import_react.createContext)(null);
|
|
57
|
+
var DirectiveScopeContext = (0, import_react.createContext)({});
|
|
58
|
+
function DirectiveScopeProvider({
|
|
59
|
+
conversationId,
|
|
60
|
+
children
|
|
61
|
+
}) {
|
|
62
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DirectiveScopeContext.Provider, { value: { conversationId: conversationId ?? null }, children });
|
|
63
|
+
}
|
|
64
|
+
function useDirectiveScope() {
|
|
65
|
+
return (0, import_react.useContext)(DirectiveScopeContext);
|
|
66
|
+
}
|
|
57
67
|
var EMPTY_HOST = {};
|
|
58
68
|
function useDirectiveHost() {
|
|
59
69
|
return (0, import_react.useContext)(DirectiveHostContext) ?? EMPTY_HOST;
|
|
@@ -248,6 +258,10 @@ var MaximizeIcon = (p) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Svg, { .
|
|
|
248
258
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("line", { x1: "3", x2: "10", y1: "21", y2: "14" })
|
|
249
259
|
] });
|
|
250
260
|
var LoaderIcon = (p) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Svg, { ...p, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M21 12a9 9 0 1 1-6.219-8.56" }) });
|
|
261
|
+
var RotateCcwIcon = (p) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Svg, { ...p, children: [
|
|
262
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8" }),
|
|
263
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M3 3v5h5" })
|
|
264
|
+
] });
|
|
251
265
|
var CheckCircleIcon = (p) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(Svg, { ...p, children: [
|
|
252
266
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("circle", { cx: "12", cy: "12", r: "10" }),
|
|
253
267
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "m9 12 2 2 4-4" })
|
|
@@ -283,6 +297,8 @@ function ApplyDirectiveButton({
|
|
|
283
297
|
onApplied
|
|
284
298
|
}) {
|
|
285
299
|
const host = useDirectiveHost();
|
|
300
|
+
const scope = useDirectiveScope();
|
|
301
|
+
const conversationId = scope.conversationId || void 0;
|
|
286
302
|
const items = directive.items;
|
|
287
303
|
const readsLedger = !!host.applyState && !!host.confirm && directive.parsed.executes && items.length > 0;
|
|
288
304
|
const [state, setState] = (0, import_react4.useState)(
|
|
@@ -291,17 +307,19 @@ function ApplyDirectiveButton({
|
|
|
291
307
|
const [elapsed, setElapsed] = (0, import_react4.useState)(0);
|
|
292
308
|
const startedAt = (0, import_react4.useRef)(null);
|
|
293
309
|
const nounText = (0, import_content_ir.nounLabel)(directive.noun, host.nouns);
|
|
294
|
-
const shellKey = readsLedger ? JSON.stringify([directive.slug, items]) : "";
|
|
310
|
+
const shellKey = readsLedger ? JSON.stringify([directive.slug, items, conversationId ?? null]) : "";
|
|
295
311
|
const read = host.applyState;
|
|
296
312
|
const report = host.reportError;
|
|
297
313
|
(0, import_react4.useEffect)(() => {
|
|
298
314
|
if (!shellKey || !read) return;
|
|
299
|
-
const [slug, shellItems] = JSON.parse(shellKey);
|
|
315
|
+
const [slug, shellItems, inConversation] = JSON.parse(shellKey);
|
|
316
|
+
const shell = { __kind: slug, items: shellItems };
|
|
317
|
+
if (inConversation) shell.conversationId = inConversation;
|
|
300
318
|
let live = true;
|
|
301
319
|
let polls = 0;
|
|
302
320
|
let timer = null;
|
|
303
321
|
const ask = () => {
|
|
304
|
-
read(
|
|
322
|
+
read(shell).then((answer) => {
|
|
305
323
|
if (!live) return;
|
|
306
324
|
if (answer.state === "applied") {
|
|
307
325
|
setState(
|
|
@@ -347,8 +365,9 @@ function ApplyDirectiveButton({
|
|
|
347
365
|
if (!directive.parsed.executes) return null;
|
|
348
366
|
const confirm = host.confirm;
|
|
349
367
|
if (!confirm) return null;
|
|
350
|
-
async function handleApply() {
|
|
368
|
+
async function handleApply(again = false) {
|
|
351
369
|
if (!confirm) return;
|
|
370
|
+
const before = state;
|
|
352
371
|
if (host.ask) {
|
|
353
372
|
setState({ status: "asking" });
|
|
354
373
|
let ok = false;
|
|
@@ -356,7 +375,8 @@ function ApplyDirectiveButton({
|
|
|
356
375
|
ok = await host.ask({
|
|
357
376
|
directive,
|
|
358
377
|
items,
|
|
359
|
-
nounLabel: nounText
|
|
378
|
+
nounLabel: nounText,
|
|
379
|
+
...again ? { again: true } : {}
|
|
360
380
|
});
|
|
361
381
|
} catch (error) {
|
|
362
382
|
setState({
|
|
@@ -366,14 +386,17 @@ function ApplyDirectiveButton({
|
|
|
366
386
|
return;
|
|
367
387
|
}
|
|
368
388
|
if (!ok) {
|
|
369
|
-
setState({ status: "idle" });
|
|
389
|
+
setState(again ? before : { status: "idle" });
|
|
370
390
|
return;
|
|
371
391
|
}
|
|
372
392
|
}
|
|
373
393
|
setElapsed(0);
|
|
374
394
|
setState({ status: "applying" });
|
|
375
395
|
try {
|
|
376
|
-
const
|
|
396
|
+
const shell = { __kind: directive.slug, items };
|
|
397
|
+
if (conversationId) shell.conversationId = conversationId;
|
|
398
|
+
if (again) shell.force = true;
|
|
399
|
+
const result = await confirm(shell);
|
|
377
400
|
setState({
|
|
378
401
|
status: "applied",
|
|
379
402
|
applied: result.applied,
|
|
@@ -397,20 +420,35 @@ function ApplyDirectiveButton({
|
|
|
397
420
|
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
398
421
|
"span",
|
|
399
422
|
{
|
|
400
|
-
className: `
|
|
423
|
+
className: `flex min-w-0 flex-wrap items-center gap-x-2 gap-y-0.5 text-xs ${bad ? "text-destructive" : "text-primary"}`,
|
|
401
424
|
"data-apply-state": "applied",
|
|
402
425
|
children: [
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
426
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "inline-flex min-w-0 items-start gap-1", children: [
|
|
427
|
+
bad ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AlertIcon, { className: "mt-px h-3.5 w-3.5 shrink-0" }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CheckCircleIcon, { className: "mt-px h-3.5 w-3.5 shrink-0" }),
|
|
428
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "min-w-0", children: [
|
|
429
|
+
state.message ?? `Applied ${state.applied}`,
|
|
430
|
+
bad && !state.message ? ` \xB7 ${state.failed} failed` : ""
|
|
431
|
+
] })
|
|
407
432
|
] }),
|
|
408
433
|
records.map((record) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "inline-flex min-w-0 items-center", children: host.renderRecord?.({
|
|
409
434
|
...record,
|
|
410
435
|
fallback: recordFallbackName(label2, record.id),
|
|
411
436
|
context: "applied",
|
|
412
437
|
trashed
|
|
413
|
-
}) }, `${record.noun}:${record.id}`))
|
|
438
|
+
}) }, `${record.noun}:${record.id}`)),
|
|
439
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
440
|
+
"button",
|
|
441
|
+
{
|
|
442
|
+
type: "button",
|
|
443
|
+
onClick: () => void handleApply(!bad),
|
|
444
|
+
className: "inline-flex items-center gap-1 rounded px-1 py-0.5 text-muted-foreground hover:bg-accent hover:text-accent-foreground",
|
|
445
|
+
"data-apply-action": bad ? "retry" : "run-again",
|
|
446
|
+
children: [
|
|
447
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(RotateCcwIcon, { className: "h-3 w-3" }),
|
|
448
|
+
bad ? "Retry" : "Run again"
|
|
449
|
+
]
|
|
450
|
+
}
|
|
451
|
+
)
|
|
414
452
|
]
|
|
415
453
|
}
|
|
416
454
|
);
|
|
@@ -684,7 +722,11 @@ function isWholeJson(content) {
|
|
|
684
722
|
return false;
|
|
685
723
|
}
|
|
686
724
|
}
|
|
687
|
-
function DirectiveRender({
|
|
725
|
+
function DirectiveRender({ conversationId, ...props }) {
|
|
726
|
+
if (conversationId === void 0) return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(DirectiveRenderInner, { ...props });
|
|
727
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(DirectiveScopeProvider, { conversationId, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(DirectiveRenderInner, { ...props }) });
|
|
728
|
+
}
|
|
729
|
+
function DirectiveRenderInner({ content, className, streaming }) {
|
|
688
730
|
const host = useDirectiveHost();
|
|
689
731
|
const directive = (0, import_content_ir6.tryDecodeDirectiveContent)(content, (message) => {
|
|
690
732
|
const line = `[kind-directives] ${message}`;
|