@almadar/ui 5.64.0 → 5.67.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.
Files changed (31) hide show
  1. package/dist/avl/index.cjs +241 -71
  2. package/dist/avl/index.d.cts +10 -2
  3. package/dist/avl/index.d.ts +1 -0
  4. package/dist/avl/index.js +244 -75
  5. package/dist/components/avl/derive-edit-focus.d.ts +8 -0
  6. package/dist/components/core/organisms/ChatBar.d.ts +31 -0
  7. package/dist/components/core/organisms/SubagentTracePanel.d.ts +50 -0
  8. package/dist/components/core/organisms/index.d.ts +3 -0
  9. package/dist/components/core/organisms/trace-edit-focus.d.ts +14 -0
  10. package/dist/components/game/atoms/ChoiceButton.d.ts +7 -1
  11. package/dist/components/game/molecules/HealthPanel.d.ts +3 -0
  12. package/dist/components/game/molecules/IsometricCanvas.d.ts +4 -1
  13. package/dist/components/game/molecules/PowerupSlots.d.ts +3 -0
  14. package/dist/components/game/molecules/TurnPanel.d.ts +3 -0
  15. package/dist/components/game/molecules/index.d.ts +1 -0
  16. package/dist/components/game/molecules/three/index.cjs +6 -6
  17. package/dist/components/game/molecules/three/index.js +6 -6
  18. package/dist/components/game/organisms/HexStrategyBoard.d.ts +37 -0
  19. package/dist/components/game/organisms/index.d.ts +2 -0
  20. package/dist/components/game/organisms/utils/isometric.d.ts +20 -7
  21. package/dist/components/index.cjs +1241 -53
  22. package/dist/components/index.js +1243 -60
  23. package/dist/hooks/index.cjs +94 -0
  24. package/dist/hooks/index.d.ts +1 -0
  25. package/dist/hooks/index.js +95 -2
  26. package/dist/hooks/useAgentTrace.d.ts +85 -0
  27. package/dist/providers/index.cjs +210 -45
  28. package/dist/providers/index.js +213 -48
  29. package/dist/runtime/index.cjs +212 -47
  30. package/dist/runtime/index.js +215 -50
  31. package/package.json +2 -2
@@ -2821,6 +2821,99 @@ function useRenderInterpolation(options = {}) {
2821
2821
  }, []);
2822
2822
  return { onSnapshot, getInterpolated, startLoop };
2823
2823
  }
