@ai-matrx/chat 0.3.11 → 0.3.19

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 (129) hide show
  1. package/CHANGELOG.md +83 -0
  2. package/dist/agent-copy/export.d.ts +10 -2
  3. package/dist/agent-copy/export.js +3 -2
  4. package/dist/agents/components/agent-widgets/chat-assistant/CompactAssistantInput.js +1 -1
  5. package/dist/agents/components/debug/SandboxFileViewer.js +1 -3
  6. package/dist/agents/components/inputs/AgentVariablesInline.js +1 -1
  7. package/dist/agents/components/inputs/smart-input/AgentTextarea.js +1 -1
  8. package/dist/agents/components/inputs/smart-input/InputActionButtons.js +1 -1
  9. package/dist/agents/components/inputs/smart-input/composer/ComposerAgentPeek.js +6 -6
  10. package/dist/agents/components/messages-display/TranscriptIntegrityCopyButton.js +4 -4
  11. package/dist/agents/components/messages-display/user/UserActionBar.js +3 -18
  12. package/dist/agents/components/run/AgentRunHeader.js +1 -2
  13. package/dist/agents/components/shared/AgentConversationColumn.js +1 -1
  14. package/dist/agents/components/shared/AgentHeader.js +1 -2
  15. package/dist/agents/components/shared/AgentHeaderMobile.js +1 -2
  16. package/dist/agents/components/working-document/DocumentLinkPicker.d.ts +1 -1
  17. package/dist/agents/components/working-document/WorkingDocumentPanel.js +1 -1
  18. package/dist/agents/components/working-document/documents-workspace/DocumentsListRail.js +2 -2
  19. package/dist/agents/components/working-document/documents-workspace/DocumentsWorkspace.js +2 -2
  20. package/dist/agents/hooks/useInstanceInputUndoRedo.d.ts +1 -1
  21. package/dist/agents/hooks/useInstanceInputUndoRedo.js +1 -1
  22. package/dist/agents/hooks/useWorkingDocument.js +7 -6
  23. package/dist/agents/model-registry/model-classes.d.ts +1 -43
  24. package/dist/agents/model-registry/model-classes.js +1 -40
  25. package/dist/agents/model-registry/parse.d.ts +1 -88
  26. package/dist/agents/model-registry/parse.js +1 -246
  27. package/dist/agents/prompt-preview/PromptPreviewContent.js +1 -3
  28. package/dist/agents/redux/agent-definition/selectors.d.ts +8 -8
  29. package/dist/agents/redux/execution-system/active-requests/active-requests.selectors.d.ts +14 -0
  30. package/dist/agents/redux/execution-system/active-requests/active-requests.selectors.js +30 -0
  31. package/dist/agents/redux/execution-system/client-capabilities/desktop-native.provider.js +10 -1
  32. package/dist/agents/redux/execution-system/instance-working-document/cx-working-document.service.d.ts +18 -16
  33. package/dist/agents/redux/execution-system/instance-working-document/cx-working-document.service.js +101 -52
  34. package/dist/agents/redux/execution-system/instance-working-document/instance-working-document.slice.d.ts +2 -2
  35. package/dist/agents/redux/execution-system/instance-working-document/instance-working-document.thunks.d.ts +1 -1
  36. package/dist/agents/redux/execution-system/instance-working-document/scratchpad.thunks.d.ts +1 -1
  37. package/dist/agents/redux/execution-system/message-crud/refetch-single-message.thunk.js +5 -0
  38. package/dist/agents/redux/execution-system/thunks/process-stream.js +2 -2
  39. package/dist/agents/redux/execution-system/utils/stream-block-accumulator.d.ts +14 -0
  40. package/dist/agents/redux/execution-system/utils/stream-block-accumulator.js +28 -0
  41. package/dist/agents/utils/platform-keys.d.ts +15 -0
  42. package/dist/agents/utils/platform-keys.js +69 -0
  43. package/dist/context/sources/scopes.d.ts +1 -1
  44. package/dist/cx-chat/components/user-input/ConversationInput.js +1 -1
  45. package/dist/cx-conversation/ConversationInput.js +1 -1
  46. package/dist/host/db-types.d.ts +23242 -23071
  47. package/dist/host/ui-slots.d.ts +50 -64
  48. package/dist/host/ui-slots.js +12 -52
  49. package/dist/public-chat/components/GuidedVariableInputs.js +1 -1
  50. package/dist/public-chat/components/PublicVariableInputs.js +1 -1
  51. package/dist/react.cjs +11 -23
  52. package/dist/react.cjs.map +1 -1
  53. package/dist/react.js +11 -23
  54. package/dist/react.js.map +1 -1
  55. package/dist/surfaces/manifests/_conversation-document.manifest.js +1 -1
  56. package/dist/tool-call-visualization/registry/registry.js +13 -0
  57. package/dist/ui/composer/useTouchOnlyDevice.js +1 -1
  58. package/dist/ui/skills-types.d.ts +1 -275
  59. package/dist/ui/skills-types.js +1 -0
  60. package/dist/voice-agent/components/VoiceDebugPanel.js +1 -3
  61. package/package.json +60 -34
  62. package/dist/agents/components/run/run-sidebar/AgentRunsSidebar.d.ts +0 -15
  63. package/dist/agents/components/run/run-sidebar/AgentRunsSidebar.js +0 -201
  64. package/dist/agents/components/run-controls/AgentExecutionTestModal.d.ts +0 -36
  65. package/dist/agents/components/run-controls/AgentExecutionTestModal.js +0 -440
  66. package/dist/agents/components/run-controls/AgentLauncherSidebarTester.d.ts +0 -6
  67. package/dist/agents/components/run-controls/AgentLauncherSidebarTester.js +0 -127
  68. package/dist/agents/components/run-controls/AgentWidgetInvokerTester.d.ts +0 -6
  69. package/dist/agents/components/run-controls/AgentWidgetInvokerTester.js +0 -84
  70. package/dist/agents/components/run-controls/CreatorRunPanel.d.ts +0 -22
  71. package/dist/agents/components/run-controls/CreatorRunPanel.js +0 -108
  72. package/dist/agents/components/run-controls/CreatorRunTabContent.d.ts +0 -30
  73. package/dist/agents/components/run-controls/CreatorRunTabContent.js +0 -319
  74. package/dist/agents/components/run-controls/PayloadTab.d.ts +0 -5
  75. package/dist/agents/components/run-controls/PayloadTab.js +0 -388
  76. package/dist/agents/components/run-controls/TesterSettingsPanel.d.ts +0 -71
  77. package/dist/agents/components/run-controls/TesterSettingsPanel.js +0 -470
  78. package/dist/agents/components/shared/AgentOptionsMenu.d.ts +0 -8
  79. package/dist/agents/components/shared/AgentOptionsMenu.js +0 -776
  80. package/dist/agents/components/shared/AgentPeekDuplicateButton.d.ts +0 -8
  81. package/dist/agents/components/shared/AgentPeekDuplicateButton.js +0 -66
  82. package/dist/agents/components/shared/AgentSaveStatus.d.ts +0 -7
  83. package/dist/agents/components/shared/AgentSaveStatus.js +0 -128
  84. package/dist/agents/components/shared/AgentSaveTapButton.d.ts +0 -18
  85. package/dist/agents/components/shared/AgentSaveTapButton.js +0 -105
  86. package/dist/agents/components/shared/useAgentSaveAction.d.ts +0 -33
  87. package/dist/agents/components/shared/useAgentSaveAction.js +0 -179
  88. package/dist/agents/components/shell/AgentsListHeader.d.ts +0 -1
  89. package/dist/agents/components/shell/AgentsListHeader.js +0 -69
  90. package/dist/agents/components/undo-history/AgentEditHistory.d.ts +0 -9
  91. package/dist/agents/components/undo-history/AgentEditHistory.js +0 -244
  92. package/dist/agents/components/unused/AgentSharedHeader.d.ts +0 -3
  93. package/dist/agents/components/unused/AgentSharedHeader.js +0 -134
  94. package/dist/agents/components/widgets/AgentWidgetsPage.d.ts +0 -11
  95. package/dist/agents/components/widgets/AgentWidgetsPage.js +0 -571
  96. package/dist/agents/components/widgets/WidgetVariableInputs.d.ts +0 -8
  97. package/dist/agents/components/widgets/WidgetVariableInputs.js +0 -80
  98. package/dist/agents/components/widgets/build-widget-launch.d.ts +0 -70
  99. package/dist/agents/components/widgets/build-widget-launch.js +0 -90
  100. package/dist/agents/hooks/useAgentAutoSave.d.ts +0 -1
  101. package/dist/agents/hooks/useAgentAutoSave.js +0 -127
  102. package/dist/agents/hooks/useAgentBuilderWriteHandlers.d.ts +0 -9
  103. package/dist/agents/hooks/useAgentBuilderWriteHandlers.js +0 -102
  104. package/dist/agents/hooks/useAgentDuplicateFlow.d.ts +0 -25
  105. package/dist/agents/hooks/useAgentDuplicateFlow.js +0 -133
  106. package/dist/agents/hooks/useAgentUndoRedo.d.ts +0 -31
  107. package/dist/agents/hooks/useAgentUndoRedo.js +0 -134
  108. package/dist/agents/hooks/useAgentUsages.d.ts +0 -17
  109. package/dist/agents/hooks/useAgentUsages.js +0 -36
  110. package/dist/agents/hooks/useDriftAlerts.d.ts +0 -11
  111. package/dist/agents/hooks/useDriftAlerts.js +0 -36
  112. package/dist/agents/hooks/useDriftReport.d.ts +0 -20
  113. package/dist/agents/hooks/useDriftReport.js +0 -34
  114. package/dist/agents/lifecycle/useAgentLifecycleActions.d.ts +0 -17
  115. package/dist/agents/lifecycle/useAgentLifecycleActions.js +0 -63
  116. package/dist/agents/message-flags/useMessageFlags.d.ts +0 -8
  117. package/dist/agents/message-flags/useMessageFlags.js +0 -68
  118. package/dist/agents/services/agent-definition-snapshot.service.d.ts +0 -15
  119. package/dist/agents/services/agent-definition-snapshot.service.js +0 -20
  120. package/dist/agents/surface-catalog-profile.d.ts +0 -96
  121. package/dist/agents/surface-catalog-profile.js +0 -79
  122. package/dist/cx-chat/hooks/useAgentBootstrap.d.ts +0 -1
  123. package/dist/cx-chat/hooks/useAgentBootstrap.js +0 -110
  124. package/dist/host/builder-door.d.ts +0 -61
  125. package/dist/host/builder-door.js +0 -25
  126. package/dist/next/lazy/CreatorRunPanel.d.ts +0 -1
  127. package/dist/next/lazy/CreatorRunPanel.js +0 -11
  128. package/dist/ui/composer/composerSubmit.d.ts +0 -50
  129. package/dist/ui/composer/composerSubmit.js +0 -32
