@ykurilov/agent-chat-server 0.98.1 → 0.100.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/CHANGELOG.md +33 -0
- package/README.md +8 -0
- package/dist/index.js +410 -3
- package/dist/index.js.map +1 -1
- package/dist/types/browser-chat/codec.d.ts +10 -0
- package/dist/types/browser-chat/index.d.ts +4 -0
- package/dist/types/browser-chat/input.d.ts +5 -0
- package/dist/types/browser-chat/types.d.ts +52 -0
- package/dist/types/index.d.ts +2 -0
- package/package.json +2 -2
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { BrowserChatSnapshot, ChatHistory, InMemoryChatSnapshot } from "@ykurilov/agent-chat-core";
|
|
2
|
+
export interface BrowserChatPayload {
|
|
3
|
+
version: 1;
|
|
4
|
+
internalChatId: string;
|
|
5
|
+
storage: InMemoryChatSnapshot;
|
|
6
|
+
}
|
|
7
|
+
export declare function createBrowserChatCodec(keyInput: string | Uint8Array, namespace: string, maxBytes: number): {
|
|
8
|
+
encode(ownerId: string, chatId: string, payload: BrowserChatPayload, history: ChatHistory): BrowserChatSnapshot;
|
|
9
|
+
decode(value: unknown, ownerId: string, chatId: string): BrowserChatPayload;
|
|
10
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { BrowserChatHandler, BrowserChatHandlerOptions } from "./types.js";
|
|
2
|
+
export type * from "./types.js";
|
|
3
|
+
/** An isolated service/storage per operation. No ordinary ChatStorage can be supplied. */
|
|
4
|
+
export declare function createBrowserChatHandler(options: BrowserChatHandlerOptions): BrowserChatHandler;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { IncomingUserMessage } from "@ykurilov/agent-chat-core";
|
|
2
|
+
import type { BrowserChatRequest } from "./types.js";
|
|
3
|
+
export declare const identifier: (value: unknown) => value is string;
|
|
4
|
+
export declare function plainUserMessage(value: unknown): IncomingUserMessage;
|
|
5
|
+
export declare function readBrowserRequest(request: Request, maxBytes: number, signal?: AbortSignal): Promise<BrowserChatRequest>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { AgentSettings, BrowserChatSnapshot, ChatCapabilities, CompactionSettings, IncomingUserMessage, ModelCatalog, ModelChoice, ResolvedUser, UsageRecord } from "@ykurilov/agent-chat-core";
|
|
2
|
+
export type BrowserChatOperation = {
|
|
3
|
+
type: "bootstrap" | "models" | "retry";
|
|
4
|
+
} | {
|
|
5
|
+
type: "message";
|
|
6
|
+
message: IncomingUserMessage;
|
|
7
|
+
} | {
|
|
8
|
+
type: "edit";
|
|
9
|
+
messageId: string;
|
|
10
|
+
message: IncomingUserMessage;
|
|
11
|
+
} | {
|
|
12
|
+
type: "regenerate" | "selectBranch";
|
|
13
|
+
messageId: string;
|
|
14
|
+
};
|
|
15
|
+
export interface BrowserChatRequest {
|
|
16
|
+
chatId: string;
|
|
17
|
+
snapshot: BrowserChatSnapshot | null;
|
|
18
|
+
operation: BrowserChatOperation;
|
|
19
|
+
}
|
|
20
|
+
/** Billing metadata only; no conversation, tool arguments, or persistent chat reference. */
|
|
21
|
+
export type BrowserChatUsage = Omit<UsageRecord, "chatId" | "messageId">;
|
|
22
|
+
export interface BrowserChatSettings {
|
|
23
|
+
catalog: ModelCatalog;
|
|
24
|
+
agent: Omit<AgentSettings, "helpers" | "browserTools" | "browserToolTimeoutMs" | "widgets" | "voices">;
|
|
25
|
+
defaultChoice?: ModelChoice;
|
|
26
|
+
env?: Record<string, string | undefined>;
|
|
27
|
+
compaction?: CompactionSettings | false;
|
|
28
|
+
capabilities?: Partial<ChatCapabilities>;
|
|
29
|
+
assertWithinLimit?: (ownerId: string, signal: AbortSignal) => Promise<void>;
|
|
30
|
+
/** Durable/idempotent numeric billing. Runs on Stop too, with its own 5s deadline signal. */
|
|
31
|
+
onUsage?: (usage: BrowserChatUsage, signal: AbortSignal) => Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
export interface BrowserChatHandlerOptions {
|
|
34
|
+
namespace: string;
|
|
35
|
+
snapshotKey: string | Uint8Array;
|
|
36
|
+
resolveUser: (request: Request) => Promise<ResolvedUser>;
|
|
37
|
+
configure: (ownerId: string) => BrowserChatSettings | Promise<BrowserChatSettings>;
|
|
38
|
+
allowedOrigins?: string[];
|
|
39
|
+
maxRequestBytes?: number;
|
|
40
|
+
maxSnapshotBytes?: number;
|
|
41
|
+
maxTurnMs?: number;
|
|
42
|
+
checkpointIntervalMs?: number;
|
|
43
|
+
maxConcurrentTurnsPerUser?: number;
|
|
44
|
+
/** Diagnostics have codes only. The SDK never logs raw provider errors or conversation data here. */
|
|
45
|
+
onError?: (code: "configuration" | "snapshot" | "turn" | "usage" | "limit") => void;
|
|
46
|
+
}
|
|
47
|
+
export interface BrowserChatHandler {
|
|
48
|
+
fetch(request: Request): Promise<Response>;
|
|
49
|
+
/** Active requests only; no retained chat/session registry. */
|
|
50
|
+
readonly activeRequests: number;
|
|
51
|
+
close(): Promise<void>;
|
|
52
|
+
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -6,3 +6,5 @@ export { turnRefusalResponse } from "./subject-chat-route.js";
|
|
|
6
6
|
export type { SubjectChatSettings, SubjectChatsResolver } from "./subject-chat-route.js";
|
|
7
7
|
export type { NewChatGreetingResolver } from "./new-chat-greeting.js";
|
|
8
8
|
export type { HistoryPartReference, HistoryView } from "./history-view.js";
|
|
9
|
+
export { createBrowserChatHandler } from "./browser-chat/index.js";
|
|
10
|
+
export type { BrowserChatHandler, BrowserChatHandlerOptions, BrowserChatSettings, BrowserChatUsage, BrowserChatOperation, BrowserChatRequest } from "./browser-chat/types.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ykurilov/agent-chat-server",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.100.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"ai": "7.0.122",
|
|
53
|
-
"@ykurilov/agent-chat-core": "0.
|
|
53
|
+
"@ykurilov/agent-chat-core": "0.100.0"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
56
|
"hono": "^4.13.10"
|