@turingfocus/chat-protocol 0.1.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.
@@ -0,0 +1,319 @@
1
+ import type { ReadonlyJsonValue } from "./raw.js";
2
+ export type ConversationId = string;
3
+ export type TimelineItemId = string;
4
+ export type RunId = string;
5
+ export interface Conversation {
6
+ readonly id: ConversationId;
7
+ readonly title: string;
8
+ readonly description?: string | undefined;
9
+ /** Unix epoch milliseconds. */
10
+ readonly updatedAt?: number | undefined;
11
+ readonly raw?: ReadonlyJsonValue | undefined;
12
+ }
13
+ export type MessageRole = "assistant" | "system" | "tool" | "unknown" | "user";
14
+ export interface TextMessageContent {
15
+ readonly kind: "text";
16
+ readonly text: string;
17
+ }
18
+ export interface MediaMessageContent {
19
+ readonly kind: "media";
20
+ readonly mediaType: "audio" | "image" | "video";
21
+ readonly summary: string;
22
+ readonly raw?: ReadonlyJsonValue | undefined;
23
+ }
24
+ export interface FileMessageContent {
25
+ readonly kind: "file";
26
+ readonly summary: string;
27
+ readonly raw?: ReadonlyJsonValue | undefined;
28
+ }
29
+ export interface ContactMessageContent {
30
+ readonly kind: "contact";
31
+ readonly summary: string;
32
+ readonly raw?: ReadonlyJsonValue | undefined;
33
+ }
34
+ export interface UrlMessageContent {
35
+ readonly kind: "url";
36
+ readonly summary: string;
37
+ readonly raw?: ReadonlyJsonValue | undefined;
38
+ }
39
+ export interface UnknownMessageContent {
40
+ readonly kind: "unknown";
41
+ readonly summary: string;
42
+ readonly raw?: ReadonlyJsonValue | undefined;
43
+ }
44
+ /**
45
+ * One normalized received-message variant. Multipart and attachment resource
46
+ * contracts remain deferred; non-text variants expose only safe fallback data.
47
+ */
48
+ export type MessageContent = ContactMessageContent | FileMessageContent | MediaMessageContent | TextMessageContent | UnknownMessageContent | UrlMessageContent;
49
+ export interface MessageAuthor {
50
+ readonly id?: string | undefined;
51
+ readonly displayName?: string | undefined;
52
+ readonly avatarUrl?: string | undefined;
53
+ }
54
+ export interface Message {
55
+ readonly kind: "message";
56
+ readonly id: TimelineItemId;
57
+ readonly conversationId: ConversationId;
58
+ readonly role: MessageRole;
59
+ readonly content: MessageContent;
60
+ /** Server-owned Unix epoch milliseconds used for stable ordering. */
61
+ readonly createdAt: number;
62
+ readonly updatedAt?: number | undefined;
63
+ /** Optional server-defined tie breaker for items sharing createdAt. */
64
+ readonly sequence?: number | undefined;
65
+ readonly author?: MessageAuthor | undefined;
66
+ readonly reasoning?: string | undefined;
67
+ readonly raw?: ReadonlyJsonValue | undefined;
68
+ }
69
+ export type AgentEventStatus = "aborted" | "failed" | "running" | "success" | "timeout" | "unknown";
70
+ export interface AgentEventTransition {
71
+ /** Gateway-normalized stable ID; duplicate delivery must reuse the same ID. */
72
+ readonly id: string;
73
+ readonly status: AgentEventStatus;
74
+ /** Server-owned Unix epoch milliseconds; array order breaks equal-time ties. */
75
+ readonly occurredAt: number;
76
+ readonly sequence?: number | undefined;
77
+ readonly summary?: string | undefined;
78
+ readonly error?: ChatError | undefined;
79
+ readonly raw?: ReadonlyJsonValue | undefined;
80
+ }
81
+ export interface ToolCall {
82
+ readonly id?: string | undefined;
83
+ readonly name: string;
84
+ readonly description?: string | undefined;
85
+ readonly arguments?: ReadonlyJsonValue | undefined;
86
+ readonly index?: number | undefined;
87
+ }
88
+ interface ToolReturnFields {
89
+ readonly result?: ReadonlyJsonValue | undefined;
90
+ readonly success?: boolean | undefined;
91
+ readonly done?: boolean | undefined;
92
+ readonly raw?: ReadonlyJsonValue | undefined;
93
+ }
94
+ /** A normalized Tool return must preserve at least one meaningful field. */
95
+ export type ToolReturn = (ToolReturnFields & {
96
+ readonly result: ReadonlyJsonValue;
97
+ }) | (ToolReturnFields & {
98
+ readonly success: boolean;
99
+ }) | (ToolReturnFields & {
100
+ readonly done: boolean;
101
+ }) | (ToolReturnFields & {
102
+ readonly raw: ReadonlyJsonValue;
103
+ });
104
+ export interface AskUserInteractionOption {
105
+ readonly label: string;
106
+ readonly value: string;
107
+ readonly description?: string | undefined;
108
+ }
109
+ export interface AskUserInteractionQuestion {
110
+ readonly id: string;
111
+ readonly prompt: string;
112
+ readonly title?: string | undefined;
113
+ readonly description?: string | undefined;
114
+ readonly placeholder?: string | undefined;
115
+ readonly required: boolean;
116
+ readonly multiple: boolean;
117
+ readonly defaultValue?: AskUserInteractionValue | undefined;
118
+ readonly options: readonly AskUserInteractionOption[];
119
+ }
120
+ export type AskUserInteractionValue = string | readonly string[];
121
+ /** One conversation-scoped request for structured user input. */
122
+ export interface AskUserInteractionRequest {
123
+ readonly kind: "ask-user";
124
+ readonly conversationId: ConversationId;
125
+ readonly requestId: string;
126
+ /** Immutable Gateway-issued identity for this exact request envelope. */
127
+ readonly revision: string;
128
+ readonly eventId?: string | undefined;
129
+ readonly title: string;
130
+ readonly questions: readonly AskUserInteractionQuestion[];
131
+ readonly timeoutSeconds?: number | undefined;
132
+ }
133
+ export interface AskUserInteractionAnswer {
134
+ readonly requestId: string;
135
+ readonly revision: string;
136
+ readonly action: "cancel" | "submit";
137
+ readonly answers: Readonly<Record<string, AskUserInteractionValue>>;
138
+ }
139
+ /** Gateway-normalized terminal Ask User data suitable for history rendering. */
140
+ export interface AskUserInteractionResult {
141
+ readonly kind: "ask-user";
142
+ readonly requestId: string;
143
+ readonly revision?: string | undefined;
144
+ readonly status: "answered" | "cancelled" | "chat-about-this" | "failed" | "timeout";
145
+ readonly questions: readonly AskUserInteractionQuestion[];
146
+ readonly answers?: Readonly<Record<string, AskUserInteractionValue>> | undefined;
147
+ readonly error?: string | undefined;
148
+ }
149
+ export interface ToolEventTransition extends AgentEventTransition {
150
+ readonly toolCall?: ToolCall | undefined;
151
+ readonly toolReturn?: ToolReturn | undefined;
152
+ readonly interaction?: AskUserInteractionResult | undefined;
153
+ }
154
+ interface AgentEventBase {
155
+ readonly kind: "agent-event";
156
+ readonly id: TimelineItemId;
157
+ readonly conversationId: ConversationId;
158
+ readonly eventType: string;
159
+ /** Latest transition status; schemas require it to match transitions.at(-1). */
160
+ readonly status: AgentEventStatus;
161
+ readonly createdAt: number;
162
+ readonly updatedAt?: number | undefined;
163
+ readonly sequence?: number | undefined;
164
+ readonly summary?: string | undefined;
165
+ readonly raw?: ReadonlyJsonValue | undefined;
166
+ }
167
+ export interface GenericAgentEvent extends AgentEventBase {
168
+ readonly eventCategory: "generic";
169
+ readonly transitions: readonly AgentEventTransition[];
170
+ }
171
+ /** Structured Tool event preserving partial and terminal transition data. */
172
+ export interface ToolAgentEvent extends AgentEventBase {
173
+ readonly eventCategory: "tool";
174
+ readonly transitions: readonly ToolEventTransition[];
175
+ }
176
+ export type AgentEvent = GenericAgentEvent | ToolAgentEvent;
177
+ interface AgentEventTransitionPayloadBase {
178
+ /** Immutable event identity established by the first accepted transition. */
179
+ readonly id: TimelineItemId;
180
+ /** Immutable for an event ID; conflicting updates must be rejected. */
181
+ readonly eventType: string;
182
+ /** Immutable for an event ID; conflicting updates must be rejected. */
183
+ readonly createdAt: number;
184
+ /** Immutable for an event ID; conflicting updates must be rejected. */
185
+ readonly sequence?: number | undefined;
186
+ }
187
+ export interface GenericAgentEventTransitionPayload extends AgentEventTransitionPayloadBase {
188
+ readonly eventCategory: "generic";
189
+ readonly transition: AgentEventTransition;
190
+ }
191
+ export interface ToolAgentEventTransitionPayload extends AgentEventTransitionPayloadBase {
192
+ readonly eventCategory: "tool";
193
+ readonly transition: ToolEventTransition;
194
+ }
195
+ export type AgentEventTransitionPayload = GenericAgentEventTransitionPayload | ToolAgentEventTransitionPayload;
196
+ /** Safe fallback for an event type the Gateway cannot normalize. */
197
+ export interface UnknownEvent {
198
+ readonly kind: "unknown-event";
199
+ readonly id: TimelineItemId;
200
+ readonly conversationId: ConversationId;
201
+ readonly originalType: string;
202
+ readonly createdAt: number;
203
+ readonly updatedAt?: number | undefined;
204
+ readonly sequence?: number | undefined;
205
+ readonly summary: string;
206
+ readonly raw?: ReadonlyJsonValue | undefined;
207
+ }
208
+ export type TimelineItem = AgentEvent | Message | UnknownEvent;
209
+ export type RunStatus = "aborted" | "failed" | "running" | "succeeded" | "unknown";
210
+ export interface Run {
211
+ readonly id: RunId;
212
+ readonly conversationId: ConversationId;
213
+ readonly status: RunStatus;
214
+ readonly canInterrupt: boolean;
215
+ readonly startedAt?: number | undefined;
216
+ readonly finishedAt?: number | undefined;
217
+ readonly error?: ChatError | undefined;
218
+ }
219
+ export type ChatErrorCode = "authentication" | "authorization" | "conflict" | "network" | "not-found" | "server" | "timeout" | "unknown" | "unsupported" | "validation";
220
+ export interface ChatError {
221
+ readonly code: ChatErrorCode;
222
+ readonly message: string;
223
+ readonly retryable: boolean;
224
+ readonly conversationId?: ConversationId | undefined;
225
+ readonly details?: ReadonlyJsonValue | undefined;
226
+ }
227
+ export interface Capabilities {
228
+ /** Enables ChatGateway.answerInteraction when the optional method exists. */
229
+ readonly answerInteraction?: boolean | undefined;
230
+ /** Enables interrupt only while the current run is running and interruptible. */
231
+ readonly interrupt: boolean;
232
+ /** Enables ChatGateway.listConversations. */
233
+ readonly listConversations: boolean;
234
+ /** Enables ChatGateway.subscribe. */
235
+ readonly liveUpdates: boolean;
236
+ /** Enables history requests carrying a previousCursor; initial load remains available. */
237
+ readonly loadHistory: boolean;
238
+ /** Enables ChatGateway.sendText. */
239
+ readonly sendText: boolean;
240
+ }
241
+ export interface TimelinePageInfo {
242
+ readonly previousCursor?: string | undefined;
243
+ readonly hasPreviousPage: boolean;
244
+ }
245
+ export interface ChatSnapshot {
246
+ readonly conversation: Conversation;
247
+ readonly timeline: readonly TimelineItem[];
248
+ readonly run: Run | null;
249
+ readonly capabilities: Capabilities;
250
+ readonly pageInfo: TimelinePageInfo;
251
+ readonly pendingInteraction?: AskUserInteractionRequest | undefined;
252
+ readonly error?: ChatError | undefined;
253
+ }
254
+ export interface AgentEventTransitionUpdate {
255
+ readonly kind: "event.transition.upsert";
256
+ readonly conversationId: ConversationId;
257
+ readonly event: AgentEventTransitionPayload;
258
+ }
259
+ export type ChatUpdate = {
260
+ readonly kind: "snapshot.replace";
261
+ readonly snapshot: ChatSnapshot;
262
+ } | {
263
+ readonly kind: "conversation.upsert";
264
+ readonly conversation: Conversation;
265
+ } | {
266
+ /** Full item replacement; use event.transition.upsert for one transition. */
267
+ readonly kind: "timeline.upsert";
268
+ readonly conversationId: ConversationId;
269
+ readonly item: TimelineItem;
270
+ }
271
+ /**
272
+ * Idempotently upserts one transition without requiring Gateway state.
273
+ * Runtime groups by conversationId/event.id, upserts by transition.id,
274
+ * orders by occurredAt/sequence/id, and derives the latest status.
275
+ */
276
+ | AgentEventTransitionUpdate | {
277
+ readonly kind: "run.replace";
278
+ readonly conversationId: ConversationId;
279
+ readonly run: Run | null;
280
+ } | {
281
+ readonly kind: "capabilities.replace";
282
+ readonly conversationId: ConversationId;
283
+ readonly capabilities: Capabilities;
284
+ } | {
285
+ readonly kind: "interaction.replace";
286
+ readonly conversationId: ConversationId;
287
+ readonly interaction: AskUserInteractionRequest | null;
288
+ } | {
289
+ readonly kind: "error.reported";
290
+ readonly conversationId?: ConversationId | undefined;
291
+ readonly error: ChatError;
292
+ };
293
+ export declare const conversationSchema: import("./schema.js").RuntimeSchema<Conversation>;
294
+ export declare const askUserInteractionRequestSchema: import("./schema.js").RuntimeSchema<AskUserInteractionRequest>;
295
+ export declare const askUserInteractionAnswerSchema: import("./schema.js").RuntimeSchema<AskUserInteractionAnswer>;
296
+ export declare const askUserInteractionResultSchema: import("./schema.js").RuntimeSchema<AskUserInteractionResult>;
297
+ export declare const messageSchema: import("./schema.js").RuntimeSchema<Message>;
298
+ export declare const agentEventSchema: import("./schema.js").RuntimeSchema<AgentEvent>;
299
+ export declare const unknownEventSchema: import("./schema.js").RuntimeSchema<UnknownEvent>;
300
+ export declare const timelineItemSchema: import("./schema.js").RuntimeSchema<TimelineItem>;
301
+ export declare const runSchema: import("./schema.js").RuntimeSchema<Run>;
302
+ export declare const chatErrorSchema: import("./schema.js").RuntimeSchema<ChatError>;
303
+ export declare const capabilitiesSchema: import("./schema.js").RuntimeSchema<Capabilities>;
304
+ export declare const chatSnapshotSchema: import("./schema.js").RuntimeSchema<ChatSnapshot>;
305
+ export declare const chatUpdateSchema: import("./schema.js").RuntimeSchema<ChatUpdate>;
306
+ /** Stable identity used by Runtime upsert and deduplication. */
307
+ export declare const getTimelineItemKey: (item: TimelineItem) => string;
308
+ /**
309
+ * Total ordering independent of arrival order. Updating an existing item does
310
+ * not move it because updatedAt is deliberately excluded from this key.
311
+ */
312
+ export declare const compareTimelineItems: (left: TimelineItem, right: TimelineItem) => number;
313
+ /**
314
+ * Enforces the immutable envelope rule for event.transition.upsert. Runtime
315
+ * ignores and reports conflicting updates instead of guessing an overwrite.
316
+ */
317
+ export declare const hasCompatibleAgentEventMetadata: (event: AgentEvent, update: AgentEventTransitionUpdate) => boolean;
318
+ export {};
319
+ //# sourceMappingURL=models.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAElD,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC;AACpC,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC;AACpC,MAAM,MAAM,KAAK,GAAG,MAAM,CAAC;AAE3B,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,EAAE,cAAc,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1C,+BAA+B;IAC/B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACxC,QAAQ,CAAC,GAAG,CAAC,EAAE,iBAAiB,GAAG,SAAS,CAAC;CAC9C;AAED,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG,QAAQ,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,CAAC;AAE/E,MAAM,WAAW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O,MAAM,+BAA+B,gEAE3C,CAAC;AACF,eAAO,MAAM,8BAA8B,+DAE1C,CAAC;AACF,eAAO,MAAM,8BAA8B,+DAE1C,CAAC;AACF,eAAO,MAAM,aAAa,8CAAqC,CAAC;AAChE,eAAO,MAAM,gBAAgB,iDAAwC,CAAC;AACtE,eAAO,MAAM,kBAAkB,mDAA0C,CAAC;AAC1E,eAAO,MAAM,kBAAkB,mDAA0C,CAAC;AAC1E,eAAO,MAAM,SAAS,0CAAiC,CAAC;AACxD,eAAO,MAAM,eAAe,gDAAuC,CAAC;AACpE,eAAO,MAAM,kBAAkB,mDAA0C,CAAC;AAC1E,eAAO,MAAM,kBAAkB,mDAA0C,CAAC;AAC1E,eAAO,MAAM,gBAAgB,iDAAwC,CAAC;AAEtE,gEAAgE;AAChE,eAAO,MAAM,kBAAkB,GAAI,MAAM,YAAY,KAAG,MACa,CAAC;AAEtE;;;GAGG;AACH,eAAO,MAAM,oBAAoB,GAC/B,MAAM,YAAY,EAClB,OAAO,YAAY,KAClB,MAYF,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,+BAA+B,GAC1C,OAAO,UAAU,EACjB,QAAQ,0BAA0B,KACjC,OAMuC,CAAC"}
package/dist/models.js ADDED
@@ -0,0 +1,44 @@
1
+ import { agentEventParser, askUserInteractionAnswerParser, askUserInteractionRequestParser, askUserInteractionResultParser, capabilitiesParser, chatErrorParser, chatSnapshotParser, chatUpdateParser, conversationParser, messageParser, runParser, timelineItemParser, unknownEventParser, } from "./internal-schemas.js";
2
+ import { createRuntimeSchema } from "./internal-runtime-schema.js";
3
+ export const conversationSchema = createRuntimeSchema(conversationParser);
4
+ export const askUserInteractionRequestSchema = createRuntimeSchema(askUserInteractionRequestParser);
5
+ export const askUserInteractionAnswerSchema = createRuntimeSchema(askUserInteractionAnswerParser);
6
+ export const askUserInteractionResultSchema = createRuntimeSchema(askUserInteractionResultParser);
7
+ export const messageSchema = createRuntimeSchema(messageParser);
8
+ export const agentEventSchema = createRuntimeSchema(agentEventParser);
9
+ export const unknownEventSchema = createRuntimeSchema(unknownEventParser);
10
+ export const timelineItemSchema = createRuntimeSchema(timelineItemParser);
11
+ export const runSchema = createRuntimeSchema(runParser);
12
+ export const chatErrorSchema = createRuntimeSchema(chatErrorParser);
13
+ export const capabilitiesSchema = createRuntimeSchema(capabilitiesParser);
14
+ export const chatSnapshotSchema = createRuntimeSchema(chatSnapshotParser);
15
+ export const chatUpdateSchema = createRuntimeSchema(chatUpdateParser);
16
+ /** Stable identity used by Runtime upsert and deduplication. */
17
+ export const getTimelineItemKey = (item) => item.kind === "message" ? `message:${item.id}` : `event:${item.id}`;
18
+ /**
19
+ * Total ordering independent of arrival order. Updating an existing item does
20
+ * not move it because updatedAt is deliberately excluded from this key.
21
+ */
22
+ export const compareTimelineItems = (left, right) => {
23
+ const timestampOrder = left.createdAt - right.createdAt;
24
+ if (timestampOrder !== 0)
25
+ return timestampOrder;
26
+ const sequenceOrder = (left.sequence ?? Number.MAX_SAFE_INTEGER) -
27
+ (right.sequence ?? Number.MAX_SAFE_INTEGER);
28
+ if (sequenceOrder !== 0)
29
+ return sequenceOrder;
30
+ const leftKey = getTimelineItemKey(left);
31
+ const rightKey = getTimelineItemKey(right);
32
+ return leftKey < rightKey ? -1 : leftKey > rightKey ? 1 : 0;
33
+ };
34
+ /**
35
+ * Enforces the immutable envelope rule for event.transition.upsert. Runtime
36
+ * ignores and reports conflicting updates instead of guessing an overwrite.
37
+ */
38
+ export const hasCompatibleAgentEventMetadata = (event, update) => event.conversationId === update.conversationId &&
39
+ event.id === update.event.id &&
40
+ event.eventCategory === update.event.eventCategory &&
41
+ event.eventType === update.event.eventType &&
42
+ event.createdAt === update.event.createdAt &&
43
+ event.sequence === update.event.sequence;
44
+ //# sourceMappingURL=models.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"models.js","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,8BAA8B,EAC9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AM,CAAC,KAAK,CAAC,SAAS;IAC1C,KAAK,CAAC,QAAQ,KAAK,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC"}
@@ -0,0 +1,9 @@
1
+ interface OrderedAgentEventTransition {
2
+ readonly id: string;
3
+ readonly occurredAt: number;
4
+ readonly sequence?: number | undefined;
5
+ }
6
+ /** Total ordering used after idempotent transition upsert by transition.id. */
7
+ export declare const compareAgentEventTransitions: (left: OrderedAgentEventTransition, right: OrderedAgentEventTransition) => number;
8
+ export {};
9
+ //# sourceMappingURL=ordering.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ordering.d.ts","sourceRoot":"","sources":["../src/ordering.ts"],"names":[],"mappings":"AAAA,UAAU,2BAA2B;IACnC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACxC;AAED,+EAA+E;AAC/E,eAAO,MAAM,4BAA4B,GACvC,MAAM,2BAA2B,EACjC,OAAO,2BAA2B,KACjC,MAUF,CAAC"}
@@ -0,0 +1,12 @@
1
+ /** Total ordering used after idempotent transition upsert by transition.id. */
2
+ export const compareAgentEventTransitions = (left, right) => {
3
+ const timestampOrder = left.occurredAt - right.occurredAt;
4
+ if (timestampOrder !== 0)
5
+ return timestampOrder;
6
+ const sequenceOrder = (left.sequence ?? Number.MAX_SAFE_INTEGER) -
7
+ (right.sequence ?? Number.MAX_SAFE_INTEGER);
8
+ if (sequenceOrder !== 0)
9
+ return sequenceOrder;
10
+ return left.id < right.id ? -1 : left.id > right.id ? 1 : 0;
11
+ };
12
+ //# sourceMappingURL=ordering.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ordering.js","sourceRoot":"","sources":["../src/ordering.ts"],"names":[],"mappings":"AAMA,+EAA+E;AAC/E,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAC1C,IAAiC,EACjC,KAAkC,EAC1B,EAAE;IACV,MAAM,cAAc,GAAG,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC;IAC1D,IAAI,cAAc,KAAK,CAAC;QAAE,OAAO,cAAc,CAAC;IAEhD,MAAM,aAAa,GACjB,CAAC,IAAI,CAAC,QAAQ,IAAI,MAAM,CAAC,gBAAgB,CAAC;QAC1C,CAAC,KAAK,CAAC,QAAQ,IAAI,MAAM,CAAC,gBAAgB,CAAC,CAAC;IAC9C,IAAI,aAAa,KAAK,CAAC;QAAE,OAAO,aAAa,CAAC;IAE9C,OAAO,IAAI,CAAC,EAAE,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,GAAG,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9D,CAAC,CAAC"}
package/dist/raw.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ export type JsonPrimitive = boolean | null | number | string;
2
+ export type ReadonlyJsonValue = JsonPrimitive | readonly ReadonlyJsonValue[] | {
3
+ readonly [key: string]: ReadonlyJsonValue;
4
+ };
5
+ export declare const isSensitiveRawKey: (key: string) => boolean;
6
+ /** Removes credential-shaped fragments from user-visible diagnostic text. */
7
+ export declare const sanitizeDiagnosticText: (input: string) => string;
8
+ /**
9
+ * Produces an immutable JSON value and redacts credential-shaped keys, header
10
+ * tuples, authorization strings, JWTs, URL userinfo, and signed query values.
11
+ * The retained result is bounded by depth, nodes, per-string size, and total
12
+ * key/string characters so many individually valid values cannot amplify it.
13
+ * Gateway adapters must still allowlist transport fields before retaining raw;
14
+ * this sanitizer is the final defense rather than permission to keep headers.
15
+ */
16
+ export declare const sanitizeRaw: (input: unknown) => ReadonlyJsonValue;
17
+ //# sourceMappingURL=raw.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"raw.d.ts","sourceRoot":"","sources":["../src/raw.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,IAAI,GAAG,MAAM,GAAG,MAAM,CAAC;AAE7D,MAAM,MAAM,iBAAiB,GACzB,aAAa,GACb,SAAS,iBAAiB,EAAE,GAC5B;IAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,iBAAiB,CAAA;CAAE,CAAC;AAoDlD,eAAO,MAAM,iBAAiB,GAAI,KAAK,MAAM,KAAG,OAM/C,CAAC;AA0BF,6EAA6E;AAC7E,eAAO,MAAM,sBAAsB,GAAI,OAAO,MAAM,KAAG,MAgCtD,CAAC;AAoJF;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,GAAI,OAAO,OAAO,KAAG,iBAKzC,CAAC"}
package/dist/raw.js ADDED
@@ -0,0 +1,208 @@
1
+ const MAX_RAW_DEPTH = 32;
2
+ const MAX_RAW_KEY_LENGTH = 1_024;
3
+ const MAX_RAW_NODES = 10_000;
4
+ const MAX_RAW_STRING_LENGTH = 262_144;
5
+ const MAX_RAW_TOTAL_CHARACTERS = 1_048_576;
6
+ const REDACTED_VALUE = "[REDACTED]";
7
+ const sensitiveKeyNames = new Set([
8
+ "adminkey",
9
+ "apikey",
10
+ "auth",
11
+ "authorization",
12
+ "bearer",
13
+ "clientsecret",
14
+ "cookie",
15
+ "credentials",
16
+ "credential",
17
+ "password",
18
+ "privatekey",
19
+ "refreshtoken",
20
+ "jwt",
21
+ "secret",
22
+ "secretkey",
23
+ "setcookie",
24
+ "sig",
25
+ "signature",
26
+ "token",
27
+ "accesstoken",
28
+ "xamzcredential",
29
+ "xamzsignature",
30
+ ]);
31
+ const sensitiveKeySuffixes = [
32
+ "adminkey",
33
+ "apikey",
34
+ "authorization",
35
+ "clientsecret",
36
+ "cookie",
37
+ "credentials",
38
+ "credential",
39
+ "password",
40
+ "privatekey",
41
+ "secret",
42
+ "secretkey",
43
+ "signature",
44
+ "token",
45
+ ];
46
+ const canonicalizeKey = (key) => key.toLocaleLowerCase("en-US").replaceAll(/[^a-z0-9]/gu, "");
47
+ export const isSensitiveRawKey = (key) => {
48
+ const canonicalKey = canonicalizeKey(key);
49
+ return (sensitiveKeyNames.has(canonicalKey) ||
50
+ sensitiveKeySuffixes.some((suffix) => canonicalKey.endsWith(suffix)));
51
+ };
52
+ const authorizationValuePattern = /\b(?:basic|bearer)\s+[A-Za-z0-9+/_:.~-]+={0,}/giu;
53
+ const credentialHeaderValuePattern = /\b(?:(?:x[-_])?(?:admin|api)[-_]?key|(?:proxy[-_])?authorization|cookie|set-cookie)\s*[:=]\s*[^\r\n]+/giu;
54
+ const jwtValuePattern = /\b(?:[A-Za-z0-9_-]{8,}\.){2,4}[A-Za-z0-9_-]+\b/gu;
55
+ const pemPrivateKeyPattern = /-----BEGIN (?:[A-Z0-9]+ )*PRIVATE KEY(?: BLOCK)?-----/iu;
56
+ const providerTokenPattern = /\b(?:gh[pousr]_[A-Za-z0-9]{20,}|github_pat_[A-Za-z0-9_]{20,}|glpat-[A-Za-z0-9_-]{20,}|sk-[A-Za-z0-9_-]{20,}|xox[baprs]-[A-Za-z0-9-]{10,})\b/gu;
57
+ const awsAccessKeyPattern = /\b(?:A3T[A-Z0-9]{17}|A(?:GPA|IDA|IPA|KIA|NPA|NVA|ROA|SCA|SIA)[A-Z0-9]{16})\b/gu;
58
+ const urlParameterPattern = /([?&#])([^?&#=]+)=([^&#]*)/gu;
59
+ const urlUserInfoPattern = /((?:\b[A-Za-z][A-Za-z0-9+.-]*:)?\/\/)([^/@\s]+)@/gu;
60
+ const embeddedParameterPattern = /(^|[\s,;])([^?&#:=\s,;]+)\s*([:=])\s*([^\s,;&#]+)/gu;
61
+ const decodeUrlKey = (key) => {
62
+ try {
63
+ return decodeURIComponent(key.replaceAll("+", " "));
64
+ }
65
+ catch {
66
+ return key;
67
+ }
68
+ };
69
+ /** Removes credential-shaped fragments from user-visible diagnostic text. */
70
+ export const sanitizeDiagnosticText = (input) => {
71
+ const trimmed = input.trim();
72
+ const standaloneParameter = /^([^?&#:=\s]+)\s*[:=]\s*\S+/u.exec(trimmed);
73
+ if (pemPrivateKeyPattern.test(trimmed) ||
74
+ (standaloneParameter !== null &&
75
+ isSensitiveRawKey(decodeUrlKey(standaloneParameter[1])))) {
76
+ return REDACTED_VALUE;
77
+ }
78
+ return input
79
+ .replace(urlUserInfoPattern, `$1${REDACTED_VALUE}@`)
80
+ .replace(urlParameterPattern, (match, separator, encodedKey) => isSensitiveRawKey(decodeUrlKey(encodedKey))
81
+ ? `${separator}${encodedKey}=${encodeURIComponent(REDACTED_VALUE)}`
82
+ : match)
83
+ .replace(credentialHeaderValuePattern, REDACTED_VALUE)
84
+ .replace(authorizationValuePattern, REDACTED_VALUE)
85
+ .replace(jwtValuePattern, REDACTED_VALUE)
86
+ .replace(providerTokenPattern, REDACTED_VALUE)
87
+ .replace(awsAccessKeyPattern, REDACTED_VALUE)
88
+ .replace(embeddedParameterPattern, (match, prefix, encodedKey, separator) => isSensitiveRawKey(decodeUrlKey(encodedKey))
89
+ ? `${prefix}${encodedKey}${separator}${REDACTED_VALUE}`
90
+ : match);
91
+ };
92
+ const addCharacters = (state, count) => {
93
+ state.totalCharacters += count;
94
+ if (state.totalCharacters > MAX_RAW_TOTAL_CHARACTERS) {
95
+ throw new TypeError(`raw data exceeds the maximum total character count of ${MAX_RAW_TOTAL_CHARACTERS}`);
96
+ }
97
+ };
98
+ const addNodes = (state, count = 1) => {
99
+ state.nodes += count;
100
+ if (state.nodes > MAX_RAW_NODES) {
101
+ throw new TypeError(`raw data exceeds the maximum node count of ${MAX_RAW_NODES}`);
102
+ }
103
+ };
104
+ const addRedactedLeaf = (state) => {
105
+ addNodes(state);
106
+ addCharacters(state, REDACTED_VALUE.length);
107
+ return REDACTED_VALUE;
108
+ };
109
+ const sanitizeValue = (input, depth, state) => {
110
+ addNodes(state);
111
+ if (depth > MAX_RAW_DEPTH) {
112
+ throw new TypeError(`raw data exceeds the maximum depth of ${MAX_RAW_DEPTH}`);
113
+ }
114
+ if (input === null || typeof input === "boolean") {
115
+ return input;
116
+ }
117
+ if (typeof input === "string") {
118
+ if (input.length > MAX_RAW_STRING_LENGTH) {
119
+ throw new TypeError(`raw data strings must not exceed ${MAX_RAW_STRING_LENGTH} characters`);
120
+ }
121
+ const sanitized = sanitizeDiagnosticText(input);
122
+ if (sanitized.length > MAX_RAW_STRING_LENGTH) {
123
+ throw new TypeError(`sanitized raw data strings must not exceed ${MAX_RAW_STRING_LENGTH} characters`);
124
+ }
125
+ addCharacters(state, sanitized.length);
126
+ return sanitized;
127
+ }
128
+ if (typeof input === "number") {
129
+ if (!Number.isFinite(input)) {
130
+ throw new TypeError("raw data numbers must be finite");
131
+ }
132
+ return input;
133
+ }
134
+ if (typeof input !== "object") {
135
+ throw new TypeError(`raw data contains unsupported ${typeof input} value`);
136
+ }
137
+ if (state.ancestors.has(input)) {
138
+ throw new TypeError("raw data must not contain circular references");
139
+ }
140
+ state.ancestors.add(input);
141
+ try {
142
+ if (Array.isArray(input)) {
143
+ if (input.length > MAX_RAW_NODES - state.nodes) {
144
+ throw new TypeError(`raw data exceeds the maximum node count of ${MAX_RAW_NODES}`);
145
+ }
146
+ if (input.length === 2 &&
147
+ Object.hasOwn(input, 0) &&
148
+ Object.hasOwn(input, 1) &&
149
+ typeof input[0] === "string" &&
150
+ isSensitiveRawKey(input[0])) {
151
+ if (input[0].length > MAX_RAW_STRING_LENGTH) {
152
+ throw new TypeError(`raw data strings must not exceed ${MAX_RAW_STRING_LENGTH} characters`);
153
+ }
154
+ addNodes(state, 2);
155
+ addCharacters(state, input[0].length + REDACTED_VALUE.length);
156
+ return Object.freeze([input[0], REDACTED_VALUE]);
157
+ }
158
+ const output = [];
159
+ for (let index = 0; index < input.length; index += 1) {
160
+ if (!Object.hasOwn(input, index)) {
161
+ throw new TypeError("raw data arrays must not be sparse");
162
+ }
163
+ output.push(sanitizeValue(input[index], depth + 1, state));
164
+ }
165
+ return Object.freeze(output);
166
+ }
167
+ const prototype = Object.getPrototypeOf(input);
168
+ if (prototype !== Object.prototype && prototype !== null) {
169
+ throw new TypeError("raw data objects must be plain JSON objects");
170
+ }
171
+ const output = {};
172
+ for (const key in input) {
173
+ if (!Object.hasOwn(input, key))
174
+ continue;
175
+ if (key.length > MAX_RAW_KEY_LENGTH) {
176
+ throw new TypeError(`raw data keys must not exceed ${MAX_RAW_KEY_LENGTH} characters`);
177
+ }
178
+ addCharacters(state, key.length);
179
+ const sanitizedValue = isSensitiveRawKey(key)
180
+ ? addRedactedLeaf(state)
181
+ : sanitizeValue(input[key], depth + 1, state);
182
+ Object.defineProperty(output, key, {
183
+ configurable: false,
184
+ enumerable: true,
185
+ writable: false,
186
+ value: sanitizedValue,
187
+ });
188
+ }
189
+ return Object.freeze(output);
190
+ }
191
+ finally {
192
+ state.ancestors.delete(input);
193
+ }
194
+ };
195
+ /**
196
+ * Produces an immutable JSON value and redacts credential-shaped keys, header
197
+ * tuples, authorization strings, JWTs, URL userinfo, and signed query values.
198
+ * The retained result is bounded by depth, nodes, per-string size, and total
199
+ * key/string characters so many individually valid values cannot amplify it.
200
+ * Gateway adapters must still allowlist transport fields before retaining raw;
201
+ * this sanitizer is the final defense rather than permission to keep headers.
202
+ */
203
+ export const sanitizeRaw = (input) => sanitizeValue(input, 0, {
204
+ ancestors: new WeakSet(),
205
+ nodes: 0,
206
+ totalCharacters: 0,
207
+ });
208
+ //# sourceMappingURL=raw.js.map