@mastra/memory 1.17.1 → 1.17.2-alpha.0

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/dist/index.cjs CHANGED
@@ -4314,9 +4314,6 @@ var ParseError = class extends Error {
4314
4314
  super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
4315
4315
  }
4316
4316
  };
4317
- var LF = 10;
4318
- var CR = 13;
4319
- var SPACE = 32;
4320
4317
  function noop(_arg) {
4321
4318
  }
4322
4319
  function createParser(callbacks) {
@@ -4324,109 +4321,39 @@ function createParser(callbacks) {
4324
4321
  throw new TypeError(
4325
4322
  "`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?"
4326
4323
  );
4327
- const { onEvent = noop, onError = noop, onRetry = noop, onComment } = callbacks, pendingFragments = [];
4328
- let isFirstChunk = true, id, data = "", dataLines = 0, eventType;
4329
- function feed(chunk) {
4330
- if (isFirstChunk && (isFirstChunk = false, chunk.charCodeAt(0) === 239 && chunk.charCodeAt(1) === 187 && chunk.charCodeAt(2) === 191 && (chunk = chunk.slice(3))), pendingFragments.length === 0) {
4331
- const trailing2 = processLines(chunk);
4332
- trailing2 !== "" && pendingFragments.push(trailing2);
4333
- return;
4334
- }
4335
- if (chunk.indexOf(`
4336
- `) === -1 && chunk.indexOf("\r") === -1) {
4337
- pendingFragments.push(chunk);
4338
- return;
4339
- }
4340
- pendingFragments.push(chunk);
4341
- const input = pendingFragments.join("");
4342
- pendingFragments.length = 0;
4343
- const trailing = processLines(input);
4344
- trailing !== "" && pendingFragments.push(trailing);
4345
- }
4346
- function processLines(chunk) {
4347
- let searchIndex = 0;
4348
- if (chunk.indexOf("\r") === -1) {
4349
- let lfIndex = chunk.indexOf(`
4350
- `, searchIndex);
4351
- for (; lfIndex !== -1; ) {
4352
- if (searchIndex === lfIndex) {
4353
- dataLines > 0 && onEvent({ id, event: eventType, data }), id = void 0, data = "", dataLines = 0, eventType = void 0, searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
4354
- `, searchIndex);
4355
- continue;
4356
- }
4357
- const firstCharCode = chunk.charCodeAt(searchIndex);
4358
- if (isDataPrefix(chunk, searchIndex, firstCharCode)) {
4359
- const valueStart = chunk.charCodeAt(searchIndex + 5) === SPACE ? searchIndex + 6 : searchIndex + 5, value = chunk.slice(valueStart, lfIndex);
4360
- if (dataLines === 0 && chunk.charCodeAt(lfIndex + 1) === LF) {
4361
- onEvent({ id, event: eventType, data: value }), id = void 0, data = "", eventType = void 0, searchIndex = lfIndex + 2, lfIndex = chunk.indexOf(`
4362
- `, searchIndex);
4363
- continue;
4364
- }
4365
- data = dataLines === 0 ? value : `${data}
4366
- ${value}`, dataLines++;
4367
- } else isEventPrefix(chunk, searchIndex, firstCharCode) ? eventType = chunk.slice(
4368
- chunk.charCodeAt(searchIndex + 6) === SPACE ? searchIndex + 7 : searchIndex + 6,
4369
- lfIndex
4370
- ) || void 0 : parseLine(chunk, searchIndex, lfIndex);
4371
- searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
4372
- `, searchIndex);
4373
- }
4374
- return chunk.slice(searchIndex);
4375
- }
4376
- for (; searchIndex < chunk.length; ) {
4377
- const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
4378
- `, searchIndex);
4379
- let lineEnd = -1;
4380
- if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = crIndex < lfIndex ? crIndex : lfIndex : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1)
4381
- break;
4382
- parseLine(chunk, searchIndex, lineEnd), searchIndex = lineEnd + 1, chunk.charCodeAt(searchIndex - 1) === CR && chunk.charCodeAt(searchIndex) === LF && searchIndex++;
4383
- }
4384
- return chunk.slice(searchIndex);
4385
- }
4386
- function parseLine(chunk, start, end) {
4387
- if (start === end) {
4324
+ const { onEvent = noop, onError = noop, onRetry = noop, onComment } = callbacks;
4325
+ let incompleteLine = "", isFirstChunk = true, id, data = "", eventType = "";
4326
+ function feed(newChunk) {
4327
+ const chunk = isFirstChunk ? newChunk.replace(/^\xEF\xBB\xBF/, "") : newChunk, [complete, incomplete] = splitLines(`${incompleteLine}${chunk}`);
4328
+ for (const line of complete)
4329
+ parseLine(line);
4330
+ incompleteLine = incomplete, isFirstChunk = false;
4331
+ }
4332
+ function parseLine(line) {
4333
+ if (line === "") {
4388
4334
  dispatchEvent();
4389
4335
  return;
4390
4336
  }
4391
- const firstCharCode = chunk.charCodeAt(start);
4392
- if (isDataPrefix(chunk, start, firstCharCode)) {
4393
- const valueStart = chunk.charCodeAt(start + 5) === SPACE ? start + 6 : start + 5, value2 = chunk.slice(valueStart, end);
4394
- data = dataLines === 0 ? value2 : `${data}
4395
- ${value2}`, dataLines++;
4396
- return;
4397
- }
4398
- if (isEventPrefix(chunk, start, firstCharCode)) {
4399
- eventType = chunk.slice(chunk.charCodeAt(start + 6) === SPACE ? start + 7 : start + 6, end) || void 0;
4400
- return;
4401
- }
4402
- if (firstCharCode === 105 && chunk.charCodeAt(start + 1) === 100 && chunk.charCodeAt(start + 2) === 58) {
4403
- const value2 = chunk.slice(chunk.charCodeAt(start + 3) === SPACE ? start + 4 : start + 3, end);
4404
- id = value2.includes("\0") ? void 0 : value2;
4405
- return;
4406
- }
4407
- if (firstCharCode === 58) {
4408
- if (onComment) {
4409
- const line2 = chunk.slice(start, end);
4410
- onComment(line2.slice(chunk.charCodeAt(start + 1) === SPACE ? 2 : 1));
4411
- }
4337
+ if (line.startsWith(":")) {
4338
+ onComment && onComment(line.slice(line.startsWith(": ") ? 2 : 1));
4412
4339
  return;
4413
4340
  }
4414
- const line = chunk.slice(start, end), fieldSeparatorIndex = line.indexOf(":");
4415
- if (fieldSeparatorIndex === -1) {
4416
- processField(line, "", line);
4341
+ const fieldSeparatorIndex = line.indexOf(":");
4342
+ if (fieldSeparatorIndex !== -1) {
4343
+ const field = line.slice(0, fieldSeparatorIndex), offset = line[fieldSeparatorIndex + 1] === " " ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
4344
+ processField(field, value, line);
4417
4345
  return;
4418
4346
  }
4419
- const field = line.slice(0, fieldSeparatorIndex), offset = line.charCodeAt(fieldSeparatorIndex + 1) === SPACE ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
4420
- processField(field, value, line);
4347
+ processField(line, "", line);
4421
4348
  }
4422
4349
  function processField(field, value, line) {
4423
4350
  switch (field) {
4424
4351
  case "event":
4425
- eventType = value || void 0;
4352
+ eventType = value;
4426
4353
  break;
4427
4354
  case "data":
4428
- data = dataLines === 0 ? value : `${data}
4429
- ${value}`, dataLines++;
4355
+ data = `${data}${value}
4356
+ `;
4430
4357
  break;
4431
4358
  case "id":
4432
4359
  id = value.includes("\0") ? void 0 : value;
@@ -4451,26 +4378,37 @@ ${value}`, dataLines++;
4451
4378
  }
4452
4379
  }
4453
4380
  function dispatchEvent() {
4454
- dataLines > 0 && onEvent({
4381
+ data.length > 0 && onEvent({
4455
4382
  id,
4456
- event: eventType,
4457
- data
4458
- }), id = void 0, data = "", dataLines = 0, eventType = void 0;
4383
+ event: eventType || void 0,
4384
+ // If the data buffer's last character is a U+000A LINE FEED (LF) character,
4385
+ // then remove the last character from the data buffer.
4386
+ data: data.endsWith(`
4387
+ `) ? data.slice(0, -1) : data
4388
+ }), id = void 0, data = "", eventType = "";
4459
4389
  }
4460
4390
  function reset(options = {}) {
4461
- if (options.consume && pendingFragments.length > 0) {
4462
- const incompleteLine = pendingFragments.join("");
4463
- parseLine(incompleteLine, 0, incompleteLine.length);
4464
- }
4465
- isFirstChunk = true, id = void 0, data = "", dataLines = 0, eventType = void 0, pendingFragments.length = 0;
4391
+ incompleteLine && options.consume && parseLine(incompleteLine), isFirstChunk = true, id = void 0, data = "", eventType = "", incompleteLine = "";
4466
4392
  }
4467
4393
  return { feed, reset };
4468
4394
  }
4469
- function isDataPrefix(chunk, i, firstCharCode) {
4470
- return firstCharCode === 100 && chunk.charCodeAt(i + 1) === 97 && chunk.charCodeAt(i + 2) === 116 && chunk.charCodeAt(i + 3) === 97 && chunk.charCodeAt(i + 4) === 58;
4471
- }
4472
- function isEventPrefix(chunk, i, firstCharCode) {
4473
- return firstCharCode === 101 && chunk.charCodeAt(i + 1) === 118 && chunk.charCodeAt(i + 2) === 101 && chunk.charCodeAt(i + 3) === 110 && chunk.charCodeAt(i + 4) === 116 && chunk.charCodeAt(i + 5) === 58;
4395
+ function splitLines(chunk) {
4396
+ const lines = [];
4397
+ let incompleteLine = "", searchIndex = 0;
4398
+ for (; searchIndex < chunk.length; ) {
4399
+ const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
4400
+ `, searchIndex);
4401
+ let lineEnd = -1;
4402
+ if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = Math.min(crIndex, lfIndex) : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1) {
4403
+ incompleteLine = chunk.slice(searchIndex);
4404
+ break;
4405
+ } else {
4406
+ const line = chunk.slice(searchIndex, lineEnd);
4407
+ lines.push(line), searchIndex = lineEnd + 1, chunk[searchIndex - 1] === "\r" && chunk[searchIndex] === `
4408
+ ` && searchIndex++;
4409
+ }
4410
+ }
4411
+ return [lines, incompleteLine];
4474
4412
  }
4475
4413
  var EventSourceParserStream = class extends TransformStream {
4476
4414
  constructor({ onError, onRetry, onComment } = {}) {
@@ -4646,7 +4584,7 @@ function withUserAgentSuffix(headers, ...userAgentSuffixParts) {
4646
4584
  );
4647
4585
  return Object.fromEntries(normalizedHeaders.entries());
4648
4586
  }
4649
- var VERSION2 = "3.0.23";
4587
+ var VERSION2 = "3.0.22";
4650
4588
  var getOriginalFetch = () => globalThis.fetch;
4651
4589
  var getFromApi = async ({
4652
4590
  url,
@@ -6693,7 +6631,6 @@ async function parseAuthMethod(headers) {
6693
6631
  var gatewayAuthMethodSchema = lazyValidator(
6694
6632
  () => zodSchema2(z4.z.union([z4.z.literal("api-key"), z4.z.literal("oidc")]))
6695
6633
  );
6696
- var KNOWN_MODEL_TYPES = ["embedding", "image", "language"];
6697
6634
  var GatewayFetchMetadata = class {
6698
6635
  constructor(config) {
6699
6636
  this.config = config;
@@ -6764,12 +6701,8 @@ var gatewayAvailableModelsResponseSchema = lazyValidator(
6764
6701
  provider: z4.z.string(),
6765
6702
  modelId: z4.z.string()
6766
6703
  }),
6767
- modelType: z4.z.string().nullish()
6704
+ modelType: z4.z.enum(["language", "embedding", "image"]).nullish()
6768
6705
  })
6769
- ).transform(
6770
- (models) => models.filter(
6771
- (m) => m.modelType == null || KNOWN_MODEL_TYPES.includes(m.modelType)
6772
- )
6773
6706
  )
6774
6707
  })
6775
6708
  )
@@ -6785,187 +6718,6 @@ var gatewayCreditsResponseSchema = lazyValidator(
6785
6718
  }))
6786
6719
  )
6787
6720
  );
6788
- var GatewaySpendReport = class {
6789
- constructor(config) {
6790
- this.config = config;
6791
- }
6792
- async getSpendReport(params) {
6793
- try {
6794
- const baseUrl = new URL(this.config.baseURL);
6795
- const searchParams = new URLSearchParams();
6796
- searchParams.set("start_date", params.startDate);
6797
- searchParams.set("end_date", params.endDate);
6798
- if (params.groupBy) {
6799
- searchParams.set("group_by", params.groupBy);
6800
- }
6801
- if (params.datePart) {
6802
- searchParams.set("date_part", params.datePart);
6803
- }
6804
- if (params.userId) {
6805
- searchParams.set("user_id", params.userId);
6806
- }
6807
- if (params.model) {
6808
- searchParams.set("model", params.model);
6809
- }
6810
- if (params.provider) {
6811
- searchParams.set("provider", params.provider);
6812
- }
6813
- if (params.credentialType) {
6814
- searchParams.set("credential_type", params.credentialType);
6815
- }
6816
- if (params.tags && params.tags.length > 0) {
6817
- searchParams.set("tags", params.tags.join(","));
6818
- }
6819
- const { value } = await getFromApi({
6820
- url: `${baseUrl.origin}/v1/report?${searchParams.toString()}`,
6821
- headers: await resolve(this.config.headers()),
6822
- successfulResponseHandler: createJsonResponseHandler(
6823
- gatewaySpendReportResponseSchema
6824
- ),
6825
- failedResponseHandler: createJsonErrorResponseHandler({
6826
- errorSchema: z4.z.any(),
6827
- errorToMessage: (data) => data
6828
- }),
6829
- fetch: this.config.fetch
6830
- });
6831
- return value;
6832
- } catch (error) {
6833
- throw await asGatewayError(error);
6834
- }
6835
- }
6836
- };
6837
- var gatewaySpendReportResponseSchema = lazySchema(
6838
- () => zodSchema2(
6839
- z4.z.object({
6840
- results: z4.z.array(
6841
- z4.z.object({
6842
- day: z4.z.string().optional(),
6843
- hour: z4.z.string().optional(),
6844
- user: z4.z.string().optional(),
6845
- model: z4.z.string().optional(),
6846
- tag: z4.z.string().optional(),
6847
- provider: z4.z.string().optional(),
6848
- credential_type: z4.z.enum(["byok", "system"]).optional(),
6849
- total_cost: z4.z.number(),
6850
- market_cost: z4.z.number().optional(),
6851
- input_tokens: z4.z.number().optional(),
6852
- output_tokens: z4.z.number().optional(),
6853
- cached_input_tokens: z4.z.number().optional(),
6854
- cache_creation_input_tokens: z4.z.number().optional(),
6855
- reasoning_tokens: z4.z.number().optional(),
6856
- request_count: z4.z.number().optional()
6857
- }).transform(
6858
- ({
6859
- credential_type,
6860
- total_cost,
6861
- market_cost,
6862
- input_tokens,
6863
- output_tokens,
6864
- cached_input_tokens,
6865
- cache_creation_input_tokens,
6866
- reasoning_tokens,
6867
- request_count,
6868
- ...rest
6869
- }) => ({
6870
- ...rest,
6871
- ...credential_type !== void 0 ? { credentialType: credential_type } : {},
6872
- totalCost: total_cost,
6873
- ...market_cost !== void 0 ? { marketCost: market_cost } : {},
6874
- ...input_tokens !== void 0 ? { inputTokens: input_tokens } : {},
6875
- ...output_tokens !== void 0 ? { outputTokens: output_tokens } : {},
6876
- ...cached_input_tokens !== void 0 ? { cachedInputTokens: cached_input_tokens } : {},
6877
- ...cache_creation_input_tokens !== void 0 ? { cacheCreationInputTokens: cache_creation_input_tokens } : {},
6878
- ...reasoning_tokens !== void 0 ? { reasoningTokens: reasoning_tokens } : {},
6879
- ...request_count !== void 0 ? { requestCount: request_count } : {}
6880
- })
6881
- )
6882
- )
6883
- })
6884
- )
6885
- );
6886
- var GatewayGenerationInfoFetcher = class {
6887
- constructor(config) {
6888
- this.config = config;
6889
- }
6890
- async getGenerationInfo(params) {
6891
- try {
6892
- const baseUrl = new URL(this.config.baseURL);
6893
- const { value } = await getFromApi({
6894
- url: `${baseUrl.origin}/v1/generation?id=${encodeURIComponent(params.id)}`,
6895
- headers: await resolve(this.config.headers()),
6896
- successfulResponseHandler: createJsonResponseHandler(
6897
- gatewayGenerationInfoResponseSchema
6898
- ),
6899
- failedResponseHandler: createJsonErrorResponseHandler({
6900
- errorSchema: z4.z.any(),
6901
- errorToMessage: (data) => data
6902
- }),
6903
- fetch: this.config.fetch
6904
- });
6905
- return value;
6906
- } catch (error) {
6907
- throw await asGatewayError(error);
6908
- }
6909
- }
6910
- };
6911
- var gatewayGenerationInfoResponseSchema = lazySchema(
6912
- () => zodSchema2(
6913
- z4.z.object({
6914
- data: z4.z.object({
6915
- id: z4.z.string(),
6916
- total_cost: z4.z.number(),
6917
- upstream_inference_cost: z4.z.number(),
6918
- usage: z4.z.number(),
6919
- created_at: z4.z.string(),
6920
- model: z4.z.string(),
6921
- is_byok: z4.z.boolean(),
6922
- provider_name: z4.z.string(),
6923
- streamed: z4.z.boolean(),
6924
- finish_reason: z4.z.string(),
6925
- latency: z4.z.number(),
6926
- generation_time: z4.z.number(),
6927
- native_tokens_prompt: z4.z.number(),
6928
- native_tokens_completion: z4.z.number(),
6929
- native_tokens_reasoning: z4.z.number(),
6930
- native_tokens_cached: z4.z.number(),
6931
- native_tokens_cache_creation: z4.z.number(),
6932
- billable_web_search_calls: z4.z.number()
6933
- }).transform(
6934
- ({
6935
- total_cost,
6936
- upstream_inference_cost,
6937
- created_at,
6938
- is_byok,
6939
- provider_name,
6940
- finish_reason,
6941
- generation_time,
6942
- native_tokens_prompt,
6943
- native_tokens_completion,
6944
- native_tokens_reasoning,
6945
- native_tokens_cached,
6946
- native_tokens_cache_creation,
6947
- billable_web_search_calls,
6948
- ...rest
6949
- }) => ({
6950
- ...rest,
6951
- totalCost: total_cost,
6952
- upstreamInferenceCost: upstream_inference_cost,
6953
- createdAt: created_at,
6954
- isByok: is_byok,
6955
- providerName: provider_name,
6956
- finishReason: finish_reason,
6957
- generationTime: generation_time,
6958
- promptTokens: native_tokens_prompt,
6959
- completionTokens: native_tokens_completion,
6960
- reasoningTokens: native_tokens_reasoning,
6961
- cachedTokens: native_tokens_cached,
6962
- cacheCreationTokens: native_tokens_cache_creation,
6963
- billableWebSearchCalls: billable_web_search_calls
6964
- })
6965
- )
6966
- }).transform(({ data }) => data)
6967
- )
6968
- );
6969
6721
  var GatewayLanguageModel = class {
6970
6722
  constructor(modelId, config) {
6971
6723
  this.modelId = modelId;
@@ -7468,7 +7220,7 @@ async function getVercelRequestId() {
7468
7220
  var _a932;
7469
7221
  return (_a932 = getContext().headers) == null ? void 0 : _a932["x-vercel-id"];
7470
7222
  }
7471
- var VERSION3 = "2.0.82";
7223
+ var VERSION3 = "2.0.59";
7472
7224
  var AI_GATEWAY_PROTOCOL_VERSION = "0.0.1";
7473
7225
  function createGatewayProvider(options = {}) {
7474
7226
  var _a932, _b93;
@@ -7566,30 +7318,6 @@ function createGatewayProvider(options = {}) {
7566
7318
  );
7567
7319
  });
7568
7320
  };
7569
- const getSpendReport = async (params) => {
7570
- return new GatewaySpendReport({
7571
- baseURL,
7572
- headers: getHeaders,
7573
- fetch: options.fetch
7574
- }).getSpendReport(params).catch(async (error) => {
7575
- throw await asGatewayError(
7576
- error,
7577
- await parseAuthMethod(await getHeaders())
7578
- );
7579
- });
7580
- };
7581
- const getGenerationInfo = async (params) => {
7582
- return new GatewayGenerationInfoFetcher({
7583
- baseURL,
7584
- headers: getHeaders,
7585
- fetch: options.fetch
7586
- }).getGenerationInfo(params).catch(async (error) => {
7587
- throw await asGatewayError(
7588
- error,
7589
- await parseAuthMethod(await getHeaders())
7590
- );
7591
- });
7592
- };
7593
7321
  const provider = function(modelId) {
7594
7322
  if (new.target) {
7595
7323
  throw new Error(
@@ -7600,8 +7328,6 @@ function createGatewayProvider(options = {}) {
7600
7328
  };
7601
7329
  provider.getAvailableModels = getAvailableModels;
7602
7330
  provider.getCredits = getCredits;
7603
- provider.getSpendReport = getSpendReport;
7604
- provider.getGenerationInfo = getGenerationInfo;
7605
7331
  provider.imageModel = (modelId) => {
7606
7332
  return new GatewayImageModel(modelId, {
7607
7333
  provider: "gateway",
@@ -8455,7 +8181,7 @@ function getGlobalProvider() {
8455
8181
  var _a163;
8456
8182
  return (_a163 = globalThis.AI_SDK_DEFAULT_PROVIDER) != null ? _a163 : gateway;
8457
8183
  }
8458
- var VERSION32 = "5.0.179";
8184
+ var VERSION32 = "5.0.155";
8459
8185
  var dataContentSchema2 = z4.z.union([
8460
8186
  z4.z.string(),
8461
8187
  z4.z.instanceof(Uint8Array),
@@ -9760,9 +9486,6 @@ var ParseError2 = class extends Error {
9760
9486
  super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
9761
9487
  }
9762
9488
  };
9763
- var LF2 = 10;
9764
- var CR2 = 13;
9765
- var SPACE2 = 32;
9766
9489
  function noop2(_arg) {
9767
9490
  }
9768
9491
  function createParser2(callbacks) {
@@ -9770,109 +9493,39 @@ function createParser2(callbacks) {
9770
9493
  throw new TypeError(
9771
9494
  "`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?"
9772
9495
  );
9773
- const { onEvent = noop2, onError = noop2, onRetry = noop2, onComment } = callbacks, pendingFragments = [];
9774
- let isFirstChunk = true, id, data = "", dataLines = 0, eventType;
9775
- function feed(chunk) {
9776
- if (isFirstChunk && (isFirstChunk = false, chunk.charCodeAt(0) === 239 && chunk.charCodeAt(1) === 187 && chunk.charCodeAt(2) === 191 && (chunk = chunk.slice(3))), pendingFragments.length === 0) {
9777
- const trailing2 = processLines(chunk);
9778
- trailing2 !== "" && pendingFragments.push(trailing2);
9779
- return;
9780
- }
9781
- if (chunk.indexOf(`
9782
- `) === -1 && chunk.indexOf("\r") === -1) {
9783
- pendingFragments.push(chunk);
9784
- return;
9785
- }
9786
- pendingFragments.push(chunk);
9787
- const input = pendingFragments.join("");
9788
- pendingFragments.length = 0;
9789
- const trailing = processLines(input);
9790
- trailing !== "" && pendingFragments.push(trailing);
9791
- }
9792
- function processLines(chunk) {
9793
- let searchIndex = 0;
9794
- if (chunk.indexOf("\r") === -1) {
9795
- let lfIndex = chunk.indexOf(`
9796
- `, searchIndex);
9797
- for (; lfIndex !== -1; ) {
9798
- if (searchIndex === lfIndex) {
9799
- dataLines > 0 && onEvent({ id, event: eventType, data }), id = void 0, data = "", dataLines = 0, eventType = void 0, searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
9800
- `, searchIndex);
9801
- continue;
9802
- }
9803
- const firstCharCode = chunk.charCodeAt(searchIndex);
9804
- if (isDataPrefix2(chunk, searchIndex, firstCharCode)) {
9805
- const valueStart = chunk.charCodeAt(searchIndex + 5) === SPACE2 ? searchIndex + 6 : searchIndex + 5, value = chunk.slice(valueStart, lfIndex);
9806
- if (dataLines === 0 && chunk.charCodeAt(lfIndex + 1) === LF2) {
9807
- onEvent({ id, event: eventType, data: value }), id = void 0, data = "", eventType = void 0, searchIndex = lfIndex + 2, lfIndex = chunk.indexOf(`
9808
- `, searchIndex);
9809
- continue;
9810
- }
9811
- data = dataLines === 0 ? value : `${data}
9812
- ${value}`, dataLines++;
9813
- } else isEventPrefix2(chunk, searchIndex, firstCharCode) ? eventType = chunk.slice(
9814
- chunk.charCodeAt(searchIndex + 6) === SPACE2 ? searchIndex + 7 : searchIndex + 6,
9815
- lfIndex
9816
- ) || void 0 : parseLine(chunk, searchIndex, lfIndex);
9817
- searchIndex = lfIndex + 1, lfIndex = chunk.indexOf(`
9818
- `, searchIndex);
9819
- }
9820
- return chunk.slice(searchIndex);
9821
- }
9822
- for (; searchIndex < chunk.length; ) {
9823
- const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
9824
- `, searchIndex);
9825
- let lineEnd = -1;
9826
- if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = crIndex < lfIndex ? crIndex : lfIndex : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1)
9827
- break;
9828
- parseLine(chunk, searchIndex, lineEnd), searchIndex = lineEnd + 1, chunk.charCodeAt(searchIndex - 1) === CR2 && chunk.charCodeAt(searchIndex) === LF2 && searchIndex++;
9829
- }
9830
- return chunk.slice(searchIndex);
9831
- }
9832
- function parseLine(chunk, start, end) {
9833
- if (start === end) {
9496
+ const { onEvent = noop2, onError = noop2, onRetry = noop2, onComment } = callbacks;
9497
+ let incompleteLine = "", isFirstChunk = true, id, data = "", eventType = "";
9498
+ function feed(newChunk) {
9499
+ const chunk = isFirstChunk ? newChunk.replace(/^\xEF\xBB\xBF/, "") : newChunk, [complete, incomplete] = splitLines2(`${incompleteLine}${chunk}`);
9500
+ for (const line of complete)
9501
+ parseLine(line);
9502
+ incompleteLine = incomplete, isFirstChunk = false;
9503
+ }
9504
+ function parseLine(line) {
9505
+ if (line === "") {
9834
9506
  dispatchEvent();
9835
9507
  return;
9836
9508
  }
9837
- const firstCharCode = chunk.charCodeAt(start);
9838
- if (isDataPrefix2(chunk, start, firstCharCode)) {
9839
- const valueStart = chunk.charCodeAt(start + 5) === SPACE2 ? start + 6 : start + 5, value2 = chunk.slice(valueStart, end);
9840
- data = dataLines === 0 ? value2 : `${data}
9841
- ${value2}`, dataLines++;
9509
+ if (line.startsWith(":")) {
9510
+ onComment && onComment(line.slice(line.startsWith(": ") ? 2 : 1));
9842
9511
  return;
9843
9512
  }
9844
- if (isEventPrefix2(chunk, start, firstCharCode)) {
9845
- eventType = chunk.slice(chunk.charCodeAt(start + 6) === SPACE2 ? start + 7 : start + 6, end) || void 0;
9513
+ const fieldSeparatorIndex = line.indexOf(":");
9514
+ if (fieldSeparatorIndex !== -1) {
9515
+ const field = line.slice(0, fieldSeparatorIndex), offset = line[fieldSeparatorIndex + 1] === " " ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
9516
+ processField(field, value, line);
9846
9517
  return;
9847
9518
  }
9848
- if (firstCharCode === 105 && chunk.charCodeAt(start + 1) === 100 && chunk.charCodeAt(start + 2) === 58) {
9849
- const value2 = chunk.slice(chunk.charCodeAt(start + 3) === SPACE2 ? start + 4 : start + 3, end);
9850
- id = value2.includes("\0") ? void 0 : value2;
9851
- return;
9852
- }
9853
- if (firstCharCode === 58) {
9854
- if (onComment) {
9855
- const line2 = chunk.slice(start, end);
9856
- onComment(line2.slice(chunk.charCodeAt(start + 1) === SPACE2 ? 2 : 1));
9857
- }
9858
- return;
9859
- }
9860
- const line = chunk.slice(start, end), fieldSeparatorIndex = line.indexOf(":");
9861
- if (fieldSeparatorIndex === -1) {
9862
- processField(line, "", line);
9863
- return;
9864
- }
9865
- const field = line.slice(0, fieldSeparatorIndex), offset = line.charCodeAt(fieldSeparatorIndex + 1) === SPACE2 ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
9866
- processField(field, value, line);
9519
+ processField(line, "", line);
9867
9520
  }
9868
9521
  function processField(field, value, line) {
9869
9522
  switch (field) {
9870
9523
  case "event":
9871
- eventType = value || void 0;
9524
+ eventType = value;
9872
9525
  break;
9873
9526
  case "data":
9874
- data = dataLines === 0 ? value : `${data}
9875
- ${value}`, dataLines++;
9527
+ data = `${data}${value}
9528
+ `;
9876
9529
  break;
9877
9530
  case "id":
9878
9531
  id = value.includes("\0") ? void 0 : value;
@@ -9897,26 +9550,37 @@ ${value}`, dataLines++;
9897
9550
  }
9898
9551
  }
9899
9552
  function dispatchEvent() {
9900
- dataLines > 0 && onEvent({
9553
+ data.length > 0 && onEvent({
9901
9554
  id,
9902
- event: eventType,
9903
- data
9904
- }), id = void 0, data = "", dataLines = 0, eventType = void 0;
9555
+ event: eventType || void 0,
9556
+ // If the data buffer's last character is a U+000A LINE FEED (LF) character,
9557
+ // then remove the last character from the data buffer.
9558
+ data: data.endsWith(`
9559
+ `) ? data.slice(0, -1) : data
9560
+ }), id = void 0, data = "", eventType = "";
9905
9561
  }
9906
9562
  function reset(options = {}) {
9907
- if (options.consume && pendingFragments.length > 0) {
9908
- const incompleteLine = pendingFragments.join("");
9909
- parseLine(incompleteLine, 0, incompleteLine.length);
9910
- }
9911
- isFirstChunk = true, id = void 0, data = "", dataLines = 0, eventType = void 0, pendingFragments.length = 0;
9563
+ incompleteLine && options.consume && parseLine(incompleteLine), isFirstChunk = true, id = void 0, data = "", eventType = "", incompleteLine = "";
9912
9564
  }
9913
9565
  return { feed, reset };
9914
9566
  }
9915
- function isDataPrefix2(chunk, i, firstCharCode) {
9916
- return firstCharCode === 100 && chunk.charCodeAt(i + 1) === 97 && chunk.charCodeAt(i + 2) === 116 && chunk.charCodeAt(i + 3) === 97 && chunk.charCodeAt(i + 4) === 58;
9917
- }
9918
- function isEventPrefix2(chunk, i, firstCharCode) {
9919
- return firstCharCode === 101 && chunk.charCodeAt(i + 1) === 118 && chunk.charCodeAt(i + 2) === 101 && chunk.charCodeAt(i + 3) === 110 && chunk.charCodeAt(i + 4) === 116 && chunk.charCodeAt(i + 5) === 58;
9567
+ function splitLines2(chunk) {
9568
+ const lines = [];
9569
+ let incompleteLine = "", searchIndex = 0;
9570
+ for (; searchIndex < chunk.length; ) {
9571
+ const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
9572
+ `, searchIndex);
9573
+ let lineEnd = -1;
9574
+ if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = Math.min(crIndex, lfIndex) : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1) {
9575
+ incompleteLine = chunk.slice(searchIndex);
9576
+ break;
9577
+ } else {
9578
+ const line = chunk.slice(searchIndex, lineEnd);
9579
+ lines.push(line), searchIndex = lineEnd + 1, chunk[searchIndex - 1] === "\r" && chunk[searchIndex] === `
9580
+ ` && searchIndex++;
9581
+ }
9582
+ }
9583
+ return [lines, incompleteLine];
9920
9584
  }
9921
9585
  var EventSourceParserStream2 = class extends TransformStream {
9922
9586
  constructor({ onError, onRetry, onComment } = {}) {
@@ -10128,7 +9792,7 @@ function withUserAgentSuffix2(headers, ...userAgentSuffixParts) {
10128
9792
  );
10129
9793
  return Object.fromEntries(normalizedHeaders.entries());
10130
9794
  }
10131
- var VERSION4 = "4.0.23";
9795
+ var VERSION4 = "4.0.19";
10132
9796
  var getOriginalFetch3 = () => globalThis.fetch;
10133
9797
  var getFromApi2 = async ({
10134
9798
  url,
@@ -12213,13 +11877,6 @@ async function parseAuthMethod2(headers) {
12213
11877
  var gatewayAuthMethodSchema2 = lazySchema2(
12214
11878
  () => zodSchema3(z4.z.union([z4.z.literal("api-key"), z4.z.literal("oidc")]))
12215
11879
  );
12216
- var KNOWN_MODEL_TYPES2 = [
12217
- "embedding",
12218
- "image",
12219
- "language",
12220
- "reranking",
12221
- "video"
12222
- ];
12223
11880
  var GatewayFetchMetadata2 = class {
12224
11881
  constructor(config) {
12225
11882
  this.config = config;
@@ -12290,12 +11947,8 @@ var gatewayAvailableModelsResponseSchema2 = lazySchema2(
12290
11947
  provider: z4.z.string(),
12291
11948
  modelId: z4.z.string()
12292
11949
  }),
12293
- modelType: z4.z.string().nullish()
11950
+ modelType: z4.z.enum(["embedding", "image", "language", "video"]).nullish()
12294
11951
  })
12295
- ).transform(
12296
- (models) => models.filter(
12297
- (m) => m.modelType == null || KNOWN_MODEL_TYPES2.includes(m.modelType)
12298
- )
12299
11952
  )
12300
11953
  })
12301
11954
  )
@@ -12311,187 +11964,6 @@ var gatewayCreditsResponseSchema2 = lazySchema2(
12311
11964
  }))
12312
11965
  )
12313
11966
  );
