@lostgradient/cinder 0.8.0 → 0.11.0
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/CHANGELOG.md +25 -0
- package/README.md +2 -2
- package/components.json +140 -18
- package/dist/components/_internal/command-list-context.d.ts +3 -3
- package/dist/components/_internal/create-command-list-state.svelte.d.ts +11 -11
- package/dist/components/access-gate/index.js +435 -218
- package/dist/components/approval-card/approval-card-actions.svelte.d.ts +16 -0
- package/dist/components/approval-card/approval-card-state.d.ts +65 -0
- package/dist/components/approval-card/approval-card.css +269 -92
- package/dist/components/approval-card/approval-card.schema.js +10 -31
- package/dist/components/approval-card/approval-card.svelte.d.ts +3 -3
- package/dist/components/approval-card/approval-card.types.d.ts +14 -28
- package/dist/components/approval-card/index.d.ts +1 -1
- package/dist/components/approval-card/index.js +4268 -2884
- package/dist/components/card/card.css +5 -0
- package/dist/components/card/card.schema.js +2 -2
- package/dist/components/card/card.types.d.ts +2 -2
- package/dist/components/card/index.js +2 -1
- package/dist/components/chat/builders.d.ts +17 -8
- package/dist/components/chat/chat.schema.js +44 -2
- package/dist/components/chat/chat.svelte.d.ts +4 -2
- package/dist/components/chat/chat.types.d.ts +34 -3
- package/dist/components/chat/container/chat.svelte.d.ts +4 -2
- package/dist/components/chat/conversation-model.d.ts +1 -1
- package/dist/components/chat/index.d.ts +4 -4
- package/dist/components/chat/index.js +2767 -6278
- package/dist/components/chat/input/chat-attachment-serialization.d.ts +9 -0
- package/dist/components/chat/input/chat-input.svelte.d.ts +22 -1
- package/dist/components/chat/input/index.d.ts +1 -0
- package/dist/components/chat/utilities/conversation.d.ts +6 -6
- package/dist/components/chat-composer-popover/chat-composer-popover-filter.d.ts +11 -0
- package/dist/components/chat-composer-popover/chat-composer-popover.css +7 -0
- package/dist/components/chat-composer-popover/chat-composer-popover.css.d.ts +1 -0
- package/dist/components/chat-composer-popover/chat-composer-popover.schema.d.ts +3 -0
- package/dist/components/chat-composer-popover/chat-composer-popover.schema.js +150 -0
- package/dist/components/chat-composer-popover/chat-composer-popover.svelte.d.ts +46 -0
- package/dist/components/chat-composer-popover/chat-composer-popover.types.d.ts +77 -0
- package/dist/components/chat-composer-popover/chat-composer-popover.variables.d.ts +2 -0
- package/dist/components/chat-composer-popover/chat-composer-popover.variables.js +61 -0
- package/dist/components/chat-composer-popover/index.d.ts +6 -0
- package/dist/components/chat-composer-popover/index.js +3285 -0
- package/dist/components/chat-conversation-header/index.js +577 -4537
- package/dist/components/chat-conversation-list/index.js +24 -3984
- package/dist/components/code-block/code-block.schema.js +5 -1
- package/dist/components/code-block/code-block.types.d.ts +6 -0
- package/dist/components/code-block/index.js +4 -4
- package/dist/components/command-item/index.js +7 -6
- package/dist/components/command-menu/command-menu.schema.js +5 -1
- package/dist/components/command-menu/command-menu.types.d.ts +2 -0
- package/dist/components/command-menu/index.js +48 -19
- package/dist/components/command-palette/index.js +40 -14
- package/dist/components/connection-indicator/connection-indicator.css +136 -0
- package/dist/components/connection-indicator/connection-indicator.css.d.ts +1 -0
- package/dist/components/connection-indicator/connection-indicator.schema.d.ts +3 -0
- package/dist/components/connection-indicator/connection-indicator.schema.js +89 -0
- package/dist/components/connection-indicator/connection-indicator.svelte.d.ts +21 -0
- package/dist/components/connection-indicator/connection-indicator.types.d.ts +46 -0
- package/dist/components/connection-indicator/connection-indicator.variables.d.ts +2 -0
- package/dist/components/connection-indicator/connection-indicator.variables.js +61 -0
- package/dist/components/connection-indicator/index.d.ts +5 -0
- package/dist/components/connection-indicator/index.js +409 -0
- package/dist/components/container/container.schema.js +4 -4
- package/dist/components/event-stream-viewer/index.js +44 -44
- package/dist/components/experimental/json-viewer/index.js +44 -44
- package/dist/components/invocation-rule-builder/index.d.ts +1 -1
- package/dist/components/invocation-rule-builder/index.js +305 -150
- package/dist/components/invocation-rule-builder/invocation-rule-builder.css +28 -0
- package/dist/components/invocation-rule-builder/invocation-rule-builder.schema.js +89 -5
- package/dist/components/invocation-rule-builder/invocation-rule-builder.svelte.d.ts +2 -1
- package/dist/components/invocation-rule-builder/invocation-rule-builder.types.d.ts +114 -16
- package/dist/components/json-schema-editor/index.js +5 -2
- package/dist/components/json-viewer/index.js +44 -44
- package/dist/components/json-viewer/json-viewer.css +10 -6
- package/dist/components/payload-inspector/index.d.ts +1 -1
- package/dist/components/payload-inspector/index.js +306 -1422
- package/dist/components/payload-inspector/payload-inspector.css +15 -75
- package/dist/components/payload-inspector/payload-inspector.schema.js +5 -41
- package/dist/components/payload-inspector/payload-inspector.svelte.d.ts +5 -5
- package/dist/components/payload-inspector/payload-inspector.types.d.ts +10 -56
- package/dist/components/run-step-timeline/index.d.ts +1 -1
- package/dist/components/run-step-timeline/index.js +992 -559
- package/dist/components/run-step-timeline/run-step-branch-disclosure.svelte.d.ts +17 -0
- package/dist/components/run-step-timeline/run-step-timeline.css +124 -0
- package/dist/components/run-step-timeline/run-step-timeline.schema.js +873 -350
- package/dist/components/run-step-timeline/run-step-timeline.svelte.d.ts +1 -15
- package/dist/components/run-step-timeline/run-step-timeline.types.d.ts +182 -5
- package/dist/components/run-step-timeline/run-step-timeline.utilities.d.ts +52 -0
- package/dist/components/schedule-builder/index.d.ts +5 -0
- package/dist/components/schedule-builder/index.js +3176 -0
- package/dist/components/schedule-builder/schedule-builder.css +121 -0
- package/dist/components/schedule-builder/schedule-builder.css.d.ts +1 -0
- package/dist/components/schedule-builder/schedule-builder.schema.d.ts +3 -0
- package/dist/components/schedule-builder/schedule-builder.schema.js +141 -0
- package/dist/components/schedule-builder/schedule-builder.svelte.d.ts +22 -0
- package/dist/components/schedule-builder/schedule-builder.types.d.ts +130 -0
- package/dist/components/schedule-builder/schedule-builder.utilities.d.ts +78 -0
- package/dist/components/schedule-builder/schedule-builder.variables.d.ts +2 -0
- package/dist/components/schedule-builder/schedule-builder.variables.js +61 -0
- package/dist/components/tab/index.js +5 -2
- package/dist/components/tab/tab.schema.js +7 -3
- package/dist/components/tab/tab.svelte.d.ts +2 -1
- package/dist/components/tab/tab.types.d.ts +8 -2
- package/dist/components/tabs/index.js +5 -2
- package/dist/components/tag-input/index.js +22 -4
- package/dist/components/tag-input/tag-input.schema.js +5 -1
- package/dist/components/tag-input/tag-input.types.d.ts +4 -0
- package/dist/components/team-section/index.js +2 -1
- package/dist/components/testimonial-section/index.js +2 -1
- package/dist/index.d.ts +10 -4
- package/dist/index.js +28577 -30168
- package/dist/server/components/access-gate/index.js +3 -1
- package/dist/server/components/accordion/index.js +2 -2
- package/dist/server/components/alert-dialog/index.js +2 -2
- package/dist/server/components/approval-card/index.js +15 -19
- package/dist/server/components/autocomplete/index.js +7 -7
- package/dist/server/components/avatar-group/index.js +5 -5
- package/dist/server/components/button-group/index.js +3 -5
- package/dist/server/components/card/index.js +2 -2
- package/dist/server/components/chat/index.js +15 -12
- package/dist/server/components/chat-composer-popover/index.js +26 -0
- package/dist/server/components/chat-conversation-header/index.js +10 -11
- package/dist/server/components/chat-conversation-list/index.js +4 -5
- package/dist/server/components/checkbox/index.js +3 -3
- package/dist/server/components/choice-grid/index.js +2 -2
- package/dist/server/components/code-block/index.js +2 -2
- package/dist/server/components/color-field/index.js +3 -3
- package/dist/server/components/combobox/index.js +6 -6
- package/dist/server/components/command-item/index.js +5 -3
- package/dist/server/components/command-menu/index.js +6 -4
- package/dist/server/components/command-palette/index.js +2 -2
- package/dist/server/components/confirm-dialog/index.js +2 -2
- package/dist/server/components/connection-indicator/index.js +16 -0
- package/dist/server/components/context-menu/index.js +5 -5
- package/dist/server/components/data-table/index.js +5 -5
- package/dist/server/components/date-picker/index.js +6 -6
- package/dist/server/components/date-range-field/index.js +7 -7
- package/dist/server/components/description-list/index.js +3 -5
- package/dist/server/components/diff-viewer/index.js +9 -8
- package/dist/server/components/drawer/index.js +3 -3
- package/dist/server/components/dropdown/index.js +4 -4
- package/dist/server/components/event-stream-viewer/index.js +2 -2
- package/dist/server/components/experimental/json-viewer/index.js +2 -2
- package/dist/server/components/faceted-filter-bar/index.js +1 -1
- package/dist/server/components/hover-card/index.js +1 -1
- package/dist/server/components/input/index.js +3 -3
- package/dist/server/components/invocation-rule-builder/index.js +1 -1
- package/dist/server/components/json-schema-editor/index.js +24 -23
- package/dist/server/components/json-viewer/index.js +2 -2
- package/dist/server/components/markdown-editor/index.js +13 -13
- package/dist/server/components/modal/index.js +1 -1
- package/dist/server/components/multi-select/index.js +1 -1
- package/dist/server/components/newsletter-section/index.js +3 -3
- package/dist/server/components/payload-inspector/index.js +4 -16
- package/dist/server/components/popover/index.js +5 -5
- package/dist/server/components/review-editor/index.js +27 -26
- package/dist/server/components/run-step-timeline/index.js +2 -2
- package/dist/server/components/schedule-builder/index.js +30 -0
- package/dist/server/components/schema-form/index.js +4 -4
- package/dist/server/components/secret-value-field/index.js +3 -5
- package/dist/server/components/segment/index.js +3 -3
- package/dist/server/components/segmented-control/index.js +4 -4
- package/dist/server/components/selection-popover/index.js +4 -4
- package/dist/server/components/sheet/index.js +2 -2
- package/dist/server/components/side-navigation/index.js +2 -2
- package/dist/server/components/sidebar/index.js +3 -3
- package/dist/server/components/tab/index.js +2 -2
- package/dist/server/components/table/index.js +3 -3
- package/dist/server/components/tabs/index.js +4 -4
- package/dist/server/components/tag-input/index.js +3 -3
- package/dist/server/components/team-section/index.js +8 -8
- package/dist/server/components/testimonial-section/index.js +2 -2
- package/dist/server/components/time-field/index.js +5 -3
- package/dist/server/components/toggle/index.js +2 -2
- package/dist/server/components/tooltip/index.js +1 -1
- package/dist/server/index.js +235 -211
- package/dist/server/{index.server-20y4mdhm.js → index.server-0chhpkg7.js} +40 -14
- package/dist/server/index.server-0sx92swg.js +9 -0
- package/dist/server/{index.server-ecm1vs3g.js → index.server-1nq7z1qw.js} +1 -1
- package/dist/server/{index.server-s9khh4ry.js → index.server-2bbwajb2.js} +3 -5
- package/dist/server/index.server-2hqrv7ca.js +9 -0
- package/dist/server/{index.server-69epaape.js → index.server-2qj6s2mh.js} +1 -1
- package/dist/server/{index.server-gxf0d1p5.js → index.server-2s5h1d05.js} +2 -2
- package/dist/server/{index.server-qfa2rxzx.js → index.server-2zdbz3rj.js} +3 -5
- package/dist/server/{index.server-pt8b65mt.js → index.server-38aywdk1.js} +1 -1
- package/dist/server/{index.server-0jhra85x.js → index.server-3w72dxz7.js} +4 -4
- package/dist/server/{index.server-rermas0k.js → index.server-47v2fhp4.js} +4 -4
- package/dist/server/{index.server-v4zabrsx.js → index.server-4x4hgvqe.js} +434 -26
- package/dist/server/{index.server-9j5sym59.js → index.server-4x91gzy1.js} +2 -2
- package/dist/server/{index.server-q48q15g7.js → index.server-4y2jtvv1.js} +4 -2
- package/dist/server/{index.server-j3ddzcaa.js → index.server-5gzyqv78.js} +6 -6
- package/dist/server/index.server-67qgdypc.js +9 -0
- package/dist/server/index.server-6hnfzc7f.js +263 -0
- package/dist/server/{index.server-9jete4xx.js → index.server-6sh11ap6.js} +4 -4
- package/dist/server/{index.server-4ztq565m.js → index.server-85p4ydph.js} +1 -1
- package/dist/server/{index.server-4nk7gy0q.js → index.server-894t97kv.js} +1 -1
- package/dist/server/{index.server-1vscnped.js → index.server-8dt36sdm.js} +2 -1
- package/dist/server/{index.server-bfsbp9dz.js → index.server-8xvc73zh.js} +4 -4
- package/dist/server/{index.server-cvnw3hw9.js → index.server-9kz37z89.js} +1 -1
- package/dist/server/{index.server-kc1k02tk.js → index.server-9ykk1kbg.js} +1 -1
- package/dist/server/{index.server-g789yep6.js → index.server-aqethy0w.js} +2 -2
- package/dist/server/index.server-be9bpqeh.js +93 -0
- package/dist/server/{index.server-wc9aggfz.js → index.server-bmxbsk4y.js} +7 -7
- package/dist/server/{index.server-f3z7tpxr.js → index.server-c42b462p.js} +2 -4
- package/dist/server/{index.server-7vyzen5x.js → index.server-c5qv3p61.js} +171 -63
- package/dist/server/index.server-cch0eed5.js +144 -0
- package/dist/server/{index.server-q89dz8h1.js → index.server-d3pqthtp.js} +4 -3
- package/dist/server/{index.server-jk4rx4aa.js → index.server-dmmvwy6p.js} +1 -1
- package/dist/server/{index.server-hcfnae5y.js → index.server-dwwqssey.js} +4 -4
- package/dist/server/{index.server-e8x1hgw6.js → index.server-dz1r9xw5.js} +4 -4
- package/dist/server/{index.server-wm7mk5kw.js → index.server-ez5hp0ya.js} +1 -1
- package/dist/server/{index.server-wc8dbm5e.js → index.server-g95bk8rc.js} +4 -2
- package/dist/server/index.server-gkazv439.js +576 -0
- package/dist/server/index.server-gmh5ar16.js +2 -0
- package/dist/server/{index.server-dp9j2kkr.js → index.server-h0cvwvhy.js} +1 -1
- package/dist/server/{index.server-cbtg8rq5.js → index.server-h89zk5ev.js} +8 -8
- package/dist/server/{index.server-pacrqvyz.js → index.server-h90pjrez.js} +1 -1
- package/dist/server/{index.server-p8d04em5.js → index.server-hcsd5gdb.js} +6 -2
- package/dist/server/{index.server-n39drzes.js → index.server-hpeavvnq.js} +1 -1
- package/dist/server/{index.server-1p3patnj.js → index.server-hx91ng7z.js} +1 -1
- package/dist/server/{index.server-mehav5vs.js → index.server-jdcq5zza.js} +7 -7
- package/dist/server/{index.server-jync915v.js → index.server-jfrssta6.js} +25 -25
- package/dist/server/{index.server-jtj3r53y.js → index.server-jgb8yh5k.js} +1 -1
- package/dist/server/{index.server-ejyf7e48.js → index.server-jj76374p.js} +1 -1
- package/dist/server/{index.server-w1g5q9j9.js → index.server-jtgw9d23.js} +4 -2
- package/dist/server/{index.server-hd8gpehd.js → index.server-jxseyx33.js} +1 -1
- package/dist/server/{index.server-kg2sepsr.js → index.server-krqvnt6p.js} +14 -15
- package/dist/server/{index.server-0e1m3agz.js → index.server-ks49bprh.js} +1 -1
- package/dist/server/{index.server-f0hma3jp.js → index.server-kt0ncrqs.js} +1 -1
- package/dist/server/index.server-m0ezemav.js +170 -0
- package/dist/server/index.server-m191rm44.js +79 -0
- package/dist/server/{index.server-z721a5gp.js → index.server-n82rcv0m.js} +4 -4
- package/dist/server/{index.server-rhhmdxtz.js → index.server-np3c7kx0.js} +4 -4
- package/dist/server/{index.server-hpcs7tmh.js → index.server-p56xxef1.js} +1 -1
- package/dist/server/{index.server-w83kmcrx.js → index.server-pag862vz.js} +10 -10
- package/dist/server/index.server-qbkxz7r2.js +750 -0
- package/dist/server/{index.server-sh2rxejg.js → index.server-qke3ekjt.js} +1 -1
- package/dist/server/{index.server-73x2d3j3.js → index.server-rbpvcrr3.js} +1 -1
- package/dist/server/{index.server-8cxs4kya.js → index.server-rga8sc7j.js} +41 -44
- package/dist/server/{index.server-e3fnv1g6.js → index.server-sedjxt36.js} +5 -5
- package/dist/server/{index.server-pen9pxt6.js → index.server-sf3nk3j2.js} +2 -2
- package/dist/server/{index.server-f23vtaw4.js → index.server-tcay903b.js} +8 -7
- package/dist/server/{index.server-7fp0epev.js → index.server-veastatv.js} +4 -4
- package/dist/server/{index.server-jeqg2d22.js → index.server-xeqtpv61.js} +1 -1
- package/dist/server/{index.server-9s4na701.js → index.server-xjnge1yw.js} +4 -4
- package/dist/server/index.server-xtjjmsyq.js +315 -0
- package/dist/server/{index.server-hhxjaeen.js → index.server-xz99aed4.js} +4 -4
- package/dist/server/{index.server-vne4rzfa.js → index.server-y4n8vc08.js} +1 -1
- package/dist/server/{index.server-5d01cn4f.js → index.server-y83kqayt.js} +4 -4
- package/dist/server/{index.server-1nh09ck7.js → index.server-yhzydqxe.js} +5 -5
- package/dist/server/index.server-z38bxms8.js +734 -0
- package/dist/server/{index.server-atjc1qcq.js → index.server-z7hxtqs1.js} +1 -1
- package/dist/server/{index.server-w6k62afr.js → index.server-ze1ymmbw.js} +2 -2
- package/dist/server/{index.server-914v805w.js → index.server-zgd1g8mk.js} +1 -1
- package/dist/server/{index.server-aeexcxdp.js → index.server-zh3r8vfd.js} +1 -1
- package/dist/server/{index.server-10jb2jzm.js → index.server-zsjf8enc.js} +4 -4
- package/package.json +102 -5
- package/src/components/_internal/command-list-context.ts +3 -3
- package/src/components/_internal/create-command-list-state.svelte.ts +39 -13
- package/src/components/approval-card/approval-card-actions.svelte +168 -0
- package/src/components/approval-card/approval-card-state.ts +152 -1
- package/src/components/approval-card/approval-card.css +269 -92
- package/src/components/approval-card/approval-card.examples.json +3 -3
- package/src/components/approval-card/approval-card.schema.json +9 -30
- package/src/components/approval-card/approval-card.schema.ts +13 -31
- package/src/components/approval-card/approval-card.svelte +176 -470
- package/src/components/approval-card/approval-card.types.ts +15 -28
- package/src/components/approval-card/index.ts +1 -0
- package/src/components/card/card.css +5 -0
- package/src/components/card/card.schema.json +1 -1
- package/src/components/card/card.schema.ts +1 -1
- package/src/components/card/card.svelte +1 -0
- package/src/components/card/card.types.ts +2 -2
- package/src/components/chat/builders.ts +445 -14
- package/src/components/chat/chat.schema.json +36 -1
- package/src/components/chat/chat.schema.ts +44 -1
- package/src/components/chat/chat.svelte +12 -0
- package/src/components/chat/chat.types.ts +35 -3
- package/src/components/chat/container/chat.svelte +73 -3
- package/src/components/chat/conversation-model.ts +1 -0
- package/src/components/chat/index.ts +16 -3
- package/src/components/chat/input/chat-attachment-serialization.ts +63 -0
- package/src/components/chat/input/chat-input.svelte +22 -5
- package/src/components/chat/input/index.ts +5 -0
- package/src/components/chat/utilities/conversation.ts +33 -15
- package/src/components/chat-composer-popover/chat-composer-popover-filter.ts +68 -0
- package/src/components/chat-composer-popover/chat-composer-popover.css +7 -0
- package/src/components/chat-composer-popover/chat-composer-popover.examples.json +13 -0
- package/src/components/chat-composer-popover/chat-composer-popover.schema.json +90 -0
- package/src/components/chat-composer-popover/chat-composer-popover.schema.ts +95 -0
- package/src/components/chat-composer-popover/chat-composer-popover.svelte +234 -0
- package/src/components/chat-composer-popover/chat-composer-popover.types.ts +88 -0
- package/src/components/chat-composer-popover/chat-composer-popover.variables.json +1 -0
- package/src/components/chat-composer-popover/chat-composer-popover.variables.ts +3 -0
- package/src/components/chat-composer-popover/index.ts +19 -0
- package/src/components/code-block/code-block.schema.json +4 -0
- package/src/components/code-block/code-block.schema.ts +5 -0
- package/src/components/code-block/code-block.svelte +3 -3
- package/src/components/code-block/code-block.types.ts +6 -0
- package/src/components/command-item/command-item.svelte +7 -6
- package/src/components/command-menu/command-menu.schema.json +4 -0
- package/src/components/command-menu/command-menu.schema.ts +4 -0
- package/src/components/command-menu/command-menu.svelte +16 -5
- package/src/components/command-menu/command-menu.types.ts +2 -0
- package/src/components/connection-indicator/connection-indicator.css +136 -0
- package/src/components/connection-indicator/connection-indicator.examples.json +31 -0
- package/src/components/connection-indicator/connection-indicator.schema.json +29 -0
- package/src/components/connection-indicator/connection-indicator.schema.ts +36 -0
- package/src/components/connection-indicator/connection-indicator.svelte +63 -0
- package/src/components/connection-indicator/connection-indicator.types.ts +58 -0
- package/src/components/connection-indicator/connection-indicator.variables.json +1 -0
- package/src/components/connection-indicator/connection-indicator.variables.ts +3 -0
- package/src/components/connection-indicator/index.ts +10 -0
- package/src/components/container/container.schema.json +3 -3
- package/src/components/container/container.schema.ts +3 -3
- package/src/components/invocation-rule-builder/index.ts +4 -0
- package/src/components/invocation-rule-builder/invocation-rule-builder.css +28 -0
- package/src/components/invocation-rule-builder/invocation-rule-builder.examples.json +6 -0
- package/src/components/invocation-rule-builder/invocation-rule-builder.schema.json +76 -3
- package/src/components/invocation-rule-builder/invocation-rule-builder.schema.ts +83 -3
- package/src/components/invocation-rule-builder/invocation-rule-builder.svelte +326 -113
- package/src/components/invocation-rule-builder/invocation-rule-builder.types.ts +157 -43
- package/src/components/json-viewer/_json-viewer-node.svelte +15 -1
- package/src/components/json-viewer/json-viewer.css +10 -6
- package/src/components/payload-inspector/index.ts +0 -2
- package/src/components/payload-inspector/payload-inspector.css +15 -75
- package/src/components/payload-inspector/payload-inspector.examples.json +5 -5
- package/src/components/payload-inspector/payload-inspector.schema.json +3 -31
- package/src/components/payload-inspector/payload-inspector.schema.ts +3 -36
- package/src/components/payload-inspector/payload-inspector.svelte +46 -239
- package/src/components/payload-inspector/payload-inspector.types.ts +10 -58
- package/src/components/run-step-timeline/index.ts +8 -0
- package/src/components/run-step-timeline/run-step-branch-disclosure.svelte +16 -0
- package/src/components/run-step-timeline/run-step-timeline.css +124 -0
- package/src/components/run-step-timeline/run-step-timeline.examples.json +18 -0
- package/src/components/run-step-timeline/run-step-timeline.schema.json +872 -349
- package/src/components/run-step-timeline/run-step-timeline.schema.ts +931 -349
- package/src/components/run-step-timeline/run-step-timeline.svelte +387 -268
- package/src/components/run-step-timeline/run-step-timeline.types.ts +192 -5
- package/src/components/run-step-timeline/run-step-timeline.utilities.ts +242 -0
- package/src/components/schedule-builder/index.ts +14 -0
- package/src/components/schedule-builder/schedule-builder.css +121 -0
- package/src/components/schedule-builder/schedule-builder.examples.json +31 -0
- package/src/components/schedule-builder/schedule-builder.schema.json +78 -0
- package/src/components/schedule-builder/schedule-builder.schema.ts +86 -0
- package/src/components/schedule-builder/schedule-builder.svelte +629 -0
- package/src/components/schedule-builder/schedule-builder.types.ts +137 -0
- package/src/components/schedule-builder/schedule-builder.utilities.ts +344 -0
- package/src/components/schedule-builder/schedule-builder.variables.json +1 -0
- package/src/components/schedule-builder/schedule-builder.variables.ts +3 -0
- package/src/components/tab/tab.schema.json +6 -2
- package/src/components/tab/tab.schema.ts +8 -2
- package/src/components/tab/tab.svelte +9 -5
- package/src/components/tab/tab.types.ts +8 -2
- package/src/components/tag-input/tag-input.schema.json +4 -0
- package/src/components/tag-input/tag-input.schema.ts +4 -0
- package/src/components/tag-input/tag-input.svelte +20 -3
- package/src/components/tag-input/tag-input.types.ts +4 -0
- package/src/index.ts +41 -5
- package/src/styles/components.css +3 -0
- package/dist/server/index-49we2xfs.js +0 -344
- package/dist/server/index-8fhvxk30.js +0 -265
- package/dist/server/index-x2ysg8ds.js +0 -388
- package/dist/server/index.server-20j0jh30.js +0 -9
- package/dist/server/index.server-dc35kh7d.js +0 -1835
- package/dist/server/index.server-kd4b0342.js +0 -607
- package/dist/server/index.server-n5cdmsz4.js +0 -30
- package/dist/server/index.server-pxg74pyp.js +0 -393
- package/dist/server/index.server-rjap4k7y.js +0 -1389
- package/dist/server/index.server-vt6sn9y4.js +0 -447
- package/dist/server/index.server-w63n618v.js +0 -9
- package/dist/server/index.server-y2pa1k46.js +0 -9
|
@@ -1,1835 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ConversationalistError,
|
|
3
|
-
appendAssistantMessage,
|
|
4
|
-
appendMessages,
|
|
5
|
-
appendStreamingMessage,
|
|
6
|
-
appendSystemMessage,
|
|
7
|
-
appendToolCall,
|
|
8
|
-
appendToolCalls,
|
|
9
|
-
appendToolResult,
|
|
10
|
-
appendToolResultAsync,
|
|
11
|
-
appendToolResults,
|
|
12
|
-
appendToolResultsAsync,
|
|
13
|
-
appendUserMessage,
|
|
14
|
-
assertConversationSafe,
|
|
15
|
-
cancelStreamingMessage,
|
|
16
|
-
collapseSystemMessages,
|
|
17
|
-
copyContent,
|
|
18
|
-
createConversationHistory,
|
|
19
|
-
createIntegrityError,
|
|
20
|
-
createMessage,
|
|
21
|
-
deserializeConversationHistory,
|
|
22
|
-
ensureConversationSafe,
|
|
23
|
-
finalizeStreamingMessage,
|
|
24
|
-
getFirstSystemMessage,
|
|
25
|
-
getMessageAtPosition,
|
|
26
|
-
getMessageById,
|
|
27
|
-
getMessageIds,
|
|
28
|
-
getMessages,
|
|
29
|
-
getOrderedMessages,
|
|
30
|
-
getPendingToolCalls,
|
|
31
|
-
getStatistics,
|
|
32
|
-
getStreamingMessage,
|
|
33
|
-
getSystemMessages,
|
|
34
|
-
getToolInteractions,
|
|
35
|
-
hasSystemMessage,
|
|
36
|
-
isAssistantMessage,
|
|
37
|
-
isConversationEnvironmentParameter,
|
|
38
|
-
isStreamingMessage,
|
|
39
|
-
pairToolCallsWithResults,
|
|
40
|
-
prependSystemMessage,
|
|
41
|
-
redactMessageAtPosition,
|
|
42
|
-
replaceSystemMessage,
|
|
43
|
-
resolveConversationEnvironment,
|
|
44
|
-
searchConversationMessages,
|
|
45
|
-
simpleTokenEstimator,
|
|
46
|
-
toChatMessages,
|
|
47
|
-
toIdRecord,
|
|
48
|
-
toReadonly,
|
|
49
|
-
toSessionInfo,
|
|
50
|
-
updateStreamingMessage
|
|
51
|
-
} from "./index.server-rjap4k7y.js";
|
|
52
|
-
import {
|
|
53
|
-
__require
|
|
54
|
-
} from "./index.server-0v6na3yp.js";
|
|
55
|
-
|
|
56
|
-
// src/components/chat/utilities/utilities.ts
|
|
57
|
-
var CINDER_REASONING_METADATA_KEY = "cinder:reasoning";
|
|
58
|
-
var CINDER_STEPS_METADATA_KEY = "cinder:steps";
|
|
59
|
-
var CINDER_SUGGESTIONS_METADATA_KEY = "cinder:suggestions";
|
|
60
|
-
var STEP_STATUSES = new Set([
|
|
61
|
-
"pending",
|
|
62
|
-
"running",
|
|
63
|
-
"done",
|
|
64
|
-
"error"
|
|
65
|
-
]);
|
|
66
|
-
function isStepInfo(value) {
|
|
67
|
-
if (value === null || typeof value !== "object")
|
|
68
|
-
return false;
|
|
69
|
-
if (!("title" in value) || !("content" in value) || !("status" in value))
|
|
70
|
-
return false;
|
|
71
|
-
return typeof value.title === "string" && typeof value.content === "string" && typeof value.status === "string" && STEP_STATUSES.has(value.status);
|
|
72
|
-
}
|
|
73
|
-
function runOverlayCallback(message, fromProp) {
|
|
74
|
-
if (fromProp === undefined)
|
|
75
|
-
return { handled: false, value: undefined };
|
|
76
|
-
try {
|
|
77
|
-
const value = fromProp(message);
|
|
78
|
-
return value === undefined ? { handled: false, value: undefined } : { handled: true, value };
|
|
79
|
-
} catch {
|
|
80
|
-
return { handled: false, value: undefined };
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
function resolveMessageReasoning(message, fromProp) {
|
|
84
|
-
const fromCallback = runOverlayCallback(message, fromProp);
|
|
85
|
-
if (fromCallback.handled && fromCallback.value === "")
|
|
86
|
-
return "";
|
|
87
|
-
const candidate = fromCallback.handled ? fromCallback.value : message.metadata[CINDER_REASONING_METADATA_KEY];
|
|
88
|
-
return typeof candidate === "string" && candidate.length > 0 ? candidate : undefined;
|
|
89
|
-
}
|
|
90
|
-
function resolveMessageSteps(message, fromProp) {
|
|
91
|
-
const fromCallback = runOverlayCallback(message, fromProp);
|
|
92
|
-
const candidate = fromCallback.handled ? fromCallback.value : message.metadata[CINDER_STEPS_METADATA_KEY];
|
|
93
|
-
if (!Array.isArray(candidate))
|
|
94
|
-
return;
|
|
95
|
-
const steps = candidate.filter(isStepInfo);
|
|
96
|
-
return steps.length > 0 ? steps : undefined;
|
|
97
|
-
}
|
|
98
|
-
function resolveMessageSuggestions(message, fromProp) {
|
|
99
|
-
const fromCallback = runOverlayCallback(message, fromProp);
|
|
100
|
-
const candidate = fromCallback.handled ? fromCallback.value : message.metadata[CINDER_SUGGESTIONS_METADATA_KEY];
|
|
101
|
-
if (!Array.isArray(candidate))
|
|
102
|
-
return;
|
|
103
|
-
const suggestions = candidate.filter((entry) => typeof entry === "string");
|
|
104
|
-
return suggestions.length > 0 ? suggestions : undefined;
|
|
105
|
-
}
|
|
106
|
-
function toMultiModalArray(input) {
|
|
107
|
-
if (typeof input === "string")
|
|
108
|
-
return [{ type: "text", text: input }];
|
|
109
|
-
return "type" in input ? [input] : input;
|
|
110
|
-
}
|
|
111
|
-
function formatJSONValue(value) {
|
|
112
|
-
return typeof value === "string" ? value : JSON.stringify(value, null, 2);
|
|
113
|
-
}
|
|
114
|
-
function getServerContentText(part) {
|
|
115
|
-
switch (part.type) {
|
|
116
|
-
case "text":
|
|
117
|
-
return part.text;
|
|
118
|
-
case "server_tool_use":
|
|
119
|
-
return [`Server tool use: ${part.name}`, formatJSONValue(part.input)].join(`
|
|
120
|
-
`);
|
|
121
|
-
case "web_search_tool_result":
|
|
122
|
-
return [`Web search result: ${part.tool_use_id}`, formatJSONValue(part.content)].join(`
|
|
123
|
-
`);
|
|
124
|
-
case "code_execution_tool_result":
|
|
125
|
-
case "bash_code_execution_tool_result":
|
|
126
|
-
case "text_editor_code_execution_tool_result":
|
|
127
|
-
case "web_fetch_tool_result":
|
|
128
|
-
return [`Server tool result: ${part.tool_use_id}`, formatJSONValue(part.content)].join(`
|
|
129
|
-
`);
|
|
130
|
-
case "container_upload":
|
|
131
|
-
return `Container upload: ${part.file_id}`;
|
|
132
|
-
default:
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
function getMessageParts(message) {
|
|
137
|
-
return toMultiModalArray(message.content);
|
|
138
|
-
}
|
|
139
|
-
function getMessageText(message) {
|
|
140
|
-
return getMessageParts(message).map(getServerContentText).filter((text) => typeof text === "string" && text.length > 0).join(`
|
|
141
|
-
`);
|
|
142
|
-
}
|
|
143
|
-
function deriveImageParts(message) {
|
|
144
|
-
if (typeof message.content === "string")
|
|
145
|
-
return [];
|
|
146
|
-
const parts = [];
|
|
147
|
-
message.content.forEach((segment, index) => {
|
|
148
|
-
if (segment.type === "image") {
|
|
149
|
-
parts.push({
|
|
150
|
-
type: "image",
|
|
151
|
-
key: `${message.id}:image:${index}`,
|
|
152
|
-
image: segment
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
return parts;
|
|
157
|
-
}
|
|
158
|
-
function deriveReasoningContent(message, explicitReasoning) {
|
|
159
|
-
if (explicitReasoning === "")
|
|
160
|
-
return;
|
|
161
|
-
const reasoningSegments = explicitReasoning && explicitReasoning.length > 0 ? [explicitReasoning] : [];
|
|
162
|
-
if (typeof message.content !== "string") {
|
|
163
|
-
let hasRedactedThinking = false;
|
|
164
|
-
for (const segment of message.content) {
|
|
165
|
-
if (segment.type === "thinking" && segment.thinking.length > 0) {
|
|
166
|
-
reasoningSegments.push(segment.thinking);
|
|
167
|
-
}
|
|
168
|
-
if (segment.type === "redacted_thinking") {
|
|
169
|
-
hasRedactedThinking = true;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
if (hasRedactedThinking) {
|
|
173
|
-
reasoningSegments.push("Redacted reasoning is preserved in this transcript but cannot be displayed.");
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
return reasoningSegments.length > 0 ? reasoningSegments.join(`
|
|
177
|
-
|
|
178
|
-
`) : undefined;
|
|
179
|
-
}
|
|
180
|
-
function deriveToolApprovalPart(messageId, result, context) {
|
|
181
|
-
const approved = context.approvedToolCallIds?.has(result.callId) ? true : context.deniedToolCallIds?.has(result.callId) ? false : undefined;
|
|
182
|
-
return {
|
|
183
|
-
type: "tool-approval",
|
|
184
|
-
key: `${messageId}:tool-approval:${result.callId}`,
|
|
185
|
-
toolCallId: result.callId,
|
|
186
|
-
toolName: context.toolCallPair?.call.name ?? result.callId,
|
|
187
|
-
action: result.action,
|
|
188
|
-
approved
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
function deriveMessageParts(message, context = {}) {
|
|
192
|
-
const imageParts = deriveImageParts(message);
|
|
193
|
-
if (message.role === "tool-call" && message.toolCall && context.toolCallPair) {
|
|
194
|
-
const result = context.toolCallPair.result;
|
|
195
|
-
const approvalPart = result && result.outcome === "action_required" && result.action ? deriveToolApprovalPart(message.id, result, context) : undefined;
|
|
196
|
-
return [
|
|
197
|
-
{
|
|
198
|
-
type: "tool-call",
|
|
199
|
-
key: `${message.id}:tool-call:${message.toolCall.id}`,
|
|
200
|
-
pair: context.toolCallPair
|
|
201
|
-
},
|
|
202
|
-
...approvalPart ? [approvalPart] : [],
|
|
203
|
-
...imageParts
|
|
204
|
-
];
|
|
205
|
-
}
|
|
206
|
-
if (message.role === "tool-result" && message.toolResult) {
|
|
207
|
-
const result = message.toolResult;
|
|
208
|
-
if (result.outcome === "action_required" && result.action) {
|
|
209
|
-
return [deriveToolApprovalPart(message.id, result, context), ...imageParts];
|
|
210
|
-
}
|
|
211
|
-
return [
|
|
212
|
-
{
|
|
213
|
-
type: "tool-result",
|
|
214
|
-
key: `${message.id}:tool-result:${result.callId}`,
|
|
215
|
-
result
|
|
216
|
-
},
|
|
217
|
-
...imageParts
|
|
218
|
-
];
|
|
219
|
-
}
|
|
220
|
-
const content = context.overrideContent ?? getMessageText(message);
|
|
221
|
-
const bodyParts = [];
|
|
222
|
-
if (context.steps && context.steps.length > 0) {
|
|
223
|
-
for (let index = 0;index < context.steps.length; index++) {
|
|
224
|
-
const step = context.steps[index];
|
|
225
|
-
bodyParts.push({
|
|
226
|
-
type: "step",
|
|
227
|
-
key: `${message.id}:step:${index}`,
|
|
228
|
-
index,
|
|
229
|
-
title: step.title,
|
|
230
|
-
content: step.content,
|
|
231
|
-
status: step.status
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
const reasoningContent = deriveReasoningContent(message, context.reasoning);
|
|
236
|
-
if (reasoningContent) {
|
|
237
|
-
bodyParts.push({
|
|
238
|
-
type: "reasoning",
|
|
239
|
-
key: `${message.id}:reasoning`,
|
|
240
|
-
content: reasoningContent,
|
|
241
|
-
streaming: context.streaming ?? false
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
bodyParts.push({
|
|
245
|
-
type: "markdown",
|
|
246
|
-
key: `${message.id}:body`,
|
|
247
|
-
content,
|
|
248
|
-
streaming: context.streaming ?? false,
|
|
249
|
-
expanded: context.expanded ?? true
|
|
250
|
-
});
|
|
251
|
-
if (context.suggestions && context.suggestions.length > 0) {
|
|
252
|
-
for (let index = 0;index < context.suggestions.length; index++) {
|
|
253
|
-
const label = context.suggestions[index];
|
|
254
|
-
bodyParts.push({
|
|
255
|
-
type: "suggestion",
|
|
256
|
-
key: `${message.id}:suggestion:${index}`,
|
|
257
|
-
index,
|
|
258
|
-
label
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
return [...bodyParts, ...imageParts];
|
|
263
|
-
}
|
|
264
|
-
function getMessageRoleLabel(message) {
|
|
265
|
-
const labels = {
|
|
266
|
-
user: "User",
|
|
267
|
-
assistant: "Assistant",
|
|
268
|
-
system: "System",
|
|
269
|
-
developer: "Developer",
|
|
270
|
-
"tool-call": "Tool Call",
|
|
271
|
-
"tool-result": "Tool Result",
|
|
272
|
-
snapshot: "Snapshot"
|
|
273
|
-
};
|
|
274
|
-
return labels[message.role] ?? message.role;
|
|
275
|
-
}
|
|
276
|
-
function formatMessageAsMarkdown(message) {
|
|
277
|
-
return getMessageText(message);
|
|
278
|
-
}
|
|
279
|
-
function formatMessageWithRole(message) {
|
|
280
|
-
const roleLabel = getMessageRoleLabel(message);
|
|
281
|
-
const text = getMessageText(message);
|
|
282
|
-
return `**${roleLabel}:**
|
|
283
|
-
|
|
284
|
-
${text}`;
|
|
285
|
-
}
|
|
286
|
-
function messagesToMarkdown(messages) {
|
|
287
|
-
return messages.filter((msg) => msg.role !== "system" && msg.role !== "developer").map(formatMessageWithRole).join(`
|
|
288
|
-
|
|
289
|
-
---
|
|
290
|
-
|
|
291
|
-
`);
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
// ../../node_modules/conversationalist/dist/context.js
|
|
295
|
-
var cloneMessageWithPosition = (message, position, content) => {
|
|
296
|
-
const baseMessage = {
|
|
297
|
-
id: message.id,
|
|
298
|
-
role: message.role,
|
|
299
|
-
content,
|
|
300
|
-
position,
|
|
301
|
-
createdAt: message.createdAt,
|
|
302
|
-
metadata: { ...message.metadata },
|
|
303
|
-
hidden: message.hidden,
|
|
304
|
-
toolCall: message.toolCall ? { ...message.toolCall } : undefined,
|
|
305
|
-
toolResult: message.toolResult ? { ...message.toolResult } : undefined,
|
|
306
|
-
tokenUsage: message.tokenUsage ? { ...message.tokenUsage } : undefined
|
|
307
|
-
};
|
|
308
|
-
if (isAssistantMessage(message))
|
|
309
|
-
return createMessage({
|
|
310
|
-
...baseMessage,
|
|
311
|
-
role: "assistant",
|
|
312
|
-
goalCompleted: message.goalCompleted
|
|
313
|
-
});
|
|
314
|
-
return createMessage(baseMessage);
|
|
315
|
-
};
|
|
316
|
-
var isPromiseLike = (value) => typeof value?.then === "function";
|
|
317
|
-
var hasConversationTokenEstimator = (value) => Boolean(value && typeof value === "object" && typeof value["estimateConversationTokens"] === "function");
|
|
318
|
-
var createMessageBlock = (message) => ({
|
|
319
|
-
messages: [message],
|
|
320
|
-
minPosition: message.position,
|
|
321
|
-
maxPosition: message.position,
|
|
322
|
-
tokenCount: 0
|
|
323
|
-
});
|
|
324
|
-
var estimateMessageBlockTokens = (messages, options, environment) => {
|
|
325
|
-
if (options.estimateConversationTokens)
|
|
326
|
-
return options.estimateConversationTokens(messages);
|
|
327
|
-
const estimator = options.estimateTokens ?? environment.estimateTokens;
|
|
328
|
-
return messages.reduce((total, message) => total + estimator(message), 0);
|
|
329
|
-
};
|
|
330
|
-
var buildMessageBlocks = (messages, estimateBlockTokens, preserveToolPairs) => {
|
|
331
|
-
if (!preserveToolPairs) {
|
|
332
|
-
const blocks2 = messages.map((message) => createMessageBlock(message));
|
|
333
|
-
for (const block of blocks2)
|
|
334
|
-
block.tokenCount = estimateBlockTokens(block.messages);
|
|
335
|
-
const messageToBlock2 = /* @__PURE__ */ new Map;
|
|
336
|
-
for (const block of blocks2) {
|
|
337
|
-
const message = block.messages[0];
|
|
338
|
-
if (message)
|
|
339
|
-
messageToBlock2.set(message.id, block);
|
|
340
|
-
}
|
|
341
|
-
return {
|
|
342
|
-
blocks: blocks2,
|
|
343
|
-
messageToBlock: messageToBlock2
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
|
-
const blocks = [];
|
|
347
|
-
const toolUses = /* @__PURE__ */ new Map;
|
|
348
|
-
for (const message of messages) {
|
|
349
|
-
if (message.role === "tool-call" && message.toolCall) {
|
|
350
|
-
const block = createMessageBlock(message);
|
|
351
|
-
toolUses.set(message.toolCall.id, block);
|
|
352
|
-
blocks.push(block);
|
|
353
|
-
continue;
|
|
354
|
-
}
|
|
355
|
-
if (message.role === "tool-result" && message.toolResult) {
|
|
356
|
-
const existing = toolUses.get(message.toolResult.callId);
|
|
357
|
-
if (existing) {
|
|
358
|
-
existing.messages.push(message);
|
|
359
|
-
existing.maxPosition = Math.max(existing.maxPosition, message.position);
|
|
360
|
-
continue;
|
|
361
|
-
}
|
|
362
|
-
const orphanBlock = createMessageBlock(message);
|
|
363
|
-
orphanBlock.orphanToolResult = true;
|
|
364
|
-
blocks.push(orphanBlock);
|
|
365
|
-
continue;
|
|
366
|
-
}
|
|
367
|
-
blocks.push(createMessageBlock(message));
|
|
368
|
-
}
|
|
369
|
-
const filteredBlocks = blocks.filter((block) => !block.orphanToolResult);
|
|
370
|
-
for (const block of filteredBlocks)
|
|
371
|
-
block.tokenCount = estimateBlockTokens(block.messages);
|
|
372
|
-
const messageToBlock = /* @__PURE__ */ new Map;
|
|
373
|
-
for (const block of filteredBlocks)
|
|
374
|
-
for (const message of block.messages)
|
|
375
|
-
messageToBlock.set(message.id, block);
|
|
376
|
-
return {
|
|
377
|
-
blocks: filteredBlocks,
|
|
378
|
-
messageToBlock
|
|
379
|
-
};
|
|
380
|
-
};
|
|
381
|
-
var buildMessageBlocksAsync = async (messages, estimateBlockTokens, preserveToolPairs) => {
|
|
382
|
-
const { blocks, messageToBlock } = buildMessageBlocks(messages, () => 0, preserveToolPairs);
|
|
383
|
-
await Promise.all(blocks.map(async (block) => {
|
|
384
|
-
block.tokenCount = await estimateBlockTokens(block.messages);
|
|
385
|
-
}));
|
|
386
|
-
return {
|
|
387
|
-
blocks,
|
|
388
|
-
messageToBlock
|
|
389
|
-
};
|
|
390
|
-
};
|
|
391
|
-
var estimateBlocksAsConversation = (blocks, options, environment) => estimateMessageBlockTokens(collectMessagesFromBlocks(blocks), options, environment);
|
|
392
|
-
var collectBlocksForMessages = (messages, messageToBlock) => {
|
|
393
|
-
const blocks = [];
|
|
394
|
-
const seen = /* @__PURE__ */ new Set;
|
|
395
|
-
for (const message of messages) {
|
|
396
|
-
const block = messageToBlock.get(message.id);
|
|
397
|
-
if (block && !seen.has(block)) {
|
|
398
|
-
seen.add(block);
|
|
399
|
-
blocks.push(block);
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
return blocks;
|
|
403
|
-
};
|
|
404
|
-
var collectMessagesFromBlocks = (blocks) => {
|
|
405
|
-
const messages = [];
|
|
406
|
-
const seen = /* @__PURE__ */ new Set;
|
|
407
|
-
for (const block of blocks)
|
|
408
|
-
for (const message of block.messages)
|
|
409
|
-
if (!seen.has(message.id)) {
|
|
410
|
-
seen.add(message.id);
|
|
411
|
-
messages.push(message);
|
|
412
|
-
}
|
|
413
|
-
messages.sort((a, b) => a.position - b.position);
|
|
414
|
-
return messages;
|
|
415
|
-
};
|
|
416
|
-
var ensureTruncationSafe = (conversation, preserveToolPairs, operation) => {
|
|
417
|
-
try {
|
|
418
|
-
return ensureConversationSafe(conversation);
|
|
419
|
-
} catch (error) {
|
|
420
|
-
if (!preserveToolPairs && error instanceof ConversationalistError && error.code === "error:integrity")
|
|
421
|
-
throw createIntegrityError(`${operation} produced invalid tool linkage; use preserveToolPairs: true to keep tool interactions intact`, {
|
|
422
|
-
preserveToolPairs,
|
|
423
|
-
issues: error.context?.["issues"]
|
|
424
|
-
});
|
|
425
|
-
throw error;
|
|
426
|
-
}
|
|
427
|
-
};
|
|
428
|
-
function estimateConversationTokens(conversation, optionsOrEstimator, environment) {
|
|
429
|
-
let options = {};
|
|
430
|
-
let env = environment;
|
|
431
|
-
if (typeof optionsOrEstimator === "function")
|
|
432
|
-
options = { estimateTokens: optionsOrEstimator };
|
|
433
|
-
else if (optionsOrEstimator)
|
|
434
|
-
if (!environment && !hasConversationTokenEstimator(optionsOrEstimator) && isConversationEnvironmentParameter(optionsOrEstimator))
|
|
435
|
-
env = optionsOrEstimator;
|
|
436
|
-
else
|
|
437
|
-
options = optionsOrEstimator;
|
|
438
|
-
const resolvedEnvironment = resolveConversationEnvironment(env);
|
|
439
|
-
return estimateMessageBlockTokens(getOrderedMessages(conversation), options, resolvedEnvironment);
|
|
440
|
-
}
|
|
441
|
-
var truncateToTokenLimitFromBlocks = (conversation, maxTokens, currentTokens, orderedMessages, blocks, messageToBlock, options, environment) => {
|
|
442
|
-
if (currentTokens <= maxTokens)
|
|
443
|
-
return conversation;
|
|
444
|
-
const now = environment.now();
|
|
445
|
-
const preserveSystem = options.preserveSystemMessages ?? true;
|
|
446
|
-
const preserveLastN = options.preserveLastN ?? 0;
|
|
447
|
-
const preserveToolPairs = options.preserveToolPairs ?? true;
|
|
448
|
-
const systemMessages = preserveSystem ? orderedMessages.filter((m) => m.role === "system") : [];
|
|
449
|
-
const nonSystemMessages = orderedMessages.filter((m) => m.role !== "system");
|
|
450
|
-
const protectedMessages = preserveLastN > 0 ? nonSystemMessages.slice(-preserveLastN) : [];
|
|
451
|
-
const streamingMessages = orderedMessages.filter(isStreamingMessage);
|
|
452
|
-
const systemBlocks = collectBlocksForMessages(systemMessages, messageToBlock);
|
|
453
|
-
const protectedBlocks = collectBlocksForMessages(protectedMessages, messageToBlock);
|
|
454
|
-
const streamingBlocks = collectBlocksForMessages(streamingMessages, messageToBlock);
|
|
455
|
-
const lockedBlocks = new Set([
|
|
456
|
-
...systemBlocks,
|
|
457
|
-
...protectedBlocks,
|
|
458
|
-
...streamingBlocks
|
|
459
|
-
]);
|
|
460
|
-
const removableBlocks = blocks.filter((block) => !lockedBlocks.has(block));
|
|
461
|
-
const systemTokens = systemBlocks.reduce((sum, block) => sum + block.tokenCount, 0);
|
|
462
|
-
const protectedTokens = protectedBlocks.reduce((sum, block) => sum + block.tokenCount, 0);
|
|
463
|
-
const streamingTokens = streamingBlocks.reduce((sum, block) => sum + block.tokenCount, 0);
|
|
464
|
-
const availableTokens = maxTokens - systemTokens - protectedTokens - streamingTokens;
|
|
465
|
-
let selectedBlocks;
|
|
466
|
-
if (availableTokens <= 0)
|
|
467
|
-
selectedBlocks = [
|
|
468
|
-
...systemBlocks,
|
|
469
|
-
...protectedBlocks,
|
|
470
|
-
...streamingBlocks
|
|
471
|
-
];
|
|
472
|
-
else {
|
|
473
|
-
const sortedRemovable = [...removableBlocks].sort((a, b) => a.maxPosition - b.maxPosition);
|
|
474
|
-
const keptRemovable = [];
|
|
475
|
-
let usedTokens = 0;
|
|
476
|
-
for (let i = sortedRemovable.length - 1;i >= 0; i--) {
|
|
477
|
-
const block = sortedRemovable[i];
|
|
478
|
-
if (usedTokens + block.tokenCount <= availableTokens) {
|
|
479
|
-
keptRemovable.unshift(block);
|
|
480
|
-
usedTokens += block.tokenCount;
|
|
481
|
-
} else
|
|
482
|
-
break;
|
|
483
|
-
}
|
|
484
|
-
selectedBlocks = [
|
|
485
|
-
...systemBlocks,
|
|
486
|
-
...keptRemovable,
|
|
487
|
-
...streamingBlocks,
|
|
488
|
-
...protectedBlocks
|
|
489
|
-
];
|
|
490
|
-
}
|
|
491
|
-
const renumbered = collectMessagesFromBlocks(selectedBlocks).map((message, index) => cloneMessageWithPosition(message, index, copyContent(message.content)));
|
|
492
|
-
return ensureTruncationSafe(toReadonly({
|
|
493
|
-
...conversation,
|
|
494
|
-
ids: renumbered.map((message) => message.id),
|
|
495
|
-
messages: toIdRecord(renumbered),
|
|
496
|
-
updatedAt: now
|
|
497
|
-
}), preserveToolPairs, "truncateToTokenLimit");
|
|
498
|
-
};
|
|
499
|
-
var truncateToTokenLimitWithConversationEstimator = (conversation, maxTokens, orderedMessages, options, environment) => {
|
|
500
|
-
const preserveSystem = options.preserveSystemMessages ?? true;
|
|
501
|
-
const preserveLastN = options.preserveLastN ?? 0;
|
|
502
|
-
const preserveToolPairs = options.preserveToolPairs ?? true;
|
|
503
|
-
const { blocks, messageToBlock } = buildMessageBlocks(orderedMessages, () => 0, preserveToolPairs);
|
|
504
|
-
const countAllMessages = estimateMessageBlockTokens(orderedMessages, options, environment);
|
|
505
|
-
const selectBlocks = (currentTokens) => {
|
|
506
|
-
if (currentTokens <= maxTokens)
|
|
507
|
-
return blocks;
|
|
508
|
-
const systemMessages = preserveSystem ? orderedMessages.filter((m) => m.role === "system") : [];
|
|
509
|
-
const nonSystemMessages = orderedMessages.filter((m) => m.role !== "system");
|
|
510
|
-
const protectedMessages = preserveLastN > 0 ? nonSystemMessages.slice(-preserveLastN) : [];
|
|
511
|
-
const streamingMessages = orderedMessages.filter(isStreamingMessage);
|
|
512
|
-
const systemBlocks = collectBlocksForMessages(systemMessages, messageToBlock);
|
|
513
|
-
const protectedBlocks = collectBlocksForMessages(protectedMessages, messageToBlock);
|
|
514
|
-
const streamingBlocks = collectBlocksForMessages(streamingMessages, messageToBlock);
|
|
515
|
-
const lockedBlocks = new Set([
|
|
516
|
-
...systemBlocks,
|
|
517
|
-
...protectedBlocks,
|
|
518
|
-
...streamingBlocks
|
|
519
|
-
]);
|
|
520
|
-
const removableBlocks = blocks.filter((block) => !lockedBlocks.has(block));
|
|
521
|
-
const selectedLockedBlocks = [...lockedBlocks];
|
|
522
|
-
const sortedRemovable = [...removableBlocks].sort((a, b) => a.maxPosition - b.maxPosition);
|
|
523
|
-
const lockedTokens = estimateBlocksAsConversation(selectedLockedBlocks, options, environment);
|
|
524
|
-
const selectFromNewest = (lockedTokenCount) => {
|
|
525
|
-
if (lockedTokenCount >= maxTokens)
|
|
526
|
-
return selectedLockedBlocks;
|
|
527
|
-
const keptRemovable = [];
|
|
528
|
-
for (let index = sortedRemovable.length - 1;index >= 0; index--) {
|
|
529
|
-
const candidate = sortedRemovable[index];
|
|
530
|
-
const candidateTokens = estimateBlocksAsConversation([
|
|
531
|
-
...selectedLockedBlocks,
|
|
532
|
-
candidate,
|
|
533
|
-
...keptRemovable
|
|
534
|
-
], options, environment);
|
|
535
|
-
if (isPromiseLike(candidateTokens))
|
|
536
|
-
return candidateTokens.then(async (resolvedCandidateTokens) => {
|
|
537
|
-
if (resolvedCandidateTokens > maxTokens)
|
|
538
|
-
return [...selectedLockedBlocks, ...keptRemovable];
|
|
539
|
-
keptRemovable.unshift(candidate);
|
|
540
|
-
for (let asyncIndex = index - 1;asyncIndex >= 0; asyncIndex--) {
|
|
541
|
-
const asyncCandidate = sortedRemovable[asyncIndex];
|
|
542
|
-
if (await estimateBlocksAsConversation([
|
|
543
|
-
...selectedLockedBlocks,
|
|
544
|
-
asyncCandidate,
|
|
545
|
-
...keptRemovable
|
|
546
|
-
], options, environment) > maxTokens)
|
|
547
|
-
break;
|
|
548
|
-
keptRemovable.unshift(asyncCandidate);
|
|
549
|
-
}
|
|
550
|
-
return [...selectedLockedBlocks, ...keptRemovable];
|
|
551
|
-
});
|
|
552
|
-
if (candidateTokens > maxTokens)
|
|
553
|
-
break;
|
|
554
|
-
keptRemovable.unshift(candidate);
|
|
555
|
-
}
|
|
556
|
-
return [...selectedLockedBlocks, ...keptRemovable];
|
|
557
|
-
};
|
|
558
|
-
if (isPromiseLike(lockedTokens))
|
|
559
|
-
return lockedTokens.then(selectFromNewest);
|
|
560
|
-
return selectFromNewest(lockedTokens);
|
|
561
|
-
};
|
|
562
|
-
const finish = (selectedBlocks2) => {
|
|
563
|
-
if (selectedBlocks2 === blocks)
|
|
564
|
-
return conversation;
|
|
565
|
-
const renumbered = collectMessagesFromBlocks(selectedBlocks2).map((message, index) => cloneMessageWithPosition(message, index, copyContent(message.content)));
|
|
566
|
-
return ensureTruncationSafe(toReadonly({
|
|
567
|
-
...conversation,
|
|
568
|
-
ids: renumbered.map((message) => message.id),
|
|
569
|
-
messages: toIdRecord(renumbered),
|
|
570
|
-
updatedAt: environment.now()
|
|
571
|
-
}), preserveToolPairs, "truncateToTokenLimit");
|
|
572
|
-
};
|
|
573
|
-
const finishAsync = async (currentTokens) => {
|
|
574
|
-
return finish(await selectBlocks(await currentTokens));
|
|
575
|
-
};
|
|
576
|
-
if (isPromiseLike(countAllMessages))
|
|
577
|
-
return finishAsync(countAllMessages);
|
|
578
|
-
const selectedBlocks = selectBlocks(countAllMessages);
|
|
579
|
-
return isPromiseLike(selectedBlocks) ? selectedBlocks.then(finish) : finish(selectedBlocks);
|
|
580
|
-
};
|
|
581
|
-
function truncateToTokenLimit(conversation, maxTokens, optionsOrEstimator, environment) {
|
|
582
|
-
assertConversationSafe(conversation);
|
|
583
|
-
let options = {};
|
|
584
|
-
let env = environment;
|
|
585
|
-
if (typeof optionsOrEstimator === "function")
|
|
586
|
-
options = { estimateTokens: optionsOrEstimator };
|
|
587
|
-
else if (optionsOrEstimator)
|
|
588
|
-
if (!environment && isConversationEnvironmentParameter(optionsOrEstimator)) {
|
|
589
|
-
const candidate = optionsOrEstimator;
|
|
590
|
-
if (!!(candidate["now"] || candidate["randomId"] || Array.isArray(candidate["plugins"]) && candidate["plugins"].length > 0))
|
|
591
|
-
env = optionsOrEstimator;
|
|
592
|
-
else
|
|
593
|
-
options = optionsOrEstimator;
|
|
594
|
-
} else
|
|
595
|
-
options = optionsOrEstimator;
|
|
596
|
-
const resolvedEnvironment = resolveConversationEnvironment(env);
|
|
597
|
-
const preserveToolPairs = options.preserveToolPairs ?? true;
|
|
598
|
-
const orderedMessages = getOrderedMessages(conversation);
|
|
599
|
-
if (options.estimateConversationTokens)
|
|
600
|
-
return truncateToTokenLimitWithConversationEstimator(conversation, maxTokens, orderedMessages, options, resolvedEnvironment);
|
|
601
|
-
const estimateBlockTokens = (messages) => estimateMessageBlockTokens(messages, options, resolvedEnvironment);
|
|
602
|
-
const currentTokens = estimateBlockTokens(orderedMessages);
|
|
603
|
-
if (isPromiseLike(currentTokens))
|
|
604
|
-
return currentTokens.then(async (resolvedCurrentTokens) => {
|
|
605
|
-
if (resolvedCurrentTokens <= maxTokens)
|
|
606
|
-
return conversation;
|
|
607
|
-
const { blocks: blocks2, messageToBlock: messageToBlock2 } = await buildMessageBlocksAsync(orderedMessages, estimateBlockTokens, preserveToolPairs);
|
|
608
|
-
return truncateToTokenLimitFromBlocks(conversation, maxTokens, resolvedCurrentTokens, orderedMessages, blocks2, messageToBlock2, options, resolvedEnvironment);
|
|
609
|
-
});
|
|
610
|
-
if (currentTokens <= maxTokens)
|
|
611
|
-
return conversation;
|
|
612
|
-
const { blocks, messageToBlock } = buildMessageBlocks(orderedMessages, (messages) => estimateMessageBlockTokens(messages, options, resolvedEnvironment), preserveToolPairs);
|
|
613
|
-
return truncateToTokenLimitFromBlocks(conversation, maxTokens, currentTokens, orderedMessages, blocks, messageToBlock, options, resolvedEnvironment);
|
|
614
|
-
}
|
|
615
|
-
function getRecentMessages(conversation, count, options) {
|
|
616
|
-
const includeHidden = options?.includeHidden ?? false;
|
|
617
|
-
const includeSystem = options?.includeSystem ?? false;
|
|
618
|
-
const preserveToolPairs = options?.preserveToolPairs ?? true;
|
|
619
|
-
const filtered = getOrderedMessages(conversation).filter((m) => {
|
|
620
|
-
if (!includeHidden && m.hidden)
|
|
621
|
-
return false;
|
|
622
|
-
if (!includeSystem && m.role === "system")
|
|
623
|
-
return false;
|
|
624
|
-
return true;
|
|
625
|
-
});
|
|
626
|
-
if (!preserveToolPairs)
|
|
627
|
-
return filtered.slice(-count);
|
|
628
|
-
const { messageToBlock } = buildMessageBlocks(filtered, () => 0, preserveToolPairs);
|
|
629
|
-
return collectMessagesFromBlocks(collectBlocksForMessages(filtered.slice(-count), messageToBlock));
|
|
630
|
-
}
|
|
631
|
-
function truncateFromPosition(conversation, position, options, environment) {
|
|
632
|
-
assertConversationSafe(conversation);
|
|
633
|
-
const preserveSystem = options?.preserveSystemMessages ?? true;
|
|
634
|
-
const preserveToolPairs = options?.preserveToolPairs ?? true;
|
|
635
|
-
const now = resolveConversationEnvironment(environment).now();
|
|
636
|
-
const ordered = getOrderedMessages(conversation);
|
|
637
|
-
const { messageToBlock } = buildMessageBlocks(ordered, () => 0, preserveToolPairs);
|
|
638
|
-
const systemMessages = preserveSystem ? ordered.filter((m) => m.role === "system" && m.position < position) : [];
|
|
639
|
-
const streamingMessages = ordered.filter((m) => isStreamingMessage(m) && m.position < position);
|
|
640
|
-
const keptMessages = ordered.filter((m) => m.position >= position);
|
|
641
|
-
const systemBlocks = collectBlocksForMessages(systemMessages, messageToBlock);
|
|
642
|
-
const streamingBlocks = collectBlocksForMessages(streamingMessages, messageToBlock);
|
|
643
|
-
const keptBlocks = collectBlocksForMessages(keptMessages, messageToBlock);
|
|
644
|
-
const renumbered = collectMessagesFromBlocks([
|
|
645
|
-
...systemBlocks,
|
|
646
|
-
...streamingBlocks,
|
|
647
|
-
...keptBlocks
|
|
648
|
-
]).map((message, index) => cloneMessageWithPosition(message, index, copyContent(message.content)));
|
|
649
|
-
return ensureTruncationSafe(toReadonly({
|
|
650
|
-
...conversation,
|
|
651
|
-
ids: renumbered.map((message) => message.id),
|
|
652
|
-
messages: toIdRecord(renumbered),
|
|
653
|
-
updatedAt: now
|
|
654
|
-
}), preserveToolPairs, "truncateFromPosition");
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
// ../../node_modules/conversationalist/dist/history-5vdiTmMp.js
|
|
658
|
-
function calculateChunkSize(totalTokens, averageMessageTokens, contextWindow, options) {
|
|
659
|
-
const baseRatio = options?.baseChunkRatio ?? 0.4;
|
|
660
|
-
const minRatio = options?.minimumChunkRatio ?? 0.15;
|
|
661
|
-
const safety = options?.safetyMargin ?? 1.2;
|
|
662
|
-
const ratio = averageMessageTokens > contextWindow * 0.1 ? minRatio : baseRatio;
|
|
663
|
-
return Math.max(1, Math.floor(totalTokens * ratio / safety));
|
|
664
|
-
}
|
|
665
|
-
function partitionMessages(conversation, options, _environment) {
|
|
666
|
-
const preserveRecent = options?.preserveRecentCount ?? 4;
|
|
667
|
-
const preserveSystem = options?.preserveSystemMessages ?? true;
|
|
668
|
-
const preserveToolPairs = options?.preserveToolPairs ?? true;
|
|
669
|
-
const allMessages = getMessages(conversation);
|
|
670
|
-
const systemMessages = preserveSystem ? allMessages.filter((m) => m.role === "system") : [];
|
|
671
|
-
const streamingMessages = allMessages.filter(isStreamingMessage);
|
|
672
|
-
const nonSystem = allMessages.filter((m) => m.role !== "system");
|
|
673
|
-
if (nonSystem.length <= preserveRecent)
|
|
674
|
-
return {
|
|
675
|
-
compactable: [],
|
|
676
|
-
preserved: [...allMessages]
|
|
677
|
-
};
|
|
678
|
-
let recentMessages = nonSystem.slice(-preserveRecent);
|
|
679
|
-
if (preserveToolPairs && recentMessages.length > 0) {
|
|
680
|
-
const firstRecent = recentMessages[0];
|
|
681
|
-
if (firstRecent.role === "tool-result" && firstRecent.toolResult) {
|
|
682
|
-
const callId = firstRecent.toolResult.callId;
|
|
683
|
-
const toolCallMsg = nonSystem.find((m) => m.role === "tool-call" && m.toolCall?.id === callId);
|
|
684
|
-
if (toolCallMsg && !recentMessages.includes(toolCallMsg))
|
|
685
|
-
recentMessages = [toolCallMsg, ...recentMessages];
|
|
686
|
-
}
|
|
687
|
-
}
|
|
688
|
-
const preservedSet = new Set([
|
|
689
|
-
...systemMessages.map((m) => m.id),
|
|
690
|
-
...recentMessages.map((m) => m.id),
|
|
691
|
-
...streamingMessages.map((m) => m.id)
|
|
692
|
-
]);
|
|
693
|
-
return {
|
|
694
|
-
compactable: allMessages.filter((m) => !preservedSet.has(m.id)),
|
|
695
|
-
preserved: allMessages.filter((m) => preservedSet.has(m.id))
|
|
696
|
-
};
|
|
697
|
-
}
|
|
698
|
-
function chunkMessages(messages, chunkTokenBudget, estimator) {
|
|
699
|
-
if (messages.length === 0)
|
|
700
|
-
return [];
|
|
701
|
-
const chunks = [];
|
|
702
|
-
let currentChunk = [];
|
|
703
|
-
let currentTokens = 0;
|
|
704
|
-
for (let i = 0;i < messages.length; i++) {
|
|
705
|
-
const message = messages[i];
|
|
706
|
-
const tokens = estimator(message);
|
|
707
|
-
let pairedMessages = [message];
|
|
708
|
-
let pairedTokens = tokens;
|
|
709
|
-
if (message.role === "tool-call" && message.toolCall) {
|
|
710
|
-
const nextIdx = i + 1;
|
|
711
|
-
if (nextIdx < messages.length) {
|
|
712
|
-
const next = messages[nextIdx];
|
|
713
|
-
if (next.role === "tool-result" && next.toolResult?.callId === message.toolCall.id) {
|
|
714
|
-
pairedMessages = [message, next];
|
|
715
|
-
pairedTokens = tokens + estimator(next);
|
|
716
|
-
i++;
|
|
717
|
-
}
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
if (currentTokens + pairedTokens > chunkTokenBudget && currentChunk.length > 0) {
|
|
721
|
-
chunks.push(currentChunk);
|
|
722
|
-
currentChunk = [];
|
|
723
|
-
currentTokens = 0;
|
|
724
|
-
}
|
|
725
|
-
currentChunk.push(...pairedMessages);
|
|
726
|
-
currentTokens += pairedTokens;
|
|
727
|
-
}
|
|
728
|
-
if (currentChunk.length > 0)
|
|
729
|
-
chunks.push(currentChunk);
|
|
730
|
-
return chunks;
|
|
731
|
-
}
|
|
732
|
-
var STRIPPED_PLACEHOLDER = "[tool result]";
|
|
733
|
-
function stripStructuralToolBlocks(content) {
|
|
734
|
-
if (typeof content === "string")
|
|
735
|
-
return content;
|
|
736
|
-
return content.flatMap((part) => {
|
|
737
|
-
switch (part.type) {
|
|
738
|
-
case "server_tool_use":
|
|
739
|
-
return [{
|
|
740
|
-
...part,
|
|
741
|
-
input: STRIPPED_PLACEHOLDER
|
|
742
|
-
}];
|
|
743
|
-
case "web_search_tool_result":
|
|
744
|
-
case "web_fetch_tool_result":
|
|
745
|
-
case "code_execution_tool_result":
|
|
746
|
-
case "bash_code_execution_tool_result":
|
|
747
|
-
case "text_editor_code_execution_tool_result":
|
|
748
|
-
return [{
|
|
749
|
-
...part,
|
|
750
|
-
content: STRIPPED_PLACEHOLDER
|
|
751
|
-
}];
|
|
752
|
-
case "text": {
|
|
753
|
-
if (part.citations === undefined)
|
|
754
|
-
return [part];
|
|
755
|
-
const { citations: _citations, ...rest } = part;
|
|
756
|
-
return [rest];
|
|
757
|
-
}
|
|
758
|
-
case "thinking":
|
|
759
|
-
case "redacted_thinking":
|
|
760
|
-
return [];
|
|
761
|
-
default:
|
|
762
|
-
return [part];
|
|
763
|
-
}
|
|
764
|
-
});
|
|
765
|
-
}
|
|
766
|
-
function stripToolResultDetails(messages) {
|
|
767
|
-
return messages.map((message) => {
|
|
768
|
-
if (message.role === "tool-result" && message.toolResult)
|
|
769
|
-
return {
|
|
770
|
-
...message,
|
|
771
|
-
content: STRIPPED_PLACEHOLDER,
|
|
772
|
-
toolResult: {
|
|
773
|
-
...message.toolResult,
|
|
774
|
-
content: STRIPPED_PLACEHOLDER
|
|
775
|
-
}
|
|
776
|
-
};
|
|
777
|
-
if (typeof message.content !== "string")
|
|
778
|
-
return {
|
|
779
|
-
...message,
|
|
780
|
-
content: stripStructuralToolBlocks(message.content)
|
|
781
|
-
};
|
|
782
|
-
return message;
|
|
783
|
-
});
|
|
784
|
-
}
|
|
785
|
-
async function compactConversation(conversation, summarizer, options, environment) {
|
|
786
|
-
const env = resolveConversationEnvironment(environment);
|
|
787
|
-
const estimator = env.estimateTokens ?? simpleTokenEstimator;
|
|
788
|
-
const { compactable, preserved } = partitionMessages(conversation, options, environment);
|
|
789
|
-
if (compactable.length === 0)
|
|
790
|
-
return {
|
|
791
|
-
conversation,
|
|
792
|
-
result: {
|
|
793
|
-
compacted: false,
|
|
794
|
-
chunksProcessed: 0,
|
|
795
|
-
messagesRemoved: 0,
|
|
796
|
-
summaryContent: ""
|
|
797
|
-
}
|
|
798
|
-
};
|
|
799
|
-
const totalTokens = compactable.reduce((sum, m) => sum + estimator(m), 0);
|
|
800
|
-
const chunkBudget = calculateChunkSize(totalTokens, totalTokens / compactable.length, totalTokens * 3, options);
|
|
801
|
-
const chunks = chunkMessages(stripToolResultDetails(compactable), chunkBudget, estimator);
|
|
802
|
-
const summaries = [];
|
|
803
|
-
for (const chunk of chunks) {
|
|
804
|
-
const summary = await summarizer(chunk, { maxTokens: options?.maxSummaryTokens });
|
|
805
|
-
summaries.push(summary);
|
|
806
|
-
}
|
|
807
|
-
const summaryContent = summaries.length === 1 ? summaries[0] : summaries.join(`
|
|
808
|
-
|
|
809
|
-
---
|
|
810
|
-
|
|
811
|
-
`);
|
|
812
|
-
let compacted = {
|
|
813
|
-
schemaVersion: 4,
|
|
814
|
-
id: conversation.id,
|
|
815
|
-
title: conversation.title,
|
|
816
|
-
status: conversation.status,
|
|
817
|
-
metadata: { ...conversation.metadata },
|
|
818
|
-
ids: [],
|
|
819
|
-
messages: {},
|
|
820
|
-
createdAt: conversation.createdAt,
|
|
821
|
-
updatedAt: env.now()
|
|
822
|
-
};
|
|
823
|
-
compacted = ensureConversationSafe(toReadonly(compacted));
|
|
824
|
-
compacted = appendMessages(compacted, {
|
|
825
|
-
role: "system",
|
|
826
|
-
content: summaryContent,
|
|
827
|
-
metadata: { compactionSummary: true }
|
|
828
|
-
}, env);
|
|
829
|
-
if (preserved.length > 0) {
|
|
830
|
-
const preservedInputs = preserved.map((m) => ({
|
|
831
|
-
role: m.role,
|
|
832
|
-
content: typeof m.content === "string" ? m.content : [...m.content],
|
|
833
|
-
metadata: { ...m.metadata },
|
|
834
|
-
hidden: m.hidden,
|
|
835
|
-
toolCall: m.toolCall ? { ...m.toolCall } : undefined,
|
|
836
|
-
toolResult: m.toolResult ? { ...m.toolResult } : undefined,
|
|
837
|
-
tokenUsage: m.tokenUsage ? { ...m.tokenUsage } : undefined
|
|
838
|
-
}));
|
|
839
|
-
compacted = appendMessages(compacted, ...preservedInputs, env);
|
|
840
|
-
}
|
|
841
|
-
return {
|
|
842
|
-
conversation: compacted,
|
|
843
|
-
result: {
|
|
844
|
-
compacted: true,
|
|
845
|
-
chunksProcessed: chunks.length,
|
|
846
|
-
messagesRemoved: compactable.length,
|
|
847
|
-
summaryContent
|
|
848
|
-
}
|
|
849
|
-
};
|
|
850
|
-
}
|
|
851
|
-
var ConversationEvent = class extends Event {
|
|
852
|
-
action;
|
|
853
|
-
conversation;
|
|
854
|
-
previousConversation;
|
|
855
|
-
messageIds;
|
|
856
|
-
toolCallIds;
|
|
857
|
-
constructor(type, detail) {
|
|
858
|
-
super(type);
|
|
859
|
-
this.action = detail.action;
|
|
860
|
-
this.conversation = detail.conversation;
|
|
861
|
-
this.previousConversation = detail.previousConversation;
|
|
862
|
-
if (detail.messageIds !== undefined)
|
|
863
|
-
this.messageIds = detail.messageIds;
|
|
864
|
-
if (detail.toolCallIds !== undefined)
|
|
865
|
-
this.toolCallIds = detail.toolCallIds;
|
|
866
|
-
}
|
|
867
|
-
};
|
|
868
|
-
var ConversationChangeEvent = class ConversationChangeEvent2 extends ConversationEvent {
|
|
869
|
-
static type = "change";
|
|
870
|
-
constructor(detail) {
|
|
871
|
-
super(ConversationChangeEvent2.type, detail);
|
|
872
|
-
}
|
|
873
|
-
};
|
|
874
|
-
var ConversationPushEvent = class ConversationPushEvent2 extends ConversationEvent {
|
|
875
|
-
static type = "push";
|
|
876
|
-
constructor(detail) {
|
|
877
|
-
super(ConversationPushEvent2.type, detail);
|
|
878
|
-
}
|
|
879
|
-
};
|
|
880
|
-
var ConversationUndoEvent = class ConversationUndoEvent2 extends ConversationEvent {
|
|
881
|
-
static type = "undo";
|
|
882
|
-
constructor(detail) {
|
|
883
|
-
super(ConversationUndoEvent2.type, detail);
|
|
884
|
-
}
|
|
885
|
-
};
|
|
886
|
-
var ConversationRedoEvent = class ConversationRedoEvent2 extends ConversationEvent {
|
|
887
|
-
static type = "redo";
|
|
888
|
-
constructor(detail) {
|
|
889
|
-
super(ConversationRedoEvent2.type, detail);
|
|
890
|
-
}
|
|
891
|
-
};
|
|
892
|
-
var ConversationSwitchEvent = class ConversationSwitchEvent2 extends ConversationEvent {
|
|
893
|
-
static type = "switch";
|
|
894
|
-
constructor(detail) {
|
|
895
|
-
super(ConversationSwitchEvent2.type, detail);
|
|
896
|
-
}
|
|
897
|
-
};
|
|
898
|
-
var MessagesAppendedEvent = class MessagesAppendedEvent2 extends ConversationEvent {
|
|
899
|
-
static type = "messages.appended";
|
|
900
|
-
constructor(detail) {
|
|
901
|
-
super(MessagesAppendedEvent2.type, detail);
|
|
902
|
-
}
|
|
903
|
-
};
|
|
904
|
-
var MessagesUpdatedEvent = class MessagesUpdatedEvent2 extends ConversationEvent {
|
|
905
|
-
static type = "messages.updated";
|
|
906
|
-
constructor(detail) {
|
|
907
|
-
super(MessagesUpdatedEvent2.type, detail);
|
|
908
|
-
}
|
|
909
|
-
};
|
|
910
|
-
var MessagesRemovedEvent = class MessagesRemovedEvent2 extends ConversationEvent {
|
|
911
|
-
static type = "messages.removed";
|
|
912
|
-
constructor(detail) {
|
|
913
|
-
super(MessagesRemovedEvent2.type, detail);
|
|
914
|
-
}
|
|
915
|
-
};
|
|
916
|
-
var ToolCallsAppendedEvent = class ToolCallsAppendedEvent2 extends ConversationEvent {
|
|
917
|
-
static type = "tool-calls.appended";
|
|
918
|
-
constructor(detail) {
|
|
919
|
-
super(ToolCallsAppendedEvent2.type, detail);
|
|
920
|
-
}
|
|
921
|
-
};
|
|
922
|
-
var ToolResultsAppendedEvent = class ToolResultsAppendedEvent2 extends ConversationEvent {
|
|
923
|
-
static type = "tool-results.appended";
|
|
924
|
-
constructor(detail) {
|
|
925
|
-
super(ToolResultsAppendedEvent2.type, detail);
|
|
926
|
-
}
|
|
927
|
-
};
|
|
928
|
-
var StreamStartedEvent = class StreamStartedEvent2 extends ConversationEvent {
|
|
929
|
-
static type = "stream.started";
|
|
930
|
-
constructor(detail) {
|
|
931
|
-
super(StreamStartedEvent2.type, detail);
|
|
932
|
-
}
|
|
933
|
-
};
|
|
934
|
-
var StreamUpdatedEvent = class StreamUpdatedEvent2 extends ConversationEvent {
|
|
935
|
-
static type = "stream.updated";
|
|
936
|
-
constructor(detail) {
|
|
937
|
-
super(StreamUpdatedEvent2.type, detail);
|
|
938
|
-
}
|
|
939
|
-
};
|
|
940
|
-
var StreamFinalizedEvent = class StreamFinalizedEvent2 extends ConversationEvent {
|
|
941
|
-
static type = "stream.finalized";
|
|
942
|
-
constructor(detail) {
|
|
943
|
-
super(StreamFinalizedEvent2.type, detail);
|
|
944
|
-
}
|
|
945
|
-
};
|
|
946
|
-
var StreamCancelledEvent = class StreamCancelledEvent2 extends ConversationEvent {
|
|
947
|
-
static type = "stream.cancelled";
|
|
948
|
-
constructor(detail) {
|
|
949
|
-
super(StreamCancelledEvent2.type, detail);
|
|
950
|
-
}
|
|
951
|
-
};
|
|
952
|
-
var CompactionStartedEvent = class CompactionStartedEvent2 extends ConversationEvent {
|
|
953
|
-
static type = "compaction.started";
|
|
954
|
-
constructor(detail) {
|
|
955
|
-
super(CompactionStartedEvent2.type, detail);
|
|
956
|
-
}
|
|
957
|
-
};
|
|
958
|
-
var CompactionCompletedEvent = class CompactionCompletedEvent2 extends ConversationEvent {
|
|
959
|
-
static type = "compaction.completed";
|
|
960
|
-
constructor(detail) {
|
|
961
|
-
super(CompactionCompletedEvent2.type, detail);
|
|
962
|
-
}
|
|
963
|
-
};
|
|
964
|
-
var SessionForkedEvent = class SessionForkedEvent2 extends ConversationEvent {
|
|
965
|
-
static type = "session.forked";
|
|
966
|
-
constructor(detail) {
|
|
967
|
-
super(SessionForkedEvent2.type, detail);
|
|
968
|
-
}
|
|
969
|
-
};
|
|
970
|
-
var SessionTaggedEvent = class SessionTaggedEvent2 extends ConversationEvent {
|
|
971
|
-
static type = "session.tagged";
|
|
972
|
-
constructor(detail) {
|
|
973
|
-
super(SessionTaggedEvent2.type, detail);
|
|
974
|
-
}
|
|
975
|
-
};
|
|
976
|
-
var SessionRenamedEvent = class SessionRenamedEvent2 extends ConversationEvent {
|
|
977
|
-
static type = "session.renamed";
|
|
978
|
-
constructor(detail) {
|
|
979
|
-
super(SessionRenamedEvent2.type, detail);
|
|
980
|
-
}
|
|
981
|
-
};
|
|
982
|
-
var PersistenceErrorEvent = class PersistenceErrorEvent2 extends Event {
|
|
983
|
-
static type = "persistence.error";
|
|
984
|
-
error;
|
|
985
|
-
constructor(error) {
|
|
986
|
-
super(PersistenceErrorEvent2.type);
|
|
987
|
-
this.error = error;
|
|
988
|
-
}
|
|
989
|
-
};
|
|
990
|
-
var conversationEventConstructors = {
|
|
991
|
-
[ConversationChangeEvent.type]: ConversationChangeEvent,
|
|
992
|
-
[ConversationPushEvent.type]: ConversationPushEvent,
|
|
993
|
-
[ConversationUndoEvent.type]: ConversationUndoEvent,
|
|
994
|
-
[ConversationRedoEvent.type]: ConversationRedoEvent,
|
|
995
|
-
[ConversationSwitchEvent.type]: ConversationSwitchEvent,
|
|
996
|
-
[MessagesAppendedEvent.type]: MessagesAppendedEvent,
|
|
997
|
-
[MessagesUpdatedEvent.type]: MessagesUpdatedEvent,
|
|
998
|
-
[MessagesRemovedEvent.type]: MessagesRemovedEvent,
|
|
999
|
-
[ToolCallsAppendedEvent.type]: ToolCallsAppendedEvent,
|
|
1000
|
-
[ToolResultsAppendedEvent.type]: ToolResultsAppendedEvent,
|
|
1001
|
-
[StreamStartedEvent.type]: StreamStartedEvent,
|
|
1002
|
-
[StreamUpdatedEvent.type]: StreamUpdatedEvent,
|
|
1003
|
-
[StreamFinalizedEvent.type]: StreamFinalizedEvent,
|
|
1004
|
-
[StreamCancelledEvent.type]: StreamCancelledEvent,
|
|
1005
|
-
[CompactionStartedEvent.type]: CompactionStartedEvent,
|
|
1006
|
-
[CompactionCompletedEvent.type]: CompactionCompletedEvent,
|
|
1007
|
-
[SessionForkedEvent.type]: SessionForkedEvent,
|
|
1008
|
-
[SessionTaggedEvent.type]: SessionTaggedEvent,
|
|
1009
|
-
[SessionRenamedEvent.type]: SessionRenamedEvent
|
|
1010
|
-
};
|
|
1011
|
-
function Y(H, f, R) {
|
|
1012
|
-
let P = R?.bufferSize ?? 256, D = R?.signal, G = [], M = null, B = false;
|
|
1013
|
-
function C(K) {
|
|
1014
|
-
let Q = K;
|
|
1015
|
-
if (M) {
|
|
1016
|
-
let z = M;
|
|
1017
|
-
M = null, z({
|
|
1018
|
-
value: Q,
|
|
1019
|
-
done: false
|
|
1020
|
-
});
|
|
1021
|
-
} else if (G.length < P)
|
|
1022
|
-
G.push(Q);
|
|
1023
|
-
}
|
|
1024
|
-
function J() {
|
|
1025
|
-
if (B)
|
|
1026
|
-
return;
|
|
1027
|
-
if (B = true, H.removeEventListener(f, C), M) {
|
|
1028
|
-
let K = M;
|
|
1029
|
-
M = null, K({
|
|
1030
|
-
value: undefined,
|
|
1031
|
-
done: true
|
|
1032
|
-
});
|
|
1033
|
-
}
|
|
1034
|
-
}
|
|
1035
|
-
if (D?.aborted)
|
|
1036
|
-
B = true;
|
|
1037
|
-
else
|
|
1038
|
-
H.addEventListener(f, C), D?.addEventListener("abort", J, { once: true });
|
|
1039
|
-
return {
|
|
1040
|
-
next() {
|
|
1041
|
-
if (G.length > 0)
|
|
1042
|
-
return Promise.resolve({
|
|
1043
|
-
value: G.shift(),
|
|
1044
|
-
done: false
|
|
1045
|
-
});
|
|
1046
|
-
if (B)
|
|
1047
|
-
return Promise.resolve({
|
|
1048
|
-
value: undefined,
|
|
1049
|
-
done: true
|
|
1050
|
-
});
|
|
1051
|
-
return new Promise((K) => {
|
|
1052
|
-
M = K;
|
|
1053
|
-
});
|
|
1054
|
-
},
|
|
1055
|
-
return() {
|
|
1056
|
-
return J(), Promise.resolve({
|
|
1057
|
-
value: undefined,
|
|
1058
|
-
done: true
|
|
1059
|
-
});
|
|
1060
|
-
},
|
|
1061
|
-
[Symbol.asyncIterator]() {
|
|
1062
|
-
return this;
|
|
1063
|
-
}
|
|
1064
|
-
};
|
|
1065
|
-
}
|
|
1066
|
-
function Z(H, f, R) {
|
|
1067
|
-
return { subscribe(P, D, G) {
|
|
1068
|
-
let M = typeof P === "function" ? {
|
|
1069
|
-
next: P,
|
|
1070
|
-
error: D,
|
|
1071
|
-
complete: G
|
|
1072
|
-
} : P ?? {}, B = new AbortController, C = false, J = {
|
|
1073
|
-
unsubscribe() {
|
|
1074
|
-
if (C)
|
|
1075
|
-
return;
|
|
1076
|
-
C = true, B.abort(), M.complete?.();
|
|
1077
|
-
},
|
|
1078
|
-
get closed() {
|
|
1079
|
-
return C;
|
|
1080
|
-
}
|
|
1081
|
-
};
|
|
1082
|
-
if (M.start?.(J), C)
|
|
1083
|
-
return J;
|
|
1084
|
-
function U(Q) {
|
|
1085
|
-
M.next?.(Q);
|
|
1086
|
-
}
|
|
1087
|
-
let K = R?.signal ? AbortSignal.any([R.signal, B.signal]) : B.signal;
|
|
1088
|
-
if (H.addEventListener(f, U, { signal: K }), R?.signal)
|
|
1089
|
-
R.signal.addEventListener("abort", () => {
|
|
1090
|
-
if (!C)
|
|
1091
|
-
C = true, M.complete?.();
|
|
1092
|
-
}, {
|
|
1093
|
-
once: true,
|
|
1094
|
-
signal: B.signal
|
|
1095
|
-
});
|
|
1096
|
-
return J;
|
|
1097
|
-
} };
|
|
1098
|
-
}
|
|
1099
|
-
var W = class extends EventTarget {
|
|
1100
|
-
constructor() {
|
|
1101
|
-
super();
|
|
1102
|
-
}
|
|
1103
|
-
addEventListener(H, f, R) {
|
|
1104
|
-
super.addEventListener(H, f, R);
|
|
1105
|
-
}
|
|
1106
|
-
removeEventListener(H, f, R) {
|
|
1107
|
-
super.removeEventListener(H, f, R);
|
|
1108
|
-
}
|
|
1109
|
-
dispatch(H) {
|
|
1110
|
-
return this.dispatchEvent(H);
|
|
1111
|
-
}
|
|
1112
|
-
};
|
|
1113
|
-
var j = class extends W {
|
|
1114
|
-
#H = new AbortController;
|
|
1115
|
-
#f = /* @__PURE__ */ new Set;
|
|
1116
|
-
constructor() {
|
|
1117
|
-
super();
|
|
1118
|
-
}
|
|
1119
|
-
get completed() {
|
|
1120
|
-
return this.#H.signal.aborted;
|
|
1121
|
-
}
|
|
1122
|
-
get signal() {
|
|
1123
|
-
return this.#H.signal;
|
|
1124
|
-
}
|
|
1125
|
-
complete() {
|
|
1126
|
-
if (!this.#H.signal.aborted)
|
|
1127
|
-
this.#H.abort();
|
|
1128
|
-
}
|
|
1129
|
-
dispatchEvent(H) {
|
|
1130
|
-
let f = super.dispatchEvent(H);
|
|
1131
|
-
for (let R of this.#f)
|
|
1132
|
-
R(H);
|
|
1133
|
-
return f;
|
|
1134
|
-
}
|
|
1135
|
-
on(H, f) {
|
|
1136
|
-
return Z(this, H, { signal: f?.signal ?? this.signal });
|
|
1137
|
-
}
|
|
1138
|
-
once(H, f) {
|
|
1139
|
-
this.addEventListener(H, f, {
|
|
1140
|
-
once: true,
|
|
1141
|
-
signal: this.signal
|
|
1142
|
-
});
|
|
1143
|
-
}
|
|
1144
|
-
subscribe(H, f, R, P) {
|
|
1145
|
-
return this.on(H).subscribe(f, R, P);
|
|
1146
|
-
}
|
|
1147
|
-
toObservable() {
|
|
1148
|
-
return { subscribe: (H, f, R) => {
|
|
1149
|
-
let P = typeof H === "function" ? {
|
|
1150
|
-
next: H,
|
|
1151
|
-
error: f,
|
|
1152
|
-
complete: R
|
|
1153
|
-
} : H ?? {}, D = false, G = (B) => {
|
|
1154
|
-
if (!D)
|
|
1155
|
-
P.next?.(B);
|
|
1156
|
-
};
|
|
1157
|
-
this.#f.add(G);
|
|
1158
|
-
let M = () => {
|
|
1159
|
-
if (!D)
|
|
1160
|
-
D = true, this.#f.delete(G), P.complete?.();
|
|
1161
|
-
};
|
|
1162
|
-
return this.signal.addEventListener("abort", M, { once: true }), {
|
|
1163
|
-
unsubscribe: () => {
|
|
1164
|
-
if (D)
|
|
1165
|
-
return;
|
|
1166
|
-
D = true, this.#f.delete(G), this.signal.removeEventListener("abort", M), P.complete?.();
|
|
1167
|
-
},
|
|
1168
|
-
get closed() {
|
|
1169
|
-
return D;
|
|
1170
|
-
}
|
|
1171
|
-
};
|
|
1172
|
-
} };
|
|
1173
|
-
}
|
|
1174
|
-
events(H, f) {
|
|
1175
|
-
return Y(this, H, {
|
|
1176
|
-
signal: f?.signal ?? this.signal,
|
|
1177
|
-
bufferSize: f?.bufferSize
|
|
1178
|
-
});
|
|
1179
|
-
}
|
|
1180
|
-
};
|
|
1181
|
-
function diffConversationMessages(previousConversation, nextConversation) {
|
|
1182
|
-
const previousIds = new Set(previousConversation.ids);
|
|
1183
|
-
const nextIds = new Set(nextConversation.ids);
|
|
1184
|
-
const appended = nextConversation.ids.filter((id) => !previousIds.has(id));
|
|
1185
|
-
const removed = previousConversation.ids.filter((id) => !nextIds.has(id));
|
|
1186
|
-
const updated = [];
|
|
1187
|
-
for (const id of nextConversation.ids) {
|
|
1188
|
-
if (!previousIds.has(id))
|
|
1189
|
-
continue;
|
|
1190
|
-
const previousMessage = previousConversation.messages[id];
|
|
1191
|
-
const nextMessage = nextConversation.messages[id];
|
|
1192
|
-
if (!previousMessage || !nextMessage)
|
|
1193
|
-
continue;
|
|
1194
|
-
if (JSON.stringify(previousMessage) !== JSON.stringify(nextMessage))
|
|
1195
|
-
updated.push(id);
|
|
1196
|
-
}
|
|
1197
|
-
return {
|
|
1198
|
-
appended,
|
|
1199
|
-
updated,
|
|
1200
|
-
removed
|
|
1201
|
-
};
|
|
1202
|
-
}
|
|
1203
|
-
function collectToolCallIds(conversation, messageIds) {
|
|
1204
|
-
if (!messageIds || messageIds.length === 0)
|
|
1205
|
-
return;
|
|
1206
|
-
const ids = /* @__PURE__ */ new Set;
|
|
1207
|
-
for (const messageId of messageIds) {
|
|
1208
|
-
const message = conversation.messages[messageId];
|
|
1209
|
-
if (!message)
|
|
1210
|
-
continue;
|
|
1211
|
-
if (message.toolCall?.id)
|
|
1212
|
-
ids.add(message.toolCall.id);
|
|
1213
|
-
if (message.toolResult?.callId)
|
|
1214
|
-
ids.add(message.toolResult.callId);
|
|
1215
|
-
}
|
|
1216
|
-
return ids.size > 0 ? [...ids] : undefined;
|
|
1217
|
-
}
|
|
1218
|
-
async function loadConversationAdapter(provider) {
|
|
1219
|
-
switch (provider) {
|
|
1220
|
-
case "openai":
|
|
1221
|
-
return (await import("./index-8fhvxk30.js")).openAIConversationAdapter;
|
|
1222
|
-
case "anthropic":
|
|
1223
|
-
return (await import("./index-x2ysg8ds.js")).anthropicConversationAdapter;
|
|
1224
|
-
case "gemini":
|
|
1225
|
-
return (await import("./index-49we2xfs.js")).geminiConversationAdapter;
|
|
1226
|
-
}
|
|
1227
|
-
}
|
|
1228
|
-
var Conversation = class Conversation2 {
|
|
1229
|
-
currentNode;
|
|
1230
|
-
environment;
|
|
1231
|
-
emitter = new j;
|
|
1232
|
-
constructor(initial = createConversationHistory(), environment) {
|
|
1233
|
-
this.environment = resolveConversationEnvironment(environment);
|
|
1234
|
-
const safeInitial = ensureConversationSafe(initial);
|
|
1235
|
-
this.currentNode = {
|
|
1236
|
-
conversation: safeInitial,
|
|
1237
|
-
parent: null,
|
|
1238
|
-
children: []
|
|
1239
|
-
};
|
|
1240
|
-
if (this.environment.persistence) {
|
|
1241
|
-
const store = this.environment.persistence;
|
|
1242
|
-
const setTimeoutFunction = this.environment.setTimeoutFunction ?? ((callback, milliseconds) => setTimeout(() => {
|
|
1243
|
-
callback();
|
|
1244
|
-
}, milliseconds));
|
|
1245
|
-
const clearTimeoutFunction = this.environment.clearTimeoutFunction ?? ((handle) => clearTimeout(handle));
|
|
1246
|
-
const debounceMilliseconds = this.environment.persistenceDebounceMilliseconds ?? 100;
|
|
1247
|
-
let debounceTimer;
|
|
1248
|
-
let hasDebounceTimer = false;
|
|
1249
|
-
this.addEventListener("change", () => {
|
|
1250
|
-
if (hasDebounceTimer)
|
|
1251
|
-
clearTimeoutFunction(debounceTimer);
|
|
1252
|
-
debounceTimer = setTimeoutFunction(() => {
|
|
1253
|
-
const conversation = this.current;
|
|
1254
|
-
return Promise.all([store.set(`session:${conversation.id}`, JSON.stringify(conversation)), store.set(`session-info:${conversation.id}`, JSON.stringify(toSessionInfo(conversation)))]).then(() => {
|
|
1255
|
-
return;
|
|
1256
|
-
}).catch((error) => {
|
|
1257
|
-
this.emitter.dispatchEvent(new PersistenceErrorEvent(error));
|
|
1258
|
-
});
|
|
1259
|
-
}, debounceMilliseconds);
|
|
1260
|
-
hasDebounceTimer = true;
|
|
1261
|
-
});
|
|
1262
|
-
}
|
|
1263
|
-
}
|
|
1264
|
-
buildEventDetail(action, previousConversation, context = {}) {
|
|
1265
|
-
return {
|
|
1266
|
-
action,
|
|
1267
|
-
conversation: this.current,
|
|
1268
|
-
previousConversation,
|
|
1269
|
-
...context.messageIds && context.messageIds.length > 0 ? { messageIds: context.messageIds } : {},
|
|
1270
|
-
...context.toolCallIds && context.toolCallIds.length > 0 ? { toolCallIds: context.toolCallIds } : {}
|
|
1271
|
-
};
|
|
1272
|
-
}
|
|
1273
|
-
emitConversationEvent(type, detail) {
|
|
1274
|
-
const EventConstructor = conversationEventConstructors[type];
|
|
1275
|
-
if (EventConstructor)
|
|
1276
|
-
this.emitter.dispatchEvent(new EventConstructor(detail));
|
|
1277
|
-
}
|
|
1278
|
-
commit(next, changeAction, emittedEvents, context) {
|
|
1279
|
-
const previousConversation = this.current;
|
|
1280
|
-
const newNode = {
|
|
1281
|
-
conversation: next,
|
|
1282
|
-
parent: this.currentNode,
|
|
1283
|
-
children: []
|
|
1284
|
-
};
|
|
1285
|
-
this.currentNode.children.push(newNode);
|
|
1286
|
-
this.currentNode = newNode;
|
|
1287
|
-
if (this.environment.maxHistoryDepth !== undefined)
|
|
1288
|
-
this.pruneToDepth(this.environment.maxHistoryDepth);
|
|
1289
|
-
this.emitConversationEvent("change", this.buildEventDetail(changeAction, previousConversation, context));
|
|
1290
|
-
for (const eventType of emittedEvents) {
|
|
1291
|
-
if (eventType === "change")
|
|
1292
|
-
continue;
|
|
1293
|
-
const eventAction = eventType;
|
|
1294
|
-
this.emitConversationEvent(eventType, this.buildEventDetail(eventAction, previousConversation, context));
|
|
1295
|
-
}
|
|
1296
|
-
}
|
|
1297
|
-
pruneToDepth(maxDepth) {
|
|
1298
|
-
let depth = 0;
|
|
1299
|
-
let node = this.currentNode;
|
|
1300
|
-
while (node) {
|
|
1301
|
-
depth++;
|
|
1302
|
-
node = node.parent;
|
|
1303
|
-
}
|
|
1304
|
-
while (depth > maxDepth) {
|
|
1305
|
-
let root = this.currentNode;
|
|
1306
|
-
while (root.parent)
|
|
1307
|
-
root = root.parent;
|
|
1308
|
-
const childOnPath = root.children.find((child) => {
|
|
1309
|
-
let curr = this.currentNode;
|
|
1310
|
-
while (curr) {
|
|
1311
|
-
if (curr === child)
|
|
1312
|
-
return true;
|
|
1313
|
-
curr = curr.parent;
|
|
1314
|
-
}
|
|
1315
|
-
return false;
|
|
1316
|
-
});
|
|
1317
|
-
if (!childOnPath)
|
|
1318
|
-
break;
|
|
1319
|
-
childOnPath.parent = null;
|
|
1320
|
-
depth--;
|
|
1321
|
-
}
|
|
1322
|
-
}
|
|
1323
|
-
addEventListener(type, callback, options) {
|
|
1324
|
-
const resolved = typeof options === "boolean" ? { capture: options } : { ...options };
|
|
1325
|
-
resolved.signal ??= this.emitter.signal;
|
|
1326
|
-
this.emitter.addEventListener(type, callback, resolved);
|
|
1327
|
-
}
|
|
1328
|
-
removeEventListener(type, callback, options) {
|
|
1329
|
-
this.emitter.removeEventListener(type, callback, options);
|
|
1330
|
-
}
|
|
1331
|
-
dispatchEvent(event) {
|
|
1332
|
-
return this.emitter.dispatchEvent(event);
|
|
1333
|
-
}
|
|
1334
|
-
watch(run) {
|
|
1335
|
-
run(this.current);
|
|
1336
|
-
const handler = (event) => {
|
|
1337
|
-
run(event.conversation);
|
|
1338
|
-
};
|
|
1339
|
-
this.emitter.addEventListener("change", handler, { signal: this.emitter.signal });
|
|
1340
|
-
return () => {
|
|
1341
|
-
this.emitter.removeEventListener("change", handler);
|
|
1342
|
-
};
|
|
1343
|
-
}
|
|
1344
|
-
on(type) {
|
|
1345
|
-
return this.emitter.on(type);
|
|
1346
|
-
}
|
|
1347
|
-
once(type, listener) {
|
|
1348
|
-
this.emitter.once(type, listener);
|
|
1349
|
-
}
|
|
1350
|
-
subscribe(type, observerOrNext, error, complete) {
|
|
1351
|
-
return this.emitter.subscribe(type, observerOrNext, error, complete);
|
|
1352
|
-
}
|
|
1353
|
-
toObservable() {
|
|
1354
|
-
return this.emitter.toObservable();
|
|
1355
|
-
}
|
|
1356
|
-
events(type, options) {
|
|
1357
|
-
return this.emitter.events(type, options);
|
|
1358
|
-
}
|
|
1359
|
-
complete() {
|
|
1360
|
-
this.emitter.complete();
|
|
1361
|
-
}
|
|
1362
|
-
get completed() {
|
|
1363
|
-
return this.emitter.completed;
|
|
1364
|
-
}
|
|
1365
|
-
getSnapshot() {
|
|
1366
|
-
return this.current;
|
|
1367
|
-
}
|
|
1368
|
-
get current() {
|
|
1369
|
-
return this.currentNode.conversation;
|
|
1370
|
-
}
|
|
1371
|
-
get ids() {
|
|
1372
|
-
return getMessageIds(this.current);
|
|
1373
|
-
}
|
|
1374
|
-
get canUndo() {
|
|
1375
|
-
return this.currentNode.parent !== null;
|
|
1376
|
-
}
|
|
1377
|
-
get canRedo() {
|
|
1378
|
-
return this.currentNode.children.length > 0;
|
|
1379
|
-
}
|
|
1380
|
-
get env() {
|
|
1381
|
-
return this.environment;
|
|
1382
|
-
}
|
|
1383
|
-
get branchCount() {
|
|
1384
|
-
return this.currentNode.parent ? this.currentNode.parent.children.length : 1;
|
|
1385
|
-
}
|
|
1386
|
-
get branchIndex() {
|
|
1387
|
-
if (!this.currentNode.parent)
|
|
1388
|
-
return 0;
|
|
1389
|
-
return this.currentNode.parent.children.indexOf(this.currentNode);
|
|
1390
|
-
}
|
|
1391
|
-
get redoCount() {
|
|
1392
|
-
return this.currentNode.children.length;
|
|
1393
|
-
}
|
|
1394
|
-
createChangeContext(previousConversation, nextConversation, action) {
|
|
1395
|
-
const diff = diffConversationMessages(previousConversation, nextConversation);
|
|
1396
|
-
const messageIds = action === "messages.appended" ? diff.appended : action === "messages.updated" ? diff.updated : diff.removed;
|
|
1397
|
-
const toolCallIds = collectToolCallIds(action === "messages.removed" ? previousConversation : nextConversation, messageIds);
|
|
1398
|
-
return {
|
|
1399
|
-
...messageIds.length > 0 ? { messageIds } : {},
|
|
1400
|
-
...toolCallIds ? { toolCallIds } : {}
|
|
1401
|
-
};
|
|
1402
|
-
}
|
|
1403
|
-
pushWithEvents(next, changeAction, context) {
|
|
1404
|
-
this.commit(next, changeAction, ["push", changeAction], context);
|
|
1405
|
-
}
|
|
1406
|
-
push(next) {
|
|
1407
|
-
this.commit(next, "push", ["push"]);
|
|
1408
|
-
}
|
|
1409
|
-
undo() {
|
|
1410
|
-
if (this.currentNode.parent) {
|
|
1411
|
-
const previousConversation = this.current;
|
|
1412
|
-
this.currentNode = this.currentNode.parent;
|
|
1413
|
-
this.emitConversationEvent("change", this.buildEventDetail("undo", previousConversation));
|
|
1414
|
-
this.emitConversationEvent("undo", this.buildEventDetail("undo", previousConversation));
|
|
1415
|
-
return this.current;
|
|
1416
|
-
}
|
|
1417
|
-
}
|
|
1418
|
-
redo(childIndex = 0) {
|
|
1419
|
-
const next = this.currentNode.children[childIndex];
|
|
1420
|
-
if (next) {
|
|
1421
|
-
const previousConversation = this.current;
|
|
1422
|
-
this.currentNode = next;
|
|
1423
|
-
this.emitConversationEvent("change", this.buildEventDetail("redo", previousConversation));
|
|
1424
|
-
this.emitConversationEvent("redo", this.buildEventDetail("redo", previousConversation));
|
|
1425
|
-
return this.current;
|
|
1426
|
-
}
|
|
1427
|
-
}
|
|
1428
|
-
switchToBranch(index) {
|
|
1429
|
-
if (this.currentNode.parent) {
|
|
1430
|
-
const target = this.currentNode.parent.children[index];
|
|
1431
|
-
if (target) {
|
|
1432
|
-
const previousConversation = this.current;
|
|
1433
|
-
this.currentNode = target;
|
|
1434
|
-
this.emitConversationEvent("change", this.buildEventDetail("switch", previousConversation));
|
|
1435
|
-
this.emitConversationEvent("switch", this.buildEventDetail("switch", previousConversation));
|
|
1436
|
-
return this.current;
|
|
1437
|
-
}
|
|
1438
|
-
}
|
|
1439
|
-
}
|
|
1440
|
-
fork(messageId) {
|
|
1441
|
-
const previous = this.current;
|
|
1442
|
-
const cloned = JSON.parse(JSON.stringify(this.current));
|
|
1443
|
-
let forkedHistory;
|
|
1444
|
-
if (messageId) {
|
|
1445
|
-
const messageIndex = cloned.ids.indexOf(messageId);
|
|
1446
|
-
if (messageIndex === -1)
|
|
1447
|
-
throw new Error(`Message with id "${messageId}" not found`);
|
|
1448
|
-
const truncatedIds = cloned.ids.slice(0, messageIndex + 1);
|
|
1449
|
-
const truncatedMessages = {};
|
|
1450
|
-
for (const id of truncatedIds) {
|
|
1451
|
-
const message = cloned.messages[id];
|
|
1452
|
-
if (message)
|
|
1453
|
-
truncatedMessages[id] = message;
|
|
1454
|
-
}
|
|
1455
|
-
forkedHistory = {
|
|
1456
|
-
...cloned,
|
|
1457
|
-
id: this.environment.randomId(),
|
|
1458
|
-
ids: truncatedIds,
|
|
1459
|
-
messages: truncatedMessages,
|
|
1460
|
-
updatedAt: this.environment.now()
|
|
1461
|
-
};
|
|
1462
|
-
} else
|
|
1463
|
-
forkedHistory = {
|
|
1464
|
-
...cloned,
|
|
1465
|
-
id: this.environment.randomId(),
|
|
1466
|
-
updatedAt: this.environment.now()
|
|
1467
|
-
};
|
|
1468
|
-
const detail = this.buildEventDetail("session.forked", previous);
|
|
1469
|
-
this.emitConversationEvent("session.forked", detail);
|
|
1470
|
-
this.emitConversationEvent("change", detail);
|
|
1471
|
-
return new Conversation2(forkedHistory, this.environment);
|
|
1472
|
-
}
|
|
1473
|
-
tag(label) {
|
|
1474
|
-
const previous = this.current;
|
|
1475
|
-
const existingTags = previous.metadata["_tags"] ?? [];
|
|
1476
|
-
if (existingTags.includes(label))
|
|
1477
|
-
return;
|
|
1478
|
-
const next = {
|
|
1479
|
-
...previous,
|
|
1480
|
-
metadata: {
|
|
1481
|
-
...previous.metadata,
|
|
1482
|
-
_tags: [...existingTags, label]
|
|
1483
|
-
},
|
|
1484
|
-
updatedAt: this.environment.now()
|
|
1485
|
-
};
|
|
1486
|
-
this.commit(next, "session.tagged", ["push", "session.tagged"]);
|
|
1487
|
-
}
|
|
1488
|
-
rename(title) {
|
|
1489
|
-
const previous = this.current;
|
|
1490
|
-
if (previous.title === title)
|
|
1491
|
-
return;
|
|
1492
|
-
const next = {
|
|
1493
|
-
...previous,
|
|
1494
|
-
title,
|
|
1495
|
-
updatedAt: this.environment.now()
|
|
1496
|
-
};
|
|
1497
|
-
this.commit(next, "session.renamed", ["push", "session.renamed"]);
|
|
1498
|
-
}
|
|
1499
|
-
getPath() {
|
|
1500
|
-
const path = [];
|
|
1501
|
-
let curr = this.currentNode;
|
|
1502
|
-
while (curr) {
|
|
1503
|
-
path.unshift(curr.conversation);
|
|
1504
|
-
curr = curr.parent;
|
|
1505
|
-
}
|
|
1506
|
-
return path;
|
|
1507
|
-
}
|
|
1508
|
-
getMessages(options) {
|
|
1509
|
-
return getMessages(this.current, options);
|
|
1510
|
-
}
|
|
1511
|
-
getMessageAtPosition(position) {
|
|
1512
|
-
return getMessageAtPosition(this.current, position);
|
|
1513
|
-
}
|
|
1514
|
-
getMessageIds() {
|
|
1515
|
-
return getMessageIds(this.current);
|
|
1516
|
-
}
|
|
1517
|
-
getMessageById(id) {
|
|
1518
|
-
return getMessageById(this.current, id);
|
|
1519
|
-
}
|
|
1520
|
-
get(id) {
|
|
1521
|
-
return getMessageById(this.current, id);
|
|
1522
|
-
}
|
|
1523
|
-
searchMessages(predicate) {
|
|
1524
|
-
return searchConversationMessages(this.current, predicate);
|
|
1525
|
-
}
|
|
1526
|
-
getStatistics() {
|
|
1527
|
-
return getStatistics(this.current);
|
|
1528
|
-
}
|
|
1529
|
-
hasSystemMessage() {
|
|
1530
|
-
return hasSystemMessage(this.current);
|
|
1531
|
-
}
|
|
1532
|
-
getFirstSystemMessage() {
|
|
1533
|
-
return getFirstSystemMessage(this.current);
|
|
1534
|
-
}
|
|
1535
|
-
getSystemMessages() {
|
|
1536
|
-
return getSystemMessages(this.current);
|
|
1537
|
-
}
|
|
1538
|
-
toChatMessages() {
|
|
1539
|
-
return toChatMessages(this.current);
|
|
1540
|
-
}
|
|
1541
|
-
estimateTokens(estimator) {
|
|
1542
|
-
return estimateConversationTokens(this.current, estimator, this.env);
|
|
1543
|
-
}
|
|
1544
|
-
getRecentMessages(count, options) {
|
|
1545
|
-
return getRecentMessages(this.current, count, options);
|
|
1546
|
-
}
|
|
1547
|
-
getStreamingMessage() {
|
|
1548
|
-
return getStreamingMessage(this.current);
|
|
1549
|
-
}
|
|
1550
|
-
appendMessages(...inputs) {
|
|
1551
|
-
const previousConversation = this.current;
|
|
1552
|
-
const nextConversation = appendMessages(this.current, ...inputs, this.env);
|
|
1553
|
-
this.pushWithEvents(nextConversation, "messages.appended", this.createChangeContext(previousConversation, nextConversation, "messages.appended"));
|
|
1554
|
-
}
|
|
1555
|
-
appendUserMessage(content, metadata) {
|
|
1556
|
-
const previousConversation = this.current;
|
|
1557
|
-
const nextConversation = appendUserMessage(this.current, content, metadata, this.env);
|
|
1558
|
-
this.pushWithEvents(nextConversation, "messages.appended", this.createChangeContext(previousConversation, nextConversation, "messages.appended"));
|
|
1559
|
-
}
|
|
1560
|
-
appendAssistantMessage(content, metadata) {
|
|
1561
|
-
const previousConversation = this.current;
|
|
1562
|
-
const nextConversation = appendAssistantMessage(this.current, content, metadata, this.env);
|
|
1563
|
-
this.pushWithEvents(nextConversation, "messages.appended", this.createChangeContext(previousConversation, nextConversation, "messages.appended"));
|
|
1564
|
-
}
|
|
1565
|
-
appendSystemMessage(content, metadata) {
|
|
1566
|
-
const previousConversation = this.current;
|
|
1567
|
-
const nextConversation = appendSystemMessage(this.current, content, metadata, this.env);
|
|
1568
|
-
this.pushWithEvents(nextConversation, "messages.appended", this.createChangeContext(previousConversation, nextConversation, "messages.appended"));
|
|
1569
|
-
}
|
|
1570
|
-
prependSystemMessage(content, metadata) {
|
|
1571
|
-
const previousConversation = this.current;
|
|
1572
|
-
const nextConversation = prependSystemMessage(this.current, content, metadata, this.env);
|
|
1573
|
-
this.pushWithEvents(nextConversation, "messages.appended", this.createChangeContext(previousConversation, nextConversation, "messages.appended"));
|
|
1574
|
-
}
|
|
1575
|
-
replaceSystemMessage(content, metadata) {
|
|
1576
|
-
const previousConversation = this.current;
|
|
1577
|
-
const nextConversation = replaceSystemMessage(this.current, content, metadata, this.env);
|
|
1578
|
-
this.pushWithEvents(nextConversation, "messages.updated", this.createChangeContext(previousConversation, nextConversation, "messages.updated"));
|
|
1579
|
-
}
|
|
1580
|
-
collapseSystemMessages() {
|
|
1581
|
-
const previousConversation = this.current;
|
|
1582
|
-
const nextConversation = collapseSystemMessages(this.current, this.env);
|
|
1583
|
-
const action = previousConversation.ids.length === nextConversation.ids.length ? "messages.updated" : "messages.removed";
|
|
1584
|
-
this.pushWithEvents(nextConversation, action, this.createChangeContext(previousConversation, nextConversation, action));
|
|
1585
|
-
}
|
|
1586
|
-
redactMessageAtPosition(position, placeholderOrOptions) {
|
|
1587
|
-
const previousConversation = this.current;
|
|
1588
|
-
const nextConversation = redactMessageAtPosition(this.current, position, placeholderOrOptions, this.env);
|
|
1589
|
-
this.pushWithEvents(nextConversation, "messages.updated", this.createChangeContext(previousConversation, nextConversation, "messages.updated"));
|
|
1590
|
-
}
|
|
1591
|
-
truncateFromPosition(position, options) {
|
|
1592
|
-
const previousConversation = this.current;
|
|
1593
|
-
const nextConversation = truncateFromPosition(this.current, position, options, this.env);
|
|
1594
|
-
this.pushWithEvents(nextConversation, "messages.removed", this.createChangeContext(previousConversation, nextConversation, "messages.removed"));
|
|
1595
|
-
}
|
|
1596
|
-
truncateToTokenLimit(maxTokens, options) {
|
|
1597
|
-
const previousConversation = this.current;
|
|
1598
|
-
const nextConversation = truncateToTokenLimit(this.current, maxTokens, options, this.env);
|
|
1599
|
-
this.pushWithEvents(nextConversation, "messages.removed", this.createChangeContext(previousConversation, nextConversation, "messages.removed"));
|
|
1600
|
-
}
|
|
1601
|
-
async compact(summarizer, options) {
|
|
1602
|
-
const previous = this.current;
|
|
1603
|
-
this.emitConversationEvent("compaction.started", this.buildEventDetail("compaction.started", previous));
|
|
1604
|
-
const { conversation, result } = await compactConversation(this.current, summarizer, options, this.env);
|
|
1605
|
-
if (result.compacted)
|
|
1606
|
-
this.pushWithEvents(conversation, "compaction.completed", this.createChangeContext(previous, conversation, "messages.removed"));
|
|
1607
|
-
else
|
|
1608
|
-
this.emitConversationEvent("compaction.completed", this.buildEventDetail("compaction.completed", previous));
|
|
1609
|
-
return result;
|
|
1610
|
-
}
|
|
1611
|
-
appendStreamingMessage(role, metadata) {
|
|
1612
|
-
const { conversation, messageId } = appendStreamingMessage(this.current, role, metadata, this.env);
|
|
1613
|
-
this.commit(conversation, "stream.started", [
|
|
1614
|
-
"push",
|
|
1615
|
-
"messages.appended",
|
|
1616
|
-
"stream.started"
|
|
1617
|
-
], { messageIds: [messageId] });
|
|
1618
|
-
return messageId;
|
|
1619
|
-
}
|
|
1620
|
-
updateStreamingMessage(messageId, content) {
|
|
1621
|
-
const nextConversation = updateStreamingMessage(this.current, messageId, content, this.env);
|
|
1622
|
-
this.commit(nextConversation, "stream.updated", [
|
|
1623
|
-
"push",
|
|
1624
|
-
"messages.updated",
|
|
1625
|
-
"stream.updated"
|
|
1626
|
-
], { messageIds: [messageId] });
|
|
1627
|
-
}
|
|
1628
|
-
finalizeStreamingMessage(messageId, options) {
|
|
1629
|
-
const nextConversation = finalizeStreamingMessage(this.current, messageId, options, this.env);
|
|
1630
|
-
this.commit(nextConversation, "stream.finalized", [
|
|
1631
|
-
"push",
|
|
1632
|
-
"messages.updated",
|
|
1633
|
-
"stream.finalized"
|
|
1634
|
-
], { messageIds: [messageId] });
|
|
1635
|
-
}
|
|
1636
|
-
cancelStreamingMessage(messageId) {
|
|
1637
|
-
const nextConversation = cancelStreamingMessage(this.current, messageId, this.env);
|
|
1638
|
-
this.commit(nextConversation, "stream.cancelled", [
|
|
1639
|
-
"push",
|
|
1640
|
-
"messages.removed",
|
|
1641
|
-
"stream.cancelled"
|
|
1642
|
-
], { messageIds: [messageId] });
|
|
1643
|
-
}
|
|
1644
|
-
appendToolCall(toolCall, options) {
|
|
1645
|
-
const nextConversation = appendToolCall(this.current, toolCall, options, this.env);
|
|
1646
|
-
const context = this.createChangeContext(this.current, nextConversation, "messages.appended");
|
|
1647
|
-
this.commit(nextConversation, "tool-calls.appended", [
|
|
1648
|
-
"push",
|
|
1649
|
-
"messages.appended",
|
|
1650
|
-
"tool-calls.appended"
|
|
1651
|
-
], context);
|
|
1652
|
-
}
|
|
1653
|
-
appendToolCalls(toolCalls) {
|
|
1654
|
-
const nextConversation = appendToolCalls(this.current, toolCalls, this.env);
|
|
1655
|
-
if (nextConversation === this.current)
|
|
1656
|
-
return;
|
|
1657
|
-
const context = this.createChangeContext(this.current, nextConversation, "messages.appended");
|
|
1658
|
-
this.commit(nextConversation, "tool-calls.appended", [
|
|
1659
|
-
"push",
|
|
1660
|
-
"messages.appended",
|
|
1661
|
-
"tool-calls.appended"
|
|
1662
|
-
], context);
|
|
1663
|
-
}
|
|
1664
|
-
appendToolResult(toolResult, options) {
|
|
1665
|
-
const nextConversation = appendToolResult(this.current, toolResult, options, this.env);
|
|
1666
|
-
const context = this.createChangeContext(this.current, nextConversation, "messages.appended");
|
|
1667
|
-
this.commit(nextConversation, "tool-results.appended", [
|
|
1668
|
-
"push",
|
|
1669
|
-
"messages.appended",
|
|
1670
|
-
"tool-results.appended"
|
|
1671
|
-
], context);
|
|
1672
|
-
}
|
|
1673
|
-
appendToolResults(toolResults) {
|
|
1674
|
-
const nextConversation = appendToolResults(this.current, toolResults, this.env);
|
|
1675
|
-
if (nextConversation === this.current)
|
|
1676
|
-
return;
|
|
1677
|
-
const context = this.createChangeContext(this.current, nextConversation, "messages.appended");
|
|
1678
|
-
this.commit(nextConversation, "tool-results.appended", [
|
|
1679
|
-
"push",
|
|
1680
|
-
"messages.appended",
|
|
1681
|
-
"tool-results.appended"
|
|
1682
|
-
], context);
|
|
1683
|
-
}
|
|
1684
|
-
async appendToolResultAsync(toolResult, options) {
|
|
1685
|
-
const nextConversation = await appendToolResultAsync(this.current, toolResult, options, this.env);
|
|
1686
|
-
const context = this.createChangeContext(this.current, nextConversation, "messages.appended");
|
|
1687
|
-
this.commit(nextConversation, "tool-results.appended", [
|
|
1688
|
-
"push",
|
|
1689
|
-
"messages.appended",
|
|
1690
|
-
"tool-results.appended"
|
|
1691
|
-
], context);
|
|
1692
|
-
}
|
|
1693
|
-
async appendToolResultsAsync(toolResults) {
|
|
1694
|
-
const nextConversation = await appendToolResultsAsync(this.current, toolResults, this.env);
|
|
1695
|
-
if (nextConversation === this.current)
|
|
1696
|
-
return;
|
|
1697
|
-
const context = this.createChangeContext(this.current, nextConversation, "messages.appended");
|
|
1698
|
-
this.commit(nextConversation, "tool-results.appended", [
|
|
1699
|
-
"push",
|
|
1700
|
-
"messages.appended",
|
|
1701
|
-
"tool-results.appended"
|
|
1702
|
-
], context);
|
|
1703
|
-
}
|
|
1704
|
-
getPendingToolCalls() {
|
|
1705
|
-
return getPendingToolCalls(this.current);
|
|
1706
|
-
}
|
|
1707
|
-
getToolInteractions() {
|
|
1708
|
-
return getToolInteractions(this.current);
|
|
1709
|
-
}
|
|
1710
|
-
static async fromProvider(provider, payload, environment) {
|
|
1711
|
-
return new Conversation2((await loadConversationAdapter(provider)).import(payload), environment);
|
|
1712
|
-
}
|
|
1713
|
-
async toProvider(provider, options) {
|
|
1714
|
-
return (await loadConversationAdapter(provider)).export(this.current, options);
|
|
1715
|
-
}
|
|
1716
|
-
async appendProvider(provider, payload) {
|
|
1717
|
-
const nextConversation = (await loadConversationAdapter(provider)).append(this.current, payload);
|
|
1718
|
-
if (nextConversation === this.current)
|
|
1719
|
-
return;
|
|
1720
|
-
const diff = diffConversationMessages(this.current, nextConversation);
|
|
1721
|
-
const appendedIds = diff.appended;
|
|
1722
|
-
const updatedIds = diff.updated;
|
|
1723
|
-
const removedIds = diff.removed;
|
|
1724
|
-
const action = removedIds.length > 0 ? "messages.removed" : updatedIds.length > 0 ? "messages.updated" : "messages.appended";
|
|
1725
|
-
const messageIds = action === "messages.removed" ? removedIds : action === "messages.updated" ? updatedIds : appendedIds;
|
|
1726
|
-
const toolCallIds = collectToolCallIds(nextConversation, messageIds);
|
|
1727
|
-
this.commit(nextConversation, action, ["push", action], {
|
|
1728
|
-
...messageIds.length > 0 ? { messageIds } : {},
|
|
1729
|
-
...toolCallIds ? { toolCallIds } : {}
|
|
1730
|
-
});
|
|
1731
|
-
}
|
|
1732
|
-
snapshot() {
|
|
1733
|
-
const getPath = (node) => {
|
|
1734
|
-
const path = [];
|
|
1735
|
-
let curr = node;
|
|
1736
|
-
while (curr.parent) {
|
|
1737
|
-
path.unshift(curr.parent.children.indexOf(curr));
|
|
1738
|
-
curr = curr.parent;
|
|
1739
|
-
}
|
|
1740
|
-
return path;
|
|
1741
|
-
};
|
|
1742
|
-
const serializeNode = (node) => ({
|
|
1743
|
-
conversation: node.conversation,
|
|
1744
|
-
children: node.children.map(serializeNode)
|
|
1745
|
-
});
|
|
1746
|
-
let root = this.currentNode;
|
|
1747
|
-
while (root.parent)
|
|
1748
|
-
root = root.parent;
|
|
1749
|
-
return {
|
|
1750
|
-
root: serializeNode(root),
|
|
1751
|
-
currentPath: getPath(this.currentNode)
|
|
1752
|
-
};
|
|
1753
|
-
}
|
|
1754
|
-
static from(json, environment) {
|
|
1755
|
-
const conversation = new Conversation2(deserializeConversationHistory(json.root.conversation), environment);
|
|
1756
|
-
const buildTree = (nodeJSON, parentNode) => {
|
|
1757
|
-
const node = {
|
|
1758
|
-
conversation: deserializeConversationHistory(nodeJSON.conversation),
|
|
1759
|
-
parent: parentNode,
|
|
1760
|
-
children: []
|
|
1761
|
-
};
|
|
1762
|
-
node.children = nodeJSON.children.map((child) => buildTree(child, node));
|
|
1763
|
-
return node;
|
|
1764
|
-
};
|
|
1765
|
-
const rootNode = conversation.currentNode;
|
|
1766
|
-
rootNode.children = json.root.children.map((child) => buildTree(child, rootNode));
|
|
1767
|
-
let current = rootNode;
|
|
1768
|
-
for (const index of json.currentPath) {
|
|
1769
|
-
const target = current.children[index];
|
|
1770
|
-
if (target)
|
|
1771
|
-
current = target;
|
|
1772
|
-
}
|
|
1773
|
-
conversation.currentNode = current;
|
|
1774
|
-
return conversation;
|
|
1775
|
-
}
|
|
1776
|
-
static async fromOpenAIMessages(messages, environment) {
|
|
1777
|
-
return Conversation2.fromProvider("openai", [...messages], environment);
|
|
1778
|
-
}
|
|
1779
|
-
static async fromAnthropicMessages(payload, environment) {
|
|
1780
|
-
return Conversation2.fromProvider("anthropic", payload, environment);
|
|
1781
|
-
}
|
|
1782
|
-
static async fromGeminiMessages(payload, environment) {
|
|
1783
|
-
return Conversation2.fromProvider("gemini", payload, environment);
|
|
1784
|
-
}
|
|
1785
|
-
async toOpenAIMessages() {
|
|
1786
|
-
return this.toProvider("openai", { groupToolCalls: false });
|
|
1787
|
-
}
|
|
1788
|
-
async toOpenAIMessagesGrouped() {
|
|
1789
|
-
return this.toProvider("openai", { groupToolCalls: true });
|
|
1790
|
-
}
|
|
1791
|
-
async toAnthropicMessages() {
|
|
1792
|
-
return this.toProvider("anthropic");
|
|
1793
|
-
}
|
|
1794
|
-
async toGeminiMessages() {
|
|
1795
|
-
return this.toProvider("gemini");
|
|
1796
|
-
}
|
|
1797
|
-
bind(fn) {
|
|
1798
|
-
return (...args) => {
|
|
1799
|
-
const result = fn(this.current, ...args, this.env);
|
|
1800
|
-
if (isConversationHistory(result))
|
|
1801
|
-
this.push(result);
|
|
1802
|
-
return result;
|
|
1803
|
-
};
|
|
1804
|
-
}
|
|
1805
|
-
[Symbol.dispose]() {
|
|
1806
|
-
this.complete();
|
|
1807
|
-
let root = this.currentNode;
|
|
1808
|
-
while (root?.parent)
|
|
1809
|
-
root = root.parent;
|
|
1810
|
-
const clearNode = (node) => {
|
|
1811
|
-
for (const child of node.children)
|
|
1812
|
-
clearNode(child);
|
|
1813
|
-
node.children = [];
|
|
1814
|
-
const n = node;
|
|
1815
|
-
n.parent = null;
|
|
1816
|
-
n.conversation = null;
|
|
1817
|
-
};
|
|
1818
|
-
if (root)
|
|
1819
|
-
clearNode(root);
|
|
1820
|
-
}
|
|
1821
|
-
};
|
|
1822
|
-
function isConversationHistory(value) {
|
|
1823
|
-
return value !== null && typeof value === "object" && typeof value.schemaVersion === "number" && typeof value.id === "string" && typeof value.status === "string" && value.metadata !== null && typeof value.metadata === "object" && Array.isArray(value.ids) && typeof value.messages === "object" && value.messages !== null && !Array.isArray(value.messages) && typeof value.createdAt === "string" && typeof value.updatedAt === "string";
|
|
1824
|
-
}
|
|
1825
|
-
|
|
1826
|
-
// src/components/chat/utilities/conversation.ts
|
|
1827
|
-
function hasPairableToolField(message) {
|
|
1828
|
-
return message.role === "tool-call" && message.toolCall !== undefined || message.role === "tool-result" && message.toolResult !== undefined;
|
|
1829
|
-
}
|
|
1830
|
-
function pairToolCallsWithResults2(messages) {
|
|
1831
|
-
return pairToolCallsWithResults(messages.filter(hasPairableToolField));
|
|
1832
|
-
}
|
|
1833
|
-
export { pairToolCallsWithResults2 as pairToolCallsWithResults, resolveMessageReasoning, resolveMessageSteps, resolveMessageSuggestions, getMessageText, deriveMessageParts, getMessageRoleLabel, formatMessageAsMarkdown, messagesToMarkdown };
|
|
1834
|
-
|
|
1835
|
-
//# debugId=881E2782584A045764756E2164756E21
|