@agent-native/core 0.221.0-same-host-mcp-20261027-20261027081850 → 0.221.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/a2a/server.js +4 -4
- package/dist/a2a/task-lifecycle.d.ts +12 -12
- package/dist/a2a/task-lifecycle.js +10 -12
- package/dist/a2a/task-store.js +81 -228
- package/dist/action-caller.d.ts +3 -0
- package/dist/action-caller.js +8 -0
- package/dist/action.d.ts +1 -0
- package/dist/agent/engine/ai-sdk-engine.js +3 -3
- package/dist/agent/engine/anthropic-engine.js +3 -3
- package/dist/agent/engine/credential-owner.d.ts +3 -0
- package/dist/agent/engine/credential-owner.js +9 -0
- package/dist/agent/engine/registry.js +28 -2
- package/dist/agent/harness/acp-adapter.d.ts +1 -0
- package/dist/agent/harness/acp-adapter.js +36 -5
- package/dist/agent/harness/background.d.ts +5 -1
- package/dist/agent/harness/background.js +4 -3
- package/dist/agent/harness/lifecycle.d.ts +2 -0
- package/dist/agent/harness/lifecycle.js +452 -84
- package/dist/agent/harness/run-policy.d.ts +5 -0
- package/dist/agent/harness/run-policy.js +70 -0
- package/dist/agent/harness/runner.js +89 -73
- package/dist/agent/harness/store.d.ts +10 -1
- package/dist/agent/harness/store.js +91 -12
- package/dist/agent/harness/turn-driver.d.ts +12 -0
- package/dist/agent/harness/turn-driver.js +42 -0
- package/dist/agent/harness/types.d.ts +11 -0
- package/dist/agent/production-agent.d.ts +9 -0
- package/dist/agent/production-agent.js +153 -41
- package/dist/agent/run-manager.d.ts +4 -0
- package/dist/agent/run-manager.js +23 -7
- package/dist/agent/run-store.d.ts +3 -1
- package/dist/agent/run-store.fencing.native-harness.fixture.test.support.js +34 -0
- package/dist/agent/run-store.fencing.worker.test.support.d.ts +1 -0
- package/dist/agent/{run-store.fencing.worker.js → run-store.fencing.worker.test.support.js} +337 -4
- package/dist/agent/run-store.js +89 -17
- package/dist/app-config/clips.d.ts +10 -0
- package/dist/app-config/clips.js +24 -0
- package/dist/app-config/index.d.ts +1 -1
- package/dist/app-config/index.js +1 -1
- package/dist/app-config/schema.d.ts +1 -0
- package/dist/appearance/actions/set-theme-family.js +16 -2
- package/dist/appearance/theme-family.d.ts +11 -1
- package/dist/appearance/theme-family.js +21 -2
- package/dist/automations/outside-origin.d.ts +13 -0
- package/dist/automations/outside-origin.js +23 -0
- package/dist/automations/service.d.ts +4 -2
- package/dist/automations/service.js +11 -8
- package/dist/cli/code-agent-executor.js +5 -16
- package/dist/cli/create.d.ts +11 -2
- package/dist/cli/create.js +121 -32
- package/dist/cli/skills-content/turn-into-app-skill.d.ts +4 -3
- package/dist/cli/skills-content/turn-into-app-skill.js +143 -36
- package/dist/cli/skills.d.ts +3 -0
- package/dist/cli/skills.js +4 -1
- package/dist/cli/template-sync.js +4 -4
- package/dist/cli/upgrade.d.ts +1 -0
- package/dist/cli/upgrade.js +207 -2
- package/dist/client/chat/agentkit-agent-native.js +23 -3
- package/dist/client/mcp-approval.d.ts +53 -0
- package/dist/client/mcp-approval.js +81 -0
- package/dist/client/onboarding/use-onboarding.js +6 -4
- package/dist/client/resources/mcp-integration-catalog.js +19 -0
- package/dist/client/theme-family.d.ts +2 -1
- package/dist/client/theme-family.js +271 -32
- package/dist/client/theme.js +3 -2
- package/dist/code-agents/background-controller.js +1 -13
- package/dist/code-agents/prompt-attachments.d.ts +11 -0
- package/dist/code-agents/prompt-attachments.js +103 -6
- package/dist/collab/awareness-store.d.ts +8 -0
- package/dist/collab/awareness-store.js +9 -1
- package/dist/collab/index.d.ts +1 -1
- package/dist/collab/index.js +1 -1
- package/dist/collab/routes.d.ts +1 -1
- package/dist/collab/struct-routes.d.ts +1 -1
- package/dist/config.d.ts +13 -3
- package/dist/config.js +64 -1
- package/dist/db/client.d.ts +8 -6
- package/dist/db/client.js +56 -17
- package/dist/db/create-get-db.js +6 -1
- package/dist/db/index.d.ts +2 -1
- package/dist/db/index.js +1 -0
- package/dist/db/schema-snapshot.generated.js +9 -2
- package/dist/db/sql.d.ts +28 -0
- package/dist/db/sql.js +186 -0
- package/dist/decisions/actions/decide.d.ts +4 -0
- package/dist/decisions/actions/decide.js +7 -0
- package/dist/decisions/decide.d.ts +1 -0
- package/dist/decisions/decide.js +21 -9
- package/dist/decisions/index.d.ts +4 -1
- package/dist/decisions/index.js +3 -0
- package/dist/decisions/response.d.ts +1 -0
- package/dist/decisions/response.js +36 -11
- package/dist/decisions/types.d.ts +5 -0
- package/dist/decisions/validation.js +6 -3
- package/dist/deploy/build.js +11 -5
- package/dist/file-upload/actions/upload-image.d.ts +2 -2
- package/dist/file-upload/attachment-text.d.ts +71 -0
- package/dist/file-upload/attachment-text.js +209 -0
- package/dist/file-upload/downscale-inline-image.d.ts +4 -0
- package/dist/file-upload/downscale-inline-image.js +27 -0
- package/dist/file-upload/inline-attachment-limits.d.ts +4 -0
- package/dist/file-upload/inline-attachment-limits.js +20 -1
- package/dist/file-upload/owned-attachment.d.ts +13 -1
- package/dist/file-upload/owned-attachment.js +52 -15
- package/dist/file-upload/pre-upload-attachments.js +74 -12
- package/dist/file-upload/registry.d.ts +1 -0
- package/dist/file-upload/registry.js +15 -7
- package/dist/file-upload/status.d.ts +19 -0
- package/dist/file-upload/status.js +49 -0
- package/dist/file-upload/thread-image-history.js +10 -2
- package/dist/index.browser.d.ts +1 -0
- package/dist/index.browser.js +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/ingestion/media.js +11 -5
- package/dist/jobs/actions/run-automation-now.js +2 -2
- package/dist/jobs/background-automation-runner.js +4 -4
- package/dist/jobs/frontmatter.d.ts +1 -1
- package/dist/jobs/frontmatter.js +5 -2
- package/dist/jobs/run-now.d.ts +2 -0
- package/dist/jobs/run-now.js +1 -1
- package/dist/jobs/scheduler.d.ts +2 -0
- package/dist/jobs/scheduler.js +1 -1
- package/dist/localization/automation-outcome-messages.js +22 -22
- package/dist/localization/core-messages/supplemental/ar-SA.js +1 -0
- package/dist/localization/core-messages/supplemental/de-DE.js +1 -0
- package/dist/localization/core-messages/supplemental/en-US.js +1 -0
- package/dist/localization/core-messages/supplemental/es-ES.js +1 -0
- package/dist/localization/core-messages/supplemental/fr-FR.js +1 -0
- package/dist/localization/core-messages/supplemental/hi-IN.js +1 -0
- package/dist/localization/core-messages/supplemental/ja-JP.js +1 -0
- package/dist/localization/core-messages/supplemental/ko-KR.js +1 -0
- package/dist/localization/core-messages/supplemental/pt-BR.js +1 -0
- package/dist/localization/core-messages/supplemental/zh-CN.js +1 -0
- package/dist/localization/core-messages/supplemental/zh-TW.js +1 -0
- package/dist/localization/mcp-approval-messages.d.ts +7 -1
- package/dist/localization/mcp-approval-messages.js +66 -0
- package/dist/localization/mcp-settings-messages.d.ts +1 -0
- package/dist/mcp/action-eligibility.d.ts +1 -0
- package/dist/mcp/action-eligibility.js +10 -5
- package/dist/mcp/analytics.d.ts +2 -0
- package/dist/mcp/analytics.js +10 -2
- package/dist/mcp/approval-route.d.ts +7 -0
- package/dist/mcp/approval-route.js +41 -16
- package/dist/mcp/approval-summary.d.ts +12 -2
- package/dist/mcp/approval-summary.js +128 -23
- package/dist/mcp/approval-time.d.ts +13 -3
- package/dist/mcp/approval-time.js +49 -5
- package/dist/mcp/build-server.d.ts +12 -1
- package/dist/mcp/build-server.js +157 -155
- package/dist/mcp/builtin-tools.d.ts +1 -0
- package/dist/mcp/builtin-tools.js +30 -14
- package/dist/mcp/direct-action-call.js +72 -27
- package/dist/mcp/embed-app.js +11 -6
- package/dist/mcp/embed-redaction.d.ts +10 -13
- package/dist/mcp/embed-redaction.js +227 -40
- package/dist/mcp/execute-action-call.d.ts +3 -2
- package/dist/mcp/execute-action-call.js +1 -4
- package/dist/mcp/framework-tools.d.ts +2 -2
- package/dist/mcp/oauth-route.js +102 -6
- package/dist/mcp/screen-memory-stdio.d.ts +3 -3
- package/dist/mcp/server.js +6 -0
- package/dist/mcp-client/oauth-routes.js +12 -2
- package/dist/notifications/routes.d.ts +3 -3
- package/dist/observability/failure-context.js +1 -0
- package/dist/observability/traces.js +11 -1
- package/dist/onboarding/first-run-builder-credits-experiment.d.ts +12 -0
- package/dist/onboarding/first-run-builder-credits-experiment.js +91 -0
- package/dist/org/index.d.ts +1 -1
- package/dist/provider-api/actions/custom-provider-registration.d.ts +11 -11
- package/dist/provider-api/actions/provider-api.d.ts +12 -12
- package/dist/server/action-approval.d.ts +2 -2
- package/dist/server/action-approval.js +17 -10
- package/dist/server/action-discovery.js +2 -122
- package/dist/server/action-routes.d.ts +0 -1
- package/dist/server/action-routes.js +138 -58
- package/dist/server/agent-chat/action-filters-a2a.d.ts +1 -0
- package/dist/server/agent-chat/action-filters-a2a.js +11 -1
- package/dist/server/agent-chat/framework-prompts.d.ts +1 -0
- package/dist/server/agent-chat/framework-prompts.js +22 -1
- package/dist/server/agent-chat/mcp-options.d.ts +7 -0
- package/dist/server/agent-chat/mcp-options.js +1 -0
- package/dist/server/agent-chat/plugin-options.d.ts +23 -0
- package/dist/server/agent-chat/prompt-resources.d.ts +4 -2
- package/dist/server/agent-chat/prompt-resources.js +78 -32
- package/dist/server/agent-chat-plugin.js +214 -125
- package/dist/server/agent-engine-api-key-route.d.ts +2 -2
- package/dist/server/agent-engine-ollama-models-route.d.ts +1 -1
- package/dist/server/agent-run-context.js +4 -0
- package/dist/server/attachment-actions.d.ts +14 -7
- package/dist/server/attachment-actions.js +310 -65
- package/dist/server/attribution.d.ts +2 -0
- package/dist/server/auth.d.ts +2 -1
- package/dist/server/auth.js +84 -17
- package/dist/server/better-auth-instance.js +46 -12
- package/dist/server/builder-api-auth.d.ts +1 -0
- package/dist/server/builder-api-auth.js +8 -0
- package/dist/server/builder-browser.d.ts +5 -1
- package/dist/server/builder-browser.js +80 -4
- package/dist/server/cli-wrapper-flags.d.ts +27 -0
- package/dist/server/cli-wrapper-flags.js +500 -0
- package/dist/server/consent-route.d.ts +3 -0
- package/dist/server/consent-route.js +29 -10
- package/dist/server/core-routes-plugin.js +72 -60
- package/dist/server/credential-provider.js +26 -11
- package/dist/server/edge.d.ts +3 -2
- package/dist/server/edge.js +3 -2
- package/dist/server/embed-request-origin.d.ts +4 -0
- package/dist/server/embed-request-origin.js +28 -0
- package/dist/server/embed-route.js +4 -2
- package/dist/server/embed-session.d.ts +16 -4
- package/dist/server/embed-session.js +253 -145
- package/dist/server/embedded.d.ts +2 -1
- package/dist/server/embedded.js +9 -5
- package/dist/server/filesystem-action-entry.d.ts +15 -1
- package/dist/server/filesystem-action-entry.js +153 -23
- package/dist/server/first-touch-route.d.ts +1 -1
- package/dist/server/google-oauth.d.ts +7 -0
- package/dist/server/google-oauth.js +33 -6
- package/dist/server/index.d.ts +11 -6
- package/dist/server/index.js +8 -3
- package/dist/server/magic-link-attribution.d.ts +2 -0
- package/dist/server/magic-link-attribution.js +8 -2
- package/dist/server/mcp-signup-attribution.d.ts +23 -0
- package/dist/server/mcp-signup-attribution.js +135 -0
- package/dist/server/prompts/framework-core.js +2 -1
- package/dist/server/prompts/shared-rules.d.ts +2 -0
- package/dist/server/prompts/shared-rules.js +2 -0
- package/dist/server/realtime-voice.d.ts +65 -2
- package/dist/server/realtime-voice.js +235 -36
- package/dist/server/release-migrations.js +37 -10
- package/dist/server/request-context.d.ts +17 -0
- package/dist/server/request-context.js +4 -0
- package/dist/server/request-origin.d.ts +4 -6
- package/dist/server/request-origin.js +26 -28
- package/dist/server/session-resolution-unavailable.d.ts +22 -0
- package/dist/server/session-resolution-unavailable.js +65 -0
- package/dist/server/short-lived-token.d.ts +10 -2
- package/dist/server/short-lived-token.js +12 -4
- package/dist/server/ui-action-capability.js +18 -4
- package/dist/shared/first-run-builder-credits-experiment.d.ts +13 -0
- package/dist/shared/first-run-builder-credits-experiment.js +22 -0
- package/dist/shared/index.d.ts +1 -0
- package/dist/shared/index.js +1 -0
- package/dist/shared/mcp-approval-review.d.ts +19 -0
- package/dist/shared/mcp-approval-review.js +29 -0
- package/dist/shared/reasoning-effort.d.ts +4 -0
- package/dist/shared/reasoning-effort.js +20 -0
- package/dist/sharing/access.d.ts +11 -2
- package/dist/sharing/access.js +12 -7
- package/dist/state-machine/index.d.ts +5 -8
- package/dist/state-machine/index.js +6 -2
- package/dist/templates/builder-code-starter/app/components/layout/Layout.tsx.patch +48 -18
- package/dist/templates/builder-code-starter/server/plugins/agent-chat.ts.patch +7 -6
- package/dist/templates/builder-code-starter/template-layer.json +1 -0
- package/dist/templates/chat/.agents/skills/storing-data/SKILL.md +18 -0
- package/dist/templates/chat/app/components/chat/ChatRouteContent.tsx +18 -4
- package/dist/templates/chat/app/components/home/HomePage.tsx +28 -69
- package/dist/templates/chat/app/components/layout/Layout.tsx +46 -14
- package/dist/templates/chat/app/i18n/ar-SA.ts +0 -4
- package/dist/templates/chat/app/i18n/de-DE.ts +0 -5
- package/dist/templates/chat/app/i18n/en-US.ts +0 -4
- package/dist/templates/chat/app/i18n/es-ES.ts +0 -5
- package/dist/templates/chat/app/i18n/fr-FR.ts +0 -5
- package/dist/templates/chat/app/i18n/hi-IN.ts +0 -5
- package/dist/templates/chat/app/i18n/ja-JP.ts +0 -5
- package/dist/templates/chat/app/i18n/ko-KR.ts +0 -5
- package/dist/templates/chat/app/i18n/pt-BR.ts +0 -5
- package/dist/templates/chat/app/i18n/zh-CN.ts +0 -4
- package/dist/templates/chat/app/i18n/zh-TW.ts +0 -4
- package/dist/templates/chat/app/lib/chat-paths.ts +36 -13
- package/dist/templates/chat/package.json +1 -0
- package/dist/templates/chat/server/plugins/agent-chat.ts +2 -1
- package/dist/templates/default/.agents/skills/storing-data/SKILL.md +18 -0
- package/dist/templates/factory/.agents/skills/review-latest-feedback/SKILL.md +123 -33
- package/dist/templates/headless/.agents/skills/storing-data/SKILL.md +18 -0
- package/dist/templates/workspace-core/.agents/skills/storing-data/SKILL.md +18 -0
- package/dist/templates/workspace-core/.agents/skills/turn-into-app/SKILL.md +34 -29
- package/dist/templates/workspace-core/.agents/skills/turn-into-app/references/fresh-project.md +12 -5
- package/dist/templates/workspace-core/.agents/skills/turn-into-app/references/review-loop.md +3 -2
- package/dist/templates/workspace-core/.agents/skills/turn-into-app/references/where-it-runs.md +93 -0
- package/dist/tracking/registry.js +25 -0
- package/dist/triggers/actions/manage-automation.js +6 -2
- package/dist/triggers/actions.js +14 -2
- package/dist/triggers/index.d.ts +1 -0
- package/dist/triggers/index.js +1 -0
- package/dist/vite/client.js +5 -4
- package/docs/content/authentication.mdx +2 -0
- package/docs/content/components.mdx +1 -1
- package/docs/content/decisions.mdx +1 -1
- package/docs/content/recurring-jobs.mdx +15 -0
- package/docs/content/template-chat-developers.mdx +1 -1
- package/docs/content/template-chat-features.mdx +4 -4
- package/docs/content/turn-into-app.mdx +18 -10
- package/package.json +6 -4
- package/src/templates/builder-code-starter/app/components/layout/Layout.tsx.patch +48 -18
- package/src/templates/builder-code-starter/server/plugins/agent-chat.ts.patch +7 -6
- package/src/templates/builder-code-starter/template-layer.json +1 -0
- package/src/templates/chat/.agents/skills/storing-data/SKILL.md +18 -0
- package/src/templates/chat/app/components/chat/ChatRouteContent.tsx +18 -4
- package/src/templates/chat/app/components/home/HomePage.tsx +28 -69
- package/src/templates/chat/app/components/layout/Layout.tsx +46 -14
- package/src/templates/chat/app/i18n/ar-SA.ts +0 -4
- package/src/templates/chat/app/i18n/de-DE.ts +0 -5
- package/src/templates/chat/app/i18n/en-US.ts +0 -4
- package/src/templates/chat/app/i18n/es-ES.ts +0 -5
- package/src/templates/chat/app/i18n/fr-FR.ts +0 -5
- package/src/templates/chat/app/i18n/hi-IN.ts +0 -5
- package/src/templates/chat/app/i18n/ja-JP.ts +0 -5
- package/src/templates/chat/app/i18n/ko-KR.ts +0 -5
- package/src/templates/chat/app/i18n/pt-BR.ts +0 -5
- package/src/templates/chat/app/i18n/zh-CN.ts +0 -4
- package/src/templates/chat/app/i18n/zh-TW.ts +0 -4
- package/src/templates/chat/app/lib/chat-paths.ts +36 -13
- package/src/templates/chat/package.json +1 -0
- package/src/templates/chat/server/plugins/agent-chat.ts +2 -1
- package/src/templates/default/.agents/skills/storing-data/SKILL.md +18 -0
- package/src/templates/factory/.agents/skills/review-latest-feedback/SKILL.md +123 -33
- package/src/templates/headless/.agents/skills/storing-data/SKILL.md +18 -0
- package/src/templates/workspace-core/.agents/skills/storing-data/SKILL.md +18 -0
- package/src/templates/workspace-core/.agents/skills/turn-into-app/SKILL.md +34 -29
- package/src/templates/workspace-core/.agents/skills/turn-into-app/references/fresh-project.md +12 -5
- package/src/templates/workspace-core/.agents/skills/turn-into-app/references/review-loop.md +3 -2
- package/src/templates/workspace-core/.agents/skills/turn-into-app/references/where-it-runs.md +93 -0
- package/dist/automations/mcp-origin.d.ts +0 -2
- package/dist/automations/mcp-origin.js +0 -10
- /package/dist/agent/{run-store.fencing.worker.d.ts → run-store.fencing.native-harness.fixture.test.support.d.ts} +0 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { StartRunOptions } from "../run-manager.js";
|
|
2
|
+
import type { AgentHarnessRunPolicy } from "./types.js";
|
|
3
|
+
export declare function resolveAgentHarnessRunPolicy(options: StartRunOptions | undefined, defaultEngineName: string): AgentHarnessRunPolicy;
|
|
4
|
+
export declare function isAgentHarnessRunPolicy(value: unknown): value is AgentHarnessRunPolicy;
|
|
5
|
+
export declare function agentHarnessFollowUpRunOptions(policy: AgentHarnessRunPolicy | null | undefined): StartRunOptions;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { resolveRunNoProgressTimeoutMs, resolveRunSoftTimeoutMs, } from "../run-manager.js";
|
|
2
|
+
export function resolveAgentHarnessRunPolicy(options, defaultEngineName) {
|
|
3
|
+
const backgroundFunction = options?.backgroundFunction === true;
|
|
4
|
+
const softTimeoutMs = resolveRunSoftTimeoutMs(options?.softTimeoutMs, {
|
|
5
|
+
useHostedDefault: options?.useHostedSoftTimeoutDefault === true,
|
|
6
|
+
backgroundFunction,
|
|
7
|
+
});
|
|
8
|
+
const noProgressTimeoutMs = resolveRunNoProgressTimeoutMs({
|
|
9
|
+
softTimeoutMs,
|
|
10
|
+
backgroundFunction,
|
|
11
|
+
...(options?.noProgressTimeoutMs !== undefined
|
|
12
|
+
? { overrideMs: options.noProgressTimeoutMs }
|
|
13
|
+
: {}),
|
|
14
|
+
...(options?.backgroundNoProgressTimeoutMs !== undefined
|
|
15
|
+
? { backgroundOverrideMs: options.backgroundNoProgressTimeoutMs }
|
|
16
|
+
: {}),
|
|
17
|
+
});
|
|
18
|
+
return {
|
|
19
|
+
softTimeoutMs,
|
|
20
|
+
noProgressTimeoutMs,
|
|
21
|
+
backgroundFunction,
|
|
22
|
+
recoverChunkBoundaries: options?.recoverChunkBoundaries ?? true,
|
|
23
|
+
engineName: options?.engineName ?? defaultEngineName,
|
|
24
|
+
...(options?.model ? { model: options.model } : {}),
|
|
25
|
+
...(options?.attemptCount !== undefined
|
|
26
|
+
? { attemptCount: options.attemptCount }
|
|
27
|
+
: {}),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export function isAgentHarnessRunPolicy(value) {
|
|
31
|
+
if (!value || typeof value !== "object")
|
|
32
|
+
return false;
|
|
33
|
+
const policy = value;
|
|
34
|
+
return (typeof policy.softTimeoutMs === "number" &&
|
|
35
|
+
Number.isFinite(policy.softTimeoutMs) &&
|
|
36
|
+
policy.softTimeoutMs >= 0 &&
|
|
37
|
+
typeof policy.noProgressTimeoutMs === "number" &&
|
|
38
|
+
Number.isFinite(policy.noProgressTimeoutMs) &&
|
|
39
|
+
policy.noProgressTimeoutMs >= 0 &&
|
|
40
|
+
typeof policy.backgroundFunction === "boolean" &&
|
|
41
|
+
typeof policy.recoverChunkBoundaries === "boolean" &&
|
|
42
|
+
typeof policy.engineName === "string" &&
|
|
43
|
+
(policy.model === undefined || typeof policy.model === "string") &&
|
|
44
|
+
(policy.attemptCount === undefined ||
|
|
45
|
+
(typeof policy.attemptCount === "number" &&
|
|
46
|
+
Number.isFinite(policy.attemptCount))));
|
|
47
|
+
}
|
|
48
|
+
export function agentHarnessFollowUpRunOptions(policy) {
|
|
49
|
+
if (!policy) {
|
|
50
|
+
return {
|
|
51
|
+
executionLease: true,
|
|
52
|
+
recoverChunkBoundaries: true,
|
|
53
|
+
softTimeoutMs: resolveRunSoftTimeoutMs(undefined, {
|
|
54
|
+
useHostedDefault: true,
|
|
55
|
+
}),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
executionLease: true,
|
|
60
|
+
softTimeoutMs: policy.softTimeoutMs,
|
|
61
|
+
noProgressTimeoutMs: policy.noProgressTimeoutMs,
|
|
62
|
+
backgroundFunction: policy.backgroundFunction,
|
|
63
|
+
recoverChunkBoundaries: policy.recoverChunkBoundaries,
|
|
64
|
+
engineName: policy.engineName,
|
|
65
|
+
...(policy.model ? { model: policy.model } : {}),
|
|
66
|
+
...(policy.attemptCount !== undefined
|
|
67
|
+
? { attemptCount: policy.attemptCount }
|
|
68
|
+
: {}),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { startRun } from "../run-manager.js";
|
|
2
2
|
import { getLiveAgentHarnessSessionGeneration, registerLiveAgentHarnessSession, refreshLiveAgentHarnessSessionGeneration, releaseLiveAgentHarnessSession, } from "./lifecycle.js";
|
|
3
|
+
import { resolveAgentHarnessRunPolicy } from "./run-policy.js";
|
|
3
4
|
import { AgentHarnessSessionConflictError, getAgentHarnessSession, isAgentHarnessSessionConflictError, markAgentHarnessSessionStopped, saveAgentHarnessSession, updateAgentHarnessSession, updateAgentHarnessSessionAtGeneration, } from "./store.js";
|
|
4
5
|
import { agentHarnessEventToAgentChatEvents } from "./translate.js";
|
|
6
|
+
import { driveAgentHarnessTurnChunks } from "./turn-driver.js";
|
|
5
7
|
const APPROVAL_RESOLUTION_POLL_INTERVAL_MS = 500;
|
|
6
8
|
const APPROVAL_RESOLUTION_TIMEOUT_MS = 30_000;
|
|
7
9
|
export class AgentHarnessApprovalResolutionTimeoutError extends Error {
|
|
@@ -19,17 +21,29 @@ export class AgentHarnessApprovalResolutionTimeoutError extends Error {
|
|
|
19
21
|
export function startAgentHarnessRun(opts) {
|
|
20
22
|
let harnessSession = opts.session;
|
|
21
23
|
const detachOnComplete = opts.detachOnComplete !== false;
|
|
24
|
+
const runTurnId = opts.turnId ?? opts.runOptions?.turnId;
|
|
25
|
+
const runOptions = {
|
|
26
|
+
...(opts.runOptions ?? {}),
|
|
27
|
+
...(runTurnId === undefined ? {} : { turnId: runTurnId }),
|
|
28
|
+
recoverChunkBoundaries: opts.runOptions?.recoverChunkBoundaries ?? true,
|
|
29
|
+
useHostedSoftTimeoutDefault: opts.runOptions?.useHostedSoftTimeoutDefault ?? true,
|
|
30
|
+
engineName: opts.runOptions?.engineName ?? opts.adapter.name,
|
|
31
|
+
executionLease: opts.runOptions?.executionLease ?? true,
|
|
32
|
+
};
|
|
33
|
+
const runPolicy = resolveAgentHarnessRunPolicy(runOptions, opts.adapter.name);
|
|
22
34
|
return startRun(opts.runId, opts.threadId, async (send, signal, control) => {
|
|
23
35
|
const runControl = control ?? {
|
|
24
36
|
turnSignal: signal,
|
|
25
37
|
chunkSignal: signal,
|
|
26
38
|
chunkBoundaryReason: () => null,
|
|
27
39
|
beginChunk: () => signal,
|
|
40
|
+
flushEvents: async () => { },
|
|
28
41
|
};
|
|
29
42
|
let storedSessionId;
|
|
30
43
|
let harnessSessionRegistered = false;
|
|
31
44
|
let keepLiveSession = false;
|
|
32
45
|
let liveSessionReleasedBeforeCheckpoint = false;
|
|
46
|
+
const wasLiveSessionReleasedBeforeCheckpoint = () => liveSessionReleasedBeforeCheckpoint;
|
|
33
47
|
const releaseLiveSessionBeforeCheckpoint = () => {
|
|
34
48
|
if (!liveSessionReleasedBeforeCheckpoint &&
|
|
35
49
|
storedSessionId &&
|
|
@@ -39,7 +53,7 @@ export function startAgentHarnessRun(opts) {
|
|
|
39
53
|
}
|
|
40
54
|
};
|
|
41
55
|
try {
|
|
42
|
-
send({
|
|
56
|
+
await send({
|
|
43
57
|
type: "activity",
|
|
44
58
|
label: `Starting ${opts.adapter.label}`,
|
|
45
59
|
tool: "harness",
|
|
@@ -59,6 +73,7 @@ export function startAgentHarnessRun(opts) {
|
|
|
59
73
|
threadId: opts.threadId,
|
|
60
74
|
runId: opts.runId,
|
|
61
75
|
providerSessionId: harnessSession.id,
|
|
76
|
+
runPolicy,
|
|
62
77
|
status: "running",
|
|
63
78
|
resumeState: opts.createSession?.resumeState,
|
|
64
79
|
ownerEmail: opts.ownerEmail ?? opts.createSession?.ownerEmail ?? null,
|
|
@@ -78,80 +93,86 @@ export function startAgentHarnessRun(opts) {
|
|
|
78
93
|
...opts.input,
|
|
79
94
|
abortSignal: runControl.chunkSignal,
|
|
80
95
|
};
|
|
81
|
-
|
|
96
|
+
const currentHarnessSession = harnessSession;
|
|
97
|
+
if (!storedSessionId) {
|
|
98
|
+
throw new Error("Harness session is unavailable for turn driving.");
|
|
99
|
+
}
|
|
100
|
+
const currentStoredSessionId = storedSessionId;
|
|
101
|
+
let checkpointHandled = false;
|
|
102
|
+
const wasCheckpointHandled = () => checkpointHandled;
|
|
82
103
|
let pendingApproval = null;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
104
|
+
await driveAgentHarnessTurnChunks({
|
|
105
|
+
session: currentHarnessSession,
|
|
106
|
+
input,
|
|
107
|
+
control: runControl,
|
|
108
|
+
consume: async (events) => {
|
|
109
|
+
pendingApproval = null;
|
|
110
|
+
try {
|
|
111
|
+
for await (const event of events) {
|
|
112
|
+
if (runControl.turnSignal.aborted)
|
|
113
|
+
break;
|
|
114
|
+
if (event.type === "approval-request") {
|
|
115
|
+
pendingApproval = event;
|
|
116
|
+
const resumeState = currentHarnessSession.checkpoint
|
|
117
|
+
? await currentHarnessSession.checkpoint()
|
|
118
|
+
: storedSession.resumeState;
|
|
119
|
+
await updateLiveAgentHarnessSession(currentStoredSessionId, currentHarnessSession, { pendingApproval: event, resumeState });
|
|
120
|
+
}
|
|
121
|
+
await opts.onHarnessEvent?.(event);
|
|
122
|
+
if (event.type === "error") {
|
|
123
|
+
throw new Error(event.error);
|
|
124
|
+
}
|
|
125
|
+
for (const chatEvent of agentHarnessEventToAgentChatEvents(event)) {
|
|
126
|
+
await send(chatEvent);
|
|
127
|
+
}
|
|
105
128
|
}
|
|
106
129
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
130
|
+
catch (error) {
|
|
131
|
+
if (runControl.turnSignal.aborted ||
|
|
132
|
+
!runControl.chunkBoundaryReason()) {
|
|
133
|
+
throw error;
|
|
134
|
+
}
|
|
112
135
|
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
return;
|
|
136
|
+
},
|
|
137
|
+
afterStream: async () => {
|
|
138
|
+
if (pendingApproval) {
|
|
139
|
+
const stored = await getAgentHarnessSession(currentStoredSessionId);
|
|
140
|
+
const stillPending = stored?.pendingApproval &&
|
|
141
|
+
typeof stored.pendingApproval === "object" &&
|
|
142
|
+
"id" in stored.pendingApproval &&
|
|
143
|
+
stored.pendingApproval.id === pendingApproval.id &&
|
|
144
|
+
!stored.resolvedApprovalIds?.includes(pendingApproval.id);
|
|
145
|
+
if (stillPending) {
|
|
146
|
+
keepLiveSession = true;
|
|
147
|
+
await persistHarnessCheckpoint(currentStoredSessionId, currentHarnessSession, stored.resumeState, undefined, async () => currentHarnessSession.checkpoint
|
|
148
|
+
? currentHarnessSession.checkpoint()
|
|
149
|
+
: stored.resumeState, true);
|
|
150
|
+
checkpointHandled = true;
|
|
151
|
+
return "stop";
|
|
152
|
+
}
|
|
131
153
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
154
|
+
if (runControl.chunkBoundaryReason() &&
|
|
155
|
+
!currentHarnessSession.continueTurn) {
|
|
156
|
+
await saveHarnessCheckpoint(currentStoredSessionId, currentHarnessSession, opts.createSession?.resumeState, detachOnComplete, detachOnComplete
|
|
157
|
+
? releaseLiveSessionBeforeCheckpoint
|
|
158
|
+
: undefined);
|
|
159
|
+
checkpointHandled = true;
|
|
160
|
+
if (!detachOnComplete) {
|
|
161
|
+
keepLiveSession = true;
|
|
162
|
+
}
|
|
163
|
+
return "stop";
|
|
139
164
|
}
|
|
140
165
|
return;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
await markAgentHarnessSessionStopped(storedSessionId, "stopped");
|
|
144
|
-
releaseLiveAgentHarnessSession(storedSessionId, harnessSession);
|
|
145
|
-
await stopHarnessSession(harnessSession);
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
166
|
+
},
|
|
167
|
+
});
|
|
149
168
|
if (runControl.turnSignal.aborted) {
|
|
150
169
|
await markAgentHarnessSessionStopped(storedSessionId, "stopped");
|
|
151
170
|
releaseLiveAgentHarnessSession(storedSessionId, harnessSession);
|
|
152
171
|
await stopHarnessSession(harnessSession);
|
|
153
172
|
return;
|
|
154
173
|
}
|
|
174
|
+
if (wasCheckpointHandled())
|
|
175
|
+
return;
|
|
155
176
|
let resumeState = opts.createSession?.resumeState;
|
|
156
177
|
await persistHarnessCheckpoint(storedSessionId, harnessSession, resumeState, releaseLiveSessionBeforeCheckpoint, detachOnComplete && harnessSession.detach
|
|
157
178
|
? () => harnessSession.detach()
|
|
@@ -198,7 +219,7 @@ export function startAgentHarnessRun(opts) {
|
|
|
198
219
|
}
|
|
199
220
|
return;
|
|
200
221
|
}
|
|
201
|
-
if (harnessSession
|
|
222
|
+
if (harnessSession) {
|
|
202
223
|
await stopHarnessSession(harnessSession).catch(() => undefined);
|
|
203
224
|
}
|
|
204
225
|
if (storedSessionId) {
|
|
@@ -212,19 +233,12 @@ export function startAgentHarnessRun(opts) {
|
|
|
212
233
|
}
|
|
213
234
|
finally {
|
|
214
235
|
if (!keepLiveSession &&
|
|
215
|
-
!
|
|
236
|
+
!wasLiveSessionReleasedBeforeCheckpoint() &&
|
|
216
237
|
storedSessionId) {
|
|
217
238
|
releaseLiveAgentHarnessSession(storedSessionId, harnessSession);
|
|
218
239
|
}
|
|
219
240
|
}
|
|
220
|
-
}, opts.onRunComplete,
|
|
221
|
-
...(opts.runOptions ?? {}),
|
|
222
|
-
turnId: opts.turnId ?? opts.runOptions?.turnId,
|
|
223
|
-
recoverChunkBoundaries: opts.runOptions?.recoverChunkBoundaries ?? true,
|
|
224
|
-
useHostedSoftTimeoutDefault: opts.runOptions?.useHostedSoftTimeoutDefault ?? true,
|
|
225
|
-
engineName: opts.runOptions?.engineName ?? opts.adapter.name,
|
|
226
|
-
executionLease: opts.runOptions?.executionLease ?? true,
|
|
227
|
-
});
|
|
241
|
+
}, opts.onRunComplete, runOptions);
|
|
228
242
|
}
|
|
229
243
|
async function persistRecoverableCheckpointAfterApprovalTimeout(sessionId, session) {
|
|
230
244
|
let conflict;
|
|
@@ -297,7 +311,9 @@ async function persistHarnessCheckpoint(sessionId, session, resumeState, beforeC
|
|
|
297
311
|
}
|
|
298
312
|
const pendingApproval = checkpointPendingApproval(stored);
|
|
299
313
|
try {
|
|
300
|
-
const
|
|
314
|
+
const preserveStoredResumeState = waitedForApprovalResolution ||
|
|
315
|
+
(preserveLatestResumeState && !pendingApproval);
|
|
316
|
+
const checkpointResumeState = preserveStoredResumeState
|
|
301
317
|
? stored.resumeState
|
|
302
318
|
: resolveResumeState
|
|
303
319
|
? await resolveResumeState()
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { type DbExec } from "../../db/client.js";
|
|
1
2
|
import type { AgentChatEvent } from "../types.js";
|
|
3
|
+
import type { AgentHarnessRunPolicy } from "./types.js";
|
|
2
4
|
export declare const APPROVAL_RESOLUTION_CLAIM_LEASE_MS = 60000;
|
|
3
5
|
export declare const RESOLVED_APPROVAL_LIMIT = 32;
|
|
4
6
|
export type AgentHarnessSessionStatus = "running" | "idle" | "stopped" | "errored" | "destroyed";
|
|
@@ -12,6 +14,7 @@ export interface StoredAgentHarnessSession {
|
|
|
12
14
|
threadId: string;
|
|
13
15
|
runId?: string | null;
|
|
14
16
|
providerSessionId?: string | null;
|
|
17
|
+
runPolicy?: AgentHarnessRunPolicy | null;
|
|
15
18
|
status: AgentHarnessSessionStatus;
|
|
16
19
|
resumeState?: unknown;
|
|
17
20
|
workspaceRef?: string | null;
|
|
@@ -41,6 +44,7 @@ export interface SaveAgentHarnessSessionInput {
|
|
|
41
44
|
threadId: string;
|
|
42
45
|
runId?: string | null;
|
|
43
46
|
providerSessionId?: string | null;
|
|
47
|
+
runPolicy?: AgentHarnessRunPolicy | null;
|
|
44
48
|
status?: AgentHarnessSessionStatus;
|
|
45
49
|
resumeState?: unknown;
|
|
46
50
|
workspaceRef?: string | null;
|
|
@@ -144,6 +148,10 @@ export declare function finalizeAgentHarnessSessionApprovalResolution(input: {
|
|
|
144
148
|
export declare function failAgentHarnessSessionApprovalResolution(input: {
|
|
145
149
|
sessionId: string;
|
|
146
150
|
approvalId: string;
|
|
151
|
+
errorEvent?: Extract<AgentChatEvent, {
|
|
152
|
+
type: "error";
|
|
153
|
+
}>;
|
|
154
|
+
recordResolvedId?: boolean;
|
|
147
155
|
eventAt?: number;
|
|
148
156
|
}): Promise<StoredAgentHarnessSession | null>;
|
|
149
157
|
export declare function releaseAgentHarnessSessionApprovalResolutionBeforeDispatch(input: {
|
|
@@ -159,10 +167,11 @@ export declare function reconcileExpiredAgentHarnessApprovalResolution(sessionId
|
|
|
159
167
|
export declare function listAgentHarnessSessionEvents(sessionId: string): Promise<StoredAgentHarnessSessionEvent[]>;
|
|
160
168
|
export declare function reconcileExpiredAgentHarnessFollowUp(sessionId: string, claimId: string, expectedGeneration: number): Promise<StoredAgentHarnessSession | null>;
|
|
161
169
|
export declare function listExpiredAgentHarnessFollowUps(limit?: number): Promise<StoredAgentHarnessSession[]>;
|
|
162
|
-
export declare function startAgentHarnessSessionFollowUpDispatch<T>(id: string, expectedGeneration: number, claimId: string, start: () => T): Promise<{
|
|
170
|
+
export declare function startAgentHarnessSessionFollowUpDispatch<T>(id: string, expectedGeneration: number, claimId: string, start: (assertCurrent: (tx: DbExec) => Promise<void>) => T | Promise<T>): Promise<{
|
|
163
171
|
session: StoredAgentHarnessSession;
|
|
164
172
|
started: T;
|
|
165
173
|
} | null>;
|
|
174
|
+
export declare function assertAgentHarnessSessionFollowUpClaimCurrent(tx: DbExec, id: string, generation: number, claimId: string): Promise<void>;
|
|
166
175
|
export declare function startAgentHarnessSessionApprovalDispatch<T>(id: string, expectedStatus: AgentHarnessSessionStatus, expectedGeneration: number, approvalId: string, start: () => T): Promise<{
|
|
167
176
|
session: StoredAgentHarnessSession;
|
|
168
177
|
started: T;
|
|
@@ -42,6 +42,7 @@ export const agentHarnessSessionsStore = defineStore({
|
|
|
42
42
|
thread_id TEXT NOT NULL,
|
|
43
43
|
run_id TEXT,
|
|
44
44
|
provider_session_id TEXT,
|
|
45
|
+
run_policy TEXT,
|
|
45
46
|
status TEXT NOT NULL DEFAULT 'idle',
|
|
46
47
|
resume_state TEXT,
|
|
47
48
|
workspace_ref TEXT,
|
|
@@ -61,6 +62,7 @@ export const agentHarnessSessionsStore = defineStore({
|
|
|
61
62
|
for (const col of [
|
|
62
63
|
"run_id",
|
|
63
64
|
"provider_session_id",
|
|
65
|
+
"run_policy",
|
|
64
66
|
"resume_state",
|
|
65
67
|
"workspace_ref",
|
|
66
68
|
"pending_approval",
|
|
@@ -145,6 +147,10 @@ export const agentHarnessSessionsStore = defineStore({
|
|
|
145
147
|
});
|
|
146
148
|
},
|
|
147
149
|
},
|
|
150
|
+
{
|
|
151
|
+
name: "agent-harness-sessions-run-policy",
|
|
152
|
+
sql: "ALTER TABLE agent_harness_sessions ADD COLUMN IF NOT EXISTS run_policy TEXT",
|
|
153
|
+
},
|
|
148
154
|
],
|
|
149
155
|
});
|
|
150
156
|
export function ensureAgentHarnessSessionTables() {
|
|
@@ -162,6 +168,7 @@ export async function saveAgentHarnessSession(input) {
|
|
|
162
168
|
threadId: input.threadId,
|
|
163
169
|
runId: input.runId ?? null,
|
|
164
170
|
providerSessionId: input.providerSessionId ?? null,
|
|
171
|
+
runPolicy: input.runPolicy ?? existing?.runPolicy ?? null,
|
|
165
172
|
status: input.status ?? existing?.status ?? "idle",
|
|
166
173
|
resumeState: input.resumeState !== undefined
|
|
167
174
|
? input.resumeState
|
|
@@ -220,6 +227,7 @@ export async function saveAgentHarnessSession(input) {
|
|
|
220
227
|
record.threadId,
|
|
221
228
|
record.runId ?? null,
|
|
222
229
|
record.providerSessionId ?? null,
|
|
230
|
+
serializeJson(record.runPolicy),
|
|
223
231
|
record.status,
|
|
224
232
|
serializeJson(record.resumeState),
|
|
225
233
|
record.workspaceRef ?? null,
|
|
@@ -246,14 +254,14 @@ export async function saveAgentHarnessSession(input) {
|
|
|
246
254
|
if (!existing) {
|
|
247
255
|
const inserted = await client.execute({
|
|
248
256
|
sql: `INSERT INTO agent_harness_sessions (
|
|
249
|
-
id, harness_name, thread_id, run_id, provider_session_id, status,
|
|
257
|
+
id, harness_name, thread_id, run_id, provider_session_id, run_policy, status,
|
|
250
258
|
resume_state, workspace_ref, pending_approval, approval_resolution_id,
|
|
251
259
|
approval_resolution_claim_expires_at, expiry_cleanup_id, resolved_approval_ids,
|
|
252
260
|
owner_email, org_id, generation, created_at, updated_at, stopped_at,
|
|
253
261
|
follow_up_claim_id, follow_up_id, follow_up_prompt,
|
|
254
262
|
follow_up_metadata, follow_up_claim_expires_at,
|
|
255
263
|
follow_up_deadline_at, follow_up_dispatched_at, follow_up_outcome
|
|
256
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
264
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
257
265
|
ON CONFLICT(id) DO NOTHING`,
|
|
258
266
|
args: values,
|
|
259
267
|
});
|
|
@@ -304,7 +312,7 @@ export async function saveAgentHarnessSession(input) {
|
|
|
304
312
|
}
|
|
305
313
|
const updated = await client.execute({
|
|
306
314
|
sql: `UPDATE agent_harness_sessions SET
|
|
307
|
-
harness_name = ?, thread_id = ?, run_id = ?, provider_session_id = ?,
|
|
315
|
+
harness_name = ?, thread_id = ?, run_id = ?, provider_session_id = ?, run_policy = ?,
|
|
308
316
|
status = ?, resume_state = ?, workspace_ref = ?, pending_approval = ?,
|
|
309
317
|
approval_resolution_id = ?, approval_resolution_claim_expires_at = ?,
|
|
310
318
|
expiry_cleanup_id = ?, resolved_approval_ids = ?, owner_email = ?,
|
|
@@ -319,6 +327,7 @@ export async function saveAgentHarnessSession(input) {
|
|
|
319
327
|
record.threadId,
|
|
320
328
|
record.runId ?? null,
|
|
321
329
|
record.providerSessionId ?? null,
|
|
330
|
+
serializeJson(record.runPolicy),
|
|
322
331
|
record.status,
|
|
323
332
|
serializeJson(record.resumeState),
|
|
324
333
|
record.workspaceRef ?? null,
|
|
@@ -860,10 +869,12 @@ export async function failAgentHarnessSessionApprovalResolution(input) {
|
|
|
860
869
|
const pendingApproval = pendingApprovalId(current.pendingApproval) === input.approvalId
|
|
861
870
|
? null
|
|
862
871
|
: current.pendingApproval;
|
|
863
|
-
const resolvedApprovalIds =
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
872
|
+
const resolvedApprovalIds = input.recordResolvedId === false
|
|
873
|
+
? (current.resolvedApprovalIds ?? [])
|
|
874
|
+
: [
|
|
875
|
+
...(current.resolvedApprovalIds ?? []).filter((id) => id !== input.approvalId),
|
|
876
|
+
input.approvalId,
|
|
877
|
+
].slice(-RESOLVED_APPROVAL_LIMIT);
|
|
867
878
|
const { rows: updatedRows } = await tx.execute({
|
|
868
879
|
sql: `UPDATE agent_harness_sessions
|
|
869
880
|
SET pending_approval = ?, approval_resolution_id = NULL,
|
|
@@ -891,7 +902,7 @@ export async function failAgentHarnessSessionApprovalResolution(input) {
|
|
|
891
902
|
sessionId: input.sessionId,
|
|
892
903
|
operationId,
|
|
893
904
|
eventAt,
|
|
894
|
-
event: {
|
|
905
|
+
event: input.errorEvent ?? {
|
|
895
906
|
type: "error",
|
|
896
907
|
error: "The approval outcome is unknown because its worker stopped after dispatch. Check for completed effects before submitting it again.",
|
|
897
908
|
errorCode: "harness_approval_outcome_unknown",
|
|
@@ -1342,7 +1353,7 @@ export async function startAgentHarnessSessionFollowUpDispatch(id, expectedGener
|
|
|
1342
1353
|
if (!client.transaction) {
|
|
1343
1354
|
throw new Error("Agent harness follow-up dispatch requires database transactions.");
|
|
1344
1355
|
}
|
|
1345
|
-
|
|
1356
|
+
const session = await client.transaction(async (tx) => {
|
|
1346
1357
|
const { rows } = await tx.execute({
|
|
1347
1358
|
sql: `UPDATE agent_harness_sessions
|
|
1348
1359
|
SET generation = generation + 1,
|
|
@@ -1358,10 +1369,41 @@ export async function startAgentHarnessSessionFollowUpDispatch(id, expectedGener
|
|
|
1358
1369
|
const session = rowToHarnessSession(rows[0]);
|
|
1359
1370
|
if (!session)
|
|
1360
1371
|
return null;
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1372
|
+
return session;
|
|
1373
|
+
});
|
|
1374
|
+
if (!session)
|
|
1375
|
+
return null;
|
|
1376
|
+
// Starting a run can use the same pool as this store. Release the row lock
|
|
1377
|
+
// before its run admission needs another database connection.
|
|
1378
|
+
const current = await getAgentHarnessSession(id);
|
|
1379
|
+
if (!current ||
|
|
1380
|
+
current.status !== "running" ||
|
|
1381
|
+
current.followUpClaimId !== claimId ||
|
|
1382
|
+
current.generation !== session.generation ||
|
|
1383
|
+
(current.followUpClaimExpiresAt ?? 0) <= Date.now() ||
|
|
1384
|
+
(current.followUpDeadlineAt ?? 0) <= Date.now() ||
|
|
1385
|
+
current.expiryCleanupId) {
|
|
1386
|
+
return null;
|
|
1387
|
+
}
|
|
1388
|
+
return {
|
|
1389
|
+
session: current,
|
|
1390
|
+
started: await start((tx) => assertAgentHarnessSessionFollowUpClaimCurrent(tx, id, current.generation, claimId)),
|
|
1391
|
+
};
|
|
1392
|
+
}
|
|
1393
|
+
export async function assertAgentHarnessSessionFollowUpClaimCurrent(tx, id, generation, claimId) {
|
|
1394
|
+
const { rows } = await tx.execute({
|
|
1395
|
+
sql: `UPDATE agent_harness_sessions
|
|
1396
|
+
SET updated_at = updated_at
|
|
1397
|
+
WHERE id = ? AND status = 'running' AND follow_up_claim_id = ?
|
|
1398
|
+
AND generation = ?
|
|
1399
|
+
AND follow_up_claim_expires_at > ${DATABASE_NOW_MS_SQL}
|
|
1400
|
+
AND follow_up_deadline_at > ${DATABASE_NOW_MS_SQL}
|
|
1401
|
+
AND expiry_cleanup_id IS NULL
|
|
1402
|
+
RETURNING id`,
|
|
1403
|
+
args: [id, claimId, generation],
|
|
1364
1404
|
});
|
|
1405
|
+
if (!rows[0])
|
|
1406
|
+
throw new AgentHarnessSessionConflictError(id);
|
|
1365
1407
|
}
|
|
1366
1408
|
export async function startAgentHarnessSessionApprovalDispatch(id, expectedStatus, expectedGeneration, approvalId, start) {
|
|
1367
1409
|
await ensureAgentHarnessSessionTables();
|
|
@@ -1606,6 +1648,7 @@ export async function markAgentHarnessSessionStoppedIfUnclaimed(id, expectedStat
|
|
|
1606
1648
|
updated_at = ?
|
|
1607
1649
|
WHERE id = ? AND status = ? AND generation = ?
|
|
1608
1650
|
AND follow_up_claim_id IS NULL
|
|
1651
|
+
AND approval_resolution_id IS NULL
|
|
1609
1652
|
AND expiry_cleanup_id IS NULL
|
|
1610
1653
|
RETURNING *`,
|
|
1611
1654
|
args: [
|
|
@@ -1629,6 +1672,7 @@ function rowToHarnessSession(row) {
|
|
|
1629
1672
|
threadId: String(record.thread_id),
|
|
1630
1673
|
runId: stringOrNull(record.run_id),
|
|
1631
1674
|
providerSessionId: stringOrNull(record.provider_session_id),
|
|
1675
|
+
runPolicy: parseAgentHarnessRunPolicy(record.run_policy),
|
|
1632
1676
|
status: normalizeStatus(record.status),
|
|
1633
1677
|
resumeState: parseJson(record.resume_state),
|
|
1634
1678
|
workspaceRef: stringOrNull(record.workspace_ref),
|
|
@@ -1682,6 +1726,41 @@ function parseJson(value) {
|
|
|
1682
1726
|
return undefined;
|
|
1683
1727
|
}
|
|
1684
1728
|
}
|
|
1729
|
+
function parseAgentHarnessRunPolicy(value) {
|
|
1730
|
+
if (value === null || value === undefined)
|
|
1731
|
+
return null;
|
|
1732
|
+
const parsed = parseJson(value);
|
|
1733
|
+
if (!parsed || typeof parsed !== "object") {
|
|
1734
|
+
throw new Error("Stored AgentHarness run policy is invalid.");
|
|
1735
|
+
}
|
|
1736
|
+
const policy = parsed;
|
|
1737
|
+
if (typeof policy.softTimeoutMs !== "number" ||
|
|
1738
|
+
!Number.isFinite(policy.softTimeoutMs) ||
|
|
1739
|
+
policy.softTimeoutMs < 0 ||
|
|
1740
|
+
typeof policy.noProgressTimeoutMs !== "number" ||
|
|
1741
|
+
!Number.isFinite(policy.noProgressTimeoutMs) ||
|
|
1742
|
+
policy.noProgressTimeoutMs < 0 ||
|
|
1743
|
+
typeof policy.backgroundFunction !== "boolean" ||
|
|
1744
|
+
typeof policy.recoverChunkBoundaries !== "boolean" ||
|
|
1745
|
+
typeof policy.engineName !== "string" ||
|
|
1746
|
+
(policy.model !== undefined && typeof policy.model !== "string") ||
|
|
1747
|
+
(policy.attemptCount !== undefined &&
|
|
1748
|
+
(typeof policy.attemptCount !== "number" ||
|
|
1749
|
+
!Number.isFinite(policy.attemptCount)))) {
|
|
1750
|
+
throw new Error("Stored AgentHarness run policy is invalid.");
|
|
1751
|
+
}
|
|
1752
|
+
return {
|
|
1753
|
+
softTimeoutMs: policy.softTimeoutMs,
|
|
1754
|
+
noProgressTimeoutMs: policy.noProgressTimeoutMs,
|
|
1755
|
+
backgroundFunction: policy.backgroundFunction,
|
|
1756
|
+
recoverChunkBoundaries: policy.recoverChunkBoundaries,
|
|
1757
|
+
engineName: policy.engineName,
|
|
1758
|
+
...(typeof policy.model === "string" ? { model: policy.model } : {}),
|
|
1759
|
+
...(typeof policy.attemptCount === "number"
|
|
1760
|
+
? { attemptCount: policy.attemptCount }
|
|
1761
|
+
: {}),
|
|
1762
|
+
};
|
|
1763
|
+
}
|
|
1685
1764
|
async function hasActiveFollowUpClaim(id, claimId, expectedApprovalResolutionId) {
|
|
1686
1765
|
const approvalCondition = expectedApprovalResolutionId === null
|
|
1687
1766
|
? "approval_resolution_id IS NULL"
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { RunChunkControl } from "../run-manager.js";
|
|
2
|
+
import type { AgentHarnessEvent, AgentHarnessSession, AgentHarnessTurnInput } from "./types.js";
|
|
3
|
+
export interface DriveAgentHarnessTurnChunksOptions {
|
|
4
|
+
session: AgentHarnessSession;
|
|
5
|
+
input?: AgentHarnessTurnInput;
|
|
6
|
+
control: Pick<RunChunkControl, "turnSignal" | "chunkSignal" | "chunkBoundaryReason" | "beginChunk">;
|
|
7
|
+
consume: (stream: AsyncIterable<AgentHarnessEvent>) => Promise<"stop" | void>;
|
|
8
|
+
beforeStream?: () => Promise<void>;
|
|
9
|
+
onProviderDispatch?: () => void;
|
|
10
|
+
afterStream?: () => Promise<"stop" | void>;
|
|
11
|
+
}
|
|
12
|
+
export declare function driveAgentHarnessTurnChunks(options: DriveAgentHarnessTurnChunksOptions): Promise<void>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
function isAborted(signal) {
|
|
2
|
+
return signal.aborted;
|
|
3
|
+
}
|
|
4
|
+
export async function driveAgentHarnessTurnChunks(options) {
|
|
5
|
+
let input = options.input;
|
|
6
|
+
let firstStream = input !== undefined;
|
|
7
|
+
while (!isAborted(options.control.turnSignal)) {
|
|
8
|
+
await options.beforeStream?.();
|
|
9
|
+
if (isAborted(options.control.turnSignal))
|
|
10
|
+
return;
|
|
11
|
+
let stream;
|
|
12
|
+
if (firstStream) {
|
|
13
|
+
options.onProviderDispatch?.();
|
|
14
|
+
stream = options.session.streamTurn({
|
|
15
|
+
...input,
|
|
16
|
+
abortSignal: options.control.chunkSignal,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
else if (options.session.continueTurn) {
|
|
20
|
+
options.onProviderDispatch?.();
|
|
21
|
+
stream = options.session.continueTurn({
|
|
22
|
+
abortSignal: options.control.chunkSignal,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
firstStream = false;
|
|
26
|
+
input = undefined;
|
|
27
|
+
if (!stream)
|
|
28
|
+
return;
|
|
29
|
+
if ((await options.consume(stream)) === "stop")
|
|
30
|
+
return;
|
|
31
|
+
if (isAborted(options.control.turnSignal))
|
|
32
|
+
return;
|
|
33
|
+
if ((await options.afterStream?.()) === "stop")
|
|
34
|
+
return;
|
|
35
|
+
if (!options.control.chunkBoundaryReason())
|
|
36
|
+
return;
|
|
37
|
+
if (!options.session.continueTurn)
|
|
38
|
+
return;
|
|
39
|
+
if (options.control.beginChunk().aborted)
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -7,6 +7,15 @@ export interface AgentHarnessCapabilities {
|
|
|
7
7
|
hostTools: boolean;
|
|
8
8
|
fileEvents: boolean;
|
|
9
9
|
}
|
|
10
|
+
export interface AgentHarnessRunPolicy {
|
|
11
|
+
softTimeoutMs: number;
|
|
12
|
+
noProgressTimeoutMs: number;
|
|
13
|
+
backgroundFunction: boolean;
|
|
14
|
+
recoverChunkBoundaries: boolean;
|
|
15
|
+
engineName: string;
|
|
16
|
+
model?: string;
|
|
17
|
+
attemptCount?: number;
|
|
18
|
+
}
|
|
10
19
|
export interface AgentHarnessAdapter {
|
|
11
20
|
readonly name: string;
|
|
12
21
|
readonly label: string;
|
|
@@ -56,6 +65,8 @@ export interface AgentHarnessSession {
|
|
|
56
65
|
streamTurn(input: AgentHarnessTurnInput): AsyncIterable<AgentHarnessEvent>;
|
|
57
66
|
continueTurn?(input?: AgentHarnessContinueInput): AsyncIterable<AgentHarnessEvent>;
|
|
58
67
|
approve?(approval: AgentHarnessApproval): Promise<void>;
|
|
68
|
+
canResolveApproval?(approval: AgentHarnessApproval): boolean | Promise<boolean>;
|
|
69
|
+
checkpoint?(): Promise<unknown>;
|
|
59
70
|
detach?(): Promise<unknown>;
|
|
60
71
|
stop?(): Promise<unknown>;
|
|
61
72
|
destroy?(): Promise<void>;
|