@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
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Rom Iluz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # ClawMongo
2
+
3
+ A new project created with Intent by Augment.
@@ -0,0 +1,108 @@
1
+ import assert from "node:assert/strict";
2
+ import { validateEventEnvelope, validateGatewayToOrchestratorRequest, validateOrchestratorToProviderRequest, validateOrchestratorToToolRuntimeRequest } from "../contracts/validators.js";
3
+ function assertValidationError(result, expectedBoundary) {
4
+ assert.equal(result.ok, false, "validation should fail");
5
+ if (result.ok) {
6
+ return;
7
+ }
8
+ assert.equal(result.error.code, "VALIDATION_ERROR");
9
+ assert.equal(result.error.retryable, false);
10
+ assert.equal(result.error.details.boundary, expectedBoundary);
11
+ }
12
+ function run() {
13
+ const gatewayValid = validateGatewayToOrchestratorRequest({
14
+ requestId: "req-001",
15
+ tenantId: "tenant-demo",
16
+ workspaceId: "workspace-alpha",
17
+ actor: "user:123",
18
+ sessionKey: "agent:agent-alpha:main",
19
+ inputPayload: { text: "hello" }
20
+ });
21
+ assert.equal(gatewayValid.ok, true);
22
+ if (gatewayValid.ok) {
23
+ assert.equal(gatewayValid.value.request_id, "req-001");
24
+ assert.equal(gatewayValid.value.mode, "sync");
25
+ }
26
+ const gatewayInvalid = validateGatewayToOrchestratorRequest({
27
+ request_id: "req-002",
28
+ workspace_id: "workspace-alpha",
29
+ actor: "user:123",
30
+ session_key: "agent:agent-alpha:main",
31
+ input_payload: { text: "missing tenant_id" },
32
+ mode: "sync"
33
+ });
34
+ assertValidationError(gatewayInvalid, "gateway->orchestrator.v1");
35
+ const providerValid = validateOrchestratorToProviderRequest({
36
+ provider: "openai",
37
+ model: "gpt-5-mini",
38
+ messages: [{ role: "user", content: "hi" }],
39
+ toolContext: { run_mode: "smoke" },
40
+ generationConfig: { temperature: 0 }
41
+ });
42
+ assert.equal(providerValid.ok, true);
43
+ if (providerValid.ok) {
44
+ assert.equal(providerValid.value.provider, "openai");
45
+ assert.equal(providerValid.value.messages.length, 1);
46
+ }
47
+ const providerInvalid = validateOrchestratorToProviderRequest({
48
+ provider: "openai",
49
+ model: "gpt-5-mini",
50
+ messages: "not-an-array",
51
+ tool_context: {},
52
+ generation_config: {}
53
+ });
54
+ assertValidationError(providerInvalid, "orchestrator->provider.v1");
55
+ const toolValid = validateOrchestratorToToolRuntimeRequest({
56
+ toolName: "fetch_profile",
57
+ toolCallId: "call-001",
58
+ params: { user_id: "u-123" },
59
+ policyContext: { tenant_id: "tenant-demo" }
60
+ });
61
+ assert.equal(toolValid.ok, true);
62
+ if (toolValid.ok) {
63
+ assert.equal(toolValid.value.tool_name, "fetch_profile");
64
+ assert.equal(toolValid.value.tool_call_id, "call-001");
65
+ }
66
+ const toolInvalid = validateOrchestratorToToolRuntimeRequest({
67
+ tool_call_id: "call-002",
68
+ params: {},
69
+ policy_context: {}
70
+ });
71
+ assertValidationError(toolInvalid, "orchestrator->tool-runtime.v1");
72
+ const eventValid = validateEventEnvelope({
73
+ eventId: "evt-001",
74
+ eventType: "tool.side_effect.appended",
75
+ aggregateId: "tool-run:call-001",
76
+ tenantId: "tenant-demo",
77
+ payload: {
78
+ side_effect_ref: "sidefx:fetch_profile:call-001"
79
+ },
80
+ createdAt: "2026-02-11T00:00:00.000Z",
81
+ traceId: "trace-evt-001"
82
+ });
83
+ assert.equal(eventValid.ok, true);
84
+ if (eventValid.ok) {
85
+ assert.equal(eventValid.value.event_id, "evt-001");
86
+ assert.equal(eventValid.value.event_type, "tool.side_effect.appended");
87
+ }
88
+ const eventInvalid = validateEventEnvelope({
89
+ event_type: "tool.side_effect.appended",
90
+ aggregate_id: "tool-run:call-001",
91
+ tenant_id: "tenant-demo",
92
+ payload: {},
93
+ created_at: "2026-02-11T00:00:00.000Z",
94
+ trace_id: "trace-evt-002"
95
+ });
96
+ assertValidationError(eventInvalid, "eventing->outbox.v1");
97
+ process.stdout.write(`${JSON.stringify({
98
+ status: "PASS",
99
+ checks: [
100
+ { id: "gateway_mapper_and_validator", ok: true },
101
+ { id: "provider_mapper_and_validator", ok: true },
102
+ { id: "tool_runtime_mapper_and_validator", ok: true },
103
+ { id: "eventing_mapper_and_validator", ok: true },
104
+ { id: "validation_error_taxonomy", ok: true }
105
+ ]
106
+ }, null, 2)}\n`);
107
+ }
108
+ run();
@@ -0,0 +1,66 @@
1
+ import assert from "node:assert/strict";
2
+ import { applyEmbeddingPolicyToScope, DEFAULT_EMBEDDING_MODEL, DEFAULT_EMBEDDING_PROVIDER, resolveEmbeddingPolicy } from "../retrieval/embeddings/policy.js";
3
+ function run() {
4
+ const defaults = resolveEmbeddingPolicy({
5
+ tenant_id: "tenant-demo"
6
+ });
7
+ assert.equal(defaults.provider, DEFAULT_EMBEDDING_PROVIDER);
8
+ assert.equal(defaults.model, DEFAULT_EMBEDDING_MODEL);
9
+ assert.equal(defaults.source, "defaults");
10
+ const override = resolveEmbeddingPolicy({
11
+ tenant_id: "tenant-demo",
12
+ embedding_provider: "voyage",
13
+ embedding_model: "voyage-3-lite"
14
+ });
15
+ assert.equal(override.provider, "voyage");
16
+ assert.equal(override.model, "voyage-3-lite");
17
+ assert.equal(override.source, "scope_override");
18
+ const partialOverride = resolveEmbeddingPolicy({
19
+ tenant_id: "tenant-demo",
20
+ embedding_model: "voyage-4-large"
21
+ });
22
+ assert.equal(partialOverride.provider, DEFAULT_EMBEDDING_PROVIDER);
23
+ assert.equal(partialOverride.model, "voyage-4-large");
24
+ assert.equal(partialOverride.source, "scope_override");
25
+ const noOverridePolicy = resolveEmbeddingPolicy({
26
+ embedding_provider: "custom-provider",
27
+ embedding_model: "custom-model"
28
+ }, {
29
+ allowScopeOverride: false
30
+ });
31
+ assert.equal(noOverridePolicy.provider, DEFAULT_EMBEDDING_PROVIDER);
32
+ assert.equal(noOverridePolicy.model, DEFAULT_EMBEDDING_MODEL);
33
+ assert.equal(noOverridePolicy.source, "defaults");
34
+ const scoped = applyEmbeddingPolicyToScope({
35
+ tenant_id: "tenant-demo",
36
+ workspace_id: "workspace-alpha"
37
+ }, override);
38
+ assert.equal(scoped.embedding_provider, "voyage");
39
+ assert.equal(scoped.embedding_model, "voyage-3-lite");
40
+ process.stdout.write(`${JSON.stringify({
41
+ status: "PASS",
42
+ checks: [
43
+ {
44
+ id: "embedding_policy_defaults",
45
+ ok: true,
46
+ policy: defaults
47
+ },
48
+ {
49
+ id: "embedding_policy_scope_override",
50
+ ok: true,
51
+ policy: override
52
+ },
53
+ {
54
+ id: "embedding_policy_partial_override",
55
+ ok: true,
56
+ policy: partialOverride
57
+ },
58
+ {
59
+ id: "embedding_policy_override_disabled",
60
+ ok: true,
61
+ policy: noOverridePolicy
62
+ }
63
+ ]
64
+ }, null, 2)}\n`);
65
+ }
66
+ run();
@@ -0,0 +1,94 @@
1
+ import assert from "node:assert/strict";
2
+ import { createDefaultEmbeddingProviderRegistry, embedTextsWithPolicy } from "../retrieval/embeddings/provider.js";
3
+ import { resolveEmbeddingPolicy } from "../retrieval/embeddings/policy.js";
4
+ function hasAnyEnv(keys) {
5
+ return keys.some((key) => {
6
+ const value = process.env[key];
7
+ return typeof value === "string" && value.trim().length > 0;
8
+ });
9
+ }
10
+ function detectLiveProviders() {
11
+ const voyage = hasAnyEnv(["CLAWMONGO_VOYAGE_API_KEY", "VOYAGE_API_KEY"]);
12
+ const openai = hasAnyEnv(["CLAWMONGO_OPENAI_API_KEY", "OPENAI_API_KEY"]);
13
+ const globalDimensions = Number(process.env.CLAWMONGO_EMBEDDING_LIVE_DIMENSIONS ?? "");
14
+ const voyageDimensions = Number(process.env.CLAWMONGO_VOYAGE_EMBEDDING_DIMENSIONS ?? "");
15
+ const openaiDimensions = Number(process.env.CLAWMONGO_OPENAI_EMBEDDING_DIMENSIONS ?? "");
16
+ const pickDimensions = (provider) => {
17
+ const providerValue = provider === "voyage" ? voyageDimensions : openaiDimensions;
18
+ if (Number.isInteger(providerValue) && providerValue > 0) {
19
+ return providerValue;
20
+ }
21
+ if (Number.isInteger(globalDimensions) && globalDimensions > 0) {
22
+ return globalDimensions;
23
+ }
24
+ // Keep live smoke dimensions provider-valid by default.
25
+ return 256;
26
+ };
27
+ const allProviders = [
28
+ {
29
+ provider: "voyage",
30
+ model: process.env.CLAWMONGO_VOYAGE_EMBEDDING_MODEL ?? "voyage-4-large",
31
+ dimensions: pickDimensions("voyage"),
32
+ hasKey: voyage
33
+ },
34
+ {
35
+ provider: "openai",
36
+ model: process.env.CLAWMONGO_OPENAI_EMBEDDING_MODEL ?? "text-embedding-3-large",
37
+ dimensions: pickDimensions("openai"),
38
+ hasKey: openai
39
+ }
40
+ ];
41
+ return allProviders.filter((entry) => entry.hasKey);
42
+ }
43
+ async function run() {
44
+ if (process.env.CLAWMONGO_EMBEDDING_LIVE !== "true") {
45
+ process.stdout.write(`${JSON.stringify({
46
+ status: "SKIP",
47
+ reason: "Set CLAWMONGO_EMBEDDING_LIVE=true to run live embedding smoke checks."
48
+ }, null, 2)}\n`);
49
+ return;
50
+ }
51
+ const providers = detectLiveProviders();
52
+ if (providers.length === 0) {
53
+ process.stdout.write(`${JSON.stringify({
54
+ status: "SKIP",
55
+ reason: "No live embedding API keys detected. Provide Voyage and/or OpenAI keys to run this check."
56
+ }, null, 2)}\n`);
57
+ return;
58
+ }
59
+ const registry = createDefaultEmbeddingProviderRegistry({ preferLive: true });
60
+ const checks = [];
61
+ for (const providerConfig of providers) {
62
+ const policy = resolveEmbeddingPolicy({
63
+ embedding_provider: providerConfig.provider,
64
+ embedding_model: providerConfig.model
65
+ });
66
+ const result = await embedTextsWithPolicy(["ClawMongo live embedding smoke verification query"], policy, {
67
+ dimensions: providerConfig.dimensions,
68
+ inputType: "query",
69
+ registry
70
+ });
71
+ assert.equal(result.provider, providerConfig.provider);
72
+ assert.equal(result.model, providerConfig.model);
73
+ assert.equal(result.source, "live");
74
+ assert.equal(result.dimensions, providerConfig.dimensions);
75
+ assert.equal(result.vectors.length, 1);
76
+ assert.equal(result.vectors[0]?.length, providerConfig.dimensions);
77
+ checks.push({
78
+ provider: result.provider,
79
+ model: result.model,
80
+ source: result.source,
81
+ dimensions: result.dimensions,
82
+ vectorCount: result.vectors.length
83
+ });
84
+ }
85
+ process.stdout.write(`${JSON.stringify({
86
+ status: "PASS",
87
+ checks
88
+ }, null, 2)}\n`);
89
+ }
90
+ void run().catch((error) => {
91
+ const message = error instanceof Error ? error.message : String(error);
92
+ process.stderr.write(`embedding-provider-live-smoke failed: ${message}\n`);
93
+ process.exitCode = 1;
94
+ });
@@ -0,0 +1,81 @@
1
+ import assert from "node:assert/strict";
2
+ import { createDefaultEmbeddingProviderRegistry, embedTextsWithPolicy, resolveEmbeddingProvider } from "../retrieval/embeddings/provider.js";
3
+ import { resolveEmbeddingPolicy } from "../retrieval/embeddings/policy.js";
4
+ import { resolveQueryEmbeddingVector } from "../retrieval/embeddings/query-vector.js";
5
+ async function run() {
6
+ const registry = createDefaultEmbeddingProviderRegistry({ preferLive: false });
7
+ const policy = resolveEmbeddingPolicy({
8
+ embedding_provider: "voyage",
9
+ embedding_model: "voyage/voyage-4-large"
10
+ });
11
+ const provider = resolveEmbeddingProvider(policy, registry);
12
+ assert.equal(provider.provider, "voyage");
13
+ const batchA = await embedTextsWithPolicy(["Slack IDs keep case", "Mongo rank fusion fallback"], policy, {
14
+ dimensions: 8,
15
+ registry
16
+ });
17
+ const batchB = await embedTextsWithPolicy(["Slack IDs keep case", "Mongo rank fusion fallback"], policy, {
18
+ dimensions: 8,
19
+ registry
20
+ });
21
+ assert.equal(batchA.provider, "voyage");
22
+ assert.equal(batchA.model, "voyage-4-large");
23
+ assert.equal(batchA.dimensions, 8);
24
+ assert.equal(batchA.vectors.length, 2);
25
+ assert.equal(batchA.vectors[0]?.length, 8);
26
+ assert.deepEqual(batchA.vectors, batchB.vectors, "deterministic vectors should be stable");
27
+ const unsupportedPolicy = resolveEmbeddingPolicy({
28
+ embedding_provider: "custom-provider",
29
+ embedding_model: "custom-model"
30
+ });
31
+ let unsupportedError = null;
32
+ try {
33
+ resolveEmbeddingProvider(unsupportedPolicy, registry);
34
+ }
35
+ catch (error) {
36
+ unsupportedError = error instanceof Error ? error.message : String(error);
37
+ }
38
+ assert.ok(unsupportedError && unsupportedError.includes("Unsupported embedding provider"));
39
+ const scopeFallback = await resolveQueryEmbeddingVector({
40
+ query: "Unsupported provider should degrade, not crash",
41
+ scopeFilters: {
42
+ embedding_provider: "custom-provider",
43
+ embedding_model: "custom-model",
44
+ tenant_id: "tenant-demo"
45
+ },
46
+ topK: 3,
47
+ profile: "atlas-default",
48
+ preferNativeFusion: true
49
+ }, 8);
50
+ assert.equal(scopeFallback.vector.length, 8);
51
+ assert.equal(scopeFallback.degraded, true);
52
+ assert.ok(scopeFallback.note.includes("fallback"));
53
+ process.stdout.write(`${JSON.stringify({
54
+ status: "PASS",
55
+ checks: [
56
+ {
57
+ id: "provider_registry_resolution",
58
+ ok: true,
59
+ provider: provider.provider
60
+ },
61
+ {
62
+ id: "deterministic_embedding_batch",
63
+ ok: true,
64
+ dimensions: batchA.dimensions,
65
+ vectorCount: batchA.vectors.length
66
+ },
67
+ {
68
+ id: "unsupported_provider_error",
69
+ ok: true,
70
+ message: unsupportedError
71
+ },
72
+ {
73
+ id: "query_embedding_scope_fallback",
74
+ ok: true,
75
+ degraded: scopeFallback.degraded,
76
+ note: scopeFallback.note
77
+ }
78
+ ]
79
+ }, null, 2)}\n`);
80
+ }
81
+ void run();
@@ -0,0 +1,129 @@
1
+ import assert from "node:assert/strict";
2
+ import { createDefaultEmbeddingProviderRegistry, embedTextsWithPolicy } from "../retrieval/embeddings/provider.js";
3
+ import { resolveEmbeddingPolicy } from "../retrieval/embeddings/policy.js";
4
+ function jsonResponse(payload, status = 200) {
5
+ return new Response(JSON.stringify(payload), {
6
+ status,
7
+ headers: { "content-type": "application/json" }
8
+ });
9
+ }
10
+ function textResponse(payload, status = 200) {
11
+ return new Response(payload, {
12
+ status,
13
+ headers: { "content-type": "text/plain" }
14
+ });
15
+ }
16
+ async function run() {
17
+ const originalFetch = globalThis.fetch;
18
+ const originalEnv = {
19
+ CLAWMONGO_VOYAGE_API_KEY: process.env.CLAWMONGO_VOYAGE_API_KEY,
20
+ CLAWMONGO_VOYAGE_API_BASE: process.env.CLAWMONGO_VOYAGE_API_BASE
21
+ };
22
+ const calls = [];
23
+ let createBatchBody = null;
24
+ process.env.CLAWMONGO_VOYAGE_API_KEY = "test-key";
25
+ process.env.CLAWMONGO_VOYAGE_API_BASE = "https://api.voyageai.com/v1";
26
+ globalThis.fetch = (async (input, init) => {
27
+ const url = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
28
+ const method = init?.method ?? "GET";
29
+ calls.push({ url, method });
30
+ if (url.endsWith("/files") && method === "POST") {
31
+ const body = init?.body;
32
+ assert.ok(body instanceof FormData, "file upload must use FormData");
33
+ assert.equal(body.get("purpose"), "batch");
34
+ return jsonResponse({ id: "file-123" });
35
+ }
36
+ if (url.endsWith("/batches") && method === "POST") {
37
+ const body = init?.body;
38
+ assert.equal(typeof body, "string");
39
+ createBatchBody = JSON.parse(body);
40
+ return jsonResponse({ id: "batch-abc", status: "pending" });
41
+ }
42
+ if (url.endsWith("/batches/batch-abc") && method === "GET") {
43
+ return jsonResponse({
44
+ id: "batch-abc",
45
+ status: "completed",
46
+ output_file_id: "file-out-999"
47
+ });
48
+ }
49
+ if (url.endsWith("/files/file-out-999/content") && method === "GET") {
50
+ const lines = [
51
+ JSON.stringify({
52
+ custom_id: "req-1",
53
+ response: {
54
+ status_code: 200,
55
+ body: { data: [{ embedding: [0.1, 0.1, 0.1] }] }
56
+ }
57
+ }),
58
+ JSON.stringify({
59
+ custom_id: "req-2",
60
+ response: {
61
+ status_code: 200,
62
+ body: { data: [{ embedding: [0.2, 0.2, 0.2] }] }
63
+ }
64
+ })
65
+ ].join("\n");
66
+ return textResponse(lines);
67
+ }
68
+ throw new Error(`Unexpected fetch call: ${method} ${url}`);
69
+ });
70
+ try {
71
+ const registry = createDefaultEmbeddingProviderRegistry({ preferLive: true });
72
+ const policy = resolveEmbeddingPolicy({
73
+ embedding_provider: "voyage",
74
+ embedding_model: "voyage/voyage-4-large"
75
+ });
76
+ const result = await embedTextsWithPolicy(["document one", "document two"], policy, {
77
+ registry,
78
+ inputType: "document",
79
+ remoteBatch: true,
80
+ remoteBatchMinTexts: 1,
81
+ remoteBatchPollIntervalMs: 1,
82
+ remoteBatchTimeoutMs: 1000
83
+ });
84
+ assert.equal(result.provider, "voyage");
85
+ assert.equal(result.model, "voyage-4-large");
86
+ assert.equal(result.source, "live");
87
+ assert.equal(result.vectors.length, 2);
88
+ assert.deepEqual(result.vectors[0], [0.1, 0.1, 0.1]);
89
+ assert.deepEqual(result.vectors[1], [0.2, 0.2, 0.2]);
90
+ assert.ok(createBatchBody, "batch-create payload should be captured");
91
+ const batchBody = createBatchBody;
92
+ const requestParams = (batchBody.request_params ?? null);
93
+ assert.equal(batchBody.input_file_id, "file-123");
94
+ assert.equal(batchBody.endpoint, "/v1/embeddings");
95
+ assert.equal(batchBody.completion_window, "12h");
96
+ assert.deepEqual(requestParams, {
97
+ model: "voyage-4-large",
98
+ input_type: "document"
99
+ });
100
+ process.stdout.write(`${JSON.stringify({
101
+ status: "PASS",
102
+ checks: [
103
+ {
104
+ id: "voyage_remote_batch_flow",
105
+ ok: true,
106
+ fetchCallCount: calls.length
107
+ },
108
+ {
109
+ id: "voyage_remote_batch_request_shape",
110
+ ok: true,
111
+ requestParams
112
+ }
113
+ ]
114
+ }, null, 2)}\n`);
115
+ }
116
+ finally {
117
+ globalThis.fetch = originalFetch;
118
+ process.env.CLAWMONGO_VOYAGE_API_KEY = originalEnv.CLAWMONGO_VOYAGE_API_KEY;
119
+ process.env.CLAWMONGO_VOYAGE_API_BASE = originalEnv.CLAWMONGO_VOYAGE_API_BASE;
120
+ }
121
+ }
122
+ void run().catch((error) => {
123
+ const message = error instanceof Error ? error.message : String(error);
124
+ process.stdout.write(`${JSON.stringify({
125
+ status: "FAIL",
126
+ error: message
127
+ }, null, 2)}\n`);
128
+ process.exitCode = 1;
129
+ });
@@ -0,0 +1,65 @@
1
+ import assert from "node:assert/strict";
2
+ import { createDefaultGatewayDependencies, executeGatewayRequest } from "../modules/gateway/service.js";
3
+ async function run() {
4
+ const deps = createDefaultGatewayDependencies();
5
+ const successResponse = await executeGatewayRequest({
6
+ requestId: "gateway-success-001",
7
+ tenantId: "tenant-demo",
8
+ workspaceId: "workspace-alpha",
9
+ actor: "user:123",
10
+ sessionKey: "agent:agent-alpha:main",
11
+ traceId: "trace-success-001",
12
+ inputPayload: {
13
+ text: "hello gateway"
14
+ }
15
+ }, deps);
16
+ assert.equal(successResponse.status, "ok");
17
+ assert.equal(successResponse.request_id, "gateway-success-001");
18
+ assert.equal(successResponse.errors.length, 0);
19
+ assert.equal(typeof successResponse.timings.gateway_normalize_ms, "number");
20
+ assert.equal(typeof successResponse.timings.gateway_total_ms, "number");
21
+ const invalidResponse = await executeGatewayRequest({
22
+ requestId: "gateway-invalid-001",
23
+ workspaceId: "workspace-alpha",
24
+ actor: "user:123",
25
+ sessionKey: "agent:agent-alpha:main",
26
+ inputPayload: {}
27
+ }, deps);
28
+ assert.equal(invalidResponse.status, "error");
29
+ assert.equal(invalidResponse.errors[0]?.code, "VALIDATION_ERROR");
30
+ const dependencyFailureResponse = await executeGatewayRequest({
31
+ requestId: "gateway-dependency-fail-001",
32
+ tenantId: "tenant-demo",
33
+ workspaceId: "workspace-alpha",
34
+ actor: "user:123",
35
+ sessionKey: "agent:agent-alpha:main",
36
+ inputPayload: {
37
+ text: "trigger dependency failure"
38
+ }
39
+ }, {
40
+ orchestrator: async () => {
41
+ throw new Error("orchestrator unavailable");
42
+ }
43
+ });
44
+ assert.equal(dependencyFailureResponse.status, "error");
45
+ assert.equal(dependencyFailureResponse.errors[0]?.code, "DEPENDENCY_UNAVAILABLE");
46
+ assert.equal(dependencyFailureResponse.errors[0]?.retryable, true);
47
+ process.stdout.write(`${JSON.stringify({
48
+ status: "PASS",
49
+ checks: [
50
+ {
51
+ id: "gateway_normalization_and_forwarding",
52
+ ok: true
53
+ },
54
+ {
55
+ id: "gateway_validation_error",
56
+ ok: true
57
+ },
58
+ {
59
+ id: "gateway_dependency_error",
60
+ ok: true
61
+ }
62
+ ]
63
+ }, null, 2)}\n`);
64
+ }
65
+ void run();
@@ -0,0 +1,17 @@
1
+ import { bootstrapRuntime, resolveProfileSummary } from "../runtime/bootstrap.js";
2
+ async function run() {
3
+ const report = await bootstrapRuntime();
4
+ const response = {
5
+ status: report.status,
6
+ timestamp: report.timestamp,
7
+ request_id: report.requestId,
8
+ deployment_profile: report.profile,
9
+ deployment_profile_summary: resolveProfileSummary(report.profile),
10
+ modules: report.modules
11
+ };
12
+ process.stdout.write(`${JSON.stringify(response, null, 2)}\n`);
13
+ if (report.status !== "ready") {
14
+ process.exitCode = 1;
15
+ }
16
+ }
17
+ void run();
@@ -0,0 +1,14 @@
1
+ import assert from "node:assert/strict";
2
+ import { assertSearchIndexBudget } from "../store/mongo/indexes.js";
3
+ const baseline = assertSearchIndexBudget("atlas-m0", 2);
4
+ assert.equal(baseline.withinBudget, true, "atlas-m0 should allow planned=2");
5
+ assert.equal(baseline.budget, 3, "atlas-m0 budget should be 3");
6
+ const overflow = assertSearchIndexBudget("atlas-m0", 4);
7
+ assert.equal(overflow.withinBudget, false, "atlas-m0 should reject planned=4");
8
+ process.stdout.write(`${JSON.stringify({
9
+ status: "PASS",
10
+ checks: [
11
+ { id: "atlas_m0_within_budget", result: baseline },
12
+ { id: "atlas_m0_over_budget", result: overflow }
13
+ ]
14
+ }, null, 2)}\n`);