@jaypie/llm 1.2.23 → 1.2.25
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/cjs/index.cjs +123 -67
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/providers/gemini/types.d.ts +1 -0
- package/dist/cjs/util/index.d.ts +1 -0
- package/dist/cjs/util/jsonSchemaToOpenApi3.d.ts +10 -0
- package/dist/cjs/util/logger.d.ts +0 -1
- package/dist/esm/index.js +123 -67
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/providers/gemini/types.d.ts +1 -0
- package/dist/esm/util/index.d.ts +1 -0
- package/dist/esm/util/jsonSchemaToOpenApi3.d.ts +10 -0
- package/dist/esm/util/logger.d.ts +0 -1
- package/package.json +1 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var errors = require('@jaypie/errors');
|
|
4
|
-
var log$
|
|
4
|
+
var log$1 = require('@jaypie/logger');
|
|
5
5
|
var v4 = require('zod/v4');
|
|
6
6
|
var kit = require('@jaypie/kit');
|
|
7
7
|
var RandomLib = require('random');
|
|
@@ -554,8 +554,51 @@ function formatOperateInput(input, options) {
|
|
|
554
554
|
return [input];
|
|
555
555
|
}
|
|
556
556
|
|
|
557
|
-
|
|
558
|
-
|
|
557
|
+
/**
|
|
558
|
+
* Converts a JSON Schema (Draft 2020-12) object to the OpenAPI 3.0 schema subset
|
|
559
|
+
* that Gemini's `responseSchema` accepts. This constrains generation (not just validation)
|
|
560
|
+
* and avoids the `items`-keyword leakage bug in `responseJsonSchema`.
|
|
561
|
+
*
|
|
562
|
+
* Strips: $schema, additionalProperties, $defs, $ref (inlines where possible), const
|
|
563
|
+
* Preserves: type, properties, required, items, enum, description, nullable
|
|
564
|
+
*/
|
|
565
|
+
function jsonSchemaToOpenApi3(schema) {
|
|
566
|
+
if (typeof schema !== "object" || schema === null || Array.isArray(schema)) {
|
|
567
|
+
return schema;
|
|
568
|
+
}
|
|
569
|
+
const result = {};
|
|
570
|
+
for (const [key, value] of Object.entries(schema)) {
|
|
571
|
+
// Strip JSON Schema keywords not in OpenAPI 3.0 subset
|
|
572
|
+
if (key === "$schema" ||
|
|
573
|
+
key === "$defs" ||
|
|
574
|
+
key === "additionalProperties" ||
|
|
575
|
+
key === "const" ||
|
|
576
|
+
key === "$ref") {
|
|
577
|
+
continue;
|
|
578
|
+
}
|
|
579
|
+
if (key === "properties" &&
|
|
580
|
+
typeof value === "object" &&
|
|
581
|
+
value !== null &&
|
|
582
|
+
!Array.isArray(value)) {
|
|
583
|
+
const convertedProps = {};
|
|
584
|
+
for (const [propKey, propValue] of Object.entries(value)) {
|
|
585
|
+
convertedProps[propKey] = jsonSchemaToOpenApi3(propValue);
|
|
586
|
+
}
|
|
587
|
+
result[key] = convertedProps;
|
|
588
|
+
}
|
|
589
|
+
else if (key === "items" &&
|
|
590
|
+
typeof value === "object" &&
|
|
591
|
+
value !== null) {
|
|
592
|
+
result[key] = jsonSchemaToOpenApi3(value);
|
|
593
|
+
}
|
|
594
|
+
else {
|
|
595
|
+
result[key] = value;
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
return result;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
const getLogger$5 = () => log$1.log.lib({ lib: kit.JAYPIE.LIB.LLM });
|
|
559
602
|
|
|
560
603
|
// Turn policy constants
|
|
561
604
|
const MAX_TURNS_ABSOLUTE_LIMIT = 72;
|
|
@@ -1541,11 +1584,21 @@ class GeminiAdapter extends BaseProviderAdapter {
|
|
|
1541
1584
|
// Gemini doesn't support combining function calling with responseMimeType: 'application/json'
|
|
1542
1585
|
// When tools are present, structured output is handled via the structured_output tool
|
|
1543
1586
|
if (request.format && !(request.tools && request.tools.length > 0)) {
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1587
|
+
const useJsonSchema = request.providerOptions?.useJsonSchema === true;
|
|
1588
|
+
if (useJsonSchema) {
|
|
1589
|
+
geminiRequest.config = {
|
|
1590
|
+
...geminiRequest.config,
|
|
1591
|
+
responseMimeType: "application/json",
|
|
1592
|
+
responseJsonSchema: request.format,
|
|
1593
|
+
};
|
|
1594
|
+
}
|
|
1595
|
+
else {
|
|
1596
|
+
geminiRequest.config = {
|
|
1597
|
+
...geminiRequest.config,
|
|
1598
|
+
responseMimeType: "application/json",
|
|
1599
|
+
responseSchema: jsonSchemaToOpenApi3(request.format),
|
|
1600
|
+
};
|
|
1601
|
+
}
|
|
1549
1602
|
}
|
|
1550
1603
|
// When format is specified with tools, add instruction to use structured_output tool
|
|
1551
1604
|
if (request.format && request.tools && request.tools.length > 0) {
|
|
@@ -1613,11 +1666,7 @@ class GeminiAdapter extends BaseProviderAdapter {
|
|
|
1613
1666
|
: naturalZodSchema(schema);
|
|
1614
1667
|
jsonSchema = v4.z.toJSONSchema(zodSchema);
|
|
1615
1668
|
}
|
|
1616
|
-
|
|
1617
|
-
if (jsonSchema.$schema) {
|
|
1618
|
-
delete jsonSchema.$schema;
|
|
1619
|
-
}
|
|
1620
|
-
return jsonSchema;
|
|
1669
|
+
return jsonSchemaToOpenApi3(jsonSchema);
|
|
1621
1670
|
}
|
|
1622
1671
|
//
|
|
1623
1672
|
// API Execution
|
|
@@ -2662,16 +2711,16 @@ function convertContentToOpenRouter(content) {
|
|
|
2662
2711
|
}
|
|
2663
2712
|
// Image content - warn and discard
|
|
2664
2713
|
if (item.type === exports.LlmMessageType.InputImage) {
|
|
2665
|
-
log$
|
|
2714
|
+
log$1.log.warn("OpenRouter does not support image uploads; image discarded");
|
|
2666
2715
|
continue;
|
|
2667
2716
|
}
|
|
2668
2717
|
// File/Document content - warn and discard
|
|
2669
2718
|
if (item.type === exports.LlmMessageType.InputFile) {
|
|
2670
|
-
log$
|
|
2719
|
+
log$1.log.warn({ filename: item.filename }, "OpenRouter does not support file uploads; file discarded");
|
|
2671
2720
|
continue;
|
|
2672
2721
|
}
|
|
2673
2722
|
// Unknown type - warn and skip
|
|
2674
|
-
log$
|
|
2723
|
+
log$1.log.warn({ item }, "Unknown content type for OpenRouter; discarded");
|
|
2675
2724
|
}
|
|
2676
2725
|
// If no text parts remain, return empty string to avoid empty array
|
|
2677
2726
|
if (parts.length === 0) {
|
|
@@ -3249,7 +3298,7 @@ class XaiAdapter extends OpenAiAdapter {
|
|
|
3249
3298
|
const xaiAdapter = new XaiAdapter();
|
|
3250
3299
|
|
|
3251
3300
|
const DEFAULT_TOOL_TYPE = "function";
|
|
3252
|
-
const log = log$
|
|
3301
|
+
const log = log$1.log.lib({ lib: kit.JAYPIE.LIB.LLM });
|
|
3253
3302
|
function logToolMessage(message, context) {
|
|
3254
3303
|
log.trace.var({ [context.name]: message });
|
|
3255
3304
|
}
|
|
@@ -4055,6 +4104,7 @@ class RetryExecutor {
|
|
|
4055
4104
|
* @throws BadGatewayError if all retries are exhausted or error is not retryable
|
|
4056
4105
|
*/
|
|
4057
4106
|
async execute(operation, options) {
|
|
4107
|
+
const log = getLogger$5();
|
|
4058
4108
|
let attempt = 0;
|
|
4059
4109
|
// Persistent guard against stale socket errors (TypeError: terminated).
|
|
4060
4110
|
// Installed after the first abort and kept alive through subsequent attempts
|
|
@@ -4066,7 +4116,7 @@ class RetryExecutor {
|
|
|
4066
4116
|
return;
|
|
4067
4117
|
staleGuard = (reason) => {
|
|
4068
4118
|
if (isTransientNetworkError(reason)) {
|
|
4069
|
-
log
|
|
4119
|
+
log.trace("Suppressed stale socket error during retry");
|
|
4070
4120
|
}
|
|
4071
4121
|
};
|
|
4072
4122
|
process.on("unhandledRejection", staleGuard);
|
|
@@ -4083,7 +4133,7 @@ class RetryExecutor {
|
|
|
4083
4133
|
try {
|
|
4084
4134
|
const result = await operation(controller.signal);
|
|
4085
4135
|
if (attempt > 0) {
|
|
4086
|
-
log
|
|
4136
|
+
log.debug(`API call succeeded after ${attempt} retries`);
|
|
4087
4137
|
}
|
|
4088
4138
|
return result;
|
|
4089
4139
|
}
|
|
@@ -4096,8 +4146,8 @@ class RetryExecutor {
|
|
|
4096
4146
|
installGuard();
|
|
4097
4147
|
// Check if we've exhausted retries
|
|
4098
4148
|
if (!this.policy.shouldRetry(attempt)) {
|
|
4099
|
-
log
|
|
4100
|
-
log
|
|
4149
|
+
log.error(`API call failed after ${this.policy.maxRetries} retries`);
|
|
4150
|
+
log.var({ error });
|
|
4101
4151
|
await this.hookRunner.runOnUnrecoverableError(options.hooks, {
|
|
4102
4152
|
input: options.context.input,
|
|
4103
4153
|
options: options.context.options,
|
|
@@ -4109,8 +4159,8 @@ class RetryExecutor {
|
|
|
4109
4159
|
}
|
|
4110
4160
|
// Check if error is not retryable
|
|
4111
4161
|
if (!this.errorClassifier.isRetryable(error)) {
|
|
4112
|
-
log
|
|
4113
|
-
log
|
|
4162
|
+
log.error("API call failed with non-retryable error");
|
|
4163
|
+
log.var({ error });
|
|
4114
4164
|
await this.hookRunner.runOnUnrecoverableError(options.hooks, {
|
|
4115
4165
|
input: options.context.input,
|
|
4116
4166
|
options: options.context.options,
|
|
@@ -4122,11 +4172,11 @@ class RetryExecutor {
|
|
|
4122
4172
|
}
|
|
4123
4173
|
// Warn if this is an unknown error type
|
|
4124
4174
|
if (!this.errorClassifier.isKnownError(error)) {
|
|
4125
|
-
log
|
|
4126
|
-
log
|
|
4175
|
+
log.warn("API returned unknown error type, will retry");
|
|
4176
|
+
log.var({ error });
|
|
4127
4177
|
}
|
|
4128
4178
|
const delay = this.policy.getDelayForAttempt(attempt);
|
|
4129
|
-
log
|
|
4179
|
+
log.warn(`API call failed. Retrying in ${delay}ms...`);
|
|
4130
4180
|
await this.hookRunner.runOnRetryableError(options.hooks, {
|
|
4131
4181
|
input: options.context.input,
|
|
4132
4182
|
options: options.context.options,
|
|
@@ -4192,10 +4242,11 @@ class OperateLoop {
|
|
|
4192
4242
|
* Execute the operate loop for multi-turn conversations with tool calling.
|
|
4193
4243
|
*/
|
|
4194
4244
|
async execute(input, options = {}) {
|
|
4245
|
+
const log = getLogger$5();
|
|
4195
4246
|
// Log what was passed to operate
|
|
4196
|
-
log
|
|
4197
|
-
log
|
|
4198
|
-
log
|
|
4247
|
+
log.trace("[operate] Starting operate loop");
|
|
4248
|
+
log.var({ "operate.input": input });
|
|
4249
|
+
log.var({ "operate.options": options });
|
|
4199
4250
|
// Initialize state
|
|
4200
4251
|
const state = await this.initializeState(input, options);
|
|
4201
4252
|
const context = this.createContext(options);
|
|
@@ -4304,6 +4355,7 @@ class OperateLoop {
|
|
|
4304
4355
|
};
|
|
4305
4356
|
}
|
|
4306
4357
|
async executeOneTurn(request, state, context, options) {
|
|
4358
|
+
const log = getLogger$5();
|
|
4307
4359
|
// Create error classifier from adapter
|
|
4308
4360
|
const errorClassifier = createErrorClassifier(this.adapter);
|
|
4309
4361
|
// Create retry executor for this turn
|
|
@@ -4315,8 +4367,8 @@ class OperateLoop {
|
|
|
4315
4367
|
// Build provider-specific request
|
|
4316
4368
|
const providerRequest = this.adapter.buildRequest(request);
|
|
4317
4369
|
// Log what was passed to the model
|
|
4318
|
-
log
|
|
4319
|
-
log
|
|
4370
|
+
log.trace("[operate] Calling model");
|
|
4371
|
+
log.var({ "operate.request": providerRequest });
|
|
4320
4372
|
// Execute beforeEachModelRequest hook
|
|
4321
4373
|
await this.hookRunnerInstance.runBeforeModelRequest(context.hooks, {
|
|
4322
4374
|
input: state.currentInput,
|
|
@@ -4333,8 +4385,8 @@ class OperateLoop {
|
|
|
4333
4385
|
hooks: context.hooks,
|
|
4334
4386
|
});
|
|
4335
4387
|
// Log what was returned from the model
|
|
4336
|
-
log
|
|
4337
|
-
log
|
|
4388
|
+
log.trace("[operate] Model response received");
|
|
4389
|
+
log.var({ "operate.response": response });
|
|
4338
4390
|
// Parse response
|
|
4339
4391
|
const parsed = this.adapter.parseResponse(response, options);
|
|
4340
4392
|
// Track usage
|
|
@@ -4382,7 +4434,7 @@ class OperateLoop {
|
|
|
4382
4434
|
toolName: toolCall.name,
|
|
4383
4435
|
});
|
|
4384
4436
|
// Call the tool
|
|
4385
|
-
log
|
|
4437
|
+
log.trace(`[operate] Calling tool - ${toolCall.name}`);
|
|
4386
4438
|
const result = await state.toolkit.call({
|
|
4387
4439
|
arguments: toolCall.arguments,
|
|
4388
4440
|
name: toolCall.name,
|
|
@@ -4440,13 +4492,13 @@ class OperateLoop {
|
|
|
4440
4492
|
};
|
|
4441
4493
|
const toolResultFormatted = this.adapter.formatToolResult(toolCall, errorResult);
|
|
4442
4494
|
state.responseBuilder.appendToHistory(toolResultFormatted);
|
|
4443
|
-
log
|
|
4444
|
-
log
|
|
4495
|
+
log.error(`Error executing function call ${toolCall.name}`);
|
|
4496
|
+
log.var({ error });
|
|
4445
4497
|
// Track consecutive errors and stop if threshold reached
|
|
4446
4498
|
state.consecutiveToolErrors++;
|
|
4447
4499
|
if (state.consecutiveToolErrors >= MAX_CONSECUTIVE_TOOL_ERRORS) {
|
|
4448
4500
|
const detail = `Stopped after ${MAX_CONSECUTIVE_TOOL_ERRORS} consecutive tool errors`;
|
|
4449
|
-
log
|
|
4501
|
+
log.warn(detail);
|
|
4450
4502
|
state.responseBuilder.setError({
|
|
4451
4503
|
detail,
|
|
4452
4504
|
status: 502,
|
|
@@ -4461,7 +4513,7 @@ class OperateLoop {
|
|
|
4461
4513
|
if (state.currentTurn >= state.maxTurns) {
|
|
4462
4514
|
const error = new errors.TooManyRequestsError();
|
|
4463
4515
|
const detail = `Model requested function call but exceeded ${state.maxTurns} turns`;
|
|
4464
|
-
log
|
|
4516
|
+
log.warn(detail);
|
|
4465
4517
|
state.responseBuilder.setError({
|
|
4466
4518
|
detail,
|
|
4467
4519
|
status: error.status,
|
|
@@ -4615,6 +4667,7 @@ class StreamLoop {
|
|
|
4615
4667
|
* Yields stream chunks as they become available.
|
|
4616
4668
|
*/
|
|
4617
4669
|
async *execute(input, options = {}) {
|
|
4670
|
+
const log = getLogger$5();
|
|
4618
4671
|
// Verify adapter supports streaming
|
|
4619
4672
|
if (!this.adapter.executeStreamRequest) {
|
|
4620
4673
|
throw new errors.BadGatewayError(`Provider ${this.adapter.name} does not support streaming`);
|
|
@@ -4639,7 +4692,7 @@ class StreamLoop {
|
|
|
4639
4692
|
if (state.currentTurn >= state.maxTurns) {
|
|
4640
4693
|
const error = new errors.TooManyRequestsError();
|
|
4641
4694
|
const detail = `Model requested function call but exceeded ${state.maxTurns} turns`;
|
|
4642
|
-
log
|
|
4695
|
+
log.warn(detail);
|
|
4643
4696
|
yield {
|
|
4644
4697
|
type: exports.LlmStreamChunkType.Error,
|
|
4645
4698
|
error: {
|
|
@@ -4732,6 +4785,7 @@ class StreamLoop {
|
|
|
4732
4785
|
};
|
|
4733
4786
|
}
|
|
4734
4787
|
async *executeOneStreamingTurn(request, state, context, options) {
|
|
4788
|
+
const log = getLogger$5();
|
|
4735
4789
|
// Build provider-specific request
|
|
4736
4790
|
const providerRequest = this.adapter.buildRequest(request);
|
|
4737
4791
|
// Execute beforeEachModelRequest hook
|
|
@@ -4753,7 +4807,7 @@ class StreamLoop {
|
|
|
4753
4807
|
return;
|
|
4754
4808
|
staleGuard = (reason) => {
|
|
4755
4809
|
if (isTransientNetworkError(reason)) {
|
|
4756
|
-
log
|
|
4810
|
+
log.trace("Suppressed stale socket error during retry");
|
|
4757
4811
|
}
|
|
4758
4812
|
};
|
|
4759
4813
|
process.on("unhandledRejection", staleGuard);
|
|
@@ -4799,7 +4853,7 @@ class StreamLoop {
|
|
|
4799
4853
|
}
|
|
4800
4854
|
// Stream completed successfully
|
|
4801
4855
|
if (attempt > 0) {
|
|
4802
|
-
log
|
|
4856
|
+
log.debug(`Stream request succeeded after ${attempt} retries`);
|
|
4803
4857
|
}
|
|
4804
4858
|
break;
|
|
4805
4859
|
}
|
|
@@ -4811,8 +4865,8 @@ class StreamLoop {
|
|
|
4811
4865
|
// If chunks were already yielded, we can't transparently retry
|
|
4812
4866
|
if (chunksYielded) {
|
|
4813
4867
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
4814
|
-
log
|
|
4815
|
-
log
|
|
4868
|
+
log.error("Stream failed after partial data was delivered");
|
|
4869
|
+
log.var({ error });
|
|
4816
4870
|
yield {
|
|
4817
4871
|
type: exports.LlmStreamChunkType.Error,
|
|
4818
4872
|
error: {
|
|
@@ -4826,14 +4880,14 @@ class StreamLoop {
|
|
|
4826
4880
|
// Check if we've exhausted retries or error is not retryable
|
|
4827
4881
|
if (!this.retryPolicy.shouldRetry(attempt) ||
|
|
4828
4882
|
!this.adapter.isRetryableError(error)) {
|
|
4829
|
-
log
|
|
4830
|
-
log
|
|
4883
|
+
log.error(`Stream request failed after ${this.retryPolicy.maxRetries} retries`);
|
|
4884
|
+
log.var({ error });
|
|
4831
4885
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
4832
4886
|
throw new errors.BadGatewayError(errorMessage);
|
|
4833
4887
|
}
|
|
4834
4888
|
const delay = this.retryPolicy.getDelayForAttempt(attempt);
|
|
4835
|
-
log
|
|
4836
|
-
log
|
|
4889
|
+
log.warn(`Stream request failed. Retrying in ${delay}ms...`);
|
|
4890
|
+
log.var({ error });
|
|
4837
4891
|
await kit.sleep(delay);
|
|
4838
4892
|
attempt++;
|
|
4839
4893
|
}
|
|
@@ -4877,6 +4931,7 @@ class StreamLoop {
|
|
|
4877
4931
|
return { shouldContinue: false };
|
|
4878
4932
|
}
|
|
4879
4933
|
async *processToolCalls(toolCalls, state, context, _options) {
|
|
4934
|
+
const log = getLogger$5();
|
|
4880
4935
|
for (const toolCall of toolCalls) {
|
|
4881
4936
|
try {
|
|
4882
4937
|
// Execute beforeEachTool hook
|
|
@@ -4885,7 +4940,7 @@ class StreamLoop {
|
|
|
4885
4940
|
toolName: toolCall.name,
|
|
4886
4941
|
});
|
|
4887
4942
|
// Call the tool
|
|
4888
|
-
log
|
|
4943
|
+
log.trace(`[stream] Calling tool - ${toolCall.name}`);
|
|
4889
4944
|
const result = await state.toolkit.call({
|
|
4890
4945
|
arguments: toolCall.arguments,
|
|
4891
4946
|
name: toolCall.name,
|
|
@@ -4948,13 +5003,13 @@ class StreamLoop {
|
|
|
4948
5003
|
call_id: toolCall.callId,
|
|
4949
5004
|
name: toolCall.name,
|
|
4950
5005
|
});
|
|
4951
|
-
log
|
|
4952
|
-
log
|
|
5006
|
+
log.error(`Error executing function call ${toolCall.name}`);
|
|
5007
|
+
log.var({ error });
|
|
4953
5008
|
// Track consecutive errors and stop if threshold reached
|
|
4954
5009
|
state.consecutiveToolErrors++;
|
|
4955
5010
|
if (state.consecutiveToolErrors >= MAX_CONSECUTIVE_TOOL_ERRORS) {
|
|
4956
5011
|
const stopDetail = `Stopped after ${MAX_CONSECUTIVE_TOOL_ERRORS} consecutive tool errors`;
|
|
4957
|
-
log
|
|
5012
|
+
log.warn(stopDetail);
|
|
4958
5013
|
yield {
|
|
4959
5014
|
type: exports.LlmStreamChunkType.Error,
|
|
4960
5015
|
error: {
|
|
@@ -5035,7 +5090,7 @@ async function loadSdk$2() {
|
|
|
5035
5090
|
}
|
|
5036
5091
|
}
|
|
5037
5092
|
// Logger
|
|
5038
|
-
const getLogger$4 = () => log$
|
|
5093
|
+
const getLogger$4 = () => log$1.log.lib({ lib: kit.JAYPIE.LIB.LLM });
|
|
5039
5094
|
// Client initialization
|
|
5040
5095
|
async function initializeClient$4({ apiKey, } = {}) {
|
|
5041
5096
|
const logger = getLogger$4();
|
|
@@ -5074,7 +5129,7 @@ function prepareMessages$3(message, { data, placeholders } = {}) {
|
|
|
5074
5129
|
}
|
|
5075
5130
|
// Basic text completion
|
|
5076
5131
|
async function createTextCompletion$1(client, messages, model, systemMessage) {
|
|
5077
|
-
log$
|
|
5132
|
+
log$1.log.trace("Using text output (unstructured)");
|
|
5078
5133
|
const params = {
|
|
5079
5134
|
model,
|
|
5080
5135
|
messages,
|
|
@@ -5083,17 +5138,17 @@ async function createTextCompletion$1(client, messages, model, systemMessage) {
|
|
|
5083
5138
|
// Add system instruction if provided
|
|
5084
5139
|
if (systemMessage) {
|
|
5085
5140
|
params.system = systemMessage;
|
|
5086
|
-
log$
|
|
5141
|
+
log$1.log.trace(`System message: ${systemMessage.length} characters`);
|
|
5087
5142
|
}
|
|
5088
5143
|
const response = await client.messages.create(params);
|
|
5089
5144
|
const firstContent = response.content[0];
|
|
5090
5145
|
const text = firstContent && "text" in firstContent ? firstContent.text : "";
|
|
5091
|
-
log$
|
|
5146
|
+
log$1.log.trace(`Assistant reply: ${text.length} characters`);
|
|
5092
5147
|
return text;
|
|
5093
5148
|
}
|
|
5094
5149
|
// Structured output completion
|
|
5095
5150
|
async function createStructuredCompletion$1(client, messages, model, responseSchema, systemMessage) {
|
|
5096
|
-
log$
|
|
5151
|
+
log$1.log.trace("Using structured output");
|
|
5097
5152
|
// Get the JSON schema for the response
|
|
5098
5153
|
const schema = responseSchema instanceof v4.z.ZodType
|
|
5099
5154
|
? responseSchema
|
|
@@ -5126,7 +5181,7 @@ async function createStructuredCompletion$1(client, messages, model, responseSch
|
|
|
5126
5181
|
if (!schema.parse(result)) {
|
|
5127
5182
|
throw new Error(`JSON response from Anthropic does not match schema: ${responseText}`);
|
|
5128
5183
|
}
|
|
5129
|
-
log$
|
|
5184
|
+
log$1.log.trace("Received structured response", { result });
|
|
5130
5185
|
return result;
|
|
5131
5186
|
}
|
|
5132
5187
|
catch {
|
|
@@ -5137,7 +5192,7 @@ async function createStructuredCompletion$1(client, messages, model, responseSch
|
|
|
5137
5192
|
throw new Error("Failed to parse structured response from Anthropic");
|
|
5138
5193
|
}
|
|
5139
5194
|
catch (error) {
|
|
5140
|
-
log$
|
|
5195
|
+
log$1.log.error("Error creating structured completion", { error });
|
|
5141
5196
|
throw error;
|
|
5142
5197
|
}
|
|
5143
5198
|
}
|
|
@@ -5251,7 +5306,7 @@ async function loadSdk$1() {
|
|
|
5251
5306
|
}
|
|
5252
5307
|
}
|
|
5253
5308
|
// Logger
|
|
5254
|
-
const getLogger$3 = () => log$
|
|
5309
|
+
const getLogger$3 = () => log$1.log.lib({ lib: kit.JAYPIE.LIB.LLM });
|
|
5255
5310
|
// Client initialization
|
|
5256
5311
|
async function initializeClient$3({ apiKey, } = {}) {
|
|
5257
5312
|
const logger = getLogger$3();
|
|
@@ -5402,7 +5457,7 @@ class GeminiProvider {
|
|
|
5402
5457
|
}
|
|
5403
5458
|
|
|
5404
5459
|
// Logger
|
|
5405
|
-
const getLogger$2 = () => log$
|
|
5460
|
+
const getLogger$2 = () => log$1.log.lib({ lib: kit.JAYPIE.LIB.LLM });
|
|
5406
5461
|
// Client initialization
|
|
5407
5462
|
async function initializeClient$2({ apiKey, } = {}) {
|
|
5408
5463
|
const logger = getLogger$2();
|
|
@@ -5586,7 +5641,7 @@ async function loadSdk() {
|
|
|
5586
5641
|
}
|
|
5587
5642
|
}
|
|
5588
5643
|
// Logger
|
|
5589
|
-
const getLogger$1 = () => log$
|
|
5644
|
+
const getLogger$1 = () => log$1.log.lib({ lib: kit.JAYPIE.LIB.LLM });
|
|
5590
5645
|
// Client initialization
|
|
5591
5646
|
async function initializeClient$1({ apiKey, } = {}) {
|
|
5592
5647
|
const logger = getLogger$1();
|
|
@@ -5735,7 +5790,7 @@ class OpenRouterProvider {
|
|
|
5735
5790
|
}
|
|
5736
5791
|
|
|
5737
5792
|
// Logger
|
|
5738
|
-
const getLogger = () => log$
|
|
5793
|
+
const getLogger = () => log$1.log.lib({ lib: kit.JAYPIE.LIB.LLM });
|
|
5739
5794
|
// Client initialization
|
|
5740
5795
|
async function initializeClient({ apiKey, } = {}) {
|
|
5741
5796
|
const logger = getLogger();
|
|
@@ -5842,7 +5897,7 @@ class Llm {
|
|
|
5842
5897
|
let finalModel = model;
|
|
5843
5898
|
// Legacy: accept "gemini" but warn
|
|
5844
5899
|
if (providerName === "gemini") {
|
|
5845
|
-
log$
|
|
5900
|
+
log$1.warn(`Provider "gemini" is deprecated, use "${PROVIDER.GEMINI.NAME}" instead`);
|
|
5846
5901
|
}
|
|
5847
5902
|
if (model) {
|
|
5848
5903
|
const modelDetermined = determineModelProvider(model);
|
|
@@ -5954,7 +6009,7 @@ class Llm {
|
|
|
5954
6009
|
}
|
|
5955
6010
|
catch (error) {
|
|
5956
6011
|
lastError = error;
|
|
5957
|
-
log$
|
|
6012
|
+
log$1.warn(`Provider ${this._provider} failed`, {
|
|
5958
6013
|
error: lastError.message,
|
|
5959
6014
|
fallbacksRemaining: fallbackChain.length,
|
|
5960
6015
|
});
|
|
@@ -5974,7 +6029,7 @@ class Llm {
|
|
|
5974
6029
|
}
|
|
5975
6030
|
catch (error) {
|
|
5976
6031
|
lastError = error;
|
|
5977
|
-
log$
|
|
6032
|
+
log$1.warn(`Fallback provider ${fallbackConfig.provider} failed`, {
|
|
5978
6033
|
error: lastError.message,
|
|
5979
6034
|
fallbacksRemaining: fallbackChain.length - attempts + 1,
|
|
5980
6035
|
});
|
|
@@ -6143,16 +6198,17 @@ const roll = {
|
|
|
6143
6198
|
},
|
|
6144
6199
|
type: "function",
|
|
6145
6200
|
call: ({ number = 1, sides = 6 } = {}) => {
|
|
6201
|
+
const log = getLogger$5();
|
|
6146
6202
|
const rng = random$1();
|
|
6147
6203
|
const rolls = [];
|
|
6148
6204
|
let total = 0;
|
|
6149
6205
|
const parsedNumber = tryParseNumber(number, {
|
|
6150
6206
|
defaultValue: 1,
|
|
6151
|
-
warnFunction: log
|
|
6207
|
+
warnFunction: log.warn,
|
|
6152
6208
|
});
|
|
6153
6209
|
const parsedSides = tryParseNumber(sides, {
|
|
6154
6210
|
defaultValue: 6,
|
|
6155
|
-
warnFunction: log
|
|
6211
|
+
warnFunction: log.warn,
|
|
6156
6212
|
});
|
|
6157
6213
|
for (let i = 0; i < parsedNumber; i++) {
|
|
6158
6214
|
const rollValue = rng({ min: 1, max: parsedSides, integer: true });
|