12314
- var GatewaySpendReport2 = class {
12315
- constructor(config) {
12316
- this.config = config;
12317
- }
12318
- async getSpendReport(params) {
12319
- try {
12320
- const baseUrl = new URL(this.config.baseURL);
12321
- const searchParams = new URLSearchParams();
12322
- searchParams.set("start_date", params.startDate);
12323
- searchParams.set("end_date", params.endDate);
12324
- if (params.groupBy) {
12325
- searchParams.set("group_by", params.groupBy);
12326
- }
12327
- if (params.datePart) {
12328
- searchParams.set("date_part", params.datePart);
12329
- }
12330
- if (params.userId) {
12331
- searchParams.set("user_id", params.userId);
12332
- }
12333
- if (params.model) {
12334
- searchParams.set("model", params.model);
12335
- }
12336
- if (params.provider) {
12337
- searchParams.set("provider", params.provider);
12338
- }
12339
- if (params.credentialType) {
12340
- searchParams.set("credential_type", params.credentialType);
12341
- }
12342
- if (params.tags && params.tags.length > 0) {
12343
- searchParams.set("tags", params.tags.join(","));
12344
- }
12345
- const { value } = await getFromApi2({
12346
- url: `${baseUrl.origin}/v1/report?${searchParams.toString()}`,
12347
- headers: await resolve2(this.config.headers()),
12348
- successfulResponseHandler: createJsonResponseHandler2(
12349
- gatewaySpendReportResponseSchema2
12350
- ),
12351
- failedResponseHandler: createJsonErrorResponseHandler2({
12352
- errorSchema: z4.z.any(),
12353
- errorToMessage: (data) => data
12354
- }),
12355
- fetch: this.config.fetch
12356
- });
12357
- return value;
12358
- } catch (error) {
12359
- throw await asGatewayError2(error);
12360
- }
12361
- }
12362
- };
12363
- var gatewaySpendReportResponseSchema2 = lazySchema2(
12364
- () => zodSchema3(
12365
- z4.z.object({
12366
- results: z4.z.array(
12367
- z4.z.object({
12368
- day: z4.z.string().optional(),
12369
- hour: z4.z.string().optional(),
12370
- user: z4.z.string().optional(),
12371
- model: z4.z.string().optional(),
12372
- tag: z4.z.string().optional(),
12373
- provider: z4.z.string().optional(),
12374
- credential_type: z4.z.enum(["byok", "system"]).optional(),
12375
- total_cost: z4.z.number(),
12376
- market_cost: z4.z.number().optional(),
12377
- input_tokens: z4.z.number().optional(),
12378
- output_tokens: z4.z.number().optional(),
12379
- cached_input_tokens: z4.z.number().optional(),
12380
- cache_creation_input_tokens: z4.z.number().optional(),
12381
- reasoning_tokens: z4.z.number().optional(),
12382
- request_count: z4.z.number().optional()
12383
- }).transform(
12384
- ({
12385
- credential_type,
12386
- total_cost,
12387
- market_cost,
12388
- input_tokens,
12389
- output_tokens,
12390
- cached_input_tokens,
12391
- cache_creation_input_tokens,
12392
- reasoning_tokens,
12393
- request_count,
12394
- ...rest
12395
- }) => ({
12396
- ...rest,
12397
- ...credential_type !== void 0 ? { credentialType: credential_type } : {},
12398
- totalCost: total_cost,
12399
- ...market_cost !== void 0 ? { marketCost: market_cost } : {},
12400
- ...input_tokens !== void 0 ? { inputTokens: input_tokens } : {},
12401
- ...output_tokens !== void 0 ? { outputTokens: output_tokens } : {},
12402
- ...cached_input_tokens !== void 0 ? { cachedInputTokens: cached_input_tokens } : {},
12403
- ...cache_creation_input_tokens !== void 0 ? { cacheCreationInputTokens: cache_creation_input_tokens } : {},
12404
- ...reasoning_tokens !== void 0 ? { reasoningTokens: reasoning_tokens } : {},
12405
- ...request_count !== void 0 ? { requestCount: request_count } : {}
12406
- })
12407
- )
12408
- )
12409
- })
12410
- )
12411
- );
12412
- var GatewayGenerationInfoFetcher2 = class {
12413
- constructor(config) {
12414
- this.config = config;
12415
- }
12416
- async getGenerationInfo(params) {
12417
- try {
12418
- const baseUrl = new URL(this.config.baseURL);
12419
- const { value } = await getFromApi2({
12420
- url: `${baseUrl.origin}/v1/generation?id=${encodeURIComponent(params.id)}`,
12421
- headers: await resolve2(this.config.headers()),
12422
- successfulResponseHandler: createJsonResponseHandler2(
12423
- gatewayGenerationInfoResponseSchema2
12424
- ),
12425
- failedResponseHandler: createJsonErrorResponseHandler2({
12426
- errorSchema: z4.z.any(),
12427
- errorToMessage: (data) => data
12428
- }),
12429
- fetch: this.config.fetch
12430
- });
12431
- return value;
12432
- } catch (error) {
12433
- throw await asGatewayError2(error);
12434
- }
12435
- }
12436
- };
12437
- var gatewayGenerationInfoResponseSchema2 = lazySchema2(
12438
- () => zodSchema3(
12439
- z4.z.object({
12440
- data: z4.z.object({
12441
- id: z4.z.string(),
12442
- total_cost: z4.z.number(),
12443
- upstream_inference_cost: z4.z.number(),
12444
- usage: z4.z.number(),
12445
- created_at: z4.z.string(),
12446
- model: z4.z.string(),
12447
- is_byok: z4.z.boolean(),
12448
- provider_name: z4.z.string(),
12449
- streamed: z4.z.boolean(),
12450
- finish_reason: z4.z.string(),
12451
- latency: z4.z.number(),
12452
- generation_time: z4.z.number(),
12453
- native_tokens_prompt: z4.z.number(),
12454
- native_tokens_completion: z4.z.number(),
12455
- native_tokens_reasoning: z4.z.number(),
12456
- native_tokens_cached: z4.z.number(),
12457
- native_tokens_cache_creation: z4.z.number(),
12458
- billable_web_search_calls: z4.z.number()
12459
- }).transform(
12460
- ({
12461
- total_cost,
12462
- upstream_inference_cost,
12463
- created_at,
12464
- is_byok,
12465
- provider_name,
12466
- finish_reason,
12467
- generation_time,
12468
- native_tokens_prompt,
12469
- native_tokens_completion,
12470
- native_tokens_reasoning,
12471
- native_tokens_cached,
12472
- native_tokens_cache_creation,
12473
- billable_web_search_calls,
12474
- ...rest
12475
- }) => ({
12476
- ...rest,
12477
- totalCost: total_cost,
12478
- upstreamInferenceCost: upstream_inference_cost,
12479
- createdAt: created_at,
12480
- isByok: is_byok,
12481
- providerName: provider_name,
12482
- finishReason: finish_reason,
12483
- generationTime: generation_time,
12484
- promptTokens: native_tokens_prompt,
12485
- completionTokens: native_tokens_completion,
12486
- reasoningTokens: native_tokens_reasoning,
12487
- cachedTokens: native_tokens_cached,
12488
- cacheCreationTokens: native_tokens_cache_creation,
12489
- billableWebSearchCalls: billable_web_search_calls
12490
- })
12491
- )
12492
- }).transform(({ data }) => data)
12493
- )
12494
- );
12495
11967
  var GatewayLanguageModel2 = class {
12496
11968
  constructor(modelId, config) {
12497
11969
  this.modelId = modelId;
@@ -13039,86 +12511,6 @@ var gatewayVideoEventSchema = z4.z.discriminatedUnion("type", [
13039
12511
  param: z4.z.unknown().nullable()
13040
12512
  })
13041
12513
  ]);
