@opengeni/react 0.6.0 → 0.6.2
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.d.ts +2 -0
- package/dist/index.js +116 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/message-timeline.tsx +5 -2
- package/src/timeline/projection.ts +142 -1
- package/src/timeline/types.ts +2 -0
package/dist/index.d.ts
CHANGED
|
@@ -42,6 +42,8 @@ type UserMessageItem = {
|
|
|
42
42
|
kind: "user-message";
|
|
43
43
|
id: string;
|
|
44
44
|
text: string;
|
|
45
|
+
/** Queued for a future turn whose start has not appeared in the event log. */
|
|
46
|
+
pending?: boolean;
|
|
45
47
|
/** Resources attached to this message (file uploads, repositories). */
|
|
46
48
|
resources: ResourceRef[];
|
|
47
49
|
/** Tools requested for the turn this message starts. */
|
package/dist/index.js
CHANGED
|
@@ -105,7 +105,8 @@ var WORKER_MESSAGE_TOOL = "session_send_message";
|
|
|
105
105
|
var WORKER_INTERRUPT_TOOL = "session_interrupt";
|
|
106
106
|
function buildTimeline(events) {
|
|
107
107
|
const items = [];
|
|
108
|
-
const
|
|
108
|
+
const prescan = prescanTurnAnchors(events);
|
|
109
|
+
const ordered = orderTimelineEvents(events, prescan);
|
|
109
110
|
const last = () => items[items.length - 1];
|
|
110
111
|
const closeStreamingTail = () => {
|
|
111
112
|
const open = last();
|
|
@@ -139,6 +140,7 @@ function buildTimeline(events) {
|
|
|
139
140
|
kind: "user-message",
|
|
140
141
|
id: event.id,
|
|
141
142
|
text: typeof payload.text === "string" ? payload.text : "",
|
|
143
|
+
...event.pendingUserMessage ? { pending: true } : {},
|
|
142
144
|
resources: resourceRefs(payload.resources),
|
|
143
145
|
tools: toolRefs(payload.tools),
|
|
144
146
|
occurredAt: event.occurredAt
|
|
@@ -320,6 +322,9 @@ ${message}` : message;
|
|
|
320
322
|
if (!isSessionStatus(status)) {
|
|
321
323
|
break;
|
|
322
324
|
}
|
|
325
|
+
if (!ATTENTION_STATUSES.has(status)) {
|
|
326
|
+
break;
|
|
327
|
+
}
|
|
323
328
|
const previous = [...items].reverse().find((item) => item.kind === "session-status");
|
|
324
329
|
if (previous?.status === status) {
|
|
325
330
|
break;
|
|
@@ -360,6 +365,9 @@ ${message}` : message;
|
|
|
360
365
|
break;
|
|
361
366
|
}
|
|
362
367
|
case "turn.cancelled": {
|
|
368
|
+
if (turnId && !prescan.startedTurnIds.has(turnId)) {
|
|
369
|
+
break;
|
|
370
|
+
}
|
|
363
371
|
const hadActivity = hasTurnActivity(items, turnId);
|
|
364
372
|
finalizeOpen(turnId, "cancelled");
|
|
365
373
|
items.push(turnEndItem(event, "cancelled", null));
|
|
@@ -440,6 +448,108 @@ function groupTimeline(items) {
|
|
|
440
448
|
}
|
|
441
449
|
return groups;
|
|
442
450
|
}
|
|
451
|
+
function prescanTurnAnchors(events) {
|
|
452
|
+
const ordered = [...events].sort((a, b) => a.sequence - b.sequence);
|
|
453
|
+
const queuedTurnByTrigger = /* @__PURE__ */ new Map();
|
|
454
|
+
const startSeqByTrigger = /* @__PURE__ */ new Map();
|
|
455
|
+
const cancelledTurnIds = /* @__PURE__ */ new Set();
|
|
456
|
+
const fallbackSeqByTurn = /* @__PURE__ */ new Map();
|
|
457
|
+
const startedTurnIds = /* @__PURE__ */ new Set();
|
|
458
|
+
for (const event of ordered) {
|
|
459
|
+
const payload = asRecord(event.payload);
|
|
460
|
+
const turnId = event.turnId ?? null;
|
|
461
|
+
if (event.type === "turn.queued") {
|
|
462
|
+
const triggerEventId = typeof payload.triggerEventId === "string" ? payload.triggerEventId : null;
|
|
463
|
+
const queuedTurnId = typeof payload.turnId === "string" ? payload.turnId : turnId;
|
|
464
|
+
if (triggerEventId && queuedTurnId) {
|
|
465
|
+
queuedTurnByTrigger.set(triggerEventId, queuedTurnId);
|
|
466
|
+
}
|
|
467
|
+
continue;
|
|
468
|
+
}
|
|
469
|
+
if (event.type === "turn.started") {
|
|
470
|
+
const triggerEventId = typeof payload.triggerEventId === "string" ? payload.triggerEventId : null;
|
|
471
|
+
if (triggerEventId) {
|
|
472
|
+
startSeqByTrigger.set(triggerEventId, event.sequence);
|
|
473
|
+
}
|
|
474
|
+
if (turnId) {
|
|
475
|
+
startedTurnIds.add(turnId);
|
|
476
|
+
}
|
|
477
|
+
} else if (event.type === "turn.cancelled" && turnId) {
|
|
478
|
+
cancelledTurnIds.add(turnId);
|
|
479
|
+
}
|
|
480
|
+
if (turnId && event.type !== "turn.queued" && event.type !== "turn.cancelled") {
|
|
481
|
+
const previous = fallbackSeqByTurn.get(turnId);
|
|
482
|
+
if (previous === void 0 || event.sequence < previous) {
|
|
483
|
+
fallbackSeqByTurn.set(turnId, event.sequence);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
if (turnId && isAgentActivityEvent(event.type)) {
|
|
487
|
+
startedTurnIds.add(turnId);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
for (const [triggerEventId, turnId] of queuedTurnByTrigger) {
|
|
491
|
+
if (!startSeqByTrigger.has(triggerEventId)) {
|
|
492
|
+
const fallbackSeq = fallbackSeqByTurn.get(turnId);
|
|
493
|
+
if (fallbackSeq !== void 0) {
|
|
494
|
+
startSeqByTrigger.set(triggerEventId, fallbackSeq);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
const cancelledBeforeStartTriggers = /* @__PURE__ */ new Set();
|
|
499
|
+
for (const [triggerEventId, turnId] of queuedTurnByTrigger) {
|
|
500
|
+
if (cancelledTurnIds.has(turnId) && !startSeqByTrigger.has(triggerEventId) && !fallbackSeqByTurn.has(turnId)) {
|
|
501
|
+
cancelledBeforeStartTriggers.add(triggerEventId);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
return { queuedTurnByTrigger, startSeqByTrigger, cancelledBeforeStartTriggers, startedTurnIds };
|
|
505
|
+
}
|
|
506
|
+
function orderTimelineEvents(events, prescan) {
|
|
507
|
+
const ordered = [...events].sort((a, b) => a.sequence - b.sequence);
|
|
508
|
+
const insertions = /* @__PURE__ */ new Map();
|
|
509
|
+
const pending = [];
|
|
510
|
+
for (const event of ordered) {
|
|
511
|
+
if (event.type !== "user.message") {
|
|
512
|
+
continue;
|
|
513
|
+
}
|
|
514
|
+
const queuedTurnId = prescan.queuedTurnByTrigger.get(event.id);
|
|
515
|
+
if (!queuedTurnId) {
|
|
516
|
+
pushInsertion(insertions, event.sequence, event);
|
|
517
|
+
continue;
|
|
518
|
+
}
|
|
519
|
+
if (prescan.cancelledBeforeStartTriggers.has(event.id)) {
|
|
520
|
+
continue;
|
|
521
|
+
}
|
|
522
|
+
const startSeq = prescan.startSeqByTrigger.get(event.id);
|
|
523
|
+
if (startSeq !== void 0) {
|
|
524
|
+
pushInsertion(insertions, startSeq, event);
|
|
525
|
+
continue;
|
|
526
|
+
}
|
|
527
|
+
pending.push({ ...event, pendingUserMessage: true });
|
|
528
|
+
}
|
|
529
|
+
const projected = [];
|
|
530
|
+
for (const event of ordered) {
|
|
531
|
+
const before = insertions.get(event.sequence);
|
|
532
|
+
if (before) {
|
|
533
|
+
projected.push(...before);
|
|
534
|
+
}
|
|
535
|
+
if (event.type !== "user.message") {
|
|
536
|
+
projected.push(event);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
projected.push(...pending);
|
|
540
|
+
return projected;
|
|
541
|
+
}
|
|
542
|
+
function pushInsertion(insertions, sequence, event) {
|
|
543
|
+
const bucket = insertions.get(sequence);
|
|
544
|
+
if (bucket) {
|
|
545
|
+
bucket.push(event);
|
|
546
|
+
} else {
|
|
547
|
+
insertions.set(sequence, [event]);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
function isAgentActivityEvent(type) {
|
|
551
|
+
return type.startsWith("agent.") || type.startsWith("sandbox.");
|
|
552
|
+
}
|
|
443
553
|
function turnEndItem(event, outcome, failureText) {
|
|
444
554
|
return {
|
|
445
555
|
kind: "turn-end",
|
|
@@ -572,6 +682,7 @@ function asRecord(value) {
|
|
|
572
682
|
return value !== null && typeof value === "object" ? value : {};
|
|
573
683
|
}
|
|
574
684
|
var SESSION_STATUSES = ["queued", "running", "idle", "requires_action", "failed", "cancelled"];
|
|
685
|
+
var ATTENTION_STATUSES = /* @__PURE__ */ new Set(["requires_action", "failed", "cancelled"]);
|
|
575
686
|
function resourceRefs(value) {
|
|
576
687
|
if (!Array.isArray(value)) {
|
|
577
688
|
return [];
|
|
@@ -6084,7 +6195,10 @@ function UserMessageRow({
|
|
|
6084
6195
|
item,
|
|
6085
6196
|
renderMessageText
|
|
6086
6197
|
}) {
|
|
6087
|
-
return /* @__PURE__ */ jsx15("div", { className: "animate-og-enter flex justify-end", children: /* @__PURE__ */
|
|
6198
|
+
return /* @__PURE__ */ jsx15("div", { className: "animate-og-enter flex justify-end", children: /* @__PURE__ */ jsxs12("div", { className: "flex max-w-[85%] min-w-0 flex-col items-end gap-1", children: [
|
|
6199
|
+
item.pending ? /* @__PURE__ */ jsx15("span", { className: "px-1 text-og-xs text-og-fg-subtle", children: "queued" }) : null,
|
|
6200
|
+
/* @__PURE__ */ jsx15("div", { className: "w-fit max-w-full min-w-0 rounded-og-lg rounded-br-og-xs border border-og-border bg-og-surface-2 px-4 py-2.5 text-og-md leading-6 text-og-fg", children: renderMessageText ? renderMessageText(item.text, item) : /* @__PURE__ */ jsx15(Markdown, { children: item.text }) })
|
|
6201
|
+
] }) });
|
|
6088
6202
|
}
|
|
6089
6203
|
function AgentMessageRow({
|
|
6090
6204
|
item,
|