@vellumai/assistant 0.12.1-dev.202609141913.5e16607 → 0.12.1-dev.202609142113.d1590bc
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/ARCHITECTURE.md +9 -9
- package/openapi.yaml +35 -2
- package/package.json +2 -1
- package/src/__tests__/anthropic-provider.test.ts +0 -63
- package/src/__tests__/assistant-event-hub-machine-name.test.ts +6 -7
- package/src/__tests__/assistant-event-hub.test.ts +44 -0
- package/src/__tests__/computer-use-skill-manifest-regression.test.ts +1 -1
- package/src/__tests__/computer-use-tools.test.ts +2 -2
- package/src/__tests__/heartbeat-service.test.ts +56 -40
- package/src/__tests__/host-cu-proxy.test.ts +539 -0
- package/src/__tests__/list-messages-camera-frame.test.ts +121 -0
- package/src/__tests__/oauth-commands-routes.test.ts +113 -0
- package/src/__tests__/oauth-provider-profiles.test.ts +18 -0
- package/src/__tests__/openai-provider.test.ts +1 -0
- package/src/__tests__/plugin-import-boundary-guard.test.ts +1 -0
- package/src/__tests__/qdrant-manager.test.ts +132 -0
- package/src/__tests__/scaffold-managed-skill-tool.test.ts +229 -6
- package/src/__tests__/skills.test.ts +9 -4
- package/src/__tests__/test-support/computer-use-skill-harness.ts +3 -2
- package/src/__tests__/unicode.test.ts +13 -0
- package/src/acp/agent-process.ts +2 -1
- package/src/agent/loop.ts +1 -0
- package/src/api/events/user-message-echo.ts +7 -1
- package/src/api/responses/conversation-message.ts +5 -0
- package/src/avatar/identity-avatar.ts +7 -2
- package/src/config/bundled-skills/computer-use/SKILL.md +20 -2
- package/src/config/bundled-skills/computer-use/TOOLS.json +99 -0
- package/src/config/bundled-skills/computer-use/tools/computer-use-sequence.ts +12 -0
- package/src/config/bundled-skills/media-processing/services/preprocess.ts +2 -1
- package/src/config/bundled-skills/media-processing/services/processing-pipeline.ts +2 -1
- package/src/config/bundled-skills/media-processing/tools/generate-clip.ts +2 -1
- package/src/config/bundled-skills/playbooks/tools/playbook-create.ts +2 -1
- package/src/config/bundled-skills/playbooks/tools/playbook-update.ts +2 -1
- package/src/config/bundled-skills/skill-management/TOOLS.json +4 -0
- package/src/config/bundled-skills/transcribe/tools/transcribe-media.ts +5 -2
- package/src/credential-health/credential-health-service.ts +11 -17
- package/src/daemon/conversation-error.ts +3 -2
- package/src/daemon/conversation-media-retry.ts +2 -1
- package/src/daemon/conversation-runtime-assembly.ts +2 -1
- package/src/daemon/conversation-surfaces.ts +5 -1
- package/src/daemon/dictation-profile-store.ts +2 -1
- package/src/daemon/handlers/shared.ts +2 -1
- package/src/daemon/handlers/skills.ts +6 -3
- package/src/daemon/host-cu-proxy.ts +186 -19
- package/src/daemon/host-proxy-preactivation.ts +2 -1
- package/src/daemon/reaction-history-render.ts +2 -1
- package/src/heartbeat/heartbeat-service.ts +21 -3
- package/src/live-voice/__tests__/live-voice-sight-frame-echo.test.ts +238 -0
- package/src/live-voice/live-voice-photo.ts +25 -6
- package/src/oauth/AGENTS.md +2 -0
- package/src/oauth/byo-connection.test.ts +60 -0
- package/src/oauth/scope-utils.ts +24 -0
- package/src/oauth/seed-providers.ts +39 -25
- package/src/persistence/conversation-queries.ts +2 -2
- package/src/persistence/embeddings/qdrant-manager.ts +163 -18
- package/src/plugins/defaults/memory/__tests__/memory-retrospective-prompt.test.ts +5 -0
- package/src/plugins/defaults/memory/context-search/agent-runner.ts +3 -2
- package/src/plugins/defaults/memory/context-search/format.ts +3 -2
- package/src/plugins/defaults/memory/context-search/sources/memory-v2.ts +6 -3
- package/src/plugins/defaults/memory/context-search/sources/workspace.ts +3 -2
- package/src/plugins/defaults/memory/graph/capability-seed.ts +2 -1
- package/src/plugins/defaults/memory/host-utils.ts +10 -0
- package/src/plugins/defaults/memory/memory-retrospective-prompt.ts +1 -1
- package/src/plugins/defaults/memory/startup.ts +22 -1
- package/src/plugins/defaults/memory/substrate/page-index.ts +6 -1
- package/src/plugins/defaults/memory/v1/graph/consolidation.ts +4 -2
- package/src/plugins/defaults/memory/v1/graph/extraction.ts +4 -2
- package/src/plugins/defaults/memory/v1/graph/retriever.ts +4 -1
- package/src/plugins/defaults/memory/v2/reranker.ts +6 -1
- package/src/plugins/defaults/memory/v3/__tests__/card.test.ts +24 -0
- package/src/plugins/defaults/memory/v3/__tests__/pool-select.test.ts +39 -3
- package/src/plugins/defaults/memory/v3/__tests__/sections.test.ts +26 -0
- package/src/plugins/defaults/memory/v3/__tests__/shadow-plugin.test.ts +30 -0
- package/src/plugins/defaults/memory/v3/card.ts +3 -2
- package/src/plugins/defaults/memory/v3/pool-select.ts +5 -3
- package/src/plugins/defaults/memory/v3/sections.ts +9 -3
- package/src/plugins/defaults/memory/v3/shadow-plugin.ts +5 -2
- package/src/providers/__tests__/retry-outbound-sanitize.test.ts +176 -0
- package/src/providers/anthropic/client.ts +0 -47
- package/src/providers/openai/__tests__/chat-completions-output-token-limit.test.ts +141 -0
- package/src/providers/openai/chat-completions-provider.ts +20 -1
- package/src/providers/openrouter/client.ts +20 -0
- package/src/providers/outbound-request-sanitize.ts +96 -0
- package/src/providers/retry.ts +24 -3
- package/src/providers/unparseable-tool-args.ts +5 -1
- package/src/runtime/AGENTS.md +1 -1
- package/src/runtime/__tests__/host-observe.test.ts +40 -1
- package/src/runtime/agent-wake.ts +2 -1
- package/src/runtime/assistant-event-hub.ts +21 -3
- package/src/runtime/host-observe.ts +11 -1
- package/src/runtime/routes/conversation-routes.ts +16 -3
- package/src/runtime/routes/diagnostics-routes.ts +6 -1
- package/src/runtime/routes/events-routes.ts +4 -0
- package/src/runtime/routes/host-cu-routes.ts +6 -0
- package/src/runtime/routes/oauth-commands-routes.ts +36 -0
- package/src/runtime/routes/workspace-routes.test.ts +55 -26
- package/src/runtime/routes/workspace-routes.ts +46 -63
- package/src/runtime/routes/workspace-tree-walk.test.ts +244 -0
- package/src/runtime/routes/workspace-tree-walk.ts +240 -0
- package/src/runtime/routes/workspace-utils.ts +17 -0
- package/src/schedule/run-script.ts +2 -1
- package/src/schedule/schedule-store.ts +9 -2
- package/src/security/untrusted-content.ts +3 -1
- package/src/tools/__tests__/side-effect-abort-guard.test.ts +1 -0
- package/src/tools/browser/browser-execution.ts +1 -1
- package/src/tools/browser/cdp-client/accessibility-snapshot.ts +9 -3
- package/src/tools/browser/cdp-client/cdp-inspect/discovery.ts +2 -1
- package/src/tools/browser/cdp-client/extension-cdp-client.ts +3 -2
- package/src/tools/browser/network-recorder.ts +2 -1
- package/src/tools/computer-use/definitions.ts +117 -0
- package/src/tools/filesystem/search.ts +2 -1
- package/src/tools/network/web-search.ts +6 -1
- package/src/tools/skills/scaffold-managed.ts +61 -3
- package/src/types/host-capabilities.ts +5 -3
- package/src/util/unicode.ts +15 -1
- package/src/watch/watch-timeline.ts +2 -2
- package/src/workflows/run-manager.ts +2 -1
- package/src/workspace/git-service.ts +1 -1
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
* 3. `executionError` from the client surfaces as a structured failure.
|
|
10
10
|
* 4. The pending interaction is unregistered on every path.
|
|
11
11
|
* 5. No capable client connected: failure rather than a throw.
|
|
12
|
-
* 6. `includeScreenshot: false` drops the screenshot from the result
|
|
12
|
+
* 6. `includeScreenshot: false` drops the screenshot from the result, and
|
|
13
|
+
* is sent to the helper only for an unscoped observation.
|
|
13
14
|
* 7. Actor binding: another user's client is never selected by default, an
|
|
14
15
|
* explicit clientId owned by another user is rejected, a caller with no
|
|
15
16
|
* actor principal reaches nothing, and two same-user clients are
|
|
@@ -226,6 +227,44 @@ describe("observeHostScreen", () => {
|
|
|
226
227
|
expect(pendingInteractions.getAll()).toHaveLength(0);
|
|
227
228
|
});
|
|
228
229
|
|
|
230
|
+
test("tells the helper when no screenshot is wanted on an unscoped observation, and only then", async () => {
|
|
231
|
+
const skipped = observe({ includeScreenshot: false });
|
|
232
|
+
const skippedRequest = sentMessages.find(
|
|
233
|
+
(m) => m.type === "host_cu_request",
|
|
234
|
+
);
|
|
235
|
+
expect(skippedRequest?.input).toEqual({ includeScreenshot: false });
|
|
236
|
+
await postResult({ requestId: sentRequestId(), axTree: "Window [1]" });
|
|
237
|
+
await skipped;
|
|
238
|
+
|
|
239
|
+
sentMessages.length = 0;
|
|
240
|
+
const wanted = observe();
|
|
241
|
+
const wantedRequest = sentMessages.find(
|
|
242
|
+
(m) => m.type === "host_cu_request",
|
|
243
|
+
);
|
|
244
|
+
expect(wantedRequest?.input).toEqual({});
|
|
245
|
+
await postResult({ requestId: sentRequestId(), axTree: "Window [1]" });
|
|
246
|
+
await wanted;
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
test("a scoped observation sends no opt-out and still drops the screenshot", async () => {
|
|
250
|
+
const observation = observe({
|
|
251
|
+
includeScreenshot: false,
|
|
252
|
+
captureTarget: { kind: "window", windowId: 4211 },
|
|
253
|
+
});
|
|
254
|
+
const request = sentMessages.find((m) => m.type === "host_cu_request");
|
|
255
|
+
expect(request?.input).toEqual({ captureWindowId: 4211 });
|
|
256
|
+
|
|
257
|
+
await postResult({
|
|
258
|
+
requestId: sentRequestId(),
|
|
259
|
+
axTree: "Window [1]",
|
|
260
|
+
screenshot: "base64png",
|
|
261
|
+
screenshotWidthPx: 1200,
|
|
262
|
+
screenshotHeightPx: 800,
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
expect(await observation).toEqual({ ok: true, axTree: "Window [1]" });
|
|
266
|
+
});
|
|
267
|
+
|
|
229
268
|
test("drops the screenshot when includeScreenshot is false", async () => {
|
|
230
269
|
const observation = observe({ includeScreenshot: false });
|
|
231
270
|
await postResult({
|
|
@@ -126,6 +126,7 @@ import {
|
|
|
126
126
|
import type { CompletedBackgroundTool } from "../tools/background-tool-registry.js";
|
|
127
127
|
import { getLogger } from "../util/logger.js";
|
|
128
128
|
import { createKeyedSingleFlight } from "../util/single-flight.js";
|
|
129
|
+
import { safeStringSlice } from "../util/unicode.js";
|
|
129
130
|
|
|
130
131
|
const log = getLogger("agent-wake");
|
|
131
132
|
|
|
@@ -139,7 +140,7 @@ const WAKE_POSTAMBLE =
|
|
|
139
140
|
|
|
140
141
|
/** Sanitize a value for use as an XML attribute (no quotes/brackets/newlines). */
|
|
141
142
|
function sanitizeEventAttr(value: string): string {
|
|
142
|
-
return value.replace(/[<>"&\r\n]/g, "")
|
|
143
|
+
return safeStringSlice(value.replace(/[<>"&\r\n]/g, ""), 0, 200);
|
|
143
144
|
}
|
|
144
145
|
|
|
145
146
|
/**
|
|
@@ -745,9 +745,8 @@ export function broadcastMessage(
|
|
|
745
745
|
// A reconnect can overlap an older executor with the same device ID.
|
|
746
746
|
// Filter at delivery too, not only when HostCuProxy resolves its target.
|
|
747
747
|
const targetCapability =
|
|
748
|
-
msg.type === "host_cu_request"
|
|
749
|
-
|
|
750
|
-
? "host_cu_window_capture"
|
|
748
|
+
msg.type === "host_cu_request"
|
|
749
|
+
? hostCuRequestCapability(msg.toolName, msg.input)
|
|
751
750
|
: capabilityForMessageType(msg.type);
|
|
752
751
|
// Self-echo suppression: a `sync_changed` carrying an `originClientId`
|
|
753
752
|
// means a specific client just mutated the resource. The hub must not
|
|
@@ -782,6 +781,25 @@ export function broadcastMessage(
|
|
|
782
781
|
});
|
|
783
782
|
}
|
|
784
783
|
|
|
784
|
+
/**
|
|
785
|
+
* The capability a `host_cu_request` needs from the client that receives it.
|
|
786
|
+
* Window-scoped observation and batched actions are answered only by a helper
|
|
787
|
+
* that claimed them; an older helper would capture the whole desktop or end
|
|
788
|
+
* the session on the unknown tool.
|
|
789
|
+
*/
|
|
790
|
+
function hostCuRequestCapability(
|
|
791
|
+
toolName: string,
|
|
792
|
+
input: Record<string, unknown>,
|
|
793
|
+
): HostProxyCapability {
|
|
794
|
+
if (Object.hasOwn(input, "capture_window_id")) {
|
|
795
|
+
return "host_cu_window_capture";
|
|
796
|
+
}
|
|
797
|
+
if (toolName === "computer_use_sequence") {
|
|
798
|
+
return "host_cu_sequence";
|
|
799
|
+
}
|
|
800
|
+
return "host_cu";
|
|
801
|
+
}
|
|
802
|
+
|
|
785
803
|
function extractConversationId(msg: AssistantEvent): string | undefined {
|
|
786
804
|
const record = msg as unknown as Record<string, unknown>;
|
|
787
805
|
if ("conversationId" in msg && typeof record.conversationId === "string") {
|
|
@@ -257,7 +257,17 @@ export async function observeHostScreen(
|
|
|
257
257
|
// conversation is attached.
|
|
258
258
|
conversationId: options.stateKey ?? "",
|
|
259
259
|
toolName: "computer_use_observe",
|
|
260
|
-
|
|
260
|
+
// An unscoped request tells the helper up front when no
|
|
261
|
+
// screenshot is wanted, so it can skip capturing and uploading
|
|
262
|
+
// one. The helper always captures a scoped observation, so the
|
|
263
|
+
// flag is not sent there. The strip below removes the picture in
|
|
264
|
+
// both cases.
|
|
265
|
+
input: {
|
|
266
|
+
...captureTargetInput(options.captureTarget),
|
|
267
|
+
...(includeScreenshot || options.captureTarget !== undefined
|
|
268
|
+
? {}
|
|
269
|
+
: { includeScreenshot: false }),
|
|
270
|
+
},
|
|
261
271
|
stepNumber: 1,
|
|
262
272
|
},
|
|
263
273
|
undefined,
|
|
@@ -140,7 +140,10 @@ import {
|
|
|
140
140
|
getOrCreateConversation,
|
|
141
141
|
} from "../../persistence/conversation-key-store.js";
|
|
142
142
|
import { searchConversations } from "../../persistence/conversation-queries.js";
|
|
143
|
-
import {
|
|
143
|
+
import {
|
|
144
|
+
isNoResponseMetadata,
|
|
145
|
+
messageMetadataIsAmbientSightKeep,
|
|
146
|
+
} from "../../persistence/conversation-types.js";
|
|
144
147
|
import { linkRequestLogsToMessage } from "../../persistence/llm-request-log-store.js";
|
|
145
148
|
import { assistantTextVisibilityOf } from "../../persistence/user-facing-content.js";
|
|
146
149
|
import { MEMORY_RETROSPECTIVE_FORK_SOURCE } from "../../plugins/defaults/memory/memory-retrospective-constants.js";
|
|
@@ -159,6 +162,7 @@ import {
|
|
|
159
162
|
getWorkspaceDir,
|
|
160
163
|
getWorkspacePromptPath,
|
|
161
164
|
} from "../../util/platform.js";
|
|
165
|
+
import { safeStringSlice } from "../../util/unicode.js";
|
|
162
166
|
import { assistantEventHub, broadcastMessage } from "../assistant-event-hub.js";
|
|
163
167
|
import { getCurrentSeq } from "../assistant-stream-state.js";
|
|
164
168
|
import { ACTOR_PRINCIPALS } from "../auth/route-policy.js";
|
|
@@ -1037,6 +1041,9 @@ export async function handleListMessages({
|
|
|
1037
1041
|
let backgroundToolCompletion: ConversationMessage["backgroundToolCompletion"];
|
|
1038
1042
|
let systemCard: boolean | undefined;
|
|
1039
1043
|
let noResponse: boolean | undefined;
|
|
1044
|
+
const cameraFrame = messageMetadataIsAmbientSightKeep(msg.metadata)
|
|
1045
|
+
? true
|
|
1046
|
+
: undefined;
|
|
1040
1047
|
let reaction: ConversationMessage["reaction"];
|
|
1041
1048
|
let providerError: ConversationMessage["providerError"];
|
|
1042
1049
|
let deletedAt: number | undefined;
|
|
@@ -1136,6 +1143,7 @@ export async function handleListMessages({
|
|
|
1136
1143
|
backgroundToolCompletion,
|
|
1137
1144
|
systemCard,
|
|
1138
1145
|
noResponse,
|
|
1146
|
+
cameraFrame,
|
|
1139
1147
|
reaction,
|
|
1140
1148
|
providerError,
|
|
1141
1149
|
slackMessage,
|
|
@@ -1353,6 +1361,7 @@ export async function handleListMessages({
|
|
|
1353
1361
|
: {}),
|
|
1354
1362
|
...(m.systemCard ? { systemCard: true } : {}),
|
|
1355
1363
|
...(m.noResponse ? { noResponse: true } : {}),
|
|
1364
|
+
...(m.cameraFrame ? { cameraFrame: true as const } : {}),
|
|
1356
1365
|
// The row's own marker, so a client gates per-row presentation on what
|
|
1357
1366
|
// this row was written with rather than on the live flag.
|
|
1358
1367
|
...(m.assistantTextVisibility
|
|
@@ -3289,11 +3298,15 @@ async function generateLlmSuggestion(
|
|
|
3289
3298
|
): Promise<string | null> {
|
|
3290
3299
|
const log = (await import("../../util/logger.js")).getLogger("runtime-http");
|
|
3291
3300
|
const truncatedAssistant = escapeXmlContent(
|
|
3292
|
-
assistantText.length > 2000
|
|
3301
|
+
assistantText.length > 2000
|
|
3302
|
+
? safeStringSlice(assistantText, assistantText.length - 2000)
|
|
3303
|
+
: assistantText,
|
|
3293
3304
|
);
|
|
3294
3305
|
const truncatedUser =
|
|
3295
3306
|
priorUserText && priorUserText.length > 500
|
|
3296
|
-
? escapeXmlContent(
|
|
3307
|
+
? escapeXmlContent(
|
|
3308
|
+
safeStringSlice(priorUserText, priorUserText.length - 500),
|
|
3309
|
+
)
|
|
3297
3310
|
: priorUserText
|
|
3298
3311
|
? escapeXmlContent(priorUserText)
|
|
3299
3312
|
: priorUserText;
|
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
} from "../../providers/provider-send-message.js";
|
|
25
25
|
import { isMaxTokensStopReason } from "../../providers/stop-reasons.js";
|
|
26
26
|
import { getLogger } from "../../util/logger.js";
|
|
27
|
+
import { safeStringSlice } from "../../util/unicode.js";
|
|
27
28
|
import { ACTOR_PRINCIPALS } from "../auth/route-policy.js";
|
|
28
29
|
import { BadRequestError } from "./errors.js";
|
|
29
30
|
import type { RouteDefinition, RouteHandlerArgs } from "./types.js";
|
|
@@ -49,7 +50,11 @@ function sanitizeWindowTitle(title: string | undefined): string {
|
|
|
49
50
|
if (!title) {
|
|
50
51
|
return "";
|
|
51
52
|
}
|
|
52
|
-
return
|
|
53
|
+
return safeStringSlice(
|
|
54
|
+
title.replace(/[<>]/g, ""),
|
|
55
|
+
0,
|
|
56
|
+
MAX_WINDOW_TITLE_LENGTH,
|
|
57
|
+
);
|
|
53
58
|
}
|
|
54
59
|
|
|
55
60
|
interface DictationBody {
|
|
@@ -445,6 +445,10 @@ export function handleSubscribeAssistantEvents(
|
|
|
445
445
|
? ["host_cu_window_capture" as const]
|
|
446
446
|
: []),
|
|
447
447
|
...(interfaceId === "macos" &&
|
|
448
|
+
headers?.["x-vellum-cu-sequence"] === "1"
|
|
449
|
+
? ["host_cu_sequence" as const]
|
|
450
|
+
: []),
|
|
451
|
+
...(interfaceId === "macos" &&
|
|
448
452
|
headers?.["x-vellum-cu-annotate"] === "1"
|
|
449
453
|
? ["host_cu_annotate" as const]
|
|
450
454
|
: []),
|
|
@@ -36,6 +36,10 @@ const HostCuResultBodySchema = z.object({
|
|
|
36
36
|
executionError: z.string().optional(),
|
|
37
37
|
secondaryWindows: z.string().optional(),
|
|
38
38
|
userGuidance: z.string().optional(),
|
|
39
|
+
timings: z
|
|
40
|
+
.record(z.string(), z.number())
|
|
41
|
+
.describe("Per-phase helper timings in milliseconds")
|
|
42
|
+
.optional(),
|
|
39
43
|
});
|
|
40
44
|
|
|
41
45
|
// ---------------------------------------------------------------------------
|
|
@@ -56,6 +60,7 @@ async function handleHostCuResult({ body, headers }: RouteHandlerArgs) {
|
|
|
56
60
|
executionError,
|
|
57
61
|
secondaryWindows,
|
|
58
62
|
userGuidance,
|
|
63
|
+
timings,
|
|
59
64
|
} = parseBody(HostCuResultBodySchema, body);
|
|
60
65
|
|
|
61
66
|
const peeked = pendingInteractions.get(requestId);
|
|
@@ -119,6 +124,7 @@ async function handleHostCuResult({ body, headers }: RouteHandlerArgs) {
|
|
|
119
124
|
executionError,
|
|
120
125
|
secondaryWindows,
|
|
121
126
|
userGuidance,
|
|
127
|
+
timings,
|
|
122
128
|
});
|
|
123
129
|
|
|
124
130
|
return { accepted: true };
|
|
@@ -41,9 +41,11 @@ import {
|
|
|
41
41
|
listConnections,
|
|
42
42
|
type OAuthProviderRow,
|
|
43
43
|
} from "../../oauth/oauth-store.js";
|
|
44
|
+
import { missingScopesForStoredToken } from "../../oauth/scope-utils.js";
|
|
44
45
|
import { VellumPlatformClient } from "../../platform/client.js";
|
|
45
46
|
import { withValidToken } from "../../security/token-manager.js";
|
|
46
47
|
import { matchHostPattern } from "../../tools/credentials/host-pattern-match.js";
|
|
48
|
+
import { parseJsonSafe } from "../../util/json.js";
|
|
47
49
|
import { getLogger } from "../../util/logger.js";
|
|
48
50
|
import {
|
|
49
51
|
findContentTypeHeader,
|
|
@@ -230,6 +232,31 @@ function assertOAuthRequestUrlAllowed(
|
|
|
230
232
|
}
|
|
231
233
|
}
|
|
232
234
|
|
|
235
|
+
/**
|
|
236
|
+
* Required scopes the resolved connection's stored grant lacks. Credential
|
|
237
|
+
* health measures the same thing on the heartbeat; measuring it on the
|
|
238
|
+
* request names the gap at the moment a call may depend on it, since a
|
|
239
|
+
* connection made before a scope was required keeps working for every call
|
|
240
|
+
* that does not need it. A managed connection has no local row and reports
|
|
241
|
+
* nothing.
|
|
242
|
+
*/
|
|
243
|
+
function missingScopesForConnection(
|
|
244
|
+
providerRow: OAuthProviderRow,
|
|
245
|
+
connectionId: string,
|
|
246
|
+
): string[] {
|
|
247
|
+
const row = getConnection(connectionId);
|
|
248
|
+
if (!row) {
|
|
249
|
+
return [];
|
|
250
|
+
}
|
|
251
|
+
return missingScopesForStoredToken(
|
|
252
|
+
parseJsonSafe<string[]>(providerRow.defaultScopes ?? "[]") ?? [],
|
|
253
|
+
parseJsonSafe<Record<string, string>>(providerRow.authorizeParams ?? "") ??
|
|
254
|
+
undefined,
|
|
255
|
+
providerRow.scopeSeparator,
|
|
256
|
+
parseJsonSafe<string[]>(row.grantedScopes ?? "[]") ?? [],
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
|
|
233
260
|
// ---------------------------------------------------------------------------
|
|
234
261
|
// Disconnect handler
|
|
235
262
|
// ---------------------------------------------------------------------------
|
|
@@ -1002,6 +1029,15 @@ export async function handleRequest({ body = {} }: RouteHandlerArgs) {
|
|
|
1002
1029
|
`(e.g. https://host/full/path) so the host and full path are set explicitly.`;
|
|
1003
1030
|
}
|
|
1004
1031
|
|
|
1032
|
+
const missingScopes = missingScopesForConnection(providerRow, connection.id);
|
|
1033
|
+
if (missingScopes.length > 0) {
|
|
1034
|
+
const scopeHint =
|
|
1035
|
+
`The ${b.provider} connection is missing required scopes: ${missingScopes.join(", ")}. ` +
|
|
1036
|
+
`It was connected before they were required, so calls that need them fail. ` +
|
|
1037
|
+
`Reconnect it from Integrations, or run 'assistant oauth connect ${b.provider}', to grant them.`;
|
|
1038
|
+
result.hint = result.hint ? `${scopeHint}\n\n${result.hint}` : scopeHint;
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1005
1041
|
return result;
|
|
1006
1042
|
}
|
|
1007
1043
|
|
|
@@ -211,8 +211,8 @@ describe("isTextMimeType", () => {
|
|
|
211
211
|
describe("GET /v1/workspace/tree", () => {
|
|
212
212
|
const { handler } = getRoute("workspace_tree");
|
|
213
213
|
|
|
214
|
-
test("root listing returns entries", () => {
|
|
215
|
-
const result = handler({ queryParams: {} }) as {
|
|
214
|
+
test("root listing returns entries", async () => {
|
|
215
|
+
const result = (await handler({ queryParams: {} })) as {
|
|
216
216
|
path: string;
|
|
217
217
|
entries: Array<{ name: string; type: string }>;
|
|
218
218
|
};
|
|
@@ -222,8 +222,8 @@ describe("GET /v1/workspace/tree", () => {
|
|
|
222
222
|
expect(names).toContain("subdir");
|
|
223
223
|
});
|
|
224
224
|
|
|
225
|
-
test("subdirectory listing returns child entries", () => {
|
|
226
|
-
const result = handler({ queryParams: { path: "subdir" } }) as {
|
|
225
|
+
test("subdirectory listing returns child entries", async () => {
|
|
226
|
+
const result = (await handler({ queryParams: { path: "subdir" } })) as {
|
|
227
227
|
path: string;
|
|
228
228
|
entries: Array<{ name: string; type: string }>;
|
|
229
229
|
};
|
|
@@ -232,20 +232,20 @@ describe("GET /v1/workspace/tree", () => {
|
|
|
232
232
|
expect(result.entries[0].type).toBe("file");
|
|
233
233
|
});
|
|
234
234
|
|
|
235
|
-
test("non-existent directory throws NotFoundError", () => {
|
|
236
|
-
expect(
|
|
235
|
+
test("non-existent directory throws NotFoundError", async () => {
|
|
236
|
+
await expect(handler({ queryParams: { path: "nope" } })).rejects.toThrow(
|
|
237
237
|
NotFoundError,
|
|
238
238
|
);
|
|
239
239
|
});
|
|
240
240
|
|
|
241
|
-
test("path traversal attempt throws BadRequestError", () => {
|
|
242
|
-
expect(
|
|
243
|
-
|
|
244
|
-
);
|
|
241
|
+
test("path traversal attempt throws BadRequestError", async () => {
|
|
242
|
+
await expect(
|
|
243
|
+
handler({ queryParams: { path: "../../etc" } }),
|
|
244
|
+
).rejects.toThrow(BadRequestError);
|
|
245
245
|
});
|
|
246
246
|
|
|
247
|
-
test("entries have correct type field", () => {
|
|
248
|
-
const result = handler({ queryParams: {} }) as {
|
|
247
|
+
test("entries have correct type field", async () => {
|
|
248
|
+
const result = (await handler({ queryParams: {} })) as {
|
|
249
249
|
entries: Array<{ name: string; type: "file" | "directory" }>;
|
|
250
250
|
};
|
|
251
251
|
const subdirEntry = result.entries.find((e) => e.name === "subdir");
|
|
@@ -254,8 +254,8 @@ describe("GET /v1/workspace/tree", () => {
|
|
|
254
254
|
expect(fileEntry?.type).toBe("file");
|
|
255
255
|
});
|
|
256
256
|
|
|
257
|
-
test("dotfiles and dot-directories are excluded", () => {
|
|
258
|
-
const result = handler({ queryParams: {} }) as {
|
|
257
|
+
test("dotfiles and dot-directories are excluded", async () => {
|
|
258
|
+
const result = (await handler({ queryParams: {} })) as {
|
|
259
259
|
entries: Array<{ name: string }>;
|
|
260
260
|
};
|
|
261
261
|
const names = result.entries.map((e) => e.name);
|
|
@@ -263,8 +263,8 @@ describe("GET /v1/workspace/tree", () => {
|
|
|
263
263
|
expect(names).not.toContain(".hidden");
|
|
264
264
|
});
|
|
265
265
|
|
|
266
|
-
test("directory entries have null size and mimeType", () => {
|
|
267
|
-
const result = handler({ queryParams: {} }) as {
|
|
266
|
+
test("directory entries have null size and mimeType", async () => {
|
|
267
|
+
const result = (await handler({ queryParams: {} })) as {
|
|
268
268
|
entries: Array<{
|
|
269
269
|
name: string;
|
|
270
270
|
type: string;
|
|
@@ -278,8 +278,8 @@ describe("GET /v1/workspace/tree", () => {
|
|
|
278
278
|
expect(dirEntry!.mimeType).toBeNull();
|
|
279
279
|
});
|
|
280
280
|
|
|
281
|
-
test("directories sorted before files", () => {
|
|
282
|
-
const result = handler({ queryParams: {} }) as {
|
|
281
|
+
test("directories sorted before files", async () => {
|
|
282
|
+
const result = (await handler({ queryParams: {} })) as {
|
|
283
283
|
entries: Array<{ type: string }>;
|
|
284
284
|
};
|
|
285
285
|
const firstFileIdx = result.entries.findIndex((e) => e.type === "file");
|
|
@@ -295,8 +295,10 @@ describe("GET /v1/workspace/tree", () => {
|
|
|
295
295
|
}
|
|
296
296
|
});
|
|
297
297
|
|
|
298
|
-
test("includeDirSizes=true returns recursive byte size for directories", () => {
|
|
299
|
-
const result = handler({
|
|
298
|
+
test("includeDirSizes=true returns recursive byte size for directories", async () => {
|
|
299
|
+
const result = (await handler({
|
|
300
|
+
queryParams: { includeDirSizes: "true" },
|
|
301
|
+
})) as {
|
|
300
302
|
entries: Array<{ name: string; type: string; size: number | null }>;
|
|
301
303
|
};
|
|
302
304
|
const subdirEntry = result.entries.find((e) => e.name === "subdir");
|
|
@@ -307,8 +309,10 @@ describe("GET /v1/workspace/tree", () => {
|
|
|
307
309
|
expect(subdirEntry!.size).toBe("nested content".length);
|
|
308
310
|
});
|
|
309
311
|
|
|
310
|
-
test("includeDirSizes=true preserves accurate file sizes", () => {
|
|
311
|
-
const result = handler({
|
|
312
|
+
test("includeDirSizes=true preserves accurate file sizes", async () => {
|
|
313
|
+
const result = (await handler({
|
|
314
|
+
queryParams: { includeDirSizes: "true" },
|
|
315
|
+
})) as {
|
|
312
316
|
entries: Array<{ name: string; type: string; size: number | null }>;
|
|
313
317
|
};
|
|
314
318
|
const fileEntry = result.entries.find((e) => e.name === "hello.txt");
|
|
@@ -316,8 +320,8 @@ describe("GET /v1/workspace/tree", () => {
|
|
|
316
320
|
expect(fileEntry!.size).toBe("Hello, world!".length);
|
|
317
321
|
});
|
|
318
322
|
|
|
319
|
-
test("includeDirSizes omitted preserves null size for directories", () => {
|
|
320
|
-
const result = handler({ queryParams: {} }) as {
|
|
323
|
+
test("includeDirSizes omitted preserves null size for directories", async () => {
|
|
324
|
+
const result = (await handler({ queryParams: {} })) as {
|
|
321
325
|
entries: Array<{ type: string; size: number | null }>;
|
|
322
326
|
};
|
|
323
327
|
const dirEntry = result.entries.find((e) => e.type === "directory");
|
|
@@ -325,11 +329,36 @@ describe("GET /v1/workspace/tree", () => {
|
|
|
325
329
|
expect(dirEntry!.size).toBeNull();
|
|
326
330
|
});
|
|
327
331
|
|
|
328
|
-
test("
|
|
332
|
+
test("recursive=true lists nested entries and the bound fields", async () => {
|
|
333
|
+
const result = (await handler({ queryParams: { recursive: "true" } })) as {
|
|
334
|
+
entries: Array<{ path: string }>;
|
|
335
|
+
truncated: boolean;
|
|
336
|
+
skipped: string[];
|
|
337
|
+
};
|
|
338
|
+
expect(result.entries.map((e) => e.path)).toContain("subdir/nested.txt");
|
|
339
|
+
expect(result.truncated).toBe(false);
|
|
340
|
+
expect(Array.isArray(result.skipped)).toBe(true);
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
test("a non-recursive listing carries the same fields, unset", async () => {
|
|
344
|
+
const result = (await handler({ queryParams: {} })) as {
|
|
345
|
+
entries: Array<{ path: string }>;
|
|
346
|
+
truncated: boolean;
|
|
347
|
+
skipped: string[];
|
|
348
|
+
};
|
|
349
|
+
expect(result.entries.map((e) => e.path)).not.toContain(
|
|
350
|
+
"subdir/nested.txt",
|
|
351
|
+
);
|
|
352
|
+
expect(result).toMatchObject({ truncated: false, skipped: [] });
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
test("includeDirSizes=true returns 0 for empty directory", async () => {
|
|
329
356
|
const emptyDir = join(testWorkspaceDir, "empty-for-size");
|
|
330
357
|
mkdirSync(emptyDir, { recursive: true });
|
|
331
358
|
|
|
332
|
-
const result = handler({
|
|
359
|
+
const result = (await handler({
|
|
360
|
+
queryParams: { includeDirSizes: "true" },
|
|
361
|
+
})) as {
|
|
333
362
|
entries: Array<{ name: string; size: number | null }>;
|
|
334
363
|
};
|
|
335
364
|
const emptyEntry = result.entries.find((e) => e.name === "empty-for-size");
|
|
@@ -30,24 +30,15 @@ import {
|
|
|
30
30
|
} from "./errors.js";
|
|
31
31
|
import type { RouteDefinition, RouteHandlerArgs } from "./types.js";
|
|
32
32
|
import { RouteResponse } from "./types.js";
|
|
33
|
+
import { walkWorkspaceTree } from "./workspace-tree-walk.js";
|
|
33
34
|
import {
|
|
34
35
|
isTextMimeType,
|
|
35
36
|
MAX_INLINE_TEXT_SIZE,
|
|
36
37
|
resolveWorkspacePath,
|
|
38
|
+
workspaceEntrySchema,
|
|
37
39
|
writeWorkspaceFile,
|
|
38
40
|
} from "./workspace-utils.js";
|
|
39
41
|
|
|
40
|
-
const workspaceTreeEntrySchema = z.object({
|
|
41
|
-
name: z.string(),
|
|
42
|
-
path: z.string(),
|
|
43
|
-
type: z.enum(["file", "directory"]),
|
|
44
|
-
size: z.number().nullable(),
|
|
45
|
-
mimeType: z.string().nullable(),
|
|
46
|
-
modifiedAt: z.string(),
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
type TreeEntry = z.infer<typeof workspaceTreeEntrySchema>;
|
|
50
|
-
|
|
51
42
|
// Recursive directory sizing walks the filesystem synchronously, so it is
|
|
52
43
|
// bounded by two caps that work together:
|
|
53
44
|
//
|
|
@@ -175,10 +166,11 @@ function publishSoundsConfigUpdatedForPaths(
|
|
|
175
166
|
// GET /v1/workspace/tree — list directory contents
|
|
176
167
|
// ---------------------------------------------------------------------------
|
|
177
168
|
|
|
178
|
-
function handleWorkspaceTree({ queryParams }: RouteHandlerArgs) {
|
|
169
|
+
async function handleWorkspaceTree({ queryParams }: RouteHandlerArgs) {
|
|
179
170
|
const requestedPath = queryParams?.path ?? "";
|
|
180
171
|
const showHidden = queryParams?.showHidden === "true";
|
|
181
172
|
const includeDirSizes = queryParams?.includeDirSizes === "true";
|
|
173
|
+
const recursive = queryParams?.recursive === "true";
|
|
182
174
|
const resolved = resolveWorkspacePath(requestedPath, {
|
|
183
175
|
allowHidden: showHidden,
|
|
184
176
|
});
|
|
@@ -186,62 +178,36 @@ function handleWorkspaceTree({ queryParams }: RouteHandlerArgs) {
|
|
|
186
178
|
throw new BadRequestError("Invalid path");
|
|
187
179
|
}
|
|
188
180
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
// subtree can't starve its siblings, while the shared remainder still caps
|
|
196
|
-
// total synchronous traversal for the whole listing.
|
|
197
|
-
const listingBudget: DirSizeBudget | undefined = includeDirSizes
|
|
181
|
+
// Listing-wide budget, only constructed when sizes are requested. Each
|
|
182
|
+
// directory draws a per-directory allotment from it so one oversized
|
|
183
|
+
// subtree can't starve its siblings, while the shared remainder still caps
|
|
184
|
+
// total synchronous traversal for the whole listing.
|
|
185
|
+
const listingBudget: DirSizeBudget | undefined =
|
|
186
|
+
includeDirSizes && !recursive
|
|
198
187
|
? { remaining: DIR_SIZE_TOTAL_ENTRY_BUDGET }
|
|
199
188
|
: undefined;
|
|
200
189
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
stats = statSync(fullPath);
|
|
212
|
-
} catch {
|
|
213
|
-
continue;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
const isDir = stats.isDirectory();
|
|
217
|
-
const relativePath = fullPath.slice(workspaceDir.length + 1);
|
|
218
|
-
|
|
219
|
-
const dirSize =
|
|
220
|
-
isDir && listingBudget
|
|
221
|
-
? computeDirSizeWithinListing(fullPath, listingBudget)
|
|
222
|
-
: null;
|
|
223
|
-
|
|
224
|
-
entries.push({
|
|
225
|
-
name: entry.name,
|
|
226
|
-
path: relativePath,
|
|
227
|
-
type: isDir ? "directory" : "file",
|
|
228
|
-
size: isDir ? dirSize : stats.size,
|
|
229
|
-
mimeType: isDir ? null : Bun.file(fullPath).type,
|
|
230
|
-
modifiedAt: stats.mtime.toISOString(),
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
entries.sort((a, b) => {
|
|
235
|
-
if (a.type !== b.type) {
|
|
236
|
-
return a.type === "directory" ? -1 : 1;
|
|
237
|
-
}
|
|
238
|
-
return a.name.localeCompare(b.name);
|
|
190
|
+
let walk: Awaited<ReturnType<typeof walkWorkspaceTree>>;
|
|
191
|
+
try {
|
|
192
|
+
walk = await walkWorkspaceTree({
|
|
193
|
+
rootPath: resolved,
|
|
194
|
+
workspaceDir: getWorkspaceDir(),
|
|
195
|
+
showHidden,
|
|
196
|
+
recursive,
|
|
197
|
+
directorySize: listingBudget
|
|
198
|
+
? (absPath) => computeDirSizeWithinListing(absPath, listingBudget)
|
|
199
|
+
: undefined,
|
|
239
200
|
});
|
|
240
|
-
|
|
241
|
-
return { path: requestedPath, entries };
|
|
242
201
|
} catch {
|
|
243
202
|
throw new NotFoundError("Directory not found");
|
|
244
203
|
}
|
|
204
|
+
|
|
205
|
+
return {
|
|
206
|
+
path: requestedPath,
|
|
207
|
+
entries: walk.entries,
|
|
208
|
+
truncated: walk.truncated,
|
|
209
|
+
skipped: walk.skipped,
|
|
210
|
+
};
|
|
245
211
|
}
|
|
246
212
|
|
|
247
213
|
// ---------------------------------------------------------------------------
|
|
@@ -569,14 +535,31 @@ export const ROUTES: RouteDefinition[] = [
|
|
|
569
535
|
{
|
|
570
536
|
name: "includeDirSizes",
|
|
571
537
|
description:
|
|
572
|
-
"Compute recursive byte size for each directory entry (true/false). Budget-bounded
|
|
538
|
+
"Compute recursive byte size for each directory entry (true/false). Budget-bounded: large subtrees may return size: null. Not applied to a recursive listing, which carries every file for the client to sum.",
|
|
539
|
+
},
|
|
540
|
+
{
|
|
541
|
+
name: "recursive",
|
|
542
|
+
description:
|
|
543
|
+
"List the whole subtree in one response (true/false). Depth-first, each directory's entries in listing order, so grouping by parent path recovers per-directory listings. Bounded: sets truncated when the entry cap or deadline stops the walk, and does not enter directories the workspace gitignore rules exclude, which are named in skipped.",
|
|
573
544
|
},
|
|
574
545
|
],
|
|
575
546
|
responseBody: z.object({
|
|
576
547
|
path: z.string(),
|
|
577
548
|
entries: z
|
|
578
|
-
.array(
|
|
549
|
+
.array(workspaceEntrySchema)
|
|
579
550
|
.describe("Directory entry objects"),
|
|
551
|
+
truncated: z
|
|
552
|
+
.boolean()
|
|
553
|
+
.optional()
|
|
554
|
+
.describe(
|
|
555
|
+
"A recursive walk stopped at its entry cap or deadline, so deeper entries are missing. Absent from assistants that predate recursive listings.",
|
|
556
|
+
),
|
|
557
|
+
skipped: z
|
|
558
|
+
.array(z.string())
|
|
559
|
+
.optional()
|
|
560
|
+
.describe(
|
|
561
|
+
"Directories a recursive walk listed but did not enter, whether because a workspace gitignore rule excludes them, they are symlinks, or they could not be read. Each can still be listed on its own. Absent from assistants that predate recursive listings.",
|
|
562
|
+
),
|
|
580
563
|
}),
|
|
581
564
|
handler: handleWorkspaceTree,
|
|
582
565
|
},
|