agentic-server 0.30.2 → 0.31.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.
- package/README.md +3 -2
- package/esm/index.js +1 -0
- package/esm/models.js +72 -0
- package/esm/router.js +24 -12
- package/esm/server.js +3 -1
- package/index.d.ts +2 -0
- package/index.js +4 -1
- package/models.d.ts +15 -0
- package/models.js +76 -0
- package/package.json +2 -2
- package/router.js +24 -12
- package/server.d.ts +2 -0
- package/server.js +4 -2
- package/types.d.ts +5 -0
package/README.md
CHANGED
|
@@ -43,8 +43,9 @@ app.listen(3001, () => {
|
|
|
43
43
|
| POST | `/v1/chat/completions` | OpenAI-compatible chat completion (multi-provider) |
|
|
44
44
|
| POST | `/v1/embeddings` | OpenAI-compatible embeddings (multi-provider) |
|
|
45
45
|
| POST | `/v1/usage` | Submit an external usage report to the metering sink |
|
|
46
|
-
| GET | `/v1/
|
|
47
|
-
| GET | `/
|
|
46
|
+
| GET | `/v1/models` | Models a caller can run: `{ object: 'list', data: [{ id, name }] }`. Requires `X-Database-Id`. `id` is what to send as `model`; nothing about the providers is returned |
|
|
47
|
+
| GET | `/v1/providers` | List configured providers (operator) |
|
|
48
|
+
| GET | `/healthz` | Liveness: `{ status: 'ok' }` |
|
|
48
49
|
|
|
49
50
|
## Streaming
|
|
50
51
|
|
package/esm/index.js
CHANGED
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
24
|
export { BadRequestError } from './errors';
|
|
25
|
+
export { listServedModels, MODEL_LIST_HINT } from './models';
|
|
25
26
|
export { buildProviderHeaders, resolveProvider, resolveUpstreamUrl } from './providers';
|
|
26
27
|
export { createRouter } from './router';
|
|
27
28
|
export { createAgenticServer } from './server';
|
package/esm/models.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { buildProviderHeaders, resolveProvider } from './providers';
|
|
2
|
+
import { providerName, upstreamModel } from './transforms';
|
|
3
|
+
/** Appended to an upstream "no such model" answer, so the caller knows where to look. */
|
|
4
|
+
export const MODEL_LIST_HINT = 'GET /v1/models lists the models this gateway serves';
|
|
5
|
+
const configuredProviders = (options) => options.providers && options.providers.length > 0
|
|
6
|
+
? options.providers
|
|
7
|
+
: [resolveProvider(options)];
|
|
8
|
+
const text = (value) => typeof value === 'string' && value ? value : undefined;
|
|
9
|
+
const served = (row, idField) => {
|
|
10
|
+
const id = text(row[idField]);
|
|
11
|
+
return id ? [{ id, name: text(row.display_name) ?? id }] : [];
|
|
12
|
+
};
|
|
13
|
+
/** The models one provider serves, as its own listing names them. */
|
|
14
|
+
async function upstreamModels(provider) {
|
|
15
|
+
const listing = async (url) => {
|
|
16
|
+
const res = await fetch(url, { headers: buildProviderHeaders(provider) });
|
|
17
|
+
if (!res.ok) {
|
|
18
|
+
throw new Error(`${providerName(provider)} answered ${res.status} to a model listing`);
|
|
19
|
+
}
|
|
20
|
+
return await res.json();
|
|
21
|
+
};
|
|
22
|
+
const rows = (list) => {
|
|
23
|
+
if (!Array.isArray(list)) {
|
|
24
|
+
throw new Error(`${providerName(provider)} answered a model listing with no list`);
|
|
25
|
+
}
|
|
26
|
+
return list;
|
|
27
|
+
};
|
|
28
|
+
if (provider.type === 'ollama') {
|
|
29
|
+
const body = await listing(`${provider.baseUrl}/api/tags`);
|
|
30
|
+
return rows(body.models).flatMap((row) => served(row, 'name'));
|
|
31
|
+
}
|
|
32
|
+
// A listing may be paged (Anthropic's is): follow it to the end, or the
|
|
33
|
+
// models on a later page read as not served.
|
|
34
|
+
const models = [];
|
|
35
|
+
let after;
|
|
36
|
+
do {
|
|
37
|
+
const page = after ? `?after_id=${encodeURIComponent(after)}` : '';
|
|
38
|
+
const body = await listing(`${provider.baseUrl}/v1/models${page}`);
|
|
39
|
+
models.push(...rows(body.data).flatMap((row) => served(row, 'id')));
|
|
40
|
+
const next = body.has_more === true ? text(body.last_id) : undefined;
|
|
41
|
+
if (next === after)
|
|
42
|
+
break;
|
|
43
|
+
after = next;
|
|
44
|
+
} while (after);
|
|
45
|
+
return models;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Every model the gateway serves, under the id that reaches it: the bare
|
|
49
|
+
* upstream id when the router would send that, unchanged, to the provider serving it, the
|
|
50
|
+
* `name/` prefixed one otherwise. Only the id and a display name leave here —
|
|
51
|
+
* which provider serves a model, and where, is the deployment's business.
|
|
52
|
+
*/
|
|
53
|
+
export async function listServedModels(options) {
|
|
54
|
+
const providers = configuredProviders(options);
|
|
55
|
+
const lists = await Promise.all(providers.map(upstreamModels));
|
|
56
|
+
const seen = new Set();
|
|
57
|
+
return lists.flatMap((models, index) => {
|
|
58
|
+
const provider = providers[index];
|
|
59
|
+
return models.flatMap(({ id, name }) => {
|
|
60
|
+
const routed = resolveProvider(options, id);
|
|
61
|
+
// Bare only when the id both routes here and survives the prefix strip:
|
|
62
|
+
// an upstream id that itself begins `openai/` would lose that segment.
|
|
63
|
+
const bare = (providers.length === 1 || providerName(routed) === providerName(provider)) &&
|
|
64
|
+
upstreamModel(provider, id) === id;
|
|
65
|
+
const served = bare ? id : `${providerName(provider)}/${id}`;
|
|
66
|
+
if (seen.has(served))
|
|
67
|
+
return [];
|
|
68
|
+
seen.add(served);
|
|
69
|
+
return [{ id: served, name }];
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
}
|
package/esm/router.js
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
import { Logger } from '@pgpmjs/logger';
|
|
13
13
|
import { Router } from 'express';
|
|
14
14
|
import { BadRequestError } from './errors';
|
|
15
|
+
import { listServedModels, MODEL_LIST_HINT } from './models';
|
|
15
16
|
import { buildProviderHeaders, resolveProvider, resolveUpstreamUrl } from './providers';
|
|
16
17
|
import { relayEventStream, withUsageStreamOptions } from './streaming';
|
|
17
18
|
import { providerName, transformChatRequest, transformChatResponse, transformEmbedRequest, transformEmbedResponse } from './transforms';
|
|
@@ -64,9 +65,12 @@ function upstreamErrorMessage(provider, status, body) {
|
|
|
64
65
|
const reason = parsed.length > UPSTREAM_REASON_LIMIT
|
|
65
66
|
? `${parsed.slice(0, UPSTREAM_REASON_LIMIT)}…`
|
|
66
67
|
: parsed;
|
|
67
|
-
|
|
68
|
+
const message = reason
|
|
68
69
|
? `${provider.type} provider error ${status}: ${reason}`
|
|
69
70
|
: `${provider.type} provider error ${status}`;
|
|
71
|
+
// 404 is how every dialect answers a model it does not serve, and a run
|
|
72
|
+
// configured with one fails on its first call: say where the served ones are.
|
|
73
|
+
return status === 404 ? `${message} — ${MODEL_LIST_HINT}` : message;
|
|
70
74
|
}
|
|
71
75
|
/**
|
|
72
76
|
* Who the call is for and which task it is a cost of. Identity comes from the
|
|
@@ -369,6 +373,22 @@ export const createRouter = (options) => {
|
|
|
369
373
|
}
|
|
370
374
|
res.status(202).json({ accepted: true });
|
|
371
375
|
});
|
|
376
|
+
// GET /v1/models — the models a caller can run: id and display name, nothing
|
|
377
|
+
// of the providers behind them. Asked for with the identity a run carries.
|
|
378
|
+
router.get('/v1/models', async (req, res) => {
|
|
379
|
+
if (!req.get('X-Database-Id')) {
|
|
380
|
+
res.status(400).json({ error: { message: 'X-Database-Id is required' } });
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
try {
|
|
384
|
+
res.json({ object: 'list', data: await listServedModels(options) });
|
|
385
|
+
}
|
|
386
|
+
catch (err) {
|
|
387
|
+
// The reason names a provider; it is the operator's to read, in the log.
|
|
388
|
+
log.error('models error', err);
|
|
389
|
+
res.status(502).json({ error: { message: 'the model list is unavailable' } });
|
|
390
|
+
}
|
|
391
|
+
});
|
|
372
392
|
// GET /v1/providers — list configured providers
|
|
373
393
|
router.get('/v1/providers', (_req, res) => {
|
|
374
394
|
const providers = options.providers || [{
|
|
@@ -383,18 +403,10 @@ export const createRouter = (options) => {
|
|
|
383
403
|
}))
|
|
384
404
|
});
|
|
385
405
|
});
|
|
386
|
-
// GET /healthz —
|
|
406
|
+
// GET /healthz — liveness only. It is unauthenticated, and whatever forwards
|
|
407
|
+
// to this gateway forwards here too, so it describes no provider.
|
|
387
408
|
router.get('/healthz', (_req, res) => {
|
|
388
|
-
|
|
389
|
-
type: options.providerType || 'ollama',
|
|
390
|
-
baseUrl: options.providerBaseUrl || 'http://localhost:11434'
|
|
391
|
-
}];
|
|
392
|
-
res.json({
|
|
393
|
-
status: 'ok',
|
|
394
|
-
provider: providers[0]?.type || 'ollama',
|
|
395
|
-
providerUrl: providers[0]?.baseUrl || options.providerBaseUrl,
|
|
396
|
-
providers: providers.map((p) => p.type)
|
|
397
|
-
});
|
|
409
|
+
res.json({ status: 'ok' });
|
|
398
410
|
});
|
|
399
411
|
return router;
|
|
400
412
|
};
|
package/esm/server.js
CHANGED
|
@@ -13,13 +13,15 @@ const IDENTITY_HEADERS = [
|
|
|
13
13
|
'x-attempt',
|
|
14
14
|
'x-run-id'
|
|
15
15
|
];
|
|
16
|
+
/** An image arrives inside the JSON body as base64, a third larger than its bytes. */
|
|
17
|
+
export const DEFAULT_BODY_LIMIT = '32mb';
|
|
16
18
|
/**
|
|
17
19
|
* Create a standalone Express app for the agentic server.
|
|
18
20
|
* Used by both standalone mode and integration tests.
|
|
19
21
|
*/
|
|
20
22
|
export const createAgenticServer = (options) => {
|
|
21
23
|
const app = express();
|
|
22
|
-
app.use(express.json());
|
|
24
|
+
app.use(express.json({ limit: options.bodyLimit ?? DEFAULT_BODY_LIMIT }));
|
|
23
25
|
// When isPublic === true, strip identity headers from all incoming requests.
|
|
24
26
|
// Public deployments cannot trust client-supplied tenant context.
|
|
25
27
|
// When isPublic === false (default), the server is on a private network
|
package/index.d.ts
CHANGED
|
@@ -22,6 +22,8 @@
|
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
24
|
export { BadRequestError } from './errors';
|
|
25
|
+
export type { ServedModel } from './models';
|
|
26
|
+
export { listServedModels, MODEL_LIST_HINT } from './models';
|
|
25
27
|
export { buildProviderHeaders, resolveProvider, resolveUpstreamUrl } from './providers';
|
|
26
28
|
export { createRouter } from './router';
|
|
27
29
|
export type { AgenticServerStartOptions } from './server';
|
package/index.js
CHANGED
|
@@ -23,9 +23,12 @@
|
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.upstreamModel = exports.transformEmbedResponse = exports.transformEmbedRequest = exports.transformChatResponse = exports.transformChatRequest = exports.providerName = exports.createAgenticServer = exports.createRouter = exports.resolveUpstreamUrl = exports.resolveProvider = exports.buildProviderHeaders = exports.BadRequestError = void 0;
|
|
26
|
+
exports.upstreamModel = exports.transformEmbedResponse = exports.transformEmbedRequest = exports.transformChatResponse = exports.transformChatRequest = exports.providerName = exports.createAgenticServer = exports.createRouter = exports.resolveUpstreamUrl = exports.resolveProvider = exports.buildProviderHeaders = exports.MODEL_LIST_HINT = exports.listServedModels = exports.BadRequestError = void 0;
|
|
27
27
|
var errors_1 = require("./errors");
|
|
28
28
|
Object.defineProperty(exports, "BadRequestError", { enumerable: true, get: function () { return errors_1.BadRequestError; } });
|
|
29
|
+
var models_1 = require("./models");
|
|
30
|
+
Object.defineProperty(exports, "listServedModels", { enumerable: true, get: function () { return models_1.listServedModels; } });
|
|
31
|
+
Object.defineProperty(exports, "MODEL_LIST_HINT", { enumerable: true, get: function () { return models_1.MODEL_LIST_HINT; } });
|
|
29
32
|
var providers_1 = require("./providers");
|
|
30
33
|
Object.defineProperty(exports, "buildProviderHeaders", { enumerable: true, get: function () { return providers_1.buildProviderHeaders; } });
|
|
31
34
|
Object.defineProperty(exports, "resolveProvider", { enumerable: true, get: function () { return providers_1.resolveProvider; } });
|
package/models.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AgenticServerOptions } from './types';
|
|
2
|
+
/** A model a caller can run: what to send as `model`, and what to show for it. */
|
|
3
|
+
export interface ServedModel {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
}
|
|
7
|
+
/** Appended to an upstream "no such model" answer, so the caller knows where to look. */
|
|
8
|
+
export declare const MODEL_LIST_HINT = "GET /v1/models lists the models this gateway serves";
|
|
9
|
+
/**
|
|
10
|
+
* Every model the gateway serves, under the id that reaches it: the bare
|
|
11
|
+
* upstream id when the router would send that, unchanged, to the provider serving it, the
|
|
12
|
+
* `name/` prefixed one otherwise. Only the id and a display name leave here —
|
|
13
|
+
* which provider serves a model, and where, is the deployment's business.
|
|
14
|
+
*/
|
|
15
|
+
export declare function listServedModels(options: AgenticServerOptions): Promise<ServedModel[]>;
|
package/models.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MODEL_LIST_HINT = void 0;
|
|
4
|
+
exports.listServedModels = listServedModels;
|
|
5
|
+
const providers_1 = require("./providers");
|
|
6
|
+
const transforms_1 = require("./transforms");
|
|
7
|
+
/** Appended to an upstream "no such model" answer, so the caller knows where to look. */
|
|
8
|
+
exports.MODEL_LIST_HINT = 'GET /v1/models lists the models this gateway serves';
|
|
9
|
+
const configuredProviders = (options) => options.providers && options.providers.length > 0
|
|
10
|
+
? options.providers
|
|
11
|
+
: [(0, providers_1.resolveProvider)(options)];
|
|
12
|
+
const text = (value) => typeof value === 'string' && value ? value : undefined;
|
|
13
|
+
const served = (row, idField) => {
|
|
14
|
+
const id = text(row[idField]);
|
|
15
|
+
return id ? [{ id, name: text(row.display_name) ?? id }] : [];
|
|
16
|
+
};
|
|
17
|
+
/** The models one provider serves, as its own listing names them. */
|
|
18
|
+
async function upstreamModels(provider) {
|
|
19
|
+
const listing = async (url) => {
|
|
20
|
+
const res = await fetch(url, { headers: (0, providers_1.buildProviderHeaders)(provider) });
|
|
21
|
+
if (!res.ok) {
|
|
22
|
+
throw new Error(`${(0, transforms_1.providerName)(provider)} answered ${res.status} to a model listing`);
|
|
23
|
+
}
|
|
24
|
+
return await res.json();
|
|
25
|
+
};
|
|
26
|
+
const rows = (list) => {
|
|
27
|
+
if (!Array.isArray(list)) {
|
|
28
|
+
throw new Error(`${(0, transforms_1.providerName)(provider)} answered a model listing with no list`);
|
|
29
|
+
}
|
|
30
|
+
return list;
|
|
31
|
+
};
|
|
32
|
+
if (provider.type === 'ollama') {
|
|
33
|
+
const body = await listing(`${provider.baseUrl}/api/tags`);
|
|
34
|
+
return rows(body.models).flatMap((row) => served(row, 'name'));
|
|
35
|
+
}
|
|
36
|
+
// A listing may be paged (Anthropic's is): follow it to the end, or the
|
|
37
|
+
// models on a later page read as not served.
|
|
38
|
+
const models = [];
|
|
39
|
+
let after;
|
|
40
|
+
do {
|
|
41
|
+
const page = after ? `?after_id=${encodeURIComponent(after)}` : '';
|
|
42
|
+
const body = await listing(`${provider.baseUrl}/v1/models${page}`);
|
|
43
|
+
models.push(...rows(body.data).flatMap((row) => served(row, 'id')));
|
|
44
|
+
const next = body.has_more === true ? text(body.last_id) : undefined;
|
|
45
|
+
if (next === after)
|
|
46
|
+
break;
|
|
47
|
+
after = next;
|
|
48
|
+
} while (after);
|
|
49
|
+
return models;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Every model the gateway serves, under the id that reaches it: the bare
|
|
53
|
+
* upstream id when the router would send that, unchanged, to the provider serving it, the
|
|
54
|
+
* `name/` prefixed one otherwise. Only the id and a display name leave here —
|
|
55
|
+
* which provider serves a model, and where, is the deployment's business.
|
|
56
|
+
*/
|
|
57
|
+
async function listServedModels(options) {
|
|
58
|
+
const providers = configuredProviders(options);
|
|
59
|
+
const lists = await Promise.all(providers.map(upstreamModels));
|
|
60
|
+
const seen = new Set();
|
|
61
|
+
return lists.flatMap((models, index) => {
|
|
62
|
+
const provider = providers[index];
|
|
63
|
+
return models.flatMap(({ id, name }) => {
|
|
64
|
+
const routed = (0, providers_1.resolveProvider)(options, id);
|
|
65
|
+
// Bare only when the id both routes here and survives the prefix strip:
|
|
66
|
+
// an upstream id that itself begins `openai/` would lose that segment.
|
|
67
|
+
const bare = (providers.length === 1 || (0, transforms_1.providerName)(routed) === (0, transforms_1.providerName)(provider)) &&
|
|
68
|
+
(0, transforms_1.upstreamModel)(provider, id) === id;
|
|
69
|
+
const served = bare ? id : `${(0, transforms_1.providerName)(provider)}/${id}`;
|
|
70
|
+
if (seen.has(served))
|
|
71
|
+
return [];
|
|
72
|
+
seen.add(served);
|
|
73
|
+
return [{ id: served, name }];
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agentic-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.0",
|
|
4
4
|
"description": "Standalone OpenAI-compatible LLM gateway — multi-provider proxy with pluggable inference metering",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "esm/index.js",
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"metering",
|
|
52
52
|
"constructive"
|
|
53
53
|
],
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "8cc2311b286b42c60815794773bc038fa1250643"
|
|
55
55
|
}
|
package/router.js
CHANGED
|
@@ -15,6 +15,7 @@ exports.createRouter = exports.readAttribution = void 0;
|
|
|
15
15
|
const logger_1 = require("@pgpmjs/logger");
|
|
16
16
|
const express_1 = require("express");
|
|
17
17
|
const errors_1 = require("./errors");
|
|
18
|
+
const models_1 = require("./models");
|
|
18
19
|
const providers_1 = require("./providers");
|
|
19
20
|
const streaming_1 = require("./streaming");
|
|
20
21
|
const transforms_1 = require("./transforms");
|
|
@@ -67,9 +68,12 @@ function upstreamErrorMessage(provider, status, body) {
|
|
|
67
68
|
const reason = parsed.length > UPSTREAM_REASON_LIMIT
|
|
68
69
|
? `${parsed.slice(0, UPSTREAM_REASON_LIMIT)}…`
|
|
69
70
|
: parsed;
|
|
70
|
-
|
|
71
|
+
const message = reason
|
|
71
72
|
? `${provider.type} provider error ${status}: ${reason}`
|
|
72
73
|
: `${provider.type} provider error ${status}`;
|
|
74
|
+
// 404 is how every dialect answers a model it does not serve, and a run
|
|
75
|
+
// configured with one fails on its first call: say where the served ones are.
|
|
76
|
+
return status === 404 ? `${message} — ${models_1.MODEL_LIST_HINT}` : message;
|
|
73
77
|
}
|
|
74
78
|
/**
|
|
75
79
|
* Who the call is for and which task it is a cost of. Identity comes from the
|
|
@@ -373,6 +377,22 @@ const createRouter = (options) => {
|
|
|
373
377
|
}
|
|
374
378
|
res.status(202).json({ accepted: true });
|
|
375
379
|
});
|
|
380
|
+
// GET /v1/models — the models a caller can run: id and display name, nothing
|
|
381
|
+
// of the providers behind them. Asked for with the identity a run carries.
|
|
382
|
+
router.get('/v1/models', async (req, res) => {
|
|
383
|
+
if (!req.get('X-Database-Id')) {
|
|
384
|
+
res.status(400).json({ error: { message: 'X-Database-Id is required' } });
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
try {
|
|
388
|
+
res.json({ object: 'list', data: await (0, models_1.listServedModels)(options) });
|
|
389
|
+
}
|
|
390
|
+
catch (err) {
|
|
391
|
+
// The reason names a provider; it is the operator's to read, in the log.
|
|
392
|
+
log.error('models error', err);
|
|
393
|
+
res.status(502).json({ error: { message: 'the model list is unavailable' } });
|
|
394
|
+
}
|
|
395
|
+
});
|
|
376
396
|
// GET /v1/providers — list configured providers
|
|
377
397
|
router.get('/v1/providers', (_req, res) => {
|
|
378
398
|
const providers = options.providers || [{
|
|
@@ -387,18 +407,10 @@ const createRouter = (options) => {
|
|
|
387
407
|
}))
|
|
388
408
|
});
|
|
389
409
|
});
|
|
390
|
-
// GET /healthz —
|
|
410
|
+
// GET /healthz — liveness only. It is unauthenticated, and whatever forwards
|
|
411
|
+
// to this gateway forwards here too, so it describes no provider.
|
|
391
412
|
router.get('/healthz', (_req, res) => {
|
|
392
|
-
|
|
393
|
-
type: options.providerType || 'ollama',
|
|
394
|
-
baseUrl: options.providerBaseUrl || 'http://localhost:11434'
|
|
395
|
-
}];
|
|
396
|
-
res.json({
|
|
397
|
-
status: 'ok',
|
|
398
|
-
provider: providers[0]?.type || 'ollama',
|
|
399
|
-
providerUrl: providers[0]?.baseUrl || options.providerBaseUrl,
|
|
400
|
-
providers: providers.map((p) => p.type)
|
|
401
|
-
});
|
|
413
|
+
res.json({ status: 'ok' });
|
|
402
414
|
});
|
|
403
415
|
return router;
|
|
404
416
|
};
|
package/server.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ import type { AgenticServerOptions } from './types';
|
|
|
3
3
|
export interface AgenticServerStartOptions extends AgenticServerOptions {
|
|
4
4
|
port?: number;
|
|
5
5
|
}
|
|
6
|
+
/** An image arrives inside the JSON body as base64, a third larger than its bytes. */
|
|
7
|
+
export declare const DEFAULT_BODY_LIMIT = "32mb";
|
|
6
8
|
/**
|
|
7
9
|
* Create a standalone Express app for the agentic server.
|
|
8
10
|
* Used by both standalone mode and integration tests.
|
package/server.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createAgenticServer = void 0;
|
|
6
|
+
exports.createAgenticServer = exports.DEFAULT_BODY_LIMIT = void 0;
|
|
7
7
|
const express_1 = __importDefault(require("express"));
|
|
8
8
|
const router_1 = require("./router");
|
|
9
9
|
/** Identity + task-correlation headers trusted only when isPublic === false
|
|
@@ -19,13 +19,15 @@ const IDENTITY_HEADERS = [
|
|
|
19
19
|
'x-attempt',
|
|
20
20
|
'x-run-id'
|
|
21
21
|
];
|
|
22
|
+
/** An image arrives inside the JSON body as base64, a third larger than its bytes. */
|
|
23
|
+
exports.DEFAULT_BODY_LIMIT = '32mb';
|
|
22
24
|
/**
|
|
23
25
|
* Create a standalone Express app for the agentic server.
|
|
24
26
|
* Used by both standalone mode and integration tests.
|
|
25
27
|
*/
|
|
26
28
|
const createAgenticServer = (options) => {
|
|
27
29
|
const app = (0, express_1.default)();
|
|
28
|
-
app.use(express_1.default.json());
|
|
30
|
+
app.use(express_1.default.json({ limit: options.bodyLimit ?? exports.DEFAULT_BODY_LIMIT }));
|
|
29
31
|
// When isPublic === true, strip identity headers from all incoming requests.
|
|
30
32
|
// Public deployments cannot trust client-supplied tenant context.
|
|
31
33
|
// When isPublic === false (default), the server is on a private network
|
package/types.d.ts
CHANGED
|
@@ -33,6 +33,11 @@ export interface AgenticServerOptions {
|
|
|
33
33
|
* When true, identity headers are stripped from incoming requests
|
|
34
34
|
* (external clients cannot set tenant context). */
|
|
35
35
|
isPublic?: boolean;
|
|
36
|
+
/** Largest JSON request body accepted, as express.json's `limit` (bytes, or
|
|
37
|
+
* a string such as '32mb'). A request carries an image as base64 — an embed
|
|
38
|
+
* input, a chat image part — so express's 100kb default refuses any real
|
|
39
|
+
* one with a 413. Default: '32mb'. */
|
|
40
|
+
bodyLimit?: number | string;
|
|
36
41
|
}
|
|
37
42
|
export interface ResolvedProvider {
|
|
38
43
|
name?: string;
|