@method-ai-hq/sdk 0.15.1 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/README.md +1 -1
  2. package/dist/packages/method-document/src/conversion-report.d.ts +2 -2
  3. package/dist/packages/sdk/examples/outbound-management/README.md +1 -1
  4. package/dist/packages/sdk/examples/outbound-management/outbound.method +3 -3
  5. package/dist/packages/sdk/examples/social-briefing/README.md +1 -1
  6. package/dist/packages/sdk/examples/social-briefing/social-briefing.method +1 -1
  7. package/dist/packages/sdk/package.json +2 -2
  8. package/dist/packages/sdk/src/authoring-instructions.d.ts +2 -2
  9. package/dist/packages/sdk/src/authoring-instructions.js +2 -2
  10. package/dist/packages/sdk/src/current-inspection.d.ts +2 -0
  11. package/dist/packages/sdk/src/current-inspection.js +26 -17
  12. package/dist/packages/sdk/src/current-runtime.js +6 -2
  13. package/dist/packages/sdk/src/failure.d.ts +11 -0
  14. package/dist/packages/sdk/src/failure.js +25 -0
  15. package/dist/packages/sdk/src/improve.d.ts +7 -4
  16. package/dist/packages/sdk/src/improve.js +11 -17
  17. package/dist/packages/sdk/src/inspect.js +1 -1
  18. package/dist/packages/sdk/src/judge.d.ts +20 -0
  19. package/dist/packages/sdk/src/judge.js +59 -0
  20. package/dist/packages/sdk/src/method-help.d.ts +1 -1
  21. package/dist/packages/sdk/src/method-help.js +9 -8
  22. package/dist/packages/sdk/src/method-sync.js +3 -4
  23. package/dist/packages/sdk/src/method.d.ts +0 -2
  24. package/dist/packages/sdk/src/method.js +8 -10
  25. package/dist/packages/sdk/src/model-checks.d.ts +18 -1
  26. package/dist/packages/sdk/src/model-checks.js +67 -7
  27. package/dist/packages/sdk/src/production.js +1 -1
  28. package/dist/packages/sdk/src/proposals.d.ts +4 -4
  29. package/dist/packages/sdk/src/proposals.js +29 -50
  30. package/dist/packages/sdk/src/run-saved.d.ts +1 -1
  31. package/dist/packages/sdk/src/run-saved.js +4 -2
  32. package/dist/packages/sdk/src/run-worker.js +10 -1
  33. package/dist/packages/sdk/src/worker.js +4 -3
  34. package/dist/packages/workflow-language/src/inspection.d.ts +272 -138
  35. package/dist/packages/workflow-language/src/inspection.js +30 -10
  36. package/package.json +2 -2
@@ -2,7 +2,24 @@ import { AttachedFileSchema, MAX_RESULT_FILES } from "./result-files.js";
2
2
  import { z } from "zod";
3
3
  import { JsonSchema, WorkflowSchema, effectiveOutputs, executionText } from "./schema.js";
4
4
  import { producers, references, referenceShape } from "./validate.js";