13042
- var GatewayRerankingModel = class {
13043
- constructor(modelId, config) {
13044
- this.modelId = modelId;
13045
- this.config = config;
13046
- this.specificationVersion = "v3";
13047
- }
13048
- get provider() {
13049
- return this.config.provider;
13050
- }
13051
- async doRerank({
13052
- documents,
13053
- query,
13054
- topN,
13055
- headers,
13056
- abortSignal,
13057
- providerOptions
13058
- }) {
13059
- const resolvedHeaders = await resolve2(this.config.headers());
13060
- try {
13061
- const {
13062
- responseHeaders,
13063
- value: responseBody,
13064
- rawValue
13065
- } = await postJsonToApi2({
13066
- url: this.getUrl(),
13067
- headers: combineHeaders2(
13068
- resolvedHeaders,
13069
- headers != null ? headers : {},
13070
- this.getModelConfigHeaders(),
13071
- await resolve2(this.config.o11yHeaders)
13072
- ),
13073
- body: {
13074
- documents,
13075
- query,
13076
- ...topN != null ? { topN } : {},
13077
- ...providerOptions ? { providerOptions } : {}
13078
- },
13079
- successfulResponseHandler: createJsonResponseHandler2(
13080
- gatewayRerankingResponseSchema
13081
- ),
13082
- failedResponseHandler: createJsonErrorResponseHandler2({
13083
- errorSchema: z4.z.any(),
13084
- errorToMessage: (data) => data
13085
- }),
13086
- ...abortSignal && { abortSignal },
13087
- fetch: this.config.fetch
13088
- });
13089
- return {
13090
- ranking: responseBody.ranking,
13091
- providerMetadata: responseBody.providerMetadata,
13092
- response: { headers: responseHeaders, body: rawValue },
13093
- warnings: []
13094
- };
13095
- } catch (error) {
13096
- throw await asGatewayError2(error, await parseAuthMethod2(resolvedHeaders));
13097
- }
13098
- }
13099
- getUrl() {
13100
- return `${this.config.baseURL}/reranking-model`;
13101
- }
13102
- getModelConfigHeaders() {
13103
- return {
13104
- "ai-reranking-model-specification-version": "3",
13105
- "ai-model-id": this.modelId
13106
- };
13107
- }
13108
- };
13109
- var gatewayRerankingResponseSchema = lazySchema2(
13110
- () => zodSchema3(
13111
- z4.z.object({
13112
- ranking: z4.z.array(
13113
- z4.z.object({
13114
- index: z4.z.number(),
13115
- relevanceScore: z4.z.number()
13116
- })
13117
- ),
13118
- providerMetadata: z4.z.record(z4.z.string(), z4.z.record(z4.z.string(), z4.z.unknown())).optional()
13119
- })
13120
- )
13121
- );
13122
12514
  var parallelSearchInputSchema2 = lazySchema2(
13123
12515
  () => zodSchema3(
13124
12516
  zod.z.object({
@@ -13295,7 +12687,7 @@ async function getVercelRequestId2() {
13295
12687
  var _a932;
13296
12688
  return (_a932 = getContext2().headers) == null ? void 0 : _a932["x-vercel-id"];
13297
12689
  }
13298
- var VERSION5 = "3.0.104";
12690
+ var VERSION5 = "3.0.66";
13299
12691
  var AI_GATEWAY_PROTOCOL_VERSION2 = "0.0.1";
13300
12692
  function createGatewayProvider2(options = {}) {
13301
12693
  var _a932, _b93;
@@ -13395,30 +12787,6 @@ function createGatewayProvider2(options = {}) {
13395
12787
  );
13396
12788
  });
13397
12789
  };
13398
- const getSpendReport = async (params) => {
13399
- return new GatewaySpendReport2({
13400
- baseURL,
13401
- headers: getHeaders,
13402
- fetch: options.fetch
13403
- }).getSpendReport(params).catch(async (error) => {
13404
- throw await asGatewayError2(
13405
- error,
13406
- await parseAuthMethod2(await getHeaders())
13407
- );
13408
- });
13409
- };
13410
- const getGenerationInfo = async (params) => {
13411
- return new GatewayGenerationInfoFetcher2({
13412
- baseURL,
13413
- headers: getHeaders,
13414
- fetch: options.fetch
13415
- }).getGenerationInfo(params).catch(async (error) => {
13416
- throw await asGatewayError2(
13417
- error,
13418
- await parseAuthMethod2(await getHeaders())
13419
- );
13420
- });
13421
- };
13422
12790
  const provider = function(modelId) {
13423
12791
  if (new.target) {
13424
12792
  throw new Error(
@@ -13430,8 +12798,6 @@ function createGatewayProvider2(options = {}) {
13430
12798
  provider.specificationVersion = "v3";
13431
12799
  provider.getAvailableModels = getAvailableModels;
13432
12800
  provider.getCredits = getCredits;
13433
- provider.getSpendReport = getSpendReport;
13434
- provider.getGenerationInfo = getGenerationInfo;
13435
12801
  provider.imageModel = (modelId) => {
13436
12802
  return new GatewayImageModel2(modelId, {
13437
12803
  provider: "gateway",
@@ -13462,17 +12828,6 @@ function createGatewayProvider2(options = {}) {
13462
12828
  o11yHeaders: createO11yHeaders()
13463
12829
  });
13464
12830
  };
13465
- const createRerankingModel = (modelId) => {
13466
- return new GatewayRerankingModel(modelId, {
13467
- provider: "gateway",
13468
- baseURL,
13469
- headers: getHeaders,
13470
- fetch: options.fetch,
13471
- o11yHeaders: createO11yHeaders()
13472
- });
13473
- };
13474
- provider.rerankingModel = createRerankingModel;
13475
- provider.reranking = createRerankingModel;
13476
12831
  provider.chat = provider.languageModel;
13477
12832
  provider.embedding = provider.embeddingModel;
13478
12833
  provider.image = provider.imageModel;
@@ -14405,7 +13760,7 @@ function getTotalTimeoutMs(timeout) {
14405
13760
  }
14406
13761
  return timeout.totalMs;
14407
13762
  }
14408
- var VERSION33 = "6.0.168";
13763
+ var VERSION33 = "6.0.116";
14409
13764
  var dataContentSchema3 = z4.z.union([
14410
13765
  z4.z.string(),
14411
13766
  z4.z.instanceof(Uint8Array),
@@ -16616,7 +15971,7 @@ async function recallThreadFromStart({
16616
15971
  var recallTool = (_memoryConfig, options) => {
16617
15972
  const retrievalScope = options?.retrievalScope ?? "thread";
16618
15973
  const isResourceScope = retrievalScope === "resource";
16619
- const description = isResourceScope ? 'Browse conversation history. Use mode="threads" to list all threads for the current user. Use mode="messages" (default) to browse messages in the current thread or pass threadId to browse another thread in the active resource. If you pass only a cursor, it must belong to the current thread. Use mode="search" to find messages by content across all threads.' : `Browse conversation history in the current thread. Use mode="messages" (default) to page through messages near a cursor. Use mode="search" to find messages by content in this thread. Use mode="threads" to get the current thread's ID and title.`;
15974
+ const description = isResourceScope ? 'Browse conversation history. Use mode="threads" to list all threads for the current user. Use mode="messages" (default) to browse messages in the current thread or pass threadId to browse another thread in the active resource. When mode="messages" has no cursor or threadId, it defaults to the current thread and says so at the top of the result. If you pass only a cursor, it must belong to the current thread. Use mode="search" to find messages by content across all threads.' : `Browse conversation history in the current thread. Use mode="messages" (default) to page through messages near a cursor. Use mode="search" to find messages by content in this thread. Use mode="threads" to get the current thread's ID and title.`;
16620
15975
  return tools.createTool({
16621
15976
  id: "recall",
16622
15977
  description,
@@ -16641,7 +15996,7 @@ var recallTool = (_memoryConfig, options) => {
16641
15996
  },
16642
15997
  query: zod.z.string().min(1).optional().describe('Search query for mode="search". Finds messages semantically similar to this text.'),
16643
15998
  cursor: zod.z.string().min(1).optional().describe(
16644
- 'A message ID to use as the pagination cursor. For mode="messages", provide either cursor or threadId. If only cursor is provided, it must belong to the current thread. Extract it from the start or end of an observation group range.'
15999
+ 'A message ID to use as the pagination cursor. For mode="messages", omit both cursor and threadId to browse the current thread. If only cursor is provided, it must belong to the current thread. Extract it from the start or end of an observation group range.'
16645
16000
  ),
16646
16001
  anchor: zod.z.enum(["start", "end"]).optional().describe(
16647
16002
  'For mode="messages" without a cursor, page from the start (oldest-first) or end (newest-first) of the thread. Defaults to "start".'
@@ -16739,7 +16094,13 @@ var recallTool = (_memoryConfig, options) => {
16739
16094
  after
16740
16095
  });
16741
16096
  }
16742
- const hasExplicitThreadId = typeof resolvedExplicitThreadId === "string" && resolvedExplicitThreadId.length > 0;
16097
+ const usedDefaultThreadId = isResourceScope && !explicitThreadId && !cursor && Boolean(currentThreadId);
16098
+ const defaultThreadNote = usedDefaultThreadId ? `threadId wasn't passed so used default ${currentThreadId}.
16099
+
16100
+ ` : "";
16101
+ const effectiveThreadId = explicitThreadId || (usedDefaultThreadId ? "current" : void 0);
16102
+ const resolvedThreadId = effectiveThreadId === "current" ? currentThreadId : effectiveThreadId;
16103
+ const hasExplicitThreadId = typeof resolvedThreadId === "string" && resolvedThreadId.length > 0;
16743
16104
  const hasCursor = typeof cursor === "string" && cursor.length > 0;
16744
16105
  if (!hasExplicitThreadId && !hasCursor) {
16745
16106
  throw new Error('Either cursor or threadId is required for mode="messages"');
@@ -16756,7 +16117,7 @@ var recallTool = (_memoryConfig, options) => {
16756
16117
  if (!memory.getThreadById) {
16757
16118
  throw new Error("Memory instance cannot verify thread access for recall");
16758
16119
  }
16759
- const thread = await memory.getThreadById({ threadId: resolvedExplicitThreadId });
16120
+ const thread = await memory.getThreadById({ threadId: resolvedThreadId });
16760
16121
  if (!thread || thread.resourceId !== resourceId) {
16761
16122
  throw new Error("Thread does not belong to the active resource");
16762
16123
  }
@@ -16791,7 +16152,7 @@ var recallTool = (_memoryConfig, options) => {
16791
16152
  throw new Error("Thread ID is required for recall");
16792
16153
  }
16793
16154
  if (!cursor) {
16794
- return recallThreadFromStart({
16155
+ const result = await recallThreadFromStart({
16795
16156
  memory,
16796
16157
  threadId: targetThreadId,
16797
16158
  resourceId: isResourceScope ? resourceId : void 0,
@@ -16802,6 +16163,10 @@ var recallTool = (_memoryConfig, options) => {
16802
16163
  toolName,
16803
16164
  anchor: anchor ?? "start"
16804
16165
  });
16166
+ if (defaultThreadNote) {
16167
+ return { ...result, messages: `${defaultThreadNote}${result.messages}` };
16168
+ }
16169
+ return result;
16805
16170
  }
16806
16171
  if (partIndex !== void 0 && partIndex !== null) {
16807
16172
  return recallPart({