@langchain/google-common 0.1.1 → 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.
@@ -1,7 +1,8 @@
1
1
  import { BaseLanguageModelCallOptions } from "@langchain/core/language_models/base";
2
2
  import { AsyncCaller, AsyncCallerCallOptions } from "@langchain/core/utils/async_caller";
3
- import { StructuredToolParams } from "@langchain/core/tools";
4
- import type { GoogleAIBaseLLMInput, GoogleConnectionParams, GoogleLLMModelFamily, GooglePlatformType, GoogleResponse, GoogleLLMResponse, GeminiContent, GeminiGenerationConfig, GeminiRequest, GeminiSafetySetting, GeminiTool, GeminiFunctionDeclaration, GoogleAIModelRequestParams, GoogleRawResponse } from "./types.js";
3
+ import { BaseRunManager } from "@langchain/core/callbacks/manager";
4
+ import { BaseCallbackHandler } from "@langchain/core/callbacks/base";
5
+ import type { GoogleAIBaseLLMInput, GoogleConnectionParams, GooglePlatformType, GoogleResponse, GoogleLLMResponse, GoogleAIModelRequestParams, GoogleRawResponse, GoogleAIAPI, VertexModelFamily, GoogleAIAPIConfig } from "./types.js";
5
6
  import { GoogleAbstractedClient, GoogleAbstractedClientOps, GoogleAbstractedClientOpsMethod } from "./auth.js";
6
7
  export declare abstract class GoogleConnection<CallOptions extends AsyncCallerCallOptions, ResponseType extends GoogleResponse> {
7
8
  caller: AsyncCaller;
@@ -22,12 +23,16 @@ export declare abstract class GoogleConnection<CallOptions extends AsyncCallerCa
22
23
  }
23
24
  export declare abstract class GoogleHostConnection<CallOptions extends AsyncCallerCallOptions, ResponseType extends GoogleResponse, AuthOptions> extends GoogleConnection<CallOptions, ResponseType> implements GoogleConnectionParams<AuthOptions> {
24
25
  platformType: GooglePlatformType | undefined;
25
- endpoint: string;
26
- location: string;
26
+ _endpoint: string | undefined;
27
+ _location: string | undefined;
27
28
  apiVersion: string;
28
29
  constructor(fields: GoogleConnectionParams<AuthOptions> | undefined, caller: AsyncCaller, client: GoogleAbstractedClient, streaming?: boolean);
29
30
  get platform(): GooglePlatformType;
30
31
  get computedPlatformType(): GooglePlatformType;
32
+ get location(): string;
33
+ get computedLocation(): string;
34
+ get endpoint(): string;
35
+ get computedEndpoint(): string;
31
36
  buildMethod(): GoogleAbstractedClientOpsMethod;
32
37
  }
33
38
  export declare abstract class GoogleRawConnection<CallOptions extends AsyncCallerCallOptions, AuthOptions> extends GoogleHostConnection<CallOptions, GoogleRawResponse, AuthOptions> {
@@ -37,27 +42,53 @@ export declare abstract class GoogleAIConnection<CallOptions extends AsyncCaller
37
42
  model: string;
38
43
  modelName: string;
39
44
  client: GoogleAbstractedClient;
40
- api: any;
45
+ _apiName?: string;
46
+ apiConfig?: GoogleAIAPIConfig;
41
47
  constructor(fields: GoogleAIBaseLLMInput<AuthOptions> | undefined, caller: AsyncCaller, client: GoogleAbstractedClient, streaming?: boolean);
42
- get modelFamily(): GoogleLLMModelFamily;
48
+ get modelFamily(): VertexModelFamily;
49
+ get modelPublisher(): string;
50
+ get computedAPIName(): string;
51
+ get apiName(): string;
52
+ get api(): GoogleAIAPI;
43
53
  get computedPlatformType(): GooglePlatformType;
54
+ get computedLocation(): string;
44
55
  abstract buildUrlMethod(): Promise<string>;
45
56
  buildUrlGenerativeLanguage(): Promise<string>;
46
57
  buildUrlVertex(): Promise<string>;
47
58
  buildUrl(): Promise<string>;
48
59
  abstract formatData(input: InputType, parameters: GoogleAIModelRequestParams): Promise<unknown>;
49
- request(input: InputType, parameters: GoogleAIModelRequestParams, options: CallOptions): Promise<GoogleResponse>;
60
+ request(input: InputType, parameters: GoogleAIModelRequestParams, options: CallOptions, runManager?: BaseRunManager): Promise<ResponseType>;
50
61
  }