2824
+ var EMPTY_STATE = {
2825
+ activities: [],
2826
+ subagents: [],
2827
+ coordinatorMessages: [],
2828
+ status: "idle"
2829
+ };
2830
+ function upsertSubagent(subagents, id, patch) {
2831
+ const idx = subagents.findIndex((s) => s.id === id);
2832
+ if (idx === -1) {
2833
+ const next = {
2834
+ id,
2835
+ name: patch.name ?? id,
2836
+ role: patch.role ?? "",
2837
+ status: patch.status ?? "running",
2838
+ task: patch.task ?? "",
2839
+ messages: []
2840
+ };
2841
+ if (patch.orbitalName !== void 0) next.orbitalName = patch.orbitalName;
2842
+ if (patch.parentId !== void 0) next.parentId = patch.parentId;
2843
+ if (patch.durationMs !== void 0) next.durationMs = patch.durationMs;
2844
+ return [...subagents, next];
2845
+ }
2846
+ const merged = { ...subagents[idx] };
2847
+ if (patch.name !== void 0) merged.name = patch.name;
2848
+ if (patch.role !== void 0) merged.role = patch.role;
2849
+ if (patch.orbitalName !== void 0) merged.orbitalName = patch.orbitalName;
2850
+ if (patch.parentId !== void 0) merged.parentId = patch.parentId;
2851
+ if (patch.status !== void 0) merged.status = patch.status;
2852
+ if (patch.task !== void 0) merged.task = patch.task;
2853
+ if (patch.durationMs !== void 0) merged.durationMs = patch.durationMs;
2854
+ const out = subagents.slice();
2855
+ out[idx] = merged;
2856
+ return out;
2857
+ }
2858
+ function appendSubagentMessage(subagents, id, message) {
2859
+ const idx = subagents.findIndex((s) => s.id === id);
2860
+ if (idx === -1) return subagents;
2861
+ const out = subagents.slice();
2862
+ out[idx] = { ...out[idx], messages: [...out[idx].messages, message] };
2863
+ return out;
2864
+ }
2865
+ function setCoordinatorMessage(messages, index, message) {
2866
+ if (index < messages.length) {
2867
+ const out = messages.slice();
2868
+ out[index] = message;
2869
+ return out;
2870
+ }
2871
+ return [...messages, message];
2872
+ }
2873
+ function reduce(state, update) {
2874
+ switch (update.kind) {
2875
+ case "activity":
2876
+ return { ...state, activities: [...state.activities, update.activity] };
2877
+ case "subagent-upsert":
2878
+ return { ...state, subagents: upsertSubagent(state.subagents, update.id, update.subagent) };
2879
+ case "subagent-message":
2880
+ return { ...state, subagents: appendSubagentMessage(state.subagents, update.id, update.message) };
2881
+ case "coordinator-message":
2882
+ return {
2883
+ ...state,
2884
+ coordinatorMessages: setCoordinatorMessage(state.coordinatorMessages, update.index, update.message)
2885
+ };
2886
+ case "status":
2887
+ return { ...state, status: update.status };
2888
+ case "reset":
2889
+ return EMPTY_STATE;
2890
+ }
2891
+ }
2892
+ function traceReducer(state, action) {
2893
+ if (action.type === "apply") return reduce(state, action.update);
2894
+ return action.updates.reduce(reduce, state);
2895
+ }
2896
+ function useAgentTrace() {
2897
+ const [state, dispatch] = react.useReducer(traceReducer, EMPTY_STATE);
2898
+ const apply = react.useCallback((update) => {
2899
+ dispatch({ type: "apply", update });
2900
+ }, []);
2901
+ const applyAll = react.useCallback((updates) => {
2902
+ dispatch({ type: "applyAll", updates });
2903
+ }, []);
2904
+ const reset = react.useCallback(() => {
2905
+ dispatch({ type: "apply", update: { kind: "reset" } });
2906
+ }, []);
2907
+ return {
2908
+ activities: state.activities,
2909
+ subagents: state.subagents,
2910
+ coordinatorMessages: state.coordinatorMessages,
2911
+ status: state.status,
2912
+ apply,
2913
+ applyAll,
2914
+ reset
2915
+ };
2916
+ }
2824
2917
  var API_BASE = typeof process !== "undefined" && process.env?.VITE_API_URL ? process.env.VITE_API_URL : "http://localhost:3000";
