@indexnetwork/protocol 0.1.0
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/agents/chat.agent.d.ts +218 -0
- package/dist/agents/chat.agent.d.ts.map +1 -0
- package/dist/agents/chat.agent.js +884 -0
- package/dist/agents/chat.agent.js.map +1 -0
- package/dist/agents/chat.prompt.d.ts +18 -0
- package/dist/agents/chat.prompt.d.ts.map +1 -0
- package/dist/agents/chat.prompt.js +372 -0
- package/dist/agents/chat.prompt.js.map +1 -0
- package/dist/agents/chat.prompt.modules.d.ts +61 -0
- package/dist/agents/chat.prompt.modules.d.ts.map +1 -0
- package/dist/agents/chat.prompt.modules.js +366 -0
- package/dist/agents/chat.prompt.modules.js.map +1 -0
- package/dist/agents/chat.title.generator.d.ts +20 -0
- package/dist/agents/chat.title.generator.d.ts.map +1 -0
- package/dist/agents/chat.title.generator.js +66 -0
- package/dist/agents/chat.title.generator.js.map +1 -0
- package/dist/agents/home.categorizer.d.ts +28 -0
- package/dist/agents/home.categorizer.d.ts.map +1 -0
- package/dist/agents/home.categorizer.js +170 -0
- package/dist/agents/home.categorizer.js.map +1 -0
- package/dist/agents/hyde.generator.d.ts +27 -0
- package/dist/agents/hyde.generator.d.ts.map +1 -0
- package/dist/agents/hyde.generator.js +75 -0
- package/dist/agents/hyde.generator.js.map +1 -0
- package/dist/agents/hyde.strategies.d.ts +17 -0
- package/dist/agents/hyde.strategies.d.ts.map +1 -0
- package/dist/agents/hyde.strategies.js +29 -0
- package/dist/agents/hyde.strategies.js.map +1 -0
- package/dist/agents/intent.clarifier.d.ts +29 -0
- package/dist/agents/intent.clarifier.d.ts.map +1 -0
- package/dist/agents/intent.clarifier.js +186 -0
- package/dist/agents/intent.clarifier.js.map +1 -0
- package/dist/agents/intent.indexer.d.ts +77 -0
- package/dist/agents/intent.indexer.d.ts.map +1 -0
- package/dist/agents/intent.indexer.js +164 -0
- package/dist/agents/intent.indexer.js.map +1 -0
- package/dist/agents/intent.inferrer.d.ts +95 -0
- package/dist/agents/intent.inferrer.d.ts.map +1 -0
- package/dist/agents/intent.inferrer.js +238 -0
- package/dist/agents/intent.inferrer.js.map +1 -0
- package/dist/agents/intent.reconciler.d.ts +106 -0
- package/dist/agents/intent.reconciler.d.ts.map +1 -0
- package/dist/agents/intent.reconciler.js +184 -0
- package/dist/agents/intent.reconciler.js.map +1 -0
- package/dist/agents/intent.verifier.d.ts +97 -0
- package/dist/agents/intent.verifier.d.ts.map +1 -0
- package/dist/agents/intent.verifier.js +234 -0
- package/dist/agents/intent.verifier.js.map +1 -0
- package/dist/agents/invite.generator.d.ts +47 -0
- package/dist/agents/invite.generator.d.ts.map +1 -0
- package/dist/agents/invite.generator.js +56 -0
- package/dist/agents/invite.generator.js.map +1 -0
- package/dist/agents/lens.inferrer.d.ts +37 -0
- package/dist/agents/lens.inferrer.d.ts.map +1 -0
- package/dist/agents/lens.inferrer.js +98 -0
- package/dist/agents/lens.inferrer.js.map +1 -0
- package/dist/agents/model.config.d.ts +120 -0
- package/dist/agents/model.config.d.ts.map +1 -0
- package/dist/agents/model.config.js +76 -0
- package/dist/agents/model.config.js.map +1 -0
- package/dist/agents/negotiation.insights.generator.d.ts +32 -0
- package/dist/agents/negotiation.insights.generator.d.ts.map +1 -0
- package/dist/agents/negotiation.insights.generator.js +105 -0
- package/dist/agents/negotiation.insights.generator.js.map +1 -0
- package/dist/agents/negotiation.proposer.d.ts +26 -0
- package/dist/agents/negotiation.proposer.d.ts.map +1 -0
- package/dist/agents/negotiation.proposer.js +67 -0
- package/dist/agents/negotiation.proposer.js.map +1 -0
- package/dist/agents/negotiation.responder.d.ts +26 -0
- package/dist/agents/negotiation.responder.d.ts.map +1 -0
- package/dist/agents/negotiation.responder.js +71 -0
- package/dist/agents/negotiation.responder.js.map +1 -0
- package/dist/agents/opportunity.evaluator.d.ts +253 -0
- package/dist/agents/opportunity.evaluator.d.ts.map +1 -0
- package/dist/agents/opportunity.evaluator.js +413 -0
- package/dist/agents/opportunity.evaluator.js.map +1 -0
- package/dist/agents/opportunity.presenter.d.ts +115 -0
- package/dist/agents/opportunity.presenter.d.ts.map +1 -0
- package/dist/agents/opportunity.presenter.js +524 -0
- package/dist/agents/opportunity.presenter.js.map +1 -0
- package/dist/agents/profile.generator.d.ts +67 -0
- package/dist/agents/profile.generator.d.ts.map +1 -0
- package/dist/agents/profile.generator.js +97 -0
- package/dist/agents/profile.generator.js.map +1 -0
- package/dist/agents/profile.hyde.generator.d.ts +43 -0
- package/dist/agents/profile.hyde.generator.d.ts.map +1 -0
- package/dist/agents/profile.hyde.generator.js +113 -0
- package/dist/agents/profile.hyde.generator.js.map +1 -0
- package/dist/agents/suggestion.generator.d.ts +24 -0
- package/dist/agents/suggestion.generator.d.ts.map +1 -0
- package/dist/agents/suggestion.generator.js +96 -0
- package/dist/agents/suggestion.generator.js.map +1 -0
- package/dist/graphs/chat.graph.d.ts +312 -0
- package/dist/graphs/chat.graph.d.ts.map +1 -0
- package/dist/graphs/chat.graph.js +267 -0
- package/dist/graphs/chat.graph.js.map +1 -0
- package/dist/graphs/home.graph.d.ts +180 -0
- package/dist/graphs/home.graph.d.ts.map +1 -0
- package/dist/graphs/home.graph.js +598 -0
- package/dist/graphs/home.graph.js.map +1 -0
- package/dist/graphs/hyde.graph.d.ts +110 -0
- package/dist/graphs/hyde.graph.d.ts.map +1 -0
- package/dist/graphs/hyde.graph.js +235 -0
- package/dist/graphs/hyde.graph.js.map +1 -0
- package/dist/graphs/index.graph.d.ts +620 -0
- package/dist/graphs/index.graph.d.ts.map +1 -0
- package/dist/graphs/index.graph.js +226 -0
- package/dist/graphs/index.graph.js.map +1 -0
- package/dist/graphs/index_membership.graph.d.ts +250 -0
- package/dist/graphs/index_membership.graph.d.ts.map +1 -0
- package/dist/graphs/index_membership.graph.js +204 -0
- package/dist/graphs/index_membership.graph.js.map +1 -0
- package/dist/graphs/intent.graph.d.ts +490 -0
- package/dist/graphs/intent.graph.d.ts.map +1 -0
- package/dist/graphs/intent.graph.js +787 -0
- package/dist/graphs/intent.graph.js.map +1 -0
- package/dist/graphs/intent_index.graph.d.ts +396 -0
- package/dist/graphs/intent_index.graph.d.ts.map +1 -0
- package/dist/graphs/intent_index.graph.js +331 -0
- package/dist/graphs/intent_index.graph.js.map +1 -0
- package/dist/graphs/maintenance.graph.d.ts +177 -0
- package/dist/graphs/maintenance.graph.d.ts.map +1 -0
- package/dist/graphs/maintenance.graph.js +173 -0
- package/dist/graphs/maintenance.graph.js.map +1 -0
- package/dist/graphs/negotiation.graph.d.ts +819 -0
- package/dist/graphs/negotiation.graph.d.ts.map +1 -0
- package/dist/graphs/negotiation.graph.js +255 -0
- package/dist/graphs/negotiation.graph.js.map +1 -0
- package/dist/graphs/opportunity.graph.d.ts +1082 -0
- package/dist/graphs/opportunity.graph.d.ts.map +1 -0
- package/dist/graphs/opportunity.graph.js +2534 -0
- package/dist/graphs/opportunity.graph.js.map +1 -0
- package/dist/graphs/profile.graph.d.ts +617 -0
- package/dist/graphs/profile.graph.d.ts.map +1 -0
- package/dist/graphs/profile.graph.js +839 -0
- package/dist/graphs/profile.graph.js.map +1 -0
- package/dist/graphs/tests/chat.graph.mocks.d.ts +104 -0
- package/dist/graphs/tests/chat.graph.mocks.d.ts.map +1 -0
- package/dist/graphs/tests/chat.graph.mocks.js +225 -0
- package/dist/graphs/tests/chat.graph.mocks.js.map +1 -0
- package/dist/index.d.ts +62 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +44 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/auth.interface.d.ts +15 -0
- package/dist/interfaces/auth.interface.d.ts.map +1 -0
- package/dist/interfaces/auth.interface.js +2 -0
- package/dist/interfaces/auth.interface.js.map +1 -0
- package/dist/interfaces/cache.interface.d.ts +43 -0
- package/dist/interfaces/cache.interface.d.ts.map +1 -0
- package/dist/interfaces/cache.interface.js +6 -0
- package/dist/interfaces/cache.interface.js.map +1 -0
- package/dist/interfaces/chat-session.interface.d.ts +11 -0
- package/dist/interfaces/chat-session.interface.d.ts.map +1 -0
- package/dist/interfaces/chat-session.interface.js +2 -0
- package/dist/interfaces/chat-session.interface.js.map +1 -0
- package/dist/interfaces/contact.interface.d.ts +48 -0
- package/dist/interfaces/contact.interface.d.ts.map +1 -0
- package/dist/interfaces/contact.interface.js +2 -0
- package/dist/interfaces/contact.interface.js.map +1 -0
- package/dist/interfaces/database.interface.d.ts +1495 -0
- package/dist/interfaces/database.interface.d.ts.map +1 -0
- package/dist/interfaces/database.interface.js +2 -0
- package/dist/interfaces/database.interface.js.map +1 -0
- package/dist/interfaces/embedder.interface.d.ts +85 -0
- package/dist/interfaces/embedder.interface.d.ts.map +1 -0
- package/dist/interfaces/embedder.interface.js +5 -0
- package/dist/interfaces/embedder.interface.js.map +1 -0
- package/dist/interfaces/enrichment.interface.d.ts +40 -0
- package/dist/interfaces/enrichment.interface.d.ts.map +1 -0
- package/dist/interfaces/enrichment.interface.js +2 -0
- package/dist/interfaces/enrichment.interface.js.map +1 -0
- package/dist/interfaces/integration.interface.d.ts +91 -0
- package/dist/interfaces/integration.interface.d.ts.map +1 -0
- package/dist/interfaces/integration.interface.js +2 -0
- package/dist/interfaces/integration.interface.js.map +1 -0
- package/dist/interfaces/queue.interface.d.ts +17 -0
- package/dist/interfaces/queue.interface.d.ts.map +1 -0
- package/dist/interfaces/queue.interface.js +5 -0
- package/dist/interfaces/queue.interface.js.map +1 -0
- package/dist/interfaces/scraper.interface.d.ts +31 -0
- package/dist/interfaces/scraper.interface.d.ts.map +1 -0
- package/dist/interfaces/scraper.interface.js +2 -0
- package/dist/interfaces/scraper.interface.js.map +1 -0
- package/dist/interfaces/storage.interface.d.ts +46 -0
- package/dist/interfaces/storage.interface.d.ts.map +1 -0
- package/dist/interfaces/storage.interface.js +6 -0
- package/dist/interfaces/storage.interface.js.map +1 -0
- package/dist/mcp/mcp.server.d.ts +29 -0
- package/dist/mcp/mcp.server.d.ts.map +1 -0
- package/dist/mcp/mcp.server.js +171 -0
- package/dist/mcp/mcp.server.js.map +1 -0
- package/dist/states/chat.state.d.ts +126 -0
- package/dist/states/chat.state.d.ts.map +1 -0
- package/dist/states/chat.state.js +112 -0
- package/dist/states/chat.state.js.map +1 -0
- package/dist/states/home.state.d.ts +100 -0
- package/dist/states/home.state.d.ts.map +1 -0
- package/dist/states/home.state.js +74 -0
- package/dist/states/home.state.js.map +1 -0
- package/dist/states/hyde.state.d.ts +54 -0
- package/dist/states/hyde.state.d.ts.map +1 -0
- package/dist/states/hyde.state.js +66 -0
- package/dist/states/hyde.state.js.map +1 -0
- package/dist/states/index.state.d.ts +179 -0
- package/dist/states/index.state.d.ts.map +1 -0
- package/dist/states/index.state.js +56 -0
- package/dist/states/index.state.js.map +1 -0
- package/dist/states/index_membership.state.d.ts +77 -0
- package/dist/states/index_membership.state.d.ts.map +1 -0
- package/dist/states/index_membership.state.js +43 -0
- package/dist/states/index_membership.state.js.map +1 -0
- package/dist/states/intent.state.d.ts +203 -0
- package/dist/states/intent.state.d.ts.map +1 -0
- package/dist/states/intent.state.js +153 -0
- package/dist/states/intent.state.js.map +1 -0
- package/dist/states/intent_index.state.d.ts +148 -0
- package/dist/states/intent_index.state.d.ts.map +1 -0
- package/dist/states/intent_index.state.js +100 -0
- package/dist/states/intent_index.state.js.map +1 -0
- package/dist/states/maintenance.state.d.ts +36 -0
- package/dist/states/maintenance.state.d.ts.map +1 -0
- package/dist/states/maintenance.state.js +56 -0
- package/dist/states/maintenance.state.js.map +1 -0
- package/dist/states/negotiation.state.d.ts +230 -0
- package/dist/states/negotiation.state.d.ts.map +1 -0
- package/dist/states/negotiation.state.js +82 -0
- package/dist/states/negotiation.state.js.map +1 -0
- package/dist/states/opportunity.state.d.ts +300 -0
- package/dist/states/opportunity.state.d.ts.map +1 -0
- package/dist/states/opportunity.state.js +207 -0
- package/dist/states/opportunity.state.js.map +1 -0
- package/dist/states/profile.state.d.ts +172 -0
- package/dist/states/profile.state.d.ts.map +1 -0
- package/dist/states/profile.state.js +133 -0
- package/dist/states/profile.state.js.map +1 -0
- package/dist/streamers/chat.streamer.d.ts +55 -0
- package/dist/streamers/chat.streamer.d.ts.map +1 -0
- package/dist/streamers/chat.streamer.js +186 -0
- package/dist/streamers/chat.streamer.js.map +1 -0
- package/dist/streamers/index.d.ts +3 -0
- package/dist/streamers/index.d.ts.map +1 -0
- package/dist/streamers/index.js +3 -0
- package/dist/streamers/index.js.map +1 -0
- package/dist/streamers/response.streamer.d.ts +36 -0
- package/dist/streamers/response.streamer.d.ts.map +1 -0
- package/dist/streamers/response.streamer.js +46 -0
- package/dist/streamers/response.streamer.js.map +1 -0
- package/dist/support/chat.utils.d.ts +42 -0
- package/dist/support/chat.utils.d.ts.map +1 -0
- package/dist/support/chat.utils.js +89 -0
- package/dist/support/chat.utils.js.map +1 -0
- package/dist/support/debug-meta.sanitizer.d.ts +18 -0
- package/dist/support/debug-meta.sanitizer.d.ts.map +1 -0
- package/dist/support/debug-meta.sanitizer.js +82 -0
- package/dist/support/debug-meta.sanitizer.js.map +1 -0
- package/dist/support/feed.health.d.ts +32 -0
- package/dist/support/feed.health.d.ts.map +1 -0
- package/dist/support/feed.health.js +76 -0
- package/dist/support/feed.health.js.map +1 -0
- package/dist/support/introducer.discovery.d.ts +78 -0
- package/dist/support/introducer.discovery.d.ts.map +1 -0
- package/dist/support/introducer.discovery.js +101 -0
- package/dist/support/introducer.discovery.js.map +1 -0
- package/dist/support/log.d.ts +65 -0
- package/dist/support/log.d.ts.map +1 -0
- package/dist/support/log.js +76 -0
- package/dist/support/log.js.map +1 -0
- package/dist/support/lucide.icon-catalog.d.ts +22 -0
- package/dist/support/lucide.icon-catalog.d.ts.map +1 -0
- package/dist/support/lucide.icon-catalog.js +101 -0
- package/dist/support/lucide.icon-catalog.js.map +1 -0
- package/dist/support/opportunity.card-text.d.ts +39 -0
- package/dist/support/opportunity.card-text.d.ts.map +1 -0
- package/dist/support/opportunity.card-text.js +333 -0
- package/dist/support/opportunity.card-text.js.map +1 -0
- package/dist/support/opportunity.constants.d.ts +9 -0
- package/dist/support/opportunity.constants.d.ts.map +1 -0
- package/dist/support/opportunity.constants.js +11 -0
- package/dist/support/opportunity.constants.js.map +1 -0
- package/dist/support/opportunity.discover.d.ts +144 -0
- package/dist/support/opportunity.discover.d.ts.map +1 -0
- package/dist/support/opportunity.discover.js +610 -0
- package/dist/support/opportunity.discover.js.map +1 -0
- package/dist/support/opportunity.enricher.d.ts +44 -0
- package/dist/support/opportunity.enricher.d.ts.map +1 -0
- package/dist/support/opportunity.enricher.js +245 -0
- package/dist/support/opportunity.enricher.js.map +1 -0
- package/dist/support/opportunity.persist.d.ts +39 -0
- package/dist/support/opportunity.persist.d.ts.map +1 -0
- package/dist/support/opportunity.persist.js +63 -0
- package/dist/support/opportunity.persist.js.map +1 -0
- package/dist/support/opportunity.presentation.d.ts +21 -0
- package/dist/support/opportunity.presentation.d.ts.map +1 -0
- package/dist/support/opportunity.presentation.js +75 -0
- package/dist/support/opportunity.presentation.js.map +1 -0
- package/dist/support/opportunity.sanitize.d.ts +18 -0
- package/dist/support/opportunity.sanitize.d.ts.map +1 -0
- package/dist/support/opportunity.sanitize.js +89 -0
- package/dist/support/opportunity.sanitize.js.map +1 -0
- package/dist/support/opportunity.utils.d.ts +99 -0
- package/dist/support/opportunity.utils.d.ts.map +1 -0
- package/dist/support/opportunity.utils.js +184 -0
- package/dist/support/opportunity.utils.js.map +1 -0
- package/dist/support/performance.d.ts +19 -0
- package/dist/support/performance.d.ts.map +1 -0
- package/dist/support/performance.js +43 -0
- package/dist/support/performance.js.map +1 -0
- package/dist/support/profile.enrichment-display-name.d.ts +16 -0
- package/dist/support/profile.enrichment-display-name.d.ts.map +1 -0
- package/dist/support/profile.enrichment-display-name.js +22 -0
- package/dist/support/profile.enrichment-display-name.js.map +1 -0
- package/dist/support/protocol.logger.d.ts +22 -0
- package/dist/support/protocol.logger.d.ts.map +1 -0
- package/dist/support/protocol.logger.js +44 -0
- package/dist/support/protocol.logger.js.map +1 -0
- package/dist/support/request-context.d.ts +19 -0
- package/dist/support/request-context.d.ts.map +1 -0
- package/dist/support/request-context.js +7 -0
- package/dist/support/request-context.js.map +1 -0
- package/dist/tools/contact.tools.d.ts +7 -0
- package/dist/tools/contact.tools.d.ts.map +1 -0
- package/dist/tools/contact.tools.js +115 -0
- package/dist/tools/contact.tools.js.map +1 -0
- package/dist/tools/index.d.ts +17 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +140 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/index.tools.d.ts +3 -0
- package/dist/tools/index.tools.d.ts.map +1 -0
- package/dist/tools/index.tools.js +423 -0
- package/dist/tools/index.tools.js.map +1 -0
- package/dist/tools/integration.tools.d.ts +13 -0
- package/dist/tools/integration.tools.d.ts.map +1 -0
- package/dist/tools/integration.tools.js +77 -0
- package/dist/tools/integration.tools.js.map +1 -0
- package/dist/tools/intent.tools.d.ts +3 -0
- package/dist/tools/intent.tools.d.ts.map +1 -0
- package/dist/tools/intent.tools.js +458 -0
- package/dist/tools/intent.tools.js.map +1 -0
- package/dist/tools/opportunity.tools.d.ts +44 -0
- package/dist/tools/opportunity.tools.d.ts.map +1 -0
- package/dist/tools/opportunity.tools.js +814 -0
- package/dist/tools/opportunity.tools.js.map +1 -0
- package/dist/tools/profile.tools.d.ts +3 -0
- package/dist/tools/profile.tools.d.ts.map +1 -0
- package/dist/tools/profile.tools.js +513 -0
- package/dist/tools/profile.tools.js.map +1 -0
- package/dist/tools/tool.helpers.d.ts +225 -0
- package/dist/tools/tool.helpers.d.ts.map +1 -0
- package/dist/tools/tool.helpers.js +172 -0
- package/dist/tools/tool.helpers.js.map +1 -0
- package/dist/tools/tool.registry.d.ts +12 -0
- package/dist/tools/tool.registry.d.ts.map +1 -0
- package/dist/tools/tool.registry.js +62 -0
- package/dist/tools/tool.registry.js.map +1 -0
- package/dist/tools/utility.tools.d.ts +3 -0
- package/dist/tools/utility.tools.d.ts.map +1 -0
- package/dist/tools/utility.tools.js +107 -0
- package/dist/tools/utility.tools.js.map +1 -0
- package/dist/types/chat-streaming.types.d.ts +472 -0
- package/dist/types/chat-streaming.types.d.ts.map +1 -0
- package/dist/types/chat-streaming.types.js +260 -0
- package/dist/types/chat-streaming.types.js.map +1 -0
- package/package.json +32 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Home Categorizer Agent
|
|
3
|
+
*
|
|
4
|
+
* Takes a list of presenter-produced opportunity cards and returns dynamic sections
|
|
5
|
+
* with CTA-style titles and Lucide icon names. Used by the home graph after
|
|
6
|
+
* generateCardText.
|
|
7
|
+
*/
|
|
8
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
9
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
10
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
11
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
12
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
13
|
+
};
|
|
14
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
15
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
16
|
+
};
|
|
17
|
+
import { HumanMessage, SystemMessage } from '@langchain/core/messages';
|
|
18
|
+
import { z } from 'zod';
|
|
19
|
+
import { config } from 'dotenv';
|
|
20
|
+
config({ path: '.env.development' });
|
|
21
|
+
import { getIconNamesForPrompt, DEFAULT_HOME_SECTION_ICON } from '../support/lucide.icon-catalog.js';
|
|
22
|
+
import { protocolLogger } from '../support/protocol.logger.js';
|
|
23
|
+
import { Timed } from "../support/performance.js";
|
|
24
|
+
import { createModel } from "./model.config.js";
|
|
25
|
+
const logger = protocolLogger('HomeCategorizer');
|
|
26
|
+
const categorizationSchema = z.object({
|
|
27
|
+
sections: z.array(z.object({
|
|
28
|
+
id: z.string().describe('Short kebab-case id for the section'),
|
|
29
|
+
title: z
|
|
30
|
+
.string()
|
|
31
|
+
.describe('Call-to-action style section heading (e.g. REACH OUT NOW, YOUR MOVE, CONNECTIONS WAITING FOR YOU)'),
|
|
32
|
+
subtitle: z.string().nullable().describe('Optional one-line description; use null if none'),
|
|
33
|
+
iconName: z.string().describe('Lucide icon name in kebab-case from the allowed list'),
|
|
34
|
+
itemIndices: z.array(z.number()).describe('Indices of cards in this section (0-based)'),
|
|
35
|
+
})),
|
|
36
|
+
});
|
|
37
|
+
const UNCATEGORIZED_SECTION_ID = 'uncategorized';
|
|
38
|
+
const UNCATEGORIZED_SECTION_TITLE = 'UNCATEGORIZED OPPORTUNITIES';
|
|
39
|
+
/**
|
|
40
|
+
* Build card summaries for the categorizer prompt.
|
|
41
|
+
*/
|
|
42
|
+
function buildCardSummaries(cards) {
|
|
43
|
+
return cards
|
|
44
|
+
.map((c) => {
|
|
45
|
+
const role = c.viewerRole ?? 'party';
|
|
46
|
+
const status = c.opportunityStatus ?? 'pending';
|
|
47
|
+
return `[${c.index}] role=${role}; status=${status}; ${c.headline ?? c.mainText.slice(0, 60)}... (${c.name})`;
|
|
48
|
+
})
|
|
49
|
+
.join('\n');
|
|
50
|
+
}
|
|
51
|
+
function reconcileSections(sections, maxIndex) {
|
|
52
|
+
const assigned = new Set();
|
|
53
|
+
const normalizedSections = sections.map((section) => {
|
|
54
|
+
const uniqueIndices = Array.from(new Set(section.itemIndices.filter((index) => index >= 0 && index <= maxIndex))).sort((a, b) => a - b);
|
|
55
|
+
for (const index of uniqueIndices) {
|
|
56
|
+
assigned.add(index);
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
...section,
|
|
60
|
+
itemIndices: uniqueIndices,
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
const missingIndices = [];
|
|
64
|
+
for (let index = 0; index <= maxIndex; index += 1) {
|
|
65
|
+
if (!assigned.has(index)) {
|
|
66
|
+
missingIndices.push(index);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (missingIndices.length === 0) {
|
|
70
|
+
return normalizedSections;
|
|
71
|
+
}
|
|
72
|
+
const fallbackSection = normalizedSections.find((section) => section.id === UNCATEGORIZED_SECTION_ID);
|
|
73
|
+
if (fallbackSection) {
|
|
74
|
+
fallbackSection.itemIndices = Array.from(new Set([...fallbackSection.itemIndices, ...missingIndices])).sort((a, b) => a - b);
|
|
75
|
+
return normalizedSections;
|
|
76
|
+
}
|
|
77
|
+
return [
|
|
78
|
+
...normalizedSections,
|
|
79
|
+
{
|
|
80
|
+
id: UNCATEGORIZED_SECTION_ID,
|
|
81
|
+
title: UNCATEGORIZED_SECTION_TITLE,
|
|
82
|
+
iconName: DEFAULT_HOME_SECTION_ICON,
|
|
83
|
+
itemIndices: missingIndices,
|
|
84
|
+
},
|
|
85
|
+
];
|
|
86
|
+
}
|
|
87
|
+
export class HomeCategorizerAgent {
|
|
88
|
+
constructor() {
|
|
89
|
+
const llm = createModel("homeCategorizer");
|
|
90
|
+
this.model = llm.withStructuredOutput(categorizationSchema, { name: 'home_sections' });
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Categorize presenter-produced cards into 1–5 sections with CTA-style titles and icons.
|
|
94
|
+
*/
|
|
95
|
+
async categorize(cards) {
|
|
96
|
+
if (cards.length === 0) {
|
|
97
|
+
return { sections: [] };
|
|
98
|
+
}
|
|
99
|
+
const iconList = getIconNamesForPrompt();
|
|
100
|
+
const cardSummaries = buildCardSummaries(cards);
|
|
101
|
+
const maxIndex = cards.length - 1;
|
|
102
|
+
const systemPrompt = `You are organizing connection opportunities into dynamic sections for a user's home feed.
|
|
103
|
+
|
|
104
|
+
Given a list of opportunity cards (each with index, headline/summary, and name), group them into 1–5 sections.
|
|
105
|
+
|
|
106
|
+
Each section must have:
|
|
107
|
+
- id: short kebab-case identifier (e.g. waiting-for-action, your-perspective, connector)
|
|
108
|
+
- title: CALL-TO-ACTION style section heading in uppercase. Write as an action or invitation, not a neutral label. Examples: REACH OUT NOW, YOUR MOVE, CONNECTIONS WAITING FOR YOU, INTROS READY TO SEND, PEOPLE YOU SHOULD MEET
|
|
109
|
+
- subtitle: optional one-line description
|
|
110
|
+
- iconName: exactly ONE icon from this list (use the name as-is): ${iconList}
|
|
111
|
+
- itemIndices: array of card indices that belong in this section (each index 0 to ${maxIndex} at most once)
|
|
112
|
+
|
|
113
|
+
Rules:
|
|
114
|
+
- Use only icon names from the list above.
|
|
115
|
+
- Every card index must appear in exactly one section.
|
|
116
|
+
- Section titles must read as calls-to-action or invitations, not passive labels.
|
|
117
|
+
- If a card has role=introducer and status=pending, prioritize grouping those cards under a connector curation section with a CTA title like "YOU'RE THE CONNECTOR THEY NEED", "MAKE THE INTRO", or "DECIDE IF IT'S A GOOD MATCH".`;
|
|
118
|
+
const userContent = `Cards to categorize:\n${cardSummaries}\n\nOutput sections with id, title (CTA-style), subtitle (optional), iconName, and itemIndices.`;
|
|
119
|
+
try {
|
|
120
|
+
const result = await this.model.invoke([
|
|
121
|
+
new SystemMessage(systemPrompt),
|
|
122
|
+
new HumanMessage(userContent),
|
|
123
|
+
]);
|
|
124
|
+
const parsed = categorizationSchema.safeParse(result);
|
|
125
|
+
if (!parsed.success) {
|
|
126
|
+
logger.warn('HomeCategorizer parse failed', { error: parsed.error });
|
|
127
|
+
return {
|
|
128
|
+
sections: [
|
|
129
|
+
{
|
|
130
|
+
id: 'opportunities',
|
|
131
|
+
title: 'OPPORTUNITIES',
|
|
132
|
+
iconName: DEFAULT_HOME_SECTION_ICON,
|
|
133
|
+
itemIndices: cards.map((c) => c.index),
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
const sections = parsed.data.sections.map((s) => ({
|
|
139
|
+
id: s.id,
|
|
140
|
+
title: s.title,
|
|
141
|
+
subtitle: s.subtitle ?? undefined,
|
|
142
|
+
iconName: s.iconName,
|
|
143
|
+
itemIndices: s.itemIndices.filter((i) => i >= 0 && i <= maxIndex),
|
|
144
|
+
}));
|
|
145
|
+
const reconciledSections = reconcileSections(sections, maxIndex);
|
|
146
|
+
return { sections: reconciledSections };
|
|
147
|
+
}
|
|
148
|
+
catch (e) {
|
|
149
|
+
const err = e instanceof Error ? { message: e.message, name: e.name } : String(e);
|
|
150
|
+
logger.error('HomeCategorizer categorize failed', { error: err });
|
|
151
|
+
return {
|
|
152
|
+
sections: [
|
|
153
|
+
{
|
|
154
|
+
id: 'opportunities',
|
|
155
|
+
title: 'OPPORTUNITIES',
|
|
156
|
+
iconName: DEFAULT_HOME_SECTION_ICON,
|
|
157
|
+
itemIndices: cards.map((c) => c.index),
|
|
158
|
+
},
|
|
159
|
+
],
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
__decorate([
|
|
165
|
+
Timed(),
|
|
166
|
+
__metadata("design:type", Function),
|
|
167
|
+
__metadata("design:paramtypes", [Array]),
|
|
168
|
+
__metadata("design:returntype", Promise)
|
|
169
|
+
], HomeCategorizerAgent.prototype, "categorize", null);
|
|
170
|
+
//# sourceMappingURL=home.categorizer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"home.categorizer.js","sourceRoot":"","sources":["../../src/agents/home.categorizer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;;;;;;;;;;AAGH,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,MAAM,CAAC,EAAE,IAAI,EAAE,kBAAkB,EAAE,CAAC,CAAC;AAGrC,OAAO,EAAE,qBAAqB,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;A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,YAAY,KAAK,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YAClF,MAAM,CAAC,KAAK,CAAC,mCAAmC,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;YAClE,OAAO;gBACL,QAAQ,EAAE;oBACR;wBACE,EAAE,EAAE,eAAe;wBACnB,KAAK,EAAE,eAAe;wBACtB,QAAQ,EAAE,yBAAyB;wBACnC,WAAW,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;qBACvC;iBACF;aACF,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AAtEO;IADL,KAAK,EAAE;;;;sDAsEP"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { HydeTargetCorpus } from './lens.inferrer.js';
|
|
2
|
+
export interface HydeGeneratorOutput {
|
|
3
|
+
text: string;
|
|
4
|
+
}
|
|
5
|
+
export interface HydeGenerateInput {
|
|
6
|
+
/** Original intent or query text. */
|
|
7
|
+
sourceText: string;
|
|
8
|
+
/** Free-text lens label from LensInferrer (e.g. "crypto infra VC"). */
|
|
9
|
+
lens: string;
|
|
10
|
+
/** Which corpus voice to generate in. */
|
|
11
|
+
corpus: HydeTargetCorpus;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Generates hypothetical documents in a target corpus voice for semantic search.
|
|
15
|
+
* Uses free-text lens labels (from LensInferrer) instead of enum strategies.
|
|
16
|
+
*/
|
|
17
|
+
export declare class HydeGenerator {
|
|
18
|
+
private model;
|
|
19
|
+
/**
|
|
20
|
+
* Generate a hypothetical document for the given source text and lens.
|
|
21
|
+
*
|
|
22
|
+
* @param input - Source text, lens label, and target corpus
|
|
23
|
+
* @returns Generated hypothetical document text
|
|
24
|
+
*/
|
|
25
|
+
generate(input: HydeGenerateInput): Promise<HydeGeneratorOutput>;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=hyde.generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hyde.generator.d.ts","sourceRoot":"","sources":["../../src/agents/hyde.generator.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAyB3D,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,iBAAiB;IAChC,qCAAqC;IACrC,UAAU,EAAE,MAAM,CAAC;IACnB,uEAAuE;IACvE,IAAI,EAAE,MAAM,CAAC;IACb,yCAAyC;IACzC,MAAM,EAAE,gBAAgB,CAAC;CAC1B;AAED;;;GAGG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,KAAK,CAEV;IAEH;;;;;OAKG;IAEG,QAAQ,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,mBAAmB,CAAC;CAoBvE"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* HyDE Generator Agent: pure LLM agent for generating hypothetical documents
|
|
12
|
+
* in the target corpus voice. Uses free-text lens labels instead of enum strategies.
|
|
13
|
+
*/
|
|
14
|
+
import { HumanMessage, SystemMessage } from '@langchain/core/messages';
|
|
15
|
+
import { z } from 'zod';
|
|
16
|
+
import { HYDE_CORPUS_PROMPTS } from './hyde.strategies.js';
|
|
17
|
+
import { Timed } from "../support/performance.js";
|
|
18
|
+
import { protocolLogger } from '../support/protocol.logger.js';
|
|
19
|
+
import { createModel } from "./model.config.js";
|
|
20
|
+
const logger = protocolLogger("HydeGenerator");
|
|
21
|
+
const SYSTEM_PROMPT = `You are a Hypothetical Document Generator for semantic search.
|
|
22
|
+
|
|
23
|
+
Your task: Given a source statement (e.g. an intent or goal), write a short hypothetical document in the voice of the TARGET side—the kind of person or statement that would be an ideal match for that source.
|
|
24
|
+
|
|
25
|
+
Rules:
|
|
26
|
+
- Write in first person as the target.
|
|
27
|
+
- Be concrete and specific so the text is good for vector similarity search.
|
|
28
|
+
- Output only the hypothetical document text, no meta-commentary.
|
|
29
|
+
- Keep length to a few sentences or one short paragraph.`;
|
|
30
|
+
const responseFormat = z.object({
|
|
31
|
+
hypotheticalDocument: z
|
|
32
|
+
.string()
|
|
33
|
+
.describe('The hypothetical document text in the target voice, suitable for embedding and retrieval'),
|
|
34
|
+
});
|
|
35
|
+
const model = createModel("hydeGenerator");
|
|
36
|
+
/**
|
|
37
|
+
* Generates hypothetical documents in a target corpus voice for semantic search.
|
|
38
|
+
* Uses free-text lens labels (from LensInferrer) instead of enum strategies.
|
|
39
|
+
*/
|
|
40
|
+
export class HydeGenerator {
|
|
41
|
+
constructor() {
|
|
42
|
+
this.model = model.withStructuredOutput(responseFormat, {
|
|
43
|
+
name: "hyde_generator",
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Generate a hypothetical document for the given source text and lens.
|
|
48
|
+
*
|
|
49
|
+
* @param input - Source text, lens label, and target corpus
|
|
50
|
+
* @returns Generated hypothetical document text
|
|
51
|
+
*/
|
|
52
|
+
async generate(input) {
|
|
53
|
+
const promptText = HYDE_CORPUS_PROMPTS[input.corpus](input.sourceText, input.lens);
|
|
54
|
+
const messages = [
|
|
55
|
+
new SystemMessage(SYSTEM_PROMPT),
|
|
56
|
+
new HumanMessage(promptText),
|
|
57
|
+
];
|
|
58
|
+
const result = await this.model.invoke(messages);
|
|
59
|
+
const parsed = responseFormat.parse(result);
|
|
60
|
+
const text = parsed.hypotheticalDocument ?? '';
|
|
61
|
+
logger.verbose('Generated HyDE document', {
|
|
62
|
+
lens: input.lens,
|
|
63
|
+
corpus: input.corpus,
|
|
64
|
+
textLength: text.length,
|
|
65
|
+
});
|
|
66
|
+
return { text };
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
__decorate([
|
|
70
|
+
Timed(),
|
|
71
|
+
__metadata("design:type", Function),
|
|
72
|
+
__metadata("design:paramtypes", [Object]),
|
|
73
|
+
__metadata("design:returntype", Promise)
|
|
74
|
+
], HydeGenerator.prototype, "generate", null);
|
|
75
|
+
//# sourceMappingURL=hyde.generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hyde.generator.js","sourceRoot":"","sources":["../../src/agents/hyde.generator.ts"],"names":[],"mappings":";;;;;;;;;AAAA;;;GAGG;AACH,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAE3D,OAAO,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,MAAM,GAAG,cAAc,CAAC,eAAe,CAAC,CAAC;AAE/C,MAAM,aAAa,GAAG;;;;;;;;yDAQmC,CAAC;AAE1D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
|
+
* The system is now role-agnostic: instead of hardcoded strategy names
|
|
5
|
+
* (mirror, reciprocal, mentor, investor, collaborator, hiree), an LLM
|
|
6
|
+
* infers free-text "lenses" dynamically. This file re-exports the lens
|
|
7
|
+
* types and provides constants for the HyDE pipeline.
|
|
8
|
+
*/
|
|
9
|
+
export type { Lens, HydeTargetCorpus, LensInferenceInput, LensInferenceOutput } from './lens.inferrer.js';
|
|
10
|
+
/** Default cache TTL for ephemeral HyDE documents (1 hour). */
|
|
11
|
+
export declare const HYDE_DEFAULT_CACHE_TTL = 3600;
|
|
12
|
+
/**
|
|
13
|
+
* Prompt templates for HyDE document generation.
|
|
14
|
+
* Keyed by target corpus — the lens label provides the semantic specificity.
|
|
15
|
+
*/
|
|
16
|
+
export declare const HYDE_CORPUS_PROMPTS: Record<'profiles' | 'intents', (sourceText: string, lens: string) => string>;
|
|
17
|
+
//# sourceMappingURL=hyde.strategies.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hyde.strategies.d.ts","sourceRoot":"","sources":["../../src/agents/hyde.strategies.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,YAAY,EAAE,IAAI,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAE1G,+DAA+D;AAC/D,eAAO,MAAM,sBAAsB,OAAO,CAAC;AAE3C;;;GAGG;AACH,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,UAAU,GAAG,SAAS,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAa5G,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HyDE (Hypothetical Document Embeddings) type definitions.
|
|
3
|
+
*
|
|
4
|
+
* The system is now role-agnostic: instead of hardcoded strategy names
|
|
5
|
+
* (mirror, reciprocal, mentor, investor, collaborator, hiree), an LLM
|
|
6
|
+
* infers free-text "lenses" dynamically. This file re-exports the lens
|
|
7
|
+
* types and provides constants for the HyDE pipeline.
|
|
8
|
+
*/
|
|
9
|
+
/** Default cache TTL for ephemeral HyDE documents (1 hour). */
|
|
10
|
+
export const HYDE_DEFAULT_CACHE_TTL = 3600;
|
|
11
|
+
/**
|
|
12
|
+
* Prompt templates for HyDE document generation.
|
|
13
|
+
* Keyed by target corpus — the lens label provides the semantic specificity.
|
|
14
|
+
*/
|
|
15
|
+
export const HYDE_CORPUS_PROMPTS = {
|
|
16
|
+
profiles: (sourceText, lens) => `
|
|
17
|
+
Write a professional biography for someone who could fulfill this need: "${sourceText}".
|
|
18
|
+
Focus on the specific expertise, background, and role described by: ${lens}.
|
|
19
|
+
|
|
20
|
+
Write in first person. Include concrete skills, domain experience, and current professional focus that would make them a strong match.
|
|
21
|
+
`,
|
|
22
|
+
intents: (sourceText, lens) => `
|
|
23
|
+
Write a goal or aspiration statement for someone who is: ${lens}.
|
|
24
|
+
This person's needs would complement: "${sourceText}".
|
|
25
|
+
|
|
26
|
+
Write in first person as if stating their own goal.
|
|
27
|
+
`,
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=hyde.strategies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hyde.strategies.js","sourceRoot":"","sources":["../../src/agents/hyde.strategies.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,+DAA+D;AAC/D,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,CAAC;AAE3C;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAiF;IAC/G,QAAQ,EAAE,CAAC,UAAU,EAAE,IAAI,EAAE,EAAE,CAAC;+EAC6C,UAAU;0EACf,IAAI;;;GAG3E;IACD,OAAO,EAAE,CAAC,UAAU,EAAE,IAAI,EAAE,EAAE,CAAC;+DAC8B,IAAI;6CACtB,UAAU;;;GAGpD;CACF,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
declare const clarificationSchema: z.ZodObject<{
|
|
3
|
+
needsClarification: z.ZodBoolean;
|
|
4
|
+
reason: z.ZodString;
|
|
5
|
+
suggestedDescription: z.ZodNullable<z.ZodString>;
|
|
6
|
+
clarificationMessage: z.ZodNullable<z.ZodString>;
|
|
7
|
+
}, "strip", z.ZodTypeAny, {
|
|
8
|
+
reason: string;
|
|
9
|
+
needsClarification: boolean;
|
|
10
|
+
suggestedDescription: string | null;
|
|
11
|
+
clarificationMessage: string | null;
|
|
12
|
+
}, {
|
|
13
|
+
reason: string;
|
|
14
|
+
needsClarification: boolean;
|
|
15
|
+
suggestedDescription: string | null;
|
|
16
|
+
clarificationMessage: string | null;
|
|
17
|
+
}>;
|
|
18
|
+
export type IntentClarifierOutput = z.infer<typeof clarificationSchema>;
|
|
19
|
+
export declare class IntentClarifier {
|
|
20
|
+
private readonly model;
|
|
21
|
+
private readonly suggestionModel;
|
|
22
|
+
private readonly clarificationDraftModel;
|
|
23
|
+
constructor();
|
|
24
|
+
invoke(description: string, profileContext: string, activeIntentsContext: string): Promise<IntentClarifierOutput>;
|
|
25
|
+
private generateSuggestion;
|
|
26
|
+
private generateClarificationDraft;
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=intent.clarifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intent.clarifier.d.ts","sourceRoot":"","sources":["../../src/agents/intent.clarifier.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAWxB,QAAA,MAAM,mBAAmB;;;;;;;;;;;;;;;EAKvB,CAAC;AASH,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AA4CxE,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA2B;IACjD,OAAO,CAAC,QAAQ,CAAC,eAAe,CAA2B;IAC3D,OAAO,CAAC,QAAQ,CAAC,uBAAuB,CAA2B;;IAiBtD,MAAM,CACjB,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,MAAM,EACtB,oBAAoB,EAAE,MAAM,GAC3B,OAAO,CAAC,qBAAqB,CAAC;YA2CnB,kBAAkB;YA6BlB,0BAA0B;CAoCzC"}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { HumanMessage, SystemMessage } from "@langchain/core/messages";
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
import { protocolLogger } from "../support/protocol.logger.js";
|
|
13
|
+
import { Timed } from "../support/performance.js";
|
|
14
|
+
import { createModel } from "./model.config.js";
|
|
15
|
+
const logger = protocolLogger("IntentClarifier");
|
|
16
|
+
const clarificationSchema = z.object({
|
|
17
|
+
needsClarification: z.boolean(),
|
|
18
|
+
reason: z.string(),
|
|
19
|
+
suggestedDescription: z.string().nullable(),
|
|
20
|
+
clarificationMessage: z.string().nullable(),
|
|
21
|
+
});
|
|
22
|
+
const suggestionSchema = z.object({
|
|
23
|
+
suggestedDescription: z.string(),
|
|
24
|
+
});
|
|
25
|
+
const clarificationDraftSchema = z.object({
|
|
26
|
+
suggestedDescription: z.string(),
|
|
27
|
+
clarificationMessage: z.string(),
|
|
28
|
+
});
|
|
29
|
+
const systemPrompt = `
|
|
30
|
+
You evaluate whether an intent is specific enough to persist without asking the user to confirm a refinement.
|
|
31
|
+
|
|
32
|
+
Only set needsClarification=true when the intent is truly vague — e.g. a single generic phrase with no role, domain, location, or other concrete criteria (like "find a job", "I need help", "looking for something").
|
|
33
|
+
|
|
34
|
+
Do NOT ask for clarification when the user has already given:
|
|
35
|
+
- A role or type (e.g. "UX designer", "technical co-founder", "engineer")
|
|
36
|
+
- A domain or industry (e.g. "in AI", "climate tech", "fintech")
|
|
37
|
+
- A location or format (e.g. "remote", "Berlin", "full-time")
|
|
38
|
+
- Any other concrete detail that makes the intent actionable
|
|
39
|
+
|
|
40
|
+
Default to needsClarification=false when in doubt. Only clarify when the intent is so broad that persisting it as-is would be unhelpful (e.g. literally "a job" or "something" with no other signal).
|
|
41
|
+
|
|
42
|
+
Rules when needsClarification=true:
|
|
43
|
+
- User Profile is the primary source for suggestedDescription; Active Intents are secondary.
|
|
44
|
+
- You MUST provide a concrete suggestedDescription and short clarificationMessage.
|
|
45
|
+
- Do not include JSON in clarificationMessage.
|
|
46
|
+
`;
|
|
47
|
+
const suggestionPrompt = `
|
|
48
|
+
You generate one concrete, specific intent rewrite.
|
|
49
|
+
|
|
50
|
+
Rules:
|
|
51
|
+
- Output only a concise intent sentence in suggestedDescription.
|
|
52
|
+
- Use profile as primary source of personalization.
|
|
53
|
+
- Use active intents as secondary context for consistency.
|
|
54
|
+
- Keep user intent meaning, but make it actionable and specific.
|
|
55
|
+
- Never return an empty suggestion.
|
|
56
|
+
`;
|
|
57
|
+
const clarificationDraftPrompt = `
|
|
58
|
+
You draft a concise clarification response for a vague intent.
|
|
59
|
+
|
|
60
|
+
Rules:
|
|
61
|
+
- Return both:
|
|
62
|
+
1) suggestedDescription (specific rewritten intent)
|
|
63
|
+
2) clarificationMessage (single short message to the user)
|
|
64
|
+
- clarificationMessage must include the suggestion naturally and ask for confirmation.
|
|
65
|
+
- Use this shape: ` + "`Did you mean: \"<suggestedDescription>\"?`" + ` followed by a brief confirmation instruction.
|
|
66
|
+
- Keep it short. No bullet lists. No JSON.
|
|
67
|
+
`;
|
|
68
|
+
export class IntentClarifier {
|
|
69
|
+
constructor() {
|
|
70
|
+
const baseModel = createModel("intentClarifier");
|
|
71
|
+
this.model = baseModel.withStructuredOutput(clarificationSchema, {
|
|
72
|
+
name: "intent_clarifier",
|
|
73
|
+
});
|
|
74
|
+
this.suggestionModel = baseModel.withStructuredOutput(suggestionSchema, {
|
|
75
|
+
name: "intent_clarifier_suggestion",
|
|
76
|
+
});
|
|
77
|
+
this.clarificationDraftModel = baseModel.withStructuredOutput(clarificationDraftSchema, { name: "intent_clarifier_message" });
|
|
78
|
+
}
|
|
79
|
+
async invoke(description, profileContext, activeIntentsContext) {
|
|
80
|
+
try {
|
|
81
|
+
const prompt = `
|
|
82
|
+
# User Input Intent
|
|
83
|
+
${description}
|
|
84
|
+
|
|
85
|
+
# User Profile
|
|
86
|
+
${profileContext || "none"}
|
|
87
|
+
|
|
88
|
+
# Active Intents
|
|
89
|
+
${activeIntentsContext || "none"}
|
|
90
|
+
`;
|
|
91
|
+
const result = await this.model.invoke([
|
|
92
|
+
new SystemMessage(systemPrompt),
|
|
93
|
+
new HumanMessage(prompt),
|
|
94
|
+
]);
|
|
95
|
+
const parsed = clarificationSchema.parse(result);
|
|
96
|
+
if (parsed.needsClarification) {
|
|
97
|
+
// Always prefer a dedicated rewrite pass for vague inputs so we avoid generic follow-up text.
|
|
98
|
+
const draft = await this.generateClarificationDraft(description, profileContext, activeIntentsContext);
|
|
99
|
+
if (draft) {
|
|
100
|
+
return {
|
|
101
|
+
...parsed,
|
|
102
|
+
suggestedDescription: draft.suggestedDescription,
|
|
103
|
+
clarificationMessage: draft.clarificationMessage,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return parsed;
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
logger.warn("invoke: clarification failed", { error });
|
|
111
|
+
return {
|
|
112
|
+
needsClarification: false,
|
|
113
|
+
reason: "fallback_on_model_error",
|
|
114
|
+
suggestedDescription: null,
|
|
115
|
+
clarificationMessage: null,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
async generateSuggestion(description, profileContext, activeIntentsContext) {
|
|
120
|
+
try {
|
|
121
|
+
const prompt = `
|
|
122
|
+
# User Input Intent
|
|
123
|
+
${description}
|
|
124
|
+
|
|
125
|
+
# User Profile
|
|
126
|
+
${profileContext || "none"}
|
|
127
|
+
|
|
128
|
+
# Active Intents
|
|
129
|
+
${activeIntentsContext || "none"}
|
|
130
|
+
`;
|
|
131
|
+
const output = await this.suggestionModel.invoke([
|
|
132
|
+
new SystemMessage(suggestionPrompt),
|
|
133
|
+
new HumanMessage(prompt),
|
|
134
|
+
]);
|
|
135
|
+
const parsed = suggestionSchema.parse(output);
|
|
136
|
+
const suggestion = parsed.suggestedDescription.trim();
|
|
137
|
+
return suggestion.length > 0 ? suggestion : null;
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
logger.warn("generateSuggestion: failed", { error });
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
async generateClarificationDraft(description, profileContext, activeIntentsContext) {
|
|
145
|
+
try {
|
|
146
|
+
const prompt = `
|
|
147
|
+
# User Input Intent
|
|
148
|
+
${description}
|
|
149
|
+
|
|
150
|
+
# User Profile
|
|
151
|
+
${profileContext || "none"}
|
|
152
|
+
|
|
153
|
+
# Active Intents
|
|
154
|
+
${activeIntentsContext || "none"}
|
|
155
|
+
`;
|
|
156
|
+
const output = await this.clarificationDraftModel.invoke([
|
|
157
|
+
new SystemMessage(clarificationDraftPrompt),
|
|
158
|
+
new HumanMessage(prompt),
|
|
159
|
+
]);
|
|
160
|
+
const parsed = clarificationDraftSchema.parse(output);
|
|
161
|
+
const suggestedDescription = parsed.suggestedDescription.trim();
|
|
162
|
+
const clarificationMessage = parsed.clarificationMessage.trim();
|
|
163
|
+
if (!suggestedDescription || !clarificationMessage)
|
|
164
|
+
return null;
|
|
165
|
+
return { suggestedDescription, clarificationMessage };
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
logger.warn("generateClarificationDraft: failed", { error });
|
|
169
|
+
const suggestion = await this.generateSuggestion(description, profileContext, activeIntentsContext);
|
|
170
|
+
if (!suggestion)
|
|
171
|
+
return null;
|
|
172
|
+
const clarificationMessage = `Do you mean: ${suggestion}?`;
|
|
173
|
+
return {
|
|
174
|
+
suggestedDescription: suggestion,
|
|
175
|
+
clarificationMessage,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
__decorate([
|
|
181
|
+
Timed(),
|
|
182
|
+
__metadata("design:type", Function),
|
|
183
|
+
__metadata("design:paramtypes", [String, String, String]),
|
|
184
|
+
__metadata("design:returntype", Promise)
|
|
185
|
+
], IntentClarifier.prototype, "invoke", null);
|
|
186
|
+
//# sourceMappingURL=intent.clarifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intent.clarifier.js","sourceRoot":"","sources":["../../src/agents/intent.clarifier.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAElD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,MAAM,GAAG,cAAc,CAAC,iBAAiB,CAAC,CAAC;AAIjD,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,kBAAkB,EAAE,CAAC,CAAC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AE,EAAE,KAAK,EAAE,CAAC,CAAC;YAC7D,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,kBAAkB,CAAC,WAAW,EAAE,cAAc,EAAE,oBAAoB,CAAC,CAAC;YACpG,IAAI,CAAC,UAAU;gBAAE,OAAO,IAAI,CAAC;YAC7B,MAAM,oBAAoB,GAAG,gBAAgB,UAAU,GAAG,CAAC;YAC3D,OAAO;gBACL,oBAAoB,EAAE,UAAU;gBAChC,oBAAoB;aACrB,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AAhHc;IADZ,KAAK,EAAE;;;;6CA8CP"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const IntentIndexerOutputSchema: z.ZodObject<{
|
|
3
|
+
indexScore: z.ZodNumber;
|
|
4
|
+
memberScore: z.ZodNumber;
|
|
5
|
+
reasoning: z.ZodString;
|
|
6
|
+
}, "strip", z.ZodTypeAny, {
|
|
7
|
+
reasoning: string;
|
|
8
|
+
indexScore: number;
|
|
9
|
+
memberScore: number;
|
|
10
|
+
}, {
|
|
11
|
+
reasoning: string;
|
|
12
|
+
indexScore: number;
|
|
13
|
+
memberScore: number;
|
|
14
|
+
}>;
|
|
15
|
+
/**
|
|
16
|
+
* Output structure for the Intent Indexer agent.
|
|
17
|
+
*/
|
|
18
|
+
export type IntentIndexerOutput = z.infer<typeof IntentIndexerOutputSchema>;
|
|
19
|
+
export declare class IntentIndexer {
|
|
20
|
+
private model;
|
|
21
|
+
constructor();
|
|
22
|
+
/**
|
|
23
|
+
* Converts the structured response into a string for logging or embedding.
|
|
24
|
+
* Used when the output needs to be serialized (e.g. for traces).
|
|
25
|
+
*/
|
|
26
|
+
private toString;
|
|
27
|
+
/**
|
|
28
|
+
* Main entry point. Evaluates the appropriateness of an intent for a given index and member context.
|
|
29
|
+
*
|
|
30
|
+
* @param intent - The intent payload.
|
|
31
|
+
* @param indexPrompt - The purpose of the index (community).
|
|
32
|
+
* @param memberPrompt - The member's sharing preferences (optional).
|
|
33
|
+
* @param sourceName - Optional source name for context (e.g. file, link).
|
|
34
|
+
* @returns Structured output with indexScore, memberScore, and reasoning, or null on error.
|
|
35
|
+
*/
|
|
36
|
+
invoke(intent: string, indexPrompt: string | null, memberPrompt: string | null, sourceName?: string | null): Promise<IntentIndexerOutput | null>;
|
|
37
|
+
/**
|
|
38
|
+
* Alias for invoke. Evaluates the appropriateness of an intent for a given index and member context.
|
|
39
|
+
* Kept for compatibility with callers (e.g. Index Graph) that use evaluate().
|
|
40
|
+
*/
|
|
41
|
+
evaluate(intent: string, indexPrompt: string | null, memberPrompt: string | null, sourceName?: string | null): Promise<IntentIndexerOutput | null>;
|
|
42
|
+
/**
|
|
43
|
+
* Factory method to expose the agent as a LangChain tool.
|
|
44
|
+
* Useful for composing agents into larger graphs.
|
|
45
|
+
*/
|
|
46
|
+
static asTool(): import("@langchain/core/tools").DynamicStructuredTool<z.ZodObject<{
|
|
47
|
+
intent: z.ZodString;
|
|
48
|
+
indexPrompt: z.ZodNullable<z.ZodString>;
|
|
49
|
+
memberPrompt: z.ZodNullable<z.ZodString>;
|
|
50
|
+
sourceName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
51
|
+
}, "strip", z.ZodTypeAny, {
|
|
52
|
+
intent: string;
|
|
53
|
+
indexPrompt: string | null;
|
|
54
|
+
memberPrompt: string | null;
|
|
55
|
+
sourceName?: string | null | undefined;
|
|
56
|
+
}, {
|
|
57
|
+
intent: string;
|
|
58
|
+
indexPrompt: string | null;
|
|
59
|
+
memberPrompt: string | null;
|
|
60
|
+
sourceName?: string | null | undefined;
|
|
61
|
+
}>, {
|
|
62
|
+
intent: string;
|
|
63
|
+
indexPrompt: string | null;
|
|
64
|
+
memberPrompt: string | null;
|
|
65
|
+
sourceName?: string | null | undefined;
|
|
66
|
+
}, {
|
|
67
|
+
intent: string;
|
|
68
|
+
indexPrompt: string | null;
|
|
69
|
+
memberPrompt: string | null;
|
|
70
|
+
sourceName?: string | null | undefined;
|
|
71
|
+
}, {
|
|
72
|
+
reasoning: string;
|
|
73
|
+
indexScore: number;
|
|
74
|
+
memberScore: number;
|
|
75
|
+
} | null, unknown, "intent_indexer">;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=intent.indexer.d.ts.map
|