@theia/ai-anthropic 1.74.0-next.5 → 1.74.0-next.53
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/lib/browser/anthropic-frontend-application-contribution.d.ts.map +1 -1
- package/lib/browser/anthropic-frontend-application-contribution.js +27 -2
- package/lib/browser/anthropic-frontend-application-contribution.js.map +1 -1
- package/lib/common/anthropic-language-models-manager.d.ts +4 -0
- package/lib/common/anthropic-language-models-manager.d.ts.map +1 -1
- package/lib/common/anthropic-language-models-manager.js +2 -2
- package/lib/common/anthropic-language-models-manager.js.map +1 -1
- package/lib/common/anthropic-preferences.d.ts +2 -0
- package/lib/common/anthropic-preferences.d.ts.map +1 -1
- package/lib/common/anthropic-preferences.js +25 -1
- package/lib/common/anthropic-preferences.js.map +1 -1
- package/lib/node/anthropic-language-model.d.ts +23 -2
- package/lib/node/anthropic-language-model.d.ts.map +1 -1
- package/lib/node/anthropic-language-model.js +107 -26
- package/lib/node/anthropic-language-model.js.map +1 -1
- package/lib/node/anthropic-language-model.spec.js +211 -1
- package/lib/node/anthropic-language-model.spec.js.map +1 -1
- package/lib/node/anthropic-language-models-manager-impl.d.ts +6 -0
- package/lib/node/anthropic-language-models-manager-impl.d.ts.map +1 -1
- package/lib/node/anthropic-language-models-manager-impl.js +26 -3
- package/lib/node/anthropic-language-models-manager-impl.js.map +1 -1
- package/lib/node/anthropic-language-models-manager-impl.spec.js +48 -0
- package/lib/node/anthropic-language-models-manager-impl.spec.js.map +1 -1
- package/lib/node/anthropic-server-tools.d.ts +4 -0
- package/lib/node/anthropic-server-tools.d.ts.map +1 -1
- package/lib/node/anthropic-server-tools.js +5 -1
- package/lib/node/anthropic-server-tools.js.map +1 -1
- package/package.json +4 -4
- package/src/browser/anthropic-frontend-application-contribution.ts +32 -4
- package/src/common/anthropic-language-models-manager.ts +5 -0
- package/src/common/anthropic-preferences.ts +28 -1
- package/src/node/anthropic-language-model.spec.ts +265 -3
- package/src/node/anthropic-language-model.ts +114 -29
- package/src/node/anthropic-language-models-manager-impl.spec.ts +51 -0
- package/src/node/anthropic-language-models-manager-impl.ts +31 -3
- package/src/node/anthropic-server-tools.ts +5 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic-frontend-application-contribution.d.ts","sourceRoot":"","sources":["../../src/browser/anthropic-frontend-application-contribution.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,+BAA+B,EAAE,MAAM,yBAAyB,CAAC;AAE1E,OAAO,EAAE,8BAA8B,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"anthropic-frontend-application-contribution.d.ts","sourceRoot":"","sources":["../../src/browser/anthropic-frontend-application-contribution.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,+BAA+B,EAAE,MAAM,yBAAyB,CAAC;AAE1E,OAAO,EAAE,8BAA8B,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC;AAItF,OAAO,EACH,iBAAiB,EACpB,MAAM,+CAA+C,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAKhD,qBACa,wCAAyC,YAAW,+BAA+B;IAG5F,SAAS,CAAC,iBAAiB,EAAE,iBAAiB,CAAC;IAG/C,SAAS,CAAC,OAAO,EAAE,8BAA8B,CAAC;IAGlD,SAAS,CAAC,iBAAiB,EAAE,iBAAiB,CAAC;IAE/C,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE,CAAM;IACpC,SAAS,CAAC,gBAAgB,EAAE,OAAO,CAAC,yBAAyB,CAAC,EAAE,CAAM;IAEtE,OAAO,IAAI,IAAI;IA2Cf,SAAS,CAAC,kBAAkB,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,IAAI;IAYvD,SAAS,CAAC,wBAAwB,CAAC,eAAe,EAAE,OAAO,CAAC,yBAAyB,CAAC,EAAE,GAAG,IAAI;IAsB/F,SAAS,CAAC,eAAe,IAAI,IAAI;IAQjC,4FAA4F;IAC5F,SAAS,CAAC,+BAA+B,CAAC,OAAO,EAAE,MAAM,GAAG,yBAAyB;IAsBrF,SAAS,CAAC,4CAA4C,CAAC,WAAW,EAAE,OAAO,CAAC,yBAAyB,CAAC,EAAE,GAAG,yBAAyB,EAAE;CA6BzI"}
|
|
@@ -22,6 +22,7 @@ const common_1 = require("../common");
|
|
|
22
22
|
const anthropic_preferences_1 = require("../common/anthropic-preferences");
|
|
23
23
|
const ai_core_preferences_1 = require("@theia/ai-core/lib/common/ai-core-preferences");
|
|
24
24
|
const core_1 = require("@theia/core");
|
|
25
|
+
const ai_core_1 = require("@theia/ai-core");
|
|
25
26
|
const ANTHROPIC_PROVIDER_ID = 'anthropic';
|
|
26
27
|
let AnthropicFrontendApplicationContribution = class AnthropicFrontendApplicationContribution {
|
|
27
28
|
constructor() {
|
|
@@ -52,6 +53,12 @@ let AnthropicFrontendApplicationContribution = class AnthropicFrontendApplicatio
|
|
|
52
53
|
this.manager.setProxyUrl(this.preferenceService.get('http.proxy', undefined));
|
|
53
54
|
this.updateAllModels();
|
|
54
55
|
}
|
|
56
|
+
else if (event.preferenceName === anthropic_preferences_1.SERVER_SIDE_COMPACTION_PREF ||
|
|
57
|
+
event.preferenceName === ai_core_preferences_1.PREFERENCE_NAME_SERVER_SIDE_COMPACTION ||
|
|
58
|
+
event.preferenceName === anthropic_preferences_1.SERVER_SIDE_COMPACTION_TOKEN_THRESHOLD_PREF ||
|
|
59
|
+
event.preferenceName === ai_core_preferences_1.PREFERENCE_NAME_SERVER_SIDE_COMPACTION_TOKEN_THRESHOLD) {
|
|
60
|
+
this.updateAllModels();
|
|
61
|
+
}
|
|
55
62
|
else if (event.preferenceName === anthropic_preferences_1.CUSTOM_ENDPOINTS_PREF) {
|
|
56
63
|
this.handleCustomModelChanges(this.preferenceService.get(anthropic_preferences_1.CUSTOM_ENDPOINTS_PREF, []));
|
|
57
64
|
}
|
|
@@ -82,6 +89,8 @@ let AnthropicFrontendApplicationContribution = class AnthropicFrontendApplicatio
|
|
|
82
89
|
model.apiKey === newModel.apiKey &&
|
|
83
90
|
model.maxRetries === newModel.maxRetries &&
|
|
84
91
|
model.useCaching === newModel.useCaching &&
|
|
92
|
+
model.serverSideCompactionEnabledByDefault === newModel.serverSideCompactionEnabledByDefault &&
|
|
93
|
+
model.serverSideCompactionTokenThresholdByDefault === newModel.serverSideCompactionTokenThresholdByDefault &&
|
|
85
94
|
model.enableStreaming === newModel.enableStreaming));
|
|
86
95
|
this.manager.removeLanguageModels(...modelsToRemove.map(model => model.id));
|
|
87
96
|
this.manager.createOrUpdateLanguageModels(...modelsToAddOrUpdate);
|
|
@@ -97,17 +106,31 @@ let AnthropicFrontendApplicationContribution = class AnthropicFrontendApplicatio
|
|
|
97
106
|
createAnthropicModelDescription(modelId) {
|
|
98
107
|
const id = `${ANTHROPIC_PROVIDER_ID}/${modelId}`;
|
|
99
108
|
const maxRetries = this.aiCorePreferences.get(ai_core_preferences_1.PREFERENCE_NAME_MAX_RETRIES) ?? 3;
|
|
109
|
+
const globalCompaction = this.preferenceService.get(ai_core_preferences_1.PREFERENCE_NAME_SERVER_SIDE_COMPACTION, true);
|
|
110
|
+
const compactionOverride = this.preferenceService.get(anthropic_preferences_1.SERVER_SIDE_COMPACTION_PREF, 'default');
|
|
111
|
+
const serverSideCompactionEnabledByDefault = (0, ai_core_1.resolveCompactionDefault)(globalCompaction, compactionOverride);
|
|
112
|
+
const globalThreshold = this.preferenceService.get(ai_core_preferences_1.PREFERENCE_NAME_SERVER_SIDE_COMPACTION_TOKEN_THRESHOLD, undefined);
|
|
113
|
+
const providerThreshold = this.preferenceService.get(anthropic_preferences_1.SERVER_SIDE_COMPACTION_TOKEN_THRESHOLD_PREF, undefined);
|
|
114
|
+
const serverSideCompactionTokenThresholdByDefault = (0, ai_core_1.resolveCompactionTokenThresholdDefault)(globalThreshold, providerThreshold);
|
|
100
115
|
return {
|
|
101
116
|
id: id,
|
|
102
117
|
model: modelId,
|
|
103
118
|
apiKey: true,
|
|
104
119
|
enableStreaming: true,
|
|
105
120
|
useCaching: true,
|
|
106
|
-
maxRetries: maxRetries
|
|
121
|
+
maxRetries: maxRetries,
|
|
122
|
+
serverSideCompactionEnabledByDefault,
|
|
123
|
+
serverSideCompactionTokenThresholdByDefault
|
|
107
124
|
};
|
|
108
125
|
}
|
|
109
126
|
createCustomModelDescriptionsFromPreferences(preferences) {
|
|
110
127
|
const maxRetries = this.aiCorePreferences.get(ai_core_preferences_1.PREFERENCE_NAME_MAX_RETRIES) ?? 3;
|
|
128
|
+
const globalCompaction = this.preferenceService.get(ai_core_preferences_1.PREFERENCE_NAME_SERVER_SIDE_COMPACTION, true);
|
|
129
|
+
const compactionOverride = this.preferenceService.get(anthropic_preferences_1.SERVER_SIDE_COMPACTION_PREF, 'default');
|
|
130
|
+
const serverSideCompactionEnabledByDefault = (0, ai_core_1.resolveCompactionDefault)(globalCompaction, compactionOverride);
|
|
131
|
+
const globalThreshold = this.preferenceService.get(ai_core_preferences_1.PREFERENCE_NAME_SERVER_SIDE_COMPACTION_TOKEN_THRESHOLD, undefined);
|
|
132
|
+
const providerThreshold = this.preferenceService.get(anthropic_preferences_1.SERVER_SIDE_COMPACTION_TOKEN_THRESHOLD_PREF, undefined);
|
|
133
|
+
const serverSideCompactionTokenThresholdByDefault = (0, ai_core_1.resolveCompactionTokenThresholdDefault)(globalThreshold, providerThreshold);
|
|
111
134
|
return preferences.reduce((acc, pref) => {
|
|
112
135
|
if (!pref.model || !pref.url || typeof pref.model !== 'string' || typeof pref.url !== 'string') {
|
|
113
136
|
return acc;
|
|
@@ -121,7 +144,9 @@ let AnthropicFrontendApplicationContribution = class AnthropicFrontendApplicatio
|
|
|
121
144
|
apiKey: typeof pref.apiKey === 'string' || pref.apiKey === true ? pref.apiKey : undefined,
|
|
122
145
|
enableStreaming: pref.enableStreaming ?? true,
|
|
123
146
|
useCaching: pref.useCaching ?? true,
|
|
124
|
-
maxRetries: pref.maxRetries ?? maxRetries
|
|
147
|
+
maxRetries: pref.maxRetries ?? maxRetries,
|
|
148
|
+
serverSideCompactionEnabledByDefault,
|
|
149
|
+
serverSideCompactionTokenThresholdByDefault
|
|
125
150
|
}
|
|
126
151
|
];
|
|
127
152
|
}, []);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic-frontend-application-contribution.js","sourceRoot":"","sources":["../../src/browser/anthropic-frontend-application-contribution.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;;AAGhF,4DAAkE;AAClE,sCAAsF;AACtF,
|
|
1
|
+
{"version":3,"file":"anthropic-frontend-application-contribution.js","sourceRoot":"","sources":["../../src/browser/anthropic-frontend-application-contribution.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;;AAGhF,4DAAkE;AAClE,sCAAsF;AACtF,2EAEyC;AACzC,uFAEuD;AACvD,sCAAgD;AAChD,4CAA+H;AAE/H,MAAM,qBAAqB,GAAG,WAAW,CAAC;AAGnC,IAAM,wCAAwC,GAA9C,MAAM,wCAAwC;IAA9C;QAWO,eAAU,GAAa,EAAE,CAAC;QAC1B,qBAAgB,GAAyC,EAAE,CAAC;IA2I1E,CAAC;IAzIG,OAAO;QACH,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE;YACnC,MAAM,MAAM,GAAG,IAAI,CAAC,iBA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C;;mFACqB;AAGrC;IADT,IAAA,kBAAM,EAAC,uCAA8B,CAAC;;yEACW;AAGxC;IADT,IAAA,kBAAM,EAAC,uCAAiB,CAAC;;mFACqB;mDATtC,wCAAwC;IADpD,IAAA,sBAAU,GAAE;GACA,wCAAwC,CAuJpD"}
|
|
@@ -15,6 +15,10 @@ export interface AnthropicModelDescription {
|
|
|
15
15
|
useCaching: boolean;
|
|
16
16
|
/** Maximum number of retry attempts when a request fails. Default is 3. */
|
|
17
17
|
maxRetries: number;
|
|
18
|
+
/** Resolved default enablement of server-side compaction (global preference folded with the per-provider override). Defaults to disabled when omitted. */
|
|
19
|
+
serverSideCompactionEnabledByDefault?: boolean;
|
|
20
|
+
/** Resolved default input-token threshold for server-side compaction. `undefined` preserves the provider default. */
|
|
21
|
+
serverSideCompactionTokenThresholdByDefault?: number;
|
|
18
22
|
}
|
|
19
23
|
export interface AnthropicLanguageModelsManager {
|
|
20
24
|
apiKey: string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic-language-models-manager.d.ts","sourceRoot":"","sources":["../../src/common/anthropic-language-models-manager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"anthropic-language-models-manager.d.ts","sourceRoot":"","sources":["../../src/common/anthropic-language-models-manager.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,sCAAsC,+CAA+C,CAAC;AACnG,eAAO,MAAM,8BAA8B,eAA2C,CAAC;AAEvF,MAAM,WAAW,yBAAyB;IACtC,iEAAiE;IACjE,EAAE,EAAE,MAAM,CAAC;IACX,iDAAiD;IACjD,KAAK,EAAE,MAAM,CAAC;IACd,oIAAoI;IACpI,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,8FAA8F;IAC9F,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAClC,wDAAwD;IACxD,eAAe,EAAE,OAAO,CAAC;IACzB,0DAA0D;IAC1D,UAAU,EAAE,OAAO,CAAC;IACpB,2EAA2E;IAC3E,UAAU,EAAE,MAAM,CAAC;IACnB,0JAA0J;IAC1J,oCAAoC,CAAC,EAAE,OAAO,CAAC;IAC/C,qHAAqH;IACrH,2CAA2C,CAAC,EAAE,MAAM,CAAC;CACxD;AACD,MAAM,WAAW,8BAA8B;IAC3C,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;IACzC,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;IAChD,4BAA4B,CAAC,GAAG,MAAM,EAAE,yBAAyB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpF,oBAAoB,CAAC,GAAG,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI,CAAA;CACpD"}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AnthropicLanguageModelsManager = exports.ANTHROPIC_LANGUAGE_MODELS_MANAGER_PATH = void 0;
|
|
4
2
|
// *****************************************************************************
|
|
5
3
|
// Copyright (C) 2024 EclipseSource GmbH.
|
|
6
4
|
//
|
|
@@ -16,6 +14,8 @@ exports.AnthropicLanguageModelsManager = exports.ANTHROPIC_LANGUAGE_MODELS_MANAG
|
|
|
16
14
|
//
|
|
17
15
|
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
18
16
|
// *****************************************************************************
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.AnthropicLanguageModelsManager = exports.ANTHROPIC_LANGUAGE_MODELS_MANAGER_PATH = void 0;
|
|
19
19
|
exports.ANTHROPIC_LANGUAGE_MODELS_MANAGER_PATH = '/services/anthropic/language-model-manager';
|
|
20
20
|
exports.AnthropicLanguageModelsManager = Symbol('AnthropicLanguageModelsManager');
|
|
21
21
|
//# sourceMappingURL=anthropic-language-models-manager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic-language-models-manager.js","sourceRoot":"","sources":["../../src/common/anthropic-language-models-manager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"anthropic-language-models-manager.js","sourceRoot":"","sources":["../../src/common/anthropic-language-models-manager.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;AAEnE,QAAA,sCAAsC,GAAG,4CAA4C,CAAC;AACtF,QAAA,8BAA8B,GAAG,MAAM,CAAC,gCAAgC,CAAC,CAAC"}
|
|
@@ -2,5 +2,7 @@ import { PreferenceSchema } from '@theia/core';
|
|
|
2
2
|
export declare const API_KEY_PREF = "ai-features.anthropic.AnthropicApiKey";
|
|
3
3
|
export declare const MODELS_PREF = "ai-features.anthropic.AnthropicModels";
|
|
4
4
|
export declare const CUSTOM_ENDPOINTS_PREF = "ai-features.anthropicCustom.customAnthropicModels";
|
|
5
|
+
export declare const SERVER_SIDE_COMPACTION_PREF = "ai-features.anthropic.serverSideCompaction";
|
|
6
|
+
export declare const SERVER_SIDE_COMPACTION_TOKEN_THRESHOLD_PREF = "ai-features.anthropic.serverSideCompactionTokenThreshold";
|
|
5
7
|
export declare const AnthropicPreferencesSchema: PreferenceSchema;
|
|
6
8
|
//# sourceMappingURL=anthropic-preferences.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic-preferences.d.ts","sourceRoot":"","sources":["../../src/common/anthropic-preferences.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"anthropic-preferences.d.ts","sourceRoot":"","sources":["../../src/common/anthropic-preferences.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAuB,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEpE,eAAO,MAAM,YAAY,0CAA0C,CAAC;AACpE,eAAO,MAAM,WAAW,0CAA0C,CAAC;AACnE,eAAO,MAAM,qBAAqB,sDAAsD,CAAC;AACzF,eAAO,MAAM,2BAA2B,+CAA+C,CAAC;AACxF,eAAO,MAAM,2CAA2C,6DAA6D,CAAC;AAEtH,eAAO,MAAM,0BAA0B,EAAE,gBA4GxC,CAAC"}
|
|
@@ -15,12 +15,15 @@
|
|
|
15
15
|
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
16
|
// *****************************************************************************
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.AnthropicPreferencesSchema = exports.CUSTOM_ENDPOINTS_PREF = exports.MODELS_PREF = exports.API_KEY_PREF = void 0;
|
|
18
|
+
exports.AnthropicPreferencesSchema = exports.SERVER_SIDE_COMPACTION_TOKEN_THRESHOLD_PREF = exports.SERVER_SIDE_COMPACTION_PREF = exports.CUSTOM_ENDPOINTS_PREF = exports.MODELS_PREF = exports.API_KEY_PREF = void 0;
|
|
19
19
|
const ai_core_preferences_1 = require("@theia/ai-core/lib/common/ai-core-preferences");
|
|
20
|
+
const language_model_1 = require("@theia/ai-core/lib/common/language-model");
|
|
20
21
|
const core_1 = require("@theia/core");
|
|
21
22
|
exports.API_KEY_PREF = 'ai-features.anthropic.AnthropicApiKey';
|
|
22
23
|
exports.MODELS_PREF = 'ai-features.anthropic.AnthropicModels';
|
|
23
24
|
exports.CUSTOM_ENDPOINTS_PREF = 'ai-features.anthropicCustom.customAnthropicModels';
|
|
25
|
+
exports.SERVER_SIDE_COMPACTION_PREF = 'ai-features.anthropic.serverSideCompaction';
|
|
26
|
+
exports.SERVER_SIDE_COMPACTION_TOKEN_THRESHOLD_PREF = 'ai-features.anthropic.serverSideCompactionTokenThreshold';
|
|
24
27
|
exports.AnthropicPreferencesSchema = {
|
|
25
28
|
properties: {
|
|
26
29
|
[exports.API_KEY_PREF]: {
|
|
@@ -45,6 +48,27 @@ exports.AnthropicPreferencesSchema = {
|
|
|
45
48
|
type: 'string'
|
|
46
49
|
}
|
|
47
50
|
},
|
|
51
|
+
[exports.SERVER_SIDE_COMPACTION_PREF]: {
|
|
52
|
+
type: 'string',
|
|
53
|
+
enum: ['default', 'enabled', 'disabled'],
|
|
54
|
+
enumDescriptions: [
|
|
55
|
+
core_1.nls.localize('theia/ai/anthropic/compaction/default', 'Follow the global chat server-side compaction setting.'),
|
|
56
|
+
core_1.nls.localize('theia/ai/anthropic/compaction/enabled', 'Always request server-side compaction for Anthropic models.'),
|
|
57
|
+
core_1.nls.localize('theia/ai/anthropic/compaction/disabled', 'Never request server-side compaction for Anthropic models.')
|
|
58
|
+
],
|
|
59
|
+
default: 'default',
|
|
60
|
+
markdownDescription: core_1.nls.localize('theia/ai/anthropic/compaction/description', 'Override provider-native server-side compaction for Anthropic models. "default" follows the global chat setting ' +
|
|
61
|
+
'({0}). When effectively enabled, the Anthropic Beta Messages API is used so the provider can summarize ' +
|
|
62
|
+
'older turns once the conversation grows past its threshold.', `\`#${ai_core_preferences_1.PREFERENCE_NAME_SERVER_SIDE_COMPACTION}#\``),
|
|
63
|
+
title: ai_core_preferences_1.AI_CORE_PREFERENCES_TITLE,
|
|
64
|
+
},
|
|
65
|
+
[exports.SERVER_SIDE_COMPACTION_TOKEN_THRESHOLD_PREF]: {
|
|
66
|
+
type: 'integer',
|
|
67
|
+
minimum: language_model_1.SERVER_SIDE_COMPACTION_TOKEN_THRESHOLD_MINIMUM,
|
|
68
|
+
markdownDescription: core_1.nls.localize('theia/ai/anthropic/compactionTokenThreshold/description', 'Override the global input-token threshold for server-side compaction for Anthropic models. When unset, the global setting or provider default applies. ' +
|
|
69
|
+
'If set, the value must be at least 50,000 tokens.'),
|
|
70
|
+
title: ai_core_preferences_1.AI_CORE_PREFERENCES_TITLE,
|
|
71
|
+
},
|
|
48
72
|
[exports.CUSTOM_ENDPOINTS_PREF]: {
|
|
49
73
|
type: 'array',
|
|
50
74
|
title: ai_core_preferences_1.AI_CORE_PREFERENCES_TITLE,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic-preferences.js","sourceRoot":"","sources":["../../src/common/anthropic-preferences.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;AAEhF,
|
|
1
|
+
{"version":3,"file":"anthropic-preferences.js","sourceRoot":"","sources":["../../src/common/anthropic-preferences.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,yCAAyC;AACzC,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;AAEhF,uFAAkI;AAClI,6EAA0G;AAC1G,sCAAoE;AAEvD,QAAA,YAAY,GAAG,uCAAuC,CAAC;AACvD,QAAA,WAAW,GAAG,uCAAuC,CAAC;AACtD,QAAA,qBAAqB,GAAG,mDAAmD,CAAC;AAC5E,QAAA,2BAA2B,GAAG,4CAA4C,CAAC;AAC3E,QAAA,2CAA2C,GAAG,0DAA0D,CAAC;AAEzG,QAAA,0BAA0B,GAAqB;IACxD,UAAU,EAAE;QACR,CAAC,oBAAY,CAAC,EAAE;YACZ,IAAI,EAAE,QAAQ;YACd,mBAAmB,EAAE,UAAG,CAAC,QAAQ,CAAC,uCAAuC,EACrE;oHACoG,CAAC,GAAG,qBAAc;YAC1H,KAAK,EAAE,+CAAy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AO,EAAE,EAAE;YACX,KAAK,EAAE;gBACH,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACR,KAAK,EAAE;wBACH,IAAI,EAAE,QAAQ;wBACd,KAAK,EAAE,UAAG,CAAC,QAAQ,CAAC,kDAAkD,EAAE,UAAU,CAAC;qBACtF;oBACD,GAAG,EAAE;wBACD,IAAI,EAAE,QAAQ;wBACd,KAAK,EAAE,UAAG,CAAC,QAAQ,CAAC,8CAA8C,EAAE,iEAAiE,CAAC;qBACzI;oBACD,EAAE,EAAE;wBACA,IAAI,EAAE,QAAQ;wBACd,KAAK,EAAE,UAAG,CAAC,QAAQ,CAAC,6CAA6C,EAAE,0EAA0E,CAAC;qBACjJ;oBACD,MAAM,EAAE;wBACJ,IAAI,EAAE,CAAC,QAAQ,EAAE,SAAS,CAAC;wBAC3B,KAAK,EAAE,UAAG,CAAC,QAAQ,CAAC,iDAAiD,EACjE,wGAAwG,CAAC;qBAChH;oBACD,eAAe,EAAE;wBACb,IAAI,EAAE,SAAS;wBACf,KAAK,EAAE,UAAG,CAAC,QAAQ,CAAC,0DAA0D,EAC1E,uEAAuE,CAAC;qBAC/E;oBACD,UAAU,EAAE;wBACR,IAAI,EAAE,SAAS;wBACf,KAAK,EAAE,UAAG,CAAC,QAAQ,CAAC,qDAAqD,EACrE,wEAAwE,CAAC;qBAChF;oBACD,UAAU,EAAE;wBACR,IAAI,EAAE,QAAQ;wBACd,KAAK,EAAE,UAAG,CAAC,QAAQ,CAAC,qDAAqD,EACrE,8DAA8D,CAAC;qBACtE;iBACJ;aACJ;SACJ;KACJ;CACJ,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LanguageModel, LanguageModelRequest, LanguageModelResponse, LanguageModelStatus, LanguageModelStreamResponse, LanguageModelTextResponse, ReasoningApi, ReasoningSupport, ServerToolDescriptor, UserRequest } from '@theia/ai-core';
|
|
1
|
+
import { LanguageModel, LanguageModelMessage, LanguageModelRequest, LanguageModelResponse, LanguageModelStatus, LanguageModelStreamResponse, LanguageModelTextResponse, ReasoningApi, ReasoningSupport, ServerToolDescriptor, UserRequest } from '@theia/ai-core';
|
|
2
2
|
import { CancellationToken } from '@theia/core';
|
|
3
3
|
import { Anthropic } from '@anthropic-ai/sdk';
|
|
4
4
|
import type { MessageParam } from '@anthropic-ai/sdk/resources';
|
|
@@ -9,6 +9,17 @@ export declare const DEFAULT_MAX_TOKENS = 4096;
|
|
|
9
9
|
* for rendering (see {@link buildServerToolResultPart}).
|
|
10
10
|
*/
|
|
11
11
|
export declare const ANTHROPIC_RESULT_BLOCK_DATA_KEY = "anthropicResultBlock";
|
|
12
|
+
/**
|
|
13
|
+
* Transforms Theia language model messages to Anthropic API format
|
|
14
|
+
* @param messages Array of LanguageModelRequestMessage to transform
|
|
15
|
+
* @param addCacheControl whether to add prompt-cache control to the system message
|
|
16
|
+
* @param compactionEnabled whether the request will use the beta endpoint, so compaction replay blocks may be emitted
|
|
17
|
+
* @returns Object containing transformed messages and optional system message
|
|
18
|
+
*/
|
|
19
|
+
export declare function transformToAnthropicParams(messages: readonly LanguageModelMessage[], addCacheControl?: boolean, compactionEnabled?: boolean): {
|
|
20
|
+
messages: MessageParam[];
|
|
21
|
+
systemMessage?: Anthropic.Messages.TextBlockParam[];
|
|
22
|
+
};
|
|
12
23
|
export declare function mergeConsecutiveSameRoleMessages(messages: MessageParam[]): MessageParam[];
|
|
13
24
|
/**
|
|
14
25
|
* If possible adds a cache control to the last message in the conversation.
|
|
@@ -39,10 +50,20 @@ export declare class AnthropicModel implements LanguageModel {
|
|
|
39
50
|
supportsXHighEffort?: boolean | undefined;
|
|
40
51
|
maxInputTokens?: number | undefined;
|
|
41
52
|
serverTools?: ServerToolDescriptor[] | undefined;
|
|
53
|
+
serverSideCompactionSupport: boolean;
|
|
54
|
+
serverSideCompactionEnabledByDefault: boolean;
|
|
55
|
+
serverSideCompactionTokenThresholdByDefault?: number | undefined;
|
|
42
56
|
/** Provider identifier, used to key per-provider settings (e.g. server tool selections) and the capabilities UI. */
|
|
43
57
|
readonly vendor = "anthropic";
|
|
44
|
-
constructor(id: string, model: string, status: LanguageModelStatus, enableStreaming: boolean, useCaching: boolean, apiKey: () => string | undefined, url: string | undefined, maxTokens?: number, maxRetries?: number, proxy?: string | undefined, reasoningSupport?: ReasoningSupport | undefined, reasoningApi?: ReasoningApi | undefined, supportsXHighEffort?: boolean | undefined, maxInputTokens?: number | undefined, serverTools?: ServerToolDescriptor[] | undefined);
|
|
58
|
+
constructor(id: string, model: string, status: LanguageModelStatus, enableStreaming: boolean, useCaching: boolean, apiKey: () => string | undefined, url: string | undefined, maxTokens?: number, maxRetries?: number, proxy?: string | undefined, reasoningSupport?: ReasoningSupport | undefined, reasoningApi?: ReasoningApi | undefined, supportsXHighEffort?: boolean | undefined, maxInputTokens?: number | undefined, serverTools?: ServerToolDescriptor[] | undefined, serverSideCompactionSupport?: boolean, serverSideCompactionEnabledByDefault?: boolean, serverSideCompactionTokenThresholdByDefault?: number | undefined);
|
|
45
59
|
protected getSettings(request: LanguageModelRequest): Readonly<Record<string, unknown>>;
|
|
60
|
+
/** Resolves whether this request will route through the Anthropic Beta Messages API for server-side compaction. */
|
|
61
|
+
protected useServerSideCompaction(request: LanguageModelRequest): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Augments the base message-create params with the beta flag and context-management edit when server-side compaction
|
|
64
|
+
* is enabled for the given request. When disabled, the params are returned unchanged so the default (stable) path is byte-for-byte identical.
|
|
65
|
+
*/
|
|
66
|
+
protected applyCompactionParams<T extends Anthropic.MessageCreateParams>(params: T, request: LanguageModelRequest): T;
|
|
46
67
|
request(request: UserRequest, cancellationToken?: CancellationToken): Promise<LanguageModelResponse>;
|
|
47
68
|
protected handleStreamingRequest(anthropic: Anthropic, request: UserRequest, cancellationToken?: CancellationToken, toolMessages?: readonly Anthropic.Messages.MessageParam[]): Promise<LanguageModelStreamResponse>;
|
|
48
69
|
protected createTools(request: LanguageModelRequest): Anthropic.Messages.ToolUnion[] | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic-language-model.d.ts","sourceRoot":"","sources":["../../src/node/anthropic-language-model.ts"],"names":[],"mappings":"AAgBA,OAAO,EAIH,aAAa,
|
|
1
|
+
{"version":3,"file":"anthropic-language-model.d.ts","sourceRoot":"","sources":["../../src/node/anthropic-language-model.ts"],"names":[],"mappings":"AAgBA,OAAO,EAIH,aAAa,EACb,oBAAoB,EACpB,oBAAoB,EACpB,qBAAqB,EACrB,mBAAmB,EACnB,2BAA2B,EAE3B,yBAAyB,EACzB,YAAY,EACZ,gBAAgB,EAIhB,oBAAoB,EAIpB,WAAW,EACd,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAgB,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,KAAK,EAA+C,YAAY,EAAwC,MAAM,6BAA6B,CAAC;AAKnJ,eAAO,MAAM,kBAAkB,OAAO,CAAC;AAEvC;;;;GAIG;AACH,eAAO,MAAM,+BAA+B,yBAAyB,CAAC;AA2FtE;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CACtC,QAAQ,EAAE,SAAS,oBAAoB,EAAE,EACzC,eAAe,GAAE,OAAc,EAC/B,iBAAiB,GAAE,OAAe,GACnC;IAAE,QAAQ,EAAE,YAAY,EAAE,CAAC;IAAC,aAAa,CAAC,EAAE,SAAS,CAAC,QAAQ,CAAC,cAAc,EAAE,CAAA;CAAE,CAuBnF;AAED,wBAAgB,gCAAgC,CAAC,QAAQ,EAAE,YAAY,EAAE,GAAG,YAAY,EAAE,CAwBzF;AAED;;;;;;GAMG;AACH,wBAAgB,4BAA4B,CAAC,QAAQ,EAAE,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,GAAG,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,CA2B3H;AAED,eAAO,MAAM,wBAAwB,eAAqC,CAAC;AAiE3E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AO,EAAE,oBAAoB,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAOvF,mHAAmH;IACnH,SAAS,CAAC,uBAAuB,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO;IAIzE;;;OAGG;IACH,SAAS,CAAC,qBAAqB,CAAC,CAAC,SAAS,SAAS,CAAC,mBAAmB,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,oBAAoB,GAAG,CAAC;IAgB/G,OAAO,CAAC,OAAO,EAAE,WAAW,EAAE,iBAAiB,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,qBAAqB,CAAC;cAkB1F,sBAAsB,CAClC,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,WAAW,EACpB,iBAAiB,CAAC,EAAE,iBAAiB,EACrC,YAAY,CAAC,EAAE,SAAS,SAAS,CAAC,QAAQ,CAAC,YAAY,EAAE,GAC1D,OAAO,CAAC,2BAA2B,CAAC;IA+OvC,SAAS,CAAC,WAAW,CAAC,OAAO,EAAE,oBAAoB,GAAG,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,GAAG,SAAS;IAsBhG,sGAAsG;IACtG,SAAS,CAAC,iBAAiB,CAAC,OAAO,EAAE,oBAAoB,GAAG,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE;cAY1E,yBAAyB,CACrC,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,WAAW,GACrB,OAAO,CAAC,yBAAyB,CAAC;IAqCrC,SAAS,CAAC,mBAAmB,IAAI,SAAS;CAW7C"}
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
// *****************************************************************************
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.AnthropicModel = exports.AnthropicModelIdentifier = exports.ANTHROPIC_RESULT_BLOCK_DATA_KEY = exports.DEFAULT_MAX_TOKENS = void 0;
|
|
19
|
+
exports.transformToAnthropicParams = transformToAnthropicParams;
|
|
19
20
|
exports.mergeConsecutiveSameRoleMessages = mergeConsecutiveSameRoleMessages;
|
|
20
21
|
exports.addCacheControlToLastMessage = addCacheControlToLastMessage;
|
|
21
22
|
const ai_core_1 = require("@theia/ai-core");
|
|
@@ -31,8 +32,17 @@ exports.DEFAULT_MAX_TOKENS = 4096;
|
|
|
31
32
|
* for rendering (see {@link buildServerToolResultPart}).
|
|
32
33
|
*/
|
|
33
34
|
exports.ANTHROPIC_RESULT_BLOCK_DATA_KEY = 'anthropicResultBlock';
|
|
34
|
-
const createMessageContent = (message) => {
|
|
35
|
-
if (ai_core_1.LanguageModelMessage.
|
|
35
|
+
const createMessageContent = (message, compactionEnabled) => {
|
|
36
|
+
if (ai_core_1.LanguageModelMessage.isCompactionMessage(message)) {
|
|
37
|
+
// Only replay our own provider's compaction blocks, and only when the request will use the beta endpoint.
|
|
38
|
+
// Returning [] for a skipped/foreign/disabled compaction message lets the surrounding real history carry the context.
|
|
39
|
+
if (compactionEnabled && message.provider === 'anthropic') {
|
|
40
|
+
const data = message.data;
|
|
41
|
+
return [{ type: 'compaction', content: data.content, encrypted_content: data.encrypted_content }];
|
|
42
|
+
}
|
|
43
|
+
return [];
|
|
44
|
+
}
|
|
45
|
+
else if (ai_core_1.LanguageModelMessage.isTextMessage(message)) {
|
|
36
46
|
return [{ type: 'text', text: message.text }];
|
|
37
47
|
}
|
|
38
48
|
else if (ai_core_1.LanguageModelMessage.isThinkingMessage(message)) {
|
|
@@ -109,19 +119,26 @@ function isNonThinkingParam(content) {
|
|
|
109
119
|
/**
|
|
110
120
|
* Transforms Theia language model messages to Anthropic API format
|
|
111
121
|
* @param messages Array of LanguageModelRequestMessage to transform
|
|
122
|
+
* @param addCacheControl whether to add prompt-cache control to the system message
|
|
123
|
+
* @param compactionEnabled whether the request will use the beta endpoint, so compaction replay blocks may be emitted
|
|
112
124
|
* @returns Object containing transformed messages and optional system message
|
|
113
125
|
*/
|
|
114
|
-
function transformToAnthropicParams(messages, addCacheControl = true) {
|
|
126
|
+
function transformToAnthropicParams(messages, addCacheControl = true, compactionEnabled = false) {
|
|
115
127
|
// Extract the system message (if any), as it is a separate parameter in the Anthropic API.
|
|
116
128
|
const systemMessageObj = messages.find(message => message.actor === 'system');
|
|
117
129
|
const systemMessageText = systemMessageObj && ai_core_1.LanguageModelMessage.isTextMessage(systemMessageObj) && systemMessageObj.text || undefined;
|
|
118
130
|
const systemMessage = systemMessageText ? [{ type: 'text', text: systemMessageText, cache_control: addCacheControl ? { type: 'ephemeral' } : undefined }] : undefined;
|
|
119
131
|
const convertedMessages = messages
|
|
120
132
|
.filter(message => message.actor !== 'system')
|
|
133
|
+
// The deferred-tool search is surfaced to the UI (see stream handling) but is executed by Anthropic
|
|
134
|
+
// internally; it must not be echoed back as history, so drop it before replay.
|
|
135
|
+
.filter(message => !(ai_core_1.LanguageModelMessage.isServerToolUseMessage(message) && message.name === anthropic_server_tools_1.ANTHROPIC_TOOL_SEARCH))
|
|
121
136
|
.map(message => ({
|
|
122
137
|
role: toAnthropicRole(message),
|
|
123
|
-
content: createMessageContent(message)
|
|
124
|
-
}))
|
|
138
|
+
content: createMessageContent(message, compactionEnabled)
|
|
139
|
+
}))
|
|
140
|
+
// Drop messages whose content converted to empty (e.g. a skipped compaction message), so no empty turns are sent.
|
|
141
|
+
.filter(message => !Array.isArray(message.content) || message.content.length > 0);
|
|
125
142
|
return {
|
|
126
143
|
messages: mergeConsecutiveSameRoleMessages(convertedMessages),
|
|
127
144
|
systemMessage,
|
|
@@ -248,7 +265,7 @@ function buildServerToolResultPart(serverToolCalls, toolUseId, nativeName, resul
|
|
|
248
265
|
* translation lives in {@link anthropicReasoningFor}.
|
|
249
266
|
*/
|
|
250
267
|
class AnthropicModel {
|
|
251
|
-
constructor(id, model, status, enableStreaming, useCaching, apiKey, url, maxTokens = exports.DEFAULT_MAX_TOKENS, maxRetries = 3, proxy, reasoningSupport, reasoningApi, supportsXHighEffort, maxInputTokens, serverTools) {
|
|
268
|
+
constructor(id, model, status, enableStreaming, useCaching, apiKey, url, maxTokens = exports.DEFAULT_MAX_TOKENS, maxRetries = 3, proxy, reasoningSupport, reasoningApi, supportsXHighEffort, maxInputTokens, serverTools, serverSideCompactionSupport = false, serverSideCompactionEnabledByDefault = false, serverSideCompactionTokenThresholdByDefault) {
|
|
252
269
|
this.id = id;
|
|
253
270
|
this.model = model;
|
|
254
271
|
this.status = status;
|
|
@@ -264,6 +281,9 @@ class AnthropicModel {
|
|
|
264
281
|
this.supportsXHighEffort = supportsXHighEffort;
|
|
265
282
|
this.maxInputTokens = maxInputTokens;
|
|
266
283
|
this.serverTools = serverTools;
|
|
284
|
+
this.serverSideCompactionSupport = serverSideCompactionSupport;
|
|
285
|
+
this.serverSideCompactionEnabledByDefault = serverSideCompactionEnabledByDefault;
|
|
286
|
+
this.serverSideCompactionTokenThresholdByDefault = serverSideCompactionTokenThresholdByDefault;
|
|
267
287
|
/** Provider identifier, used to key per-provider settings (e.g. server tool selections) and the capabilities UI. */
|
|
268
288
|
this.vendor = 'anthropic';
|
|
269
289
|
}
|
|
@@ -273,6 +293,29 @@ class AnthropicModel {
|
|
|
273
293
|
...(0, anthropic_reasoning_1.anthropicReasoningFor)(request.reasoning?.level, this.reasoningApi, this.supportsXHighEffort)
|
|
274
294
|
};
|
|
275
295
|
}
|
|
296
|
+
/** Resolves whether this request will route through the Anthropic Beta Messages API for server-side compaction. */
|
|
297
|
+
useServerSideCompaction(request) {
|
|
298
|
+
return (0, ai_core_1.resolveServerSideCompaction)(this.serverSideCompactionSupport, this.serverSideCompactionEnabledByDefault, request.compaction);
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Augments the base message-create params with the beta flag and context-management edit when server-side compaction
|
|
302
|
+
* is enabled for the given request. When disabled, the params are returned unchanged so the default (stable) path is byte-for-byte identical.
|
|
303
|
+
*/
|
|
304
|
+
applyCompactionParams(params, request) {
|
|
305
|
+
if (!this.useServerSideCompaction(request)) {
|
|
306
|
+
return params;
|
|
307
|
+
}
|
|
308
|
+
const betaParams = params;
|
|
309
|
+
const tokenThreshold = (0, ai_core_1.resolveCompactionTokenThreshold)(this.serverSideCompactionTokenThresholdByDefault, request.compaction);
|
|
310
|
+
betaParams.betas = ['compact-2026-01-12'];
|
|
311
|
+
betaParams.context_management = {
|
|
312
|
+
edits: [{
|
|
313
|
+
type: 'compact_20260112',
|
|
314
|
+
...(tokenThreshold !== undefined && { trigger: { type: 'input_tokens', value: tokenThreshold } })
|
|
315
|
+
}]
|
|
316
|
+
};
|
|
317
|
+
return betaParams;
|
|
318
|
+
}
|
|
276
319
|
async request(request, cancellationToken) {
|
|
277
320
|
if (!request.messages?.length) {
|
|
278
321
|
throw new Error('Request must contain at least one message');
|
|
@@ -291,7 +334,8 @@ class AnthropicModel {
|
|
|
291
334
|
}
|
|
292
335
|
async handleStreamingRequest(anthropic, request, cancellationToken, toolMessages) {
|
|
293
336
|
const settings = this.getSettings(request);
|
|
294
|
-
const
|
|
337
|
+
const useCompaction = this.useServerSideCompaction(request);
|
|
338
|
+
const { messages, systemMessage } = transformToAnthropicParams(request.messages, this.useCaching, useCompaction);
|
|
295
339
|
let anthropicMessages = [...messages, ...(toolMessages ?? [])];
|
|
296
340
|
if (this.useCaching && anthropicMessages.length) {
|
|
297
341
|
anthropicMessages = addCacheControlToLastMessage(anthropicMessages);
|
|
@@ -304,7 +348,7 @@ class AnthropicModel {
|
|
|
304
348
|
defer_loading: 'defer_loading' in tool ? tool.defer_loading : undefined
|
|
305
349
|
})));
|
|
306
350
|
}
|
|
307
|
-
const params = {
|
|
351
|
+
const params = this.applyCompactionParams({
|
|
308
352
|
max_tokens: this.maxTokens,
|
|
309
353
|
messages: anthropicMessages,
|
|
310
354
|
tools,
|
|
@@ -312,8 +356,13 @@ class AnthropicModel {
|
|
|
312
356
|
model: this.model,
|
|
313
357
|
...(systemMessage && { system: systemMessage }),
|
|
314
358
|
...settings
|
|
315
|
-
};
|
|
316
|
-
|
|
359
|
+
}, request);
|
|
360
|
+
// The beta message params are a structural superset of the stable ones for the content we build, so the cast at the beta call boundary is safe.
|
|
361
|
+
// The beta stream is likewise structurally compatible with the stable MessageStream: we narrow compaction events via explicit casts in the
|
|
362
|
+
// loop below, and casting the stream here keeps the iterator and lifecycle handling identical on both paths.
|
|
363
|
+
const stream = useCompaction
|
|
364
|
+
? anthropic.beta.messages.stream(params, { maxRetries: this.maxRetries })
|
|
365
|
+
: anthropic.messages.stream(params, { maxRetries: this.maxRetries });
|
|
317
366
|
cancellationToken?.onCancellationRequested(() => {
|
|
318
367
|
stream.abort();
|
|
319
368
|
});
|
|
@@ -329,6 +378,8 @@ class AnthropicModel {
|
|
|
329
378
|
let currentMessage = undefined;
|
|
330
379
|
let currentOutputTokens = 0;
|
|
331
380
|
let usageYielded = false;
|
|
381
|
+
// Accumulator for a streamed compaction block (beta path only): content + opaque encrypted_content across start + deltas.
|
|
382
|
+
let compaction;
|
|
332
383
|
try {
|
|
333
384
|
for await (const event of stream) {
|
|
334
385
|
if (event.type === 'content_block_start') {
|
|
@@ -339,20 +390,22 @@ class AnthropicModel {
|
|
|
339
390
|
if (contentBlock.type === 'text') {
|
|
340
391
|
yield { content: contentBlock.text };
|
|
341
392
|
}
|
|
393
|
+
// Compaction blocks only occur on the beta path; guard via type narrowing.
|
|
394
|
+
if (contentBlock.type === 'compaction') {
|
|
395
|
+
const block = contentBlock;
|
|
396
|
+
compaction = { index: event.index, content: block.content, encrypted_content: block.encrypted_content };
|
|
397
|
+
}
|
|
342
398
|
if (contentBlock.type === 'tool_use') {
|
|
343
399
|
toolCall = { name: contentBlock.name, args: '', id: contentBlock.id, index: event.index };
|
|
344
400
|
yield { tool_calls: [{ finished: false, id: toolCall.id, function: { name: toolCall.name, arguments: toolCall.args } }] };
|
|
345
401
|
}
|
|
346
402
|
if (contentBlock.type === 'server_tool_use') {
|
|
347
|
-
// The deferred-tool search invocation also arrives as `server_tool_use
|
|
348
|
-
//
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
serverToolCall = { name: contentBlock.name, args: '', id: contentBlock.id, index: event.index };
|
|
354
|
-
yield { server_tool_calls: [{ id: serverToolCall.id, name: serverToolCall.name, arguments: '', finished: false }] };
|
|
355
|
-
}
|
|
403
|
+
// The deferred-tool search invocation also arrives as `server_tool_use` (native name
|
|
404
|
+
// `tool_search_tool_bm25`); surface it under a stable, user-facing name so the UI shows the
|
|
405
|
+
// search running. Anthropic executes it on its own infrastructure, like other server tools.
|
|
406
|
+
const name = contentBlock.name === anthropic_server_tools_1.ANTHROPIC_TOOL_SEARCH_NATIVE ? anthropic_server_tools_1.ANTHROPIC_TOOL_SEARCH : contentBlock.name;
|
|
407
|
+
serverToolCall = { name, args: '', id: contentBlock.id, index: event.index };
|
|
408
|
+
yield { server_tool_calls: [{ id: serverToolCall.id, name: serverToolCall.name, arguments: '', finished: false }] };
|
|
356
409
|
}
|
|
357
410
|
if (contentBlock.type === 'web_fetch_tool_result') {
|
|
358
411
|
// Result blocks are delivered complete (not streamed). Surface them as a finished server tool call.
|
|
@@ -375,7 +428,21 @@ class AnthropicModel {
|
|
|
375
428
|
yield buildServerToolResultPart(serverToolCalls, contentBlock.tool_use_id, anthropic_server_tools_1.ANTHROPIC_WEB_SEARCH, result, searchContent);
|
|
376
429
|
}
|
|
377
430
|
if (contentBlock.type === 'tool_search_tool_result') {
|
|
378
|
-
|
|
431
|
+
// Result blocks are delivered complete (not streamed). Finish the search server tool call so
|
|
432
|
+
// the UI replaces the spinner with a summary.
|
|
433
|
+
const searchContent = contentBlock.content;
|
|
434
|
+
let result;
|
|
435
|
+
if (searchContent.type === 'tool_search_tool_search_result') {
|
|
436
|
+
const found = searchContent.tool_references.length;
|
|
437
|
+
const text = found === 1
|
|
438
|
+
? core_1.nls.localize('theia/ai/anthropic/toolSearch/foundOne', 'Found 1 tool.')
|
|
439
|
+
: core_1.nls.localize('theia/ai/anthropic/toolSearch/found', 'Found {0} tools.', found);
|
|
440
|
+
result = { content: [{ type: 'text', text }] };
|
|
441
|
+
}
|
|
442
|
+
else {
|
|
443
|
+
result = (0, ai_core_1.createToolCallError)(core_1.nls.localize('theia/ai/anthropic/toolSearch/failed', 'Tool search failed: {0}', searchContent.error_code));
|
|
444
|
+
}
|
|
445
|
+
yield buildServerToolResultPart(serverToolCalls, contentBlock.tool_use_id, anthropic_server_tools_1.ANTHROPIC_TOOL_SEARCH, result, searchContent);
|
|
379
446
|
}
|
|
380
447
|
}
|
|
381
448
|
else if (event.type === 'content_block_delta') {
|
|
@@ -389,6 +456,11 @@ class AnthropicModel {
|
|
|
389
456
|
if (delta.type === 'text_delta') {
|
|
390
457
|
yield { content: delta.text };
|
|
391
458
|
}
|
|
459
|
+
if (compaction && delta.type === 'compaction_delta') {
|
|
460
|
+
const compactionDelta = delta;
|
|
461
|
+
compaction.content = compactionDelta.content;
|
|
462
|
+
compaction.encrypted_content = compactionDelta.encrypted_content;
|
|
463
|
+
}
|
|
392
464
|
if (toolCall && delta.type === 'input_json_delta') {
|
|
393
465
|
toolCall.args += delta.partial_json;
|
|
394
466
|
yield { tool_calls: [{ function: { arguments: delta.partial_json } }] };
|
|
@@ -407,6 +479,11 @@ class AnthropicModel {
|
|
|
407
479
|
serverToolCalls.push(serverToolCall);
|
|
408
480
|
serverToolCall = undefined;
|
|
409
481
|
}
|
|
482
|
+
if (compaction && compaction.index === event.index) {
|
|
483
|
+
const data = { content: compaction.content, encrypted_content: compaction.encrypted_content };
|
|
484
|
+
yield { compaction: { provider: 'anthropic', data, summary: compaction.content ?? undefined } };
|
|
485
|
+
compaction = undefined;
|
|
486
|
+
}
|
|
410
487
|
}
|
|
411
488
|
else if (event.type === 'message_delta') {
|
|
412
489
|
currentOutputTokens = event.usage.output_tokens;
|
|
@@ -491,8 +568,8 @@ class AnthropicModel {
|
|
|
491
568
|
}));
|
|
492
569
|
if (deferred.size > 0) {
|
|
493
570
|
tools.push({
|
|
494
|
-
type:
|
|
495
|
-
name:
|
|
571
|
+
type: anthropic_server_tools_1.ANTHROPIC_TOOL_SEARCH_NATIVE,
|
|
572
|
+
name: anthropic_server_tools_1.ANTHROPIC_TOOL_SEARCH_NATIVE
|
|
496
573
|
});
|
|
497
574
|
}
|
|
498
575
|
// Cache the client tools as before; server tools are appended afterwards.
|
|
@@ -516,16 +593,20 @@ class AnthropicModel {
|
|
|
516
593
|
}
|
|
517
594
|
async handleNonStreamingRequest(anthropic, request) {
|
|
518
595
|
const settings = this.getSettings(request);
|
|
519
|
-
const
|
|
520
|
-
const
|
|
596
|
+
const useCompaction = this.useServerSideCompaction(request);
|
|
597
|
+
const { messages, systemMessage } = transformToAnthropicParams(request.messages, true, useCompaction);
|
|
598
|
+
const params = this.applyCompactionParams({
|
|
521
599
|
max_tokens: this.maxTokens,
|
|
522
600
|
messages,
|
|
523
601
|
model: this.model,
|
|
524
602
|
...(systemMessage && { system: systemMessage }),
|
|
525
603
|
...settings,
|
|
526
|
-
};
|
|
604
|
+
}, request);
|
|
527
605
|
try {
|
|
528
|
-
|
|
606
|
+
// The beta message params are a structural superset of the stable ones, so the cast at the beta call boundary is safe.
|
|
607
|
+
const response = useCompaction
|
|
608
|
+
? await anthropic.beta.messages.create(params)
|
|
609
|
+
: await anthropic.messages.create(params);
|
|
529
610
|
const textContent = response.content[0];
|
|
530
611
|
const usage = response.usage ? {
|
|
531
612
|
input_tokens: response.usage.input_tokens,
|