@vellumai/assistant 0.12.4 → 0.12.5-dev.202609251017.e467a6c
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/docs/architecture/memory.md +9 -1
- package/docs/architecture/scheduling.md +13 -5
- package/docs/desktop-browser-cli.md +3 -2
- package/docs/guardian-request-flow.md +1 -1
- package/node_modules/@vellumai/avatar-manifest/src/__tests__/notification-avatar.test.ts +48 -4
- package/node_modules/@vellumai/avatar-manifest/src/notification-avatar.ts +12 -8
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/__tests__/guardian-requests.test.ts +26 -0
- package/node_modules/@vellumai/ces-client/node_modules/@vellumai/service-contracts/src/guardian-requests.ts +77 -3
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/__tests__/guardian-requests.test.ts +26 -0
- package/node_modules/@vellumai/gateway-client/node_modules/@vellumai/service-contracts/src/guardian-requests.ts +77 -3
- package/node_modules/@vellumai/gateway-client/src/outbound-contract.ts +2 -4
- package/node_modules/@vellumai/service-contracts/src/__tests__/guardian-requests.test.ts +26 -0
- package/node_modules/@vellumai/service-contracts/src/guardian-requests.ts +77 -3
- package/openapi.yaml +152 -3
- package/package.json +1 -1
- package/src/__tests__/agent-loop.test.ts +76 -0
- package/src/__tests__/anthropic-error-formatting.test.ts +9 -0
- package/src/__tests__/background-shell-bash.test.ts +34 -0
- package/src/__tests__/background-shell-host-bash.test.ts +98 -1
- package/src/__tests__/background-tool-registry.test.ts +39 -0
- package/src/__tests__/channel-readiness-discord.test.ts +8 -0
- package/src/__tests__/channel-readiness-slack-remote.test.ts +8 -0
- package/src/__tests__/client-os-metadata-persistence.test.ts +4 -20
- package/src/__tests__/conversation-agent-loop.test.ts +529 -1
- package/src/__tests__/conversation-error.test.ts +18 -0
- package/src/__tests__/conversation-pairing.test.ts +69 -0
- package/src/__tests__/conversation-queue.test.ts +257 -4
- package/src/__tests__/conversation-runtime-assembly.test.ts +27 -0
- package/src/__tests__/emit-signal-routing-intent.test.ts +62 -0
- package/src/__tests__/evict-conversations-for-reload.test.ts +21 -0
- package/src/__tests__/gemini-provider.test.ts +9 -0
- package/src/__tests__/host-cu-proxy.test.ts +79 -0
- package/src/__tests__/host-cu-routes-targeted.test.ts +14 -5
- package/src/__tests__/introduction-card-resolver.test.ts +53 -8
- package/src/__tests__/job-handler-registration-guard.test.ts +1 -0
- package/src/__tests__/non-member-access-request.test.ts +48 -0
- package/src/__tests__/notification-events-source-context-probe.test.ts +48 -1
- package/src/__tests__/notification-platform-adapter.test.ts +97 -0
- package/src/__tests__/notification-vellum-adapter.test.ts +103 -3
- package/src/__tests__/platform-callback-registration.test.ts +46 -1
- package/src/__tests__/plugin-import-boundary-guard.test.ts +3 -0
- package/src/__tests__/scaffold-managed-skill-tool.test.ts +116 -66
- package/src/__tests__/scheduler-disk-pressure.test.ts +1 -0
- package/src/__tests__/scheduler-result-notification.test.ts +521 -7
- package/src/__tests__/scheduler-wake.test.ts +1 -0
- package/src/__tests__/skill-load-inline-command.test.ts +35 -0
- package/src/__tests__/subagent-cron-run-attribution.test.ts +41 -2
- package/src/__tests__/subagent-manager-notify.test.ts +48 -0
- package/src/__tests__/trusted-contact-inline-approval-integration.test.ts +6 -6
- package/src/__tests__/usage-attribution.test.ts +31 -0
- package/src/__tests__/wake-schedule-escalation.test.ts +1 -0
- package/src/agent/loop.ts +23 -0
- package/src/api/ask-question-tool.ts +50 -0
- package/src/api/events/generation-handoff.ts +4 -0
- package/src/api/events/message-complete.ts +4 -0
- package/src/api/events/tool-result.ts +11 -0
- package/src/api/index.ts +11 -0
- package/src/api/requests/guardian-actions.test.ts +45 -0
- package/src/api/requests/guardian-actions.ts +20 -0
- package/src/api/responses/conversation-message.ts +4 -0
- package/src/api/responses/home.ts +27 -0
- package/src/approvals/guardian-decision-primitive.ts +6 -4
- package/src/approvals/guardian-request-resolvers.ts +35 -30
- package/src/avatar/notification-avatar.test.ts +42 -34
- package/src/avatar/notification-avatar.ts +1 -0
- package/src/calls/__tests__/call-controller.test.ts +18 -0
- package/src/calls/__tests__/voice-control-protocol.test.ts +6 -1
- package/src/calls/__tests__/voice-leg-coordinator.test.ts +70 -0
- package/src/calls/__tests__/voice-session-bridge.test.ts +116 -4
- package/src/calls/__tests__/voice-triage-escalate.test.ts +77 -11
- package/src/calls/call-controller.ts +3 -1
- package/src/calls/voice-control-protocol.ts +12 -4
- package/src/calls/voice-escalation-judge.ts +2 -2
- package/src/calls/voice-leg-coordinator.ts +23 -5
- package/src/calls/voice-screen-annotation.ts +44 -0
- package/src/calls/voice-session-bridge.ts +63 -20
- package/src/calls/voice-triage-escalate.ts +82 -27
- package/src/cli/commands/__tests__/conversations-clear.test.ts +156 -0
- package/src/cli/commands/conversations.help.ts +7 -2
- package/src/cli/commands/conversations.ts +36 -30
- package/src/cli/commands/oauth/index.help.ts +8 -2
- package/src/cli/commands/oauth/request.test.ts +32 -0
- package/src/cli/commands/platform/index.help.ts +2 -1
- package/src/cli/commands/platform/index.ts +8 -2
- package/src/cli/lib/__tests__/plugin-catalog-cache.test.ts +60 -0
- package/src/cli/lib/__tests__/plugin-catalog-platform.test.ts +66 -2
- package/src/cli/lib/bundled-marketplace.json +35 -0
- package/src/cli/lib/bundled-plugin-packages.json +21 -0
- package/src/cli/lib/plugin-catalog-cache.ts +17 -2
- package/src/cli/lib/plugin-catalog-platform.ts +48 -9
- package/src/config/__tests__/default-profile-catalog.test.ts +28 -0
- package/src/config/__tests__/platform-identity.test.ts +59 -0
- package/src/config/__tests__/profile-order.test.ts +19 -0
- package/src/config/__tests__/sync-gated-profiles.test.ts +71 -0
- package/src/config/bundled-skills/computer-use/SKILL.md +20 -0
- package/src/config/bundled-skills/computer-use/TOOLS.json +11 -11
- package/src/config/bundled-skills/screen-annotation/SKILL.md +41 -29
- package/src/config/bundled-skills/screen-annotation/TOOLS.json +5 -5
- package/src/config/call-site-defaults.ts +6 -0
- package/src/config/default-profile-catalog.ts +30 -1
- package/src/config/default-profile-names.ts +36 -2
- package/src/config/feature-flag-registry.json +9 -1
- package/src/config/platform-identity.ts +22 -5
- package/src/config/profile-order.ts +7 -1
- package/src/config/schemas/call-site-catalog.ts +7 -0
- package/src/config/schemas/llm.ts +21 -5
- package/src/config/sync-gated-profiles.ts +96 -44
- package/src/daemon/__tests__/abort-null-controller.test.ts +135 -1
- package/src/daemon/__tests__/auto-profile-router.test.ts +380 -0
- package/src/daemon/__tests__/turn-tail-assistant-reply-notify.test.ts +16 -0
- package/src/daemon/activity-trail.test.ts +206 -0
- package/src/daemon/activity-trail.ts +190 -0
- package/src/daemon/auto-profile-router.ts +431 -0
- package/src/daemon/computer-use-observation.test.ts +81 -0
- package/src/daemon/computer-use-observation.ts +23 -0
- package/src/daemon/conversation-agent-loop-handlers.ts +11 -0
- package/src/daemon/conversation-agent-loop.ts +157 -32
- package/src/daemon/conversation-error.ts +19 -0
- package/src/daemon/conversation-lifecycle.ts +70 -7
- package/src/daemon/conversation-media-retry.ts +1 -2
- package/src/daemon/conversation-messaging.ts +31 -2
- package/src/daemon/conversation-process.ts +107 -16
- package/src/daemon/conversation-queue-manager.ts +7 -0
- package/src/daemon/conversation-runtime-assembly.ts +1 -0
- package/src/daemon/conversation-turn-finalize.ts +14 -0
- package/src/daemon/conversation.ts +25 -6
- package/src/daemon/event-loop-watchdog.test.ts +201 -2
- package/src/daemon/event-loop-watchdog.ts +182 -6
- package/src/daemon/host-cu-proxy.ts +34 -3
- package/src/daemon/pkb-reminder-builder.test.ts +10 -3
- package/src/daemon/pkb-reminder-builder.ts +1 -1
- package/src/daemon/wake-conversation-ops.ts +4 -2
- package/src/desktop/desktop-computer-use.test.ts +14 -4
- package/src/home/feed-types.ts +2 -0
- package/src/inbound/platform-callback-registration.ts +19 -6
- package/src/live-voice/__tests__/live-voice-agent-turn.test.ts +27 -0
- package/src/live-voice/__tests__/live-voice-flux-turn-end.test.ts +83 -0
- package/src/live-voice/__tests__/live-voice-triage-escalate.test.ts +48 -1
- package/src/live-voice/__tests__/live-voice-vad.test.ts +34 -2
- package/src/live-voice/__tests__/protocol.test.ts +22 -0
- package/src/live-voice/continuation-judge.ts +1 -1
- package/src/live-voice/live-voice-session.ts +25 -19
- package/src/live-voice/protocol.ts +16 -5
- package/src/messaging/providers/discord/withdraw.ts +4 -5
- package/src/messaging/providers/gmail/client.ts +4 -0
- package/src/messaging/providers/slack/withdraw.ts +5 -5
- package/src/messaging/providers/telegram-bot/withdraw.ts +4 -5
- package/src/monitoring/__tests__/proc-fixtures.ts +28 -0
- package/src/monitoring/__tests__/proc-wait-state.test.ts +232 -0
- package/src/monitoring/__tests__/process-usage.test.ts +243 -0
- package/src/monitoring/proc-wait-state.ts +366 -0
- package/src/monitoring/process-memory.ts +4 -3
- package/src/monitoring/process-usage.ts +215 -0
- package/src/monitoring/resource-sample-types.ts +8 -0
- package/src/monitoring/resource-sampler.ts +17 -2
- package/src/monitoring/stall-capture.ts +12 -0
- package/src/notifications/README.md +88 -9
- package/src/notifications/__tests__/assistant-reply-producer.test.ts +390 -119
- package/src/notifications/__tests__/background-result-producer.test.ts +1272 -0
- package/src/notifications/__tests__/broadcaster.test.ts +292 -1
- package/src/notifications/__tests__/completion-policy.test.ts +243 -0
- package/src/notifications/__tests__/decision-engine.test.ts +51 -4
- package/src/notifications/__tests__/has-pending-background-work.test.ts +281 -0
- package/src/notifications/__tests__/home-feed-side-effect.test.ts +161 -3
- package/src/notifications/__tests__/resolve-visible-in-source.test.ts +110 -1
- package/src/notifications/__tests__/schedule-result-producer.test.ts +11 -4
- package/src/notifications/adapters/macos.ts +24 -12
- package/src/notifications/adapters/platform.ts +16 -5
- package/src/notifications/assistant-reply-producer.ts +96 -71
- package/src/notifications/background-result-producer.ts +369 -0
- package/src/notifications/broadcaster.ts +28 -8
- package/src/notifications/completion-policy.ts +115 -0
- package/src/notifications/completion-work.ts +46 -0
- package/src/notifications/conversation-pairing.ts +32 -13
- package/src/notifications/decision-engine.ts +18 -24
- package/src/notifications/emit-signal.ts +16 -1
- package/src/notifications/events-store.ts +4 -0
- package/src/notifications/has-pending-background-work.ts +91 -0
- package/src/notifications/home-feed-mirror.ts +44 -0
- package/src/notifications/home-feed-side-effect.ts +54 -28
- package/src/notifications/resolve-visible-in-source.ts +56 -2
- package/src/notifications/result-output.ts +154 -0
- package/src/notifications/schedule-result-producer.ts +6 -187
- package/src/notifications/types.ts +2 -0
- package/src/oauth/AGENTS.md +9 -1
- package/src/oauth/byo-connection.test.ts +28 -0
- package/src/persistence/__tests__/recent-conversation-messages.test.ts +41 -0
- package/src/persistence/conversation-crud.ts +26 -0
- package/src/persistence/conversation-types.ts +15 -37
- package/src/persistence/embeddings/__tests__/embedding-local-lifecycle.test.ts +85 -14
- package/src/persistence/jobs-store.ts +229 -0
- package/src/persistence/migrations/383-normalize-opencode-host-connections.ts +44 -0
- package/src/persistence/migrations/__tests__/383-normalize-opencode-host-connections.test.ts +102 -0
- package/src/persistence/steps.ts +12 -0
- package/src/platform/sync-avatar.test.ts +29 -0
- package/src/plugins/defaults/memory/AGENTS.md +5 -3
- package/src/plugins/defaults/memory/__tests__/skill-update-receipt-boundary-guard.test.ts +45 -0
- package/src/plugins/defaults/memory/__tests__/skill-update-receipt-job.test.ts +580 -0
- package/src/plugins/defaults/memory/__tests__/turn-retrieval.test.ts +21 -0
- package/src/plugins/defaults/memory/graph/tools.ts +9 -5
- package/src/plugins/defaults/memory/hooks/conversation-deleted.ts +4 -0
- package/src/plugins/defaults/memory/hooks/user-prompt-submit.ts +7 -3
- package/src/plugins/defaults/memory/job-handlers.ts +8 -2
- package/src/plugins/defaults/memory/skill-update-receipt-job.ts +334 -0
- package/src/plugins/defaults/memory/tools.test.ts +17 -0
- package/src/plugins/defaults/memory/turn-retrieval.ts +8 -0
- package/src/plugins/defaults/memory/v3/__tests__/injection.test.ts +24 -0
- package/src/plugins/defaults/memory/v3/injector.ts +4 -4
- package/src/plugins/types.ts +2 -0
- package/src/providers/__tests__/search-provider-catalog.test.ts +8 -0
- package/src/providers/anthropic/client.ts +4 -0
- package/src/providers/gemini/client.ts +7 -1
- package/src/providers/inference/auth.ts +25 -0
- package/src/providers/inference/profile-probe.ts +1 -0
- package/src/{calls/__tests__/typesafe-noul.test.ts → providers/jev/ask.test.ts} +4 -4
- package/src/{calls/typesafe-noul.ts → providers/jev/ask.ts} +67 -34
- package/src/providers/openai/__tests__/api-error-normalization.test.ts +12 -0
- package/src/providers/openai/api-error-normalization.ts +4 -0
- package/src/providers/retry.ts +2 -0
- package/src/providers/search-provider-catalog.ts +10 -0
- package/src/providers/types.ts +7 -0
- package/src/providers/usage-tracking.ts +5 -3
- package/src/runtime/__tests__/agent-wake.test.ts +308 -0
- package/src/runtime/access-request-helper.ts +16 -9
- package/src/runtime/agent-wake-queue.ts +52 -0
- package/src/runtime/agent-wake.ts +111 -18
- package/src/runtime/channel-approval-types.ts +6 -38
- package/src/runtime/channel-approvals.ts +4 -5
- package/src/runtime/http-server.ts +4 -1
- package/src/runtime/introduction-policy.test.ts +17 -1
- package/src/runtime/introduction-policy.ts +25 -7
- package/src/runtime/migrations/vbundle-builder.ts +9 -0
- package/src/runtime/routes/__tests__/inference-profiles-routes.test.ts +21 -1
- package/src/runtime/routes/__tests__/inference-provider-connection-routes.test.ts +60 -0
- package/src/runtime/routes/__tests__/oauth-proxy-routes.test.ts +61 -3
- package/src/runtime/routes/auto-profile-routes.ts +83 -0
- package/src/runtime/routes/conversation-management-routes.ts +1 -3
- package/src/runtime/routes/conversation-routes.ts +9 -0
- package/src/runtime/routes/guardian-action-routes.ts +8 -23
- package/src/runtime/routes/host-cu-routes.ts +3 -1
- package/src/runtime/routes/index.ts +2 -0
- package/src/runtime/routes/inference-profiles-routes.ts +5 -2
- package/src/runtime/routes/inference-provider-connection-routes.ts +25 -8
- package/src/runtime/routes/migration-routes.ts +8 -2
- package/src/runtime/routes/oauth-proxy-passthrough.test.ts +32 -0
- package/src/runtime/routes/platform-routes.ts +6 -1
- package/src/runtime/routes/user-route-dispatcher.ts +1 -2
- package/src/runtime/web-presence.ts +3 -4
- package/src/schedule/schedule-store.ts +10 -0
- package/src/schedule/scheduler.ts +92 -24
- package/src/subagent/manager.ts +32 -12
- package/src/telegram/__tests__/webhook-health.test.ts +8 -0
- package/src/telemetry/telemetry-wire-source.json +1 -1
- package/src/telemetry/telemetry-wire.generated.ts +1 -0
- package/src/tools/background-tool-registry.ts +30 -3
- package/src/tools/browser/cdp-client/local-cdp-client.ts +1 -2
- package/src/tools/host-terminal/host-shell.ts +7 -0
- package/src/tools/network/__tests__/web-fetch-firecrawl.test.ts +28 -1
- package/src/tools/network/__tests__/web-fetch-metadata.test.ts +34 -0
- package/src/tools/network/__tests__/web-fetch-tinyfish.test.ts +35 -1
- package/src/tools/network/__tests__/web-search.test.ts +96 -0
- package/src/tools/network/web-fetch.ts +30 -9
- package/src/tools/network/web-search.ts +235 -4
- package/src/tools/skills/load.ts +13 -17
- package/src/tools/skills/scaffold-managed.ts +86 -71
- package/src/tools/terminal/shell-launch.test.ts +27 -1
- package/src/tools/terminal/shell.ts +4 -0
- package/src/tools/workspace-tools/loader.ts +1 -2
- package/src/usage/attribution.ts +18 -1
- package/src/util/abort-reasons.ts +2 -0
- package/src/util/errors.ts +1 -0
- package/src/util/oauth-request-body.test.ts +5 -1
- package/src/util/provider-error-patterns.ts +11 -0
- package/src/util/single-flight.test.ts +6 -0
- package/src/util/single-flight.ts +2 -0
- package/src/util/worker-pipe.test.ts +56 -10
- package/src/util/worker-pipe.ts +9 -4
- package/src/workspace/git-service.ts +6 -1
- package/src/workspace/migrations/158-repoint-opencode-host-provider-fragments.ts +163 -0
- package/src/workspace/migrations/__tests__/158-repoint-opencode-host-provider-fragments.test.ts +188 -0
- package/src/workspace/migrations/registry.ts +2 -0
|
@@ -1,28 +1,36 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* One bounded
|
|
3
|
-
* the voice judges
|
|
4
|
-
*
|
|
5
|
-
* keeps its default
|
|
2
|
+
* One bounded question set to TypeSafe's System One model (Jev), shared by
|
|
3
|
+
* the voice judges and the automatic profile router. A caller runs its
|
|
4
|
+
* question only when its call site resolves to the TypeSafe provider; every
|
|
5
|
+
* failure comes back as a non-answer so the caller keeps its default
|
|
6
|
+
* behavior.
|
|
6
7
|
*/
|
|
7
8
|
|
|
8
|
-
import type { LLMCallSite } from "
|
|
9
|
-
import {
|
|
10
|
-
import { resolveConfiguredProvider } from "../
|
|
11
|
-
import type { Provider, ProviderResponse } from "../
|
|
12
|
-
import {
|
|
9
|
+
import type { LLMCallSite } from "../../config/schemas/llm.js";
|
|
10
|
+
import { getLogger } from "../../util/logger.js";
|
|
11
|
+
import { resolveConfiguredProvider } from "../provider-send-message.js";
|
|
12
|
+
import type { Provider, ProviderResponse } from "../types.js";
|
|
13
|
+
import {
|
|
14
|
+
type JevJsonValue,
|
|
15
|
+
type JevQuestions,
|
|
16
|
+
noulFromAnswer,
|
|
17
|
+
} from "./client.js";
|
|
13
18
|
|
|
14
|
-
const log = getLogger("typesafe-
|
|
19
|
+
const log = getLogger("typesafe-ask");
|
|
15
20
|
|
|
16
21
|
const TYPESAFE_PROVIDER_NAME = "typesafe";
|
|
17
22
|
|
|
18
|
-
export type
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
export type TypesafeOutcome = "answered" | "unavailable" | "timeout" | "error";
|
|
24
|
+
|
|
25
|
+
export interface TypesafeAskResult {
|
|
26
|
+
outcome: TypesafeOutcome;
|
|
27
|
+
/** One entry per question id, present when the outcome is "answered". */
|
|
28
|
+
answers?: Record<string, unknown>;
|
|
29
|
+
latencyMs: number;
|
|
30
|
+
}
|
|
23
31
|
|
|
24
32
|
export interface TypesafeNoulResult {
|
|
25
|
-
outcome:
|
|
33
|
+
outcome: TypesafeOutcome;
|
|
26
34
|
/** Calibrated P(yes), present when the outcome is "answered". */
|
|
27
35
|
noul?: number;
|
|
28
36
|
latencyMs: number;
|
|
@@ -71,21 +79,25 @@ function answersFrom(
|
|
|
71
79
|
}
|
|
72
80
|
}
|
|
73
81
|
|
|
74
|
-
|
|
75
|
-
* Ask one noul question. Never rejects. The timeout is a hard race rather
|
|
76
|
-
* than trust in the provider honoring the abort, because callers hold user
|
|
77
|
-
* audio or background work on the answer.
|
|
78
|
-
*/
|
|
79
|
-
export async function askTypesafeNoul(args: {
|
|
82
|
+
export interface TypesafeAskArgs {
|
|
80
83
|
callSite: LLMCallSite;
|
|
81
84
|
conversationId: string;
|
|
82
85
|
state: JevJsonValue;
|
|
83
|
-
|
|
86
|
+
questions: JevQuestions;
|
|
84
87
|
timeoutMs: number;
|
|
85
88
|
signal?: AbortSignal;
|
|
86
89
|
/** Defaults to {@link resolveTypesafeProvider} for `callSite`. */
|
|
87
90
|
resolveProvider?: () => Promise<Provider | null>;
|
|
88
|
-
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Ask one question set. Never rejects. The timeout is a hard race rather
|
|
95
|
+
* than trust in the provider honoring the abort, because callers hold user
|
|
96
|
+
* audio or a turn's first token on the answer.
|
|
97
|
+
*/
|
|
98
|
+
export async function askTypesafe(
|
|
99
|
+
args: TypesafeAskArgs,
|
|
100
|
+
): Promise<TypesafeAskResult> {
|
|
89
101
|
const startedAt = Date.now();
|
|
90
102
|
const elapsed = () => Date.now() - startedAt;
|
|
91
103
|
const controller = new AbortController();
|
|
@@ -93,7 +105,7 @@ export async function askTypesafeNoul(args: {
|
|
|
93
105
|
? AbortSignal.any([args.signal, controller.signal])
|
|
94
106
|
: controller.signal;
|
|
95
107
|
|
|
96
|
-
const ask = async (): Promise<
|
|
108
|
+
const ask = async (): Promise<TypesafeAskResult> => {
|
|
97
109
|
try {
|
|
98
110
|
const provider = await (
|
|
99
111
|
args.resolveProvider ?? (() => resolveTypesafeProvider(args.callSite))
|
|
@@ -110,9 +122,7 @@ export async function askTypesafeNoul(args: {
|
|
|
110
122
|
type: "text",
|
|
111
123
|
text: JSON.stringify({
|
|
112
124
|
state: args.state,
|
|
113
|
-
questions:
|
|
114
|
-
answer: { type: "noul", instructions: args.instructions },
|
|
115
|
-
},
|
|
125
|
+
questions: args.questions,
|
|
116
126
|
}),
|
|
117
127
|
},
|
|
118
128
|
],
|
|
@@ -127,20 +137,20 @@ export async function askTypesafeNoul(args: {
|
|
|
127
137
|
signal,
|
|
128
138
|
},
|
|
129
139
|
);
|
|
130
|
-
const
|
|
131
|
-
if (
|
|
140
|
+
const answers = answersFrom(response);
|
|
141
|
+
if (answers === null) {
|
|
132
142
|
log.warn(
|
|
133
143
|
{ callSite: args.callSite, conversationId: args.conversationId },
|
|
134
|
-
"TypeSafe
|
|
144
|
+
"TypeSafe returned no usable answers",
|
|
135
145
|
);
|
|
136
146
|
return { outcome: "error", latencyMs: elapsed() };
|
|
137
147
|
}
|
|
138
|
-
return { outcome: "answered",
|
|
148
|
+
return { outcome: "answered", answers, latencyMs: elapsed() };
|
|
139
149
|
} catch (err) {
|
|
140
150
|
if (!signal.aborted) {
|
|
141
151
|
log.warn(
|
|
142
152
|
{ err, callSite: args.callSite, conversationId: args.conversationId },
|
|
143
|
-
"TypeSafe
|
|
153
|
+
"TypeSafe question failed",
|
|
144
154
|
);
|
|
145
155
|
}
|
|
146
156
|
return { outcome: "error", latencyMs: elapsed() };
|
|
@@ -148,7 +158,7 @@ export async function askTypesafeNoul(args: {
|
|
|
148
158
|
};
|
|
149
159
|
|
|
150
160
|
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
151
|
-
const timedOut = new Promise<
|
|
161
|
+
const timedOut = new Promise<TypesafeAskResult>((resolve) => {
|
|
152
162
|
timer = setTimeout(() => {
|
|
153
163
|
controller.abort();
|
|
154
164
|
resolve({ outcome: "timeout", latencyMs: elapsed() });
|
|
@@ -160,3 +170,26 @@ export async function askTypesafeNoul(args: {
|
|
|
160
170
|
clearTimeout(timer);
|
|
161
171
|
}
|
|
162
172
|
}
|
|
173
|
+
|
|
174
|
+
/** Ask one yes/no question. Never rejects. */
|
|
175
|
+
export async function askTypesafeNoul(
|
|
176
|
+
args: Omit<TypesafeAskArgs, "questions"> & { instructions: string },
|
|
177
|
+
): Promise<TypesafeNoulResult> {
|
|
178
|
+
const { instructions, ...rest } = args;
|
|
179
|
+
const result = await askTypesafe({
|
|
180
|
+
...rest,
|
|
181
|
+
questions: { answer: { type: "noul", instructions } },
|
|
182
|
+
});
|
|
183
|
+
if (result.outcome !== "answered") {
|
|
184
|
+
return { outcome: result.outcome, latencyMs: result.latencyMs };
|
|
185
|
+
}
|
|
186
|
+
const noul = noulFromAnswer(result.answers?.answer);
|
|
187
|
+
if (noul === undefined) {
|
|
188
|
+
log.warn(
|
|
189
|
+
{ callSite: args.callSite, conversationId: args.conversationId },
|
|
190
|
+
"TypeSafe judge returned no usable answer",
|
|
191
|
+
);
|
|
192
|
+
return { outcome: "error", latencyMs: result.latencyMs };
|
|
193
|
+
}
|
|
194
|
+
return { outcome: "answered", noul, latencyMs: result.latencyMs };
|
|
195
|
+
}
|
|
@@ -463,6 +463,18 @@ describe("deriveReason", () => {
|
|
|
463
463
|
expect(deriveReason(n(), 402)).toBe("insufficient_credits");
|
|
464
464
|
});
|
|
465
465
|
|
|
466
|
+
test("free-tier daily-limit body code → free_tier_daily_limit_reached (before insufficient_credits)", () => {
|
|
467
|
+
expect(
|
|
468
|
+
deriveReason(
|
|
469
|
+
n({
|
|
470
|
+
rawBody:
|
|
471
|
+
'{"code":"free_tier_daily_limit_reached","detail":"free usage"}',
|
|
472
|
+
}),
|
|
473
|
+
402,
|
|
474
|
+
),
|
|
475
|
+
).toBe("free_tier_daily_limit_reached");
|
|
476
|
+
});
|
|
477
|
+
|
|
466
478
|
test("daily-limit body code → daily_limit_reached (before insufficient_credits)", () => {
|
|
467
479
|
// Both are 402s from the managed proxy; the specific daily-limit code must
|
|
468
480
|
// win over the generic status-402 → insufficient_credits mapping.
|
|
@@ -3,6 +3,7 @@ import OpenAI from "openai";
|
|
|
3
3
|
import type { ProviderErrorReason } from "../../util/errors.js";
|
|
4
4
|
import {
|
|
5
5
|
DAILY_LIMIT_PATTERNS,
|
|
6
|
+
FREE_TIER_DAILY_LIMIT_PATTERNS,
|
|
6
7
|
INSUFFICIENT_CREDITS_PATTERNS,
|
|
7
8
|
isChatTemplateFailureError,
|
|
8
9
|
MODEL_NOT_FOUND_PATTERNS,
|
|
@@ -111,6 +112,9 @@ export function deriveReason(
|
|
|
111
112
|
|
|
112
113
|
// The managed proxy's daily-limit 402 shares the status with generic credit
|
|
113
114
|
// exhaustion; match its specific body code first so it isn't swallowed.
|
|
115
|
+
if (FREE_TIER_DAILY_LIMIT_PATTERNS.some((re) => re.test(haystack))) {
|
|
116
|
+
return "free_tier_daily_limit_reached";
|
|
117
|
+
}
|
|
114
118
|
if (DAILY_LIMIT_PATTERNS.some((re) => re.test(haystack))) {
|
|
115
119
|
return "daily_limit_reached";
|
|
116
120
|
}
|
package/src/providers/retry.ts
CHANGED
|
@@ -689,6 +689,7 @@ function normalizeSendMessageOptions(
|
|
|
689
689
|
// (after the `openai` promptCacheKey copy above) so they never leak into
|
|
690
690
|
// provider request bodies even when callers set them without a `callSite`.
|
|
691
691
|
delete nextConfig.overrideProfile;
|
|
692
|
+
delete nextConfig.overrideProfileOrigin;
|
|
692
693
|
delete nextConfig.forceOverrideProfile;
|
|
693
694
|
delete nextConfig.selectionSeed;
|
|
694
695
|
delete nextConfig.conversationId;
|
|
@@ -703,6 +704,7 @@ function normalizeSendMessageOptions(
|
|
|
703
704
|
const attribution = resolveUsageAttribution({
|
|
704
705
|
callSite: config.callSite,
|
|
705
706
|
overrideProfile: config.overrideProfile,
|
|
707
|
+
overrideProfileOrigin: config.overrideProfileOrigin,
|
|
706
708
|
forceOverrideProfile: config.forceOverrideProfile,
|
|
707
709
|
selectionSeed: config.selectionSeed,
|
|
708
710
|
});
|
|
@@ -187,6 +187,16 @@ export const SEARCH_PROVIDER_CATALOG: readonly SearchProviderCatalogEntry[] = [
|
|
|
187
187
|
supportsApiBase: true,
|
|
188
188
|
defaultApiBase: "https://api.search.tinyfish.ai",
|
|
189
189
|
},
|
|
190
|
+
{
|
|
191
|
+
id: "exa",
|
|
192
|
+
displayName: "Exa",
|
|
193
|
+
kind: "byok",
|
|
194
|
+
apiKeyPrefix: "Exa API key...",
|
|
195
|
+
envVar: "EXA_API_KEY",
|
|
196
|
+
secretKey: "exa",
|
|
197
|
+
fallbackOrder: 9,
|
|
198
|
+
privacyPolicyUrl: "https://exa.ai/privacy-policy",
|
|
199
|
+
},
|
|
190
200
|
];
|
|
191
201
|
|
|
192
202
|
/** Provider ids accepted by the web-search config schema. */
|
package/src/providers/types.ts
CHANGED
|
@@ -346,6 +346,13 @@ export interface SendMessageConfig {
|
|
|
346
346
|
* silently fall through.
|
|
347
347
|
*/
|
|
348
348
|
overrideProfile?: string;
|
|
349
|
+
/**
|
|
350
|
+
* Who chose `overrideProfile`: `"auto"` when the Auto profile's router
|
|
351
|
+
* picked it for the turn. Usage attribution reports it as the profile
|
|
352
|
+
* source so a routed turn is not counted as a user pin. A routing-time
|
|
353
|
+
* concern only; stripped before any provider wire request.
|
|
354
|
+
*/
|
|
355
|
+
overrideProfileOrigin?: "auto";
|
|
349
356
|
/**
|
|
350
357
|
* When true, the resolver floats `overrideProfile` above the call-site
|
|
351
358
|
* layers (named site profile + call-site override) for non-main-agent call
|
|
@@ -77,9 +77,11 @@ export class UsageTrackingProvider implements Provider {
|
|
|
77
77
|
const attribution = resolveUsageAttribution({
|
|
78
78
|
callSite: config.callSite,
|
|
79
79
|
overrideProfile: appliedOverride,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
// A rerouted serve ran on the backup the wrapper chose, not on the
|
|
81
|
+
// router's pick, so the origin applies only to the original route.
|
|
82
|
+
...(response.actualInferenceProfile === undefined
|
|
83
|
+
? { overrideProfileOrigin: config.overrideProfileOrigin }
|
|
84
|
+
: { forceOverrideProfile: true }),
|
|
83
85
|
});
|
|
84
86
|
const providerName = response.actualProvider ?? this.inner.name;
|
|
85
87
|
const pricingUsage = buildPricingUsageFromResponse(
|
|
@@ -22,6 +22,12 @@ import { beforeEach, describe, expect, mock, spyOn, test } from "bun:test";
|
|
|
22
22
|
|
|
23
23
|
import type { DiskPressureStatus } from "../../daemon/disk-pressure-guard.js";
|
|
24
24
|
import { desktopAutomationLease } from "../../desktop/desktop-automation-lease.js";
|
|
25
|
+
import { hasPendingAgentWake } from "../agent-wake-queue.js";
|
|
26
|
+
|
|
27
|
+
let scheduleRunStatus: "running" | "ok" | "error" | undefined;
|
|
28
|
+
mock.module("../../schedule/schedule-store.js", () => ({
|
|
29
|
+
getScheduleRunStatus: () => scheduleRunStatus,
|
|
30
|
+
}));
|
|
25
31
|
|
|
26
32
|
// ── Per-conversation capture registry ────────────────────────────────
|
|
27
33
|
//
|
|
@@ -131,6 +137,27 @@ interface WakeConversationProbe {
|
|
|
131
137
|
}
|
|
132
138
|
|
|
133
139
|
const wakeConvRegistry = new Map<string, WakeConversationProbe>();
|
|
140
|
+
const backgroundNotificationCalls: Array<{
|
|
141
|
+
conversationId: string;
|
|
142
|
+
assistantMessageId?: string;
|
|
143
|
+
userMessageId?: string;
|
|
144
|
+
recoverOnly?: boolean;
|
|
145
|
+
pendingWake: boolean;
|
|
146
|
+
}> = [];
|
|
147
|
+
mock.module("../../notifications/background-result-producer.js", () => ({
|
|
148
|
+
emitBackgroundResultNotification: async (params: {
|
|
149
|
+
conversationId: string;
|
|
150
|
+
assistantMessageId?: string;
|
|
151
|
+
userMessageId?: string;
|
|
152
|
+
recoverOnly?: boolean;
|
|
153
|
+
}) => {
|
|
154
|
+
backgroundNotificationCalls.push({
|
|
155
|
+
...params,
|
|
156
|
+
pendingWake: hasPendingAgentWake(params.conversationId),
|
|
157
|
+
});
|
|
158
|
+
wakeConvRegistry.get(params.conversationId)?.callSequence.push("notify");
|
|
159
|
+
},
|
|
160
|
+
}));
|
|
134
161
|
|
|
135
162
|
// Stub the DB-backed override-profile read so unit tests don't need a
|
|
136
163
|
// real SQLite database. The wake helper calls this on every invocation
|
|
@@ -144,8 +171,18 @@ const wakeConvRegistry = new Map<string, WakeConversationProbe>();
|
|
|
144
171
|
let mockGetConversationOverrideProfile: (
|
|
145
172
|
conversationId: string,
|
|
146
173
|
) => string | undefined = () => undefined;
|
|
174
|
+
const wakeOutcomeStamps: Array<{
|
|
175
|
+
messageId: string;
|
|
176
|
+
metadata: Record<string, unknown>;
|
|
177
|
+
}> = [];
|
|
147
178
|
|
|
148
179
|
mock.module("../../persistence/conversation-crud.js", () => ({
|
|
180
|
+
updateMessageMetadata: (
|
|
181
|
+
messageId: string,
|
|
182
|
+
metadata: Record<string, unknown>,
|
|
183
|
+
) => {
|
|
184
|
+
wakeOutcomeStamps.push({ messageId, metadata });
|
|
185
|
+
},
|
|
149
186
|
getConversationOverrideProfile: (conversationId: string) =>
|
|
150
187
|
mockGetConversationOverrideProfile(conversationId),
|
|
151
188
|
getConversation: () => ({
|
|
@@ -625,6 +662,9 @@ function makeWakeConversation(options: {
|
|
|
625
662
|
let wakeSightFrameCaptureTimes = new Map<string, number>();
|
|
626
663
|
|
|
627
664
|
beforeEach(() => {
|
|
665
|
+
scheduleRunStatus = undefined;
|
|
666
|
+
wakeOutcomeStamps.length = 0;
|
|
667
|
+
backgroundNotificationCalls.length = 0;
|
|
628
668
|
__resetWakeChainForTests();
|
|
629
669
|
wakeSightFrameCaptureTimes = new Map();
|
|
630
670
|
wakeConvRegistry.clear();
|
|
@@ -654,6 +694,109 @@ beforeEach(() => {
|
|
|
654
694
|
// ── Tests ────────────────────────────────────────────────────────────
|
|
655
695
|
|
|
656
696
|
describe("wakeAgentForOpportunity", () => {
|
|
697
|
+
test("tracks each scheduled owner while wakes hydrate and wait behind other wakes", async () => {
|
|
698
|
+
const firstGate = Promise.withResolvers<void>();
|
|
699
|
+
const secondGate = Promise.withResolvers<void>();
|
|
700
|
+
const lastGate = Promise.withResolvers<void>();
|
|
701
|
+
const conversationId = "conv-scheduled-wakes";
|
|
702
|
+
const start = (cronRunId: string | undefined, gate: Promise<void>) =>
|
|
703
|
+
wakeAgentForOpportunity(
|
|
704
|
+
{
|
|
705
|
+
conversationId,
|
|
706
|
+
cronRunId,
|
|
707
|
+
source: "background-tool",
|
|
708
|
+
hint: "Command finished",
|
|
709
|
+
},
|
|
710
|
+
{
|
|
711
|
+
resolveTarget: async () => {
|
|
712
|
+
await gate;
|
|
713
|
+
return null;
|
|
714
|
+
},
|
|
715
|
+
},
|
|
716
|
+
);
|
|
717
|
+
const first = start("run-first", firstGate.promise);
|
|
718
|
+
const second = start("run-second", secondGate.promise);
|
|
719
|
+
const repeated = start("run-first", lastGate.promise);
|
|
720
|
+
const userWake = start(undefined, Promise.resolve());
|
|
721
|
+
try {
|
|
722
|
+
expect(hasPendingAgentWake(conversationId, "run-first")).toBe(true);
|
|
723
|
+
expect(hasPendingAgentWake(conversationId, "run-second")).toBe(true);
|
|
724
|
+
expect(hasPendingAgentWake(conversationId, "run-other")).toBe(false);
|
|
725
|
+
firstGate.resolve();
|
|
726
|
+
await first;
|
|
727
|
+
expect(hasPendingAgentWake(conversationId, "run-first")).toBe(true);
|
|
728
|
+
secondGate.resolve();
|
|
729
|
+
await second;
|
|
730
|
+
expect(hasPendingAgentWake(conversationId, "run-second")).toBe(false);
|
|
731
|
+
expect(hasPendingAgentWake(conversationId, "run-first")).toBe(true);
|
|
732
|
+
} finally {
|
|
733
|
+
firstGate.resolve();
|
|
734
|
+
secondGate.resolve();
|
|
735
|
+
lastGate.resolve();
|
|
736
|
+
await Promise.all([first, second, repeated, userWake]);
|
|
737
|
+
}
|
|
738
|
+
expect(hasPendingAgentWake(conversationId)).toBe(false);
|
|
739
|
+
expect(hasPendingAgentWake(conversationId, "run-first")).toBe(false);
|
|
740
|
+
});
|
|
741
|
+
|
|
742
|
+
test("age-filters command wakes throughout hydration and single-flight queueing", async () => {
|
|
743
|
+
const conversationId = "conv-wake-age";
|
|
744
|
+
const oldGate = Promise.withResolvers<void>();
|
|
745
|
+
const freshGate = Promise.withResolvers<void>();
|
|
746
|
+
const start = (startedAt: number, gate: Promise<void>) =>
|
|
747
|
+
wakeAgentForOpportunity(
|
|
748
|
+
{
|
|
749
|
+
conversationId,
|
|
750
|
+
source: "background-tool",
|
|
751
|
+
hint: "Command completed",
|
|
752
|
+
backgroundToolCompletion: {
|
|
753
|
+
id: `tool-${startedAt}`,
|
|
754
|
+
conversationId,
|
|
755
|
+
toolName: "bash",
|
|
756
|
+
command: "example-command",
|
|
757
|
+
startedAt,
|
|
758
|
+
completedAt: 300,
|
|
759
|
+
status: "completed",
|
|
760
|
+
exitCode: 0,
|
|
761
|
+
output: "Done",
|
|
762
|
+
},
|
|
763
|
+
},
|
|
764
|
+
{
|
|
765
|
+
resolveTarget: async () => {
|
|
766
|
+
await gate;
|
|
767
|
+
return null;
|
|
768
|
+
},
|
|
769
|
+
},
|
|
770
|
+
);
|
|
771
|
+
const older = start(100, oldGate.promise);
|
|
772
|
+
try {
|
|
773
|
+
expect(
|
|
774
|
+
hasPendingAgentWake(conversationId, undefined, { startedAfter: 200 }),
|
|
775
|
+
).toBe(false);
|
|
776
|
+
const fresh = start(200, freshGate.promise);
|
|
777
|
+
try {
|
|
778
|
+
expect(
|
|
779
|
+
hasPendingAgentWake(conversationId, undefined, { startedAfter: 200 }),
|
|
780
|
+
).toBe(true);
|
|
781
|
+
oldGate.resolve();
|
|
782
|
+
await older;
|
|
783
|
+
expect(
|
|
784
|
+
hasPendingAgentWake(conversationId, undefined, { startedAfter: 200 }),
|
|
785
|
+
).toBe(true);
|
|
786
|
+
} finally {
|
|
787
|
+
freshGate.resolve();
|
|
788
|
+
await fresh;
|
|
789
|
+
}
|
|
790
|
+
} finally {
|
|
791
|
+
oldGate.resolve();
|
|
792
|
+
await older;
|
|
793
|
+
}
|
|
794
|
+
expect(hasPendingAgentWake(conversationId)).toBe(false);
|
|
795
|
+
expect(
|
|
796
|
+
hasPendingAgentWake(conversationId, undefined, { startedAfter: 200 }),
|
|
797
|
+
).toBe(false);
|
|
798
|
+
});
|
|
799
|
+
|
|
657
800
|
test("disabled disk pressure flag allows background wakes to pass through", async () => {
|
|
658
801
|
const conversation = makeWakeConversation({
|
|
659
802
|
scriptedAssistant: null,
|
|
@@ -3795,3 +3938,168 @@ describe("wakeAgentForOpportunity", () => {
|
|
|
3795
3938
|
});
|
|
3796
3939
|
});
|
|
3797
3940
|
});
|
|
3941
|
+
|
|
3942
|
+
describe("background command completion notification wiring", () => {
|
|
3943
|
+
for (const status of ["completed", "failed", "cancelled"] as const) {
|
|
3944
|
+
test.each([
|
|
3945
|
+
"no_tool_calls",
|
|
3946
|
+
"error",
|
|
3947
|
+
"aborted_pre_call",
|
|
3948
|
+
"checkpoint_handoff",
|
|
3949
|
+
] as const)(
|
|
3950
|
+
`%s wake settles a ${status} command after releasing the wake queue`,
|
|
3951
|
+
async (reason) => {
|
|
3952
|
+
const conversation = makeWakeConversation({
|
|
3953
|
+
conversationId: "conv-command-result",
|
|
3954
|
+
runImpl: async (input, onEvent) => {
|
|
3955
|
+
await onEvent({ type: "agent_loop_exit", reason });
|
|
3956
|
+
return runResult([
|
|
3957
|
+
...input,
|
|
3958
|
+
{
|
|
3959
|
+
role: "assistant",
|
|
3960
|
+
content: [
|
|
3961
|
+
{ type: "text", text: "The requested export is ready." },
|
|
3962
|
+
],
|
|
3963
|
+
},
|
|
3964
|
+
]);
|
|
3965
|
+
},
|
|
3966
|
+
});
|
|
3967
|
+
await wakeAgentForOpportunity(
|
|
3968
|
+
{
|
|
3969
|
+
conversationId: conversation.conversationId,
|
|
3970
|
+
hint: "Background command completed",
|
|
3971
|
+
source: "background-tool",
|
|
3972
|
+
persistTriggerAsEvent: true,
|
|
3973
|
+
backgroundToolCompletion: {
|
|
3974
|
+
id: "tool-123",
|
|
3975
|
+
toolName: "bash",
|
|
3976
|
+
conversationId: conversation.conversationId,
|
|
3977
|
+
command: "example-command",
|
|
3978
|
+
startedAt: 1,
|
|
3979
|
+
completedAt: 2,
|
|
3980
|
+
status,
|
|
3981
|
+
exitCode: 0,
|
|
3982
|
+
output: "file exported",
|
|
3983
|
+
},
|
|
3984
|
+
},
|
|
3985
|
+
{ resolveTarget: async () => conversation },
|
|
3986
|
+
);
|
|
3987
|
+
expect(backgroundNotificationCalls).toHaveLength(1);
|
|
3988
|
+
expect(backgroundNotificationCalls[0].pendingWake).toBe(false);
|
|
3989
|
+
expect(backgroundNotificationCalls[0].recoverOnly).toBe(
|
|
3990
|
+
reason !== "no_tool_calls",
|
|
3991
|
+
);
|
|
3992
|
+
expect(wakeOutcomeStamps).toHaveLength(
|
|
3993
|
+
reason === "no_tool_calls" ? 0 : 1,
|
|
3994
|
+
);
|
|
3995
|
+
if (reason === "no_tool_calls") {
|
|
3996
|
+
expect(backgroundNotificationCalls[0]).toMatchObject({
|
|
3997
|
+
userMessageId: "msg-1",
|
|
3998
|
+
assistantMessageId: "msg-2",
|
|
3999
|
+
});
|
|
4000
|
+
expect(conversation.callSequence.lastIndexOf("persist")).toBeLessThan(
|
|
4001
|
+
conversation.callSequence.indexOf("notify"),
|
|
4002
|
+
);
|
|
4003
|
+
}
|
|
4004
|
+
},
|
|
4005
|
+
);
|
|
4006
|
+
}
|
|
4007
|
+
});
|
|
4008
|
+
|
|
4009
|
+
describe("scheduled wake cancellation", () => {
|
|
4010
|
+
test("a wake loading its target cannot resume a failed run", async () => {
|
|
4011
|
+
scheduleRunStatus = "running";
|
|
4012
|
+
const loading = Promise.withResolvers<void>();
|
|
4013
|
+
const release = Promise.withResolvers<void>();
|
|
4014
|
+
const conversation = makeWakeConversation({});
|
|
4015
|
+
const wake = wakeAgentForOpportunity(
|
|
4016
|
+
{
|
|
4017
|
+
conversationId: conversation.conversationId,
|
|
4018
|
+
cronRunId: "run-123",
|
|
4019
|
+
source: "background-tool",
|
|
4020
|
+
hint: "Command finished",
|
|
4021
|
+
},
|
|
4022
|
+
{
|
|
4023
|
+
resolveTarget: async () => {
|
|
4024
|
+
loading.resolve();
|
|
4025
|
+
await release.promise;
|
|
4026
|
+
return conversation;
|
|
4027
|
+
},
|
|
4028
|
+
},
|
|
4029
|
+
);
|
|
4030
|
+
await loading.promise;
|
|
4031
|
+
scheduleRunStatus = "error";
|
|
4032
|
+
release.resolve();
|
|
4033
|
+
expect(await wake).toMatchObject({ invoked: false, reason: "timeout" });
|
|
4034
|
+
expect(conversation.runCalls).toHaveLength(0);
|
|
4035
|
+
expect(conversation.processingToggles).toEqual([]);
|
|
4036
|
+
});
|
|
4037
|
+
|
|
4038
|
+
test("cancellation reaches the active loop and prevents queued schedule wakes", async () => {
|
|
4039
|
+
scheduleRunStatus = "running";
|
|
4040
|
+
const running = Promise.withResolvers<AbortSignal>();
|
|
4041
|
+
const conversation = makeWakeConversation({
|
|
4042
|
+
runImpl: async (input, onEvent, options) => {
|
|
4043
|
+
const signal = options!.signal!;
|
|
4044
|
+
running.resolve(signal);
|
|
4045
|
+
await new Promise<void>((resolve) =>
|
|
4046
|
+
signal.addEventListener("abort", () => resolve(), { once: true }),
|
|
4047
|
+
);
|
|
4048
|
+
await onEvent({
|
|
4049
|
+
type: "agent_loop_exit",
|
|
4050
|
+
reason: "aborted_pre_call",
|
|
4051
|
+
} as AgentEvent);
|
|
4052
|
+
return runResult(input);
|
|
4053
|
+
},
|
|
4054
|
+
});
|
|
4055
|
+
const options = {
|
|
4056
|
+
conversationId: conversation.conversationId,
|
|
4057
|
+
cronRunId: "run-123",
|
|
4058
|
+
source: "background-tool",
|
|
4059
|
+
hint: "Command finished",
|
|
4060
|
+
};
|
|
4061
|
+
const deps = { resolveTarget: async () => conversation };
|
|
4062
|
+
const wake = wakeAgentForOpportunity(options, deps);
|
|
4063
|
+
const signal = await running.promise;
|
|
4064
|
+
expect(conversation.currentTurnCronRunId).toBe("run-123");
|
|
4065
|
+
const queuedWake = wakeAgentForOpportunity(options, deps);
|
|
4066
|
+
scheduleRunStatus = "error";
|
|
4067
|
+
conversation.abortController!.abort();
|
|
4068
|
+
await wake;
|
|
4069
|
+
expect(signal.aborted).toBe(true);
|
|
4070
|
+
expect(await queuedWake).toMatchObject({
|
|
4071
|
+
invoked: false,
|
|
4072
|
+
reason: "timeout",
|
|
4073
|
+
});
|
|
4074
|
+
expect(conversation.runCalls).toHaveLength(1);
|
|
4075
|
+
expect(conversation.isProcessing()).toBe(false);
|
|
4076
|
+
expect(conversation.abortController).toBeNull();
|
|
4077
|
+
expect(conversation.currentTurnCronRunId).toBeUndefined();
|
|
4078
|
+
});
|
|
4079
|
+
|
|
4080
|
+
test("a timeout during compaction never starts the scheduled loop", async () => {
|
|
4081
|
+
scheduleRunStatus = "running";
|
|
4082
|
+
const conversation = makeWakeConversation({});
|
|
4083
|
+
conversation.maybeCompact = async () => {
|
|
4084
|
+
expect(conversation.currentTurnCronRunId).toBe("run-123");
|
|
4085
|
+
scheduleRunStatus = "error";
|
|
4086
|
+
conversation.abortController!.abort();
|
|
4087
|
+
return null;
|
|
4088
|
+
};
|
|
4089
|
+
expect(
|
|
4090
|
+
await wakeAgentForOpportunity(
|
|
4091
|
+
{
|
|
4092
|
+
conversationId: conversation.conversationId,
|
|
4093
|
+
cronRunId: "run-123",
|
|
4094
|
+
source: "background-tool",
|
|
4095
|
+
hint: "Command finished",
|
|
4096
|
+
},
|
|
4097
|
+
{ resolveTarget: async () => conversation },
|
|
4098
|
+
),
|
|
4099
|
+
).toMatchObject({ invoked: false, reason: "timeout" });
|
|
4100
|
+
expect(conversation.runCalls).toHaveLength(0);
|
|
4101
|
+
expect(conversation.isProcessing()).toBe(false);
|
|
4102
|
+
expect(conversation.abortController).toBeNull();
|
|
4103
|
+
expect(conversation.currentTurnCronRunId).toBeUndefined();
|
|
4104
|
+
});
|
|
4105
|
+
});
|
|
@@ -326,14 +326,17 @@ export async function notifyGuardianOfAccessRequest(
|
|
|
326
326
|
});
|
|
327
327
|
|
|
328
328
|
let vellumDeliveryIdPromise: Promise<string | undefined> | undefined;
|
|
329
|
-
//
|
|
330
|
-
//
|
|
331
|
-
//
|
|
332
|
-
//
|
|
333
|
-
//
|
|
334
|
-
//
|
|
335
|
-
//
|
|
336
|
-
// the
|
|
329
|
+
// Where the card goes:
|
|
330
|
+
// - Slack or Telegram with the guardian verified on that same channel: only
|
|
331
|
+
// that channel, where the card is answered in place.
|
|
332
|
+
// - Email, for a sender who was denied: every channel the guardian is
|
|
333
|
+
// connected on. The card cannot be delivered or answered by email, and
|
|
334
|
+
// the in-app copy alone is easy to miss for a guardian who handles
|
|
335
|
+
// requests in a chat app. An admitted sender's nudge blocks nobody, so it
|
|
336
|
+
// takes the default below.
|
|
337
|
+
// - Anywhere else: the channels the decision engine selects. The in-app
|
|
338
|
+
// card is always among them (`emit-signal.ts` forces it for access
|
|
339
|
+
// requests).
|
|
337
340
|
const TEXT_CHANNELS_WITH_DELIVERY: ReadonlySet<string> = new Set([
|
|
338
341
|
"slack",
|
|
339
342
|
"telegram",
|
|
@@ -355,7 +358,11 @@ export async function notifyGuardianOfAccessRequest(
|
|
|
355
358
|
sourceContextId: `access-req-${sourceChannel}-${actorExternalId}`,
|
|
356
359
|
requiresConversation: true,
|
|
357
360
|
...(vellumConversationAffinity ?? {}),
|
|
358
|
-
...(sameChannelOnly
|
|
361
|
+
...(sameChannelOnly
|
|
362
|
+
? { routingIntent: "single_channel" as const }
|
|
363
|
+
: sourceChannel === "email" && trigger === "denied"
|
|
364
|
+
? { routingIntent: "all_channels" as const }
|
|
365
|
+
: {}),
|
|
359
366
|
attentionHints: {
|
|
360
367
|
requiresAction: true,
|
|
361
368
|
// An admitted sender is already conversing — the guardian should
|