@@ -1,70 +0,0 @@
1
- /**
2
- * build-widget-launch — the ONE extractor that turns the widget tester's
3
- * on-screen form into launch options.
4
- *
5
- * `AgentWidgetsPage` is a pure local-state harness: "the on-screen state is
6
- * exactly what ships to `launchAgent`". That promise only holds if there is a
7
- * single builder, so both consumers read it here:
8
- *
9
- * - clicking a display mode → the options actually launched
10
- * - Copy / Copy-for-AI → the SAME options, so the payload is what the
11
- * user sees, never a parallel re-derivation
12
- *
13
- * Pure: no React, no side effects. JSON parse failures come back as the exact
14
- * `error` string the tester renders in its red banner, so the copy payload can
15
- * carry the blocker verbatim instead of silently omitting it.
16
- */
17
- import type { ApiEndpointMode, ManagedAgentOptions, ResultDisplayMode } from "../../types/instance.types.js";
18
- import type { VariablesPanelStyle } from "../inputs/variable-input-variations/variable-input-options.js";
19
- /** Every piece of live tester state the launch options are built from. */
20
- export interface WidgetLaunchState {
21
- variableValues: Record<string, unknown>;
22
- userInput: string;
23
- autoRun: boolean;
24
- showVariablePanel: boolean;
25
- variablesPanelStyle: VariablesPanelStyle;
26
- showPreExecutionGate: boolean;
27
- preExecutionMessage: string;
28
- showDefinitionMessages: boolean;
29
- showDefinitionMessageContent: boolean;
30
- allowChat: boolean;
31
- hideReasoning: boolean;
32
- hideToolResults: boolean;
33
- includeEditorContext: boolean;
34
- editorSelection: string;
35
- editorTextBefore: string;
36
- editorTextAfter: string;
37
- editorContent: string;
38
- editorContext: string;
39
- apiEndpointMode: ApiEndpointMode;
40
- showAutoClearToggle: boolean;
41
- autoClearConversation: boolean;
42
- jsonExtractionEnabled: boolean;
43
- jsonExtractionFuzzy: boolean;
44
- jsonExtractionMaxResults: string;
45
- overridesJson: string;
46
- applicationScopeJson: string;
47
- }
48
- /**
49
- * Launch options minus the two values assigned at click time: `surfaceKey`
50
- * (minted per launch) and `config.displayMode` (the mode the user clicks).
51
- * Everything else is fully determined by what is on screen — which is exactly
52
- * what makes this copyable before any mode is chosen.
53
- */
54
- export type WidgetLaunchDraft = Omit<ManagedAgentOptions, "surfaceKey" | "config"> & {
55
- config: Omit<NonNullable<ManagedAgentOptions["config"]>, "displayMode">;
56
- };
57
- export type WidgetLaunchBuild = {
58
- ok: true;
59
- draft: WidgetLaunchDraft;
60
- } | {
61
- ok: false;
62
- error: string;
63
- };
64
- /** Build the launch draft from live state, or the blocking error verbatim. */
65
- export declare function buildWidgetLaunchDraft(state: WidgetLaunchState): WidgetLaunchBuild;
66
- /** Seal a draft into the options `launchAgent` is called with. */
67
- export declare function sealWidgetLaunchOptions(draft: WidgetLaunchDraft, args: {
68
- surfaceKey: string;
69
- displayMode: ResultDisplayMode;
70
- }): ManagedAgentOptions;
@@ -1,90 +0,0 @@
1
- function buildWidgetLaunchDraft(state) {
2
- let overrides;
3
- if (state.overridesJson.trim()) {
4
- try {
5
- const parsed = JSON.parse(state.overridesJson);
6
- if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
7
- return { ok: false, error: "Overrides must be a JSON object" };
8
- }
9
- overrides = parsed;
10
- } catch (e) {
11
- return {
12
- ok: false,
13
- error: `Overrides JSON: ${e instanceof Error ? e.message : "invalid"}`
14
- };
15
- }
16
- }
17
- const scope = {};
18
- if (state.includeEditorContext) {
19
- if (state.editorSelection) scope.selection = state.editorSelection;
20
- if (state.editorTextBefore) scope.text_before = state.editorTextBefore;
21
- if (state.editorTextAfter) scope.text_after = state.editorTextAfter;
22
- if (state.editorContent) scope.content = state.editorContent;
23
- if (state.editorContext) scope.context = state.editorContext;
24
- }
25
- if (state.applicationScopeJson.trim()) {
26
- try {
27
- const parsed = JSON.parse(state.applicationScopeJson);
28
- if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
29
- return { ok: false, error: "Application scope must be a JSON object" };
30
- }
31
- Object.assign(scope, parsed);
32
- } catch (e) {
33
- return {
34
- ok: false,
35
- error: `Scope JSON: ${e instanceof Error ? e.message : "invalid"}`
36
- };
37
- }
38
- }
39
- const applicationScope = Object.keys(scope).length > 0 ? scope : void 0;
40
- const maxResults = state.jsonExtractionMaxResults.trim() ? Number(state.jsonExtractionMaxResults) : NaN;
41
- const jsonExtraction = state.jsonExtractionEnabled ? {
42
- enabled: true,
43
- ...state.jsonExtractionFuzzy ? { fuzzyOnFinalize: true } : {},
44
- ...Number.isFinite(maxResults) ? { maxResults } : {}
45
- } : void 0;
46
- return {
47
- ok: true,
48
- draft: {
49
- sourceFeature: "agents-other",
50
- apiEndpointMode: state.apiEndpointMode,
51
- autoClearConversation: state.autoClearConversation,
52
- showAutoClearToggle: state.showAutoClearToggle,
53
- ...jsonExtraction ? { jsonExtraction } : {},
54
- config: {
55
- autoRun: state.autoRun,
56
- allowChat: state.allowChat,
57
- showPreExecutionGate: state.showPreExecutionGate,
58
- variablesPanelStyle: state.variablesPanelStyle,
59
- showVariablePanel: state.showVariablePanel,
60
- showDefinitionMessages: state.showDefinitionMessages,
61
- showDefinitionMessageContent: state.showDefinitionMessageContent,
62
- hideReasoning: state.hideReasoning,
63
- hideToolResults: state.hideToolResults,
64
- defaultVariables: state.variableValues,
65
- ...state.preExecutionMessage ? { preExecutionMessage: state.preExecutionMessage } : {},
66
- ...overrides ? { llmOverrides: overrides } : {}
67
- },
68
- runtime: {
69
- // The widget lab is testing the selected agent itself. Only the
70
- // explicit sample/application scope below belongs in the run; never
71
- // auto-adopt the surrounding agent administration page.
72
- surfaceName: null,
73
- ...state.userInput ? { userInput: state.userInput } : {},
74
- ...state.includeEditorContext && state.editorSelection ? { originalText: state.editorSelection } : {},
75
- ...applicationScope ? { applicationScope } : {}
76
- }
77
- }
78
- };
79
- }
80
- function sealWidgetLaunchOptions(draft, args) {
81
- return {
82
- ...draft,
83
- surfaceKey: args.surfaceKey,
84
- config: { ...draft.config, displayMode: args.displayMode }
85
- };
86
- }
87
- export {
88
- buildWidgetLaunchDraft,
89
- sealWidgetLaunchOptions
90
- };
@@ -1 +0,0 @@
1
- export declare function useAgentAutoSave(agentId: string): void;
@@ -1,127 +0,0 @@
1
- "use client";
2
- import { useEffect, useRef } from "react";
3
- import { useAppSelector, useAppDispatch } from "../../store/hooks.js";
4
- import isEqual from "lodash/isEqual";
5
- import {
6
- selectAgentById,
7
- selectAgentFetchStatus,
8
- selectAgentIsReadOnly,
9
- selectAgentAccessResolved
10
- } from "../redux/agent-definition/selectors.js";
11
- import {
12
- resetAllAgentFields,
13
- setAgentField
14
- } from "../redux/agent-definition/slice.js";
15
- import { readField } from "@ai-matrx/agents/field-flags";
16
- import { toast } from "../../host/notify.js";
17
- const STORAGE_PREFIX = "agent-autosave:";
18
- const DEBOUNCE_MS = 2e3;
19
- function useAgentAutoSave(agentId) {
20
- const dispatch = useAppDispatch();
21
- const record = useAppSelector((state) => selectAgentById(state, agentId));
22
- const accessResolved = useAppSelector(
23
- (state) => selectAgentAccessResolved(state, agentId)
24
- );
25
- const isReadOnly = useAppSelector(
26
- (state) => selectAgentIsReadOnly(state, agentId)
27
- );
28
- const fetchStatus = useAppSelector(
29
- (state) => selectAgentFetchStatus(state, agentId)
30
- );
31
- const timerRef = useRef(null);
32
- const pendingRecoveryRef = useRef(null);
33
- const restoredRef = useRef(false);
34
- const skipPersistence = accessResolved && isReadOnly;
35
- useEffect(() => {
36
- pendingRecoveryRef.current = null;
37
- restoredRef.current = false;
38
- const storageKey = `${STORAGE_PREFIX}${agentId}`;
39
- try {
40
- const raw = localStorage.getItem(storageKey);
41
- if (raw) {
42
- const saved = JSON.parse(raw);
43
- if (saved?._dirty) {
44
- const { _dirty: _unused, ...fields } = saved;
45
- pendingRecoveryRef.current = fields;
46
- }
47
- }
48
- } catch {
49
- }
50
- }, [agentId]);
51
- useEffect(() => {
52
- const fields = pendingRecoveryRef.current;
53
- if (!fields || !record || fetchStatus !== "full") return;
54
- pendingRecoveryRef.current = null;
55
- const restored = [];
56
- for (const [field, value] of Object.entries(fields)) {
57
- const key = field;
58
- if (isEqual(readField(record, key), value)) continue;
59
- dispatch(
60
- setAgentField({
61
- id: agentId,
62
- field: key,
63
- value
64
- })
65
- );
66
- restored.push(field);
67
- }
68
- if (restored.length > 0) {
69
- restoredRef.current = true;
70
- toast.info(
71
- `Restored unsaved changes to ${record.name || "this agent"} from this browser (${restored.join(", ")}). Save to keep them, or discard them.`,
72
- {
73
- id: `agent-autosave-restored:${agentId}`,
74
- duration: 2e4,
75
- action: {
76
- label: "Discard",
77
- // Back to the saved agent; the clean-state effect drops the backup.
78
- onClick: () => dispatch(resetAllAgentFields({ id: agentId }))
79
- }
80
- }
81
- );
82
- }
83
- }, [agentId, record, fetchStatus, dispatch]);
84
- useEffect(() => {
85
- if (record?._dirty) restoredRef.current = false;
86
- if (skipPersistence || !record?._dirty) return void 0;
87
- if (timerRef.current) clearTimeout(timerRef.current);
88
- timerRef.current = setTimeout(() => {
89
- const storageKey = `${STORAGE_PREFIX}${agentId}`;
90
- try {
91
- const snapshot = { _dirty: true };
92
- if (record._dirtyFields) {
93
- const fields = new Set(
94
- Object.keys(record._dirtyFields)
95
- );
96
- if (fields.has("modelId") || fields.has("settings")) {
97
- fields.add("modelId");
98
- fields.add("settings");
99
- }
100
- for (const field of fields) {
101
- snapshot[field] = readField(record, field);
102
- }
103
- }
104
- localStorage.setItem(storageKey, JSON.stringify(snapshot));
105
- } catch {
106
- }
107
- }, DEBOUNCE_MS);
108
- return () => {
109
- if (timerRef.current) clearTimeout(timerRef.current);
110
- };
111
- }, [agentId, record, skipPersistence]);
112
- useEffect(() => {
113
- if (record?._dirty !== false) return;
114
- if (pendingRecoveryRef.current || restoredRef.current) {
115
- restoredRef.current = false;
116
- return;
117
- }
118
- const storageKey = `${STORAGE_PREFIX}${agentId}`;
119
- try {
120
- localStorage.removeItem(storageKey);
121
- } catch {
122
- }
123
- }, [agentId, record?._dirty]);
124
- }
125
- export {
126
- useAgentAutoSave
127
- };
@@ -1,9 +0,0 @@
1
- /**
2
- * Returns the `getWriteHandlers` callback for the agent-builder surface.
3
- *
4
- * Reads through the store rather than `useAppSelector` for the same reason
5
- * `useAgentBuilderSurfaceScope` does: the builder must not re-render on every
6
- * keystroke of the agent it is editing, and a handler invoked at apply time
7
- * needs the state as it is THEN, not as it was at the last render.
8
- */
9
- export declare function useAgentBuilderWriteHandlers(agentId: string): () => Record<string, (value: unknown) => void>;
@@ -1,102 +0,0 @@
1
- "use client";
2
- import { useCallback } from "react";
3
- import { useAppDispatch, useAppStore } from "../../store/hooks.js";
4
- import {
5
- selectAgentAccessResolved,
6
- selectAgentById,
7
- selectAgentIsReadOnly,
8
- selectAgentMessages
9
- } from "../redux/agent-definition/selectors.js";
10
- import {
11
- setAgentField,
12
- setAgentMessages
13
- } from "../redux/agent-definition/slice.js";
14
- import { withAgentSystemInstruction } from "../utils/agent-system-instruction.js";
15
- function requireText(value, target) {
16
- if (typeof value !== "string") {
17
- throw new Error(`${target} expects a string value.`);
18
- }
19
- const trimmed = value.trim();
20
- if (!trimmed) {
21
- throw new Error(`${target} expects a non-empty string.`);
22
- }
23
- return trimmed;
24
- }
25
- function requireEditableAgent(state, agentId) {
26
- const record = selectAgentById(state, agentId);
27
- if (!record) {
28
- throw new Error(
29
- "The agent being edited has not finished loading \u2014 try again in a moment."
30
- );
31
- }
32
- if (record.isVersion) {
33
- throw new Error(
34
- "This is a published version snapshot, which is read-only. Open the live agent to change it."
35
- );
36
- }
37
- if (selectAgentAccessResolved(state, agentId) && selectAgentIsReadOnly(state, agentId)) {
38
- throw new Error(
39
- "This agent is shared with you as view-only, so changes cannot be saved here."
40
- );
41
- }
42
- return record;
43
- }
44
- function useAgentBuilderWriteHandlers(agentId) {
45
- const store = useAppStore();
46
- const dispatch = useAppDispatch();
47
- return useCallback(() => {
48
- const patchField = (field, value) => {
49
- requireEditableAgent(store.getState(), agentId);
50
- dispatch(setAgentField({ id: agentId, field, value }));
51
- };
52
- const setSystemInstruction = (text) => {
53
- const state = store.getState();
54
- requireEditableAgent(state, agentId);
55
- const messages = selectAgentMessages(state, agentId);
56
- if (!messages) {
57
- throw new Error(
58
- "The agent's messages have not finished loading \u2014 try again in a moment."
59
- );
60
- }
61
- dispatch(
62
- setAgentMessages({
63
- id: agentId,
64
- messages: withAgentSystemInstruction(messages, text)
65
- })
66
- );
67
- };
68
- return {
69
- system_instruction: (value) => {
70
- setSystemInstruction(requireText(value, "system_instruction"));
71
- },
72
- agent_description: (value) => {
73
- patchField("description", requireText(value, "agent_description"));
74
- },
75
- agent_name: (value) => {
76
- patchField("name", requireText(value, "agent_name"));
77
- },
78
- agent_category: (value) => {
79
- patchField("category", requireText(value, "agent_category"));
80
- },
81
- agent_tags: (value) => {
82
- if (!Array.isArray(value)) {
83
- throw new Error(
84
- "agent_tags expects an array of tag strings (pass [] to clear all tags)."
85
- );
86
- }
87
- const tags = value.map((entry, index) => {
88
- if (typeof entry !== "string" || !entry.trim()) {
89
- throw new Error(
90
- `agent_tags[${index}] must be a non-empty string; got ${JSON.stringify(entry)}.`
91
- );
92
- }
93
- return entry.trim();
94
- });
95
- patchField("tags", tags);
96
- }
97
- };
98
- }, [store, dispatch, agentId]);
99
- }
100
- export {
101
- useAgentBuilderWriteHandlers
102
- };
@@ -1,25 +0,0 @@
1
- interface UseAgentDuplicateFlowOptions {
2
- basePath?: string;
3
- /** Sub-route the copy opens on when the source is not the current page. */
4
- fallbackSuffix?: string;
5
- }
6
- export interface StartDuplicateOptions {
7
- /** Copy this saved version (definition_version id). Omitted = the current agent. */
8
- versionId?: string;
9
- }
10
- /**
11
- * Shared duplicate flow for agent surfaces (options menu, versions tab,
12
- * read-only builder save, floating "create my copy" chip). Returns triggers +
13
- * the one dialog element:
14
- * - `startDuplicate()` copies right away (current agent, or `{ versionId }`).
15
- * - `openChooser()` first asks which version to copy, defaulting to current.
16
- */
17
- export declare function useAgentDuplicateFlow(agentId: string, options?: UseAgentDuplicateFlowOptions): {
18
- readonly startDuplicate: (opts?: StartDuplicateOptions) => Promise<void>;
19
- readonly openChooser: () => Promise<void>;
20
- readonly dialog: import("react").JSX.Element;
21
- readonly isDuplicating: boolean;
22
- /** False in a host that registered no builder door: nothing offers a duplicate (reported once). */
23
- readonly available: boolean;
24
- };
25
- export {};
@@ -1,133 +0,0 @@
1
- "use client";
2
- import { jsx } from "react/jsx-runtime";
3
- import { useCallback, useState } from "react";
4
- import { usePathname } from "../../host/navigation.js";
5
- import { useAppDispatch, useAppSelector } from "../../store/hooks.js";
6
- import { selectAgentById } from "../redux/agent-definition/selectors.js";
7
- import { getBuilderDoor, requireBuilderDoor } from "../../host/builder-door.js";
8
- import { supabase } from "../../host/db.js";
9
- import {
10
- AgentDuplicateOutcomeDialog,
11
- CURRENT_VERSION_CHOICE
12
- } from "../components/shared/AgentDuplicateOutcomeDialog.js";
13
- import { isAdminSystemAgentsContext } from "../components/shared/agent-route-context.js";
14
- import { getUserMessage } from "@ai-matrx/agents/matrx";
15
- import { isOrganizationSelectionCancelled } from "../../host/org.js";
16
- function useAgentDuplicateFlow(agentId, options) {
17
- const dispatch = useAppDispatch();
18
- const pathname = usePathname();
19
- const basePath = options?.basePath ?? "/agents";
20
- const fallbackSuffix = options?.fallbackSuffix ?? "/build";
21
- const agent = useAppSelector((state2) => selectAgentById(state2, agentId));
22
- const [open, setOpen] = useState(false);
23
- const [state, setState] = useState("loading");
24
- const [newAgentId, setNewAgentId] = useState(null);
25
- const [errorMessage, setErrorMessage] = useState("");
26
- const [asSystem, setAsSystem] = useState(false);
27
- const [versions, setVersions] = useState([]);
28
- const [versionsLoading, setVersionsLoading] = useState(false);
29
- const [versionsError, setVersionsError] = useState(null);
30
- const [selected, setSelected] = useState(CURRENT_VERSION_CHOICE);
31
- const newAgent = useAppSelector(
32
- (s) => newAgentId ? selectAgentById(s, newAgentId) : void 0
33
- );
34
- const isAdminContext = isAdminSystemAgentsContext(basePath);
35
- const isBuiltin = agent?.agentType === "builtin";
36
- const newAgentPath = newAgentId ? (() => {
37
- const sourceSegment = `${basePath}/${agentId}`;
38
- const here = pathname && pathname.startsWith(sourceSegment) ? pathname.slice(sourceSegment.length) : fallbackSuffix;
39
- const suffix = /^\/v(\/|$)/.test(here) ? fallbackSuffix : here;
40
- return `${basePath}/${newAgentId}${suffix || fallbackSuffix}`;
41
- })() : null;
42
- const startDuplicate = useCallback(
43
- async (opts) => {
44
- const duplicateAsSystem = isAdminContext && isBuiltin;
45
- setAsSystem(duplicateAsSystem);
46
- setNewAgentId(null);
47
- setErrorMessage("");
48
- setState("loading");
49
- setOpen(true);
50
- try {
51
- const id = await dispatch(
52
- requireBuilderDoor().duplicateAgent({
53
- agentId,
54
- asSystem: duplicateAsSystem,
55
- versionId: opts?.versionId
56
- })
57
- ).unwrap();
58
- setNewAgentId(id);
59
- setState("success");
60
- } catch (err) {
61
- if (isOrganizationSelectionCancelled(err)) {
62
- setOpen(false);
63
- return;
64
- }
65
- setErrorMessage(getUserMessage(err));
66
- setState("error");
67
- }
68
- },
69
- [agentId, dispatch, isAdminContext, isBuiltin]
70
- );
71
- const openChooser = useCallback(async () => {
72
- setSelected(CURRENT_VERSION_CHOICE);
73
- setNewAgentId(null);
74
- setErrorMessage("");
75
- setState("choose");
76
- setOpen(true);
77
- setVersionsLoading(true);
78
- setVersionsError(null);
79
- const { data, error } = await supabase.rpc("agx_get_version_history", {
80
- p_agent_id: agentId,
81
- p_limit: 500,
82
- p_offset: 0
83
- });
84
- setVersionsLoading(false);
85
- if (error) {
86
- setVersions([]);
87
- setVersionsError(error.message);
88
- return;
89
- }
90
- setVersions(
91
- (data ?? []).map((row) => ({
92
- versionId: row.version_id,
93
- versionNumber: row.version_number,
94
- changedAt: row.changed_at,
95
- changeNote: row.change_note ?? null
96
- }))
97
- );
98
- }, [agentId]);
99
- const dialog = /* @__PURE__ */ jsx(
100
- AgentDuplicateOutcomeDialog,
101
- {
102
- open,
103
- onOpenChange: setOpen,
104
- state,
105
- newAgentName: newAgent?.name ?? "",
106
- newAgentPath,
107
- errorMessage,
108
- asSystem,
109
- chooser: {
110
- currentVersion: agent?.version ?? null,
111
- versions,
112
- versionsLoading,
113
- versionsError,
114
- selected,
115
- onSelectedChange: setSelected,
116
- onConfirm: () => void startDuplicate(
117
- selected === CURRENT_VERSION_CHOICE ? void 0 : { versionId: selected }
118
- )
119
- }
120
- }
121
- );
122
- return {
123
- startDuplicate,
124
- openChooser,
125
- dialog,
126
- isDuplicating: open && state === "loading",
127
- /** False in a host that registered no builder door: nothing offers a duplicate (reported once). */
128
- available: getBuilderDoor() !== null
129
- };
130
- }
131
- export {
132
- useAgentDuplicateFlow
133
- };
@@ -1,31 +0,0 @@
1
- export type Platform = "mac" | "windows" | "ios" | "android" | "linux" | "unknown";
2
- export declare function getPlatform(): Platform;
3
- export declare function isMacLike(): boolean;
4
- export declare function isTouchDevice(): boolean;
5
- /**
6
- * Returns a human-readable shortcut hint string for the current platform.
7
- * Examples: "⌘Z" on Mac, "Ctrl+Z" on Windows, "Shake" on iOS.
8
- */
9
- export declare function getUndoShortcutHint(): string;
10
- export declare function getRedoShortcutHint(): string;
11
- interface UseAgentUndoRedoOptions {
12
- agentId: string | null;
13
- /**
14
- * The editing surface this mount owns — the shortcut answers only keys
15
- * pressed inside it. The builder mounts this hook once per message; an
16
- * unscoped listener undid the agent once PER MESSAGE on a single ⌘Z.
17
- */
18
- scope: () => Element | null;
19
- enabled?: boolean;
20
- }
21
- interface UseAgentUndoRedoReturn {
22
- canUndo: boolean;
23
- canRedo: boolean;
24
- undo: () => void;
25
- redo: () => void;
26
- undoHint: string;
27
- redoHint: string;
28
- platform: Platform;
29
- }
30
- export declare function useAgentUndoRedo({ agentId, scope, enabled, }: UseAgentUndoRedoOptions): UseAgentUndoRedoReturn;
31
- export {};