@capybara-hq/kernel 0.1.0-rc.48 → 0.1.0-rc.49
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/admin/admin.module.js +2 -0
- package/dist/admin/admin.schemas.d.ts +4 -0
- package/dist/admin/health.service.d.ts +2 -2
- package/dist/admin/health.service.js +8 -4
- package/dist/agents/agents.schemas.js +1 -1
- package/dist/agents/instruction-files.js +0 -3
- package/dist/background/launch.d.ts +4 -0
- package/dist/background/launch.js +6 -2
- package/dist/catalog/marketplaces.service.d.ts +1 -1
- package/dist/conversations/delivery-scope.d.ts +34 -0
- package/dist/conversations/delivery-scope.js +23 -0
- package/dist/conversations/event-log.d.ts +18 -0
- package/dist/conversations/event-log.js +54 -0
- package/dist/conversations/events.d.ts +2 -0
- package/dist/conversations/events.js +15 -2
- package/dist/conversations/prompt-suggestion-request.d.ts +95 -0
- package/dist/conversations/prompt-suggestion-request.js +213 -0
- package/dist/conversations/prompt-suggestion-store.d.ts +51 -0
- package/dist/conversations/prompt-suggestion-store.js +136 -0
- package/dist/conversations/prompt-suggestions.d.ts +153 -0
- package/dist/conversations/prompt-suggestions.js +563 -0
- package/dist/conversations/titles.js +11 -5
- package/dist/evals/reconstruct.d.ts +26 -1
- package/dist/evals/reconstruct.js +25 -6
- package/dist/identity/settings.d.ts +13 -0
- package/dist/identity/settings.js +37 -2
- package/dist/infra/queue/queue-names.d.ts +1 -1
- package/dist/infra/queue/queue-names.js +1 -0
- package/dist/kernel.module.js +4 -1
- package/dist/lifecycle/kernel-lifecycle.d.ts +3 -1
- package/dist/lifecycle/kernel-lifecycle.js +13 -7
- package/dist/models/image-usable.d.ts +30 -6
- package/dist/models/image-usable.js +38 -7
- package/dist/models/images.js +6 -4
- package/dist/models/purposes.d.ts +1 -1
- package/dist/models/purposes.js +10 -4
- package/dist/orgs/settings.service.d.ts +16 -0
- package/dist/orgs/settings.service.js +46 -5
- package/dist/overrides.d.ts +4 -0
- package/dist/overrides.js +2 -0
- package/dist/platform/availability.d.ts +5 -0
- package/dist/platform/availability.js +7 -3
- package/dist/platform/ops/accounts.ops.d.ts +1 -1
- package/dist/platform/ops/accounts.ops.js +1 -1
- package/dist/platform/ops/admin.ops.js +3 -2
- package/dist/platform/ops/agent-skills.ops.js +5 -5
- package/dist/platform/ops/agents.ops.js +3 -3
- package/dist/platform/ops/approvals.ops.d.ts +1 -1
- package/dist/platform/ops/approvals.ops.js +2 -2
- package/dist/platform/ops/background.ops.js +1 -1
- package/dist/platform/ops/catalog-admin.ops.js +3 -3
- package/dist/platform/ops/conversations.ops.js +2 -2
- package/dist/platform/ops/devices.ops.js +2 -2
- package/dist/platform/ops/extensions-admin.ops.js +2 -2
- package/dist/platform/ops/extensions.ops.js +3 -3
- package/dist/platform/ops/inbox.ops.js +4 -4
- package/dist/platform/ops/org-plugins.ops.js +4 -4
- package/dist/platform/ops/org-settings.ops.js +2 -2
- package/dist/platform/ops/orgs.ops.js +1 -0
- package/dist/platform/ops/plugins.ops.d.ts +1 -1
- package/dist/platform/ops/plugins.ops.js +3 -3
- package/dist/platform/ops/requests.ops.js +1 -1
- package/dist/platform/ops/schedules.ops.js +6 -6
- package/dist/roles/worker-role.d.ts +6 -3
- package/dist/roles/worker-role.js +21 -13
- package/dist/roles/worker.module.js +2 -0
- package/dist/runtime/compaction-settings.service.d.ts +8 -0
- package/dist/runtime/compaction-settings.service.js +12 -6
- package/dist/runtime/run-processors.d.ts +14 -6
- package/dist/runtime/run-processors.js +43 -8
- package/dist/runtime/run-worker.d.ts +5 -0
- package/dist/runtime/run-worker.js +24 -16
- package/dist/runtime/runtime.module.d.ts +1 -1
- package/dist/runtime/runtime.module.js +7 -1
- package/dist/runtime/stream.d.ts +7 -1
- package/dist/runtime/stream.js +54 -3
- package/dist/runtime/usage-report.d.ts +2 -1
- package/dist/runtime/usage-report.js +2 -1
- package/dist/sandbox/sandbox-file-reader.js +1 -1
- package/dist/tools/builtins/agent.js +5 -5
- package/dist/tools/builtins/artifacts.d.ts +33 -7
- package/dist/tools/builtins/artifacts.js +92 -14
- package/dist/tools/builtins/image/generate.d.ts +4 -1
- package/dist/tools/builtins/image/generate.js +70 -14
- package/dist/tools/builtins/platform.d.ts +0 -2
- package/dist/tools/builtins/platform.js +3 -5
- package/dist/tools/builtins/sandbox/bash.js +15 -11
- package/dist/tools/builtins/sandbox/common.d.ts +3 -2
- package/dist/tools/builtins/sandbox/deliver.js +13 -7
- package/dist/tools/builtins/sandbox/glob.js +1 -1
- package/dist/tools/builtins/sandbox/grep.js +1 -1
- package/dist/tools/builtins/sandbox/read.js +3 -3
- package/dist/tools/builtins/sandbox/task-output.d.ts +1 -1
- package/dist/tools/builtins/sandbox/task-output.js +13 -11
- package/dist/tools/builtins/send-message.d.ts +1 -1
- package/dist/tools/builtins/send-message.js +3 -3
- package/dist/tools/builtins/skill-load.d.ts +1 -1
- package/dist/tools/builtins/tool-search.js +1 -1
- package/dist/tools/builtins/web/extract.js +1 -1
- package/dist/tools/builtins/web/search.js +2 -4
- package/dist/tools/connector-account-policies.js +1 -1
- package/dist/tools/registry.d.ts +6 -0
- package/dist/tools/registry.js +1 -1
- package/package.json +2 -2
|
@@ -7,6 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
import { Module } from "@nestjs/common";
|
|
8
8
|
import { CatalogModule } from "../catalog/catalog.module.js";
|
|
9
9
|
import { ChannelsModule } from "../channels/channels.module.js";
|
|
10
|
+
import { PromptSuggestionsModule } from "../conversations/prompt-suggestions.js";
|
|
10
11
|
import { TitlesModule } from "../conversations/titles.js";
|
|
11
12
|
import { EvalsModule } from "../evals/evals.module.js";
|
|
12
13
|
import { ExtensionsModule } from "../extensions/extensions.module.js";
|
|
@@ -49,6 +50,7 @@ AdminModule = __decorate([
|
|
|
49
50
|
RunJobsModule,
|
|
50
51
|
ChannelsModule,
|
|
51
52
|
TitlesModule,
|
|
53
|
+
PromptSuggestionsModule,
|
|
52
54
|
UsageReportModule,
|
|
53
55
|
EvalsModule,
|
|
54
56
|
LifecycleHooksModule,
|
|
@@ -87,6 +87,10 @@ export declare const DeploymentSettingsBody: z.ZodObject<{
|
|
|
87
87
|
deny: "deny";
|
|
88
88
|
}>>>;
|
|
89
89
|
shareMaxExpiryDays: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
90
|
+
promptSuggestions: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
91
|
+
off: "off";
|
|
92
|
+
on: "on";
|
|
93
|
+
}>>>;
|
|
90
94
|
htmlRenderCdnAllowlist: z.ZodOptional<z.ZodArray<z.ZodType<string, unknown, z.core.$ZodTypeInternals<string, unknown>>>>;
|
|
91
95
|
}, z.core.$strict>;
|
|
92
96
|
export declare const PurposeParams: z.ZodObject<{
|
|
@@ -4,7 +4,7 @@ import { KernelDb } from "../infra/database/kernel-db.js";
|
|
|
4
4
|
import { type LiveReplica, ReplicaPresence } from "../infra/presence/replica-presence.js";
|
|
5
5
|
import type { KernelLogger } from "../log.js";
|
|
6
6
|
/** The kernel's own queues, in the order the overview lists them (extension queues are not read). */
|
|
7
|
-
export declare const KERNEL_QUEUE_NAMES: readonly ["cap-kernel-runs", "cap-kernel-subagent-runs", "cap-kernel-channels", "cap-kernel-maintenance", "cap-kernel-plugin-scope", "cap-kernel-titles", "cap-kernel-usage-report", "cap-kernel-evals", "cap-kernel-lifecycle"];
|
|
7
|
+
export declare const KERNEL_QUEUE_NAMES: readonly ["cap-kernel-runs", "cap-kernel-subagent-runs", "cap-kernel-channels", "cap-kernel-maintenance", "cap-kernel-plugin-scope", "cap-kernel-titles", "cap-kernel-suggestions", "cap-kernel-usage-report", "cap-kernel-evals", "cap-kernel-lifecycle"];
|
|
8
8
|
/** How long each source's reads may take before the answer marks it unavailable. */
|
|
9
9
|
export declare const HEALTH_READ_TIMEOUT_MS = 3000;
|
|
10
10
|
/** A live replica as the overview shows it. */
|
|
@@ -97,7 +97,7 @@ export declare class AdminHealthService {
|
|
|
97
97
|
private readonly redis;
|
|
98
98
|
private readonly log;
|
|
99
99
|
private readonly queues;
|
|
100
|
-
constructor(presence: Pick<ReplicaPresence, "live">, db: KernelDb, redis: Pick<Redis, "zcount" | "status">, log: Pick<KernelLogger, "warn">, runs: Queue, subagentRuns: Queue, channels: Queue, maintenance: Queue, pluginScope: Queue, titles: Queue, usageReport: Queue, evals: Queue, lifecycle: Queue);
|
|
100
|
+
constructor(presence: Pick<ReplicaPresence, "live">, db: KernelDb, redis: Pick<Redis, "zcount" | "status">, log: Pick<KernelLogger, "warn">, runs: Queue, subagentRuns: Queue, channels: Queue, maintenance: Queue, pluginScope: Queue, titles: Queue, suggestions: Queue, usageReport: Queue, evals: Queue, lifecycle: Queue);
|
|
101
101
|
read(): Promise<AdminHealth>;
|
|
102
102
|
private readRedis;
|
|
103
103
|
private readDb;
|
|
@@ -12,6 +12,7 @@ import { Inject, Injectable } from "@nestjs/common";
|
|
|
12
12
|
import { sql } from "kysely";
|
|
13
13
|
import { PLUGIN_SCOPE_QUEUE } from "../catalog/scope-sync.js";
|
|
14
14
|
import { CHANNEL_QUEUE_NAME } from "../channels/jobs.js";
|
|
15
|
+
import { PROMPT_SUGGESTION_QUEUE } from "../conversations/prompt-suggestions.js";
|
|
15
16
|
import { TITLE_QUEUE } from "../conversations/titles.js";
|
|
16
17
|
import { EVAL_QUEUE_NAME } from "../evals/jobs.js";
|
|
17
18
|
import { LIFECYCLE_QUEUE } from "../extensions/lifecycle-hooks.js";
|
|
@@ -30,6 +31,7 @@ export const KERNEL_QUEUE_NAMES = [
|
|
|
30
31
|
MAINTENANCE_QUEUE_NAME,
|
|
31
32
|
PLUGIN_SCOPE_QUEUE,
|
|
32
33
|
TITLE_QUEUE,
|
|
34
|
+
PROMPT_SUGGESTION_QUEUE,
|
|
33
35
|
USAGE_REPORT_QUEUE,
|
|
34
36
|
EVAL_QUEUE_NAME,
|
|
35
37
|
LIFECYCLE_QUEUE,
|
|
@@ -60,7 +62,7 @@ let AdminHealthService = class AdminHealthService {
|
|
|
60
62
|
redis;
|
|
61
63
|
log;
|
|
62
64
|
queues;
|
|
63
|
-
constructor(presence, db, redis, log, runs, subagentRuns, channels, maintenance, pluginScope, titles, usageReport, evals, lifecycle) {
|
|
65
|
+
constructor(presence, db, redis, log, runs, subagentRuns, channels, maintenance, pluginScope, titles, suggestions, usageReport, evals, lifecycle) {
|
|
64
66
|
this.presence = presence;
|
|
65
67
|
this.db = db;
|
|
66
68
|
this.redis = redis;
|
|
@@ -73,6 +75,7 @@ let AdminHealthService = class AdminHealthService {
|
|
|
73
75
|
maintenance,
|
|
74
76
|
pluginScope,
|
|
75
77
|
titles,
|
|
78
|
+
suggestions,
|
|
76
79
|
usageReport,
|
|
77
80
|
evals,
|
|
78
81
|
lifecycle,
|
|
@@ -243,8 +246,9 @@ AdminHealthService = __decorate([
|
|
|
243
246
|
__param(7, Inject(getQueueToken(MAINTENANCE_QUEUE_NAME))),
|
|
244
247
|
__param(8, Inject(getQueueToken(PLUGIN_SCOPE_QUEUE))),
|
|
245
248
|
__param(9, Inject(getQueueToken(TITLE_QUEUE))),
|
|
246
|
-
__param(10, Inject(getQueueToken(
|
|
247
|
-
__param(11, Inject(getQueueToken(
|
|
248
|
-
__param(12, Inject(getQueueToken(
|
|
249
|
+
__param(10, Inject(getQueueToken(PROMPT_SUGGESTION_QUEUE))),
|
|
250
|
+
__param(11, Inject(getQueueToken(USAGE_REPORT_QUEUE))),
|
|
251
|
+
__param(12, Inject(getQueueToken(EVAL_QUEUE_NAME))),
|
|
252
|
+
__param(13, Inject(getQueueToken(LIFECYCLE_QUEUE)))
|
|
249
253
|
], AdminHealthService);
|
|
250
254
|
export { AdminHealthService };
|
|
@@ -15,7 +15,7 @@ const RequestInstructions = z.string().max(100_000).optional();
|
|
|
15
15
|
const RequestOnly = {
|
|
16
16
|
tools: z
|
|
17
17
|
.undefined({
|
|
18
|
-
error: "tools
|
|
18
|
+
error: "tools is not a definition field: an agent has every tool unless disabledTools turns it off",
|
|
19
19
|
})
|
|
20
20
|
.optional(),
|
|
21
21
|
subagentTools: z
|
|
@@ -19,9 +19,6 @@ export const AGENTS_MD_STARTER = [
|
|
|
19
19
|
"You are an assistant for this team. Help people get their work done accurately and efficiently.",
|
|
20
20
|
"",
|
|
21
21
|
"- Tone: clear, friendly and concise. Use plain language, keep answers short, and add detail when asked.",
|
|
22
|
-
"- When a request is unclear or missing key details, ask one short clarifying question before acting.",
|
|
23
|
-
" If you go ahead anyway, say what you assumed.",
|
|
24
|
-
"- If you don't know something or can't do it, say so instead of guessing.",
|
|
25
22
|
].join("\n");
|
|
26
23
|
/**
|
|
27
24
|
* The model-visible join: one file gives exactly its content (so an old agent edited without
|
|
@@ -78,6 +78,10 @@ export declare const GROUP_LAUNCHER: string;
|
|
|
78
78
|
* go into the script unquoted).
|
|
79
79
|
*/
|
|
80
80
|
export declare function launchScript(id: string, command: string, seconds: number): string;
|
|
81
|
+
/**
|
|
82
|
+
* The launch result's last line: how the task's end is reported and how to read and stop it.
|
|
83
|
+
*/
|
|
84
|
+
export declare const LAUNCH_NEXT_STEP = "You will be told when it finishes. Read its output with TaskOutput (or Read), stop it with TaskStop.";
|
|
81
85
|
/** The model-visible result of a launch (spec §2.1); `workspace`: the instance's workspace root. */
|
|
82
86
|
export declare function startedText(id: string, description: string, workspace?: string): string;
|
|
83
87
|
/**
|
|
@@ -150,12 +150,16 @@ export function launchScript(id, command, seconds) {
|
|
|
150
150
|
`cat ${t}.sid`,
|
|
151
151
|
].join("\n");
|
|
152
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* The launch result's last line: how the task's end is reported and how to read and stop it.
|
|
155
|
+
*/
|
|
156
|
+
export const LAUNCH_NEXT_STEP = "You will be told when it finishes. Read its output with TaskOutput (or Read), stop it with TaskStop.";
|
|
153
157
|
/** The model-visible result of a launch (spec §2.1); `workspace`: the instance's workspace root. */
|
|
154
158
|
export function startedText(id, description, workspace = DEFAULT_SANDBOX_ROOTS.workspace) {
|
|
155
159
|
return [
|
|
156
160
|
`Started background task ${id} ("${description}").`,
|
|
157
161
|
`Output: ${workspace}/${taskOutputPath(id)}`,
|
|
158
|
-
|
|
162
|
+
LAUNCH_NEXT_STEP,
|
|
159
163
|
].join("\n");
|
|
160
164
|
}
|
|
161
165
|
/**
|
|
@@ -209,6 +213,6 @@ export function managedStartedText(id, description, outputPath) {
|
|
|
209
213
|
return [
|
|
210
214
|
`Started background task ${id} ("${description}").`,
|
|
211
215
|
`Output: ${outputPath}`,
|
|
212
|
-
|
|
216
|
+
LAUNCH_NEXT_STEP,
|
|
213
217
|
].join("\n");
|
|
214
218
|
}
|
|
@@ -188,7 +188,7 @@ export declare function headsToResolve(entries: readonly MarketplaceEntry[], imp
|
|
|
188
188
|
/** The host versions (an entry's `minKernel` is judged against them). */
|
|
189
189
|
export declare const HOST_VERSIONS: {
|
|
190
190
|
readonly kernel: string;
|
|
191
|
-
readonly sdk: "0.1.0-rc.
|
|
191
|
+
readonly sdk: "0.1.0-rc.35";
|
|
192
192
|
};
|
|
193
193
|
/** Whether this deployment satisfies the entry's `minKernel`. */
|
|
194
194
|
export declare const entryCompatible: (e: Pick<MarketplaceEntry, "minKernel">) => boolean;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The delivery scope (truthful delivery spec §2): the current run of a conversation after the
|
|
3
|
+
* person last spoke in it. The same bytes reach the user once per scope; this file holds the
|
|
4
|
+
* shapes and the pure repeat decision, {@link EventLog.readDeliveryScope} reads a scope.
|
|
5
|
+
*/
|
|
6
|
+
/** An `artifact_created` event of the scope, as the repeat decision needs it. */
|
|
7
|
+
export interface ScopeArtifact {
|
|
8
|
+
seq: number;
|
|
9
|
+
artifactId: string;
|
|
10
|
+
name: string;
|
|
11
|
+
/** Absent on events written before the field existed: such an artifact never matches. */
|
|
12
|
+
sha256?: string;
|
|
13
|
+
sourcePath: string;
|
|
14
|
+
}
|
|
15
|
+
/** A run's delivery scope: its boundary seq and the artifacts delivered after it. */
|
|
16
|
+
export interface DeliveryScope {
|
|
17
|
+
/**
|
|
18
|
+
* The highest seq among the run's `user_message` events and `question_answered` events with
|
|
19
|
+
* outcome `answered` / `skipped`; the run's `run_started` seq when there is none.
|
|
20
|
+
*/
|
|
21
|
+
boundary: number;
|
|
22
|
+
/** This scope's `artifact_created` events (seq above the boundary), in ascending seq. */
|
|
23
|
+
artifacts: ScopeArtifact[];
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Whether a file with `sha256` from `sourcePath` repeats an artifact of the scope: with M the
|
|
27
|
+
* latest scope artifact with that hash and L the latest with that source path, the file repeats
|
|
28
|
+
* M when M exists and L does not come after M (so v1, v2, v1 of one path delivers v1 again).
|
|
29
|
+
* `lastOfSource` is L's seq (0 without one), part of the append's idempotency key.
|
|
30
|
+
*/
|
|
31
|
+
export declare function findRepeat(scope: DeliveryScope, sha256: string, sourcePath: string): {
|
|
32
|
+
repeatOf: ScopeArtifact | null;
|
|
33
|
+
lastOfSource: number;
|
|
34
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The delivery scope (truthful delivery spec §2): the current run of a conversation after the
|
|
3
|
+
* person last spoke in it. The same bytes reach the user once per scope; this file holds the
|
|
4
|
+
* shapes and the pure repeat decision, {@link EventLog.readDeliveryScope} reads a scope.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Whether a file with `sha256` from `sourcePath` repeats an artifact of the scope: with M the
|
|
8
|
+
* latest scope artifact with that hash and L the latest with that source path, the file repeats
|
|
9
|
+
* M when M exists and L does not come after M (so v1, v2, v1 of one path delivers v1 again).
|
|
10
|
+
* `lastOfSource` is L's seq (0 without one), part of the append's idempotency key.
|
|
11
|
+
*/
|
|
12
|
+
export function findRepeat(scope, sha256, sourcePath) {
|
|
13
|
+
let m = null;
|
|
14
|
+
let lastOfSource = 0;
|
|
15
|
+
for (const a of scope.artifacts) {
|
|
16
|
+
if (a.sha256 !== undefined && a.sha256 === sha256 && (m === null || a.seq > m.seq))
|
|
17
|
+
m = a;
|
|
18
|
+
if (a.sourcePath === sourcePath && a.seq > lastOfSource)
|
|
19
|
+
lastOfSource = a.seq;
|
|
20
|
+
}
|
|
21
|
+
const repeatOf = m !== null && !(lastOfSource > m.seq) ? m : null;
|
|
22
|
+
return { repeatOf, lastOfSource };
|
|
23
|
+
}
|
|
@@ -2,6 +2,7 @@ import { KernelDb } from "../infra/database/kernel-db.js";
|
|
|
2
2
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
3
3
|
import { OutboxService } from "../infra/outbox/outbox.service.js";
|
|
4
4
|
import type { KernelLogger } from "../log.js";
|
|
5
|
+
import type { DeliveryScope } from "./delivery-scope.js";
|
|
5
6
|
import { type ConversationEvent, type ConversationEventType } from "./events.js";
|
|
6
7
|
/** 事件日志依赖的总线:内核 bus(命名空间 `kernel`)。 */
|
|
7
8
|
export interface EventBus {
|
|
@@ -41,6 +42,8 @@ export declare const conversationTopic: (conversationId: string) => string;
|
|
|
41
42
|
* - `compaction_progress`: a compaction of a run is running (context compaction spec §4.6), on that
|
|
42
43
|
* run's own conversation's topic **only** (a child's compaction stays on the child's stream); the
|
|
43
44
|
* SSE forwards the flat data as `event: compaction`. Ephemeral, display-only, not in the log.
|
|
45
|
+
* - `prompt_suggestion`: a completed run's prompt suggestion was stored (prompt suggestions spec
|
|
46
|
+
* §4, `PromptSuggestionStore`). Ephemeral, display-only, not in the log.
|
|
44
47
|
*/
|
|
45
48
|
export type ConversationBusMessage = {
|
|
46
49
|
kind: "events";
|
|
@@ -76,6 +79,12 @@ export type ConversationBusMessage = {
|
|
|
76
79
|
chunks?: number;
|
|
77
80
|
chars?: number;
|
|
78
81
|
startedAt: number;
|
|
82
|
+
} | {
|
|
83
|
+
kind: "prompt_suggestion";
|
|
84
|
+
conversationId: string;
|
|
85
|
+
runId: string;
|
|
86
|
+
afterSeq: number;
|
|
87
|
+
text: string;
|
|
79
88
|
};
|
|
80
89
|
/**
|
|
81
90
|
* What changed about a conversation outside its event log (UI refresh B): the SSE stream sends it as
|
|
@@ -148,6 +157,15 @@ export declare class EventLog {
|
|
|
148
157
|
* 往前翻页读较早的运行时不扫更晚运行的事件。
|
|
149
158
|
*/
|
|
150
159
|
readRunsAfter(conversationId: string, runIds: readonly string[], afterSeq: number, limit?: number): Promise<ConversationEvent[]>;
|
|
160
|
+
/**
|
|
161
|
+
* The delivery scope of `runId` in the conversation (truthful delivery spec §2 step 2): the run's
|
|
162
|
+
* `run_started` seq `S` through the run index (0 when the run has none), then one range read of
|
|
163
|
+
* the `user_message`, `question_answered` and `artifact_created` events from `S` on (a
|
|
164
|
+
* `user_message` carries no run id, so the run index cannot find it). The boundary is the highest
|
|
165
|
+
* seq of a `user_message` or of a `question_answered` answered / skipped, else `S`; the artifacts
|
|
166
|
+
* are the `artifact_created` events after it.
|
|
167
|
+
*/
|
|
168
|
+
readDeliveryScope(conversationId: string, runId: string): Promise<DeliveryScope>;
|
|
151
169
|
/** 按幂等键取事件;没有 → undefined。 */
|
|
152
170
|
findByIdem(conversationId: string, idemKey: string): Promise<ConversationEvent | undefined>;
|
|
153
171
|
/**
|
|
@@ -251,6 +251,60 @@ let EventLog = class EventLog {
|
|
|
251
251
|
.execute();
|
|
252
252
|
return rows.map(toEvent);
|
|
253
253
|
}
|
|
254
|
+
/**
|
|
255
|
+
* The delivery scope of `runId` in the conversation (truthful delivery spec §2 step 2): the run's
|
|
256
|
+
* `run_started` seq `S` through the run index (0 when the run has none), then one range read of
|
|
257
|
+
* the `user_message`, `question_answered` and `artifact_created` events from `S` on (a
|
|
258
|
+
* `user_message` carries no run id, so the run index cannot find it). The boundary is the highest
|
|
259
|
+
* seq of a `user_message` or of a `question_answered` answered / skipped, else `S`; the artifacts
|
|
260
|
+
* are the `artifact_created` events after it.
|
|
261
|
+
*/
|
|
262
|
+
async readDeliveryScope(conversationId, runId) {
|
|
263
|
+
const start = await this.db
|
|
264
|
+
.selectFrom("conversation_events")
|
|
265
|
+
.select("seq")
|
|
266
|
+
.where("conversation_id", "=", conversationId)
|
|
267
|
+
.where("run_id", "=", runId)
|
|
268
|
+
.where("type", "=", "run_started")
|
|
269
|
+
.orderBy("seq")
|
|
270
|
+
.limit(1)
|
|
271
|
+
.executeTakeFirst();
|
|
272
|
+
const s = start === undefined ? 0 : Number(start.seq);
|
|
273
|
+
const rows = await this.db
|
|
274
|
+
.selectFrom("conversation_events")
|
|
275
|
+
.select(["seq", "type", "payload"])
|
|
276
|
+
.where("conversation_id", "=", conversationId)
|
|
277
|
+
.where("seq", ">=", String(s))
|
|
278
|
+
.where("type", "in", ["user_message", "question_answered", "artifact_created"])
|
|
279
|
+
.orderBy("seq")
|
|
280
|
+
.execute();
|
|
281
|
+
let boundary = s;
|
|
282
|
+
for (const r of rows) {
|
|
283
|
+
const seq = Number(r.seq);
|
|
284
|
+
if (r.type === "user_message")
|
|
285
|
+
boundary = Math.max(boundary, seq);
|
|
286
|
+
else if (r.type === "question_answered") {
|
|
287
|
+
const outcome = r.payload.outcome;
|
|
288
|
+
if (outcome === "answered" || outcome === "skipped")
|
|
289
|
+
boundary = Math.max(boundary, seq);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
const artifacts = [];
|
|
293
|
+
for (const r of rows) {
|
|
294
|
+
const seq = Number(r.seq);
|
|
295
|
+
if (r.type !== "artifact_created" || seq <= boundary)
|
|
296
|
+
continue;
|
|
297
|
+
const p = r.payload;
|
|
298
|
+
artifacts.push({
|
|
299
|
+
seq,
|
|
300
|
+
artifactId: p.artifactId,
|
|
301
|
+
name: p.name,
|
|
302
|
+
...(p.sha256 !== undefined && { sha256: p.sha256 }),
|
|
303
|
+
sourcePath: p.sourcePath,
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
return { boundary, artifacts };
|
|
307
|
+
}
|
|
254
308
|
/** 按幂等键取事件;没有 → undefined。 */
|
|
255
309
|
async findByIdem(conversationId, idemKey) {
|
|
256
310
|
const r = await this.db
|
|
@@ -907,6 +907,7 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
|
|
|
907
907
|
compaction: "compaction";
|
|
908
908
|
image: "image";
|
|
909
909
|
review: "review";
|
|
910
|
+
suggestion: "suggestion";
|
|
910
911
|
title: "title";
|
|
911
912
|
web_fetch: "web_fetch";
|
|
912
913
|
}>>;
|
|
@@ -1306,6 +1307,7 @@ export declare const ConversationEventSchema: z.ZodDiscriminatedUnion<[z.ZodObje
|
|
|
1306
1307
|
objectKey: z.ZodString;
|
|
1307
1308
|
sourcePath: z.ZodString;
|
|
1308
1309
|
callId: z.ZodString;
|
|
1310
|
+
sha256: z.ZodOptional<z.ZodString>;
|
|
1309
1311
|
}, z.core.$strip>;
|
|
1310
1312
|
}, z.core.$strip>, z.ZodObject<{
|
|
1311
1313
|
type: z.ZodLiteral<"skills_catalog">;
|
|
@@ -839,14 +839,18 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
|
|
|
839
839
|
* `review` = the command-review classifier's call (auto mode spec §5.3: not model-visible, billed
|
|
840
840
|
* and reported, `callId` = the reviewed tool call); `image` = a `GenerateImage` call (image
|
|
841
841
|
* generation spec §7: the tool call's run and step, `callId` = the call, `outputImages` = the
|
|
842
|
-
* images produced; not model-visible, billed and reported, counted on a sub-agent's parent)
|
|
842
|
+
* images produced; not model-visible, billed and reported, counted on a sub-agent's parent);
|
|
843
|
+
* `suggestion` = the prompt suggestion call after a completed run (prompt suggestions spec §7: no
|
|
844
|
+
* run, `step` 0, one per run, not model-visible, billed and reported).
|
|
843
845
|
*/
|
|
844
846
|
ev("usage", z.object({
|
|
845
847
|
step: count,
|
|
846
848
|
provider: z.string(),
|
|
847
849
|
model: z.string(),
|
|
848
850
|
...ModelUsageShape,
|
|
849
|
-
purpose: z
|
|
851
|
+
purpose: z
|
|
852
|
+
.enum(["compaction", "title", "web_fetch", "review", "image", "suggestion"])
|
|
853
|
+
.optional(),
|
|
850
854
|
/**
|
|
851
855
|
* The chunk a chunked compaction call summarised (1-based), with the number of calls the
|
|
852
856
|
* compaction attempted (the full chunk count on a completed one; on a failed or hook-denied
|
|
@@ -1155,6 +1159,15 @@ export const ConversationEventSchema = z.discriminatedUnion("type", [
|
|
|
1155
1159
|
objectKey: z.string().min(1),
|
|
1156
1160
|
sourcePath: z.string().min(1),
|
|
1157
1161
|
callId: z.string(),
|
|
1162
|
+
/**
|
|
1163
|
+
* The hex sha256 of the bytes (truthful delivery spec §2): the same bytes are delivered once
|
|
1164
|
+
* per delivery scope. Optional only because earlier events cannot be backfilled; an event
|
|
1165
|
+
* without it never matches.
|
|
1166
|
+
*/
|
|
1167
|
+
sha256: z
|
|
1168
|
+
.string()
|
|
1169
|
+
.regex(/^[0-9a-f]{64}$/)
|
|
1170
|
+
.optional(),
|
|
1158
1171
|
})),
|
|
1159
1172
|
/**
|
|
1160
1173
|
* 本对话此刻生效的技能(M5 T14,Ruling M17):运行开始时内核解析生效的技能集合(agent 版本选中的组织技能 +
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { ConversationSource, ModelInfo, ModelRequest } from "@capybara-hq/plugin-sdk";
|
|
2
|
+
import type { ConversationKind } from "../db/kernel-schema.js";
|
|
3
|
+
import { type CaseSnapshot } from "../evals/snapshot.js";
|
|
4
|
+
import type { MediaBytes, MediaInfo } from "../runtime/context/build.js";
|
|
5
|
+
import type { ConversationEvent, EventPayload } from "./events.js";
|
|
6
|
+
/**
|
|
7
|
+
* Prompt suggestions (spec 2026-11-19 §1, §2): the pure part of the side request sent after a
|
|
8
|
+
* completed web run. The request is the run's last request rebuilt through the eval zero-drift
|
|
9
|
+
* path, plus the final reply and {@link PROMPT_SUGGESTION_INSTRUCTION}; only the output cap and
|
|
10
|
+
* `purpose` change besides, so the provider's prompt cache serves the prefix.
|
|
11
|
+
*/
|
|
12
|
+
/** The appended instruction (model-facing, English; spec §1.3). */
|
|
13
|
+
export declare const PROMPT_SUGGESTION_INSTRUCTION: string;
|
|
14
|
+
/** The side request's output cap ceiling (a cost ceiling, not a target; spec §1.4). */
|
|
15
|
+
export declare const PROMPT_SUGGESTION_MAX_OUTPUT_TOKENS = 2048;
|
|
16
|
+
/** Above this many input tokens with no cache activity on the last step, skip (spec §1.5). */
|
|
17
|
+
export declare const PROMPT_SUGGESTION_UNCACHED_INPUT_MAX = 8000;
|
|
18
|
+
/** A job that starts later than this after the run finished is stale (spec §1.5). */
|
|
19
|
+
export declare const PROMPT_SUGGESTION_MAX_DELAY_MS = 60000;
|
|
20
|
+
/** The side call's time limit (spec §1.6). */
|
|
21
|
+
export declare const PROMPT_SUGGESTION_TIMEOUT_MS = 60000;
|
|
22
|
+
/** The longest suggestion kept, in characters (code points; spec §1.7). */
|
|
23
|
+
export declare const PROMPT_SUGGESTION_MAX_CHARS = 200;
|
|
24
|
+
/** Why no side request is built for a run. */
|
|
25
|
+
export type SuggestionSkip = "no_model_call"
|
|
26
|
+
/** The resolved `model` is not the model of the run's last call. */
|
|
27
|
+
| "model_mismatch" | "no_final_reply" | "final_reply_has_tool_call" | "drift" | "fit" | "prefix_mismatch" | "too_large" | "uncached";
|
|
28
|
+
type ModelCallEvent = Extract<ConversationEvent, {
|
|
29
|
+
type: "model_call";
|
|
30
|
+
}>;
|
|
31
|
+
/** The run's last `model_call` (the highest seq with the run's id), or undefined. */
|
|
32
|
+
export declare function lastModelCallOf(events: readonly ConversationEvent[], runId: string): ModelCallEvent | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* The side request, or why there is none (spec §1). `model` is the current info of the last
|
|
35
|
+
* call's provider and model as the caller resolved it for the org; `mediaInfo` / `media` come from
|
|
36
|
+
* `loadSnapshotMedia` for that call; `reserveTokens` is the org's compaction reserve.
|
|
37
|
+
*
|
|
38
|
+
* Checks, in order: the run has a `model_call` (`no_model_call`); `model` is that call's model
|
|
39
|
+
* (`model_mismatch`); the call carries no fit plan (`fit`); a final `assistant_message` follows
|
|
40
|
+
* the call (`no_final_reply`) without a `tool_call` block (`final_reply_has_tool_call`) and with
|
|
41
|
+
* text (`no_final_reply`); the run's last step usage shows cache activity or at most
|
|
42
|
+
* {@link PROMPT_SUGGESTION_UNCACHED_INPUT_MAX} input tokens (`uncached`); the baseline
|
|
43
|
+
* reconstruction of the call has no drift and the snapshot is valid (`drift`); the extension, the
|
|
44
|
+
* same inputs with every snapshot event up to the run's terminal event, keeps `model`, `system`,
|
|
45
|
+
* `tools`, `toolChoice`, `params` and the messages as a prefix, followed by exactly one assistant
|
|
46
|
+
* message, so only usage and the terminal event follow the final reply (`prefix_mismatch`); the
|
|
47
|
+
* estimate plus the cap fits `contextWindow - reserveTokens` (`too_large`). Never throws for a
|
|
48
|
+
* snapshot's content.
|
|
49
|
+
*/
|
|
50
|
+
export declare function buildSuggestionRequest(input: {
|
|
51
|
+
snapshot: CaseSnapshot;
|
|
52
|
+
model: ModelInfo;
|
|
53
|
+
mediaInfo?: ReadonlyMap<string, MediaInfo>;
|
|
54
|
+
media?: ReadonlyMap<string, MediaBytes | null>;
|
|
55
|
+
reserveTokens: number;
|
|
56
|
+
}): {
|
|
57
|
+
request: ModelRequest;
|
|
58
|
+
lastCall: {
|
|
59
|
+
seq: number;
|
|
60
|
+
provider: string;
|
|
61
|
+
model: string;
|
|
62
|
+
};
|
|
63
|
+
finalText: string;
|
|
64
|
+
estimate: number;
|
|
65
|
+
} | {
|
|
66
|
+
skip: SuggestionSkip;
|
|
67
|
+
};
|
|
68
|
+
/** The run facts eligibility reads (spec §2, the first four rows). */
|
|
69
|
+
export interface SuggestionEligibilityInput {
|
|
70
|
+
/** `run_finished.reason`. */
|
|
71
|
+
outcome: EventPayload<"run_finished">["reason"];
|
|
72
|
+
/** `conversations.kind`. */
|
|
73
|
+
kind: ConversationKind;
|
|
74
|
+
/** `conversations.source`. */
|
|
75
|
+
source: ConversationSource;
|
|
76
|
+
/** `run_started.trigger` (absent = a person's message). */
|
|
77
|
+
trigger: EventPayload<"run_started">["trigger"];
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Whether a finished run may get a suggestion by its outcome, conversation and trigger (spec §2):
|
|
81
|
+
* `completed` or `max_steps`, a `chat` conversation from `web`, not a scheduled or compact run.
|
|
82
|
+
* The final reply, freshness and the switches are checked elsewhere.
|
|
83
|
+
*/
|
|
84
|
+
export declare function suggestionEligible(i: SuggestionEligibilityInput): boolean;
|
|
85
|
+
/**
|
|
86
|
+
* The suggestion from the model's reply text (spec §1.7), or null for none: the first non-empty
|
|
87
|
+
* line with control and hidden format characters removed, a leading user label (`User:`, or the
|
|
88
|
+
* Chinese word for user with a full-width colon, `LABEL_RE`) and balanced wrapping quotes
|
|
89
|
+
* stripped, trimmed, cut to {@link PROMPT_SUGGESTION_MAX_CHARS} code points.
|
|
90
|
+
* `NONE` (any case), an empty result or an echo of the final reply (`finalText`) is null.
|
|
91
|
+
*/
|
|
92
|
+
export declare function cleanSuggestion(reply: string, finalText: string): string | null;
|
|
93
|
+
/** Whether the job is too late (`now - finishedAt > PROMPT_SUGGESTION_MAX_DELAY_MS`). */
|
|
94
|
+
export declare function suggestionStale(finishedAt: number, now: number): boolean;
|
|
95
|
+
export {};
|