optio-api 0.5.0 → 0.7.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/dist/adapters/fastify.d.ts +12 -0
- package/dist/adapters/fastify.d.ts.map +1 -1
- package/dist/adapters/fastify.js +215 -16
- package/dist/adapters/fastify.js.map +1 -1
- package/dist/chat-avatar.d.ts +54 -0
- package/dist/chat-avatar.d.ts.map +1 -0
- package/dist/chat-avatar.js +70 -0
- package/dist/chat-avatar.js.map +1 -0
- package/dist/chat-hub.d.ts +100 -0
- package/dist/chat-hub.d.ts.map +1 -0
- package/dist/chat-hub.js +174 -0
- package/dist/chat-hub.js.map +1 -0
- package/dist/conversation-archive.d.ts +3 -2
- package/dist/conversation-archive.d.ts.map +1 -1
- package/dist/conversation-archive.js +18 -2
- package/dist/conversation-archive.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/input-author.d.ts +59 -0
- package/dist/input-author.d.ts.map +1 -0
- package/dist/input-author.js +124 -0
- package/dist/input-author.js.map +1 -0
- package/dist/widget-proxy-core.d.ts +23 -0
- package/dist/widget-proxy-core.d.ts.map +1 -1
- package/dist/widget-proxy-core.js +33 -0
- package/dist/widget-proxy-core.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-avatar.js","sourceRoot":"","sources":["../src/chat-avatar.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C;;;;;;;;;;;;;;;GAeG;AAEH,MAAM,CAAC,MAAM,yBAAyB,GAAG,eAAe,CAAC;AACzD,MAAM,CAAC,MAAM,4BAA4B,GAAG,OAAO,CAAC;AACpD,MAAM,CAAC,MAAM,sBAAsB,GAAG,gBAAgB,CAAC;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,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;IAC/G,IAAI,IAAI,GAAG,IAAI,CAAC;IAChB,KAAK,MAAM,EAAE,IAAI,OAAO,EAAE,CAAC;QACzB,IAAI,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QAC3D,IAAI,IAAI;YAAE,MAAM;IAClB,CAAC;IACD,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,kBAAkB,EAAE,EAAE,CAAC;IAC5F,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC;IACxB,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,EAAE,WAAW,CAAC;IAC1C,OAAO;QACL,MAAM,EAAE,GAAG;QACX,OAAO,EAAE;YACP,cAAc,EAAE,OAAO,MAAM,KAAK,QAAQ,IAAI,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,0BAA0B;YAC5G,gBAAgB,EAAE,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;YACrC,eAAe,EAAE,sCAAsC;YACvD,wBAAwB,EAAE,SAAS;SACpC;QACD,IAAI,EAAE,MAAM,CAAC,kBAAkB,CAAC,MAAM,CAAC;KACxC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { IncomingMessage } from 'node:http';
|
|
2
|
+
import type { Db } from 'mongodb';
|
|
3
|
+
import { type DbOptions } from './resolve.js';
|
|
4
|
+
/**
|
|
5
|
+
* The proxy side of a shared chat hub (spec docs/2026-11-24-agent-chat-design.md
|
|
6
|
+
* §6). An engine with `OPTIO_CHAT_SHARED_PASSWORD` set opens a WebSocket
|
|
7
|
+
* listener for its MQTT hub and publishes `{ _id: 'chatHub', url:
|
|
8
|
+
* 'ws://host:port/', updatedAt }` in `{prefix}_engine_endpoints`
|
|
9
|
+
* (optio_chat/wire.py `ENGINE_ENDPOINT_ID`). optio-api tunnels
|
|
10
|
+
* `/api/chat/<database>/<prefix>` (optio_chat/wire.py `tunnel_path`) to it,
|
|
11
|
+
* so other servers reach the hub through the app's own domain and TLS.
|
|
12
|
+
*
|
|
13
|
+
* The tunnel is not behind the app's login: its callers are engines and CLIs,
|
|
14
|
+
* and the MQTT password inside the stream is its only gate (owner's decision,
|
|
15
|
+
* spec §6). The exemption covers WebSocket upgrades of exactly that path shape
|
|
16
|
+
* (`isChatTunnelUpgrade`), nothing else. Since anyone can reach it, what one
|
|
17
|
+
* caller can cost is bounded: names optio does not use are refused before
|
|
18
|
+
* MongoDB is read (`chatTunnelRouting`), lookups are cached, absences too
|
|
19
|
+
* (`resolveChatHub`), and the open connections of a process are capped
|
|
20
|
+
* (`chatTunnelSlots`).
|
|
21
|
+
*/
|
|
22
|
+
export declare const CHAT_HUB_ENDPOINT_ID = "chatHub";
|
|
23
|
+
/**
|
|
24
|
+
* How long a resolved hub address is reused before MongoDB is read again: a
|
|
25
|
+
* hub that moved (an engine restarted on another port) is followed within
|
|
26
|
+
* this time. The lookup is one findOne by `_id` per connection otherwise.
|
|
27
|
+
*/
|
|
28
|
+
export declare const CHAT_HUB_CACHE_TTL_MS = 2000;
|
|
29
|
+
/**
|
|
30
|
+
* How long an absence (no hub shared, or a document that is no hub address) is
|
|
31
|
+
* remembered: a caller retrying a pair without a hub costs one MongoDB read
|
|
32
|
+
* per this time, and a hub just shared is found this much later at most.
|
|
33
|
+
*/
|
|
34
|
+
export declare const CHAT_HUB_ABSENT_TTL_MS = 1000;
|
|
35
|
+
/**
|
|
36
|
+
* The published hub address of `(db, prefix)`, or null when no engine shares
|
|
37
|
+
* its hub there (no document, a malformed one, or a url that is not ws: or
|
|
38
|
+
* wss:). A found address is cached for `CHAT_HUB_CACHE_TTL_MS` (2 s), an
|
|
39
|
+
* absence for `CHAT_HUB_ABSENT_TTL_MS` (1 s). A failed lookup throws and is
|
|
40
|
+
* not cached.
|
|
41
|
+
*/
|
|
42
|
+
export declare function resolveChatHub(db: Db, prefix: string): Promise<string | null>;
|
|
43
|
+
/**
|
|
44
|
+
* The database and prefix a chat route (the tunnel, the avatars) serves, or
|
|
45
|
+
* null when it serves none: `resolveDb` refuses (multi-database mode without a
|
|
46
|
+
* database), or, in single-database mode, the URL names a database other than
|
|
47
|
+
* the one the options hold (`resolveDb` would serve that one whatever the URL
|
|
48
|
+
* names).
|
|
49
|
+
*/
|
|
50
|
+
export declare function resolveChatDb(dbOpts: DbOptions, query: {
|
|
51
|
+
database?: string;
|
|
52
|
+
prefix?: string;
|
|
53
|
+
}): {
|
|
54
|
+
db: Db;
|
|
55
|
+
prefix: string;
|
|
56
|
+
} | null;
|
|
57
|
+
/** Where the tunnel route lives; `@fastify/http-proxy` is registered on this prefix. */
|
|
58
|
+
export declare const CHAT_TUNNEL_PREFIX = "/api/chat";
|
|
59
|
+
/**
|
|
60
|
+
* A database or prefix the tunnel serves (once url-decoded): letters, digits,
|
|
61
|
+
* `_` and `-`, at most 63 (MongoDB's limit for a database name). optio's own
|
|
62
|
+
* names fit (`optio-demo-chat-a`, `optio`); anything else (a `/`, `\`, `.`,
|
|
63
|
+
* `$`, a NUL, a space) is refused before MongoDB sees it.
|
|
64
|
+
*/
|
|
65
|
+
export declare const CHAT_TUNNEL_NAME: RegExp;
|
|
66
|
+
/**
|
|
67
|
+
* The database and prefix a tunnel URL names, or null for any other path
|
|
68
|
+
* shape and for a name outside `CHAT_TUNNEL_NAME`.
|
|
69
|
+
*/
|
|
70
|
+
export declare function chatTunnelRouting(url: string): {
|
|
71
|
+
database: string;
|
|
72
|
+
prefix: string;
|
|
73
|
+
} | null;
|
|
74
|
+
/**
|
|
75
|
+
* True for the one request the app's login does not cover: a WebSocket upgrade
|
|
76
|
+
* (Node handed it over as an upgrade: `upgrade` is set only then, never for a
|
|
77
|
+
* plain request carrying upgrade headers) of the tunnel path's shape. The
|
|
78
|
+
* shape alone: a name optio does not use is answered 404 by the route
|
|
79
|
+
* (`chatTunnelRouting`), to every caller alike.
|
|
80
|
+
*/
|
|
81
|
+
export declare function isChatTunnelUpgrade(raw: IncomingMessage): boolean;
|
|
82
|
+
/**
|
|
83
|
+
* How many tunnel connections one process keeps open at once. An upgrade over
|
|
84
|
+
* it is refused (503) before the hub is dialled: each connection holds two
|
|
85
|
+
* sockets and is open to callers without the app's login.
|
|
86
|
+
*/
|
|
87
|
+
export declare const CHAT_TUNNEL_MAX_CONNECTIONS = 256;
|
|
88
|
+
/** A counter of open tunnel connections, bounded by `max`. */
|
|
89
|
+
export declare class ChatTunnelSlots {
|
|
90
|
+
readonly max: number;
|
|
91
|
+
active: number;
|
|
92
|
+
constructor(max: number);
|
|
93
|
+
/** Takes a slot; false (nothing taken) when all are taken. */
|
|
94
|
+
tryAcquire(): boolean;
|
|
95
|
+
/** Frees a slot taken with `tryAcquire`. */
|
|
96
|
+
release(): void;
|
|
97
|
+
}
|
|
98
|
+
/** The process's tunnel connections (the Fastify adapter takes one per proxied upgrade). */
|
|
99
|
+
export declare const chatTunnelSlots: ChatTunnelSlots;
|
|
100
|
+
//# sourceMappingURL=chat-hub.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-hub.d.ts","sourceRoot":"","sources":["../src/chat-hub.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,KAAK,EAAE,EAAE,EAAe,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAa,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzD;;;;;;;;;;;;;;;;;GAiBG;AAEH,eAAO,MAAM,oBAAoB,YAAY,CAAC;AAC9C;;;;GAIG;AACH,eAAO,MAAM,q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y side of a shared chat hub (spec docs/2026-11-24-agent-chat-design.md
|
|
4
|
+
* §6). An engine with `OPTIO_CHAT_SHARED_PASSWORD` set opens a WebSocket
|
|
5
|
+
* listener for its MQTT hub and publishes `{ _id: 'chatHub', url:
|
|
6
|
+
* 'ws://host:port/', updatedAt }` in `{prefix}_engine_endpoints`
|
|
7
|
+
* (optio_chat/wire.py `ENGINE_ENDPOINT_ID`). optio-api tunnels
|
|
8
|
+
* `/api/chat/<database>/<prefix>` (optio_chat/wire.py `tunnel_path`) to it,
|
|
9
|
+
* so other servers reach the hub through the app's own domain and TLS.
|
|
10
|
+
*
|
|
11
|
+
* The tunnel is not behind the app's login: its callers are engines and CLIs,
|
|
12
|
+
* and the MQTT password inside the stream is its only gate (owner's decision,
|
|
13
|
+
* spec §6). The exemption covers WebSocket upgrades of exactly that path shape
|
|
14
|
+
* (`isChatTunnelUpgrade`), nothing else. Since anyone can reach it, what one
|
|
15
|
+
* caller can cost is bounded: names optio does not use are refused before
|
|
16
|
+
* MongoDB is read (`chatTunnelRouting`), lookups are cached, absences too
|
|
17
|
+
* (`resolveChatHub`), and the open connections of a process are capped
|
|
18
|
+
* (`chatTunnelSlots`).
|
|
19
|
+
*/
|
|
20
|
+
export const CHAT_HUB_ENDPOINT_ID = 'chatHub';
|
|
21
|
+
/**
|
|
22
|
+
* How long a resolved hub address is reused before MongoDB is read again: a
|
|
23
|
+
* hub that moved (an engine restarted on another port) is followed within
|
|
24
|
+
* this time. The lookup is one findOne by `_id` per connection otherwise.
|
|
25
|
+
*/
|
|
26
|
+
export const CHAT_HUB_CACHE_TTL_MS = 2_000;
|
|
27
|
+
/**
|
|
28
|
+
* How long an absence (no hub shared, or a document that is no hub address) is
|
|
29
|
+
* remembered: a caller retrying a pair without a hub costs one MongoDB read
|
|
30
|
+
* per this time, and a hub just shared is found this much later at most.
|
|
31
|
+
*/
|
|
32
|
+
export const CHAT_HUB_ABSENT_TTL_MS = 1_000;
|
|
33
|
+
// Per MongoClient, then per database name and prefix (as the conversation
|
|
34
|
+
// archive's cache): two clusters that both have a database `x` never share an entry.
|
|
35
|
+
const cache = new WeakMap();
|
|
36
|
+
function entries(db) {
|
|
37
|
+
let map = cache.get(db.client);
|
|
38
|
+
if (!map) {
|
|
39
|
+
map = new Map();
|
|
40
|
+
cache.set(db.client, map);
|
|
41
|
+
}
|
|
42
|
+
return map;
|
|
43
|
+
}
|
|
44
|
+
const keyOf = (db, prefix) => `${db.databaseName}\u0000${prefix}`;
|
|
45
|
+
/** Only an absolute ws: or wss: URL is a hub address. */
|
|
46
|
+
function isWsUrl(url) {
|
|
47
|
+
try {
|
|
48
|
+
const { protocol } = new URL(url);
|
|
49
|
+
return protocol === 'ws:' || protocol === 'wss:';
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The published hub address of `(db, prefix)`, or null when no engine shares
|
|
57
|
+
* its hub there (no document, a malformed one, or a url that is not ws: or
|
|
58
|
+
* wss:). A found address is cached for `CHAT_HUB_CACHE_TTL_MS` (2 s), an
|
|
59
|
+
* absence for `CHAT_HUB_ABSENT_TTL_MS` (1 s). A failed lookup throws and is
|
|
60
|
+
* not cached.
|
|
61
|
+
*/
|
|
62
|
+
export async function resolveChatHub(db, prefix) {
|
|
63
|
+
const map = entries(db);
|
|
64
|
+
const key = keyOf(db, prefix);
|
|
65
|
+
const cached = map.get(key);
|
|
66
|
+
if (cached && Date.now() < cached.expiresAt)
|
|
67
|
+
return cached.url;
|
|
68
|
+
if (cached)
|
|
69
|
+
map.delete(key);
|
|
70
|
+
const doc = await db
|
|
71
|
+
.collection(`${prefix}_engine_endpoints`)
|
|
72
|
+
.findOne({ _id: CHAT_HUB_ENDPOINT_ID }, { projection: { url: 1 } });
|
|
73
|
+
const url = doc && typeof doc.url === 'string' && isWsUrl(doc.url) ? doc.url : null;
|
|
74
|
+
const ttl = url === null ? CHAT_HUB_ABSENT_TTL_MS : CHAT_HUB_CACHE_TTL_MS;
|
|
75
|
+
map.set(key, { url, expiresAt: Date.now() + ttl });
|
|
76
|
+
return url;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The database and prefix a chat route (the tunnel, the avatars) serves, or
|
|
80
|
+
* null when it serves none: `resolveDb` refuses (multi-database mode without a
|
|
81
|
+
* database), or, in single-database mode, the URL names a database other than
|
|
82
|
+
* the one the options hold (`resolveDb` would serve that one whatever the URL
|
|
83
|
+
* names).
|
|
84
|
+
*/
|
|
85
|
+
export function resolveChatDb(dbOpts, query) {
|
|
86
|
+
let resolved;
|
|
87
|
+
try {
|
|
88
|
+
resolved = resolveDb(dbOpts, query);
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
if (query.database !== undefined && resolved.database !== query.database)
|
|
94
|
+
return null;
|
|
95
|
+
return { db: resolved.db, prefix: resolved.prefix };
|
|
96
|
+
}
|
|
97
|
+
/** Where the tunnel route lives; `@fastify/http-proxy` is registered on this prefix. */
|
|
98
|
+
export const CHAT_TUNNEL_PREFIX = '/api/chat';
|
|
99
|
+
// Exactly /api/chat/<database>/<prefix>: two non-empty segments, nothing after
|
|
100
|
+
// them but an optional query string (never forwarded).
|
|
101
|
+
const CHAT_TUNNEL_PATH = /^\/api\/chat\/([^/?#]+)\/([^/?#]+)(?:\?.*)?$/;
|
|
102
|
+
/**
|
|
103
|
+
* A database or prefix the tunnel serves (once url-decoded): letters, digits,
|
|
104
|
+
* `_` and `-`, at most 63 (MongoDB's limit for a database name). optio's own
|
|
105
|
+
* names fit (`optio-demo-chat-a`, `optio`); anything else (a `/`, `\`, `.`,
|
|
106
|
+
* `$`, a NUL, a space) is refused before MongoDB sees it.
|
|
107
|
+
*/
|
|
108
|
+
export const CHAT_TUNNEL_NAME = /^[A-Za-z0-9_-]{1,63}$/;
|
|
109
|
+
/**
|
|
110
|
+
* The database and prefix a tunnel URL names, or null for any other path
|
|
111
|
+
* shape and for a name outside `CHAT_TUNNEL_NAME`.
|
|
112
|
+
*/
|
|
113
|
+
export function chatTunnelRouting(url) {
|
|
114
|
+
const m = CHAT_TUNNEL_PATH.exec(url);
|
|
115
|
+
if (!m)
|
|
116
|
+
return null;
|
|
117
|
+
let database;
|
|
118
|
+
let prefix;
|
|
119
|
+
try {
|
|
120
|
+
database = decodeURIComponent(m[1]);
|
|
121
|
+
prefix = decodeURIComponent(m[2]);
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
if (!CHAT_TUNNEL_NAME.test(database) || !CHAT_TUNNEL_NAME.test(prefix))
|
|
127
|
+
return null;
|
|
128
|
+
return { database, prefix };
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* True for the one request the app's login does not cover: a WebSocket upgrade
|
|
132
|
+
* (Node handed it over as an upgrade: `upgrade` is set only then, never for a
|
|
133
|
+
* plain request carrying upgrade headers) of the tunnel path's shape. The
|
|
134
|
+
* shape alone: a name optio does not use is answered 404 by the route
|
|
135
|
+
* (`chatTunnelRouting`), to every caller alike.
|
|
136
|
+
*/
|
|
137
|
+
export function isChatTunnelUpgrade(raw) {
|
|
138
|
+
return (
|
|
139
|
+
// Node sets `upgrade` on the request it hands to an upgrade listener; @types/node does
|
|
140
|
+
// not declare it.
|
|
141
|
+
raw.upgrade === true
|
|
142
|
+
&& raw.method === 'GET'
|
|
143
|
+
&& String(raw.headers.upgrade ?? '').toLowerCase() === 'websocket'
|
|
144
|
+
&& CHAT_TUNNEL_PATH.test(raw.url ?? ''));
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* How many tunnel connections one process keeps open at once. An upgrade over
|
|
148
|
+
* it is refused (503) before the hub is dialled: each connection holds two
|
|
149
|
+
* sockets and is open to callers without the app's login.
|
|
150
|
+
*/
|
|
151
|
+
export const CHAT_TUNNEL_MAX_CONNECTIONS = 256;
|
|
152
|
+
/** A counter of open tunnel connections, bounded by `max`. */
|
|
153
|
+
export class ChatTunnelSlots {
|
|
154
|
+
max;
|
|
155
|
+
active = 0;
|
|
156
|
+
constructor(max) {
|
|
157
|
+
this.max = max;
|
|
158
|
+
}
|
|
159
|
+
/** Takes a slot; false (nothing taken) when all are taken. */
|
|
160
|
+
tryAcquire() {
|
|
161
|
+
if (this.active >= this.max)
|
|
162
|
+
return false;
|
|
163
|
+
this.active += 1;
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
/** Frees a slot taken with `tryAcquire`. */
|
|
167
|
+
release() {
|
|
168
|
+
if (this.active > 0)
|
|
169
|
+
this.active -= 1;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/** The process's tunnel connections (the Fastify adapter takes one per proxied upgrade). */
|
|
173
|
+
export const chatTunnelSlots = new ChatTunnelSlots(CHAT_TUNNEL_MAX_CONNECTIONS);
|
|
174
|
+
//# sourceMappingURL=chat-hub.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-hub.js","sourceRoot":"","sources":["../src/chat-hub.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAkB,MAAM,cAAc,CAAC;AAEzD;;;;;;;;;;;;;;;;;GAiBG;AAEH,MAAM,CAAC,MAAM,oBAAoB,GAAG,SAAS,CAAC;AAC9C;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,CAAC;AAC3C;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,KAAK,CAAC;AAO5C,0EAA0E;AAC1E,qFAAqF;AACrF,MAAM,KAAK,GAAG,IAAI,OAAO,EAAwC,CAAC;AAElE,SAAS,OAAO,CAAC,EAAM;IACrB,IAAI,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;IAC/B,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,GAAG,GAAG,IAAI,GAAG,EAAE,CAAC;QAChB,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,GAAG,CAAC;YAAE,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC;IACxC,CAAC;CACF;AAED,4FAA4F;AAC5F,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,eAAe,CAAC,2BAA2B,CAAC,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Db } from 'mongodb';
|
|
2
|
-
import type
|
|
2
|
+
import { type ConversationFailureReason, type ConversationRecord } from 'optio-contracts';
|
|
3
3
|
/**
|
|
4
4
|
* The proxy side of the engine's conversation archive (optio-core
|
|
5
5
|
* `conversation_archive.py`): one aiohttp listener per engine that serves a
|
|
@@ -61,7 +61,8 @@ export declare function forgetConversationArchive(db: Db, prefix: string, endpoi
|
|
|
61
61
|
* Ask the archive for the record of process `processObjectId` (the process
|
|
62
62
|
* document's `_id`, 24 hex; anything else is 404 `not-found` with no MongoDB
|
|
63
63
|
* read and no upstream call, as the engine would answer it). The archive's
|
|
64
|
-
* 200 / 404 / 409 / 500 answers pass through as they are
|
|
64
|
+
* 200 / 404 / 409 / 500 answers pass through as they are (a 200's
|
|
65
|
+
* `pendingChat` only when valid, else left out: `relayedRecord`). Everything else is
|
|
65
66
|
* 503 `engine-unavailable` and drops the cached address, so the next request
|
|
66
67
|
* reads MongoDB again: no published address, a connection failure, no
|
|
67
68
|
* complete answer within `timeoutMs`, a body over `maxBodyBytes` (default
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversation-archive.d.ts","sourceRoot":"","sources":["../src/conversation-archive.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAe,MAAM,SAAS,CAAC;AAC/C,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"conversation-archive.d.ts","sourceRoot":"","sources":["../src/conversation-archive.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAe,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAqB,KAAK,yBAAyB,EAAE,KAAK,kBAAkB,EAA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-1,3 +1,4 @@
|
|
|
1
|
+
import { PendingChatSchema } from 'optio-contracts';
|
|
1
2
|
/**
|
|
2
3
|
* The proxy side of the engine's conversation archive (optio-core
|
|
3
4
|
* `conversation_archive.py`): one aiohttp listener per engine that serves a
|
|
@@ -105,6 +106,20 @@ function isRecord(body) {
|
|
|
105
106
|
return typeof body === 'object' && body !== null && Array.isArray(body.events)
|
|
106
107
|
&& (body.capturedAt === null || typeof body.capturedAt === 'string');
|
|
107
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* The record as relayed: `events` and `capturedAt`, plus the archive's
|
|
111
|
+
* `pendingChat` (agent chat: the messages waiting for the suspended agent)
|
|
112
|
+
* unchanged when it is a list of such messages (the contract's
|
|
113
|
+
* `PendingChatSchema`). An invalid one is left out rather than failing the
|
|
114
|
+
* answer: the record itself is still good, and the view reads a missing list
|
|
115
|
+
* as none, as from an older engine.
|
|
116
|
+
*/
|
|
117
|
+
function relayedRecord(body) {
|
|
118
|
+
const record = { events: body.events, capturedAt: body.capturedAt };
|
|
119
|
+
if (PendingChatSchema.safeParse(body.pendingChat).success)
|
|
120
|
+
record.pendingChat = body.pendingChat;
|
|
121
|
+
return record;
|
|
122
|
+
}
|
|
108
123
|
class BodyTooLarge extends Error {
|
|
109
124
|
}
|
|
110
125
|
/** The body as text, or BodyTooLarge past `max` bytes (declared or read). */
|
|
@@ -140,7 +155,8 @@ function noSuchProcess() {
|
|
|
140
155
|
* Ask the archive for the record of process `processObjectId` (the process
|
|
141
156
|
* document's `_id`, 24 hex; anything else is 404 `not-found` with no MongoDB
|
|
142
157
|
* read and no upstream call, as the engine would answer it). The archive's
|
|
143
|
-
* 200 / 404 / 409 / 500 answers pass through as they are
|
|
158
|
+
* 200 / 404 / 409 / 500 answers pass through as they are (a 200's
|
|
159
|
+
* `pendingChat` only when valid, else left out: `relayedRecord`). Everything else is
|
|
144
160
|
* 503 `engine-unavailable` and drops the cached address, so the next request
|
|
145
161
|
* reads MongoDB again: no published address, a connection failure, no
|
|
146
162
|
* complete answer within `timeoutMs`, a body over `maxBodyBytes` (default
|
|
@@ -185,7 +201,7 @@ export async function fetchConversation(db, prefix, processObjectId, opts = {})
|
|
|
185
201
|
body = undefined;
|
|
186
202
|
}
|
|
187
203
|
if (status === 200 && isRecord(body)) {
|
|
188
|
-
return { status: 200, body:
|
|
204
|
+
return { status: 200, body: relayedRecord(body) };
|
|
189
205
|
}
|
|
190
206
|
if ((status === 404 || status === 409 || status === 500) && isErrorBody(body)) {
|
|
191
207
|
return { status, body: { reason: body.reason, message: body.message } };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversation-archive.js","sourceRoot":"","sources":["../src/conversation-archive.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"conversation-archive.js","sourceRoot":"","sources":["../src/conversation-archive.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAA2D,MAAM,iBAAiB,CAAC;AAE7G;;;;;;;;;;;;;;GAcG;AAEH,MAAM,CAAC,MAAM,gCAAgC,GAAG,qBAAqB,CAAC;AACtE,2EAA2E;AAC3E,MAAM,CAAC,MAAM,iCAAiC,GAAG,MAAM,CAAC;AACxD,uFAAuF;AACvF,MAAM,CAAC,MAAM,+BAA+B,GAAG,MAAM,CAAC;AACtD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,mCAAmC,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAmBpE,+EAA+E;AAC/E,2EAA2E;AAC3E,MAAM,KAAK,GAAG,IAAI,OAAO,EAAwC,CAAC;AAElE,SAAS,OAAO,CAAC,EAAM;IACrB,IAAI,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;IAC/B,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,GAAG,GAAG,IAAI,GAAG,EAAE,CAAC;QAChB,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IA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CAAC;QACH,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IAAC,MAAM,CAAC;QACP,IAAI,GAAG,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,MAAM,KAAK,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QACrC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC;IACpD,CAAC;IACD,IAAI,CAAC,MAAM,KAAK,GAAG,IAAI,MAAM,KAAK,GAAG,IAAI,MAAM,KAAK,GAAG,CAAC,IAAI,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9E,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC;IAC1E,CAAC;IACD,yBAAyB,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;IAChD,OAAO,WAAW,CAAC,MAAM,KAAK,GAAG,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC;AAC3E,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ export { normalizeVisibility, visibilityToMongo, andVisibility, isVisible, prune
|
|
|
8
8
|
export { processCollection, processReads, processReadsOf, type ProcessReads, } from './process-reads.js';
|
|
9
9
|
export { and, or, not, leaf, eq, ne, isIn, notIn, exists, gt, gte, lt, lte } from 'optio-contracts';
|
|
10
10
|
export { createListPoller, createTreePoller, createMultiTreePoller, createSessionEventsPoller, type StreamPollerOptions, type TreePollerOptions, type MultiTreePollerOptions, type MultiTreeRoot, type SessionEventsPollerOptions, type ListPollerHandle, } from './stream-poller.js';
|
|
11
|
+
export { INPUT_AUTHOR_HEADER, encodeInputAuthor, parseInputAuthor, type InputAuthor, type InputAuthorCallback, } from './input-author.js';
|
|
12
|
+
export { isChatTunnelUpgrade } from './chat-hub.js';
|
|
11
13
|
export { discoverInstances } from './discovery.js';
|
|
12
14
|
export { resolveDb, resolveOptioEngine, type DbOptions, type SingleDbOptions, type MultiDbOptions } from './resolve.js';
|
|
13
15
|
export { parseMetadataFilterQuery, metadataFilterToMongo, detectLegacyMetadataParams, formatLegacyMetadataMessage, type ParseResult, } from './metadata-filter-query.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,aAAa,EACb,UAAU,EACV,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,sBAAsB,EACtB,mBAAmB,EACnB,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,KAAK,SAAS,EACd,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,sBAAsB,EAC3B,KAAK,mBAAmB,EACxB,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,oBAAoB,GAC1B,MAAM,eAAe,CAAC;AAGvB,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,sBAAsB,EACtB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,GACvB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EACL,0BAA0B,EAC1B,yBAAyB,EACzB,iBAAiB,EACjB,iCAAiC,EACjC,+BAA+B,EAC/B,mCAAmC,EACnC,KAAK,2BAA2B,EAChC,KAAK,uBAAuB,GAC7B,MAAM,2BAA2B,CAAC;AAInC,OAAO,EACL,SAAS,EACT,SAAS,EACT,aAAa,EACb,cAAc,EACd,WAAW,EACX,YAAY,EACZ,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,K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AM,uBAAuB,CAAC;AACpF,OAAO,EAAE,kBAAkB,EAAE,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -18,6 +18,13 @@ export { processCollection, processReads, processReadsOf, } from './process-read
|
|
|
18
18
|
export { and, or, not, leaf, eq, ne, isIn, notIn, exists, gt, gte, lt, lte } from 'optio-contracts';
|
|
19
19
|
// Stream poller (for custom adapters)
|
|
20
20
|
export { createListPoller, createTreePoller, createMultiTreePoller, createSessionEventsPoller, } from './stream-poller.js';
|
|
21
|
+
// Message authors: the app stamp of an input (the widget proxy's X-Optio-Author
|
|
22
|
+
// header, set from the inputAuthor hook; for custom adapters)
|
|
23
|
+
export { INPUT_AUTHOR_HEADER, encodeInputAuthor, parseInputAuthor, } from './input-author.js';
|
|
24
|
+
// Agent chat: the one request the app's login does not cover (the tunnel to a
|
|
25
|
+
// shared chat hub), for a host whose own login hook runs before optio's
|
|
26
|
+
// (see AGENTS.md "Agent chat routes")
|
|
27
|
+
export { isChatTunnelUpgrade } from './chat-hub.js';
|
|
21
28
|
// Multi-db discovery
|
|
22
29
|
export { discoverInstances } from './discovery.js';
|
|
23
30
|
export { resolveDb, resolveOptioEngine } from './resolve.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,OAAO,EACL,aAAa,EACb,UAAU,EACV,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,sBAAsB,EACtB,mBAAmB,EACnB,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,eAAe,GAahB,MAAM,eAAe,CAAC;AAEvB,qDAAqD;AACrD,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,sBAAsB,GAGvB,MAAM,sBAAsB,CAAC;AAE9B,sFAAsF;AACtF,OAAO,EACL,0BAA0B,EAC1B,yBAAy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C;AACpC,yEAAyE;AACzE,2EAA2E;AAC3E,2EAA2E;AAC3E,+CAA+C;AAC/C,wEAAwE;AACxE,wFAAwF;AACxF,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAwB,MAAM,uBAAuB,CAAC;AACpF,OAAO,EAAE,kBAAkB,EAAqB,MAAM,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,OAAO,EACL,aAAa,EACb,UAAU,EACV,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,sBAAsB,EACtB,mBAAmB,EACnB,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,eAAe,GAahB,MAAM,eAAe,CAAC;AAEvB,qDAAqD;AACrD,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,sBAAsB,GAGvB,MAAM,sBAAsB,CAAC;AAE9B,sFAAsF;AACtF,OAAO,EACL,0BAA0B,EAC1B,yBAAyB,EACzB,iBAAiB,EACjB,iCAAiC,EACjC,+BAA+B,EAC/B,mCAAmC,GAGpC,MAAM,2BAA2B,CAAC;AAEnC,8EAA8E;AAC9E,4DAA4D;AAC5D,OAAO,EACL,SAAS,EACT,SAAS,EACT,aAAa,EACb,cAAc,EACd,WAAW,EACX,YAAY,GAgBb,MAAM,WAAW,CAAC;AACnB,sCAAsC;AACtC,OAAO,EACL,QAAQ,EACR,YAAY,EACZ,OAAO,EACP,iBAAiB,EACjB,mBAAmB,EACnB,WAAW,EACX,gBAAgB,EAChB,aAAa,EACb,kBAAkB,EAClB,YAAY,GAGb,MAAM,mBAAmB,CAAC;AAI3B,2CAA2C;AAC3C,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,aAAa,EACb,SAAS,EACT,YAAY,GACb,MAAM,iBAAiB,CAAC;AAEzB,4EAA4E;AAC5E,qBAAqB;AACr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+
* `docs/2026-11-24-message-authors-design.md`, section 3).
|
|
4
|
+
*
|
|
5
|
+
* The host app's server, never the browser, says which of its users wrote an
|
|
6
|
+
* input: optio-api's widget proxy calls the `inputAuthor` hook for every proxied
|
|
7
|
+
* request with a body method (POST, PUT, PATCH) the gate admitted, and sets
|
|
8
|
+
* `X-Optio-Author: <value>` on the upstream request; it removes any
|
|
9
|
+
* `X-Optio-Author` the client sent from every request it forwards (HTTP and
|
|
10
|
+
* WebSocket), hook set or not. The agent's conversation listener reads the
|
|
11
|
+
* header (optio-agents' `parse_author_header`) and stamps the input as an
|
|
12
|
+
* `app` author. The header carries only the `app` author: its JSON has no `ns`.
|
|
13
|
+
*
|
|
14
|
+
* The value: base64url (RFC 4648 section 5, no padding; padding tolerated on
|
|
15
|
+
* read) of the UTF-8 JSON `{"id":<id>,"label":<label>}`, keys in that order,
|
|
16
|
+
* `label` left out when absent, no other key. Examples:
|
|
17
|
+
* - `{ id: 'u1', label: 'Ann' }` -> `eyJpZCI6InUxIiwibGFiZWwiOiJBbm4ifQ`
|
|
18
|
+
* - `{ id: '65a1f0c2e4b0a1b2c3d4e5f6', label: 'Ági Kovács' }` ->
|
|
19
|
+
* `eyJpZCI6IjY1YTFmMGMyZTRiMGExYjJjM2Q0ZTVmNiIsImxhYmVsIjoiw4FnaSBLb3bDoWNzIn0`
|
|
20
|
+
*
|
|
21
|
+
* Exported from `optio-api`, so a custom adapter can do the same.
|
|
22
|
+
*/
|
|
23
|
+
/** The header the widget proxy sets on the upstream request (lower case, as Node keys headers). */
|
|
24
|
+
export declare const INPUT_AUTHOR_HEADER = "x-optio-author";
|
|
25
|
+
/**
|
|
26
|
+
* A host-app user who wrote in the conversation view. `id`: the app's user id
|
|
27
|
+
* (opaque to optio), 1-128 Unicode code points; `label`: their display name at
|
|
28
|
+
* send time, at most 200 code points (a longer one is cut, not refused). No
|
|
29
|
+
* control characters (C0, DEL, C1) and no lone surrogates (U+D800-DFFF) in
|
|
30
|
+
* either.
|
|
31
|
+
*/
|
|
32
|
+
export type InputAuthor = {
|
|
33
|
+
id: string;
|
|
34
|
+
label?: string;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* optio-api's `inputAuthor` hook (`OptioApiOptions.inputAuthor`, Fastify): the
|
|
38
|
+
* author of the request's input, or null (no header is sent). Called once per
|
|
39
|
+
* proxied POST, PUT or PATCH, after the gate admitted it. An author that breaks
|
|
40
|
+
* the rules is a host bug: the request fails with 500 and is logged, never
|
|
41
|
+
* forwarded with a bad header.
|
|
42
|
+
*/
|
|
43
|
+
export type InputAuthorCallback<TRequest> = (req: TRequest) => InputAuthor | null | Promise<InputAuthor | null>;
|
|
44
|
+
/**
|
|
45
|
+
* The header value of `author` (see the module comment). A `label` over 200
|
|
46
|
+
* code points is cut. Throws for an author that breaks the rules: an `id` that
|
|
47
|
+
* is not a string of 1-128 code points, a `label` that is not a string, a
|
|
48
|
+
* control character or a lone surrogate in either.
|
|
49
|
+
*/
|
|
50
|
+
export declare function encodeInputAuthor(author: InputAuthor): string;
|
|
51
|
+
/**
|
|
52
|
+
* The author a header value carries, or null when it is not valid: it must
|
|
53
|
+
* decode (base64url, padding tolerated) to UTF-8 JSON of an object with a
|
|
54
|
+
* string `id` and at most an optional string `label`, nothing else, both by the
|
|
55
|
+
* rules of `InputAuthor` (a `label` over 200 code points is cut). Null and
|
|
56
|
+
* undefined give null.
|
|
57
|
+
*/
|
|
58
|
+
export declare function parseInputAuthor(value: string | null | undefined): InputAuthor | null;
|
|
59
|
+
//# sourceMappingURL=input-author.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input-author.d.ts","sourceRoot":"","sources":["../src/input-author.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,mGAAmG;AACnG,eAAO,MAAM,mBAAmB,mBAAmB,CAAC;AAEpD;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEzD;;;;;;GAMG;AACH,MAAM,MAAM,mBAAmB,CAAC,QAAQ,IACtC,CAAC,GAAG,EAAE,QAAQ,KAAK,WAAW,GAAG,IAAI,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;AA2DtE;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAS7D;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,WAAW,GAAG,IAAI,CAarF"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The app stamp of an input to an agent (message authors spec,
|
|
3
|
+
* `docs/2026-11-24-message-authors-design.md`, section 3).
|
|
4
|
+
*
|
|
5
|
+
* The host app's server, never the browser, says which of its users wrote an
|
|
6
|
+
* input: optio-api's widget proxy calls the `inputAuthor` hook for every proxied
|
|
7
|
+
* request with a body method (POST, PUT, PATCH) the gate admitted, and sets
|
|
8
|
+
* `X-Optio-Author: <value>` on the upstream request; it removes any
|
|
9
|
+
* `X-Optio-Author` the client sent from every request it forwards (HTTP and
|
|
10
|
+
* WebSocket), hook set or not. The agent's conversation listener reads the
|
|
11
|
+
* header (optio-agents' `parse_author_header`) and stamps the input as an
|
|
12
|
+
* `app` author. The header carries only the `app` author: its JSON has no `ns`.
|
|
13
|
+
*
|
|
14
|
+
* The value: base64url (RFC 4648 section 5, no padding; padding tolerated on
|
|
15
|
+
* read) of the UTF-8 JSON `{"id":<id>,"label":<label>}`, keys in that order,
|
|
16
|
+
* `label` left out when absent, no other key. Examples:
|
|
17
|
+
* - `{ id: 'u1', label: 'Ann' }` -> `eyJpZCI6InUxIiwibGFiZWwiOiJBbm4ifQ`
|
|
18
|
+
* - `{ id: '65a1f0c2e4b0a1b2c3d4e5f6', label: 'Ági Kovács' }` ->
|
|
19
|
+
* `eyJpZCI6IjY1YTFmMGMyZTRiMGExYjJjM2Q0ZTVmNiIsImxhYmVsIjoiw4FnaSBLb3bDoWNzIn0`
|
|
20
|
+
*
|
|
21
|
+
* Exported from `optio-api`, so a custom adapter can do the same.
|
|
22
|
+
*/
|
|
23
|
+
/** The header the widget proxy sets on the upstream request (lower case, as Node keys headers). */
|
|
24
|
+
export const INPUT_AUTHOR_HEADER = 'x-optio-author';
|
|
25
|
+
// In Unicode code points, as optio-agents' MAX_AUTHOR_ID_CHARS / MAX_AUTHOR_LABEL_CHARS.
|
|
26
|
+
const MAX_ID_CODE_POINTS = 128;
|
|
27
|
+
const MAX_LABEL_CODE_POINTS = 200;
|
|
28
|
+
// Unicode's control characters (Cc): C0, DEL, C1 (optio-agents' authors.py has the same).
|
|
29
|
+
const CONTROL_CHARACTER = /[\u0000-\u001f\u007f-\u009f]/;
|
|
30
|
+
// Lone surrogates (U+D800-DFFF; optio-agents' authors.py has the same rule). With the `u` flag a
|
|
31
|
+
// surrogate pair is one code point outside this range, so only an unpaired one matches: no
|
|
32
|
+
// UTF-8 text can carry it (Buffer would write U+FFFD), only JSON's `\u` escapes can.
|
|
33
|
+
const LONE_SURROGATE = /[\uD800-\uDFFF]/u;
|
|
34
|
+
// The base64url alphabet, then at most two padding characters.
|
|
35
|
+
const BASE64URL = /^[A-Za-z0-9_-]*={0,2}$/;
|
|
36
|
+
// Strict: a byte sequence that is not UTF-8 is refused, not replaced, and a
|
|
37
|
+
// leading byte order mark is kept (so JSON.parse refuses it, as Python does).
|
|
38
|
+
const UTF8 = new TextDecoder('utf-8', { fatal: true, ignoreBOM: true });
|
|
39
|
+
/** `label` cut to its first 200 code points (never inside a surrogate pair). */
|
|
40
|
+
function cutLabel(label) {
|
|
41
|
+
// At most 200 UTF-16 units is at most 200 code points.
|
|
42
|
+
if (label.length <= MAX_LABEL_CODE_POINTS)
|
|
43
|
+
return label;
|
|
44
|
+
const codePoints = Array.from(label);
|
|
45
|
+
return codePoints.length <= MAX_LABEL_CODE_POINTS
|
|
46
|
+
? label
|
|
47
|
+
: codePoints.slice(0, MAX_LABEL_CODE_POINTS).join('');
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The author `value` holds, its `label` cut, or the rule it breaks. The label
|
|
51
|
+
* is cut first and checked after, as optio-agents' `parse_author_header` does.
|
|
52
|
+
* The rule names no value: an id or a label is never put in a log line.
|
|
53
|
+
*/
|
|
54
|
+
function checkAuthor(value) {
|
|
55
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
56
|
+
return 'an author must be an object';
|
|
57
|
+
}
|
|
58
|
+
if (Object.keys(value).some((key) => key !== 'id' && key !== 'label')) {
|
|
59
|
+
return 'an author has only an id and a label';
|
|
60
|
+
}
|
|
61
|
+
const { id, label } = value;
|
|
62
|
+
if (typeof id !== 'string')
|
|
63
|
+
return 'the id must be a string';
|
|
64
|
+
const idCodePoints = Array.from(id).length;
|
|
65
|
+
if (idCodePoints < 1 || idCodePoints > MAX_ID_CODE_POINTS) {
|
|
66
|
+
return `the id must be 1-${MAX_ID_CODE_POINTS} code points`;
|
|
67
|
+
}
|
|
68
|
+
if (CONTROL_CHARACTER.test(id))
|
|
69
|
+
return 'the id must have no control characters';
|
|
70
|
+
if (LONE_SURROGATE.test(id))
|
|
71
|
+
return 'the id must have no lone surrogates';
|
|
72
|
+
if (label === undefined)
|
|
73
|
+
return { id };
|
|
74
|
+
if (typeof label !== 'string')
|
|
75
|
+
return 'the label must be a string';
|
|
76
|
+
const cut = cutLabel(label);
|
|
77
|
+
if (CONTROL_CHARACTER.test(cut))
|
|
78
|
+
return 'the label must have no control characters';
|
|
79
|
+
if (LONE_SURROGATE.test(cut))
|
|
80
|
+
return 'the label must have no lone surrogates';
|
|
81
|
+
return { id, label: cut };
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The header value of `author` (see the module comment). A `label` over 200
|
|
85
|
+
* code points is cut. Throws for an author that breaks the rules: an `id` that
|
|
86
|
+
* is not a string of 1-128 code points, a `label` that is not a string, a
|
|
87
|
+
* control character or a lone surrogate in either.
|
|
88
|
+
*/
|
|
89
|
+
export function encodeInputAuthor(author) {
|
|
90
|
+
const checked = checkAuthor(author);
|
|
91
|
+
if (typeof checked === 'string')
|
|
92
|
+
throw new Error(`invalid input author: ${checked}`);
|
|
93
|
+
// Built afresh, so the keys come in the order id, label.
|
|
94
|
+
const json = checked.label === undefined
|
|
95
|
+
? JSON.stringify({ id: checked.id })
|
|
96
|
+
: JSON.stringify({ id: checked.id, label: checked.label });
|
|
97
|
+
// Node's base64url has no padding.
|
|
98
|
+
return Buffer.from(json, 'utf8').toString('base64url');
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The author a header value carries, or null when it is not valid: it must
|
|
102
|
+
* decode (base64url, padding tolerated) to UTF-8 JSON of an object with a
|
|
103
|
+
* string `id` and at most an optional string `label`, nothing else, both by the
|
|
104
|
+
* rules of `InputAuthor` (a `label` over 200 code points is cut). Null and
|
|
105
|
+
* undefined give null.
|
|
106
|
+
*/
|
|
107
|
+
export function parseInputAuthor(value) {
|
|
108
|
+
if (typeof value !== 'string' || !BASE64URL.test(value))
|
|
109
|
+
return null;
|
|
110
|
+
const data = value.replace(/=+$/, '');
|
|
111
|
+
// No encoding ends with a single character of a group.
|
|
112
|
+
if (data.length % 4 === 1)
|
|
113
|
+
return null;
|
|
114
|
+
let json;
|
|
115
|
+
try {
|
|
116
|
+
json = JSON.parse(UTF8.decode(Buffer.from(data, 'base64url')));
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
const checked = checkAuthor(json);
|
|
122
|
+
return typeof checked === 'string' ? null : checked;
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=input-author.js.map
|