assistme 0.6.6 → 0.6.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -3875,11 +3875,11 @@ var SELF_ANALYSIS_OUTPUT_FORMAT = {
3875
3875
  type: "object",
3876
3876
  properties: {
3877
3877
  session_logs_useful: { type: "boolean" },
3878
- session_logs_gaps: { type: ["string", "null"] },
3878
+ session_logs_gaps: { type: "string" },
3879
3879
  message_events_useful: { type: "boolean" },
3880
- message_events_gaps: { type: ["string", "null"] },
3880
+ message_events_gaps: { type: "string" },
3881
3881
  conversation_context_useful: { type: "boolean" },
3882
- conversation_context_gaps: { type: ["string", "null"] }
3882
+ conversation_context_gaps: { type: "string" }
3883
3883
  },
3884
3884
  required: [
3885
3885
  "session_logs_useful",
@@ -4106,6 +4106,13 @@ ${dataQualityNotes}
4106
4106
  }
4107
4107
  }
4108
4108
  async function runAnalysisQuery(model, prompt) {
4109
+ const result = await attemptQuery(model, prompt, SELF_ANALYSIS_OUTPUT_FORMAT);
4110
+ if (result) return result;
4111
+ log.info("Self-analysis: retrying without structured output (fallback)");
4112
+ const fallbackResult = await attemptQuery(model, prompt, void 0);
4113
+ return fallbackResult;
4114
+ }
4115
+ async function attemptQuery(model, prompt, outputFormat) {
4109
4116
  let structuredOutput;
4110
4117
  for await (const message of query2({
4111
4118
  prompt,
@@ -4114,7 +4121,7 @@ async function runAnalysisQuery(model, prompt) {
4114
4121
  maxTurns: 10,
4115
4122
  allowedTools: [],
4116
4123
  effort: "medium",
4117
- outputFormat: SELF_ANALYSIS_OUTPUT_FORMAT
4124
+ ...outputFormat ? { outputFormat } : {}
4118
4125
  }
4119
4126
  })) {
4120
4127
  if (message.type === "result") {
@@ -4126,9 +4133,16 @@ async function runAnalysisQuery(model, prompt) {
4126
4133
  `Self-analysis cost: $${successMsg.total_cost_usd.toFixed(4)}`
4127
4134
  );
4128
4135
  if (!structuredOutput) {
4129
- log.warn(
4130
- `Self-analysis: success but no structured_output. result text: ${String(successMsg.result ?? "").slice(0, 500)}`
4131
- );
4136
+ const text = String(successMsg.result ?? "");
4137
+ const parsed = tryParseJson(text);
4138
+ if (parsed) {
4139
+ log.info("Self-analysis: parsed JSON from text result");
4140
+ structuredOutput = parsed;
4141
+ } else {
4142
+ log.warn(
4143
+ `Self-analysis: success but no structured_output. result text: ${text.slice(0, 500)}`
4144
+ );
4145
+ }
4132
4146
  }
4133
4147
  } else {
4134
4148
  log.warn(
@@ -4139,6 +4153,15 @@ async function runAnalysisQuery(model, prompt) {
4139
4153
  }
4140
4154
  return structuredOutput;
4141
4155
  }
4156
+ function tryParseJson(text) {
4157
+ const jsonMatch = text.match(/```(?:json)?\s*([\s\S]*?)```/) || text.match(/(\{[\s\S]*\})/);
4158
+ if (!jsonMatch) return null;
4159
+ try {
4160
+ return JSON.parse(jsonMatch[1]);
4161
+ } catch {
4162
+ return null;
4163
+ }
4164
+ }
4142
4165
  async function analyzeSelfPostTask(opts) {
4143
4166
  const {
4144
4167
  model,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "assistme",
3
- "version": "0.6.6",
3
+ "version": "0.6.7",
4
4
  "description": "AssistMe CLI Agent - AI-powered assistant that controls your real browser",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -65,11 +65,11 @@ const SELF_ANALYSIS_OUTPUT_FORMAT: OutputFormat = {
65
65
  type: "object",
66
66
  properties: {
67
67
  session_logs_useful: { type: "boolean" },
68
- session_logs_gaps: { type: ["string", "null"] },
68
+ session_logs_gaps: { type: "string" },
69
69
  message_events_useful: { type: "boolean" },
70
- message_events_gaps: { type: ["string", "null"] },
70
+ message_events_gaps: { type: "string" },
71
71
  conversation_context_useful: { type: "boolean" },
72
- conversation_context_gaps: { type: ["string", "null"] },
72
+ conversation_context_gaps: { type: "string" },
73
73
  },
74
74
  required: [
75
75
  "session_logs_useful",
@@ -348,6 +348,21 @@ async function submitSelfAnalysisFeedback(analysis: SelfAnalysisResult): Promise
348
348
  // ── Query Runner ────────────────────────────────────────────────
349
349
 
350
350
  async function runAnalysisQuery(model: string, prompt: string): Promise<unknown> {
351
+ // First attempt: structured output
352
+ const result = await attemptQuery(model, prompt, SELF_ANALYSIS_OUTPUT_FORMAT);
353
+ if (result) return result;
354
+
355
+ // Fallback: no structured output, parse JSON from text response
356
+ log.info("Self-analysis: retrying without structured output (fallback)");
357
+ const fallbackResult = await attemptQuery(model, prompt, undefined);
358
+ return fallbackResult;
359
+ }
360
+
361
+ async function attemptQuery(
362
+ model: string,
363
+ prompt: string,
364
+ outputFormat: OutputFormat | undefined
365
+ ): Promise<unknown> {
351
366
  let structuredOutput: unknown;
352
367
 
353
368
  // Use independent query() instead of session resume to avoid
@@ -359,7 +374,7 @@ async function runAnalysisQuery(model: string, prompt: string): Promise<unknown>
359
374
  maxTurns: 10,
360
375
  allowedTools: [],
361
376
  effort: "medium",
362
- outputFormat: SELF_ANALYSIS_OUTPUT_FORMAT,
377
+ ...(outputFormat ? { outputFormat } : {}),
363
378
  },
364
379
  })) {
365
380
  if (message.type === "result") {
@@ -371,10 +386,17 @@ async function runAnalysisQuery(model: string, prompt: string): Promise<unknown>
371
386
  `Self-analysis cost: $${successMsg.total_cost_usd.toFixed(4)}`
372
387
  );
373
388
  if (!structuredOutput) {
374
- // structured_output can be undefined even on success log the text result
375
- log.warn(
376
- `Self-analysis: success but no structured_output. result text: ${String((successMsg as any).result ?? "").slice(0, 500)}`
377
- );
389
+ // Try to parse JSON from text result as fallback
390
+ const text = String((successMsg as any).result ?? "");
391
+ const parsed = tryParseJson(text);
392
+ if (parsed) {
393
+ log.info("Self-analysis: parsed JSON from text result");
394
+ structuredOutput = parsed;
395
+ } else {
396
+ log.warn(
397
+ `Self-analysis: success but no structured_output. result text: ${text.slice(0, 500)}`
398
+ );
399
+ }
378
400
  }
379
401
  } else {
380
402
  log.warn(
@@ -387,6 +409,17 @@ async function runAnalysisQuery(model: string, prompt: string): Promise<unknown>
387
409
  return structuredOutput;
388
410
  }
389
411
 
412
+ function tryParseJson(text: string): unknown {
413
+ // Extract JSON from text that may contain markdown code fences
414
+ const jsonMatch = text.match(/```(?:json)?\s*([\s\S]*?)```/) || text.match(/(\{[\s\S]*\})/);
415
+ if (!jsonMatch) return null;
416
+ try {
417
+ return JSON.parse(jsonMatch[1]);
418
+ } catch {
419
+ return null;
420
+ }
421
+ }
422
+
390
423
  // ── Main Entry Point ────────────────────────────────────────────
391
424
 
392
425
  /**