You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

ai

Package Overview
Dependencies
Maintainers
5
Versions
1024
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ai - npm Package Compare versions

Comparing version
7.0.0-beta.32
to
7.0.0-beta.33
+120
src/rerank/rerank-events.ts
import type { JSONObject, JSONValue } from '@ai-sdk/provider';
import type { ProviderOptions } from '@ai-sdk/provider-utils';
import type { ProviderMetadata } from '../types';
import type { Warning } from '../types/warning';
/**
* Event passed to the `onStart` callback for rerank operations.
*
* Called when the operation begins, before the reranking model is called.
*/
export interface RerankOnStartEvent {
/** Unique identifier for this rerank call, used to correlate events. */
readonly callId: string;
/** Identifies the operation type ('ai.rerank'). */
readonly operationId: string;
//** The provider identifier (e.g., 'openai', 'anthropic'). */
readonly provider: string;
/** The specific model identifier (e.g., 'gpt-4o'). */
readonly modelId: string;
/** The documents being reranked. */
readonly documents: Array<JSONObject | string>;
/** The query to rerank the documents against. */
readonly query: string;
/** Number of top documents to return. */
readonly topN: number | undefined;
/** Maximum number of retries for failed requests. */
readonly maxRetries: number;
/** Abort signal for cancelling the operation. */
readonly abortSignal: AbortSignal | undefined;
/** Additional HTTP headers sent with the request. */
readonly headers: Record<string, string | undefined> | undefined;
/** Additional provider-specific options. */
readonly providerOptions: ProviderOptions | undefined;
/** Whether telemetry is enabled. */
readonly isEnabled: boolean | undefined;
/** Whether to record inputs in telemetry. Enabled by default. */
readonly recordInputs: boolean | undefined;
/** Whether to record outputs in telemetry. Enabled by default. */
readonly recordOutputs: boolean | undefined;
/** Identifier from telemetry settings for grouping related operations. */
readonly functionId: string | undefined;
/** Additional metadata from telemetry settings. */
readonly metadata: Record<string, JSONValue> | undefined;
}
/**
* Event passed to the `onFinish` callback for rerank operations.
*
* Called when the operation completes, after the reranking model returns.
*/
export interface RerankOnFinishEvent {
/** Unique identifier for this rerank call, used to correlate events. */
readonly callId: string;
/** Identifies the operation type ('ai.rerank'). */
readonly operationId: string;
//** The provider identifier (e.g., 'openai', 'anthropic'). */
readonly provider: string;
/** The specific model identifier (e.g., 'gpt-4o'). */
readonly modelId: string;
/** The documents that were reranked. */
readonly documents: Array<JSONObject | string>;
/** The query that documents were reranked against. */
readonly query: string;
/** The reranked results sorted by relevance score in descending order. */
readonly ranking: Array<{
originalIndex: number;
score: number;
document: JSONObject | string;
}>;
/** Warnings from the reranking model. */
readonly warnings: Array<Warning>;
/** Optional provider-specific metadata. */
readonly providerMetadata: ProviderMetadata | undefined;
/** Response data including headers and body. */
readonly response: {
id?: string;
timestamp: Date;
modelId: string;
headers?: Record<string, string>;
body?: unknown;
};
/** Whether telemetry is enabled. */
readonly isEnabled: boolean | undefined;
/** Whether to record inputs in telemetry. Enabled by default. */
readonly recordInputs: boolean | undefined;
/** Whether to record outputs in telemetry. Enabled by default. */
readonly recordOutputs: boolean | undefined;
/** Identifier from telemetry settings for grouping related operations. */
readonly functionId: string | undefined;
/** Additional metadata from telemetry settings. */
readonly metadata: Record<string, JSONValue> | undefined;
}
+1
-1

@@ -156,3 +156,3 @@ "use strict";

// src/version.ts
var VERSION = true ? "7.0.0-beta.32" : "0.0.0-test";
var VERSION = true ? "7.0.0-beta.33" : "0.0.0-test";

@@ -159,0 +159,0 @@ // src/util/download/download.ts

@@ -136,3 +136,3 @@ // internal/index.ts

// src/version.ts
var VERSION = true ? "7.0.0-beta.32" : "0.0.0-test";
var VERSION = true ? "7.0.0-beta.33" : "0.0.0-test";

@@ -139,0 +139,0 @@ // src/util/download/download.ts

