@ai-matrx/content-ir-react 0.14.0 → 0.15.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/dist/react.d.cts CHANGED
@@ -1,9 +1,9 @@
1
- import { c as KindDefinitionSource, C as ContentIrHost } from './host-types-BpmKg07p.cjs';
1
+ import { c as KindDefinitionSource, C as ContentIrHost } from './host-types-DVIaaGR_.cjs';
2
2
  import { d as ComponentResolutionSource } from './component-resolution.types-C1MzCf2s.cjs';
3
3
  import * as react from 'react';
4
4
  import react__default, { ReactNode } from 'react';
5
5
  import '@ai-matrx/content-ir';
6
- import './directive-host-DLp5QFI2.cjs';
6
+ import './directive-host-DJfF35FD.cjs';
7
7
 
8
8
  /**
9
9
  * The two registries this hook watches. Passed explicitly by a host whose
package/dist/react.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { c as KindDefinitionSource, C as ContentIrHost } from './host-types-DHKFg06S.js';
1
+ import { c as KindDefinitionSource, C as ContentIrHost } from './host-types-9NfBeqrG.js';
2
2
  import { d as ComponentResolutionSource } from './component-resolution.types-C1MzCf2s.js';
3
3
  import * as react from 'react';
4
4
  import react__default, { ReactNode } from 'react';
5
5
  import '@ai-matrx/content-ir';
6
- import './directive-host-DLp5QFI2.js';
6
+ import './directive-host-DJfF35FD.js';
7
7
 
8
8
  /**
9
9
  * The two registries this hook watches. Passed explicitly by a host whose
package/dist/react.js CHANGED
@@ -10,6 +10,16 @@ import { createContext as createContext2, useContext as useContext2, useMemo } f
10
10
  import { createContext, useContext } from "react";
11
11
  import { jsx } from "react/jsx-runtime";
12
12
  var DirectiveHostContext = createContext(null);
13
+ var DirectiveScopeContext = createContext({});
14
+ function DirectiveScopeProvider({
15
+ conversationId,
16
+ children
17
+ }) {
18
+ return /* @__PURE__ */ jsx(DirectiveScopeContext.Provider, { value: { conversationId: conversationId ?? null }, children });
19
+ }
20
+ function useDirectiveScope() {
21
+ return useContext(DirectiveScopeContext);
22
+ }
13
23
  var EMPTY_HOST = {};