5
- export const FailureSchema = z.strictObject({ phase: z.enum(["environment", "input", "action", "check", "change"]), expected: z.string(), observed: z.string(), evidence: z.array(z.string()) });
5
+ export const FailureOwnerSchema = z.enum(["method_code", "agent_work", "outside_service", "limit", "setup", "needs_you", "method_platform"]);
6
+ /** The runtime's failure record of a run that stopped: whose problem it is, where in the Method, and the next action. */
7
+ export const FailureSchema = z.strictObject({
8
+ owner: FailureOwnerSchema, code: z.string(), headline: z.string(),
9
+ step: z.string().nullable(), step_name: z.string().nullable(),
10
+ iteration: z.number().int().nonnegative().nullable(), failed_iterations: z.array(z.number().int().nonnegative()), total: z.number().int().nonnegative().nullable(),
11
+ phase: z.enum(["action", "check", "effect", "tool", "setup"]).nullable(), check_name: z.string().nullable(),
12
+ next: z.strictObject({ action: z.enum(["fix_method", "run_again", "raise_limit", "fix_setup", "answer", "report_bug"]), text: z.string(), command: z.string().optional() }),
13
+ // Run content. The device form of a run record (deviceOnly) has no evidence, details, or diagnostics.
14
+ evidence: z.array(z.string()).optional(), details: z.string().optional(), diagnostics: z.string().optional(),
15
+ });
16
+ const ownerTexts = {
17
+ method_code: "Problem in the Method's code", agent_work: "The agent's work did not pass", outside_service: "A service outside Method",
18
+ limit: "A limit was reached", setup: "Your setup", needs_you: "Needs your answer", method_platform: "A problem in Method",
19
+ };
20
+ /** Whose problem a failure is, in a few plain words. */
21
+ export function ownerText(owner) { return ownerTexts[owner]; }
22
+ export const RunStatusSchema = z.enum(["running", "waiting_for_you", "succeeded", "unconfirmed", "failed"]);
6
23
  // What a script process was seen to do (runtime observed_effects): hosts, paths, variable names, and program names.
7
24
  const observedList = z.array(z.string()).max(200);
