@indexnetwork/protocol 3.12.0-rc.287.1 → 4.0.0-rc.289.1
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/dist/chat/chat.prompt.js +5 -5
- package/dist/chat/chat.prompt.js.map +1 -1
- package/dist/chat/tests/chat.graph.mocks.d.ts +1 -7
- package/dist/chat/tests/chat.graph.mocks.d.ts.map +1 -1
- package/dist/chat/tests/chat.graph.mocks.js +1 -2
- package/dist/chat/tests/chat.graph.mocks.js.map +1 -1
- package/dist/{profile/profile.enricher.d.ts → enrichment/enrichment.enricher.d.ts} +1 -1
- package/dist/enrichment/enrichment.enricher.d.ts.map +1 -0
- package/dist/{profile/profile.enricher.js → enrichment/enrichment.enricher.js} +1 -1
- package/dist/enrichment/enrichment.enricher.js.map +1 -0
- package/dist/{profile/profile.generator.d.ts → enrichment/enrichment.generator.d.ts} +3 -3
- package/dist/enrichment/enrichment.generator.d.ts.map +1 -0
- package/dist/{profile/profile.generator.js → enrichment/enrichment.generator.js} +6 -6
- package/dist/enrichment/enrichment.generator.js.map +1 -0
- package/dist/{profile/profile.graph.d.ts → enrichment/enrichment.graph.d.ts} +124 -191
- package/dist/enrichment/enrichment.graph.d.ts.map +1 -0
- package/dist/{profile/profile.graph.js → enrichment/enrichment.graph.js} +33 -241
- package/dist/enrichment/enrichment.graph.js.map +1 -0
- package/dist/{profile/profile.state.d.ts → enrichment/enrichment.state.d.ts} +31 -19
- package/dist/enrichment/enrichment.state.d.ts.map +1 -0
- package/dist/{profile/profile.state.js → enrichment/enrichment.state.js} +5 -13
- package/dist/enrichment/enrichment.state.js.map +1 -0
- package/dist/enrichment/enrichment.tools.d.ts +3 -0
- package/dist/enrichment/enrichment.tools.d.ts.map +1 -0
- package/dist/{profile/profile.tools.js → enrichment/enrichment.tools.js} +74 -87
- package/dist/enrichment/enrichment.tools.js.map +1 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/intent/intent.tools.js +3 -3
- package/dist/intent/intent.tools.js.map +1 -1
- package/dist/opportunity/opportunity.graph.d.ts +1 -7
- package/dist/opportunity/opportunity.graph.d.ts.map +1 -1
- package/dist/opportunity/opportunity.graph.js +5 -22
- package/dist/opportunity/opportunity.graph.js.map +1 -1
- package/dist/opportunity/opportunity.presenter.d.ts.map +1 -1
- package/dist/opportunity/opportunity.presenter.js +3 -11
- package/dist/opportunity/opportunity.presenter.js.map +1 -1
- package/dist/opportunity/opportunity.state.d.ts +2 -8
- package/dist/opportunity/opportunity.state.d.ts.map +1 -1
- package/dist/opportunity/opportunity.state.js.map +1 -1
- package/dist/questioner/questioner.presets.js +1 -1
- package/dist/questioner/questioner.presets.js.map +1 -1
- package/dist/questioner/questioner.tools.d.ts +1 -1
- package/dist/questioner/questioner.tools.js +2 -2
- package/dist/questioner/questioner.tools.js.map +1 -1
- package/dist/shared/agent/tool.factory.js +6 -6
- package/dist/shared/agent/tool.factory.js.map +1 -1
- package/dist/shared/agent/tool.helpers.d.ts +8 -8
- package/dist/shared/agent/tool.helpers.d.ts.map +1 -1
- package/dist/shared/agent/tool.helpers.js.map +1 -1
- package/dist/shared/agent/tool.registry.js +2 -2
- package/dist/shared/agent/tool.registry.js.map +1 -1
- package/dist/shared/hyde/hyde.graph.d.ts +6 -6
- package/dist/shared/hyde/hyde.state.d.ts +2 -2
- package/dist/shared/hyde/hyde.state.js.map +1 -1
- package/dist/shared/interfaces/database.interface.d.ts +14 -14
- package/dist/shared/interfaces/database.interface.d.ts.map +1 -1
- package/dist/shared/interfaces/database.interface.js.map +1 -1
- package/dist/shared/interfaces/{profile-run.interface.d.ts → enrichment-run.interface.d.ts} +21 -21
- package/dist/shared/interfaces/enrichment-run.interface.d.ts.map +1 -0
- package/dist/shared/interfaces/enrichment-run.interface.js +2 -0
- package/dist/shared/interfaces/enrichment-run.interface.js.map +1 -0
- package/dist/shared/schemas/discovery-question.schema.d.ts +2 -2
- package/dist/shared/schemas/identity.schema.d.ts +45 -0
- package/dist/shared/schemas/identity.schema.d.ts.map +1 -0
- package/dist/shared/schemas/identity.schema.js +20 -0
- package/dist/shared/schemas/identity.schema.js.map +1 -0
- package/dist/shared/schemas/question.schema.d.ts +4 -4
- package/dist/shared/schemas/question.schema.d.ts.map +1 -1
- package/dist/shared/schemas/question.schema.js +1 -1
- package/dist/shared/schemas/question.schema.js.map +1 -1
- package/package.json +1 -1
- package/dist/profile/profile.enricher.d.ts.map +0 -1
- package/dist/profile/profile.enricher.js.map +0 -1
- package/dist/profile/profile.generator.d.ts.map +0 -1
- package/dist/profile/profile.generator.js.map +0 -1
- package/dist/profile/profile.graph.d.ts.map +0 -1
- package/dist/profile/profile.graph.js.map +0 -1
- package/dist/profile/profile.state.d.ts.map +0 -1
- package/dist/profile/profile.state.js.map +0 -1
- package/dist/profile/profile.tools.d.ts +0 -3
- package/dist/profile/profile.tools.d.ts.map +0 -1
- package/dist/profile/profile.tools.js.map +0 -1
- package/dist/shared/interfaces/profile-run.interface.d.ts.map +0 -1
- package/dist/shared/interfaces/profile-run.interface.js +0 -2
- package/dist/shared/interfaces/profile-run.interface.js.map +0 -1
- package/dist/shared/schemas/profile.schema.d.ts +0 -100
- package/dist/shared/schemas/profile.schema.d.ts.map +0 -1
- package/dist/shared/schemas/profile.schema.js +0 -26
- package/dist/shared/schemas/profile.schema.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enrichment.state.d.ts","sourceRoot":"/","sources":["enrichment/enrichment.state.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAEtE;;GAEG;AACH,eAAO,MAAM,oBAAoB;IAE/B;;OAEG;;;;;;IAKH;;;;;;OAMG;;IAMH;;;OAGG;;IAQH;;OAEG;;IAMH;;OAEG;;IAMH;;;;;OAKG;;IAMH;;OAEG;;;;;;;;;;;;;;;;;;;;;;;;;;IAMH;;OAEG;;IAMH;;;OAGG;;IAMH;;;OAGG;;IAQH;;OAEG;;IAQH;;;OAGG;;kBAES,OAAO;6BACI,OAAO;2BACT,OAAO;uBACX,OAAO;;kBAHZ,OAAO;6BACI,OAAO;2BACT,OAAO;uBACX,OAAO;;kBAHZ,OAAO;6BACI,OAAO;2BACT,OAAO;uBACX,OAAO;;IAMxB,sEAAsE;;IAMtE;;OAEG;;oBAEW,OAAO;kBACT;YACR,EAAE,CAAC,EAAE,MAAM,CAAC;YACZ,IAAI,EAAE,MAAM,CAAC;YACb,GAAG,EAAE,MAAM,CAAC;YACZ,QAAQ,EAAE,MAAM,CAAC;SAClB;kBACS,MAAM;;oBAPJ,OAAO;kBACT;YACR,EAAE,CAAC,EAAE,MAAM,CAAC;YACZ,IAAI,EAAE,MAAM,CAAC;YACb,GAAG,EAAE,MAAM,CAAC;YACZ,QAAQ,EAAE,MAAM,CAAC;SAClB;kBACS,MAAM;;oBAPJ,OAAO;kBACT;YACR,EAAE,CAAC,EAAE,MAAM,CAAC;YACZ,IAAI,EAAE,MAAM,CAAC;YACb,GAAG,EAAE,MAAM,CAAC;YACZ,QAAQ,EAAE,MAAM,CAAC;SAClB;kBACS,MAAM;;EAKlB,CAAC"}
|
|
@@ -2,7 +2,7 @@ import { Annotation } from "@langchain/langgraph";
|
|
|
2
2
|
/**
|
|
3
3
|
* The Graph State for Profile Generation.
|
|
4
4
|
*/
|
|
5
|
-
export const
|
|
5
|
+
export const EnrichmentGraphState = Annotation.Root({
|
|
6
6
|
// --- Inputs (Required at start) ---
|
|
7
7
|
/**
|
|
8
8
|
* The User ID to link the profile to.
|
|
@@ -12,9 +12,9 @@ export const ProfileGraphState = Annotation.Root({
|
|
|
12
12
|
/**
|
|
13
13
|
* Operation mode controls graph flow:
|
|
14
14
|
* - 'query': Fast path - only retrieve existing profile (no generation)
|
|
15
|
-
* - 'write':
|
|
16
|
-
* - 'generate': Auto-
|
|
17
|
-
*
|
|
15
|
+
* - 'write': Decompose provided/scraped input into premises
|
|
16
|
+
* - 'generate': Auto-enrich from user table data via enrichUserProfile Chat API,
|
|
17
|
+
* then decompose the enrichment into premises
|
|
18
18
|
*/
|
|
19
19
|
operationMode: Annotation({
|
|
20
20
|
reducer: (curr, next) => next ?? curr,
|
|
@@ -28,14 +28,6 @@ export const ProfileGraphState = Annotation.Root({
|
|
|
28
28
|
reducer: (curr, next) => next ?? curr,
|
|
29
29
|
default: () => false,
|
|
30
30
|
}),
|
|
31
|
-
/**
|
|
32
|
-
* Flag indicating the profile is being regenerated from aggregated premises.
|
|
33
|
-
* When true, `generate_profile` uses synthesis framing instead of "apply user request" framing.
|
|
34
|
-
*/
|
|
35
|
-
isAggregate: Annotation({
|
|
36
|
-
reducer: (curr, next) => next ?? curr,
|
|
37
|
-
default: () => false,
|
|
38
|
-
}),
|
|
39
31
|
// --- Intermediate State ---
|
|
40
32
|
/**
|
|
41
33
|
* Internal objective constructed from user data.
|
|
@@ -121,4 +113,4 @@ export const ProfileGraphState = Annotation.Root({
|
|
|
121
113
|
default: () => undefined,
|
|
122
114
|
}),
|
|
123
115
|
});
|
|
124
|
-
//# sourceMappingURL=
|
|
116
|
+
//# sourceMappingURL=enrichment.state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enrichment.state.js","sourceRoot":"/","sources":["enrichment/enrichment.state.ts"],"names":[],"mappings":"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","sourcesContent":["import { Annotation } from \"@langchain/langgraph\";\nimport type { UserIdentity } from \"../shared/schemas/identity.schema.js\";\nimport type { DebugMetaAgent } from '../chat/chat-streaming.types.js';\n\n/**\n * The Graph State for Profile Generation.\n */\nexport const EnrichmentGraphState = Annotation.Root({\n // --- Inputs (Required at start) ---\n /**\n * The User ID to link the profile to.\n */\n userId: Annotation<string>,\n\n // --- Control Fields (Operation Mode) ---\n\n /**\n * Operation mode controls graph flow:\n * - 'query': Fast path - only retrieve existing profile (no generation)\n * - 'write': Decompose provided/scraped input into premises\n * - 'generate': Auto-enrich from user table data via enrichUserProfile Chat API,\n * then decompose the enrichment into premises\n */\n operationMode: Annotation<'query' | 'write' | 'generate'>({\n reducer: (curr, next) => next ?? curr,\n default: () => 'write',\n }),\n\n /**\n * Flag to force profile regeneration even if profile exists.\n * When true with new input, the graph will re-generate and update the profile.\n */\n forceUpdate: Annotation<boolean>({\n reducer: (curr, next) => next ?? curr,\n default: () => false,\n }),\n\n // --- Intermediate State ---\n\n /**\n * Internal objective constructed from user data.\n */\n objective: Annotation<string | undefined>({\n reducer: (curr, next) => next,\n default: () => undefined,\n }),\n\n /**\n * Raw input data (either provided or scraped).\n */\n input: Annotation<string | undefined>({\n reducer: (curr, next) => next,\n default: () => undefined,\n }),\n\n /**\n * IDs of the user_socials records active during the current scrape/generate run.\n * Populated by scrapeNode and autoGenerateNode after getUserSocials is called.\n * Empty by default; read by decomposePremisesNode to set provenanceSource:\n * 'integration' + provenanceSourceId when premises derive from social enrichment.\n */\n activeSocialIds: Annotation<string[]>({\n reducer: (_, next) => next ?? [],\n default: () => [],\n }),\n\n /**\n * The generated or loaded profile document.\n */\n profile: Annotation<UserIdentity | undefined>({\n reducer: (curr, next) => next,\n default: () => undefined,\n }),\n\n /**\n * Flags to track what needs to be generated.\n */\n needsProfileGeneration: Annotation<boolean>({\n reducer: (curr, next) => next ?? curr,\n default: () => false,\n }),\n\n /**\n * Flag indicating that user information is insufficient for accurate profile generation.\n * When true, the graph should request additional information from the user.\n */\n needsUserInfo: Annotation<boolean>({\n reducer: (curr, next) => next ?? curr,\n default: () => false,\n }),\n\n /**\n * List of missing user information fields.\n * Used to construct a helpful clarification message.\n */\n missingUserInfo: Annotation<string[]>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n\n // --- Output ---\n\n /**\n * Error message if any step fails (non-fatal).\n */\n error: Annotation<string | undefined>({\n reducer: (curr, next) => next,\n default: () => undefined,\n }),\n\n // --- Operation Tracking (for transparency) ---\n\n /**\n * Tracks which operations were actually performed during this graph execution.\n * Used to provide explicit feedback to the user about what happened.\n */\n operationsPerformed: Annotation<{\n scraped?: boolean;\n decomposedPremises?: boolean;\n generatedProfile?: boolean;\n savedProfile?: boolean;\n }>({\n reducer: (curr, next) => ({ ...curr, ...next }),\n default: () => ({}),\n }),\n\n /** Timing records for each agent invocation within this graph run. */\n agentTimings: Annotation<DebugMetaAgent[]>({\n reducer: (acc, val) => [...acc, ...val],\n default: () => [],\n }),\n\n /**\n * Output for query mode: structured result for the tool to read.\n */\n readResult: Annotation<{\n hasProfile: boolean;\n profile?: {\n id?: string;\n name: string;\n bio: string;\n location: string;\n };\n message?: string;\n } | undefined>({\n reducer: (curr, next) => next,\n default: () => undefined,\n }),\n});\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enrichment.tools.d.ts","sourceRoot":"/","sources":["enrichment/enrichment.tools.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAuB,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAgCjG,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,0DAmtC3E"}
|
|
@@ -4,7 +4,7 @@ import { success, error, needsClarification, UUID_REGEX } from "../shared/agent/
|
|
|
4
4
|
import { protocolLogger } from "../shared/observability/protocol.logger.js";
|
|
5
5
|
import { socialsToEnrichmentRequest, detectSocialLabel } from "../shared/utils/social-label.js";
|
|
6
6
|
import { normalizeTelegramHandle } from "../shared/utils/telegram-handle.js";
|
|
7
|
-
import {
|
|
7
|
+
import { EnrichmentGenerator } from "./enrichment.generator.js";
|
|
8
8
|
import { invokeWithAbortSignal } from "../shared/agent/model-signal.js";
|
|
9
9
|
const logger = protocolLogger("ChatTools:Profile");
|
|
10
10
|
function isMeaningfulEnrichment(enrichment) {
|
|
@@ -20,7 +20,7 @@ const approvedProfileDraftSchema = z.object({
|
|
|
20
20
|
narrative: z.object({ context: z.string() }),
|
|
21
21
|
attributes: z.object({ interests: z.array(z.string()), skills: z.array(z.string()) }),
|
|
22
22
|
});
|
|
23
|
-
export function
|
|
23
|
+
export function createEnrichmentTools(defineTool, deps) {
|
|
24
24
|
const { userDb, systemDb, graphs, enricher, grantDefaultSystemPermissions, reportToolError, getUserContextText } = deps;
|
|
25
25
|
function trimToUndefined(value) {
|
|
26
26
|
const trimmed = value?.trim();
|
|
@@ -104,10 +104,10 @@ export function createProfileTools(defineTool, deps) {
|
|
|
104
104
|
return [];
|
|
105
105
|
return Object.entries(socials).map(([label, value]) => ({ label, value }));
|
|
106
106
|
}
|
|
107
|
-
async function
|
|
108
|
-
if (!context.isMcp || !deps.
|
|
107
|
+
async function enqueueEnrichmentRun(context, operation, input) {
|
|
108
|
+
if (!context.isMcp || !deps.enrichmentRuns || !deps.enrichmentRunQueue)
|
|
109
109
|
return null;
|
|
110
|
-
const run = await deps.
|
|
110
|
+
const run = await deps.enrichmentRuns.create({
|
|
111
111
|
userId: context.userId,
|
|
112
112
|
agentId: context.agentId ?? null,
|
|
113
113
|
operation,
|
|
@@ -125,11 +125,11 @@ export function createProfileTools(defineTool, deps) {
|
|
|
125
125
|
},
|
|
126
126
|
});
|
|
127
127
|
try {
|
|
128
|
-
await deps.
|
|
128
|
+
await deps.enrichmentRunQueue.enqueue(run.id);
|
|
129
129
|
}
|
|
130
130
|
catch (err) {
|
|
131
131
|
const message = err instanceof Error ? err.message : String(err);
|
|
132
|
-
await deps.
|
|
132
|
+
await deps.enrichmentRuns.markFailed(run.id, message);
|
|
133
133
|
if (err instanceof Error)
|
|
134
134
|
throw err;
|
|
135
135
|
const wrapped = new Error(`Failed to enqueue profile run: ${message}`);
|
|
@@ -203,7 +203,7 @@ export function createProfileTools(defineTool, deps) {
|
|
|
203
203
|
return;
|
|
204
204
|
const traceEmitter = requestContext.getStore()?.traceEmitter;
|
|
205
205
|
const graphStart = Date.now();
|
|
206
|
-
traceEmitter?.({ type: "graph_start", name: "
|
|
206
|
+
traceEmitter?.({ type: "graph_start", name: "enrichment" });
|
|
207
207
|
try {
|
|
208
208
|
const graphInput = {
|
|
209
209
|
userId: profile.userId,
|
|
@@ -223,7 +223,7 @@ export function createProfileTools(defineTool, deps) {
|
|
|
223
223
|
error: result.error,
|
|
224
224
|
});
|
|
225
225
|
reportToolError?.(err, {
|
|
226
|
-
subsystem: '
|
|
226
|
+
subsystem: 'enrichment',
|
|
227
227
|
operation: 'profile.confirm_draft_decompose',
|
|
228
228
|
toolName: 'confirm_user_profile',
|
|
229
229
|
userId: profile.userId,
|
|
@@ -243,7 +243,7 @@ export function createProfileTools(defineTool, deps) {
|
|
|
243
243
|
error: err instanceof Error ? err.message : String(err),
|
|
244
244
|
});
|
|
245
245
|
reportToolError?.(err, {
|
|
246
|
-
subsystem: '
|
|
246
|
+
subsystem: 'enrichment',
|
|
247
247
|
operation: 'profile.confirm_draft_decompose',
|
|
248
248
|
toolName: 'confirm_user_profile',
|
|
249
249
|
userId: profile.userId,
|
|
@@ -251,7 +251,7 @@ export function createProfileTools(defineTool, deps) {
|
|
|
251
251
|
});
|
|
252
252
|
}
|
|
253
253
|
finally {
|
|
254
|
-
traceEmitter?.({ type: "graph_end", name: "
|
|
254
|
+
traceEmitter?.({ type: "graph_end", name: "enrichment", durationMs: Date.now() - graphStart });
|
|
255
255
|
}
|
|
256
256
|
}
|
|
257
257
|
const readUserProfiles = defineTool({
|
|
@@ -324,19 +324,15 @@ export function createProfileTools(defineTool, deps) {
|
|
|
324
324
|
const profiles = await Promise.all(matched.map(async (m) => {
|
|
325
325
|
try {
|
|
326
326
|
const profile = await systemDb.getProfile(m.userId);
|
|
327
|
-
//
|
|
328
|
-
// identity text (global user_context) is fetched per-user via a userId read.
|
|
327
|
+
// Flat thin identity for list results. skills/interests are retired; the
|
|
328
|
+
// rich identity text (global user_context) is fetched per-user via a userId read.
|
|
329
329
|
return {
|
|
330
330
|
userId: m.userId,
|
|
331
331
|
name: m.name,
|
|
332
332
|
hasProfile: !!profile,
|
|
333
|
-
profile
|
|
334
|
-
? {
|
|
335
|
-
|
|
336
|
-
bio: profile.identity.bio,
|
|
337
|
-
location: profile.identity.location,
|
|
338
|
-
}
|
|
339
|
-
: undefined,
|
|
333
|
+
...(profile
|
|
334
|
+
? { bio: profile.identity.bio, location: profile.identity.location }
|
|
335
|
+
: {}),
|
|
340
336
|
};
|
|
341
337
|
}
|
|
342
338
|
catch (err) {
|
|
@@ -367,19 +363,15 @@ export function createProfileTools(defineTool, deps) {
|
|
|
367
363
|
const members = await systemDb.getNetworkMembers(effectiveIndexId);
|
|
368
364
|
const profiles = await Promise.all(members.map(async (member) => {
|
|
369
365
|
const profile = await systemDb.getProfile(member.userId);
|
|
370
|
-
//
|
|
366
|
+
// Flat thin identity for roster results. skills/interests are retired; fetch a
|
|
371
367
|
// member's global user_context text via a single-user (userId) read.
|
|
372
368
|
return {
|
|
373
369
|
userId: member.userId,
|
|
374
370
|
name: member.name,
|
|
375
371
|
hasProfile: !!profile,
|
|
376
|
-
profile
|
|
377
|
-
? {
|
|
378
|
-
|
|
379
|
-
bio: profile.identity.bio,
|
|
380
|
-
location: profile.identity.location,
|
|
381
|
-
}
|
|
382
|
-
: undefined,
|
|
372
|
+
...(profile
|
|
373
|
+
? { bio: profile.identity.bio, location: profile.identity.location }
|
|
374
|
+
: {}),
|
|
383
375
|
};
|
|
384
376
|
}));
|
|
385
377
|
return success({ networkId: effectiveIndexId, memberCount: members.length, profiles });
|
|
@@ -403,12 +395,10 @@ export function createProfileTools(defineTool, deps) {
|
|
|
403
395
|
const context = getUserContextText ? await getUserContextText(targetUserId) : '';
|
|
404
396
|
return success({
|
|
405
397
|
hasProfile: true,
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
context,
|
|
411
|
-
},
|
|
398
|
+
name: profile.identity.name,
|
|
399
|
+
bio: profile.identity.bio,
|
|
400
|
+
location: profile.identity.location,
|
|
401
|
+
context,
|
|
412
402
|
});
|
|
413
403
|
}
|
|
414
404
|
return success({ hasProfile: false, message: "This user does not have a profile yet." });
|
|
@@ -416,13 +406,13 @@ export function createProfileTools(defineTool, deps) {
|
|
|
416
406
|
// --- Mode 1: No args / self → use profileGraph query (returns id for updates) ---
|
|
417
407
|
const _readProfileGraphStart = Date.now();
|
|
418
408
|
const _readProfileTraceEmitter = requestContext.getStore()?.traceEmitter;
|
|
419
|
-
_readProfileTraceEmitter?.({ type: "graph_start", name: "
|
|
409
|
+
_readProfileTraceEmitter?.({ type: "graph_start", name: "enrichment" });
|
|
420
410
|
const result = await invokeWithAbortSignal(graphs.profile, {
|
|
421
411
|
userId: context.userId,
|
|
422
412
|
operationMode: 'query',
|
|
423
413
|
});
|
|
424
414
|
const _readProfileGraphMs = Date.now() - _readProfileGraphStart;
|
|
425
|
-
_readProfileTraceEmitter?.({ type: "graph_end", name: "
|
|
415
|
+
_readProfileTraceEmitter?.({ type: "graph_end", name: "enrichment", durationMs: _readProfileGraphMs });
|
|
426
416
|
// Self-lookup includes onboarding status so MCP agents (e.g. Edge Claw)
|
|
427
417
|
// can decide whether to run the onboarding flow without depending on
|
|
428
418
|
// local-only state like a workspace BOOTSTRAP.md file.
|
|
@@ -435,29 +425,28 @@ export function createProfileTools(defineTool, deps) {
|
|
|
435
425
|
// Augment the graph's thin-identity readResult with the caller's global
|
|
436
426
|
// user_context text (the rich, profile-replacing identity paragraph).
|
|
437
427
|
const readResult = result.readResult;
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
: readResult
|
|
441
|
-
|
|
428
|
+
// Flatten identity fields up; drop the nested `profile` object (WS11).
|
|
429
|
+
const flat = readResult.hasProfile && readResult.profile
|
|
430
|
+
? { hasProfile: true, ...readResult.profile, context: getUserContextText ? await getUserContextText(context.userId) : '' }
|
|
431
|
+
: { ...readResult };
|
|
432
|
+
return success({ ...flat, ...onboardingFields, _graphTimings: [{ name: 'enrichment', durationMs: _readProfileGraphMs, agents: result.agentTimings ?? [] }] });
|
|
442
433
|
}
|
|
443
434
|
if (result.profile) {
|
|
444
435
|
return success({
|
|
445
436
|
hasProfile: true,
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
context: getUserContextText ? await getUserContextText(context.userId) : '',
|
|
451
|
-
},
|
|
437
|
+
name: result.profile.identity.name,
|
|
438
|
+
bio: result.profile.identity.bio,
|
|
439
|
+
location: result.profile.identity.location,
|
|
440
|
+
context: getUserContextText ? await getUserContextText(context.userId) : '',
|
|
452
441
|
...onboardingFields,
|
|
453
|
-
_graphTimings: [{ name: '
|
|
442
|
+
_graphTimings: [{ name: 'enrichment', durationMs: _readProfileGraphMs, agents: result.agentTimings ?? [] }],
|
|
454
443
|
});
|
|
455
444
|
}
|
|
456
445
|
return success({
|
|
457
446
|
hasProfile: false,
|
|
458
447
|
...onboardingFields,
|
|
459
448
|
message: "You don't have a profile yet. Would you like to create one? You can share your LinkedIn, GitHub, or X/Twitter profile, or just tell me about yourself.",
|
|
460
|
-
_graphTimings: [{ name: '
|
|
449
|
+
_graphTimings: [{ name: 'enrichment', durationMs: _readProfileGraphMs, agents: result.agentTimings ?? [] }],
|
|
461
450
|
});
|
|
462
451
|
},
|
|
463
452
|
});
|
|
@@ -525,7 +514,7 @@ export function createProfileTools(defineTool, deps) {
|
|
|
525
514
|
const user = await userDb.getUser();
|
|
526
515
|
if (!user)
|
|
527
516
|
return error("User not found.");
|
|
528
|
-
const profileRunId = await
|
|
517
|
+
const profileRunId = await enqueueEnrichmentRun(context, "preview_user_profile", query);
|
|
529
518
|
if (profileRunId) {
|
|
530
519
|
return success({
|
|
531
520
|
status: "queued",
|
|
@@ -574,7 +563,7 @@ export function createProfileTools(defineTool, deps) {
|
|
|
574
563
|
message: "Please share a short description, allowed EdgeOS profile text, or user-provided profile links so I can draft your profile.",
|
|
575
564
|
});
|
|
576
565
|
}
|
|
577
|
-
const generated = await new
|
|
566
|
+
const generated = await new EnrichmentGenerator().invoke(input);
|
|
578
567
|
const profile = { ...generated.output, userId: context.userId };
|
|
579
568
|
return success({
|
|
580
569
|
preview: true,
|
|
@@ -612,7 +601,7 @@ export function createProfileTools(defineTool, deps) {
|
|
|
612
601
|
const user = await userDb.getUser();
|
|
613
602
|
if (query.draft) {
|
|
614
603
|
const profile = { ...query.draft, userId: context.userId };
|
|
615
|
-
await userDb.saveProfile(profile);
|
|
604
|
+
await userDb.saveProfile({ userId: context.userId, identity: profile.identity, context: profile.narrative?.context ?? '' });
|
|
616
605
|
await persistApprovedProfileContext(profile, user, context.networkId);
|
|
617
606
|
const decomposeLogLabel = context.isMcp
|
|
618
607
|
? 'Approved draft premise decomposition failed'
|
|
@@ -652,7 +641,7 @@ export function createProfileTools(defineTool, deps) {
|
|
|
652
641
|
await persistApprovedProfileContext(rawProfile, user, context.networkId);
|
|
653
642
|
const _confirmTraceEmitter = requestContext.getStore()?.traceEmitter;
|
|
654
643
|
const _confirmGraphStart = Date.now();
|
|
655
|
-
_confirmTraceEmitter?.({ type: "graph_start", name: "
|
|
644
|
+
_confirmTraceEmitter?.({ type: "graph_start", name: "enrichment" });
|
|
656
645
|
graphs.profile.invoke({
|
|
657
646
|
userId: context.userId,
|
|
658
647
|
operationMode: 'write',
|
|
@@ -670,7 +659,7 @@ export function createProfileTools(defineTool, deps) {
|
|
|
670
659
|
error: err instanceof Error ? err.message : String(err),
|
|
671
660
|
})).finally(() => {
|
|
672
661
|
const _confirmGraphMs = Date.now() - _confirmGraphStart;
|
|
673
|
-
_confirmTraceEmitter?.({ type: "graph_end", name: "
|
|
662
|
+
_confirmTraceEmitter?.({ type: "graph_end", name: "enrichment", durationMs: _confirmGraphMs });
|
|
674
663
|
});
|
|
675
664
|
return success({
|
|
676
665
|
created: true,
|
|
@@ -749,8 +738,6 @@ export function createProfileTools(defineTool, deps) {
|
|
|
749
738
|
name: existingProfile.identity.name,
|
|
750
739
|
bio: existingProfile.identity.bio,
|
|
751
740
|
location: existingProfile.identity.location,
|
|
752
|
-
skills: existingProfile.attributes.skills,
|
|
753
|
-
interests: existingProfile.attributes.interests,
|
|
754
741
|
},
|
|
755
742
|
});
|
|
756
743
|
}
|
|
@@ -820,13 +807,13 @@ export function createProfileTools(defineTool, deps) {
|
|
|
820
807
|
try {
|
|
821
808
|
const _confirmGraphStart = Date.now();
|
|
822
809
|
const _confirmTraceEmitter = requestContext.getStore()?.traceEmitter;
|
|
823
|
-
_confirmTraceEmitter?.({ type: "graph_start", name: "
|
|
810
|
+
_confirmTraceEmitter?.({ type: "graph_start", name: "enrichment" });
|
|
824
811
|
const result = await invokeWithAbortSignal(graphs.profile, {
|
|
825
812
|
userId: context.userId,
|
|
826
813
|
operationMode: 'generate',
|
|
827
814
|
});
|
|
828
815
|
const _confirmGraphMs = Date.now() - _confirmGraphStart;
|
|
829
|
-
_confirmTraceEmitter?.({ type: "graph_end", name: "
|
|
816
|
+
_confirmTraceEmitter?.({ type: "graph_end", name: "enrichment", durationMs: _confirmGraphMs });
|
|
830
817
|
if (result.error)
|
|
831
818
|
return error(result.error);
|
|
832
819
|
if (result.profile) {
|
|
@@ -840,7 +827,7 @@ export function createProfileTools(defineTool, deps) {
|
|
|
840
827
|
skills: result.profile.attributes.skills,
|
|
841
828
|
interests: result.profile.attributes.interests,
|
|
842
829
|
},
|
|
843
|
-
_graphTimings: [{ name: '
|
|
830
|
+
_graphTimings: [{ name: 'enrichment', durationMs: _confirmGraphMs, agents: result.agentTimings ?? [] }],
|
|
844
831
|
});
|
|
845
832
|
}
|
|
846
833
|
}
|
|
@@ -854,7 +841,7 @@ export function createProfileTools(defineTool, deps) {
|
|
|
854
841
|
const hasBioOrDescription = !!query.bioOrDescription?.trim();
|
|
855
842
|
if (hasBioOrDescription) {
|
|
856
843
|
// Create/update profile from user's explicit text only; do not persist to user record
|
|
857
|
-
// Include name and location in the input if provided so the
|
|
844
|
+
// Include name and location in the input if provided so the EnrichmentGenerator can use them
|
|
858
845
|
const inputParts = [];
|
|
859
846
|
if (name)
|
|
860
847
|
inputParts.push(`Name: ${name}`);
|
|
@@ -864,7 +851,7 @@ export function createProfileTools(defineTool, deps) {
|
|
|
864
851
|
const profileInput = inputParts.join('\n');
|
|
865
852
|
const _bioProfileGraphStart = Date.now();
|
|
866
853
|
const _bioProfileTraceEmitter = requestContext.getStore()?.traceEmitter;
|
|
867
|
-
_bioProfileTraceEmitter?.({ type: "graph_start", name: "
|
|
854
|
+
_bioProfileTraceEmitter?.({ type: "graph_start", name: "enrichment" });
|
|
868
855
|
const result = await invokeWithAbortSignal(graphs.profile, {
|
|
869
856
|
userId: context.userId,
|
|
870
857
|
operationMode: 'write',
|
|
@@ -872,7 +859,7 @@ export function createProfileTools(defineTool, deps) {
|
|
|
872
859
|
forceUpdate: true,
|
|
873
860
|
});
|
|
874
861
|
const _bioProfileGraphMs = Date.now() - _bioProfileGraphStart;
|
|
875
|
-
_bioProfileTraceEmitter?.({ type: "graph_end", name: "
|
|
862
|
+
_bioProfileTraceEmitter?.({ type: "graph_end", name: "enrichment", durationMs: _bioProfileGraphMs });
|
|
876
863
|
if (result.error) {
|
|
877
864
|
return error(result.error);
|
|
878
865
|
}
|
|
@@ -887,26 +874,26 @@ export function createProfileTools(defineTool, deps) {
|
|
|
887
874
|
skills: result.profile.attributes.skills,
|
|
888
875
|
interests: result.profile.attributes.interests,
|
|
889
876
|
},
|
|
890
|
-
_graphTimings: [{ name: '
|
|
877
|
+
_graphTimings: [{ name: 'enrichment', durationMs: _bioProfileGraphMs, agents: result.agentTimings ?? [] }],
|
|
891
878
|
});
|
|
892
879
|
}
|
|
893
880
|
return success({
|
|
894
881
|
created: true,
|
|
895
882
|
message: "Profile created/updated with the information you provided.",
|
|
896
|
-
_graphTimings: [{ name: '
|
|
883
|
+
_graphTimings: [{ name: 'enrichment', durationMs: _bioProfileGraphMs, agents: result.agentTimings ?? [] }],
|
|
897
884
|
});
|
|
898
885
|
}
|
|
899
886
|
// Invoke profile graph in generate mode (uses enrichUserProfile Chat API)
|
|
900
887
|
const _generateProfileGraphStart = Date.now();
|
|
901
888
|
const _generateProfileTraceEmitter = requestContext.getStore()?.traceEmitter;
|
|
902
|
-
_generateProfileTraceEmitter?.({ type: "graph_start", name: "
|
|
889
|
+
_generateProfileTraceEmitter?.({ type: "graph_start", name: "enrichment" });
|
|
903
890
|
const result = await invokeWithAbortSignal(graphs.profile, {
|
|
904
891
|
userId: context.userId,
|
|
905
892
|
operationMode: 'generate',
|
|
906
893
|
forceUpdate: true,
|
|
907
894
|
});
|
|
908
895
|
const _generateProfileGraphMs = Date.now() - _generateProfileGraphStart;
|
|
909
|
-
_generateProfileTraceEmitter?.({ type: "graph_end", name: "
|
|
896
|
+
_generateProfileTraceEmitter?.({ type: "graph_end", name: "enrichment", durationMs: _generateProfileGraphMs });
|
|
910
897
|
// If user info is insufficient, ask conversationally
|
|
911
898
|
if (result.needsUserInfo) {
|
|
912
899
|
return needsClarification({
|
|
@@ -928,7 +915,7 @@ export function createProfileTools(defineTool, deps) {
|
|
|
928
915
|
skills: result.profile.attributes.skills,
|
|
929
916
|
interests: result.profile.attributes.interests,
|
|
930
917
|
},
|
|
931
|
-
_graphTimings: [{ name: '
|
|
918
|
+
_graphTimings: [{ name: 'enrichment', durationMs: _generateProfileGraphMs, agents: result.agentTimings ?? [] }],
|
|
932
919
|
});
|
|
933
920
|
}
|
|
934
921
|
return error("Failed to create profile. Please try again.");
|
|
@@ -966,7 +953,7 @@ export function createProfileTools(defineTool, deps) {
|
|
|
966
953
|
}
|
|
967
954
|
return error("Please specify what to update (e.g. action: 'update bio to X') or provide socials.");
|
|
968
955
|
}
|
|
969
|
-
const profileRunId = await
|
|
956
|
+
const profileRunId = await enqueueEnrichmentRun(context, "update_user_profile", query);
|
|
970
957
|
if (profileRunId) {
|
|
971
958
|
return success({
|
|
972
959
|
status: "queued",
|
|
@@ -977,10 +964,10 @@ export function createProfileTools(defineTool, deps) {
|
|
|
977
964
|
// Use profileGraph query mode to validate profile existence and get id
|
|
978
965
|
const _updateQueryProfileGraphStart = Date.now();
|
|
979
966
|
const _updateQueryProfileTraceEmitter = requestContext.getStore()?.traceEmitter;
|
|
980
|
-
_updateQueryProfileTraceEmitter?.({ type: "graph_start", name: "
|
|
967
|
+
_updateQueryProfileTraceEmitter?.({ type: "graph_start", name: "enrichment" });
|
|
981
968
|
const queryResult = await invokeWithAbortSignal(graphs.profile, { userId: context.userId, operationMode: 'query' });
|
|
982
969
|
const _updateQueryProfileGraphMs = Date.now() - _updateQueryProfileGraphStart;
|
|
983
|
-
_updateQueryProfileTraceEmitter?.({ type: "graph_end", name: "
|
|
970
|
+
_updateQueryProfileTraceEmitter?.({ type: "graph_end", name: "enrichment", durationMs: _updateQueryProfileGraphMs });
|
|
984
971
|
if (!queryResult.readResult?.hasProfile && !queryResult.profile) {
|
|
985
972
|
return error("You don't have a profile yet. Use create_user_profile first.");
|
|
986
973
|
}
|
|
@@ -995,7 +982,7 @@ export function createProfileTools(defineTool, deps) {
|
|
|
995
982
|
if (context.isMcp) {
|
|
996
983
|
const _backgroundWriteProfileGraphStart = Date.now();
|
|
997
984
|
const _backgroundWriteProfileTraceEmitter = requestContext.getStore()?.traceEmitter;
|
|
998
|
-
_backgroundWriteProfileTraceEmitter?.({ type: "graph_start", name: "
|
|
985
|
+
_backgroundWriteProfileTraceEmitter?.({ type: "graph_start", name: "enrichment" });
|
|
999
986
|
graphs.profile.invoke({
|
|
1000
987
|
userId: context.userId,
|
|
1001
988
|
operationMode: "write",
|
|
@@ -1008,7 +995,7 @@ export function createProfileTools(defineTool, deps) {
|
|
|
1008
995
|
error: writeResult.error,
|
|
1009
996
|
});
|
|
1010
997
|
reportToolError?.(new Error(writeResult.error), {
|
|
1011
|
-
subsystem: "
|
|
998
|
+
subsystem: "enrichment",
|
|
1012
999
|
operation: "profile.update_background",
|
|
1013
1000
|
toolName: "update_user_profile",
|
|
1014
1001
|
userId: context.userId,
|
|
@@ -1023,7 +1010,7 @@ export function createProfileTools(defineTool, deps) {
|
|
|
1023
1010
|
error: message,
|
|
1024
1011
|
});
|
|
1025
1012
|
reportToolError?.(err, {
|
|
1026
|
-
subsystem: "
|
|
1013
|
+
subsystem: "enrichment",
|
|
1027
1014
|
operation: "profile.update_background",
|
|
1028
1015
|
toolName: "update_user_profile",
|
|
1029
1016
|
userId: context.userId,
|
|
@@ -1032,20 +1019,20 @@ export function createProfileTools(defineTool, deps) {
|
|
|
1032
1019
|
});
|
|
1033
1020
|
}).finally(() => {
|
|
1034
1021
|
const _backgroundWriteProfileGraphMs = Date.now() - _backgroundWriteProfileGraphStart;
|
|
1035
|
-
_backgroundWriteProfileTraceEmitter?.({ type: "graph_end", name: "
|
|
1022
|
+
_backgroundWriteProfileTraceEmitter?.({ type: "graph_end", name: "enrichment", durationMs: _backgroundWriteProfileGraphMs });
|
|
1036
1023
|
});
|
|
1037
1024
|
return success({
|
|
1038
1025
|
accepted: true,
|
|
1039
1026
|
message: "Profile update accepted. The structured profile will refresh in the background.",
|
|
1040
1027
|
_graphTimings: [
|
|
1041
|
-
{ name: '
|
|
1028
|
+
{ name: 'enrichment', durationMs: _updateQueryProfileGraphMs, agents: queryResult.agentTimings ?? [] },
|
|
1042
1029
|
],
|
|
1043
1030
|
});
|
|
1044
1031
|
}
|
|
1045
1032
|
// Execute update directly
|
|
1046
1033
|
const _updateWriteProfileGraphStart = Date.now();
|
|
1047
1034
|
const _updateWriteProfileTraceEmitter = requestContext.getStore()?.traceEmitter;
|
|
1048
|
-
_updateWriteProfileTraceEmitter?.({ type: "graph_start", name: "
|
|
1035
|
+
_updateWriteProfileTraceEmitter?.({ type: "graph_start", name: "enrichment" });
|
|
1049
1036
|
const _writeResult = await invokeWithAbortSignal(graphs.profile, {
|
|
1050
1037
|
userId: context.userId,
|
|
1051
1038
|
operationMode: "write",
|
|
@@ -1053,15 +1040,15 @@ export function createProfileTools(defineTool, deps) {
|
|
|
1053
1040
|
forceUpdate: true,
|
|
1054
1041
|
});
|
|
1055
1042
|
const _updateWriteProfileGraphMs = Date.now() - _updateWriteProfileGraphStart;
|
|
1056
|
-
_updateWriteProfileTraceEmitter?.({ type: "graph_end", name: "
|
|
1043
|
+
_updateWriteProfileTraceEmitter?.({ type: "graph_end", name: "enrichment", durationMs: _updateWriteProfileGraphMs });
|
|
1057
1044
|
if (_writeResult.error) {
|
|
1058
1045
|
return error(_writeResult.error);
|
|
1059
1046
|
}
|
|
1060
1047
|
return success({
|
|
1061
1048
|
message: "Profile updated.",
|
|
1062
1049
|
_graphTimings: [
|
|
1063
|
-
{ name: '
|
|
1064
|
-
{ name: '
|
|
1050
|
+
{ name: 'enrichment', durationMs: _updateQueryProfileGraphMs, agents: queryResult.agentTimings ?? [] },
|
|
1051
|
+
{ name: 'enrichment', durationMs: _updateWriteProfileGraphMs, agents: _writeResult.agentTimings ?? [] },
|
|
1065
1052
|
],
|
|
1066
1053
|
});
|
|
1067
1054
|
},
|
|
@@ -1074,10 +1061,10 @@ export function createProfileTools(defineTool, deps) {
|
|
|
1074
1061
|
profileRunId: z.string().describe("Profile run ID returned by preview_user_profile or update_user_profile."),
|
|
1075
1062
|
}),
|
|
1076
1063
|
handler: async ({ context, query }) => {
|
|
1077
|
-
if (!deps.
|
|
1064
|
+
if (!deps.enrichmentRuns) {
|
|
1078
1065
|
return error("Profile run polling is not available in this environment.");
|
|
1079
1066
|
}
|
|
1080
|
-
const run = await deps.
|
|
1067
|
+
const run = await deps.enrichmentRuns.get(query.profileRunId, context.userId);
|
|
1081
1068
|
if (!run)
|
|
1082
1069
|
return error("Profile run not found.");
|
|
1083
1070
|
return success({
|
|
@@ -1101,10 +1088,10 @@ export function createProfileTools(defineTool, deps) {
|
|
|
1101
1088
|
profileRunId: z.string().describe("Profile run ID returned by preview_user_profile or update_user_profile."),
|
|
1102
1089
|
}),
|
|
1103
1090
|
handler: async ({ context, query }) => {
|
|
1104
|
-
if (!deps.
|
|
1091
|
+
if (!deps.enrichmentRuns || !deps.enrichmentRunQueue) {
|
|
1105
1092
|
return error("Profile run cancellation is not available in this environment.");
|
|
1106
1093
|
}
|
|
1107
|
-
const existing = await deps.
|
|
1094
|
+
const existing = await deps.enrichmentRuns.get(query.profileRunId, context.userId);
|
|
1108
1095
|
if (!existing)
|
|
1109
1096
|
return error("Profile run not found.");
|
|
1110
1097
|
if (!["queued", "running"].includes(existing.status)) {
|
|
@@ -1114,14 +1101,14 @@ export function createProfileTools(defineTool, deps) {
|
|
|
1114
1101
|
message: `Profile run is already ${existing.status}.`,
|
|
1115
1102
|
});
|
|
1116
1103
|
}
|
|
1117
|
-
const run = await deps.
|
|
1104
|
+
const run = await deps.enrichmentRuns.requestCancel(query.profileRunId, context.userId);
|
|
1118
1105
|
if (!run)
|
|
1119
1106
|
return error("Profile run not found or cannot be cancelled.");
|
|
1120
|
-
const removed = await deps.
|
|
1107
|
+
const removed = await deps.enrichmentRunQueue.cancel(run.id);
|
|
1121
1108
|
if (removed) {
|
|
1122
|
-
await deps.
|
|
1109
|
+
await deps.enrichmentRuns.markCancelled(run.id, "cancelled before worker start");
|
|
1123
1110
|
}
|
|
1124
|
-
const updated = await deps.
|
|
1111
|
+
const updated = await deps.enrichmentRuns.get(run.id, context.userId);
|
|
1125
1112
|
return success({
|
|
1126
1113
|
profileRunId: run.id,
|
|
1127
1114
|
status: updated?.status ?? run.status,
|
|
@@ -1178,4 +1165,4 @@ export function createProfileTools(defineTool, deps) {
|
|
|
1178
1165
|
});
|
|
1179
1166
|
return [readUserProfiles, recordOnboardingPrivacyConsent, previewUserProfile, confirmUserProfile, createUserProfile, updateUserProfile, getProfileRun, cancelProfileRun, completeOnboarding];
|
|
1180
1167
|
}
|
|
1181
|
-
//# sourceMappingURL=
|
|
1168
|
+
//# sourceMappingURL=enrichment.tools.js.map
|