@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
|
@@ -37,6 +37,7 @@ import {
|
|
|
37
37
|
} from "./memory-retrospective-job.js";
|
|
38
38
|
import { skillCardInsertJob } from "./memory-retrospective-skill-card.js";
|
|
39
39
|
import { memoryRetrospectiveSweepJob } from "./memory-retrospective-sweep.js";
|
|
40
|
+
import { skillUpdateReceiptJob } from "./skill-update-receipt-job.js";
|
|
40
41
|
// SUBSTRATE (v2+v3).
|
|
41
42
|
import {
|
|
42
43
|
type ConsolidationOutcome,
|
|
@@ -309,8 +310,9 @@ export const memoryJobHandlers: readonly JobHandlerEntry[] = [
|
|
|
309
310
|
|
|
310
311
|
// RETROSPECTIVE (all tiers).
|
|
311
312
|
// The retrospective pass and its cross-conversation sweep are tier-agnostic
|
|
312
|
-
// and survive every tier deletion. `skill_card_insert`
|
|
313
|
-
// v3 but
|
|
313
|
+
// and survive every tier deletion. `skill_card_insert` and
|
|
314
|
+
// `skill_update_receipt` are emitted only on v3 but are owned by the
|
|
315
|
+
// retrospective, so they group here.
|
|
314
316
|
{
|
|
315
317
|
type: "memory_retrospective",
|
|
316
318
|
handler: async (job, config) =>
|
|
@@ -324,6 +326,10 @@ export const memoryJobHandlers: readonly JobHandlerEntry[] = [
|
|
|
324
326
|
type: "skill_card_insert",
|
|
325
327
|
handler: (job) => skillCardInsertJob(job),
|
|
326
328
|
},
|
|
329
|
+
{
|
|
330
|
+
type: "skill_update_receipt",
|
|
331
|
+
handler: (job) => skillUpdateReceiptJob(job),
|
|
332
|
+
},
|
|
327
333
|
];
|
|
328
334
|
|
|
329
335
|
/**
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Memory retrospective: skill-update receipts.
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
//
|
|
5
|
+
// A background pass can rewrite several managed skills within minutes. A
|
|
6
|
+
// receipt collapses one such burst into one announcement: every rewrite is
|
|
7
|
+
// appended to the one pending `skill_update_receipt` job
|
|
8
|
+
// (`upsertSkillUpdateReceiptJob`), and this handler announces the burst once
|
|
9
|
+
// it has settled, through `emitNotificationSignal`, the single entry point
|
|
10
|
+
// every notification producer uses. The same shape as the skill card's
|
|
11
|
+
// delivery job, keyed to a burst rather than to a run.
|
|
12
|
+
//
|
|
13
|
+
// Settled means every run that contributed an entry has finished (its fork
|
|
14
|
+
// conversation is no longer processing, or is gone) and no entry has landed
|
|
15
|
+
// for the quiet window. A burst that never goes quiet is announced at the
|
|
16
|
+
// cap, measured from its earliest entry. Until then the handler re-upserts
|
|
17
|
+
// the payload for a later check, the way the card defers until its run ends,
|
|
18
|
+
// so no attempt counter accumulates.
|
|
19
|
+
//
|
|
20
|
+
// The pending-only match in the upsert is what makes a burst boundary
|
|
21
|
+
// possible without a table of its own, and also what bounds it. The claimed
|
|
22
|
+
// row's payload is frozen, so an entry landing during evaluation opens a
|
|
23
|
+
// pending sibling; the handler checks for one right before announcing and,
|
|
24
|
+
// if it finds one, merges its own entries into it and announces nothing,
|
|
25
|
+
// leaving the sibling to carry the whole burst. Two windows stay open, and
|
|
26
|
+
// both surface as a second bell row rather than a lost entry: an entry
|
|
27
|
+
// landing between that check and the announcement's event row, and a
|
|
28
|
+
// sibling claimed by another worker between the check and the merge, in
|
|
29
|
+
// which case the merge opens a third row. Both are accepted.
|
|
30
|
+
//
|
|
31
|
+
// One announcement per row: the dedupe key is the row id, so a retry after a
|
|
32
|
+
// crash past the event row meets the key and completes. A pipeline failure
|
|
33
|
+
// before that is reported as retryable and the worker's own budget covers
|
|
34
|
+
// it; a row that exhausts it loses its entries, as the per-update notice it
|
|
35
|
+
// replaces would have.
|
|
36
|
+
|
|
37
|
+
import {
|
|
38
|
+
getConversation,
|
|
39
|
+
isConversationProcessing,
|
|
40
|
+
} from "@vellumai/plugin-api";
|
|
41
|
+
|
|
42
|
+
import { emitNotificationSignal } from "../../../notifications/emit-signal.js";
|
|
43
|
+
import {
|
|
44
|
+
hasPendingJobOfType,
|
|
45
|
+
type MemoryJob,
|
|
46
|
+
parseSkillUpdateReceiptPayload,
|
|
47
|
+
type SkillUpdateReceiptEntry,
|
|
48
|
+
type SkillUpdateReceiptJobPayload,
|
|
49
|
+
upsertSkillUpdateReceiptJob,
|
|
50
|
+
} from "../../../persistence/jobs-store.js";
|
|
51
|
+
import type { JobQueueResolution } from "../../types.js";
|
|
52
|
+
import { getLogger } from "./logging.js";
|
|
53
|
+
|
|
54
|
+
const log = getLogger("skill-update-receipt-job");
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* How long a receipt stays open after its last entry before it is announced.
|
|
58
|
+
* Equal to the retrospective's default interval trigger, so runs a
|
|
59
|
+
* conversation's message count keeps triggering (at most every five minutes)
|
|
60
|
+
* chain into one receipt, while interval-driven runs of a slow conversation
|
|
61
|
+
* each get their own.
|
|
62
|
+
*/
|
|
63
|
+
export const SKILL_UPDATE_RECEIPT_QUIET_MS = 30 * 60 * 1000;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The longest a receipt stays open, measured from its earliest entry. A
|
|
67
|
+
* burst that never goes quiet is announced at the cap and a later entry
|
|
68
|
+
* opens the next receipt.
|
|
69
|
+
*/
|
|
70
|
+
export const SKILL_UPDATE_RECEIPT_CAP_MS = 2 * 60 * 60 * 1000;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* How soon the handler looks again at a receipt whose contributing run is
|
|
74
|
+
* still live. The run's end is what it waits for, and a run is one wake, so a
|
|
75
|
+
* short cadence catches it without polling hard.
|
|
76
|
+
*/
|
|
77
|
+
export const SKILL_UPDATE_RECEIPT_LIVE_RUN_RECHECK_MS = 30_000;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Record one rewrite on the open receipt and make sure a check is queued.
|
|
81
|
+
* Called by the scaffold tool after a background overwrite lands. Throws on
|
|
82
|
+
* a store failure; the caller logs it and lets the skill write stand.
|
|
83
|
+
*/
|
|
84
|
+
export function recordSkillUpdate(
|
|
85
|
+
entry: Omit<SkillUpdateReceiptEntry, "createdAt">,
|
|
86
|
+
now: number = Date.now(),
|
|
87
|
+
): void {
|
|
88
|
+
upsertSkillUpdateReceiptJob(
|
|
89
|
+
{
|
|
90
|
+
firstEntryAt: now,
|
|
91
|
+
lastEntryAt: now,
|
|
92
|
+
entries: [{ ...entry, createdAt: now }],
|
|
93
|
+
},
|
|
94
|
+
now + SKILL_UPDATE_RECEIPT_QUIET_MS,
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** The dedupe key a receipt row is announced under. */
|
|
99
|
+
export function skillUpdateReceiptDedupeKey(jobId: string): string {
|
|
100
|
+
return `skill-update-receipt:${jobId}`;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* The `sourceContextId` a receipt is announced with. The home feed's "Go to
|
|
105
|
+
* Conversation" and the vellum delivery's body append both resolve it to a
|
|
106
|
+
* conversation, so a receipt whose rewrites all came from one conversation
|
|
107
|
+
* names it; one spanning several, or with a rewrite of unknown lineage,
|
|
108
|
+
* passes a sentinel that resolves to nothing, and the receipt's own entries
|
|
109
|
+
* carry the links.
|
|
110
|
+
*/
|
|
111
|
+
export function skillUpdateReceiptSourceContextId(
|
|
112
|
+
jobId: string,
|
|
113
|
+
entries: SkillUpdateReceiptEntry[],
|
|
114
|
+
): string {
|
|
115
|
+
// An entry with no lineage counts as its own source: linking the whole
|
|
116
|
+
// receipt to the one known conversation would attribute that rewrite
|
|
117
|
+
// there too.
|
|
118
|
+
const sources = new Set(entries.map((entry) => entry.sourceConversationId));
|
|
119
|
+
const [only] = sources;
|
|
120
|
+
return sources.size === 1 && only ? only : `skill-update-receipt:${jobId}`;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* The English fallback title and body, for a surface that renders the item
|
|
125
|
+
* as it arrived: a bundle without the receipt panel, a channel post, a
|
|
126
|
+
* banner. The web client derives its own title from the entries.
|
|
127
|
+
*/
|
|
128
|
+
export function composeSkillUpdateReceiptCopy(
|
|
129
|
+
entries: SkillUpdateReceiptEntry[],
|
|
130
|
+
): { title: string; body: string } {
|
|
131
|
+
const skills = new Map<string, string>();
|
|
132
|
+
for (const entry of entries) {
|
|
133
|
+
skills.set(entry.skillId, entry.name);
|
|
134
|
+
}
|
|
135
|
+
const names = [...skills.values()];
|
|
136
|
+
const title =
|
|
137
|
+
names.length === 1
|
|
138
|
+
? `Skill updated: ${names[0]}`
|
|
139
|
+
: `${names.length} skills updated`;
|
|
140
|
+
const body = entries
|
|
141
|
+
.map((entry) => `- ${entry.name}: ${entry.changeSummary}`)
|
|
142
|
+
.join("\n");
|
|
143
|
+
return { title, body };
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export type SkillUpdateReceiptSealDecision =
|
|
147
|
+
| { seal: "quiet" | "cap" }
|
|
148
|
+
| { seal: null; nextCheckAt: number };
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Whether the receipt is due to be announced, and if not, when to look
|
|
152
|
+
* again. Pure, so the boundary can be asserted without a clock or a queue.
|
|
153
|
+
*/
|
|
154
|
+
export function decideSkillUpdateReceiptSeal(args: {
|
|
155
|
+
receipt: Pick<SkillUpdateReceiptJobPayload, "firstEntryAt" | "lastEntryAt">;
|
|
156
|
+
anyRunLive: boolean;
|
|
157
|
+
now: number;
|
|
158
|
+
}): SkillUpdateReceiptSealDecision {
|
|
159
|
+
const capAt = args.receipt.firstEntryAt + SKILL_UPDATE_RECEIPT_CAP_MS;
|
|
160
|
+
if (args.now >= capAt) {
|
|
161
|
+
return { seal: "cap" };
|
|
162
|
+
}
|
|
163
|
+
const quietAt = args.receipt.lastEntryAt + SKILL_UPDATE_RECEIPT_QUIET_MS;
|
|
164
|
+
if (args.anyRunLive) {
|
|
165
|
+
return {
|
|
166
|
+
seal: null,
|
|
167
|
+
nextCheckAt: Math.min(
|
|
168
|
+
args.now + SKILL_UPDATE_RECEIPT_LIVE_RUN_RECHECK_MS,
|
|
169
|
+
capAt,
|
|
170
|
+
),
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
if (args.now >= quietAt) {
|
|
174
|
+
return { seal: "quiet" };
|
|
175
|
+
}
|
|
176
|
+
return { seal: null, nextCheckAt: Math.min(quietAt, capAt) };
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Whether the run that produced an entry has finished. A fork conversation
|
|
181
|
+
* that no longer exists counts as finished: superseded-fork GC deletes the
|
|
182
|
+
* row, and a run cannot be processing without one. Same reading as the
|
|
183
|
+
* skill card's gate.
|
|
184
|
+
*/
|
|
185
|
+
async function isRunFinished(runConversationId: string): Promise<boolean> {
|
|
186
|
+
const conversation = await getConversation(runConversationId);
|
|
187
|
+
if (!conversation) {
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
return !(await isConversationProcessing(runConversationId));
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* The entries whose source conversation still exists. An entry with no
|
|
195
|
+
* lineage has nothing to check and stays.
|
|
196
|
+
*/
|
|
197
|
+
async function dropEntriesOfDeletedSources(
|
|
198
|
+
entries: SkillUpdateReceiptEntry[],
|
|
199
|
+
): Promise<SkillUpdateReceiptEntry[]> {
|
|
200
|
+
const sources = new Set(
|
|
201
|
+
entries.flatMap((entry) =>
|
|
202
|
+
entry.sourceConversationId ? [entry.sourceConversationId] : [],
|
|
203
|
+
),
|
|
204
|
+
);
|
|
205
|
+
const gone = new Set<string>();
|
|
206
|
+
for (const source of sources) {
|
|
207
|
+
if (!(await getConversation(source))) {
|
|
208
|
+
gone.add(source);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return entries.filter(
|
|
212
|
+
(entry) =>
|
|
213
|
+
!entry.sourceConversationId || !gone.has(entry.sourceConversationId),
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Job handler for `skill_update_receipt` (registered in `job-handlers.ts`).
|
|
219
|
+
* A malformed payload is dropped with a warning. A pipeline failure returns
|
|
220
|
+
* `retryable` so the worker's budget covers it.
|
|
221
|
+
*/
|
|
222
|
+
export async function skillUpdateReceiptJob(
|
|
223
|
+
job: MemoryJob,
|
|
224
|
+
): Promise<JobQueueResolution | undefined> {
|
|
225
|
+
const payload = parseSkillUpdateReceiptPayload(job.payload);
|
|
226
|
+
if (!payload || payload.entries.length === 0) {
|
|
227
|
+
log.warn(
|
|
228
|
+
{ jobId: job.id },
|
|
229
|
+
"skill-update receipt: dropping job with malformed or empty payload",
|
|
230
|
+
);
|
|
231
|
+
return undefined;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const runIds = [
|
|
235
|
+
...new Set(payload.entries.map((entry) => entry.runConversationId)),
|
|
236
|
+
];
|
|
237
|
+
let anyRunLive = false;
|
|
238
|
+
for (const runId of runIds) {
|
|
239
|
+
if (!(await isRunFinished(runId))) {
|
|
240
|
+
anyRunLive = true;
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
const decision = decideSkillUpdateReceiptSeal({
|
|
245
|
+
receipt: payload,
|
|
246
|
+
anyRunLive,
|
|
247
|
+
now: Date.now(),
|
|
248
|
+
});
|
|
249
|
+
if (decision.seal === null) {
|
|
250
|
+
// Not settled. The claimed row completes and the payload moves to a
|
|
251
|
+
// pending row for the next check, merging with any entries that landed
|
|
252
|
+
// meanwhile.
|
|
253
|
+
upsertSkillUpdateReceiptJob(payload, decision.nextCheckAt);
|
|
254
|
+
return undefined;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (hasPendingJobOfType("skill_update_receipt")) {
|
|
258
|
+
// An entry landed while this row was being evaluated and opened a
|
|
259
|
+
// sibling. The sibling carries the burst: merge into it and announce
|
|
260
|
+
// nothing, so the two rows do not become two bell rows.
|
|
261
|
+
upsertSkillUpdateReceiptJob(payload, Date.now());
|
|
262
|
+
log.info(
|
|
263
|
+
{ jobId: job.id, entryCount: payload.entries.length },
|
|
264
|
+
"skill-update receipt: merged into the sibling that opened during evaluation",
|
|
265
|
+
);
|
|
266
|
+
return undefined;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// The claimed payload is a snapshot: a source conversation deleted while
|
|
270
|
+
// this row was evaluated was purged from pending rows only. Announce
|
|
271
|
+
// nothing distilled from a conversation that is gone.
|
|
272
|
+
const entries = await dropEntriesOfDeletedSources(payload.entries);
|
|
273
|
+
if (entries.length === 0) {
|
|
274
|
+
log.info(
|
|
275
|
+
{ jobId: job.id },
|
|
276
|
+
"skill-update receipt: every entry's source conversation was deleted; nothing to announce",
|
|
277
|
+
);
|
|
278
|
+
return undefined;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
const { title, body } = composeSkillUpdateReceiptCopy(entries);
|
|
282
|
+
const skillIds = new Set(entries.map((entry) => entry.skillId));
|
|
283
|
+
const [onlySkillId] = skillIds;
|
|
284
|
+
const result = await emitNotificationSignal({
|
|
285
|
+
// A tool's work reported after the fact, not the scheduler's:
|
|
286
|
+
// `home-feed-side-effect` derives `fromAssistant` from the channel.
|
|
287
|
+
sourceChannel: "assistant_tool",
|
|
288
|
+
sourceContextId: skillUpdateReceiptSourceContextId(job.id, entries),
|
|
289
|
+
sourceEventName: "activity.complete",
|
|
290
|
+
dedupeKey: skillUpdateReceiptDedupeKey(job.id),
|
|
291
|
+
contextPayload: {
|
|
292
|
+
summary: body,
|
|
293
|
+
title,
|
|
294
|
+
body,
|
|
295
|
+
// The typed list the receipt panel renders; the feed maps it onto the
|
|
296
|
+
// item and strips it from the free-form metadata.
|
|
297
|
+
updates: entries.map((entry) => ({
|
|
298
|
+
skillId: entry.skillId,
|
|
299
|
+
name: entry.name,
|
|
300
|
+
summary: entry.changeSummary,
|
|
301
|
+
...(entry.sourceConversationId
|
|
302
|
+
? { conversationId: entry.sourceConversationId }
|
|
303
|
+
: {}),
|
|
304
|
+
})),
|
|
305
|
+
// A receipt naming one skill links to it from the detail's footer the
|
|
306
|
+
// way a single-skill notification does.
|
|
307
|
+
...(skillIds.size === 1 && onlySkillId ? { skillId: onlySkillId } : {}),
|
|
308
|
+
},
|
|
309
|
+
attentionHints: {
|
|
310
|
+
requiresAction: false,
|
|
311
|
+
urgency: "low",
|
|
312
|
+
isAsyncBackground: true,
|
|
313
|
+
visibleInSourceNow: false,
|
|
314
|
+
},
|
|
315
|
+
});
|
|
316
|
+
if (result.pipelineFailed) {
|
|
317
|
+
return {
|
|
318
|
+
queueResolution: "retryable",
|
|
319
|
+
errorMessage: `skill-update receipt announcement failed: ${result.reason}`,
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
log.info(
|
|
323
|
+
{
|
|
324
|
+
jobId: job.id,
|
|
325
|
+
sealedBy: decision.seal,
|
|
326
|
+
entryCount: entries.length,
|
|
327
|
+
skillCount: skillIds.size,
|
|
328
|
+
deduplicated: result.deduplicated,
|
|
329
|
+
dispatched: result.dispatched,
|
|
330
|
+
},
|
|
331
|
+
"skill-update receipt announced",
|
|
332
|
+
);
|
|
333
|
+
return undefined;
|
|
334
|
+
}
|
|
@@ -451,6 +451,23 @@ describe("rememberTool definition", () => {
|
|
|
451
451
|
finish_turn: { type: "boolean" },
|
|
452
452
|
});
|
|
453
453
|
});
|
|
454
|
+
|
|
455
|
+
test("says later capture is conditional and never covers scheduled work", () => {
|
|
456
|
+
const description = rememberTool.description;
|
|
457
|
+
expect(description).toContain("not guaranteed");
|
|
458
|
+
expect(description).toContain("never runs over scheduled work");
|
|
459
|
+
expect(description).toContain("save it now");
|
|
460
|
+
// A pass that reviews every conversation on a cadence is not what runs:
|
|
461
|
+
// the enqueue gate skips scheduled conversations.
|
|
462
|
+
expect(description).not.toContain("after each message-count");
|
|
463
|
+
expect(description).not.toContain("saves what you didn't capture");
|
|
464
|
+
// The provider reads the definition after JSON serialization, so the
|
|
465
|
+
// contract has to survive that round trip unchanged.
|
|
466
|
+
const serialized = z
|
|
467
|
+
.object({ description: z.string() })
|
|
468
|
+
.parse(JSON.parse(JSON.stringify(rememberTool)));
|
|
469
|
+
expect(serialized.description).toBe(description);
|
|
470
|
+
});
|
|
454
471
|
});
|
|
455
472
|
|
|
456
473
|
describe("rememberTool definition — page-hint guidance gating", () => {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { TurnContext } from "../../types.js";
|
|
2
|
+
|
|
3
|
+
/** Gates fresh retrieval only; history and static memory remain available. */
|
|
4
|
+
export function shouldRetrieveTurnMemory(
|
|
5
|
+
ctx: Pick<TurnContext, "callSite" | "skipMemoryRetrieval">,
|
|
6
|
+
): boolean {
|
|
7
|
+
return ctx.callSite !== "voiceFrontDoor" && ctx.skipMemoryRetrieval !== true;
|
|
8
|
+
}
|
|
@@ -462,6 +462,30 @@ describe("memoryV3Injector: frozen net-new sections", () => {
|
|
|
462
462
|
expect(activeIds("conv-voice")).toEqual(new Set());
|
|
463
463
|
});
|
|
464
464
|
|
|
465
|
+
test("screen-action bypass preserves resident sections and retrieval resumes next turn", async () => {
|
|
466
|
+
liveEnabled = true;
|
|
467
|
+
turnResults.set(0, result(["page-a"]));
|
|
468
|
+
const resident = await produceSections("conv-1", 0);
|
|
469
|
+
expect(resident).not.toBeNull();
|
|
470
|
+
const before = activeIds("conv-1");
|
|
471
|
+
observeTurnSpy.mockClear();
|
|
472
|
+
const ctx = {
|
|
473
|
+
requestId: "req-screen",
|
|
474
|
+
conversationId: "conv-1",
|
|
475
|
+
turnIndex: 1,
|
|
476
|
+
trust: GUARDIAN_TRUST,
|
|
477
|
+
callSite: "callAgent" as const,
|
|
478
|
+
skipMemoryRetrieval: true,
|
|
479
|
+
};
|
|
480
|
+
expect(await memoryV3Injector.produce(ctx)).toBeNull();
|
|
481
|
+
expect(await memoryV3PointerInjector.produce(ctx)).toBeNull();
|
|
482
|
+
expect(observeTurnSpy).not.toHaveBeenCalled();
|
|
483
|
+
expect(activeIds("conv-1")).toEqual(before);
|
|
484
|
+
turnResults.set(2, result(["page-b"]));
|
|
485
|
+
expect(await produceSections("conv-1", 2)).not.toBeNull();
|
|
486
|
+
expect(observeTurnSpy).toHaveBeenCalledTimes(1);
|
|
487
|
+
});
|
|
488
|
+
|
|
465
489
|
test("a live orchestration throw queues a degraded-memory notice and no block", async () => {
|
|
466
490
|
liveEnabled = true;
|
|
467
491
|
turnResults.set(
|
|
@@ -80,6 +80,7 @@ import {
|
|
|
80
80
|
import { getLogger } from "../logging.js";
|
|
81
81
|
import { wrapMemoryBlock, wrapMemoryPointerBlock } from "../memory-marker.js";
|
|
82
82
|
import { renderedBytes } from "../substrate/injected-block-slugs.js";
|
|
83
|
+
import { shouldRetrieveTurnMemory } from "../turn-retrieval.js";
|
|
83
84
|
import {
|
|
84
85
|
type InjectionUnit,
|
|
85
86
|
injectionUnits,
|
|
@@ -200,9 +201,8 @@ function queueMemoryV3ConversationNotice(
|
|
|
200
201
|
|
|
201
202
|
/**
|
|
202
203
|
* The gates both injectors share: memory on, v3 live, a trusted actor, and
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
* its first token).
|
|
204
|
+
* fresh retrieval allowed for this turn. Front-door and screen-action turns
|
|
205
|
+
* retain carried sections without awaiting current-turn selection.
|
|
206
206
|
*/
|
|
207
207
|
function turnIsEligible(ctx: TurnContext): boolean {
|
|
208
208
|
const config = getConfig();
|
|
@@ -212,7 +212,7 @@ function turnIsEligible(ctx: TurnContext): boolean {
|
|
|
212
212
|
if (!isPersonalMemoryAllowed(ctx.trust)) {
|
|
213
213
|
return false;
|
|
214
214
|
}
|
|
215
|
-
return ctx
|
|
215
|
+
return shouldRetrieveTurnMemory(ctx);
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
// ─── shared per-turn orchestration memo ─────────────────────────────────────
|
package/src/plugins/types.ts
CHANGED
|
@@ -263,6 +263,8 @@ export interface TurnContext {
|
|
|
263
263
|
* absence conservatively.
|
|
264
264
|
*/
|
|
265
265
|
callSite?: LLMCallSite;
|
|
266
|
+
/** Skip fresh retrieval while keeping resident memory and static context. */
|
|
267
|
+
skipMemoryRetrieval?: boolean;
|
|
266
268
|
}
|
|
267
269
|
|
|
268
270
|
// ─── Injectors ───────────────────────────────────────────────────────────────
|
|
@@ -104,4 +104,12 @@ describe("search-provider-catalog", () => {
|
|
|
104
104
|
expect(tinyfish?.defaultApiBase).toBe("https://api.search.tinyfish.ai");
|
|
105
105
|
expect(tinyfish?.envVar).toBe("TINYFISH_API_KEY");
|
|
106
106
|
});
|
|
107
|
+
|
|
108
|
+
test("Exa is a keyed BYOK provider without a custom API base", () => {
|
|
109
|
+
const exa = getSearchProvider("exa");
|
|
110
|
+
expect(exa?.kind).toBe("byok");
|
|
111
|
+
expect(exa?.keyless).toBeUndefined();
|
|
112
|
+
expect(exa?.supportsApiBase).toBeUndefined();
|
|
113
|
+
expect(exa?.envVar).toBe("EXA_API_KEY");
|
|
114
|
+
});
|
|
107
115
|
});
|
|
@@ -6,6 +6,7 @@ import { ProviderError, type ProviderErrorReason } from "../../util/errors.js";
|
|
|
6
6
|
import { getLogger } from "../../util/logger.js";
|
|
7
7
|
import {
|
|
8
8
|
DAILY_LIMIT_PATTERNS,
|
|
9
|
+
FREE_TIER_DAILY_LIMIT_PATTERNS,
|
|
9
10
|
INSUFFICIENT_CREDITS_PATTERNS,
|
|
10
11
|
} from "../../util/provider-error-patterns.js";
|
|
11
12
|
import { extractRetryAfterMs } from "../../util/retry.js";
|
|
@@ -154,6 +155,9 @@ export function deriveAnthropicReason(
|
|
|
154
155
|
|
|
155
156
|
// The managed proxy's daily-limit 402 shares the status with generic credit
|
|
156
157
|
// exhaustion; match its specific body code first so it isn't swallowed.
|
|
158
|
+
if (FREE_TIER_DAILY_LIMIT_PATTERNS.some((re) => re.test(haystack))) {
|
|
159
|
+
return "free_tier_daily_limit_reached";
|
|
160
|
+
}
|
|
157
161
|
if (DAILY_LIMIT_PATTERNS.some((re) => re.test(haystack))) {
|
|
158
162
|
return "daily_limit_reached";
|
|
159
163
|
}
|
|
@@ -9,7 +9,10 @@ import { SYSTEM_PROMPT_CACHE_BOUNDARY } from "../../prompts/cache-boundary.js";
|
|
|
9
9
|
import { isAbortReason } from "../../util/abort-reasons.js";
|
|
10
10
|
import { ProviderError, type ProviderErrorReason } from "../../util/errors.js";
|
|
11
11
|
import { getLogger } from "../../util/logger.js";
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
DAILY_LIMIT_PATTERNS,
|
|
14
|
+
FREE_TIER_DAILY_LIMIT_PATTERNS,
|
|
15
|
+
} from "../../util/provider-error-patterns.js";
|
|
13
16
|
import {
|
|
14
17
|
clampProviderString,
|
|
15
18
|
keepFileAsWorkspaceRef,
|
|
@@ -308,6 +311,9 @@ export function deriveGeminiReason(error: ApiError): ProviderErrorReason {
|
|
|
308
311
|
|
|
309
312
|
// The managed proxy's daily-limit 402 body carries a specific code; match it
|
|
310
313
|
// before the status branches so it isn't classified as a generic 4xx.
|
|
314
|
+
if (FREE_TIER_DAILY_LIMIT_PATTERNS.some((re) => re.test(message))) {
|
|
315
|
+
return "free_tier_daily_limit_reached";
|
|
316
|
+
}
|
|
311
317
|
if (DAILY_LIMIT_PATTERNS.some((re) => re.test(message))) {
|
|
312
318
|
return "daily_limit_reached";
|
|
313
319
|
}
|
|
@@ -176,6 +176,31 @@ export type ConnectionModel = z.infer<typeof ConnectionModelSchema>;
|
|
|
176
176
|
* `models` list (openai-compatible endpoints have no fixed upstream, so the
|
|
177
177
|
* user must supply both).
|
|
178
178
|
*/
|
|
179
|
+
/**
|
|
180
|
+
* An openai-compatible connection whose endpoint is opencode.ai is an
|
|
181
|
+
* OpenCode connection: zen/go rejects requests without the session headers
|
|
182
|
+
* only the opencode adapter and probe send, so the generic adapter can never
|
|
183
|
+
* dispatch against it. Applied on create so the row is stored as provider
|
|
184
|
+
* "opencode" and every provider-keyed path treats it as one.
|
|
185
|
+
*/
|
|
186
|
+
export function normalizeConnectionProvider(
|
|
187
|
+
provider: string,
|
|
188
|
+
baseUrl: unknown,
|
|
189
|
+
): string {
|
|
190
|
+
if (provider !== "openai-compatible" || typeof baseUrl !== "string") {
|
|
191
|
+
return provider;
|
|
192
|
+
}
|
|
193
|
+
let host: string;
|
|
194
|
+
try {
|
|
195
|
+
host = new URL(baseUrl).hostname.toLowerCase();
|
|
196
|
+
} catch {
|
|
197
|
+
return provider;
|
|
198
|
+
}
|
|
199
|
+
return host === "opencode.ai" || host.endsWith(".opencode.ai")
|
|
200
|
+
? "opencode"
|
|
201
|
+
: provider;
|
|
202
|
+
}
|
|
203
|
+
|
|
179
204
|
export const PROVIDERS_REQUIRING_BASE_URL_AND_MODELS: ReadonlySet<string> =
|
|
180
205
|
new Set(["openai-compatible"]);
|
|
181
206
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { afterAll, describe, expect, mock, test } from "bun:test";
|
|
2
2
|
|
|
3
|
-
import type { Provider } from "
|
|
3
|
+
import type { Provider } from "../types.js";
|
|
4
4
|
|
|
5
5
|
let configured: {
|
|
6
6
|
provider: Provider;
|
|
@@ -8,13 +8,13 @@ let configured: {
|
|
|
8
8
|
entryRouted: boolean;
|
|
9
9
|
} | null = null;
|
|
10
10
|
|
|
11
|
-
const actual = await import("
|
|
12
|
-
mock.module("
|
|
11
|
+
const actual = await import("../provider-send-message.js");
|
|
12
|
+
mock.module("../provider-send-message.js", () => ({
|
|
13
13
|
...actual,
|
|
14
14
|
resolveConfiguredProvider: async () => configured,
|
|
15
15
|
}));
|
|
16
16
|
|
|
17
|
-
const { resolveTypesafeProvider } = await import("
|
|
17
|
+
const { resolveTypesafeProvider } = await import("./ask.js");
|
|
18
18
|
|
|
19
19
|
afterAll(() => {
|
|
20
20
|
mock.restore();
|