51
62
  export declare abstract class AbstractGoogleLLMConnection<MessageType, AuthOptions> extends GoogleAIConnection<BaseLanguageModelCallOptions, MessageType, AuthOptions, GoogleLLMResponse> {
52
63
  buildUrlMethodGemini(): Promise<string>;
64
+ buildUrlMethodClaude(): Promise<string>;
53
65
  buildUrlMethod(): Promise<string>;
54
- abstract formatContents(input: MessageType, parameters: GoogleAIModelRequestParams): Promise<GeminiContent[]>;
55
- formatGenerationConfig(_input: MessageType, parameters: GoogleAIModelRequestParams): GeminiGenerationConfig;
56
- formatSafetySettings(_input: MessageType, parameters: GoogleAIModelRequestParams): GeminiSafetySetting[];
57
- formatSystemInstruction(_input: MessageType, _parameters: GoogleAIModelRequestParams): Promise<GeminiContent>;
58
- structuredToolToFunctionDeclaration(tool: StructuredToolParams): GeminiFunctionDeclaration;
59
- structuredToolsToGeminiTools(tools: StructuredToolParams[]): GeminiTool[];
60
- formatTools(_input: MessageType, parameters: GoogleAIModelRequestParams): GeminiTool[];
61
- formatToolConfig(parameters: GoogleAIModelRequestParams): GeminiRequest["toolConfig"] | undefined;
62
- formatData(input: MessageType, parameters: GoogleAIModelRequestParams): Promise<GeminiRequest>;
66
+ formatData(input: MessageType, parameters: GoogleAIModelRequestParams): Promise<unknown>;
67
+ }
68
+ export interface GoogleCustomEventInfo {
69
+ subEvent: string;
70
+ module: string;
71
+ }
72
+ export declare abstract class GoogleRequestCallbackHandler extends BaseCallbackHandler {
73
+ customEventInfo(eventName: string): GoogleCustomEventInfo;
74
+ abstract handleCustomRequestEvent(eventName: string, eventInfo: GoogleCustomEventInfo, data: any, runId: string, tags?: string[], metadata?: Record<string, any>): any;
75
+ abstract handleCustomResponseEvent(eventName: string, eventInfo: GoogleCustomEventInfo, data: any, runId: string, tags?: string[], metadata?: Record<string, any>): any;
76
+ abstract handleCustomChunkEvent(eventName: string, eventInfo: GoogleCustomEventInfo, data: any, runId: string, tags?: string[], metadata?: Record<string, any>): any;
77
+ handleCustomEvent(eventName: string, data: any, runId: string, tags?: string[], metadata?: Record<string, any>): any;
78
+ }
79
+ export declare class GoogleRequestLogger extends GoogleRequestCallbackHandler {
80
+ name: string;
81
+ log(eventName: string, data: any, tags?: string[]): undefined;
82
+ handleCustomRequestEvent(eventName: string, _eventInfo: GoogleCustomEventInfo, data: any, _runId: string, tags?: string[], _metadata?: Record<string, any>): any;
83
+ handleCustomResponseEvent(eventName: string, _eventInfo: GoogleCustomEventInfo, data: any, _runId: string, tags?: string[], _metadata?: Record<string, any>): any;
84
+ handleCustomChunkEvent(eventName: string, _eventInfo: GoogleCustomEventInfo, data: any, _runId: string, tags?: string[], _metadata?: Record<string, any>): any;
85
+ }
86
+ export declare class GoogleRequestRecorder extends GoogleRequestCallbackHandler {
87
+ name: string;
88
+ request: any;
89
+ response: any;
90
+ chunk: any[];
91
+ handleCustomRequestEvent(_eventName: string, _eventInfo: GoogleCustomEventInfo, data: any, _runId: string, _tags?: string[], _metadata?: Record<string, any>): any;
92
+ handleCustomResponseEvent(_eventName: string, _eventInfo: GoogleCustomEventInfo, data: any, _runId: string, _tags?: string[], _metadata?: Record<string, any>): any;
93
+ handleCustomChunkEvent(_eventName: string, _eventInfo: GoogleCustomEventInfo, data: any, _runId: string, _tags?: string[], _metadata?: Record<string, any>): any;
63
94
  }
