@open-mercato/enterprise 0.10.1-develop.7801.1.52db3dc0dd → 0.10.1-develop.7802.1.2697b2d029

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.
@@ -1,6 +1,7 @@
1
1
  import { NextResponse } from "next/server";
2
2
  import { createRequestContainer } from "@open-mercato/shared/lib/di/container";
3
3
  import { readEndpointRateLimitConfig } from "@open-mercato/shared/lib/ratelimit/config";
4
+ import { readBoundedRequestBody, WebhookBodyTooLargeError } from "@open-mercato/shared/lib/webhooks";
4
5
  import { traceIngestSchema } from "../../../data/validators.js";
5
6
  import { enforcePublicEndpointRateLimit } from "../../../lib/guardrails/publicEndpointRateLimit.js";
6
7
  import { verifyTraceIngestRequest } from "../../../lib/trace/ingestAuth.js";
@@ -17,7 +18,15 @@ async function POST(req) {
17
18
  const container = await createRequestContainer();
18
19
  const rateLimited = await enforcePublicEndpointRateLimit(container, req, traceIngestRateLimitConfig);
19
20
  if (rateLimited) return rateLimited;
20
- const rawBody = await req.text();
21
+ let rawBody;
22
+ try {
23
+ rawBody = await readBoundedRequestBody(req);
24
+ } catch (error) {
25
+ if (error instanceof WebhookBodyTooLargeError) {
26
+ return NextResponse.json({ error: "payload_too_large" }, { status: 413 });
27
+ }
28
+ throw error;
29
+ }
21
30
  const principal = verifyTraceIngestRequest(req.headers, rawBody);
22
31
  if (!principal) {
23
32
  return NextResponse.json({ error: "Trace ingest verification failed" }, { status: 401 });
@@ -65,6 +74,7 @@ const openApi = {
65
74
  responses: [
66
75
  { status: 202, description: "Trace accepted (run upserted, spans/tool-calls appended)" },
67
76
  { status: 401, description: "HMAC signature verification failed" },
77
+ { status: 413, description: "Request body exceeds the byte limit (1 MiB by default; OM_WEBHOOK_MAX_BODY_BYTES overrides)" },
68
78
  { status: 422, description: "Invalid trace payload" },
69
79
  { status: 429, description: "Too many ingest requests from this client IP" },
70
80
  { status: 503, description: "Rate limiter unavailable \u2014 the request is refused rather than left uncounted" }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../../../../src/modules/agent_orchestrator/api/trace/ingest/route.ts"],
4
- "sourcesContent": ["import { NextResponse } from 'next/server'\nimport { createRequestContainer } from '@open-mercato/shared/lib/di/container'\nimport type { CommandBus, CommandRuntimeContext } from '@open-mercato/shared/lib/commands'\nimport { readEndpointRateLimitConfig } from '@open-mercato/shared/lib/ratelimit/config'\nimport { traceIngestSchema } from '../../../data/validators'\nimport { enforcePublicEndpointRateLimit } from '../../../lib/guardrails/publicEndpointRateLimit'\nimport { verifyTraceIngestRequest } from '../../../lib/trace/ingestAuth'\nimport type { IngestTraceCommandInput } from '../../../commands/trace'\nimport type { IngestTraceResult } from '../../../lib/trace/traceIngestionService'\nimport { agentOrchestratorTag } from '../../openapi'\n\n/**\n * Trace ingestion webhook (trace-eval overlay). Machine-to-machine: runtime\n * adapters POST a normalized trace, HMAC-signed per tenant. `requireAuth: false`\n * because there is no user session \u2014 the verified signature establishes the\n * tenant/org scope (never the body). Idempotent on `(runtime, externalRunId)`.\n *\n * Rate-limited per client IP BEFORE the HMAC check and the write, so an unsigned\n * flood costs neither the verification nor the database round trip. The ceiling is\n * high because legitimate adapters batch traces from a small set of hosts.\n */\nexport const metadata = {\n POST: { requireAuth: false },\n}\n\nconst traceIngestRateLimitConfig = readEndpointRateLimitConfig('AGENT_ORCH_TRACE_INGEST', {\n points: 120,\n duration: 60,\n keyPrefix: 'agent_orchestrator:trace_ingest',\n})\n\nexport async function POST(req: Request) {\n const container = await createRequestContainer()\n const rateLimited = await enforcePublicEndpointRateLimit(container, req, traceIngestRateLimitConfig)\n if (rateLimited) return rateLimited\n\n const rawBody = await req.text()\n\n const principal = verifyTraceIngestRequest(req.headers, rawBody)\n if (!principal) {\n return NextResponse.json({ error: 'Trace ingest verification failed' }, { status: 401 })\n }\n\n let body: unknown\n try {\n body = rawBody ? JSON.parse(rawBody) : {}\n } catch {\n return NextResponse.json({ error: 'Invalid JSON body' }, { status: 400 })\n }\n\n const parsed = traceIngestSchema.safeParse(body)\n if (!parsed.success) {\n return NextResponse.json({ error: 'Invalid trace payload', details: parsed.error.flatten() }, { status: 422 })\n }\n\n const commandBus = container.resolve('commandBus') as CommandBus\n const ctx: CommandRuntimeContext = {\n container,\n auth: null,\n organizationScope: null,\n selectedOrganizationId: principal.organizationId,\n organizationIds: [principal.organizationId],\n request: req,\n systemActor: true,\n }\n\n const { result } = await commandBus.execute<IngestTraceCommandInput, IngestTraceResult>(\n 'agent_orchestrator.trace.ingest',\n {\n input: {\n tenantId: principal.tenantId,\n organizationId: principal.organizationId,\n payload: parsed.data,\n },\n ctx,\n },\n )\n\n return NextResponse.json({ ok: true, ...result }, { status: 202 })\n}\n\nexport const openApi = {\n tags: [agentOrchestratorTag],\n summary: 'Ingest an agent run trace',\n methods: {\n POST: {\n summary: 'Ingest a normalized, HMAC-signed agent run trace (idempotent by runtime + externalRunId)',\n tags: [agentOrchestratorTag],\n responses: [\n { status: 202, description: 'Trace accepted (run upserted, spans/tool-calls appended)' },\n { status: 401, description: 'HMAC signature verification failed' },\n { status: 422, description: 'Invalid trace payload' },\n { status: 429, description: 'Too many ingest requests from this client IP' },\n { status: 503, description: 'Rate limiter unavailable \u2014 the request is refused rather than left uncounted' },\n ],\n },\n },\n}\n"],
5
- "mappings": "AAAA,SAAS,oBAAoB;AAC7B,SAAS,8BAA8B;AAEvC,SAAS,mCAAmC;AAC5C,SAAS,yBAAyB;AAClC,SAAS,sCAAsC;AAC/C,SAAS,gCAAgC;AAGzC,SAAS,4BAA4B;AAY9B,MAAM,WAAW;AAAA,EACtB,MAAM,EAAE,aAAa,MAAM;AAC7B;AAEA,MAAM,6BAA6B,4BAA4B,2BAA2B;AAAA,EACxF,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,WAAW;AACb,CAAC;AAED,eAAsB,KAAK,KAAc;AACvC,QAAM,YAAY,MAAM,uBAAuB;AAC/C,QAAM,cAAc,MAAM,+BAA+B,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SAAS;AAAA,MACT,MAAM,CAAC,oBAAoB;AAAA,MAC3B,WAAW;AAAA,QACT,EAAE,QAAQ,KAAK,aAAa,2DAA2D;AAAA,QACvF,EAAE,QAAQ,KAAK,aAAa,qCAAqC;AAAA,QACjE,EAAE,QAAQ,KAAK,aAAa,wBAAwB;AAAA,QACpD,EAAE,QAAQ,KAAK,aAAa,+CAA+C;AAAA,QAC3E,EAAE,QAAQ,KAAK,aAAa,oFAA+E;AAAA,MAC7G;AAAA,IACF;AAAA,EACF;AACF;",
4
+ "sourcesContent": ["import { NextResponse } from 'next/server'\nimport { createRequestContainer } from '@open-mercato/shared/lib/di/container'\nimport type { CommandBus, CommandRuntimeContext } from '@open-mercato/shared/lib/commands'\nimport { readEndpointRateLimitConfig } from '@open-mercato/shared/lib/ratelimit/config'\nimport { readBoundedRequestBody, WebhookBodyTooLargeError } from '@open-mercato/shared/lib/webhooks'\nimport { traceIngestSchema } from '../../../data/validators'\nimport { enforcePublicEndpointRateLimit } from '../../../lib/guardrails/publicEndpointRateLimit'\nimport { verifyTraceIngestRequest } from '../../../lib/trace/ingestAuth'\nimport type { IngestTraceCommandInput } from '../../../commands/trace'\nimport type { IngestTraceResult } from '../../../lib/trace/traceIngestionService'\nimport { agentOrchestratorTag } from '../../openapi'\n\n/**\n * Trace ingestion webhook (trace-eval overlay). Machine-to-machine: runtime\n * adapters POST a normalized trace, HMAC-signed per tenant. `requireAuth: false`\n * because there is no user session \u2014 the verified signature establishes the\n * tenant/org scope (never the body). Idempotent on `(runtime, externalRunId)`.\n *\n * Rate-limited per client IP BEFORE the HMAC check and the write, so an unsigned\n * flood costs neither the verification nor the database round trip. The ceiling is\n * high because legitimate adapters batch traces from a small set of hosts.\n */\nexport const metadata = {\n POST: { requireAuth: false },\n}\n\nconst traceIngestRateLimitConfig = readEndpointRateLimitConfig('AGENT_ORCH_TRACE_INGEST', {\n points: 120,\n duration: 60,\n keyPrefix: 'agent_orchestrator:trace_ingest',\n})\n\nexport async function POST(req: Request) {\n const container = await createRequestContainer()\n const rateLimited = await enforcePublicEndpointRateLimit(container, req, traceIngestRateLimitConfig)\n if (rateLimited) return rateLimited\n\n let rawBody: string\n try {\n rawBody = await readBoundedRequestBody(req)\n } catch (error) {\n if (error instanceof WebhookBodyTooLargeError) {\n return NextResponse.json({ error: 'payload_too_large' }, { status: 413 })\n }\n throw error\n }\n\n const principal = verifyTraceIngestRequest(req.headers, rawBody)\n if (!principal) {\n return NextResponse.json({ error: 'Trace ingest verification failed' }, { status: 401 })\n }\n\n let body: unknown\n try {\n body = rawBody ? JSON.parse(rawBody) : {}\n } catch {\n return NextResponse.json({ error: 'Invalid JSON body' }, { status: 400 })\n }\n\n const parsed = traceIngestSchema.safeParse(body)\n if (!parsed.success) {\n return NextResponse.json({ error: 'Invalid trace payload', details: parsed.error.flatten() }, { status: 422 })\n }\n\n const commandBus = container.resolve('commandBus') as CommandBus\n const ctx: CommandRuntimeContext = {\n container,\n auth: null,\n organizationScope: null,\n selectedOrganizationId: principal.organizationId,\n organizationIds: [principal.organizationId],\n request: req,\n systemActor: true,\n }\n\n const { result } = await commandBus.execute<IngestTraceCommandInput, IngestTraceResult>(\n 'agent_orchestrator.trace.ingest',\n {\n input: {\n tenantId: principal.tenantId,\n organizationId: principal.organizationId,\n payload: parsed.data,\n },\n ctx,\n },\n )\n\n return NextResponse.json({ ok: true, ...result }, { status: 202 })\n}\n\nexport const openApi = {\n tags: [agentOrchestratorTag],\n summary: 'Ingest an agent run trace',\n methods: {\n POST: {\n summary: 'Ingest a normalized, HMAC-signed agent run trace (idempotent by runtime + externalRunId)',\n tags: [agentOrchestratorTag],\n responses: [\n { status: 202, description: 'Trace accepted (run upserted, spans/tool-calls appended)' },\n { status: 401, description: 'HMAC signature verification failed' },\n { status: 413, description: 'Request body exceeds the byte limit (1 MiB by default; OM_WEBHOOK_MAX_BODY_BYTES overrides)' },\n { status: 422, description: 'Invalid trace payload' },\n { status: 429, description: 'Too many ingest requests from this client IP' },\n { status: 503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O,MAAM,QAAQ,EAAE,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,EAC/G;AAEA,QAAM,aAAa,UAAU,QAAQ,YAAY;AACjD,QAAM,MAA6B;AAAA,IACjC;AAAA,IACA,MAAM;AAAA,IACN,mBAAmB;AAAA,IACnB,wBAAwB,UAAU;AAAA,IAClC,iBAAiB,CAAC,UAAU,cAAc;AAAA,IAC1C,SAAS;AAAA,IACT,aAAa;AAAA,EACf;AAEA,QAAM,EAAE,OAAO,IAAI,MAAM,WAAW;AAAA,IAClC;AAAA,IACA;AAAA,MACE,OAAO;AAAA,QACL,UAAU,UAAU;AAAA,QACpB,gBAAgB,UAAU;AAAA,QAC1B,SAAS,OAAO;AAAA,MAClB;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO,aAAa,KAAK,EAAE,IAAI,MAAM,GAAG,OAAO,GAAG,EAAE,QAAQ,IAAI,CAAC;AACnE;AAEO,MAAM,UAAU;AAAA,EACrB,MAAM,CAAC,oBAAoB;AAAA,EAC3B,SAAS;AAAA,EACT,SAAS;AAAA,IACP,MAAM;AAAA,MACJ,SAAS;AAAA,MACT,MAAM,CAAC,oBAAoB;AAAA,MAC3B,WAAW;AAAA,QACT,EAAE,QAAQ,KAAK,aAAa,2DAA2D;AAAA,QACvF,EAAE,QAAQ,KAAK,aAAa,qCAAqC;AAAA,QACjE,EAAE,QAAQ,KAAK,aAAa,8FAA8F;AAAA,QAC1H,EAAE,QAAQ,KAAK,aAAa,wBAAwB;AAAA,QACpD,EAAE,QAAQ,KAAK,aAAa,+CAA+C;AAAA,QAC3E,EAAE,QAAQ,KAAK,aAAa,oFAA+E;AAAA,MAC7G;AAAA,IACF;AAAA,EACF;AACF;",
6
6
  "names": []
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-mercato/enterprise",
3
- "version": "0.10.1-develop.7801.1.52db3dc0dd",
3
+ "version": "0.10.1-develop.7802.1.2697b2d029",
4
4
  "license": "SEE LICENSE IN LICENSE.md",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -70,12 +70,12 @@
70
70
  "@dnd-kit/core": "^6.3.1",
71
71
  "@dnd-kit/sortable": "^10.0.0",
72
72
  "@dnd-kit/utilities": "^3.2.2",
73
- "@open-mercato/ai-assistant": "0.10.1-develop.7801.1.52db3dc0dd",
74
- "@open-mercato/core": "0.10.1-develop.7801.1.52db3dc0dd",
75
- "@open-mercato/queue": "0.10.1-develop.7801.1.52db3dc0dd",
76
- "@open-mercato/scheduler": "0.10.1-develop.7801.1.52db3dc0dd",
77
- "@open-mercato/ui": "0.10.1-develop.7801.1.52db3dc0dd",
78
- "@open-mercato/web-research": "0.10.1-develop.7801.1.52db3dc0dd",
73
+ "@open-mercato/ai-assistant": "0.10.1-develop.7802.1.2697b2d029",
74
+ "@open-mercato/core": "0.10.1-develop.7802.1.2697b2d029",
75
+ "@open-mercato/queue": "0.10.1-develop.7802.1.2697b2d029",
76
+ "@open-mercato/scheduler": "0.10.1-develop.7802.1.2697b2d029",
77
+ "@open-mercato/ui": "0.10.1-develop.7802.1.2697b2d029",
78
+ "@open-mercato/web-research": "0.10.1-develop.7802.1.2697b2d029",
79
79
  "@simplewebauthn/browser": "^13.3.0",
80
80
  "@simplewebauthn/server": "^13.3.2",
81
81
  "@simplewebauthn/types": "^12.0.0",
@@ -87,13 +87,13 @@
87
87
  },
88
88
  "peerDependencies": {
89
89
  "@mikro-orm/core": "^7.0.14",
90
- "@open-mercato/shared": "0.10.1-develop.7801.1.52db3dc0dd",
90
+ "@open-mercato/shared": "0.10.1-develop.7802.1.2697b2d029",
91
91
  "react": "^19.0.0",
92
92
  "react-dom": "^19.0.0",
93
93
  "zod": ">=3.23.0"
94
94
  },
95
95
  "devDependencies": {
96
- "@open-mercato/shared": "0.10.1-develop.7801.1.52db3dc0dd",
96
+ "@open-mercato/shared": "0.10.1-develop.7802.1.2697b2d029",
97
97
  "@types/jest": "^30.0.0",
98
98
  "@types/react": "^19.2.18",
99
99
  "@types/react-dom": "^19.2.5",
@@ -2,6 +2,7 @@ import { NextResponse } from 'next/server'
2
2
  import { createRequestContainer } from '@open-mercato/shared/lib/di/container'
3
3
  import type { CommandBus, CommandRuntimeContext } from '@open-mercato/shared/lib/commands'
4
4
  import { readEndpointRateLimitConfig } from '@open-mercato/shared/lib/ratelimit/config'
5
+ import { readBoundedRequestBody, WebhookBodyTooLargeError } from '@open-mercato/shared/lib/webhooks'
5
6
  import { traceIngestSchema } from '../../../data/validators'
6
7
  import { enforcePublicEndpointRateLimit } from '../../../lib/guardrails/publicEndpointRateLimit'
7
8
  import { verifyTraceIngestRequest } from '../../../lib/trace/ingestAuth'
@@ -34,7 +35,15 @@ export async function POST(req: Request) {
34
35
  const rateLimited = await enforcePublicEndpointRateLimit(container, req, traceIngestRateLimitConfig)
35
36
  if (rateLimited) return rateLimited
36
37
 
37
- const rawBody = await req.text()
38
+ let rawBody: string
39
+ try {
40
+ rawBody = await readBoundedRequestBody(req)
41
+ } catch (error) {
42
+ if (error instanceof WebhookBodyTooLargeError) {
43
+ return NextResponse.json({ error: 'payload_too_large' }, { status: 413 })
44
+ }
45
+ throw error
46
+ }
38
47
 
39
48
  const principal = verifyTraceIngestRequest(req.headers, rawBody)
40
49
  if (!principal) {
@@ -89,6 +98,7 @@ export const openApi = {
89
98
  responses: [
90
99
  { status: 202, description: 'Trace accepted (run upserted, spans/tool-calls appended)' },
91
100
  { status: 401, description: 'HMAC signature verification failed' },
101
+ { status: 413, description: 'Request body exceeds the byte limit (1 MiB by default; OM_WEBHOOK_MAX_BODY_BYTES overrides)' },
92
102
  { status: 422, description: 'Invalid trace payload' },
93
103
  { status: 429, description: 'Too many ingest requests from this client IP' },
94
104
  { status: 503, description: 'Rate limiter unavailable — the request is refused rather than left uncounted' },