@dnotifier-realtime/dnotifier 1.1.15 → 1.1.17

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 (51) hide show
  1. package/dist/cjs/dnotifier.js +1 -1
  2. package/dist/cjs/providers/openai.js +1 -1
  3. package/dist/cjs/transport/httpTransport.js +1 -1
  4. package/dist/cjs/transport/websocketTransport.js +1 -1
  5. package/dist/cjs/utils/buffer.js +1 -1
  6. package/dist/cjs/utils/frame.js +1 -1
  7. package/dist/cjs/utils/id.js +1 -1
  8. package/dist/cjs/utils/payload.js +1 -1
  9. package/dist/config/endpoints.d.ts +2 -2
  10. package/dist/config/endpoints.d.ts.map +1 -1
  11. package/dist/config/endpoints.js +1 -1
  12. package/dist/dnotifier.cjs +394 -38
  13. package/dist/dnotifier.d.ts +5 -0
  14. package/dist/dnotifier.d.ts.map +1 -1
  15. package/dist/dnotifier.js +1 -1
  16. package/dist/providers/openai.js +1 -1
  17. package/dist/transport/httpTransport.d.ts +3 -1
  18. package/dist/transport/httpTransport.d.ts.map +1 -1
  19. package/dist/transport/httpTransport.js +1 -1
  20. package/dist/transport/websocketTransport.js +1 -1
  21. package/dist/utils/buffer.js +1 -1
  22. package/dist/utils/frame.js +1 -1
  23. package/dist/utils/id.js +1 -1
  24. package/dist/utils/logs.js +1 -1
  25. package/dist/utils/payload.js +1 -1
  26. package/dist/workflow/agent.js +1 -1
  27. package/dist/workflow/context.d.ts +49 -1
  28. package/dist/workflow/context.d.ts.map +1 -1
  29. package/dist/workflow/context.js +1 -1
  30. package/dist/workflow/errors.js +1 -1
  31. package/dist/workflow/graphParents.d.ts +13 -0
  32. package/dist/workflow/graphParents.d.ts.map +1 -0
  33. package/dist/workflow/graphParents.js +1 -0
  34. package/dist/workflow/ids.js +1 -1
  35. package/dist/workflow/index.d.ts +1 -0
  36. package/dist/workflow/index.js +1 -1
  37. package/dist/workflow/jsonPayload.js +1 -1
  38. package/dist/workflow/mockObservabilityClient.js +1 -1
  39. package/dist/workflow/observability.d.ts +9 -2
  40. package/dist/workflow/observability.d.ts.map +1 -1
  41. package/dist/workflow/observability.js +1 -1
  42. package/dist/workflow/runner.d.ts.map +1 -1
  43. package/dist/workflow/runner.js +1 -1
  44. package/dist/workflow/stepTypes.d.ts +4 -0
  45. package/dist/workflow/stepTypes.d.ts.map +1 -1
  46. package/dist/workflow/stepTypes.js +1 -1
  47. package/dist/workflow/workflow.js +1 -1
  48. package/dist/workflow/workflowObservabilityClient.d.ts +3 -2
  49. package/dist/workflow/workflowObservabilityClient.d.ts.map +1 -1
  50. package/dist/workflow/workflowObservabilityClient.js +1 -1
  51. package/package.json +1 -1
