@indexnetwork/protocol 13.2.0-rc.466.1 → 13.2.1-rc.467.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.
Files changed (59) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/dist/communities/public/index.d.ts +2 -2
  3. package/dist/communities/public/index.js +2 -2
  4. package/dist/contacts/public/index.d.ts +1 -1
  5. package/dist/contacts/public/index.js +1 -1
  6. package/dist/integrations/public/index.d.ts +1 -1
  7. package/dist/integrations/public/index.js +1 -1
  8. package/dist/mcp/mcp.server.d.ts +1 -1
  9. package/dist/mcp/mcp.server.js +1 -1
  10. package/dist/negotiation/public/index.d.ts +1 -1
  11. package/dist/negotiation/public/index.js +1 -1
  12. package/dist/participant-agents/public/index.d.ts +1 -1
  13. package/dist/participant-agents/public/index.js +1 -1
  14. package/dist/participant-context/application/index.js +1 -1
  15. package/dist/participant-context/domain/index.d.ts +1 -1
  16. package/dist/participant-context/domain/index.js +1 -1
  17. package/dist/participant-context/public/index.d.ts +2 -2
  18. package/dist/participant-context/public/index.js +2 -2
  19. package/dist/questions/public/index.d.ts +1 -1
  20. package/dist/questions/public/index.js +1 -1
  21. package/dist/shared/agent/tool.factory.d.ts +15 -4
  22. package/dist/shared/agent/tool.factory.js +233 -4
  23. package/dist/shared/agent/tool.registry.d.ts +21 -9
  24. package/dist/shared/agent/tool.registry.js +80 -12
  25. package/dist/signals/application/index.d.ts +1 -1
  26. package/dist/signals/application/index.js +1 -1
  27. package/dist/signals/public/index.d.ts +2 -2
  28. package/dist/signals/public/index.js +2 -2
  29. package/package.json +1 -1
  30. package/dist/communities/index.d.ts +0 -14
  31. package/dist/communities/index.js +0 -14
  32. package/dist/contacts/index.d.ts +0 -18
  33. package/dist/contacts/index.js +0 -18
  34. package/dist/integrations/index.d.ts +0 -22
  35. package/dist/integrations/index.js +0 -22
  36. package/dist/negotiation/index.d.ts +0 -25
  37. package/dist/negotiation/index.js +0 -25
  38. package/dist/opportunity/index.d.ts +0 -29
  39. package/dist/opportunity/index.js +0 -29
  40. package/dist/participant-agents/index.d.ts +0 -17
  41. package/dist/participant-agents/index.js +0 -17
  42. package/dist/platform/index.d.ts +0 -19
  43. package/dist/platform/index.js +0 -23
  44. package/dist/public/index.d.ts +0 -17
  45. package/dist/public/index.js +0 -17
  46. package/dist/questions/index.d.ts +0 -15
  47. package/dist/questions/index.js +0 -15
  48. package/dist/runtime/background/index.d.ts +0 -14
  49. package/dist/runtime/background/index.js +0 -14
  50. package/dist/runtime/foreground/composition/tool.factory.d.ts +0 -17
  51. package/dist/runtime/foreground/composition/tool.factory.js +0 -235
  52. package/dist/runtime/foreground/composition/tool.registry.d.ts +0 -24
  53. package/dist/runtime/foreground/composition/tool.registry.js +0 -80
  54. package/dist/runtime/foreground/index.d.ts +0 -13
  55. package/dist/runtime/foreground/index.js +0 -13
  56. package/dist/runtime/foreground/signals/intent.tools.d.ts +0 -13
  57. package/dist/runtime/foreground/signals/intent.tools.js +0 -13
  58. package/dist/signals/index.d.ts +0 -13
  59. package/dist/signals/index.js +0 -13
package/CHANGELOG.md CHANGED
@@ -20,6 +20,45 @@ went 6.7.1 → 8.0.2 with no 7.x in between because the whole 7.x line shipped a
20
20
  prereleases between the two promotions. To track every change, read `rc`; to
21
21
  pin a supported release, use `latest`.
22
22
 
