@ahmadposten/talos-wire 0.1.1 → 0.1.3

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.cjs CHANGED
@@ -366,6 +366,170 @@ const ProviderUsageSnapshotSchema = z__namespace.object({
366
366
  retryAt: z__namespace.number().finite().optional()
367
367
  });
368
368
 
369
+ const text = z.z.string().trim().min(1).max(24e3);
370
+ const WorkflowAgentSchema = z.z.object({
371
+ id: z.z.string().min(1).max(100),
372
+ revision: z.z.number().int().positive(),
373
+ name: z.z.string().min(1).max(60),
374
+ description: z.z.string().max(300),
375
+ provider: z.z.literal("codex"),
376
+ model: z.z.string().min(1).max(200),
377
+ effort: z.z.string().max(30).nullable(),
378
+ permissionMode: z.z.enum(["default", "read-only"]),
379
+ instructions: text,
380
+ documents: z.z.array(z.z.object({ name: z.z.string().max(120), content: z.z.string().max(16e3) })).max(5)
381
+ });
382
+ const WorkflowSlotSchema = z.z.object({ agent: WorkflowAgentSchema, assignment: text });
383
+ const WorkflowStepSchema = z.z.object({
384
+ id: z.z.string().uuid(),
385
+ name: z.z.string().trim().min(1).max(80),
386
+ kind: z.z.enum(["plan", "execute", "review"]),
387
+ agents: z.z.array(WorkflowSlotSchema).min(1).max(3),
388
+ criteria: z.z.string().trim().max(24e3),
389
+ checks: z.z.array(z.z.object({ name: z.z.string().trim().min(1).max(100), command: z.z.string().trim().min(1).max(2e3) })).max(8)
390
+ });
391
+ function workflowProjection(steps) {
392
+ return {
393
+ planners: steps.find((s) => s.kind === "plan")?.agents ?? [],
394
+ executor: steps.find((s) => s.kind === "execute")?.agents[0],
395
+ reviewers: [...steps].reverse().find((s) => s.kind === "review")?.agents ?? []
396
+ };
397
+ }
398
+ const WorkflowDefinitionSchema = z.z.object({
399
+ id: z.z.string().uuid(),
400
+ revision: z.z.number().int().positive(),
401
+ name: z.z.string().trim().min(1).max(80),
402
+ description: z.z.string().max(1e3),
403
+ planners: z.z.array(WorkflowSlotSchema).min(1).max(4),
404
+ executor: WorkflowSlotSchema,
405
+ reviewers: z.z.array(WorkflowSlotSchema).min(1).max(4),
406
+ steps: z.z.array(WorkflowStepSchema).min(3).max(8).optional(),
407
+ criteria: text,
408
+ checks: z.z.array(z.z.object({ name: z.z.string().trim().min(1).max(100), command: z.z.string().trim().min(1).max(2e3) })).min(1).max(8),
409
+ planningRounds: z.z.number().int().min(1).max(5),
410
+ reviewRounds: z.z.number().int().min(1).max(5),
411
+ turnMinutes: z.z.number().int().min(1).max(30),
412
+ maxTurns: z.z.number().int().min(8).max(100),
413
+ approvePlan: z.z.boolean(),
414
+ updatedAt: z.z.number()
415
+ }).superRefine((d, ctx) => {
416
+ if (new TextEncoder().encode(JSON.stringify(d)).length > 64e3) ctx.addIssue({ code: "custom", message: "Workflow definition exceeds 64 KB. Shorten instructions or documents." });
417
+ const issue = (message) => ctx.addIssue({ code: "custom", message });
418
+ if (d.steps) {
419
+ if (d.steps[0].kind !== "plan" || d.steps.at(-1)?.kind !== "review" || !d.steps.some((s) => s.kind === "execute")) issue("Start with planning, include execution, and finish with review.");
420
+ if (new Set(d.steps.map((s) => s.id)).size !== d.steps.length) issue("Each step needs a unique ID.");
421
+ const writers = new Set(d.steps.filter((s) => s.kind === "execute").flatMap((s) => s.agents.map((a) => a.agent.id)));
422
+ const identities = /* @__PURE__ */ new Map();
423
+ let executed = false;
424
+ for (const step of d.steps) {
425
+ if (step.kind === "plan") executed = false;
426
+ if (step.kind === "execute") executed = true;
427
+ if (step.kind === "review" && !executed) issue("Place an execution step between planning and review.");
428
+ if (step.kind === "execute" && (step.agents.length !== 1 || step.agents[0].agent.permissionMode === "read-only")) issue("Each execution step needs one agent that allows workspace edits.");
429
+ if (step.kind !== "review" && step.checks.length) issue("Attach step checks to a review step.");
430
+ if (new Set(step.agents.map((s) => s.agent.id)).size !== step.agents.length) issue("Choose distinct agents within a consensus step.");
431
+ for (const slot of step.agents) {
432
+ if (step.kind === "review" && writers.has(slot.agent.id)) issue("Reviewers must be independent of every executor.");
433
+ const snapshot = JSON.stringify(slot.agent);
434
+ if (identities.has(slot.agent.id) && identities.get(slot.agent.id) !== snapshot) issue("A reused agent must have the same configuration in every step.");
435
+ identities.set(slot.agent.id, snapshot);
436
+ }
437
+ }
438
+ const projection = workflowProjection(d.steps);
439
+ if (JSON.stringify([d.planners, d.executor, d.reviewers]) !== JSON.stringify([projection.planners, projection.executor, projection.reviewers])) issue("Workflow role summaries must match its steps.");
440
+ } else {
441
+ if (d.planners.length < 2 || d.reviewers.length < 2) issue("Legacy workflows require at least two planners and reviewers.");
442
+ const ids = [...d.planners, d.executor, ...d.reviewers].map((s) => s.agent.id);
443
+ if (new Set(ids).size !== ids.length) issue("Each workflow participant must be a different saved agent.");
444
+ if (d.executor.agent.permissionMode === "read-only") issue("The executor must allow workspace edits.");
445
+ }
446
+ });
447
+ const WorkflowLibrarySchema = z.z.array(WorkflowDefinitionSchema).max(20).refine((x) => JSON.stringify(x).length < 128e3, "Workflow library is too large.");
448
+ function workflowSlots(d) {
449
+ return d.steps?.flatMap((s) => s.agents) ?? [...d.planners, d.executor, ...d.reviewers];
450
+ }
451
+ const WorkflowStageSchema = z.z.enum(["propose", "consolidate", "plan_vote", "execute", "review", "verify"]);
452
+ const WorkflowDecisionSchema = z.z.object({
453
+ decision: z.z.enum(["approve", "changes", "information", "replan"]),
454
+ summary: text,
455
+ document: z.z.string().max(24e3),
456
+ findings: z.z.array(z.z.object({ title: z.z.string().min(1).max(300), evidence: text, correction: text, blocking: z.z.boolean() })).max(20)
457
+ });
458
+ const WorkflowTaskSchema = z.z.object({
459
+ id: z.z.string(),
460
+ stage: WorkflowStageSchema,
461
+ round: z.z.number(),
462
+ agentId: z.z.string(),
463
+ agentName: z.z.string(),
464
+ stepId: z.z.string().uuid().optional(),
465
+ attempt: z.z.number().int().positive().optional(),
466
+ clarifications: z.z.number().int().optional(),
467
+ assignment: z.z.string(),
468
+ version: z.z.string(),
469
+ status: z.z.enum(["running", "done", "interrupted"]),
470
+ startedAt: z.z.number(),
471
+ completedAt: z.z.number().optional(),
472
+ sessionId: z.z.string().optional(),
473
+ threadId: z.z.string().optional(),
474
+ prompt: z.z.string(),
475
+ result: WorkflowDecisionSchema.optional(),
476
+ error: z.z.string().optional()
477
+ });
478
+ const WorkflowRunSchema = z.z.object({
479
+ id: z.z.string().uuid(),
480
+ revision: z.z.number().int(),
481
+ definition: WorkflowDefinitionSchema,
482
+ machineId: z.z.string(),
483
+ task: text,
484
+ requestedDirectory: z.z.string().optional(),
485
+ sourceDirectory: z.z.string(),
486
+ directory: z.z.string(),
487
+ branch: z.z.string(),
488
+ baseCommit: z.z.string(),
489
+ status: z.z.enum(["running", "paused", "needs_input", "complete", "cancelled"]),
490
+ stage: WorkflowStageSchema,
491
+ stepIndex: z.z.number().int().nonnegative().optional(),
492
+ stepAttempt: z.z.number().int().positive().optional(),
493
+ stepRounds: z.z.record(z.z.string(), z.z.number().int().positive()).optional(),
494
+ completedSteps: z.z.array(z.z.string().uuid()).max(8).optional(),
495
+ planningRound: z.z.number().int(),
496
+ reviewRound: z.z.number().int(),
497
+ planVersion: z.z.number().int(),
498
+ plan: z.z.string(),
499
+ artifactVersion: z.z.string(),
500
+ reason: z.z.string(),
501
+ tasks: z.z.array(WorkflowTaskSchema).max(200),
502
+ checks: z.z.array(z.z.object({ name: z.z.string(), exitCode: z.z.number().nullable(), output: z.z.string(), version: z.z.string() })),
503
+ events: z.z.array(z.z.object({ at: z.z.number(), text: z.z.string() })).max(500),
504
+ notes: z.z.array(z.z.string()).max(30),
505
+ approvedPlanVersion: z.z.number().nullable(),
506
+ createdAt: z.z.number(),
507
+ updatedAt: z.z.number()
508
+ }).superRefine((run, ctx) => {
509
+ if (!run.definition.steps) return;
510
+ const steps = run.definition.steps;
511
+ const step = steps[run.stepIndex ?? -1];
512
+ if (!step || !run.stepAttempt || !run.completedSteps || !run.stepRounds) {
513
+ ctx.addIssue({ code: "custom", message: "Editable workflow recovery state is incomplete." });
514
+ return;
515
+ }
516
+ const stages = step.kind === "plan" ? ["propose", "consolidate", "plan_vote"] : step.kind === "execute" ? ["execute"] : ["verify", "review"];
517
+ if (!stages.includes(run.stage) || run.completedSteps.some((id) => !steps.some((s) => s.id === id)) || run.tasks.some((t) => !t.stepId || !t.attempt || !steps.some((s) => s.id === t.stepId))) ctx.addIssue({ code: "custom", message: "Saved workflow stage does not match its definition." });
518
+ });
519
+ const WorkflowStartSchema = z.z.object({ id: z.z.string().uuid(), definition: WorkflowDefinitionSchema, task: text, directory: z.z.string().min(1).max(4e3) });
520
+ const WorkflowActionSchema = z.z.object({
521
+ id: z.z.string().uuid(),
522
+ expectedRevision: z.z.number().int(),
523
+ action: z.z.enum(["pause", "resume", "cancel", "approve_plan", "revise_plan", "retry_review", "replace_agent"]),
524
+ note: z.z.string().trim().max(24e3).default(""),
525
+ agentId: z.z.string().optional(),
526
+ replacement: WorkflowAgentSchema.optional()
527
+ });
528
+ function workflowEnabled(s) {
529
+ return s.experiments === true && s.expWorkflows === true;
530
+ }
531
+ const workflowStageLabel = { propose: "Independent proposals", consolidate: "Consolidating plan", plan_vote: "Planning consensus", execute: "Executing", review: "Independent review", verify: "Completion checks" };
532
+
369
533
  exports.AgentMessageSchema = AgentMessageSchema;
