@indexnetwork/protocol 4.4.1 → 4.5.0-rc.322.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.interrupt.classifier.d.ts.map +1 -1
- package/dist/chat/chat.interrupt.classifier.js +2 -2
- package/dist/chat/chat.interrupt.classifier.js.map +1 -1
- package/dist/chat/chat.suggester.d.ts.map +1 -1
- package/dist/chat/chat.suggester.js +2 -3
- package/dist/chat/chat.suggester.js.map +1 -1
- package/dist/chat/chat.summarizer.d.ts.map +1 -1
- package/dist/chat/chat.summarizer.js +11 -3
- package/dist/chat/chat.summarizer.js.map +1 -1
- package/dist/chat/chat.title.generator.d.ts.map +1 -1
- package/dist/chat/chat.title.generator.js +2 -2
- package/dist/chat/chat.title.generator.js.map +1 -1
- package/dist/contact/contact.inviter.d.ts.map +1 -1
- package/dist/contact/contact.inviter.js +2 -3
- package/dist/contact/contact.inviter.js.map +1 -1
- package/dist/context/context.generator.d.ts.map +1 -1
- package/dist/context/context.generator.js +2 -2
- package/dist/context/context.generator.js.map +1 -1
- package/dist/enrichment/enrichment.generator.d.ts +1 -1
- package/dist/enrichment/enrichment.generator.d.ts.map +1 -1
- package/dist/enrichment/enrichment.generator.js +3 -4
- package/dist/enrichment/enrichment.generator.js.map +1 -1
- package/dist/intent/intent.clarifier.d.ts.map +1 -1
- package/dist/intent/intent.clarifier.js +4 -5
- package/dist/intent/intent.clarifier.js.map +1 -1
- package/dist/intent/intent.indexer.d.ts.map +1 -1
- package/dist/intent/intent.indexer.js +2 -3
- package/dist/intent/intent.indexer.js.map +1 -1
- package/dist/intent/intent.inferrer.d.ts.map +1 -1
- package/dist/intent/intent.inferrer.js +2 -3
- package/dist/intent/intent.inferrer.js.map +1 -1
- package/dist/intent/intent.reconciler.d.ts.map +1 -1
- package/dist/intent/intent.reconciler.js +2 -3
- package/dist/intent/intent.reconciler.js.map +1 -1
- package/dist/intent/intent.verifier.d.ts.map +1 -1
- package/dist/intent/intent.verifier.js +2 -3
- package/dist/intent/intent.verifier.js.map +1 -1
- package/dist/negotiation/insight.generator.d.ts.map +1 -1
- package/dist/negotiation/insight.generator.js +2 -2
- package/dist/negotiation/insight.generator.js.map +1 -1
- package/dist/negotiation/negotiation.agent.js +2 -2
- package/dist/negotiation/negotiation.agent.js.map +1 -1
- package/dist/negotiation/negotiation.summarizer.d.ts +11 -0
- package/dist/negotiation/negotiation.summarizer.d.ts.map +1 -1
- package/dist/negotiation/negotiation.summarizer.js +13 -3
- package/dist/negotiation/negotiation.summarizer.js.map +1 -1
- package/dist/network/network.recommender.d.ts.map +1 -1
- package/dist/network/network.recommender.js +2 -3
- package/dist/network/network.recommender.js.map +1 -1
- package/dist/opportunity/feed/feed.categorizer.d.ts.map +1 -1
- package/dist/opportunity/feed/feed.categorizer.js +2 -3
- package/dist/opportunity/feed/feed.categorizer.js.map +1 -1
- package/dist/opportunity/opportunity.evaluator.d.ts.map +1 -1
- package/dist/opportunity/opportunity.evaluator.js +3 -4
- package/dist/opportunity/opportunity.evaluator.js.map +1 -1
- package/dist/opportunity/opportunity.presenter.d.ts.map +1 -1
- package/dist/opportunity/opportunity.presenter.js +3 -4
- package/dist/opportunity/opportunity.presenter.js.map +1 -1
- package/dist/opportunity/question.generator.d.ts.map +1 -1
- package/dist/opportunity/question.generator.js +17 -3
- package/dist/opportunity/question.generator.js.map +1 -1
- package/dist/premise/premise.analyzer.d.ts.map +1 -1
- package/dist/premise/premise.analyzer.js +2 -3
- package/dist/premise/premise.analyzer.js.map +1 -1
- package/dist/premise/premise.decomposer.d.ts.map +1 -1
- package/dist/premise/premise.decomposer.js +2 -3
- package/dist/premise/premise.decomposer.js.map +1 -1
- package/dist/premise/premise.indexer.d.ts.map +1 -1
- package/dist/premise/premise.indexer.js +2 -3
- package/dist/premise/premise.indexer.js.map +1 -1
- package/dist/questioner/questioner.agent.d.ts +2 -2
- package/dist/questioner/questioner.agent.d.ts.map +1 -1
- package/dist/questioner/questioner.agent.js +12 -4
- package/dist/questioner/questioner.agent.js.map +1 -1
- package/dist/shared/agent/model.config.d.ts +41 -2
- package/dist/shared/agent/model.config.d.ts.map +1 -1
- package/dist/shared/agent/model.config.js +98 -1
- package/dist/shared/agent/model.config.js.map +1 -1
- package/dist/shared/hyde/hyde.generator.d.ts.map +1 -1
- package/dist/shared/hyde/hyde.generator.js +2 -3
- package/dist/shared/hyde/hyde.generator.js.map +1 -1
- package/dist/shared/hyde/lens.inferrer.d.ts.map +1 -1
- package/dist/shared/hyde/lens.inferrer.js +2 -3
- package/dist/shared/hyde/lens.inferrer.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.config.js","sourceRoot":"/","sources":["shared/agent/model.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AA6B/C,SAAS,cAAc,CAAC,MAAoB;IAC1C,OAAO;QACL,cAAc,EAAQ,EAAE,KAAK,EAAE,yBAAyB,EAAE;QAC1D,aAAa,EAAS,EAAE,KAAK,EAAE,yBAAyB,EAAE;QAC1D,cAAc,EAAQ,EAAE,KAAK,EAAE,yBAAyB,EAAE;QAC1D,gBAAgB,EAAM,EAAE,KAAK,EAAE,yBAAyB,EAAE;QAC1D,eAAe,EAAO,EAAE,KAAK,EAAE,yBAAyB,EAAE;QAC1D,gBAAgB,EAAM,EAAE,KAAK,EAAE,yBAAyB,EAAE;QAC1D,aAAa,EAAS,EAAE,KAAK,EAAE,yBAAyB,EAAE;QAC1D,YAAY,EAAU,EAAE,KAAK,EAAE,yBAAyB,EAAE;QAC1D,oBAAoB,EAAE,EAAE,KAAK,EAAE,yBAAyB,EAAE;QAC1D,oBAAoB,EAAE,EAAE,KAAK,EAAE,yBAAyB,EAAE;QAC1D,UAAU,EAAY,EAAE,KAAK,EAAE,yBAAyB,EAAE;QAC1D,eAAe,EAAO,EAAE,KAAK,EAAE,yBAAyB,EAAE;QAC1D,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AA0B;IAC1B,MAAM,UAAU,GAAG,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,sBAAsB,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;IACjF,MAAM,UAAU,GAAG,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,UAAU,IAAI,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;IACnF,OAAO,IAAI,UAAU,CAAC;QACpB,KAAK,EAAE,GAAG,CAAC,KAAK;QAChB,aAAa,EAAE;YACb,OAAO,EAAE,MAAM,EAAE,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,8BAA8B;YAC7F,MAAM;SACP;QACD,WAAW,EAAE,GAAG,CAAC,WAAW;QAC5B,SAAS,EAAE,GAAG,CAAC,SAAS;QACxB,OAAO;QACP,UAAU;QACV,GAAG,CAAC,GAAG,CAAC,SAAS,IAAI,EAAE,WAAW,EAAE,EAAE,SAAS,EAAE,GAAG,CAAC,SAAS,EAAE,EAAE,CAAC;KACpE,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { ChatOpenAI } from \"@langchain/openai\";\n\n/** Settings that can be configured per agent. */\nexport interface ModelSettings {\n model: string;\n temperature?: number;\n maxTokens?: number;\n reasoning?: { effort?: 'minimal' | 'low' | 'medium' | 'high' | 'xhigh'; exclude?: boolean };\n}\n\n/**\n * Runtime configuration for the protocol package.\n * When passed via `ToolContext.modelConfig`, all fields (`apiKey`, `baseURL`, `chatModel`,\n * `chatReasoningEffort`) are honored by `ChatAgent` when the chat graph runs.\n * Other protocol agents don't read from `ToolContext` but may accept an explicit `ModelConfig`\n * as a direct parameter to `createModel()`.\n * All fields fall back to environment variables if not provided.\n */\nexport interface ModelConfig {\n /** OpenRouter API key. Falls back to OPENROUTER_API_KEY env var. */\n apiKey?: string;\n /** OpenRouter base URL. Falls back to OPENROUTER_BASE_URL env var. */\n baseURL?: string;\n /** Override the chat agent model. Falls back to CHAT_MODEL env var. */\n chatModel?: string;\n /** Override the chat reasoning effort. Falls back to CHAT_REASONING_EFFORT env var. */\n chatReasoningEffort?: 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';\n}\n\nfunction getModelConfig(config?: ModelConfig) {\n return {\n intentInferrer: { model: \"google/gemini-2.5-flash\" },\n intentIndexer: { model: \"google/gemini-2.5-flash\" },\n intentVerifier: { model: \"google/gemini-2.5-flash\" },\n intentReconciler: { model: \"google/gemini-2.5-flash\" },\n intentClarifier: { model: \"google/gemini-2.5-flash\" },\n profileGenerator: { model: \"google/gemini-2.5-flash\" },\n hydeGenerator: { model: \"google/gemini-2.5-flash\" },\n lensInferrer: { model: \"google/gemini-2.5-flash\" },\n opportunityEvaluator: { model: \"google/gemini-2.5-flash\" },\n opportunityPresenter: { model: \"google/gemini-2.5-flash\" },\n negotiator: { model: \"google/gemini-2.5-flash\" },\n homeCategorizer: { model: \"google/gemini-2.5-flash\" },\n suggestionGenerator: { model: \"google/gemini-2.5-flash\", temperature: 0.4, maxTokens: 512 },\n chatTitleGenerator: { model: \"google/gemini-2.5-flash\", temperature: 0.3, maxTokens: 32 },\n negotiationInsights: { model: \"google/gemini-2.5-flash\", temperature: 0.4, maxTokens: 512 },\n chatContextSummarizer: { model: \"google/gemini-2.5-flash\", temperature: 0.2, maxTokens: 512 },\n discoveryQuestionGenerator: { model: \"google/gemini-2.5-flash\", temperature: 0.5, maxTokens: 1024 },\n questioner: { model: \"google/gemini-2.5-flash\", temperature: 0.5, maxTokens: 1024 },\n negotiationSummarizer: { model: \"google/gemini-2.5-flash\", temperature: 0.2, maxTokens: 256 },\n inviteGenerator: { model: \"google/gemini-2.5-flash\", temperature: 0.3, maxTokens: 512 },\n premiseAnalyzer: { model: \"google/gemini-2.5-flash\" },\n premiseDecomposer: { model: \"google/gemini-2.5-flash\" },\n premiseIndexer: { model: \"google/gemini-2.5-flash\" },\n userContextGenerator: { model: \"google/gemini-2.5-flash\", temperature: 0.3, maxTokens: 512 },\n networkRecommender: { model: \"google/gemini-2.5-flash\", temperature: 0.2, maxTokens: 512 },\n interruptClassifier: { model: \"google/gemini-2.5-flash\", temperature: 0.0, maxTokens: 16 },\n chat: {\n model: config?.chatModel ?? process.env.CHAT_MODEL ?? \"google/gemini-3-pro-preview\",\n maxTokens: 8192,\n reasoning: {\n effort: (config?.chatReasoningEffort ?? process.env.CHAT_REASONING_EFFORT ?? \"low\") as NonNullable<ModelSettings[\"reasoning\"]>[\"effort\"],\n exclude: true,\n },\n },\n } as const;\n}\n\n/**\n * Returns the model name string for the given agent key.\n * @param agent - Key from MODEL_CONFIG identifying which agent's settings to use.\n * @param config - Optional runtime config overrides.\n */\nexport function getModelName(agent: keyof ReturnType<typeof getModelConfig>, config?: ModelConfig): string {\n return getModelConfig(config)[agent].model;\n}\n\n/**\n * Creates a ChatOpenAI instance configured for OpenRouter.\n * @param agent - Key identifying which agent's model settings to use.\n * @param config - Optional runtime config overrides.\n */\nexport function createModel(agent: keyof ReturnType<typeof getModelConfig>, config?: ModelConfig): ChatOpenAI {\n const apiKey = config?.apiKey ?? process.env.OPENROUTER_API_KEY;\n if (!apiKey?.trim()) {\n throw new Error(`createModel(${agent}): OPENROUTER_API_KEY is required. Pass via the config argument, ToolContext.modelConfig.apiKey, or set the OPENROUTER_API_KEY environment variable.`);\n }\n const cfg = getModelConfig(config)[agent] as ModelSettings;\n // Hard upper bound on a single LLM call. Without this, langchain's HTTP\n // client waits until the upstream cuts the socket (~3 minutes via\n // OpenRouter), blocking the entire chat response. 60 s is generous enough\n // for slow providers but bounds the worst case.\n const timeoutEnv = Number.parseInt(process.env.OPENROUTER_REQUEST_TIMEOUT_MS ?? \"\", 10);\n const timeout = Number.isFinite(timeoutEnv) && timeoutEnv > 0 ? timeoutEnv : 60_000;\n // ChatOpenAI defaults to maxRetries=2. That means a single hung upstream\n // provider gets retried up to 2 more times, each waiting `timeout` before\n // failing — so worst-case latency becomes timeout * 3. Cap retries at 1\n // so the worst case stays bounded at ~2 * timeout. Configurable via\n // OPENROUTER_MAX_RETRIES.\n const retriesEnv = Number.parseInt(process.env.OPENROUTER_MAX_RETRIES ?? \"\", 10);\n const maxRetries = Number.isFinite(retriesEnv) && retriesEnv >= 0 ? retriesEnv : 1;\n return new ChatOpenAI({\n model: cfg.model,\n configuration: {\n baseURL: config?.baseURL ?? process.env.OPENROUTER_BASE_URL ?? \"https://openrouter.ai/api/v1\",\n apiKey,\n },\n temperature: cfg.temperature,\n maxTokens: cfg.maxTokens,\n timeout,\n maxRetries,\n ...(cfg.reasoning && { modelKwargs: { reasoning: cfg.reasoning } }),\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"model.config.js","sourceRoot":"/","sources":["shared/agent/model.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAiC/C,SAAS,cAAc,CAAC,MAAoB;IAC1C,OAAO;QACL,cAAc,EAAQ,EAAE,KAAK,EAAE,yBAAyB,EAAE;QAC1D,aAAa,EAAS,EAAE,KAAK,EAAE,yBAAyB,EAAE;QAC1D,cAAc,EAAQ,EAAE,KAAK,EAAE,yBAAyB,EAAE;QAC1D,gBAAgB,EAAM,EAAE,KAAK,EAAE,yBAAyB,EAAE;QAC1D,eAAe,EAAO,EAAE,KAAK,EAAE,yBAAyB,EAAE;QAC1D,gBAAgB,EAAM,EAAE,KAAK,EAAE,yBAAyB,EAAE;QAC1D,aAAa,EAAS,EAAE,KAAK,EAAE,yBAAyB,EAAE;QAC1D,YAAY,EAAU,EAAE,KAAK,EAAE,yBAAyB,EAAE;QAC1D,oBAAoB,EAAE,EAAE,KAAK,EAAE,yBAAyB,EAAE;QAC1D,oBAAoB,EAAE,EAAE,KAAK,EAAE,yBAAyB,EAAE;QAC1D,UAAU,EAAY,EAAE,KAAK,EAAE,yBAAyB,EAAE;QAC1D,eAAe,EAAO,EAAE,KAAK,EAAE,yBAAyB,EAAE;QAC1D,mBAAmB,EAAG,EAAE,KAAK,EA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AC,aAAa,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC5D,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,sKAAsK;AACtK,MAAM,UAAU,qBAAqB,CACnC,KAAiB,EACjB,YAAiE,EACjE,OAA8C,EAC9C,MAAoB;IAEpB,MAAM,OAAO,GAAG,WAAW,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,oBAAoB,CAAY,YAAY,EAAE,OAAO,CAAC,CAAC;IAClG,MAAM,aAAa,GAAG,mBAAmB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IACzD,MAAM,QAAQ,GAAG,aAAa,EAAE,oBAAoB,CAAY,YAAY,EAAE,OAAO,CAAC,CAAC;IACvF,OAAO,cAAc,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;AAC3C,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CAClC,KAAiB,EACjB,MAAoB;IAEpB,OAAO,cAAc,CAAC,WAAW,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE,mBAAmB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;AACxF,CAAC","sourcesContent":["import { ChatOpenAI } from \"@langchain/openai\";\nimport type { AIMessageChunk } from \"@langchain/core/messages\";\nimport type { BaseLanguageModelInput, StructuredOutputMethodOptions } from \"@langchain/core/language_models/base\";\nimport type { Runnable } from \"@langchain/core/runnables\";\nimport type { InteropZodType } from \"@langchain/core/utils/types\";\n\n/** Settings that can be configured per agent. */\nexport interface ModelSettings {\n model: string;\n temperature?: number;\n maxTokens?: number;\n reasoning?: { effort?: 'minimal' | 'low' | 'medium' | 'high' | 'xhigh'; exclude?: boolean };\n}\n\n/**\n * Runtime configuration for the protocol package.\n * When passed via `ToolContext.modelConfig`, all fields (`apiKey`, `baseURL`, `chatModel`,\n * `chatReasoningEffort`) are honored by `ChatAgent` when the chat graph runs.\n * Other protocol agents don't read from `ToolContext` but may accept an explicit `ModelConfig`\n * as a direct parameter to `createModel()`.\n * All fields fall back to environment variables if not provided.\n */\nexport interface ModelConfig {\n /** OpenRouter API key. Falls back to OPENROUTER_API_KEY env var. */\n apiKey?: string;\n /** OpenRouter base URL. Falls back to OPENROUTER_BASE_URL env var. */\n baseURL?: string;\n /** Override the chat agent model. Falls back to CHAT_MODEL env var. */\n chatModel?: string;\n /** Override the chat reasoning effort. Falls back to CHAT_REASONING_EFFORT env var. */\n chatReasoningEffort?: 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';\n}\n\nfunction getModelConfig(config?: ModelConfig) {\n return {\n intentInferrer: { model: \"google/gemini-2.5-flash\" },\n intentIndexer: { model: \"google/gemini-2.5-flash\" },\n intentVerifier: { model: \"google/gemini-2.5-flash\" },\n intentReconciler: { model: \"google/gemini-2.5-flash\" },\n intentClarifier: { model: \"google/gemini-2.5-flash\" },\n profileGenerator: { model: \"google/gemini-2.5-flash\" },\n hydeGenerator: { model: \"google/gemini-2.5-flash\" },\n lensInferrer: { model: \"google/gemini-2.5-flash\" },\n opportunityEvaluator: { model: \"google/gemini-2.5-flash\" },\n opportunityPresenter: { model: \"google/gemini-2.5-flash\" },\n negotiator: { model: \"google/gemini-2.5-flash\" },\n homeCategorizer: { model: \"google/gemini-2.5-flash\" },\n suggestionGenerator: { model: \"google/gemini-2.5-flash\", temperature: 0.4, maxTokens: 512 },\n chatTitleGenerator: { model: \"google/gemini-2.5-flash\", temperature: 0.3, maxTokens: 32 },\n negotiationInsights: { model: \"google/gemini-2.5-flash\", temperature: 0.4, maxTokens: 512 },\n chatContextSummarizer: { model: \"google/gemini-2.5-flash\", temperature: 0.2, maxTokens: 512 },\n discoveryQuestionGenerator: { model: \"google/gemini-2.5-flash\", temperature: 0.5, maxTokens: 1024 },\n questioner: { model: \"google/gemini-2.5-flash\", temperature: 0.5, maxTokens: 1024 },\n negotiationSummarizer: { model: \"google/gemini-2.5-flash\", temperature: 0.2, maxTokens: 256 },\n inviteGenerator: { model: \"google/gemini-2.5-flash\", temperature: 0.3, maxTokens: 512 },\n premiseAnalyzer: { model: \"google/gemini-2.5-flash\" },\n premiseDecomposer: { model: \"google/gemini-2.5-flash\" },\n premiseIndexer: { model: \"google/gemini-2.5-flash\" },\n userContextGenerator: { model: \"google/gemini-2.5-flash\", temperature: 0.3, maxTokens: 512 },\n networkRecommender: { model: \"google/gemini-2.5-flash\", temperature: 0.2, maxTokens: 512 },\n interruptClassifier: { model: \"google/gemini-2.5-flash\", temperature: 0.0, maxTokens: 16 },\n chat: {\n model: config?.chatModel ?? process.env.CHAT_MODEL ?? \"google/gemini-3-pro-preview\",\n maxTokens: 8192,\n reasoning: {\n effort: (config?.chatReasoningEffort ?? process.env.CHAT_REASONING_EFFORT ?? \"low\") as NonNullable<ModelSettings[\"reasoning\"]>[\"effort\"],\n exclude: true,\n },\n },\n } as const;\n}\n\n/** Key identifying one of the per-agent model configurations. */\nexport type ModelAgent = keyof ReturnType<typeof getModelConfig>;\n\n/**\n * Returns the model name string for the given agent key.\n * @param agent - Key from MODEL_CONFIG identifying which agent's settings to use.\n * @param config - Optional runtime config overrides.\n */\nexport function getModelName(agent: ModelAgent, config?: ModelConfig): string {\n return getModelConfig(config)[agent].model;\n}\n\n/**\n * Creates a ChatOpenAI instance configured for OpenRouter.\n * @param agent - Key identifying which agent's model settings to use.\n * @param config - Optional runtime config overrides.\n */\nexport function createModel(agent: ModelAgent, config?: ModelConfig): ChatOpenAI {\n const cfg = getModelConfig(config)[agent] as ModelSettings;\n return instantiateModel(agent, cfg, config);\n}\n\n/** Instantiates a ChatOpenAI from explicit settings (shared by primary + fallback creation). */\nfunction instantiateModel(agent: string, cfg: ModelSettings, config?: ModelConfig): ChatOpenAI {\n const apiKey = config?.apiKey ?? process.env.OPENROUTER_API_KEY;\n if (!apiKey?.trim()) {\n throw new Error(`createModel(${agent}): OPENROUTER_API_KEY is required. Pass via the config argument, ToolContext.modelConfig.apiKey, or set the OPENROUTER_API_KEY environment variable.`);\n }\n // Hard upper bound on a single LLM call. Without this, langchain's HTTP\n // client waits until the upstream cuts the socket (~3 minutes via\n // OpenRouter), blocking the entire chat response. 60 s is generous enough\n // for slow providers but bounds the worst case.\n const timeoutEnv = Number.parseInt(process.env.OPENROUTER_REQUEST_TIMEOUT_MS ?? \"\", 10);\n const timeout = Number.isFinite(timeoutEnv) && timeoutEnv > 0 ? timeoutEnv : 60_000;\n // ChatOpenAI defaults to maxRetries=2. That means a single hung upstream\n // provider gets retried up to 2 more times, each waiting `timeout` before\n // failing — so worst-case latency becomes timeout * 3. Cap retries at 1\n // so the worst case stays bounded at ~2 * timeout. Configurable via\n // OPENROUTER_MAX_RETRIES.\n const retriesEnv = Number.parseInt(process.env.OPENROUTER_MAX_RETRIES ?? \"\", 10);\n const maxRetries = Number.isFinite(retriesEnv) && retriesEnv >= 0 ? retriesEnv : 1;\n return new ChatOpenAI({\n model: cfg.model,\n configuration: {\n baseURL: config?.baseURL ?? process.env.OPENROUTER_BASE_URL ?? \"https://openrouter.ai/api/v1\",\n apiKey,\n },\n temperature: cfg.temperature,\n maxTokens: cfg.maxTokens,\n timeout,\n maxRetries,\n ...(cfg.reasoning && { modelKwargs: { reasoning: cfg.reasoning } }),\n });\n}\n\n/**\n * Default cross-vendor fallback model. The per-agent primaries run on Google's\n * provider lane (gemini-2.5-flash); a same-key OpenRouter fallback on a\n * different vendor survives Google-side outages.\n * Override via OPENROUTER_FALLBACK_MODEL; set it to \"none\" (or \"off\") to disable.\n */\nconst DEFAULT_FALLBACK_MODEL = \"openai/gpt-4o-mini\";\n\nfunction getFallbackModelName(): string | undefined {\n const raw = process.env.OPENROUTER_FALLBACK_MODEL;\n if (raw === undefined) return DEFAULT_FALLBACK_MODEL;\n const value = raw.trim();\n if (!value || value.toLowerCase() === \"none\" || value.toLowerCase() === \"off\") return undefined;\n return value;\n}\n\n/**\n * Creates the fallback ChatOpenAI for an agent, or undefined when fallbacks\n * are disabled or the fallback would be the same model as the primary.\n * Reuses the agent's sampling settings but drops `reasoning` kwargs, which are\n * primary-model specific.\n */\nexport function createFallbackModel(agent: ModelAgent, config?: ModelConfig): ChatOpenAI | undefined {\n const fallbackName = getFallbackModelName();\n if (!fallbackName) return undefined;\n const cfg = getModelConfig(config)[agent] as ModelSettings;\n if (cfg.model === fallbackName) return undefined;\n return instantiateModel(agent, { ...cfg, model: fallbackName, reasoning: undefined }, config);\n}\n\n/**\n * Number of attempts (1 = no retry) for runnable-level retries added by\n * `createStructuredModel` / `createResilientModel`. These wrap ChatOpenAI's\n * own HTTP-level `maxRetries` and additionally cover structured-output\n * parse/validation failures. Configurable via OPENROUTER_RUNNABLE_MAX_ATTEMPTS.\n */\nfunction getRunnableMaxAttempts(): number {\n const env = Number.parseInt(process.env.OPENROUTER_RUNNABLE_MAX_ATTEMPTS ?? \"\", 10);\n return Number.isFinite(env) && env >= 1 ? env : 2;\n}\n\n/**\n * Stops runnable-level retries when the failure was a caller abort —\n * retrying a cancelled request only delays cancellation. Thrown errors from\n * `onFailedAttempt` abort the retry loop.\n */\nfunction abortAwareFailedAttemptHandler(error: Error): void {\n if (error?.name === \"AbortError\" || error?.name === \"APIUserAbortError\") throw error;\n}\n\nfunction withResilience<RunOutput>(\n primary: Runnable<BaseLanguageModelInput, RunOutput>,\n fallback: Runnable<BaseLanguageModelInput, RunOutput> | undefined,\n): Runnable<BaseLanguageModelInput, RunOutput> {\n const attempts = getRunnableMaxAttempts();\n let runnable: Runnable<BaseLanguageModelInput, RunOutput> = attempts > 1\n ? primary.withRetry({ stopAfterAttempt: attempts, onFailedAttempt: abortAwareFailedAttemptHandler })\n : primary;\n if (fallback) runnable = runnable.withFallbacks([fallback]);\n return runnable;\n}\n\n/**\n * Creates a structured-output model with runnable-level retry and cross-model\n * fallback. Equivalent to `createModel(agent).withStructuredOutput(schema, options)`\n * plus `.withRetry(...)` and `.withFallbacks([...])`.\n *\n * Retry covers transient provider errors *and* schema parse/validation\n * failures; the fallback model (see OPENROUTER_FALLBACK_MODEL) is bound to the\n * same schema so a provider outage degrades to a different vendor instead of\n * failing the call. Abort signals pass through: aborts are never retried and\n * skip the fallback.\n *\n * @param agent - Key identifying which agent's model settings to use.\n * @param outputSchema - Zod schema or JSON-schema response format.\n * @param options - Same options as `withStructuredOutput` (e.g. `{ name }`).\n * @param config - Optional runtime model config overrides.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any -- mirrors ChatOpenAI.withStructuredOutput's constraint; `unknown` rejects zod-inferred interface types\nexport function createStructuredModel<RunOutput extends Record<string, any> = Record<string, any>>(\n agent: ModelAgent,\n outputSchema: InteropZodType<RunOutput> | Record<string, unknown>,\n options?: StructuredOutputMethodOptions<false>,\n config?: ModelConfig,\n): Runnable<BaseLanguageModelInput, RunOutput> {\n const primary = createModel(agent, config).withStructuredOutput<RunOutput>(outputSchema, options);\n const fallbackModel = createFallbackModel(agent, config);\n const fallback = fallbackModel?.withStructuredOutput<RunOutput>(outputSchema, options);\n return withResilience(primary, fallback);\n}\n\n/**\n * Creates a plain-completion model with runnable-level retry and cross-model\n * fallback, for call sites that `invoke()` the model directly (no\n * `withStructuredOutput`/`bindTools`/`stream` chaining).\n *\n * @param agent - Key identifying which agent's model settings to use.\n * @param config - Optional runtime model config overrides.\n */\nexport function createResilientModel(\n agent: ModelAgent,\n config?: ModelConfig,\n): Runnable<BaseLanguageModelInput, AIMessageChunk> {\n return withResilience(createModel(agent, config), createFallbackModel(agent, config));\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hyde.generator.d.ts","sourceRoot":"/","sources":["shared/hyde/hyde.generator.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"hyde.generator.d.ts","sourceRoot":"/","sources":["shared/hyde/hyde.generator.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAwB3D,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"}
|
|
@@ -16,7 +16,7 @@ import { z } from 'zod';
|
|
|
16
16
|
import { HYDE_CORPUS_PROMPTS } from './hyde.strategies.js';
|
|
17
17
|
import { Timed } from "../observability/performance.js";
|
|
18
18
|
import { protocolLogger } from '../observability/protocol.logger.js';
|
|
19
|
-
import {
|
|
19
|
+
import { createStructuredModel } from "../agent/model.config.js";
|
|
20
20
|
import { invokeWithAbortSignal } from "../agent/model-signal.js";
|
|
21
21
|
const logger = protocolLogger("HydeGenerator");
|
|
22
22
|
const SYSTEM_PROMPT = `You are a Hypothetical Document Generator for semantic search.
|
|
@@ -33,14 +33,13 @@ const responseFormat = z.object({
|
|
|
33
33
|
.string()
|
|
34
34
|
.describe('The hypothetical document text in the target voice, suitable for embedding and retrieval'),
|
|
35
35
|
});
|
|
36
|
-
const model = createModel("hydeGenerator");
|
|
37
36
|
/**
|
|
38
37
|
* Generates hypothetical documents in a target corpus voice for semantic search.
|
|
39
38
|
* Uses free-text lens labels (from LensInferrer) instead of enum strategies.
|
|
40
39
|
*/
|
|
41
40
|
export class HydeGenerator {
|
|
42
41
|
constructor() {
|
|
43
|
-
this.model =
|
|
42
|
+
this.model = createStructuredModel("hydeGenerator", responseFormat, {
|
|
44
43
|
name: "hyde_generator",
|
|
45
44
|
});
|
|
46
45
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hyde.generator.js","sourceRoot":"/","sources":["shared/hyde/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,iCAAiC,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AACrE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"hyde.generator.js","sourceRoot":"/","sources":["shared/hyde/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,iCAAiC,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAEjE,MAAM,MAAM,GAAG,cAAc,CAAC,eAAe,CAAC,CAAC;AAE/C,MAAM,aAAa,GAAG;;;;;;;;yDAQmC,CAAC;AAE1D,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC;IAC9B,oBAAoB,EAAE,CAAC;SACpB,MAAM,EAAE;SACR,QAAQ,CAAC,0FAA0F,CAAC;CACxG,CAAC,CAAC;AAeH;;;GAGG;AACH,MAAM,OAAO,aAAa;IAA1B;QACU,UAAK,GAAG,qBAAqB,CAAC,eAAe,EAAE,cAAc,EAAE;YACrE,IAAI,EAAE,gBAAgB;SACvB,CAAC,CAAC;IA6BL,CAAC;IA3BC;;;;;OAKG;IAEG,AAAN,KAAK,CAAC,QAAQ,CAAC,KAAwB;QACrC,MAAM,UAAU,GAAG,mBAAmB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;QAEnF,MAAM,QAAQ,GAAG;YACf,IAAI,aAAa,CAAC,aAAa,CAAC;YAChC,IAAI,YAAY,CAAC,UAAU,CAAC;SAC7B,CAAC;QAEF,MAAM,MAAM,GAAG,MAAM,qBAAqB,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QACjE,MAAM,MAAM,GAAG,cAAc,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAC5C,MAAM,IAAI,GAAG,MAAM,CAAC,oBAAoB,IAAI,EAAE,CAAC;QAE/C,MAAM,CAAC,OAAO,CAAC,yBAAyB,EAAE;YACxC,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,UAAU,EAAE,IAAI,CAAC,MAAM;SACxB,CAAC,CAAC;QAEH,OAAO,EAAE,IAAI,EAAE,CAAC;IAClB,CAAC;CACF;AApBO;IADL,KAAK,EAAE;;;;6CAoBP","sourcesContent":["/**\n * HyDE Generator Agent: pure LLM agent for generating hypothetical documents\n * in the target corpus voice. Uses free-text lens labels instead of enum strategies.\n */\nimport { HumanMessage, SystemMessage } from '@langchain/core/messages';\nimport { z } from 'zod';\nimport { HYDE_CORPUS_PROMPTS } from './hyde.strategies.js';\nimport type { HydeTargetCorpus } from './lens.inferrer.js';\nimport { Timed } from \"../observability/performance.js\";\nimport { protocolLogger } from '../observability/protocol.logger.js';\nimport { createStructuredModel } from \"../agent/model.config.js\";\nimport { invokeWithAbortSignal } from \"../agent/model-signal.js\";\n\nconst logger = protocolLogger(\"HydeGenerator\");\n\nconst SYSTEM_PROMPT = `You are a Hypothetical Document Generator for semantic search.\n\nYour 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.\n\nRules:\n- Write in first person as the target.\n- Be concrete and specific so the text is good for vector similarity search.\n- Output only the hypothetical document text, no meta-commentary.\n- Keep length to a few sentences or one short paragraph.`;\n\nconst responseFormat = z.object({\n hypotheticalDocument: z\n .string()\n .describe('The hypothetical document text in the target voice, suitable for embedding and retrieval'),\n});\n\nexport interface HydeGeneratorOutput {\n text: string;\n}\n\nexport interface HydeGenerateInput {\n /** Original intent or query text. */\n sourceText: string;\n /** Free-text lens label from LensInferrer (e.g. \"crypto infra VC\"). */\n lens: string;\n /** Which corpus voice to generate in. */\n corpus: HydeTargetCorpus;\n}\n\n/**\n * Generates hypothetical documents in a target corpus voice for semantic search.\n * Uses free-text lens labels (from LensInferrer) instead of enum strategies.\n */\nexport class HydeGenerator {\n private model = createStructuredModel(\"hydeGenerator\", responseFormat, {\n name: \"hyde_generator\",\n });\n\n /**\n * Generate a hypothetical document for the given source text and lens.\n *\n * @param input - Source text, lens label, and target corpus\n * @returns Generated hypothetical document text\n */\n @Timed()\n async generate(input: HydeGenerateInput): Promise<HydeGeneratorOutput> {\n const promptText = HYDE_CORPUS_PROMPTS[input.corpus](input.sourceText, input.lens);\n\n const messages = [\n new SystemMessage(SYSTEM_PROMPT),\n new HumanMessage(promptText),\n ];\n\n const result = await invokeWithAbortSignal(this.model, messages);\n const parsed = responseFormat.parse(result);\n const text = parsed.hypotheticalDocument ?? '';\n\n logger.verbose('Generated HyDE document', {\n lens: input.lens,\n corpus: input.corpus,\n textLength: text.length,\n });\n\n return { text };\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lens.inferrer.d.ts","sourceRoot":"/","sources":["shared/hyde/lens.inferrer.ts"],"names":[],"mappings":"AAYA,MAAM,MAAM,gBAAgB,GAAG,UAAU,GAAG,SAAS,GAAG,UAAU,CAAC;AAEnE,iFAAiF;AACjF,MAAM,WAAW,IAAI;IACnB,+DAA+D;IAC/D,KAAK,EAAE,MAAM,CAAC;IACd,mEAAmE;IACnE,MAAM,EAAE,gBAAgB,CAAC;IACzB,4DAA4D;IAC5D,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,kBAAkB;IACjC,sCAAsC;IACtC,UAAU,EAAE,MAAM,CAAC;IACnB,4DAA4D;IAC5D,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,qDAAqD;IACrD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,IAAI,EAAE,CAAC;CAChB;
|
|
1
|
+
{"version":3,"file":"lens.inferrer.d.ts","sourceRoot":"/","sources":["shared/hyde/lens.inferrer.ts"],"names":[],"mappings":"AAYA,MAAM,MAAM,gBAAgB,GAAG,UAAU,GAAG,SAAS,GAAG,UAAU,CAAC;AAEnE,iFAAiF;AACjF,MAAM,WAAW,IAAI;IACnB,+DAA+D;IAC/D,KAAK,EAAE,MAAM,CAAC;IACd,mEAAmE;IACnE,MAAM,EAAE,gBAAgB,CAAC;IACzB,4DAA4D;IAC5D,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,kBAAkB;IACjC,sCAAsC;IACtC,UAAU,EAAE,MAAM,CAAC;IACnB,4DAA4D;IAC5D,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,qDAAqD;IACrD,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,IAAI,EAAE,CAAC;CAChB;AA4BD;;;;GAIG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,KAAK,CAEV;IAEH;;;;;OAKG;IAEG,KAAK,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,mBAAmB,CAAC;CAoCrE"}
|
|
@@ -16,7 +16,7 @@ import { HumanMessage, SystemMessage } from '@langchain/core/messages';
|
|
|
16
16
|
import { z } from 'zod';
|
|
17
17
|
import { Timed } from "../observability/performance.js";
|
|
18
18
|
import { protocolLogger } from '../observability/protocol.logger.js';
|
|
19
|
-
import {
|
|
19
|
+
import { createStructuredModel } from "../agent/model.config.js";
|
|
20
20
|
import { invokeWithAbortSignal } from "../agent/model-signal.js";
|
|
21
21
|
const SYSTEM_PROMPT = `You analyze goals and search queries to identify the most relevant perspectives for finding matching people in a professional network.
|
|
22
22
|
|
|
@@ -40,7 +40,6 @@ const responseFormat = z.object({
|
|
|
40
40
|
reasoning: z.string().describe('Why this perspective is relevant'),
|
|
41
41
|
})).min(1).max(5).describe('Inferred search lenses'),
|
|
42
42
|
});
|
|
43
|
-
const model = createModel("lensInferrer");
|
|
44
43
|
const logger = protocolLogger("LensInferrer");
|
|
45
44
|
/**
|
|
46
45
|
* Infers search lenses from source text and optional profile context.
|
|
@@ -49,7 +48,7 @@ const logger = protocolLogger("LensInferrer");
|
|
|
49
48
|
*/
|
|
50
49
|
export class LensInferrer {
|
|
51
50
|
constructor() {
|
|
52
|
-
this.model =
|
|
51
|
+
this.model = createStructuredModel("lensInferrer", responseFormat, {
|
|
53
52
|
name: "lens_inferrer",
|
|
54
53
|
});
|
|
55
54
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lens.inferrer.js","sourceRoot":"/","sources":["shared/hyde/lens.inferrer.ts"],"names":[],"mappings":";;;;;;;;;AAAA;;;;GAIG;AACH,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,KAAK,EAAE,MAAM,iCAAiC,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AACrE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"lens.inferrer.js","sourceRoot":"/","sources":["shared/hyde/lens.inferrer.ts"],"names":[],"mappings":";;;;;;;;;AAAA;;;;GAIG;AACH,OAAO,EAA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Inferrer Agent: analyzes source text (intent or query) with optional\n * profile context and infers 1-N search lenses, each tagged with a target corpus.\n * Replaces the hardcoded HydeStrategy enum and regex-based selectStrategiesFromQuery.\n */\nimport { HumanMessage, SystemMessage } from '@langchain/core/messages';\nimport { z } from 'zod';\nimport { Timed } from \"../observability/performance.js\";\nimport { protocolLogger } from '../observability/protocol.logger.js';\nimport { createStructuredModel } from \"../agent/model.config.js\";\nimport { invokeWithAbortSignal } from \"../agent/model-signal.js\";\n\nexport type HydeTargetCorpus = 'profiles' | 'intents' | 'premises';\n\n/** A single inferred lens — a search perspective the LLM decided is relevant. */\nexport interface Lens {\n /** Free-text description (e.g. \"crypto infrastructure VC\"). */\n label: string;\n /** Which vector index to search: user profiles or user intents. */\n corpus: HydeTargetCorpus;\n /** Why this perspective is relevant (for logging/trace). */\n reasoning: string;\n}\n\nexport interface LensInferenceInput {\n /** Intent payload or search query. */\n sourceText: string;\n /** User's profile summary for domain context (optional). */\n profileContext?: string;\n /** Maximum number of lenses to infer (default 3). */\n maxLenses?: number;\n}\n\nexport interface LensInferenceOutput {\n lenses: Lens[];\n}\n\nconst SYSTEM_PROMPT = `You analyze goals and search queries to identify the most relevant perspectives for finding matching people in a professional network.\n\nFor each perspective you identify, specify:\n1. A clear, specific description of who or what to search for\n2. Whether to search \"profiles\" (user bios, expertise, backgrounds), \"intents\" (stated goals, needs, aspirations), or \"premises\" (identity assertions, values, worldview)\n3. A brief reason why this perspective is relevant\n\nGuidelines:\n- Be specific and domain-aware. \"early-stage crypto infrastructure investor\" is better than \"investor\".\n- Consider both sides: who can help the person AND whose goals complement theirs.\n- When user context is provided, tailor perspectives to their domain (e.g. a DePIN founder searching for \"investors\" needs crypto-native infra investors specifically).\n- Generate only perspectives that add distinct search value — don't repeat similar angles.\n- Use \"profiles\" when looking for a type of person (expert, advisor, leader). Use \"intents\" when looking for a complementary goal or need (someone raising, someone hiring, someone seeking collaboration). Use \"premises\" when looking for someone whose identity, values, or worldview aligns — stable traits rather than transient goals.\n- Always include at least one \"profiles\" perspective when the source describes a need that a specific type of professional could fulfill. Most intents benefit from profile-based discovery.\n- LOCATION AWARENESS: When the source text or user context mentions a specific location (city, region, country), incorporate it into lens descriptions. For example, \"investors in San Francisco\" should produce a lens like \"SF-based early-stage investor\" rather than just \"early-stage investor\". This helps the hypothetical document generator produce location-specific search documents, improving retrieval quality.`;\n\nconst responseFormat = z.object({\n lenses: z.array(z.object({\n label: z.string().describe('Specific description of the search perspective'),\n corpus: z.enum(['profiles', 'intents', 'premises']).describe('Search user profiles, user intents, or user premises (identity/values)'),\n reasoning: z.string().describe('Why this perspective is relevant'),\n })).min(1).max(5).describe('Inferred search lenses'),\n});\n\nconst logger = protocolLogger(\"LensInferrer\");\n\n/**\n * Infers search lenses from source text and optional profile context.\n * Each lens represents a search perspective tagged with a target corpus\n * (profiles or intents) for downstream HyDE document generation.\n */\nexport class LensInferrer {\n private model = createStructuredModel(\"lensInferrer\", responseFormat, {\n name: \"lens_inferrer\",\n });\n\n /**\n * Infer search lenses from source text and optional profile context.\n *\n * @param input - Source text, optional profile context, optional max lenses\n * @returns Array of inferred lenses with corpus tags; empty array on failure\n */\n @Timed()\n async infer(input: LensInferenceInput): Promise<LensInferenceOutput> {\n const { sourceText, profileContext, maxLenses = 3 } = input;\n\n logger.verbose('Inferring lenses', {\n sourceTextLength: sourceText.length,\n hasProfileContext: !!profileContext,\n maxLenses,\n });\n\n let humanPrompt = `Identify up to ${maxLenses} search perspectives for finding relevant matches.\\n\\nSource: \"${sourceText}\"`;\n\n if (profileContext) {\n humanPrompt += `\\n\\nUser context: ${profileContext}`;\n }\n\n const messages = [\n new SystemMessage(SYSTEM_PROMPT),\n new HumanMessage(humanPrompt),\n ];\n\n try {\n const result = await invokeWithAbortSignal(this.model, messages);\n const parsed = responseFormat.parse(result);\n const lenses = parsed.lenses.slice(0, maxLenses);\n\n logger.verbose('Lenses inferred', {\n count: lenses.length,\n lenses: lenses.map(l => ({ label: l.label, corpus: l.corpus })),\n });\n\n return { lenses };\n } catch (error: unknown) {\n logger.error('Lens inference failed', { error });\n return { lenses: [] };\n }\n }\n}\n"]}
|