@vellumai/assistant 0.10.11-dev.202607222226.fdf0e3d → 0.10.11-dev.202607222325.35fc367
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/package.json +1 -1
- package/src/__tests__/document-preview-surface-schema.test.ts +33 -0
- package/src/__tests__/surface-type-registry-guard.test.ts +66 -0
- package/src/__tests__/ui-choice-copy-surfaces.test.ts +26 -0
- package/src/api/index.ts +3 -0
- package/src/api/surfaces.ts +42 -5
- package/src/daemon/conversation-surfaces.ts +12 -4
package/package.json
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
|
|
3
|
+
import { DocumentPreviewSurfaceDataSchema } from "../api/surfaces.js";
|
|
4
|
+
|
|
5
|
+
describe("DocumentPreviewSurfaceDataSchema", () => {
|
|
6
|
+
test("models the content/mimeType the client renderer reads", () => {
|
|
7
|
+
const parsed = DocumentPreviewSurfaceDataSchema.parse({
|
|
8
|
+
title: "Notes",
|
|
9
|
+
surfaceId: "doc-real",
|
|
10
|
+
subtitle: "Document",
|
|
11
|
+
content: "# Heading\n\nbody",
|
|
12
|
+
mimeType: "text/markdown",
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
expect(parsed).toEqual({
|
|
16
|
+
title: "Notes",
|
|
17
|
+
surfaceId: "doc-real",
|
|
18
|
+
subtitle: "Document",
|
|
19
|
+
content: "# Heading\n\nbody",
|
|
20
|
+
mimeType: "text/markdown",
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("content/mimeType are optional (a bare preview still parses)", () => {
|
|
25
|
+
const parsed = DocumentPreviewSurfaceDataSchema.parse({
|
|
26
|
+
title: "Notes",
|
|
27
|
+
surfaceId: "doc-real",
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
expect(parsed.content).toBeUndefined();
|
|
31
|
+
expect(parsed.mimeType).toBeUndefined();
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { readdirSync, readFileSync, statSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { describe, expect, test } from "bun:test";
|
|
4
|
+
|
|
5
|
+
import { SURFACE_TYPES } from "../api/surfaces.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Guard: every `surfaceType` literal the daemon emits or declares in
|
|
9
|
+
* production code must be a member of the canonical `SURFACE_TYPES` set.
|
|
10
|
+
*
|
|
11
|
+
* This exists because a surface type that is emitted (appended to history as
|
|
12
|
+
* a `ui_surface` block, or sent as `ui_surface_show`) but missing from
|
|
13
|
+
* `SURFACE_TYPES` regresses silently: history restore and the surface content
|
|
14
|
+
* route can't classify it, so it renders wrong or loses its data. The memory
|
|
15
|
+
* retrospective's `skill_card` and a call's `call_summary` are emitted this
|
|
16
|
+
* way; both must stay registered.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
const SRC_ROOT = join(import.meta.dir, "..");
|
|
20
|
+
|
|
21
|
+
function collectTsFiles(dir: string, out: string[] = []): string[] {
|
|
22
|
+
for (const entry of readdirSync(dir)) {
|
|
23
|
+
const full = join(dir, entry);
|
|
24
|
+
const st = statSync(full);
|
|
25
|
+
if (st.isDirectory()) {
|
|
26
|
+
// Skip test trees and generated code — this guard is about production
|
|
27
|
+
// emission sites, and tests deliberately exercise invalid types.
|
|
28
|
+
if (entry === "__tests__" || entry === "generated") {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
collectTsFiles(full, out);
|
|
32
|
+
} else if (
|
|
33
|
+
(entry.endsWith(".ts") || entry.endsWith(".tsx")) &&
|
|
34
|
+
!entry.endsWith(".test.ts") &&
|
|
35
|
+
!entry.endsWith(".test.tsx")
|
|
36
|
+
) {
|
|
37
|
+
out.push(full);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return out;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
describe("surface-type registry guard", () => {
|
|
44
|
+
test("every surfaceType literal in production code is in SURFACE_TYPES", () => {
|
|
45
|
+
const registered = new Set<string>(SURFACE_TYPES);
|
|
46
|
+
const literalRe = /surfaceType:\s*"([a-z_]+)"/g;
|
|
47
|
+
const offenders: Array<{ type: string; file: string }> = [];
|
|
48
|
+
|
|
49
|
+
for (const file of collectTsFiles(SRC_ROOT)) {
|
|
50
|
+
const source = readFileSync(file, "utf8");
|
|
51
|
+
for (const match of source.matchAll(literalRe)) {
|
|
52
|
+
const type = match[1];
|
|
53
|
+
if (!registered.has(type)) {
|
|
54
|
+
offenders.push({ type, file: file.slice(SRC_ROOT.length + 1) });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
expect(offenders).toEqual([]);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("SURFACE_TYPES includes the daemon-appended card types", () => {
|
|
63
|
+
expect(SURFACE_TYPES).toContain("skill_card");
|
|
64
|
+
expect(SURFACE_TYPES).toContain("call_summary");
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -303,6 +303,32 @@ describe("choice and copy_block surface proxying", () => {
|
|
|
303
303
|
expect(sent).toHaveLength(0);
|
|
304
304
|
});
|
|
305
305
|
|
|
306
|
+
test("ui_show rejects daemon-internal surface types and omits them from the valid list", async () => {
|
|
307
|
+
for (const internalType of ["skill_card", "call_summary"]) {
|
|
308
|
+
const sent: ServerMessage[] = [];
|
|
309
|
+
const ctx = makeContext(sent);
|
|
310
|
+
|
|
311
|
+
const result = await surfaceProxyResolver(ctx, "ui_show", {
|
|
312
|
+
surface_type: internalType,
|
|
313
|
+
data: { anything: true },
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
expect(result.isError).toBe(true);
|
|
317
|
+
expect(result.content).toContain(
|
|
318
|
+
`"${internalType}" is not a valid surface_type`,
|
|
319
|
+
);
|
|
320
|
+
// The advertised valid list must never enumerate the internal types
|
|
321
|
+
// (the leading echo of the rejected input naming it is expected).
|
|
322
|
+
const validList =
|
|
323
|
+
typeof result.content === "string"
|
|
324
|
+
? (result.content.split("Valid surface_type values:")[1] ?? "")
|
|
325
|
+
: "";
|
|
326
|
+
expect(validList).not.toContain("skill_card");
|
|
327
|
+
expect(validList).not.toContain("call_summary");
|
|
328
|
+
expect(sent).toHaveLength(0);
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
|
|
306
332
|
test("ui_show teaching guard accepts copy_block text at the top level of the input", () => {
|
|
307
333
|
const teachingError = uiShowTeachingError({
|
|
308
334
|
surface_type: "copy_block",
|
package/src/api/index.ts
CHANGED
|
@@ -588,6 +588,7 @@ export {
|
|
|
588
588
|
ConfirmationSurfaceDataSchema,
|
|
589
589
|
type CopyBlockSurfaceData,
|
|
590
590
|
CopyBlockSurfaceDataSchema,
|
|
591
|
+
DAEMON_INTERNAL_SURFACE_TYPES,
|
|
591
592
|
type DocumentPreviewSurfaceData,
|
|
592
593
|
DocumentPreviewSurfaceDataSchema,
|
|
593
594
|
type DynamicPagePreview,
|
|
@@ -602,10 +603,12 @@ export {
|
|
|
602
603
|
FormPageSchema,
|
|
603
604
|
type FormSurfaceData,
|
|
604
605
|
FormSurfaceDataSchema,
|
|
606
|
+
isDaemonInternalSurfaceType,
|
|
605
607
|
type ListItem,
|
|
606
608
|
ListItemSchema,
|
|
607
609
|
type ListSurfaceData,
|
|
608
610
|
ListSurfaceDataSchema,
|
|
611
|
+
MODEL_INVOKABLE_SURFACE_TYPES,
|
|
609
612
|
normalizeCopyBlockShowData,
|
|
610
613
|
type OAuthConnectSurfaceData,
|
|
611
614
|
OAuthConnectSurfaceDataSchema,
|
package/src/api/surfaces.ts
CHANGED
|
@@ -372,6 +372,10 @@ export const DocumentPreviewSurfaceDataSchema = z.object({
|
|
|
372
372
|
/** The document's real surfaceId, for focusing the panel. */
|
|
373
373
|
surfaceId: z.string().catch(""),
|
|
374
374
|
subtitle: tolerantString(),
|
|
375
|
+
/** Document body the client renderer displays inline. */
|
|
376
|
+
content: tolerantString(),
|
|
377
|
+
/** MIME type the client renderer uses to choose how to render `content`. */
|
|
378
|
+
mimeType: tolerantString(),
|
|
375
379
|
});
|
|
376
380
|
export type DocumentPreviewSurfaceData = z.infer<
|
|
377
381
|
typeof DocumentPreviewSurfaceDataSchema
|
|
@@ -471,11 +475,40 @@ export const SURFACE_TYPES = [
|
|
|
471
475
|
"document_preview",
|
|
472
476
|
"task_preferences",
|
|
473
477
|
"work_result",
|
|
478
|
+
"skill_card",
|
|
479
|
+
"call_summary",
|
|
474
480
|
] as const;
|
|
475
481
|
|
|
476
482
|
export const SurfaceTypeSchema = z.enum(SURFACE_TYPES);
|
|
477
483
|
export type SurfaceType = z.infer<typeof SurfaceTypeSchema>;
|
|
478
484
|
|
|
485
|
+
/**
|
|
486
|
+
* Surface types the daemon emits and persists directly — the memory
|
|
487
|
+
* retrospective's `skill_card` and a call's `call_summary` — but that the
|
|
488
|
+
* model must never invoke via `ui_show`. They are members of `SurfaceType`
|
|
489
|
+
* so the persistence/restore path can represent them, but they are
|
|
490
|
+
* deliberately absent from the model-facing `ui_show` surface list
|
|
491
|
+
* (`SURFACE_SHAPE_DOCS`), and the `ui_show` resolver rejects them.
|
|
492
|
+
*/
|
|
493
|
+
export const DAEMON_INTERNAL_SURFACE_TYPES = [
|
|
494
|
+
"skill_card",
|
|
495
|
+
"call_summary",
|
|
496
|
+
] as const;
|
|
497
|
+
|
|
498
|
+
const DAEMON_INTERNAL_SURFACE_TYPE_SET = new Set<string>(
|
|
499
|
+
DAEMON_INTERNAL_SURFACE_TYPES,
|
|
500
|
+
);
|
|
501
|
+
|
|
502
|
+
/** Whether `type` is a daemon-internal surface type the model must not `ui_show`. */
|
|
503
|
+
export function isDaemonInternalSurfaceType(type: string): boolean {
|
|
504
|
+
return DAEMON_INTERNAL_SURFACE_TYPE_SET.has(type);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/** Surface types the model may request via `ui_show` (internal types excluded). */
|
|
508
|
+
export const MODEL_INVOKABLE_SURFACE_TYPES = SURFACE_TYPES.filter(
|
|
509
|
+
(type) => !isDaemonInternalSurfaceType(type),
|
|
510
|
+
);
|
|
511
|
+
|
|
479
512
|
export type SurfaceData =
|
|
480
513
|
| CardSurfaceData
|
|
481
514
|
| ChoiceSurfaceData
|
|
@@ -538,11 +571,15 @@ export function safeParseSurfaceData(
|
|
|
538
571
|
return parse(WorkResultSurfaceDataSchema);
|
|
539
572
|
case "channel_setup":
|
|
540
573
|
case "task_preferences":
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
//
|
|
544
|
-
//
|
|
545
|
-
//
|
|
574
|
+
case "skill_card":
|
|
575
|
+
case "call_summary":
|
|
576
|
+
// Opaque payloads the daemon forwards/persists verbatim: channel_setup
|
|
577
|
+
// is a side-effect command whose data goes to the setup panel,
|
|
578
|
+
// task_preferences renders a fixed grid that reads no data, and
|
|
579
|
+
// skill_card / call_summary are daemon-appended cards whose data shape
|
|
580
|
+
// is owned by their client renderers. There is no canonical shape to
|
|
581
|
+
// parse into, so this is the one deliberate cast in the surface-data
|
|
582
|
+
// parse path.
|
|
546
583
|
return coerceSurfaceDataRecord(data) as SurfaceData;
|
|
547
584
|
default:
|
|
548
585
|
return surfaceType satisfies never;
|
|
@@ -7,10 +7,11 @@ import {
|
|
|
7
7
|
ChoiceSurfaceDataSchema,
|
|
8
8
|
coerceSurfaceDataRecord,
|
|
9
9
|
DynamicPageSurfaceDataSchema,
|
|
10
|
+
isDaemonInternalSurfaceType,
|
|
11
|
+
MODEL_INVOKABLE_SURFACE_TYPES,
|
|
10
12
|
normalizeCopyBlockShowData,
|
|
11
13
|
OAuthConnectSurfaceDataSchema,
|
|
12
14
|
safeParseSurfaceData,
|
|
13
|
-
SURFACE_TYPES,
|
|
14
15
|
SurfaceTypeSchema,
|
|
15
16
|
} from "../api/surfaces.js";
|
|
16
17
|
import {
|
|
@@ -2935,16 +2936,23 @@ export async function surfaceProxyResolver(
|
|
|
2935
2936
|
const surfaceId = uuid();
|
|
2936
2937
|
// Parse, don't cast: an unrecognized surface_type used to be asserted
|
|
2937
2938
|
// into the union and fall through to an opaque passthrough the client
|
|
2938
|
-
// silently dropped. Reject it with the valid values instead.
|
|
2939
|
+
// silently dropped. Reject it with the valid values instead. Daemon-
|
|
2940
|
+
// internal types (skill_card, call_summary) are members of SurfaceType
|
|
2941
|
+
// for persistence but are not model-invokable — reject them here too so
|
|
2942
|
+
// the model can never report an unrenderable surface as shown. Both
|
|
2943
|
+
// messages enumerate only the model-facing set, never the internal types.
|
|
2939
2944
|
const parsedSurfaceType = SurfaceTypeSchema.safeParse(input.surface_type);
|
|
2940
|
-
if (
|
|
2945
|
+
if (
|
|
2946
|
+
!parsedSurfaceType.success ||
|
|
2947
|
+
isDaemonInternalSurfaceType(parsedSurfaceType.data)
|
|
2948
|
+
) {
|
|
2941
2949
|
const got =
|
|
2942
2950
|
typeof input.surface_type === "string" &&
|
|
2943
2951
|
input.surface_type.trim().length > 0
|
|
2944
2952
|
? `"${input.surface_type}" is not a valid surface_type`
|
|
2945
2953
|
: "`surface_type` is missing";
|
|
2946
2954
|
return {
|
|
2947
|
-
content: `Error: ui_show was not displayed — ${got}. Valid surface_type values: ${
|
|
2955
|
+
content: `Error: ui_show was not displayed — ${got}. Valid surface_type values: ${MODEL_INVOKABLE_SURFACE_TYPES.join(", ")}. Resend ui_show with one of these values.`,
|
|
2948
2956
|
isError: true,
|
|
2949
2957
|
};
|
|
2950
2958
|
}
|