@getpochi/cli 0.5.59 → 0.5.60

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.
Files changed (2) hide show
  1. package/dist/cli.js +764 -9
  2. 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,
@@ -350721,7 +350746,651 @@ function convertToModelMessages(messages, options) {
350721
350746
  }
350722
350747
  return modelMessages;
350723
350748
  }
350749
+ function extractReasoningContent(content) {
350750
+ const parts = content.filter((content2) => content2.type === "reasoning");
350751
+ return parts.length === 0 ? undefined : parts.map((content2) => content2.text).join(`
350752
+ `);
350753
+ }
350754
+ var noSchemaOutputStrategy = {
350755
+ type: "no-schema",
350756
+ jsonSchema: undefined,
350757
+ async validatePartialResult({ value: value2, textDelta }) {
350758
+ return { success: true, value: { partial: value2, textDelta } };
350759
+ },
350760
+ async validateFinalResult(value2, context) {
350761
+ return value2 === undefined ? {
350762
+ success: false,
350763
+ error: new NoObjectGeneratedError({
350764
+ message: "No object generated: response did not match schema.",
350765
+ text: context.text,
350766
+ response: context.response,
350767
+ usage: context.usage,
350768
+ finishReason: context.finishReason
350769
+ })
350770
+ } : { success: true, value: value2 };
350771
+ },
350772
+ createElementStream() {
350773
+ throw new UnsupportedFunctionalityError({
350774
+ functionality: "element streams in no-schema mode"
350775
+ });
350776
+ }
350777
+ };
350778
+ var objectOutputStrategy = (schema) => ({
350779
+ type: "object",
350780
+ jsonSchema: schema.jsonSchema,
350781
+ async validatePartialResult({ value: value2, textDelta }) {
350782
+ return {
350783
+ success: true,
350784
+ value: {
350785
+ partial: value2,
350786
+ textDelta
350787
+ }
350788
+ };
350789
+ },
350790
+ async validateFinalResult(value2) {
350791
+ return safeValidateTypes({ value: value2, schema });
350792
+ },
350793
+ createElementStream() {
350794
+ throw new UnsupportedFunctionalityError({
350795
+ functionality: "element streams in object mode"
350796
+ });
350797
+ }
350798
+ });
350799
+ var arrayOutputStrategy = (schema) => {
350800
+ const { $schema, ...itemSchema } = schema.jsonSchema;
350801
+ return {
350802
+ type: "enum",
350803
+ jsonSchema: {
350804
+ $schema: "http://json-schema.org/draft-07/schema#",
350805
+ type: "object",
350806
+ properties: {
350807
+ elements: { type: "array", items: itemSchema }
350808
+ },
350809
+ required: ["elements"],
350810
+ additionalProperties: false
350811
+ },
350812
+ async validatePartialResult({
350813
+ value: value2,
350814
+ latestObject,
350815
+ isFirstDelta,
350816
+ isFinalDelta
350817
+ }) {
350818
+ var _a172;
350819
+ if (!isJSONObject(value2) || !isJSONArray(value2.elements)) {
350820
+ return {
350821
+ success: false,
350822
+ error: new TypeValidationError({
350823
+ value: value2,
350824
+ cause: "value must be an object that contains an array of elements"
350825
+ })
350826
+ };
350827
+ }
350828
+ const inputArray = value2.elements;
350829
+ const resultArray = [];
350830
+ for (let i6 = 0;i6 < inputArray.length; i6++) {
350831
+ const element = inputArray[i6];
350832
+ const result2 = await safeValidateTypes({ value: element, schema });
350833
+ if (i6 === inputArray.length - 1 && !isFinalDelta) {
350834
+ continue;
350835
+ }
350836
+ if (!result2.success) {
350837
+ return result2;
350838
+ }
350839
+ resultArray.push(result2.value);
350840
+ }
350841
+ const publishedElementCount = (_a172 = latestObject == null ? undefined : latestObject.length) != null ? _a172 : 0;
350842
+ let textDelta = "";
350843
+ if (isFirstDelta) {
350844
+ textDelta += "[";
350845
+ }
350846
+ if (publishedElementCount > 0) {
350847
+ textDelta += ",";
350848
+ }
350849
+ textDelta += resultArray.slice(publishedElementCount).map((element) => JSON.stringify(element)).join(",");
350850
+ if (isFinalDelta) {
350851
+ textDelta += "]";
350852
+ }
350853
+ return {
350854
+ success: true,
350855
+ value: {
350856
+ partial: resultArray,
350857
+ textDelta
350858
+ }
350859
+ };
350860
+ },
350861
+ async validateFinalResult(value2) {
350862
+ if (!isJSONObject(value2) || !isJSONArray(value2.elements)) {
350863
+ return {
350864
+ success: false,
350865
+ error: new TypeValidationError({
350866
+ value: value2,
350867
+ cause: "value must be an object that contains an array of elements"
350868
+ })
350869
+ };
350870
+ }
350871
+ const inputArray = value2.elements;
350872
+ for (const element of inputArray) {
350873
+ const result2 = await safeValidateTypes({ value: element, schema });
350874
+ if (!result2.success) {
350875
+ return result2;
350876
+ }
350877
+ }
350878
+ return { success: true, value: inputArray };
350879
+ },
350880
+ createElementStream(originalStream) {
350881
+ let publishedElements = 0;
350882
+ return createAsyncIterableStream(originalStream.pipeThrough(new TransformStream({
350883
+ transform(chunk, controller) {
350884
+ switch (chunk.type) {
350885
+ case "object": {
350886
+ const array2 = chunk.object;
350887
+ for (;publishedElements < array2.length; publishedElements++) {
350888
+ controller.enqueue(array2[publishedElements]);
350889
+ }
350890
+ break;
350891
+ }
350892
+ case "text-delta":
350893
+ case "finish":
350894
+ case "error":
350895
+ break;
350896
+ default: {
350897
+ const _exhaustiveCheck = chunk;
350898
+ throw new Error(`Unsupported chunk type: ${_exhaustiveCheck}`);
350899
+ }
350900
+ }
350901
+ }
350902
+ })));
350903
+ }
350904
+ };
350905
+ };
350906
+ var enumOutputStrategy = (enumValues) => {
350907
+ return {
350908
+ type: "enum",
350909
+ jsonSchema: {
350910
+ $schema: "http://json-schema.org/draft-07/schema#",
350911
+ type: "object",
350912
+ properties: {
350913
+ result: { type: "string", enum: enumValues }
350914
+ },
350915
+ required: ["result"],
350916
+ additionalProperties: false
350917
+ },
350918
+ async validateFinalResult(value2) {
350919
+ if (!isJSONObject(value2) || typeof value2.result !== "string") {
350920
+ return {
350921
+ success: false,
350922
+ error: new TypeValidationError({
350923
+ value: value2,
350924
+ cause: 'value must be an object that contains a string in the "result" property.'
350925
+ })
350926
+ };
350927
+ }
350928
+ const result2 = value2.result;
350929
+ return enumValues.includes(result2) ? { success: true, value: result2 } : {
350930
+ success: false,
350931
+ error: new TypeValidationError({
350932
+ value: value2,
350933
+ cause: "value must be a string in the enum"
350934
+ })
350935
+ };
350936
+ },
350937
+ async validatePartialResult({ value: value2, textDelta }) {
350938
+ if (!isJSONObject(value2) || typeof value2.result !== "string") {
350939
+ return {
350940
+ success: false,
350941
+ error: new TypeValidationError({
350942
+ value: value2,
350943
+ cause: 'value must be an object that contains a string in the "result" property.'
350944
+ })
350945
+ };
350946
+ }
350947
+ const result2 = value2.result;
350948
+ const possibleEnumValues = enumValues.filter((enumValue) => enumValue.startsWith(result2));
350949
+ if (value2.result.length === 0 || possibleEnumValues.length === 0) {
350950
+ return {
350951
+ success: false,
350952
+ error: new TypeValidationError({
350953
+ value: value2,
350954
+ cause: "value must be a string in the enum"
350955
+ })
350956
+ };
350957
+ }
350958
+ return {
350959
+ success: true,
350960
+ value: {
350961
+ partial: possibleEnumValues.length > 1 ? result2 : possibleEnumValues[0],
350962
+ textDelta
350963
+ }
350964
+ };
350965
+ },
350966
+ createElementStream() {
350967
+ throw new UnsupportedFunctionalityError({
350968
+ functionality: "element streams in enum mode"
350969
+ });
350970
+ }
350971
+ };
350972
+ };
350973
+ function getOutputStrategy({
350974
+ output,
350975
+ schema,
350976
+ enumValues
350977
+ }) {
350978
+ switch (output) {
350979
+ case "object":
350980
+ return objectOutputStrategy(asSchema(schema));
350981
+ case "array":
350982
+ return arrayOutputStrategy(asSchema(schema));
350983
+ case "enum":
350984
+ return enumOutputStrategy(enumValues);
350985
+ case "no-schema":
350986
+ return noSchemaOutputStrategy;
350987
+ default: {
350988
+ const _exhaustiveCheck = output;
350989
+ throw new Error(`Unsupported output: ${_exhaustiveCheck}`);
350990
+ }
350991
+ }
350992
+ }
350993
+ async function parseAndValidateObjectResult(result2, outputStrategy, context) {
350994
+ const parseResult = await safeParseJSON({ text: result2 });
350995
+ if (!parseResult.success) {
350996
+ throw new NoObjectGeneratedError({
350997
+ message: "No object generated: could not parse the response.",
350998
+ cause: parseResult.error,
350999
+ text: result2,
351000
+ response: context.response,
351001
+ usage: context.usage,
351002
+ finishReason: context.finishReason
351003
+ });
351004
+ }
351005
+ const validationResult = await outputStrategy.validateFinalResult(parseResult.value, {
351006
+ text: result2,
351007
+ response: context.response,
351008
+ usage: context.usage
351009
+ });
351010
+ if (!validationResult.success) {
351011
+ throw new NoObjectGeneratedError({
351012
+ message: "No object generated: response did not match schema.",
351013
+ cause: validationResult.error,
351014
+ text: result2,
351015
+ response: context.response,
351016
+ usage: context.usage,
351017
+ finishReason: context.finishReason
351018
+ });
351019
+ }
351020
+ return validationResult.value;
351021
+ }
351022
+ async function parseAndValidateObjectResultWithRepair(result2, outputStrategy, repairText, context) {
351023
+ try {
351024
+ return await parseAndValidateObjectResult(result2, outputStrategy, context);
351025
+ } catch (error40) {
351026
+ if (repairText != null && NoObjectGeneratedError.isInstance(error40) && (JSONParseError.isInstance(error40.cause) || TypeValidationError.isInstance(error40.cause))) {
351027
+ const repairedText = await repairText({
351028
+ text: result2,
351029
+ error: error40.cause
351030
+ });
351031
+ if (repairedText === null) {
351032
+ throw error40;
351033
+ }
351034
+ return await parseAndValidateObjectResult(repairedText, outputStrategy, context);
351035
+ }
351036
+ throw error40;
351037
+ }
351038
+ }
351039
+ function validateObjectGenerationInput({
351040
+ output,
351041
+ schema,
351042
+ schemaName,
351043
+ schemaDescription,
351044
+ enumValues
351045
+ }) {
351046
+ if (output != null && output !== "object" && output !== "array" && output !== "enum" && output !== "no-schema") {
351047
+ throw new InvalidArgumentError2({
351048
+ parameter: "output",
351049
+ value: output,
351050
+ message: "Invalid output type."
351051
+ });
351052
+ }
351053
+ if (output === "no-schema") {
351054
+ if (schema != null) {
351055
+ throw new InvalidArgumentError2({
351056
+ parameter: "schema",
351057
+ value: schema,
351058
+ message: "Schema is not supported for no-schema output."
351059
+ });
351060
+ }
351061
+ if (schemaDescription != null) {
351062
+ throw new InvalidArgumentError2({
351063
+ parameter: "schemaDescription",
351064
+ value: schemaDescription,
351065
+ message: "Schema description is not supported for no-schema output."
351066
+ });
351067
+ }
351068
+ if (schemaName != null) {
351069
+ throw new InvalidArgumentError2({
351070
+ parameter: "schemaName",
351071
+ value: schemaName,
351072
+ message: "Schema name is not supported for no-schema output."
351073
+ });
351074
+ }
351075
+ if (enumValues != null) {
351076
+ throw new InvalidArgumentError2({
351077
+ parameter: "enumValues",
351078
+ value: enumValues,
351079
+ message: "Enum values are not supported for no-schema output."
351080
+ });
351081
+ }
351082
+ }
351083
+ if (output === "object") {
351084
+ if (schema == null) {
351085
+ throw new InvalidArgumentError2({
351086
+ parameter: "schema",
351087
+ value: schema,
351088
+ message: "Schema is required for object output."
351089
+ });
351090
+ }
351091
+ if (enumValues != null) {
351092
+ throw new InvalidArgumentError2({
351093
+ parameter: "enumValues",
351094
+ value: enumValues,
351095
+ message: "Enum values are not supported for object output."
351096
+ });
351097
+ }
351098
+ }
351099
+ if (output === "array") {
351100
+ if (schema == null) {
351101
+ throw new InvalidArgumentError2({
351102
+ parameter: "schema",
351103
+ value: schema,
351104
+ message: "Element schema is required for array output."
351105
+ });
351106
+ }
351107
+ if (enumValues != null) {
351108
+ throw new InvalidArgumentError2({
351109
+ parameter: "enumValues",
351110
+ value: enumValues,
351111
+ message: "Enum values are not supported for array output."
351112
+ });
351113
+ }
351114
+ }
351115
+ if (output === "enum") {
351116
+ if (schema != null) {
351117
+ throw new InvalidArgumentError2({
351118
+ parameter: "schema",
351119
+ value: schema,
351120
+ message: "Schema is not supported for enum output."
351121
+ });
351122
+ }
351123
+ if (schemaDescription != null) {
351124
+ throw new InvalidArgumentError2({
351125
+ parameter: "schemaDescription",
351126
+ value: schemaDescription,
351127
+ message: "Schema description is not supported for enum output."
351128
+ });
351129
+ }
351130
+ if (schemaName != null) {
351131
+ throw new InvalidArgumentError2({
351132
+ parameter: "schemaName",
351133
+ value: schemaName,
351134
+ message: "Schema name is not supported for enum output."
351135
+ });
351136
+ }
351137
+ if (enumValues == null) {
351138
+ throw new InvalidArgumentError2({
351139
+ parameter: "enumValues",
351140
+ value: enumValues,
351141
+ message: "Enum values are required for enum output."
351142
+ });
351143
+ }
351144
+ for (const value2 of enumValues) {
351145
+ if (typeof value2 !== "string") {
351146
+ throw new InvalidArgumentError2({
351147
+ parameter: "enumValues",
351148
+ value: value2,
351149
+ message: "Enum values must be strings."
351150
+ });
351151
+ }
351152
+ }
351153
+ }
351154
+ }
350724
351155
  var originalGenerateId3 = createIdGenerator({ prefix: "aiobj", size: 24 });
