@codehz/ai 0.1.0 → 0.1.2
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/README.md +109 -2
- package/dist/index.d.mts +174 -7
- package/dist/index.mjs +382 -107
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
- package/src/adapters/chat-completions.ts +1 -0
- package/src/adapters/index.ts +21 -0
- package/src/adapters/messages.ts +1 -0
- package/src/adapters/mock.ts +721 -0
- package/src/adapters/ollama.ts +2 -0
- package/src/adapters/responses.ts +1 -0
- package/src/core/aggregator.ts +72 -177
- package/src/core/collect-stream.ts +4 -4
- package/src/core/event-factory.ts +1 -1
- package/src/helpers/adapter-base.ts +5 -5
- package/src/helpers/synthetic-stream.ts +1 -1
- package/src/types/adapter.ts +13 -1
- package/src/types/events.ts +1 -1
- package/src/types/response.ts +1 -1
package/package.json
CHANGED
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
"test": "bun test",
|
|
18
18
|
"example:basic": "bun run examples/basic.ts",
|
|
19
19
|
"example:multi-turn": "bun run examples/multi-turn.ts",
|
|
20
|
-
"example:tool-loop": "bun run examples/tool-loop.ts"
|
|
20
|
+
"example:tool-loop": "bun run examples/tool-loop.ts",
|
|
21
|
+
"prepack": "tsdown"
|
|
21
22
|
},
|
|
22
23
|
"devDependencies": {
|
|
23
24
|
"@types/bun": "latest",
|
|
@@ -26,5 +27,5 @@
|
|
|
26
27
|
"tsdown": "^0.22.3",
|
|
27
28
|
"typescript": "^6"
|
|
28
29
|
},
|
|
29
|
-
"version": "0.1.
|
|
30
|
+
"version": "0.1.2"
|
|
30
31
|
}
|
|
@@ -161,6 +161,7 @@ function ensureTextCompatibleBlocks(
|
|
|
161
161
|
): import("../index.js").ContentBlock[] {
|
|
162
162
|
for (let i = 0; i < blocks.length; i++) {
|
|
163
163
|
const block = blocks[i];
|
|
164
|
+
if (!block) continue;
|
|
164
165
|
if (block.type !== "text" && block.type !== "json") {
|
|
165
166
|
throw new AIRequestError(
|
|
166
167
|
`chat-completions does not support ${field}[${i}] of type "${block.type}"; only text/json blocks are supported`,
|
package/src/adapters/index.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* - messages
|
|
7
7
|
* - chat.completions
|
|
8
8
|
* - ollama
|
|
9
|
+
* - mock
|
|
9
10
|
*
|
|
10
11
|
* 每个 adapter 实现 BackendAdapter 内部协议。
|
|
11
12
|
*/
|
|
@@ -18,3 +19,23 @@ export { ChatCompletionsAdapter } from "./chat-completions.js";
|
|
|
18
19
|
export type { ChatCompletionsAdapterOptions } from "./chat-completions.js";
|
|
19
20
|
export { OllamaAdapter } from "./ollama.js";
|
|
20
21
|
export type { OllamaAdapterOptions } from "./ollama.js";
|
|
22
|
+
export { MockAdapter } from "./mock.js";
|
|
23
|
+
export type {
|
|
24
|
+
MockAdapterOptions,
|
|
25
|
+
MockInputExpectation,
|
|
26
|
+
MockRequestExpectation,
|
|
27
|
+
MockTurnContext,
|
|
28
|
+
MockTurnValidator,
|
|
29
|
+
MockWarningStep,
|
|
30
|
+
MockAuxiliaryStep,
|
|
31
|
+
MockMessageStep,
|
|
32
|
+
MockReasoningStep,
|
|
33
|
+
MockToolCallStep,
|
|
34
|
+
MockOutputStep,
|
|
35
|
+
MockCompleteStep,
|
|
36
|
+
MockErrorStep,
|
|
37
|
+
MockInterruptStep,
|
|
38
|
+
MockThrowStep,
|
|
39
|
+
MockStep,
|
|
40
|
+
MockTurn,
|
|
41
|
+
} from "./mock.js";
|
package/src/adapters/messages.ts
CHANGED
|
@@ -78,6 +78,7 @@ function ensureMessagesTextBlocks(
|
|
|
78
78
|
): import("../index.js").ContentBlock[] {
|
|
79
79
|
for (let i = 0; i < blocks.length; i++) {
|
|
80
80
|
const block = blocks[i];
|
|
81
|
+
if (!block) continue;
|
|
81
82
|
if (block.type !== "text" && block.type !== "json") {
|
|
82
83
|
throw new AIRequestError(
|
|
83
84
|
`messages does not support ${field}[${i}] of type "${block.type}"; only text/json blocks are supported`,
|