@yaklabs-ai/plugin-sdk 0.15.3 → 0.26.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.
@@ -533,43 +533,98 @@ function createTranscriptReview(options = {}) {
533
533
  }
534
534
  starts.sort((left, right) => left.boundary - right.boundary);
535
535
  const runStarts = [...finalRuns.values()].map((run) => ({ runId: run.runId, boundary: run.boundary })).sort((left, right) => left.boundary - right.boundary);
536
+ const runEndAt = Array.from({ length: runStarts.length });
537
+ for (let at = runStarts.length - 1; at >= 0; at -= 1) {
538
+ const next = runStarts[at + 1];
539
+ runEndAt[at] = next === void 0 ? endPosition : next.boundary > runStarts[at].boundary ? next.boundary : runEndAt[at + 1];
540
+ }
541
+ const runStartIndex = /* @__PURE__ */ new Map();
542
+ runStarts.forEach((run, at) => runStartIndex.set(run.runId, at));
543
+ const lastProseBefore = [];
544
+ let lastProse;
545
+ for (const record of records) {
546
+ lastProseBefore.push(lastProse);
547
+ if (record.hasProse)
548
+ lastProse = record.position;
549
+ }
536
550
  const previousProse = (before) => {
537
- let index = byPosition.get(before);
538
- if (index === void 0)
551
+ const index = byPosition.get(before);
552
+ return index === void 0 ? void 0 : lastProseBefore[index];
553
+ };
554
+ const spanIndexAt = (position) => {
555
+ if (position >= endPosition)
539
556
  return void 0;
540
- for (index -= 1; index >= 0; index -= 1) {
541
- if (records[index].hasProse)
542
- return records[index].position;
557
+ let low = 0;
558
+ let high = starts.length - 1;
559
+ let found;
560
+ while (low <= high) {
561
+ const middle = low + high >> 1;
562
+ if (starts[middle].boundary <= position) {
563
+ found = middle;
564
+ low = middle + 1;
565
+ } else {
566
+ high = middle - 1;
567
+ }
543
568
  }
544
- return void 0;
569
+ return found;
570
+ };
571
+ const ownRunsOf = starts.map(() => ({
572
+ ids: [],
573
+ seen: /* @__PURE__ */ new Set()
574
+ }));
575
+ const addOwnRun = (span, runId) => {
576
+ const own = ownRunsOf[span];
577
+ if (own.seen.has(runId))
578
+ return;
579
+ own.seen.add(runId);
580
+ own.ids.push(runId);
581
+ };
582
+ for (const run of runStarts) {
583
+ const started = finalRuns.get(run.runId).startedPosition;
584
+ if (started === void 0)
585
+ continue;
586
+ const span = spanIndexAt(started);
587
+ if (span !== void 0)
588
+ addOwnRun(span, run.runId);
589
+ }
590
+ const joinedOf = starts.map(() => []);
591
+ for (const input of inputs) {
592
+ if (input.runId === void 0)
593
+ continue;
594
+ const span = spanIndexAt(input.position);
595
+ if (span === void 0)
596
+ continue;
597
+ addOwnRun(span, input.runId);
598
+ if (input.human && !input.opensRun)
599
+ joinedOf[span].push(input);
600
+ }
601
+ const firstInputAtOrAfter = (position) => {
602
+ let low = 0;
603
+ let high = inputs.length;
604
+ while (low < high) {
605
+ const middle = low + high >> 1;
606
+ if (inputs[middle].position < position)
607
+ low = middle + 1;
608
+ else
609
+ high = middle;
610
+ }
611
+ return low;
545
612
  };
546
613
  const spans = starts.map((start, index) => {
547
614
  const next = starts[index + 1];
548
615
  const end = next?.boundary ?? endPosition;
549
616
  const closingEnd = next?.opener !== void 0 ? Math.max(end, next.opener.position + 1) : end;
550
- const ownRuns = [];
617
+ const ownRuns = ownRunsOf[index].ids;
551
618
  const closingRuns = [];
552
- for (const run of runStarts) {
553
- const started = finalRuns.get(run.runId).startedPosition;
554
- if (started !== void 0 && started >= start.boundary && started < end) {
555
- if (!ownRuns.includes(run.runId))
556
- ownRuns.push(run.runId);
557
- }
558
- }
559
- const joined = [];
560
- for (const input of inputs) {
561
- if (input.runId === void 0)
562
- continue;
563
- if (input.position >= start.boundary && input.position < end) {
564
- if (!ownRuns.includes(input.runId))
565
- ownRuns.push(input.runId);
566
- if (input.human && !input.opensRun)
567
- joined.push(input);
568
- } else if (input.position >= end && input.position < closingEnd) {
569
- if (!closingRuns.includes(input.runId))
570
- closingRuns.push(input.runId);
619
+ const closingSeen = /* @__PURE__ */ new Set();
620
+ for (let at = firstInputAtOrAfter(end); at < inputs.length && inputs[at].position < closingEnd; at += 1) {
621
+ const runId = inputs[at].runId;
622
+ if (runId !== void 0 && !closingSeen.has(runId)) {
623
+ closingSeen.add(runId);
624
+ closingRuns.push(runId);
571
625
  }
572
626
  }
627
+ const joined = joinedOf[index];
573
628
  ownRuns.sort((left, right) => finalRuns.get(left).boundary - finalRuns.get(right).boundary);
574
629
  const close = next !== void 0 ? next.opener !== void 0 ? "next-opener" : "next-opener-unresolved" : cutAt !== void 0 ? "time-bound" : "end-of-store";
575
630
  const previousAnswer = previousProse(start.boundary);
@@ -626,12 +681,30 @@ function createTranscriptReview(options = {}) {
626
681
  },
627
682
  spanAt: (position) => position < endPosition ? lastAtOrBefore(spans, position) : void 0,
628
683
  runExtent: (runId) => {
629
- const run = finalRuns.get(runId);
630
- if (run === void 0)
684
+ const at = runStartIndex.get(runId);
685
+ return at === void 0 ? void 0 : { start: runStarts[at].boundary, end: runEndAt[at] };
686
+ },
687
+ runAt: (position) => {
688
+ let low = 0;
689
+ let high = runStarts.length - 1;
690
+ let found;
691
+ while (low <= high) {
692
+ const middle = low + high >> 1;
693
+ if (runStarts[middle].boundary <= position) {
694
+ found = middle;
695
+ low = middle + 1;
696
+ } else {
697
+ high = middle - 1;
698
+ }
699
+ }
700
+ if (found === void 0)
701
+ return void 0;
702
+ const start = runStarts[found].boundary;
703
+ while (found > 0 && runStarts[found - 1].boundary === start)
704
+ found -= 1;
705
+ if (position >= runEndAt[found])
631
706
  return void 0;
632
- const at = runStarts.findIndex((candidate) => candidate.runId === runId);
633
- const next = runStarts.slice(at + 1).find((candidate) => candidate.boundary > run.boundary);
634
- return { start: run.boundary, end: next?.boundary ?? endPosition };
707
+ return { runId: runStarts[found].runId, start, end: runEndAt[found] };
635
708
  },
636
709
  inputById: (inputId) => inputById.get(inputId),
637
710
  attemptAt: (position, block) => {
@@ -15,16 +15,16 @@ export declare const ATTACHMENTS_CUSTOM_TYPE = "attachments";
15
15
  export declare function branchEntryIds(entries: readonly TranscriptTreeEntryLike[]): ReadonlySet<string>;
16
16
 
17
17
  /**
18
- * Every `type: "custom"` entry of one `customType`, oldest→newest, with every
18
+ * Every `type: "custom"` entry of one `customType`, oldest->newest, with every
19
19
  * field ({@link TranscriptSourceEntryLike}'s id/timestamp/tree links plus the
20
- * entry's own `data`) preserved unchanged — `data` is returned exactly as it
20
+ * entry's own `data`) preserved unchanged - `data` is returned exactly as it
21
21
  * arrived, opaque and unvalidated, never coerced toward a schema this module
22
22
  * cannot know.
23
23
  *
24
24
  * `options.branch` is required, deliberately: `"active"` filters to
25
25
  * {@link branchEntryIds}; `"all"` returns every matching entry in the flat
26
26
  * log, rewind-abandoned or not. A silent default would let a caller reach
27
- * for whichever one it did not mean to — pick `"all"` only when the caller
27
+ * for whichever one it did not mean to - pick `"all"` only when the caller
28
28
  * itself needs to reason about abandoned entries (an audit, a recovery
29
29
  * tool); an ordinary reader states `"active"` explicitly.
30
30
  */
@@ -53,7 +53,7 @@ declare type ProducedResourceAction = "created" | "updated";
53
53
 
54
54
  /** One URI a tool call created or updated as a side effect. */
55
55
  declare interface ProducedResourceDeclaration {
56
- /** A `scheme://…` URI or an absolute local file path, compared as an exact string. */
56
+ /** A `scheme://...` URI or an absolute local file path, compared as an exact string. */
57
57
  readonly uri: string;
58
58
  readonly action: ProducedResourceAction;
59
59
  }
@@ -92,7 +92,7 @@ export declare interface TranscriptEntryLike {
92
92
  readonly id: string;
93
93
  readonly type: string;
94
94
  readonly customType?: string;
95
- /** Opaque. Never parsed or validated here — a feature's own schema owns that. */
95
+ /** Opaque. Never parsed or validated here - a feature's own schema owns that. */
96
96
  readonly data?: unknown;
97
97
  }
98
98
 
@@ -162,7 +162,9 @@ export declare interface TurnSegment {
162
162
  * nothing distinguishes a steer from a fresh request.
163
163
  *
164
164
  * `throughIndex` bounds the walk for a caller holding only a prefix; segments
165
- * are returned oldest first.
165
+ * are returned oldest first. A daemon reader that cannot hold the entry list
166
+ * looks the run up by run id instead (engine redesign 3.1,
167
+ * `docs/engine-redesign/decisions/2026-10-28-3.1-turn-definition.md`).
166
168
  */
167
169
  export declare function turnSegments(entries: readonly TurnBoundaryEntry[], throughIndex?: number): readonly TurnSegment[];
168
170