@ai-matrx/agents 0.10.6 → 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 +20 -0
- package/dist/content-transfer/index.cjs +1422 -0
- package/dist/content-transfer/index.cjs.map +1 -0
- package/dist/content-transfer/index.d.cts +84 -0
- package/dist/content-transfer/index.d.ts +84 -0
- package/dist/content-transfer/index.js +1404 -0
- package/dist/content-transfer/index.js.map +1 -0
- package/dist/content-transfer/react/index.cjs +1564 -0
- package/dist/content-transfer/react/index.cjs.map +1 -0
- package/dist/content-transfer/react/index.d.cts +63 -0
- package/dist/content-transfer/react/index.d.ts +63 -0
- package/dist/content-transfer/react/index.js +1539 -0
- package/dist/content-transfer/react/index.js.map +1 -0
- package/dist/index.cjs +23 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -1
- package/dist/mandates/index.cjs +8 -2
- package/dist/mandates/index.cjs.map +1 -1
- package/dist/mandates/index.d.cts +11 -5
- package/dist/mandates/index.d.ts +11 -5
- package/dist/mandates/index.js +8 -2
- package/dist/mandates/index.js.map +1 -1
- package/dist/matrx/index.cjs +23 -0
- package/dist/matrx/index.cjs.map +1 -1
- package/dist/matrx/index.d.cts +13 -646
- package/dist/matrx/index.d.ts +13 -646
- package/dist/matrx/index.js +23 -0
- package/dist/matrx/index.js.map +1 -1
- package/dist/operations--f5ko9Su.d.cts +659 -0
- package/dist/operations-BT5kKMHl.d.cts +203 -0
- package/dist/operations-BT5kKMHl.d.ts +203 -0
- package/dist/operations-Dp4ut-ac.d.ts +659 -0
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +44 -244
- package/dist/react/index.d.ts +44 -244
- package/dist/react/index.js.map +1 -1
- package/mandates/snapshots/keys.0.10.6.json +2 -1
- package/mandates/snapshots/keys.0.10.7.json +470 -0
- package/mandates/snapshots/keys.0.11.0.json +475 -0
- package/package.json +24 -3
|
@@ -0,0 +1,1404 @@
|
|
|
1
|
+
// content-transfer/index.ts
|
|
2
|
+
import {
|
|
3
|
+
editDraft,
|
|
4
|
+
serialize
|
|
5
|
+
} from "@ai-matrx/kit/content-transfer";
|
|
6
|
+
|
|
7
|
+
// mandates/keys.generated.ts
|
|
8
|
+
var MANDATE_KEYS = {
|
|
9
|
+
agent_apps__auto_create: "agent_apps.auto_create",
|
|
10
|
+
agent_apps__auto_create_lightning: "agent_apps.auto_create_lightning",
|
|
11
|
+
agent_apps__metadata: "agent_apps.metadata",
|
|
12
|
+
agent_apps__prompt_app_dev: "agent_apps.prompt_app_dev",
|
|
13
|
+
agent_factory__structure_builder: "agent_factory.structure_builder",
|
|
14
|
+
alchemy__prepare_content: "alchemy.prepare_content",
|
|
15
|
+
ambient__page_guidance: "ambient.page_guidance",
|
|
16
|
+
ambient__spoken_summary: "ambient.spoken_summary",
|
|
17
|
+
chat__cx_default: "chat.cx_default",
|
|
18
|
+
chat__default_new_chat: "chat.default_new_chat",
|
|
19
|
+
chat__quick_audio_plan: "chat.quick_audio_plan",
|
|
20
|
+
chat__quick_fair_news: "chat.quick_fair_news",
|
|
21
|
+
chat__quick_flashcards: "chat.quick_flashcards",
|
|
22
|
+
chat__quick_image: "chat.quick_image",
|
|
23
|
+
chat__quick_org_chart: "chat.quick_org_chart",
|
|
24
|
+
chat__quick_research: "chat.quick_research",
|
|
25
|
+
chat__quick_showcase: "chat.quick_showcase",
|
|
26
|
+
chat__quick_writing_partner: "chat.quick_writing_partner",
|
|
27
|
+
chat__response_mode_brainstorm: "chat.response_mode_brainstorm",
|
|
28
|
+
chat__response_mode_data: "chat.response_mode_data",
|
|
29
|
+
chat__response_mode_research: "chat.response_mode_research",
|
|
30
|
+
chat__response_mode_video: "chat.response_mode_video",
|
|
31
|
+
code_editor__code_edit: "code_editor.code_edit",
|
|
32
|
+
code_editor__dynamic_context_edit: "code_editor.dynamic_context_edit",
|
|
33
|
+
code_editor__prompt_app_ui_edit: "code_editor.prompt_app_ui_edit",
|
|
34
|
+
coding_session__managed_translation_reference: "coding_session.managed_translation_reference",
|
|
35
|
+
commerce_intake__assess_value: "commerce_intake.assess_value",
|
|
36
|
+
commerce_intake__extract_vision: "commerce_intake.extract_vision",
|
|
37
|
+
commerce_intake__grading: "commerce_intake.grading",
|
|
38
|
+
commerce_intake__instant_analysis: "commerce_intake.instant_analysis",
|
|
39
|
+
commerce_intake__refute_no_value: "commerce_intake.refute_no_value",
|
|
40
|
+
commerce_intake__research_product: "commerce_intake.research_product",
|
|
41
|
+
commerce_intake__segment_photos: "commerce_intake.segment_photos",
|
|
42
|
+
commerce_intake__verify_enrichment: "commerce_intake.verify_enrichment",
|
|
43
|
+
content_ir__component_artisan: "content_ir.component_artisan",
|
|
44
|
+
content_ir__kind_architect: "content_ir.kind_architect",
|
|
45
|
+
content_ir__kind_component_builder: "content_ir.kind_component_builder",
|
|
46
|
+
content_ir__kind_creator: "content_ir.kind_creator",
|
|
47
|
+
content_plan__brief_writer: "content_plan.brief_writer",
|
|
48
|
+
content_plan__entity_attacher: "content_plan.entity_attacher",
|
|
49
|
+
content_plan__entity_curator: "content_plan.entity_curator",
|
|
50
|
+
content_plan__family_namer: "content_plan.family_namer",
|
|
51
|
+
content_plan__keyword_strategist: "content_plan.keyword_strategist",
|
|
52
|
+
content_plan__p3_family: "content_plan.p3_family",
|
|
53
|
+
content_plan__p4_write: "content_plan.p4_write",
|
|
54
|
+
content_plan__p5_review: "content_plan.p5_review",
|
|
55
|
+
content_plan__p6_build: "content_plan.p6_build",
|
|
56
|
+
content_plan__p6_build__about: "content_plan.p6_build.about",
|
|
57
|
+
content_plan__p6_build__blog: "content_plan.p6_build.blog",
|
|
58
|
+
content_plan__p6_build__comparison: "content_plan.p6_build.comparison",
|
|
59
|
+
content_plan__p6_build__contact: "content_plan.p6_build.contact",
|
|
60
|
+
content_plan__p6_build__faq: "content_plan.p6_build.faq",
|
|
61
|
+
content_plan__p6_build__guide: "content_plan.p6_build.guide",
|
|
62
|
+
content_plan__p6_build__home: "content_plan.p6_build.home",
|
|
63
|
+
content_plan__p6_build__index: "content_plan.p6_build.index",
|
|
64
|
+
content_plan__p6_build__location: "content_plan.p6_build.location",
|
|
65
|
+
content_plan__p6_build__pillar: "content_plan.p6_build.pillar",
|
|
66
|
+
content_plan__p6_build__pricing: "content_plan.p6_build.pricing",
|
|
67
|
+
content_plan__p6_build__service: "content_plan.p6_build.service",
|
|
68
|
+
content_plan__plan_reviewer: "content_plan.plan_reviewer",
|
|
69
|
+
content_plan__route_picker: "content_plan.route_picker",
|
|
70
|
+
content_plan__shape_planner: "content_plan.shape_planner",
|
|
71
|
+
conversation__action_auditor: "conversation.action_auditor",
|
|
72
|
+
conversation__decision_ledger: "conversation.decision_ledger",
|
|
73
|
+
conversation__drift_auditor: "conversation.drift_auditor",
|
|
74
|
+
conversation__outcome_summarizer: "conversation.outcome_summarizer",
|
|
75
|
+
conversation__vision_extractor: "conversation.vision_extractor",
|
|
76
|
+
conversation__vision_interviewer: "conversation.vision_interviewer",
|
|
77
|
+
crm__journalist_beat_analyst: "crm.journalist_beat_analyst",
|
|
78
|
+
crm__media_list_ranker: "crm.media_list_ranker",
|
|
79
|
+
crm__outreach_draft_reviewer: "crm.outreach_draft_reviewer",
|
|
80
|
+
crm__outreach_personalization_coach: "crm.outreach_personalization_coach",
|
|
81
|
+
crm__outreach_personalization_writer: "crm.outreach_personalization_writer",
|
|
82
|
+
crm__outreach_pitch_writer: "crm.outreach_pitch_writer",
|
|
83
|
+
crm__outreach_recipient_shortlister: "crm.outreach_recipient_shortlister",
|
|
84
|
+
crm__outreach_reply_drafter: "crm.outreach_reply_drafter",
|
|
85
|
+
crm__party_kind_judge: "crm.party_kind_judge",
|
|
86
|
+
crm__save_contact: "crm.save_contact",
|
|
87
|
+
data__page_guidance: "data.page_guidance",
|
|
88
|
+
dictionary__workspace_guide: "dictionary.workspace_guide",
|
|
89
|
+
education__admin_guidance: "education.admin_guidance",
|
|
90
|
+
education__analytics_narrate: "education.analytics_narrate",
|
|
91
|
+
education__audio_study_guidance: "education.audio_study_guidance",
|
|
92
|
+
education__card_image_generator: "education.card_image_generator",
|
|
93
|
+
education__card_image_prompt_writer: "education.card_image_prompt_writer",
|
|
94
|
+
education__card_image_qc_judge: "education.card_image_qc_judge",
|
|
95
|
+
education__card_image_web_source: "education.card_image_web_source",
|
|
96
|
+
education__classes_guidance: "education.classes_guidance",
|
|
97
|
+
education__creator_guidance: "education.creator_guidance",
|
|
98
|
+
education__data_guidance: "education.data_guidance",
|
|
99
|
+
education__exam_prep_guidance: "education.exam_prep_guidance",
|
|
100
|
+
education__family_guidance: "education.family_guidance",
|
|
101
|
+
education__fastfire_guidance: "education.fastfire_guidance",
|
|
102
|
+
education__features_guidance: "education.features_guidance",
|
|
103
|
+
education__flashcards_guidance: "education.flashcards_guidance",
|
|
104
|
+
education__game_guidance: "education.game_guidance",
|
|
105
|
+
education__grade_handwritten: "education.grade_handwritten",
|
|
106
|
+
education__grade_work_guidance: "education.grade_work_guidance",
|
|
107
|
+
education__kit_title: "education.kit_title",
|
|
108
|
+
education__learn_guidance: "education.learn_guidance",
|
|
109
|
+
education__levels_guidance: "education.levels_guidance",
|
|
110
|
+
education__library_guidance: "education.library_guidance",
|
|
111
|
+
education__media_guidance: "education.media_guidance",
|
|
112
|
+
education__memory_generate: "education.memory_generate",
|
|
113
|
+
education__memory_guidance: "education.memory_guidance",
|
|
114
|
+
education__memory_hint: "education.memory_hint",
|
|
115
|
+
education__mind_maps_guidance: "education.mind_maps_guidance",
|
|
116
|
+
education__mindmap_generate: "education.mindmap_generate",
|
|
117
|
+
education__notes_generate: "education.notes_generate",
|
|
118
|
+
education__notes_guidance: "education.notes_guidance",
|
|
119
|
+
education__offline_guidance: "education.offline_guidance",
|
|
120
|
+
education__page_guidance: "education.page_guidance",
|
|
121
|
+
education__plan_generate: "education.plan_generate",
|
|
122
|
+
education__planner_guidance: "education.planner_guidance",
|
|
123
|
+
education__practice_oral_guidance: "education.practice_oral_guidance",
|
|
124
|
+
education__practice_tests_guidance: "education.practice_tests_guidance",
|
|
125
|
+
education__progress_guidance: "education.progress_guidance",
|
|
126
|
+
education__quiz_deepen_item: "education.quiz_deepen_item",
|
|
127
|
+
education__quiz_generate: "education.quiz_generate",
|
|
128
|
+
education__quiz_generate_from_source: "education.quiz_generate_from_source",
|
|
129
|
+
education__quizzes_guidance: "education.quizzes_guidance",
|
|
130
|
+
education__spoken_practice_design: "education.spoken_practice_design",
|
|
131
|
+
education__spoken_practice_design_language: "education.spoken_practice_design_language",
|
|
132
|
+
education__spoken_practice_grade: "education.spoken_practice_grade",
|
|
133
|
+
education__spoken_practice_grade_pronunciation: "education.spoken_practice_grade_pronunciation",
|
|
134
|
+
education__spoken_practice_review: "education.spoken_practice_review",
|
|
135
|
+
education__start_guidance: "education.start_guidance",
|
|
136
|
+
education__study_aids_guidance: "education.study_aids_guidance",
|
|
137
|
+
education__study_pack_flashcards: "education.study_pack_flashcards",
|
|
138
|
+
education__study_pack_lessons: "education.study_pack_lessons",
|
|
139
|
+
education__study_pack_notes: "education.study_pack_notes",
|
|
140
|
+
education__study_pack_quiz: "education.study_pack_quiz",
|
|
141
|
+
education__study_pack_v2_flashcards: "education.study_pack_v2_flashcards",
|
|
142
|
+
education__study_pack_v2_lessons: "education.study_pack_v2_lessons",
|
|
143
|
+
education__study_pack_v2_notes: "education.study_pack_v2_notes",
|
|
144
|
+
education__study_pack_v2_quiz: "education.study_pack_v2_quiz",
|
|
145
|
+
education__subjects_guidance: "education.subjects_guidance",
|
|
146
|
+
education__summaries_guidance: "education.summaries_guidance",
|
|
147
|
+
education__summarize: "education.summarize",
|
|
148
|
+
education__tutor_guidance: "education.tutor_guidance",
|
|
149
|
+
education__tutor_message: "education.tutor_message",
|
|
150
|
+
education__voice_tutor: "education.voice_tutor",
|
|
151
|
+
extend__browser_chat: "extend.browser_chat",
|
|
152
|
+
extend__pattern_from_data: "extend.pattern_from_data",
|
|
153
|
+
extend__structured_extractor: "extend.structured_extractor",
|
|
154
|
+
flashcards__enrich_card: "flashcards.enrich_card",
|
|
155
|
+
flashcards__expand_card: "flashcards.expand_card",
|
|
156
|
+
flashcards__generate_cards: "flashcards.generate_cards",
|
|
157
|
+
flashcards__generate_from_source: "flashcards.generate_from_source",
|
|
158
|
+
flashcards__grade_spoken: "flashcards.grade_spoken",
|
|
159
|
+
flashcards__grade_typed_answer: "flashcards.grade_typed_answer",
|
|
160
|
+
flashcards__help_live: "flashcards.help_live",
|
|
161
|
+
flashcards__helper_tts: "flashcards.helper_tts",
|
|
162
|
+
flashcards__make_quiz_items: "flashcards.make_quiz_items",
|
|
163
|
+
flashcards__micro_coach: "flashcards.micro_coach",
|
|
164
|
+
flashcards__review_batch: "flashcards.review_batch",
|
|
165
|
+
flashcards__spoken_front_tts: "flashcards.spoken_front_tts",
|
|
166
|
+
flashcards__verify_against_source: "flashcards.verify_against_source",
|
|
167
|
+
foundry__planner: "foundry.planner",
|
|
168
|
+
growth_loop__quality_analyze: "growth_loop.quality_analyze",
|
|
169
|
+
growth_loop__quality_brief: "growth_loop.quality_brief",
|
|
170
|
+
growth_loop__quality_crawl: "growth_loop.quality_crawl",
|
|
171
|
+
growth_loop__quality_fill: "growth_loop.quality_fill",
|
|
172
|
+
growth_loop__quality_measure: "growth_loop.quality_measure",
|
|
173
|
+
growth_loop__quality_plan: "growth_loop.quality_plan",
|
|
174
|
+
growth_loop__quality_publish: "growth_loop.quality_publish",
|
|
175
|
+
growth_loop__quality_realize: "growth_loop.quality_realize",
|
|
176
|
+
growth_loop__quality_research: "growth_loop.quality_research",
|
|
177
|
+
growth_loop__quality_serve: "growth_loop.quality_serve",
|
|
178
|
+
growth_loop__quality_suggest: "growth_loop.quality_suggest",
|
|
179
|
+
growth_loop__quality_writeback: "growth_loop.quality_writeback",
|
|
180
|
+
growth_loop__supervisor: "growth_loop.supervisor",
|
|
181
|
+
hindsight__crystallizer: "hindsight.crystallizer",
|
|
182
|
+
hindsight__replay_judge: "hindsight.replay_judge",
|
|
183
|
+
hindsight__reviewer: "hindsight.reviewer",
|
|
184
|
+
human_decisions__fallback_decider: "human_decisions.fallback_decider",
|
|
185
|
+
iteration__architect: "iteration.architect",
|
|
186
|
+
iteration__diagnostic: "iteration.diagnostic",
|
|
187
|
+
iteration__root_cause: "iteration.root_cause",
|
|
188
|
+
iteration__thinking_display: "iteration.thinking_display",
|
|
189
|
+
kg__cluster_namer: "kg.cluster_namer",
|
|
190
|
+
kg__ner_extractor: "kg.ner_extractor",
|
|
191
|
+
knowledge__document_verifier: "knowledge.document_verifier",
|
|
192
|
+
knowledge__qa_generator: "knowledge.qa_generator",
|
|
193
|
+
knowledge__section_summarizer: "knowledge.section_summarizer",
|
|
194
|
+
local__cloud_chat: "local.cloud_chat",
|
|
195
|
+
marketing__endowment_analysis: "marketing.endowment_analysis",
|
|
196
|
+
marketing__endowment_portfolio: "marketing.endowment_portfolio",
|
|
197
|
+
marketing__image_prompt: "marketing.image_prompt",
|
|
198
|
+
marketing__page_image: "marketing.page_image",
|
|
199
|
+
marketing__page_image_all_in_one: "marketing.page_image_all_in_one",
|
|
200
|
+
marketing__video_metadata: "marketing.video_metadata",
|
|
201
|
+
masterwork__approach_selector: "masterwork.approach_selector",
|
|
202
|
+
masterwork__audition_judge: "masterwork.audition_judge",
|
|
203
|
+
masterwork__bad_draft: "masterwork.bad_draft",
|
|
204
|
+
masterwork__checkup_auditor: "masterwork.checkup_auditor",
|
|
205
|
+
masterwork__coherence_partner: "masterwork.coherence_partner",
|
|
206
|
+
masterwork__conductor: "masterwork.conductor",
|
|
207
|
+
masterwork__corpus_cleaner: "masterwork.corpus_cleaner",
|
|
208
|
+
masterwork__corpus_synthesizer: "masterwork.corpus_synthesizer",
|
|
209
|
+
masterwork__draft_triage: "masterwork.draft_triage",
|
|
210
|
+
masterwork__exception_hunter: "masterwork.exception_hunter",
|
|
211
|
+
masterwork__exemplar_distiller: "masterwork.exemplar_distiller",
|
|
212
|
+
masterwork__intake_designer: "masterwork.intake_designer",
|
|
213
|
+
masterwork__monologue_distiller: "masterwork.monologue_distiller",
|
|
214
|
+
masterwork__outcome_judge: "masterwork.outcome_judge",
|
|
215
|
+
masterwork__relationship_auditor: "masterwork.relationship_auditor",
|
|
216
|
+
masterwork__rule_improver: "masterwork.rule_improver",
|
|
217
|
+
masterwork__rulebook_auditor: "masterwork.rulebook_auditor",
|
|
218
|
+
masterwork__scout: "masterwork.scout",
|
|
219
|
+
masterwork__source_distiller: "masterwork.source_distiller",
|
|
220
|
+
masterwork__template__chief_edit: "masterwork.template.chief_edit",
|
|
221
|
+
masterwork__template__chief_generate: "masterwork.template.chief_generate",
|
|
222
|
+
masterwork__template__editor: "masterwork.template.editor",
|
|
223
|
+
masterwork__template__maker: "masterwork.template.maker",
|
|
224
|
+
masterwork__timeline_distiller: "masterwork.timeline_distiller",
|
|
225
|
+
masterwork__timeline_segmenter: "masterwork.timeline_segmenter",
|
|
226
|
+
masterwork__transcript_distiller: "masterwork.transcript_distiller",
|
|
227
|
+
masterwork__transcript_shortlister: "masterwork.transcript_shortlister",
|
|
228
|
+
masterwork__understudy: "masterwork.understudy",
|
|
229
|
+
media__youtube_analyzer: "media.youtube_analyzer",
|
|
230
|
+
meet__live_intelligence: "meet.live_intelligence",
|
|
231
|
+
meet__live_notes: "meet.live_notes",
|
|
232
|
+
meet__wrap_up: "meet.wrap_up",
|
|
233
|
+
messaging__action_item_extraction: "messaging.action_item_extraction",
|
|
234
|
+
messaging__conversation_catch_up: "messaging.conversation_catch_up",
|
|
235
|
+
messaging__conversation_summary: "messaging.conversation_summary",
|
|
236
|
+
messaging__reply_drafting: "messaging.reply_drafting",
|
|
237
|
+
ner__deep_chunk_extractor: "ner.deep_chunk_extractor",
|
|
238
|
+
ner__document_orienter: "ner.document_orienter",
|
|
239
|
+
ner__entity_canonicalizer: "ner.entity_canonicalizer",
|
|
240
|
+
ner__finisher: "ner.finisher",
|
|
241
|
+
ner__item_proposer: "ner.item_proposer",
|
|
242
|
+
ner__magic_moment_detector: "ner.magic_moment_detector",
|
|
243
|
+
ner__scope_proposer: "ner.scope_proposer",
|
|
244
|
+
ner__scope_slot_filler: "ner.scope_slot_filler",
|
|
245
|
+
ner__suggestion_reviewer: "ner.suggestion_reviewer",
|
|
246
|
+
ner__sweep_scope_discoverer: "ner.sweep_scope_discoverer",
|
|
247
|
+
ner__sweep_scope_reference_finder: "ner.sweep_scope_reference_finder",
|
|
248
|
+
ner__sweep_value_miner: "ner.sweep_value_miner",
|
|
249
|
+
notes__organizer: "notes.organizer",
|
|
250
|
+
notes__page_guidance: "notes.page_guidance",
|
|
251
|
+
observability__tool_trace_pattern_detection: "observability.tool_trace_pattern_detection",
|
|
252
|
+
observability__tool_trace_triage: "observability.tool_trace_triage",
|
|
253
|
+
orchestras__role_describer: "orchestras.role_describer",
|
|
254
|
+
pdf__content_cleaner: "pdf.content_cleaner",
|
|
255
|
+
podcast__audience_adapter: "podcast.audience_adapter",
|
|
256
|
+
podcast__audio_dialogue: "podcast.audio_dialogue",
|
|
257
|
+
podcast__audio_english: "podcast.audio_english",
|
|
258
|
+
podcast__audio_persian: "podcast.audio_persian",
|
|
259
|
+
podcast__chapter_marker: "podcast.chapter_marker",
|
|
260
|
+
podcast__content_extractor: "podcast.content_extractor",
|
|
261
|
+
podcast__deep_research: "podcast.deep_research",
|
|
262
|
+
podcast__image_v1: "podcast.image_v1",
|
|
263
|
+
podcast__image_v2: "podcast.image_v2",
|
|
264
|
+
podcast__image_v3: "podcast.image_v3",
|
|
265
|
+
podcast__image_v4: "podcast.image_v4",
|
|
266
|
+
podcast__image_v5: "podcast.image_v5",
|
|
267
|
+
podcast__image_v6_feature: "podcast.image_v6_feature",
|
|
268
|
+
podcast__image_v6_feature_prompt: "podcast.image_v6_feature_prompt",
|
|
269
|
+
podcast__live_rewrite: "podcast.live_rewrite",
|
|
270
|
+
podcast__metadata: "podcast.metadata",
|
|
271
|
+
podcast__multihost_script: "podcast.multihost_script",
|
|
272
|
+
podcast__post_prep_expansion: "podcast.post_prep_expansion",
|
|
273
|
+
podcast__post_prep_fact_checking: "podcast.post_prep_fact_checking",
|
|
274
|
+
podcast__post_prep_summarization: "podcast.post_prep_summarization",
|
|
275
|
+
podcast__post_prep_translation: "podcast.post_prep_translation",
|
|
276
|
+
podcast__race_frontier: "podcast.race_frontier",
|
|
277
|
+
podcast__relevance_gate: "podcast.relevance_gate",
|
|
278
|
+
podcast__roundtable_script: "podcast.roundtable_script",
|
|
279
|
+
podcast__script_educational: "podcast.script_educational",
|
|
280
|
+
podcast__script_news: "podcast.script_news",
|
|
281
|
+
podcast__script_persian: "podcast.script_persian",
|
|
282
|
+
podcast__solo_script: "podcast.solo_script",
|
|
283
|
+
podcast__title_optimizer: "podcast.title_optimizer",
|
|
284
|
+
podcast__video_v1: "podcast.video_v1",
|
|
285
|
+
podcast__video_v2: "podcast.video_v2",
|
|
286
|
+
podcast_client__blog_writer: "podcast_client.blog_writer",
|
|
287
|
+
podcast_client__show_notes: "podcast_client.show_notes",
|
|
288
|
+
podcast_client__topic_ideas: "podcast_client.topic_ideas",
|
|
289
|
+
podcast_client__web_content_extractor: "podcast_client.web_content_extractor",
|
|
290
|
+
podcast_client__youtube_research: "podcast_client.youtube_research",
|
|
291
|
+
product_capture__instant_analysis: "product_capture.instant_analysis",
|
|
292
|
+
projects__creation_guide: "projects.creation_guide",
|
|
293
|
+
proof_runs__judge: "proof_runs.judge",
|
|
294
|
+
purpose__writer: "purpose.writer",
|
|
295
|
+
rag__chunk_contextualizer: "rag.chunk_contextualizer",
|
|
296
|
+
rag__hyde_generator: "rag.hyde_generator",
|
|
297
|
+
rag__pdf_page_cleaner: "rag.pdf_page_cleaner",
|
|
298
|
+
rag__query_expander: "rag.query_expander",
|
|
299
|
+
research__auto_tagger: "research.auto_tagger",
|
|
300
|
+
research__condenser_1: "research.condenser_1",
|
|
301
|
+
research__condenser_2: "research.condenser_2",
|
|
302
|
+
research__coverage_audit: "research.coverage_audit",
|
|
303
|
+
research__cross_cutting_tags: "research.cross_cutting_tags",
|
|
304
|
+
research__document_assembly: "research.document_assembly",
|
|
305
|
+
research__keyword_synthesis: "research.keyword_synthesis",
|
|
306
|
+
research__report: "research.report",
|
|
307
|
+
research__report_updater: "research.report_updater",
|
|
308
|
+
research__source_authority: "research.source_authority",
|
|
309
|
+
research__structured_page_summary: "research.structured_page_summary",
|
|
310
|
+
research__suggest_setup: "research.suggest_setup",
|
|
311
|
+
research__tag_consolidation: "research.tag_consolidation",
|
|
312
|
+
research_client__output_blog: "research_client.output_blog",
|
|
313
|
+
research_client__output_brand_profile: "research_client.output_brand_profile",
|
|
314
|
+
research_client__output_competitive_landscape: "research_client.output_competitive_landscape",
|
|
315
|
+
research_client__output_gap_analysis: "research_client.output_gap_analysis",
|
|
316
|
+
research_client__output_literature_review: "research_client.output_literature_review",
|
|
317
|
+
research_client__output_reputation_business: "research_client.output_reputation_business",
|
|
318
|
+
research_client__output_reputation_personal: "research_client.output_reputation_personal",
|
|
319
|
+
research_client__output_seo: "research_client.output_seo",
|
|
320
|
+
research_client__output_slides: "research_client.output_slides",
|
|
321
|
+
scraper__fact_check: "scraper.fact_check",
|
|
322
|
+
scraper__keyword_analysis: "scraper.keyword_analysis",
|
|
323
|
+
seo__ai_visibility_decision_analyst: "seo.ai_visibility_decision_analyst",
|
|
324
|
+
seo__backlink_context_assessor: "seo.backlink_context_assessor",
|
|
325
|
+
seo__backlink_work_planner: "seo.backlink_work_planner",
|
|
326
|
+
seo__business_model_verdict: "seo.business_model_verdict",
|
|
327
|
+
seo__competitor_classifier: "seo.competitor_classifier",
|
|
328
|
+
seo__competitor_opportunity_autopsy: "seo.competitor_opportunity_autopsy",
|
|
329
|
+
seo__competitor_page_autopsy: "seo.competitor_page_autopsy",
|
|
330
|
+
seo__coverage_analyst: "seo.coverage_analyst",
|
|
331
|
+
seo__digital_pr_reputation_adjudicator: "seo.digital_pr_reputation_adjudicator",
|
|
332
|
+
seo__evidence_workbench: "seo.evidence_workbench",
|
|
333
|
+
seo__finding_fixer: "seo.finding_fixer",
|
|
334
|
+
seo__guidelines_drafter: "seo.guidelines_drafter",
|
|
335
|
+
seo__ideal_customer_profile: "seo.ideal_customer_profile",
|
|
336
|
+
seo__keyword_classifier: "seo.keyword_classifier",
|
|
337
|
+
seo__keyword_expander: "seo.keyword_expander",
|
|
338
|
+
seo__keyword_researcher: "seo.keyword_researcher",
|
|
339
|
+
seo__keyword_serp_intent_analyst: "seo.keyword_serp_intent_analyst",
|
|
340
|
+
seo__landscape_brief: "seo.landscape_brief",
|
|
341
|
+
seo__money_map: "seo.money_map",
|
|
342
|
+
seo__offering_extraction: "seo.offering_extraction",
|
|
343
|
+
seo__offering_valuation: "seo.offering_valuation",
|
|
344
|
+
seo__page_analyzer: "seo.page_analyzer",
|
|
345
|
+
seo__page_keyword_mapper: "seo.page_keyword_mapper",
|
|
346
|
+
seo__press_source_request_responder: "seo.press_source_request_responder",
|
|
347
|
+
seo__press_story_analyst: "seo.press_story_analyst",
|
|
348
|
+
seo__session_rule_writer: "seo.session_rule_writer",
|
|
349
|
+
seo__session_stamp_proposer: "seo.session_stamp_proposer",
|
|
350
|
+
seo__site_intake: "seo.site_intake",
|
|
351
|
+
seo__site_link_authority_router: "seo.site_link_authority_router",
|
|
352
|
+
seo__site_strategist: "seo.site_strategist",
|
|
353
|
+
seo__starter_pack_proposer: "seo.starter_pack_proposer",
|
|
354
|
+
seo__topic_assigner: "seo.topic_assigner",
|
|
355
|
+
sms__owner_beta: "sms.owner_beta",
|
|
356
|
+
surfaces_client__binding_mapper: "surfaces_client.binding_mapper",
|
|
357
|
+
tasks__triage: "tasks.triage",
|
|
358
|
+
tool_viz__component_generator: "tool_viz.component_generator",
|
|
359
|
+
tools__summarize_content: "tools.summarize_content",
|
|
360
|
+
transcript_studio__document_edit: "transcript_studio.document_edit",
|
|
361
|
+
transcript_studio__scribe_live: "transcript_studio.scribe_live",
|
|
362
|
+
vision_interview__adversary: "vision_interview.adversary",
|
|
363
|
+
vision_interview__amplifier: "vision_interview.amplifier",
|
|
364
|
+
vision_interview__answer_tracker: "vision_interview.answer_tracker",
|
|
365
|
+
vision_interview__archaeologist: "vision_interview.archaeologist",
|
|
366
|
+
vision_interview__architect: "vision_interview.architect",
|
|
367
|
+
vision_interview__cartographer: "vision_interview.cartographer",
|
|
368
|
+
vision_interview__requirements_author: "vision_interview.requirements_author",
|
|
369
|
+
vision_interview__scribe: "vision_interview.scribe",
|
|
370
|
+
vision_interview__sounding_board: "vision_interview.sounding_board",
|
|
371
|
+
vision_interview__transcript_cleaner: "vision_interview.transcript_cleaner",
|
|
372
|
+
vision_interview__vision_author: "vision_interview.vision_author",
|
|
373
|
+
voice__communicator: "voice.communicator",
|
|
374
|
+
voice__intro: "voice.intro",
|
|
375
|
+
voice__owner_beta: "voice.owner_beta",
|
|
376
|
+
war_room__master: "war_room.master",
|
|
377
|
+
war_room__room: "war_room.room",
|
|
378
|
+
war_room__thread: "war_room.thread",
|
|
379
|
+
web__endpoint_family_judge: "web.endpoint_family_judge",
|
|
380
|
+
workflow__complex_research__keyword_synthesis: "workflow.complex_research.keyword_synthesis",
|
|
381
|
+
workflow__complex_research__page_summary: "workflow.complex_research.page_summary",
|
|
382
|
+
workflow__complex_research__report: "workflow.complex_research.report",
|
|
383
|
+
workflow__conductor: "workflow.conductor",
|
|
384
|
+
workflow__deep_research__keyword_synthesis: "workflow.deep_research.keyword_synthesis",
|
|
385
|
+
workflow__extract_namer: "workflow.extract_namer",
|
|
386
|
+
workflow__plan_design: "workflow.plan_design",
|
|
387
|
+
workflow__plan_input_kind_authoring: "workflow.plan_input_kind_authoring",
|
|
388
|
+
workflow__plan_node_type_recommender: "workflow.plan_node_type_recommender",
|
|
389
|
+
workflow__plan_notes_writer: "workflow.plan_notes_writer",
|
|
390
|
+
workflow__plan_output_kind_authoring: "workflow.plan_output_kind_authoring",
|
|
391
|
+
workflow__recovery_advisor: "workflow.recovery_advisor",
|
|
392
|
+
workflow__run_assist_suggester: "workflow.run_assist_suggester",
|
|
393
|
+
workflow__step_intelligence: "workflow.step_intelligence",
|
|
394
|
+
workflow__steward: "workflow.steward",
|
|
395
|
+
workflow__steward__agent_run: "workflow.steward.agent_run",
|
|
396
|
+
workflow__steward__data: "workflow.steward.data",
|
|
397
|
+
workflow__steward__decision: "workflow.steward.decision",
|
|
398
|
+
workflow__steward__user_input: "workflow.steward.user_input"
|
|
399
|
+
};
|
|
400
|
+
var ALL_MANDATE_KEYS = Object.values(MANDATE_KEYS);
|
|
401
|
+
|
|
402
|
+
// mandates/index.ts
|
|
403
|
+
var KEY_SET = new Set(ALL_MANDATE_KEYS);
|
|
404
|
+
|
|
405
|
+
// matrx/transport.ts
|
|
406
|
+
var MatrxApiError = class extends Error {
|
|
407
|
+
name = "MatrxApiError";
|
|
408
|
+
/** HTTP status of the failed response. */
|
|
409
|
+
status;
|
|
410
|
+
/** Machine code from the server body (`code`, or `detail.code`), when present. */
|
|
411
|
+
code;
|
|
412
|
+
/** The parsed server error body, verbatim (undefined when unparsable). */
|
|
413
|
+
serverDetail;
|
|
414
|
+
/** The request path the failure came from (server-relative). */
|
|
415
|
+
path;
|
|
416
|
+
constructor(args) {
|
|
417
|
+
super(
|
|
418
|
+
args.message ?? extractMatrxErrorMessage(args.serverDetail) ?? `HTTP ${args.status}`
|
|
419
|
+
);
|
|
420
|
+
this.status = args.status;
|
|
421
|
+
this.path = args.path;
|
|
422
|
+
this.serverDetail = args.serverDetail;
|
|
423
|
+
this.code = extractMatrxErrorCode(args.serverDetail);
|
|
424
|
+
}
|
|
425
|
+
};
|
|
426
|
+
function isRecord(value) {
|
|
427
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
428
|
+
}
|
|
429
|
+
function nonBlankString(value) {
|
|
430
|
+
return typeof value === "string" && value.trim() ? value : void 0;
|
|
431
|
+
}
|
|
432
|
+
function extractMatrxErrorMessage(serverDetail) {
|
|
433
|
+
if (!isRecord(serverDetail)) return void 0;
|
|
434
|
+
const userMessage = nonBlankString(serverDetail.user_message);
|
|
435
|
+
if (userMessage) return userMessage;
|
|
436
|
+
const message = nonBlankString(serverDetail.message);
|
|
437
|
+
if (message) return message;
|
|
438
|
+
if (Array.isArray(serverDetail.details)) {
|
|
439
|
+
const messages = serverDetail.details.map((entry) => {
|
|
440
|
+
if (!isRecord(entry)) return void 0;
|
|
441
|
+
const detailMessage = nonBlankString(entry.message);
|
|
442
|
+
if (!detailMessage) return void 0;
|
|
443
|
+
const field = nonBlankString(entry.field);
|
|
444
|
+
return field ? `${field}: ${detailMessage}` : detailMessage;
|
|
445
|
+
}).filter((m) => typeof m === "string");
|
|
446
|
+
if (messages.length > 0) return messages.join("; ");
|
|
447
|
+
}
|
|
448
|
+
const detail = serverDetail.detail;
|
|
449
|
+
if (isRecord(detail)) {
|
|
450
|
+
const detailMessage = nonBlankString(detail.message) ?? nonBlankString(detail.user_message);
|
|
451
|
+
if (detailMessage) return detailMessage;
|
|
452
|
+
}
|
|
453
|
+
if (typeof detail === "string" && detail.trim()) return detail;
|
|
454
|
+
if (Array.isArray(detail)) {
|
|
455
|
+
const messages = detail.map(
|
|
456
|
+
(entry) => isRecord(entry) ? nonBlankString(entry.msg) : void 0
|
|
457
|
+
).filter((m) => typeof m === "string");
|
|
458
|
+
if (messages.length > 0) return messages.join("; ");
|
|
459
|
+
}
|
|
460
|
+
return void 0;
|
|
461
|
+
}
|
|
462
|
+
function extractMatrxErrorCode(serverDetail) {
|
|
463
|
+
if (!isRecord(serverDetail)) return null;
|
|
464
|
+
const topLevel = nonBlankString(serverDetail.code);
|
|
465
|
+
if (topLevel) return topLevel;
|
|
466
|
+
const detail = serverDetail.detail;
|
|
467
|
+
if (isRecord(detail)) {
|
|
468
|
+
const nested = nonBlankString(detail.code);
|
|
469
|
+
if (nested) return nested;
|
|
470
|
+
}
|
|
471
|
+
return null;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// matrx/conversation.ts
|
|
475
|
+
function mintMatrxConversationId() {
|
|
476
|
+
return crypto.randomUUID();
|
|
477
|
+
}
|
|
478
|
+
function newStoredConversationStart(conversationId) {
|
|
479
|
+
return {
|
|
480
|
+
conversation_id: conversationId ?? mintMatrxConversationId(),
|
|
481
|
+
is_new: true,
|
|
482
|
+
store: true
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
// stream/ndjson.ts
|
|
487
|
+
var DEFAULT_MATRX_NDJSON_READ_AHEAD = 64;
|
|
488
|
+
function isRecord2(value) {
|
|
489
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
490
|
+
}
|
|
491
|
+
function normalizeMatrxStreamEnvelope(value) {
|
|
492
|
+
if (!isRecord2(value)) return null;
|
|
493
|
+
if (typeof value.event === "string") {
|
|
494
|
+
const streamSeq = typeof value.stream_seq === "number" && Number.isFinite(value.stream_seq) ? value.stream_seq : void 0;
|
|
495
|
+
const streamId = typeof value.stream_id === "string" ? value.stream_id : void 0;
|
|
496
|
+
return {
|
|
497
|
+
event: value.event,
|
|
498
|
+
data: value.data,
|
|
499
|
+
...streamId === void 0 ? {} : { stream_id: streamId },
|
|
500
|
+
...streamSeq === void 0 ? {} : { stream_seq: streamSeq }
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
if (value.e === "c" && typeof value.t === "string") {
|
|
504
|
+
const streamId = typeof value.stream_id === "string" ? value.stream_id : void 0;
|
|
505
|
+
const streamSeq = typeof value.stream_seq === "number" && Number.isFinite(value.stream_seq) ? value.stream_seq : void 0;
|
|
506
|
+
return {
|
|
507
|
+
event: "chunk",
|
|
508
|
+
data: { text: value.t },
|
|
509
|
+
...streamId === void 0 ? {} : { stream_id: streamId },
|
|
510
|
+
...streamSeq === void 0 ? {} : { stream_seq: streamSeq }
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
if (value.e === "r" && typeof value.t === "string") {
|
|
514
|
+
const streamId = typeof value.stream_id === "string" ? value.stream_id : void 0;
|
|
515
|
+
const streamSeq = typeof value.stream_seq === "number" && Number.isFinite(value.stream_seq) ? value.stream_seq : void 0;
|
|
516
|
+
return {
|
|
517
|
+
event: "reasoning_chunk",
|
|
518
|
+
data: { text: value.t },
|
|
519
|
+
...streamId === void 0 ? {} : { stream_id: streamId },
|
|
520
|
+
...streamSeq === void 0 ? {} : { stream_seq: streamSeq }
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
return null;
|
|
524
|
+
}
|
|
525
|
+
function createMatrxNdjsonFramer(options = {}) {
|
|
526
|
+
const decoder = new TextDecoder();
|
|
527
|
+
let buffer = "";
|
|
528
|
+
let lineNumber = 0;
|
|
529
|
+
let finished = false;
|
|
530
|
+
const assertOpen = () => {
|
|
531
|
+
if (finished) throw new Error("Matrx NDJSON framer is already finished");
|
|
532
|
+
};
|
|
533
|
+
const parseLine = (line, atCompletion) => {
|
|
534
|
+
const currentLineNumber = ++lineNumber;
|
|
535
|
+
const trimmed = line.trim();
|
|
536
|
+
if (!trimmed) return null;
|
|
537
|
+
let parsed;
|
|
538
|
+
try {
|
|
539
|
+
parsed = JSON.parse(trimmed);
|
|
540
|
+
} catch (error) {
|
|
541
|
+
options.onMalformedLine?.({
|
|
542
|
+
line: trimmed,
|
|
543
|
+
error,
|
|
544
|
+
lineNumber: currentLineNumber,
|
|
545
|
+
atCompletion
|
|
546
|
+
});
|
|
547
|
+
return null;
|
|
548
|
+
}
|
|
549
|
+
const envelope = normalizeMatrxStreamEnvelope(parsed);
|
|
550
|
+
if (!envelope) {
|
|
551
|
+
options.onUnknownEnvelope?.(parsed);
|
|
552
|
+
return null;
|
|
553
|
+
}
|
|
554
|
+
options.onValidEnvelope?.({
|
|
555
|
+
raw: parsed,
|
|
556
|
+
envelope,
|
|
557
|
+
line: trimmed,
|
|
558
|
+
lineNumber: currentLineNumber,
|
|
559
|
+
atCompletion
|
|
560
|
+
});
|
|
561
|
+
return envelope;
|
|
562
|
+
};
|
|
563
|
+
const pushDecodedText = (fragment) => {
|
|
564
|
+
buffer += fragment;
|
|
565
|
+
const lines = buffer.split("\n");
|
|
566
|
+
buffer = lines.pop() ?? "";
|
|
567
|
+
const envelopes = [];
|
|
568
|
+
for (const line of lines) {
|
|
569
|
+
const envelope = parseLine(line, false);
|
|
570
|
+
if (envelope) envelopes.push(envelope);
|
|
571
|
+
}
|
|
572
|
+
return envelopes;
|
|
573
|
+
};
|
|
574
|
+
return {
|
|
575
|
+
pushText(fragment) {
|
|
576
|
+
assertOpen();
|
|
577
|
+
return pushDecodedText(decoder.decode() + fragment);
|
|
578
|
+
},
|
|
579
|
+
pushBytes(fragment) {
|
|
580
|
+
assertOpen();
|
|
581
|
+
return pushDecodedText(decoder.decode(fragment, { stream: true }));
|
|
582
|
+
},
|
|
583
|
+
finish() {
|
|
584
|
+
assertOpen();
|
|
585
|
+
finished = true;
|
|
586
|
+
const envelopes = pushDecodedText(decoder.decode());
|
|
587
|
+
if (buffer.length > 0) {
|
|
588
|
+
const envelope = parseLine(buffer, true);
|
|
589
|
+
buffer = "";
|
|
590
|
+
if (envelope) envelopes.push(envelope);
|
|
591
|
+
}
|
|
592
|
+
return envelopes;
|
|
593
|
+
}
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
function readAheadLimit(value) {
|
|
597
|
+
const limit = value ?? DEFAULT_MATRX_NDJSON_READ_AHEAD;
|
|
598
|
+
if (!Number.isSafeInteger(limit) || limit < 1) {
|
|
599
|
+
throw new RangeError("maxReadAhead must be a positive safe integer");
|
|
600
|
+
}
|
|
601
|
+
return limit;
|
|
602
|
+
}
|
|
603
|
+
async function* readMatrxNdjsonStream(body, options = {}) {
|
|
604
|
+
const maxReadAhead = readAheadLimit(options.maxReadAhead);
|
|
605
|
+
const queue = [];
|
|
606
|
+
let queuedEventCount = 0;
|
|
607
|
+
let wakeConsumer = null;
|
|
608
|
+
let wakeProducer = null;
|
|
609
|
+
let readerFinished = false;
|
|
610
|
+
let consumerClosed = false;
|
|
611
|
+
const wakeWaitingConsumer = () => {
|
|
612
|
+
const wake = wakeConsumer;
|
|
613
|
+
wakeConsumer = null;
|
|
614
|
+
wake?.();
|
|
615
|
+
};
|
|
616
|
+
const wakeWaitingProducer = () => {
|
|
617
|
+
const wake = wakeProducer;
|
|
618
|
+
wakeProducer = null;
|
|
619
|
+
wake?.();
|
|
620
|
+
};
|
|
621
|
+
const enqueueTerminal = (item) => {
|
|
622
|
+
if (consumerClosed) return;
|
|
623
|
+
queue.push(item);
|
|
624
|
+
wakeWaitingConsumer();
|
|
625
|
+
};
|
|
626
|
+
const enqueueEvent = async (value) => {
|
|
627
|
+
while (queuedEventCount >= maxReadAhead && !consumerClosed && !options.signal?.aborted) {
|
|
628
|
+
await new Promise((resolve2) => {
|
|
629
|
+
wakeProducer = resolve2;
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
if (consumerClosed || options.signal?.aborted) return false;
|
|
633
|
+
queue.push({ kind: "event", value });
|
|
634
|
+
queuedEventCount += 1;
|
|
635
|
+
wakeWaitingConsumer();
|
|
636
|
+
return true;
|
|
637
|
+
};
|
|
638
|
+
const waitForReadCapacity = async () => {
|
|
639
|
+
while (queuedEventCount >= maxReadAhead && !consumerClosed && !options.signal?.aborted) {
|
|
640
|
+
await new Promise((resolve2) => {
|
|
641
|
+
wakeProducer = resolve2;
|
|
642
|
+
});
|
|
643
|
+
}
|
|
644
|
+
return !consumerClosed && !options.signal?.aborted;
|
|
645
|
+
};
|
|
646
|
+
const reader = body.getReader();
|
|
647
|
+
const framer = createMatrxNdjsonFramer(options);
|
|
648
|
+
const onAbort = () => {
|
|
649
|
+
wakeWaitingProducer();
|
|
650
|
+
wakeWaitingConsumer();
|
|
651
|
+
void reader.cancel(options.signal?.reason).catch(() => void 0);
|
|
652
|
+
};
|
|
653
|
+
options.signal?.addEventListener("abort", onAbort, { once: true });
|
|
654
|
+
if (options.signal?.aborted) onAbort();
|
|
655
|
+
const readerPromise = (async () => {
|
|
656
|
+
try {
|
|
657
|
+
while (!options.signal?.aborted && !consumerClosed) {
|
|
658
|
+
if (!await waitForReadCapacity()) return;
|
|
659
|
+
const { value, done } = await reader.read();
|
|
660
|
+
if (done) break;
|
|
661
|
+
for (const envelope of framer.pushBytes(value)) {
|
|
662
|
+
if (!await enqueueEvent(envelope)) return;
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
if (!options.signal?.aborted && !consumerClosed) {
|
|
666
|
+
for (const envelope of framer.finish()) {
|
|
667
|
+
if (!await enqueueEvent(envelope)) return;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
} catch (error) {
|
|
671
|
+
const aborted = options.signal?.aborted || consumerClosed || error instanceof Error && error.name === "AbortError";
|
|
672
|
+
if (!aborted) enqueueTerminal({ kind: "error", error });
|
|
673
|
+
} finally {
|
|
674
|
+
readerFinished = true;
|
|
675
|
+
reader.releaseLock();
|
|
676
|
+
enqueueTerminal({ kind: "done" });
|
|
677
|
+
}
|
|
678
|
+
})();
|
|
679
|
+
try {
|
|
680
|
+
while (true) {
|
|
681
|
+
if (queue.length === 0) {
|
|
682
|
+
if (options.signal?.aborted || readerFinished) return;
|
|
683
|
+
await new Promise((resolve2) => {
|
|
684
|
+
wakeConsumer = resolve2;
|
|
685
|
+
});
|
|
686
|
+
}
|
|
687
|
+
const item = queue.shift();
|
|
688
|
+
if (item?.kind === "event") queuedEventCount -= 1;
|
|
689
|
+
wakeWaitingProducer();
|
|
690
|
+
if (!item || item.kind === "done") return;
|
|
691
|
+
if (item.kind === "error") throw item.error;
|
|
692
|
+
yield item.value;
|
|
693
|
+
}
|
|
694
|
+
} finally {
|
|
695
|
+
consumerClosed = true;
|
|
696
|
+
wakeWaitingProducer();
|
|
697
|
+
wakeWaitingConsumer();
|
|
698
|
+
options.signal?.removeEventListener("abort", onAbort);
|
|
699
|
+
if (!readerFinished) {
|
|
700
|
+
await reader.cancel().catch(() => void 0);
|
|
701
|
+
}
|
|
702
|
+
await readerPromise;
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
// matrx/internal.ts
|
|
707
|
+
function encodePathSegment(value) {
|
|
708
|
+
return encodeURIComponent(value);
|
|
709
|
+
}
|
|
710
|
+
function buildQuery(params) {
|
|
711
|
+
const search = new URLSearchParams();
|
|
712
|
+
for (const [key, value] of Object.entries(params)) {
|
|
713
|
+
if (value === void 0) continue;
|
|
714
|
+
if (Array.isArray(value)) {
|
|
715
|
+
for (const entry of value) search.append(key, entry);
|
|
716
|
+
} else {
|
|
717
|
+
search.append(key, String(value));
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
const encoded = search.toString();
|
|
721
|
+
return encoded ? `?${encoded}` : "";
|
|
722
|
+
}
|
|
723
|
+
async function readServerDetail(response) {
|
|
724
|
+
try {
|
|
725
|
+
return await response.json();
|
|
726
|
+
} catch {
|
|
727
|
+
return void 0;
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
async function throwApiError(path, response) {
|
|
731
|
+
throw new MatrxApiError({
|
|
732
|
+
status: response.status,
|
|
733
|
+
path,
|
|
734
|
+
serverDetail: await readServerDetail(response)
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
async function requestJson(transport, path, options) {
|
|
738
|
+
const hasBody = options.method !== "GET" && options.body !== void 0;
|
|
739
|
+
const response = await transport.fetch(path, {
|
|
740
|
+
method: options.method,
|
|
741
|
+
headers: hasBody ? { "Content-Type": "application/json" } : {},
|
|
742
|
+
...hasBody ? { body: JSON.stringify(options.body) } : {},
|
|
743
|
+
...options.signal ? { signal: options.signal } : {}
|
|
744
|
+
});
|
|
745
|
+
if (!response.ok) return throwApiError(path, response);
|
|
746
|
+
return await response.json();
|
|
747
|
+
}
|
|
748
|
+
function toRunHandle(response, options) {
|
|
749
|
+
return {
|
|
750
|
+
requestId: response.headers.get("X-Request-ID"),
|
|
751
|
+
conversationId: response.headers.get("X-Conversation-ID"),
|
|
752
|
+
events: readMatrxNdjsonStream(response.body, {
|
|
753
|
+
...options.signal ? { signal: options.signal } : {},
|
|
754
|
+
...options.maxReadAhead !== void 0 ? { maxReadAhead: options.maxReadAhead } : {},
|
|
755
|
+
...options.onMalformedLine ? { onMalformedLine: options.onMalformedLine } : {},
|
|
756
|
+
...options.onUnknownEnvelope ? { onUnknownEnvelope: options.onUnknownEnvelope } : {},
|
|
757
|
+
...options.onValidEnvelope ? { onValidEnvelope: options.onValidEnvelope } : {}
|
|
758
|
+
}),
|
|
759
|
+
response
|
|
760
|
+
};
|
|
761
|
+
}
|
|
762
|
+
async function requestStream(transport, path, options) {
|
|
763
|
+
const hasBody = options.method !== "GET" && options.body !== void 0;
|
|
764
|
+
const response = await transport.fetch(path, {
|
|
765
|
+
method: options.method,
|
|
766
|
+
headers: {
|
|
767
|
+
...hasBody ? { "Content-Type": "application/json" } : {},
|
|
768
|
+
...options.headers
|
|
769
|
+
},
|
|
770
|
+
...hasBody ? { body: JSON.stringify(options.body) } : {},
|
|
771
|
+
...options.signal ? { signal: options.signal } : {}
|
|
772
|
+
});
|
|
773
|
+
if (!response.ok) return throwApiError(path, response);
|
|
774
|
+
if (!response.body) {
|
|
775
|
+
throw new MatrxApiError({
|
|
776
|
+
status: response.status,
|
|
777
|
+
path,
|
|
778
|
+
serverDetail: { code: "missing_response_body" },
|
|
779
|
+
message: "The streaming response carried no body."
|
|
780
|
+
});
|
|
781
|
+
}
|
|
782
|
+
return response;
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
// matrx/run.ts
|
|
786
|
+
async function streamCall(transport, path, body, options) {
|
|
787
|
+
const response = await requestStream(transport, path, {
|
|
788
|
+
method: "POST",
|
|
789
|
+
// This client IS the streaming path — `stream: true` always, last so a
|
|
790
|
+
// caller-supplied value can never flip the response off NDJSON.
|
|
791
|
+
body: { ...body, stream: true },
|
|
792
|
+
...options.signal ? { signal: options.signal } : {}
|
|
793
|
+
});
|
|
794
|
+
return toRunHandle(response, options);
|
|
795
|
+
}
|
|
796
|
+
function startMandateRun(transport, mandateKey, request, options = {}) {
|
|
797
|
+
return streamCall(
|
|
798
|
+
transport,
|
|
799
|
+
`/ai/mandates/${encodePathSegment(mandateKey)}`,
|
|
800
|
+
request,
|
|
801
|
+
options
|
|
802
|
+
);
|
|
803
|
+
}
|
|
804
|
+
function cancelAgentRun(transport, requestId, options = {}) {
|
|
805
|
+
const query = buildQuery(
|
|
806
|
+
options.mode === "interrupt" ? { mode: "interrupt" } : {}
|
|
807
|
+
);
|
|
808
|
+
return requestJson(
|
|
809
|
+
transport,
|
|
810
|
+
`/ai/cancel/${encodePathSegment(requestId)}${query}`,
|
|
811
|
+
{
|
|
812
|
+
method: "POST",
|
|
813
|
+
...options.signal ? { signal: options.signal } : {}
|
|
814
|
+
}
|
|
815
|
+
);
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
// stream/sse.ts
|
|
819
|
+
var FRAME_SEPARATOR = /\r\n\r\n|\n\n|\r\r/;
|
|
820
|
+
var LINE_SEPARATOR = /\r\n|\n|\r/;
|
|
821
|
+
function parseMatrxSseFrame(frame) {
|
|
822
|
+
let event = "message";
|
|
823
|
+
let id = null;
|
|
824
|
+
const dataLines = [];
|
|
825
|
+
let sawData = false;
|
|
826
|
+
for (const line of frame.split(LINE_SEPARATOR)) {
|
|
827
|
+
if (line.startsWith(":")) continue;
|
|
828
|
+
if (line.startsWith("event:")) event = line.slice(6).trim();
|
|
829
|
+
else if (line.startsWith("data:")) {
|
|
830
|
+
sawData = true;
|
|
831
|
+
dataLines.push(line.slice(5).replace(/^ /, ""));
|
|
832
|
+
} else if (line.startsWith("id:")) id = line.slice(3).trim();
|
|
833
|
+
}
|
|
834
|
+
const seqCandidate = id !== null && id !== "" ? Number(id) : NaN;
|
|
835
|
+
const seq = Number.isSafeInteger(seqCandidate) && seqCandidate >= 0 ? seqCandidate : null;
|
|
836
|
+
return { event, id, seq, data: sawData ? dataLines.join("\n") : null };
|
|
837
|
+
}
|
|
838
|
+
function createMatrxSseFramer() {
|
|
839
|
+
let buffer = "";
|
|
840
|
+
return {
|
|
841
|
+
push(chunk) {
|
|
842
|
+
buffer += chunk;
|
|
843
|
+
const frames = [];
|
|
844
|
+
for (; ; ) {
|
|
845
|
+
const sep = FRAME_SEPARATOR.exec(buffer);
|
|
846
|
+
if (sep === null) break;
|
|
847
|
+
const frame = buffer.slice(0, sep.index);
|
|
848
|
+
buffer = buffer.slice(sep.index + sep[0].length);
|
|
849
|
+
frames.push(parseMatrxSseFrame(frame));
|
|
850
|
+
}
|
|
851
|
+
return frames;
|
|
852
|
+
},
|
|
853
|
+
flush() {
|
|
854
|
+
const rest = buffer;
|
|
855
|
+
buffer = "";
|
|
856
|
+
return { incomplete: rest.length > 0 ? rest : null };
|
|
857
|
+
}
|
|
858
|
+
};
|
|
859
|
+
}
|
|
860
|
+
async function* readMatrxSseStream(stream, options = {}) {
|
|
861
|
+
const reader = stream.getReader();
|
|
862
|
+
const decoder = new TextDecoder();
|
|
863
|
+
const framer = createMatrxSseFramer();
|
|
864
|
+
try {
|
|
865
|
+
for (; ; ) {
|
|
866
|
+
const { value, done } = await reader.read();
|
|
867
|
+
if (done) break;
|
|
868
|
+
const frames = framer.push(decoder.decode(value, { stream: true }));
|
|
869
|
+
for (const frame of frames) yield frame;
|
|
870
|
+
}
|
|
871
|
+
const tail = framer.push(decoder.decode());
|
|
872
|
+
for (const frame of tail) yield frame;
|
|
873
|
+
const { incomplete } = framer.flush();
|
|
874
|
+
if (incomplete !== null) options.onIncomplete?.(incomplete);
|
|
875
|
+
} finally {
|
|
876
|
+
reader.releaseLock();
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
// matrx/operations.ts
|
|
881
|
+
var RUNTIME_STATUSES = /* @__PURE__ */ new Set([
|
|
882
|
+
"pending",
|
|
883
|
+
"running",
|
|
884
|
+
"paused",
|
|
885
|
+
"waiting_input",
|
|
886
|
+
"completed",
|
|
887
|
+
"failed",
|
|
888
|
+
"cancelled"
|
|
889
|
+
]);
|
|
890
|
+
async function getRuntimeOperationStatus(transport, requestId, options = {}) {
|
|
891
|
+
try {
|
|
892
|
+
return await requestJson(
|
|
893
|
+
transport,
|
|
894
|
+
`/runtime/operations/${encodePathSegment(requestId)}`,
|
|
895
|
+
{ method: "GET", ...options.signal ? { signal: options.signal } : {} }
|
|
896
|
+
);
|
|
897
|
+
} catch (error) {
|
|
898
|
+
if (error instanceof MatrxApiError && error.status === 404) return null;
|
|
899
|
+
throw error;
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
function parseEndStatus(data) {
|
|
903
|
+
if (data === null) return null;
|
|
904
|
+
try {
|
|
905
|
+
const parsed = JSON.parse(data);
|
|
906
|
+
if (typeof parsed === "object" && parsed !== null && typeof parsed.status === "string") {
|
|
907
|
+
const status = parsed.status;
|
|
908
|
+
return RUNTIME_STATUSES.has(status) ? status : null;
|
|
909
|
+
}
|
|
910
|
+
} catch {
|
|
911
|
+
}
|
|
912
|
+
return null;
|
|
913
|
+
}
|
|
914
|
+
async function* followRuntimeOperationEvents(transport, executionId, options = {}) {
|
|
915
|
+
let cursor = options.lastEventSeq ?? 0;
|
|
916
|
+
const headers = { Accept: "text/event-stream" };
|
|
917
|
+
if (cursor > 0) headers["Last-Event-ID"] = String(cursor);
|
|
918
|
+
const response = await requestStream(
|
|
919
|
+
transport,
|
|
920
|
+
`/runtime/executions/${encodePathSegment(executionId)}/events/stream`,
|
|
921
|
+
{
|
|
922
|
+
method: "GET",
|
|
923
|
+
headers,
|
|
924
|
+
...options.signal ? { signal: options.signal } : {}
|
|
925
|
+
}
|
|
926
|
+
);
|
|
927
|
+
const frames = readMatrxSseStream(
|
|
928
|
+
response.body,
|
|
929
|
+
options.onIncomplete ? { onIncomplete: options.onIncomplete } : {}
|
|
930
|
+
);
|
|
931
|
+
for await (const frame of frames) {
|
|
932
|
+
if (frame.event === "end") {
|
|
933
|
+
yield { type: "end", status: parseEndStatus(frame.data), cursor };
|
|
934
|
+
return;
|
|
935
|
+
}
|
|
936
|
+
if (frame.event === "execution_event" && frame.data !== null) {
|
|
937
|
+
let event;
|
|
938
|
+
try {
|
|
939
|
+
event = JSON.parse(frame.data);
|
|
940
|
+
} catch (error) {
|
|
941
|
+
options.onMalformedFrame?.(frame, error);
|
|
942
|
+
yield { type: "liveness", cursor };
|
|
943
|
+
continue;
|
|
944
|
+
}
|
|
945
|
+
if (frame.seq !== null && frame.seq > cursor) cursor = frame.seq;
|
|
946
|
+
yield { type: "event", event, seq: frame.seq, cursor };
|
|
947
|
+
continue;
|
|
948
|
+
}
|
|
949
|
+
yield { type: "liveness", cursor };
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
async function followRuntimeOperationToEnd(transport, executionId, options) {
|
|
953
|
+
const stallTimeoutMs = options.stallTimeoutMs ?? 45e3;
|
|
954
|
+
const reconnectLimit = options.reconnectLimit ?? 60;
|
|
955
|
+
const reconnectDelayMs = options.reconnectDelayMs ?? 2e3;
|
|
956
|
+
const outer = options.signal;
|
|
957
|
+
let cursor = options.lastEventSeq ?? 0;
|
|
958
|
+
let failures = 0;
|
|
959
|
+
while (!outer?.aborted && failures < reconnectLimit) {
|
|
960
|
+
const attempt = new AbortController();
|
|
961
|
+
const onOuterAbort = () => attempt.abort();
|
|
962
|
+
outer?.addEventListener("abort", onOuterAbort, { once: true });
|
|
963
|
+
let stallTimer = null;
|
|
964
|
+
const armStall = () => {
|
|
965
|
+
if (stallTimer !== null) clearTimeout(stallTimer);
|
|
966
|
+
stallTimer = setTimeout(() => attempt.abort(), stallTimeoutMs);
|
|
967
|
+
};
|
|
968
|
+
try {
|
|
969
|
+
const items = followRuntimeOperationEvents(transport, executionId, {
|
|
970
|
+
lastEventSeq: cursor,
|
|
971
|
+
signal: attempt.signal,
|
|
972
|
+
...options.onMalformedFrame ? { onMalformedFrame: options.onMalformedFrame } : {}
|
|
973
|
+
});
|
|
974
|
+
armStall();
|
|
975
|
+
for await (const item of items) {
|
|
976
|
+
armStall();
|
|
977
|
+
failures = 0;
|
|
978
|
+
cursor = item.cursor;
|
|
979
|
+
if (item.type === "end") {
|
|
980
|
+
return { ended: true, status: item.status };
|
|
981
|
+
}
|
|
982
|
+
if (item.type === "event") {
|
|
983
|
+
options.onEvent(item.event, item.seq);
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
failures += 1;
|
|
987
|
+
} catch (error) {
|
|
988
|
+
if (outer?.aborted) break;
|
|
989
|
+
failures += 1;
|
|
990
|
+
options.onAttemptError?.(error);
|
|
991
|
+
} finally {
|
|
992
|
+
if (stallTimer !== null) clearTimeout(stallTimer);
|
|
993
|
+
outer?.removeEventListener("abort", onOuterAbort);
|
|
994
|
+
}
|
|
995
|
+
if (!outer?.aborted && failures < reconnectLimit) {
|
|
996
|
+
await new Promise((r) => setTimeout(r, reconnectDelayMs));
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
return { ended: false, status: null };
|
|
1000
|
+
}
|
|
1001
|
+
async function rejoinRuntimeOperation(transport, requestId, options = {}) {
|
|
1002
|
+
const response = await requestStream(
|
|
1003
|
+
transport,
|
|
1004
|
+
`/runtime/operations/${encodePathSegment(requestId)}/rejoin`,
|
|
1005
|
+
{
|
|
1006
|
+
method: "POST",
|
|
1007
|
+
// The route takes no body model; the reference client posts an empty
|
|
1008
|
+
// JSON object. Match it so proxies see an ordinary JSON POST.
|
|
1009
|
+
body: {},
|
|
1010
|
+
...options.signal ? { signal: options.signal } : {}
|
|
1011
|
+
}
|
|
1012
|
+
);
|
|
1013
|
+
return toRunHandle(response, options);
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
// content-transfer/index.ts
|
|
1017
|
+
var SupersededRunError = class extends Error {
|
|
1018
|
+
constructor() {
|
|
1019
|
+
super("A newer AI preparation started before this result settled.");
|
|
1020
|
+
}
|
|
1021
|
+
};
|
|
1022
|
+
function resolve(value) {
|
|
1023
|
+
return typeof value === "function" ? value() : value;
|
|
1024
|
+
}
|
|
1025
|
+
function deepFreeze(value) {
|
|
1026
|
+
if (ArrayBuffer.isView(value)) return value;
|
|
1027
|
+
if (value && typeof value === "object" && !Object.isFrozen(value)) {
|
|
1028
|
+
Object.freeze(value);
|
|
1029
|
+
for (const nested of Object.values(value)) deepFreeze(nested);
|
|
1030
|
+
}
|
|
1031
|
+
return value;
|
|
1032
|
+
}
|
|
1033
|
+
function isDeepFrozen(value, seen = /* @__PURE__ */ new WeakSet()) {
|
|
1034
|
+
if (!value || typeof value !== "object" || ArrayBuffer.isView(value))
|
|
1035
|
+
return true;
|
|
1036
|
+
if (seen.has(value)) return true;
|
|
1037
|
+
seen.add(value);
|
|
1038
|
+
return Object.isFrozen(value) && Object.values(value).every((nested) => isDeepFrozen(nested, seen));
|
|
1039
|
+
}
|
|
1040
|
+
function descriptionForCoverage(snapshot, draft) {
|
|
1041
|
+
const { coverage } = snapshot;
|
|
1042
|
+
const total = coverage.total === null ? "unknown total" : `${coverage.total} total`;
|
|
1043
|
+
const offered = draft.payload.kind === "rows" ? `${draft.payload.rows.length} prepared rows` : "one prepared document";
|
|
1044
|
+
return `snapshot ${coverage.status}: ${coverage.included} included, ${total}; offered ${offered} from ${draft.sourceId}@${draft.sourceRevision}, draft revision ${draft.revision}${coverage.reason ? `; ${coverage.reason}` : ""}`;
|
|
1045
|
+
}
|
|
1046
|
+
function descriptionForOmissions(draft) {
|
|
1047
|
+
if (draft.omissions.length === 0)
|
|
1048
|
+
return "No pre-AI exclusions or reductions were recorded in this prepared draft.";
|
|
1049
|
+
return draft.omissions.map(
|
|
1050
|
+
(o) => `${o.path || "document"}: ${o.reason}${o.count === void 0 ? "" : ` (${o.count})`}`
|
|
1051
|
+
).join("; ");
|
|
1052
|
+
}
|
|
1053
|
+
function visibleAssistantText(content) {
|
|
1054
|
+
if (typeof content === "string") return content.trim() || null;
|
|
1055
|
+
if (!Array.isArray(content)) return null;
|
|
1056
|
+
const parts = content.flatMap((part) => {
|
|
1057
|
+
if (!part || typeof part !== "object" || Array.isArray(part)) return [];
|
|
1058
|
+
const block = part;
|
|
1059
|
+
return block.type === "text" && typeof block.text === "string" ? [block.text] : [];
|
|
1060
|
+
});
|
|
1061
|
+
return parts.join("\n\n").trim() || null;
|
|
1062
|
+
}
|
|
1063
|
+
function responseMessageId(metadata) {
|
|
1064
|
+
if (!metadata || typeof metadata !== "object" || Array.isArray(metadata))
|
|
1065
|
+
return null;
|
|
1066
|
+
const value = metadata.response_message_id;
|
|
1067
|
+
return typeof value === "string" && value.length > 0 ? value : null;
|
|
1068
|
+
}
|
|
1069
|
+
function draftFromAssistant(source, text, identity) {
|
|
1070
|
+
const edited = editDraft(source, { kind: "markdown", text });
|
|
1071
|
+
const reducedBy = serialize(source, "markdown").plainText.length - text.length;
|
|
1072
|
+
return deepFreeze({
|
|
1073
|
+
...edited,
|
|
1074
|
+
manuallyEdited: source.manuallyEdited,
|
|
1075
|
+
omissions: [
|
|
1076
|
+
...edited.omissions,
|
|
1077
|
+
...reducedBy > 0 ? [
|
|
1078
|
+
{
|
|
1079
|
+
path: "/ai/content",
|
|
1080
|
+
reason: "truncated",
|
|
1081
|
+
count: reducedBy
|
|
1082
|
+
}
|
|
1083
|
+
] : []
|
|
1084
|
+
],
|
|
1085
|
+
provenance: [
|
|
1086
|
+
...edited.provenance.slice(0, -1),
|
|
1087
|
+
{
|
|
1088
|
+
kind: "ai",
|
|
1089
|
+
operationId: identity.requestId,
|
|
1090
|
+
description: `AI preparation of ${source.sourceId}@${source.sourceRevision}; source omissions remain separately recorded.`
|
|
1091
|
+
}
|
|
1092
|
+
]
|
|
1093
|
+
});
|
|
1094
|
+
}
|
|
1095
|
+
function assertCoherent(snapshot, draft) {
|
|
1096
|
+
if (!isDeepFrozen(snapshot) || !isDeepFrozen(draft))
|
|
1097
|
+
throw new Error(
|
|
1098
|
+
"Alchemy requires the deeply frozen Snapshot and Draft produced by @ai-matrx/kit/content-transfer."
|
|
1099
|
+
);
|
|
1100
|
+
if (draft.snapshotId !== snapshot.id || draft.sourceId !== snapshot.sourceId || draft.sourceRevision !== snapshot.revision)
|
|
1101
|
+
throw new Error(
|
|
1102
|
+
"The prepared draft does not belong to this captured snapshot."
|
|
1103
|
+
);
|
|
1104
|
+
}
|
|
1105
|
+
function assertIdentitySource(identity, source) {
|
|
1106
|
+
if (!isDeepFrozen(source))
|
|
1107
|
+
throw new Error(
|
|
1108
|
+
"Alchemy recovery requires the deeply frozen Draft produced by @ai-matrx/kit/content-transfer."
|
|
1109
|
+
);
|
|
1110
|
+
if (identity.snapshotId !== source.snapshotId || identity.sourceId !== source.sourceId || identity.sourceRevision !== source.sourceRevision || identity.draftRevision !== source.revision) {
|
|
1111
|
+
throw new Error(
|
|
1112
|
+
"The recovery identity does not belong to this frozen prepared draft."
|
|
1113
|
+
);
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
function errorMessage(error) {
|
|
1117
|
+
return error instanceof Error && error.message ? error.message : "Unknown stream failure.";
|
|
1118
|
+
}
|
|
1119
|
+
function detached(identity, message) {
|
|
1120
|
+
return { status: "detached", identity, draft: null, message };
|
|
1121
|
+
}
|
|
1122
|
+
async function consume(handle, afterAwait, onEvent) {
|
|
1123
|
+
for await (const event of handle.events) {
|
|
1124
|
+
afterAwait();
|
|
1125
|
+
onEvent?.(event);
|
|
1126
|
+
}
|
|
1127
|
+
afterAwait();
|
|
1128
|
+
}
|
|
1129
|
+
function createMatrxContentTransferAdapter(options) {
|
|
1130
|
+
let latestGeneration = 0;
|
|
1131
|
+
const transport = () => resolve(options.transport);
|
|
1132
|
+
const organizationId = () => resolve(options.organizationId);
|
|
1133
|
+
let activeGeneration = null;
|
|
1134
|
+
const inGeneration = async (outer, run) => {
|
|
1135
|
+
activeGeneration?.abort();
|
|
1136
|
+
const controller = new AbortController();
|
|
1137
|
+
activeGeneration = controller;
|
|
1138
|
+
const generation = ++latestGeneration;
|
|
1139
|
+
const abort = () => controller.abort(outer?.reason);
|
|
1140
|
+
if (outer?.aborted) abort();
|
|
1141
|
+
else outer?.addEventListener("abort", abort, { once: true });
|
|
1142
|
+
try {
|
|
1143
|
+
return await run(generation, controller.signal);
|
|
1144
|
+
} finally {
|
|
1145
|
+
outer?.removeEventListener("abort", abort);
|
|
1146
|
+
if (activeGeneration === controller) activeGeneration = null;
|
|
1147
|
+
}
|
|
1148
|
+
};
|
|
1149
|
+
const check = (generation) => {
|
|
1150
|
+
if (generation !== latestGeneration) throw new SupersededRunError();
|
|
1151
|
+
activeGeneration?.signal.throwIfAborted();
|
|
1152
|
+
};
|
|
1153
|
+
const readVisibleAssistant = async (identity, generation) => {
|
|
1154
|
+
const requestResult = await options.supabase.schema("chat").from("request").select("id, metadata, iteration").eq("user_request_id", identity.requestId).eq("conversation_id", identity.conversationId).is("deleted_at", null).not("metadata->>response_message_id", "is", null).order("iteration", { ascending: false }).limit(1);
|
|
1155
|
+
check(generation);
|
|
1156
|
+
if (requestResult.error)
|
|
1157
|
+
throw new Error(
|
|
1158
|
+
requestResult.error.message || "Could not read the persisted AI request."
|
|
1159
|
+
);
|
|
1160
|
+
const messageId = responseMessageId(requestResult.data?.[0]?.metadata);
|
|
1161
|
+
if (!messageId)
|
|
1162
|
+
throw new Error(
|
|
1163
|
+
"The completed AI request has no persisted response message link yet."
|
|
1164
|
+
);
|
|
1165
|
+
const messageResult = await options.supabase.schema("chat").from("message").select("id, content").eq("id", messageId).eq("conversation_id", identity.conversationId).eq("role", "assistant").is("deleted_at", null).eq("is_visible_to_user", true).limit(1);
|
|
1166
|
+
check(generation);
|
|
1167
|
+
if (messageResult.error)
|
|
1168
|
+
throw new Error(
|
|
1169
|
+
messageResult.error.message || "Could not read the prepared AI result."
|
|
1170
|
+
);
|
|
1171
|
+
const exact = messageResult.data?.find((row) => row.id === messageId);
|
|
1172
|
+
return exact ? visibleAssistantText(exact.content) : null;
|
|
1173
|
+
};
|
|
1174
|
+
const locate = async (identity, generation, signal) => {
|
|
1175
|
+
const result = await getRuntimeOperationStatus(
|
|
1176
|
+
transport(),
|
|
1177
|
+
identity.requestId,
|
|
1178
|
+
signal ? { signal } : {}
|
|
1179
|
+
);
|
|
1180
|
+
check(generation);
|
|
1181
|
+
const exact = result?.operations.find(
|
|
1182
|
+
(operation) => operation.request_id === identity.requestId && operation.link_kind === "conversation" && operation.link_id === identity.conversationId
|
|
1183
|
+
) ?? null;
|
|
1184
|
+
if (!exact && result?.operation_count)
|
|
1185
|
+
throw new Error(
|
|
1186
|
+
"The durable operation identity does not match this stored conversation."
|
|
1187
|
+
);
|
|
1188
|
+
return exact;
|
|
1189
|
+
};
|
|
1190
|
+
const recoverInGeneration = async (generation, identity, source, onProgress, signal) => {
|
|
1191
|
+
try {
|
|
1192
|
+
assertIdentitySource(identity, source);
|
|
1193
|
+
check(generation);
|
|
1194
|
+
let operation = await locate(identity, generation, signal);
|
|
1195
|
+
if (!operation)
|
|
1196
|
+
return {
|
|
1197
|
+
status: "unavailable",
|
|
1198
|
+
identity,
|
|
1199
|
+
draft: null,
|
|
1200
|
+
message: "The durable operation is not available to this account yet."
|
|
1201
|
+
};
|
|
1202
|
+
let resolvedIdentity = deepFreeze({
|
|
1203
|
+
...identity,
|
|
1204
|
+
executionId: operation.execution_id
|
|
1205
|
+
});
|
|
1206
|
+
if (!operation.is_terminal) {
|
|
1207
|
+
onProgress?.({ ...resolvedIdentity, status: operation.status });
|
|
1208
|
+
const settled = await followRuntimeOperationToEnd(
|
|
1209
|
+
transport(),
|
|
1210
|
+
operation.execution_id,
|
|
1211
|
+
{
|
|
1212
|
+
...signal ? { signal } : {},
|
|
1213
|
+
lastEventSeq: operation.last_event_seq,
|
|
1214
|
+
onEvent: (event, seq) => {
|
|
1215
|
+
if (generation !== latestGeneration || signal?.aborted) return;
|
|
1216
|
+
options.onRuntimeEvent?.(event, seq);
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
);
|
|
1220
|
+
check(generation);
|
|
1221
|
+
if (!settled.ended || settled.status === null)
|
|
1222
|
+
return detached(
|
|
1223
|
+
resolvedIdentity,
|
|
1224
|
+
"The lifecycle stream detached; the operation remains recoverable from this request."
|
|
1225
|
+
);
|
|
1226
|
+
const refreshed = await locate(identity, generation, signal);
|
|
1227
|
+
if (!refreshed)
|
|
1228
|
+
return detached(
|
|
1229
|
+
resolvedIdentity,
|
|
1230
|
+
"The settled operation is temporarily unavailable; retry recovery with this request."
|
|
1231
|
+
);
|
|
1232
|
+
operation = refreshed;
|
|
1233
|
+
resolvedIdentity = deepFreeze({
|
|
1234
|
+
...identity,
|
|
1235
|
+
executionId: operation.execution_id
|
|
1236
|
+
});
|
|
1237
|
+
}
|
|
1238
|
+
onProgress?.({ ...resolvedIdentity, status: operation.status });
|
|
1239
|
+
if (operation.status === "cancelled")
|
|
1240
|
+
return {
|
|
1241
|
+
status: "cancelled",
|
|
1242
|
+
identity: resolvedIdentity,
|
|
1243
|
+
draft: null,
|
|
1244
|
+
message: "The AI preparation was cancelled. Any partial output was not applied."
|
|
1245
|
+
};
|
|
1246
|
+
if (operation.status !== "completed")
|
|
1247
|
+
return {
|
|
1248
|
+
status: "failed",
|
|
1249
|
+
identity: resolvedIdentity,
|
|
1250
|
+
draft: null,
|
|
1251
|
+
message: typeof operation.error?.message === "string" ? operation.error.message : "The AI preparation did not complete."
|
|
1252
|
+
};
|
|
1253
|
+
const text = await readVisibleAssistant(resolvedIdentity, generation);
|
|
1254
|
+
check(generation);
|
|
1255
|
+
if (!text)
|
|
1256
|
+
return {
|
|
1257
|
+
status: "unavailable",
|
|
1258
|
+
identity: resolvedIdentity,
|
|
1259
|
+
draft: null,
|
|
1260
|
+
message: "The exact persisted assistant result is not visible yet."
|
|
1261
|
+
};
|
|
1262
|
+
const draft = draftFromAssistant(source, text, resolvedIdentity);
|
|
1263
|
+
check(generation);
|
|
1264
|
+
return {
|
|
1265
|
+
status: "completed",
|
|
1266
|
+
identity: resolvedIdentity,
|
|
1267
|
+
draft,
|
|
1268
|
+
message: null
|
|
1269
|
+
};
|
|
1270
|
+
} catch (error) {
|
|
1271
|
+
return detached(
|
|
1272
|
+
identity,
|
|
1273
|
+
error instanceof SupersededRunError ? error.message : `Recovery detached: ${errorMessage(error)} You can retry with this request.`
|
|
1274
|
+
);
|
|
1275
|
+
}
|
|
1276
|
+
};
|
|
1277
|
+
return {
|
|
1278
|
+
async launch(input) {
|
|
1279
|
+
return inGeneration(input.signal, async (generation, signal) => {
|
|
1280
|
+
assertCoherent(input.snapshot, input.draft);
|
|
1281
|
+
const conversation = newStoredConversationStart();
|
|
1282
|
+
input.onProgress?.({
|
|
1283
|
+
requestId: null,
|
|
1284
|
+
conversationId: conversation.conversation_id,
|
|
1285
|
+
executionId: null,
|
|
1286
|
+
status: "starting"
|
|
1287
|
+
});
|
|
1288
|
+
const preparedContent = serialize(input.draft, "markdown").plainText;
|
|
1289
|
+
let identity = null;
|
|
1290
|
+
try {
|
|
1291
|
+
const handle = await startMandateRun(
|
|
1292
|
+
transport(),
|
|
1293
|
+
MANDATE_KEYS.alchemy__prepare_content,
|
|
1294
|
+
{
|
|
1295
|
+
...conversation,
|
|
1296
|
+
organization_id: organizationId(),
|
|
1297
|
+
source_app: options.sourceApp,
|
|
1298
|
+
source_feature: `mandate:${MANDATE_KEYS.alchemy__prepare_content}`,
|
|
1299
|
+
user_input: input.instruction,
|
|
1300
|
+
variables: {
|
|
1301
|
+
prepared_content: preparedContent,
|
|
1302
|
+
content_label: input.snapshot.label,
|
|
1303
|
+
coverage_description: descriptionForCoverage(
|
|
1304
|
+
input.snapshot,
|
|
1305
|
+
input.draft
|
|
1306
|
+
),
|
|
1307
|
+
omission_description: descriptionForOmissions(input.draft)
|
|
1308
|
+
}
|
|
1309
|
+
},
|
|
1310
|
+
{ signal }
|
|
1311
|
+
);
|
|
1312
|
+
if (!handle.requestId)
|
|
1313
|
+
throw new Error(
|
|
1314
|
+
"The Matrx server did not return X-Request-ID for the preparation run."
|
|
1315
|
+
);
|
|
1316
|
+
identity = deepFreeze({
|
|
1317
|
+
requestId: handle.requestId,
|
|
1318
|
+
conversationId: handle.conversationId ?? conversation.conversation_id,
|
|
1319
|
+
executionId: null,
|
|
1320
|
+
snapshotId: input.snapshot.id,
|
|
1321
|
+
sourceId: input.draft.sourceId,
|
|
1322
|
+
sourceRevision: input.draft.sourceRevision,
|
|
1323
|
+
draftRevision: input.draft.revision
|
|
1324
|
+
});
|
|
1325
|
+
assertIdentitySource(identity, input.draft);
|
|
1326
|
+
check(generation);
|
|
1327
|
+
input.onProgress?.({ ...identity, status: "streaming" });
|
|
1328
|
+
await consume(handle, () => check(generation), options.onStreamEvent);
|
|
1329
|
+
check(generation);
|
|
1330
|
+
const result = await recoverInGeneration(
|
|
1331
|
+
generation,
|
|
1332
|
+
identity,
|
|
1333
|
+
input.draft,
|
|
1334
|
+
input.onProgress,
|
|
1335
|
+
signal
|
|
1336
|
+
);
|
|
1337
|
+
check(generation);
|
|
1338
|
+
return result;
|
|
1339
|
+
} catch (error) {
|
|
1340
|
+
if (!identity) throw error;
|
|
1341
|
+
return detached(
|
|
1342
|
+
identity,
|
|
1343
|
+
error instanceof SupersededRunError ? error.message : `The local stream detached after the server accepted the request: ${errorMessage(error)} Server work was not cancelled; retry recovery with this request.`
|
|
1344
|
+
);
|
|
1345
|
+
}
|
|
1346
|
+
});
|
|
1347
|
+
},
|
|
1348
|
+
async recover(identity, source, onProgress, signal) {
|
|
1349
|
+
return inGeneration(signal, async (generation, signal2) => {
|
|
1350
|
+
assertIdentitySource(identity, source);
|
|
1351
|
+
const result = await recoverInGeneration(
|
|
1352
|
+
generation,
|
|
1353
|
+
identity,
|
|
1354
|
+
source,
|
|
1355
|
+
onProgress,
|
|
1356
|
+
signal2
|
|
1357
|
+
);
|
|
1358
|
+
return generation === latestGeneration ? result : detached(
|
|
1359
|
+
identity,
|
|
1360
|
+
"A newer AI preparation started before this result settled."
|
|
1361
|
+
);
|
|
1362
|
+
});
|
|
1363
|
+
},
|
|
1364
|
+
async rejoin(identity, source, onProgress, signal) {
|
|
1365
|
+
return inGeneration(signal, async (generation, signal2) => {
|
|
1366
|
+
assertIdentitySource(identity, source);
|
|
1367
|
+
try {
|
|
1368
|
+
const handle = await rejoinRuntimeOperation(
|
|
1369
|
+
transport(),
|
|
1370
|
+
identity.requestId,
|
|
1371
|
+
signal2 ? { signal: signal2 } : {}
|
|
1372
|
+
);
|
|
1373
|
+
check(generation);
|
|
1374
|
+
await consume(handle, () => check(generation), options.onStreamEvent);
|
|
1375
|
+
check(generation);
|
|
1376
|
+
} catch (error) {
|
|
1377
|
+
if (!(error instanceof MatrxApiError && error.status === 409))
|
|
1378
|
+
return detached(
|
|
1379
|
+
identity,
|
|
1380
|
+
error instanceof SupersededRunError ? error.message : `Live rejoin detached: ${errorMessage(error)} You can retry durable recovery with this request.`
|
|
1381
|
+
);
|
|
1382
|
+
}
|
|
1383
|
+
const result = await recoverInGeneration(
|
|
1384
|
+
generation,
|
|
1385
|
+
identity,
|
|
1386
|
+
source,
|
|
1387
|
+
onProgress,
|
|
1388
|
+
signal2
|
|
1389
|
+
);
|
|
1390
|
+
return generation === latestGeneration ? result : detached(
|
|
1391
|
+
identity,
|
|
1392
|
+
"A newer AI preparation started before this result settled."
|
|
1393
|
+
);
|
|
1394
|
+
});
|
|
1395
|
+
},
|
|
1396
|
+
cancel(requestId) {
|
|
1397
|
+
return cancelAgentRun(transport(), requestId);
|
|
1398
|
+
}
|
|
1399
|
+
};
|
|
1400
|
+
}
|
|
1401
|
+
export {
|
|
1402
|
+
createMatrxContentTransferAdapter
|
|
1403
|
+
};
|
|
1404
|
+
//# sourceMappingURL=index.js.map
|