370
534
  exports.ApiMessageSchema = ApiMessageSchema;
371
535
  exports.ApiUpdateMachineStateSchema = ApiUpdateMachineStateSchema;
@@ -397,6 +561,17 @@ exports.VoiceConversationDeniedSchema = VoiceConversationDeniedSchema;
397
561
  exports.VoiceConversationGrantedSchema = VoiceConversationGrantedSchema;
398
562
  exports.VoiceConversationResponseSchema = VoiceConversationResponseSchema;
399
563
  exports.VoiceUsageResponseSchema = VoiceUsageResponseSchema;
564
+ exports.WorkflowActionSchema = WorkflowActionSchema;
565
+ exports.WorkflowAgentSchema = WorkflowAgentSchema;
566
+ exports.WorkflowDecisionSchema = WorkflowDecisionSchema;
567
+ exports.WorkflowDefinitionSchema = WorkflowDefinitionSchema;
568
+ exports.WorkflowLibrarySchema = WorkflowLibrarySchema;
569
+ exports.WorkflowRunSchema = WorkflowRunSchema;
570
+ exports.WorkflowSlotSchema = WorkflowSlotSchema;
571
+ exports.WorkflowStageSchema = WorkflowStageSchema;
572
+ exports.WorkflowStartSchema = WorkflowStartSchema;
573
+ exports.WorkflowStepSchema = WorkflowStepSchema;
574
+ exports.WorkflowTaskSchema = WorkflowTaskSchema;
400
575
  exports.authenticationContexts = authenticationContexts;
401
576
  exports.createEnvelope = createEnvelope;
402
577
  exports.encryptionContexts = encryptionContexts;
@@ -418,3 +593,7 @@ exports.sessionTurnEndEventSchema = sessionTurnEndEventSchema;
418
593
  exports.sessionTurnEndStatusSchema = sessionTurnEndStatusSchema;
419
594
  exports.sessionTurnStartEventSchema = sessionTurnStartEventSchema;
420
595
  exports.toWireMetadata = toWireMetadata;
596
+ exports.workflowEnabled = workflowEnabled;
597
+ exports.workflowProjection = workflowProjection;
598
+ exports.workflowSlots = workflowSlots;
599
+ exports.workflowStageLabel = workflowStageLabel;