23
+ ## 13.2.1 - 2026-08-16
24
+
25
+ No public API change: all 441 exported symbols are byte-identical to 13.2.0, and
26
+ `src/index.ts` is untouched. This is internal structure only.
27
+
28
+ ### Removed
29
+
30
+ - Removed the IND-543 outer shells — `src/public/`, `src/platform/`,
31
+ `src/runtime/foreground/`, and `src/runtime/background/`. All four were
32
+ declaration-only placeholders with zero inbound imports; `runtime/background`
33
+ and `public` consisted of nothing but a header comment. The only thing
34
+ referencing them was a spec asserting that they existed.
35
+ - Removed eight unused capability barrels (`signals/index.ts`,
36
+ `communities/index.ts`, `contacts/index.ts`, `questions/index.ts`,
37
+ `opportunity/index.ts`, `negotiation/index.ts`, `integrations/index.ts`,
38
+ `participant-agents/index.ts`). Each was `export * from "./public/index.js"`
39
+ with no importers — every real consumer already went to `public/` directly.
40
+ - Removed `src/shared/ui/`, which contained no source, only a `tests/tsconfig.json`.
41
+ - Removed the `ambient-background`, `neutral-platform`, and
42
+ `public-compatibility` capability classifications, which existed solely to
43
+ describe the deleted shells.
44
+
45
+ ### Changed
46
+
47
+ - Resolved the tool-composition shim inversion. `tool.registry.ts` and
48
+ `tool.factory.ts` were implemented in `runtime/foreground/composition/` and
49
+ re-exported from `shared/agent/` through modules marked `@deprecated` — but
50
+ all 25 importers used the deprecated path. The implementations now live at
51
+ `shared/agent/tool.registry.ts` and `shared/agent/tool.factory.ts`, and the
52
+ indirection is gone. `mcp.server.ts` was the one direct consumer of the old
53
+ location and now resolves to the same single home.
54
+ - `signals/application/intent.tools.ts` is imported directly by the tool
55
+ factory; the `runtime/foreground/signals/intent.tools.ts` pass-through
56
+ re-export that sat between them is removed.
57
+ - Replaced `architecture/tests/runtime-shells.spec.ts` with
58
+ `architecture/tests/package-entry.spec.ts`, which asserts the invariants that
59
+ outlived the shells: `src/index.ts` is the sole `package.json` export, and the
60
+ tool composition root has exactly one implementation.
61
+
23
62
  ## 13.2.0 - 2026-08-16
24
63
 
25
64
  ### Added
@@ -4,10 +4,10 @@
4
4
  * Re-exports the stable contracts from domain, application, and ports.
5
5
  * Runtime adapter creation (graph factories, tool factories) is accessible
6
6
  * via capabilities/communities.facade.ts for package consumers and via the
7
- * foreground shell (runtime/foreground) for internal registries.
7
+ * tool composition root (shared/agent) for internal registries.
8
8
  *
9
9
  * Boundary: public-compatibility. References only communities/domain,
10
- * communities/application, and communities/ports — never runtime/foreground
10
+ * communities/application, and communities/ports — never the tool composition root (shared/agent)
11
11
  * or host implementations.
12
12
  *
13
13
  * ## Intentionally excluded from public surface
@@ -4,10 +4,10 @@
4
4
  * Re-exports the stable contracts from domain, application, and ports.
5
5
  * Runtime adapter creation (graph factories, tool factories) is accessible
6
6
  * via capabilities/communities.facade.ts for package consumers and via the
7
- * foreground shell (runtime/foreground) for internal registries.
7
+ * tool composition root (shared/agent) for internal registries.
8
8
  *
9
9
  * Boundary: public-compatibility. References only communities/domain,
10
- * communities/application, and communities/ports — never runtime/foreground
10
+ * communities/application, and communities/ports — never the tool composition root (shared/agent)
11
11
  * or host implementations.
12
12
  *
13
13
  * ## Intentionally excluded from public surface
@@ -8,7 +8,7 @@
8
8
  * ## Boundary
9
9
  *
10
10
  * References only contacts/domain, contacts/application, and contacts/ports.
11
- * Never imports from runtime/foreground, host implementations, or other
11
+ * Never imports from the tool composition root (shared/agent), host implementations, or other
12
12
  * capability internals.
13
13
  *
14
14
  * ## Intentionally excluded from public surface
@@ -8,7 +8,7 @@
8
8
  * ## Boundary
9
9
  *
10
10
  * References only contacts/domain, contacts/application, and contacts/ports.
11
- * Never imports from runtime/foreground, host implementations, or other
11
+ * Never imports from the tool composition root (shared/agent), host implementations, or other
12
12
  * capability internals.
13
13
  *
14
14
  * ## Intentionally excluded from public surface
@@ -8,7 +8,7 @@
8
8
  * ## Boundary
9
9
  *
10
10
  * References only integrations/domain, integrations/application, and