8
25
  export const ObservedEffectsSchema = z.union([
@@ -19,20 +36,22 @@ export const RunEventSchema = z.strictObject({
19
36
  tool: z.string().optional(), call_id: z.string().optional(), command: z.string().optional(),
20
37
  exit_code: z.number().int().nullable().optional(), diagnostics: z.string().optional(),
21
38
  child: z.string().max(100).optional(), completed: z.number().int().nonnegative().optional(),
22
- total: z.number().int().positive().optional(), unit: z.string().max(50).optional(),
39
+ total: z.number().int().nonnegative().optional(), unit: z.string().max(50).optional(),
40
+ // Notice events: key is the same for each repeat of one problem, so a newer notice replaces an older one.
41
+ key: z.string().max(500).optional(), attempt: z.number().int().positive().optional(), attempts: z.number().int().positive().optional(),
23
42
  });
24
43
  export const InspectionSchema = z.strictObject({
25
44
  started_at: z.string().optional(), device_name: z.string().optional(),
26
45
  local_run_directory: z.string().optional(),
27
46
  // run_data: device. The run's content stays on the device that ran it.
28
47
  content: z.literal("device").optional(),
29
- schema: z.literal("workflow-inspection/2"), workflow: WorkflowSchema, run_id: z.string(), status: z.string(), error: z.string().optional(), failure: FailureSchema.optional(),
48
+ schema: z.literal("workflow-inspection/2"), workflow: WorkflowSchema, run_id: z.string(), status: RunStatusSchema, failure: FailureSchema.optional(),
30
49
  inputs: z.record(JsonSchema), state: z.record(JsonSchema).optional(), resources: z.record(z.strictObject({ description: z.string(), setup: z.string().optional(), path: z.string().optional() })),
31
50
  environment: z.record(z.object({ result: z.enum(["pass", "fail", "ambiguous"]), summary: z.string(), evidence: z.array(z.string()) })).optional(),
32
51
  files: z.array(AttachedFileSchema).max(MAX_RESULT_FILES).optional(),
33
52
  events: z.array(RunEventSchema).optional(),
34
53
  invocations: z.record(z.strictObject({
35
- step_id: z.string(), status: z.string(), verification: z.enum(["checked", "unchecked"]).optional(), error: z.string().optional(), failure: FailureSchema.optional(), inputs: z.record(JsonSchema).optional(), outputs: z.record(JsonSchema).optional(),
54
+ step_id: z.string(), status: z.enum(["running", "returned", "passed", "skipped", "waiting_for_you", "failed", "stopped"]), verification: z.enum(["checked", "unchecked"]).optional(), inputs: z.record(JsonSchema).optional(), outputs: z.record(JsonSchema).optional(),
36
55
  checks: z.array(z.object({ id: z.string(), result: z.enum(["pass", "fail", "ambiguous"]), summary: z.string(), evidence: z.array(z.string()), method: z.string() })), changes: z.record(JsonSchema),
37
56
  prompts: z.array(z.strictObject({ sequence: z.number().int(), phase: z.enum(["action", "check"]), template: z.string(), rendered: z.string() })).optional(),
38
57
  events: z.array(RunEventSchema),
@@ -112,19 +131,20 @@ export function observedValue(item, inspection, invocation) {
112
131
  return value;
113
132
  }
114
133
  /**
115
- * The device form of a run record (run_data: device). Keep step status, kinds, names, timing, and the phase of a failure. Remove inputs, outputs,
116
- * prompts, files, errors, and free text. The server accepts only this form when an organization keeps run content on devices.
134
+ * The device form of a run record (run_data: device). Keep step status, kinds, names, timing, task counts, and the failure record without its
135
+ * evidence, details, and diagnostics. Remove inputs, outputs, prompts, files, event text, and other free text. The server accepts only this
136
+ * form when an organization keeps run content on devices.
117
137
  */
118
138
  export function deviceOnly(inspection) {
119
- const failure = (value) => value ? { failure: { phase: value.phase, expected: '', observed: '', evidence: [] } } : {};
120
- const event = ({ at, type, sequence, phase, duration_ms, usage, provider, model, kind, exit_code }) => Object.fromEntries(Object.entries({ at, type, sequence, phase, duration_ms, usage, provider, model, kind, exit_code }).filter(([, value]) => value !== undefined));
139
+ const failure = inspection.failure ? (({ evidence, details, diagnostics, ...kept }) => ({ failure: kept }))(inspection.failure) : {};
140
+ const event = ({ at, type, sequence, phase, duration_ms, usage, provider, model, kind, exit_code, completed, total, key, attempt, attempts }) => Object.fromEntries(Object.entries({ at, type, sequence, phase, duration_ms, usage, provider, model, kind, exit_code, completed, total, key, attempt, attempts }).filter(([, value]) => value !== undefined));
121
141
  return {
122
- schema: inspection.schema, content: 'device', workflow: inspection.workflow, run_id: inspection.run_id, status: inspection.status, ...failure(inspection.failure),
142
+ schema: inspection.schema, content: 'device', workflow: inspection.workflow, run_id: inspection.run_id, status: inspection.status, ...failure,
123
143
  ...(inspection.started_at ? { started_at: inspection.started_at } : {}), ...(inspection.device_name ? { device_name: inspection.device_name } : {}),
124
144
  inputs: {}, resources: Object.fromEntries(Object.entries(inspection.resources).map(([name, value]) => [name, { description: value.description }])),
125
145
  ...(inspection.events ? { events: inspection.events.map(event) } : {}),
126
146
  invocations: Object.fromEntries(Object.entries(inspection.invocations).map(([id, value]) => [id, {
127
- step_id: value.step_id, status: value.status, ...(value.verification ? { verification: value.verification } : {}), ...failure(value.failure),
147
+ step_id: value.step_id, status: value.status, ...(value.verification ? { verification: value.verification } : {}),
128
148
  checks: value.checks.map(check => ({ id: check.id, result: check.result, summary: '', evidence: [], method: check.method })), changes: {}, events: value.events.map(event),
129
149
  }])),
130
150
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@method-ai-hq/sdk",
3
- "version": "0.15.1",
3
+ "version": "0.17.0",
4
4
  "description": "Build and run reusable .method files with checked steps and saved results.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -35,7 +35,7 @@
35
35
  "prepack": "npm --prefix ../.. run build"
36
36
  },
37
37
  "dependencies": {
38
- "@withmethod/runtime": "https://codeload.github.com/method-ai-hq/method-spec/tar.gz/c45c5ba1a3432b8d4e90ff07a7457eef5ea0f371",
38
+ "@withmethod/runtime": "https://codeload.github.com/method-ai-hq/method-spec/tar.gz/54461cb387d8f10813db05bb0cea29c0a3a53504",
39
39
  "fflate": "^0.8.3",
40
40
  "yaml": "^2.9.0",
41
41
  "zod": "^3.25.76"