@chatcops/core 0.4.0 → 0.6.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/agent/chat.d.ts +13 -0
- package/dist/agent/chat.d.ts.map +1 -0
- package/dist/agent/chat.js +42 -0
- package/dist/agent/chat.js.map +1 -0
- package/dist/agent/errors.d.ts +14 -0
- package/dist/agent/errors.d.ts.map +1 -0
- package/dist/agent/errors.js +24 -0
- package/dist/agent/errors.js.map +1 -0
- package/dist/agent/index.d.ts +5 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +5 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/agent/run-turn.d.ts +79 -0
- package/dist/agent/run-turn.d.ts.map +1 -0
- package/dist/agent/run-turn.js +400 -0
- package/dist/agent/run-turn.js.map +1 -0
- package/dist/agent/tool-registry.d.ts +30 -0
- package/dist/agent/tool-registry.d.ts.map +1 -0
- package/dist/agent/tool-registry.js +66 -0
- package/dist/agent/tool-registry.js.map +1 -0
- package/dist/analytics/collector.d.ts +2 -0
- package/dist/analytics/collector.d.ts.map +1 -1
- package/dist/analytics/collector.js +16 -10
- package/dist/analytics/collector.js.map +1 -1
- package/dist/analytics/index.d.ts +2 -0
- package/dist/analytics/index.d.ts.map +1 -1
- package/dist/analytics/index.js +2 -0
- package/dist/analytics/index.js.map +1 -1
- package/dist/analytics/names.d.ts +21 -0
- package/dist/analytics/names.d.ts.map +1 -0
- package/dist/analytics/names.js +41 -0
- package/dist/analytics/names.js.map +1 -0
- package/dist/analytics/sink.d.ts +27 -0
- package/dist/analytics/sink.d.ts.map +1 -0
- package/dist/analytics/sink.js +109 -0
- package/dist/analytics/sink.js.map +1 -0
- package/dist/conversation/index.d.ts +1 -0
- package/dist/conversation/index.d.ts.map +1 -1
- package/dist/conversation/index.js.map +1 -1
- package/dist/conversation/manager.d.ts +65 -6
- package/dist/conversation/manager.d.ts.map +1 -1
- package/dist/conversation/manager.js +110 -34
- package/dist/conversation/manager.js.map +1 -1
- package/dist/conversation/store.d.ts +6 -5
- package/dist/conversation/store.d.ts.map +1 -1
- package/dist/conversation/store.js +4 -0
- package/dist/conversation/store.js.map +1 -1
- package/dist/index.d.ts +21 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -2
- package/dist/index.js.map +1 -1
- package/dist/knowledge/base.d.ts +8 -0
- package/dist/knowledge/base.d.ts.map +1 -1
- package/dist/knowledge/tokenize.d.ts.map +1 -1
- package/dist/knowledge/tokenize.js +4 -4
- package/dist/knowledge/tokenize.js.map +1 -1
- package/dist/limits/budget.d.ts +84 -0
- package/dist/limits/budget.d.ts.map +1 -0
- package/dist/limits/budget.js +114 -0
- package/dist/limits/budget.js.map +1 -0
- package/dist/limits/rate-limit.d.ts +53 -0
- package/dist/limits/rate-limit.d.ts.map +1 -0
- package/dist/limits/rate-limit.js +68 -0
- package/dist/limits/rate-limit.js.map +1 -0
- package/dist/logger.d.ts +36 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +40 -0
- package/dist/logger.js.map +1 -0
- package/dist/parts.d.ts +9 -0
- package/dist/parts.d.ts.map +1 -0
- package/dist/parts.js +17 -0
- package/dist/parts.js.map +1 -0
- package/dist/protocol/ai-sdk.d.ts +27 -0
- package/dist/protocol/ai-sdk.d.ts.map +1 -0
- package/dist/protocol/ai-sdk.js +127 -0
- package/dist/protocol/ai-sdk.js.map +1 -0
- package/dist/protocol/errors.d.ts +10 -0
- package/dist/protocol/errors.d.ts.map +1 -0
- package/dist/protocol/errors.js +42 -0
- package/dist/protocol/errors.js.map +1 -0
- package/dist/protocol/index.d.ts +9 -0
- package/dist/protocol/index.d.ts.map +1 -0
- package/dist/protocol/index.js +6 -0
- package/dist/protocol/index.js.map +1 -0
- package/dist/protocol/legacy.d.ts +18 -0
- package/dist/protocol/legacy.d.ts.map +1 -0
- package/dist/protocol/legacy.js +41 -0
- package/dist/protocol/legacy.js.map +1 -0
- package/dist/protocol/sse.d.ts +10 -0
- package/dist/protocol/sse.d.ts.map +1 -0
- package/dist/protocol/sse.js +15 -0
- package/dist/protocol/sse.js.map +1 -0
- package/dist/protocol/v1.d.ts +140 -0
- package/dist/protocol/v1.d.ts.map +1 -0
- package/dist/protocol/v1.js +15 -0
- package/dist/protocol/v1.js.map +1 -0
- package/dist/providers/base.d.ts +13 -28
- package/dist/providers/base.d.ts.map +1 -1
- package/dist/providers/base.js +36 -47
- package/dist/providers/base.js.map +1 -1
- package/dist/providers/claude.d.ts +41 -6
- package/dist/providers/claude.d.ts.map +1 -1
- package/dist/providers/claude.js +223 -96
- package/dist/providers/claude.js.map +1 -1
- package/dist/providers/gemini.d.ts +18 -3
- package/dist/providers/gemini.d.ts.map +1 -1
- package/dist/providers/gemini.js +208 -91
- package/dist/providers/gemini.js.map +1 -1
- package/dist/providers/history.d.ts +52 -0
- package/dist/providers/history.d.ts.map +1 -0
- package/dist/providers/history.js +212 -0
- package/dist/providers/history.js.map +1 -0
- package/dist/providers/index.d.ts +5 -5
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +5 -4
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/openai.d.ts +28 -6
- package/dist/providers/openai.d.ts.map +1 -1
- package/dist/providers/openai.js +213 -113
- package/dist/providers/openai.js.map +1 -1
- package/dist/providers/registry.d.ts +7 -0
- package/dist/providers/registry.d.ts.map +1 -0
- package/dist/providers/registry.js +12 -0
- package/dist/providers/registry.js.map +1 -0
- package/dist/providers/schema.d.ts +16 -0
- package/dist/providers/schema.d.ts.map +1 -0
- package/dist/providers/schema.js +80 -0
- package/dist/providers/schema.js.map +1 -0
- package/dist/providers/tool-execution.d.ts +13 -0
- package/dist/providers/tool-execution.d.ts.map +1 -1
- package/dist/providers/tool-execution.js +49 -13
- package/dist/providers/tool-execution.js.map +1 -1
- package/dist/providers/types.d.ts +89 -0
- package/dist/providers/types.d.ts.map +1 -0
- package/dist/providers/types.js +2 -0
- package/dist/providers/types.js.map +1 -0
- package/dist/retrieval/citations.d.ts +44 -0
- package/dist/retrieval/citations.d.ts.map +1 -0
- package/dist/retrieval/citations.js +97 -0
- package/dist/retrieval/citations.js.map +1 -0
- package/dist/retrieval/cohere-reranker.d.ts +13 -0
- package/dist/retrieval/cohere-reranker.d.ts.map +1 -0
- package/dist/retrieval/cohere-reranker.js +33 -0
- package/dist/retrieval/cohere-reranker.js.map +1 -0
- package/dist/retrieval/gemini-embedder.d.ts +26 -0
- package/dist/retrieval/gemini-embedder.d.ts.map +1 -0
- package/dist/retrieval/gemini-embedder.js +36 -0
- package/dist/retrieval/gemini-embedder.js.map +1 -0
- package/dist/retrieval/http.d.ts +20 -0
- package/dist/retrieval/http.d.ts.map +1 -0
- package/dist/retrieval/http.js +68 -0
- package/dist/retrieval/http.js.map +1 -0
- package/dist/retrieval/index.d.ts +14 -0
- package/dist/retrieval/index.d.ts.map +1 -0
- package/dist/retrieval/index.js +13 -0
- package/dist/retrieval/index.js.map +1 -0
- package/dist/retrieval/knowledge.d.ts +16 -0
- package/dist/retrieval/knowledge.d.ts.map +1 -0
- package/dist/retrieval/knowledge.js +21 -0
- package/dist/retrieval/knowledge.js.map +1 -0
- package/dist/retrieval/openai-embedder.d.ts +25 -0
- package/dist/retrieval/openai-embedder.d.ts.map +1 -0
- package/dist/retrieval/openai-embedder.js +30 -0
- package/dist/retrieval/openai-embedder.js.map +1 -0
- package/dist/retrieval/query.d.ts +8 -0
- package/dist/retrieval/query.d.ts.map +1 -0
- package/dist/retrieval/query.js +19 -0
- package/dist/retrieval/query.js.map +1 -0
- package/dist/retrieval/retrievers.d.ts +30 -0
- package/dist/retrieval/retrievers.d.ts.map +1 -0
- package/dist/retrieval/retrievers.js +89 -0
- package/dist/retrieval/retrievers.js.map +1 -0
- package/dist/retrieval/sources.d.ts +16 -0
- package/dist/retrieval/sources.d.ts.map +1 -0
- package/dist/retrieval/sources.js +37 -0
- package/dist/retrieval/sources.js.map +1 -0
- package/dist/retrieval/types.d.ts +50 -0
- package/dist/retrieval/types.d.ts.map +1 -0
- package/dist/retrieval/types.js +2 -0
- package/dist/retrieval/types.js.map +1 -0
- package/dist/retrieval/voyage-embedder.d.ts +33 -0
- package/dist/retrieval/voyage-embedder.d.ts.map +1 -0
- package/dist/retrieval/voyage-embedder.js +33 -0
- package/dist/retrieval/voyage-embedder.js.map +1 -0
- package/dist/retrieval/voyage-reranker.d.ts +13 -0
- package/dist/retrieval/voyage-reranker.d.ts.map +1 -0
- package/dist/retrieval/voyage-reranker.js +38 -0
- package/dist/retrieval/voyage-reranker.js.map +1 -0
- package/dist/retrieval/workers-ai-embedder.d.ts +21 -0
- package/dist/retrieval/workers-ai-embedder.d.ts.map +1 -0
- package/dist/retrieval/workers-ai-embedder.js +42 -0
- package/dist/retrieval/workers-ai-embedder.js.map +1 -0
- package/dist/retrieval/workers-ai-reranker.d.ts +11 -0
- package/dist/retrieval/workers-ai-reranker.d.ts.map +1 -0
- package/dist/retrieval/workers-ai-reranker.js +54 -0
- package/dist/retrieval/workers-ai-reranker.js.map +1 -0
- package/dist/storage/adapt.d.ts +15 -0
- package/dist/storage/adapt.d.ts.map +1 -0
- package/dist/storage/adapt.js +83 -0
- package/dist/storage/adapt.js.map +1 -0
- package/dist/storage/errors.d.ts +18 -0
- package/dist/storage/errors.d.ts.map +1 -0
- package/dist/storage/errors.js +28 -0
- package/dist/storage/errors.js.map +1 -0
- package/dist/storage/index.d.ts +6 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +5 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/memory-vectors.d.ts +22 -0
- package/dist/storage/memory-vectors.d.ts.map +1 -0
- package/dist/storage/memory-vectors.js +140 -0
- package/dist/storage/memory-vectors.js.map +1 -0
- package/dist/storage/memory.d.ts +24 -0
- package/dist/storage/memory.d.ts.map +1 -0
- package/dist/storage/memory.js +265 -0
- package/dist/storage/memory.js.map +1 -0
- package/dist/storage/types.d.ts +188 -0
- package/dist/storage/types.d.ts.map +1 -0
- package/dist/storage/types.js +2 -0
- package/dist/storage/types.js.map +1 -0
- package/dist/testing/conformance.d.ts +30 -0
- package/dist/testing/conformance.d.ts.map +1 -0
- package/dist/testing/conformance.js +505 -0
- package/dist/testing/conformance.js.map +1 -0
- package/dist/testing/index.d.ts +3 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +5 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/provider.d.ts +47 -0
- package/dist/testing/provider.d.ts.map +1 -0
- package/dist/testing/provider.js +83 -0
- package/dist/testing/provider.js.map +1 -0
- package/dist/tools/base.d.ts +14 -4
- package/dist/tools/base.d.ts.map +1 -1
- package/dist/tools/base.js +4 -2
- package/dist/tools/base.js.map +1 -1
- package/dist/tools/lead-capture.d.ts +4 -2
- package/dist/tools/lead-capture.d.ts.map +1 -1
- package/dist/tools/lead-capture.js +7 -2
- package/dist/tools/lead-capture.js.map +1 -1
- package/dist/types.d.ts +146 -7
- package/dist/types.d.ts.map +1 -1
- package/package.json +51 -3
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import type { JSONSchema, PageContext, ToolExecutor } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Version 1 of the stream between the widget and the server.
|
|
4
|
+
*
|
|
5
|
+
* The widget asks for it with `"protocol": 1` in the request body. A body
|
|
6
|
+
* field rather than a header, because servers before 0.6 only allow
|
|
7
|
+
* `Content-Type` in their CORS preflight. A server that doesn't know the field
|
|
8
|
+
* ignores it and answers in the old format, and the widget tells the two apart
|
|
9
|
+
* by the first part: v1 always starts with `start`.
|
|
10
|
+
*
|
|
11
|
+
* Every part is one SSE line, `data: <json>`. Clients ignore part types they
|
|
12
|
+
* don't know, so adding a part is not a version change; changing or removing
|
|
13
|
+
* one is.
|
|
14
|
+
*/
|
|
15
|
+
export declare const PROTOCOL_VERSION: 1;
|
|
16
|
+
export type WireErrorCode = 'invalid_request' | 'session_required' | 'token_expired' | 'conversation_mismatch' | 'turnstile_failed' | 'origin_not_allowed' | 'conversation_busy' | 'payload_too_large' | 'rate_limited' | 'provider_unavailable' | 'provider_error' | 'tool_error' | 'budget_exceeded' | 'content_filtered' | 'internal_error' | 'timeout';
|
|
17
|
+
export type WireFinishReason = 'stop' | 'length' | 'client-tool-calls' | 'approval-required' | 'handoff' | 'error' | 'aborted';
|
|
18
|
+
export interface WireAgent {
|
|
19
|
+
name: string;
|
|
20
|
+
avatarUrl?: string;
|
|
21
|
+
}
|
|
22
|
+
export type WirePart = {
|
|
23
|
+
type: 'start';
|
|
24
|
+
protocol: typeof PROTOCOL_VERSION;
|
|
25
|
+
conversationId: string;
|
|
26
|
+
/** The id the server saves the reply under. */
|
|
27
|
+
messageId: string;
|
|
28
|
+
resumed?: boolean;
|
|
29
|
+
/** Optional server features the widget can turn on. */
|
|
30
|
+
capabilities?: {
|
|
31
|
+
session?: boolean;
|
|
32
|
+
};
|
|
33
|
+
} | {
|
|
34
|
+
type: 'text-start';
|
|
35
|
+
id: string;
|
|
36
|
+
} | {
|
|
37
|
+
type: 'text-delta';
|
|
38
|
+
id: string;
|
|
39
|
+
delta: string;
|
|
40
|
+
} | {
|
|
41
|
+
type: 'text-end';
|
|
42
|
+
id: string;
|
|
43
|
+
} | {
|
|
44
|
+
type: 'source';
|
|
45
|
+
sourceId: string;
|
|
46
|
+
url: string;
|
|
47
|
+
title?: string;
|
|
48
|
+
snippet?: string;
|
|
49
|
+
} | {
|
|
50
|
+
type: 'tool-call';
|
|
51
|
+
toolCallId: string;
|
|
52
|
+
toolName: string;
|
|
53
|
+
input: unknown;
|
|
54
|
+
executor: ToolExecutor;
|
|
55
|
+
needsApproval?: boolean;
|
|
56
|
+
title?: string;
|
|
57
|
+
} | {
|
|
58
|
+
type: 'tool-result';
|
|
59
|
+
toolCallId: string;
|
|
60
|
+
output?: unknown;
|
|
61
|
+
error?: string;
|
|
62
|
+
} | {
|
|
63
|
+
type: 'lead-captured';
|
|
64
|
+
lead: Record<string, unknown>;
|
|
65
|
+
} | {
|
|
66
|
+
type: 'handoff';
|
|
67
|
+
status: 'requested' | 'queued' | 'connected' | 'ended';
|
|
68
|
+
agent?: WireAgent;
|
|
69
|
+
pollAfterMs?: number;
|
|
70
|
+
} | {
|
|
71
|
+
type: 'agent-message';
|
|
72
|
+
messageId: string;
|
|
73
|
+
text: string;
|
|
74
|
+
agent: WireAgent;
|
|
75
|
+
timestamp: number;
|
|
76
|
+
} | {
|
|
77
|
+
type: 'suggestions';
|
|
78
|
+
items: string[];
|
|
79
|
+
} | {
|
|
80
|
+
type: 'error';
|
|
81
|
+
code: WireErrorCode;
|
|
82
|
+
message?: string;
|
|
83
|
+
retryable: boolean;
|
|
84
|
+
retryAfterMs?: number;
|
|
85
|
+
scope?: 'conversation' | 'session' | 'ip' | 'global';
|
|
86
|
+
} | {
|
|
87
|
+
type: 'finish';
|
|
88
|
+
reason: WireFinishReason;
|
|
89
|
+
/** Only sent when the server is configured to expose usage. */
|
|
90
|
+
usage?: {
|
|
91
|
+
inputTokens: number;
|
|
92
|
+
outputTokens: number;
|
|
93
|
+
};
|
|
94
|
+
pendingToolCalls?: string[];
|
|
95
|
+
resumeToken?: string;
|
|
96
|
+
};
|
|
97
|
+
export type WirePartType = WirePart['type'];
|
|
98
|
+
/** A tool the page offers, run in the browser (page tools). */
|
|
99
|
+
export interface ClientToolManifest {
|
|
100
|
+
name: string;
|
|
101
|
+
description: string;
|
|
102
|
+
inputSchema: JSONSchema;
|
|
103
|
+
needsApproval?: boolean;
|
|
104
|
+
title?: string;
|
|
105
|
+
}
|
|
106
|
+
export interface ChatRequestV1 {
|
|
107
|
+
protocol: typeof PROTOCOL_VERSION;
|
|
108
|
+
conversationId: string;
|
|
109
|
+
/** Absent when the request only sends tool results or approvals. */
|
|
110
|
+
message?: string;
|
|
111
|
+
messageId?: string;
|
|
112
|
+
/** `true` is the 0.5 form and regenerates the latest reply. */
|
|
113
|
+
regenerate?: boolean | {
|
|
114
|
+
assistantMessageId: string;
|
|
115
|
+
};
|
|
116
|
+
toolResults?: Array<{
|
|
117
|
+
toolCallId: string;
|
|
118
|
+
output?: unknown;
|
|
119
|
+
error?: string;
|
|
120
|
+
}>;
|
|
121
|
+
toolApprovals?: Array<{
|
|
122
|
+
toolCallId: string;
|
|
123
|
+
approved: boolean;
|
|
124
|
+
reason?: string;
|
|
125
|
+
}>;
|
|
126
|
+
resumeToken?: string;
|
|
127
|
+
clientTools?: ClientToolManifest[];
|
|
128
|
+
pageContext?: PageContext;
|
|
129
|
+
locale?: string;
|
|
130
|
+
userData?: Record<string, string>;
|
|
131
|
+
}
|
|
132
|
+
/** The JSON body of an error answered before the stream starts. */
|
|
133
|
+
export interface WireErrorBody {
|
|
134
|
+
error: {
|
|
135
|
+
code: WireErrorCode;
|
|
136
|
+
message?: string;
|
|
137
|
+
retryAfterMs?: number;
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=v1.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v1.d.ts","sourceRoot":"","sources":["../../src/protocol/v1.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEzE;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,gBAAgB,EAAG,CAAU,CAAC;AAE3C,MAAM,MAAM,aAAa,GAErB,iBAAiB,GACjB,kBAAkB,GAClB,eAAe,GACf,uBAAuB,GACvB,kBAAkB,GAClB,oBAAoB,GACpB,mBAAmB,GACnB,mBAAmB,GACnB,cAAc,GACd,sBAAsB,GAEtB,gBAAgB,GAChB,YAAY,GACZ,iBAAiB,GACjB,kBAAkB,GAClB,gBAAgB,GAChB,SAAS,CAAC;AAEd,MAAM,MAAM,gBAAgB,GACxB,MAAM,GACN,QAAQ,GACR,mBAAmB,GACnB,mBAAmB,GACnB,SAAS,GACT,OAAO,GACP,SAAS,CAAC;AAEd,MAAM,WAAW,SAAS;IACxB,IAA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,CAAC;CAChB;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,OAAO,gBAAgB,CAAC;IAClC,cAAc,EAAE,MAAM,CAAC;IACvB,oEAAoE;IACpE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,+DAA+D;IAC/D,UAAU,CAAC,EAAE,OAAO,GAAG;QAAE,kBAAkB,EAAE,MAAM,CAAA;KAAE,CAAC;IACtD,WAAW,CAAC,EAAE,KAAK,CAAC;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,OAAO,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC9E,aAAa,CAAC,EAAE,KAAK,CAAC;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,OAAO,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAClF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,kBAAkB,EAAE,CAAC;IACnC,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnC;AAED,mEAAmE;AACnE,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE;QACL,IAAI,EAAE,aAAa,CAAC;QACpB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB,CAAC;CACH"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Version 1 of the stream between the widget and the server.
|
|
3
|
+
*
|
|
4
|
+
* The widget asks for it with `"protocol": 1` in the request body. A body
|
|
5
|
+
* field rather than a header, because servers before 0.6 only allow
|
|
6
|
+
* `Content-Type` in their CORS preflight. A server that doesn't know the field
|
|
7
|
+
* ignores it and answers in the old format, and the widget tells the two apart
|
|
8
|
+
* by the first part: v1 always starts with `start`.
|
|
9
|
+
*
|
|
10
|
+
* Every part is one SSE line, `data: <json>`. Clients ignore part types they
|
|
11
|
+
* don't know, so adding a part is not a version change; changing or removing
|
|
12
|
+
* one is.
|
|
13
|
+
*/
|
|
14
|
+
export const PROTOCOL_VERSION = 1;
|
|
15
|
+
//# sourceMappingURL=v1.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v1.js","sourceRoot":"","sources":["../../src/protocol/v1.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAU,CAAC"}
|
package/dist/providers/base.d.ts
CHANGED
|
@@ -1,40 +1,29 @@
|
|
|
1
|
+
import type { Logger } from '../logger.js';
|
|
1
2
|
import type { Tool as GeminiTool } from '@google/genai';
|
|
2
|
-
import type { ChatMessage,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
chat(params: ProviderChatParams): AsyncGenerator<string>;
|
|
6
|
-
chatSync(params: ProviderChatParams): Promise<string>;
|
|
7
|
-
}
|
|
3
|
+
import type { ChatMessage, ProviderConfig, ToolDefinition } from '../types.js';
|
|
4
|
+
import type { AIProvider } from './types.js';
|
|
5
|
+
export type { AIProvider } from './types.js';
|
|
8
6
|
/** Output token limit used when neither the server config nor the request sets one. */
|
|
9
7
|
export declare const DEFAULT_MAX_TOKENS = 4096;
|
|
8
|
+
/**
|
|
9
|
+
* True for a provider object, false for a provider config. A config never
|
|
10
|
+
* has functions, so an object with a `step` or `chat` function is a provider.
|
|
11
|
+
*/
|
|
12
|
+
export declare function isAIProvider(value: unknown): value is AIProvider;
|
|
10
13
|
export declare function createProvider(config: ProviderConfig): Promise<AIProvider>;
|
|
11
14
|
export declare function toProviderMessages(messages: ChatMessage[]): Array<{
|
|
12
15
|
role: string;
|
|
13
16
|
content: string;
|
|
14
17
|
}>;
|
|
15
|
-
export
|
|
16
|
-
role: 'user' | 'assistant';
|
|
17
|
-
content: string;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Turns stored messages into a history every provider accepts: it starts with
|
|
21
|
-
* a user turn and alternates between user and assistant.
|
|
22
|
-
*
|
|
23
|
-
* - System messages and empty messages are dropped.
|
|
24
|
-
* - Leading assistant turns are dropped (history trimming can leave one first).
|
|
25
|
-
* - Consecutive turns with the same role are merged with a blank line, for
|
|
26
|
-
* example a user message saved before a provider call that then failed.
|
|
27
|
-
*/
|
|
28
|
-
export declare function normalizeHistory(messages: ChatMessage[]): NormalizedMessage[];
|
|
18
|
+
export { normalizeHistory, normalizeTurns, trimHistory, estimateTokens, type NormalizedMessage, type NormalizedTurn, type TurnPart, } from './history.js';
|
|
29
19
|
/** Logs a configuration warning once per process. */
|
|
30
|
-
export declare function warnOnce(key: string, message: string): void;
|
|
20
|
+
export declare function warnOnce(logger: Logger, key: string, message: string): void;
|
|
31
21
|
export declare function toClaudeTools(tools: ToolDefinition[]): {
|
|
32
22
|
name: string;
|
|
33
23
|
description: string;
|
|
34
24
|
input_schema: {
|
|
35
25
|
type: "object";
|
|
36
|
-
|
|
37
|
-
required: string[];
|
|
26
|
+
[key: string]: unknown;
|
|
38
27
|
};
|
|
39
28
|
}[];
|
|
40
29
|
export declare function toOpenAITools(tools: ToolDefinition[]): {
|
|
@@ -42,11 +31,7 @@ export declare function toOpenAITools(tools: ToolDefinition[]): {
|
|
|
42
31
|
function: {
|
|
43
32
|
name: string;
|
|
44
33
|
description: string;
|
|
45
|
-
parameters:
|
|
46
|
-
type: "object";
|
|
47
|
-
properties: Record<string, import("../types.js").ToolParameter>;
|
|
48
|
-
required: string[];
|
|
49
|
-
};
|
|
34
|
+
parameters: import("../types.js").JSONSchema;
|
|
50
35
|
};
|
|
51
36
|
}[];
|
|
52
37
|
export declare function toGeminiTools(tools: ToolDefinition[]): GeminiTool[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/providers/base.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/providers/base.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,EAAE,IAAI,IAAI,UAAU,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC/E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAI7C,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,uFAAuF;AACvF,eAAO,MAAM,kBAAkB,OAAO,CAAC;AAEvC;;;GAGG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAIhE;AAED,wBAAsB,cAAc,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC,CAwBhF;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC,CAIpG;AAED,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,WAAW,EACX,cAAc,EACd,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,QAAQ,GACd,MAAM,cAAc,CAAC;AAItB,qDAAqD;AACrD,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAI3E;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,cAAc,EAAE;;;kBAIb;QAAE,IAAI,EAAE,QAAQ,CAAC;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE;IAEjF;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,cAAc,EAAE;;;;;;;IAapD;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,UAAU,EAAE,CAQnE"}
|
package/dist/providers/base.js
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
|
+
import { toolInputSchema } from './schema.js';
|
|
2
|
+
import { getProviderFactory } from './registry.js';
|
|
1
3
|
/** Output token limit used when neither the server config nor the request sets one. */
|
|
2
4
|
export const DEFAULT_MAX_TOKENS = 4096;
|
|
5
|
+
/**
|
|
6
|
+
* True for a provider object, false for a provider config. A config never
|
|
7
|
+
* has functions, so an object with a `step` or `chat` function is a provider.
|
|
8
|
+
*/
|
|
9
|
+
export function isAIProvider(value) {
|
|
10
|
+
if (typeof value !== 'object' || value === null)
|
|
11
|
+
return false;
|
|
12
|
+
const candidate = value;
|
|
13
|
+
return typeof candidate.step === 'function' || typeof candidate.chat === 'function';
|
|
14
|
+
}
|
|
3
15
|
export async function createProvider(config) {
|
|
16
|
+
const factory = getProviderFactory(config.type);
|
|
17
|
+
if (factory)
|
|
18
|
+
return factory(config);
|
|
4
19
|
switch (config.type) {
|
|
5
20
|
case 'claude': {
|
|
6
21
|
const { ClaudeProvider } = await import('./claude.js');
|
|
@@ -10,6 +25,10 @@ export async function createProvider(config) {
|
|
|
10
25
|
const { OpenAIProvider } = await import('./openai.js');
|
|
11
26
|
return new OpenAIProvider(config);
|
|
12
27
|
}
|
|
28
|
+
case 'openai-compatible': {
|
|
29
|
+
const { OpenAIProvider } = await import('./openai.js');
|
|
30
|
+
return new OpenAIProvider(config, { compatible: true });
|
|
31
|
+
}
|
|
13
32
|
case 'gemini': {
|
|
14
33
|
const { GeminiProvider } = await import('./gemini.js');
|
|
15
34
|
return new GeminiProvider(config);
|
|
@@ -23,72 +42,42 @@ export function toProviderMessages(messages) {
|
|
|
23
42
|
.filter((m) => m.role !== 'system')
|
|
24
43
|
.map((m) => ({ role: m.role, content: m.content }));
|
|
25
44
|
}
|
|
26
|
-
|
|
27
|
-
* Turns stored messages into a history every provider accepts: it starts with
|
|
28
|
-
* a user turn and alternates between user and assistant.
|
|
29
|
-
*
|
|
30
|
-
* - System messages and empty messages are dropped.
|
|
31
|
-
* - Leading assistant turns are dropped (history trimming can leave one first).
|
|
32
|
-
* - Consecutive turns with the same role are merged with a blank line, for
|
|
33
|
-
* example a user message saved before a provider call that then failed.
|
|
34
|
-
*/
|
|
35
|
-
export function normalizeHistory(messages) {
|
|
36
|
-
const normalized = [];
|
|
37
|
-
for (const message of messages) {
|
|
38
|
-
if (message.role !== 'user' && message.role !== 'assistant')
|
|
39
|
-
continue;
|
|
40
|
-
if (!message.content.trim())
|
|
41
|
-
continue;
|
|
42
|
-
if (normalized.length === 0 && message.role !== 'user')
|
|
43
|
-
continue;
|
|
44
|
-
const previous = normalized.at(-1);
|
|
45
|
-
if (previous && previous.role === message.role) {
|
|
46
|
-
previous.content += `\n\n${message.content}`;
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
normalized.push({ role: message.role, content: message.content });
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return normalized;
|
|
53
|
-
}
|
|
45
|
+
export { normalizeHistory, normalizeTurns, trimHistory, estimateTokens, } from './history.js';
|
|
54
46
|
const warned = new Set();
|
|
55
47
|
/** Logs a configuration warning once per process. */
|
|
56
|
-
export function warnOnce(key, message) {
|
|
48
|
+
export function warnOnce(logger, key, message) {
|
|
57
49
|
if (warned.has(key))
|
|
58
50
|
return;
|
|
59
51
|
warned.add(key);
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
function toJsonSchemaObject(tool) {
|
|
63
|
-
return {
|
|
64
|
-
type: 'object',
|
|
65
|
-
properties: tool.parameters,
|
|
66
|
-
required: tool.required,
|
|
67
|
-
};
|
|
52
|
+
logger.warn('config_warning', message, { key });
|
|
68
53
|
}
|
|
69
54
|
export function toClaudeTools(tools) {
|
|
70
55
|
return tools.map((t) => ({
|
|
71
56
|
name: t.name,
|
|
72
57
|
description: t.description,
|
|
73
|
-
input_schema:
|
|
58
|
+
input_schema: toolInputSchema(t),
|
|
74
59
|
}));
|
|
75
60
|
}
|
|
76
61
|
export function toOpenAITools(tools) {
|
|
77
|
-
return tools.map((t) =>
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
62
|
+
return tools.map((t) => {
|
|
63
|
+
const schema = toolInputSchema(t);
|
|
64
|
+
return {
|
|
65
|
+
type: 'function',
|
|
66
|
+
function: {
|
|
67
|
+
name: t.name,
|
|
68
|
+
description: t.description,
|
|
69
|
+
// OpenAI rejects an object schema without `properties`.
|
|
70
|
+
parameters: 'properties' in schema ? schema : { ...schema, properties: {} },
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
});
|
|
85
74
|
}
|
|
86
75
|
export function toGeminiTools(tools) {
|
|
87
76
|
return [{
|
|
88
77
|
functionDeclarations: tools.map((t) => ({
|
|
89
78
|
name: t.name,
|
|
90
79
|
description: t.description,
|
|
91
|
-
parametersJsonSchema:
|
|
80
|
+
parametersJsonSchema: toolInputSchema(t),
|
|
92
81
|
})),
|
|
93
82
|
}];
|
|
94
83
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/providers/base.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/providers/base.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAInD,uFAAuF;AACvF,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAEvC;;;GAGG;AACH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mB;YACzB,QAAQ,EAAE;gBACR,IAAI,EAAE,CAAC,CAAC,IAAI;gBACZ,WAAW,EAAE,CAAC,CAAC,WAAW;gBAC1B,wDAAwD;gBACxD,UAAU,EAAE,YAAY,IAAI,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,UAAU,EAAE,EAAE,EAAE;aAC5E;SACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,KAAuB;IACnD,OAAO,CAAC;YACN,oBAAoB,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;gBACtC,IAAI,EAAE,CAAC,CAAC,IAAI;gBACZ,WAAW,EAAE,CAAC,CAAC,WAAW;gBAC1B,oBAAoB,EAAE,eAAe,CAAC,CAAC,CAAC;aACzC,CAAC,CAAC;SACJ,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Anthropic from '@anthropic-ai/sdk';
|
|
2
|
+
import type { ChatMessage, ProviderChatParams, ProviderConfig } from '../types.js';
|
|
2
3
|
import type { AIProvider } from './base.js';
|
|
4
|
+
import type { ProviderEvent, ProviderStepParams } from './types.js';
|
|
5
|
+
import type { RetrievedChunk } from '../retrieval/types.js';
|
|
3
6
|
interface ClaudeVersion {
|
|
4
7
|
family: string;
|
|
5
8
|
major: number;
|
|
@@ -9,20 +12,52 @@ interface ClaudeVersion {
|
|
|
9
12
|
export declare function parseClaudeModel(model: string): ClaudeVersion | null;
|
|
10
13
|
/** `output_config.effort` exists on Opus 4.5 and on every model from 4.6 on. */
|
|
11
14
|
export declare function claudeSupportsEffort(model: string): boolean;
|
|
12
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* Fable, Mythos, every 5.x model and Opus 4.7+ reject non-default `temperature`.
|
|
17
|
+
* Since API version 2026-10-21 no Claude model takes it, so the provider no
|
|
18
|
+
* longer uses this; it stays exported for code that does.
|
|
19
|
+
*/
|
|
13
20
|
export declare function claudeRejectsTemperature(model: string): boolean;
|
|
21
|
+
type MessageParam = Anthropic.Messages.MessageParam;
|
|
22
|
+
/**
|
|
23
|
+
* Stored history as Claude messages. An assistant message with tool calls
|
|
24
|
+
* becomes the assistant turn with its `tool_use` blocks, then a user turn
|
|
25
|
+
* with the results, and so on for each step. Thinking blocks go back with
|
|
26
|
+
* their signatures, as Claude requires within a tool loop.
|
|
27
|
+
*/
|
|
28
|
+
export declare function toClaudeStepMessages(messages: ChatMessage[]): MessageParam[];
|
|
14
29
|
export declare class ClaudeProvider implements AIProvider {
|
|
30
|
+
/** Retrieved chunks go to Claude as `search_result` blocks, and it cites them natively. */
|
|
31
|
+
readonly citations: "native";
|
|
15
32
|
name: string;
|
|
16
33
|
private client;
|
|
17
|
-
|
|
34
|
+
readonly model: string;
|
|
18
35
|
private effort;
|
|
36
|
+
private promptCaching;
|
|
37
|
+
private readonly logger;
|
|
19
38
|
constructor(config: ProviderConfig);
|
|
39
|
+
/**
|
|
40
|
+
* The system prompt, with a cache breakpoint after it. Claude caches tools
|
|
41
|
+
* and system together, in that order, so both are read from the cache on
|
|
42
|
+
* later requests. Per-request context goes after the breakpoint.
|
|
43
|
+
*/
|
|
44
|
+
private system;
|
|
20
45
|
private request;
|
|
21
|
-
/**
|
|
22
|
-
|
|
46
|
+
/** One model request: streams text and reasoning, then reports tool calls and why it stopped. */
|
|
47
|
+
step(params: ProviderStepParams): AsyncGenerator<ProviderEvent>;
|
|
48
|
+
/**
|
|
49
|
+
* A turn with tools run through `params.toolExecutor`, as text.
|
|
50
|
+
* @deprecated Use `runTurn()`, which also returns the reply's parts, status and usage.
|
|
51
|
+
*/
|
|
23
52
|
chat(params: ProviderChatParams): AsyncGenerator<string>;
|
|
53
|
+
/** @deprecated Use `runTurn()`. */
|
|
24
54
|
chatSync(params: ProviderChatParams): Promise<string>;
|
|
25
|
-
private runTools;
|
|
26
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Puts retrieved chunks before the visitor's latest message as `search_result`
|
|
58
|
+
* blocks, so Claude can cite them by index. Retrieved text travels as
|
|
59
|
+
* content, never in the system prompt. Tool results after it are left alone.
|
|
60
|
+
*/
|
|
61
|
+
export declare function withSearchResults(messages: MessageParam[], sources: RetrievedChunk[] | undefined): MessageParam[];
|
|
27
62
|
export {};
|
|
28
63
|
//# sourceMappingURL=claude.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claude.d.ts","sourceRoot":"","sources":["../../src/providers/claude.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"claude.d.ts","sourceRoot":"","sources":["../../src/providers/claude.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,mBAAmB,CAAC;AAC1C,OAAO,KAAK,EACV,WAAW,EAEX,kBAAkB,EAClB,cAAc,EAIf,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAM5C,OAAO,KAAK,EAAgB,aAAa,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAClF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAK5D,UAAU,aAAa;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAED,gGAAgG;AAChG,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,GAAG,IAAI,CAIpE;AAED,gFAAgF;AAChF,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAO3D;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAM/D;AAED,KAAK,YAAY,GAAG,SAAS,CAAC,QAAQ,CAAC,YAAY,CAAC;AAgDpD;;;;;GAKG;AACH,wBAAgB,oBAAo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