11
- * integrations/ports. Never imports from runtime/foreground, host
11
+ * integrations/ports. Never imports from the tool composition root (shared/agent), host
12
12
  * implementations, or other capability internals.
13
13
  *
14
14
  * ## Intentionally excluded from public surface
@@ -8,7 +8,7 @@
8
8
  * ## Boundary
9
9
  *
10
10
  * References only integrations/domain, integrations/application, and
11
- * integrations/ports. Never imports from runtime/foreground, host
11
+ * integrations/ports. Never imports from the tool composition root (shared/agent), host
12
12
  * implementations, or other capability internals.
13
13
  *
14
14
  * ## Intentionally excluded from public surface
@@ -8,7 +8,7 @@ import { McpServer, fromJsonSchema } from '@modelcontextprotocol/server';
8
8
  import type { JsonSchemaType } from '@modelcontextprotocol/server';
9
9
  import type { McpAuthResolver } from '../shared/interfaces/auth.interface.js';
10
10
  import type { ToolDeps, ResolvedToolContext, RawToolDefinition } from '../shared/agent/tool.helpers.js';
11
- import type { ToolRegistryDeps } from '../runtime/foreground/composition/tool.registry.js';
11
+ import type { ToolRegistryDeps } from '../shared/agent/tool.registry.js';
12
12
  import type { McpAuthorizationObserver, McpCapabilityPolicyOptions } from './mcp.authorization-policy.js';
