@stigmer/react 3.12.4 → 3.12.6
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/agent/AgentDetailView.js +2 -2
- package/agent/AgentDetailView.js.map +1 -1
- package/agent/index.d.ts +0 -1
- package/agent/index.d.ts.map +1 -1
- package/agent/index.js +0 -1
- package/agent/index.js.map +1 -1
- package/agent/useUpdateAgent.d.ts +3 -3
- package/agent/useUpdateAgent.js +3 -3
- package/agent-instance/AgentInstanceDetailPanel.d.ts.map +1 -1
- package/agent-instance/AgentInstanceDetailPanel.js +5 -7
- package/agent-instance/AgentInstanceDetailPanel.js.map +1 -1
- package/agent-instance/useUpdateAgentInstance.d.ts +1 -1
- package/agent-instance/useUpdateAgentInstance.js +1 -1
- package/attachment/AttachmentChipList.js +16 -6
- package/attachment/AttachmentChipList.js.map +1 -1
- package/attachment/index.d.ts +1 -1
- package/attachment/index.d.ts.map +1 -1
- package/attachment/index.js.map +1 -1
- package/attachment/useAttachments.d.ts +51 -8
- package/attachment/useAttachments.d.ts.map +1 -1
- package/attachment/useAttachments.js +74 -3
- package/attachment/useAttachments.js.map +1 -1
- package/channel/AgentChannelsPanel.d.ts.map +1 -1
- package/channel/AgentChannelsPanel.js +10 -5
- package/channel/AgentChannelsPanel.js.map +1 -1
- package/channel/ChannelRunConfigDialog.d.ts +51 -0
- package/channel/ChannelRunConfigDialog.d.ts.map +1 -0
- package/channel/ChannelRunConfigDialog.js +121 -0
- package/channel/ChannelRunConfigDialog.js.map +1 -0
- package/channel/index.d.ts +2 -0
- package/channel/index.d.ts.map +1 -1
- package/channel/index.js +1 -0
- package/channel/index.js.map +1 -1
- package/channel/useSaveAgentChannel.d.ts.map +1 -1
- package/channel/useSaveAgentChannel.js +6 -3
- package/channel/useSaveAgentChannel.js.map +1 -1
- package/channel-app/ChannelAppDetailPanel.js +9 -9
- package/channel-app/ChannelAppDetailPanel.js.map +1 -1
- package/composer/ComposerToolbar.d.ts +6 -1
- package/composer/ComposerToolbar.d.ts.map +1 -1
- package/composer/ComposerToolbar.js +2 -2
- package/composer/ComposerToolbar.js.map +1 -1
- package/composer/SessionComposer.d.ts +9 -0
- package/composer/SessionComposer.d.ts.map +1 -1
- package/composer/SessionComposer.js +39 -13
- package/composer/SessionComposer.js.map +1 -1
- package/conversation/ConversationComposer.d.ts +19 -3
- package/conversation/ConversationComposer.d.ts.map +1 -1
- package/conversation/ConversationComposer.js +4 -4
- package/conversation/ConversationComposer.js.map +1 -1
- package/conversation/ConversationTemplatePickerDialog.d.ts +63 -0
- package/conversation/ConversationTemplatePickerDialog.d.ts.map +1 -0
- package/conversation/ConversationTemplatePickerDialog.js +151 -0
- package/conversation/ConversationTemplatePickerDialog.js.map +1 -0
- package/conversation/ConversationsWorkbench.d.ts.map +1 -1
- package/conversation/ConversationsWorkbench.js +16 -5
- package/conversation/ConversationsWorkbench.js.map +1 -1
- package/conversation/index.d.ts +3 -1
- package/conversation/index.d.ts.map +1 -1
- package/conversation/index.js +1 -0
- package/conversation/index.js.map +1 -1
- package/conversation/useConversationParticipation.d.ts +41 -4
- package/conversation/useConversationParticipation.d.ts.map +1 -1
- package/conversation/useConversationParticipation.js +13 -2
- package/conversation/useConversationParticipation.js.map +1 -1
- package/cursor-accounts/CursorAccountsConsole.d.ts.map +1 -1
- package/cursor-accounts/CursorAccountsConsole.js +12 -3
- package/cursor-accounts/CursorAccountsConsole.js.map +1 -1
- package/cursor-accounts/cursor-account-coverage.d.ts +30 -1
- package/cursor-accounts/cursor-account-coverage.d.ts.map +1 -1
- package/cursor-accounts/cursor-account-coverage.js +21 -0
- package/cursor-accounts/cursor-account-coverage.js.map +1 -1
- package/execution/useCreateAgentExecution.d.ts +15 -0
- package/execution/useCreateAgentExecution.d.ts.map +1 -1
- package/execution/useCreateAgentExecution.js +5 -0
- package/execution/useCreateAgentExecution.js.map +1 -1
- package/identity-account/AccountPreferencesPanel.d.ts +36 -0
- package/identity-account/AccountPreferencesPanel.d.ts.map +1 -0
- package/identity-account/AccountPreferencesPanel.js +202 -0
- package/identity-account/AccountPreferencesPanel.js.map +1 -0
- package/identity-account/index.d.ts +8 -0
- package/identity-account/index.d.ts.map +1 -1
- package/identity-account/index.js +4 -0
- package/identity-account/index.js.map +1 -1
- package/identity-account/useAccountExecutionDefaults.d.ts +36 -0
- package/identity-account/useAccountExecutionDefaults.d.ts.map +1 -0
- package/identity-account/useAccountExecutionDefaults.js +46 -0
- package/identity-account/useAccountExecutionDefaults.js.map +1 -0
- package/identity-account/useMyIdentityAccount.d.ts +55 -0
- package/identity-account/useMyIdentityAccount.d.ts.map +1 -0
- package/identity-account/useMyIdentityAccount.js +37 -0
- package/identity-account/useMyIdentityAccount.js.map +1 -0
- package/identity-account/useUpdateIdentityAccount.d.ts +42 -0
- package/identity-account/useUpdateIdentityAccount.d.ts.map +1 -0
- package/identity-account/useUpdateIdentityAccount.js +53 -0
- package/identity-account/useUpdateIdentityAccount.js.map +1 -0
- package/identity-provider/IdentityProviderDetailPanel.d.ts.map +1 -1
- package/identity-provider/IdentityProviderDetailPanel.js +16 -15
- package/identity-provider/IdentityProviderDetailPanel.js.map +1 -1
- package/index.d.ts +15 -13
- package/index.d.ts.map +1 -1
- package/index.js +11 -8
- package/index.js.map +1 -1
- package/internal/StandingContextField.d.ts +37 -0
- package/internal/StandingContextField.d.ts.map +1 -0
- package/internal/StandingContextField.js +24 -0
- package/internal/StandingContextField.js.map +1 -0
- package/library/InstanceVisibilitySelector.d.ts.map +1 -1
- package/library/InstanceVisibilitySelector.js +9 -2
- package/library/InstanceVisibilitySelector.js.map +1 -1
- package/library/ResourceVisibilityControl.d.ts +13 -3
- package/library/ResourceVisibilityControl.d.ts.map +1 -1
- package/library/ResourceVisibilityControl.js +33 -5
- package/library/ResourceVisibilityControl.js.map +1 -1
- package/library/VisibilityOptionRow.d.ts +6 -0
- package/library/VisibilityOptionRow.d.ts.map +1 -1
- package/library/VisibilityOptionRow.js +11 -1
- package/library/VisibilityOptionRow.js.map +1 -1
- package/library/VisibilitySelector.d.ts.map +1 -1
- package/library/VisibilitySelector.js +14 -2
- package/library/VisibilitySelector.js.map +1 -1
- package/library/index.d.ts +4 -2
- package/library/index.d.ts.map +1 -1
- package/library/index.js +2 -1
- package/library/index.js.map +1 -1
- package/library/useCanSetPublicVisibility.d.ts +30 -0
- package/library/useCanSetPublicVisibility.d.ts.map +1 -0
- package/library/useCanSetPublicVisibility.js +41 -0
- package/library/useCanSetPublicVisibility.js.map +1 -0
- package/library/visibilityLevels.d.ts +32 -1
- package/library/visibilityLevels.d.ts.map +1 -1
- package/library/visibilityLevels.js +34 -14
- package/library/visibilityLevels.js.map +1 -1
- package/mcp-server/McpServerDetailView.js +2 -2
- package/mcp-server/McpServerDetailView.js.map +1 -1
- package/mcp-server/index.d.ts +0 -1
- package/mcp-server/index.d.ts.map +1 -1
- package/mcp-server/index.js +0 -1
- package/mcp-server/index.js.map +1 -1
- package/mcp-server/internal/definitionDrift.d.ts +14 -12
- package/mcp-server/internal/definitionDrift.d.ts.map +1 -1
- package/mcp-server/internal/definitionDrift.js +22 -19
- package/mcp-server/internal/definitionDrift.js.map +1 -1
- package/mcp-server/useMcpServerConnect.d.ts +8 -5
- package/mcp-server/useMcpServerConnect.d.ts.map +1 -1
- package/mcp-server/useMcpServerConnect.js +2 -1
- package/mcp-server/useMcpServerConnect.js.map +1 -1
- package/mcp-server/useMcpServerOAuthConnect.d.ts.map +1 -1
- package/mcp-server/useMcpServerOAuthConnect.js +7 -2
- package/mcp-server/useMcpServerOAuthConnect.js.map +1 -1
- package/mcp-server/useUpdateMcpServer.d.ts +3 -3
- package/mcp-server/useUpdateMcpServer.js +3 -3
- package/models/ModelSelector.d.ts +33 -1
- package/models/ModelSelector.d.ts.map +1 -1
- package/models/ModelSelector.js +37 -4
- package/models/ModelSelector.js.map +1 -1
- package/models/index.d.ts +2 -0
- package/models/index.d.ts.map +1 -1
- package/models/index.js +1 -0
- package/models/index.js.map +1 -1
- package/models/registry.d.ts +16 -0
- package/models/registry.d.ts.map +1 -1
- package/models/registry.js +13 -0
- package/models/registry.js.map +1 -1
- package/models/thinking-mode.d.ts +27 -0
- package/models/thinking-mode.d.ts.map +1 -0
- package/models/thinking-mode.js +32 -0
- package/models/thinking-mode.js.map +1 -0
- package/oauth-app/CreateOAuthAppForm.d.ts +2 -2
- package/oauth-app/CreateOAuthAppForm.d.ts.map +1 -1
- package/oauth-app/CreateOAuthAppForm.js +13 -4
- package/oauth-app/CreateOAuthAppForm.js.map +1 -1
- package/oauth-app/OAuthAppDetailPanel.d.ts.map +1 -1
- package/oauth-app/OAuthAppDetailPanel.js +50 -22
- package/oauth-app/OAuthAppDetailPanel.js.map +1 -1
- package/organization/OrgPreferencesPanel.d.ts +32 -0
- package/organization/OrgPreferencesPanel.d.ts.map +1 -0
- package/organization/OrgPreferencesPanel.js +90 -0
- package/organization/OrgPreferencesPanel.js.map +1 -0
- package/organization/OrgProfilePanel.d.ts.map +1 -1
- package/organization/OrgProfilePanel.js +5 -4
- package/organization/OrgProfilePanel.js.map +1 -1
- package/organization/index.d.ts +2 -0
- package/organization/index.d.ts.map +1 -1
- package/organization/index.js +1 -0
- package/organization/index.js.map +1 -1
- package/package.json +4 -4
- package/platform-client/PlatformClientDetailPanel.d.ts.map +1 -1
- package/platform-client/PlatformClientDetailPanel.js +12 -13
- package/platform-client/PlatformClientDetailPanel.js.map +1 -1
- package/schedule/ScheduleDetailView.d.ts.map +1 -1
- package/schedule/ScheduleDetailView.js +21 -10
- package/schedule/ScheduleDetailView.js.map +1 -1
- package/schedule/ScheduleForm.d.ts.map +1 -1
- package/schedule/ScheduleForm.js +13 -3
- package/schedule/ScheduleForm.js.map +1 -1
- package/session/NewSessionViewer.d.ts +10 -1
- package/session/NewSessionViewer.d.ts.map +1 -1
- package/session/NewSessionViewer.js +2 -1
- package/session/NewSessionViewer.js.map +1 -1
- package/session/run-config.d.ts +9 -0
- package/session/run-config.d.ts.map +1 -1
- package/session/run-config.js +5 -0
- package/session/run-config.js.map +1 -1
- package/session/useNewSessionFlow.d.ts +27 -1
- package/session/useNewSessionFlow.d.ts.map +1 -1
- package/session/useNewSessionFlow.js +51 -8
- package/session/useNewSessionFlow.js.map +1 -1
- package/session/useSessionConversation.d.ts +12 -1
- package/session/useSessionConversation.d.ts.map +1 -1
- package/session/useSessionConversation.js +15 -24
- package/session/useSessionConversation.js.map +1 -1
- package/session/useSessionPageFlow.d.ts.map +1 -1
- package/session/useSessionPageFlow.js +14 -10
- package/session/useSessionPageFlow.js.map +1 -1
- package/session/useUpdateSession.d.ts +18 -24
- package/session/useUpdateSession.d.ts.map +1 -1
- package/session/useUpdateSession.js +18 -24
- package/session/useUpdateSession.js.map +1 -1
- package/settings/AccountPreferencesSection.d.ts +3 -0
- package/settings/AccountPreferencesSection.d.ts.map +1 -0
- package/settings/AccountPreferencesSection.js +10 -0
- package/settings/AccountPreferencesSection.js.map +1 -0
- package/settings/OrgPreferencesSection.d.ts +3 -0
- package/settings/OrgPreferencesSection.d.ts.map +1 -0
- package/settings/OrgPreferencesSection.js +13 -0
- package/settings/OrgPreferencesSection.js.map +1 -0
- package/settings/index.d.ts +2 -0
- package/settings/index.d.ts.map +1 -1
- package/settings/index.js +2 -0
- package/settings/index.js.map +1 -1
- package/settings/settings-nav.d.ts.map +1 -1
- package/settings/settings-nav.js +17 -1
- package/settings/settings-nav.js.map +1 -1
- package/src/agent/AgentDetailView.tsx +2 -2
- package/src/agent/index.ts +0 -2
- package/src/agent/useUpdateAgent.ts +3 -3
- package/src/agent-instance/AgentInstanceDetailPanel.tsx +5 -7
- package/src/agent-instance/__tests__/AgentInstanceDetailPanel.test.tsx +75 -0
- package/src/agent-instance/useUpdateAgentInstance.ts +1 -1
- package/src/attachment/AttachmentChipList.tsx +19 -8
- package/src/attachment/__tests__/AttachmentChipList.test.tsx +12 -0
- package/src/attachment/__tests__/useAttachments.test.ts +293 -0
- package/src/attachment/index.ts +1 -0
- package/src/attachment/useAttachments.ts +143 -11
- package/src/channel/AgentChannelsPanel.tsx +26 -1
- package/src/channel/ChannelRunConfigDialog.tsx +351 -0
- package/src/channel/__tests__/ChannelRunConfigDialog.test.tsx +210 -0
- package/src/channel/index.ts +2 -0
- package/src/channel/useSaveAgentChannel.ts +6 -3
- package/src/channel-app/ChannelAppDetailPanel.tsx +9 -9
- package/src/channel-app/__tests__/channelAppWhatsApp.test.tsx +2 -0
- package/src/channel-app/__tests__/channelAppWipeSafety.test.tsx +87 -0
- package/src/composer/ComposerToolbar.tsx +9 -0
- package/src/composer/SessionComposer.tsx +59 -16
- package/src/composer/__tests__/SessionComposer-thinkingMode.test.tsx +176 -0
- package/src/conversation/ConversationComposer.tsx +38 -4
- package/src/conversation/ConversationTemplatePickerDialog.tsx +441 -0
- package/src/conversation/ConversationsWorkbench.tsx +40 -4
- package/src/conversation/__tests__/ConversationComposer.test.tsx +56 -1
- package/src/conversation/__tests__/ConversationTemplatePickerDialog.test.tsx +224 -0
- package/src/conversation/__tests__/useConversationParticipation.test.tsx +45 -4
- package/src/conversation/index.ts +4 -0
- package/src/conversation/useConversationParticipation.ts +58 -6
- package/src/cursor-accounts/CursorAccountsConsole.tsx +40 -5
- package/src/cursor-accounts/__tests__/CursorAccountsConsole.test.tsx +32 -0
- package/src/cursor-accounts/__tests__/cursor-account-coverage.test.ts +58 -1
- package/src/cursor-accounts/cursor-account-coverage.ts +55 -0
- package/src/execution/useCreateAgentExecution.ts +19 -0
- package/src/identity-account/AccountPreferencesPanel.tsx +532 -0
- package/src/identity-account/__tests__/AccountPreferencesPanel.test.tsx +267 -0
- package/src/identity-account/__tests__/useAccountExecutionDefaults.test.tsx +116 -0
- package/src/identity-account/__tests__/useMyIdentityAccount.test.tsx +121 -0
- package/src/identity-account/index.ts +11 -0
- package/src/identity-account/useAccountExecutionDefaults.ts +63 -0
- package/src/identity-account/useMyIdentityAccount.ts +75 -0
- package/src/identity-account/useUpdateIdentityAccount.ts +73 -0
- package/src/identity-provider/IdentityProviderDetailPanel.tsx +18 -15
- package/src/identity-provider/__tests__/IdentityProviderDetailPanel.test.tsx +80 -0
- package/src/index.ts +26 -4
- package/src/internal/StandingContextField.tsx +92 -0
- package/src/library/InstanceVisibilitySelector.tsx +9 -2
- package/src/library/ResourceVisibilityControl.tsx +46 -13
- package/src/library/VisibilityOptionRow.tsx +28 -6
- package/src/library/VisibilitySelector.tsx +14 -2
- package/src/library/__tests__/VisibilitySelector.test.tsx +48 -1
- package/src/library/__tests__/visibilityLevels.test.ts +67 -1
- package/src/library/index.ts +6 -1
- package/src/library/useCanSetPublicVisibility.ts +56 -0
- package/src/library/visibilityLevels.ts +65 -14
- package/src/mcp-server/McpServerDetailView.tsx +2 -2
- package/src/mcp-server/__tests__/useMcpServerConnect.asyncLane.test.tsx +117 -0
- package/src/mcp-server/index.ts +0 -2
- package/src/mcp-server/internal/definitionDrift.ts +22 -20
- package/src/mcp-server/useMcpServerConnect.ts +9 -6
- package/src/mcp-server/useMcpServerOAuthConnect.ts +7 -2
- package/src/mcp-server/useUpdateMcpServer.ts +3 -3
- package/src/models/ModelSelector.tsx +94 -1
- package/src/models/index.ts +2 -0
- package/src/models/registry.ts +29 -0
- package/src/models/thinking-mode.ts +48 -0
- package/src/oauth-app/CreateOAuthAppForm.tsx +58 -3
- package/src/oauth-app/OAuthAppDetailPanel.tsx +103 -20
- package/src/oauth-app/__tests__/OAuthAppDetailPanel.test.tsx +94 -0
- package/src/organization/OrgPreferencesPanel.tsx +221 -0
- package/src/organization/OrgProfilePanel.tsx +5 -4
- package/src/organization/__tests__/OrgPreferencesPanel.test.tsx +145 -0
- package/src/organization/__tests__/OrgProfilePanel.test.tsx +108 -0
- package/src/organization/index.ts +2 -0
- package/src/platform-client/PlatformClientDetailPanel.tsx +14 -13
- package/src/platform-client/__tests__/PlatformClientDetailPanel.test.tsx +82 -0
- package/src/schedule/ScheduleDetailView.tsx +29 -4
- package/src/schedule/ScheduleForm.tsx +14 -1
- package/src/session/NewSessionViewer.tsx +12 -0
- package/src/session/__tests__/useNewSessionFlow.test.tsx +151 -0
- package/src/session/run-config.ts +16 -0
- package/src/session/useNewSessionFlow.ts +82 -9
- package/src/session/useSessionConversation.ts +32 -40
- package/src/session/useSessionPageFlow.ts +14 -11
- package/src/session/useUpdateSession.ts +18 -24
- package/src/settings/AccountPreferencesSection.tsx +25 -0
- package/src/settings/OrgPreferencesSection.tsx +35 -0
- package/src/settings/__tests__/settings-nav.test.ts +27 -0
- package/src/settings/index.ts +2 -0
- package/src/settings/settings-nav.ts +18 -0
- package/src/workflow/ApprovalFormBuilder.tsx +20 -27
- package/src/workflow/WorkflowDetailView.tsx +2 -2
- package/src/workflow/__tests__/WorkflowInstanceDetailPanel.test.tsx +83 -0
- package/src/workflow/index.ts +0 -2
- package/src/workflow/instance/WorkflowInstanceDetailPanel.tsx +6 -7
- package/src/workflow/useUpdateWorkflow.ts +3 -3
- package/styles.css +1 -1
- package/workflow/ApprovalFormBuilder.d.ts.map +1 -1
- package/workflow/ApprovalFormBuilder.js +10 -5
- package/workflow/ApprovalFormBuilder.js.map +1 -1
- package/workflow/WorkflowDetailView.js +2 -2
- package/workflow/WorkflowDetailView.js.map +1 -1
- package/workflow/index.d.ts +0 -1
- package/workflow/index.d.ts.map +1 -1
- package/workflow/index.js +0 -1
- package/workflow/index.js.map +1 -1
- package/workflow/instance/WorkflowInstanceDetailPanel.d.ts.map +1 -1
- package/workflow/instance/WorkflowInstanceDetailPanel.js +6 -7
- package/workflow/instance/WorkflowInstanceDetailPanel.js.map +1 -1
- package/workflow/useUpdateWorkflow.d.ts +3 -3
- package/workflow/useUpdateWorkflow.js +3 -3
- package/agent/internal/agentToInput.d.ts +0 -15
- package/agent/internal/agentToInput.d.ts.map +0 -1
- package/agent/internal/agentToInput.js +0 -84
- package/agent/internal/agentToInput.js.map +0 -1
- package/mcp-server/internal/mcpServerToInput.d.ts +0 -12
- package/mcp-server/internal/mcpServerToInput.d.ts.map +0 -1
- package/mcp-server/internal/mcpServerToInput.js +0 -84
- package/mcp-server/internal/mcpServerToInput.js.map +0 -1
- package/session/session-spec-converters.d.ts +0 -24
- package/session/session-spec-converters.d.ts.map +0 -1
- package/session/session-spec-converters.js +0 -72
- package/session/session-spec-converters.js.map +0 -1
- package/src/agent/internal/__tests__/agentToInput.test.ts +0 -145
- package/src/agent/internal/agentToInput.ts +0 -102
- package/src/mcp-server/__tests__/mcpServerToInput.test.ts +0 -201
- package/src/mcp-server/internal/mcpServerToInput.ts +0 -98
- package/src/session/__tests__/session-spec-converters.test.ts +0 -183
- package/src/session/session-spec-converters.ts +0 -86
- package/src/workflow/internal/workflowToInput.ts +0 -96
- package/workflow/internal/workflowToInput.d.ts +0 -12
- package/workflow/internal/workflowToInput.d.ts.map +0 -1
- package/workflow/internal/workflowToInput.js +0 -73
- package/workflow/internal/workflowToInput.js.map +0 -1
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useAttachments lifecycle tests, centered on the `preparing` phase
|
|
3
|
+
* (stigmer/stigmer#369): entries must exist from the instant a
|
|
4
|
+
* prepare-flagged file is added, transition through preparation to
|
|
5
|
+
* upload, and honor the deferred-validation and cancellation contracts
|
|
6
|
+
* documented on {@link AddFilesOptions.prepareImages}.
|
|
7
|
+
*/
|
|
8
|
+
import { describe, it, expect, vi, afterEach } from "vitest";
|
|
9
|
+
import { renderHook, act, waitFor } from "@testing-library/react";
|
|
10
|
+
|
|
11
|
+
vi.mock("../../hooks", () => ({
|
|
12
|
+
useStigmer: vi.fn(),
|
|
13
|
+
}));
|
|
14
|
+
vi.mock("../prepare-image.js", () => ({
|
|
15
|
+
prepareImageForVision: vi.fn(),
|
|
16
|
+
}));
|
|
17
|
+
|
|
18
|
+
import { useStigmer } from "../../hooks";
|
|
19
|
+
import { prepareImageForVision } from "../prepare-image.js";
|
|
20
|
+
import { useAttachments } from "../useAttachments.js";
|
|
21
|
+
import { MAX_ATTACHMENT_BYTES } from "../attachment-utils.js";
|
|
22
|
+
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
// Helpers
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
|
|
27
|
+
function deferred<T>() {
|
|
28
|
+
let resolve!: (value: T) => void;
|
|
29
|
+
const promise = new Promise<T>((r) => {
|
|
30
|
+
resolve = r;
|
|
31
|
+
});
|
|
32
|
+
return { promise, resolve };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function makeFile(name: string, sizeBytes: number, type = "image/png"): File {
|
|
36
|
+
return new File([new Uint8Array(sizeBytes)], name, { type });
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Wires useStigmer to an uploadAttachment mock that resolves immediately. */
|
|
40
|
+
function mockStigmer() {
|
|
41
|
+
const uploadAttachment = vi
|
|
42
|
+
.fn()
|
|
43
|
+
.mockResolvedValue({ storageKey: "attachments/test/key" });
|
|
44
|
+
vi.mocked(useStigmer).mockReturnValue({
|
|
45
|
+
agentExecution: { uploadAttachment },
|
|
46
|
+
} as unknown as ReturnType<typeof useStigmer>);
|
|
47
|
+
return { uploadAttachment };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const prepareMock = vi.mocked(prepareImageForVision);
|
|
51
|
+
|
|
52
|
+
afterEach(() => {
|
|
53
|
+
vi.restoreAllMocks();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// ---------------------------------------------------------------------------
|
|
57
|
+
// The preparing phase
|
|
58
|
+
// ---------------------------------------------------------------------------
|
|
59
|
+
|
|
60
|
+
describe("useAttachments — prepareImages lifecycle", () => {
|
|
61
|
+
it("shows the entry immediately in the preparing phase, gating submit", () => {
|
|
62
|
+
mockStigmer();
|
|
63
|
+
const gap = deferred<File>();
|
|
64
|
+
prepareMock.mockReturnValue(gap.promise);
|
|
65
|
+
|
|
66
|
+
const { result } = renderHook(() => useAttachments());
|
|
67
|
+
|
|
68
|
+
act(() => {
|
|
69
|
+
result.current.addFiles([makeFile("shot.png", 1024)], {
|
|
70
|
+
prepareImages: true,
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
expect(result.current.entries).toHaveLength(1);
|
|
75
|
+
expect(result.current.entries[0].phase).toBe("preparing");
|
|
76
|
+
expect(result.current.entries[0].file.name).toBe("shot.png");
|
|
77
|
+
expect(result.current.isPreparing).toBe(true);
|
|
78
|
+
// preparing gates exactly like uploading — the silent-drop guard.
|
|
79
|
+
expect(result.current.isUploading).toBe(true);
|
|
80
|
+
expect(result.current.allReady).toBe(false);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("swaps to the prepared file (name, type) and proceeds to upload → ready", async () => {
|
|
84
|
+
const { uploadAttachment } = mockStigmer();
|
|
85
|
+
const gap = deferred<File>();
|
|
86
|
+
prepareMock.mockReturnValue(gap.promise);
|
|
87
|
+
|
|
88
|
+
const { result } = renderHook(() => useAttachments());
|
|
89
|
+
|
|
90
|
+
act(() => {
|
|
91
|
+
result.current.addFiles([makeFile("shot.png", 4096)], {
|
|
92
|
+
prepareImages: true,
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// Preparation re-encoded to JPEG: name and MIME follow.
|
|
97
|
+
act(() => {
|
|
98
|
+
gap.resolve(makeFile("shot.jpg", 2048, "image/jpeg"));
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
await waitFor(() => {
|
|
102
|
+
expect(result.current.entries[0].phase).toBe("ready");
|
|
103
|
+
});
|
|
104
|
+
expect(result.current.entries[0].file.name).toBe("shot.jpg");
|
|
105
|
+
expect(result.current.entries[0].contentType).toBe("image/jpeg");
|
|
106
|
+
expect(uploadAttachment).toHaveBeenCalledTimes(1);
|
|
107
|
+
expect(result.current.toAttachmentInputs()).toEqual([
|
|
108
|
+
{
|
|
109
|
+
filename: "shot.jpg",
|
|
110
|
+
storageKey: "attachments/test/key",
|
|
111
|
+
contentType: "image/jpeg",
|
|
112
|
+
},
|
|
113
|
+
]);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("accepts a raw file over the size limit when preparation brings it under (the #369 paste contract)", async () => {
|
|
117
|
+
const { uploadAttachment } = mockStigmer();
|
|
118
|
+
const onValidationError = vi.fn();
|
|
119
|
+
const gap = deferred<File>();
|
|
120
|
+
prepareMock.mockReturnValue(gap.promise);
|
|
121
|
+
|
|
122
|
+
const { result } = renderHook(() =>
|
|
123
|
+
useAttachments({ onValidationError }),
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
// 10 MB + 1 raw screenshot — would be rejected by up-front validation.
|
|
127
|
+
act(() => {
|
|
128
|
+
result.current.addFiles(
|
|
129
|
+
[makeFile("huge-screenshot.png", MAX_ATTACHMENT_BYTES + 1)],
|
|
130
|
+
{ prepareImages: true },
|
|
131
|
+
);
|
|
132
|
+
});
|
|
133
|
+
expect(result.current.entries[0].phase).toBe("preparing");
|
|
134
|
+
|
|
135
|
+
act(() => {
|
|
136
|
+
gap.resolve(makeFile("huge-screenshot.png", 512 * 1024));
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
await waitFor(() => {
|
|
140
|
+
expect(result.current.entries[0].phase).toBe("ready");
|
|
141
|
+
});
|
|
142
|
+
expect(onValidationError).not.toHaveBeenCalled();
|
|
143
|
+
expect(uploadAttachment).toHaveBeenCalledTimes(1);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it("removes the entry and reports via onValidationError when still oversized after preparation", async () => {
|
|
147
|
+
const { uploadAttachment } = mockStigmer();
|
|
148
|
+
const onValidationError = vi.fn();
|
|
149
|
+
const oversized = makeFile("giant.zip", MAX_ATTACHMENT_BYTES + 1, "application/zip");
|
|
150
|
+
// Non-image passthrough: preparation returns the original untouched.
|
|
151
|
+
prepareMock.mockResolvedValue(oversized);
|
|
152
|
+
|
|
153
|
+
const { result } = renderHook(() =>
|
|
154
|
+
useAttachments({ onValidationError }),
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
act(() => {
|
|
158
|
+
result.current.addFiles([oversized], { prepareImages: true });
|
|
159
|
+
});
|
|
160
|
+
expect(result.current.entries).toHaveLength(1);
|
|
161
|
+
|
|
162
|
+
await waitFor(() => {
|
|
163
|
+
expect(result.current.entries).toHaveLength(0);
|
|
164
|
+
});
|
|
165
|
+
expect(onValidationError).toHaveBeenCalledWith(
|
|
166
|
+
expect.stringContaining("giant.zip"),
|
|
167
|
+
);
|
|
168
|
+
expect(uploadAttachment).not.toHaveBeenCalled();
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it("discards the preparation result when the entry is removed mid-preparation", async () => {
|
|
172
|
+
const { uploadAttachment } = mockStigmer();
|
|
173
|
+
const gap = deferred<File>();
|
|
174
|
+
prepareMock.mockReturnValue(gap.promise);
|
|
175
|
+
|
|
176
|
+
const { result } = renderHook(() => useAttachments());
|
|
177
|
+
|
|
178
|
+
act(() => {
|
|
179
|
+
result.current.addFiles([makeFile("shot.png", 1024)], {
|
|
180
|
+
prepareImages: true,
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
const id = result.current.entries[0].id;
|
|
184
|
+
|
|
185
|
+
act(() => {
|
|
186
|
+
result.current.removeEntry(id);
|
|
187
|
+
});
|
|
188
|
+
expect(result.current.entries).toHaveLength(0);
|
|
189
|
+
|
|
190
|
+
// Late completion must not resurrect the entry or start an upload.
|
|
191
|
+
await act(async () => {
|
|
192
|
+
gap.resolve(makeFile("shot.jpg", 512, "image/jpeg"));
|
|
193
|
+
await gap.promise;
|
|
194
|
+
});
|
|
195
|
+
expect(result.current.entries).toHaveLength(0);
|
|
196
|
+
expect(uploadAttachment).not.toHaveBeenCalled();
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it("discards the preparation result on clear()", async () => {
|
|
200
|
+
const { uploadAttachment } = mockStigmer();
|
|
201
|
+
const gap = deferred<File>();
|
|
202
|
+
prepareMock.mockReturnValue(gap.promise);
|
|
203
|
+
|
|
204
|
+
const { result } = renderHook(() => useAttachments());
|
|
205
|
+
|
|
206
|
+
act(() => {
|
|
207
|
+
result.current.addFiles([makeFile("shot.png", 1024)], {
|
|
208
|
+
prepareImages: true,
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
act(() => {
|
|
213
|
+
result.current.clear();
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
await act(async () => {
|
|
217
|
+
gap.resolve(makeFile("shot.jpg", 512, "image/jpeg"));
|
|
218
|
+
await gap.promise;
|
|
219
|
+
});
|
|
220
|
+
expect(result.current.entries).toHaveLength(0);
|
|
221
|
+
expect(uploadAttachment).not.toHaveBeenCalled();
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it("uniquifies the prepared name against other entries' settled names", async () => {
|
|
225
|
+
mockStigmer();
|
|
226
|
+
const gap = deferred<File>();
|
|
227
|
+
prepareMock.mockReturnValue(gap.promise);
|
|
228
|
+
|
|
229
|
+
const { result } = renderHook(() => useAttachments());
|
|
230
|
+
|
|
231
|
+
// A settled entry already owns "pasted-image.png".
|
|
232
|
+
act(() => {
|
|
233
|
+
result.current.addFiles([makeFile("pasted-image.png", 256)]);
|
|
234
|
+
});
|
|
235
|
+
// The prepared file lands on the same name.
|
|
236
|
+
act(() => {
|
|
237
|
+
result.current.addFiles([makeFile("other.png", 256)], {
|
|
238
|
+
prepareImages: true,
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
act(() => {
|
|
242
|
+
gap.resolve(makeFile("pasted-image.png", 128));
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
await waitFor(() => {
|
|
246
|
+
expect(result.current.entries[1].phase).toBe("ready");
|
|
247
|
+
});
|
|
248
|
+
expect(result.current.entries[1].file.name).toBe("pasted-image-2.png");
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
// ---------------------------------------------------------------------------
|
|
253
|
+
// The unflagged path — byte-identical to the pre-#369 behavior
|
|
254
|
+
// ---------------------------------------------------------------------------
|
|
255
|
+
|
|
256
|
+
describe("useAttachments — unflagged addFiles", () => {
|
|
257
|
+
it("never enters the preparing phase and never calls prepareImageForVision", async () => {
|
|
258
|
+
mockStigmer();
|
|
259
|
+
|
|
260
|
+
const { result } = renderHook(() => useAttachments());
|
|
261
|
+
|
|
262
|
+
act(() => {
|
|
263
|
+
result.current.addFiles([makeFile("picked.png", 1024)]);
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
expect(result.current.entries[0].phase).toBe("uploading");
|
|
267
|
+
expect(result.current.isPreparing).toBe(false);
|
|
268
|
+
expect(prepareMock).not.toHaveBeenCalled();
|
|
269
|
+
|
|
270
|
+
await waitFor(() => {
|
|
271
|
+
expect(result.current.entries[0].phase).toBe("ready");
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
it("still validates size up front and rejects without creating an entry", () => {
|
|
276
|
+
const { uploadAttachment } = mockStigmer();
|
|
277
|
+
const onValidationError = vi.fn();
|
|
278
|
+
|
|
279
|
+
const { result } = renderHook(() =>
|
|
280
|
+
useAttachments({ onValidationError }),
|
|
281
|
+
);
|
|
282
|
+
|
|
283
|
+
act(() => {
|
|
284
|
+
result.current.addFiles([
|
|
285
|
+
makeFile("too-big.png", MAX_ATTACHMENT_BYTES + 1),
|
|
286
|
+
]);
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
expect(result.current.entries).toHaveLength(0);
|
|
290
|
+
expect(onValidationError).toHaveBeenCalledTimes(1);
|
|
291
|
+
expect(uploadAttachment).not.toHaveBeenCalled();
|
|
292
|
+
});
|
|
293
|
+
});
|
package/src/attachment/index.ts
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
uniquifyFilename,
|
|
13
13
|
validateAttachmentSize,
|
|
14
14
|
} from "./attachment-utils.js";
|
|
15
|
+
import { prepareImageForVision } from "./prepare-image.js";
|
|
15
16
|
|
|
16
17
|
// ---------------------------------------------------------------------------
|
|
17
18
|
// Types
|
|
@@ -20,11 +21,16 @@ import {
|
|
|
20
21
|
/**
|
|
21
22
|
* Lifecycle phase of a single attachment managed by {@link useAttachments}.
|
|
22
23
|
*
|
|
24
|
+
* - `preparing` — client-side image preparation is running (see
|
|
25
|
+
* {@link AddFilesOptions.prepareImages}); the entry exists so the UI can
|
|
26
|
+
* show the file from the instant it was added, but no bytes have been
|
|
27
|
+
* sent yet. Only entries added with `prepareImages` ever visit this
|
|
28
|
+
* phase — everything else starts at `uploading`.
|
|
23
29
|
* - `uploading` — bytes are being sent to the server
|
|
24
30
|
* - `ready` — upload succeeded, `storageKey` is available
|
|
25
31
|
* - `error` — upload failed, `error` describes the failure
|
|
26
32
|
*/
|
|
27
|
-
export type AttachmentPhase = "uploading" | "ready" | "error";
|
|
33
|
+
export type AttachmentPhase = "preparing" | "uploading" | "ready" | "error";
|
|
28
34
|
|
|
29
35
|
/**
|
|
30
36
|
* State for a single file being managed by the hook.
|
|
@@ -50,7 +56,12 @@ export type AttachmentPhase = "uploading" | "ready" | "error";
|
|
|
50
56
|
export interface AttachmentEntry {
|
|
51
57
|
/** Unique client-side identifier for this attachment. */
|
|
52
58
|
readonly id: string;
|
|
53
|
-
/**
|
|
59
|
+
/**
|
|
60
|
+
* The `File` object backing this attachment. For entries added with
|
|
61
|
+
* {@link AddFilesOptions.prepareImages} this starts as the user's
|
|
62
|
+
* original file and swaps to the prepared file (possibly smaller, with
|
|
63
|
+
* a matching extension/MIME change) when the `preparing` phase ends.
|
|
64
|
+
*/
|
|
54
65
|
readonly file: File;
|
|
55
66
|
/** Current upload lifecycle phase. */
|
|
56
67
|
readonly phase: AttachmentPhase;
|
|
@@ -71,25 +82,59 @@ export interface UseAttachmentsOptions {
|
|
|
71
82
|
readonly onValidationError?: (message: string) => void;
|
|
72
83
|
}
|
|
73
84
|
|
|
85
|
+
/** Per-call options for {@link UseAttachmentsReturn.addFiles}. */
|
|
86
|
+
export interface AddFilesOptions {
|
|
87
|
+
/**
|
|
88
|
+
* Bound image files to provider vision resolution before upload (via
|
|
89
|
+
* {@link prepareImageForVision}) — the paste-to-attach treatment
|
|
90
|
+
* (stigmer/stigmer#284). Each file's entry appears immediately in the
|
|
91
|
+
* `preparing` phase, so a large screenshot shows a chip the instant it
|
|
92
|
+
* is pasted instead of after the 150-350 ms decode/downscale/re-encode
|
|
93
|
+
* (stigmer/stigmer#369). Non-image files pass through preparation
|
|
94
|
+
* untouched.
|
|
95
|
+
*
|
|
96
|
+
* Meant for pasted content only: a picked or dragged file may be the
|
|
97
|
+
* subject of the task ("read the EXIF"), and silently re-encoding it
|
|
98
|
+
* would be a regression — see prepare-image.ts for the doctrine.
|
|
99
|
+
*
|
|
100
|
+
* With this flag, size validation runs against the PREPARED bytes (the
|
|
101
|
+
* bytes that actually upload), so an oversized paste that downscales
|
|
102
|
+
* under the limit is accepted — identical to preparing before calling
|
|
103
|
+
* `addFiles`, which is what this option replaces. A file still
|
|
104
|
+
* oversized after preparation is removed and reported via
|
|
105
|
+
* `onValidationError`.
|
|
106
|
+
*/
|
|
107
|
+
readonly prepareImages?: boolean;
|
|
108
|
+
}
|
|
109
|
+
|
|
74
110
|
/** Return value of {@link useAttachments}. */
|
|
75
111
|
export interface UseAttachmentsReturn {
|
|
76
|
-
/** Current attachment entries (uploading, ready, or errored). */
|
|
112
|
+
/** Current attachment entries (preparing, uploading, ready, or errored). */
|
|
77
113
|
readonly entries: readonly AttachmentEntry[];
|
|
78
|
-
/**
|
|
114
|
+
/**
|
|
115
|
+
* True while any entry has work in flight (`preparing` or
|
|
116
|
+
* `uploading`). This is the submit gate: `toAttachmentInputs()` carries
|
|
117
|
+
* only `ready` entries, so a send while this is true would silently
|
|
118
|
+
* drop the file the user just added.
|
|
119
|
+
*/
|
|
79
120
|
readonly isUploading: boolean;
|
|
121
|
+
/** True when at least one entry is in the `"preparing"` phase. */
|
|
122
|
+
readonly isPreparing: boolean;
|
|
80
123
|
/** Number of entries that are ready for submission. */
|
|
81
124
|
readonly readyCount: number;
|
|
82
|
-
/** True when there are entries and all are ready (none uploading or errored). */
|
|
125
|
+
/** True when there are entries and all are ready (none preparing, uploading, or errored). */
|
|
83
126
|
readonly allReady: boolean;
|
|
84
127
|
/** True when there is at least one entry (in any phase). */
|
|
85
128
|
readonly hasEntries: boolean;
|
|
86
129
|
/**
|
|
87
130
|
* Add one or more files. Each file is validated and uploaded
|
|
88
131
|
* immediately. Invalid files (e.g., too large) are rejected via
|
|
89
|
-
* `onValidationError` and not added.
|
|
132
|
+
* `onValidationError` and not added. With
|
|
133
|
+
* {@link AddFilesOptions.prepareImages}, images are bounded to vision
|
|
134
|
+
* resolution first — entries appear at once in the `preparing` phase.
|
|
90
135
|
*/
|
|
91
|
-
readonly addFiles: (files: FileList | File[]) => void;
|
|
92
|
-
/** Remove an entry by its stable ID. Aborts in-flight uploads. */
|
|
136
|
+
readonly addFiles: (files: FileList | File[], addOptions?: AddFilesOptions) => void;
|
|
137
|
+
/** Remove an entry by its stable ID. Aborts in-flight preparation and uploads. */
|
|
93
138
|
readonly removeEntry: (id: string) => void;
|
|
94
139
|
/** Retry a failed upload. */
|
|
95
140
|
readonly retryEntry: (id: string) => void;
|
|
@@ -220,13 +265,92 @@ export function useAttachments(
|
|
|
220
265
|
[stigmer],
|
|
221
266
|
);
|
|
222
267
|
|
|
268
|
+
// The `preparing` half of the lifecycle (AddFilesOptions.prepareImages):
|
|
269
|
+
// runs prepareImageForVision on the raw file, then hands the result to
|
|
270
|
+
// the normal validate → uniquify → upload sequence. The entry already
|
|
271
|
+
// exists (created by addFiles in the `preparing` phase), so this
|
|
272
|
+
// transitions it rather than creating it.
|
|
273
|
+
const prepareEntry = useCallback(
|
|
274
|
+
async (id: string, rawFile: File) => {
|
|
275
|
+
// Registered under the same id the upload path uses, so removeEntry
|
|
276
|
+
// and clear() cancel a preparation exactly like an upload. The
|
|
277
|
+
// signal is only ever read, never passed down — prepareImageForVision
|
|
278
|
+
// never throws and cannot be interrupted; cancellation means
|
|
279
|
+
// discarding its result.
|
|
280
|
+
const controller = new AbortController();
|
|
281
|
+
abortControllers.current.set(id, controller);
|
|
282
|
+
|
|
283
|
+
const prepared = await prepareImageForVision(rawFile);
|
|
284
|
+
if (controller.signal.aborted) return;
|
|
285
|
+
// Hand-off point: from here the upload path owns the map slot
|
|
286
|
+
// (uploadFile registers its own controller under this id).
|
|
287
|
+
abortControllers.current.delete(id);
|
|
288
|
+
|
|
289
|
+
// Deferred validation — deliberately on the PREPARED bytes, the
|
|
290
|
+
// bytes that actually upload: a 12 MB screenshot that downscales
|
|
291
|
+
// under the limit must pass, exactly as it did when callers
|
|
292
|
+
// prepared before calling addFiles. Rejection removes the chip the
|
|
293
|
+
// user has been watching, so the toast is the explanation.
|
|
294
|
+
const sizeError = validateAttachmentSize(prepared);
|
|
295
|
+
if (sizeError) {
|
|
296
|
+
setEntries((prev) => prev.filter((e) => e.id !== id));
|
|
297
|
+
options?.onValidationError?.(sizeError);
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// Preparation may rename (extension follows the re-encode format),
|
|
302
|
+
// so uniquify now, against every OTHER entry's settled name —
|
|
303
|
+
// same downstream-breakage rule as the un-prepared path.
|
|
304
|
+
const takenNames = new Set(
|
|
305
|
+
entriesRef.current.filter((e) => e.id !== id).map((e) => e.file.name),
|
|
306
|
+
);
|
|
307
|
+
const uniqueName = uniquifyFilename(prepared.name, takenNames);
|
|
308
|
+
const file =
|
|
309
|
+
uniqueName === prepared.name
|
|
310
|
+
? prepared
|
|
311
|
+
: new File([prepared], uniqueName, {
|
|
312
|
+
type: prepared.type,
|
|
313
|
+
lastModified: prepared.lastModified,
|
|
314
|
+
});
|
|
315
|
+
const contentType = detectContentType(file);
|
|
316
|
+
|
|
317
|
+
setEntries((prev) =>
|
|
318
|
+
prev.map((e) =>
|
|
319
|
+
e.id === id
|
|
320
|
+
? { ...e, file, contentType, phase: "uploading" as const }
|
|
321
|
+
: e,
|
|
322
|
+
),
|
|
323
|
+
);
|
|
324
|
+
uploadFile(id, file, contentType);
|
|
325
|
+
},
|
|
326
|
+
[options, uploadFile],
|
|
327
|
+
);
|
|
328
|
+
|
|
223
329
|
const addFiles = useCallback(
|
|
224
|
-
(files: FileList | File[]) => {
|
|
330
|
+
(files: FileList | File[], addOptions?: AddFilesOptions) => {
|
|
225
331
|
const fileArray = Array.from(files);
|
|
226
332
|
const validEntries: AttachmentEntry[] = [];
|
|
227
333
|
const takenNames = new Set(entriesRef.current.map((e) => e.file.name));
|
|
228
334
|
|
|
229
335
|
for (const rawFile of fileArray) {
|
|
336
|
+
if (addOptions?.prepareImages) {
|
|
337
|
+
// The entry must exist THIS tick — the whole point of the
|
|
338
|
+
// preparing phase is feedback during the decode/downscale gap.
|
|
339
|
+
// Size validation and name uniquification move to prepareEntry:
|
|
340
|
+
// both depend on the prepared file (final bytes, final name).
|
|
341
|
+
const id = generateId();
|
|
342
|
+
validEntries.push({
|
|
343
|
+
id,
|
|
344
|
+
file: rawFile,
|
|
345
|
+
phase: "preparing",
|
|
346
|
+
contentType: detectContentType(rawFile),
|
|
347
|
+
storageKey: null,
|
|
348
|
+
error: null,
|
|
349
|
+
});
|
|
350
|
+
void prepareEntry(id, rawFile);
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
|
|
230
354
|
const sizeError = validateAttachmentSize(rawFile);
|
|
231
355
|
if (sizeError) {
|
|
232
356
|
options?.onValidationError?.(sizeError);
|
|
@@ -266,7 +390,7 @@ export function useAttachments(
|
|
|
266
390
|
setEntries((prev) => [...prev, ...validEntries]);
|
|
267
391
|
}
|
|
268
392
|
},
|
|
269
|
-
[options, uploadFile],
|
|
393
|
+
[options, uploadFile, prepareEntry],
|
|
270
394
|
);
|
|
271
395
|
|
|
272
396
|
const removeEntry = useCallback((id: string) => {
|
|
@@ -317,7 +441,14 @@ export function useAttachments(
|
|
|
317
441
|
}));
|
|
318
442
|
}, [entries]);
|
|
319
443
|
|
|
320
|
-
const
|
|
444
|
+
const isPreparing = entries.some((e) => e.phase === "preparing");
|
|
445
|
+
// `preparing` counts as uploading-in-the-gate sense: both phases mean
|
|
446
|
+
// "this file will be lost if the message sends now" (see the
|
|
447
|
+
// isUploading doc). Hosts that gate submit on isUploading inherit the
|
|
448
|
+
// preparing gate without a code change.
|
|
449
|
+
const isUploading = entries.some(
|
|
450
|
+
(e) => e.phase === "preparing" || e.phase === "uploading",
|
|
451
|
+
);
|
|
321
452
|
const readyCount = entries.filter((e) => e.phase === "ready").length;
|
|
322
453
|
const hasEntries = entries.length > 0;
|
|
323
454
|
const allReady = hasEntries && readyCount === entries.length;
|
|
@@ -325,6 +456,7 @@ export function useAttachments(
|
|
|
325
456
|
return {
|
|
326
457
|
entries,
|
|
327
458
|
isUploading,
|
|
459
|
+
isPreparing,
|
|
328
460
|
readyCount,
|
|
329
461
|
allReady,
|
|
330
462
|
hasEntries,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
import { useCallback, useState } from "react";
|
|
4
|
-
import { FileCode2, KeyRound, LayoutTemplate, MessageSquare, MoreHorizontal, Share2, Trash2 } from "lucide-react";
|
|
4
|
+
import { FileCode2, KeyRound, LayoutTemplate, MessageSquare, MoreHorizontal, Share2, SlidersHorizontal, Trash2 } from "lucide-react";
|
|
5
5
|
import { cn } from "@stigmer/theme";
|
|
6
6
|
import { getUserMessage } from "@stigmer/sdk";
|
|
7
7
|
import type { Agent } from "@stigmer/protos/ai/stigmer/agentic/agent/v1/api_pb";
|
|
@@ -25,6 +25,7 @@ import { CloudFeatureNotice } from "../internal/CloudFeatureNotice.js";
|
|
|
25
25
|
import { TruncatedText } from "../internal/truncated-text.js";
|
|
26
26
|
import { ChannelConversationsDialog } from "./ChannelConversationsDialog.js";
|
|
27
27
|
import { ChannelCredentialsDialog } from "./ChannelCredentialsDialog.js";
|
|
28
|
+
import { ChannelRunConfigDialog } from "./ChannelRunConfigDialog.js";
|
|
28
29
|
import { ChannelTemplatesDialog } from "./ChannelTemplatesDialog.js";
|
|
29
30
|
import { ConnectSlackDialog } from "./ConnectSlackDialog.js";
|
|
30
31
|
import { ConnectWhatsAppDialog } from "./ConnectWhatsAppDialog.js";
|
|
@@ -160,6 +161,7 @@ export function AgentChannelsPanel({
|
|
|
160
161
|
|
|
161
162
|
// The channel being edited as YAML (the kind-agnostic manifest flow).
|
|
162
163
|
const [editingYaml, setEditingYaml] = useState<AgentChannel | null>(null);
|
|
164
|
+
const [editingRunConfig, setEditingRunConfig] = useState<AgentChannel | null>(null);
|
|
163
165
|
|
|
164
166
|
const handleConnect = useCallback(
|
|
165
167
|
(channel: AgentChannel | null, provider: ChannelProviderDescriptor) => {
|
|
@@ -305,6 +307,7 @@ export function AgentChannelsPanel({
|
|
|
305
307
|
onViewConversations={() => setViewingConversations(channel)}
|
|
306
308
|
onViewTemplates={() => setViewingTemplates(channel)}
|
|
307
309
|
onEditYaml={() => setEditingYaml(channel)}
|
|
310
|
+
onEditRunConfig={() => setEditingRunConfig(channel)}
|
|
308
311
|
refetch={refetch}
|
|
309
312
|
/>
|
|
310
313
|
);
|
|
@@ -390,6 +393,17 @@ export function AgentChannelsPanel({
|
|
|
390
393
|
/>
|
|
391
394
|
)}
|
|
392
395
|
|
|
396
|
+
{editingRunConfig && (
|
|
397
|
+
<ChannelRunConfigDialog
|
|
398
|
+
open
|
|
399
|
+
onOpenChange={(open) => {
|
|
400
|
+
if (!open) setEditingRunConfig(null);
|
|
401
|
+
}}
|
|
402
|
+
channel={editingRunConfig}
|
|
403
|
+
onSaved={refetch}
|
|
404
|
+
/>
|
|
405
|
+
)}
|
|
406
|
+
|
|
393
407
|
<ConfirmDialog
|
|
394
408
|
state={confirmState}
|
|
395
409
|
onConfirm={handleConfirm}
|
|
@@ -415,6 +429,7 @@ interface ChannelCardProps {
|
|
|
415
429
|
readonly onViewConversations: () => void;
|
|
416
430
|
readonly onViewTemplates: () => void;
|
|
417
431
|
readonly onEditYaml: () => void;
|
|
432
|
+
readonly onEditRunConfig: () => void;
|
|
418
433
|
readonly refetch: () => void;
|
|
419
434
|
}
|
|
420
435
|
|
|
@@ -429,6 +444,7 @@ function ChannelCard({
|
|
|
429
444
|
onViewConversations,
|
|
430
445
|
onViewTemplates,
|
|
431
446
|
onEditYaml,
|
|
447
|
+
onEditRunConfig,
|
|
432
448
|
refetch,
|
|
433
449
|
}: ChannelCardProps) {
|
|
434
450
|
const meta = channel.metadata;
|
|
@@ -584,6 +600,15 @@ function ChannelCard({
|
|
|
584
600
|
Templates
|
|
585
601
|
</ActionMenu.Item>
|
|
586
602
|
)}
|
|
603
|
+
{canEdit && (
|
|
604
|
+
<ActionMenu.Item
|
|
605
|
+
icon={<SlidersHorizontal />}
|
|
606
|
+
onSelect={onEditRunConfig}
|
|
607
|
+
data-cursor-target="channel-run-config"
|
|
608
|
+
>
|
|
609
|
+
Run settings
|
|
610
|
+
</ActionMenu.Item>
|
|
611
|
+
)}
|
|
587
612
|
{canEdit && (
|
|
588
613
|
<ActionMenu.Item
|
|
589
614
|
icon={<KeyRound />}
|