@vellumai/assistant 0.10.10-dev.202607201250.7cc78f7 → 0.10.10-dev.202607201338.c6dec1d
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__/plugin-import-boundary-guard.test.ts +1 -0
- package/src/cli/lib/__tests__/list-installed-plugins.test.ts +2 -2
- package/src/plugin-api/index.ts +4 -0
- package/src/plugins/defaults/index.ts +15 -0
- package/src/plugins/defaults/platform-hosted/__tests__/reengage.test.ts +121 -0
- package/src/plugins/defaults/platform-hosted/package.json +14 -0
- package/src/plugins/defaults/platform-hosted/routes/reengage.ts +128 -0
package/package.json
CHANGED
|
@@ -196,8 +196,8 @@ describe("listAllPlugins", () => {
|
|
|
196
196
|
test("includes default plugins with source=default", () => {
|
|
197
197
|
const result = listAllPlugins({ workspacePluginsDir: pluginsDir });
|
|
198
198
|
const defaults = result.filter((p) => p.source === "default");
|
|
199
|
-
// All
|
|
200
|
-
expect(defaults.length).toBe(
|
|
199
|
+
// All 19 default plugins should be present.
|
|
200
|
+
expect(defaults.length).toBe(19);
|
|
201
201
|
// Names should all start with "default-".
|
|
202
202
|
expect(defaults.every((p) => p.name.startsWith("default-"))).toBe(true);
|
|
203
203
|
// None should be disabled by default in a fresh temp dir.
|
package/src/plugin-api/index.ts
CHANGED
|
@@ -216,6 +216,10 @@ export {
|
|
|
216
216
|
getAssistantName,
|
|
217
217
|
resolveUserName,
|
|
218
218
|
} from "../daemon/identity-helpers.js";
|
|
219
|
+
// Absolute path to the active workspace directory. A plugin that reads or
|
|
220
|
+
// writes files under the workspace (e.g. its own `plugins/<name>/data/`
|
|
221
|
+
// directory) resolves them against this instead of hardcoding a base path.
|
|
222
|
+
export { getWorkspaceDir } from "../util/platform.js";
|
|
219
223
|
// Declarative help for the top-level `assistant` CLI commands that have adopted
|
|
220
224
|
// the static-help split. Plugins (e.g. the memory capability indexer) read this
|
|
221
225
|
// to embed CLI command capabilities without importing the CLI action graph.
|
|
@@ -78,6 +78,7 @@ import {
|
|
|
78
78
|
memoryV3Injector,
|
|
79
79
|
memoryV3SpotlightInjector,
|
|
80
80
|
} from "./memory/v3/injector.js";
|
|
81
|
+
import platformHostedPkg from "./platform-hosted/package.json" with { type: "json" };
|
|
81
82
|
import { sessionInjectors } from "./session/injectors.js";
|
|
82
83
|
import sessionPkg from "./session/package.json" with { type: "json" };
|
|
83
84
|
import surfaceCompletionNudgePostModelCall from "./surface-completion-nudge/hooks/post-model-call.js";
|
|
@@ -274,6 +275,19 @@ export const defaultSessionPlugin: Plugin = {
|
|
|
274
275
|
injectors: sessionInjectors,
|
|
275
276
|
};
|
|
276
277
|
|
|
278
|
+
/**
|
|
279
|
+
* `platform-hosted` — contributes the platform-hosted `/reengage` route. It
|
|
280
|
+
* ships no hooks, tools, or injectors, so it registers as a manifest only;
|
|
281
|
+
* the route source is served once the assistant dispatches default-plugin
|
|
282
|
+
* routes.
|
|
283
|
+
*/
|
|
284
|
+
export const defaultPlatformHostedPlugin: Plugin = {
|
|
285
|
+
manifest: {
|
|
286
|
+
name: platformHostedPkg.name,
|
|
287
|
+
version: platformHostedPkg.version,
|
|
288
|
+
},
|
|
289
|
+
};
|
|
290
|
+
|
|
277
291
|
/**
|
|
278
292
|
* `history-repair` — normalizes the working message history (tool-use/tool-result
|
|
279
293
|
* pairing, role alternation). The `user-prompt-submit` hook normalizes the
|
|
@@ -448,6 +462,7 @@ export function getAllDefaultPlugins(): readonly Plugin[] {
|
|
|
448
462
|
defaultDocumentsPlugin,
|
|
449
463
|
defaultChannelPlugin,
|
|
450
464
|
defaultSessionPlugin,
|
|
465
|
+
defaultPlatformHostedPlugin,
|
|
451
466
|
defaultImageFallbackPlugin,
|
|
452
467
|
defaultToolResultTruncatePlugin,
|
|
453
468
|
defaultEmptyResponsePlugin,
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for the platform-hosted /reengage route handler.
|
|
3
|
+
*
|
|
4
|
+
* The route runs a background conversation turn and asks the assistant to write
|
|
5
|
+
* `{ subject, body }` JSON to an injected file path under the plugin's data
|
|
6
|
+
* directory, then reads it back. These tests mock `@vellumai/plugin-api` to
|
|
7
|
+
* supply both a temp `getWorkspaceDir` (so the data dir is a throwaway temp
|
|
8
|
+
* location) and a `runConversationTurn` that plays the assistant's part —
|
|
9
|
+
* extracting the injected path from the prompt and writing (or not writing) a
|
|
10
|
+
* file there.
|
|
11
|
+
*
|
|
12
|
+
* Covers:
|
|
13
|
+
* - Happy path: model writes valid JSON → structured subject/body, file cleaned up
|
|
14
|
+
* - Runs in a fresh background conversation
|
|
15
|
+
* - Fenced JSON in the file → still parsed
|
|
16
|
+
* - Model writes nothing → 502
|
|
17
|
+
* - Model writes JSON missing a field → 502
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { existsSync, mkdtempSync } from "node:fs";
|
|
21
|
+
import { writeFile } from "node:fs/promises";
|
|
22
|
+
import { tmpdir } from "node:os";
|
|
23
|
+
import { join } from "node:path";
|
|
24
|
+
import { beforeEach, describe, expect, mock, test } from "bun:test";
|
|
25
|
+
|
|
26
|
+
import type { RunConversationTurnOptions } from "@vellumai/plugin-api";
|
|
27
|
+
|
|
28
|
+
// ---------------------------------------------------------------------------
|
|
29
|
+
// Mock — supplies every named export reengage.ts imports from the plugin API:
|
|
30
|
+
// a temp `getWorkspaceDir`, and a `runConversationTurn` that plays the
|
|
31
|
+
// assistant (writes `fileContents`, if non-null, to the path injected into the
|
|
32
|
+
// prompt).
|
|
33
|
+
// ---------------------------------------------------------------------------
|
|
34
|
+
|
|
35
|
+
let workspaceDir = mkdtempSync(join(tmpdir(), "reengage-test-"));
|
|
36
|
+
let fileContents: string | null = JSON.stringify({
|
|
37
|
+
subject: "Ready when you are",
|
|
38
|
+
body: "Just picking up where we left off.",
|
|
39
|
+
});
|
|
40
|
+
let lastOptions: RunConversationTurnOptions | undefined;
|
|
41
|
+
|
|
42
|
+
function extractInjectedPath(prompt: string): string {
|
|
43
|
+
const match = prompt.match(/`([^`]+)`/);
|
|
44
|
+
if (!match) {
|
|
45
|
+
throw new Error("no injected path found in prompt");
|
|
46
|
+
}
|
|
47
|
+
return match[1];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
mock.module("@vellumai/plugin-api", () => ({
|
|
51
|
+
getWorkspaceDir: () => workspaceDir,
|
|
52
|
+
runConversationTurn: async (options: RunConversationTurnOptions) => {
|
|
53
|
+
lastOptions = options;
|
|
54
|
+
const prompt = (options.content[0] as { text: string }).text;
|
|
55
|
+
if (fileContents !== null) {
|
|
56
|
+
await writeFile(extractInjectedPath(prompt), fileContents, "utf8");
|
|
57
|
+
}
|
|
58
|
+
return { content: [], userMessageId: "msg-1", conversationId: "conv-1" };
|
|
59
|
+
},
|
|
60
|
+
}));
|
|
61
|
+
|
|
62
|
+
const { POST } = await import("../routes/reengage.js");
|
|
63
|
+
|
|
64
|
+
function postRequest(): Request {
|
|
65
|
+
return new Request(
|
|
66
|
+
"http://plugin.internal/x/plugins/platform-hosted/reengage",
|
|
67
|
+
{ method: "POST" },
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
describe("platform-hosted /reengage POST", () => {
|
|
72
|
+
beforeEach(() => {
|
|
73
|
+
workspaceDir = mkdtempSync(join(tmpdir(), "reengage-test-"));
|
|
74
|
+
lastOptions = undefined;
|
|
75
|
+
fileContents = JSON.stringify({
|
|
76
|
+
subject: "Ready when you are",
|
|
77
|
+
body: "Just picking up where we left off.",
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test("returns the structured subject/body the model wrote, and cleans up", async () => {
|
|
82
|
+
const response = await POST(postRequest());
|
|
83
|
+
expect(response.status).toBe(200);
|
|
84
|
+
const json = (await response.json()) as { subject: string; body: string };
|
|
85
|
+
expect(json.subject).toBe("Ready when you are");
|
|
86
|
+
expect(json.body).toBe("Just picking up where we left off.");
|
|
87
|
+
|
|
88
|
+
// The injected file is removed after the handler returns.
|
|
89
|
+
const injectedPath = extractInjectedPath(
|
|
90
|
+
(lastOptions?.content[0] as { text: string }).text,
|
|
91
|
+
);
|
|
92
|
+
expect(existsSync(injectedPath)).toBe(false);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test("runs the turn in a fresh background conversation", async () => {
|
|
96
|
+
await POST(postRequest());
|
|
97
|
+
expect(lastOptions?.conversationType).toBe("background");
|
|
98
|
+
expect(lastOptions?.conversationId).toBeUndefined();
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test("tolerates JSON wrapped in a code fence", async () => {
|
|
102
|
+
fileContents =
|
|
103
|
+
'```json\n{"subject": "A quick nudge", "body": "Let me know."}\n```';
|
|
104
|
+
const response = await POST(postRequest());
|
|
105
|
+
const json = (await response.json()) as { subject: string; body: string };
|
|
106
|
+
expect(json.subject).toBe("A quick nudge");
|
|
107
|
+
expect(json.body).toBe("Let me know.");
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test("returns 502 when the model writes no file", async () => {
|
|
111
|
+
fileContents = null;
|
|
112
|
+
const response = await POST(postRequest());
|
|
113
|
+
expect(response.status).toBe(502);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test("returns 502 when the written JSON is missing a field", async () => {
|
|
117
|
+
fileContents = JSON.stringify({ subject: "Only a subject" });
|
|
118
|
+
const response = await POST(postRequest());
|
|
119
|
+
expect(response.status).toBe(502);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "default-platform-hosted",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "First-party default plugin contributing platform-hosted capabilities. Exposes the /reengage route, which asks the assistant to compose a re-engagement email in its own voice and returns the subject line and body for the platform to send.",
|
|
5
|
+
"private": true,
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"engines": {
|
|
9
|
+
"node": ">=20.12.0"
|
|
10
|
+
},
|
|
11
|
+
"peerDependencies": {
|
|
12
|
+
"@vellumai/plugin-api": "^0.10.9"
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Platform-hosted `/reengage` route.
|
|
3
|
+
*
|
|
4
|
+
* Authored in the userland plugin route format (`export const POST`, standard
|
|
5
|
+
* Web `Request`/`Response`) so it is served as-is once the assistant dispatches
|
|
6
|
+
* default-plugin routes.
|
|
7
|
+
*
|
|
8
|
+
* The handler runs a full background conversation turn (via
|
|
9
|
+
* `runConversationTurn`) so the assistant's identity, memory, and history are
|
|
10
|
+
* all in scope while it composes a short re-engagement email in its own voice.
|
|
11
|
+
* The turn has no way to return typed data, so the route injects an output file
|
|
12
|
+
* path into the prompt and asks the assistant to write `{ subject, body }` JSON
|
|
13
|
+
* there; the route then reads that file back, so the subject and body are read
|
|
14
|
+
* from structured JSON rather than parsed out of the chat reply. The turn runs
|
|
15
|
+
* in a fresh `background` conversation, so it stays out of the user's visible
|
|
16
|
+
* chats.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { mkdir, readFile, rm } from "node:fs/promises";
|
|
20
|
+
import { join } from "node:path";
|
|
21
|
+
|
|
22
|
+
import { getWorkspaceDir, runConversationTurn } from "@vellumai/plugin-api";
|
|
23
|
+
|
|
24
|
+
// ---------------------------------------------------------------------------
|
|
25
|
+
// Output location — the plugin's own data directory
|
|
26
|
+
// ---------------------------------------------------------------------------
|
|
27
|
+
|
|
28
|
+
/** `<workspaceDir>/plugins/platform-hosted/data` — this plugin's runtime data dir. */
|
|
29
|
+
function pluginDataDir(): string {
|
|
30
|
+
return join(getWorkspaceDir(), "plugins", "platform-hosted", "data");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// ---------------------------------------------------------------------------
|
|
34
|
+
// Prompt
|
|
35
|
+
// ---------------------------------------------------------------------------
|
|
36
|
+
|
|
37
|
+
function buildPrompt(outputPath: string): string {
|
|
38
|
+
return `Compose a short re-engagement email to me, in your own voice as my assistant, to gently draw me back into our work together.
|
|
39
|
+
|
|
40
|
+
Draw on what you know about me and our recent conversations to make it personal and specific — reference something concrete we have been working on, or a next step that is waiting on me, rather than a generic "just checking in." Keep it warm, brief, and low-pressure: a few sentences at most, with no pushy or salesy language.
|
|
41
|
+
|
|
42
|
+
When the email is ready, use your file-writing tool to write it to exactly this path:
|
|
43
|
+
|
|
44
|
+
\`${outputPath}\`
|
|
45
|
+
|
|
46
|
+
Write ONLY a raw JSON object to that file — no markdown, no code fence, no surrounding prose — with exactly these two string fields:
|
|
47
|
+
{"subject": "<the subject line>", "body": "<the plain-text email body>"}
|
|
48
|
+
|
|
49
|
+
The subject should be short and specific. The body is the email itself, written as if you are speaking directly to me. The file is the deliverable; do not include the email in your chat reply.`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// ---------------------------------------------------------------------------
|
|
53
|
+
// Parsing
|
|
54
|
+
// ---------------------------------------------------------------------------
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Read `{ subject, body }` out of the JSON the assistant wrote. The instruction
|
|
58
|
+
* asks for a bare object, but tolerate a stray code fence or surrounding prose
|
|
59
|
+
* by falling back to the first brace-delimited span.
|
|
60
|
+
*/
|
|
61
|
+
function parseEmail(raw: string): { subject: string; body: string } | null {
|
|
62
|
+
const candidates = [raw.trim()];
|
|
63
|
+
const brace = raw.match(/\{[\s\S]*\}/);
|
|
64
|
+
if (brace?.[0]) {
|
|
65
|
+
candidates.push(brace[0]);
|
|
66
|
+
}
|
|
67
|
+
for (const candidate of candidates) {
|
|
68
|
+
try {
|
|
69
|
+
const parsed = JSON.parse(candidate) as unknown;
|
|
70
|
+
if (parsed && typeof parsed === "object") {
|
|
71
|
+
const record = parsed as Record<string, unknown>;
|
|
72
|
+
const subject =
|
|
73
|
+
typeof record.subject === "string" ? record.subject.trim() : "";
|
|
74
|
+
const body = typeof record.body === "string" ? record.body.trim() : "";
|
|
75
|
+
if (subject && body) {
|
|
76
|
+
return { subject, body };
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
} catch {
|
|
80
|
+
// Try the next candidate.
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function jsonError(message: string, status: number): Response {
|
|
87
|
+
return Response.json({ error: { message } }, { status });
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// ---------------------------------------------------------------------------
|
|
91
|
+
// Handler
|
|
92
|
+
// ---------------------------------------------------------------------------
|
|
93
|
+
|
|
94
|
+
export const POST = async (request: Request): Promise<Response> => {
|
|
95
|
+
const dir = pluginDataDir();
|
|
96
|
+
await mkdir(dir, { recursive: true });
|
|
97
|
+
const outputPath = join(dir, `reengage-${crypto.randomUUID()}.json`);
|
|
98
|
+
|
|
99
|
+
try {
|
|
100
|
+
await runConversationTurn({
|
|
101
|
+
content: [{ type: "text", text: buildPrompt(outputPath) }],
|
|
102
|
+
conversationType: "background",
|
|
103
|
+
signal: request.signal,
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
let raw: string;
|
|
107
|
+
try {
|
|
108
|
+
raw = await readFile(outputPath, "utf8");
|
|
109
|
+
} catch {
|
|
110
|
+
return jsonError(
|
|
111
|
+
"The re-engagement turn did not write an email file.",
|
|
112
|
+
502,
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const email = parseEmail(raw);
|
|
117
|
+
if (!email) {
|
|
118
|
+
return jsonError(
|
|
119
|
+
"The re-engagement email file did not contain a usable subject and body.",
|
|
120
|
+
502,
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return Response.json(email);
|
|
125
|
+
} finally {
|
|
126
|
+
await rm(outputPath, { force: true });
|
|
127
|
+
}
|
|
128
|
+
};
|