@vellumai/assistant 0.8.9 → 0.8.10-dev.202606092334.09948c8
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/AGENTS.md +1 -1
- package/examples/plugins/echo/README.md +3 -3
- package/node_modules/@vellumai/skill-host-contracts/src/tool-types.ts +2 -0
- package/openapi.yaml +38 -12
- package/package.json +1 -1
- package/scripts/sync-llm-catalog.ts +2 -0
- package/src/__tests__/agent-loop-exit-reason.test.ts +21 -15
- package/src/__tests__/approval-cascade.test.ts +1 -0
- package/src/__tests__/build-persisted-content.test.ts +75 -1
- package/src/__tests__/compaction-events.test.ts +1 -0
- package/src/__tests__/config-managed-gemini-defaults.test.ts +2 -46
- package/src/__tests__/context-overflow-reducer.test.ts +264 -124
- package/src/__tests__/context-window-manager-overflow-rung.test.ts +351 -0
- package/src/__tests__/conversation-abort-tool-results.test.ts +1 -0
- package/src/__tests__/conversation-agent-loop-inference-profile.test.ts +11 -0
- package/src/__tests__/conversation-agent-loop-overflow.test.ts +90 -49
- package/src/__tests__/conversation-agent-loop.test.ts +113 -64
- package/src/__tests__/conversation-confirmation-signals.test.ts +1 -0
- package/src/__tests__/conversation-fork-crud.test.ts +110 -0
- package/src/__tests__/conversation-process-callsite.test.ts +1 -0
- package/src/__tests__/conversation-provider-retry-repair.test.ts +48 -48
- package/src/__tests__/conversation-queue.test.ts +1 -0
- package/src/__tests__/conversation-runtime-assembly.test.ts +119 -8
- package/src/__tests__/conversation-slash-queue.test.ts +1 -0
- package/src/__tests__/conversation-slash-unknown.test.ts +1 -0
- package/src/__tests__/conversation-speed-override.test.ts +1 -0
- package/src/__tests__/conversation-surfaces-app-control.test.ts +4 -1
- package/src/__tests__/conversation-tool-setup-app-refresh.test.ts +91 -142
- package/src/__tests__/conversation-tool-setup-skill-attribution.test.ts +116 -0
- package/src/__tests__/conversation-tool-setup-test-helpers.ts +98 -0
- package/src/__tests__/conversation-workspace-cache-state.test.ts +1 -0
- package/src/__tests__/conversation-workspace-injection.test.ts +1 -0
- package/src/__tests__/conversation-workspace-tool-tracking.test.ts +1 -0
- package/src/__tests__/corrected-target.test.ts +93 -0
- package/src/__tests__/credential-execution-feature-gates.test.ts +3 -5
- package/src/__tests__/credential-security-invariants.test.ts +1 -0
- package/src/__tests__/embedding-managed-proxy-selection.test.ts +6 -40
- package/src/__tests__/external-plugin-loader.test.ts +0 -1
- package/src/__tests__/guardian-routing-invariants.test.ts +91 -0
- package/src/__tests__/history-repair-hook.test.ts +2 -0
- package/src/__tests__/host-app-control-proxy.test.ts +45 -0
- package/src/__tests__/llm-catalog-parity.test.ts +4 -0
- package/src/__tests__/memory-retrieval-hook.test.ts +29 -15
- package/src/__tests__/notification-decision-strategy.test.ts +3 -3
- package/src/__tests__/persistence-secret-redaction.test.ts +78 -0
- package/src/__tests__/plugin-bootstrap.test.ts +82 -73
- package/src/__tests__/plugin-tool-contribution.test.ts +7 -4
- package/src/__tests__/plugin-types.test.ts +0 -8
- package/src/__tests__/provider-catalog-visibility.test.ts +1 -9
- package/src/__tests__/retry-thinking-adaptive-only.test.ts +245 -0
- package/src/__tests__/server-history-render.test.ts +39 -0
- package/src/__tests__/skills.test.ts +123 -0
- package/src/__tests__/title-generate-hook.test.ts +2 -0
- package/src/__tests__/tool-audit-listener.test.ts +51 -0
- package/src/__tests__/tool-executor-lifecycle-events.test.ts +32 -0
- package/src/__tests__/tool-start-timestamp.test.ts +218 -0
- package/src/agent/loop.ts +26 -39
- package/src/api/events/tool-result.ts +9 -0
- package/src/api/events/tool-use-start.ts +7 -0
- package/src/api/responses/conversation-message.ts +91 -14
- package/src/approvals/guardian-request-resolvers.ts +26 -0
- package/src/cli/commands/channel-verification-sessions.ts +6 -6
- package/src/cli/commands/inference-providers.ts +0 -8
- package/src/cli/commands/plugins.ts +2 -2
- package/src/cli/lib/__tests__/install-from-github.test.ts +174 -18
- package/src/cli/lib/__tests__/plugin-catalog-cache.test.ts +1 -1
- package/src/cli/lib/__tests__/plugin-details.test.ts +1 -1
- package/src/cli/lib/__tests__/plugin-marketplace.test.ts +1 -1
- package/src/cli/lib/__tests__/search-plugins.test.ts +11 -11
- package/src/cli/lib/install-from-github.ts +130 -19
- package/src/cli/lib/plugin-catalog-cache.ts +1 -1
- package/src/cli/lib/plugin-details.ts +4 -4
- package/src/cli/lib/plugin-marketplace.ts +2 -2
- package/src/cli/lib/search-plugins.ts +6 -6
- package/src/config/bundled-skills/skill-management/SKILL.md +89 -1
- package/src/config/env-registry.ts +12 -0
- package/src/config/feature-flag-registry.json +0 -80
- package/src/config/loader.ts +5 -22
- package/src/config/seed-inference-profiles.ts +1 -1
- package/src/config/skills.ts +101 -47
- package/src/context/strip-injections.ts +7 -4
- package/src/daemon/conversation-agent-loop-handlers.ts +102 -6
- package/src/daemon/conversation-agent-loop.ts +126 -270
- package/src/daemon/conversation-runtime-assembly.ts +44 -8
- package/src/daemon/conversation-tool-setup.ts +9 -1
- package/src/daemon/conversation.ts +13 -0
- package/src/daemon/external-plugins-bootstrap.ts +33 -87
- package/src/daemon/handlers/config-channels.ts +11 -2
- package/src/daemon/handlers/shared.ts +9 -1
- package/src/daemon/handlers/skills.ts +6 -2
- package/src/daemon/host-app-control-proxy.ts +72 -57
- package/src/daemon/message-protocol.ts +0 -7
- package/src/daemon/message-types/skills.ts +4 -0
- package/src/events/tool-audit-listener.ts +7 -1
- package/src/memory/__tests__/tool-invocation-test-helpers.ts +69 -0
- package/src/memory/conversation-crud.ts +44 -1
- package/src/memory/db-init.ts +4 -0
- package/src/memory/embedding-backend.ts +5 -22
- package/src/memory/memory-retrospective-startup-cleanup.ts +1 -1
- package/src/memory/migrations/275-tool-invocations-add-skill-id.test.ts +81 -0
- package/src/memory/migrations/275-tool-invocations-add-skill-id.ts +20 -0
- package/src/memory/migrations/276-tool-invocations-created-at-id-index.test.ts +68 -0
- package/src/memory/migrations/276-tool-invocations-created-at-id-index.ts +20 -0
- package/src/memory/migrations/index.ts +2 -0
- package/src/memory/schema/conversations.ts +3 -0
- package/src/memory/tool-execution-events-store.test.ts +162 -0
- package/src/memory/tool-execution-events-store.ts +73 -0
- package/src/memory/tool-usage-store.ts +4 -3
- package/src/memory/v2/__tests__/injected-block-slugs.test.ts +51 -0
- package/src/memory/v2/activation-store.ts +50 -1
- package/src/memory/v2/injected-block-slugs.ts +30 -0
- package/src/notifications/__tests__/copy-composer.test.ts +244 -0
- package/src/notifications/access-request-copy.ts +298 -0
- package/src/notifications/adapters/slack.ts +3 -3
- package/src/notifications/adapters/telegram.ts +2 -1
- package/src/notifications/copy-composer.ts +49 -267
- package/src/notifications/decision-engine.ts +16 -35
- package/src/notifications/home-feed-side-effect.ts +1 -6
- package/src/platform/client.ts +1 -3
- package/src/platform/feature-gate.ts +3 -12
- package/src/plugin-api/constants.ts +2 -0
- package/src/plugin-api/index.ts +37 -6
- package/src/plugin-api/types.ts +75 -0
- package/src/plugins/defaults/compaction/compact.ts +39 -1
- package/src/plugins/defaults/compaction/context-overflow-reducer.ts +240 -32
- package/src/plugins/defaults/compaction/corrected-target.ts +53 -0
- package/src/plugins/defaults/compaction/window-manager.ts +195 -1
- package/src/plugins/defaults/index.ts +24 -0
- package/src/plugins/defaults/memory-retrieval/hooks/post-compact.ts +76 -112
- package/src/plugins/defaults/memory-retrieval/hooks/{user-prompt-submit-temp.ts → user-prompt-submit.ts} +36 -67
- package/src/plugins/defaults/memory-retrieval/package.json +14 -0
- package/src/plugins/external-api.ts +1 -1
- package/src/plugins/types.ts +5 -51
- package/src/providers/inference/__tests__/base-url-route-validation.test.ts +1 -2
- package/src/providers/model-catalog.ts +57 -1
- package/src/providers/registry.ts +0 -8
- package/src/providers/retry.ts +35 -7
- package/src/runtime/routes/__tests__/acp-routes.test.ts +151 -0
- package/src/runtime/routes/__tests__/inference-provider-connection-routes.test.ts +0 -62
- package/src/runtime/routes/__tests__/plugins-routes.test.ts +4 -4
- package/src/runtime/routes/acp-routes.test.ts +106 -0
- package/src/runtime/routes/acp-routes.ts +248 -2
- package/src/runtime/routes/browser-tabs-routes.ts +1 -1
- package/src/runtime/routes/channel-verification-routes.ts +14 -5
- package/src/runtime/routes/chatgpt-subscription-auth-routes.ts +0 -14
- package/src/runtime/routes/inbound-stages/acl-enforcement.ts +33 -34
- package/src/runtime/routes/inference-provider-connection-routes.ts +0 -45
- package/src/runtime/routes/plugins-routes.ts +3 -3
- package/src/runtime/verification-outbound-actions.ts +147 -2
- package/src/runtime/verification-templates.ts +29 -3
- package/src/telemetry/types.ts +25 -1
- package/src/telemetry/usage-telemetry-reporter.test.ts +141 -7
- package/src/telemetry/usage-telemetry-reporter.ts +63 -7
- package/src/tools/executor.ts +4 -1
- package/src/tools/skills/load.ts +11 -6
- package/src/tools/terminal/safe-env.ts +1 -0
- package/src/tools/types.ts +10 -0
- package/src/__tests__/plugin-skill-contribution.test.ts +0 -355
- package/src/daemon/message-types/browser.ts +0 -10
- package/src/notifications/__tests__/emit-signal-home-feed.test.ts +0 -187
- package/src/plugins/plugin-skill-contributions.ts +0 -292
|
@@ -9,6 +9,10 @@
|
|
|
9
9
|
* values from the context payload.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
import {
|
|
13
|
+
buildAccessRequestContractText,
|
|
14
|
+
sanitizeIdentityField,
|
|
15
|
+
} from "./access-request-copy.js";
|
|
12
16
|
import {
|
|
13
17
|
buildGuardianRequestCodeInstruction,
|
|
14
18
|
resolveGuardianQuestionInstructionMode,
|
|
@@ -32,285 +36,39 @@ export function nonEmpty(value: string | undefined): string | undefined {
|
|
|
32
36
|
return trimmed.length > 0 ? trimmed : undefined;
|
|
33
37
|
}
|
|
34
38
|
|
|
35
|
-
// ── Access-request copy contract ─────────────────────────────────────────────
|
|
36
|
-
//
|
|
37
|
-
// Deterministic helpers for building guardian-facing access-request copy.
|
|
38
|
-
// These are used both by the fallback template and the decision-engine
|
|
39
|
-
// post-generation enforcement to ensure required directives always appear.
|
|
40
|
-
|
|
41
|
-
const IDENTITY_FIELD_MAX_LENGTH = 120;
|
|
42
|
-
|
|
43
39
|
/**
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* - Clamps to IDENTITY_FIELD_MAX_LENGTH characters.
|
|
48
|
-
* - Wraps in quotes to neutralize instruction-like payload text.
|
|
40
|
+
* Safely read a string property from an unknown-typed payload object.
|
|
41
|
+
* Returns `undefined` when the payload is falsy, not an object, or the
|
|
42
|
+
* key does not hold a string value.
|
|
49
43
|
*/
|
|
50
|
-
export function
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
stripped.length > IDENTITY_FIELD_MAX_LENGTH
|
|
54
|
-
? stripped.slice(0, IDENTITY_FIELD_MAX_LENGTH) + "…"
|
|
55
|
-
: stripped;
|
|
56
|
-
return clamped;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export function buildAccessRequestIdentityLine(
|
|
60
|
-
payload: Record<string, unknown>,
|
|
61
|
-
): string {
|
|
62
|
-
const requester = sanitizeIdentityField(
|
|
63
|
-
str(payload.senderIdentifier, "Someone"),
|
|
64
|
-
);
|
|
65
|
-
const sourceChannel =
|
|
66
|
-
typeof payload.sourceChannel === "string"
|
|
67
|
-
? payload.sourceChannel
|
|
68
|
-
: undefined;
|
|
69
|
-
const callerName = nonEmpty(
|
|
70
|
-
typeof payload.actorDisplayName === "string"
|
|
71
|
-
? payload.actorDisplayName
|
|
72
|
-
: undefined,
|
|
73
|
-
);
|
|
74
|
-
const actorUsername = nonEmpty(
|
|
75
|
-
typeof payload.actorUsername === "string"
|
|
76
|
-
? payload.actorUsername
|
|
77
|
-
: undefined,
|
|
78
|
-
);
|
|
79
|
-
const actorExternalId = nonEmpty(
|
|
80
|
-
typeof payload.actorExternalId === "string"
|
|
81
|
-
? payload.actorExternalId
|
|
82
|
-
: undefined,
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
if (sourceChannel === "phone" && callerName) {
|
|
86
|
-
const safeName = sanitizeIdentityField(callerName);
|
|
87
|
-
const safeId = sanitizeIdentityField(
|
|
88
|
-
str(payload.actorExternalId, requester),
|
|
89
|
-
);
|
|
90
|
-
return `${safeName} (${safeId}) is calling and requesting access to the assistant.`;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// For non-voice, include extra context when available.
|
|
94
|
-
// Sanitize before comparing to avoid deduplication failures when identity
|
|
95
|
-
// fields contain control characters that are stripped from `requester`.
|
|
96
|
-
const sanitizedUsername = actorUsername
|
|
97
|
-
? sanitizeIdentityField(actorUsername)
|
|
98
|
-
: undefined;
|
|
99
|
-
const sanitizedExternalId = actorExternalId
|
|
100
|
-
? sanitizeIdentityField(actorExternalId)
|
|
101
|
-
: undefined;
|
|
102
|
-
// When the requester is a raw Slack user ID (e.g. the fallback path in
|
|
103
|
-
// access-request-helper sets senderIdentifier to the raw actorExternalId),
|
|
104
|
-
// format it as a Slack mention so it renders as a clickable display name.
|
|
105
|
-
const formattedRequester =
|
|
106
|
-
sourceChannel === "slack" && /^U[A-Z0-9]+$/i.test(requester)
|
|
107
|
-
? `<@${requester}>`
|
|
108
|
-
: requester;
|
|
109
|
-
const parts = [formattedRequester];
|
|
110
|
-
if (sanitizedUsername && sanitizedUsername !== requester) {
|
|
111
|
-
parts.push(`@${sanitizedUsername}`);
|
|
112
|
-
}
|
|
113
|
-
if (
|
|
114
|
-
sanitizedExternalId &&
|
|
115
|
-
sanitizedExternalId !== requester &&
|
|
116
|
-
sanitizedExternalId !== sanitizedUsername
|
|
117
|
-
) {
|
|
118
|
-
// For Slack, use the <@U...> mention format so Slack auto-renders
|
|
119
|
-
// the user ID as a clickable display name.
|
|
120
|
-
const formattedId =
|
|
121
|
-
sourceChannel === "slack" && /^U[A-Z0-9]+$/i.test(sanitizedExternalId)
|
|
122
|
-
? `<@${sanitizedExternalId}>`
|
|
123
|
-
: `[${sanitizedExternalId}]`;
|
|
124
|
-
parts.push(formattedId);
|
|
125
|
-
}
|
|
126
|
-
if (sourceChannel) {
|
|
127
|
-
parts.push(`via ${sourceChannel}`);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
return `${parts.join(" ")} is requesting access to the assistant.`;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
export const MESSAGE_PREVIEW_MAX_LENGTH = 200;
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Sanitize an untrusted message preview for inclusion in notification copy.
|
|
137
|
-
*
|
|
138
|
-
* Like {@link sanitizeIdentityField} but uses the higher
|
|
139
|
-
* MESSAGE_PREVIEW_MAX_LENGTH limit (200 chars) instead of the identity
|
|
140
|
-
* field limit (120 chars).
|
|
141
|
-
*/
|
|
142
|
-
export function sanitizeMessagePreview(value: string): string {
|
|
143
|
-
const stripped = value.replace(/[\x00-\x1f\x7f-\x9f\r\n]+/g, " ").trim();
|
|
144
|
-
const clamped =
|
|
145
|
-
stripped.length > MESSAGE_PREVIEW_MAX_LENGTH
|
|
146
|
-
? stripped.slice(0, MESSAGE_PREVIEW_MAX_LENGTH) + "…"
|
|
147
|
-
: stripped;
|
|
148
|
-
return clamped;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Build a quoted preview of the requester's original message for inclusion
|
|
153
|
-
* in guardian-facing access-request copy. Sanitizes and truncates to keep
|
|
154
|
-
* the notification concise.
|
|
155
|
-
*
|
|
156
|
-
* Returns `undefined` when no usable preview is available.
|
|
157
|
-
*/
|
|
158
|
-
function buildAccessRequestMessagePreview(
|
|
159
|
-
payload: Record<string, unknown>,
|
|
44
|
+
export function readPayloadString(
|
|
45
|
+
payload: unknown,
|
|
46
|
+
key: string,
|
|
160
47
|
): string | undefined {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
: undefined;
|
|
165
|
-
if (!raw) return undefined;
|
|
166
|
-
|
|
167
|
-
const sanitized = sanitizeMessagePreview(raw);
|
|
168
|
-
if (sanitized.length === 0) return undefined;
|
|
169
|
-
|
|
170
|
-
return `> Their message: "${sanitized}"`;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
export function buildAccessRequestInviteDirective(): string {
|
|
174
|
-
return 'Reply "open invite flow" to start Trusted Contacts invite flow.';
|
|
48
|
+
if (!payload || typeof payload !== "object") return undefined;
|
|
49
|
+
const value = (payload as Record<string, unknown>)[key];
|
|
50
|
+
return typeof value === "string" ? value : undefined;
|
|
175
51
|
}
|
|
176
52
|
|
|
177
53
|
/**
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
* so contractions like "Don\u2019t" are matched by the `n't` lookbehind.
|
|
182
|
-
* - Collapses runs of whitespace into a single space so "Do not reply"
|
|
183
|
-
* is matched by the single-space negative lookbehind.
|
|
184
|
-
* - Trims leading/trailing whitespace.
|
|
54
|
+
* Derive a short notification title from a message body. Trims to the
|
|
55
|
+
* first sentence terminator when present, then caps the result at
|
|
56
|
+
* 60 characters with an ellipsis.
|
|
185
57
|
*/
|
|
186
|
-
export function
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
.
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Check whether a text contains the required access-request instruction elements:
|
|
195
|
-
* 1. Approve directive: Reply "CODE approve"
|
|
196
|
-
* 2. Reject directive: Reply "CODE reject"
|
|
197
|
-
* 3. Invite directive: Reply "open invite flow"
|
|
198
|
-
*
|
|
199
|
-
* Each directive is matched independently using negative lookbehind to reject
|
|
200
|
-
* matches preceded by negation words ("not", "n't", "never"). This prevents
|
|
201
|
-
* contradictory copy like `Do not reply "CODE reject"` from satisfying the
|
|
202
|
-
* check even when a positive approve directive exists nearby.
|
|
203
|
-
*
|
|
204
|
-
* The text is normalized before matching to handle smart apostrophes and
|
|
205
|
-
* multiple whitespace characters that would otherwise bypass negation detection.
|
|
206
|
-
*/
|
|
207
|
-
export function hasAccessRequestInstructions(
|
|
208
|
-
text: string | undefined,
|
|
209
|
-
requestCode: string,
|
|
210
|
-
): boolean {
|
|
211
|
-
if (typeof text !== "string") return false;
|
|
212
|
-
const normalized = normalizeForDirectiveMatching(text);
|
|
213
|
-
const escapedCode = requestCode.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
214
|
-
// Each directive must follow "reply" without a preceding negation word.
|
|
215
|
-
// Negative lookbehinds reject "do not reply", "don't reply", "never reply".
|
|
216
|
-
const approveRe = new RegExp(
|
|
217
|
-
`(?<!not\\s)(?<!n't\\s)(?<!never\\s)reply\\b[^.!?\\n]*?"${escapedCode}\\s+approve"`,
|
|
218
|
-
"i",
|
|
219
|
-
);
|
|
220
|
-
const rejectRe = new RegExp(
|
|
221
|
-
`(?<!not\\s)(?<!n't\\s)(?<!never\\s)reply\\b[^.!?\\n]*?"${escapedCode}\\s+reject"`,
|
|
222
|
-
"i",
|
|
223
|
-
);
|
|
224
|
-
const inviteRe =
|
|
225
|
-
/(?<!not\s)(?<!n't\s)(?<!never\s)reply\b[^.!?\n]*?"open invite flow"/i;
|
|
226
|
-
|
|
227
|
-
return (
|
|
228
|
-
approveRe.test(normalized) &&
|
|
229
|
-
rejectRe.test(normalized) &&
|
|
230
|
-
inviteRe.test(normalized)
|
|
231
|
-
);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* Check whether text contains the invite-flow directive ("open invite flow")
|
|
236
|
-
* using the same normalized negative-lookbehind pattern as the full check.
|
|
237
|
-
* This is used for enforcement when requestCode is absent but the invite
|
|
238
|
-
* directive should still be present.
|
|
239
|
-
*/
|
|
240
|
-
export function hasInviteFlowDirective(text: string | undefined): boolean {
|
|
241
|
-
if (typeof text !== "string") return false;
|
|
242
|
-
const normalized = normalizeForDirectiveMatching(text);
|
|
243
|
-
const inviteRe =
|
|
244
|
-
/(?<!not\s)(?<!n't\s)(?<!never\s)reply\b[^.!?\n]*?"open invite flow"/i;
|
|
245
|
-
return inviteRe.test(normalized);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
/**
|
|
249
|
-
* Build the deterministic access-request contract text from payload fields.
|
|
250
|
-
* This is the canonical baseline that enforcement can append when generated
|
|
251
|
-
* copy is missing required elements.
|
|
252
|
-
*
|
|
253
|
-
* Channel-agnostic by design: this function reads from the generic
|
|
254
|
-
* `contextPayload` and works identically regardless of which channel
|
|
255
|
-
* (Slack, Telegram, desktop, etc.) the notification is delivered to.
|
|
256
|
-
* When `guardianResolutionSource` is present and not `"source-channel-contact"`,
|
|
257
|
-
* the guardian was resolved via fallback (e.g. vellum anchor) rather than
|
|
258
|
-
* a verified same-channel contact — downstream copy or routing can use
|
|
259
|
-
* this to append verification CTAs like "Was this you?".
|
|
260
|
-
*/
|
|
261
|
-
export function buildAccessRequestContractText(
|
|
262
|
-
payload: Record<string, unknown>,
|
|
263
|
-
): string {
|
|
264
|
-
const requestCode = nonEmpty(
|
|
265
|
-
typeof payload.requestCode === "string" ? payload.requestCode : undefined,
|
|
266
|
-
);
|
|
267
|
-
const previousMemberStatus =
|
|
268
|
-
typeof payload.previousMemberStatus === "string"
|
|
269
|
-
? payload.previousMemberStatus
|
|
270
|
-
: undefined;
|
|
271
|
-
|
|
272
|
-
const guardianResolutionSource =
|
|
273
|
-
typeof payload.guardianResolutionSource === "string"
|
|
274
|
-
? payload.guardianResolutionSource
|
|
275
|
-
: undefined;
|
|
276
|
-
const sourceChannel =
|
|
277
|
-
typeof payload.sourceChannel === "string"
|
|
278
|
-
? payload.sourceChannel
|
|
279
|
-
: undefined;
|
|
280
|
-
|
|
281
|
-
const lines: string[] = [];
|
|
282
|
-
lines.push(buildAccessRequestIdentityLine(payload));
|
|
283
|
-
const preview = buildAccessRequestMessagePreview(payload);
|
|
284
|
-
if (preview) {
|
|
285
|
-
lines.push(preview);
|
|
286
|
-
}
|
|
287
|
-
if (previousMemberStatus === "revoked") {
|
|
288
|
-
lines.push("Note: this user was previously revoked.");
|
|
289
|
-
}
|
|
290
|
-
if (requestCode) {
|
|
291
|
-
const code = requestCode.toUpperCase();
|
|
292
|
-
lines.push(
|
|
293
|
-
`Reply "${code} approve" to grant access or "${code} reject" to deny.`,
|
|
294
|
-
);
|
|
295
|
-
}
|
|
296
|
-
lines.push(buildAccessRequestInviteDirective());
|
|
297
|
-
if (
|
|
298
|
-
(guardianResolutionSource === "vellum-anchor" ||
|
|
299
|
-
guardianResolutionSource === "none") &&
|
|
300
|
-
sourceChannel
|
|
301
|
-
) {
|
|
302
|
-
lines.push(
|
|
303
|
-
`Note: You haven't verified your identity on ${sourceChannel} yet. If this was you trying to message your assistant, say "help me verify as guardian on ${sourceChannel}" to set up direct access.`,
|
|
304
|
-
);
|
|
305
|
-
}
|
|
306
|
-
return lines.join("\n");
|
|
58
|
+
export function deriveTitle(body: string): string {
|
|
59
|
+
const firstSentenceEnd = body.search(/[.!?](\s|$)/);
|
|
60
|
+
const candidate =
|
|
61
|
+
firstSentenceEnd > 0 ? body.slice(0, firstSentenceEnd + 1) : body;
|
|
62
|
+
return candidate.length > 60
|
|
63
|
+
? candidate.slice(0, 60).trim() + "\u2026"
|
|
64
|
+
: candidate.trim();
|
|
307
65
|
}
|
|
308
66
|
|
|
309
67
|
// Templates keyed by dot-separated sourceEventName strings matching producers.
|
|
310
68
|
const TEMPLATES: Partial<Record<NotificationSourceEventName, CopyTemplate>> = {
|
|
311
69
|
"schedule.notify": (payload) => ({
|
|
312
|
-
title: "Reminder",
|
|
313
|
-
body: str(payload.message,
|
|
70
|
+
title: str(payload.label, "Reminder"),
|
|
71
|
+
body: str(payload.message, "A reminder has fired"),
|
|
314
72
|
}),
|
|
315
73
|
|
|
316
74
|
"guardian.question": (payload) => {
|
|
@@ -553,6 +311,30 @@ export function composeFallbackCopy(
|
|
|
553
311
|
signal: NotificationSignal,
|
|
554
312
|
channels: NotificationChannel[],
|
|
555
313
|
): Partial<Record<NotificationChannel, RenderedChannelCopy>> {
|
|
314
|
+
// Honor user-supplied content when present. The assistant_tool
|
|
315
|
+
// pass-through handles the happy path (sourceChannel === "assistant_tool");
|
|
316
|
+
// this catches the same payload fields when the LLM fallback fires for
|
|
317
|
+
// any source channel.
|
|
318
|
+
const msg = nonEmpty(
|
|
319
|
+
readPayloadString(signal.contextPayload, "requestedMessage"),
|
|
320
|
+
);
|
|
321
|
+
if (msg) {
|
|
322
|
+
const title =
|
|
323
|
+
nonEmpty(readPayloadString(signal.contextPayload, "requestedTitle")) ??
|
|
324
|
+
deriveTitle(msg);
|
|
325
|
+
const baseCopy: RenderedChannelCopy = {
|
|
326
|
+
title,
|
|
327
|
+
body: msg,
|
|
328
|
+
conversationSeedMessage: msg,
|
|
329
|
+
};
|
|
330
|
+
const result: Partial<Record<NotificationChannel, RenderedChannelCopy>> =
|
|
331
|
+
{};
|
|
332
|
+
for (const ch of channels) {
|
|
333
|
+
result[ch] = applyChannelDefaults(ch, baseCopy);
|
|
334
|
+
}
|
|
335
|
+
return result;
|
|
336
|
+
}
|
|
337
|
+
|
|
556
338
|
const template =
|
|
557
339
|
TEMPLATES[signal.sourceEventName as NotificationSourceEventName];
|
|
558
340
|
|
|
@@ -23,17 +23,22 @@ import {
|
|
|
23
23
|
import type { Provider } from "../providers/types.js";
|
|
24
24
|
import { getLogger } from "../util/logger.js";
|
|
25
25
|
import { truncate } from "../util/truncate.js";
|
|
26
|
+
import {
|
|
27
|
+
buildAccessRequestContractText,
|
|
28
|
+
buildAccessRequestInviteDirective,
|
|
29
|
+
hasAccessRequestInstructions,
|
|
30
|
+
hasInviteFlowDirective,
|
|
31
|
+
} from "./access-request-copy.js";
|
|
26
32
|
import {
|
|
27
33
|
buildConversationCandidates,
|
|
28
34
|
type ConversationCandidateSet,
|
|
29
35
|
serializeCandidatesForPrompt,
|
|
30
36
|
} from "./conversation-candidates.js";
|
|
31
37
|
import {
|
|
32
|
-
buildAccessRequestContractText,
|
|
33
|
-
buildAccessRequestInviteDirective,
|
|
34
38
|
composeFallbackCopy,
|
|
35
|
-
|
|
36
|
-
|
|
39
|
+
deriveTitle,
|
|
40
|
+
nonEmpty,
|
|
41
|
+
readPayloadString,
|
|
37
42
|
} from "./copy-composer.js";
|
|
38
43
|
import { createDecision } from "./decisions-store.js";
|
|
39
44
|
import {
|
|
@@ -56,21 +61,6 @@ const log = getLogger("notification-decision-engine");
|
|
|
56
61
|
const DECISION_TIMEOUT_MS = 15_000;
|
|
57
62
|
const PROMPT_VERSION = "v4";
|
|
58
63
|
|
|
59
|
-
/**
|
|
60
|
-
* Derive a short notification title from a message body. Used when an
|
|
61
|
-
* assistant_tool-sourced signal supplies `requestedMessage` without an
|
|
62
|
-
* explicit `requestedTitle`: trims to the first sentence terminator when
|
|
63
|
-
* present, then caps the result at 60 characters with an ellipsis.
|
|
64
|
-
*/
|
|
65
|
-
function deriveTitle(body: string): string {
|
|
66
|
-
const firstSentenceEnd = body.search(/[.!?](\s|$)/);
|
|
67
|
-
const candidate =
|
|
68
|
-
firstSentenceEnd > 0 ? body.slice(0, firstSentenceEnd + 1) : body;
|
|
69
|
-
return candidate.length > 60
|
|
70
|
-
? candidate.slice(0, 60).trim() + "…"
|
|
71
|
-
: candidate.trim();
|
|
72
|
-
}
|
|
73
|
-
|
|
74
64
|
/**
|
|
75
65
|
* Maximum character budget for identity context injected into the notification
|
|
76
66
|
* decision prompt. We truncate to prevent oversized prompts when SOUL.md /
|
|
@@ -768,24 +758,15 @@ export async function evaluateSignal(
|
|
|
768
758
|
// classifier entirely. The producer has already done the routing and
|
|
769
759
|
// copy decisions — we just enforce the standard post-decision guards
|
|
770
760
|
// and persist the result.
|
|
771
|
-
|
|
772
|
-
signal.
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
typeof (signal.contextPayload as Record<string, unknown>)
|
|
776
|
-
.requestedMessage === "string" &&
|
|
777
|
-
(
|
|
778
|
-
(signal.contextPayload as Record<string, unknown>)
|
|
779
|
-
.requestedMessage as string
|
|
780
|
-
).trim().length > 0
|
|
781
|
-
) {
|
|
761
|
+
const requestedBody = nonEmpty(
|
|
762
|
+
readPayloadString(signal.contextPayload, "requestedMessage"),
|
|
763
|
+
);
|
|
764
|
+
if (signal.sourceChannel === "assistant_tool" && requestedBody) {
|
|
782
765
|
const payload = signal.contextPayload as Record<string, unknown>;
|
|
783
|
-
const body =
|
|
766
|
+
const body = requestedBody;
|
|
784
767
|
const title =
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
? (payload.requestedTitle as string).trim()
|
|
788
|
-
: deriveTitle(body);
|
|
768
|
+
nonEmpty(readPayloadString(signal.contextPayload, "requestedTitle")) ??
|
|
769
|
+
deriveTitle(body);
|
|
789
770
|
const isUrgent =
|
|
790
771
|
signal.attentionHints.urgency === "critical" ||
|
|
791
772
|
signal.attentionHints.urgency === "high";
|
|
@@ -22,6 +22,7 @@ import { getConversation } from "../memory/conversation-crud.js";
|
|
|
22
22
|
import { isBackgroundConversationType } from "../memory/conversation-types.js";
|
|
23
23
|
import { getLogger } from "../util/logger.js";
|
|
24
24
|
import { isConversationSeedSane } from "./conversation-seed-composer.js";
|
|
25
|
+
import { readPayloadString } from "./copy-composer.js";
|
|
25
26
|
import type { NotificationSignal } from "./signal.js";
|
|
26
27
|
import type { NotificationDecision, RenderedChannelCopy } from "./types.js";
|
|
27
28
|
|
|
@@ -231,12 +232,6 @@ function resolveHomeFeedMirror(
|
|
|
231
232
|
return { mirror: false };
|
|
232
233
|
}
|
|
233
234
|
|
|
234
|
-
function readPayloadString(payload: unknown, key: string): string | undefined {
|
|
235
|
-
if (!payload || typeof payload !== "object") return undefined;
|
|
236
|
-
const value = (payload as Record<string, unknown>)[key];
|
|
237
|
-
return typeof value === "string" ? value : undefined;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
235
|
/**
|
|
241
236
|
* Routing-intent enforcement can prune `selectedChannels` without also
|
|
242
237
|
* pruning `renderedCopy`, so iterating `renderedCopy` directly risks
|
package/src/platform/client.ts
CHANGED
|
@@ -45,9 +45,7 @@ export class VellumPlatformClient {
|
|
|
45
45
|
*/
|
|
46
46
|
static async create(): Promise<VellumPlatformClient | null> {
|
|
47
47
|
if (!arePlatformFeaturesEnabled()) {
|
|
48
|
-
log.debug(
|
|
49
|
-
"platform-features-in-local-mode is disabled — returning null",
|
|
50
|
-
);
|
|
48
|
+
log.debug("platform features disabled — returning null");
|
|
51
49
|
return null;
|
|
52
50
|
}
|
|
53
51
|
|
|
@@ -1,15 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { getIsPlatform } from "../config/env-registry.js";
|
|
3
|
-
import type { AssistantConfig } from "../config/schema.js";
|
|
1
|
+
import { getDisablePlatform, getIsPlatform } from "../config/env-registry.js";
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export function arePlatformFeaturesEnabled(
|
|
8
|
-
config?: AssistantConfig,
|
|
9
|
-
): boolean {
|
|
3
|
+
export function arePlatformFeaturesEnabled(): boolean {
|
|
10
4
|
if (getIsPlatform()) return true;
|
|
11
|
-
return
|
|
12
|
-
FLAG_KEY,
|
|
13
|
-
(config ?? {}) as AssistantConfig,
|
|
14
|
-
);
|
|
5
|
+
return !getDisablePlatform();
|
|
15
6
|
}
|
|
@@ -28,6 +28,8 @@ export const HOOKS = {
|
|
|
28
28
|
STOP: "stop",
|
|
29
29
|
/** Fires for each finalized assistant message, once per model call, before it is persisted/streamed-final. A hook may transform the message content. */
|
|
30
30
|
POST_MODEL_CALL: "post-model-call",
|
|
31
|
+
/** Fires after the loop successfully compacts a conversation mid-turn. */
|
|
32
|
+
POST_COMPACT: "post-compact",
|
|
31
33
|
} as const;
|
|
32
34
|
|
|
33
35
|
/** Union of every hook name declared in {@link HOOKS}. */
|
package/src/plugin-api/index.ts
CHANGED
|
@@ -11,19 +11,34 @@
|
|
|
11
11
|
*
|
|
12
12
|
* ## Surface today
|
|
13
13
|
*
|
|
14
|
-
* The
|
|
15
|
-
*
|
|
16
|
-
* `
|
|
17
|
-
*
|
|
18
|
-
* runtime — plugin authors never call a runtime registration function.
|
|
14
|
+
* The primary authoring model is **declarative**: a plugin is a directory
|
|
15
|
+
* whose `package.json` is the manifest and whose `hooks/` / `tools/` /
|
|
16
|
+
* `skills/` / `routes/` subdirectories are the contributions. The host
|
|
17
|
+
* introspects the directory at load time and wires it into the runtime.
|
|
19
18
|
*
|
|
20
|
-
*
|
|
19
|
+
* Most of what this module exposes is therefore types: the context shapes
|
|
21
20
|
* the host hands to plugin hooks, and the logger shape they include.
|
|
22
21
|
*
|
|
22
|
+
* Alongside those types, the module exposes a small set of **runtime
|
|
23
|
+
* handles** for plugins that need to reach the assistant's live singletons
|
|
24
|
+
* (subscribe to runtime events, read secrets). These resolve to the
|
|
25
|
+
* assistant's own instances: the host parks the loaded plugin-api namespace
|
|
26
|
+
* on `globalThis` at boot, and the workspace-level shim re-binds each
|
|
27
|
+
* runtime export from there — so a plugin's
|
|
28
|
+
* `import { assistantEventHub } from "@vellumai/plugin-api"` lands on the
|
|
29
|
+
* same singleton the assistant uses, even when the daemon is a
|
|
30
|
+
* `bun --compile` binary where an absolute-path import would load a
|
|
31
|
+
* disjoint module copy.
|
|
32
|
+
*
|
|
33
|
+
* - {@link assistantEventHub} — the assistant's pub/sub hub for runtime events
|
|
34
|
+
* - {@link getSecureKeyAsync} — read a secret from secure storage
|
|
35
|
+
*
|
|
23
36
|
* - {@link PluginInitContext} — passed to `init` hook at bootstrap
|
|
24
37
|
* - {@link PluginShutdownContext} — passed to `shutdown` hook at teardown
|
|
25
38
|
* - {@link UserPromptSubmitContext} — passed to `user-prompt-submit` hook,
|
|
26
39
|
* fired immediately before the agent loop receives a user's prompt
|
|
40
|
+
* - {@link PostCompactContext} — passed to `post-compact` hook, fired after
|
|
41
|
+
* the agent loop compacts a conversation mid-turn to re-apply injections
|
|
27
42
|
* - {@link PreModelCallContext} — passed to `pre-model-call` hook, fired
|
|
28
43
|
* before each provider call to edit the request / defer output streaming
|
|
29
44
|
* - {@link PostToolUseContext} — passed to `post-tool-use` hook, fired once
|
|
@@ -47,6 +62,7 @@ export type {
|
|
|
47
62
|
PluginInitContext,
|
|
48
63
|
PluginLogger,
|
|
49
64
|
PluginShutdownContext,
|
|
65
|
+
PostCompactContext,
|
|
50
66
|
PostModelCallContext,
|
|
51
67
|
PostToolUseContext,
|
|
52
68
|
PreModelCallContext,
|
|
@@ -58,3 +74,18 @@ export type {
|
|
|
58
74
|
UserPromptSubmitContext,
|
|
59
75
|
} from "./types.js";
|
|
60
76
|
export { RiskLevel } from "./types.js";
|
|
77
|
+
|
|
78
|
+
// ─── Runtime handles ─────────────────────────────────────────────────────────
|
|
79
|
+
// Values (not just types) that plugins consume at module-load / init time.
|
|
80
|
+
// Workspace-local plugins resolve these via the boot-time shim, which
|
|
81
|
+
// re-binds each from the assistant's globalThis-parked namespace so they
|
|
82
|
+
// share module identity with the assistant's own singletons.
|
|
83
|
+
export type { AssistantEvent } from "../runtime/assistant-event.js";
|
|
84
|
+
export type {
|
|
85
|
+
AssistantEventCallback,
|
|
86
|
+
AssistantEventFilter,
|
|
87
|
+
AssistantEventHub,
|
|
88
|
+
AssistantEventSubscription,
|
|
89
|
+
} from "../runtime/assistant-event-hub.js";
|
|
90
|
+
export { assistantEventHub } from "../runtime/assistant-event-hub.js";
|
|
91
|
+
export { getSecureKeyAsync } from "../security/secure-keys.js";
|
package/src/plugin-api/types.ts
CHANGED
|
@@ -144,6 +144,25 @@ export interface UserPromptSubmitContext {
|
|
|
144
144
|
* for the turn and cannot be recovered from the message arrays.
|
|
145
145
|
*/
|
|
146
146
|
readonly requestId: string;
|
|
147
|
+
/**
|
|
148
|
+
* Active inference profile key to surface in this turn's context, or `null`
|
|
149
|
+
* when the profile is unchanged since the one last announced to the model.
|
|
150
|
+
* Hooks that emit the `model_profile` grounding line resolve the
|
|
151
|
+
* human-readable label (and model id) from this key via the workspace LLM
|
|
152
|
+
* config rather than receiving the rendered string — the key is the minimal
|
|
153
|
+
* turn input the message arrays cannot carry.
|
|
154
|
+
*/
|
|
155
|
+
readonly modelProfileKey: string | null;
|
|
156
|
+
/**
|
|
157
|
+
* Whether the turn has no human present to answer clarification questions
|
|
158
|
+
* (e.g. a scheduled, background, or headless run). Resolved once at turn
|
|
159
|
+
* start from the run's interactivity option, falling back to live client
|
|
160
|
+
* presence — a single value the hook reads rather than re-deriving from
|
|
161
|
+
* mutable conversation state that can flip mid-turn. Hooks that assemble the
|
|
162
|
+
* turn's runtime injections forward it so the assembled context reflects the
|
|
163
|
+
* turn's interactivity.
|
|
164
|
+
*/
|
|
165
|
+
readonly isNonInteractive: boolean;
|
|
147
166
|
/**
|
|
148
167
|
* The text of the user prompt that triggered this turn — the resolved
|
|
149
168
|
* user message (after slash-command expansion), independent of any
|
|
@@ -172,6 +191,62 @@ export interface UserPromptSubmitContext {
|
|
|
172
191
|
readonly logger: PluginLogger;
|
|
173
192
|
}
|
|
174
193
|
|
|
194
|
+
// ─── Post-compact hook context ───────────────────────────────────────────────
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Context passed to the `post-compact` hook. Fires after the agent loop
|
|
198
|
+
* compacts a conversation mid-turn — once the running history has been
|
|
199
|
+
* summarized down to fit the context window, and before the turn resumes.
|
|
200
|
+
*
|
|
201
|
+
* Compaction strips the turn's runtime injections (scratchpad, retrieved
|
|
202
|
+
* memory, workspace context, transcript snapshots) along with the raw messages
|
|
203
|
+
* it summarizes. This hook's job is to re-apply whatever injected context must
|
|
204
|
+
* survive onto the freshly compacted history before the next provider call.
|
|
205
|
+
* The default memory-retrieval plugin contributes a hook here that re-injects
|
|
206
|
+
* its memory blocks and re-tracks the memory graph; user hooks can re-apply
|
|
207
|
+
* their own injected context the same way.
|
|
208
|
+
*
|
|
209
|
+
* The hook re-injects by mutating `history` in place (or returning a new
|
|
210
|
+
* context with a replacement `history`) — see {@link PluginHookFn}'s
|
|
211
|
+
* polymorphic return shape. The agent loop reads the settled `history` back off
|
|
212
|
+
* the context and resumes the turn from it. Multiple plugins' hooks chain in
|
|
213
|
+
* registration order, each seeing the previous plugin's edits.
|
|
214
|
+
*/
|
|
215
|
+
export interface PostCompactContext {
|
|
216
|
+
/**
|
|
217
|
+
* The compacted message history to re-inject onto. Hooks mutate this in
|
|
218
|
+
* place (or return a new context with a replacement) to re-apply context
|
|
219
|
+
* that compaction stripped; the loop resumes the turn from the settled
|
|
220
|
+
* value.
|
|
221
|
+
*/
|
|
222
|
+
history: Message[];
|
|
223
|
+
/**
|
|
224
|
+
* Stable ID for the request that drives this turn. Hooks that perform
|
|
225
|
+
* runtime injection forward it onto the injector turn context so the
|
|
226
|
+
* re-applied blocks are attributed to the originating request; it is fixed
|
|
227
|
+
* for the turn and cannot be recovered from the message history.
|
|
228
|
+
*/
|
|
229
|
+
readonly requestId: string | undefined;
|
|
230
|
+
/** Conversation ID the turn being compacted is scoped to. */
|
|
231
|
+
readonly conversationId: string;
|
|
232
|
+
/**
|
|
233
|
+
* Whether the turn has no human present to answer clarification questions
|
|
234
|
+
* (e.g. a scheduled, background, or headless run). Mirrors the field of the
|
|
235
|
+
* same name on {@link UserPromptSubmitContext}: resolved once at turn start
|
|
236
|
+
* so re-injection reflects the turn's interactivity rather than mutable
|
|
237
|
+
* client-presence state that can flip mid-turn.
|
|
238
|
+
*/
|
|
239
|
+
readonly isNonInteractive: boolean;
|
|
240
|
+
/**
|
|
241
|
+
* Active inference profile key to surface in the re-injected context, or
|
|
242
|
+
* `null` when the profile is unchanged since the one last announced to the
|
|
243
|
+
* model. Mirrors {@link UserPromptSubmitContext.modelProfileKey}: hooks that
|
|
244
|
+
* emit the `model_profile` grounding line resolve the human-readable label
|
|
245
|
+
* from this key rather than receiving the rendered string.
|
|
246
|
+
*/
|
|
247
|
+
readonly modelProfileKey: string | null;
|
|
248
|
+
}
|
|
249
|
+
|
|
175
250
|
// ─── Post-tool-use hook context ──────────────────────────────────────────────
|
|
176
251
|
|
|
177
252
|
/**
|