@romiluz/clawmongo 0.1.0-rc.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.
Files changed (67) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +3 -0
  3. package/dist/cli/boundary-contract-smoke.js +108 -0
  4. package/dist/cli/embedding-policy-smoke.js +66 -0
  5. package/dist/cli/embedding-provider-live-smoke.js +94 -0
  6. package/dist/cli/embedding-provider-smoke.js +81 -0
  7. package/dist/cli/embedding-provider-voyage-batch-smoke.js +129 -0
  8. package/dist/cli/gateway-smoke.js +65 -0
  9. package/dist/cli/health.js +17 -0
  10. package/dist/cli/index-budget-smoke.js +14 -0
  11. package/dist/cli/key-schema-smoke.js +118 -0
  12. package/dist/cli/orchestrator-smoke.js +75 -0
  13. package/dist/cli/provider-adapter-smoke.js +61 -0
  14. package/dist/cli/replica-track-check.js +108 -0
  15. package/dist/cli/retrieval-compat-check.js +196 -0
  16. package/dist/cli/retrieval-contract-smoke.js +72 -0
  17. package/dist/cli/retrieval-eval.js +226 -0
  18. package/dist/cli/retrieval-provider-smoke.js +52 -0
  19. package/dist/cli/retrieval-seed-reembed-smoke.js +54 -0
  20. package/dist/cli/retrieval-seed.js +312 -0
  21. package/dist/cli/runtime-contract-smoke.js +201 -0
  22. package/dist/cli/session-key-smoke.js +62 -0
  23. package/dist/cli/sprint-checks.js +129 -0
  24. package/dist/cli/tool-runtime-smoke.js +68 -0
  25. package/dist/config/deployment-profiles.js +41 -0
  26. package/dist/config/env.js +49 -0
  27. package/dist/contracts/v1.js +1 -0
  28. package/dist/contracts/validators.js +153 -0
  29. package/dist/identity/key-schema.js +31 -0
  30. package/dist/main.js +97 -0
  31. package/dist/modules/eventing/index.js +58 -0
  32. package/dist/modules/eventing/service.js +139 -0
  33. package/dist/modules/gateway/index.js +44 -0
  34. package/dist/modules/gateway/service.js +118 -0
  35. package/dist/modules/ingestion/index.js +46 -0
  36. package/dist/modules/ingestion/service.js +56 -0
  37. package/dist/modules/mongo-store/index.js +21 -0
  38. package/dist/modules/observability/index.js +6 -0
  39. package/dist/modules/orchestrator/index.js +49 -0
  40. package/dist/modules/orchestrator/service.js +220 -0
  41. package/dist/modules/policy-engine/index.js +34 -0
  42. package/dist/modules/policy-engine/service.js +42 -0
  43. package/dist/modules/provider-adapter/index.js +37 -0
  44. package/dist/modules/provider-adapter/service.js +98 -0
  45. package/dist/modules/retrieval/index.js +64 -0
  46. package/dist/modules/stub.js +17 -0
  47. package/dist/modules/tool-runtime/index.js +30 -0
  48. package/dist/modules/tool-runtime/service.js +84 -0
  49. package/dist/retrieval/contracts.js +1 -0
  50. package/dist/retrieval/embeddings/policy.js +42 -0
  51. package/dist/retrieval/embeddings/provider.js +424 -0
  52. package/dist/retrieval/embeddings/query-vector.js +34 -0
  53. package/dist/retrieval/embeddings/voyage-remote-batch.js +312 -0
  54. package/dist/retrieval/engine.js +130 -0
  55. package/dist/retrieval/fixtures.js +123 -0
  56. package/dist/retrieval/providers/fusion.js +390 -0
  57. package/dist/retrieval/providers/lexical.js +267 -0
  58. package/dist/retrieval/providers/shared.js +88 -0
  59. package/dist/retrieval/providers/vector.js +274 -0
  60. package/dist/retrieval/reembed.js +116 -0
  61. package/dist/runtime/bootstrap.js +65 -0
  62. package/dist/runtime/types.js +1 -0
  63. package/dist/session/session-key.js +128 -0
  64. package/dist/store/mongo/bootstrap.js +129 -0
  65. package/dist/store/mongo/indexes.js +110 -0
  66. package/dist/store/mongo/validators.js +238 -0
  67. package/package.json +81 -0
