@fllf/agent-sdk 0.1.2 → 0.1.3
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 +169 -0
- package/README.md +824 -198
- package/dist/agent/Agent.d.ts +16 -5
- package/dist/agent/Agent.d.ts.map +1 -1
- package/dist/agent/Agent.js +283 -2
- package/dist/agent/Agent.js.map +1 -1
- package/dist/agent/index.d.ts +1 -1
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/types.d.ts +27 -3
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/config/config.d.ts +22 -3
- package/dist/config/config.d.ts.map +1 -1
- package/dist/config/config.js +194 -47
- package/dist/config/config.js.map +1 -1
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/errors.d.ts +74 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +186 -0
- package/dist/errors.js.map +1 -0
- package/dist/executors/base-executor.d.ts +14 -0
- package/dist/executors/base-executor.d.ts.map +1 -0
- package/dist/executors/base-executor.js +31 -0
- package/dist/executors/base-executor.js.map +1 -0
- package/dist/executors/base.d.ts +36 -5
- package/dist/executors/base.d.ts.map +1 -1
- package/dist/executors/chat-request-builder.d.ts +10 -0
- package/dist/executors/chat-request-builder.d.ts.map +1 -0
- package/dist/executors/chat-request-builder.js +96 -0
- package/dist/executors/chat-request-builder.js.map +1 -0
- package/dist/executors/index.d.ts +4 -1
- package/dist/executors/index.d.ts.map +1 -1
- package/dist/executors/index.js +6 -1
- package/dist/executors/index.js.map +1 -1
- package/dist/executors/rag-executor.js +1 -1
- package/dist/executors/rag-executor.js.map +1 -1
- package/dist/executors/simple-chat-executor.d.ts +4 -2
- package/dist/executors/simple-chat-executor.d.ts.map +1 -1
- package/dist/executors/simple-chat-executor.js +59 -57
- package/dist/executors/simple-chat-executor.js.map +1 -1
- package/dist/executors/tool-calling-executor.d.ts +20 -2
- package/dist/executors/tool-calling-executor.d.ts.map +1 -1
- package/dist/executors/tool-calling-executor.js +189 -91
- package/dist/executors/tool-calling-executor.js.map +1 -1
- package/dist/history/base.d.ts +55 -2
- package/dist/history/base.d.ts.map +1 -1
- package/dist/history/base.js +49 -0
- package/dist/history/base.js.map +1 -1
- package/dist/history/compression.d.ts +49 -0
- package/dist/history/compression.d.ts.map +1 -0
- package/dist/history/compression.js +53 -0
- package/dist/history/compression.js.map +1 -0
- package/dist/history/context-window.d.ts +33 -0
- package/dist/history/context-window.d.ts.map +1 -0
- package/dist/history/context-window.js +68 -0
- package/dist/history/context-window.js.map +1 -0
- package/dist/history/in-memory.d.ts +6 -4
- package/dist/history/in-memory.d.ts.map +1 -1
- package/dist/history/in-memory.js +25 -39
- package/dist/history/in-memory.js.map +1 -1
- package/dist/history/index.d.ts +9 -2
- package/dist/history/index.d.ts.map +1 -1
- package/dist/history/index.js +18 -1
- package/dist/history/index.js.map +1 -1
- package/dist/history/postgres/index.d.ts +4 -0
- package/dist/history/postgres/index.d.ts.map +1 -0
- package/dist/history/postgres/index.js +20 -0
- package/dist/history/postgres/index.js.map +1 -0
- package/dist/history/postgres/postgres-message-history-store.d.ts +35 -0
- package/dist/history/postgres/postgres-message-history-store.d.ts.map +1 -0
- package/dist/history/postgres/postgres-message-history-store.js +195 -0
- package/dist/history/postgres/postgres-message-history-store.js.map +1 -0
- package/dist/history/postgres/schema.d.ts +18 -0
- package/dist/history/postgres/schema.d.ts.map +1 -0
- package/dist/history/postgres/schema.js +46 -0
- package/dist/history/postgres/schema.js.map +1 -0
- package/dist/history/postgres/sql.d.ts +29 -0
- package/dist/history/postgres/sql.d.ts.map +1 -0
- package/dist/history/postgres/sql.js +102 -0
- package/dist/history/postgres/sql.js.map +1 -0
- package/dist/history/postgres/types.d.ts +20 -0
- package/dist/history/postgres/types.d.ts.map +1 -0
- package/dist/history/postgres/types.js +3 -0
- package/dist/history/postgres/types.js.map +1 -0
- package/dist/history/tool-pairing.d.ts +11 -0
- package/dist/history/tool-pairing.d.ts.map +1 -0
- package/dist/history/tool-pairing.js +52 -0
- package/dist/history/tool-pairing.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/llm/LLM.d.ts +1 -0
- package/dist/llm/LLM.d.ts.map +1 -1
- package/dist/llm/LLM.js +136 -26
- package/dist/llm/LLM.js.map +1 -1
- package/dist/llm/errors.d.ts +11 -1
- package/dist/llm/errors.d.ts.map +1 -1
- package/dist/llm/errors.js +50 -1
- package/dist/llm/errors.js.map +1 -1
- package/dist/llm/factory.d.ts +14 -2
- package/dist/llm/factory.d.ts.map +1 -1
- package/dist/llm/factory.js +48 -9
- package/dist/llm/factory.js.map +1 -1
- package/dist/llm/index.d.ts +8 -3
- package/dist/llm/index.d.ts.map +1 -1
- package/dist/llm/index.js +10 -1
- package/dist/llm/index.js.map +1 -1
- package/dist/llm/providers/anthropic.d.ts +14 -0
- package/dist/llm/providers/anthropic.d.ts.map +1 -0
- package/dist/llm/providers/anthropic.js +336 -0
- package/dist/llm/providers/anthropic.js.map +1 -0
- package/dist/llm/providers/openai-compatible.d.ts +7 -0
- package/dist/llm/providers/openai-compatible.d.ts.map +1 -1
- package/dist/llm/providers/openai-compatible.js +151 -47
- package/dist/llm/providers/openai-compatible.js.map +1 -1
- package/dist/llm/stream-accumulator.d.ts +17 -0
- package/dist/llm/stream-accumulator.d.ts.map +1 -0
- package/dist/llm/stream-accumulator.js +83 -0
- package/dist/llm/stream-accumulator.js.map +1 -0
- package/dist/llm/tool-arguments.d.ts +6 -0
- package/dist/llm/tool-arguments.d.ts.map +1 -0
- package/dist/llm/tool-arguments.js +20 -0
- package/dist/llm/tool-arguments.js.map +1 -0
- package/dist/llm/types.d.ts +76 -4
- package/dist/llm/types.d.ts.map +1 -1
- package/dist/messages/content.d.ts +36 -0
- package/dist/messages/content.d.ts.map +1 -0
- package/dist/messages/content.js +70 -0
- package/dist/messages/content.js.map +1 -0
- package/dist/messages/index.d.ts +4 -2
- package/dist/messages/index.d.ts.map +1 -1
- package/dist/messages/index.js +10 -1
- package/dist/messages/index.js.map +1 -1
- package/dist/messages/message.d.ts +11 -9
- package/dist/messages/message.d.ts.map +1 -1
- package/dist/messages/message.js +69 -4
- package/dist/messages/message.js.map +1 -1
- package/dist/messages/types.d.ts +12 -0
- package/dist/messages/types.d.ts.map +1 -1
- package/dist/observability/collecting-observer.d.ts +8 -0
- package/dist/observability/collecting-observer.d.ts.map +1 -0
- package/dist/observability/collecting-observer.js +15 -0
- package/dist/observability/collecting-observer.js.map +1 -0
- package/dist/observability/index.d.ts +1 -0
- package/dist/observability/index.d.ts.map +1 -1
- package/dist/observability/index.js +3 -1
- package/dist/observability/index.js.map +1 -1
- package/dist/observability/observer.d.ts.map +1 -1
- package/dist/observability/observer.js +14 -1
- package/dist/observability/observer.js.map +1 -1
- package/dist/observability/types.d.ts +16 -1
- package/dist/observability/types.d.ts.map +1 -1
- package/dist/rag/chunking/auto-chunker.d.ts +7 -0
- package/dist/rag/chunking/auto-chunker.d.ts.map +1 -1
- package/dist/rag/chunking/auto-chunker.js +13 -0
- package/dist/rag/chunking/auto-chunker.js.map +1 -1
- package/dist/rag/chunking/chunker.d.ts.map +1 -1
- package/dist/rag/chunking/chunker.js +29 -5
- package/dist/rag/chunking/chunker.js.map +1 -1
- package/dist/rag/chunking/index.d.ts +2 -0
- package/dist/rag/chunking/index.d.ts.map +1 -1
- package/dist/rag/chunking/index.js +2 -0
- package/dist/rag/chunking/index.js.map +1 -1
- package/dist/rag/chunking/markdown-chunker.d.ts.map +1 -1
- package/dist/rag/chunking/markdown-chunker.js.map +1 -1
- package/dist/rag/chunking/qa-pair-chunker.d.ts +23 -0
- package/dist/rag/chunking/qa-pair-chunker.d.ts.map +1 -0
- package/dist/rag/chunking/qa-pair-chunker.js +162 -0
- package/dist/rag/chunking/qa-pair-chunker.js.map +1 -0
- package/dist/rag/chunking/semantic-chunker.d.ts +19 -0
- package/dist/rag/chunking/semantic-chunker.d.ts.map +1 -0
- package/dist/rag/chunking/semantic-chunker.js +291 -0
- package/dist/rag/chunking/semantic-chunker.js.map +1 -0
- package/dist/rag/embeddings/embedder.d.ts.map +1 -1
- package/dist/rag/embeddings/embedder.js +6 -0
- package/dist/rag/embeddings/embedder.js.map +1 -1
- package/dist/rag/generation/context-builder.d.ts +7 -0
- package/dist/rag/generation/context-builder.d.ts.map +1 -1
- package/dist/rag/generation/context-builder.js +4 -1
- package/dist/rag/generation/context-builder.js.map +1 -1
- package/dist/rag/ingestion/metadata.d.ts +6 -1
- package/dist/rag/ingestion/metadata.d.ts.map +1 -1
- package/dist/rag/ingestion/metadata.js +6 -2
- package/dist/rag/ingestion/metadata.js.map +1 -1
- package/dist/rag/pipeline.d.ts.map +1 -1
- package/dist/rag/pipeline.js +34 -11
- package/dist/rag/pipeline.js.map +1 -1
- package/dist/rag/retrieval/index.d.ts +1 -0
- package/dist/rag/retrieval/index.d.ts.map +1 -1
- package/dist/rag/retrieval/index.js +1 -0
- package/dist/rag/retrieval/index.js.map +1 -1
- package/dist/rag/retrieval/parent-child-expanding-retriever.d.ts +31 -0
- package/dist/rag/retrieval/parent-child-expanding-retriever.d.ts.map +1 -0
- package/dist/rag/retrieval/parent-child-expanding-retriever.js +194 -0
- package/dist/rag/retrieval/parent-child-expanding-retriever.js.map +1 -0
- package/dist/rag/stores/in-memory-keyword-store.d.ts.map +1 -1
- package/dist/rag/stores/in-memory-keyword-store.js +3 -8
- package/dist/rag/stores/in-memory-keyword-store.js.map +1 -1
- package/dist/rag/stores/keyword-tokenizer.d.ts +4 -0
- package/dist/rag/stores/keyword-tokenizer.d.ts.map +1 -0
- package/dist/rag/stores/keyword-tokenizer.js +113 -0
- package/dist/rag/stores/keyword-tokenizer.js.map +1 -0
- package/dist/rag/stores/postgres/pg-vector-store.d.ts.map +1 -1
- package/dist/rag/stores/postgres/pg-vector-store.js +21 -8
- package/dist/rag/stores/postgres/pg-vector-store.js.map +1 -1
- package/dist/rag/stores/postgres/postgres-document-store.d.ts.map +1 -1
- package/dist/rag/stores/postgres/postgres-document-store.js +26 -13
- package/dist/rag/stores/postgres/postgres-document-store.js.map +1 -1
- package/dist/rag/stores/postgres/postgres-keyword-store.d.ts.map +1 -1
- package/dist/rag/stores/postgres/postgres-keyword-store.js +43 -43
- package/dist/rag/stores/postgres/postgres-keyword-store.js.map +1 -1
- package/dist/rag/stores/postgres/sql.d.ts +22 -0
- package/dist/rag/stores/postgres/sql.d.ts.map +1 -1
- package/dist/rag/stores/postgres/sql.js +42 -0
- package/dist/rag/stores/postgres/sql.js.map +1 -1
- package/dist/rag/stores/types.d.ts +5 -0
- package/dist/rag/stores/types.d.ts.map +1 -1
- package/dist/rag/types.d.ts +6 -0
- package/dist/rag/types.d.ts.map +1 -1
- package/dist/testing/agent.d.ts +11 -0
- package/dist/testing/agent.d.ts.map +1 -0
- package/dist/testing/agent.js +45 -0
- package/dist/testing/agent.js.map +1 -0
- package/dist/testing/history-contract.d.ts +12 -0
- package/dist/testing/history-contract.d.ts.map +1 -0
- package/dist/testing/history-contract.js +111 -0
- package/dist/testing/history-contract.js.map +1 -0
- package/dist/testing/index.d.ts +11 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +16 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/models.d.ts +34 -0
- package/dist/testing/models.d.ts.map +1 -0
- package/dist/testing/models.js +74 -0
- package/dist/testing/models.js.map +1 -0
- package/dist/testing/tool-schema.d.ts +6 -0
- package/dist/testing/tool-schema.d.ts.map +1 -0
- package/dist/testing/tool-schema.js +29 -0
- package/dist/testing/tool-schema.js.map +1 -0
- package/dist/testing/tools.d.ts +21 -0
- package/dist/testing/tools.d.ts.map +1 -0
- package/dist/testing/tools.js +43 -0
- package/dist/testing/tools.js.map +1 -0
- package/dist/tools/base.d.ts +38 -7
- package/dist/tools/base.d.ts.map +1 -1
- package/dist/tools/base.js +238 -11
- package/dist/tools/base.js.map +1 -1
- package/dist/tools/builtin/advancedSearchTool.d.ts.map +1 -1
- package/dist/tools/builtin/advancedSearchTool.js +30 -4
- package/dist/tools/builtin/advancedSearchTool.js.map +1 -1
- package/dist/tools/builtin/ragSearchTool.d.ts +6 -3
- package/dist/tools/builtin/ragSearchTool.d.ts.map +1 -1
- package/dist/tools/builtin/ragSearchTool.js +8 -6
- package/dist/tools/builtin/ragSearchTool.js.map +1 -1
- package/dist/tools/executor.d.ts +30 -2
- package/dist/tools/executor.d.ts.map +1 -1
- package/dist/tools/executor.js +83 -15
- package/dist/tools/executor.js.map +1 -1
- package/dist/tools/index.d.ts +3 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/registry.d.ts +15 -3
- package/dist/tools/registry.d.ts.map +1 -1
- package/dist/tools/registry.js +21 -2
- package/dist/tools/registry.js.map +1 -1
- package/package.json +58 -4
package/dist/llm/factory.js
CHANGED
|
@@ -1,28 +1,67 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ModelProviderFactory = void 0;
|
|
3
|
+
exports.ModelProviderFactory = exports.ModelProviderRegistry = void 0;
|
|
4
|
+
const errors_1 = require("../errors");
|
|
5
|
+
const anthropic_1 = require("./providers/anthropic");
|
|
4
6
|
const openai_1 = require("./providers/openai");
|
|
5
7
|
const local_1 = require("./providers/local");
|
|
6
|
-
class
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
class ModelProviderRegistry {
|
|
9
|
+
builders = new Map();
|
|
10
|
+
constructor(options = {}) {
|
|
11
|
+
if (options.includeDefaultProviders ?? true) {
|
|
12
|
+
registerDefaultProviders(this);
|
|
13
|
+
}
|
|
14
|
+
if (options.builders !== undefined) {
|
|
15
|
+
for (const [providerName, builder] of options.builders) {
|
|
16
|
+
this.register(providerName, builder);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
register(providerName, builder) {
|
|
9
21
|
this.builders.set(providerName, builder);
|
|
10
22
|
}
|
|
11
|
-
|
|
23
|
+
autoDetect(config = {}) {
|
|
12
24
|
if (process.env.OPENAI_API_KEY) {
|
|
13
25
|
return this.create('openai', config);
|
|
14
26
|
}
|
|
27
|
+
if (process.env.ANTHROPIC_API_KEY) {
|
|
28
|
+
return this.create('anthropic', config);
|
|
29
|
+
}
|
|
15
30
|
return this.create('local', config);
|
|
16
31
|
}
|
|
17
|
-
|
|
32
|
+
create(providerName, config = {}) {
|
|
18
33
|
const builder = this.builders.get(providerName);
|
|
19
34
|
if (!builder) {
|
|
20
|
-
throw new
|
|
35
|
+
throw new errors_1.ConfigError(`Unknown model provider: ${providerName}`, {
|
|
36
|
+
code: 'unknown_model_provider',
|
|
37
|
+
metadata: {
|
|
38
|
+
providerName,
|
|
39
|
+
},
|
|
40
|
+
});
|
|
21
41
|
}
|
|
22
42
|
return builder(config);
|
|
23
43
|
}
|
|
24
44
|
}
|
|
45
|
+
exports.ModelProviderRegistry = ModelProviderRegistry;
|
|
46
|
+
class ModelProviderFactory {
|
|
47
|
+
static defaultRegistry = new ModelProviderRegistry();
|
|
48
|
+
static register(providerName, builder) {
|
|
49
|
+
this.defaultRegistry.register(providerName, builder);
|
|
50
|
+
}
|
|
51
|
+
static autoDetect(config = {}) {
|
|
52
|
+
return this.defaultRegistry.autoDetect(config);
|
|
53
|
+
}
|
|
54
|
+
static create(providerName, config = {}) {
|
|
55
|
+
return this.defaultRegistry.create(providerName, config);
|
|
56
|
+
}
|
|
57
|
+
static createRegistry(options = {}) {
|
|
58
|
+
return new ModelProviderRegistry(options);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
25
61
|
exports.ModelProviderFactory = ModelProviderFactory;
|
|
26
|
-
|
|
27
|
-
|
|
62
|
+
function registerDefaultProviders(registry) {
|
|
63
|
+
registry.register('openai', (config) => new openai_1.OpenAIProvider(config));
|
|
64
|
+
registry.register('anthropic', (config) => new anthropic_1.AnthropicProvider(config));
|
|
65
|
+
registry.register('local', (config) => new local_1.LocalProvider(config));
|
|
66
|
+
}
|
|
28
67
|
//# sourceMappingURL=factory.js.map
|
package/dist/llm/factory.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../src/llm/factory.ts"],"names":[],"mappings":";;;AAAA,+CAAoD;AACpD,6CAAkD;
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../src/llm/factory.ts"],"names":[],"mappings":";;;AAAA,sCAAwC;AACxC,qDAA0D;AAC1D,+CAAoD;AACpD,6CAAkD;AAelD,MAAa,qBAAqB;IACb,QAAQ,GAAG,IAAI,GAAG,EAAsC,CAAC;IAE1E,YAAY,UAAwC,EAAE;QAClD,IAAI,OAAO,CAAC,uBAAuB,IAAI,IAAI,EAAE,CAAC;YAC1C,wBAAwB,CAAC,IAAI,CAAC,CAAC;QACnC,CAAC;QAED,IAAI,OAAO,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;YACjC,KAAK,MAAM,CAAC,YAAY,EAAE,OAAO,CAAC,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;gBACrD,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;YACzC,CAAC;QACL,CAAC;IACL,CAAC;IAED,QAAQ,CAAC,YAA+B,EAAE,OAAwB;QAC9D,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IAC7C,CAAC;IAED,UAAU,CAAC,SAAyB,EAAE;QAClC,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,CAAC;YAC7B,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QACzC,CAAC;QAED,IAAI,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,CAAC;YAChC,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;QAC5C,CAAC;QAED,OA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AAC,QAAQ,CAAC,WAAW,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,6BAAiB,CAAC,MAAM,CAAC,CAAC,CAAC;IAC1E,QAAQ,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,qBAAa,CAAC,MAAM,CAAC,CAAC,CAAC;AACtE,CAAC"}
|
package/dist/llm/index.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
export { LLM } from './LLM';
|
|
2
|
-
export { LLMAbortError, LLMAuthenticationError, LLMError, LLMInvalidResponseError, LLMProviderError, LLMRateLimitError, LLMStructuredOutputError, LLMTimeoutError, normalizeLLMError, } from './errors';
|
|
3
|
-
export {
|
|
2
|
+
export { isTransientNetworkError, LLMAbortError, LLMAuthenticationError, LLMError, LLMInvalidResponseError, LLMProviderError, LLMRateLimitError, LLMStructuredOutputError, LLMTimeoutError, LLMUnsupportedCapabilityError, normalizeLLMError, } from './errors';
|
|
3
|
+
export type { LLMCapability, LLMErrorCode } from './errors';
|
|
4
|
+
export { ModelProviderFactory, ModelProviderRegistry } from './factory';
|
|
5
|
+
export type { ModelProviderRegistryOptions, ProviderBuilder, } from './factory';
|
|
4
6
|
export type { ModelProvider } from './providers/base';
|
|
5
|
-
export
|
|
7
|
+
export { AnthropicProvider } from './providers/anthropic';
|
|
8
|
+
export { ChatStreamAccumulator } from './stream-accumulator';
|
|
9
|
+
export { parseToolArguments } from './tool-arguments';
|
|
10
|
+
export type { ChatFinishReason, ChatMessage, ChatModel, ChatRequest, ChatResponse, ChatResponseFormat, ChatStreamChunk, ChatToolCall, ChatToolSchema, LLMConfig, LLMRuntimeConfig, ModelCapabilities, ModelProviderName, ModelProviderResolver, ProviderConfig, ReasoningEffort, StructuredOutputRequest, StructuredOutputResponse, TokenUsage, ToolCallDelta, ToolDefinition, } from './types';
|
|
6
11
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/llm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/llm/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EACH,aAAa,EACb,sBAAsB,EACtB,QAAQ,EACR,uBAAuB,EACvB,gBAAgB,EAChB,iBAAiB,EACjB,wBAAwB,EACxB,eAAe,EACf,iBAAiB,GACpB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/llm/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAC5B,OAAO,EACH,uBAAuB,EACvB,aAAa,EACb,sBAAsB,EACtB,QAAQ,EACR,uBAAuB,EACvB,gBAAgB,EAChB,iBAAiB,EACjB,wBAAwB,EACxB,eAAe,EACf,6BAA6B,EAC7B,iBAAiB,GACpB,MAAM,UAAU,CAAC;AAClB,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AACxE,YAAY,EACR,4BAA4B,EAC5B,eAAe,GAClB,MAAM,WAAW,CAAC;AACnB,YAAY,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,YAAY,EACR,gBAAgB,EAChB,WAAW,EACX,SAAS,EACT,WAAW,EACX,YAAY,EACZ,kBAAkB,EAClB,eAAe,EACf,YAAY,EACZ,cAAc,EACd,SAAS,EACT,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EACjB,qBAAqB,EACrB,cAAc,EACd,eAAe,EACf,uBAAuB,EACvB,wBAAwB,EACxB,UAAU,EACV,aAAa,EACb,cAAc,GACjB,MAAM,SAAS,CAAC"}
|
package/dist/llm/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ModelProviderFactory = exports.normalizeLLMError = exports.LLMTimeoutError = exports.LLMStructuredOutputError = exports.LLMRateLimitError = exports.LLMProviderError = exports.LLMInvalidResponseError = exports.LLMError = exports.LLMAuthenticationError = exports.LLMAbortError = exports.LLM = void 0;
|
|
3
|
+
exports.parseToolArguments = exports.ChatStreamAccumulator = exports.AnthropicProvider = exports.ModelProviderRegistry = exports.ModelProviderFactory = exports.normalizeLLMError = exports.LLMUnsupportedCapabilityError = exports.LLMTimeoutError = exports.LLMStructuredOutputError = exports.LLMRateLimitError = exports.LLMProviderError = exports.LLMInvalidResponseError = exports.LLMError = exports.LLMAuthenticationError = exports.LLMAbortError = exports.isTransientNetworkError = exports.LLM = void 0;
|
|
4
4
|
var LLM_1 = require("./LLM");
|
|
5
5
|
Object.defineProperty(exports, "LLM", { enumerable: true, get: function () { return LLM_1.LLM; } });
|
|
6
6
|
var errors_1 = require("./errors");
|
|
7
|
+
Object.defineProperty(exports, "isTransientNetworkError", { enumerable: true, get: function () { return errors_1.isTransientNetworkError; } });
|
|
7
8
|
Object.defineProperty(exports, "LLMAbortError", { enumerable: true, get: function () { return errors_1.LLMAbortError; } });
|
|
8
9
|
Object.defineProperty(exports, "LLMAuthenticationError", { enumerable: true, get: function () { return errors_1.LLMAuthenticationError; } });
|
|
9
10
|
Object.defineProperty(exports, "LLMError", { enumerable: true, get: function () { return errors_1.LLMError; } });
|
|
@@ -12,7 +13,15 @@ Object.defineProperty(exports, "LLMProviderError", { enumerable: true, get: func
|
|
|
12
13
|
Object.defineProperty(exports, "LLMRateLimitError", { enumerable: true, get: function () { return errors_1.LLMRateLimitError; } });
|
|
13
14
|
Object.defineProperty(exports, "LLMStructuredOutputError", { enumerable: true, get: function () { return errors_1.LLMStructuredOutputError; } });
|
|
14
15
|
Object.defineProperty(exports, "LLMTimeoutError", { enumerable: true, get: function () { return errors_1.LLMTimeoutError; } });
|
|
16
|
+
Object.defineProperty(exports, "LLMUnsupportedCapabilityError", { enumerable: true, get: function () { return errors_1.LLMUnsupportedCapabilityError; } });
|
|
15
17
|
Object.defineProperty(exports, "normalizeLLMError", { enumerable: true, get: function () { return errors_1.normalizeLLMError; } });
|
|
16
18
|
var factory_1 = require("./factory");
|
|
17
19
|
Object.defineProperty(exports, "ModelProviderFactory", { enumerable: true, get: function () { return factory_1.ModelProviderFactory; } });
|
|
20
|
+
Object.defineProperty(exports, "ModelProviderRegistry", { enumerable: true, get: function () { return factory_1.ModelProviderRegistry; } });
|
|
21
|
+
var anthropic_1 = require("./providers/anthropic");
|
|
22
|
+
Object.defineProperty(exports, "AnthropicProvider", { enumerable: true, get: function () { return anthropic_1.AnthropicProvider; } });
|
|
23
|
+
var stream_accumulator_1 = require("./stream-accumulator");
|
|
24
|
+
Object.defineProperty(exports, "ChatStreamAccumulator", { enumerable: true, get: function () { return stream_accumulator_1.ChatStreamAccumulator; } });
|
|
25
|
+
var tool_arguments_1 = require("./tool-arguments");
|
|
26
|
+
Object.defineProperty(exports, "parseToolArguments", { enumerable: true, get: function () { return tool_arguments_1.parseToolArguments; } });
|
|
18
27
|
//# sourceMappingURL=index.js.map
|
package/dist/llm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/llm/index.ts"],"names":[],"mappings":";;;AAAA,6BAA4B;AAAnB,0FAAA,GAAG,OAAA;AACZ,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/llm/index.ts"],"names":[],"mappings":";;;AAAA,6BAA4B;AAAnB,0FAAA,GAAG,OAAA;AACZ,mCAYkB;AAXd,iHAAA,uBAAuB,OAAA;AACvB,uGAAA,aAAa,OAAA;AACb,gHAAA,sBAAsB,OAAA;AACtB,kGAAA,QAAQ,OAAA;AACR,iHAAA,uBAAuB,OAAA;AACvB,0GAAA,gBAAgB,OAAA;AAChB,2GAAA,iBAAiB,OAAA;AACjB,kHAAA,wBAAwB,OAAA;AACxB,yGAAA,eAAe,OAAA;AACf,uHAAA,6BAA6B,OAAA;AAC7B,2GAAA,iBAAiB,OAAA;AAGrB,qCAAwE;AAA/D,+GAAA,oBAAoB,OAAA;AAAE,gHAAA,qBAAqB,OAAA;AAMpD,mDAA0D;AAAjD,8GAAA,iBAAiB,OAAA;AAC1B,2DAA6D;AAApD,2HAAA,qBAAqB,OAAA;AAC9B,mDAAsD;AAA7C,oHAAA,kBAAkB,OAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import Anthropic from '@anthropic-ai/sdk';
|
|
2
|
+
import type { ChatRequest, ChatResponse, ChatStreamChunk, ModelCapabilities, ModelProviderName, ProviderConfig } from '../types';
|
|
3
|
+
import type { ModelProvider } from './base';
|
|
4
|
+
export declare class AnthropicProvider implements ModelProvider<Anthropic> {
|
|
5
|
+
readonly name: ModelProviderName;
|
|
6
|
+
readonly model: string;
|
|
7
|
+
readonly client: Anthropic;
|
|
8
|
+
constructor(config?: ProviderConfig);
|
|
9
|
+
capabilities(): ModelCapabilities;
|
|
10
|
+
chat(request: ChatRequest): Promise<ChatResponse>;
|
|
11
|
+
stream(request: ChatRequest): AsyncIterable<ChatStreamChunk>;
|
|
12
|
+
private buildParams;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=anthropic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../../src/llm/providers/anthropic.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,mBAAmB,CAAC;AAI1C,OAAO,KAAK,EAGR,WAAW,EACX,YAAY,EACZ,eAAe,EAEf,iBAAiB,EACjB,iBAAiB,EACjB,cAAc,EAEjB,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAU5C,qBAAa,iBAAkB,YAAW,aAAa,CAAC,SAAS,CAAC;IAC9D,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAe;IAC/C,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;gBAEf,MAAM,GAAE,cAAmB;IAoBvC,YAAY,IAAI,iBAAiB;IAW3B,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;IAShD,MAAM,CAAC,OAAO,EAAE,WAAW,GAAG,aAAa,CAAC,eAAe,CAAC;IAgEnE,OAAO,CAAC,WAAW;CA+DtB"}
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AnthropicProvider = void 0;
|
|
7
|
+
const sdk_1 = __importDefault(require("@anthropic-ai/sdk"));
|
|
8
|
+
const errors_1 = require("../../errors");
|
|
9
|
+
const content_1 = require("../../messages/content");
|
|
10
|
+
const DEFAULT_ANTHROPIC_MODEL = 'claude-opus-4-8';
|
|
11
|
+
// Anthropic 的 max_tokens 是必填参数;上层未指定时给一个宽裕的默认值,
|
|
12
|
+
// 避免长回答被截断(参见 claude 文档对 max_tokens 下限的建议)。
|
|
13
|
+
const DEFAULT_MAX_TOKENS = 16000;
|
|
14
|
+
class AnthropicProvider {
|
|
15
|
+
name = 'anthropic';
|
|
16
|
+
model;
|
|
17
|
+
client;
|
|
18
|
+
constructor(config = {}) {
|
|
19
|
+
const apiKey = config.apiKey ?? process.env.ANTHROPIC_API_KEY;
|
|
20
|
+
if (!apiKey) {
|
|
21
|
+
throw new errors_1.ConfigError('anthropic provider requires an apiKey.', {
|
|
22
|
+
code: 'missing_provider_api_key',
|
|
23
|
+
metadata: { providerName: 'anthropic' },
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
this.model = config.model ?? process.env.ANTHROPIC_MODEL ?? DEFAULT_ANTHROPIC_MODEL;
|
|
27
|
+
const clientOptions = { apiKey };
|
|
28
|
+
const baseURL = config.baseURL ?? process.env.ANTHROPIC_BASE_URL;
|
|
29
|
+
if (baseURL) {
|
|
30
|
+
clientOptions.baseURL = baseURL;
|
|
31
|
+
}
|
|
32
|
+
this.client = new sdk_1.default(clientOptions);
|
|
33
|
+
}
|
|
34
|
+
capabilities() {
|
|
35
|
+
return {
|
|
36
|
+
streaming: true,
|
|
37
|
+
toolCalling: true,
|
|
38
|
+
structuredOutput: true,
|
|
39
|
+
vision: true,
|
|
40
|
+
reasoning: true,
|
|
41
|
+
promptCaching: true,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
async chat(request) {
|
|
45
|
+
const params = this.buildParams(request, false);
|
|
46
|
+
const message = request.signal
|
|
47
|
+
? await this.client.messages.create(params, { signal: request.signal })
|
|
48
|
+
: await this.client.messages.create(params);
|
|
49
|
+
return toChatResponse(message);
|
|
50
|
+
}
|
|
51
|
+
async *stream(request) {
|
|
52
|
+
const params = { ...this.buildParams(request, true), stream: true };
|
|
53
|
+
const stream = request.signal
|
|
54
|
+
? await this.client.messages.create(params, { signal: request.signal })
|
|
55
|
+
: await this.client.messages.create(params);
|
|
56
|
+
// Anthropic 的 content block index 计入所有 block(text/thinking/tool_use),
|
|
57
|
+
// 需要映射成 tool call 的序号。
|
|
58
|
+
const toolOrdinalByBlockIndex = new Map();
|
|
59
|
+
const blockTypeByIndex = new Map();
|
|
60
|
+
let usage = {};
|
|
61
|
+
for await (const event of stream) {
|
|
62
|
+
const chunk = { raw: event };
|
|
63
|
+
switch (event.type) {
|
|
64
|
+
case 'message_start':
|
|
65
|
+
usage = mergeAnthropicUsage(usage, event.message.usage);
|
|
66
|
+
break;
|
|
67
|
+
case 'content_block_start': {
|
|
68
|
+
blockTypeByIndex.set(event.index, event.content_block.type);
|
|
69
|
+
if (event.content_block.type === 'tool_use') {
|
|
70
|
+
const ordinal = toolOrdinalByBlockIndex.size;
|
|
71
|
+
toolOrdinalByBlockIndex.set(event.index, ordinal);
|
|
72
|
+
chunk.toolCallDeltas = [{
|
|
73
|
+
index: ordinal,
|
|
74
|
+
id: event.content_block.id,
|
|
75
|
+
name: event.content_block.name,
|
|
76
|
+
}];
|
|
77
|
+
}
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
case 'content_block_delta':
|
|
81
|
+
if (event.delta.type === 'text_delta') {
|
|
82
|
+
chunk.contentDelta = event.delta.text;
|
|
83
|
+
}
|
|
84
|
+
else if (event.delta.type === 'thinking_delta') {
|
|
85
|
+
chunk.reasoningDelta = event.delta.thinking;
|
|
86
|
+
}
|
|
87
|
+
else if (event.delta.type === 'input_json_delta') {
|
|
88
|
+
const ordinal = toolOrdinalByBlockIndex.get(event.index);
|
|
89
|
+
if (ordinal !== undefined) {
|
|
90
|
+
chunk.toolCallDeltas = [{
|
|
91
|
+
index: ordinal,
|
|
92
|
+
argumentsDelta: event.delta.partial_json,
|
|
93
|
+
}];
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
break;
|
|
97
|
+
case 'message_delta': {
|
|
98
|
+
usage = mergeAnthropicUsage(usage, event.usage);
|
|
99
|
+
const finishReason = toFinishReason(event.delta.stop_reason);
|
|
100
|
+
if (finishReason !== undefined) {
|
|
101
|
+
chunk.finishReason = finishReason;
|
|
102
|
+
}
|
|
103
|
+
chunk.usage = usage;
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
default:
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
yield chunk;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
buildParams(request, streaming) {
|
|
113
|
+
const systemBlocks = [];
|
|
114
|
+
const messages = [];
|
|
115
|
+
for (const message of request.messages) {
|
|
116
|
+
if (message.role === 'system') {
|
|
117
|
+
const block = {
|
|
118
|
+
type: 'text',
|
|
119
|
+
text: (0, content_1.contentToText)(message.content),
|
|
120
|
+
};
|
|
121
|
+
if (message.cacheControl === 'ephemeral') {
|
|
122
|
+
block.cache_control = { type: 'ephemeral' };
|
|
123
|
+
}
|
|
124
|
+
systemBlocks.push(block);
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
messages.push(toAnthropicMessage(message));
|
|
128
|
+
}
|
|
129
|
+
const params = {
|
|
130
|
+
model: request.model ?? this.model,
|
|
131
|
+
max_tokens: request.maxTokens ?? DEFAULT_MAX_TOKENS,
|
|
132
|
+
messages,
|
|
133
|
+
};
|
|
134
|
+
void streaming;
|
|
135
|
+
if (systemBlocks.length > 0) {
|
|
136
|
+
params.system = systemBlocks;
|
|
137
|
+
}
|
|
138
|
+
if (request.temperature !== undefined) {
|
|
139
|
+
params.temperature = request.temperature;
|
|
140
|
+
}
|
|
141
|
+
if (request.tools !== undefined && request.tools.length > 0) {
|
|
142
|
+
params.tools = request.tools.map((tool) => ({
|
|
143
|
+
name: tool.name,
|
|
144
|
+
description: tool.description,
|
|
145
|
+
input_schema: tool.parameters,
|
|
146
|
+
}));
|
|
147
|
+
}
|
|
148
|
+
if (request.toolChoice !== undefined) {
|
|
149
|
+
params.tool_choice = toAnthropicToolChoice(request.toolChoice);
|
|
150
|
+
}
|
|
151
|
+
const outputConfig = {};
|
|
152
|
+
if (request.reasoning !== undefined) {
|
|
153
|
+
// Anthropic 无 minimal 档位,向上取 low。
|
|
154
|
+
outputConfig.effort = request.reasoning.effort === 'minimal'
|
|
155
|
+
? 'low'
|
|
156
|
+
: request.reasoning.effort;
|
|
157
|
+
}
|
|
158
|
+
if (request.responseFormat !== undefined) {
|
|
159
|
+
outputConfig.format = {
|
|
160
|
+
type: 'json_schema',
|
|
161
|
+
schema: request.responseFormat.jsonSchema.schema,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
if (Object.keys(outputConfig).length > 0) {
|
|
165
|
+
params.output_config = outputConfig;
|
|
166
|
+
}
|
|
167
|
+
return params;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
exports.AnthropicProvider = AnthropicProvider;
|
|
171
|
+
function toAnthropicMessage(message) {
|
|
172
|
+
if (message.role === 'tool') {
|
|
173
|
+
const toolResult = {
|
|
174
|
+
type: 'tool_result',
|
|
175
|
+
tool_use_id: message.toolCallId ?? '',
|
|
176
|
+
content: (0, content_1.contentToText)(message.content),
|
|
177
|
+
};
|
|
178
|
+
if (message.metadata?.isError === true) {
|
|
179
|
+
toolResult.is_error = true;
|
|
180
|
+
}
|
|
181
|
+
applyCacheControl(toolResult, message);
|
|
182
|
+
return { role: 'user', content: [toolResult] };
|
|
183
|
+
}
|
|
184
|
+
if (message.role === 'assistant') {
|
|
185
|
+
const blocks = [];
|
|
186
|
+
const text = (0, content_1.contentToText)(message.content);
|
|
187
|
+
if (text.length > 0) {
|
|
188
|
+
blocks.push({ type: 'text', text });
|
|
189
|
+
}
|
|
190
|
+
for (const toolCall of message.toolCalls ?? []) {
|
|
191
|
+
blocks.push({
|
|
192
|
+
type: 'tool_use',
|
|
193
|
+
id: toolCall.id,
|
|
194
|
+
name: toolCall.name,
|
|
195
|
+
input: toolCall.arguments,
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
if (blocks.length === 0) {
|
|
199
|
+
blocks.push({ type: 'text', text: '' });
|
|
200
|
+
}
|
|
201
|
+
applyCacheControl(blocks[blocks.length - 1], message);
|
|
202
|
+
return { role: 'assistant', content: blocks };
|
|
203
|
+
}
|
|
204
|
+
const blocks = toAnthropicUserContent(message.content);
|
|
205
|
+
applyCacheControl(blocks[blocks.length - 1], message);
|
|
206
|
+
return { role: 'user', content: blocks };
|
|
207
|
+
}
|
|
208
|
+
function toAnthropicUserContent(content) {
|
|
209
|
+
if (typeof content === 'string') {
|
|
210
|
+
return [{ type: 'text', text: content }];
|
|
211
|
+
}
|
|
212
|
+
if (content.length === 0) {
|
|
213
|
+
return [{ type: 'text', text: '' }];
|
|
214
|
+
}
|
|
215
|
+
return content.map(toAnthropicContentBlock);
|
|
216
|
+
}
|
|
217
|
+
function toAnthropicContentBlock(block) {
|
|
218
|
+
if (block.type === 'text') {
|
|
219
|
+
return { type: 'text', text: block.text };
|
|
220
|
+
}
|
|
221
|
+
if (block.source.kind === 'url') {
|
|
222
|
+
return {
|
|
223
|
+
type: 'image',
|
|
224
|
+
source: { type: 'url', url: block.source.url },
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
return {
|
|
228
|
+
type: 'image',
|
|
229
|
+
source: {
|
|
230
|
+
type: 'base64',
|
|
231
|
+
media_type: block.source.mediaType,
|
|
232
|
+
data: block.source.data,
|
|
233
|
+
},
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
function applyCacheControl(block, message) {
|
|
237
|
+
if (message.cacheControl === 'ephemeral') {
|
|
238
|
+
block.cache_control = { type: 'ephemeral' };
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
function toAnthropicToolChoice(toolChoice) {
|
|
242
|
+
if (typeof toolChoice === 'object') {
|
|
243
|
+
return { type: 'tool', name: toolChoice.name };
|
|
244
|
+
}
|
|
245
|
+
if (toolChoice === 'required') {
|
|
246
|
+
return { type: 'any' };
|
|
247
|
+
}
|
|
248
|
+
if (toolChoice === 'none') {
|
|
249
|
+
return { type: 'none' };
|
|
250
|
+
}
|
|
251
|
+
return { type: 'auto' };
|
|
252
|
+
}
|
|
253
|
+
function toChatResponse(message) {
|
|
254
|
+
let content = '';
|
|
255
|
+
let reasoning = '';
|
|
256
|
+
const toolCalls = [];
|
|
257
|
+
for (const block of message.content) {
|
|
258
|
+
if (block.type === 'text') {
|
|
259
|
+
content += block.text;
|
|
260
|
+
}
|
|
261
|
+
else if (block.type === 'thinking') {
|
|
262
|
+
reasoning += block.thinking;
|
|
263
|
+
}
|
|
264
|
+
else if (block.type === 'tool_use') {
|
|
265
|
+
toolCalls.push({
|
|
266
|
+
id: block.id,
|
|
267
|
+
name: block.name,
|
|
268
|
+
arguments: isRecord(block.input) ? block.input : { value: block.input },
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
const response = {
|
|
273
|
+
role: 'assistant',
|
|
274
|
+
content,
|
|
275
|
+
toolCalls,
|
|
276
|
+
raw: message,
|
|
277
|
+
};
|
|
278
|
+
if (reasoning.length > 0) {
|
|
279
|
+
response.reasoning = reasoning;
|
|
280
|
+
}
|
|
281
|
+
const finishReason = toFinishReason(message.stop_reason);
|
|
282
|
+
if (finishReason !== undefined) {
|
|
283
|
+
response.finishReason = finishReason;
|
|
284
|
+
}
|
|
285
|
+
const usage = mergeAnthropicUsage({}, message.usage);
|
|
286
|
+
if (Object.keys(usage).length > 0) {
|
|
287
|
+
response.usage = usage;
|
|
288
|
+
}
|
|
289
|
+
return response;
|
|
290
|
+
}
|
|
291
|
+
function toFinishReason(reason) {
|
|
292
|
+
switch (reason) {
|
|
293
|
+
case undefined:
|
|
294
|
+
case null:
|
|
295
|
+
return undefined;
|
|
296
|
+
case 'end_turn':
|
|
297
|
+
case 'stop_sequence':
|
|
298
|
+
return 'stop';
|
|
299
|
+
case 'tool_use':
|
|
300
|
+
return 'tool_calls';
|
|
301
|
+
case 'max_tokens':
|
|
302
|
+
case 'model_context_window_exceeded':
|
|
303
|
+
return 'length';
|
|
304
|
+
case 'refusal':
|
|
305
|
+
return 'content_filter';
|
|
306
|
+
default:
|
|
307
|
+
return 'other';
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
function mergeAnthropicUsage(current, usage) {
|
|
311
|
+
if (!usage) {
|
|
312
|
+
return current;
|
|
313
|
+
}
|
|
314
|
+
const merged = { ...current };
|
|
315
|
+
if (typeof usage.input_tokens === 'number') {
|
|
316
|
+
merged.promptTokens = usage.input_tokens;
|
|
317
|
+
}
|
|
318
|
+
if (typeof usage.output_tokens === 'number') {
|
|
319
|
+
merged.completionTokens = usage.output_tokens;
|
|
320
|
+
}
|
|
321
|
+
if (typeof usage.cache_read_input_tokens === 'number' && usage.cache_read_input_tokens > 0) {
|
|
322
|
+
merged.cachedPromptTokens = usage.cache_read_input_tokens;
|
|
323
|
+
}
|
|
324
|
+
if (typeof usage.cache_creation_input_tokens === 'number'
|
|
325
|
+
&& usage.cache_creation_input_tokens > 0) {
|
|
326
|
+
merged.cacheCreationPromptTokens = usage.cache_creation_input_tokens;
|
|
327
|
+
}
|
|
328
|
+
if (merged.promptTokens !== undefined && merged.completionTokens !== undefined) {
|
|
329
|
+
merged.totalTokens = merged.promptTokens + merged.completionTokens;
|
|
330
|
+
}
|
|
331
|
+
return merged;
|
|
332
|
+
}
|
|
333
|
+
function isRecord(value) {
|
|
334
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
335
|
+
}
|
|
336
|
+
//# sourceMappingURL=anthropic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../../src/llm/providers/anthropic.ts"],"names":[],"mappings":";;;;;;AAAA,4DAA0C;AAC1C,yCAA2C;AAC3C,oDAAuD;AAgBvD,MAAM,uBAAuB,GAAG,iBAAiB,CAAC;AAClD,gDAAgD;AAChD,4CAA4C;AAC5C,MAAM,kBAAkB,GAAG,KAAK,CAAC;AAKjC,MAAa,iBAAiB;IACjB,IAAI,GAAsB,WAAW,CAAC;IACtC,KAAK,CAAS;IACd,MAAM,CAAY;IAE3B,YAAY,SAAyB,EAAE;QACnC,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;QAC9D,IAAI,CAAC,MAAM,EAAE,CAAC;YACV,MAAM,IAAI,oBAAW,CAAC,wCAAwC,EAAE;gBAC5D,IAAI,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name: ModelProviderName, config: ProviderConfig);
|
|
9
9
|
capabilities(): ModelCapabilities;
|
|
10
|
+
/**
|
|
11
|
+
* OpenAI 官方端点已弃用 max_tokens(o 系列直接报错),
|
|
12
|
+
* 但部分本地 OpenAI-compatible 服务尚未支持 max_completion_tokens。
|
|
13
|
+
* 因此只对官方 openai provider 使用新参数。
|
|
14
|
+
*/
|
|
15
|
+
protected useMaxCompletionTokens(): boolean;
|
|
10
16
|
chat(request: ChatRequest): Promise<ChatResponse>;
|
|
11
17
|
stream(request: ChatRequest): AsyncIterable<ChatStreamChunk>;
|
|
18
|
+
private buildChatBody;
|
|
12
19
|
}
|
|
13
20
|
//# sourceMappingURL=openai-compatible.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai-compatible.d.ts","sourceRoot":"","sources":["../../../src/llm/providers/openai-compatible.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"openai-compatible.d.ts","sourceRoot":"","sources":["../../../src/llm/providers/openai-compatible.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAK5B,OAAO,KAAK,EAGR,WAAW,EACX,YAAY,EACZ,eAAe,EAEf,iBAAiB,EACjB,iBAAiB,EACjB,cAAc,EAGjB,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAY5C,qBAAa,wBAAyB,YAAW,aAAa,CAAC,MAAM,CAAC;IAClE,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;IACjC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEZ,IAAI,EAAE,iBAAiB,EAAE,MAAM,EAAE,cAAc;IAuB3D,YAAY,IAAI,iBAAiB;IASjC;;;;OAIG;IACH,SAAS,CAAC,sBAAsB,IAAI,OAAO;IAIrC,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;IAiChD,MAAM,CAAC,OAAO,EAAE,WAAW,GAAG,aAAa,CAAC,eAAe,CAAC;IAgBnE,OAAO,CAAC,aAAa;CAuDxB"}
|