@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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 A2C-SMCP contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,11 @@
1
+ import type { AskUserInteractionAnswer, AskUserInteractionQuestion, AskUserInteractionRequest, AskUserInteractionValue } from "./models.js";
2
+ export declare const ASK_USER_MAX_ANSWER_VALUES = 100;
3
+ export declare const ASK_USER_MAX_OPTIONS = 100;
4
+ export declare const ASK_USER_MAX_QUESTIONS = 20;
5
+ export declare const ASK_USER_MAX_QUESTION_ID_CHARACTERS = 256;
6
+ export declare const ASK_USER_MAX_REQUEST_ID_CHARACTERS = 256;
7
+ export declare const ASK_USER_MAX_TEXT_CHARACTERS = 2000;
8
+ export declare const isSafeAskUserQuestionId: (value: string) => boolean;
9
+ export declare const isAskUserInteractionValueCompatible: (question: AskUserInteractionQuestion, value: AskUserInteractionValue) => boolean;
10
+ export declare const getAskUserInteractionAnswerValidationError: (request: AskUserInteractionRequest, answer: AskUserInteractionAnswer) => string | undefined;
11
+ //# sourceMappingURL=ask-user.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ask-user.d.ts","sourceRoot":"","sources":["../src/ask-user.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,yBAAyB,EACzB,uBAAuB,EACxB,MAAM,aAAa,CAAC;AAErB,eAAO,MAAM,0BAA0B,MAAM,CAAC;AAC9C,eAAO,MAAM,oBAAoB,MAAM,CAAC;AACxC,eAAO,MAAM,sBAAsB,KAAK,CAAC;AACzC,eAAO,MAAM,mCAAmC,MAAM,CAAC;AACvD,eAAO,MAAM,kCAAkC,MAAM,CAAC;AACtD,eAAO,MAAM,4BAA4B,OAAQ,CAAC;AAIlD,eAAO,MAAM,uBAAuB,GAAI,OAAO,MAAM,KAAG,OACH,CAAC;AAKtD,eAAO,MAAM,mCAAmC,GAC9C,UAAU,0BAA0B,EACpC,OAAO,uBAAuB,KAC7B,OAYF,CAAC;AAEF,eAAO,MAAM,0CAA0C,GACrD,SAAS,yBAAyB,EAClC,QAAQ,wBAAwB,KAC/B,MAAM,GAAG,SA+BX,CAAC"}
@@ -0,0 +1,49 @@
1
+ export const ASK_USER_MAX_ANSWER_VALUES = 100;
2
+ export const ASK_USER_MAX_OPTIONS = 100;
3
+ export const ASK_USER_MAX_QUESTIONS = 20;
4
+ export const ASK_USER_MAX_QUESTION_ID_CHARACTERS = 256;
5
+ export const ASK_USER_MAX_REQUEST_ID_CHARACTERS = 256;
6
+ export const ASK_USER_MAX_TEXT_CHARACTERS = 2_000;
7
+ const reservedQuestionIds = new Set(["__proto__", "constructor", "prototype"]);
8
+ export const isSafeAskUserQuestionId = (value) => value.length > 0 && !reservedQuestionIds.has(value);
9
+ const valueParts = (value) => typeof value === "string" ? [value] : value;
10
+ export const isAskUserInteractionValueCompatible = (question, value) => {
11
+ if (question.multiple !== Array.isArray(value))
12
+ return false;
13
+ const parts = valueParts(value);
14
+ if (question.required &&
15
+ (parts.length === 0 || parts.some((part) => part.length === 0))) {
16
+ return false;
17
+ }
18
+ if (question.options.length === 0)
19
+ return true;
20
+ const allowedValues = new Set(question.options.map((option) => option.value));
21
+ return parts.every((part) => allowedValues.has(part));
22
+ };
23
+ export const getAskUserInteractionAnswerValidationError = (request, answer) => {
24
+ if (answer.action !== "submit")
25
+ return undefined;
26
+ const questions = new Map(request.questions.map((question) => [question.id, question]));
27
+ if (Object.keys(answer.answers).some((questionId) => !questions.has(questionId))) {
28
+ return "Interaction answers contain an unknown question";
29
+ }
30
+ for (const question of request.questions) {
31
+ if (!Object.hasOwn(answer.answers, question.id)) {
32
+ if (question.required) {
33
+ return "Interaction answers omit a required question";
34
+ }
35
+ continue;
36
+ }
37
+ const value = answer.answers[question.id];
38
+ if (typeof value !== "string" &&
39
+ (!Array.isArray(value) ||
40
+ value.some((candidate) => typeof candidate !== "string"))) {
41
+ return "Interaction answer values must be strings";
42
+ }
43
+ if (!isAskUserInteractionValueCompatible(question, value)) {
44
+ return "Interaction answer values do not match their question";
45
+ }
46
+ }
47
+ return undefined;
48
+ };
49
+ //# sourceMappingURL=ask-user.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ask-user.js","sourceRoot":"","sources":["../src/ask-user.ts"],"names":[],"mappings":"AAOA,MAAM,CAAC,MAAM,0BAA0B,GAAG,GAAG,CAAC;AAC9C,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,CAAC;AACxC,MAAM,CAAC,MAAM,sBAAsB,GAAG,EAAE,CAAC;AACzC,MAAM,CAAC,MAAM,mCAAmC,GAAG,GAAG,CAAC;AACvD,MAAM,CAAC,MAAM,kCAAkC,GAAG,GAAG,CAAC;AACtD,MAAM,CAAC,MAAM,4BAA4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AC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC"}
@@ -0,0 +1,141 @@
1
+ import type { AskUserInteractionAnswer, Capabilities, ChatError, ChatSnapshot, ChatUpdate, Conversation, ConversationId, Run, RunId } from "./models.js";
2
+ export type MaybePromise<T> = PromiseLike<T> | T;
3
+ export interface GatewayRequestOptions {
4
+ /**
5
+ * Unix epoch milliseconds by which the operation must settle. Adapters must
6
+ * return createGatewayDeadlineExceededError after the deadline, settle only
7
+ * once, and discard a late result. For subscribe this governs establishment;
8
+ * a late subscription must be disposed without notifying its observer.
9
+ */
10
+ readonly deadlineAt: number;
11
+ }
12
+ export declare const isGatewayDeadlineExceeded: (options: GatewayRequestOptions, now?: number) => boolean;
13
+ export declare const createGatewayDeadlineExceededError: (conversationId?: ConversationId) => ChatError;
14
+ export interface ListConversationsInput extends GatewayRequestOptions {
15
+ readonly cursor?: string | undefined;
16
+ readonly limit?: number | undefined;
17
+ }
18
+ export interface ConversationPage {
19
+ readonly conversations: readonly Conversation[];
20
+ readonly nextCursor?: string | undefined;
21
+ }
22
+ export type GatewayResult<T> = {
23
+ readonly ok: true;
24
+ readonly value: T;
25
+ } | {
26
+ readonly ok: false;
27
+ readonly error: ChatError;
28
+ };
29
+ export type GatewayOperation = "answerInteraction" | "interrupt" | "listConversations" | "loadHistory" | "sendText" | "subscribe";
30
+ /**
31
+ * Maps normalized capabilities to executable Gateway operations. Adapters use
32
+ * this before dispatch and return a structured `unsupported` GatewayResult
33
+ * when it returns false. Initial snapshot loading is always allowed; only a
34
+ * request carrying `previousCursor` is a `loadHistory` operation.
35
+ */
36
+ export declare const isGatewayOperationSupported: (capabilities: Capabilities, operation: GatewayOperation, run?: Run | null) => boolean;
37
+ export interface LoadConversationInput extends GatewayRequestOptions {
38
+ readonly conversationId: ConversationId;
39
+ readonly previousCursor?: string | undefined;
40
+ readonly limit?: number | undefined;
41
+ }
42
+ export interface SubscribeConversationInput extends GatewayRequestOptions {
43
+ readonly conversationId: ConversationId;
44
+ }
45
+ export interface SendTextInput extends GatewayRequestOptions {
46
+ readonly conversationId: ConversationId;
47
+ readonly text: string;
48
+ /** Optional stable ID supplied by a Runtime or host for idempotent mapping. */
49
+ readonly clientMessageId?: string | undefined;
50
+ }
51
+ export interface SendTextSuccess {
52
+ /** ID of the run started by the accepted message. */
53
+ readonly runId: RunId;
54
+ }
55
+ export interface InterruptRunInput extends GatewayRequestOptions {
56
+ readonly conversationId: ConversationId;
57
+ /** Protects against interrupting a newer run when the caller has a known ID. */
58
+ readonly runId?: RunId | undefined;
59
+ }
60
+ export interface InterruptRunSuccess {
61
+ /** ID of the cancellation operation, which is not the interrupted run ID. */
62
+ readonly cancellationId: string;
63
+ readonly interruptedRunId?: RunId | undefined;
64
+ }
65
+ export interface AnswerInteractionInput extends GatewayRequestOptions {
66
+ readonly conversationId: ConversationId;
67
+ readonly answer: AskUserInteractionAnswer;
68
+ }
69
+ export interface AnswerInteractionSuccess {
70
+ readonly requestId: string;
71
+ readonly revision: string;
72
+ }
73
+ export interface GatewayObserver {
74
+ next(update: ChatUpdate): void;
75
+ error?(error: ChatError): void;
76
+ }
77
+ export interface GatewaySubscription {
78
+ /**
79
+ * Becomes silent synchronously and settles cleanup no later than deadlineAt.
80
+ * Implementations must resolve at the deadline and abandon late transport
81
+ * cleanup rather than blocking a conversation switch.
82
+ */
83
+ dispose(options: GatewayRequestOptions): MaybePromise<void>;
84
+ }
85
+ /**
86
+ * Host- and transport-agnostic port consumed by Chat Runtime instances.
87
+ * Implementations own their connection and must become silent after dispose.
88
+ */
89
+ export interface ChatGateway {
90
+ /**
91
+ * Optional during migration. Runtime dispatches only when both the normalized
92
+ * capability and this method are present.
93
+ */
94
+ answerInteraction?(input: AnswerInteractionInput): Promise<GatewayResult<AnswerInteractionSuccess>>;
95
+ listConversations(input: ListConversationsInput): Promise<GatewayResult<ConversationPage>>;
96
+ loadConversation(input: LoadConversationInput): Promise<GatewayResult<ChatSnapshot>>;
97
+ subscribe(input: SubscribeConversationInput, observer: GatewayObserver): MaybePromise<GatewayResult<GatewaySubscription>>;
98
+ sendText(input: SendTextInput): Promise<GatewayResult<SendTextSuccess>>;
99
+ interrupt(input: InterruptRunInput): Promise<GatewayResult<InterruptRunSuccess>>;
100
+ /**
101
+ * Becomes silent synchronously, is idempotent, and settles no later than the
102
+ * supplied deadline even if transport cleanup never completes.
103
+ */
104
+ dispose(options: GatewayRequestOptions): MaybePromise<void>;
105
+ }
106
+ export type SessionPurpose = "connect" | "reconnect" | "request";
107
+ export type SessionOperation = "read" | "send" | "subscribe";
108
+ export interface SessionRequest {
109
+ readonly purpose: SessionPurpose;
110
+ readonly operation: SessionOperation;
111
+ readonly conversationId?: ConversationId | undefined;
112
+ }
113
+ export type SessionInvalidationReason = "expired" | "forbidden" | "rejected" | "unknown";
114
+ export interface SessionInvalidation {
115
+ readonly reason: SessionInvalidationReason;
116
+ readonly error: ChatError;
117
+ }
118
+ /**
119
+ * The session value is opaque to Protocol. A concrete Gateway defines its
120
+ * short-lived material while the host remains responsible for refresh/login.
121
+ */
122
+ export interface SessionProvider<TSession> {
123
+ getSession(request: SessionRequest): MaybePromise<TSession>;
124
+ onSessionInvalid?(invalidation: SessionInvalidation): MaybePromise<void>;
125
+ }
126
+ export declare const listConversationsInputSchema: import("./schema.js").RuntimeSchema<ListConversationsInput>;
127
+ export declare const gatewayRequestOptionsSchema: import("./schema.js").RuntimeSchema<GatewayRequestOptions>;
128
+ export declare const conversationPageSchema: import("./schema.js").RuntimeSchema<ConversationPage>;
129
+ export declare const conversationPageResultSchema: import("./schema.js").RuntimeSchema<GatewayResult<ConversationPage>>;
130
+ export declare const loadConversationInputSchema: import("./schema.js").RuntimeSchema<LoadConversationInput>;
131
+ export declare const loadConversationResultSchema: import("./schema.js").RuntimeSchema<GatewayResult<ChatSnapshot>>;
132
+ export declare const subscribeConversationInputSchema: import("./schema.js").RuntimeSchema<SubscribeConversationInput>;
133
+ export declare const sendTextInputSchema: import("./schema.js").RuntimeSchema<SendTextInput>;
134
+ export declare const sendTextResultSchema: import("./schema.js").RuntimeSchema<GatewayResult<SendTextSuccess>>;
135
+ export declare const interruptRunInputSchema: import("./schema.js").RuntimeSchema<InterruptRunInput>;
136
+ export declare const interruptRunResultSchema: import("./schema.js").RuntimeSchema<GatewayResult<InterruptRunSuccess>>;
137
+ export declare const answerInteractionInputSchema: import("./schema.js").RuntimeSchema<AnswerInteractionInput>;
138
+ export declare const answerInteractionResultSchema: import("./schema.js").RuntimeSchema<GatewayResult<AnswerInteractionSuccess>>;
139
+ export declare const sessionRequestSchema: import("./schema.js").RuntimeSchema<SessionRequest>;
140
+ export declare const sessionInvalidationSchema: import("./schema.js").RuntimeSchema<SessionInvalidation>;
141
+ //# sourceMappingURL=gateway.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gateway.d.ts","sourceRoot":"","sources":["../src/gateway.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EACV,wBAAwB,EACxB,YAAY,EACZ,SAAS,EACT,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,cAAc,EACd,GAAG,EACH,KAAK,EACN,MAAM,aAAa,CAAC;AAErB,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AAEjD,MAAM,WAAW,qBAAqB;IACpC;;;;;OAKG;IACH,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAED,eAAO,MAAM,yBAAyB,GACpC,SAAS,qBAAqB,EAC9B,MAAK,MAAmB,KACvB,OAAoC,CAAC;AAExC,eAAO,MAAM,kCAAkC,GAC7C,iBAAiB,cAAc,KAC9B,SAOF,CAAC;AAEF,MAAM,WAAW,sBAAuB,SAAQ,qBAAqB;IACnE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACrC;AAED,MAAM,WAAW,gBAAgB;I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AACF,eAAO,MAAM,2BAA2B,4DAEvC,CAAC;AACF,eAAO,MAAM,4BAA4B,kEAExC,CAAC;AACF,eAAO,MAAM,gCAAgC,iEAE5C,CAAC;AACF,eAAO,MAAM,mBAAmB,oDAA2C,CAAC;AAC5E,eAAO,MAAM,oBAAoB,qEAEhC,CAAC;AACF,eAAO,MAAM,uBAAuB,wDAEnC,CAAC;AACF,eAAO,MAAM,wBAAwB,yEAEpC,CAAC;AACF,eAAO,MAAM,4BAA4B,6DAExC,CAAC;AACF,eAAO,MAAM,6BAA6B,8EAEzC,CAAC;AACF,eAAO,MAAM,oBAAoB,qDAA4C,CAAC;AAC9E,eAAO,MAAM,yBAAyB,0DAErC,CAAC"}
@@ -0,0 +1,121 @@
1
+ import { z } from "zod/v4";
2
+ import { askUserInteractionAnswerParser, chatErrorParser, chatSnapshotParser, conversationParser, } from "./internal-schemas.js";
3
+ import { ASK_USER_MAX_REQUEST_ID_CHARACTERS } from "./ask-user.js";
4
+ import { createRuntimeSchema } from "./internal-runtime-schema.js";
5
+ export const isGatewayDeadlineExceeded = (options, now = Date.now()) => now >= options.deadlineAt;
6
+ export const createGatewayDeadlineExceededError = (conversationId) => {
7
+ const error = {
8
+ code: "timeout",
9
+ message: "Gateway operation exceeded its deadline",
10
+ retryable: true,
11
+ };
12
+ return conversationId === undefined ? error : { ...error, conversationId };
13
+ };
14
+ /**
15
+ * Maps normalized capabilities to executable Gateway operations. Adapters use
16
+ * this before dispatch and return a structured `unsupported` GatewayResult
17
+ * when it returns false. Initial snapshot loading is always allowed; only a
18
+ * request carrying `previousCursor` is a `loadHistory` operation.
19
+ */
20
+ export const isGatewayOperationSupported = (capabilities, operation, run) => {
21
+ switch (operation) {
22
+ case "answerInteraction":
23
+ return capabilities.answerInteraction === true;
24
+ case "interrupt":
25
+ return (capabilities.interrupt &&
26
+ run?.canInterrupt === true &&
27
+ run.status === "running");
28
+ case "listConversations":
29
+ return capabilities.listConversations;
30
+ case "loadHistory":
31
+ return capabilities.loadHistory;
32
+ case "sendText":
33
+ return capabilities.sendText;
34
+ case "subscribe":
35
+ return capabilities.liveUpdates;
36
+ }
37
+ };
38
+ const positiveLimitParser = z.number().int().positive();
39
+ const deadlineParser = z
40
+ .number()
41
+ .int()
42
+ .nonnegative()
43
+ .max(Number.MAX_SAFE_INTEGER);
44
+ const gatewayRequestOptionsParser = z.object({
45
+ deadlineAt: deadlineParser,
46
+ });
47
+ const listConversationsInputParser = z.object({
48
+ cursor: z.string().optional(),
49
+ limit: positiveLimitParser.optional(),
50
+ deadlineAt: deadlineParser,
51
+ });
52
+ const conversationPageParser = z.object({
53
+ conversations: z.array(conversationParser),
54
+ nextCursor: z.string().optional(),
55
+ });
56
+ const loadConversationInputParser = z.object({
57
+ conversationId: z.string().min(1),
58
+ previousCursor: z.string().optional(),
59
+ limit: positiveLimitParser.optional(),
60
+ deadlineAt: deadlineParser,
61
+ });
62
+ const subscribeConversationInputParser = z.object({
63
+ conversationId: z.string().min(1),
64
+ deadlineAt: deadlineParser,
65
+ });
66
+ const sendTextInputParser = z.object({
67
+ conversationId: z.string().min(1),
68
+ text: z.string().min(1),
69
+ clientMessageId: z.string().min(1).optional(),
70
+ deadlineAt: deadlineParser,
71
+ });
72
+ const sendTextSuccessParser = z.object({
73
+ runId: z.string().min(1),
74
+ });
75
+ const interruptRunInputParser = z.object({
76
+ conversationId: z.string().min(1),
77
+ runId: z.string().min(1).optional(),
78
+ deadlineAt: deadlineParser,
79
+ });
80
+ const interruptRunSuccessParser = z.object({
81
+ cancellationId: z.string().min(1),
82
+ interruptedRunId: z.string().min(1).optional(),
83
+ });
84
+ const answerInteractionInputParser = z.object({
85
+ conversationId: z.string().min(1),
86
+ answer: askUserInteractionAnswerParser,
87
+ deadlineAt: deadlineParser,
88
+ });
89
+ const answerInteractionSuccessParser = z.object({
90
+ requestId: z.string().min(1).max(ASK_USER_MAX_REQUEST_ID_CHARACTERS),
91
+ revision: z.string().min(1).max(ASK_USER_MAX_REQUEST_ID_CHARACTERS),
92
+ });
93
+ const gatewayResultParser = (valueParser) => z.discriminatedUnion("ok", [
94
+ z.object({ ok: z.literal(true), value: valueParser }),
95
+ z.object({ ok: z.literal(false), error: chatErrorParser }),
96
+ ]);
97
+ const sessionRequestParser = z.object({
98
+ purpose: z.enum(["connect", "reconnect", "request"]),
99
+ operation: z.enum(["read", "send", "subscribe"]),
100
+ conversationId: z.string().min(1).optional(),
101
+ });
102
+ const sessionInvalidationParser = z.object({
103
+ reason: z.enum(["expired", "forbidden", "rejected", "unknown"]),
104
+ error: chatErrorParser,
105
+ });
106
+ export const listConversationsInputSchema = createRuntimeSchema(listConversationsInputParser);
107
+ export const gatewayRequestOptionsSchema = createRuntimeSchema(gatewayRequestOptionsParser);
108
+ export const conversationPageSchema = createRuntimeSchema(conversationPageParser);
109
+ export const conversationPageResultSchema = createRuntimeSchema(gatewayResultParser(conversationPageParser));
110
+ export const loadConversationInputSchema = createRuntimeSchema(loadConversationInputParser);
111
+ export const loadConversationResultSchema = createRuntimeSchema(gatewayResultParser(chatSnapshotParser));
112
+ export const subscribeConversationInputSchema = createRuntimeSchema(subscribeConversationInputParser);
113
+ export const sendTextInputSchema = createRuntimeSchema(sendTextInputParser);
114
+ export const sendTextResultSchema = createRuntimeSchema(gatewayResultParser(sendTextSuccessParser));
115
+ export const interruptRunInputSchema = createRuntimeSchema(interruptRunInputParser);
116
+ export const interruptRunResultSchema = createRuntimeSchema(gatewayResultParser(interruptRunSuccessParser));
117
+ export const answerInteractionInputSchema = createRuntimeSchema(answerInteractionInputParser);
118
+ export const answerInteractionResultSchema = createRuntimeSchema(gatewayResultParser(answerInteractionSuccessParser));
119
+ export const sessionRequestSchema = createRuntimeSchema(sessionRequestParser);
120
+ export const sessionInvalidationSchema = createRuntimeSchema(sessionInvalidationParser);
121
+ //# sourceMappingURL=gateway.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gateway.js","sourceRoot":"","sources":["../src/gateway.ts"],"names":[],"mappings":"AAAA,OAA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_ID_CHARACTERS, ASK_USER_MAX_TEXT_CHARACTERS, getAskUserInteractionAnswerValidationError, isAskUserInteractionValueCompatible, isSafeAskUserQuestionId, } from "./ask-user.js";
3
+ export { agentEventSchema, askUserInteractionAnswerSchema, askUserInteractionRequestSchema, askUserInteractionResultSchema, capabilitiesSchema, chatErrorSchema, chatSnapshotSchema, chatUpdateSchema, compareTimelineItems, conversationSchema, getTimelineItemKey, hasCompatibleAgentEventMetadata, messageSchema, runSchema, timelineItemSchema, unknownEventSchema, } from "./models.js";
4
+ export { compareAgentEventTransitions } from "./ordering.js";
5
+ export type { AgentEvent, AgentEventStatus, AgentEventTransition, AgentEventTransitionPayload, AgentEventTransitionUpdate, AskUserInteractionAnswer, AskUserInteractionOption, AskUserInteractionQuestion, AskUserInteractionRequest, AskUserInteractionResult, AskUserInteractionValue, Capabilities, ChatError, ChatErrorCode, ChatSnapshot, ChatUpdate, Conversation, ConversationId, ContactMessageContent, FileMessageContent, GenericAgentEvent, GenericAgentEventTransitionPayload, MediaMessageContent, Message, MessageAuthor, MessageContent, MessageRole, Run, RunId, RunStatus, TimelineItem, TimelineItemId, TimelinePageInfo, TextMessageContent, ToolAgentEvent, ToolAgentEventTransitionPayload, ToolCall, ToolEventTransition, ToolReturn, UnknownEvent, UnknownMessageContent, UrlMessageContent, } from "./models.js";
6
+ export * from "./raw.js";
7
+ export { ProtocolValidationError } from "./schema.js";
8
+ export type { ProtocolParseResult, ProtocolValidationIssue, ProtocolValidationPathSegment, RuntimeSchema, } from "./schema.js";
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,OAAO,EACL,0BAA0B,EAC1B,oBAAoB,EACpB,sBAAsB,EACtB,mCAAmC,EACnC,kCAAkC,EAClC,4BAA4B,EAC5B,0CAA0C,EAC1C,mCAAmC,EACnC,uBAAuB,GACxB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,gBAAgB,EAChB,8BAA8B,EAC9B,+BAA+B,EAC/B,8BAA8B,EAC9B,kBAAkB,EAClB,eAAe,EACf,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,EAClB,kBAAkB,EAClB,+BAA+B,EAC/B,aAAa,EACb,SAAS,EACT,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,4BAA4B,EAAE,MAAM,eAAe,CAAC;AAC7D,YAAY,EACV,UAAU,EACV,gBAAgB,EAChB,oBAAoB,EACpB,2BAA2B,EAC3B,0BAA0B,EAC1B,wBAAwB,EACxB,wBAAwB,EACxB,0BAA0B,EAC1B,yBAAyB,EACzB,wBAAwB,EACxB,uBAAuB,EACvB,YAAY,EACZ,SAAS,EACT,aAAa,EACb,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,cAAc,EACd,qBAAqB,EACrB,kBAAkB,EAClB,iBAAiB,EACjB,kCAAkC,EAClC,mBAAmB,EACnB,OAAO,EACP,aAAa,EACb,cAAc,EACd,WAAW,EACX,GAAG,EACH,KAAK,EACL,SAAS,EACT,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,cAAc,EACd,+BAA+B,EAC/B,QAAQ,EACR,mBAAmB,EACnB,UAAU,EACV,YAAY,EACZ,qBAAqB,EACrB,iBAAiB,GAClB,MAAM,aAAa,CAAC;AACrB,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AACtD,YAAY,EACV,mBAAmB,EACnB,uBAAuB,EACvB,6BAA6B,EAC7B,aAAa,GACd,MAAM,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ export * from "./gateway.js";
2
+ export { ASK_USER_MAX_ANSWER_VALUES, ASK_USER_MAX_OPTIONS, ASK_USER_MAX_QUESTIONS, ASK_USER_MAX_QUESTION_ID_CHARACTERS, ASK_USER_MAX_REQUEST_ID_CHARACTERS, ASK_USER_MAX_TEXT_CHARACTERS, getAskUserInteractionAnswerValidationError, isAskUserInteractionValueCompatible, isSafeAskUserQuestionId, } from "./ask-user.js";
3
+ export { agentEventSchema, askUserInteractionAnswerSchema, askUserInteractionRequestSchema, askUserInteractionResultSchema, capabilitiesSchema, chatErrorSchema, chatSnapshotSchema, chatUpdateSchema, compareTimelineItems, conversationSchema, getTimelineItemKey, hasCompatibleAgentEventMetadata, messageSchema, runSchema, timelineItemSchema, unknownEventSchema, } from "./models.js";
4
+ export { compareAgentEventTransitions } from "./ordering.js";
5
+ export * from "./raw.js";
6
+ export { ProtocolValidationError } from "./schema.js";
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,OAAO,EACL,0BAA0B,EAC1B,oBAAoB,EACpB,sBAAsB,EACtB,mCAAmC,EACnC,kCAAkC,EAClC,4BAA4B,EAC5B,0CAA0C,EAC1C,mCAAmC,EACnC,uBAAuB,GACxB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,gBAAgB,EAChB,8BAA8B,EAC9B,+BAA+B,EAC/B,8BAA8B,EAC9B,kBAAkB,EAClB,eAAe,EACf,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,EAClB,kBAAkB,EAClB,+BAA+B,EAC/B,aAAa,EACb,SAAS,EACT,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,4BAA4B,EAAE,MAAM,eAAe,CAAC;AA6C7D,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { z } from "zod/v4";
2
+ import { type RuntimeSchema } from "./schema.js";
3
+ export declare const createRuntimeSchema: <T>(schema: z.ZodType<T>) => RuntimeSchema<T>;
4
+ //# sourceMappingURL=internal-runtime-schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal-runtime-schema.d.ts","sourceRoot":"","sources":["../src/internal-runtime-schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAIL,KAAK,aAAa,EACnB,MAAM,aAAa,CAAC;AAiCrB,eAAO,MAAM,mBAAmB,GAAI,CAAC,EACnC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KACnB,aAAa,CAAC,CAAC,CA+BjB,CAAC"}
@@ -0,0 +1,49 @@
1
+ import { ProtocolValidationError, } from "./schema.js";
2
+ const normalizePath = (path) => Object.freeze(path.map((segment) => typeof segment === "symbol"
3
+ ? (segment.description ?? segment.toString())
4
+ : segment));
5
+ const freezeRecursively = (value, seen = new WeakSet()) => {
6
+ if (value === null ||
7
+ (typeof value !== "object" && typeof value !== "function")) {
8
+ return value;
9
+ }
10
+ const objectValue = value;
11
+ if (seen.has(objectValue))
12
+ return value;
13
+ seen.add(objectValue);
14
+ for (const key of Reflect.ownKeys(objectValue)) {
15
+ const property = objectValue[key];
16
+ freezeRecursively(property, seen);
17
+ }
18
+ return Object.freeze(value);
19
+ };
20
+ export const createRuntimeSchema = (schema) => {
21
+ const safeParse = (input) => {
22
+ const result = schema.safeParse(input);
23
+ if (result.success) {
24
+ return Object.freeze({
25
+ success: true,
26
+ data: freezeRecursively(result.data),
27
+ });
28
+ }
29
+ const issues = result.error.issues.map((issue) => Object.freeze({
30
+ code: issue.code,
31
+ message: issue.message,
32
+ path: normalizePath(issue.path),
33
+ }));
34
+ return Object.freeze({
35
+ success: false,
36
+ error: new ProtocolValidationError(issues),
37
+ });
38
+ };
39
+ return Object.freeze({
40
+ parse: (input) => {
41
+ const result = safeParse(input);
42
+ if (!result.success)
43
+ throw result.error;
44
+ return result.data;
45
+ },
46
+ safeParse,
47
+ });
48
+ };
49
+ //# sourceMappingURL=internal-runtime-schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal-runtime-schema.js","sourceRoot":"","sources":["../src/internal-runtime-schema.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,uBAAuB,GAIxB,MAAM,aAAa,CAAC;AAErB,MAAM,aAAa,GAAG,CACpB,IAA4B,EACc,EAAE,CAC5C,MAAM,CAAC,MAAM,CACX,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CACnB,OAAO,OAAO,KAAK,QAAQ;IACzB,CAAC,CAAC,CAAC,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;IAC7C,CAAC,CAAC,OAAO,CACZ,CACF,CAAC;AAEJ,MAAM,iBAAiB,GAAG,CAAI,KAAQ,EAAE,OAAO,IAAI,OAAO,EAAU,EAAK,EAAE;IACzE,IACE,KAAK,KAAK,IAAI;QACd,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,UAAU,CAAC,EAC1D,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,WAAW,GAAG,KAAe,CAAC;IACpC,IAAI,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC;QAAE,OAAO,KAAK,CAAC;IACxC,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IAEtB,KAAK,MAAM,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;QAC/C,MAAM,QAAQ,GAAI,WAA4C,CAAC,GAAG,CAAC,CAAC;QACpE,iBAAiB,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IACpC,CAAC;IAED,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,MAAoB,EACF,EAAE;IACpB,MAAM,SAAS,GAAG,CAAC,KAAc,EAA0B,EAAE;QAC3D,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QACvC,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACnB,OAAO,MAAM,CAAC,MAAM,CAAC;gBACnB,OAAO,EAAE,IAAa;gBACtB,IAAI,EAAE,iBAAiB,CAAC,MAAM,CAAC,IAAI,CAAC;aACrC,CAAC,CAAC;QACL,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAC/C,MAAM,CAAC,MAAM,CAAC;YACZ,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,IAAI,EAAE,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC;SAChC,CAAC,CACH,CAAC;QACF,OAAO,MAAM,CAAC,MAAM,CAAC;YACnB,OAAO,EAAE,KAAc;YACvB,KAAK,EAAE,IAAI,uBAAuB,CAAC,MAAM,CAAC;SAC3C,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,KAAK,EAAE,CAAC,KAAc,EAAK,EAAE;YAC3B,MAAM,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;YAChC,IAAI,CAAC,MAAM,CAAC,OAAO;gBAAE,MAAM,MAAM,CAAC,KAAK,CAAC;YACxC,OAAO,MAAM,CAAC,IAAI,CAAC;QACrB,CAAC;QACD,SAAS;KACV,CAAC,CAAC;AACL,CAAC,CAAC"}
@@ -0,0 +1,16 @@
1
+ import { z } from "zod/v4";
2
+ import type { AgentEvent, AskUserInteractionAnswer, AskUserInteractionRequest, AskUserInteractionResult, Capabilities, ChatError, ChatSnapshot, ChatUpdate, Conversation, Message, Run, TimelineItem, UnknownEvent } from "./models.js";
3
+ export declare const conversationParser: z.ZodType<Conversation>;
4
+ export declare const chatErrorParser: z.ZodType<ChatError>;
5
+ export declare const messageParser: z.ZodType<Message>;
6
+ export declare const askUserInteractionRequestParser: z.ZodType<AskUserInteractionRequest>;
7
+ export declare const askUserInteractionAnswerParser: z.ZodType<AskUserInteractionAnswer>;
8
+ export declare const askUserInteractionResultParser: z.ZodType<AskUserInteractionResult>;
9
+ export declare const agentEventParser: z.ZodType<AgentEvent>;
10
+ export declare const unknownEventParser: z.ZodType<UnknownEvent>;
11
+ export declare const timelineItemParser: z.ZodType<TimelineItem>;
12
+ export declare const runParser: z.ZodType<Run>;
13
+ export declare const capabilitiesParser: z.ZodType<Capabilities>;
14
+ export declare const chatSnapshotParser: z.ZodType<ChatSnapshot>;
15
+ export declare const chatUpdateParser: z.ZodType<ChatUpdate>;
16
+ //# sourceMappingURL=internal-schemas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal-schemas.d.ts","sourceRoot":"","sources":["../src/internal-schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAY3B,OAAO,KAAK,EACV,UAAU,EAGV,wBAAwB,EAGxB,yBAAyB,EACzB,wBAAwB,EAExB,YAAY,EACZ,SAAS,EACT,YAAY,EACZ,UAAU,EACV,YAAY,EAMZ,OAAO,EAGP,GAAG,EAMH,YAAY,EAEZ,YAAY,EACb,MAAM,aAAa,CAAC;AAmBrB,eAAO,MAAM,kBAAkB,EAAE,CAAC,CAAC,OAAO,CAAC,YAAY,CAMrD,CAAC;AAyCH,eAAO,MAAM,eAAe,EAAE,CAAC,CAAC,OAAO,CAAC,SAAS,CAiB/C,CAAC;AAoBH,eAAO,MAAM,aAAa,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAY3C,CAAC;AA6JH,eAAO,MAAM,+BAA+B,EAAE,CAAC,CAAC,OAAO,CAAC,yBAAyB,CAU7E,CAAC;AAEL,eAAO,MAAM,8BAA8B,EAAE,CAAC,CAAC,OAAO,CAAC,wBAAwB,CAM3E,CAAC;AAEL,eAAO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