@@ -0,0 +1,56 @@
1
+ import { z } from "zod";
2
+ import { appendIngestionHookToOutbox } from "../eventing/service.js";
3
+ const nonEmptyString = z.string().trim().min(1);
4
+ const ingestionHookRequestSchema = z.object({
5
+ tenant_id: nonEmptyString,
6
+ aggregate_id: nonEmptyString,
7
+ hook_name: nonEmptyString,
8
+ hook_key: nonEmptyString,
9
+ payload: z.unknown(),
10
+ trace_id: nonEmptyString
11
+ });
12
+ function mapEnvelope(input) {
13
+ if (typeof input !== "object" || input === null || Array.isArray(input)) {
14
+ return input;
15
+ }
16
+ const value = input;
17
+ return {
18
+ ...value,
19
+ tenant_id: value.tenant_id ?? value.tenantId,
20
+ aggregate_id: value.aggregate_id ?? value.aggregateId,
21
+ hook_name: value.hook_name ?? value.hookName,
22
+ hook_key: value.hook_key ?? value.hookKey,
23
+ trace_id: value.trace_id ?? value.traceId
24
+ };
25
+ }
26
+ export function executeIngestionHookAppend(input) {
27
+ const parsed = ingestionHookRequestSchema.safeParse(mapEnvelope(input));
28
+ if (!parsed.success) {
29
+ return {
30
+ ok: false,
31
+ error: {
32
+ code: "VALIDATION_ERROR",
33
+ message: "Invalid ingestion hook append request.",
34
+ details: {
35
+ boundary: "ingestion->eventing.v1",
36
+ issues: parsed.error.issues.map((issue) => ({
37
+ path: issue.path.join("."),
38
+ code: issue.code,
39
+ message: issue.message
40
+ }))
41
+ }
42
+ }
43
+ };
44
+ }
45
+ return {
46
+ ok: true,
47
+ outbox_result: appendIngestionHookToOutbox({
48
+ tenant_id: parsed.data.tenant_id,
49
+ aggregate_id: parsed.data.aggregate_id,
50
+ hook_name: parsed.data.hook_name,
51
+ hook_key: parsed.data.hook_key,
52
+ payload: parsed.data.payload ?? null,
53
+ trace_id: parsed.data.trace_id
54
+ })
55
+ };
56
+ }
@@ -0,0 +1,21 @@
1
+ import { bootstrapMongoStore } from "../../store/mongo/bootstrap.js";
2
+ export const moduleDefinition = {
3
+ name: "mongo-store",
4
+ contractVersion: "v1",
5
+ boundaries: ["mongo-store->collections.v1"],
6
+ async start(ctx) {
7
+ const result = await bootstrapMongoStore({
8
+ deploymentProfile: ctx.deploymentProfile,
9
+ ...ctx.mongo
10
+ });
11
+ return {
12
+ status: result.status,
13
+ details: {
14
+ code: result.code,
15
+ retryable: result.retryable,
16
+ message: result.message,
17
+ ...result.details
18
+ }
19
+ };
20
+ }
21
+ };
@@ -0,0 +1,6 @@
1
+ import { createStubModule } from "../stub.js";
2
+ export const moduleDefinition = createStubModule({
3
+ name: "observability",
4
+ contractVersion: "v1",
5
+ boundaries: ["all-modules->observability.v1"]
6
+ });
@@ -0,0 +1,49 @@
1
+ import { createDefaultOrchestratorDependencies, executeOrchestratorRequest } from "./service.js";
2
+ const orchestratorDependencies = createDefaultOrchestratorDependencies();
3
+ export const moduleDefinition = {
4
+ name: "orchestrator",
5
+ contractVersion: "v1",
6
+ boundaries: ["orchestrator->retrieval.v1", "orchestrator->provider.v1", "orchestrator->tool-runtime.v1"],
7
+ async start(ctx) {
8
+ try {
9
+ const sampleResponse = await executeOrchestratorRequest({
10
+ request_id: `orchestrator-boot-${ctx.requestId}`,
11
+ tenant_id: "tenant-demo",
12
+ workspace_id: "workspace-alpha",
13
+ actor: "system:bootstrap",
14
+ session_key: "agent:agent-alpha:main",
15
+ input_payload: {
16
+ text: "boot health check",
17
+ tool_call: {
18
+ tool_name: "health_probe",
19
+ params: {
20
+ deployment_profile: ctx.deploymentProfile
21
+ }
22
+ }
23
+ },
24
+ mode: "sync"
25
+ }, orchestratorDependencies);
26
+ return {
27
+ status: sampleResponse.status === "ok" ? "ready" : "degraded",
28
+ details: {
29
+ deploymentProfile: ctx.deploymentProfile,
30
+ sampleStatus: sampleResponse.status,
31
+ errorCount: sampleResponse.errors.length,
32
+ timings: sampleResponse.timings,
33
+ note: "orchestrator runtime baseline initialized"
34
+ }
35
+ };
36
+ }
37
+ catch (error) {
38
+ const message = error instanceof Error ? error.message : String(error);
39
+ return {
40
+ status: "degraded",
41
+ details: {
42
+ deploymentProfile: ctx.deploymentProfile,
43
+ error: message,
44
+ note: "orchestrator runtime baseline failed"
45
+ }
46
+ };
47
+ }
48
+ }
49
+ };
@@ -0,0 +1,220 @@
1
+ import { performance } from "node:perf_hooks";
2
+ import { validateGatewayToOrchestratorRequest, validateOrchestratorToProviderRequest, validateOrchestratorToToolRuntimeRequest } from "../../contracts/validators.js";
3
+ import { executeProviderAdapter, ProviderAdapterExecutionError } from "../provider-adapter/service.js";
4
+ import { executeToolRuntime } from "../tool-runtime/service.js";
5
+ function roundedDuration(startedAt) {
6
+ return Number((performance.now() - startedAt).toFixed(3));
7
+ }
8
+ function dependencyError(stage, error) {
9
+ if (error instanceof ProviderAdapterExecutionError) {
10
+ return {
11
+ code: error.code,
12
+ message: `${stage} dependency failed: ${error.message}`,
13
+ retryable: error.retryable,
14
+ details: {
15
+ stage,
16
+ ...error.details
17
+ }
18
+ };
19
+ }
20
+ const message = error instanceof Error ? error.message : String(error);
21
+ return {
22
+ code: "DEPENDENCY_UNAVAILABLE",
23
+ message: `${stage} dependency failed: ${message}`,
24
+ retryable: true,
25
+ details: {
26
+ stage
27
+ }
28
+ };
29
+ }
30
+ function toolRuntimeFailureError(response) {
31
+ const resultPayload = typeof response.result === "object" && response.result !== null
32
+ ? response.result
33
+ : {};
34
+ const code = typeof resultPayload.error_code === "string"
35
+ ? resultPayload.error_code
36
+ : "NON_RETRYABLE_FAILURE";
37
+ const retryable = resultPayload.retryable === true;
38
+ return {
39
+ code,
40
+ message: `tool-runtime returned status=${response.status}`,
41
+ retryable,
42
+ details: {
43
+ tool_call_id: response.tool_call_id,
44
+ ...(typeof resultPayload.message === "string" ? { reason: resultPayload.message } : {})
45
+ }
46
+ };
47
+ }
48
+ function coerceRequestId(input) {
49
+ if (typeof input === "object" && input !== null) {
50
+ const value = input.request_id;
51
+ if (typeof value === "string" && value.trim().length > 0) {
52
+ return value;
53
+ }
54
+ }
55
+ return "invalid-request";
56
+ }
57
+ function buildRetrievalRequest(request) {
58
+ const payload = typeof request.input_payload === "object" && request.input_payload !== null
59
+ ? request.input_payload
60
+ : {};
61
+ const querySource = typeof payload.query === "string"
62
+ ? payload.query
63
+ : typeof payload.text === "string"
64
+ ? payload.text
65
+ : "orchestrator-default-query";
66
+ return {
67
+ query: querySource,
68
+ scope_filters: {
69
+ tenant_id: request.tenant_id,
70
+ workspace_id: request.workspace_id,
71
+ session_key: request.session_key
72
+ },
73
+ top_k: 5,
74
+ retrieval_profile: "hybrid"
75
+ };
76
+ }
77
+ function buildProviderRequest(request) {
78
+ const payload = typeof request.input_payload === "object" && request.input_payload !== null
79
+ ? request.input_payload
80
+ : {};
81
+ const messages = Array.isArray(payload.messages)
82
+ ? payload.messages
83
+ : [
84
+ {
85
+ role: "user",
86
+ content: typeof payload.text === "string" ? payload.text : request.actor
87
+ }
88
+ ];
89
+ return {
90
+ provider: typeof payload.provider === "string" ? payload.provider : "openai",
91
+ model: typeof payload.model === "string" ? payload.model : "gpt-5-mini",
92
+ messages,
93
+ tool_context: {
94
+ tenant_id: request.tenant_id,
95
+ workspace_id: request.workspace_id,
96
+ session_key: request.session_key
97
+ },
98
+ generation_config: typeof payload.generation_config === "object" && payload.generation_config !== null
99
+ ? payload.generation_config
100
+ : {}
101
+ };
102
+ }
103
+ function buildToolRuntimeRequest(request) {
104
+ const payload = typeof request.input_payload === "object" && request.input_payload !== null
105
+ ? request.input_payload
106
+ : {};
107
+ const tool = payload.tool_call;
108
+ if (typeof tool !== "object" || tool === null) {
109
+ return null;
110
+ }
111
+ const toolObject = tool;
112
+ return {
113
+ tool_name: toolObject.tool_name ?? toolObject.toolName,
114
+ tool_call_id: toolObject.tool_call_id ?? toolObject.toolCallId ?? `${request.request_id}-tool`,
115
+ params: typeof toolObject.params === "object" && toolObject.params !== null ? toolObject.params : {},
116
+ policy_context: typeof toolObject.policy_context === "object" && toolObject.policy_context !== null
117
+ ? toolObject.policy_context
118
+ : {
119
+ tenant_id: request.tenant_id,
120
+ workspace_id: request.workspace_id
121
+ }
122
+ };
123
+ }
124
+ function toResponse(requestId, result, errors, timings) {
125
+ return {
126
+ request_id: requestId,
127
+ status: errors.length === 0 ? "ok" : "error",
128
+ result,
129
+ errors,
130
+ timings
131
+ };
132
+ }
133
+ export async function executeOrchestratorRequest(input, deps) {
134
+ const totalStartedAt = performance.now();
135
+ const timings = {};
136
+ const errors = [];
137
+ const requestId = coerceRequestId(input);
138
+ const validationStartedAt = performance.now();
139
+ const gatewayValidation = validateGatewayToOrchestratorRequest(input);
140
+ timings.validation_ms = roundedDuration(validationStartedAt);
141
+ if (!gatewayValidation.ok) {
142
+ errors.push(gatewayValidation.error);
143
+ timings.total_ms = roundedDuration(totalStartedAt);
144
+ return toResponse(requestId, null, errors, timings);
145
+ }
146
+ const gatewayRequest = gatewayValidation.value;
147
+ let retrievalResponse = null;
148
+ const retrievalStartedAt = performance.now();
149
+ try {
150
+ retrievalResponse = await deps.retrieval(buildRetrievalRequest(gatewayRequest));
151
+ }
152
+ catch (error) {
153
+ errors.push(dependencyError("retrieval", error));
154
+ }
155
+ timings.retrieval_ms = roundedDuration(retrievalStartedAt);
156
+ const providerValidationStartedAt = performance.now();
157
+ const providerValidation = validateOrchestratorToProviderRequest(buildProviderRequest(gatewayRequest));
158
+ timings.provider_validation_ms = roundedDuration(providerValidationStartedAt);
159
+ if (!providerValidation.ok) {
160
+ errors.push(providerValidation.error);
161
+ timings.total_ms = roundedDuration(totalStartedAt);
162
+ return toResponse(gatewayRequest.request_id, { retrieval: retrievalResponse }, errors, timings);
163
+ }
164
+ let providerResponse = null;
165
+ const providerStartedAt = performance.now();
166
+ try {
167
+ providerResponse = await deps.provider(providerValidation.value);
168
+ }
169
+ catch (error) {
170
+ errors.push(dependencyError("provider", error));
171
+ }
172
+ timings.provider_ms = roundedDuration(providerStartedAt);
173
+ let toolRuntimeResponse = null;
174
+ const toolRuntimeStartedAt = performance.now();
175
+ const toolRuntimeCandidate = buildToolRuntimeRequest(gatewayRequest);
176
+ if (toolRuntimeCandidate !== null) {
177
+ const toolValidation = validateOrchestratorToToolRuntimeRequest(toolRuntimeCandidate);
178
+ if (!toolValidation.ok) {
179
+ errors.push(toolValidation.error);
180
+ }
181
+ else {
182
+ try {
183
+ toolRuntimeResponse = await deps.toolRuntime(toolValidation.value);
184
+ if (toolRuntimeResponse.status === "error") {
185
+ errors.push(toolRuntimeFailureError(toolRuntimeResponse));
186
+ }
187
+ }
188
+ catch (error) {
189
+ errors.push(dependencyError("tool-runtime", error));
190
+ }
191
+ }
192
+ }
193
+ timings.tool_runtime_ms = roundedDuration(toolRuntimeStartedAt);
194
+ timings.total_ms = roundedDuration(totalStartedAt);
195
+ return toResponse(gatewayRequest.request_id, {
196
+ retrieval: retrievalResponse,
197
+ provider: providerResponse,
198
+ ...(toolRuntimeResponse ? { tool_runtime: toolRuntimeResponse } : {})
199
+ }, errors, timings);
200
+ }
201
+ export function createDefaultOrchestratorDependencies() {
202
+ return {
203
+ retrieval: async (request) => ({
204
+ results: [
205
+ {
206
+ id: "orchestrator-default-result",
207
+ score: 1,
208
+ query: request.query
209
+ }
210
+ ],
211
+ pipeline_mode: "hybrid",
212
+ degraded: false,
213
+ debug: {
214
+ source: "orchestrator-default-retrieval"
215
+ }
216
+ }),
217
+ provider: async (request) => executeProviderAdapter(request),
218
+ toolRuntime: async (request) => executeToolRuntime(request)
219
+ };
220
+ }
@@ -0,0 +1,34 @@
1
+ import { evaluateToolPolicy } from "./service.js";
2
+ export const moduleDefinition = {
3
+ name: "policy-engine",
4
+ contractVersion: "v1",
5
+ boundaries: ["tool-runtime->policy-engine.v1"],
6
+ async start(ctx) {
7
+ const allowDecision = evaluateToolPolicy({
8
+ tool_name: "fetch_profile",
9
+ tool_call_id: "policy-allow-001",
10
+ params: {},
11
+ policy_context: {
12
+ tenant_id: "tenant-demo"
13
+ }
14
+ });
15
+ const denyDecision = evaluateToolPolicy({
16
+ tool_name: "internal.rebuild_index",
17
+ tool_call_id: "policy-deny-001",
18
+ params: {},
19
+ policy_context: {
20
+ tenant_id: "tenant-demo",
21
+ allow_internal_tools: false
22
+ }
23
+ });
24
+ return {
25
+ status: allowDecision.allow && !denyDecision.allow ? "ready" : "degraded",
26
+ details: {
27
+ deploymentProfile: ctx.deploymentProfile,
28
+ allowDecision,
29
+ denyDecision,
30
+ note: "policy engine runtime baseline initialized"
31
+ }
32
+ };
33
+ }
34
+ };
@@ -0,0 +1,42 @@
1
+ function readBoolean(value) {
2
+ return value === true;
3
+ }
4
+ export function evaluateToolPolicy(request) {
5
+ const context = request.policy_context;
6
+ const params = request.params;
7
+ if (readBoolean(context.blocked)) {
8
+ return {
9
+ allow: false,
10
+ reason: "context_blocked",
11
+ policySignals: {
12
+ blocked: true
13
+ }
14
+ };
15
+ }
16
+ if (readBoolean(params.requires_admin) && !readBoolean(context.is_admin)) {
17
+ return {
18
+ allow: false,
19
+ reason: "admin_required",
20
+ policySignals: {
21
+ requires_admin: true,
22
+ is_admin: false
23
+ }
24
+ };
25
+ }
26
+ if (request.tool_name.startsWith("internal.") && !readBoolean(context.allow_internal_tools)) {
27
+ return {
28
+ allow: false,
29
+ reason: "internal_tool_denied",
30
+ policySignals: {
31
+ allow_internal_tools: false
32
+ }
33
+ };
34
+ }
35
+ return {
36
+ allow: true,
37
+ reason: "policy_pass",
38
+ policySignals: {
39
+ blocked: false
40
+ }
41
+ };
42
+ }
@@ -0,0 +1,37 @@
1
+ import { executeProviderAdapterRequest } from "./service.js";
2
+ export const moduleDefinition = {
3
+ name: "provider-adapter",
4
+ contractVersion: "v1",
5
+ boundaries: ["orchestrator->provider.v1"],
6
+ async start(ctx) {
7
+ const sample = executeProviderAdapterRequest({
8
+ provider: "openai",
9
+ model: "gpt-5-mini",
10
+ messages: [{ role: "user", content: "provider health check" }],
11
+ tool_context: {
12
+ tenant_id: "tenant-demo",
13
+ workspace_id: "workspace-alpha",
14
+ deployment_profile: ctx.deploymentProfile
15
+ },
16
+ generation_config: {}
17
+ });
18
+ if (!sample.ok) {
19
+ return {
20
+ status: "degraded",
21
+ details: {
22
+ deploymentProfile: ctx.deploymentProfile,
23
+ error: sample.error
24
+ }
25
+ };
26
+ }
27
+ return {
28
+ status: "ready",
29
+ details: {
30
+ deploymentProfile: ctx.deploymentProfile,
31
+ providerMetadata: sample.response.provider_metadata,
32
+ safetySignals: sample.response.safety_signals,
33
+ note: "provider adapter runtime baseline initialized"
34
+ }
35
+ };
36
+ }
37
+ };
@@ -0,0 +1,98 @@
1
+ import { validateOrchestratorToProviderRequest } from "../../contracts/validators.js";
2
+ const SUPPORTED_PROVIDERS = new Set(["openai", "anthropic", "google", "voyage"]);
3
+ export class ProviderAdapterExecutionError extends Error {
4
+ code;
5
+ retryable;
6
+ details;
7
+ constructor(error) {
8
+ super(error.message);
9
+ this.name = "ProviderAdapterExecutionError";
10
+ this.code = error.code;
11
+ this.retryable = error.retryable;
12
+ this.details = error.details;
13
+ }
14
+ }
15
+ function toFailure(code, message, retryable, details) {
16
+ return {
17
+ code,
18
+ message,
19
+ retryable,
20
+ details
21
+ };
22
+ }
23
+ function readForceErrorMode(request) {
24
+ const mode = request.generation_config.force_provider_error;
25
+ return typeof mode === "string" && mode.trim().length > 0 ? mode : undefined;
26
+ }
27
+ function buildSuccessResponse(request) {
28
+ return {
29
+ output: {
30
+ role: "assistant",
31
+ content: `provider:${request.provider};model:${request.model};messages:${request.messages.length}`
32
+ },
33
+ usage: {
34
+ input_tokens: 128,
35
+ output_tokens: 64
36
+ },
37
+ provider_metadata: {
38
+ provider: request.provider,
39
+ model: request.model,
40
+ execution_mode: "deterministic-mock",
41
+ retry_classification: "none"
42
+ },
43
+ safety_signals: {
44
+ blocked: false,
45
+ moderation: "pass"
46
+ }
47
+ };
48
+ }
49
+ export function executeProviderAdapterRequest(input) {
50
+ const validation = validateOrchestratorToProviderRequest(input);
51
+ if (!validation.ok) {
52
+ return {
53
+ ok: false,
54
+ error: validation.error
55
+ };
56
+ }
57
+ const request = validation.value;
58
+ const providerKey = request.provider.toLowerCase();
59
+ if (!SUPPORTED_PROVIDERS.has(providerKey)) {
60
+ return {
61
+ ok: false,
62
+ error: toFailure("NON_RETRYABLE_FAILURE", `Unsupported provider '${request.provider}'.`, false, {
63
+ provider: request.provider,
64
+ supported_providers: Array.from(SUPPORTED_PROVIDERS.values())
65
+ })
66
+ };
67
+ }
68
+ const forceErrorMode = readForceErrorMode(request);
69
+ if (forceErrorMode === "retryable") {
70
+ return {
71
+ ok: false,
72
+ error: toFailure("RETRYABLE_FAILURE", "Provider adapter forced retryable failure mode.", true, {
73
+ provider: request.provider,
74
+ model: request.model
75
+ })
76
+ };
77
+ }
78
+ if (forceErrorMode === "non_retryable") {
79
+ return {
80
+ ok: false,
81
+ error: toFailure("NON_RETRYABLE_FAILURE", "Provider adapter forced non-retryable failure mode.", false, {
82
+ provider: request.provider,
83
+ model: request.model
84
+ })
85
+ };
86
+ }
87
+ return {
88
+ ok: true,
89
+ response: buildSuccessResponse(request)
90
+ };
91
+ }
92
+ export async function executeProviderAdapter(request) {
93
+ const result = executeProviderAdapterRequest(request);
94
+ if (result.ok) {
95
+ return result.response;
96
+ }
97
+ throw new ProviderAdapterExecutionError(result.error);
98
+ }
@@ -0,0 +1,64 @@
1
+ import { RetrievalEngine } from "../../retrieval/engine.js";
2
+ import { AdaptiveFusionRetriever } from "../../retrieval/providers/fusion.js";
3
+ import { MongoLexicalRetriever, StubLexicalRetriever } from "../../retrieval/providers/lexical.js";
4
+ import { MongoVectorRetriever, StubVectorRetriever } from "../../retrieval/providers/vector.js";
5
+ function hasNativeFusion(profile) {
6
+ return profile !== "atlas-m0";
7
+ }
8
+ export const moduleDefinition = {
9
+ name: "retrieval-service",
10
+ contractVersion: "v1",
11
+ boundaries: ["orchestrator->retrieval.v1", "retrieval->mongo-store.v1"],
12
+ async start(ctx) {
13
+ const lexicalProvider = ctx.mongo.uri
14
+ ? new MongoLexicalRetriever({
15
+ deploymentProfile: ctx.deploymentProfile,
16
+ uri: ctx.mongo.uri,
17
+ dbName: ctx.mongo.dbName,
18
+ connectTimeoutMs: ctx.mongo.connectTimeoutMs
19
+ })
20
+ : new StubLexicalRetriever();
21
+ const vectorProvider = ctx.mongo.uri
22
+ ? new MongoVectorRetriever({
23
+ deploymentProfile: ctx.deploymentProfile,
24
+ uri: ctx.mongo.uri,
25
+ dbName: ctx.mongo.dbName,
26
+ connectTimeoutMs: ctx.mongo.connectTimeoutMs
27
+ })
28
+ : new StubVectorRetriever();
29
+ const fusionProvider = new AdaptiveFusionRetriever({
30
+ supportsNativeFusion: hasNativeFusion(ctx.deploymentProfile),
31
+ uri: ctx.mongo.uri,
32
+ dbName: ctx.mongo.dbName,
33
+ connectTimeoutMs: ctx.mongo.connectTimeoutMs
34
+ });
35
+ const engine = new RetrievalEngine(lexicalProvider, vectorProvider, fusionProvider);
36
+ const result = await engine.retrieve({
37
+ query: "startup retrieval probe",
38
+ scopeFilters: {
39
+ ...(ctx.mongo.uri
40
+ ? {
41
+ tenant_id: "tenant-demo",
42
+ workspace_id: "workspace-alpha"
43
+ }
44
+ : {
45
+ tenant: "bootstrap"
46
+ })
47
+ },
48
+ topK: 3,
49
+ profile: ctx.deploymentProfile,
50
+ preferNativeFusion: Boolean(ctx.mongo.uri)
51
+ });
52
+ return {
53
+ status: "ready",
54
+ details: {
55
+ mode: result.mode,
56
+ degraded: result.degraded,
57
+ hitCount: result.hits.length,
58
+ fusionStrategy: result.debug.fusionStrategy,
59
+ diagnostics: result.diagnostics,
60
+ providerMode: ctx.mongo.uri ? "mongo" : "stub"
61
+ }
62
+ };
63
+ }
64
+ };
@@ -0,0 +1,17 @@
1
+ export function createStubModule(config) {
2
+ return {
3
+ name: config.name,
4
+ contractVersion: config.contractVersion,
5
+ boundaries: config.boundaries,
6
+ async start(ctx) {
7
+ return {
8
+ status: "ready",
9
+ details: {
10
+ deploymentProfile: ctx.deploymentProfile,
11
+ startedAt: ctx.startedAt,
12
+ note: "module stub initialized"
13
+ }
14
+ };
15
+ }
16
+ };
17
+ }
@@ -0,0 +1,30 @@
1
+ import { executeToolRuntimeRequest } from "./service.js";
2
+ export const moduleDefinition = {
3
+ name: "tool-runtime",
4
+ contractVersion: "v1",
5
+ boundaries: ["orchestrator->tool-runtime.v1", "tool-runtime->policy-engine.v1"],
6
+ async start(ctx) {
7
+ const sample = executeToolRuntimeRequest({
8
+ tool_name: "fetch_profile",
9
+ tool_call_id: "tool-runtime-health-001",
10
+ params: {
11
+ user_id: "u-123"
12
+ },
13
+ policy_context: {
14
+ tenant_id: "tenant-demo",
15
+ workspace_id: "workspace-alpha",
16
+ deployment_profile: ctx.deploymentProfile
17
+ }
18
+ });
19
+ return {
20
+ status: sample.ok ? "ready" : "degraded",
21
+ details: {
22
+ deploymentProfile: ctx.deploymentProfile,
23
+ status: sample.response.status,
24
+ policy: sample.policy,
25
+ sideEffectRefs: sample.response.side_effect_refs,
26
+ note: "tool runtime baseline initialized"
27
+ }
28
+ };
29
+ }
30
+ };