13
13
  /**
14
14
  * Static registration metadata for one MCP tool — schema conversion artifacts
@@ -10,7 +10,7 @@ import { McpResolvedIdentitySchema } from '../shared/schemas/mcp-auth.schema.js'
10
10
  import { CANONICAL_GUIDANCE_SUMMARY } from '../shared/agent/canonical-guidance.js';
11
11
  import { resolveChatContext } from '../shared/agent/tool.helpers.js';
12
12
  import { deriveAllowedNetworkIds, scopeFromNetworkId } from '../shared/agent/tool.scope.js';
13
- import { createToolRegistry } from '../runtime/foreground/composition/tool.registry.js';
13
+ import { createToolRegistry } from '../shared/agent/tool.registry.js';
14
14
  import { bindOwnerApprovalProvenance } from '../opportunity/application/opportunity.owner-provenance.js';
15
15
  import { ToolRuntimeError, invokeToolRuntime, toolRuntimeErrorToResult } from '../shared/agent/tool.runtime.js';
16
16
  import { protocolLogger } from '../shared/observability/protocol.logger.js';
@@ -6,7 +6,7 @@
6
6
  * ## Boundary
7
7
  *
8
8
  * References only negotiation/domain, negotiation/application, and
9
- * negotiation/ports. Never imports from runtime/foreground, host
9
+ * negotiation/ports. Never imports from the tool composition root (shared/agent), host
10
10
  * implementations, or other capability internals.
11
11
  *
12
12
  * ## Intentionally excluded from public surface
@@ -6,7 +6,7 @@
6
6
  * ## Boundary
7
7
  *
8
8
  * References only negotiation/domain, negotiation/application, and
9
- * negotiation/ports. Never imports from runtime/foreground, host
9
+ * negotiation/ports. Never imports from the tool composition root (shared/agent), host
10
10
  * implementations, or other capability internals.
11
11
  *
12
12
  * ## Intentionally excluded from public surface
@@ -9,7 +9,7 @@
9
9
  * ## Boundary
10
10
  *
11
11
  * References only participant-agents/domain, participant-agents/application,
12
- * and participant-agents/ports. Never imports from runtime/foreground, host
12
+ * and participant-agents/ports. Never imports from the tool composition root (shared/agent), host
13
13
  * implementations, or other capability internals.
14
14
  *
15
15
  * ## Intentionally excluded from public surface
@@ -9,7 +9,7 @@
9
9
  * ## Boundary
10
10
  *
11
11
  * References only participant-agents/domain, participant-agents/application,
12
- * and participant-agents/ports. Never imports from runtime/foreground, host
12
+ * and participant-agents/ports. Never imports from the tool composition root (shared/agent), host
13
13
  * implementations, or other capability internals.
14
14
  *
15
15
  * ## Intentionally excluded from public surface
@@ -64,7 +64,7 @@ export { EnrichmentGraphFactory, } from "../../enrichment/enrichment.graph.js";
64
64
  export { EnrichmentGenerator } from "../../enrichment/enrichment.generator.js";
65
65
  export { shouldEnrichGhostDisplayNameFromParallel, isEnrichedNameMeaningful, } from "../../enrichment/enrichment.enricher.js";
66
66
  // ── Tool factories (foreground adapters) ──────────────────────────────────────
67
- // These are foreground adapter entry points consumed by runtime/foreground
67
+ // These are foreground adapter entry points consumed by the tool composition root (shared/agent)
68
68
  // composition. They accept compiled graphs and host deps through the tool-dep
69
69
  // ports and produce LangChain-compatible tool arrays.
70
70
  export { createEnrichmentTools } from "../../enrichment/enrichment.tools.js";
@@ -46,7 +46,7 @@
46
46
  * ## Policy separation
47
47
  *
48
48
  * - **Foreground adapters** (onboarding preview/confirm, explicit enrichment):
49
- * managed by the foreground shell (runtime/foreground). They compose the
49
+ * managed by the tool composition root (shared/agent). They compose the
50
50
  * EnrichmentGraphFactory and PremiseGraphFactory and pass the compiled graphs
51
51
  * through the tool-dependency ports.
52
52
  * - **Ambient adapters** (scrape/decompose, regeneration, indexing, representation
@@ -46,7 +46,7 @@
46
46
  * ## Policy separation
47
47
  *
48
48
  * - **Foreground adapters** (onboarding preview/confirm, explicit enrichment):
49
- * managed by the foreground shell (runtime/foreground). They compose the
49
+ * managed by the tool composition root (shared/agent). They compose the
50
50
  * EnrichmentGraphFactory and PremiseGraphFactory and pass the compiled graphs
51
51
  * through the tool-dependency ports.
52
52
  * - **Ambient adapters** (scrape/decompose, regeneration, indexing, representation
@@ -4,11 +4,11 @@
4
4
  * Re-exports the stable contracts from domain, application, and ports.
5
5
  * Runtime adapter creation (graph factories, tool factories) is accessible via
6
6
  * capabilities/participant-context.facade for package consumers and via
7
- * the foreground shell (runtime/foreground) for internal registries.
7
+ * the tool composition root (shared/agent) for internal registries.
8
8
  *
9
9
  * Boundary: public-compatibility. References only participant-context/domain,
10
10
  * participant-context/application, and participant-context/ports — never
11
- * runtime/foreground or host implementations.
11
+ * the tool composition root (shared/agent) or host implementations.
12
12
  *
13
13
  * ## Intentionally excluded from public surface
14
14
  *
@@ -4,11 +4,11 @@
4
4
  * Re-exports the stable contracts from domain, application, and ports.
5
5
  * Runtime adapter creation (graph factories, tool factories) is accessible via
6
6
  * capabilities/participant-context.facade for package consumers and via
7
- * the foreground shell (runtime/foreground) for internal registries.
7
+ * the tool composition root (shared/agent) for internal registries.
8
8
  *
9
9
  * Boundary: public-compatibility. References only participant-context/domain,
10
10
  * participant-context/application, and participant-context/ports — never
11
- * runtime/foreground or host implementations.
11
+ * the tool composition root (shared/agent) or host implementations.
12
12
  *
13
13
  * ## Intentionally excluded from public surface
14
14
  *
@@ -9,7 +9,7 @@
9
9
  * ## Boundary
10
10
  *
11
11
  * References only questions/domain, questions/application, and questions/ports.
12
- * Never imports from runtime/foreground, host implementations, or other
12
+ * Never imports from the tool composition root (shared/agent), host implementations, or other
13
13
  * capability internals.
14
14
  *
15
15
  * ## Intentionally excluded from public surface
@@ -9,7 +9,7 @@
9
9
  * ## Boundary
10
10
  *
11
11
  * References only questions/domain, questions/application, and questions/ports.
12
- * Never imports from runtime/foreground, host implementations, or other
12
+ * Never imports from the tool composition root (shared/agent), host implementations, or other
13
13
  * capability internals.
14
14
  *
15
15
  * ## Intentionally excluded from public surface
@@ -1,6 +1,17 @@
1
+ import { type ToolContext, type ResolvedToolContext } from "./tool.helpers.js";
2
+ import type { OpportunityOwnerApprovalDeps } from "../../opportunity/ports/opportunity.tools.port.js";
3
+ export type { ToolContext, ResolvedToolContext, ProtocolDeps } from "./tool.helpers.js";
4
+ export type { ToolDeps } from "./tool.helpers.js";
1
5
  /**
2
- * @deprecated Canonical location: runtime/foreground/composition/tool.factory
3
- * Retained for backward compatibility during IND-544 migration.
4
- * Import createChatTools from @indexnetwork/protocol instead.
6
+ * Creates all chat tools bound to a specific user context.
7
+ * Resolves user/network identity from DB at init time.
8
+ * Tools are created fresh for each user session to ensure proper isolation.
9
+ *
10
+ * All external dependencies (cache, integration, queue, etc.) are provided
11
+ * via the `deps` parameter — the protocol lib never imports concrete adapters.
5
12
  */
