@vellumai/assistant 0.10.7-dev.202607100313.fffdfea → 0.10.7-dev.202607100720.fba456e
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/openapi.yaml +846 -27
- package/package.json +1 -1
- package/src/__tests__/config-watcher-skill-reseed.test.ts +1 -0
- package/src/__tests__/config-watcher.test.ts +22 -4
- package/src/__tests__/credential-security-invariants.test.ts +1 -1
- package/src/__tests__/plugin-import-boundary-guard.test.ts +6 -9
- package/src/__tests__/plugin-import-boundary-reverse-guard.test.ts +0 -2
- package/src/cli/commands/__tests__/inference-models.test.ts +86 -0
- package/src/cli/commands/__tests__/inference-profiles.test.ts +254 -0
- package/src/cli/commands/__tests__/inference-providers.test.ts +171 -0
- package/src/cli/commands/__tests__/schedules.test.ts +133 -1
- package/src/cli/commands/__tests__/usage.test.ts +131 -0
- package/src/cli/commands/inference-callsites.ts +158 -0
- package/src/cli/commands/inference-models.ts +84 -0
- package/src/cli/commands/inference-profiles.ts +371 -0
- package/src/cli/commands/inference-providers-default.ts +89 -0
- package/src/cli/commands/inference-providers.ts +87 -16
- package/src/cli/commands/inference.ts +6 -0
- package/src/cli/commands/memory/nodes.ts +90 -50
- package/src/cli/commands/schedules.ts +17 -2
- package/src/cli/commands/usage.ts +59 -21
- package/src/cli/lib/__tests__/cli-output.test.ts +20 -0
- package/src/cli/lib/cli-output.ts +55 -0
- package/src/config/__tests__/loader-last-known-good.test.ts +229 -0
- package/src/config/__tests__/loader-sparse-array-cleanup.test.ts +166 -0
- package/src/config/default-profile-catalog.ts +28 -0
- package/src/config/loader.ts +276 -46
- package/src/daemon/config-watcher.ts +65 -20
- package/src/daemon/message-types/sync.ts +1 -0
- package/src/oauth/byo-connection.test.ts +1 -1
- package/src/oauth/connection-resolver.test.ts +140 -0
- package/src/oauth/connection-resolver.ts +48 -12
- package/src/plugins/defaults/memory/anisotropy.ts +1 -1
- package/src/plugins/defaults/memory/config.ts +1 -1
- package/src/plugins/defaults/memory/context-search/agent-protocol.ts +1 -1
- package/src/plugins/defaults/memory/context-search/search.ts +1 -1
- package/src/plugins/defaults/memory/graph/bootstrap.ts +1 -1
- package/src/plugins/defaults/memory/graph/consolidation.ts +1 -1
- package/src/plugins/defaults/memory/graph/conversation-graph-memory.ts +11 -1
- package/src/plugins/defaults/memory/graph/extraction.ts +1 -1
- package/src/plugins/defaults/memory/graph/narrative.ts +1 -1
- package/src/plugins/defaults/memory/graph/pattern-scan.ts +1 -1
- package/src/plugins/defaults/memory/graph/tool-handlers.ts +1 -1
- package/src/plugins/defaults/memory/graph/tools.ts +1 -1
- package/src/plugins/defaults/memory/graph-topology/build-memory-graph.ts +43 -16
- package/src/plugins/defaults/memory/hooks/user-prompt-submit.ts +1 -1
- package/src/plugins/defaults/memory/host-utils.ts +80 -0
- package/src/plugins/defaults/memory/identity-context.ts +1 -1
- package/src/plugins/defaults/memory/injectors.ts +1 -1
- package/src/plugins/defaults/memory/jobs/embed-concept-page.ts +2 -2
- package/src/plugins/defaults/memory/jobs-worker.ts +2 -9
- package/src/plugins/defaults/memory/memory-retrospective-state.ts +1 -1
- package/src/plugins/defaults/memory/paths.ts +48 -0
- package/src/plugins/defaults/memory/pkb/autoinject.ts +1 -1
- package/src/plugins/defaults/memory/pkb/context.ts +2 -2
- package/src/plugins/defaults/memory/pkb/types.ts +1 -1
- package/src/plugins/defaults/memory/pkb-schedule.ts +2 -2
- package/src/plugins/defaults/memory/rerank-local.ts +2 -3
- package/src/plugins/defaults/memory/routes/memory-eval-routes.ts +1 -1
- package/src/plugins/defaults/memory/routes/memory-item-routes.test.ts +149 -1
- package/src/plugins/defaults/memory/routes/memory-item-routes.ts +144 -1
- package/src/plugins/defaults/memory/routes/memory-v2-routes.ts +1 -1
- package/src/plugins/defaults/memory/startup.ts +1 -1
- package/src/plugins/defaults/memory/v2/backfill-jobs.ts +1 -1
- package/src/plugins/defaults/memory/v2/consolidation-job.ts +2 -2
- package/src/plugins/defaults/memory/v2/injection.ts +1 -1
- package/src/plugins/defaults/memory/v2/memory-v2-startup.ts +1 -1
- package/src/plugins/defaults/memory/v2/prompts/consolidation.ts +1 -1
- package/src/plugins/defaults/memory/v2/qdrant.ts +1 -1
- package/src/plugins/defaults/memory/v2/reranker.ts +1 -1
- package/src/plugins/defaults/memory/v2/static-context.ts +1 -1
- package/src/plugins/defaults/memory/v2/sweep-job.ts +1 -1
- package/src/plugins/defaults/memory/v3/candidate-match.ts +1 -1
- package/src/plugins/defaults/memory/v3/maintain-job.ts +1 -1
- package/src/plugins/defaults/memory/v3/page-content.ts +1 -1
- package/src/plugins/defaults/memory/v3/pool-select.ts +1 -2
- package/src/plugins/defaults/memory/v3/selection-log-store.ts +1 -1
- package/src/plugins/defaults/memory/v3/shadow-plugin.ts +2 -5
- package/src/plugins/defaults/memory/worker.ts +1 -1
- package/src/plugins/defaults/workspace/injectors.ts +17 -15
- package/src/plugins/types.ts +9 -14
- package/src/providers/inference/connection-availability.ts +193 -0
- package/src/runtime/routes/__tests__/inference-callsites-routes.test.ts +54 -0
- package/src/runtime/routes/__tests__/inference-models-routes.test.ts +54 -0
- package/src/runtime/routes/__tests__/inference-profiles-routes.test.ts +405 -0
- package/src/runtime/routes/__tests__/inference-routes-registration.test.ts +42 -0
- package/src/runtime/routes/__tests__/theme-routes.test.ts +66 -0
- package/src/runtime/routes/conversation-query-routes.ts +5 -3
- package/src/runtime/routes/default-provider-routes.ts +5 -152
- package/src/runtime/routes/index.ts +8 -0
- package/src/runtime/routes/inference-callsites-routes.ts +211 -0
- package/src/runtime/routes/inference-models-routes.ts +104 -0
- package/src/runtime/routes/inference-profiles-routes.ts +717 -0
- package/src/runtime/routes/theme-routes.ts +36 -0
- package/src/runtime/sync/resource-sync-events.ts +4 -0
- package/src/theme/workspace-theme.test.ts +269 -0
- package/src/theme/workspace-theme.ts +304 -0
- package/src/watcher/__tests__/engine-auth-notify.test.ts +316 -0
- package/src/watcher/engine.ts +87 -2
|
@@ -78,6 +78,7 @@ mock.module("../platform/client.js", () => ({
|
|
|
78
78
|
|
|
79
79
|
import { BYOOAuthConnection } from "./byo-connection.js";
|
|
80
80
|
import {
|
|
81
|
+
formatNoConnectionError,
|
|
81
82
|
resolveEffectiveBaseUrl,
|
|
82
83
|
resolveOAuthConnection,
|
|
83
84
|
resolveOAuthConnectionWithMeta,
|
|
@@ -576,6 +577,145 @@ describe("resolveOAuthConnectionWithMeta multi-account visibility", () => {
|
|
|
576
577
|
});
|
|
577
578
|
});
|
|
578
579
|
|
|
580
|
+
describe("no-match error lists available accounts", () => {
|
|
581
|
+
function clientReturning(results: unknown[]) {
|
|
582
|
+
return {
|
|
583
|
+
...makeMockClient(),
|
|
584
|
+
fetch: mock(
|
|
585
|
+
async (path: string) =>
|
|
586
|
+
new Response(
|
|
587
|
+
JSON.stringify({
|
|
588
|
+
// Filtered lookups (account_identifier present) return nothing;
|
|
589
|
+
// the unfiltered fallback returns the real connections.
|
|
590
|
+
results: path.includes("account_identifier=") ? [] : results,
|
|
591
|
+
}),
|
|
592
|
+
{ status: 200 },
|
|
593
|
+
),
|
|
594
|
+
),
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
beforeEach(() => {
|
|
599
|
+
setupDefaults();
|
|
600
|
+
});
|
|
601
|
+
|
|
602
|
+
test("BYO: names the provider's active accounts when the requested account misses", async () => {
|
|
603
|
+
mockConnections = [
|
|
604
|
+
{
|
|
605
|
+
id: "conn-personal",
|
|
606
|
+
provider: "google",
|
|
607
|
+
accountInfo: "user@example.com",
|
|
608
|
+
grantedScopes: JSON.stringify([]),
|
|
609
|
+
status: "active",
|
|
610
|
+
},
|
|
611
|
+
{
|
|
612
|
+
id: "conn-work",
|
|
613
|
+
provider: "google",
|
|
614
|
+
accountInfo: "other@example.org",
|
|
615
|
+
grantedScopes: JSON.stringify([]),
|
|
616
|
+
status: "active",
|
|
617
|
+
},
|
|
618
|
+
];
|
|
619
|
+
|
|
620
|
+
let message = "";
|
|
621
|
+
try {
|
|
622
|
+
await resolveOAuthConnection("google", {
|
|
623
|
+
account: "missing@example.com",
|
|
624
|
+
});
|
|
625
|
+
} catch (error) {
|
|
626
|
+
message = (error as Error).message;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
expect(message).toContain('account "missing@example.com"');
|
|
630
|
+
expect(message).toContain(
|
|
631
|
+
"Active google connections: user@example.com, other@example.org",
|
|
632
|
+
);
|
|
633
|
+
expect(message).toContain("Check the account spelling.");
|
|
634
|
+
});
|
|
635
|
+
|
|
636
|
+
test("BYO: zero connections keeps the plain 'needs to be connected' shape", async () => {
|
|
637
|
+
mockConnections = [];
|
|
638
|
+
|
|
639
|
+
let message = "";
|
|
640
|
+
try {
|
|
641
|
+
await resolveOAuthConnection("google", {
|
|
642
|
+
account: "missing@example.com",
|
|
643
|
+
});
|
|
644
|
+
} catch (error) {
|
|
645
|
+
message = (error as Error).message;
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
expect(message).not.toContain("Active google connections:");
|
|
649
|
+
expect(message).toContain(
|
|
650
|
+
"The google service needs to be connected before it can be used.",
|
|
651
|
+
);
|
|
652
|
+
});
|
|
653
|
+
|
|
654
|
+
test("managed: names the provider's active accounts when the requested account misses", async () => {
|
|
655
|
+
mockProvider!.managedServiceConfigKey = "google-oauth";
|
|
656
|
+
mockPlatformClient = clientReturning([
|
|
657
|
+
{ id: "conn-personal", account_label: "user@example.com" },
|
|
658
|
+
{ id: "conn-work", account_label: "other@example.org" },
|
|
659
|
+
]);
|
|
660
|
+
|
|
661
|
+
let message = "";
|
|
662
|
+
try {
|
|
663
|
+
await resolveOAuthConnection("google", {
|
|
664
|
+
account: "missing@example.com",
|
|
665
|
+
});
|
|
666
|
+
} catch (error) {
|
|
667
|
+
message = (error as Error).message;
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
expect(message).toContain('account "missing@example.com"');
|
|
671
|
+
expect(message).toContain(
|
|
672
|
+
"Active google connections: user@example.com, other@example.org",
|
|
673
|
+
);
|
|
674
|
+
expect(message).toContain("Check the account spelling.");
|
|
675
|
+
});
|
|
676
|
+
});
|
|
677
|
+
|
|
678
|
+
describe("formatNoConnectionError", () => {
|
|
679
|
+
test("appends available account labels when the provider has active connections", () => {
|
|
680
|
+
// The requested account is a one-letter misspelling of an active one.
|
|
681
|
+
const message = formatNoConnectionError({
|
|
682
|
+
provider: "outlook",
|
|
683
|
+
account: "usr@example.com",
|
|
684
|
+
availableLabels: ["user@example.com", "other@example.org"],
|
|
685
|
+
});
|
|
686
|
+
expect(message).toBe(
|
|
687
|
+
'No active OAuth connection found for provider "outlook" with account ' +
|
|
688
|
+
'"usr@example.com". Active outlook connections: user@example.com, ' +
|
|
689
|
+
"other@example.org. Check the account spelling.",
|
|
690
|
+
);
|
|
691
|
+
});
|
|
692
|
+
|
|
693
|
+
test("keeps the plain message shape when no active connections exist", () => {
|
|
694
|
+
const message = formatNoConnectionError({
|
|
695
|
+
provider: "outlook",
|
|
696
|
+
account: "user@example.com",
|
|
697
|
+
availableLabels: [],
|
|
698
|
+
});
|
|
699
|
+
expect(message).toBe(
|
|
700
|
+
'No active OAuth connection found for provider "outlook" with account ' +
|
|
701
|
+
'"user@example.com". The outlook service needs to be connected before ' +
|
|
702
|
+
"it can be used.",
|
|
703
|
+
);
|
|
704
|
+
});
|
|
705
|
+
|
|
706
|
+
test("includes both account and client ID qualifiers when present", () => {
|
|
707
|
+
const message = formatNoConnectionError({
|
|
708
|
+
provider: "outlook",
|
|
709
|
+
account: "user@example.com",
|
|
710
|
+
clientId: "client-1",
|
|
711
|
+
availableLabels: [],
|
|
712
|
+
});
|
|
713
|
+
expect(message).toContain(
|
|
714
|
+
'with account "user@example.com" and client ID "client-1"',
|
|
715
|
+
);
|
|
716
|
+
});
|
|
717
|
+
});
|
|
718
|
+
|
|
579
719
|
describe("resolveEffectiveBaseUrl", () => {
|
|
580
720
|
const fallback = "https://login.salesforce.com";
|
|
581
721
|
|
|
@@ -147,15 +147,18 @@ export async function resolveOAuthConnectionWithMeta(
|
|
|
147
147
|
|
|
148
148
|
const candidates = getActiveConnections(provider, { clientId, account });
|
|
149
149
|
if (candidates.length === 0) {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
150
|
+
// When a filter produced zero matches, enumerate the provider's other
|
|
151
|
+
// active connections so the error can name the accounts that DO exist —
|
|
152
|
+
// a one-letter account typo should be self-correctable, not read as a
|
|
153
|
+
// disconnection.
|
|
154
|
+
const availableLabels =
|
|
155
|
+
account || clientId
|
|
156
|
+
? getActiveConnections(provider).map(
|
|
157
|
+
(row) => (row.accountInfo as string | null) ?? (row.id as string),
|
|
158
|
+
)
|
|
159
|
+
: [];
|
|
157
160
|
throw new Error(
|
|
158
|
-
|
|
161
|
+
formatNoConnectionError({ provider, account, clientId, availableLabels }),
|
|
159
162
|
);
|
|
160
163
|
}
|
|
161
164
|
|
|
@@ -365,8 +368,11 @@ async function resolvePlatformConnectionId(
|
|
|
365
368
|
accountIdentifier: account,
|
|
366
369
|
});
|
|
367
370
|
|
|
371
|
+
// Holds the provider's full active-connection list once a filtered lookup
|
|
372
|
+
// comes back empty, so the no-match error can name the accounts that exist.
|
|
373
|
+
let unfilteredConnections: PlatformConnectionEntry[] | undefined;
|
|
368
374
|
if (account && connections.length === 0) {
|
|
369
|
-
|
|
375
|
+
unfilteredConnections = await fetchPlatformConnections({
|
|
370
376
|
client,
|
|
371
377
|
provider,
|
|
372
378
|
});
|
|
@@ -377,10 +383,11 @@ async function resolvePlatformConnectionId(
|
|
|
377
383
|
}
|
|
378
384
|
|
|
379
385
|
if (connections.length === 0) {
|
|
386
|
+
const availableLabels = (unfilteredConnections ?? []).map(
|
|
387
|
+
platformConnectionLabel,
|
|
388
|
+
);
|
|
380
389
|
throw new Error(
|
|
381
|
-
|
|
382
|
-
(account ? ` with account "${account}"` : "") +
|
|
383
|
-
`. The ${provider} service needs to be connected.`,
|
|
390
|
+
formatNoConnectionError({ provider, account, availableLabels }),
|
|
384
391
|
);
|
|
385
392
|
}
|
|
386
393
|
|
|
@@ -487,6 +494,35 @@ function parseGrantedScopes(raw: string | null | undefined): string[] {
|
|
|
487
494
|
}
|
|
488
495
|
}
|
|
489
496
|
|
|
497
|
+
/**
|
|
498
|
+
* Actionable error thrown when no active connection matches the requested
|
|
499
|
+
* provider (optionally narrowed by account/clientId).
|
|
500
|
+
*
|
|
501
|
+
* When the provider has other active connections whose labels are known, the
|
|
502
|
+
* message names them so a mistyped account can be self-corrected rather than
|
|
503
|
+
* mistaken for a disconnection. Labels are the user's own account identifiers
|
|
504
|
+
* that already appear in logs — nothing beyond them is surfaced. When no other
|
|
505
|
+
* active connection exists, the message keeps the "needs to be connected" shape.
|
|
506
|
+
*/
|
|
507
|
+
export function formatNoConnectionError(params: {
|
|
508
|
+
provider: string;
|
|
509
|
+
account?: string;
|
|
510
|
+
clientId?: string;
|
|
511
|
+
availableLabels: string[];
|
|
512
|
+
}): string {
|
|
513
|
+
const { provider, account, clientId, availableLabels } = params;
|
|
514
|
+
const filters = [
|
|
515
|
+
account && `account "${account}"`,
|
|
516
|
+
clientId && `client ID "${clientId}"`,
|
|
517
|
+
].filter(Boolean);
|
|
518
|
+
const qualifier = filters.length ? ` with ${filters.join(" and ")}` : "";
|
|
519
|
+
const base = `No active OAuth connection found for provider "${provider}"${qualifier}.`;
|
|
520
|
+
if (availableLabels.length > 0) {
|
|
521
|
+
return `${base} Active ${provider} connections: ${availableLabels.join(", ")}. Check the account spelling.`;
|
|
522
|
+
}
|
|
523
|
+
return `${base} The ${provider} service needs to be connected before it can be used.`;
|
|
524
|
+
}
|
|
525
|
+
|
|
490
526
|
/** Actionable error shown when a connection is missing required scopes. */
|
|
491
527
|
function missingScopesMessage(
|
|
492
528
|
provider: string,
|
|
@@ -40,7 +40,7 @@ import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
|
40
40
|
import { join } from "node:path";
|
|
41
41
|
|
|
42
42
|
import type { EmbeddingProviderName } from "../../../persistence/embeddings/embedding-types.js";
|
|
43
|
-
import { getDataDir } from "
|
|
43
|
+
import { getDataDir } from "./paths.js";
|
|
44
44
|
|
|
45
45
|
/** Persisted anisotropy fit for a single (provider, model, dim) tuple. */
|
|
46
46
|
export interface AnisotropyCalibration {
|
|
@@ -2,8 +2,8 @@ import { readFileSync, statSync } from "node:fs";
|
|
|
2
2
|
|
|
3
3
|
import type { MemoryConfig } from "../../../config/schemas/memory.js";
|
|
4
4
|
import { MemoryConfigSchema } from "../../../config/schemas/memory.js";
|
|
5
|
-
import { getWorkspaceConfigPath } from "../../../util/platform.js";
|
|
6
5
|
import { getLogger } from "./logging.js";
|
|
6
|
+
import { getWorkspaceConfigPath } from "./paths.js";
|
|
7
7
|
|
|
8
8
|
const log = getLogger("memory-config");
|
|
9
9
|
|
|
@@ -33,9 +33,9 @@ import {
|
|
|
33
33
|
memoryGraphNodes,
|
|
34
34
|
memorySegments,
|
|
35
35
|
} from "../../../../persistence/schema/index.js";
|
|
36
|
-
import { getWorkspaceDir } from "../../../../util/platform.js";
|
|
37
36
|
import { resolveQdrantUrl } from "../embeddings.js";
|
|
38
37
|
import { getLogger } from "../logging.js";
|
|
38
|
+
import { getWorkspaceDir } from "../paths.js";
|
|
39
39
|
import { runGraphExtraction } from "./extraction.js";
|
|
40
40
|
import { countNodes } from "./store.js";
|
|
41
41
|
|
|
@@ -14,7 +14,7 @@ import { getConfiguredProvider } from "@vellumai/plugin-api";
|
|
|
14
14
|
|
|
15
15
|
import type { AssistantConfig } from "../../../../config/types.js";
|
|
16
16
|
import { getDb } from "../../../../persistence/db-connection.js";
|
|
17
|
-
import { BackendUnavailableError } from "
|
|
17
|
+
import { BackendUnavailableError } from "../host-utils.js";
|
|
18
18
|
import { extractToolUse, userMessage } from "../llm-helpers.js";
|
|
19
19
|
import { getLogger } from "../logging.js";
|
|
20
20
|
import {
|
|
@@ -19,9 +19,9 @@ import { generateSparseEmbedding } from "../../../../persistence/embeddings/embe
|
|
|
19
19
|
import type { QdrantSparseVector } from "../../../../persistence/embeddings/qdrant-client.js";
|
|
20
20
|
import { conversations } from "../../../../persistence/schema/conversations.js";
|
|
21
21
|
import { memorySummaries } from "../../../../persistence/schema/index.js";
|
|
22
|
-
import { getWorkspaceDir } from "../../../../util/platform.js";
|
|
23
22
|
import { getLogger } from "../logging.js";
|
|
24
23
|
import { wrapMemoryBlock } from "../memory-marker.js";
|
|
24
|
+
import { getWorkspaceDir } from "../paths.js";
|
|
25
25
|
import {
|
|
26
26
|
clearEverInjected as clearV2EverInjected,
|
|
27
27
|
hydrate as hydrateV2State,
|
|
@@ -84,6 +84,16 @@ export function getLiveGraphMemory(
|
|
|
84
84
|
return liveByConversation.get(conversationId);
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
+
/**
|
|
88
|
+
* Full output of a single memory-graph retrieval — the object returned by
|
|
89
|
+
* {@link ConversationGraphMemory.prepareMemory} (injected messages, query
|
|
90
|
+
* vectors, metrics). The plugin's user-prompt-submit hook consumes these
|
|
91
|
+
* fields to drive PKB hint search and runtime injection.
|
|
92
|
+
*/
|
|
93
|
+
export type GraphMemoryResult = Awaited<
|
|
94
|
+
ReturnType<ConversationGraphMemory["prepareMemory"]>
|
|
95
|
+
>;
|
|
96
|
+
|
|
87
97
|
/**
|
|
88
98
|
* Manages memory graph state for a single conversation.
|
|
89
99
|
* Create one per Conversation instance. Persists across turns.
|
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
conversations,
|
|
23
23
|
messages,
|
|
24
24
|
} from "../../../../persistence/schema/index.js";
|
|
25
|
-
import { BackendUnavailableError } from "
|
|
25
|
+
import { BackendUnavailableError } from "../host-utils.js";
|
|
26
26
|
import { buildIdentityContext } from "../identity-context.js";
|
|
27
27
|
import { extractToolUse, userMessage } from "../llm-helpers.js";
|
|
28
28
|
import { getLogger } from "../logging.js";
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
import { getConfiguredProvider } from "@vellumai/plugin-api";
|
|
13
13
|
|
|
14
14
|
import type { AssistantConfig } from "../../../../config/types.js";
|
|
15
|
-
import { BackendUnavailableError } from "
|
|
15
|
+
import { BackendUnavailableError } from "../host-utils.js";
|
|
16
16
|
import { extractToolUse, userMessage } from "../llm-helpers.js";
|
|
17
17
|
import { getLogger } from "../logging.js";
|
|
18
18
|
import { queryNodes, updateNode } from "./store.js";
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
import { getConfiguredProvider } from "@vellumai/plugin-api";
|
|
12
12
|
|
|
13
13
|
import type { AssistantConfig } from "../../../../config/types.js";
|
|
14
|
-
import { BackendUnavailableError } from "
|
|
14
|
+
import { BackendUnavailableError } from "../host-utils.js";
|
|
15
15
|
import { extractToolUse, userMessage } from "../llm-helpers.js";
|
|
16
16
|
import { getLogger } from "../logging.js";
|
|
17
17
|
import { createEdge, createNode, queryNodes } from "./store.js";
|
|
@@ -11,9 +11,9 @@ import { join } from "node:path";
|
|
|
11
11
|
|
|
12
12
|
import type { AssistantConfig } from "../../../../config/types.js";
|
|
13
13
|
import { enqueueMemoryJob } from "../../../../persistence/jobs-store.js";
|
|
14
|
-
import { getWorkspaceDir } from "../../../../util/platform.js";
|
|
15
14
|
import { enqueuePkbIndexJob } from "../jobs/embed-pkb-file.js";
|
|
16
15
|
import { getLogger } from "../logging.js";
|
|
16
|
+
import { getWorkspaceDir } from "../paths.js";
|
|
17
17
|
import { deleteNode, queryNodes, recordNodeEdit, updateNode } from "./store.js";
|
|
18
18
|
|
|
19
19
|
const log = getLogger("graph-tool-handlers");
|
|
@@ -18,7 +18,7 @@ const RECALL_DEPTHS = ["fast", "standard", "deep"] as const;
|
|
|
18
18
|
export const graphRecallDefinition = {
|
|
19
19
|
name: "recall",
|
|
20
20
|
description:
|
|
21
|
-
'Search local information the moment you feel uncertain. Use recall for memory, past conversations, and workspace files — before you guess, before you ask, before you hedge. Auto-injection is incomplete by design; it surfaces patterns, not the specifics you need to answer well. If you catch yourself reaching for "I think", "I believe", "if I remember", "didn\'t we", "last time" — that\'s the signal. Recall. If a turn references someone, a place, a decision, a document, or prior work you should be able to find locally — recall. Call it multiple times per conversation if the turn warrants it. Be specific in your query for best results.',
|
|
21
|
+
'Search local information the moment you feel uncertain. Use recall for memory, past conversations, and workspace files — before you guess, before you ask, before you hedge. Auto-injection is incomplete by design; it surfaces patterns, not the specifics you need to answer well. If you catch yourself reaching for "I think", "I believe", "if I remember", "didn\'t we", "last time" — that\'s the signal. Recall. If a turn references someone, a place, a decision, a document, or prior work you should be able to find locally — recall. Call it multiple times per conversation if the turn warrants it. Be specific in your query for best results. Results reflect what was true when the memory was written — do not use recall alone to answer questions about current system state (account connections, watchers, service health); verify those with live checks.',
|
|
22
22
|
input_schema: {
|
|
23
23
|
type: "object",
|
|
24
24
|
properties: {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
import { isMemoryV3Live } from "../../../../config/memory-v3-gate.js";
|
|
19
19
|
import type { AssistantConfig } from "../../../../config/types.js";
|
|
20
20
|
import { getDb } from "../../../../persistence/db-connection.js";
|
|
21
|
-
import { getWorkspaceDir } from "
|
|
21
|
+
import { getWorkspaceDir } from "../paths.js";
|
|
22
22
|
import { getPageIndex, type PageIndexEntry } from "../v2/page-index.js";
|
|
23
23
|
import { readPage, renderPageContent } from "../v2/page-store.js";
|
|
24
24
|
import { isSkillSlug } from "../v2/skill-store.js";
|
|
@@ -72,7 +72,9 @@ function undirectedKey(a: string, b: string): string {
|
|
|
72
72
|
function humanizeSlug(slug: string): string {
|
|
73
73
|
const last = slug.split("/").pop() ?? slug;
|
|
74
74
|
const words = last.replace(/[-_]+/g, " ").trim();
|
|
75
|
-
if (!words) {
|
|
75
|
+
if (!words) {
|
|
76
|
+
return slug;
|
|
77
|
+
}
|
|
76
78
|
return words.replace(/\b\w/g, (c) => c.toUpperCase());
|
|
77
79
|
}
|
|
78
80
|
|
|
@@ -115,9 +117,11 @@ export interface AssembleMemoryGraphInput {
|
|
|
115
117
|
* Edges referencing a slug with no node entry are dropped. Node `weight` is the
|
|
116
118
|
* resulting degree, and drives the truncation ranking.
|
|
117
119
|
*/
|
|
118
|
-
export function assembleMemoryGraph(
|
|
119
|
-
|
|
120
|
-
|
|
120
|
+
export function assembleMemoryGraph(input: AssembleMemoryGraphInput): {
|
|
121
|
+
nodes: MemoryGraphNode[];
|
|
122
|
+
edges: MemoryGraphEdge[];
|
|
123
|
+
truncated?: boolean;
|
|
124
|
+
} {
|
|
121
125
|
const { entries, staticAdjacency, learnedAdjacency } = input;
|
|
122
126
|
const maxNodes = input.maxNodes ?? DEFAULT_MAX_NODES;
|
|
123
127
|
|
|
@@ -132,16 +136,22 @@ export function assembleMemoryGraph(
|
|
|
132
136
|
|
|
133
137
|
// Static link edges — directed, authored/structural.
|
|
134
138
|
for (const [source, out] of staticAdjacency) {
|
|
135
|
-
if (!nodeIds.has(source)) {
|
|
139
|
+
if (!nodeIds.has(source)) {
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
136
142
|
for (const [target, description] of out) {
|
|
137
|
-
if (!nodeIds.has(target)) {
|
|
143
|
+
if (!nodeIds.has(target)) {
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
138
146
|
const edge: MemoryGraphEdge = {
|
|
139
147
|
source,
|
|
140
148
|
target,
|
|
141
149
|
kind: "link",
|
|
142
150
|
directed: true,
|
|
143
151
|
};
|
|
144
|
-
if (description) {
|
|
152
|
+
if (description) {
|
|
153
|
+
edge.description = description;
|
|
154
|
+
}
|
|
145
155
|
edges.push(edge);
|
|
146
156
|
staticPairs.add(undirectedKey(source, target));
|
|
147
157
|
bump(source);
|
|
@@ -153,11 +163,17 @@ export function assembleMemoryGraph(
|
|
|
153
163
|
if (learnedAdjacency) {
|
|
154
164
|
const emitted = new Set<string>();
|
|
155
165
|
for (const [source, out] of learnedAdjacency) {
|
|
156
|
-
if (!nodeIds.has(source)) {
|
|
166
|
+
if (!nodeIds.has(source)) {
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
157
169
|
for (const target of out.keys()) {
|
|
158
|
-
if (!nodeIds.has(target)) {
|
|
170
|
+
if (!nodeIds.has(target)) {
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
159
173
|
const key = undirectedKey(source, target);
|
|
160
|
-
if (staticPairs.has(key) || emitted.has(key)) {
|
|
174
|
+
if (staticPairs.has(key) || emitted.has(key)) {
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
161
177
|
emitted.add(key);
|
|
162
178
|
const [a, b] = key.split("\t") as [string, string];
|
|
163
179
|
edges.push({ source: a, target: b, kind: "learned", directed: false });
|
|
@@ -174,8 +190,12 @@ export function assembleMemoryGraph(
|
|
|
174
190
|
kind: nodeKind(entry),
|
|
175
191
|
weight: degree.get(entry.slug) ?? 0,
|
|
176
192
|
};
|
|
177
|
-
if (entry.summary) {
|
|
178
|
-
|
|
193
|
+
if (entry.summary) {
|
|
194
|
+
node.summary = entry.summary;
|
|
195
|
+
}
|
|
196
|
+
if (entry.modifiedAt > 0) {
|
|
197
|
+
node.updatedAtMs = entry.modifiedAt;
|
|
198
|
+
}
|
|
179
199
|
return node;
|
|
180
200
|
});
|
|
181
201
|
|
|
@@ -218,7 +238,9 @@ export async function getMemoryGraph(
|
|
|
218
238
|
// numeric fallbacks.
|
|
219
239
|
const pageRaw = async (slug: Slug): Promise<string> => {
|
|
220
240
|
const page = await readPage(workspaceDir, slug);
|
|
221
|
-
if (!page) {
|
|
241
|
+
if (!page) {
|
|
242
|
+
throw new Error(`page not found: ${slug}`);
|
|
243
|
+
}
|
|
222
244
|
return renderPageContent(page);
|
|
223
245
|
};
|
|
224
246
|
|
|
@@ -236,7 +258,10 @@ export async function getMemoryGraph(
|
|
|
236
258
|
{
|
|
237
259
|
halfLifeMs: learned.halfLifeDays * DAY_MS,
|
|
238
260
|
minCount: Math.max(1, learned.minCount * GRAPH_LEARNED_MIN_COUNT_FACTOR),
|
|
239
|
-
npmiFloor: Math.max(
|
|
261
|
+
npmiFloor: Math.max(
|
|
262
|
+
0,
|
|
263
|
+
learned.npmiFloor * GRAPH_LEARNED_NPMI_FLOOR_FACTOR,
|
|
264
|
+
),
|
|
240
265
|
maxPerPage: Math.max(learned.maxPerPage, GRAPH_LEARNED_MIN_MAX_PER_PAGE),
|
|
241
266
|
now: Date.now(),
|
|
242
267
|
windowMs: LEARNED_EDGES_WINDOW_DAYS * DAY_MS,
|
|
@@ -271,6 +296,8 @@ export async function getMemoryGraphNode(
|
|
|
271
296
|
return { found: false };
|
|
272
297
|
}
|
|
273
298
|
const page = await readPage(getWorkspaceDir(), id).catch(() => null);
|
|
274
|
-
if (!page) {
|
|
299
|
+
if (!page) {
|
|
300
|
+
return { found: false };
|
|
301
|
+
}
|
|
275
302
|
return { found: true, title: humanizeSlug(id), content: page.body };
|
|
276
303
|
}
|
|
@@ -45,7 +45,7 @@ import {
|
|
|
45
45
|
import type { MemoryRecalled } from "../../../../daemon/message-types/memory.js";
|
|
46
46
|
import { resolveTrustClass } from "../../../../daemon/trust-context.js";
|
|
47
47
|
import { broadcastMessage } from "../../../../runtime/assistant-event-hub.js";
|
|
48
|
-
import type { GraphMemoryResult } from "
|
|
48
|
+
import type { GraphMemoryResult } from "../graph/conversation-graph-memory.js";
|
|
49
49
|
import { recordMemoryRecallLog } from "../memory-recall-log-store.js";
|
|
50
50
|
import { MEMORY_V3_INJECTED_BLOCK_METADATA_KEY } from "../v3/ever-injected-store.js";
|
|
51
51
|
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The memory plugin's single channel for generic host utilities. Every module
|
|
3
|
+
* in this plugin obtains these helpers here rather than importing the host
|
|
4
|
+
* `util/*` modules directly, so the host imports below are the plugin's sole
|
|
5
|
+
* util escapes (tracked by `plugin-import-boundary-guard.test.ts`), mirroring
|
|
6
|
+
* `logging.ts` and `paths.ts`.
|
|
7
|
+
*
|
|
8
|
+
* Forwarding (not copying) is deliberate: `BackendUnavailableError` identity
|
|
9
|
+
* must be shared with the host — `persistence/job-utils` classifies plugin-
|
|
10
|
+
* thrown errors via `instanceof` — and `isAbortReason` must agree with the
|
|
11
|
+
* host's abort-reason tagging. The pure helpers forward alongside them so the
|
|
12
|
+
* plugin has exactly one file to re-home per concern (own the copy, or a
|
|
13
|
+
* contract facet) if memory ever builds as an external plugin.
|
|
14
|
+
*
|
|
15
|
+
* Namespace imports keep this module loadable under tests that mock a host
|
|
16
|
+
* util with a subset of its exports; each wrapper resolves its function at
|
|
17
|
+
* call time, so `mock.module` interception keeps working through the waist.
|
|
18
|
+
*/
|
|
19
|
+
import type { AbortReason } from "../../../util/abort-reasons.js";
|
|
20
|
+
import * as hostAbortReasons from "../../../util/abort-reasons.js";
|
|
21
|
+
import * as hostLogRedact from "../../../util/log-redact.js";
|
|
22
|
+
import * as hostProcessLiveness from "../../../util/process-liveness.js";
|
|
23
|
+
import * as hostRetry from "../../../util/retry.js";
|
|
24
|
+
import type { SqliteRetryOptions } from "../../../util/sqlite-retry.js";
|
|
25
|
+
import * as hostSqliteRetry from "../../../util/sqlite-retry.js";
|
|
26
|
+
import * as hostStripCommentLines from "../../../util/strip-comment-lines.js";
|
|
27
|
+
import * as hostTruncate from "../../../util/truncate.js";
|
|
28
|
+
import * as hostWorkerMemory from "../../../util/worker-memory.js";
|
|
29
|
+
|
|
30
|
+
export { BackendUnavailableError } from "../../../util/errors.js";
|
|
31
|
+
export { PromiseGuard } from "../../../util/promise-guard.js";
|
|
32
|
+
|
|
33
|
+
export function isAbortReason(value: unknown): value is AbortReason {
|
|
34
|
+
return hostAbortReasons.isAbortReason(value);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function redactLogString(value: string): string {
|
|
38
|
+
return hostLogRedact.redactLogString(value);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function isProcessAlive(pid: number): boolean {
|
|
42
|
+
return hostProcessLiveness.isProcessAlive(pid);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function computeRetryDelay(
|
|
46
|
+
attempt: number,
|
|
47
|
+
baseDelayMs?: number,
|
|
48
|
+
): number {
|
|
49
|
+
return baseDelayMs === undefined
|
|
50
|
+
? hostRetry.computeRetryDelay(attempt)
|
|
51
|
+
: hostRetry.computeRetryDelay(attempt, baseDelayMs);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function abortableSleep(
|
|
55
|
+
ms: number,
|
|
56
|
+
signal?: AbortSignal,
|
|
57
|
+
): Promise<void> {
|
|
58
|
+
return hostRetry.abortableSleep(ms, signal);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function withSqliteRetry<T>(
|
|
62
|
+
fn: () => T | Promise<T>,
|
|
63
|
+
options: SqliteRetryOptions,
|
|
64
|
+
): Promise<T> {
|
|
65
|
+
return hostSqliteRetry.withSqliteRetry(fn, options);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function stripCommentLines(content: string): string {
|
|
69
|
+
return hostStripCommentLines.stripCommentLines(content);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function truncate(str: string, maxLen: number, suffix?: string): string {
|
|
73
|
+
return suffix === undefined
|
|
74
|
+
? hostTruncate.truncate(str, maxLen)
|
|
75
|
+
: hostTruncate.truncate(str, maxLen, suffix);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function workerMemoryEnv(): Record<string, string | undefined> {
|
|
79
|
+
return hostWorkerMemory.workerMemoryEnv();
|
|
80
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { resolveGuardianPersona } from "../../../prompts/persona-resolver.js";
|
|
2
2
|
import { readPromptFile } from "../../../prompts/system-prompt.js";
|
|
3
3
|
import { isTemplateContent } from "../../../prompts/template-detection.js";
|
|
4
|
-
import { getWorkspacePromptPath } from "
|
|
4
|
+
import { getWorkspacePromptPath } from "./paths.js";
|
|
5
5
|
|
|
6
6
|
const IDENTITY_PROMPT_FILES = ["IDENTITY.md", "SOUL.md"] as const;
|
|
7
7
|
|
|
@@ -25,7 +25,6 @@ import { getInContextPkbPaths } from "../../../daemon/pkb-context-tracker.js";
|
|
|
25
25
|
import { buildPkbReminder } from "../../../daemon/pkb-reminder-builder.js";
|
|
26
26
|
import { isPersonalMemoryAllowed } from "../../../daemon/trust-context.js";
|
|
27
27
|
import type { TrustContext } from "../../../daemon/trust-context-types.js";
|
|
28
|
-
import { getSandboxWorkingDir } from "../../../util/platform.js";
|
|
29
28
|
import {
|
|
30
29
|
type InjectionBlock,
|
|
31
30
|
type Injector,
|
|
@@ -36,6 +35,7 @@ import { DEFAULT_INJECTOR_ORDER } from "../injector-order.js";
|
|
|
36
35
|
import { getMemoryConfig } from "./config.js";
|
|
37
36
|
import { getLiveGraphMemory } from "./graph/conversation-graph-memory.js";
|
|
38
37
|
import { getLogger } from "./logging.js";
|
|
38
|
+
import { getSandboxWorkingDir } from "./paths.js";
|
|
39
39
|
import { getPkbAutoInjectList } from "./pkb/autoinject.js";
|
|
40
40
|
import { readPkbContext } from "./pkb/context.js";
|
|
41
41
|
import { searchPkbFiles } from "./pkb/pkb-search.js";
|
|
@@ -38,11 +38,11 @@ import {
|
|
|
38
38
|
type MemoryJob,
|
|
39
39
|
} from "../../../../persistence/jobs-store.js";
|
|
40
40
|
import { memoryEmbeddings } from "../../../../persistence/schema/index.js";
|
|
41
|
-
import { BackendUnavailableError } from "../../../../util/errors.js";
|
|
42
|
-
import { getWorkspaceDir } from "../../../../util/platform.js";
|
|
43
41
|
import { applyCorrectionIfCalibrated } from "../anisotropy.js";
|
|
44
42
|
import { embedWithBackend } from "../embeddings.js";
|
|
43
|
+
import { BackendUnavailableError } from "../host-utils.js";
|
|
45
44
|
import { getLogger } from "../logging.js";
|
|
45
|
+
import { getWorkspaceDir } from "../paths.js";
|
|
46
46
|
import { readPage } from "../v2/page-store.js";
|
|
47
47
|
import {
|
|
48
48
|
deleteConceptPageEmbedding,
|