@@ -48,24 +48,40 @@ var HttpTransport = class {
48
48
  // this.appSecret = secret;
49
49
  // this.userId = userId;
50
50
  // }
51
- constructor({ url, headers = {} }) {
51
+ constructor({ url, headers = {}, timeoutMs = null }) {
52
52
  this.url = url;
53
53
  this.headers = headers;
54
+ this.timeoutMs = timeoutMs;
54
55
  }
55
56
  async send(payload) {
56
- const res = await fetch(`${this.url}`, {
57
- method: "POST",
58
- headers: {
59
- "Content-Type": "application/json",
60
- ...this.headers
61
- },
62
- body: JSON.stringify(payload)
63
- });
64
- if (!res.ok) {
65
- const text = await res.text();
66
- throw new Error(`DNotifier HTTP error: ${text}`);
57
+ const controller = new AbortController();
58
+ let timeoutId = null;
59
+ if (this.timeoutMs != null && this.timeoutMs > 0) {
60
+ timeoutId = setTimeout(() => controller.abort(), this.timeoutMs);
61
+ }
62
+ try {
63
+ const res = await fetch(`${this.url}`, {
64
+ method: "POST",
65
+ headers: {
66
+ "Content-Type": "application/json",
67
+ ...this.headers
68
+ },
69
+ body: JSON.stringify(payload),
70
+ signal: controller.signal
71
+ });
72
+ if (!res.ok) {
73
+ const text = await res.text();
74
+ throw new Error(`DNotifier HTTP error: ${text}`);
75
+ }
76
+ return await res.json();
77
+ } catch (err) {
78
+ if (err?.name === "AbortError") {
79
+ throw new Error(`DNotifier HTTP timeout after ${this.timeoutMs}ms: ${this.url}`);
80
+ }
81
+ throw err;
82
+ } finally {
83
+ if (timeoutId) clearTimeout(timeoutId);
67
84
  }
68
- return await res.json();
69
85
  }
70
86
  sendBinary() {
71
87
  throw new Error("Binary is not supported over HTTP yet");
@@ -223,7 +239,7 @@ var WebsocketTransport = class extends import_events.default {
223
239
  };
224
240
 
225
241
  // src/config/endpoints.js
226
- var baseHost = "https://api.dnotifier.com";
242
+ var baseHost = "https://dev.api.dnotifier.com";
227
243
  var wsHost = baseHost.replace(/^http/, "ws");
228
244
  var logHost = `${baseHost}/ecs`;
229
245
  var workflowSdkBase = `${logHost}/api/v1/log/sdk/workflow`;
@@ -510,9 +526,50 @@ var Workflow = class {
510
526
  }
511
527
  };
512
528
 
529
+ // src/workflow/graphParents.js
530
+ function formatParentStepId(value) {
531
+ if (value == null) return null;
532
+ if (Array.isArray(value)) {
533
+ const ids = value.filter((id) => id != null && String(id).trim() !== "");
534
+ return ids.length > 0 ? ids.join(",") : null;
535
+ }
536
+ const text = String(value).trim();
537
+ return text === "" ? null : text;
538
+ }
539
+ function resolveGraphParentStepId(step) {
540
+ const multi = step.parentStepIds ?? step.dependsOn;
541
+ if (multi?.length) {
542
+ return formatParentStepId(multi);
543
+ }
544
+ return formatParentStepId(step.parentStepId);
545
+ }
546
+ function resolveRecordedParentStepId(options = {}) {
547
+ const multi = options.parentStepIds ?? options.dependsOn;
548
+ if (multi?.length) {
549
+ return formatParentStepId(multi);
550
+ }
551
+ if (options.parentStepId !== void 0) {
552
+ return formatParentStepId(options.parentStepId);
553
+ }
554
+ if (options.resolveParent) {
555
+ return formatParentStepId(options.resolveParent());
556
+ }
557
+ return null;
558
+ }
559
+
513
560
  // src/workflow/stepTypes.js
514
561
  var STEP_TYPE_AGENT = "Agent";
562
+ var STEP_TYPE_PARALLEL = "Parallel";
563
+ var STEP_TYPE_ENTRY = "Entry";
564
+ var STEP_TYPE_END = "End";
515
565
  var STEP_TYPE_CUSTOM = "Custom";
566
+ var STRUCTURAL_STEP_TYPES = [
567
+ STEP_TYPE_AGENT,
568
+ STEP_TYPE_PARALLEL,
569
+ STEP_TYPE_ENTRY,
570
+ STEP_TYPE_END,
571
+ STEP_TYPE_CUSTOM
572
+ ];
516
573
  var SDK_API_STEP_TYPES = [
517
574
  "sendAI",
518
575
  "fetchAIHistory",
@@ -564,6 +621,7 @@ function resolveApiName(step) {
564
621
  function resolveStepType(step) {
565
622
  if (step?.type != null && String(step.type).trim() !== "") {
566
623
  const t = String(step.type).trim();
624
+ if (STRUCTURAL_STEP_TYPES.includes(t)) return t;
567
625
  if (Object.values(LOG_TYPE_BY_API).includes(t)) return t;
568
626
  return toLogStepType(t);
569
627
  }
@@ -593,9 +651,35 @@ function snapshot(value) {
593
651
  }
594
652
  function apiInput(opts) {
595
653
  if (!opts || typeof opts !== "object") return opts ?? null;
596
- const { label, ...rest } = opts;
654
+ const { label, dependsOn, parentStepIds, branchKey, siblingIndex, parentStepId, input, ...rest } = opts;
597
655
  return Object.keys(rest).length > 0 ? rest : null;
598
656
  }
657
+ function normalizeRunAgentsSpec(spec) {
658
+ if (Array.isArray(spec)) {
659
+ return spec.map((item, index) => {
660
+ if (typeof item === "string") {
661
+ return { name: item, input: void 0, key: String(index) };
662
+ }
663
+ if (!item || typeof item !== "object" || !item.name) {
664
+ throw new WorkflowError("runAgents entry requires name");
665
+ }
666
+ return { name: item.name, input: item.input, key: String(index) };
667
+ });
668
+ }
669
+ if (spec && typeof spec === "object") {
670
+ return Object.entries(spec).map(([key, value]) => {
671
+ if (value && typeof value === "object" && "name" in value) {
672
+ return {
673
+ name: value.name,
674
+ input: value.input,
675
+ key
676
+ };
677
+ }
678
+ return { name: key, input: value, key };
679
+ });
680
+ }
681
+ throw new WorkflowError("runAgents expects an array or object spec");
682
+ }
599
683
  var WorkflowContext = class _WorkflowContext {
600
684
  /**
601
685
  * @param {{
@@ -607,6 +691,8 @@ var WorkflowContext = class _WorkflowContext {
607
691
  * observability?: import("./observability.js").WorkflowObservability | null,
608
692
  * executionId?: string | null,
609
693
  * agentName?: string | null,
694
+ * entryStepId?: string | null,
695
+ * traceParentStepId?: string | null,
610
696
  * }} options
611
697
  */
612
698
  constructor({
@@ -617,7 +703,9 @@ var WorkflowContext = class _WorkflowContext {
617
703
  state = {},
618
704
  observability = null,
619
705
  executionId = null,
620
- agentName = null
706
+ agentName = null,
707
+ entryStepId = null,
708
+ traceParentStepId = null
621
709
  }) {
622
710
  this.notifier = notifier;
623
711
  this.senderId = senderId;
@@ -628,6 +716,53 @@ var WorkflowContext = class _WorkflowContext {
628
716
  this._executionId = executionId;
629
717
  this._observabilityEnabled = Boolean(workflow.observability && observability && executionId);
630
718
  this.agentName = agentName;
719
+ this._entryStepId = entryStepId;
720
+ this._chainHeadStepId = entryStepId;
721
+ this._traceParentStepId = traceParentStepId;
722
+ this._currentStepId = null;
723
+ this.rootStepId = null;
724
+ this._terminalStepIds = [];
725
+ }
726
+ /**
727
+ * Comma-separated parent step ids for the workflow End node.
728
+ * @returns {string | null}
729
+ */
730
+ getEndParentStepId() {
731
+ if (this._terminalStepIds.length > 0) {
732
+ return formatParentStepId(this._terminalStepIds);
733
+ }
734
+ if (this._entryStepId) return this._entryStepId;
735
+ return null;
736
+ }
737
+ /**
738
+ * @param {string[]} stepIds
739
+ */
740
+ _markTerminalSteps(stepIds) {
741
+ if (this._currentStepId) return;
742
+ this._terminalStepIds = stepIds.filter(
743
+ (id) => id != null && String(id).trim() !== ""
744
+ );
745
+ }
746
+ /**
747
+ * @returns {string | null}
748
+ */
749
+ _resolveParentStepId(options = {}) {
750
+ if (options.parentStepId !== void 0) return options.parentStepId;
751
+ if (this._currentStepId) return this._currentStepId;
752
+ if (this._traceParentStepId) return this._traceParentStepId;
753
+ if (this._chainHeadStepId) return this._chainHeadStepId;
754
+ if (this._entryStepId) return this._entryStepId;
755
+ return null;
756
+ }
757
+ /**
758
+ * @returns {{ executionId: string | null, workflowId: string, parentStepId: string | null }}
759
+ */
760
+ exportTraceContext() {
761
+ return {
762
+ executionId: this._executionId,
763
+ workflowId: this.workflow.name,
764
+ parentStepId: this._currentStepId ?? this._chainHeadStepId ?? this._traceParentStepId ?? this._entryStepId ?? null
765
+ };
631
766
  }
632
767
  /**
633
768
  * @param {string} apiName
@@ -659,9 +794,11 @@ var WorkflowContext = class _WorkflowContext {
659
794
  label: meta.label ?? logType,
660
795
  status,
661
796
  latencyMs: Date.now() - started,
797
+ parentStepId: formatParentStepId(this._currentStepId),
662
798
  ...usage,
663
799
  input: snapshot(meta.input),
664
800
  output: snapshot(output),
801
+ state: snapshot(this.state),
665
802
  error
666
803
  });
667
804
  }
@@ -669,25 +806,130 @@ var WorkflowContext = class _WorkflowContext {
669
806
  }
670
807
  /**
671
808
  * @param {string} name
672
- * @param {{ input?: * }} [options]
809
+ * @param {{
810
+ * input?: *,
811
+ * dependsOn?: string[],
812
+ * parentStepIds?: string[],
813
+ * branchKey?: string,
814
+ * siblingIndex?: number,
815
+ * parentStepId?: string | null,
816
+ * }} [options]
817
+ * @returns {Promise<{ output: *, stepId: string | null }>}
673
818
  */
674
- async runAgent(name, options = {}) {
819
+ async _runAgentObserved(name, options = {}) {
675
820
  const agent = this.workflow.getAgent(name);
676
821
  if (!agent) {
677
822
  throw new WorkflowError(`Agent not found: ${name}`);
678
823
  }
679
824
  const childInput = options.input !== void 0 ? options.input : this.input;
680
- const childCtx = new _WorkflowContext({
681
- notifier: this.notifier,
682
- senderId: this.senderId,
683
- workflow: this.workflow,
684
- input: childInput,
685
- state: this.state,
686
- observability: this._observability,
687
- executionId: this._executionId,
688
- agentName: name
825
+ const parentStepId = resolveRecordedParentStepId({
826
+ parentStepId: options.parentStepId,
827
+ parentStepIds: options.parentStepIds,
828
+ dependsOn: options.dependsOn,
829
+ resolveParent: () => this._resolveParentStepId(options)
830
+ });
831
+ const agentStepId = this._observabilityEnabled ? this._observability.allocateStepId() : null;
832
+ const started = Date.now();
833
+ let status = "ok";
834
+ let output = null;
835
+ let error = null;
836
+ try {
837
+ const childCtx = new _WorkflowContext({
838
+ notifier: this.notifier,
839
+ senderId: this.senderId,
840
+ workflow: this.workflow,
841
+ input: childInput,
842
+ state: this.state,
843
+ observability: this._observability,
844
+ executionId: this._executionId,
845
+ agentName: name,
846
+ entryStepId: this._entryStepId,
847
+ traceParentStepId: this._traceParentStepId
848
+ });
849
+ childCtx._currentStepId = agentStepId;
850
+ output = await agent.run(childCtx);
851
+ if (agentStepId) {
852
+ childCtx.rootStepId = agentStepId;
853
+ }
854
+ return { output, stepId: agentStepId };
855
+ } catch (err) {
856
+ status = "error";
857
+ error = { message: err?.message ?? String(err), stack: err?.stack };
858
+ throw err;
859
+ } finally {
860
+ if (this._observabilityEnabled && agentStepId) {
861
+ await this._observability.recordStep(this._executionId, {
862
+ id: agentStepId,
863
+ parentStepId,
864
+ branchKey: options.branchKey ?? null,
865
+ siblingIndex: options.siblingIndex ?? null,
866
+ agentName: name,
867
+ kind: name,
868
+ type: STEP_TYPE_AGENT,
869
+ label: name,
870
+ status,
871
+ latencyMs: Date.now() - started,
872
+ input: snapshot(childInput),
873
+ output: snapshot(output),
874
+ state: snapshot(this.state),
875
+ error
876
+ });
877
+ this.rootStepId = agentStepId;
878
+ if (status === "ok" && !this._currentStepId) {
879
+ this._chainHeadStepId = agentStepId;
880
+ }
881
+ }
882
+ }
883
+ }
884
+ /**
885
+ * @param {string} name
886
+ * @param {{
887
+ * input?: *,
888
+ * dependsOn?: string[],
889
+ * parentStepIds?: string[],
890
+ * branchKey?: string,
891
+ * siblingIndex?: number,
892
+ * parentStepId?: string | null,
893
+ * }} [options]
894
+ */
895
+ async runAgent(name, options = {}) {
896
+ const { output, stepId } = await this._runAgentObserved(name, options);
897
+ if (stepId && !this._currentStepId) {
898
+ this._markTerminalSteps([stepId]);
899
+ }
900
+ return output;
901
+ }
902
+ /**
903
+ * @param {Array<string | { name: string, input?: * }> | Record<string, *>} spec
904
+ * @param {{ label?: string }} [options]
905
+ * @returns {Promise<{ results: *[] | Record<string, *>, stepIds: (string | null)[] }>}
906
+ */
907
+ async runAgents(spec, options = {}) {
908
+ const entries = normalizeRunAgentsSpec(spec);
909
+ const parentStepId = resolveRecordedParentStepId({
910
+ parentStepId: options.parentStepId,
911
+ resolveParent: () => this._resolveParentStepId(options)
689
912
  });
690
- return agent.run(childCtx);
913
+ const outcomes = await Promise.all(
914
+ entries.map(
915
+ (entry, index) => this._runAgentObserved(entry.name, {
916
+ input: entry.input,
917
+ parentStepId,
918
+ siblingIndex: index
919
+ })
920
+ )
921
+ );
922
+ const results = outcomes.map((outcome) => outcome.output);
923
+ const stepIds = outcomes.map((outcome) => outcome.stepId);
924
+ this._markTerminalSteps(stepIds);
925
+ if (Array.isArray(spec)) {
926
+ return { results, stepIds };
927
+ }
928
+ const keyed = {};
929
+ entries.forEach((entry, index) => {
930
+ keyed[entry.key] = results[index];
931
+ });
932
+ return { results: keyed, stepIds };
691
933
  }
692
934
  /** @param {object} opts */
693
935
  async sendAI(opts) {
@@ -796,6 +1038,12 @@ var WorkflowContext = class _WorkflowContext {
796
1038
  * error?: object | null,
797
1039
  * type?: string,
798
1040
  * latencyMs?: number,
1041
+ * parentStepId?: string | null,
1042
+ * dependsOn?: string[],
1043
+ * parentStepIds?: string[],
1044
+ * branchKey?: string,
1045
+ * siblingIndex?: number,
1046
+ * state?: *,
799
1047
  * }} step
800
1048
  */
801
1049
  async recordStep(step) {
@@ -814,8 +1062,10 @@ var WorkflowContext = class _WorkflowContext {
814
1062
  latencyMs: step.latencyMs ?? 0,
815
1063
  status: step.status ?? "ok",
816
1064
  error: step.error ?? null,
1065
+ parentStepId: step.parentStepId != null ? formatParentStepId(step.parentStepId) : formatParentStepId(this._currentStepId),
817
1066
  input: snapshot(step.input),
818
- output: snapshot(step.output)
1067
+ output: snapshot(step.output),
1068
+ state: snapshot(step.state !== void 0 ? step.state : this.state)
819
1069
  });
820
1070
  }
821
1071
  };
@@ -883,17 +1133,23 @@ var WorkflowObservabilityClient = class {
883
1133
  /**
884
1134
  * @param {{ appId?: string, token?: string | null }} [options]
885
1135
  */
886
- constructor({ appId = null, token = null } = {}) {
1136
+ constructor({ appId = null, token = null, requestTimeoutMs = 5e3 } = {}) {
887
1137
  this.appId = appId;
888
1138
  this.token = token;
1139
+ this.requestTimeoutMs = requestTimeoutMs;
889
1140
  }
890
- configure({ appId, token } = {}) {
1141
+ configure({ appId, token, requestTimeoutMs } = {}) {
891
1142
  if (appId !== void 0) this.appId = appId;
892
1143
  if (token !== void 0) this.token = token;
1144
+ if (requestTimeoutMs !== void 0) this.requestTimeoutMs = requestTimeoutMs;
893
1145
  }
894
1146
  _transport(url) {
895
1147
  const headers = this.token ? { authorization: `${this.token}` } : {};
896
- return new HttpTransport({ url, headers });
1148
+ return new HttpTransport({
1149
+ url,
1150
+ headers,
1151
+ timeoutMs: this.requestTimeoutMs
1152
+ });
897
1153
  }
898
1154
  async _post(url, body) {
899
1155
  if (!this.token) return;
@@ -986,7 +1242,17 @@ var WorkflowObservabilityClient = class {
986
1242
  }
987
1243
  setJsonColumn(body, "input", step.input);
988
1244
  setJsonColumn(body, "output", step.output);
1245
+ setJsonColumn(body, "state", step.state);
989
1246
  setJsonColumn(body, "error", step.error);
1247
+ if (step.parentStepId != null && step.parentStepId !== "") {
1248
+ body.parentStepId = step.parentStepId;
1249
+ }
1250
+ if (step.siblingIndex != null && step.siblingIndex !== "") {
1251
+ body.siblingIndex = step.siblingIndex;
1252
+ }
1253
+ if (step.branchKey != null && step.branchKey !== "") {
1254
+ body.branchKey = step.branchKey;
1255
+ }
990
1256
  await this._post(
991
1257
  DNotifierEndpoints.workflowExecutionStepsUrl(executionId),
992
1258
  body
@@ -998,15 +1264,27 @@ var WorkflowObservabilityClient = class {
998
1264
  // src/workflow/observability.js
999
1265
  var WorkflowObservability = class {
1000
1266
  /**
1001
- * @param {{ appId: string, token?: string | null, client?: WorkflowObservabilityClient }} options
1267
+ * @param {{
1268
+ * appId: string,
1269
+ * token?: string | null,
1270
+ * client?: WorkflowObservabilityClient,
1271
+ * appendOnly?: boolean,
1272
+ * }} options
1002
1273
  */
1003
- constructor({ appId, token = null, client }) {
1274
+ constructor({ appId, token = null, client, appendOnly = false }) {
1004
1275
  this.appId = appId;
1005
1276
  this.token = token;
1006
1277
  this.client = client ?? new WorkflowObservabilityClient({ appId, token });
1007
1278
  this.client.configure({ appId, token });
1008
1279
  this._registeredWorkflowNames = /* @__PURE__ */ new Set();
1009
1280
  this._stepCounter = 0;
1281
+ this._appendOnly = Boolean(appendOnly);
1282
+ }
1283
+ /**
1284
+ * @returns {string}
1285
+ */
1286
+ allocateStepId() {
1287
+ return shortId("step");
1010
1288
  }
1011
1289
  /**
1012
1290
  * @param {import("./workflow.js").Workflow} workflow
@@ -1028,6 +1306,9 @@ var WorkflowObservability = class {
1028
1306
  * @param {object} params
1029
1307
  */
1030
1308
  async startExecution(params) {
1309
+ if (this._appendOnly) {
1310
+ throw new Error("startExecution is not allowed in append-only workflow observability mode");
1311
+ }
1031
1312
  const executionId = shortId("exec");
1032
1313
  const startedAt = (/* @__PURE__ */ new Date()).toISOString();
1033
1314
  try {
@@ -1049,11 +1330,12 @@ var WorkflowObservability = class {
1049
1330
  * @param {object} step
1050
1331
  */
1051
1332
  async recordStep(executionId, step) {
1052
- if (!executionId) return;
1333
+ if (!executionId) return null;
1053
1334
  this._stepCounter += 1;
1054
- const id = step.id ?? `n${this._stepCounter}`;
1335
+ const id = step.id ?? this.allocateStepId();
1055
1336
  const type = resolveStepType(step);
1056
1337
  const kind = step.agentName ?? step.kind ?? step.apiName ?? null;
1338
+ const parentStepId = resolveGraphParentStepId(step);
1057
1339
  const record = {
1058
1340
  ...step,
1059
1341
  id,
@@ -1063,8 +1345,13 @@ var WorkflowObservability = class {
1063
1345
  agentName: step.agentName ?? null,
1064
1346
  kind,
1065
1347
  type,
1066
- step_type: type
1348
+ step_type: type,
1349
+ parentStepId,
1350
+ siblingIndex: step.siblingIndex ?? null,
1351
+ branchKey: step.branchKey ?? null
1067
1352
  };
1353
+ delete record.dependsOn;
1354
+ delete record.parentStepIds;
1068
1355
  try {
1069
1356
  await this.client.addStep(executionId, record);
1070
1357
  } catch {
@@ -1075,6 +1362,7 @@ var WorkflowObservability = class {
1075
1362
  * @param {object} params
1076
1363
  */
1077
1364
  async completeExecution(params) {
1365
+ if (this._appendOnly) return;
1078
1366
  if (!params.executionId) return;
1079
1367
  try {
1080
1368
  await this.client.updateExecution(params.executionId, {
@@ -1097,6 +1385,14 @@ function createWorkflowObservability(params) {
1097
1385
  }
1098
1386
 
1099
1387
  // src/workflow/runner.js
1388
+ function snapshot2(value) {
1389
+ try {
1390
+ if (value === void 0) return null;
1391
+ return JSON.parse(JSON.stringify(value));
1392
+ } catch {
1393
+ return String(value);
1394
+ }
1395
+ }
1100
1396
  var WorkflowRunner = class {
1101
1397
  /**
1102
1398
  * @param {{
@@ -1137,6 +1433,20 @@ var WorkflowRunner = class {
1137
1433
  executionId = started.executionId;
1138
1434
  startedAt = started.startedAt;
1139
1435
  }
1436
+ let entryStepId = null;
1437
+ if (observability && executionId) {
1438
+ const entryRecord = await observability.recordStep(executionId, {
1439
+ type: STEP_TYPE_ENTRY,
1440
+ kind: "entry",
1441
+ label: this.workflow.name,
1442
+ status: "ok",
1443
+ latencyMs: 0,
1444
+ parentStepId: null,
1445
+ input: snapshot2(input),
1446
+ state: snapshot2(state)
1447
+ });
1448
+ entryStepId = entryRecord?.id ?? null;
1449
+ }
1140
1450
  const ctx = new WorkflowContext({
1141
1451
  notifier: this.notifier,
1142
1452
  senderId: this.senderId,
@@ -1144,7 +1454,8 @@ var WorkflowRunner = class {
1144
1454
  input,
1145
1455
  state,
1146
1456
  observability,
1147
- executionId
1457
+ executionId,
1458
+ entryStepId
1148
1459
  });
1149
1460
  let result;
1150
1461
  let status = "ok";
@@ -1160,6 +1471,17 @@ var WorkflowRunner = class {
1160
1471
  throw err;
1161
1472
  } finally {
1162
1473
  if (observability && executionId) {
1474
+ await observability.recordStep(executionId, {
1475
+ type: STEP_TYPE_END,
1476
+ kind: "end",
1477
+ label: this.workflow.name,
1478
+ status,
1479
+ latencyMs: Date.now() - runStarted,
1480
+ parentStepId: ctx.getEndParentStepId(),
1481
+ output: snapshot2(status === "ok" ? result : null),
1482
+ state: snapshot2(ctx.state),
1483
+ error: errorPayload
1484
+ });
1163
1485
  const endedAt = (/* @__PURE__ */ new Date()).toISOString();
1164
1486
  const stepCount = observability.getStepCount();
1165
1487
  await observability.completeExecution({
@@ -1887,6 +2209,40 @@ var DNotifier = class {
1887
2209
  });
1888
2210
  return runner.run({ input });
1889
2211
  }
2212
+ /**
2213
+ * Resume a workflow context on a remote server (append-only observability).
2214
+ * @param {{
2215
+ * executionId: string,
2216
+ * workflowId: string,
2217
+ * parentStepId?: string | null,
2218
+ * }} traceCtx
2219
+ */
2220
+ async resumeWorkflowContext(traceCtx) {
2221
+ if (!traceCtx?.executionId || !traceCtx?.workflowId) {
2222
+ throw new Error("traceCtx requires executionId and workflowId");
2223
+ }
2224
+ const observability = createWorkflowObservability({
2225
+ appId: this.appId,
2226
+ token: this.authToken ?? null,
2227
+ appendOnly: true
2228
+ });
2229
+ const workflow = new Workflow({
2230
+ name: traceCtx.workflowId,
2231
+ observability: true,
2232
+ entry: async () => {
2233
+ }
2234
+ });
2235
+ await observability.registerWorkflow(workflow);
2236
+ return new WorkflowContext({
2237
+ notifier: this,
2238
+ senderId: this.userId,
2239
+ workflow,
2240
+ input: null,
2241
+ observability,
2242
+ executionId: traceCtx.executionId,
2243
+ traceParentStepId: traceCtx.parentStepId ?? null
2244
+ });
2245
+ }
1890
2246
  };
1891
2247
  // Annotate the CommonJS export names for ESM import in node:
1892
2248
  0 && (module.exports = {
@@ -128,6 +128,11 @@ export class DNotifier {
128
128
  result: any;
129
129
  state: {};
130
130
  }>;
131
+ resumeWorkflowContext(traceCtx: {
132
+ executionId: string;
133
+ workflowId: string;
134
+ parentStepId?: string | null;
135
+ }): Promise<WorkflowContext>;
131
136
  }
132
137
  import { Agent } from "./workflow/index.js";
133
138
  import { defineAgent } from "./workflow/index.js";
@@ -1 +1 @@
1
- {"version":3,"file":"dnotifier.d.ts","sourceRoot":"","sources":["../src/dnotifier.js"],"names":[],"mappings":"AAkDA;IAEE,cADW,OAAO,KAAK,CACF;IAGrB,oBADW,OAAO,WAAW,CACI;IAGjC,iBADW,OAAO,QAAQ,CACC;IAG3B,wBADW,OAAO,eAAe,CACQ;IAGzC,uBADW,OAAO,cAAc,CACO;IAGvC,sBADW,OAAO,aAAa,CACM;IAErC;;;;;;;;;;;OAsCC;IAtBC,WAAkB;IAClB,YAAoB;IACpB,YAAoB;IACpB,SAA+B;IAE/B,yBAAoD;IACpD,uBAAgD;IAChD,4BAA0D;IAE1D,qBAAwB;IACxB,mBAAsB;IACtB,yBAAiC;IACjC,sBAAiC;IACjC,wBAGE;IAEF,8CAGiD;IAGnD,qCA8MC;IA3LC,mBAAsC;IACtC,eAAwC;IAGxC,kBAAmD;IA8LrD,iBAHa;QAAE,iBAAiB,EAAE,MAAM,CAAC;QAAC,mBAAmB,EAAE,MAAM,CAAC;QAAC,kBAAkB,EAAE,MAAM,CAAC;QAAC,qBAAqB,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,OAAO,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,cAAc,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAiBtM;IAED;;;;;;qBA8DC;IASD,sDAJG;QAAwB,QAAQ,EAAxB,MAAM;QACmB,OAAO,EAAhC,MAAM,GAAG,MAAM;KACvB,GAAU,MAAM,CA+ClB;IAED;;qBAqBC;IAMD,4CAFW;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,gBA6B9B;IAMD,gDAFW;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,gBA0BjD;IAMD,kDAFW;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,EAAE,CAAC;QAAC,SAA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