6
- export { createChatTools, type ChatTools, type ToolContext, type ResolvedToolContext, type ProtocolDeps, type ToolDeps, } from "../../runtime/foreground/composition/tool.factory.js";
13
+ export declare function createChatTools(deps: ToolContext & OpportunityOwnerApprovalDeps, preResolvedContext?: ResolvedToolContext): Promise<any[]>;
14
+ /**
15
+ * Type for the tools array returned by createChatTools.
16
+ */
17
+ export type ChatTools = Awaited<ReturnType<typeof createChatTools>>;
@@ -1,6 +1,235 @@
1
+ import { tool } from "@langchain/core/tools";
2
+ import { IntentGraphFactory } from "../../signals/application/intent.graph.js";
3
+ import { EnrichmentGraphFactory } from "../../enrichment/enrichment.graph.js";
4
+ import { OpportunityGraphFactory } from "../../capabilities/opportunities.facade.js";
5
+ import { HydeGraphFactory } from "../hyde/hyde.graph.js";
6
+ import { HydeGenerator } from "../hyde/hyde.generator.js";
7
+ import { LensInferrer } from "../hyde/lens.inferrer.js";
8
+ import { NetworkGraphFactory, NetworkMembershipGraphFactory, IntentNetworkGraphFactory } from "../../capabilities/communities.facade.js";
9
+ import { IntentIndexer } from "../../signals/application/intent.indexer.js";
10
+ import { NegotiationGraphFactory } from "../../capabilities/negotiation.facade.js";
11
+ import { PremiseGraphFactory } from "../../premise/premise.graph.js";
12
+ import { protocolLogger } from "../observability/protocol.logger.js";
13
+ import { resolveChatContext, error, redactSensitiveFields } from "./tool.helpers.js";
14
+ import { deriveAllowedNetworkIds, focusedIntentId, scopeFromNetworkId } from "./tool.scope.js";
15
+ import { invokeToolRuntime, toolRuntimeErrorToResult } from "./tool.runtime.js";
16
+ import { createEnrichmentTools } from "../../enrichment/enrichment.tools.js";
17
+ import { createIntentTools } from "../../signals/application/intent.tools.js";
18
+ import { createNetworkTools } from "../../capabilities/communities.facade.js";
19
+ import { createOpportunityTools } from "../../capabilities/opportunities.facade.js";
20
+ import { createUtilityTools } from "./utility.tools.js";
21
+ import { createIntegrationTools } from "../../capabilities/integrations.facade.js";
22
+ import { createContactTools } from "../../capabilities/contacts.facade.js";
23
+ import { createAgentTools } from "../../capabilities/participant-agents.tools.facade.js";
24
+ import { createNegotiationTools } from "../../capabilities/negotiation.facade.js";
25
+ import { createPremiseTools } from "../../premise/premise.tools.js";
26
+ import { createQuestionerTools, createAskUserQuestionTools } from "../../capabilities/questions.facade.js";
27
+ import { bindOwnerApprovalProvenance } from "../../opportunity/application/opportunity.owner-provenance.js";
28
+ const logger = protocolLogger("ChatTools");
29
+ // ═══════════════════════════════════════════════════════════════════════════════
30
+ // TOOL FACTORY
31
+ // ═══════════════════════════════════════════════════════════════════════════════
1
32
  /**
2
- * @deprecated Canonical location: runtime/foreground/composition/tool.factory
3
- * Retained for backward compatibility during IND-544 migration.
4
- * Import createChatTools from @indexnetwork/protocol instead.
33
+ * Creates all chat tools bound to a specific user context.
34
+ * Resolves user/network identity from DB at init time.
35
+ * Tools are created fresh for each user session to ensure proper isolation.
36
+ *
37
+ * All external dependencies (cache, integration, queue, etc.) are provided
38
+ * via the `deps` parameter — the protocol lib never imports concrete adapters.
5
39
  */
