@agimon-ai/po-workflow 0.0.0-alpha.196 → 0.0.0-alpha.197

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.
@@ -19,6 +19,7 @@ let _agimon_ai_po_core_extensionFile = require("@agimon-ai/po-core/extensionFile
19
19
  let _agimon_ai_po_db = require("@agimon-ai/po-db");
20
20
  let _agimon_ai_po_core_telemetry = require("@agimon-ai/po-core/telemetry");
21
21
  let _agimon_ai_po_core_piSettings = require("@agimon-ai/po-core/piSettings");
22
+ let _agimon_ai_po_core_locale = require("@agimon-ai/po-core/locale");
22
23
  let node_async_hooks = require("node:async_hooks");
23
24
  let _agimon_ai_po_core_codemode = require("@agimon-ai/po-core/codemode");
24
25
  let _agimon_ai_po_core_delegation = require("@agimon-ai/po-core/delegation");
@@ -3441,38 +3442,38 @@ function duration(run) {
3441
3442
  * copy. A failure, approval wait or pause outranks a run in progress, because
3442
3443
  * it is the one that needs the reader.
3443
3444
  */
3444
- function workflowSessionActivity(runs) {
3445
+ function workflowSessionActivity(runs, t = (_key, fallback, vars) => (0, _agimon_ai_po_core_locale.formatMessage)(fallback, vars)) {
3445
3446
  if (runs.length === 0) return void 0;
3446
3447
  const failed = runs.find((run) => run.stage === "error" && !run.waiting);
3447
3448
  if (failed !== void 0) return {
3448
- label: `workflow failed · ${failed.failedJob ?? failed.displayName}`,
3449
+ label: t("workflow.activity.failed", "workflow failed · {job}", { job: failed.failedJob ?? failed.displayName }),
3449
3450
  attention: true
3450
3451
  };
3451
3452
  const waiting = runs.find((run) => run.waiting);
3452
3453
  if (waiting !== void 0) return {
3453
- label: waiting.position === void 0 ? "workflow waiting for approval" : `workflow waiting for approval · ${waiting.position.job}`,
3454
+ label: waiting.position === void 0 ? t("workflow.activity.waiting", "workflow waiting for approval") : t("workflow.activity.waitingAt", "workflow waiting for approval · {job}", { job: waiting.position.job }),
3454
3455
  attention: true
3455
3456
  };
3456
3457
  const paused = runs.find(isPaused);
3457
3458
  if (paused !== void 0) return {
3458
- label: paused.position === void 0 ? "workflow paused" : `workflow paused · ${paused.position.job}`,
3459
+ label: paused.position === void 0 ? t("workflow.activity.paused", "workflow paused") : t("workflow.activity.pausedAt", "workflow paused · {job}", { job: paused.position.job }),
3459
3460
  attention: true
3460
3461
  };
3461
3462
  if (runs.find((run) => run.stage === "running" && run.stale === true) !== void 0) return {
3462
- label: "workflow interrupted",
3463
+ label: t("workflow.activity.interrupted", "workflow interrupted"),
3463
3464
  attention: true
3464
3465
  };
3465
3466
  const running = runs.find((run) => run.stage === "running");
3466
3467
  if (running !== void 0) {
3467
3468
  const where = [running.position?.job, running.position?.step].filter(Boolean).join(" › ");
3468
3469
  return {
3469
- label: where === "" ? "workflow · starting" : `workflow · ${where}`,
3470
+ label: where === "" ? t("workflow.activity.starting", "workflow · starting") : t("workflow.activity.running", "workflow · {where}", { where }),
3470
3471
  since: running.startedAt
3471
3472
  };
3472
3473
  }
3473
- if (runs.every(succeeded)) return { label: "workflow succeeded" };
3474
+ if (runs.every(succeeded)) return { label: t("workflow.activity.succeeded", "workflow succeeded") };
3474
3475
  return {
3475
- label: `workflow ${runs[0].outcome ?? "ended"}`,
3476
+ label: t("workflow.activity.ended", "workflow {outcome}", { outcome: runs[0].outcome ?? t("workflow.activity.endedState", "ended") }),
3476
3477
  attention: true
3477
3478
  };
3478
3479
  }
@@ -3504,34 +3505,59 @@ function workflowSessionBrief(runs) {
3504
3505
  "On a workflow error, diagnose it locally, summarize the cause here, and tell the session that launched it what failed and what it needs with network.send({ to: <launcher>, text, terminal: true, outcome: 'failed' }), or outcome 'blocked' when only they can unblock it. Do not automatically restart it or diagnose a user-requested stop. When the user or launcher session asks: use workflow.status with the runKey and workspace for progress, workflow.recoveryEvidence to read a failure, and load codemode-how-to-workflow before workflow.recover. Without code mode, use workflow_run status and workflow_tools recovery-evidence/recover instead. Recover, pause, resume or stop a run only when the user asks or the launcher explicitly delegates it through intercom."
3505
3506
  ].join("\n");
3506
3507
  }
3507
- function failureNotice(run) {
3508
- const cause = (run.errorMessage ?? "the run ended in the error stage").slice(0, MAX_CAUSE).replace(/\.$/, "");
3509
- const job = run.failedJob === void 0 ? "" : ` at job "${run.failedJob}"`;
3508
+ function failureNotice(run, t) {
3509
+ const cause = (run.errorMessage ?? t("workflow.notice.errorStage", "the run ended in the error stage")).slice(0, MAX_CAUSE).replace(/\.$/, "");
3510
+ const body = run.failedJob === void 0 ? t("workflow.notice.failedBody", "Workflow \"{name}\" failed: {cause}. Ask me to diagnose or recover it.", {
3511
+ name: run.displayName,
3512
+ cause
3513
+ }) : t("workflow.notice.failedAtBody", "Workflow \"{name}\" failed at job \"{job}\": {cause}. Ask me to diagnose or recover it.", {
3514
+ name: run.displayName,
3515
+ job: run.failedJob,
3516
+ cause
3517
+ });
3510
3518
  return {
3511
- title: "Workflow failed",
3512
- body: `Workflow "${run.displayName}" failed${job}: ${cause}. Ask me to diagnose or recover it.`,
3519
+ title: t("workflow.notice.failedTitle", "Workflow failed"),
3520
+ body,
3513
3521
  level: "error"
3514
3522
  };
3515
3523
  }
3516
3524
  /** A parked run is not a failure: it carries on by itself once the person answers. */
3517
- function waitingNotice(run) {
3525
+ function waitingNotice(run, t) {
3518
3526
  const step = run.position?.step ?? run.jobs.flatMap((job) => job.steps).find((item) => item.status === "running")?.name;
3527
+ const body = step === void 0 ? t("workflow.notice.waitingBody", "Workflow \"{name}\" is waiting for your approval. It carries on once you answer.", { name: run.displayName }) : t("workflow.notice.waitingAtBody", "Workflow \"{name}\" is waiting for your approval at \"{step}\". It carries on once you answer.", {
3528
+ name: run.displayName,
3529
+ step
3530
+ });
3519
3531
  return {
3520
- title: "Workflow waiting for approval",
3521
- body: `Workflow "${run.displayName}" is waiting for your approval${step === void 0 ? "" : ` at "${step}"`}. It carries on once you answer.`,
3532
+ title: t("workflow.notice.waitingTitle", "Workflow waiting for approval"),
3533
+ body,
3522
3534
  level: "info"
3523
3535
  };
3524
3536
  }
3525
- function finishNotice(run) {
3537
+ function finishNotice(run, t) {
3526
3538
  const took = duration(run);
3527
- if (succeeded(run)) return {
3528
- title: "Workflow succeeded",
3529
- body: `Workflow "${run.displayName}" ${run.outcome === "skipped" ? "was skipped" : "succeeded"}${took === void 0 ? "" : ` in ${took}`}.`,
3530
- level: "info"
3531
- };
3539
+ if (succeeded(run)) {
3540
+ const skipped = run.outcome === "skipped";
3541
+ const body = took === void 0 ? skipped ? t("workflow.notice.skippedBody", "Workflow \"{name}\" was skipped.", { name: run.displayName }) : t("workflow.notice.succeededBody", "Workflow \"{name}\" succeeded.", { name: run.displayName }) : took === "under a minute" ? skipped ? t("workflow.notice.skippedQuickBody", "Workflow \"{name}\" was skipped in under a minute.", { name: run.displayName }) : t("workflow.notice.succeededQuickBody", "Workflow \"{name}\" succeeded in under a minute.", { name: run.displayName }) : skipped ? t("workflow.notice.skippedTimedBody", "Workflow \"{name}\" was skipped in {duration}.", {
3542
+ name: run.displayName,
3543
+ duration: took
3544
+ }) : t("workflow.notice.succeededTimedBody", "Workflow \"{name}\" succeeded in {duration}.", {
3545
+ name: run.displayName,
3546
+ duration: took
3547
+ });
3548
+ return {
3549
+ title: t("workflow.notice.succeededTitle", "Workflow succeeded"),
3550
+ body,
3551
+ level: "info"
3552
+ };
3553
+ }
3554
+ const body = run.outcome === void 0 ? t("workflow.notice.noOutcomeBody", "Workflow \"{name}\" ended: no outcome recorded. Ask me to look into it.", { name: run.displayName }) : t("workflow.notice.endedBody", "Workflow \"{name}\" ended: {outcome}. Ask me to look into it.", {
3555
+ name: run.displayName,
3556
+ outcome: run.outcome
3557
+ });
3532
3558
  return {
3533
- title: "Workflow ended",
3534
- body: `Workflow "${run.displayName}" ended: ${run.outcome ?? "no outcome recorded"}. Ask me to look into it.`,
3559
+ title: t("workflow.notice.endedTitle", "Workflow ended"),
3560
+ body,
3535
3561
  level: "error"
3536
3562
  };
3537
3563
  }
@@ -3554,6 +3580,7 @@ function diagnoseText(run, launcher) {
3554
3580
  * remove it.
3555
3581
  */
3556
3582
  function createWorkflowSessionLifecycle(deps) {
3583
+ const t = deps.translate ?? ((_key, fallback, vars) => (0, _agimon_ai_po_core_locale.formatMessage)(fallback, vars));
3557
3584
  const stages = /* @__PURE__ */ new Map();
3558
3585
  let seeded = false;
3559
3586
  let attention = false;
@@ -3621,7 +3648,7 @@ function createWorkflowSessionLifecycle(deps) {
3621
3648
  return {
3622
3649
  async observe(runs) {
3623
3650
  if (disposed) return;
3624
- deps.publishActivity?.(workflowSessionActivity(runs));
3651
+ deps.publishActivity?.(workflowSessionActivity(runs, deps.translate));
3625
3652
  if (runs.some(needsAttention)) attention = true;
3626
3653
  if (!seeded) {
3627
3654
  for (const run of runs) stages.set(identity(run), run.stage);
@@ -3634,10 +3661,10 @@ function createWorkflowSessionLifecycle(deps) {
3634
3661
  stages.set(identity(run), run.stage);
3635
3662
  if (previous === run.stage || run.launcherSessionId === void 0) continue;
3636
3663
  if (run.stage === "error") {
3637
- await deps.postNotice(run.waiting ? waitingNotice(run) : failureNotice(run));
3664
+ await deps.postNotice(run.waiting ? waitingNotice(run, t) : failureNotice(run, t));
3638
3665
  if (!run.waiting) await report(run);
3639
3666
  } else if (run.stage === "completed") {
3640
- await deps.postNotice(finishNotice(run));
3667
+ await deps.postNotice(finishNotice(run, t));
3641
3668
  await report(run);
3642
3669
  finished = true;
3643
3670
  }
@@ -19370,7 +19397,7 @@ function untilAborted(work, signal) {
19370
19397
  work.then(resolveWork, rejectWork).finally(() => signal.removeEventListener("abort", onAbort));
19371
19398
  });
19372
19399
  }
19373
- function createWorkflowServerRuntime(host, serverHost, runtime, resolveSecrets, children, resolveIdentity, outcome) {
19400
+ function createWorkflowServerRuntime(host, serverHost, runtime, resolveSecrets, children, resolveIdentity, outcome, translate) {
19374
19401
  if (serverHost.context.directEvents === void 0) throw new Error("Workflow server plugin requires the session direct event bus.");
19375
19402
  const directEvents = serverHost.context.directEvents;
19376
19403
  const environment = host.context.environment;
@@ -19483,13 +19510,10 @@ function createWorkflowServerRuntime(host, serverHost, runtime, resolveSecrets,
19483
19510
  const communication = serverHost.context.sessionCommunication;
19484
19511
  const lifecycle = workflowSession ? createWorkflowSessionLifecycle({
19485
19512
  parentSessionId: host.context.sessionContext?.parentSessionId,
19513
+ translate,
19486
19514
  publishActivity: (activity) => serverHost.context.publishActivity?.(activity),
19487
19515
  postNotice: async (notice) => {
19488
- const data = (0, _agimon_ai_po_core_notification.createPoNotificationEntryData)({
19489
- title: notice.title,
19490
- body: notice.body,
19491
- level: notice.level
19492
- });
19516
+ const data = (0, _agimon_ai_po_core_notification.createPoNotificationEntryData)(notice);
19493
19517
  if (data !== void 0) await host.context.session.appendCustomEntry(_agimon_ai_po_core_notification.PO_NOTIFICATION_ENTRY_TYPE, data);
19494
19518
  },
19495
19519
  isIdle: async () => {
@@ -21189,7 +21213,7 @@ var index_server_default = (async (mountContext) => {
21189
21213
  await toolsProvider.await();
21190
21214
  if (!mounted) throw new Error("Workflow jobTools requires code mode in this managed step session.");
21191
21215
  }
21192
- const plugin = agent ? createWorkflowServerRuntime(agent, host, admitted, resolveSecrets, workflow?.children, resolveIdentity, workflow?.outcome) : { api: [createWorkflowApi(admitted)] };
21216
+ const plugin = agent ? createWorkflowServerRuntime(agent, host, admitted, resolveSecrets, workflow?.children, resolveIdentity, workflow?.outcome, (key, fallback, vars) => (0, _agimon_ai_po_core_locale.readPoLang)(context)?.t((0, _agimon_ai_po_core_locale.readPoPersonLocale)(context)?.read(), key, fallback, vars) ?? (0, _agimon_ai_po_core_locale.formatMessage)(fallback, vars)) : { api: [createWorkflowApi(admitted)] };
21193
21217
  let disposeTracker;
21194
21218
  let cleanup;
21195
21219
  disposeRuntime = () => cleanup ??= Promise.resolve().then(async () => {