{
"name": "ai",
"version": "7.0.0-beta.32",
"version": "7.0.0-beta.33",
"description": "AI SDK by Vercel - The AI Toolkit for TypeScript and JavaScript",

@@ -5,0 +5,0 @@ "license": "Apache-2.0",

export { rerank } from './rerank';
export type { RerankResult } from './rerank-result';
export type { RerankOnStartEvent, RerankOnFinishEvent } from './rerank-events';
import { JSONObject, RerankingModelV4CallOptions } from '@ai-sdk/provider';
import { ProviderOptions } from '@ai-sdk/provider-utils';
import { createIdGenerator, ProviderOptions } from '@ai-sdk/provider-utils';
import { prepareRetries } from '../../src/util/prepare-retries';
import { logWarnings } from '../logger/log-warnings';
import { assembleOperationName } from '../telemetry/assemble-operation-name';

@@ -11,5 +12,12 @@ import { getBaseTelemetryAttributes } from '../telemetry/get-base-telemetry-attributes';

import { RerankingModel } from '../types';
import { notify } from '../util/notify';
import type { Listener } from '../util/notify';
import type { RerankOnFinishEvent, RerankOnStartEvent } from './rerank-events';
import { RerankResult } from './rerank-result';
import { logWarnings } from '../logger/log-warnings';
const originalGenerateCallId = createIdGenerator({
prefix: 'call',
size: 24,
});
/**

@@ -41,2 +49,5 @@ * Rerank documents using a reranking model. The type of the value is defined by the reranking model.

experimental_telemetry: telemetry,
experimental_onStart: onStart,
experimental_onFinish: onFinish,
_internal: { generateCallId = originalGenerateCallId } = {},
}: {

@@ -92,4 +103,71 @@ /**

providerOptions?: ProviderOptions;
/**
* Callback that is called when the rerank operation begins,
* before the reranking model is called.
*/
experimental_onStart?: Listener<RerankOnStartEvent>;
/**
* Callback that is called when the rerank operation completes,
* after the reranking model returns.
*/
experimental_onFinish?: Listener<RerankOnFinishEvent>;
/**
* Internal. For test use only. May change without notice.
*/
_internal?: {
generateCallId?: () => string;
};
}): Promise<RerankResult<VALUE>> {
const callId = generateCallId();
if (documents.length === 0) {
await notify({
event: {
callId,
operationId: 'ai.rerank',
provider: model.provider,
modelId: model.modelId,
documents,
query,
topN,
maxRetries: maxRetriesArg ?? 2,
abortSignal,
headers,
providerOptions,
isEnabled: telemetry?.isEnabled,
recordInputs: telemetry?.recordInputs,
recordOutputs: telemetry?.recordOutputs,
functionId: telemetry?.functionId,
metadata: telemetry?.metadata,
},
callbacks: [onStart],
});
await notify({
event: {
callId,
operationId: 'ai.rerank',
provider: model.provider,
modelId: model.modelId,
documents,
query,
ranking: [],
warnings: [],
providerMetadata: undefined,
response: {
timestamp: new Date(),
modelId: model.modelId,
},
isEnabled: telemetry?.isEnabled,
recordInputs: telemetry?.recordInputs,
recordOutputs: telemetry?.recordOutputs,
functionId: telemetry?.functionId,
metadata: telemetry?.metadata,
},
callbacks: [onFinish],
});
return new DefaultRerankResult({

@@ -111,2 +189,24 @@ originalDocuments: [],

await notify({
event: {
callId,
operationId: 'ai.rerank',
provider: model.provider,
modelId: model.modelId,
documents,
query,
topN,
maxRetries,
abortSignal,
headers,
providerOptions,
isEnabled: telemetry?.isEnabled,
recordInputs: telemetry?.recordInputs,
recordOutputs: telemetry?.recordOutputs,
functionId: telemetry?.functionId,
metadata: telemetry?.metadata,
},
callbacks: [onStart],
});
// detect the type of the documents:

@@ -202,2 +302,33 @@ const documentsToSend: RerankingModelV4CallOptions['documents'] =

await notify({
event: {
callId,
operationId: 'ai.rerank',
provider: model.provider,
modelId: model.modelId,
documents,
query,
ranking: ranking.map(r => ({
originalIndex: r.index,
score: r.relevanceScore,
document: documents[r.index],
})),
warnings: warnings ?? [],
providerMetadata,
response: {
id: response?.id,
timestamp: response?.timestamp ?? new Date(),
modelId: response?.modelId ?? model.modelId,
headers: response?.headers,
body: response?.body,
},
isEnabled: telemetry?.isEnabled,
recordInputs: telemetry?.recordInputs,
recordOutputs: telemetry?.recordOutputs,
functionId: telemetry?.functionId,
metadata: telemetry?.metadata,
},
callbacks: [onFinish],
});
return new DefaultRerankResult({

@@ -204,0 +335,0 @@ originalDocuments: documents,

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet