@getpochi/cli 0.5.59 → 0.5.61
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/cli.js +1378 -101
- package/package.json +3 -2
package/dist/cli.js
CHANGED
|
@@ -339425,6 +339425,24 @@ var UnsupportedFunctionalityError = class extends AISDKError {
|
|
|
339425
339425
|
}
|
|
339426
339426
|
};
|
|
339427
339427
|
_a14 = symbol14;
|
|
339428
|
+
function isJSONValue(value2) {
|
|
339429
|
+
if (value2 === null || typeof value2 === "string" || typeof value2 === "number" || typeof value2 === "boolean") {
|
|
339430
|
+
return true;
|
|
339431
|
+
}
|
|
339432
|
+
if (Array.isArray(value2)) {
|
|
339433
|
+
return value2.every(isJSONValue);
|
|
339434
|
+
}
|
|
339435
|
+
if (typeof value2 === "object") {
|
|
339436
|
+
return Object.entries(value2).every(([key, val]) => typeof key === "string" && isJSONValue(val));
|
|
339437
|
+
}
|
|
339438
|
+
return false;
|
|
339439
|
+
}
|
|
339440
|
+
function isJSONArray(value2) {
|
|
339441
|
+
return Array.isArray(value2) && value2.every(isJSONValue);
|
|
339442
|
+
}
|
|
339443
|
+
function isJSONObject(value2) {
|
|
339444
|
+
return value2 != null && typeof value2 === "object" && Object.entries(value2).every(([key, val]) => typeof key === "string" && isJSONValue(val));
|
|
339445
|
+
}
|
|
339428
339446
|
|
|
339429
339447
|
// ../../node_modules/eventsource-parser/dist/index.js
|
|
339430
339448
|
class ParseError extends Error {
|
|
@@ -347433,6 +347451,13 @@ function prepareRetries({
|
|
|
347433
347451
|
})
|
|
347434
347452
|
};
|
|
347435
347453
|
}
|
|
347454
|
+
function extractTextContent(content) {
|
|
347455
|
+
const parts = content.filter((content2) => content2.type === "text");
|
|
347456
|
+
if (parts.length === 0) {
|
|
347457
|
+
return;
|
|
347458
|
+
}
|
|
347459
|
+
return parts.map((content2) => content2.text).join("");
|
|
347460
|
+
}
|
|
347436
347461
|
var DefaultGeneratedFile = class {
|
|
347437
347462
|
constructor({
|
|
347438
347463
|
data,
|
|
@@ -347724,6 +347749,520 @@ var originalGenerateId = createIdGenerator({
|
|
|
347724
347749
|
prefix: "aitxt",
|
|
347725
347750
|
size: 24
|
|
347726
347751
|
});
|
|
347752
|
+
async function generateText({
|
|
347753
|
+
model: modelArg,
|
|
347754
|
+
tools,
|
|
347755
|
+
toolChoice,
|
|
347756
|
+
system,
|
|
347757
|
+
prompt,
|
|
347758
|
+
messages,
|
|
347759
|
+
maxRetries: maxRetriesArg,
|
|
347760
|
+
abortSignal,
|
|
347761
|
+
headers,
|
|
347762
|
+
stopWhen = stepCountIs(1),
|
|
347763
|
+
experimental_output: output,
|
|
347764
|
+
experimental_telemetry: telemetry,
|
|
347765
|
+
providerOptions,
|
|
347766
|
+
experimental_activeTools,
|
|
347767
|
+
activeTools = experimental_activeTools,
|
|
347768
|
+
experimental_prepareStep,
|
|
347769
|
+
prepareStep = experimental_prepareStep,
|
|
347770
|
+
experimental_repairToolCall: repairToolCall,
|
|
347771
|
+
experimental_download: download2,
|
|
347772
|
+
experimental_context,
|
|
347773
|
+
_internal: {
|
|
347774
|
+
generateId: generateId3 = originalGenerateId,
|
|
347775
|
+
currentDate = () => /* @__PURE__ */ new Date
|
|
347776
|
+
} = {},
|
|
347777
|
+
onStepFinish,
|
|
347778
|
+
...settings
|
|
347779
|
+
}) {
|
|
347780
|
+
const model = resolveLanguageModel(modelArg);
|
|
347781
|
+
const stopConditions = asArray(stopWhen);
|
|
347782
|
+
const { maxRetries, retry } = prepareRetries({
|
|
347783
|
+
maxRetries: maxRetriesArg,
|
|
347784
|
+
abortSignal
|
|
347785
|
+
});
|
|
347786
|
+
const callSettings = prepareCallSettings(settings);
|
|
347787
|
+
const headersWithUserAgent = withUserAgentSuffix(headers != null ? headers : {}, `ai/${VERSION3}`);
|
|
347788
|
+
const baseTelemetryAttributes = getBaseTelemetryAttributes({
|
|
347789
|
+
model,
|
|
347790
|
+
telemetry,
|
|
347791
|
+
headers: headersWithUserAgent,
|
|
347792
|
+
settings: { ...callSettings, maxRetries }
|
|
347793
|
+
});
|
|
347794
|
+
const initialPrompt = await standardizePrompt({
|
|
347795
|
+
system,
|
|
347796
|
+
prompt,
|
|
347797
|
+
messages
|
|
347798
|
+
});
|
|
347799
|
+
const tracer = getTracer(telemetry);
|
|
347800
|
+
try {
|
|
347801
|
+
return await recordSpan({
|
|
347802
|
+
name: "ai.generateText",
|
|
347803
|
+
attributes: selectTelemetryAttributes({
|
|
347804
|
+
telemetry,
|
|
347805
|
+
attributes: {
|
|
347806
|
+
...assembleOperationName({
|
|
347807
|
+
operationId: "ai.generateText",
|
|
347808
|
+
telemetry
|
|
347809
|
+
}),
|
|
347810
|
+
...baseTelemetryAttributes,
|
|
347811
|
+
"ai.model.provider": model.provider,
|
|
347812
|
+
"ai.model.id": model.modelId,
|
|
347813
|
+
"ai.prompt": {
|
|
347814
|
+
input: () => JSON.stringify({ system, prompt, messages })
|
|
347815
|
+
}
|
|
347816
|
+
}
|
|
347817
|
+
}),
|
|
347818
|
+
tracer,
|
|
347819
|
+
fn: async (span) => {
|
|
347820
|
+
var _a172, _b8, _c, _d, _e, _f, _g;
|
|
347821
|
+
const callSettings2 = prepareCallSettings(settings);
|
|
347822
|
+
let currentModelResponse;
|
|
347823
|
+
let clientToolCalls = [];
|
|
347824
|
+
let clientToolOutputs = [];
|
|
347825
|
+
const responseMessages = [];
|
|
347826
|
+
const steps = [];
|
|
347827
|
+
do {
|
|
347828
|
+
const stepInputMessages = [
|
|
347829
|
+
...initialPrompt.messages,
|
|
347830
|
+
...responseMessages
|
|
347831
|
+
];
|
|
347832
|
+
const prepareStepResult = await (prepareStep == null ? undefined : prepareStep({
|
|
347833
|
+
model,
|
|
347834
|
+
steps,
|
|
347835
|
+
stepNumber: steps.length,
|
|
347836
|
+
messages: stepInputMessages
|
|
347837
|
+
}));
|
|
347838
|
+
const promptMessages = await convertToLanguageModelPrompt({
|
|
347839
|
+
prompt: {
|
|
347840
|
+
system: (_a172 = prepareStepResult == null ? undefined : prepareStepResult.system) != null ? _a172 : initialPrompt.system,
|
|
347841
|
+
messages: (_b8 = prepareStepResult == null ? undefined : prepareStepResult.messages) != null ? _b8 : stepInputMessages
|
|
347842
|
+
},
|
|
347843
|
+
supportedUrls: await model.supportedUrls,
|
|
347844
|
+
download: download2
|
|
347845
|
+
});
|
|
347846
|
+
const stepModel = resolveLanguageModel((_c = prepareStepResult == null ? undefined : prepareStepResult.model) != null ? _c : model);
|
|
347847
|
+
const { toolChoice: stepToolChoice, tools: stepTools } = prepareToolsAndToolChoice({
|
|
347848
|
+
tools,
|
|
347849
|
+
toolChoice: (_d = prepareStepResult == null ? undefined : prepareStepResult.toolChoice) != null ? _d : toolChoice,
|
|
347850
|
+
activeTools: (_e = prepareStepResult == null ? undefined : prepareStepResult.activeTools) != null ? _e : activeTools
|
|
347851
|
+
});
|
|
347852
|
+
currentModelResponse = await retry(() => {
|
|
347853
|
+
var _a18;
|
|
347854
|
+
return recordSpan({
|
|
347855
|
+
name: "ai.generateText.doGenerate",
|
|
347856
|
+
attributes: selectTelemetryAttributes({
|
|
347857
|
+
telemetry,
|
|
347858
|
+
attributes: {
|
|
347859
|
+
...assembleOperationName({
|
|
347860
|
+
operationId: "ai.generateText.doGenerate",
|
|
347861
|
+
telemetry
|
|
347862
|
+
}),
|
|
347863
|
+
...baseTelemetryAttributes,
|
|
347864
|
+
"ai.model.provider": stepModel.provider,
|
|
347865
|
+
"ai.model.id": stepModel.modelId,
|
|
347866
|
+
"ai.prompt.messages": {
|
|
347867
|
+
input: () => stringifyForTelemetry(promptMessages)
|
|
347868
|
+
},
|
|
347869
|
+
"ai.prompt.tools": {
|
|
347870
|
+
input: () => stepTools == null ? undefined : stepTools.map((tool3) => JSON.stringify(tool3))
|
|
347871
|
+
},
|
|
347872
|
+
"ai.prompt.toolChoice": {
|
|
347873
|
+
input: () => stepToolChoice != null ? JSON.stringify(stepToolChoice) : undefined
|
|
347874
|
+
},
|
|
347875
|
+
"gen_ai.system": stepModel.provider,
|
|
347876
|
+
"gen_ai.request.model": stepModel.modelId,
|
|
347877
|
+
"gen_ai.request.frequency_penalty": settings.frequencyPenalty,
|
|
347878
|
+
"gen_ai.request.max_tokens": settings.maxOutputTokens,
|
|
347879
|
+
"gen_ai.request.presence_penalty": settings.presencePenalty,
|
|
347880
|
+
"gen_ai.request.stop_sequences": settings.stopSequences,
|
|
347881
|
+
"gen_ai.request.temperature": (_a18 = settings.temperature) != null ? _a18 : undefined,
|
|
347882
|
+
"gen_ai.request.top_k": settings.topK,
|
|
347883
|
+
"gen_ai.request.top_p": settings.topP
|
|
347884
|
+
}
|
|
347885
|
+
}),
|
|
347886
|
+
tracer,
|
|
347887
|
+
fn: async (span2) => {
|
|
347888
|
+
var _a19, _b22, _c2, _d2, _e2, _f2, _g2, _h;
|
|
347889
|
+
const result2 = await stepModel.doGenerate({
|
|
347890
|
+
...callSettings2,
|
|
347891
|
+
tools: stepTools,
|
|
347892
|
+
toolChoice: stepToolChoice,
|
|
347893
|
+
responseFormat: output == null ? undefined : output.responseFormat,
|
|
347894
|
+
prompt: promptMessages,
|
|
347895
|
+
providerOptions,
|
|
347896
|
+
abortSignal,
|
|
347897
|
+
headers: headersWithUserAgent
|
|
347898
|
+
});
|
|
347899
|
+
const responseData = {
|
|
347900
|
+
id: (_b22 = (_a19 = result2.response) == null ? undefined : _a19.id) != null ? _b22 : generateId3(),
|
|
347901
|
+
timestamp: (_d2 = (_c2 = result2.response) == null ? undefined : _c2.timestamp) != null ? _d2 : currentDate(),
|
|
347902
|
+
modelId: (_f2 = (_e2 = result2.response) == null ? undefined : _e2.modelId) != null ? _f2 : stepModel.modelId,
|
|
347903
|
+
headers: (_g2 = result2.response) == null ? undefined : _g2.headers,
|
|
347904
|
+
body: (_h = result2.response) == null ? undefined : _h.body
|
|
347905
|
+
};
|
|
347906
|
+
span2.setAttributes(selectTelemetryAttributes({
|
|
347907
|
+
telemetry,
|
|
347908
|
+
attributes: {
|
|
347909
|
+
"ai.response.finishReason": result2.finishReason,
|
|
347910
|
+
"ai.response.text": {
|
|
347911
|
+
output: () => extractTextContent(result2.content)
|
|
347912
|
+
},
|
|
347913
|
+
"ai.response.toolCalls": {
|
|
347914
|
+
output: () => {
|
|
347915
|
+
const toolCalls = asToolCalls(result2.content);
|
|
347916
|
+
return toolCalls == null ? undefined : JSON.stringify(toolCalls);
|
|
347917
|
+
}
|
|
347918
|
+
},
|
|
347919
|
+
"ai.response.id": responseData.id,
|
|
347920
|
+
"ai.response.model": responseData.modelId,
|
|
347921
|
+
"ai.response.timestamp": responseData.timestamp.toISOString(),
|
|
347922
|
+
"ai.response.providerMetadata": JSON.stringify(result2.providerMetadata),
|
|
347923
|
+
"ai.usage.promptTokens": result2.usage.inputTokens,
|
|
347924
|
+
"ai.usage.completionTokens": result2.usage.outputTokens,
|
|
347925
|
+
"gen_ai.response.finish_reasons": [result2.finishReason],
|
|
347926
|
+
"gen_ai.response.id": responseData.id,
|
|
347927
|
+
"gen_ai.response.model": responseData.modelId,
|
|
347928
|
+
"gen_ai.usage.input_tokens": result2.usage.inputTokens,
|
|
347929
|
+
"gen_ai.usage.output_tokens": result2.usage.outputTokens
|
|
347930
|
+
}
|
|
347931
|
+
}));
|
|
347932
|
+
return { ...result2, response: responseData };
|
|
347933
|
+
}
|
|
347934
|
+
});
|
|
347935
|
+
});
|
|
347936
|
+
const stepToolCalls = await Promise.all(currentModelResponse.content.filter((part) => part.type === "tool-call").map((toolCall) => parseToolCall({
|
|
347937
|
+
toolCall,
|
|
347938
|
+
tools,
|
|
347939
|
+
repairToolCall,
|
|
347940
|
+
system,
|
|
347941
|
+
messages: stepInputMessages
|
|
347942
|
+
})));
|
|
347943
|
+
for (const toolCall of stepToolCalls) {
|
|
347944
|
+
if (toolCall.invalid) {
|
|
347945
|
+
continue;
|
|
347946
|
+
}
|
|
347947
|
+
const tool3 = tools[toolCall.toolName];
|
|
347948
|
+
if ((tool3 == null ? undefined : tool3.onInputAvailable) != null) {
|
|
347949
|
+
await tool3.onInputAvailable({
|
|
347950
|
+
input: toolCall.input,
|
|
347951
|
+
toolCallId: toolCall.toolCallId,
|
|
347952
|
+
messages: stepInputMessages,
|
|
347953
|
+
abortSignal,
|
|
347954
|
+
experimental_context
|
|
347955
|
+
});
|
|
347956
|
+
}
|
|
347957
|
+
}
|
|
347958
|
+
const invalidToolCalls = stepToolCalls.filter((toolCall) => toolCall.invalid && toolCall.dynamic);
|
|
347959
|
+
clientToolOutputs = [];
|
|
347960
|
+
for (const toolCall of invalidToolCalls) {
|
|
347961
|
+
clientToolOutputs.push({
|
|
347962
|
+
type: "tool-error",
|
|
347963
|
+
toolCallId: toolCall.toolCallId,
|
|
347964
|
+
toolName: toolCall.toolName,
|
|
347965
|
+
input: toolCall.input,
|
|
347966
|
+
error: getErrorMessage2(toolCall.error),
|
|
347967
|
+
dynamic: true
|
|
347968
|
+
});
|
|
347969
|
+
}
|
|
347970
|
+
clientToolCalls = stepToolCalls.filter((toolCall) => !toolCall.providerExecuted);
|
|
347971
|
+
if (tools != null) {
|
|
347972
|
+
clientToolOutputs.push(...await executeTools({
|
|
347973
|
+
toolCalls: clientToolCalls.filter((toolCall) => !toolCall.invalid),
|
|
347974
|
+
tools,
|
|
347975
|
+
tracer,
|
|
347976
|
+
telemetry,
|
|
347977
|
+
messages: stepInputMessages,
|
|
347978
|
+
abortSignal,
|
|
347979
|
+
experimental_context
|
|
347980
|
+
}));
|
|
347981
|
+
}
|
|
347982
|
+
const stepContent = asContent({
|
|
347983
|
+
content: currentModelResponse.content,
|
|
347984
|
+
toolCalls: stepToolCalls,
|
|
347985
|
+
toolOutputs: clientToolOutputs
|
|
347986
|
+
});
|
|
347987
|
+
responseMessages.push(...toResponseMessages({
|
|
347988
|
+
content: stepContent,
|
|
347989
|
+
tools
|
|
347990
|
+
}));
|
|
347991
|
+
const currentStepResult = new DefaultStepResult({
|
|
347992
|
+
content: stepContent,
|
|
347993
|
+
finishReason: currentModelResponse.finishReason,
|
|
347994
|
+
usage: currentModelResponse.usage,
|
|
347995
|
+
warnings: currentModelResponse.warnings,
|
|
347996
|
+
providerMetadata: currentModelResponse.providerMetadata,
|
|
347997
|
+
request: (_f = currentModelResponse.request) != null ? _f : {},
|
|
347998
|
+
response: {
|
|
347999
|
+
...currentModelResponse.response,
|
|
348000
|
+
messages: structuredClone(responseMessages)
|
|
348001
|
+
}
|
|
348002
|
+
});
|
|
348003
|
+
logWarnings((_g = currentModelResponse.warnings) != null ? _g : []);
|
|
348004
|
+
steps.push(currentStepResult);
|
|
348005
|
+
await (onStepFinish == null ? undefined : onStepFinish(currentStepResult));
|
|
348006
|
+
} while (clientToolCalls.length > 0 && clientToolOutputs.length === clientToolCalls.length && !await isStopConditionMet({ stopConditions, steps }));
|
|
348007
|
+
span.setAttributes(selectTelemetryAttributes({
|
|
348008
|
+
telemetry,
|
|
348009
|
+
attributes: {
|
|
348010
|
+
"ai.response.finishReason": currentModelResponse.finishReason,
|
|
348011
|
+
"ai.response.text": {
|
|
348012
|
+
output: () => extractTextContent(currentModelResponse.content)
|
|
348013
|
+
},
|
|
348014
|
+
"ai.response.toolCalls": {
|
|
348015
|
+
output: () => {
|
|
348016
|
+
const toolCalls = asToolCalls(currentModelResponse.content);
|
|
348017
|
+
return toolCalls == null ? undefined : JSON.stringify(toolCalls);
|
|
348018
|
+
}
|
|
348019
|
+
},
|
|
348020
|
+
"ai.response.providerMetadata": JSON.stringify(currentModelResponse.providerMetadata),
|
|
348021
|
+
"ai.usage.promptTokens": currentModelResponse.usage.inputTokens,
|
|
348022
|
+
"ai.usage.completionTokens": currentModelResponse.usage.outputTokens
|
|
348023
|
+
}
|
|
348024
|
+
}));
|
|
348025
|
+
const lastStep = steps[steps.length - 1];
|
|
348026
|
+
return new DefaultGenerateTextResult({
|
|
348027
|
+
steps,
|
|
348028
|
+
resolvedOutput: await (output == null ? undefined : output.parseOutput({ text: lastStep.text }, {
|
|
348029
|
+
response: lastStep.response,
|
|
348030
|
+
usage: lastStep.usage,
|
|
348031
|
+
finishReason: lastStep.finishReason
|
|
348032
|
+
}))
|
|
348033
|
+
});
|
|
348034
|
+
}
|
|
348035
|
+
});
|
|
348036
|
+
} catch (error40) {
|
|
348037
|
+
throw wrapGatewayError(error40);
|
|
348038
|
+
}
|
|
348039
|
+
}
|
|
348040
|
+
async function executeTools({
|
|
348041
|
+
toolCalls,
|
|
348042
|
+
tools,
|
|
348043
|
+
tracer,
|
|
348044
|
+
telemetry,
|
|
348045
|
+
messages,
|
|
348046
|
+
abortSignal,
|
|
348047
|
+
experimental_context
|
|
348048
|
+
}) {
|
|
348049
|
+
const toolOutputs = await Promise.all(toolCalls.map(async ({ toolCallId, toolName, input }) => {
|
|
348050
|
+
const tool3 = tools[toolName];
|
|
348051
|
+
if ((tool3 == null ? undefined : tool3.execute) == null) {
|
|
348052
|
+
return;
|
|
348053
|
+
}
|
|
348054
|
+
return recordSpan({
|
|
348055
|
+
name: "ai.toolCall",
|
|
348056
|
+
attributes: selectTelemetryAttributes({
|
|
348057
|
+
telemetry,
|
|
348058
|
+
attributes: {
|
|
348059
|
+
...assembleOperationName({
|
|
348060
|
+
operationId: "ai.toolCall",
|
|
348061
|
+
telemetry
|
|
348062
|
+
}),
|
|
348063
|
+
"ai.toolCall.name": toolName,
|
|
348064
|
+
"ai.toolCall.id": toolCallId,
|
|
348065
|
+
"ai.toolCall.args": {
|
|
348066
|
+
output: () => JSON.stringify(input)
|
|
348067
|
+
}
|
|
348068
|
+
}
|
|
348069
|
+
}),
|
|
348070
|
+
tracer,
|
|
348071
|
+
fn: async (span) => {
|
|
348072
|
+
try {
|
|
348073
|
+
const stream = executeTool({
|
|
348074
|
+
execute: tool3.execute.bind(tool3),
|
|
348075
|
+
input,
|
|
348076
|
+
options: {
|
|
348077
|
+
toolCallId,
|
|
348078
|
+
messages,
|
|
348079
|
+
abortSignal,
|
|
348080
|
+
experimental_context
|
|
348081
|
+
}
|
|
348082
|
+
});
|
|
348083
|
+
let output;
|
|
348084
|
+
for await (const part of stream) {
|
|
348085
|
+
if (part.type === "final") {
|
|
348086
|
+
output = part.output;
|
|
348087
|
+
}
|
|
348088
|
+
}
|
|
348089
|
+
try {
|
|
348090
|
+
span.setAttributes(selectTelemetryAttributes({
|
|
348091
|
+
telemetry,
|
|
348092
|
+
attributes: {
|
|
348093
|
+
"ai.toolCall.result": {
|
|
348094
|
+
output: () => JSON.stringify(output)
|
|
348095
|
+
}
|
|
348096
|
+
}
|
|
348097
|
+
}));
|
|
348098
|
+
} catch (ignored) {}
|
|
348099
|
+
return {
|
|
348100
|
+
type: "tool-result",
|
|
348101
|
+
toolCallId,
|
|
348102
|
+
toolName,
|
|
348103
|
+
input,
|
|
348104
|
+
output,
|
|
348105
|
+
dynamic: tool3.type === "dynamic"
|
|
348106
|
+
};
|
|
348107
|
+
} catch (error40) {
|
|
348108
|
+
recordErrorOnSpan(span, error40);
|
|
348109
|
+
return {
|
|
348110
|
+
type: "tool-error",
|
|
348111
|
+
toolCallId,
|
|
348112
|
+
toolName,
|
|
348113
|
+
input,
|
|
348114
|
+
error: error40,
|
|
348115
|
+
dynamic: tool3.type === "dynamic"
|
|
348116
|
+
};
|
|
348117
|
+
}
|
|
348118
|
+
}
|
|
348119
|
+
});
|
|
348120
|
+
}));
|
|
348121
|
+
return toolOutputs.filter((output) => output != null);
|
|
348122
|
+
}
|
|
348123
|
+
var DefaultGenerateTextResult = class {
|
|
348124
|
+
constructor(options) {
|
|
348125
|
+
this.steps = options.steps;
|
|
348126
|
+
this.resolvedOutput = options.resolvedOutput;
|
|
348127
|
+
}
|
|
348128
|
+
get finalStep() {
|
|
348129
|
+
return this.steps[this.steps.length - 1];
|
|
348130
|
+
}
|
|
348131
|
+
get content() {
|
|
348132
|
+
return this.finalStep.content;
|
|
348133
|
+
}
|
|
348134
|
+
get text() {
|
|
348135
|
+
return this.finalStep.text;
|
|
348136
|
+
}
|
|
348137
|
+
get files() {
|
|
348138
|
+
return this.finalStep.files;
|
|
348139
|
+
}
|
|
348140
|
+
get reasoningText() {
|
|
348141
|
+
return this.finalStep.reasoningText;
|
|
348142
|
+
}
|
|
348143
|
+
get reasoning() {
|
|
348144
|
+
return this.finalStep.reasoning;
|
|
348145
|
+
}
|
|
348146
|
+
get toolCalls() {
|
|
348147
|
+
return this.finalStep.toolCalls;
|
|
348148
|
+
}
|
|
348149
|
+
get staticToolCalls() {
|
|
348150
|
+
return this.finalStep.staticToolCalls;
|
|
348151
|
+
}
|
|
348152
|
+
get dynamicToolCalls() {
|
|
348153
|
+
return this.finalStep.dynamicToolCalls;
|
|
348154
|
+
}
|
|
348155
|
+
get toolResults() {
|
|
348156
|
+
return this.finalStep.toolResults;
|
|
348157
|
+
}
|
|
348158
|
+
get staticToolResults() {
|
|
348159
|
+
return this.finalStep.staticToolResults;
|
|
348160
|
+
}
|
|
348161
|
+
get dynamicToolResults() {
|
|
348162
|
+
return this.finalStep.dynamicToolResults;
|
|
348163
|
+
}
|
|
348164
|
+
get sources() {
|
|
348165
|
+
return this.finalStep.sources;
|
|
348166
|
+
}
|
|
348167
|
+
get finishReason() {
|
|
348168
|
+
return this.finalStep.finishReason;
|
|
348169
|
+
}
|
|
348170
|
+
get warnings() {
|
|
348171
|
+
return this.finalStep.warnings;
|
|
348172
|
+
}
|
|
348173
|
+
get providerMetadata() {
|
|
348174
|
+
return this.finalStep.providerMetadata;
|
|
348175
|
+
}
|
|
348176
|
+
get response() {
|
|
348177
|
+
return this.finalStep.response;
|
|
348178
|
+
}
|
|
348179
|
+
get request() {
|
|
348180
|
+
return this.finalStep.request;
|
|
348181
|
+
}
|
|
348182
|
+
get usage() {
|
|
348183
|
+
return this.finalStep.usage;
|
|
348184
|
+
}
|
|
348185
|
+
get totalUsage() {
|
|
348186
|
+
return this.steps.reduce((totalUsage, step) => {
|
|
348187
|
+
return addLanguageModelUsage(totalUsage, step.usage);
|
|
348188
|
+
}, {
|
|
348189
|
+
inputTokens: undefined,
|
|
348190
|
+
outputTokens: undefined,
|
|
348191
|
+
totalTokens: undefined,
|
|
348192
|
+
reasoningTokens: undefined,
|
|
348193
|
+
cachedInputTokens: undefined
|
|
348194
|
+
});
|
|
348195
|
+
}
|
|
348196
|
+
get experimental_output() {
|
|
348197
|
+
if (this.resolvedOutput == null) {
|
|
348198
|
+
throw new NoOutputSpecifiedError;
|
|
348199
|
+
}
|
|
348200
|
+
return this.resolvedOutput;
|
|
348201
|
+
}
|
|
348202
|
+
};
|
|
348203
|
+
function asToolCalls(content) {
|
|
348204
|
+
const parts = content.filter((part) => part.type === "tool-call");
|
|
348205
|
+
if (parts.length === 0) {
|
|
348206
|
+
return;
|
|
348207
|
+
}
|
|
348208
|
+
return parts.map((toolCall) => ({
|
|
348209
|
+
toolCallId: toolCall.toolCallId,
|
|
348210
|
+
toolName: toolCall.toolName,
|
|
348211
|
+
input: toolCall.input
|
|
348212
|
+
}));
|
|
348213
|
+
}
|
|
348214
|
+
function asContent({
|
|
348215
|
+
content,
|
|
348216
|
+
toolCalls,
|
|
348217
|
+
toolOutputs
|
|
348218
|
+
}) {
|
|
348219
|
+
return [
|
|
348220
|
+
...content.map((part) => {
|
|
348221
|
+
switch (part.type) {
|
|
348222
|
+
case "text":
|
|
348223
|
+
case "reasoning":
|
|
348224
|
+
case "source":
|
|
348225
|
+
return part;
|
|
348226
|
+
case "file": {
|
|
348227
|
+
return {
|
|
348228
|
+
type: "file",
|
|
348229
|
+
file: new DefaultGeneratedFile(part)
|
|
348230
|
+
};
|
|
348231
|
+
}
|
|
348232
|
+
case "tool-call": {
|
|
348233
|
+
return toolCalls.find((toolCall) => toolCall.toolCallId === part.toolCallId);
|
|
348234
|
+
}
|
|
348235
|
+
case "tool-result": {
|
|
348236
|
+
const toolCall = toolCalls.find((toolCall2) => toolCall2.toolCallId === part.toolCallId);
|
|
348237
|
+
if (toolCall == null) {
|
|
348238
|
+
throw new Error(`Tool call ${part.toolCallId} not found.`);
|
|
348239
|
+
}
|
|
348240
|
+
if (part.isError) {
|
|
348241
|
+
return {
|
|
348242
|
+
type: "tool-error",
|
|
348243
|
+
toolCallId: part.toolCallId,
|
|
348244
|
+
toolName: part.toolName,
|
|
348245
|
+
input: toolCall.input,
|
|
348246
|
+
error: part.result,
|
|
348247
|
+
providerExecuted: true,
|
|
348248
|
+
dynamic: toolCall.dynamic
|
|
348249
|
+
};
|
|
348250
|
+
}
|
|
348251
|
+
return {
|
|
348252
|
+
type: "tool-result",
|
|
348253
|
+
toolCallId: part.toolCallId,
|
|
348254
|
+
toolName: part.toolName,
|
|
348255
|
+
input: toolCall.input,
|
|
348256
|
+
output: part.result,
|
|
348257
|
+
providerExecuted: true,
|
|
348258
|
+
dynamic: toolCall.dynamic
|
|
348259
|
+
};
|
|
348260
|
+
}
|
|
348261
|
+
}
|
|
348262
|
+
}),
|
|
348263
|
+
...toolOutputs
|
|
348264
|
+
];
|
|
348265
|
+
}
|
|
347727
348266
|
function prepareHeaders(headers, defaultHeaders) {
|
|
347728
348267
|
const responseHeaders = new Headers(headers != null ? headers : {});
|
|
347729
348268
|
for (const [key, value2] of Object.entries(defaultHeaders)) {
|
|
@@ -350721,7 +351260,651 @@ function convertToModelMessages(messages, options) {
|
|
|
350721
351260
|
}
|
|
350722
351261
|
return modelMessages;
|
|
350723
351262
|
}
|
|
351263
|
+
function extractReasoningContent(content) {
|
|
351264
|
+
const parts = content.filter((content2) => content2.type === "reasoning");
|
|
351265
|
+
return parts.length === 0 ? undefined : parts.map((content2) => content2.text).join(`
|
|
351266
|
+
`);
|
|
351267
|
+
}
|
|
351268
|
+
var noSchemaOutputStrategy = {
|
|
351269
|
+
type: "no-schema",
|
|
351270
|
+
jsonSchema: undefined,
|
|
351271
|
+
async validatePartialResult({ value: value2, textDelta }) {
|
|
351272
|
+
return { success: true, value: { partial: value2, textDelta } };
|
|
351273
|
+
},
|
|
351274
|
+
async validateFinalResult(value2, context) {
|
|
351275
|
+
return value2 === undefined ? {
|
|
351276
|
+
success: false,
|
|
351277
|
+
error: new NoObjectGeneratedError({
|
|
351278
|
+
message: "No object generated: response did not match schema.",
|
|
351279
|
+
text: context.text,
|
|
351280
|
+
response: context.response,
|
|
351281
|
+
usage: context.usage,
|
|
351282
|
+
finishReason: context.finishReason
|
|
351283
|
+
})
|
|
351284
|
+
} : { success: true, value: value2 };
|
|
351285
|
+
},
|
|
351286
|
+
createElementStream() {
|
|
351287
|
+
throw new UnsupportedFunctionalityError({
|
|
351288
|
+
functionality: "element streams in no-schema mode"
|
|
351289
|
+
});
|
|
351290
|
+
}
|
|
351291
|
+
};
|
|
351292
|
+
var objectOutputStrategy = (schema) => ({
|
|
351293
|
+
type: "object",
|
|
351294
|
+
jsonSchema: schema.jsonSchema,
|
|
351295
|
+
async validatePartialResult({ value: value2, textDelta }) {
|
|
351296
|
+
return {
|
|
351297
|
+
success: true,
|
|
351298
|
+
value: {
|
|
351299
|
+
partial: value2,
|
|
351300
|
+
textDelta
|
|
351301
|
+
}
|
|
351302
|
+
};
|
|
351303
|
+
},
|
|
351304
|
+
async validateFinalResult(value2) {
|
|
351305
|
+
return safeValidateTypes({ value: value2, schema });
|
|
351306
|
+
},
|
|
351307
|
+
createElementStream() {
|
|
351308
|
+
throw new UnsupportedFunctionalityError({
|
|
351309
|
+
functionality: "element streams in object mode"
|
|
351310
|
+
});
|
|
351311
|
+
}
|
|
351312
|
+
});
|
|
351313
|
+
var arrayOutputStrategy = (schema) => {
|
|
351314
|
+
const { $schema, ...itemSchema } = schema.jsonSchema;
|
|
351315
|
+
return {
|
|
351316
|
+
type: "enum",
|
|
351317
|
+
jsonSchema: {
|
|
351318
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
351319
|
+
type: "object",
|
|
351320
|
+
properties: {
|
|
351321
|
+
elements: { type: "array", items: itemSchema }
|
|
351322
|
+
},
|
|
351323
|
+
required: ["elements"],
|
|
351324
|
+
additionalProperties: false
|
|
351325
|
+
},
|
|
351326
|
+
async validatePartialResult({
|
|
351327
|
+
value: value2,
|
|
351328
|
+
latestObject,
|
|
351329
|
+
isFirstDelta,
|
|
351330
|
+
isFinalDelta
|
|
351331
|
+
}) {
|
|
351332
|
+
var _a172;
|
|
351333
|
+
if (!isJSONObject(value2) || !isJSONArray(value2.elements)) {
|
|
351334
|
+
return {
|
|
351335
|
+
success: false,
|
|
351336
|
+
error: new TypeValidationError({
|
|
351337
|
+
value: value2,
|
|
351338
|
+
cause: "value must be an object that contains an array of elements"
|
|
351339
|
+
})
|
|
351340
|
+
};
|
|
351341
|
+
}
|
|
351342
|
+
const inputArray = value2.elements;
|
|
351343
|
+
const resultArray = [];
|
|
351344
|
+
for (let i6 = 0;i6 < inputArray.length; i6++) {
|
|
351345
|
+
const element = inputArray[i6];
|
|
351346
|
+
const result2 = await safeValidateTypes({ value: element, schema });
|
|
351347
|
+
if (i6 === inputArray.length - 1 && !isFinalDelta) {
|
|
351348
|
+
continue;
|
|
351349
|
+
}
|
|
351350
|
+
if (!result2.success) {
|
|
351351
|
+
return result2;
|
|
351352
|
+
}
|
|
351353
|
+
resultArray.push(result2.value);
|
|
351354
|
+
}
|
|
351355
|
+
const publishedElementCount = (_a172 = latestObject == null ? undefined : latestObject.length) != null ? _a172 : 0;
|
|
351356
|
+
let textDelta = "";
|
|
351357
|
+
if (isFirstDelta) {
|
|
351358
|
+
textDelta += "[";
|
|
351359
|
+
}
|
|
351360
|
+
if (publishedElementCount > 0) {
|
|
351361
|
+
textDelta += ",";
|
|
351362
|
+
}
|
|
351363
|
+
textDelta += resultArray.slice(publishedElementCount).map((element) => JSON.stringify(element)).join(",");
|
|
351364
|
+
if (isFinalDelta) {
|
|
351365
|
+
textDelta += "]";
|
|
351366
|
+
}
|
|
351367
|
+
return {
|
|
351368
|
+
success: true,
|
|
351369
|
+
value: {
|
|
351370
|
+
partial: resultArray,
|
|
351371
|
+
textDelta
|
|
351372
|
+
}
|
|
351373
|
+
};
|
|
351374
|
+
},
|
|
351375
|
+
async validateFinalResult(value2) {
|
|
351376
|
+
if (!isJSONObject(value2) || !isJSONArray(value2.elements)) {
|
|
351377
|
+
return {
|
|
351378
|
+
success: false,
|
|
351379
|
+
error: new TypeValidationError({
|
|
351380
|
+
value: value2,
|
|
351381
|
+
cause: "value must be an object that contains an array of elements"
|
|
351382
|
+
})
|
|
351383
|
+
};
|
|
351384
|
+
}
|
|
351385
|
+
const inputArray = value2.elements;
|
|
351386
|
+
for (const element of inputArray) {
|
|
351387
|
+
const result2 = await safeValidateTypes({ value: element, schema });
|
|
351388
|
+
if (!result2.success) {
|
|
351389
|
+
return result2;
|
|
351390
|
+
}
|
|
351391
|
+
}
|
|
351392
|
+
return { success: true, value: inputArray };
|
|
351393
|
+
},
|
|
351394
|
+
createElementStream(originalStream) {
|
|
351395
|
+
let publishedElements = 0;
|
|
351396
|
+
return createAsyncIterableStream(originalStream.pipeThrough(new TransformStream({
|
|
351397
|
+
transform(chunk, controller) {
|
|
351398
|
+
switch (chunk.type) {
|
|
351399
|
+
case "object": {
|
|
351400
|
+
const array2 = chunk.object;
|
|
351401
|
+
for (;publishedElements < array2.length; publishedElements++) {
|
|
351402
|
+
controller.enqueue(array2[publishedElements]);
|
|
351403
|
+
}
|
|
351404
|
+
break;
|
|
351405
|
+
}
|
|
351406
|
+
case "text-delta":
|
|
351407
|
+
case "finish":
|
|
351408
|
+
case "error":
|
|
351409
|
+
break;
|
|
351410
|
+
default: {
|
|
351411
|
+
const _exhaustiveCheck = chunk;
|
|
351412
|
+
throw new Error(`Unsupported chunk type: ${_exhaustiveCheck}`);
|
|
351413
|
+
}
|
|
351414
|
+
}
|
|
351415
|
+
}
|
|
351416
|
+
})));
|
|
351417
|
+
}
|
|
351418
|
+
};
|
|
351419
|
+
};
|
|
351420
|
+
var enumOutputStrategy = (enumValues) => {
|
|
351421
|
+
return {
|
|
351422
|
+
type: "enum",
|
|
351423
|
+
jsonSchema: {
|
|
351424
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
351425
|
+
type: "object",
|
|
351426
|
+
properties: {
|
|
351427
|
+
result: { type: "string", enum: enumValues }
|
|
351428
|
+
},
|
|
351429
|
+
required: ["result"],
|
|
351430
|
+
additionalProperties: false
|
|
351431
|
+
},
|
|
351432
|
+
async validateFinalResult(value2) {
|
|
351433
|
+
if (!isJSONObject(value2) || typeof value2.result !== "string") {
|
|
351434
|
+
return {
|
|
351435
|
+
success: false,
|
|
351436
|
+
error: new TypeValidationError({
|
|
351437
|
+
value: value2,
|
|
351438
|
+
cause: 'value must be an object that contains a string in the "result" property.'
|
|
351439
|
+
})
|
|
351440
|
+
};
|
|
351441
|
+
}
|
|
351442
|
+
const result2 = value2.result;
|
|
351443
|
+
return enumValues.includes(result2) ? { success: true, value: result2 } : {
|
|
351444
|
+
success: false,
|
|
351445
|
+
error: new TypeValidationError({
|
|
351446
|
+
value: value2,
|
|
351447
|
+
cause: "value must be a string in the enum"
|
|
351448
|
+
})
|
|
351449
|
+
};
|
|
351450
|
+
},
|
|
351451
|
+
async validatePartialResult({ value: value2, textDelta }) {
|
|
351452
|
+
if (!isJSONObject(value2) || typeof value2.result !== "string") {
|
|
351453
|
+
return {
|
|
351454
|
+
success: false,
|
|
351455
|
+
error: new TypeValidationError({
|
|
351456
|
+
value: value2,
|
|
351457
|
+
cause: 'value must be an object that contains a string in the "result" property.'
|
|
351458
|
+
})
|
|
351459
|
+
};
|
|
351460
|
+
}
|
|
351461
|
+
const result2 = value2.result;
|
|
351462
|
+
const possibleEnumValues = enumValues.filter((enumValue) => enumValue.startsWith(result2));
|
|
351463
|
+
if (value2.result.length === 0 || possibleEnumValues.length === 0) {
|
|
351464
|
+
return {
|
|
351465
|
+
success: false,
|
|
351466
|
+
error: new TypeValidationError({
|
|
351467
|
+
value: value2,
|
|
351468
|
+
cause: "value must be a string in the enum"
|
|
351469
|
+
})
|
|
351470
|
+
};
|
|
351471
|
+
}
|
|
351472
|
+
return {
|
|
351473
|
+
success: true,
|
|
351474
|
+
value: {
|
|
351475
|
+
partial: possibleEnumValues.length > 1 ? result2 : possibleEnumValues[0],
|
|
351476
|
+
textDelta
|
|
351477
|
+
}
|
|
351478
|
+
};
|
|
351479
|
+
},
|
|
351480
|
+
createElementStream() {
|
|
351481
|
+
throw new UnsupportedFunctionalityError({
|
|
351482
|
+
functionality: "element streams in enum mode"
|
|
351483
|
+
});
|
|
351484
|
+
}
|
|
351485
|
+
};
|
|
351486
|
+
};
|
|
351487
|
+
function getOutputStrategy({
|
|
351488
|
+
output,
|
|
351489
|
+
schema,
|
|
351490
|
+
enumValues
|
|
351491
|
+
}) {
|
|
351492
|
+
switch (output) {
|
|
351493
|
+
case "object":
|
|
351494
|
+
return objectOutputStrategy(asSchema(schema));
|
|
351495
|
+
case "array":
|
|
351496
|
+
return arrayOutputStrategy(asSchema(schema));
|
|
351497
|
+
case "enum":
|
|
351498
|
+
return enumOutputStrategy(enumValues);
|
|
351499
|
+
case "no-schema":
|
|
351500
|
+
return noSchemaOutputStrategy;
|
|
351501
|
+
default: {
|
|
351502
|
+
const _exhaustiveCheck = output;
|
|
351503
|
+
throw new Error(`Unsupported output: ${_exhaustiveCheck}`);
|
|
351504
|
+
}
|
|
351505
|
+
}
|
|
351506
|
+
}
|
|
351507
|
+
async function parseAndValidateObjectResult(result2, outputStrategy, context) {
|
|
351508
|
+
const parseResult = await safeParseJSON({ text: result2 });
|
|
351509
|
+
if (!parseResult.success) {
|
|
351510
|
+
throw new NoObjectGeneratedError({
|
|
351511
|
+
message: "No object generated: could not parse the response.",
|
|
351512
|
+
cause: parseResult.error,
|
|
351513
|
+
text: result2,
|
|
351514
|
+
response: context.response,
|
|
351515
|
+
usage: context.usage,
|
|
351516
|
+
finishReason: context.finishReason
|
|
351517
|
+
});
|
|
351518
|
+
}
|
|
351519
|
+
const validationResult = await outputStrategy.validateFinalResult(parseResult.value, {
|
|
351520
|
+
text: result2,
|
|
351521
|
+
response: context.response,
|
|
351522
|
+
usage: context.usage
|
|
351523
|
+
});
|
|
351524
|
+
if (!validationResult.success) {
|
|
351525
|
+
throw new NoObjectGeneratedError({
|
|
351526
|
+
message: "No object generated: response did not match schema.",
|
|
351527
|
+
cause: validationResult.error,
|
|
351528
|
+
text: result2,
|
|
351529
|
+
response: context.response,
|
|
351530
|
+
usage: context.usage,
|
|
351531
|
+
finishReason: context.finishReason
|
|
351532
|
+
});
|
|
351533
|
+
}
|
|
351534
|
+
return validationResult.value;
|
|
351535
|
+
}
|
|
351536
|
+
async function parseAndValidateObjectResultWithRepair(result2, outputStrategy, repairText, context) {
|
|
351537
|
+
try {
|
|
351538
|
+
return await parseAndValidateObjectResult(result2, outputStrategy, context);
|
|
351539
|
+
} catch (error40) {
|
|
351540
|
+
if (repairText != null && NoObjectGeneratedError.isInstance(error40) && (JSONParseError.isInstance(error40.cause) || TypeValidationError.isInstance(error40.cause))) {
|
|
351541
|
+
const repairedText = await repairText({
|
|
351542
|
+
text: result2,
|
|
351543
|
+
error: error40.cause
|
|
351544
|
+
});
|
|
351545
|
+
if (repairedText === null) {
|
|
351546
|
+
throw error40;
|
|
351547
|
+
}
|
|
351548
|
+
return await parseAndValidateObjectResult(repairedText, outputStrategy, context);
|
|
351549
|
+
}
|
|
351550
|
+
throw error40;
|
|
351551
|
+
}
|
|
351552
|
+
}
|
|
351553
|
+
function validateObjectGenerationInput({
|
|
351554
|
+
output,
|
|
351555
|
+
schema,
|
|
351556
|
+
schemaName,
|
|
351557
|
+
schemaDescription,
|
|
351558
|
+
enumValues
|
|
351559
|
+
}) {
|
|
351560
|
+
if (output != null && output !== "object" && output !== "array" && output !== "enum" && output !== "no-schema") {
|
|
351561
|
+
throw new InvalidArgumentError2({
|
|
351562
|
+
parameter: "output",
|
|
351563
|
+
value: output,
|
|
351564
|
+
message: "Invalid output type."
|
|
351565
|
+
});
|
|
351566
|
+
}
|
|
351567
|
+
if (output === "no-schema") {
|
|
351568
|
+
if (schema != null) {
|
|
351569
|
+
throw new InvalidArgumentError2({
|
|
351570
|
+
parameter: "schema",
|
|
351571
|
+
value: schema,
|
|
351572
|
+
message: "Schema is not supported for no-schema output."
|
|
351573
|
+
});
|
|
351574
|
+
}
|
|
351575
|
+
if (schemaDescription != null) {
|
|
351576
|
+
throw new InvalidArgumentError2({
|
|
351577
|
+
parameter: "schemaDescription",
|
|
351578
|
+
value: schemaDescription,
|
|
351579
|
+
message: "Schema description is not supported for no-schema output."
|
|
351580
|
+
});
|
|
351581
|
+
}
|
|
351582
|
+
if (schemaName != null) {
|
|
351583
|
+
throw new InvalidArgumentError2({
|
|
351584
|
+
parameter: "schemaName",
|
|
351585
|
+
value: schemaName,
|
|
351586
|
+
message: "Schema name is not supported for no-schema output."
|
|
351587
|
+
});
|
|
351588
|
+
}
|
|
351589
|
+
if (enumValues != null) {
|
|
351590
|
+
throw new InvalidArgumentError2({
|
|
351591
|
+
parameter: "enumValues",
|
|
351592
|
+
value: enumValues,
|
|
351593
|
+
message: "Enum values are not supported for no-schema output."
|
|
351594
|
+
});
|
|
351595
|
+
}
|
|
351596
|
+
}
|
|
351597
|
+
if (output === "object") {
|
|
351598
|
+
if (schema == null) {
|
|
351599
|
+
throw new InvalidArgumentError2({
|
|
351600
|
+
parameter: "schema",
|
|
351601
|
+
value: schema,
|
|
351602
|
+
message: "Schema is required for object output."
|
|
351603
|
+
});
|
|
351604
|
+
}
|
|
351605
|
+
if (enumValues != null) {
|
|
351606
|
+
throw new InvalidArgumentError2({
|
|
351607
|
+
parameter: "enumValues",
|
|
351608
|
+
value: enumValues,
|
|
351609
|
+
message: "Enum values are not supported for object output."
|
|
351610
|
+
});
|
|
351611
|
+
}
|
|
351612
|
+
}
|
|
351613
|
+
if (output === "array") {
|
|
351614
|
+
if (schema == null) {
|
|
351615
|
+
throw new InvalidArgumentError2({
|
|
351616
|
+
parameter: "schema",
|
|
351617
|
+
value: schema,
|
|
351618
|
+
message: "Element schema is required for array output."
|
|
351619
|
+
});
|
|
351620
|
+
}
|
|
351621
|
+
if (enumValues != null) {
|
|
351622
|
+
throw new InvalidArgumentError2({
|
|
351623
|
+
parameter: "enumValues",
|
|
351624
|
+
value: enumValues,
|
|
351625
|
+
message: "Enum values are not supported for array output."
|
|
351626
|
+
});
|
|
351627
|
+
}
|
|
351628
|
+
}
|
|
351629
|
+
if (output === "enum") {
|
|
351630
|
+
if (schema != null) {
|
|
351631
|
+
throw new InvalidArgumentError2({
|
|
351632
|
+
parameter: "schema",
|
|
351633
|
+
value: schema,
|
|
351634
|
+
message: "Schema is not supported for enum output."
|
|
351635
|
+
});
|
|
351636
|
+
}
|
|
351637
|
+
if (schemaDescription != null) {
|
|
351638
|
+
throw new InvalidArgumentError2({
|
|
351639
|
+
parameter: "schemaDescription",
|
|
351640
|
+
value: schemaDescription,
|
|
351641
|
+
message: "Schema description is not supported for enum output."
|
|
351642
|
+
});
|
|
351643
|
+
}
|
|
351644
|
+
if (schemaName != null) {
|
|
351645
|
+
throw new InvalidArgumentError2({
|
|
351646
|
+
parameter: "schemaName",
|
|
351647
|
+
value: schemaName,
|
|
351648
|
+
message: "Schema name is not supported for enum output."
|
|
351649
|
+
});
|
|
351650
|
+
}
|
|
351651
|
+
if (enumValues == null) {
|
|
351652
|
+
throw new InvalidArgumentError2({
|
|
351653
|
+
parameter: "enumValues",
|
|
351654
|
+
value: enumValues,
|
|
351655
|
+
message: "Enum values are required for enum output."
|
|
351656
|
+
});
|
|
351657
|
+
}
|
|
351658
|
+
for (const value2 of enumValues) {
|
|
351659
|
+
if (typeof value2 !== "string") {
|
|
351660
|
+
throw new InvalidArgumentError2({
|
|
351661
|
+
parameter: "enumValues",
|
|
351662
|
+
value: value2,
|
|
351663
|
+
message: "Enum values must be strings."
|
|
351664
|
+
});
|
|
351665
|
+
}
|
|
351666
|
+
}
|
|
351667
|
+
}
|
|
351668
|
+
}
|
|
350724
351669
|
var originalGenerateId3 = createIdGenerator({ prefix: "aiobj", size: 24 });
|
|
351670
|
+
async function generateObject(options) {
|
|
351671
|
+
const {
|
|
351672
|
+
model: modelArg,
|
|
351673
|
+
output = "object",
|
|
351674
|
+
system,
|
|
351675
|
+
prompt,
|
|
351676
|
+
messages,
|
|
351677
|
+
maxRetries: maxRetriesArg,
|
|
351678
|
+
abortSignal,
|
|
351679
|
+
headers,
|
|
351680
|
+
experimental_repairText: repairText,
|
|
351681
|
+
experimental_telemetry: telemetry,
|
|
351682
|
+
experimental_download: download2,
|
|
351683
|
+
providerOptions,
|
|
351684
|
+
_internal: {
|
|
351685
|
+
generateId: generateId3 = originalGenerateId3,
|
|
351686
|
+
currentDate = () => /* @__PURE__ */ new Date
|
|
351687
|
+
} = {},
|
|
351688
|
+
...settings
|
|
351689
|
+
} = options;
|
|
351690
|
+
const model = resolveLanguageModel(modelArg);
|
|
351691
|
+
const enumValues = "enum" in options ? options.enum : undefined;
|
|
351692
|
+
const {
|
|
351693
|
+
schema: inputSchema,
|
|
351694
|
+
schemaDescription,
|
|
351695
|
+
schemaName
|
|
351696
|
+
} = "schema" in options ? options : {};
|
|
351697
|
+
validateObjectGenerationInput({
|
|
351698
|
+
output,
|
|
351699
|
+
schema: inputSchema,
|
|
351700
|
+
schemaName,
|
|
351701
|
+
schemaDescription,
|
|
351702
|
+
enumValues
|
|
351703
|
+
});
|
|
351704
|
+
const { maxRetries, retry } = prepareRetries({
|
|
351705
|
+
maxRetries: maxRetriesArg,
|
|
351706
|
+
abortSignal
|
|
351707
|
+
});
|
|
351708
|
+
const outputStrategy = getOutputStrategy({
|
|
351709
|
+
output,
|
|
351710
|
+
schema: inputSchema,
|
|
351711
|
+
enumValues
|
|
351712
|
+
});
|
|
351713
|
+
const callSettings = prepareCallSettings(settings);
|
|
351714
|
+
const headersWithUserAgent = withUserAgentSuffix(headers != null ? headers : {}, `ai/${VERSION3}`);
|
|
351715
|
+
const baseTelemetryAttributes = getBaseTelemetryAttributes({
|
|
351716
|
+
model,
|
|
351717
|
+
telemetry,
|
|
351718
|
+
headers: headersWithUserAgent,
|
|
351719
|
+
settings: { ...callSettings, maxRetries }
|
|
351720
|
+
});
|
|
351721
|
+
const tracer = getTracer(telemetry);
|
|
351722
|
+
try {
|
|
351723
|
+
return await recordSpan({
|
|
351724
|
+
name: "ai.generateObject",
|
|
351725
|
+
attributes: selectTelemetryAttributes({
|
|
351726
|
+
telemetry,
|
|
351727
|
+
attributes: {
|
|
351728
|
+
...assembleOperationName({
|
|
351729
|
+
operationId: "ai.generateObject",
|
|
351730
|
+
telemetry
|
|
351731
|
+
}),
|
|
351732
|
+
...baseTelemetryAttributes,
|
|
351733
|
+
"ai.prompt": {
|
|
351734
|
+
input: () => JSON.stringify({ system, prompt, messages })
|
|
351735
|
+
},
|
|
351736
|
+
"ai.schema": outputStrategy.jsonSchema != null ? { input: () => JSON.stringify(outputStrategy.jsonSchema) } : undefined,
|
|
351737
|
+
"ai.schema.name": schemaName,
|
|
351738
|
+
"ai.schema.description": schemaDescription,
|
|
351739
|
+
"ai.settings.output": outputStrategy.type
|
|
351740
|
+
}
|
|
351741
|
+
}),
|
|
351742
|
+
tracer,
|
|
351743
|
+
fn: async (span) => {
|
|
351744
|
+
var _a172;
|
|
351745
|
+
let result2;
|
|
351746
|
+
let finishReason;
|
|
351747
|
+
let usage;
|
|
351748
|
+
let warnings;
|
|
351749
|
+
let response;
|
|
351750
|
+
let request;
|
|
351751
|
+
let resultProviderMetadata;
|
|
351752
|
+
let reasoning;
|
|
351753
|
+
const standardizedPrompt = await standardizePrompt({
|
|
351754
|
+
system,
|
|
351755
|
+
prompt,
|
|
351756
|
+
messages
|
|
351757
|
+
});
|
|
351758
|
+
const promptMessages = await convertToLanguageModelPrompt({
|
|
351759
|
+
prompt: standardizedPrompt,
|
|
351760
|
+
supportedUrls: await model.supportedUrls,
|
|
351761
|
+
download: download2
|
|
351762
|
+
});
|
|
351763
|
+
const generateResult = await retry(() => recordSpan({
|
|
351764
|
+
name: "ai.generateObject.doGenerate",
|
|
351765
|
+
attributes: selectTelemetryAttributes({
|
|
351766
|
+
telemetry,
|
|
351767
|
+
attributes: {
|
|
351768
|
+
...assembleOperationName({
|
|
351769
|
+
operationId: "ai.generateObject.doGenerate",
|
|
351770
|
+
telemetry
|
|
351771
|
+
}),
|
|
351772
|
+
...baseTelemetryAttributes,
|
|
351773
|
+
"ai.prompt.messages": {
|
|
351774
|
+
input: () => stringifyForTelemetry(promptMessages)
|
|
351775
|
+
},
|
|
351776
|
+
"gen_ai.system": model.provider,
|
|
351777
|
+
"gen_ai.request.model": model.modelId,
|
|
351778
|
+
"gen_ai.request.frequency_penalty": callSettings.frequencyPenalty,
|
|
351779
|
+
"gen_ai.request.max_tokens": callSettings.maxOutputTokens,
|
|
351780
|
+
"gen_ai.request.presence_penalty": callSettings.presencePenalty,
|
|
351781
|
+
"gen_ai.request.temperature": callSettings.temperature,
|
|
351782
|
+
"gen_ai.request.top_k": callSettings.topK,
|
|
351783
|
+
"gen_ai.request.top_p": callSettings.topP
|
|
351784
|
+
}
|
|
351785
|
+
}),
|
|
351786
|
+
tracer,
|
|
351787
|
+
fn: async (span2) => {
|
|
351788
|
+
var _a18, _b8, _c, _d, _e, _f, _g, _h;
|
|
351789
|
+
const result22 = await model.doGenerate({
|
|
351790
|
+
responseFormat: {
|
|
351791
|
+
type: "json",
|
|
351792
|
+
schema: outputStrategy.jsonSchema,
|
|
351793
|
+
name: schemaName,
|
|
351794
|
+
description: schemaDescription
|
|
351795
|
+
},
|
|
351796
|
+
...prepareCallSettings(settings),
|
|
351797
|
+
prompt: promptMessages,
|
|
351798
|
+
providerOptions,
|
|
351799
|
+
abortSignal,
|
|
351800
|
+
headers: headersWithUserAgent
|
|
351801
|
+
});
|
|
351802
|
+
const responseData = {
|
|
351803
|
+
id: (_b8 = (_a18 = result22.response) == null ? undefined : _a18.id) != null ? _b8 : generateId3(),
|
|
351804
|
+
timestamp: (_d = (_c = result22.response) == null ? undefined : _c.timestamp) != null ? _d : currentDate(),
|
|
351805
|
+
modelId: (_f = (_e = result22.response) == null ? undefined : _e.modelId) != null ? _f : model.modelId,
|
|
351806
|
+
headers: (_g = result22.response) == null ? undefined : _g.headers,
|
|
351807
|
+
body: (_h = result22.response) == null ? undefined : _h.body
|
|
351808
|
+
};
|
|
351809
|
+
const text2 = extractTextContent(result22.content);
|
|
351810
|
+
const reasoning2 = extractReasoningContent(result22.content);
|
|
351811
|
+
if (text2 === undefined) {
|
|
351812
|
+
throw new NoObjectGeneratedError({
|
|
351813
|
+
message: "No object generated: the model did not return a response.",
|
|
351814
|
+
response: responseData,
|
|
351815
|
+
usage: result22.usage,
|
|
351816
|
+
finishReason: result22.finishReason
|
|
351817
|
+
});
|
|
351818
|
+
}
|
|
351819
|
+
span2.setAttributes(selectTelemetryAttributes({
|
|
351820
|
+
telemetry,
|
|
351821
|
+
attributes: {
|
|
351822
|
+
"ai.response.finishReason": result22.finishReason,
|
|
351823
|
+
"ai.response.object": { output: () => text2 },
|
|
351824
|
+
"ai.response.id": responseData.id,
|
|
351825
|
+
"ai.response.model": responseData.modelId,
|
|
351826
|
+
"ai.response.timestamp": responseData.timestamp.toISOString(),
|
|
351827
|
+
"ai.response.providerMetadata": JSON.stringify(result22.providerMetadata),
|
|
351828
|
+
"ai.usage.promptTokens": result22.usage.inputTokens,
|
|
351829
|
+
"ai.usage.completionTokens": result22.usage.outputTokens,
|
|
351830
|
+
"gen_ai.response.finish_reasons": [result22.finishReason],
|
|
351831
|
+
"gen_ai.response.id": responseData.id,
|
|
351832
|
+
"gen_ai.response.model": responseData.modelId,
|
|
351833
|
+
"gen_ai.usage.input_tokens": result22.usage.inputTokens,
|
|
351834
|
+
"gen_ai.usage.output_tokens": result22.usage.outputTokens
|
|
351835
|
+
}
|
|
351836
|
+
}));
|
|
351837
|
+
return {
|
|
351838
|
+
...result22,
|
|
351839
|
+
objectText: text2,
|
|
351840
|
+
reasoning: reasoning2,
|
|
351841
|
+
responseData
|
|
351842
|
+
};
|
|
351843
|
+
}
|
|
351844
|
+
}));
|
|
351845
|
+
result2 = generateResult.objectText;
|
|
351846
|
+
finishReason = generateResult.finishReason;
|
|
351847
|
+
usage = generateResult.usage;
|
|
351848
|
+
warnings = generateResult.warnings;
|
|
351849
|
+
resultProviderMetadata = generateResult.providerMetadata;
|
|
351850
|
+
request = (_a172 = generateResult.request) != null ? _a172 : {};
|
|
351851
|
+
response = generateResult.responseData;
|
|
351852
|
+
reasoning = generateResult.reasoning;
|
|
351853
|
+
logWarnings(warnings);
|
|
351854
|
+
const object2 = await parseAndValidateObjectResultWithRepair(result2, outputStrategy, repairText, {
|
|
351855
|
+
response,
|
|
351856
|
+
usage,
|
|
351857
|
+
finishReason
|
|
351858
|
+
});
|
|
351859
|
+
span.setAttributes(selectTelemetryAttributes({
|
|
351860
|
+
telemetry,
|
|
351861
|
+
attributes: {
|
|
351862
|
+
"ai.response.finishReason": finishReason,
|
|
351863
|
+
"ai.response.object": {
|
|
351864
|
+
output: () => JSON.stringify(object2)
|
|
351865
|
+
},
|
|
351866
|
+
"ai.response.providerMetadata": JSON.stringify(resultProviderMetadata),
|
|
351867
|
+
"ai.usage.promptTokens": usage.inputTokens,
|
|
351868
|
+
"ai.usage.completionTokens": usage.outputTokens
|
|
351869
|
+
}
|
|
351870
|
+
}));
|
|
351871
|
+
return new DefaultGenerateObjectResult({
|
|
351872
|
+
object: object2,
|
|
351873
|
+
reasoning,
|
|
351874
|
+
finishReason,
|
|
351875
|
+
usage,
|
|
351876
|
+
warnings,
|
|
351877
|
+
request,
|
|
351878
|
+
response,
|
|
351879
|
+
providerMetadata: resultProviderMetadata
|
|
351880
|
+
});
|
|
351881
|
+
}
|
|
351882
|
+
});
|
|
351883
|
+
} catch (error40) {
|
|
351884
|
+
throw wrapGatewayError(error40);
|
|
351885
|
+
}
|
|
351886
|
+
}
|
|
351887
|
+
var DefaultGenerateObjectResult = class {
|
|
351888
|
+
constructor(options) {
|
|
351889
|
+
this.object = options.object;
|
|
351890
|
+
this.finishReason = options.finishReason;
|
|
351891
|
+
this.usage = options.usage;
|
|
351892
|
+
this.warnings = options.warnings;
|
|
351893
|
+
this.providerMetadata = options.providerMetadata;
|
|
351894
|
+
this.response = options.response;
|
|
351895
|
+
this.request = options.request;
|
|
351896
|
+
this.reasoning = options.reasoning;
|
|
351897
|
+
}
|
|
351898
|
+
toJsonResponse(init) {
|
|
351899
|
+
var _a172;
|
|
351900
|
+
return new Response(JSON.stringify(this.object), {
|
|
351901
|
+
status: (_a172 = init == null ? undefined : init.status) != null ? _a172 : 200,
|
|
351902
|
+
headers: prepareHeaders(init == null ? undefined : init.headers, {
|
|
351903
|
+
"content-type": "application/json; charset=utf-8"
|
|
351904
|
+
})
|
|
351905
|
+
});
|
|
351906
|
+
}
|
|
351907
|
+
};
|
|
350725
351908
|
var SerialJobExecutor = class {
|
|
350726
351909
|
constructor() {
|
|
350727
351910
|
this.queue = [];
|
|
@@ -352096,15 +353279,16 @@ Use this tool in the following scenarios:
|
|
|
352096
353279
|
var askFollowupQuestion = tool(toolDef2);
|
|
352097
353280
|
|
|
352098
353281
|
// ../tools/src/attempt-completion.ts
|
|
353282
|
+
var attemptCompletionSchema = exports_external2.object({
|
|
353283
|
+
result: exports_external2.string().describe("The result of the task. Formulate this result in a way that is final and does not require further input from the user."),
|
|
353284
|
+
command: exports_external2.string().optional().describe("A CLI command to execute to show a live demo of the result to the user.")
|
|
353285
|
+
});
|
|
352099
353286
|
var toolDef3 = {
|
|
352100
353287
|
description: `After each tool use. Once you've received the results of tool uses and can confirm that the task is complete, use this tool to present the result of your work to the user.
|
|
352101
353288
|
|
|
352102
353289
|
Never use this tool with a question or request to engage in further conversation! Formulate the end of your result in a way that is final and does not require further input from the user.
|
|
352103
353290
|
`.trim(),
|
|
352104
|
-
inputSchema:
|
|
352105
|
-
result: exports_external2.string().describe("The result of the task. Formulate this result in a way that is final and does not require further input from the user."),
|
|
352106
|
-
command: exports_external2.string().optional().describe("A CLI command to execute to show a live demo of the result to the user.")
|
|
352107
|
-
}),
|
|
353291
|
+
inputSchema: attemptCompletionSchema,
|
|
352108
353292
|
outputSchema: exports_external2.object({
|
|
352109
353293
|
success: exports_external2.boolean().describe("Indicates whether the completion was successful.")
|
|
352110
353294
|
})
|
|
@@ -358795,7 +359979,6 @@ function createModel(vendorId, opts) {
|
|
|
358795
359979
|
|
|
358796
359980
|
// ../vendor-pochi/src/model.ts
|
|
358797
359981
|
function createPochiModel({
|
|
358798
|
-
id,
|
|
358799
359982
|
modelId,
|
|
358800
359983
|
getCredentials
|
|
358801
359984
|
}) {
|
|
@@ -358804,11 +359987,28 @@ function createPochiModel({
|
|
|
358804
359987
|
provider: "pochi",
|
|
358805
359988
|
modelId: modelId || "<default>",
|
|
358806
359989
|
supportedUrls: {},
|
|
358807
|
-
doGenerate: async () =>
|
|
358808
|
-
|
|
359990
|
+
doGenerate: async ({ headers, ...options }) => {
|
|
359991
|
+
const apiClient = createApiClient(getCredentials);
|
|
359992
|
+
const resp = await apiClient.api.chat.$post({
|
|
359993
|
+
json: {
|
|
359994
|
+
model: modelId,
|
|
359995
|
+
options
|
|
359996
|
+
}
|
|
359997
|
+
}, {
|
|
359998
|
+
headers: headers ? i5(headers, (x) => x || "") : undefined
|
|
359999
|
+
});
|
|
360000
|
+
const data = await resp.json();
|
|
360001
|
+
return data;
|
|
360002
|
+
},
|
|
360003
|
+
doStream: async ({
|
|
360004
|
+
prompt,
|
|
360005
|
+
abortSignal,
|
|
360006
|
+
stopSequences,
|
|
360007
|
+
tools,
|
|
360008
|
+
headers
|
|
360009
|
+
}) => {
|
|
358809
360010
|
const apiClient = createApiClient(getCredentials);
|
|
358810
360011
|
const data = {
|
|
358811
|
-
id,
|
|
358812
360012
|
model: modelId,
|
|
358813
360013
|
callOptions: {
|
|
358814
360014
|
prompt: convertFilePartDataToBase64(prompt),
|
|
@@ -358819,6 +360019,7 @@ function createPochiModel({
|
|
|
358819
360019
|
const resp = await apiClient.api.chat.stream.$post({
|
|
358820
360020
|
json: data
|
|
358821
360021
|
}, {
|
|
360022
|
+
headers: headers ? i5(headers, (x) => x || "") : undefined,
|
|
358822
360023
|
init: {
|
|
358823
360024
|
signal: abortSignal
|
|
358824
360025
|
}
|
|
@@ -367770,7 +368971,7 @@ var {
|
|
|
367770
368971
|
// package.json
|
|
367771
368972
|
var package_default = {
|
|
367772
368973
|
name: "@getpochi/cli",
|
|
367773
|
-
version: "0.5.
|
|
368974
|
+
version: "0.5.61",
|
|
367774
368975
|
type: "module",
|
|
367775
368976
|
bin: {
|
|
367776
368977
|
pochi: "src/cli.ts"
|
|
@@ -367814,7 +369015,8 @@ var package_default = {
|
|
|
367814
369015
|
omelette: "^0.4.17",
|
|
367815
369016
|
ora: "^8.2.0",
|
|
367816
369017
|
remeda: "catalog:",
|
|
367817
|
-
semver: "^7.6.3"
|
|
369018
|
+
semver: "^7.6.3",
|
|
369019
|
+
zod: "catalog:"
|
|
367818
369020
|
}
|
|
367819
369021
|
};
|
|
367820
369022
|
|
|
@@ -409171,6 +410373,9 @@ function toTaskError(error46) {
|
|
|
409171
410373
|
return internalError(error46.message);
|
|
409172
410374
|
}
|
|
409173
410375
|
|
|
410376
|
+
// ../common/src/pochi-api.ts
|
|
410377
|
+
var PochiTaskIdHeader = "x-pochi-task-id";
|
|
410378
|
+
|
|
409174
410379
|
// ../livekit/src/chat/llm/generate-task-title.ts
|
|
409175
410380
|
var logger18 = getLogger("generateTaskTitle");
|
|
409176
410381
|
async function generateTaskTitle(options6) {
|
|
@@ -409182,6 +410387,7 @@ async function generateTaskTitle(options6) {
|
|
|
409182
410387
|
return newTitle;
|
|
409183
410388
|
}
|
|
409184
410389
|
async function generateTaskTitleImpl({
|
|
410390
|
+
taskId,
|
|
409185
410391
|
title,
|
|
409186
410392
|
messages: messages2,
|
|
409187
410393
|
getModel,
|
|
@@ -409199,7 +410405,7 @@ async function generateTaskTitleImpl({
|
|
|
409199
410405
|
if (partCount >= 5 && partCount < 20 && !isTitleGeneratedByLlm(title, titleFromMessages)) {
|
|
409200
410406
|
try {
|
|
409201
410407
|
const model2 = getModel();
|
|
409202
|
-
const title2 = await generateTitle2(model2, messages2, abortSignal);
|
|
410408
|
+
const title2 = await generateTitle2(taskId, model2, messages2, abortSignal);
|
|
409203
410409
|
if (title2.length > 0) {
|
|
409204
410410
|
return title2;
|
|
409205
410411
|
}
|
|
@@ -409225,7 +410431,7 @@ function getTitleFromMessages(messages2) {
|
|
|
409225
410431
|
function isTitleGeneratedByLlm(title, titleFromMessages) {
|
|
409226
410432
|
return title !== titleFromMessages;
|
|
409227
410433
|
}
|
|
409228
|
-
async function generateTitle2(model2, inputMessages, abortSignal) {
|
|
410434
|
+
async function generateTitle2(taskId, model2, inputMessages, abortSignal) {
|
|
409229
410435
|
const messages2 = [
|
|
409230
410436
|
...inputMessages,
|
|
409231
410437
|
{
|
|
@@ -409239,14 +410445,17 @@ async function generateTitle2(model2, inputMessages, abortSignal) {
|
|
|
409239
410445
|
]
|
|
409240
410446
|
}
|
|
409241
410447
|
];
|
|
409242
|
-
const
|
|
410448
|
+
const resp = await generateText({
|
|
410449
|
+
headers: {
|
|
410450
|
+
[PochiTaskIdHeader]: taskId
|
|
410451
|
+
},
|
|
409243
410452
|
model: model2,
|
|
409244
410453
|
prompt: convertToModelMessages(formatters.llm(messages2, { removeSystemReminder: true })),
|
|
409245
410454
|
abortSignal,
|
|
409246
410455
|
maxOutputTokens: 50,
|
|
409247
410456
|
maxRetries: 0
|
|
409248
410457
|
});
|
|
409249
|
-
return
|
|
410458
|
+
return resp.text;
|
|
409250
410459
|
}
|
|
409251
410460
|
|
|
409252
410461
|
// ../livekit/src/chat/background-job/manager.ts
|
|
@@ -409293,6 +410502,7 @@ async function process16({
|
|
|
409293
410502
|
return;
|
|
409294
410503
|
}
|
|
409295
410504
|
const newTitle = await generateTaskTitle({
|
|
410505
|
+
taskId,
|
|
409296
410506
|
title: task.title,
|
|
409297
410507
|
messages: messages2,
|
|
409298
410508
|
getModel
|
|
@@ -409379,56 +410589,33 @@ async function digest(data) {
|
|
|
409379
410589
|
}
|
|
409380
410590
|
|
|
409381
410591
|
// ../livekit/src/chat/llm/repair-tool-call.ts
|
|
409382
|
-
var
|
|
409383
|
-
var makeRepairToolCall = (model2) => async ({ toolCall, inputSchema: inputSchema2, error: error46 }) => {
|
|
410592
|
+
var makeRepairToolCall = (taskId, model2) => async ({ toolCall, inputSchema: inputSchema2, error: error46 }) => {
|
|
409384
410593
|
if (NoSuchToolError.isInstance(error46)) {
|
|
409385
410594
|
return null;
|
|
409386
410595
|
}
|
|
409387
|
-
const
|
|
410596
|
+
const tools = createClientTools();
|
|
410597
|
+
const tool2 = tools[toolCall.toolName];
|
|
410598
|
+
const { object: repairedArgs } = await generateObject({
|
|
410599
|
+
headers: {
|
|
410600
|
+
[PochiTaskIdHeader]: taskId
|
|
410601
|
+
},
|
|
409388
410602
|
model: model2,
|
|
410603
|
+
schema: tool2.inputSchema,
|
|
409389
410604
|
prompt: [
|
|
409390
|
-
`The model tried to call the tool "${toolCall.toolName}" with the following
|
|
410605
|
+
`The model tried to call the tool "${toolCall.toolName}" with the following inputs:`,
|
|
409391
410606
|
JSON.stringify(toolCall.input),
|
|
409392
410607
|
"The tool accepts the following schema:",
|
|
409393
410608
|
JSON.stringify(inputSchema2(toolCall)),
|
|
409394
|
-
"Please fix the
|
|
409395
|
-
"",
|
|
409396
|
-
"<good-example>",
|
|
409397
|
-
'{"path": "./src/file.ts", "content": "console.log("hello");"}',
|
|
409398
|
-
"</good-example>",
|
|
409399
|
-
"",
|
|
409400
|
-
"<bad-example>",
|
|
409401
|
-
"```json",
|
|
409402
|
-
'{"path": "./src/file.ts", "content": "console.log("hello");"}',
|
|
409403
|
-
"```",
|
|
409404
|
-
"</bad-example>",
|
|
409405
|
-
"",
|
|
409406
|
-
"<bad-example>",
|
|
409407
|
-
"Here is the corrected JSON:",
|
|
409408
|
-
'{"path": "./src/file.ts", "content": "console.log("hello");"}',
|
|
409409
|
-
"</bad-example>",
|
|
409410
|
-
"",
|
|
409411
|
-
"<bad-example>",
|
|
409412
|
-
"```",
|
|
409413
|
-
'{"path": "./src/file.ts", "content": "console.log("hello");"}',
|
|
409414
|
-
"```",
|
|
409415
|
-
"</bad-example>",
|
|
409416
|
-
"",
|
|
409417
|
-
"<bad-example>",
|
|
409418
|
-
'{"path": "./src/file.ts", "content": "console.log("hello");"} // Fixed arguments',
|
|
409419
|
-
"</bad-example>"
|
|
410609
|
+
"Please fix the inputs."
|
|
409420
410610
|
].join(`
|
|
409421
|
-
`)
|
|
409422
|
-
maxOutputTokens: 3000,
|
|
409423
|
-
maxRetries: 0
|
|
410611
|
+
`)
|
|
409424
410612
|
});
|
|
409425
|
-
|
|
409426
|
-
logger21.debug("Repairing tool call:", toolCall.toolName, input2);
|
|
409427
|
-
return { ...toolCall, input: input2 };
|
|
410613
|
+
return { ...toolCall, input: JSON.stringify(repairedArgs) };
|
|
409428
410614
|
};
|
|
409429
410615
|
// ../livekit/src/chat/llm/compact-task.ts
|
|
409430
|
-
var
|
|
410616
|
+
var logger21 = getLogger("compactTask");
|
|
409431
410617
|
async function compactTask({
|
|
410618
|
+
taskId,
|
|
409432
410619
|
model: model2,
|
|
409433
410620
|
messages: messages2,
|
|
409434
410621
|
abortSignal,
|
|
@@ -409439,7 +410626,7 @@ async function compactTask({
|
|
|
409439
410626
|
throw new Error("No messages to compact");
|
|
409440
410627
|
}
|
|
409441
410628
|
try {
|
|
409442
|
-
const text20 = prompts.inlineCompact(await createSummary(model2, abortSignal, messages2.slice(0, -1)), messages2.length - 1);
|
|
410629
|
+
const text20 = prompts.inlineCompact(await createSummary(taskId, model2, abortSignal, messages2.slice(0, -1)), messages2.length - 1);
|
|
409443
410630
|
if (inline) {
|
|
409444
410631
|
lastMessage.parts.unshift({
|
|
409445
410632
|
type: "text",
|
|
@@ -409449,10 +410636,10 @@ async function compactTask({
|
|
|
409449
410636
|
}
|
|
409450
410637
|
return text20;
|
|
409451
410638
|
} catch (err2) {
|
|
409452
|
-
|
|
410639
|
+
logger21.warn("Failed to create summary", err2);
|
|
409453
410640
|
}
|
|
409454
410641
|
}
|
|
409455
|
-
async function createSummary(model2, abortSignal, inputMessages) {
|
|
410642
|
+
async function createSummary(taskId, model2, abortSignal, inputMessages) {
|
|
409456
410643
|
const messages2 = [
|
|
409457
410644
|
...inputMessages,
|
|
409458
410645
|
{
|
|
@@ -409466,7 +410653,10 @@ async function createSummary(model2, abortSignal, inputMessages) {
|
|
|
409466
410653
|
]
|
|
409467
410654
|
}
|
|
409468
410655
|
];
|
|
409469
|
-
const
|
|
410656
|
+
const resp = await generateText({
|
|
410657
|
+
headers: {
|
|
410658
|
+
[PochiTaskIdHeader]: taskId
|
|
410659
|
+
},
|
|
409470
410660
|
model: model2,
|
|
409471
410661
|
prompt: convertToModelMessages(formatters.llm(messages2, {
|
|
409472
410662
|
removeSystemReminder: true
|
|
@@ -409475,7 +410665,7 @@ async function createSummary(model2, abortSignal, inputMessages) {
|
|
|
409475
410665
|
maxOutputTokens: 3000,
|
|
409476
410666
|
maxRetries: 0
|
|
409477
410667
|
});
|
|
409478
|
-
return
|
|
410668
|
+
return resp.text;
|
|
409479
410669
|
}
|
|
409480
410670
|
// ../livekit/src/chat/mcp-utils.ts
|
|
409481
410671
|
function parseMcpToolSet(store, mcpToolSet) {
|
|
@@ -410199,6 +411389,80 @@ function createStopWordStream(stop3) {
|
|
|
410199
411389
|
}
|
|
410200
411390
|
});
|
|
410201
411391
|
}
|
|
411392
|
+
// ../livekit/src/chat/middlewares/output-schema-middleware.ts
|
|
411393
|
+
function createOutputSchemaMiddleware(taskId, model2, outputSchema2) {
|
|
411394
|
+
return {
|
|
411395
|
+
middlewareVersion: "v2",
|
|
411396
|
+
wrapStream: async ({ doStream }) => {
|
|
411397
|
+
const { stream: stream12, ...rest } = await doStream();
|
|
411398
|
+
let toolCallId = "";
|
|
411399
|
+
const transformedStream = stream12.pipeThrough(new TransformStream({
|
|
411400
|
+
async transform(chunk4, controller) {
|
|
411401
|
+
if (chunk4.type === "tool-input-start" && chunk4.toolName === "attemptCompletion") {
|
|
411402
|
+
toolCallId = chunk4.id;
|
|
411403
|
+
return;
|
|
411404
|
+
}
|
|
411405
|
+
if (chunk4.type === "tool-input-delta" && chunk4.id === toolCallId) {
|
|
411406
|
+
return;
|
|
411407
|
+
}
|
|
411408
|
+
if (chunk4.type === "tool-call" && chunk4.toolName === "attemptCompletion" && (chunk4.toolCallId === toolCallId || toolCallId === "")) {
|
|
411409
|
+
const parsedResult = await safeParseJSON({
|
|
411410
|
+
text: chunk4.input,
|
|
411411
|
+
schema: attemptCompletionSchema
|
|
411412
|
+
});
|
|
411413
|
+
if (!parsedResult.success) {
|
|
411414
|
+
throw new InvalidToolInputError({
|
|
411415
|
+
toolName: chunk4.toolName,
|
|
411416
|
+
toolInput: chunk4.input,
|
|
411417
|
+
cause: parsedResult.error
|
|
411418
|
+
});
|
|
411419
|
+
}
|
|
411420
|
+
const { result: result2 } = parsedResult.value;
|
|
411421
|
+
const newInput = {
|
|
411422
|
+
...parsedResult.value,
|
|
411423
|
+
result: await ensureOutputSchema(taskId, model2, outputSchema2, result2)
|
|
411424
|
+
};
|
|
411425
|
+
controller.enqueue({
|
|
411426
|
+
...chunk4,
|
|
411427
|
+
input: JSON.stringify(newInput)
|
|
411428
|
+
});
|
|
411429
|
+
toolCallId = "";
|
|
411430
|
+
return;
|
|
411431
|
+
}
|
|
411432
|
+
controller.enqueue(chunk4);
|
|
411433
|
+
}
|
|
411434
|
+
}));
|
|
411435
|
+
return {
|
|
411436
|
+
stream: transformedStream,
|
|
411437
|
+
...rest
|
|
411438
|
+
};
|
|
411439
|
+
}
|
|
411440
|
+
};
|
|
411441
|
+
}
|
|
411442
|
+
async function ensureOutputSchema(taskId, model2, schema7, content3) {
|
|
411443
|
+
try {
|
|
411444
|
+
const { object: object4 } = await generateObject({
|
|
411445
|
+
headers: {
|
|
411446
|
+
[PochiTaskIdHeader]: taskId
|
|
411447
|
+
},
|
|
411448
|
+
model: model2,
|
|
411449
|
+
schema: schema7,
|
|
411450
|
+
prompt: [
|
|
411451
|
+
"The model is trying to generate object with following schema:",
|
|
411452
|
+
JSON.stringify(v4_default.toJSONSchema(schema7)),
|
|
411453
|
+
"Current input is",
|
|
411454
|
+
content3,
|
|
411455
|
+
"Please fix the inputs."
|
|
411456
|
+
].join(`
|
|
411457
|
+
`),
|
|
411458
|
+
maxRetries: 0
|
|
411459
|
+
});
|
|
411460
|
+
return JSON.stringify(object4);
|
|
411461
|
+
} catch (err2) {
|
|
411462
|
+
return content3;
|
|
411463
|
+
}
|
|
411464
|
+
}
|
|
411465
|
+
|
|
410202
411466
|
// ../livekit/src/chat/models/ai-gateway.ts
|
|
410203
411467
|
function createAiGatewayModel(llm) {
|
|
410204
411468
|
const gateway2 = createGatewayProvider({
|
|
@@ -410355,7 +411619,7 @@ function createGoogleVertexTuningModel(llm) {
|
|
|
410355
411619
|
}
|
|
410356
411620
|
|
|
410357
411621
|
// ../livekit/src/chat/models/openai.ts
|
|
410358
|
-
var
|
|
411622
|
+
var logger22 = getLogger("openai");
|
|
410359
411623
|
var OpenAIRequestParamsSchema = exports_external.object({
|
|
410360
411624
|
max_tokens: exports_external.number().positive().optional(),
|
|
410361
411625
|
max_completion_tokens: exports_external.number().positive().optional()
|
|
@@ -410405,7 +411669,7 @@ function overrideMaxOutputToken(body3) {
|
|
|
410405
411669
|
const json10 = JSON.parse(body3);
|
|
410406
411670
|
const result2 = OpenAIRequestParamsSchema.safeParse(json10);
|
|
410407
411671
|
if (!result2.success) {
|
|
410408
|
-
|
|
411672
|
+
logger22.error("OpenAI request body validation failed:", result2.error);
|
|
410409
411673
|
return;
|
|
410410
411674
|
}
|
|
410411
411675
|
const parsed = result2.data;
|
|
@@ -410414,7 +411678,7 @@ function overrideMaxOutputToken(body3) {
|
|
|
410414
411678
|
}
|
|
410415
411679
|
return JSON.stringify(parsed);
|
|
410416
411680
|
} catch (error46) {
|
|
410417
|
-
|
|
411681
|
+
logger22.error("Failed to parse OpenAI request body:", error46);
|
|
410418
411682
|
}
|
|
410419
411683
|
return;
|
|
410420
411684
|
}
|
|
@@ -410443,12 +411707,9 @@ function createOpenAIResponsesModel(llm) {
|
|
|
410443
411707
|
}
|
|
410444
411708
|
|
|
410445
411709
|
// ../livekit/src/chat/models/index.ts
|
|
410446
|
-
function createModel2({
|
|
410447
|
-
id: id5,
|
|
410448
|
-
llm
|
|
410449
|
-
}) {
|
|
411710
|
+
function createModel2({ llm }) {
|
|
410450
411711
|
if (llm.type === "vendor") {
|
|
410451
|
-
return llm.getModel(
|
|
411712
|
+
return llm.getModel();
|
|
410452
411713
|
}
|
|
410453
411714
|
if (llm.type === "openai") {
|
|
410454
411715
|
return createOpenAIModel(llm);
|
|
@@ -410479,6 +411740,7 @@ class FlexibleChatTransport {
|
|
|
410479
411740
|
isCli;
|
|
410480
411741
|
store;
|
|
410481
411742
|
customAgent;
|
|
411743
|
+
outputSchema;
|
|
410482
411744
|
constructor(options6) {
|
|
410483
411745
|
this.onStart = options6.onStart;
|
|
410484
411746
|
this.getters = options6.getters;
|
|
@@ -410486,6 +411748,7 @@ class FlexibleChatTransport {
|
|
|
410486
411748
|
this.isCli = options6.isCli;
|
|
410487
411749
|
this.store = options6.store;
|
|
410488
411750
|
this.customAgent = overrideCustomAgentTools(options6.customAgent);
|
|
411751
|
+
this.outputSchema = options6.outputSchema;
|
|
410489
411752
|
}
|
|
410490
411753
|
sendMessages = async ({
|
|
410491
411754
|
chatId,
|
|
@@ -410502,6 +411765,7 @@ class FlexibleChatTransport {
|
|
|
410502
411765
|
abortSignal,
|
|
410503
411766
|
getters: this.getters
|
|
410504
411767
|
});
|
|
411768
|
+
const model2 = createModel2({ llm });
|
|
410505
411769
|
const middlewares = [];
|
|
410506
411770
|
if (!this.isSubTask) {
|
|
410507
411771
|
middlewares.push(createNewTaskMiddleware(this.store, environment2?.info.cwd, chatId, customAgents));
|
|
@@ -410509,6 +411773,9 @@ class FlexibleChatTransport {
|
|
|
410509
411773
|
if ("modelId" in llm && isWellKnownReasoningModel(llm.modelId)) {
|
|
410510
411774
|
middlewares.push(createReasoningMiddleware());
|
|
410511
411775
|
}
|
|
411776
|
+
if (this.outputSchema) {
|
|
411777
|
+
middlewares.push(createOutputSchemaMiddleware(chatId, model2, this.outputSchema));
|
|
411778
|
+
}
|
|
410512
411779
|
if (llm.useToolCallMiddleware) {
|
|
410513
411780
|
middlewares.push(createToolCallMiddleware());
|
|
410514
411781
|
}
|
|
@@ -410527,8 +411794,10 @@ class FlexibleChatTransport {
|
|
|
410527
411794
|
return true;
|
|
410528
411795
|
});
|
|
410529
411796
|
const preparedMessages = await prepareMessages(messages2, environment2);
|
|
410530
|
-
const model2 = createModel2({ id: chatId, llm });
|
|
410531
411797
|
const stream12 = streamText({
|
|
411798
|
+
headers: {
|
|
411799
|
+
[PochiTaskIdHeader]: chatId
|
|
411800
|
+
},
|
|
410532
411801
|
system: prompts.system(environment2?.info?.customRules, this.customAgent, mcpInfo?.instructions),
|
|
410533
411802
|
messages: convertToModelMessages(formatters.llm(preparedMessages), { tools }),
|
|
410534
411803
|
model: wrapLanguageModel({
|
|
@@ -410539,7 +411808,7 @@ class FlexibleChatTransport {
|
|
|
410539
411808
|
tools,
|
|
410540
411809
|
maxRetries: 0,
|
|
410541
411810
|
onError: () => {},
|
|
410542
|
-
experimental_repairToolCall: makeRepairToolCall(model2),
|
|
411811
|
+
experimental_repairToolCall: makeRepairToolCall(chatId, model2),
|
|
410543
411812
|
experimental_download: async (items) => {
|
|
410544
411813
|
const promises5 = items.map(async ({
|
|
410545
411814
|
url: url3,
|
|
@@ -410619,7 +411888,7 @@ function estimateTotalTokens(messages2) {
|
|
|
410619
411888
|
}
|
|
410620
411889
|
|
|
410621
411890
|
// ../livekit/src/chat/live-chat-kit.ts
|
|
410622
|
-
var
|
|
411891
|
+
var logger23 = getLogger("LiveChatKit");
|
|
410623
411892
|
|
|
410624
411893
|
class LiveChatKit {
|
|
410625
411894
|
taskId;
|
|
@@ -410637,6 +411906,7 @@ class LiveChatKit {
|
|
|
410637
411906
|
isSubTask,
|
|
410638
411907
|
isCli,
|
|
410639
411908
|
customAgent,
|
|
411909
|
+
outputSchema: outputSchema2,
|
|
410640
411910
|
...chatInit
|
|
410641
411911
|
}) {
|
|
410642
411912
|
this.taskId = taskId;
|
|
@@ -410647,7 +411917,8 @@ class LiveChatKit {
|
|
|
410647
411917
|
getters,
|
|
410648
411918
|
isSubTask,
|
|
410649
411919
|
isCli,
|
|
410650
|
-
customAgent
|
|
411920
|
+
customAgent,
|
|
411921
|
+
outputSchema: outputSchema2
|
|
410651
411922
|
});
|
|
410652
411923
|
this.chat = new (makeChatWithHookClass(store, chatClass))({
|
|
410653
411924
|
...chatInit,
|
|
@@ -410667,15 +411938,16 @@ class LiveChatKit {
|
|
|
410667
411938
|
const lastMessage = messages2.at(-1);
|
|
410668
411939
|
if (lastMessage?.role === "user" && lastMessage.metadata?.kind === "user" && lastMessage.metadata.compact) {
|
|
410669
411940
|
try {
|
|
410670
|
-
const model2 = createModel2({
|
|
411941
|
+
const model2 = createModel2({ llm: getters.getLLM() });
|
|
410671
411942
|
await compactTask({
|
|
411943
|
+
taskId: this.taskId,
|
|
410672
411944
|
model: model2,
|
|
410673
411945
|
messages: messages2,
|
|
410674
411946
|
abortSignal: abortSignal2,
|
|
410675
411947
|
inline: true
|
|
410676
411948
|
});
|
|
410677
411949
|
} catch (err2) {
|
|
410678
|
-
|
|
411950
|
+
logger23.error("Failed to compact task", err2);
|
|
410679
411951
|
throw err2;
|
|
410680
411952
|
}
|
|
410681
411953
|
}
|
|
@@ -410686,8 +411958,9 @@ class LiveChatKit {
|
|
|
410686
411958
|
this.spawn = async () => {
|
|
410687
411959
|
const taskId2 = crypto.randomUUID();
|
|
410688
411960
|
const { messages: messages2 } = this.chat;
|
|
410689
|
-
const model2 = createModel2({
|
|
411961
|
+
const model2 = createModel2({ llm: getters.getLLM() });
|
|
410690
411962
|
const summary6 = await compactTask({
|
|
411963
|
+
taskId: taskId2,
|
|
410691
411964
|
model: model2,
|
|
410692
411965
|
messages: messages2,
|
|
410693
411966
|
abortSignal
|
|
@@ -410769,7 +412042,7 @@ class LiveChatKit {
|
|
|
410769
412042
|
if (!task) {
|
|
410770
412043
|
throw new Error("Task not found");
|
|
410771
412044
|
}
|
|
410772
|
-
const getModel = () => createModel2({
|
|
412045
|
+
const getModel = () => createModel2({ llm: getters.getLLM() });
|
|
410773
412046
|
scheduleGenerateTitleJob({
|
|
410774
412047
|
taskId: this.taskId,
|
|
410775
412048
|
store,
|
|
@@ -410814,7 +412087,7 @@ class LiveChatKit {
|
|
|
410814
412087
|
}));
|
|
410815
412088
|
};
|
|
410816
412089
|
onError = (error46) => {
|
|
410817
|
-
|
|
412090
|
+
logger23.error("onError", error46);
|
|
410818
412091
|
const lastMessage = this.chat.messages.at(-1) || null;
|
|
410819
412092
|
this.store.commit(events.chatStreamFailed({
|
|
410820
412093
|
id: this.taskId,
|
|
@@ -410967,7 +412240,7 @@ import * as nodePath from "node:path";
|
|
|
410967
412240
|
|
|
410968
412241
|
// ../common/src/diff-utils.ts
|
|
410969
412242
|
var import_fast_levenshtein = __toESM(require_levenshtein(), 1);
|
|
410970
|
-
var
|
|
412243
|
+
var logger24 = getLogger("diffUtils");
|
|
410971
412244
|
function normalize6(content3) {
|
|
410972
412245
|
return content3.replace(/\r\n/g, `
|
|
410973
412246
|
`).trimEnd();
|
|
@@ -410980,7 +412253,7 @@ class DiffError extends Error {
|
|
|
410980
412253
|
}
|
|
410981
412254
|
}
|
|
410982
412255
|
async function parseDiffAndApply(fileContent3, searchContent, replaceContent, expectedReplacements = 1) {
|
|
410983
|
-
|
|
412256
|
+
logger24.trace(`Applying diff with expectedReplacements: ${expectedReplacements}`);
|
|
410984
412257
|
const isCRLF = fileContent3.includes(`\r
|
|
410985
412258
|
`);
|
|
410986
412259
|
const normalizedFileContent = normalize6(fileContent3);
|
|
@@ -410997,11 +412270,11 @@ async function parseDiffAndApply(fileContent3, searchContent, replaceContent, ex
|
|
|
410997
412270
|
const matches2 = searchContentExact(normalizedFileContent, normalizedSearchContent);
|
|
410998
412271
|
if (matches2.length < expectedReplacements) {
|
|
410999
412272
|
matches2.push(...searchContentWithLineTrimmed(normalizedFileContent, normalizedSearchContent));
|
|
411000
|
-
|
|
412273
|
+
logger24.trace(`Found ${matches2.length} matches after line trimming search strategy`);
|
|
411001
412274
|
}
|
|
411002
412275
|
if (matches2.length < expectedReplacements) {
|
|
411003
412276
|
matches2.push(...searchContentByBlockAnchor(normalizedFileContent, normalizedSearchContent));
|
|
411004
|
-
|
|
412277
|
+
logger24.trace(`Found ${matches2.length} matches after block anchor search strategy`);
|
|
411005
412278
|
}
|
|
411006
412279
|
if (matches2.length === 0) {
|
|
411007
412280
|
throw new DiffError("Search content does not match the file content. Try to reread the file for the latest content.");
|
|
@@ -411010,7 +412283,7 @@ async function parseDiffAndApply(fileContent3, searchContent, replaceContent, ex
|
|
|
411010
412283
|
throw new DiffError(`Expected ${expectedReplacements} occurrences but found ${matches2.length}. Please verify the search content and expectedReplacements parameter.`);
|
|
411011
412284
|
}
|
|
411012
412285
|
const result2 = replaceMatches(normalizedFileContent, matches2, replaceContent);
|
|
411013
|
-
|
|
412286
|
+
logger24.trace("Successfully applied diff");
|
|
411014
412287
|
if (isCRLF) {
|
|
411015
412288
|
return result2.replace(/\n/g, `\r
|
|
411016
412289
|
`);
|
|
@@ -411364,11 +412637,11 @@ var readFile13 = () => async ({ path: path27, startLine, endLine }, { cwd: cwd2
|
|
|
411364
412637
|
|
|
411365
412638
|
// src/tools/search-files.ts
|
|
411366
412639
|
import * as fs14 from "node:fs";
|
|
411367
|
-
var
|
|
412640
|
+
var logger25 = getLogger("searchFiles");
|
|
411368
412641
|
var searchFiles2 = (context15) => async ({ path: path27, regex: regex3, filePattern }, { abortSignal, cwd: cwd2 }) => {
|
|
411369
412642
|
const rgPath = context15.rg;
|
|
411370
412643
|
if (!rgPath || !fs14.existsSync(rgPath)) {
|
|
411371
|
-
|
|
412644
|
+
logger25.error("Ripgrep not found at path", rgPath);
|
|
411372
412645
|
throw new Error(`Ripgrep not found at path: ${rgPath}`);
|
|
411373
412646
|
}
|
|
411374
412647
|
return await searchFilesWithRipgrep(path27, regex3, rgPath, cwd2, filePattern, abortSignal);
|
|
@@ -411446,7 +412719,7 @@ async function executeToolCall(tool2, options6, cwd2, abortSignal) {
|
|
|
411446
412719
|
}
|
|
411447
412720
|
|
|
411448
412721
|
// src/task-runner.ts
|
|
411449
|
-
var
|
|
412722
|
+
var logger26 = getLogger("TaskRunner");
|
|
411450
412723
|
|
|
411451
412724
|
class TaskRunner {
|
|
411452
412725
|
cwd;
|
|
@@ -411487,6 +412760,7 @@ class TaskRunner {
|
|
|
411487
412760
|
isCli: true,
|
|
411488
412761
|
isSubTask: options6.isSubTask,
|
|
411489
412762
|
customAgent: options6.customAgent,
|
|
412763
|
+
outputSchema: options6.outputSchema,
|
|
411490
412764
|
getters: {
|
|
411491
412765
|
getLLM: () => options6.llm,
|
|
411492
412766
|
getEnvironment: async () => ({
|
|
@@ -411522,9 +412796,9 @@ class TaskRunner {
|
|
|
411522
412796
|
return this.chatKit.task?.shareId;
|
|
411523
412797
|
}
|
|
411524
412798
|
async run() {
|
|
411525
|
-
|
|
412799
|
+
logger26.debug("Starting TaskRunner...");
|
|
411526
412800
|
try {
|
|
411527
|
-
|
|
412801
|
+
logger26.trace("Start step loop.");
|
|
411528
412802
|
this.stepCount.reset();
|
|
411529
412803
|
while (true) {
|
|
411530
412804
|
const stepResult = await this.step();
|
|
@@ -411539,7 +412813,7 @@ class TaskRunner {
|
|
|
411539
412813
|
}
|
|
411540
412814
|
} catch (e11) {
|
|
411541
412815
|
const error46 = toError2(e11);
|
|
411542
|
-
|
|
412816
|
+
logger26.trace("Failed:", error46);
|
|
411543
412817
|
}
|
|
411544
412818
|
}
|
|
411545
412819
|
async step() {
|
|
@@ -411577,24 +412851,24 @@ class TaskRunner {
|
|
|
411577
412851
|
throw new Error("Task is not loaded");
|
|
411578
412852
|
}
|
|
411579
412853
|
if ((task.status === "completed" || task.status === "pending-input") && isResultMessage(message)) {
|
|
411580
|
-
|
|
412854
|
+
logger26.trace("Task is completed or pending input, no more steps to process.");
|
|
411581
412855
|
return "finished";
|
|
411582
412856
|
}
|
|
411583
412857
|
if (task.status === "failed") {
|
|
411584
412858
|
if (task.error?.kind === "APICallError" && !task.error.isRetryable) {
|
|
411585
412859
|
return "finished";
|
|
411586
412860
|
}
|
|
411587
|
-
|
|
412861
|
+
logger26.error("Task is failed, trying to resend last message to resume it.", task.error);
|
|
411588
412862
|
return "retry";
|
|
411589
412863
|
}
|
|
411590
412864
|
if (message.role !== "assistant") {
|
|
411591
|
-
|
|
412865
|
+
logger26.trace("Last message is not a assistant message, resending it to resume the task.");
|
|
411592
412866
|
return "retry";
|
|
411593
412867
|
}
|
|
411594
412868
|
if (isAssistantMessageWithEmptyParts(message) || isAssistantMessageWithPartialToolCalls(message) || isAssistantMessageWithOutputError(message) || lastAssistantMessageIsCompleteWithToolCalls({
|
|
411595
412869
|
messages: this.chat.messages
|
|
411596
412870
|
})) {
|
|
411597
|
-
|
|
412871
|
+
logger26.trace("Last message is assistant with empty parts or partial/completed tool calls, resending it to resume the task.");
|
|
411598
412872
|
const processed = prepareLastMessageForRetry(message);
|
|
411599
412873
|
if (processed) {
|
|
411600
412874
|
this.chat.appendOrReplaceMessage(processed);
|
|
@@ -411602,28 +412876,28 @@ class TaskRunner {
|
|
|
411602
412876
|
return "retry";
|
|
411603
412877
|
}
|
|
411604
412878
|
if (isAssistantMessageWithNoToolCalls(message)) {
|
|
411605
|
-
|
|
412879
|
+
logger26.trace("Last message is assistant with no tool calls, sending a new user reminder.");
|
|
411606
412880
|
const message2 = createUserMessage(prompts.createSystemReminder("You should use tool calls to answer the question, for example, use attemptCompletion if the job is done, or use askFollowupQuestions to clarify the request."));
|
|
411607
412881
|
this.chat.appendOrReplaceMessage(message2);
|
|
411608
412882
|
return "retry";
|
|
411609
412883
|
}
|
|
411610
412884
|
}
|
|
411611
412885
|
async processToolCalls(message) {
|
|
411612
|
-
|
|
412886
|
+
logger26.trace("Processing tool calls in the last message.");
|
|
411613
412887
|
for (const toolCall of message.parts.filter(isToolUIPart)) {
|
|
411614
412888
|
if (toolCall.state !== "input-available")
|
|
411615
412889
|
continue;
|
|
411616
412890
|
const toolName = getToolName(toolCall);
|
|
411617
|
-
|
|
412891
|
+
logger26.trace(`Found tool call: ${toolName} with args: ${JSON.stringify(toolCall.input)}`);
|
|
411618
412892
|
const toolResult = await executeToolCall(toolCall, this.toolCallOptions, this.cwd);
|
|
411619
412893
|
await this.chatKit.chat.addToolResult({
|
|
411620
412894
|
tool: toolName,
|
|
411621
412895
|
toolCallId: toolCall.toolCallId,
|
|
411622
412896
|
output: toolResult
|
|
411623
412897
|
});
|
|
411624
|
-
|
|
412898
|
+
logger26.trace(`Tool call result: ${JSON.stringify(toolResult)}`);
|
|
411625
412899
|
}
|
|
411626
|
-
|
|
412900
|
+
logger26.trace("All tool calls processed in the last message.");
|
|
411627
412901
|
return "next";
|
|
411628
412902
|
}
|
|
411629
412903
|
}
|
|
@@ -411924,8 +413198,8 @@ function registerUpgradeCommand(program5) {
|
|
|
411924
413198
|
});
|
|
411925
413199
|
}
|
|
411926
413200
|
// src/cli.ts
|
|
411927
|
-
var
|
|
411928
|
-
|
|
413201
|
+
var logger27 = getLogger("Pochi");
|
|
413202
|
+
logger27.debug(`pochi v${package_default.version}`);
|
|
411929
413203
|
var parsePositiveInt = (input2) => {
|
|
411930
413204
|
if (!input2) {
|
|
411931
413205
|
return program5.error("The value for this option must be a positive integer.");
|
|
@@ -411936,7 +413210,7 @@ var parsePositiveInt = (input2) => {
|
|
|
411936
413210
|
}
|
|
411937
413211
|
return result2;
|
|
411938
413212
|
};
|
|
411939
|
-
var program5 = new Command().name("pochi").description(`${source_default.bold("Pochi")} v${package_default.version} - A powerful CLI tool for AI-driven development.`).optionsGroup("Prompt:").option("-p, --prompt <prompt>", "Create a new task with a given prompt. Input can also be piped. For example: `cat my-prompt.md | pochi`. Workflows can be triggered with `/workflow-name`, like `pochi -p /create-pr`.").optionsGroup("Options:").option("--stream-json", "Stream the output in JSON format. This is useful for parsing the output in scripts.").option("--max-steps <number>", "Set the maximum number of steps for a task. The task will stop if it exceeds this limit.", parsePositiveInt, 24).option("--max-retries <number>", "Set the maximum number of retries for a single step in a task.", parsePositiveInt, 3).optionsGroup("Model:").option("-m, --model <model>", "Specify the model to be used for the task.", "qwen/qwen3-coder").optionsGroup("MCP:").option("--no-mcp", "Disable MCP (Model Context Protocol) integration completely.").action(async (options6) => {
|
|
413213
|
+
var program5 = new Command().name("pochi").description(`${source_default.bold("Pochi")} v${package_default.version} - A powerful CLI tool for AI-driven development.`).optionsGroup("Prompt:").option("-p, --prompt <prompt>", "Create a new task with a given prompt. Input can also be piped. For example: `cat my-prompt.md | pochi`. Workflows can be triggered with `/workflow-name`, like `pochi -p /create-pr`.").optionsGroup("Options:").option("--stream-json", "Stream the output in JSON format. This is useful for parsing the output in scripts.").option("--max-steps <number>", "Set the maximum number of steps for a task. The task will stop if it exceeds this limit.", parsePositiveInt, 24).option("--max-retries <number>", "Set the maximum number of retries for a single step in a task.", parsePositiveInt, 3).addOption(new Option("--experimental-output-schema <schema>", "Specify a JSON schema for the output of the task. The task will be validated against this schema.").hideHelp()).optionsGroup("Model:").option("-m, --model <model>", "Specify the model to be used for the task.", "qwen/qwen3-coder").optionsGroup("MCP:").option("--no-mcp", "Disable MCP (Model Context Protocol) integration completely.").action(async (options6) => {
|
|
411940
413214
|
const { uid, prompt: prompt3 } = await parseTaskInput(options6, program5);
|
|
411941
413215
|
const store = await createStore3();
|
|
411942
413216
|
const llm = await createLLMConfig(program5, options6);
|
|
@@ -411969,7 +413243,8 @@ var program5 = new Command().name("pochi").description(`${source_default.bold("P
|
|
|
411969
413243
|
maxRetries: options6.maxRetries,
|
|
411970
413244
|
onSubTaskCreated,
|
|
411971
413245
|
customAgents,
|
|
411972
|
-
mcpHub
|
|
413246
|
+
mcpHub,
|
|
413247
|
+
outputSchema: options6.experimentalOutputSchema ? parseOutputSchema(options6.experimentalOutputSchema) : undefined
|
|
411973
413248
|
});
|
|
411974
413249
|
const renderer = new OutputRenderer(runner.state);
|
|
411975
413250
|
if (options6.streamJson) {
|
|
@@ -412047,8 +413322,7 @@ async function createLLMConfigWithVendors(program6, model2) {
|
|
|
412047
413322
|
return {
|
|
412048
413323
|
type: "vendor",
|
|
412049
413324
|
useToolCallMiddleware: options6.useToolCallMiddleware,
|
|
412050
|
-
getModel: (
|
|
412051
|
-
id: id5,
|
|
413325
|
+
getModel: () => createModel(vendorId, {
|
|
412052
413326
|
modelId,
|
|
412053
413327
|
getCredentials: vendor2.getCredentials
|
|
412054
413328
|
})
|
|
@@ -412064,8 +413338,7 @@ async function createLLMConfigWithPochi(model2) {
|
|
|
412064
413338
|
return {
|
|
412065
413339
|
type: "vendor",
|
|
412066
413340
|
useToolCallMiddleware: pochiModelOptions.useToolCallMiddleware,
|
|
412067
|
-
getModel: (
|
|
412068
|
-
id: id5,
|
|
413341
|
+
getModel: () => createModel(vendorId, {
|
|
412069
413342
|
modelId: model2,
|
|
412070
413343
|
getCredentials: vendor2.getCredentials
|
|
412071
413344
|
})
|
|
@@ -412148,3 +413421,7 @@ async function getModelFromWorkflow(options6) {
|
|
|
412148
413421
|
}
|
|
412149
413422
|
}
|
|
412150
413423
|
}
|
|
413424
|
+
function parseOutputSchema(outputSchema2) {
|
|
413425
|
+
const schema7 = Function("...args", `function getZodSchema(z) { return ${outputSchema2} }; return getZodSchema(...args);`)(v4_default);
|
|
413426
|
+
return schema7;
|
|
413427
|
+
}
|