6
- export { createChatTools, } from "../../runtime/foreground/composition/tool.factory.js";
40
+ export async function createChatTools(deps, preResolvedContext) {
41
+ const { database, embedder, scraper } = deps;
42
+ const explicitScope = deps.scopeType && deps.scopeId
43
+ ? { scopeType: deps.scopeType, scopeId: deps.scopeId }
44
+ : scopeFromNetworkId(deps.networkId);
45
+ // ─── Resolve context from DB ───────────────────────────────────────────────
46
+ // resolveChatContext still accepts a networkId because it loads scoped index
47
+ // presentation metadata; the canonical request scope is explicitScope.
48
+ const resolvedContext = preResolvedContext ??
49
+ (await resolveChatContext({
50
+ database,
51
+ userId: deps.userId,
52
+ networkId: explicitScope.scopeType === 'network' ? explicitScope.scopeId : deps.networkId,
53
+ sessionId: deps.sessionId,
54
+ contactsEnabled: deps.contactsEnabled,
55
+ actionToolsEnabled: deps.actionToolsEnabled,
56
+ }));
57
+ if (!preResolvedContext && explicitScope.scopeType && explicitScope.scopeId) {
58
+ resolvedContext.scopeType = explicitScope.scopeType;
59
+ resolvedContext.scopeId = explicitScope.scopeId;
60
+ }
61
+ // This factory is an orchestrated chat surface, never a direct owner request.
62
+ // Bind that fact at composition time rather than inferring it from a session
63
+ // id or a caller-controlled tool argument inside the opportunity handler.
64
+ bindOwnerApprovalProvenance(resolvedContext, {
65
+ surface: 'chat',
66
+ sessionAuthenticated: false,
67
+ });
68
+ const allowedNetworkIds = deriveAllowedNetworkIds({
69
+ memberships: resolvedContext.userNetworks,
70
+ ...(resolvedContext.scopeType && resolvedContext.scopeId
71
+ ? { scopeType: resolvedContext.scopeType, scopeId: resolvedContext.scopeId }
72
+ : {}),
73
+ });
74
+ // ─── Tool wrapper ──────────────────────────────────────────────────────────
75
+ /**
76
+ * Standardized tool factory. Auto-injects resolved context and
77
+ * provides uniform logging / error handling for every tool.
78
+ */
79
+ function defineTool(opts) {
80
+ return tool(async (query) => {
81
+ logger.info('Tool invoked', {
82
+ toolName: opts.name,
83
+ context: { userId: resolvedContext.userId, scopeType: resolvedContext.scopeType, scopeId: resolvedContext.scopeId },
84
+ query: redactSensitiveFields(query),
85
+ });
86
+ try {
87
+ return await invokeToolRuntime({
88
+ toolName: opts.name,
89
+ tool: { handler: async ({ context, query }) => opts.handler({ context, query: query }) },
90
+ context: resolvedContext,
91
+ query,
92
+ });
93
+ }
94
+ catch (err) {
95
+ logger.error('Tool failed', {
96
+ toolName: opts.name,
97
+ error: err instanceof Error ? err.message : String(err),
98
+ });
99
+ const runtimeResult = toolRuntimeErrorToResult(err);
100
+ if (runtimeResult)
101
+ return runtimeResult;
102
+ const reason = err instanceof Error ? err.message : String(err);
103
+ return error(`Failed to execute ${opts.name}: ${reason}`);
104
+ }
105
+ }, { name: opts.name, description: opts.description, schema: opts.querySchema });
106
+ }
107
+ // ─── Compile subgraphs ─────────────────────────────────────────────────────
108
+ // Wrap questionerEnqueue to include scoped/session context when available.
109
+ const sessionAwareEnqueue = deps.questionerEnqueue
110
+ ? (input) => deps.questionerEnqueue({
111
+ ...input,
112
+ ...(resolvedContext.scopeType && resolvedContext.scopeId && !input.scopeId
113
+ ? { scopeType: resolvedContext.scopeType, scopeId: resolvedContext.scopeId }
114
+ : {}),
115
+ ...(resolvedContext.sessionId && !input.conversationId ? { conversationId: resolvedContext.sessionId } : {}),
116
+ })
117
+ : undefined;
118
+ const intentGraph = new IntentGraphFactory(database, embedder, deps.intentQueue, sessionAwareEnqueue).createGraph();
119
+ const premiseGraph = new PremiseGraphFactory(database, embedder).createGraph();
120
+ const profileGraph = new EnrichmentGraphFactory(database, scraper, deps.enricher, premiseGraph).createGraph();
121
+ const hydeCache = deps.hydeCache;
122
+ const lensInferrer = new LensInferrer();
123
+ const hydeGenerator = new HydeGenerator();
124
+ const compiledHydeGraph = new HydeGraphFactory(database, embedder, hydeCache, lensInferrer, hydeGenerator).createGraph();
125
+ const negotiationGraph = deps.agentDispatcher
126
+ ? new NegotiationGraphFactory(deps.negotiationDatabase, deps.agentDispatcher, deps.negotiationTimeoutQueue, sessionAwareEnqueue).createGraph()
127
+ : undefined;
128
+ const opportunityGraph = new OpportunityGraphFactory(database, embedder, compiledHydeGraph, undefined, // evaluator (default)
129
+ undefined, // queueNotification
130
+ negotiationGraph, deps.agentDispatcher, deps.queueNegotiateExisting, deps.stampNewbornOpportunities).createGraph();
131
+ const networkGraph = new NetworkGraphFactory(database).createGraph();
132
+ const networkMembershipGraph = new NetworkMembershipGraphFactory(database).createGraph();
133
+ const intentNetworkGraph = new IntentNetworkGraphFactory(database, new IntentIndexer()).createGraph();
134
+ // ─── Create context-bound databases ────────────────────────────────────────
135
+ // Use injected instances when provided (e.g. tests). Otherwise create from the same
136
+ // database used for graphs so that scope checks (e.g. ensureScopedMembership, opportunity
137
+ // update) use the same adapter as the rest of the tool pipeline.
138
+ //
139
+ // The systemDb's DB-level clamp derives concrete allowed network IDs from the
140
+ // focused scope envelope plus memberships, rather than consuming a transported
141
+ // legacy indexScope array.
142
+ const userDb = deps.userDb ?? deps.createUserDatabase(database, resolvedContext.userId);
143
+ const systemDb = deps.systemDb ?? deps.createSystemDatabase(database, resolvedContext.userId, allowedNetworkIds, embedder);
144
+ // ─── Assemble dependencies ─────────────────────────────────────────────────
145
+ const cache = deps.cache;
146
+ const integration = deps.integration;
147
+ const toolDeps = {
148
+ database,
149
+ userDb,
150
+ systemDb,
151
+ scraper,
152
+ embedder,
153
+ cache,
154
+ integration,
155
+ contactService: deps.contactService,
156
+ contactsEnabled: deps.contactsEnabled,
157
+ integrationImporter: deps.integrationImporter,
158
+ enricher: deps.enricher,
159
+ negotiationDatabase: deps.negotiationDatabase,
160
+ negotiationTimeoutQueue: deps.negotiationTimeoutQueue,
161
+ agentDatabase: deps.agentDatabase,
162
+ grantDefaultSystemPermissions: deps.grantDefaultSystemPermissions,
163
+ agentDispatcher: deps.agentDispatcher,
164
+ stampNewbornOpportunities: deps.stampNewbornOpportunities,
165
+ deliveryLedger: deps.deliveryLedger,
166
+ ...(deps.opportunityOwnerApproval && { opportunityOwnerApproval: deps.opportunityOwnerApproval }),
167
+ enrichmentRuns: deps.enrichmentRuns,
168
+ enrichmentRunQueue: deps.enrichmentRunQueue,
169
+ frontendUrl: deps.frontendUrl,
170
+ apiBaseUrl: deps.apiBaseUrl,
171
+ ...(deps.chatSummary && { chatSummary: deps.chatSummary }),
172
+ ...(sessionAwareEnqueue && { questionerEnqueue: sessionAwareEnqueue }),
173
+ ...(deps.findPendingQuestions && { findPendingQuestions: deps.findPendingQuestions }),
174
+ ...(deps.answerPendingQuestion && { answerPendingQuestion: deps.answerPendingQuestion }),
175
+ ...(deps.negotiationSummary && { negotiationSummary: deps.negotiationSummary }),
176
+ ...(deps.chatQuestions && { chatQuestions: deps.chatQuestions }),
177
+ ...(deps.chatSession && { chatSession: deps.chatSession }),
178
+ ...(deps.getUserContextText && { getUserContextText: deps.getUserContextText }),
179
+ ...(deps.intentProposalStore && { intentProposalStore: deps.intentProposalStore }),
180
+ graphs: {
181
+ profile: profileGraph,
182
+ intent: intentGraph,
183
+ index: networkGraph,
184
+ networkMembership: networkMembershipGraph,
185
+ intentIndex: intentNetworkGraph,
186
+ opportunity: opportunityGraph,
187
+ premise: premiseGraph,
188
+ },
189
+ };
190
+ // ─── Create domain tools ──────────────────────────────────────────────────
191
+ const profileTools = createEnrichmentTools(defineTool, toolDeps);
192
+ const intentTools = createIntentTools(defineTool, toolDeps);
193
+ // An intent-scoped conversation exists to refine its selected signal. Keep
194
+ // creation out of the model-visible registry; the update handler separately
195
+ // clamps writes to the exact scoped intent as a runtime backstop.
196
+ const intentToolsForChat = focusedIntentId(resolvedContext)
197
+ ? intentTools.filter((candidate) => candidate.name !== "create_intent")
198
+ : intentTools;
199
+ const networkTools = createNetworkTools(defineTool, toolDeps);
200
+ const opportunityTools = createOpportunityTools(defineTool, toolDeps);
201
+ const utilityTools = createUtilityTools(defineTool, toolDeps);
202
+ const contactTools = createContactTools(defineTool, toolDeps);
203
+ const agentTools = createAgentTools(defineTool, toolDeps);
204
+ const integrationTools = createIntegrationTools(defineTool, toolDeps);
205
+ const negotiationTools = deps.agentDispatcher
206
+ ? createNegotiationTools(defineTool, toolDeps)
207
+ : [];
208
+ const premiseTools = createPremiseTools(defineTool, toolDeps);
209
+ const questionerTools = createQuestionerTools(defineTool, toolDeps);
210
+ // Blocking mid-conversation questions — chat-only (never in the MCP registry),
211
+ // and only when the host provides the ChatQuestionsHost bridge.
212
+ const askUserQuestionTools = deps.chatQuestions
213
+ ? createAskUserQuestionTools(defineTool, toolDeps)
214
+ : [];
215
+ // confirm_opportunity_delivery is an OpenClaw-delivery ledger write and must not be
216
+ // callable from regular chat sessions.
217
+ const chatOpportunityToolExclusions = new Set([
218
+ "confirm_opportunity_delivery",
219
+ ]);
220
+ const opportunityToolsForChat = opportunityTools.filter((t) => !chatOpportunityToolExclusions.has(t.name));
221
+ return [
222
+ ...profileTools,
223
+ ...intentToolsForChat,
224
+ ...networkTools,
225
+ ...opportunityToolsForChat,
226
+ ...utilityTools,
227
+ ...integrationTools,
228
+ ...contactTools,
229
+ ...agentTools,
230
+ ...negotiationTools,
231
+ ...premiseTools,
232
+ ...questionerTools,
233
+ ...askUserQuestionTools,
234
+ ];
235
+ }
@@ -1,12 +1,24 @@
1
+ import type { ToolDeps, ToolRegistry } from './tool.helpers.js';
2
+ import type { ToolSurface } from './utility.tools.js';
3
+ import type { OpportunityOwnerApprovalDeps } from '../../opportunity/ports/opportunity.tools.port.js';
4
+ export interface CreateToolRegistryOptions {
5
+ /**
6
+ * Tool-surface profile. The default `'rest'` profile (direct HTTP Tool API)
7
+ * exposes contact/Gmail tools and `scrape_url`. The restricted `'mcp'`
8
+ * profile omits those surfaces (IND-596/597). Retired profile/profile-run
9
+ * compatibility aliases are absent from both profiles (IND-373/598).
10
+ */
11
+ surface?: ToolSurface;
12
+ }
1
13
  /**
2
- * Compatibility re-export shim IND-543.
14
+ * Creates a tool registry containing all tool handlers indexed by name.
15
+ * Handlers are raw async functions (not LangChain tool() wrappers) that
16
+ * accept { context, query } and return a JSON string.
3
17
  *
4
- * The canonical implementation has moved to
5
- * runtime/foreground/composition/tool.registry.ts
6
- * (interaction-composition concern).
7
- *
8
- * This shim preserves all existing import paths inside the package and in
9
- * src/index.ts so that consumers need zero changes from this relocation.
10
- * It will be removed once direct importers are migrated.
18
+ * @param deps - Shared tool dependencies (graphs, database, embedder, etc.)
19
+ * @param options - Surface profile selecting the MCP-restricted or full REST set.
20
+ * @returns Map of tool name to raw tool definition.
11
21
  */
12
- export { createToolRegistry } from '../../runtime/foreground/composition/tool.registry.js';
22
+ /** Complete registry composition with the opportunity-local owner-proof port. */
23
+ export type ToolRegistryDeps = ToolDeps & OpportunityOwnerApprovalDeps;
24
+ export declare function createToolRegistry(deps: ToolRegistryDeps, options?: CreateToolRegistryOptions): ToolRegistry;