351156
+ async function generateObject(options) {
351157
+ const {
351158
+ model: modelArg,
351159
+ output = "object",
351160
+ system,
351161
+ prompt,
351162
+ messages,
351163
+ maxRetries: maxRetriesArg,
351164
+ abortSignal,
351165
+ headers,
351166
+ experimental_repairText: repairText,
351167
+ experimental_telemetry: telemetry,
351168
+ experimental_download: download2,
351169
+ providerOptions,
351170
+ _internal: {
351171
+ generateId: generateId3 = originalGenerateId3,
351172
+ currentDate = () => /* @__PURE__ */ new Date
351173
+ } = {},
351174
+ ...settings
351175
+ } = options;
351176
+ const model = resolveLanguageModel(modelArg);
351177
+ const enumValues = "enum" in options ? options.enum : undefined;
351178
+ const {
351179
+ schema: inputSchema,
351180
+ schemaDescription,
351181
+ schemaName
351182
+ } = "schema" in options ? options : {};
351183
+ validateObjectGenerationInput({
351184
+ output,
351185
+ schema: inputSchema,
351186
+ schemaName,
351187
+ schemaDescription,
351188
+ enumValues
351189
+ });
351190
+ const { maxRetries, retry } = prepareRetries({
351191
+ maxRetries: maxRetriesArg,
351192
+ abortSignal
351193
+ });
351194
+ const outputStrategy = getOutputStrategy({
351195
+ output,
351196
+ schema: inputSchema,
351197
+ enumValues
351198
+ });
351199
+ const callSettings = prepareCallSettings(settings);
351200
+ const headersWithUserAgent = withUserAgentSuffix(headers != null ? headers : {}, `ai/${VERSION3}`);
351201
+ const baseTelemetryAttributes = getBaseTelemetryAttributes({
351202
+ model,
351203
+ telemetry,
351204
+ headers: headersWithUserAgent,
351205
+ settings: { ...callSettings, maxRetries }
351206
+ });
351207
+ const tracer = getTracer(telemetry);
351208
+ try {
351209
+ return await recordSpan({
351210
+ name: "ai.generateObject",
351211
+ attributes: selectTelemetryAttributes({
351212
+ telemetry,
351213
+ attributes: {
351214
+ ...assembleOperationName({
351215
+ operationId: "ai.generateObject",
351216
+ telemetry
351217
+ }),
351218
+ ...baseTelemetryAttributes,
351219
+ "ai.prompt": {
351220
+ input: () => JSON.stringify({ system, prompt, messages })
351221
+ },
351222
+ "ai.schema": outputStrategy.jsonSchema != null ? { input: () => JSON.stringify(outputStrategy.jsonSchema) } : undefined,
351223
+ "ai.schema.name": schemaName,
351224
+ "ai.schema.description": schemaDescription,
351225
+ "ai.settings.output": outputStrategy.type
351226
+ }
351227
+ }),
351228
+ tracer,
351229
+ fn: async (span) => {
351230
+ var _a172;
351231
+ let result2;
351232
+ let finishReason;
351233
+ let usage;
351234
+ let warnings;
351235
+ let response;
351236
+ let request;
351237
+ let resultProviderMetadata;
351238
+ let reasoning;
351239
+ const standardizedPrompt = await standardizePrompt({
351240
+ system,
351241
+ prompt,
351242
+ messages
351243
+ });
351244
+ const promptMessages = await convertToLanguageModelPrompt({
351245
+ prompt: standardizedPrompt,
351246
+ supportedUrls: await model.supportedUrls,
351247
+ download: download2
351248
+ });
351249
+ const generateResult = await retry(() => recordSpan({
351250
+ name: "ai.generateObject.doGenerate",
351251
+ attributes: selectTelemetryAttributes({
351252
+ telemetry,
351253
+ attributes: {
351254
+ ...assembleOperationName({
351255
+ operationId: "ai.generateObject.doGenerate",
351256
+ telemetry
351257
+ }),
351258
+ ...baseTelemetryAttributes,
351259
+ "ai.prompt.messages": {
351260
+ input: () => stringifyForTelemetry(promptMessages)
351261
+ },
351262
+ "gen_ai.system": model.provider,
351263
+ "gen_ai.request.model": model.modelId,
351264
+ "gen_ai.request.frequency_penalty": callSettings.frequencyPenalty,
351265
+ "gen_ai.request.max_tokens": callSettings.maxOutputTokens,
351266
+ "gen_ai.request.presence_penalty": callSettings.presencePenalty,
351267
+ "gen_ai.request.temperature": callSettings.temperature,
351268
+ "gen_ai.request.top_k": callSettings.topK,
351269
+ "gen_ai.request.top_p": callSettings.topP
351270
+ }
351271
+ }),
351272
+ tracer,
351273
+ fn: async (span2) => {
351274
+ var _a18, _b8, _c, _d, _e, _f, _g, _h;
351275
+ const result22 = await model.doGenerate({
351276
+ responseFormat: {
351277
+ type: "json",
351278
+ schema: outputStrategy.jsonSchema,
351279
+ name: schemaName,
351280
+ description: schemaDescription
351281
+ },
351282
+ ...prepareCallSettings(settings),
351283
+ prompt: promptMessages,
351284
+ providerOptions,
351285
+ abortSignal,
351286
+ headers: headersWithUserAgent
351287
+ });
351288
+ const responseData = {
351289
+ id: (_b8 = (_a18 = result22.response) == null ? undefined : _a18.id) != null ? _b8 : generateId3(),
351290
+ timestamp: (_d = (_c = result22.response) == null ? undefined : _c.timestamp) != null ? _d : currentDate(),
351291
+ modelId: (_f = (_e = result22.response) == null ? undefined : _e.modelId) != null ? _f : model.modelId,
351292
+ headers: (_g = result22.response) == null ? undefined : _g.headers,
351293
+ body: (_h = result22.response) == null ? undefined : _h.body
351294
+ };
351295
+ const text2 = extractTextContent(result22.content);
351296
+ const reasoning2 = extractReasoningContent(result22.content);
351297
+ if (text2 === undefined) {
351298
+ throw new NoObjectGeneratedError({
351299
+ message: "No object generated: the model did not return a response.",
351300
+ response: responseData,
351301
+ usage: result22.usage,
351302
+ finishReason: result22.finishReason
351303
+ });
351304
+ }
351305
+ span2.setAttributes(selectTelemetryAttributes({
351306
+ telemetry,
351307
+ attributes: {
351308
+ "ai.response.finishReason": result22.finishReason,
351309
+ "ai.response.object": { output: () => text2 },
351310
+ "ai.response.id": responseData.id,
351311
+ "ai.response.model": responseData.modelId,
351312
+ "ai.response.timestamp": responseData.timestamp.toISOString(),
351313
+ "ai.response.providerMetadata": JSON.stringify(result22.providerMetadata),
351314
+ "ai.usage.promptTokens": result22.usage.inputTokens,
351315
+ "ai.usage.completionTokens": result22.usage.outputTokens,
351316
+ "gen_ai.response.finish_reasons": [result22.finishReason],
351317
+ "gen_ai.response.id": responseData.id,
351318
+ "gen_ai.response.model": responseData.modelId,
351319
+ "gen_ai.usage.input_tokens": result22.usage.inputTokens,
351320
+ "gen_ai.usage.output_tokens": result22.usage.outputTokens
351321
+ }
351322
+ }));
351323
+ return {
351324
+ ...result22,
351325
+ objectText: text2,
351326
+ reasoning: reasoning2,
351327
+ responseData
351328
+ };
351329
+ }
351330
+ }));
351331
+ result2 = generateResult.objectText;
351332
+ finishReason = generateResult.finishReason;
351333
+ usage = generateResult.usage;
351334
+ warnings = generateResult.warnings;
351335
+ resultProviderMetadata = generateResult.providerMetadata;
351336
+ request = (_a172 = generateResult.request) != null ? _a172 : {};
351337
+ response = generateResult.responseData;
351338
+ reasoning = generateResult.reasoning;
351339
+ logWarnings(warnings);
351340
+ const object2 = await parseAndValidateObjectResultWithRepair(result2, outputStrategy, repairText, {
351341
+ response,
351342
+ usage,
351343
+ finishReason
351344
+ });
351345
+ span.setAttributes(selectTelemetryAttributes({
351346
+ telemetry,
351347
+ attributes: {
351348
+ "ai.response.finishReason": finishReason,
351349
+ "ai.response.object": {
351350
+ output: () => JSON.stringify(object2)
351351
+ },
351352
+ "ai.response.providerMetadata": JSON.stringify(resultProviderMetadata),
351353
+ "ai.usage.promptTokens": usage.inputTokens,
351354
+ "ai.usage.completionTokens": usage.outputTokens
351355
+ }
351356
+ }));
351357
+ return new DefaultGenerateObjectResult({
351358
+ object: object2,
351359
+ reasoning,
351360
+ finishReason,
351361
+ usage,
351362
+ warnings,
351363
+ request,
351364
+ response,
351365
+ providerMetadata: resultProviderMetadata
351366
+ });
351367
+ }
351368
+ });
351369
+ } catch (error40) {
351370
+ throw wrapGatewayError(error40);
351371
+ }
351372
+ }
351373
+ var DefaultGenerateObjectResult = class {
351374
+ constructor(options) {
351375
+ this.object = options.object;
351376
+ this.finishReason = options.finishReason;
351377
+ this.usage = options.usage;
351378
+ this.warnings = options.warnings;
351379
+ this.providerMetadata = options.providerMetadata;
351380
+ this.response = options.response;
351381
+ this.request = options.request;
351382
+ this.reasoning = options.reasoning;
351383
+ }
351384
+ toJsonResponse(init) {
351385
+ var _a172;
351386
+ return new Response(JSON.stringify(this.object), {
351387
+ status: (_a172 = init == null ? undefined : init.status) != null ? _a172 : 200,
351388
+ headers: prepareHeaders(init == null ? undefined : init.headers, {
351389
+ "content-type": "application/json; charset=utf-8"
351390
+ })
351391
+ });
351392
+ }
351393
+ };
350725
351394
  var SerialJobExecutor = class {
350726
351395
  constructor() {
350727
351396
  this.queue = [];
@@ -352096,15 +352765,16 @@ Use this tool in the following scenarios:
352096
352765
  var askFollowupQuestion = tool(toolDef2);
352097
352766
 
352098
352767
  // ../tools/src/attempt-completion.ts
352768
+ var attemptCompletionSchema = exports_external2.object({
352769
+ 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."),
352770
+ command: exports_external2.string().optional().describe("A CLI command to execute to show a live demo of the result to the user.")
352771
+ });
352099
352772
  var toolDef3 = {
352100
352773
  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
352774
 
352102
352775
  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
352776
  `.trim(),
352104
- inputSchema: exports_external2.object({
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
- }),
352777
+ inputSchema: attemptCompletionSchema,
352108
352778
  outputSchema: exports_external2.object({
352109
352779
  success: exports_external2.boolean().describe("Indicates whether the completion was successful.")
352110
352780
  })
@@ -367770,7 +368440,7 @@ var {
367770
368440
  // package.json
367771
368441
  var package_default = {
367772
368442
  name: "@getpochi/cli",
367773
- version: "0.5.59",
368443
+ version: "0.5.60",
367774
368444
  type: "module",
367775
368445
  bin: {
367776
368446
  pochi: "src/cli.ts"
@@ -367814,7 +368484,8 @@ var package_default = {
367814
368484
  omelette: "^0.4.17",
367815
368485
  ora: "^8.2.0",
367816
368486
  remeda: "catalog:",
367817
- semver: "^7.6.3"
368487
+ semver: "^7.6.3",
368488
+ zod: "catalog:"
367818
368489
  }
367819
368490
  };
367820
368491
 
@@ -410199,6 +410870,77 @@ function createStopWordStream(stop3) {
410199
410870
  }
410200
410871
  });
410201
410872
  }
410873
+ // ../livekit/src/chat/middlewares/output-schema-middleware.ts
410874
+ function createOutputSchemaMiddleware(outputSchema2) {
410875
+ return {
410876
+ middlewareVersion: "v2",
410877
+ wrapStream: async ({ doStream, model: model2 }) => {
410878
+ const { stream: stream12, ...rest } = await doStream();
410879
+ let toolCallId = "";
410880
+ const transformedStream = stream12.pipeThrough(new TransformStream({
410881
+ async transform(chunk4, controller) {
410882
+ if (chunk4.type === "tool-input-start" && chunk4.toolName === "attemptCompletion") {
410883
+ toolCallId = chunk4.id;
410884
+ return;
410885
+ }
410886
+ if (chunk4.type === "tool-input-delta" && chunk4.id === toolCallId) {
410887
+ return;
410888
+ }
410889
+ if (chunk4.type === "tool-call" && chunk4.toolName === "attemptCompletion" && (chunk4.toolCallId === toolCallId || toolCallId === "")) {
410890
+ const parsedResult = await safeParseJSON({
410891
+ text: chunk4.input,
410892
+ schema: attemptCompletionSchema
410893
+ });
410894
+ if (!parsedResult.success) {
410895
+ throw new InvalidToolInputError({
410896
+ toolName: chunk4.toolName,
410897
+ toolInput: chunk4.input,
410898
+ cause: parsedResult.error
410899
+ });
410900
+ }
410901
+ const { result: result2 } = parsedResult.value;
410902
+ const newInput = {
410903
+ ...parsedResult.value,
410904
+ result: await ensureOutputSchema(model2, outputSchema2, result2)
410905
+ };
410906
+ controller.enqueue({
410907
+ ...chunk4,
410908
+ input: JSON.stringify(newInput)
410909
+ });
410910
+ toolCallId = "";
410911
+ return;
410912
+ }
410913
+ controller.enqueue(chunk4);
410914
+ }
410915
+ }));
410916
+ return {
410917
+ stream: transformedStream,
410918
+ ...rest
410919
+ };
410920
+ }
410921
+ };
410922
+ }
410923
+ async function ensureOutputSchema(model2, schema7, content3) {
410924
+ try {
410925
+ const { object: object4 } = await generateObject({
410926
+ model: model2,
410927
+ schema: schema7,
410928
+ prompt: [
410929
+ "The model is trying to generate object with following schema:",
410930
+ JSON.stringify(v4_default.toJSONSchema(schema7)),
410931
+ "Current input is",
410932
+ content3,
410933
+ "Please fix the inputs."
410934
+ ].join(`
410935
+ `),
410936
+ maxRetries: 0
410937
+ });
410938
+ return JSON.stringify(object4);
410939
+ } catch (err2) {
410940
+ return content3;
410941
+ }
410942
+ }
410943
+
410202
410944
  // ../livekit/src/chat/models/ai-gateway.ts
410203
410945
  function createAiGatewayModel(llm) {
410204
410946
  const gateway2 = createGatewayProvider({
@@ -410479,6 +411221,7 @@ class FlexibleChatTransport {
410479
411221
  isCli;
410480
411222
  store;
410481
411223
  customAgent;
411224
+ outputSchema;
410482
411225
  constructor(options6) {
410483
411226
  this.onStart = options6.onStart;
410484
411227
  this.getters = options6.getters;
@@ -410486,6 +411229,7 @@ class FlexibleChatTransport {
410486
411229
  this.isCli = options6.isCli;
410487
411230
  this.store = options6.store;
410488
411231
  this.customAgent = overrideCustomAgentTools(options6.customAgent);
411232
+ this.outputSchema = options6.outputSchema;
410489
411233
  }
410490
411234
  sendMessages = async ({
410491
411235
  chatId,
@@ -410509,6 +411253,9 @@ class FlexibleChatTransport {
410509
411253
  if ("modelId" in llm && isWellKnownReasoningModel(llm.modelId)) {
410510
411254
  middlewares.push(createReasoningMiddleware());
410511
411255
  }
411256
+ if (this.outputSchema) {
411257
+ middlewares.push(createOutputSchemaMiddleware(this.outputSchema));
411258
+ }
410512
411259
  if (llm.useToolCallMiddleware) {
410513
411260
  middlewares.push(createToolCallMiddleware());
410514
411261
  }
@@ -410637,6 +411384,7 @@ class LiveChatKit {
410637
411384
  isSubTask,
410638
411385
  isCli,
410639
411386
  customAgent,
411387
+ outputSchema: outputSchema2,
410640
411388
  ...chatInit
410641
411389
  }) {
410642
411390
  this.taskId = taskId;
@@ -410647,7 +411395,8 @@ class LiveChatKit {
410647
411395
  getters,
410648
411396
  isSubTask,
410649
411397
  isCli,
410650
- customAgent
411398
+ customAgent,
411399
+ outputSchema: outputSchema2
410651
411400
  });
410652
411401
  this.chat = new (makeChatWithHookClass(store, chatClass))({
410653
411402
  ...chatInit,
@@ -411487,6 +412236,7 @@ class TaskRunner {
411487
412236
  isCli: true,
411488
412237
  isSubTask: options6.isSubTask,
411489
412238
  customAgent: options6.customAgent,
412239
+ outputSchema: options6.outputSchema,
411490
412240
  getters: {
411491
412241
  getLLM: () => options6.llm,
411492
412242
  getEnvironment: async () => ({
@@ -411936,7 +412686,7 @@ var parsePositiveInt = (input2) => {
411936
412686
  }
411937
412687
  return result2;
411938
412688
  };
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) => {
412689
+ 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
412690
  const { uid, prompt: prompt3 } = await parseTaskInput(options6, program5);
411941
412691
  const store = await createStore3();
411942
412692
  const llm = await createLLMConfig(program5, options6);
@@ -411969,7 +412719,8 @@ var program5 = new Command().name("pochi").description(`${source_default.bold("P
411969
412719
  maxRetries: options6.maxRetries,
411970
412720
  onSubTaskCreated,
411971
412721
  customAgents,
411972
- mcpHub
412722
+ mcpHub,
412723
+ outputSchema: options6.experimentalOutputSchema ? parseOutputSchema(options6.experimentalOutputSchema) : undefined
411973
412724
  });
411974
412725
  const renderer = new OutputRenderer(runner.state);
411975
412726
  if (options6.streamJson) {
@@ -412148,3 +412899,7 @@ async function getModelFromWorkflow(options6) {
412148
412899
  }
412149
412900
  }
412150
412901
  }
412902
+ function parseOutputSchema(outputSchema2) {
412903
+ const schema7 = Function("...args", `function getZodSchema(z) { return ${outputSchema2} }; return getZodSchema(...args);`)(v4_default);
412904
+ return schema7;
412905
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getpochi/cli",
3
- "version": "0.5.59",
3
+ "version": "0.5.60",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "pochi": "dist/cli.js"
@@ -44,6 +44,7 @@
44
44
  "omelette": "^0.4.17",
45
45
  "ora": "^8.2.0",
46
46
  "remeda": "^2.21.3",
47
- "semver": "^7.6.3"
47
+ "semver": "^7.6.3",
48
+ "zod": "^3.25.76"
48
49
  }
49
50
  }