@@ -1,7 +1,7 @@
1
1
  import { getRuntimeEnvironment } from "@langchain/core/utils/env";
2
- import { isLangChainTool } from "@langchain/core/utils/function_calling";
3
- import { zodToGeminiParameters } from "./utils/zod_to_gemini_parameters.js";
4
- import { getGeminiAPI } from "./utils/index.js";
2
+ import { BaseCallbackHandler } from "@langchain/core/callbacks/base";
3
+ import { getGeminiAPI, modelToFamily, modelToPublisher, } from "./utils/index.js";
4
+ import { getAnthropicAPI } from "./utils/anthropic.js";
5
5
  export class GoogleConnection {
6
6
  constructor(caller, client, streaming) {
7
7
  Object.defineProperty(this, "caller", {
@@ -98,17 +98,17 @@ export class GoogleHostConnection extends GoogleConnection {
98
98
  writable: true,
99
99
  value: void 0
100
100
  });
101
- Object.defineProperty(this, "endpoint", {
101
+ Object.defineProperty(this, "_endpoint", {
102
102
  enumerable: true,
103
103
  configurable: true,
104
104
  writable: true,
105
- value: "us-central1-aiplatform.googleapis.com"
105
+ value: void 0
106
106
  });
107
- Object.defineProperty(this, "location", {
107
+ Object.defineProperty(this, "_location", {
108
108
  enumerable: true,
109
109
  configurable: true,
110
110
  writable: true,
111
- value: "us-central1"
111
+ value: void 0
112
112
  });
113
113
  Object.defineProperty(this, "apiVersion", {
114
114
  enumerable: true,
@@ -118,8 +118,8 @@ export class GoogleHostConnection extends GoogleConnection {
118
118
  });
119
119
  this.caller = caller;
120
120
  this.platformType = fields?.platformType;
121
- this.endpoint = fields?.endpoint ?? this.endpoint;
122
- this.location = fields?.location ?? this.location;
121
+ this._endpoint = fields?.endpoint;
122
+ this._location = fields?.location;
123
123
  this.apiVersion = fields?.apiVersion ?? this.apiVersion;
124
124
  this.client = client;
125
125
  }
@@ -129,6 +129,18 @@ export class GoogleHostConnection extends GoogleConnection {
129
129
  get computedPlatformType() {
130
130
  return "gcp";
131
131
  }
132
+ get location() {
133
+ return this._location ?? this.computedLocation;
134
+ }
135
+ get computedLocation() {
136
+ return "us-central1";
137
+ }
138
+ get endpoint() {
139
+ return this._endpoint ?? this.computedEndpoint;
140
+ }
141
+ get computedEndpoint() {
142
+ return `${this.location}-aiplatform.googleapis.com`;
143
+ }
132
144
  buildMethod() {
133
145
  return "POST";
134
146
  }
@@ -161,24 +173,48 @@ export class GoogleAIConnection extends GoogleHostConnection {
161
173
  writable: true,
162
174
  value: void 0
163
175
  });
164
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
165
- Object.defineProperty(this, "api", {
176
+ Object.defineProperty(this, "_apiName", {
177
+ enumerable: true,
178
+ configurable: true,
179
+ writable: true,
180
+ value: void 0
181
+ });
182
+ Object.defineProperty(this, "apiConfig", {
166
183
  enumerable: true,
167
184
  configurable: true,
168
185
  writable: true,
169
186
  value: void 0
170
- }); // FIXME: Make this a real type
187
+ });
171
188
  this.client = client;
172
189
  this.modelName = fields?.model ?? fields?.modelName ?? this.model;
173
190
  this.model = this.modelName;
174
- this.api = getGeminiAPI(fields);
191
+ this._apiName = fields?.apiName;
192
+ this.apiConfig = {
193
+ safetyHandler: fields?.safetyHandler,
194
+ ...fields?.apiConfig,
195
+ };
175
196
  }
176
197
  get modelFamily() {
177
- if (this.model.startsWith("gemini")) {
178
- return "gemini";
179
- }
180
- else {
181
- return null;
198
+ return modelToFamily(this.model);
199
+ }
200
+ get modelPublisher() {
201
+ return modelToPublisher(this.model);
202
+ }
203
+ get computedAPIName() {
204
+ // At least at the moment, model publishers and APIs map the same
205
+ return this.modelPublisher;
206
+ }
207
+ get apiName() {
208
+ return this._apiName ?? this.computedAPIName;
209
+ }
210
+ get api() {
211
+ switch (this.apiName) {
212
+ case "google":
213
+ return getGeminiAPI(this.apiConfig);
214
+ case "anthropic":
215
+ return getAnthropicAPI(this.apiConfig);
216
+ default:
217
+ throw new Error(`Unknown API: ${this.apiName}`);
182
218
  }
183
219
  }
184
220
  get computedPlatformType() {
@@ -189,6 +225,16 @@ export class GoogleAIConnection extends GoogleHostConnection {
189
225
  return "gcp";
190
226
  }
191
227
  }
228
+ get computedLocation() {
229
+ switch (this.apiName) {
230
+ case "google":
231
+ return super.computedLocation;
232
+ case "anthropic":
233
+ return "us-east5";
234
+ default:
235
+ throw new Error(`Unknown apiName: ${this.apiName}. Can't get location.`);
236
+ }
237
+ }
192
238
  async buildUrlGenerativeLanguage() {
193
239
  const method = await this.buildUrlMethod();
194
240
  const url = `https://generativelanguage.googleapis.com/${this.apiVersion}/models/${this.model}:${method}`;
@@ -197,7 +243,8 @@ export class GoogleAIConnection extends GoogleHostConnection {
197
243
  async buildUrlVertex() {
198
244
  const projectId = await this.client.getProjectId();
199
245
  const method = await this.buildUrlMethod();
200
- const url = `https://${this.endpoint}/${this.apiVersion}/projects/${projectId}/locations/${this.location}/publishers/google/models/${this.model}:${method}`;
246
+ const publisher = this.modelPublisher;
247
+ const url = `https://${this.endpoint}/${this.apiVersion}/projects/${projectId}/locations/${this.location}/publishers/${publisher}/models/${this.model}:${method}`;
201
248
  return url;
202
249
  }
203
250
  async buildUrl() {
@@ -208,9 +255,30 @@ export class GoogleAIConnection extends GoogleHostConnection {
208
255
  return this.buildUrlVertex();
209
256
  }
210
257
  }
211
- async request(input, parameters, options) {
212
- const data = await this.formatData(input, parameters);
258
+ async request(input, parameters, options, runManager) {
259
+ const moduleName = this.constructor.name;
260
+ const streamingParameters = {
261
+ ...parameters,
262
+ streaming: this.streaming,
263
+ };
264
+ const data = await this.formatData(input, streamingParameters);
265
+ await runManager?.handleCustomEvent(`google-request-${moduleName}`, {
266
+ data,
267
+ parameters: streamingParameters,
268
+ options,
269
+ connection: {
270
+ ...this,
271
+ url: await this.buildUrl(),
272
+ urlMethod: await this.buildUrlMethod(),
273
+ modelFamily: this.modelFamily,
274
+ modelPublisher: this.modelPublisher,
275
+ computedPlatformType: this.computedPlatformType,
276
+ },
277
+ });
213
278
  const response = await this._request(data, options);
279
+ await runManager?.handleCustomEvent(`google-response-${moduleName}`, {
280
+ response,
281
+ });
214
282
  return response;
215
283
  }
216
284
  }
@@ -218,98 +286,107 @@ export class AbstractGoogleLLMConnection extends GoogleAIConnection {
218
286
  async buildUrlMethodGemini() {
219
287
  return this.streaming ? "streamGenerateContent" : "generateContent";
220
288
  }
289
+ async buildUrlMethodClaude() {
290
+ return this.streaming ? "streamRawPredict" : "rawPredict";
291
+ }
221
292
  async buildUrlMethod() {
222
293
  switch (this.modelFamily) {
223
294
  case "gemini":
224
295
  return this.buildUrlMethodGemini();
296
+ case "claude":
297
+ return this.buildUrlMethodClaude();
225
298
  default:
226
299
  throw new Error(`Unknown model family: ${this.modelFamily}`);
227
300
  }
228
301
  }
229
- formatGenerationConfig(_input, parameters) {
302
+ async formatData(input, parameters) {
303
+ return this.api.formatData(input, parameters);
304
+ }
305
+ }
306
+ export class GoogleRequestCallbackHandler extends BaseCallbackHandler {
307
+ customEventInfo(eventName) {
308
+ const names = eventName.split("-");
230
309
  return {
231
- temperature: parameters.temperature,
232
- topK: parameters.topK,
233
- topP: parameters.topP,
234
- maxOutputTokens: parameters.maxOutputTokens,
235
- stopSequences: parameters.stopSequences,
236
- responseMimeType: parameters.responseMimeType,
310
+ subEvent: names[1],
311
+ module: names[2],
237
312
  };
238
313
  }
239
- formatSafetySettings(_input, parameters) {
240
- return parameters.safetySettings ?? [];
314
+ handleCustomEvent(eventName, data, runId, tags, metadata) {
315
+ if (!eventName) {
316
+ return undefined;
317
+ }
318
+ const eventInfo = this.customEventInfo(eventName);
319
+ switch (eventInfo.subEvent) {
320
+ case "request":
321
+ return this.handleCustomRequestEvent(eventName, eventInfo, data, runId, tags, metadata);
322
+ case "response":
323
+ return this.handleCustomResponseEvent(eventName, eventInfo, data, runId, tags, metadata);
324
+ case "chunk":
325
+ return this.handleCustomChunkEvent(eventName, eventInfo, data, runId, tags, metadata);
326
+ default:
327
+ console.error(`Unexpected eventInfo for ${eventName} ${JSON.stringify(eventInfo, null, 1)}`);
328
+ }
241
329
  }
242
- async formatSystemInstruction(_input, _parameters) {
243
- return {};
330
+ }
331
+ export class GoogleRequestLogger extends GoogleRequestCallbackHandler {
332
+ constructor() {
333
+ super(...arguments);
334
+ Object.defineProperty(this, "name", {
335
+ enumerable: true,
336
+ configurable: true,
337
+ writable: true,
338
+ value: "GoogleRequestLogger"
339
+ });
244
340
  }
245
- structuredToolToFunctionDeclaration(tool) {
246
- const jsonSchema = zodToGeminiParameters(tool.schema);
247
- return {
248
- name: tool.name,
249
- description: tool.description ?? `A function available to call.`,
250
- parameters: jsonSchema,
251
- };
341
+ log(eventName, data, tags) {
342
+ const tagStr = tags ? `[${tags}]` : "[]";
343
+ console.log(`${eventName} ${tagStr} ${JSON.stringify(data, null, 1)}`);
252
344
  }
253
- structuredToolsToGeminiTools(tools) {
254
- return [
255
- {
256
- functionDeclarations: tools.map(this.structuredToolToFunctionDeclaration),
257
- },
258
- ];
345
+ handleCustomRequestEvent(eventName, _eventInfo, data, _runId, tags, _metadata) {
346
+ this.log(eventName, data, tags);
259
347
  }
260
- formatTools(_input, parameters) {
261
- const tools = parameters?.tools;
262
- if (!tools || tools.length === 0) {
263
- return [];
264
- }
265
- if (tools.every(isLangChainTool)) {
266
- return this.structuredToolsToGeminiTools(tools);
267
- }
268
- else {
269
- if (tools.length === 1 &&
270
- (!("functionDeclarations" in tools[0]) ||
271
- !tools[0].functionDeclarations?.length)) {
272
- return [];
273
- }
274
- return tools;
275
- }
348
+ handleCustomResponseEvent(eventName, _eventInfo, data, _runId, tags, _metadata) {
349
+ this.log(eventName, data, tags);
276
350
  }
277
- formatToolConfig(parameters) {
278
- if (!parameters.tool_choice || typeof parameters.tool_choice !== "string") {
279
- return undefined;
280
- }
281
- return {
282
- functionCallingConfig: {
283
- mode: parameters.tool_choice,
284
- allowedFunctionNames: parameters.allowed_function_names,
285
- },
286
- };
351
+ handleCustomChunkEvent(eventName, _eventInfo, data, _runId, tags, _metadata) {
352
+ this.log(eventName, data, tags);
287
353
  }
288
- async formatData(input, parameters) {
289
- const contents = await this.formatContents(input, parameters);
290
- const generationConfig = this.formatGenerationConfig(input, parameters);
291
- const tools = this.formatTools(input, parameters);
292
- const toolConfig = this.formatToolConfig(parameters);
293
- const safetySettings = this.formatSafetySettings(input, parameters);
294
- const systemInstruction = await this.formatSystemInstruction(input, parameters);
295
- const ret = {
296
- contents,
297
- generationConfig,
298
- };
299
- if (tools && tools.length) {
300
- ret.tools = tools;
301
- }
302
- if (toolConfig) {
303
- ret.toolConfig = toolConfig;
304
- }
305
- if (safetySettings && safetySettings.length) {
306
- ret.safetySettings = safetySettings;
307
- }
308
- if (systemInstruction?.role &&
309
- systemInstruction?.parts &&
310
- systemInstruction?.parts?.length) {
311
- ret.systemInstruction = systemInstruction;
312
- }
313
- return ret;
354
+ }
355
+ export class GoogleRequestRecorder extends GoogleRequestCallbackHandler {
356
+ constructor() {
357
+ super(...arguments);
358
+ Object.defineProperty(this, "name", {
359
+ enumerable: true,
360
+ configurable: true,
361
+ writable: true,
362
+ value: "GoogleRequestRecorder"
363
+ });
364
+ Object.defineProperty(this, "request", {
365
+ enumerable: true,
366
+ configurable: true,
367
+ writable: true,
368
+ value: {}
369
+ });
370
+ Object.defineProperty(this, "response", {
371
+ enumerable: true,
372
+ configurable: true,
373
+ writable: true,
374
+ value: {}
375
+ });
376
+ Object.defineProperty(this, "chunk", {
377
+ enumerable: true,
378
+ configurable: true,
379
+ writable: true,
380
+ value: []
381
+ });
382
+ }
383
+ handleCustomRequestEvent(_eventName, _eventInfo, data, _runId, _tags, _metadata) {
384
+ this.request = data;
385
+ }
386
+ handleCustomResponseEvent(_eventName, _eventInfo, data, _runId, _tags, _metadata) {
387
+ this.response = data;
388
+ }
389
+ handleCustomChunkEvent(_eventName, _eventInfo, data, _runId, _tags, _metadata) {
390
+ this.chunk.push(data);
314
391
  }
315
392
  }
package/dist/llms.cjs CHANGED
@@ -175,7 +175,7 @@ class GoogleBaseLLM extends llms_1.LLM {
175
175
  async _call(prompt, options) {
176
176
  const parameters = (0, common_js_1.copyAIModelParams)(this, options);
177
177
  const result = await this.connection.request(prompt, parameters, options);
178
- const ret = this.connection.api.safeResponseToString(result, this.safetyHandler);
178
+ const ret = this.connection.api.responseToString(result);
179
179
  return ret;
180
180
  }
181
181
  // Normally, you should not override this method and instead should override
@@ -217,7 +217,7 @@ class GoogleBaseLLM extends llms_1.LLM {
217
217
  async predictMessages(messages, options, _callbacks) {
218
218
  const { content } = messages[0];
219
219
  const result = await this.connection.request(content, {}, options);
220
- const ret = this.connection.api.safeResponseToBaseMessage(result, this.safetyHandler);
220
+ const ret = this.connection.api.responseToBaseMessage(result);
221
221
  return ret;
222
222
  }
223
223
  /**
package/dist/llms.js CHANGED
@@ -172,7 +172,7 @@ export class GoogleBaseLLM extends LLM {
172
172
  async _call(prompt, options) {
173
173
  const parameters = copyAIModelParams(this, options);
174
174
  const result = await this.connection.request(prompt, parameters, options);
175
- const ret = this.connection.api.safeResponseToString(result, this.safetyHandler);
175
+ const ret = this.connection.api.responseToString(result);
176
176
  return ret;
177
177
  }
178
178
  // Normally, you should not override this method and instead should override
@@ -214,7 +214,7 @@ export class GoogleBaseLLM extends LLM {
214
214
  async predictMessages(messages, options, _callbacks) {
215
215
  const { content } = messages[0];
216
216
  const result = await this.connection.request(content, {}, options);
217
- const ret = this.connection.api.safeResponseToBaseMessage(result, this.safetyHandler);
217
+ const ret = this.connection.api.responseToBaseMessage(result);
218
218
  return ret;
219
219
  }
220
220
  /**
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,159 @@
1
+ export interface AnthropicCacheControl {
2
+ type: "ephemeral" | string;
3
+ }
4
+ interface AnthropicMessageContentBase {
5
+ type: string;
6
+ cache_control?: AnthropicCacheControl | null;
7
+ }
8
+ export interface AnthropicMessageContentText extends AnthropicMessageContentBase {
9
+ type: "text";
10
+ text: string;
11
+ }
12
+ export interface AnthropicMessageContentImage extends AnthropicMessageContentBase {
13
+ type: "image";
14
+ source: {
15
+ type: "base64" | string;
16
+ media_type: string;
17
+ data: string;
18
+ };
19
+ }
20
+ export type AnthropicMessageContentToolUseInput = object;
21
+ export interface AnthropicMessageContentToolUse extends AnthropicMessageContentBase {
22
+ type: "tool_use";
23
+ id: string;
24
+ name: string;
25
+ input: AnthropicMessageContentToolUseInput;
26
+ }
27
+ export type AnthropicMessageContentToolResultContent = AnthropicMessageContentText | AnthropicMessageContentImage;
28
+ export interface AnthropicMessageContentToolResult extends AnthropicMessageContentBase {
29
+ type: "tool_result";
30
+ tool_use_id: string;
31
+ is_error?: boolean;
32
+ content: string | AnthropicMessageContentToolResultContent[];
33
+ }
34
+ export type AnthropicMessageContent = AnthropicMessageContentText | AnthropicMessageContentImage | AnthropicMessageContentToolUse | AnthropicMessageContentToolResult;
35
+ export interface AnthropicMessage {
36
+ role: string;
37
+ content: string | AnthropicMessageContent[];
38
+ }
39
+ export interface AnthropicMetadata {
40
+ user_id?: string | null;
41
+ }
42
+ interface AnthropicToolChoiceBase {
43
+ type: string;
44
+ }
45
+ export interface AnthropicToolChoiceAuto extends AnthropicToolChoiceBase {
46
+ type: "auto";
47
+ }
48
+ export interface AnthropicToolChoiceAny extends AnthropicToolChoiceBase {
49
+ type: "any";
50
+ }
51
+ export interface AnthropicToolChoiceTool extends AnthropicToolChoiceBase {
52
+ type: "tool";
53
+ name: string;
54
+ }
55
+ export type AnthropicToolChoice = AnthropicToolChoiceAuto | AnthropicToolChoiceAny | AnthropicToolChoiceTool;
56
+ export type AnthropicToolInputSchema = object;
57
+ export interface AnthropicTool {
58
+ type?: string;
59
+ name: string;
60
+ description?: string;
61
+ cache_control?: AnthropicCacheControl;
62
+ input_schema: AnthropicToolInputSchema;
63
+ }
64
+ export interface AnthropicRequest {
65
+ anthropic_version: string;
66
+ messages: AnthropicMessage[];
67
+ system?: string;
68
+ stream?: boolean;
69
+ max_tokens: number;
70
+ temperature?: number;
71
+ top_k?: number;
72
+ top_p?: number;
73
+ stop_sequences?: string[];
74
+ metadata?: AnthropicMetadata;
75
+ tool_choice?: AnthropicToolChoice;
76
+ tools?: AnthropicTool[];
77
+ }
78
+ export type AnthropicRequestSettings = Pick<AnthropicRequest, "max_tokens" | "temperature" | "top_k" | "top_p" | "stop_sequences" | "stream">;
79
+ export interface AnthropicContentText {
80
+ type: "text";
81
+ text: string;
82
+ }
83
+ export interface AnthropicContentToolUse {
84
+ type: "tool_use";
85
+ id: string;
86
+ name: string;
87
+ input: object;
88
+ }
89
+ export type AnthropicContent = AnthropicContentText | AnthropicContentToolUse;
90
+ export interface AnthropicUsage {
91
+ input_tokens: number;
92
+ output_tokens: number;
93
+ cache_creation_input_tokens: number | null;
94
+ cache_creation_output_tokens: number | null;
95
+ }
96
+ export type AnthropicResponseData = AnthropicResponseMessage | AnthropicStreamBaseEvent;
97
+ export interface AnthropicResponseMessage {
98
+ id: string;
99
+ type: string;
100
+ role: string;
101
+ content: AnthropicContent[];
102
+ model: string;
103
+ stop_reason: string | null;
104
+ stop_sequence: string | null;
105
+ usage: AnthropicUsage;
106
+ }
107
+ export interface AnthropicAPIConfig {
108
+ version?: string;
109
+ }
110
+ export type AnthropicStreamEventType = "message_start" | "content_block_start" | "content_block_delta" | "content_block_stop" | "message_delta" | "message_stop" | "ping" | "error";
111
+ export type AnthropicStreamDeltaType = "text_delta" | "input_json_delta";
112
+ export interface AnthropicStreamBaseEvent {
113
+ type: AnthropicStreamEventType;
114
+ }
115
+ export interface AnthropicStreamMessageStartEvent extends AnthropicStreamBaseEvent {
116
+ type: "message_start";
117
+ message: AnthropicResponseMessage;
118
+ }
119
+ export interface AnthropicStreamContentBlockStartEvent extends AnthropicStreamBaseEvent {
120
+ type: "content_block_start";
121
+ index: number;
122
+ content_block: AnthropicContent;
123
+ }
124
+ export interface AnthropicStreamBaseDelta {
125
+ type: AnthropicStreamDeltaType;
126
+ }
127
+ export interface AnthropicStreamTextDelta extends AnthropicStreamBaseDelta {
128
+ type: "text_delta";
129
+ text: string;
130
+ }
131
+ export interface AnthropicStreamInputJsonDelta extends AnthropicStreamBaseDelta {
132
+ type: "input_json_delta";
133
+ partial_json: string;
134
+ }
135
+ export type AnthropicStreamDelta = AnthropicStreamTextDelta | AnthropicStreamInputJsonDelta;
136
+ export interface AnthropicStreamContentBlockDeltaEvent extends AnthropicStreamBaseEvent {
137
+ type: "content_block_delta";
138
+ index: number;
139
+ delta: AnthropicStreamDelta;
140
+ }
141
+ export interface AnthropicStreamContentBlockStopEvent extends AnthropicStreamBaseEvent {
142
+ type: "content_block_stop";
143
+ index: number;
144
+ }
145
+ export interface AnthropicStreamMessageDeltaEvent extends AnthropicStreamBaseEvent {
146
+ type: "message_delta";
147
+ delta: Partial<AnthropicResponseMessage>;
148
+ }
149
+ export interface AnthropicStreamMessageStopEvent extends AnthropicStreamBaseEvent {
150
+ type: "message_stop";
151
+ }
152
+ export interface AnthropicStreamPingEvent extends AnthropicStreamBaseEvent {
153
+ type: "ping";
154
+ }
155
+ export interface AnthropicStreamErrorEvent extends AnthropicStreamBaseEvent {
156
+ type: "error";
157
+ error: any;
158
+ }
159
+ export {};
@@ -0,0 +1 @@
1
+ export {};