14
24
  function useDirectiveHost() {
15
25
  return useContext(DirectiveHostContext) ?? EMPTY_HOST;
@@ -208,6 +218,10 @@ var MaximizeIcon = (p) => /* @__PURE__ */ jsxs(Svg, { ...p, children: [
208
218
  /* @__PURE__ */ jsx3("line", { x1: "3", x2: "10", y1: "21", y2: "14" })
209
219
  ] });
210
220
  var LoaderIcon = (p) => /* @__PURE__ */ jsx3(Svg, { ...p, children: /* @__PURE__ */ jsx3("path", { d: "M21 12a9 9 0 1 1-6.219-8.56" }) });
221
+ var RotateCcwIcon = (p) => /* @__PURE__ */ jsxs(Svg, { ...p, children: [
222
+ /* @__PURE__ */ jsx3("path", { d: "M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8" }),
223
+ /* @__PURE__ */ jsx3("path", { d: "M3 3v5h5" })
224
+ ] });
211
225
  var CheckCircleIcon = (p) => /* @__PURE__ */ jsxs(Svg, { ...p, children: [
212
226
  /* @__PURE__ */ jsx3("circle", { cx: "12", cy: "12", r: "10" }),
213
227
  /* @__PURE__ */ jsx3("path", { d: "m9 12 2 2 4-4" })
@@ -243,6 +257,8 @@ function ApplyDirectiveButton({
243
257
  onApplied
244
258
  }) {
245
259
  const host = useDirectiveHost();
260
+ const scope = useDirectiveScope();
261
+ const conversationId = scope.conversationId || void 0;
246
262
  const items = directive.items;
247
263
  const readsLedger = !!host.applyState && !!host.confirm && directive.parsed.executes && items.length > 0;
248
264
  const [state, setState] = useState(
@@ -251,17 +267,19 @@ function ApplyDirectiveButton({
251
267
  const [elapsed, setElapsed] = useState(0);
252
268
  const startedAt = useRef(null);
253
269
  const nounText = nounLabel(directive.noun, host.nouns);
254
- const shellKey = readsLedger ? JSON.stringify([directive.slug, items]) : "";
270
+ const shellKey = readsLedger ? JSON.stringify([directive.slug, items, conversationId ?? null]) : "";
255
271
  const read = host.applyState;
256
272
  const report = host.reportError;
257
273
  useEffect(() => {
258
274
  if (!shellKey || !read) return;
259
- const [slug, shellItems] = JSON.parse(shellKey);
275
+ const [slug, shellItems, inConversation] = JSON.parse(shellKey);
276
+ const shell = { __kind: slug, items: shellItems };
277
+ if (inConversation) shell.conversationId = inConversation;
260
278
  let live = true;
261
279
  let polls = 0;
262
280
  let timer = null;
263
281
  const ask = () => {
264
- read({ __kind: slug, items: shellItems }).then((answer) => {
282
+ read(shell).then((answer) => {
265
283
  if (!live) return;
266
284
  if (answer.state === "applied") {
267
285
  setState(
@@ -307,8 +325,9 @@ function ApplyDirectiveButton({
307
325
  if (!directive.parsed.executes) return null;
308
326
  const confirm = host.confirm;
309
327
  if (!confirm) return null;
310
- async function handleApply() {
328
+ async function handleApply(again = false) {
311
329
  if (!confirm) return;
330
+ const before = state;
312
331
  if (host.ask) {
313
332
  setState({ status: "asking" });
314
333
  let ok = false;
@@ -316,7 +335,8 @@ function ApplyDirectiveButton({
316
335
  ok = await host.ask({
317
336
  directive,
318
337
  items,
319
- nounLabel: nounText
338
+ nounLabel: nounText,
339
+ ...again ? { again: true } : {}
320
340
  });
321
341
  } catch (error) {
322
342
  setState({
@@ -326,14 +346,17 @@ function ApplyDirectiveButton({
326
346
  return;
327
347
  }
328
348
  if (!ok) {
329
- setState({ status: "idle" });
349
+ setState(again ? before : { status: "idle" });
330
350
  return;
331
351
  }
332
352
  }
333
353
  setElapsed(0);
334
354
  setState({ status: "applying" });
335
355
  try {
336
- const result = await confirm({ __kind: directive.slug, items });
356
+ const shell = { __kind: directive.slug, items };
357
+ if (conversationId) shell.conversationId = conversationId;
358
+ if (again) shell.force = true;
359
+ const result = await confirm(shell);
337
360
  setState({
338
361
  status: "applied",
339
362
  applied: result.applied,
@@ -370,7 +393,20 @@ function ApplyDirectiveButton({
370
393
  fallback: recordFallbackName(label2, record.id),
371
394
  context: "applied",
372
395
  trashed
373
- }) }, `${record.noun}:${record.id}`))
396
+ }) }, `${record.noun}:${record.id}`)),
397
+ /* @__PURE__ */ jsxs2(
398
+ "button",
399
+ {
400
+ type: "button",
401
+ onClick: () => void handleApply(!bad),
402
+ className: "inline-flex items-center gap-1 rounded px-1 py-0.5 text-muted-foreground hover:bg-accent hover:text-accent-foreground",
403
+ "data-apply-action": bad ? "retry" : "run-again",
404
+ children: [
405
+ /* @__PURE__ */ jsx4(RotateCcwIcon, { className: "h-3 w-3" }),
406
+ bad ? "Retry" : "Run again"
407
+ ]
408
+ }
409
+ )
374
410
  ]
375
411
  }
376
412
  );
@@ -654,7 +690,11 @@ function isWholeJson(content) {
654
690
  return false;
655
691
  }
656
692
  }
657
- function DirectiveRender({ content, className, streaming }) {
693
+ function DirectiveRender({ conversationId, ...props }) {
694
+ if (conversationId === void 0) return /* @__PURE__ */ jsx8(DirectiveRenderInner, { ...props });
695
+ return /* @__PURE__ */ jsx8(DirectiveScopeProvider, { conversationId, children: /* @__PURE__ */ jsx8(DirectiveRenderInner, { ...props }) });
696
+ }
697
+ function DirectiveRenderInner({ content, className, streaming }) {
658
698
  const host = useDirectiveHost();
659
699
  const directive = tryDecodeDirectiveContent(content, (message) => {
660
700
  const line = `[kind-directives] ${message}`;