@mastra/code-sdk 0.0.0-agent-tags-alpha-20261125185303
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/LICENSE.md +32 -0
- package/README.md +284 -0
- package/dist/acp/agent.d.ts +48 -0
- package/dist/acp/agent.js +414 -0
- package/dist/acp/errors.d.ts +3 -0
- package/dist/acp/errors.js +11 -0
- package/dist/acp/event-mapper.d.ts +28 -0
- package/dist/acp/event-mapper.js +274 -0
- package/dist/acp/index.d.ts +9 -0
- package/dist/acp/index.js +21 -0
- package/dist/acp/runtime.d.ts +5 -0
- package/dist/acp/runtime.js +91 -0
- package/dist/acp/server.d.ts +4 -0
- package/dist/acp/server.js +35 -0
- package/dist/acp/skills.d.ts +6 -0
- package/dist/acp/skills.js +30 -0
- package/dist/acp.d.ts +2 -0
- package/dist/acp.js +1 -0
- package/dist/agent-connections/messaging-processor.d.ts +17 -0
- package/dist/agent-connections/messaging-processor.js +131 -0
- package/dist/agent-connections/ownership.d.ts +24 -0
- package/dist/agent-connections/ownership.js +96 -0
- package/dist/agent-connections/registry.d.ts +20 -0
- package/dist/agent-connections/registry.js +167 -0
- package/dist/agent-connections/session-advertisement.d.ts +27 -0
- package/dist/agent-connections/session-advertisement.js +86 -0
- package/dist/agent-connections/signal-provider.d.ts +141 -0
- package/dist/agent-connections/signal-provider.js +35 -0
- package/dist/agent-connections/state-processor.d.ts +23 -0
- package/dist/agent-connections/state-processor.js +270 -0
- package/dist/agent-connections/thread-state.d.ts +41 -0
- package/dist/agent-connections/thread-state.js +157 -0
- package/dist/agent-connections/tools.d.ts +133 -0
- package/dist/agent-connections/tools.js +616 -0
- package/dist/agent-connections/types.d.ts +99 -0
- package/dist/agent-connections/types.js +4 -0
- package/dist/agent-connections/untrusted-text.d.ts +5 -0
- package/dist/agent-connections/untrusted-text.js +19 -0
- package/dist/agents/background-completion-events.d.ts +16 -0
- package/dist/agents/background-completion-events.js +16 -0
- package/dist/agents/background-completion.d.ts +22 -0
- package/dist/agents/background-completion.js +73 -0
- package/dist/agents/context-audit.d.ts +84 -0
- package/dist/agents/context-audit.js +115 -0
- package/dist/agents/credential-resolver.d.ts +74 -0
- package/dist/agents/credential-resolver.js +142 -0
- package/dist/agents/custom-provider-source.d.ts +35 -0
- package/dist/agents/custom-provider-source.js +22 -0
- package/dist/agents/fastembed-subprocess.d.ts +52 -0
- package/dist/agents/fastembed-subprocess.js +282 -0
- package/dist/agents/instructions.d.ts +42 -0
- package/dist/agents/instructions.js +69 -0
- package/dist/agents/mastracode-gateway.d.ts +85 -0
- package/dist/agents/mastracode-gateway.js +500 -0
- package/dist/agents/memory.d.ts +36 -0
- package/dist/agents/memory.js +248 -0
- package/dist/agents/model.d.ts +158 -0
- package/dist/agents/model.js +382 -0
- package/dist/agents/modes/build.d.ts +12 -0
- package/dist/agents/modes/build.js +33 -0
- package/dist/agents/modes/explore.d.ts +10 -0
- package/dist/agents/modes/explore.js +25 -0
- package/dist/agents/modes/plan.d.ts +8 -0
- package/dist/agents/modes/plan.js +43 -0
- package/dist/agents/prompts/agent-instructions.d.ts +122 -0
- package/dist/agents/prompts/agent-instructions.js +617 -0
- package/dist/agents/prompts/build.d.ts +12 -0
- package/dist/agents/prompts/build.js +73 -0
- package/dist/agents/prompts/fast.d.ts +5 -0
- package/dist/agents/prompts/fast.js +23 -0
- package/dist/agents/prompts/index.d.ts +61 -0
- package/dist/agents/prompts/index.js +141 -0
- package/dist/agents/prompts/model.d.ts +5 -0
- package/dist/agents/prompts/model.js +20 -0
- package/dist/agents/prompts/plan.d.ts +11 -0
- package/dist/agents/prompts/plan.js +132 -0
- package/dist/agents/prompts/tool-guidance.d.ts +18 -0
- package/dist/agents/prompts/tool-guidance.js +158 -0
- package/dist/agents/sandbox-filesystem.d.ts +232 -0
- package/dist/agents/sandbox-filesystem.js +851 -0
- package/dist/agents/subagents/execute.d.ts +3 -0
- package/dist/agents/subagents/execute.js +24 -0
- package/dist/agents/subagents/explore.d.ts +3 -0
- package/dist/agents/subagents/explore.js +15 -0
- package/dist/agents/subagents/index.d.ts +6 -0
- package/dist/agents/subagents/index.js +15 -0
- package/dist/agents/subagents/plan.d.ts +3 -0
- package/dist/agents/subagents/plan.js +15 -0
- package/dist/agents/thread-caveman-state.d.ts +17 -0
- package/dist/agents/thread-caveman-state.js +104 -0
- package/dist/agents/tool-availability.d.ts +17 -0
- package/dist/agents/tool-availability.js +134 -0
- package/dist/agents/tools.d.ts +37 -0
- package/dist/agents/tools.js +154 -0
- package/dist/agents/workflow-builder-agent.d.ts +2 -0
- package/dist/agents/workflow-builder-agent.js +79 -0
- package/dist/agents/workspace.d.ts +35 -0
- package/dist/agents/workspace.js +207 -0
- package/dist/analytics.d.ts +18 -0
- package/dist/analytics.js +159 -0
- package/dist/auth/account-rotation-processor.d.ts +210 -0
- package/dist/auth/account-rotation-processor.js +662 -0
- package/dist/auth/account-routing-context.d.ts +17 -0
- package/dist/auth/account-routing-context.js +38 -0
- package/dist/auth/authorization-input.d.ts +16 -0
- package/dist/auth/authorization-input.js +39 -0
- package/dist/auth/device-code.d.ts +93 -0
- package/dist/auth/device-code.js +126 -0
- package/dist/auth/index.d.ts +13 -0
- package/dist/auth/index.js +9 -0
- package/dist/auth/pkce.d.ts +13 -0
- package/dist/auth/pkce.js +29 -0
- package/dist/auth/provider-auth-error.d.ts +24 -0
- package/dist/auth/provider-auth-error.js +44 -0
- package/dist/auth/providers/anthropic.d.ts +40 -0
- package/dist/auth/providers/anthropic.js +117 -0
- package/dist/auth/providers/github-copilot.d.ts +154 -0
- package/dist/auth/providers/github-copilot.js +359 -0
- package/dist/auth/providers/kimi-coding.d.ts +38 -0
- package/dist/auth/providers/kimi-coding.js +225 -0
- package/dist/auth/providers/openai-codex.d.ts +141 -0
- package/dist/auth/providers/openai-codex.js +531 -0
- package/dist/auth/providers/xai.d.ts +64 -0
- package/dist/auth/providers/xai.js +223 -0
- package/dist/auth/storage.d.ts +222 -0
- package/dist/auth/storage.js +805 -0
- package/dist/auth/types.d.ts +164 -0
- package/dist/auth/types.js +1 -0
- package/dist/clipboard/index.d.ts +26 -0
- package/dist/clipboard/index.js +224 -0
- package/dist/constants.d.ts +29 -0
- package/dist/constants.js +34 -0
- package/dist/error-classification.d.ts +10 -0
- package/dist/error-classification.js +19 -0
- package/dist/evals/context-builder.d.ts +41 -0
- package/dist/evals/context-builder.js +156 -0
- package/dist/evals/index.d.ts +4 -0
- package/dist/evals/index.js +5 -0
- package/dist/evals/scorers/classify-command.d.ts +30 -0
- package/dist/evals/scorers/classify-command.js +61 -0
- package/dist/evals/scorers/efficiency.d.ts +44 -0
- package/dist/evals/scorers/efficiency.js +256 -0
- package/dist/evals/scorers/extract-tools.d.ts +25 -0
- package/dist/evals/scorers/extract-tools.js +57 -0
- package/dist/evals/scorers/index.d.ts +3 -0
- package/dist/evals/scorers/index.js +3 -0
- package/dist/evals/scorers/outcome.d.ts +49 -0
- package/dist/evals/scorers/outcome.js +360 -0
- package/dist/experimental-agent.d.ts +19 -0
- package/dist/experimental-agent.js +45 -0
- package/dist/factory/client.d.ts +44 -0
- package/dist/factory/client.js +110 -0
- package/dist/factory/remote-controller.d.ts +34 -0
- package/dist/factory/remote-controller.js +40 -0
- package/dist/factory/remote-session.d.ts +210 -0
- package/dist/factory/remote-session.js +415 -0
- package/dist/goal-manager.d.ts +114 -0
- package/dist/goal-manager.js +351 -0
- package/dist/goal-signal.d.ts +14 -0
- package/dist/goal-signal.js +14 -0
- package/dist/headless/cli.d.ts +55 -0
- package/dist/headless/cli.js +261 -0
- package/dist/headless/flags.d.ts +33 -0
- package/dist/headless/flags.js +207 -0
- package/dist/headless/format.d.ts +41 -0
- package/dist/headless/format.js +94 -0
- package/dist/headless/index.d.ts +25 -0
- package/dist/headless/index.js +6 -0
- package/dist/headless/policy.d.ts +17 -0
- package/dist/headless/policy.js +39 -0
- package/dist/headless/run-mc.d.ts +7 -0
- package/dist/headless/run-mc.js +438 -0
- package/dist/headless/types.d.ts +175 -0
- package/dist/headless/types.js +16 -0
- package/dist/hooks/config.d.ts +11 -0
- package/dist/hooks/config.js +77 -0
- package/dist/hooks/executor.d.ts +13 -0
- package/dist/hooks/executor.js +128 -0
- package/dist/hooks/index.d.ts +6 -0
- package/dist/hooks/index.js +5 -0
- package/dist/hooks/manager.d.ts +75 -0
- package/dist/hooks/manager.js +289 -0
- package/dist/hooks/types.d.ts +180 -0
- package/dist/hooks/types.js +5 -0
- package/dist/index.d.ts +537 -0
- package/dist/index.js +1399 -0
- package/dist/ipc/ipc-reporter.d.ts +14 -0
- package/dist/ipc/ipc-reporter.js +18 -0
- package/dist/knowledge-inspector.d.ts +139 -0
- package/dist/knowledge-inspector.js +533 -0
- package/dist/knowledge-scope-id.d.ts +7 -0
- package/dist/knowledge-scope-id.js +10 -0
- package/dist/knowledge-scope.d.ts +41 -0
- package/dist/knowledge-scope.js +85 -0
- package/dist/lsp/client.d.ts +56 -0
- package/dist/lsp/client.js +248 -0
- package/dist/lsp/index.d.ts +4 -0
- package/dist/lsp/index.js +4 -0
- package/dist/lsp/language.d.ts +9 -0
- package/dist/lsp/language.js +41 -0
- package/dist/lsp/manager.d.ts +34 -0
- package/dist/lsp/manager.js +79 -0
- package/dist/lsp/server.d.ts +27 -0
- package/dist/lsp/server.js +158 -0
- package/dist/lsp/workspace.d.ts +9 -0
- package/dist/lsp/workspace.js +52 -0
- package/dist/mcp/config.d.ts +77 -0
- package/dist/mcp/config.js +313 -0
- package/dist/mcp/index.d.ts +6 -0
- package/dist/mcp/index.js +3 -0
- package/dist/mcp/manager.d.ts +104 -0
- package/dist/mcp/manager.js +693 -0
- package/dist/mcp/state.d.ts +35 -0
- package/dist/mcp/state.js +94 -0
- package/dist/mcp/types.d.ts +139 -0
- package/dist/mcp/types.js +1 -0
- package/dist/onboarding/custom-packs.d.ts +7 -0
- package/dist/onboarding/custom-packs.js +17 -0
- package/dist/onboarding/custom-providers.d.ts +4 -0
- package/dist/onboarding/custom-providers.js +27 -0
- package/dist/onboarding/index.d.ts +5 -0
- package/dist/onboarding/index.js +3 -0
- package/dist/onboarding/om-settings.d.ts +47 -0
- package/dist/onboarding/om-settings.js +80 -0
- package/dist/onboarding/pack-activation.d.ts +43 -0
- package/dist/onboarding/pack-activation.js +105 -0
- package/dist/onboarding/packs.d.ts +106 -0
- package/dist/onboarding/packs.js +283 -0
- package/dist/onboarding/settings.d.ts +563 -0
- package/dist/onboarding/settings.js +1110 -0
- package/dist/permissions.d.ts +55 -0
- package/dist/permissions.js +139 -0
- package/dist/platform/index.d.ts +74 -0
- package/dist/platform/index.js +199 -0
- package/dist/plugin.d.ts +156 -0
- package/dist/plugin.js +27 -0
- package/dist/plugins/dependencies.d.ts +9 -0
- package/dist/plugins/dependencies.js +84 -0
- package/dist/plugins/install.d.ts +21 -0
- package/dist/plugins/install.js +187 -0
- package/dist/plugins/loader.d.ts +25 -0
- package/dist/plugins/loader.js +264 -0
- package/dist/plugins/manager.d.ts +115 -0
- package/dist/plugins/manager.js +507 -0
- package/dist/plugins/manifest.d.ts +14 -0
- package/dist/plugins/manifest.js +47 -0
- package/dist/plugins/package-link.d.ts +3 -0
- package/dist/plugins/package-link.js +58 -0
- package/dist/plugins/paths.d.ts +10 -0
- package/dist/plugins/paths.js +22 -0
- package/dist/plugins/registry.d.ts +8 -0
- package/dist/plugins/registry.js +109 -0
- package/dist/plugins/scaffold.d.ts +10 -0
- package/dist/plugins/scaffold.js +115 -0
- package/dist/plugins/signal-lane.d.ts +59 -0
- package/dist/plugins/signal-lane.js +163 -0
- package/dist/plugins/types.d.ts +95 -0
- package/dist/plugins/types.js +1 -0
- package/dist/process-memory-diagnostics.d.ts +136 -0
- package/dist/process-memory-diagnostics.js +497 -0
- package/dist/processors/plan-rejection-abort.d.ts +16 -0
- package/dist/processors/plan-rejection-abort.js +62 -0
- package/dist/providers/amazon-bedrock-gateway.d.ts +47 -0
- package/dist/providers/amazon-bedrock-gateway.js +142 -0
- package/dist/providers/amazon-bedrock.d.ts +28 -0
- package/dist/providers/amazon-bedrock.js +99 -0
- package/dist/providers/anthropic-prompt-cache.d.ts +19 -0
- package/dist/providers/anthropic-prompt-cache.js +8 -0
- package/dist/providers/anthropic-thinking.d.ts +5 -0
- package/dist/providers/anthropic-thinking.js +22 -0
- package/dist/providers/claude-max.d.ts +67 -0
- package/dist/providers/claude-max.js +232 -0
- package/dist/providers/github-copilot-gateway.d.ts +35 -0
- package/dist/providers/github-copilot-gateway.js +58 -0
- package/dist/providers/github-copilot.d.ts +60 -0
- package/dist/providers/github-copilot.js +320 -0
- package/dist/providers/google-thinking.d.ts +31 -0
- package/dist/providers/google-thinking.js +64 -0
- package/dist/providers/google-vertex-gateway.d.ts +23 -0
- package/dist/providers/google-vertex-gateway.js +49 -0
- package/dist/providers/google-vertex.d.ts +6 -0
- package/dist/providers/google-vertex.js +51 -0
- package/dist/providers/kimi-coding.d.ts +14 -0
- package/dist/providers/kimi-coding.js +80 -0
- package/dist/providers/model-ids.d.ts +53 -0
- package/dist/providers/model-ids.js +132 -0
- package/dist/providers/openai-codex.d.ts +114 -0
- package/dist/providers/openai-codex.js +427 -0
- package/dist/providers/provider-thinking.d.ts +23 -0
- package/dist/providers/provider-thinking.js +61 -0
- package/dist/providers/thinking-request.d.ts +14 -0
- package/dist/providers/thinking-request.js +87 -0
- package/dist/providers/xai.d.ts +33 -0
- package/dist/providers/xai.js +72 -0
- package/dist/schedules/index.d.ts +10 -0
- package/dist/schedules/index.js +6 -0
- package/dist/schedules/interval.d.ts +49 -0
- package/dist/schedules/interval.js +212 -0
- package/dist/schedules/prompt.d.ts +36 -0
- package/dist/schedules/prompt.js +36 -0
- package/dist/schedules/run-script.d.ts +8 -0
- package/dist/schedules/run-script.js +80 -0
- package/dist/schedules/scheduler.d.ts +101 -0
- package/dist/schedules/scheduler.js +167 -0
- package/dist/schedules/tools.d.ts +57 -0
- package/dist/schedules/tools.js +217 -0
- package/dist/schema.d.ts +499 -0
- package/dist/schema.js +131 -0
- package/dist/theme-palette.d.ts +17 -0
- package/dist/theme-palette.js +18 -0
- package/dist/thinking-catalog.d.ts +4 -0
- package/dist/thinking-catalog.js +13 -0
- package/dist/thinking.d.ts +37 -0
- package/dist/thinking.js +134 -0
- package/dist/tool-names.d.ts +77 -0
- package/dist/tool-names.js +53 -0
- package/dist/tools/index.d.ts +6 -0
- package/dist/tools/index.js +3 -0
- package/dist/tools/request-sandbox-access.d.ts +6 -0
- package/dist/tools/request-sandbox-access.js +80 -0
- package/dist/tools/utils.d.ts +20 -0
- package/dist/tools/utils.js +31 -0
- package/dist/tools/web-search.d.ts +116 -0
- package/dist/tools/web-search.js +158 -0
- package/dist/tools/workflows/create-workflow.d.ts +7 -0
- package/dist/tools/workflows/create-workflow.js +82 -0
- package/dist/tools/workflows/delete-workflow.d.ts +7 -0
- package/dist/tools/workflows/delete-workflow.js +18 -0
- package/dist/tools/workflows/ephemeral-memory.d.ts +28 -0
- package/dist/tools/workflows/ephemeral-memory.js +41 -0
- package/dist/tools/workflows/extract-json-schema.d.ts +12 -0
- package/dist/tools/workflows/extract-json-schema.js +19 -0
- package/dist/tools/workflows/get-workflow.d.ts +11 -0
- package/dist/tools/workflows/get-workflow.js +31 -0
- package/dist/tools/workflows/list-available-agents.d.ts +8 -0
- package/dist/tools/workflows/list-available-agents.js +29 -0
- package/dist/tools/workflows/list-available-classifiers.d.ts +19 -0
- package/dist/tools/workflows/list-available-classifiers.js +53 -0
- package/dist/tools/workflows/list-available-tools.d.ts +9 -0
- package/dist/tools/workflows/list-available-tools.js +37 -0
- package/dist/tools/workflows/list-available-workflows.d.ts +9 -0
- package/dist/tools/workflows/list-available-workflows.js +29 -0
- package/dist/tools/workflows/list-workflows.d.ts +9 -0
- package/dist/tools/workflows/list-workflows.js +30 -0
- package/dist/tools/workflows/run-workflow.d.ts +9 -0
- package/dist/tools/workflows/run-workflow.js +49 -0
- package/dist/tools/workflows/save-workflow.d.ts +1125 -0
- package/dist/tools/workflows/save-workflow.js +25 -0
- package/dist/tools/workflows/tool-ids.d.ts +16 -0
- package/dist/tools/workflows/tool-ids.js +17 -0
- package/dist/utils/binaries.d.ts +7 -0
- package/dist/utils/binaries.js +97 -0
- package/dist/utils/debug-log.d.ts +12 -0
- package/dist/utils/debug-log.js +56 -0
- package/dist/utils/discarding-scores-storage.d.ts +33 -0
- package/dist/utils/discarding-scores-storage.js +51 -0
- package/dist/utils/errors.d.ts +36 -0
- package/dist/utils/errors.js +215 -0
- package/dist/utils/gateway-sync.d.ts +26 -0
- package/dist/utils/gateway-sync.js +58 -0
- package/dist/utils/local-observability.d.ts +19 -0
- package/dist/utils/local-observability.js +54 -0
- package/dist/utils/maintenance-lock.d.ts +42 -0
- package/dist/utils/maintenance-lock.js +196 -0
- package/dist/utils/notification-dispatch.d.ts +74 -0
- package/dist/utils/notification-dispatch.js +128 -0
- package/dist/utils/open-url.d.ts +10 -0
- package/dist/utils/open-url.js +27 -0
- package/dist/utils/path-security.d.ts +2 -0
- package/dist/utils/path-security.js +7 -0
- package/dist/utils/plan-diff.d.ts +25 -0
- package/dist/utils/plan-diff.js +59 -0
- package/dist/utils/plans.d.ts +61 -0
- package/dist/utils/plans.js +120 -0
- package/dist/utils/project.d.ts +160 -0
- package/dist/utils/project.js +361 -0
- package/dist/utils/prune-cli.d.ts +24 -0
- package/dist/utils/prune-cli.js +124 -0
- package/dist/utils/signals-pubsub.d.ts +103 -0
- package/dist/utils/signals-pubsub.js +409 -0
- package/dist/utils/slash-command-loader.d.ts +52 -0
- package/dist/utils/slash-command-loader.js +139 -0
- package/dist/utils/slash-command-processor.d.ts +14 -0
- package/dist/utils/slash-command-processor.js +106 -0
- package/dist/utils/stdin-pipe.d.ts +33 -0
- package/dist/utils/stdin-pipe.js +93 -0
- package/dist/utils/storage-factory.d.ts +50 -0
- package/dist/utils/storage-factory.js +118 -0
- package/dist/utils/storage-maintenance.d.ts +121 -0
- package/dist/utils/storage-maintenance.js +352 -0
- package/dist/utils/thread-lock.d.ts +26 -0
- package/dist/utils/thread-lock.js +109 -0
- package/dist/utils/token-estimator.d.ts +3 -0
- package/dist/utils/token-estimator.js +19 -0
- package/dist/utils/update-check.d.ts +151 -0
- package/dist/utils/update-check.js +430 -0
- package/dist/utils/wake-session.d.ts +44 -0
- package/dist/utils/wake-session.js +83 -0
- package/dist/voice/stt-registry.d.ts +67 -0
- package/dist/voice/stt-registry.js +144 -0
- package/dist/voice/transcribe.d.ts +10 -0
- package/dist/voice/transcribe.js +75 -0
- package/dist/workflows/register-primitives.d.ts +52 -0
- package/dist/workflows/register-primitives.js +40 -0
- package/dist/workflows/service.d.ts +64 -0
- package/dist/workflows/service.js +50 -0
- package/package.json +117 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { FACTORY_CONTROLLER_ID, createFactoryClient } from "./client.js";
|
|
2
|
+
// src/factory/remote-controller.ts
|
|
3
|
+
/**
|
|
4
|
+
* The Factory-side counterpart to the local agent controller. Modes, models, and
|
|
5
|
+
* provider auth come from the Factory, never from local settings or auth storage.
|
|
6
|
+
*/
|
|
7
|
+
var RemoteController = class {
|
|
8
|
+
id = FACTORY_CONTROLLER_ID;
|
|
9
|
+
#remote;
|
|
10
|
+
#modes = [];
|
|
11
|
+
#models;
|
|
12
|
+
constructor(address, remote) {
|
|
13
|
+
this.#remote = remote ?? createFactoryClient(address).getAgentController("code");
|
|
14
|
+
}
|
|
15
|
+
/** Load the mode list; `listModes()` is synchronous so it must be primed. */
|
|
16
|
+
async connect() {
|
|
17
|
+
this.#modes = await this.#remote.listModes();
|
|
18
|
+
}
|
|
19
|
+
listModes() {
|
|
20
|
+
return this.#modes;
|
|
21
|
+
}
|
|
22
|
+
listAvailableModels() {
|
|
23
|
+
this.#models ??= this.#remote.listModels().then((models) => models);
|
|
24
|
+
this.#models.catch(() => this.#models = void 0);
|
|
25
|
+
return this.#models;
|
|
26
|
+
}
|
|
27
|
+
invalidateAvailableModelsCache() {
|
|
28
|
+
this.#models = void 0;
|
|
29
|
+
}
|
|
30
|
+
/** Auth is the Factory's: report what it reports, or assume ok and let the run surface errors. */
|
|
31
|
+
async getCurrentModelAuthStatus(session) {
|
|
32
|
+
const modelId = session.model.get();
|
|
33
|
+
const model = (await this.listAvailableModels().catch(() => [])).find((m) => m.id === modelId);
|
|
34
|
+
return model ? {
|
|
35
|
+
hasAuth: model.hasApiKey,
|
|
36
|
+
apiKeyEnvVar: model.apiKeyEnvVar
|
|
37
|
+
} : { hasAuth: true };
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
export { RemoteController };
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import type { AgentControllerModeInfo } from '@mastra/client-js';
|
|
2
|
+
import type { AgentControllerDisplayState, AgentControllerEventListener, AgentControllerRequestStateUpdater, AgentControllerThread, PermissionRules, Session } from '@mastra/core/agent-controller';
|
|
3
|
+
import type { FactoryAddress } from './client.js';
|
|
4
|
+
import { createFactoryClient } from './client.js';
|
|
5
|
+
type RemoteHandle = ReturnType<ReturnType<ReturnType<typeof createFactoryClient>['getAgentController']>['session']>;
|
|
6
|
+
type RemoteMode = AgentControllerModeInfo;
|
|
7
|
+
type Files = Array<{
|
|
8
|
+
data: string;
|
|
9
|
+
mediaType: string;
|
|
10
|
+
filename?: string;
|
|
11
|
+
}>;
|
|
12
|
+
/**
|
|
13
|
+
* Stands in for an in-process `Session` while the agent, tools, and storage
|
|
14
|
+
* run inside a Factory. Reads are served from state mirrored off the session's
|
|
15
|
+
* event stream; every action is forwarded to the Factory over HTTP.
|
|
16
|
+
*
|
|
17
|
+
* Only the surface the TUI drives is implemented. Anything else resolves to a
|
|
18
|
+
* no-op so local-only features (thread locks, grants) degrade instead of crash.
|
|
19
|
+
*/
|
|
20
|
+
export declare class RemoteSession {
|
|
21
|
+
#private;
|
|
22
|
+
constructor(address: FactoryAddress, sessionId: string, remote?: RemoteHandle);
|
|
23
|
+
/** Create/resume the remote session, hydrate the mirror, and open the event stream. */
|
|
24
|
+
connect(): Promise<void>;
|
|
25
|
+
/** Modes come from the controller; used to resolve the current mode's name and color. */
|
|
26
|
+
setModes(modes: RemoteMode[]): void;
|
|
27
|
+
disconnect(): void;
|
|
28
|
+
subscribe(listener: AgentControllerEventListener): () => void;
|
|
29
|
+
onBeforeAgentEnd(): () => void;
|
|
30
|
+
readonly identity: {
|
|
31
|
+
getResourceId: () => string;
|
|
32
|
+
getDefaultResourceId: () => string;
|
|
33
|
+
getId: () => string;
|
|
34
|
+
getOwnerId: () => string;
|
|
35
|
+
setResourceId: () => void;
|
|
36
|
+
};
|
|
37
|
+
readonly thread: {
|
|
38
|
+
getId: () => string | null;
|
|
39
|
+
isSet: () => boolean;
|
|
40
|
+
requireId: () => string;
|
|
41
|
+
ensureId: () => Promise<string>;
|
|
42
|
+
list: () => Promise<AgentControllerThread[]>;
|
|
43
|
+
getById: ({ threadId }: {
|
|
44
|
+
threadId: string;
|
|
45
|
+
}) => Promise<AgentControllerThread | null>;
|
|
46
|
+
create: ({ title }?: {
|
|
47
|
+
title?: string;
|
|
48
|
+
}) => Promise<AgentControllerThread>;
|
|
49
|
+
switch: ({ threadId }: {
|
|
50
|
+
threadId: string;
|
|
51
|
+
}) => Promise<void>;
|
|
52
|
+
clone: ({ sourceThreadId, title }?: {
|
|
53
|
+
sourceThreadId?: string;
|
|
54
|
+
title?: string;
|
|
55
|
+
}) => Promise<AgentControllerThread>;
|
|
56
|
+
rename: ({ title }: {
|
|
57
|
+
title: string;
|
|
58
|
+
}) => Promise<void>;
|
|
59
|
+
delete: ({ threadId }: {
|
|
60
|
+
threadId: string;
|
|
61
|
+
}) => Promise<void>;
|
|
62
|
+
listMessages: ({ threadId, limit }: {
|
|
63
|
+
threadId: string;
|
|
64
|
+
limit?: number;
|
|
65
|
+
}) => Promise<import("@mastra/client-js").MastraDBMessage[]>;
|
|
66
|
+
listActiveMessages: ({ limit }?: {
|
|
67
|
+
limit?: number;
|
|
68
|
+
}) => Promise<never[] | import("@mastra/client-js").MastraDBMessage[]>;
|
|
69
|
+
firstUserMessage: () => Promise<null>;
|
|
70
|
+
firstUserMessages: () => Promise<Map<any, any>>;
|
|
71
|
+
getSetting: () => Promise<undefined>;
|
|
72
|
+
getSettingOn: () => Promise<undefined>;
|
|
73
|
+
setSetting: () => Promise<void>;
|
|
74
|
+
setSettingOn: () => Promise<void>;
|
|
75
|
+
deleteSetting: () => Promise<void>;
|
|
76
|
+
cleanupSubscription: () => void;
|
|
77
|
+
detachFromCurrent: () => void;
|
|
78
|
+
clear: () => void;
|
|
79
|
+
clearAndReleaseLock: () => Promise<void>;
|
|
80
|
+
cloneToCurrentResource: ({ sourceThreadId }: {
|
|
81
|
+
sourceThreadId: string;
|
|
82
|
+
}) => Promise<AgentControllerThread>;
|
|
83
|
+
loadMetadata: () => Promise<void>;
|
|
84
|
+
};
|
|
85
|
+
readonly mode: {
|
|
86
|
+
get: () => string;
|
|
87
|
+
hasSelection: () => boolean;
|
|
88
|
+
resolve: () => {
|
|
89
|
+
id: string;
|
|
90
|
+
name?: string | undefined;
|
|
91
|
+
};
|
|
92
|
+
set: ({ modeId }: {
|
|
93
|
+
modeId: string;
|
|
94
|
+
}) => void;
|
|
95
|
+
switch: ({ modeId }: {
|
|
96
|
+
modeId: string;
|
|
97
|
+
}) => Promise<void>;
|
|
98
|
+
};
|
|
99
|
+
readonly model: {
|
|
100
|
+
get: () => string;
|
|
101
|
+
hasSelection: () => boolean;
|
|
102
|
+
displayName: () => string;
|
|
103
|
+
set: ({ modelId }: {
|
|
104
|
+
modelId: string;
|
|
105
|
+
}) => void;
|
|
106
|
+
switch: (modelId: string, options?: {
|
|
107
|
+
thinkingLevel?: any;
|
|
108
|
+
}) => Promise<void>;
|
|
109
|
+
syncFromPersisted: () => Promise<void>;
|
|
110
|
+
};
|
|
111
|
+
readonly state: {
|
|
112
|
+
get: () => Record<string, unknown>;
|
|
113
|
+
set: (updates: Record<string, unknown>) => Promise<void>;
|
|
114
|
+
setIf: (updates: Record<string, unknown>, shouldApply: () => boolean) => Promise<boolean>;
|
|
115
|
+
update: <TResult>(updater: AgentControllerRequestStateUpdater<any, TResult>) => Promise<TResult>;
|
|
116
|
+
};
|
|
117
|
+
readonly displayState: {
|
|
118
|
+
get: () => AgentControllerDisplayState;
|
|
119
|
+
clearModifiedFiles: () => void;
|
|
120
|
+
restoreTasks: () => void;
|
|
121
|
+
clearPendingSuspensions: () => void;
|
|
122
|
+
deletePendingSuspension: () => void;
|
|
123
|
+
clearPendingApprovals: () => void;
|
|
124
|
+
resetThread: () => void;
|
|
125
|
+
apply: () => void;
|
|
126
|
+
};
|
|
127
|
+
readonly run: {
|
|
128
|
+
isRunning: () => boolean;
|
|
129
|
+
getRunId: () => null;
|
|
130
|
+
getTraceId: () => null;
|
|
131
|
+
};
|
|
132
|
+
readonly stream: {
|
|
133
|
+
isActive: () => boolean;
|
|
134
|
+
isOpen: () => boolean;
|
|
135
|
+
};
|
|
136
|
+
readonly suspensions: {
|
|
137
|
+
hasPending: () => boolean;
|
|
138
|
+
get: ({ toolCallId }: {
|
|
139
|
+
toolCallId: string;
|
|
140
|
+
}) => {
|
|
141
|
+
toolCallId: string;
|
|
142
|
+
toolName: string;
|
|
143
|
+
args: unknown;
|
|
144
|
+
suspendPayload: unknown;
|
|
145
|
+
resumeSchema?: string;
|
|
146
|
+
resourceId?: string;
|
|
147
|
+
threadId?: string;
|
|
148
|
+
runId?: string;
|
|
149
|
+
} | undefined;
|
|
150
|
+
has: ({ toolCallId }: {
|
|
151
|
+
toolCallId: string;
|
|
152
|
+
}) => boolean;
|
|
153
|
+
delete: () => void;
|
|
154
|
+
};
|
|
155
|
+
readonly permissions: {
|
|
156
|
+
getRules: () => PermissionRules;
|
|
157
|
+
setForCategory: ({ category, policy }: {
|
|
158
|
+
category: any;
|
|
159
|
+
policy: any;
|
|
160
|
+
}) => Promise<void>;
|
|
161
|
+
setForTool: ({ toolName, policy }: {
|
|
162
|
+
toolName: string;
|
|
163
|
+
policy: any;
|
|
164
|
+
}) => Promise<void>;
|
|
165
|
+
};
|
|
166
|
+
getCurrentRunId(): string | null;
|
|
167
|
+
getTags(): Record<string, string>;
|
|
168
|
+
getTokenUsage(): import("@mastra/core/harness").TokenUsage;
|
|
169
|
+
getGrants(): {
|
|
170
|
+
categories: never[];
|
|
171
|
+
tools: never[];
|
|
172
|
+
};
|
|
173
|
+
sendMessage({ content, files }: {
|
|
174
|
+
content: string;
|
|
175
|
+
files?: Files;
|
|
176
|
+
}): Promise<void>;
|
|
177
|
+
queueMessage({ content }: {
|
|
178
|
+
content: string;
|
|
179
|
+
}): Promise<void>;
|
|
180
|
+
sendSignal(input: Parameters<Session['sendSignal']>[0]): {
|
|
181
|
+
id: `${string}-${string}-${string}-${string}-${string}`;
|
|
182
|
+
type: 'user';
|
|
183
|
+
accepted: Promise<{
|
|
184
|
+
accepted: true;
|
|
185
|
+
}>;
|
|
186
|
+
persisted: Promise<void>;
|
|
187
|
+
};
|
|
188
|
+
steer({ content }: {
|
|
189
|
+
content: string;
|
|
190
|
+
}): Promise<void>;
|
|
191
|
+
followUp({ content }: {
|
|
192
|
+
content: string;
|
|
193
|
+
}): Promise<void>;
|
|
194
|
+
respondToToolApproval({ decision, toolCallId, }: {
|
|
195
|
+
decision: 'approve' | 'decline' | 'always_allow_category';
|
|
196
|
+
toolCallId: string;
|
|
197
|
+
}): {
|
|
198
|
+
accepted: true;
|
|
199
|
+
};
|
|
200
|
+
respondToToolSuspension({ resumeData, toolCallId }: {
|
|
201
|
+
resumeData: unknown;
|
|
202
|
+
toolCallId?: string;
|
|
203
|
+
}): Promise<void>;
|
|
204
|
+
claimToolResponse(): boolean;
|
|
205
|
+
releaseToolResponse(): void;
|
|
206
|
+
abort(): void;
|
|
207
|
+
abortRun(): void;
|
|
208
|
+
}
|
|
209
|
+
export {};
|
|
210
|
+
//# sourceMappingURL=remote-session.d.ts.map
|
|
@@ -0,0 +1,415 @@
|
|
|
1
|
+
import { createFactoryClient } from "./client.js";
|
|
2
|
+
import { randomUUID } from "crypto";
|
|
3
|
+
import { defaultDisplayState } from "@mastra/core/agent-controller";
|
|
4
|
+
// src/factory/remote-session.ts
|
|
5
|
+
const MAP_FIELDS = [
|
|
6
|
+
"activeTools",
|
|
7
|
+
"toolInputBuffers",
|
|
8
|
+
"pendingSuspensions",
|
|
9
|
+
"pendingApprovals",
|
|
10
|
+
"activeSubagents",
|
|
11
|
+
"modifiedFiles"
|
|
12
|
+
];
|
|
13
|
+
/** The wire flattens the display state's Maps to objects; restore them. */
|
|
14
|
+
function hydrateDisplayState(wire) {
|
|
15
|
+
const state = {
|
|
16
|
+
...defaultDisplayState(),
|
|
17
|
+
...wire
|
|
18
|
+
};
|
|
19
|
+
for (const field of MAP_FIELDS) {
|
|
20
|
+
const value = wire[field];
|
|
21
|
+
state[field] = value instanceof Map ? value : new Map(Object.entries(value ?? {}));
|
|
22
|
+
}
|
|
23
|
+
return state;
|
|
24
|
+
}
|
|
25
|
+
/** The wire flattens errors to `{ name, message }`; restore them. */
|
|
26
|
+
function hydrateEvent(event) {
|
|
27
|
+
const out = { ...event };
|
|
28
|
+
if (out.displayState && typeof out.displayState === "object") out.displayState = hydrateDisplayState(out.displayState);
|
|
29
|
+
const error = out.error;
|
|
30
|
+
if (error && typeof error === "object" && !(error instanceof Error)) out.error = Object.assign(new Error(error.message ?? "Remote error"), { name: error.name ?? "Error" });
|
|
31
|
+
return out;
|
|
32
|
+
}
|
|
33
|
+
function toThread(thread, resourceId) {
|
|
34
|
+
const date = (value) => value ? new Date(value) : /* @__PURE__ */ new Date();
|
|
35
|
+
return {
|
|
36
|
+
id: thread.id,
|
|
37
|
+
resourceId: thread.resourceId ?? resourceId,
|
|
38
|
+
title: thread.title ?? "",
|
|
39
|
+
createdAt: date(thread.createdAt),
|
|
40
|
+
updatedAt: date(thread.updatedAt)
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Stands in for an in-process `Session` while the agent, tools, and storage
|
|
45
|
+
* run inside a Factory. Reads are served from state mirrored off the session's
|
|
46
|
+
* event stream; every action is forwarded to the Factory over HTTP.
|
|
47
|
+
*
|
|
48
|
+
* Only the surface the TUI drives is implemented. Anything else resolves to a
|
|
49
|
+
* no-op so local-only features (thread locks, grants) degrade instead of crash.
|
|
50
|
+
*/
|
|
51
|
+
var RemoteSession = class {
|
|
52
|
+
#remote;
|
|
53
|
+
#sessionId;
|
|
54
|
+
/** Whose threads and memory the session works on; the Factory reports it when the session is created. */
|
|
55
|
+
#resourceId;
|
|
56
|
+
#listeners = /* @__PURE__ */ new Set();
|
|
57
|
+
#unsubscribe;
|
|
58
|
+
#threadId = null;
|
|
59
|
+
#modeId = "";
|
|
60
|
+
#modelId = "";
|
|
61
|
+
#running = false;
|
|
62
|
+
#state = {};
|
|
63
|
+
#displayState = defaultDisplayState();
|
|
64
|
+
#modes = [];
|
|
65
|
+
#permissionRules = {
|
|
66
|
+
categories: {},
|
|
67
|
+
tools: {}
|
|
68
|
+
};
|
|
69
|
+
#pendingUserIds = [];
|
|
70
|
+
#userIdMap = /* @__PURE__ */ new Map();
|
|
71
|
+
constructor(address, sessionId, remote) {
|
|
72
|
+
this.#sessionId = sessionId;
|
|
73
|
+
this.#resourceId = sessionId;
|
|
74
|
+
this.#remote = remote ?? createFactoryClient(address).getAgentController("code").session(sessionId);
|
|
75
|
+
}
|
|
76
|
+
/** Create/resume the remote session, hydrate the mirror, and open the event stream. */
|
|
77
|
+
async connect() {
|
|
78
|
+
const created = await this.#remote.create();
|
|
79
|
+
if (created?.resourceId) this.#resourceId = created.resourceId;
|
|
80
|
+
await Promise.all([this.#hydrate(), this.#refreshPermissions()]);
|
|
81
|
+
const subscription = await this.#remote.subscribe({
|
|
82
|
+
reconnect: true,
|
|
83
|
+
onEvent: (event) => this.#receive(hydrateEvent(event)),
|
|
84
|
+
onReconnect: () => void this.#hydrate().catch(() => {})
|
|
85
|
+
});
|
|
86
|
+
this.#unsubscribe = subscription.unsubscribe;
|
|
87
|
+
}
|
|
88
|
+
/** Modes come from the controller; used to resolve the current mode's name and color. */
|
|
89
|
+
setModes(modes) {
|
|
90
|
+
this.#modes = modes;
|
|
91
|
+
}
|
|
92
|
+
disconnect() {
|
|
93
|
+
this.#unsubscribe?.();
|
|
94
|
+
this.#unsubscribe = void 0;
|
|
95
|
+
}
|
|
96
|
+
async #hydrate() {
|
|
97
|
+
const snapshot = await this.#remote.state();
|
|
98
|
+
this.#threadId = snapshot.threadId ?? null;
|
|
99
|
+
this.#modeId = snapshot.modeId;
|
|
100
|
+
this.#modelId = snapshot.modelId;
|
|
101
|
+
this.#running = Boolean(snapshot.running);
|
|
102
|
+
if (snapshot.settings) this.#state = {
|
|
103
|
+
...this.#state,
|
|
104
|
+
...snapshot.settings
|
|
105
|
+
};
|
|
106
|
+
this.#displayState = {
|
|
107
|
+
...this.#displayState,
|
|
108
|
+
...snapshot.tasks ? { tasks: snapshot.tasks } : {},
|
|
109
|
+
...snapshot.tokenUsage ? { tokenUsage: snapshot.tokenUsage } : {}
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
async #refreshPermissions() {
|
|
113
|
+
const rules = await this.#remote.getPermissions();
|
|
114
|
+
this.#permissionRules = {
|
|
115
|
+
categories: rules.categories ?? {},
|
|
116
|
+
tools: rules.tools ?? {}
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
/** Surface a failed remote command in the transcript instead of dropping it. */
|
|
120
|
+
#emitError(message) {
|
|
121
|
+
this.#receive({
|
|
122
|
+
type: "error",
|
|
123
|
+
error: new Error(message)
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* The TUI renders a user message as soon as it is sent, keyed by the id
|
|
128
|
+
* `sendSignal` returned. The Factory echoes it back under its own id, so map
|
|
129
|
+
* that echo onto the local id to keep it from rendering twice.
|
|
130
|
+
*/
|
|
131
|
+
#adoptLocalUserId(e) {
|
|
132
|
+
const message = e.message;
|
|
133
|
+
const isUser = message?.role === "user" || message?.role === "signal" && message.content?.metadata?.signal?.type === "user";
|
|
134
|
+
if (!message?.id || !isUser) return;
|
|
135
|
+
let localId = this.#userIdMap.get(message.id);
|
|
136
|
+
if (!localId && e.type === "message_start") {
|
|
137
|
+
localId = this.#pendingUserIds.shift();
|
|
138
|
+
if (localId) this.#userIdMap.set(message.id, localId);
|
|
139
|
+
}
|
|
140
|
+
if (localId) e.message = {
|
|
141
|
+
...message,
|
|
142
|
+
id: localId
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
#receive(event) {
|
|
146
|
+
const e = event;
|
|
147
|
+
if (e.type === "message_start" || e.type === "message_update" || e.type === "message_end") this.#adoptLocalUserId(e);
|
|
148
|
+
switch (e.type) {
|
|
149
|
+
case "mode_changed":
|
|
150
|
+
this.#modeId = e.modeId;
|
|
151
|
+
break;
|
|
152
|
+
case "model_changed":
|
|
153
|
+
this.#modelId = e.modelId;
|
|
154
|
+
break;
|
|
155
|
+
case "thread_changed":
|
|
156
|
+
this.#threadId = e.threadId;
|
|
157
|
+
break;
|
|
158
|
+
case "thread_created":
|
|
159
|
+
this.#threadId = e.thread.id;
|
|
160
|
+
break;
|
|
161
|
+
case "state_changed":
|
|
162
|
+
this.#state = {
|
|
163
|
+
...this.#state,
|
|
164
|
+
...e.state
|
|
165
|
+
};
|
|
166
|
+
break;
|
|
167
|
+
case "display_state_changed":
|
|
168
|
+
this.#displayState = e.displayState;
|
|
169
|
+
break;
|
|
170
|
+
case "agent_start":
|
|
171
|
+
this.#running = true;
|
|
172
|
+
break;
|
|
173
|
+
case "agent_end": this.#running = false;
|
|
174
|
+
}
|
|
175
|
+
for (const listener of this.#listeners) Promise.resolve(listener(event)).catch(() => {});
|
|
176
|
+
}
|
|
177
|
+
subscribe(listener) {
|
|
178
|
+
this.#listeners.add(listener);
|
|
179
|
+
return () => this.#listeners.delete(listener);
|
|
180
|
+
}
|
|
181
|
+
onBeforeAgentEnd() {
|
|
182
|
+
return () => {};
|
|
183
|
+
}
|
|
184
|
+
identity = {
|
|
185
|
+
getResourceId: () => this.#resourceId,
|
|
186
|
+
getDefaultResourceId: () => this.#resourceId,
|
|
187
|
+
getId: () => this.#sessionId,
|
|
188
|
+
getOwnerId: () => this.#sessionId,
|
|
189
|
+
setResourceId: () => {}
|
|
190
|
+
};
|
|
191
|
+
thread = (() => {
|
|
192
|
+
const remote = () => this.#remote;
|
|
193
|
+
const resourceId = () => this.#resourceId;
|
|
194
|
+
return {
|
|
195
|
+
getId: () => this.#threadId,
|
|
196
|
+
isSet: () => this.#threadId !== null,
|
|
197
|
+
requireId: () => {
|
|
198
|
+
if (!this.#threadId) throw new Error("No active thread");
|
|
199
|
+
return this.#threadId;
|
|
200
|
+
},
|
|
201
|
+
ensureId: async () => {
|
|
202
|
+
if (!this.#threadId) await this.thread.create();
|
|
203
|
+
return this.#threadId;
|
|
204
|
+
},
|
|
205
|
+
list: async () => (await remote().listThreads()).map((t) => toThread(t, resourceId())),
|
|
206
|
+
getById: async ({ threadId }) => (await this.thread.list()).find((t) => t.id === threadId) ?? null,
|
|
207
|
+
create: async ({ title } = {}) => {
|
|
208
|
+
const thread = toThread(await remote().createThread(title), resourceId());
|
|
209
|
+
this.#threadId = thread.id;
|
|
210
|
+
return thread;
|
|
211
|
+
},
|
|
212
|
+
switch: async ({ threadId }) => {
|
|
213
|
+
await remote().switchThread(threadId);
|
|
214
|
+
this.#threadId = threadId;
|
|
215
|
+
},
|
|
216
|
+
clone: async ({ sourceThreadId, title } = {}) => {
|
|
217
|
+
const thread = toThread(await remote().cloneThread({
|
|
218
|
+
sourceThreadId,
|
|
219
|
+
title
|
|
220
|
+
}), resourceId());
|
|
221
|
+
this.#threadId = thread.id;
|
|
222
|
+
return thread;
|
|
223
|
+
},
|
|
224
|
+
rename: async ({ title }) => {
|
|
225
|
+
if (this.#threadId) await remote().renameThread(this.#threadId, title);
|
|
226
|
+
},
|
|
227
|
+
delete: async ({ threadId }) => {
|
|
228
|
+
await remote().deleteThread(threadId);
|
|
229
|
+
if (this.#threadId === threadId) this.#threadId = null;
|
|
230
|
+
},
|
|
231
|
+
listMessages: ({ threadId, limit }) => remote().listMessages(threadId, limit),
|
|
232
|
+
listActiveMessages: async ({ limit } = {}) => this.#threadId ? remote().listMessages(this.#threadId, limit) : [],
|
|
233
|
+
firstUserMessage: async () => null,
|
|
234
|
+
firstUserMessages: async () => /* @__PURE__ */ new Map(),
|
|
235
|
+
getSetting: async () => void 0,
|
|
236
|
+
getSettingOn: async () => void 0,
|
|
237
|
+
setSetting: async () => {},
|
|
238
|
+
setSettingOn: async () => {},
|
|
239
|
+
deleteSetting: async () => {},
|
|
240
|
+
cleanupSubscription: () => {},
|
|
241
|
+
detachFromCurrent: () => {},
|
|
242
|
+
clear: () => {
|
|
243
|
+
this.#threadId = null;
|
|
244
|
+
},
|
|
245
|
+
clearAndReleaseLock: async () => {},
|
|
246
|
+
cloneToCurrentResource: async ({ sourceThreadId }) => this.thread.clone({ sourceThreadId }),
|
|
247
|
+
loadMetadata: async () => {}
|
|
248
|
+
};
|
|
249
|
+
})();
|
|
250
|
+
mode = {
|
|
251
|
+
get: () => this.#modeId,
|
|
252
|
+
hasSelection: () => Boolean(this.#modeId),
|
|
253
|
+
resolve: () => this.#modes.find((mode) => mode.id === this.#modeId) ?? {
|
|
254
|
+
id: this.#modeId,
|
|
255
|
+
name: this.#modeId
|
|
256
|
+
},
|
|
257
|
+
set: ({ modeId }) => {
|
|
258
|
+
this.#modeId = modeId;
|
|
259
|
+
},
|
|
260
|
+
switch: async ({ modeId }) => {
|
|
261
|
+
await this.#remote.switchMode(modeId);
|
|
262
|
+
this.#modeId = modeId;
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
model = {
|
|
266
|
+
get: () => this.#modelId,
|
|
267
|
+
hasSelection: () => Boolean(this.#modelId),
|
|
268
|
+
displayName: () => this.#modelId,
|
|
269
|
+
set: ({ modelId }) => {
|
|
270
|
+
this.#modelId = modelId;
|
|
271
|
+
},
|
|
272
|
+
switch: async (modelId, options = {}) => {
|
|
273
|
+
await this.#remote.switchModel(modelId, options);
|
|
274
|
+
this.#modelId = modelId;
|
|
275
|
+
},
|
|
276
|
+
syncFromPersisted: async () => {}
|
|
277
|
+
};
|
|
278
|
+
state = {
|
|
279
|
+
get: () => this.#state,
|
|
280
|
+
set: async (updates) => {
|
|
281
|
+
this.#state = {
|
|
282
|
+
...this.#state,
|
|
283
|
+
...updates
|
|
284
|
+
};
|
|
285
|
+
await this.#remote.setState(updates);
|
|
286
|
+
},
|
|
287
|
+
setIf: async (updates, shouldApply) => {
|
|
288
|
+
if (!shouldApply()) return false;
|
|
289
|
+
await this.state.set(updates);
|
|
290
|
+
return true;
|
|
291
|
+
},
|
|
292
|
+
update: async (updater) => {
|
|
293
|
+
const { updates, result } = await updater(this.#state);
|
|
294
|
+
if (updates) await this.state.set(updates);
|
|
295
|
+
return result;
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
displayState = {
|
|
299
|
+
get: () => this.#displayState,
|
|
300
|
+
clearModifiedFiles: () => {
|
|
301
|
+
this.#displayState = {
|
|
302
|
+
...this.#displayState,
|
|
303
|
+
modifiedFiles: /* @__PURE__ */ new Map()
|
|
304
|
+
};
|
|
305
|
+
},
|
|
306
|
+
restoreTasks: () => {},
|
|
307
|
+
clearPendingSuspensions: () => {},
|
|
308
|
+
deletePendingSuspension: () => {},
|
|
309
|
+
clearPendingApprovals: () => {},
|
|
310
|
+
resetThread: () => {},
|
|
311
|
+
apply: () => {}
|
|
312
|
+
};
|
|
313
|
+
run = {
|
|
314
|
+
isRunning: () => this.#running,
|
|
315
|
+
getRunId: () => null,
|
|
316
|
+
getTraceId: () => null
|
|
317
|
+
};
|
|
318
|
+
stream = {
|
|
319
|
+
isActive: () => this.#running,
|
|
320
|
+
isOpen: () => this.#running
|
|
321
|
+
};
|
|
322
|
+
suspensions = {
|
|
323
|
+
hasPending: () => this.#displayState.pendingSuspensions.size > 0,
|
|
324
|
+
get: ({ toolCallId }) => this.#displayState.pendingSuspensions.get(toolCallId),
|
|
325
|
+
has: ({ toolCallId }) => this.#displayState.pendingSuspensions.has(toolCallId),
|
|
326
|
+
delete: () => {}
|
|
327
|
+
};
|
|
328
|
+
permissions = {
|
|
329
|
+
getRules: () => this.#permissionRules,
|
|
330
|
+
setForCategory: async ({ category, policy }) => {
|
|
331
|
+
await this.#remote.setPermissionForCategory(category, policy);
|
|
332
|
+
await this.#refreshPermissions();
|
|
333
|
+
},
|
|
334
|
+
setForTool: async ({ toolName, policy }) => {
|
|
335
|
+
await this.#remote.setPermissionForTool(toolName, policy);
|
|
336
|
+
await this.#refreshPermissions();
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
getCurrentRunId() {
|
|
340
|
+
return null;
|
|
341
|
+
}
|
|
342
|
+
getTags() {
|
|
343
|
+
return {};
|
|
344
|
+
}
|
|
345
|
+
getTokenUsage() {
|
|
346
|
+
return this.#displayState.tokenUsage;
|
|
347
|
+
}
|
|
348
|
+
getGrants() {
|
|
349
|
+
return {
|
|
350
|
+
categories: [],
|
|
351
|
+
tools: []
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
async sendMessage({ content, files }) {
|
|
355
|
+
await this.#remote.sendMessage({
|
|
356
|
+
content,
|
|
357
|
+
files
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
async queueMessage({ content }) {
|
|
361
|
+
await this.#remote.followUp(content);
|
|
362
|
+
}
|
|
363
|
+
sendSignal(input) {
|
|
364
|
+
const content = "content" in input ? input.content : void 0;
|
|
365
|
+
const text = typeof content === "string" ? content : Array.isArray(content) ? content.map((part) => typeof part === "string" ? part : part?.text ?? "").join("") : JSON.stringify(content);
|
|
366
|
+
const files = "files" in input ? input.files : void 0;
|
|
367
|
+
const message = files?.length ? {
|
|
368
|
+
content: text,
|
|
369
|
+
files
|
|
370
|
+
} : text;
|
|
371
|
+
const id = randomUUID();
|
|
372
|
+
this.#pendingUserIds.push(id);
|
|
373
|
+
const sent = this.#running ? this.#remote.followUp(message) : this.#remote.sendMessage(message);
|
|
374
|
+
sent.catch(() => {
|
|
375
|
+
this.#pendingUserIds = this.#pendingUserIds.filter((pending) => pending !== id);
|
|
376
|
+
});
|
|
377
|
+
const accepted = sent.then(() => ({ accepted: true }));
|
|
378
|
+
accepted.catch(() => {});
|
|
379
|
+
return {
|
|
380
|
+
id,
|
|
381
|
+
type: "user",
|
|
382
|
+
accepted,
|
|
383
|
+
persisted: sent
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
async steer({ content }) {
|
|
387
|
+
await this.#remote.steer(content);
|
|
388
|
+
}
|
|
389
|
+
async followUp({ content }) {
|
|
390
|
+
await this.#remote.followUp(content);
|
|
391
|
+
}
|
|
392
|
+
respondToToolApproval({ decision, toolCallId }) {
|
|
393
|
+
(async () => {
|
|
394
|
+
const ack = await this.#remote.approveTool(toolCallId, decision !== "decline", { alwaysAllowCategory: decision === "always_allow_category" });
|
|
395
|
+
if (ack && "accepted" in ack && ack.accepted === false) this.#emitError(`Tool approval was not applied: ${ack.reason ?? "rejected"}`);
|
|
396
|
+
})().catch((error) => this.#emitError(`Tool approval failed: ${error instanceof Error ? error.message : String(error)}`));
|
|
397
|
+
return { accepted: true };
|
|
398
|
+
}
|
|
399
|
+
async respondToToolSuspension({ resumeData, toolCallId }) {
|
|
400
|
+
const id = toolCallId ?? this.#displayState.pendingSuspensions.keys().next().value;
|
|
401
|
+
if (!id) throw new Error("No pending tool suspension to respond to");
|
|
402
|
+
await this.#remote.respondToToolSuspension(id, resumeData);
|
|
403
|
+
}
|
|
404
|
+
claimToolResponse() {
|
|
405
|
+
return true;
|
|
406
|
+
}
|
|
407
|
+
releaseToolResponse() {}
|
|
408
|
+
abort() {
|
|
409
|
+
this.#remote.abort().catch((error) => this.#emitError(`Abort failed: ${error instanceof Error ? error.message : String(error)}`));
|
|
410
|
+
}
|
|
411
|
+
abortRun() {
|
|
412
|
+
this.abort();
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
export { RemoteSession };
|