2825
2918
  function getUserId() {
2826
2919
  return localStorage.getItem("userId") || "anonymous";
@@ -2912,6 +3005,7 @@ exports.spawnEntity = spawnEntity;
2912
3005
  exports.updateEntity = updateEntity;
2913
3006
  exports.updateSingleton = updateSingleton;
2914
3007
  exports.useAgentChat = useAgentChat;
3008
+ exports.useAgentTrace = useAgentTrace;
2915
3009
  exports.useAuthContext = useAuthContext;
2916
3010
  exports.useCanvasGestures = useCanvasGestures;
2917
3011
  exports.useCompile = useCompile;
@@ -29,4 +29,5 @@ export { useTapReveal, type TapRevealOptions, type TapRevealResult, } from './us
29
29
  export { useDraggable, ALMADAR_DND_MIME, type DraggablePayload, type UseDraggableOptions, type UseDraggableResult, } from './useDraggable';
30
30
  export { useDropZone, type UseDropZoneOptions, type UseDropZoneResult, } from './useDropZone';
31
31
  export { useRenderInterpolation, type Positioned, type RenderInterpolationOptions, type RenderInterpolationHandle, } from './useRenderInterpolation';
32
+ export { useAgentTrace, type UseAgentTraceResult, type AgentTraceState, type TraceStatus, type TraceUpdate, type SubagentUpsert, } from './useAgentTrace';
32
33
  export { useGitHubStatus, useConnectGitHub, useDisconnectGitHub, useGitHubRepos, useGitHubRepo, useGitHubBranches, type GitHubStatus, type GitHubRepo, } from './useGitHub';
@@ -1,4 +1,4 @@
1
- import { createContext, useCallback, useState, useEffect, useMemo, useContext, useRef, useSyncExternalStore } from 'react';
1
+ import { createContext, useCallback, useState, useEffect, useMemo, useContext, useRef, useSyncExternalStore, useReducer } from 'react';
2
2
  import { createLogger } from '@almadar/logger';
3
3
  import { EventBusContext, useTraitScope } from '@almadar/ui/providers';
4
4
  import { useQuery, useQueryClient, useMutation } from '@tanstack/react-query';
@@ -2819,6 +2819,99 @@ function useRenderInterpolation(options = {}) {
2819
2819
  }, []);
2820
2820
  return { onSnapshot, getInterpolated, startLoop };
2821
2821
  }
2822
+ var EMPTY_STATE = {
2823
+ activities: [],
2824
+ subagents: [],
2825
+ coordinatorMessages: [],
2826
+ status: "idle"
2827
+ };
2828
+ function upsertSubagent(subagents, id, patch) {
2829
+ const idx = subagents.findIndex((s) => s.id === id);
2830
+ if (idx === -1) {
2831
+ const next = {
2832
+ id,
2833
+ name: patch.name ?? id,
2834
+ role: patch.role ?? "",
2835
+ status: patch.status ?? "running",
2836
+ task: patch.task ?? "",
2837
+ messages: []
2838
+ };
2839
+ if (patch.orbitalName !== void 0) next.orbitalName = patch.orbitalName;
2840
+ if (patch.parentId !== void 0) next.parentId = patch.parentId;
2841
+ if (patch.durationMs !== void 0) next.durationMs = patch.durationMs;
2842
+ return [...subagents, next];
2843
+ }
2844
+ const merged = { ...subagents[idx] };
2845
+ if (patch.name !== void 0) merged.name = patch.name;
2846
+ if (patch.role !== void 0) merged.role = patch.role;
2847
+ if (patch.orbitalName !== void 0) merged.orbitalName = patch.orbitalName;
2848
+ if (patch.parentId !== void 0) merged.parentId = patch.parentId;
2849
+ if (patch.status !== void 0) merged.status = patch.status;
2850
+ if (patch.task !== void 0) merged.task = patch.task;
2851
+ if (patch.durationMs !== void 0) merged.durationMs = patch.durationMs;
2852
+ const out = subagents.slice();
2853
+ out[idx] = merged;
2854
+ return out;
2855
+ }
2856
+ function appendSubagentMessage(subagents, id, message) {
2857
+ const idx = subagents.findIndex((s) => s.id === id);
2858
+ if (idx === -1) return subagents;
2859
+ const out = subagents.slice();
2860
+ out[idx] = { ...out[idx], messages: [...out[idx].messages, message] };
2861
+ return out;
2862
+ }
2863
+ function setCoordinatorMessage(messages, index, message) {
2864
+ if (index < messages.length) {
2865
+ const out = messages.slice();
2866
+ out[index] = message;
2867
+ return out;
2868
+ }
2869
+ return [...messages, message];
2870
+ }
2871
+ function reduce(state, update) {
2872
+ switch (update.kind) {
2873
+ case "activity":
2874
+ return { ...state, activities: [...state.activities, update.activity] };
2875
+ case "subagent-upsert":
2876
+ return { ...state, subagents: upsertSubagent(state.subagents, update.id, update.subagent) };
2877
+ case "subagent-message":
2878
+ return { ...state, subagents: appendSubagentMessage(state.subagents, update.id, update.message) };
2879
+ case "coordinator-message":
2880
+ return {
2881
+ ...state,
2882
+ coordinatorMessages: setCoordinatorMessage(state.coordinatorMessages, update.index, update.message)
2883
+ };
2884
+ case "status":
2885
+ return { ...state, status: update.status };
2886
+ case "reset":
2887
+ return EMPTY_STATE;
2888
+ }
2889
+ }
2890
+ function traceReducer(state, action) {
2891
+ if (action.type === "apply") return reduce(state, action.update);
2892
+ return action.updates.reduce(reduce, state);
2893
+ }
2894
+ function useAgentTrace() {
2895
+ const [state, dispatch] = useReducer(traceReducer, EMPTY_STATE);
2896
+ const apply = useCallback((update) => {
2897
+ dispatch({ type: "apply", update });
2898
+ }, []);
2899
+ const applyAll = useCallback((updates) => {
2900
+ dispatch({ type: "applyAll", updates });
2901
+ }, []);
2902
+ const reset = useCallback(() => {
2903
+ dispatch({ type: "apply", update: { kind: "reset" } });
2904
+ }, []);
2905
+ return {
2906
+ activities: state.activities,
2907
+ subagents: state.subagents,
2908
+ coordinatorMessages: state.coordinatorMessages,
2909
+ status: state.status,
2910
+ apply,
2911
+ applyAll,
2912
+ reset
2913
+ };
2914
+ }
2822
2915
  var API_BASE = typeof process !== "undefined" && process.env?.VITE_API_URL ? process.env.VITE_API_URL : "http://localhost:3000";
2823
2916
  function getUserId() {
2824
2917
  return localStorage.getItem("userId") || "anonymous";
@@ -2895,4 +2988,4 @@ function useGitHubBranches(owner, repo, enabled = true) {
2895
2988
  });
2896
2989
  }
2897
2990
 
2898
- export { ALMADAR_DND_MIME, DEFAULT_SLOTS, I18nProvider, clearEntities, createTranslate, getAllEntities, getByType, getEntity, getSingleton, parseQueryBinding, removeEntity, spawnEntity, updateEntity, updateSingleton, useAgentChat, useAuthContext, useCanvasGestures, useCompile, useConnectGitHub, useDeepAgentGeneration, useDisconnectGitHub, useDragReorder, useDraggable, useDropZone, useEmitEvent, useEntities, useEntitiesByType, useEntity as useEntityById, useEventBus, useEventListener, useExtensions, useFileEditor, useFileSystem, useGitHubBranches, useGitHubRepo, useGitHubRepos, useGitHubStatus, useInfiniteScroll, useInput, useLongPress, useOrbitalHistory, usePhysics, usePinchZoom, usePlayer, usePreview, usePullToRefresh, useQuerySingleton, useRenderInterpolation, useSingletonEntity, useSwipeGesture, useTapReveal, useTraitListens, useTranslate, useUIEvents, useUISlotManager, useValidation };
2991
+ export { ALMADAR_DND_MIME, DEFAULT_SLOTS, I18nProvider, clearEntities, createTranslate, getAllEntities, getByType, getEntity, getSingleton, parseQueryBinding, removeEntity, spawnEntity, updateEntity, updateSingleton, useAgentChat, useAgentTrace, useAuthContext, useCanvasGestures, useCompile, useConnectGitHub, useDeepAgentGeneration, useDisconnectGitHub, useDragReorder, useDraggable, useDropZone, useEmitEvent, useEntities, useEntitiesByType, useEntity as useEntityById, useEventBus, useEventListener, useExtensions, useFileEditor, useFileSystem, useGitHubBranches, useGitHubRepo, useGitHubRepos, useGitHubStatus, useInfiniteScroll, useInput, useLongPress, useOrbitalHistory, usePhysics, usePinchZoom, usePlayer, usePreview, usePullToRefresh, useQuerySingleton, useRenderInterpolation, useSingletonEntity, useSwipeGesture, useTapReveal, useTraitListens, useTranslate, useUIEvents, useUISlotManager, useValidation };
@@ -0,0 +1,85 @@
1
+ import type { TraceActivity, TraceSubagent, TraceSubagentMessage, TraceChatMessage } from '@almadar/core';
2
+ /** Coarse run status surfaced by the trace UI (drives ChatBar's action button). */
3
+ export type TraceStatus = 'idle' | 'running' | 'paused' | 'complete' | 'error';
4
+ /** The accumulated view-model the trace components render. */
5
+ export interface AgentTraceState {
6
+ activities: TraceActivity[];
7
+ subagents: TraceSubagent[];
8
+ coordinatorMessages: TraceChatMessage[];
9
+ status: TraceStatus;
10
+ }
11
+ /**
12
+ * A pre-mapped update the runner feeds in. Each variant is a view-model delta —
13
+ * no raw SSE/transport shapes. Subagents upsert by `id`; coordinator messages
14
+ * upsert by index (the runner owns ordering); activities append.
15
+ */
16
+ export type TraceUpdate =
17
+ /** Append one already-mapped activity to the page-level stream. */
18
+ {
19
+ kind: 'activity';
20
+ activity: TraceActivity;
21
+ }
22
+ /**
23
+ * Upsert a subagent by `id`. A partial patch merges into the existing record
24
+ * (status/duration/task changes); a full record inserts when `id` is new.
25
+ */
26
+ | {
27
+ kind: 'subagent-upsert';
28
+ id: string;
29
+ subagent: SubagentUpsert;
30
+ }
31
+ /** Append a progress message to a known subagent's running log. */
32
+ | {
33
+ kind: 'subagent-message';
34
+ id: string;
35
+ message: TraceSubagentMessage;
36
+ }
37
+ /**
38
+ * Set a coordinator message at `index`. The runner emits messages in order;
39
+ * a known index replaces (e.g. streaming content grew), a new index appends.
40
+ */
41
+ | {
42
+ kind: 'coordinator-message';
43
+ index: number;
44
+ message: TraceChatMessage;
45
+ }
46
+ /** Set the coarse run status. */
47
+ | {
48
+ kind: 'status';
49
+ status: TraceStatus;
50
+ }
51
+ /** Reset the whole view-model (new turn). */
52
+ | {
53
+ kind: 'reset';
54
+ };
55
+ /**
56
+ * A subagent upsert payload: every field optional except `name`/`role`/`task`
57
+ * are required only when the id is new. Partial patches merge into the existing
58
+ * record; that's why the fields are all optional here and the reducer fills
59
+ * defaults on first insert.
60
+ */
61
+ export interface SubagentUpsert {
62
+ name?: string;
63
+ role?: string;
64
+ orbitalName?: string;
65
+ parentId?: string;
66
+ status?: TraceSubagent['status'];
67
+ task?: string;
68
+ durationMs?: number;
69
+ }
70
+ /** What the hook returns: the state plus an `apply` to feed it updates. */
71
+ export interface UseAgentTraceResult extends AgentTraceState {
72
+ /** Apply one pre-mapped view-model update (from the runner). */
73
+ apply: (update: TraceUpdate) => void;
74
+ /** Apply a batch of updates in order (single render). */
75
+ applyAll: (updates: readonly TraceUpdate[]) => void;
76
+ /** Reset to the empty view-model. */
77
+ reset: () => void;
78
+ }
79
+ /**
80
+ * Accumulate agent-trace view-model from pre-mapped updates.
81
+ *
82
+ * The consumer maps SSE/runner events to `TraceUpdate`s upstream and calls
83
+ * `apply`/`applyAll`; this hook holds nothing but the accumulated render state.
84
+ */
85
+ export declare function useAgentTrace(): UseAgentTraceResult;