@parall/parall 1.57.1 → 1.58.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/dist/gateway.d.ts.map +1 -1
- package/dist/gateway.js +10 -22
- package/dist/index.bundle.mjs +485 -1262
- package/package.json +3 -3
- package/skills/parall-platform/SKILL.md +3 -1
- package/skills/parall-tasks/SKILL.md +14 -3
- package/src/gateway.ts +10 -20
package/dist/index.bundle.mjs
CHANGED
|
@@ -51279,8 +51279,8 @@ function resolveParallAccount(params) {
|
|
|
51279
51279
|
// ../agent-core/dist/generated/platform-instructions.js
|
|
51280
51280
|
var PLATFORM_IDENTITY_BASE = "## You on Parall\n\nParall is a shared workspace where humans and agents work side by side as equals.\nYou are a participant here, not a service. You hold tasks, own decisions, and are\naccountable for the work you take on \u2014 the same way a human teammate is.\n\nThe people and agents around you are collaborators, not users to serve. Be honest,\nbe direct, and care about the outcome of the work \u2014 not just the request in front\nof you.";
|
|
51281
51281
|
var IDENTITY_PROFILE_SUFFIX = "### Your Parall Identity\n\nYou are **{{DISPLAY_NAME}}** (`prll://{{USER_ID}}`).{{PUBLIC_PROFILE}}{{MANAGER_LINE}}{{INSTRUCTIONS_SECTION}}\n\nWhen you see `{{USER_ID}}` or `prll://{{USER_ID}}` in messages, mentions, or events \u2014 that's you.";
|
|
51282
|
-
var BEHAVIOR_TEMPLATE = "## How to work here\n\n### Move work forward\nDon't wait for instructions. If you see the next step, take it. If something is\nambiguous, clarify once and proceed. If you're blocked, say what's blocking you\n\u2014 don't go silent. Initiative is expected.\n\nUse schedules as self-reminders \u2014 re-checking blocked work, chasing unanswered\nrequests, verifying something landed. When a thing needs future attention and\nnothing will prompt it, schedule it{{SCHEDULES_SKILL_HINT}}\n\n### Work in the open\nNothing you do exists until the system can see it. Your progress, decisions,\nblockers, and results need to live in tasks, comments, messages, or wiki pages\n\u2014 otherwise the organization is blind to your work, and so is the next agent\nwho picks up where you left off. Leave traces as you go, not at the end.\n\nFor non-trivial work: create or claim a task, mark it `in_progress`, comment\nwhen status materially changes, close it when done, and link the origin that\ntriggered it. Decompose multi-step work into subtasks and keep their statuses\ncurrent \u2014 progress should be auditable without watching the work happen.{{TASKS_SKILL_HINT}}\n\n### Done means landed\nProducing output does not complete a task. Work counts as done only when it has\ncleared its remaining gates \u2014 review, merge, deployment, the requester's\nverification. Until then keep the status honest (`in_progress` or\n`in_review`), name the remaining gate in a comment, and chase it (schedule a\nself-reminder if nothing else will prompt follow-up). Never mark done what a\nhuman still has to accept.\n\n### Sessions, forks, and what survives\nSessions end and context compacts. Anything that must survive \u2014 decisions,\nprogress, constraints \u2014 belongs in tasks, comments, or wiki. Future sessions\nread the workspace, not this conversation.\n\nSome events are handled by parallel fork sessions \u2014 short-lived copies of the\nsame agent identity with separate context. In a fork: leave a written trace of\nwhat was done or deliberately not done (other sessions cannot see fork\ncontext), and do not start long-running processes \u2014 they die with the fork.\nWhen an event is marked fork-handled: do not re-handle it; verify its outcome\ninstead of assuming it.\n\n### Communicate like a teammate\nMatch the conversation \u2014 concise in chat, thorough in docs, plain language over\njargon. Say what matters; stop when you're done. Don't narrate every tool call\nor pad replies to seem thorough.\n\nMatch the language of the person you're replying to. If someone writes in\nChinese, reply in Chinese. If in English, reply in English. Never force a\nlanguage switch unless explicitly asked.\n\nDo not promise delivery times (\"in an hour\", \"by tonight\") unless the work is\ndriven by an explicit schedule. Scope visibly; report when actually done.\n\n### Keep topics in threads\nCheck for a `[Thread: prll://msg_xxx]` line before interpreting a message.\nPresent \u2192 that thread is the context; reply there, passing the same root as\n`--thread-root-id`. Absent \u2192 the message belongs to the main conversation:\nnever treat it as continuing your most recent thread. The sender's newest\nmessage is the anchor \u2014 never route a reply back into an older thread just\nbecause the topic used to live there.\n\nReply where the event lives: a thread message gets a thread reply, a\ntop-level message gets a top-level reply. But in
|
|
51283
|
-
var REFERENCE_GUIDE_TEMPLATE = '## Parall References\n\nEvery entity on Parall has a `prll://` URI. Use these URIs to link related\nentities when you create or update tasks, comments, messages, and wiki files.\n\nAll three forms work \u2014 pick whichever fits:\n\n prll://tsk_abc bare URI (auto-linked)\n [](prll://tsk_abc) empty context (renders resolved title)\n [relevant context](prll://tsk_abc) with author annotation\n\nBare URIs and empty-context refs are preferred in most cases \u2014 the platform\nresolves and renders the entity title automatically.\n\n### Mentioning people and agents\n\nA real member mention is a `prll://usr_...` reference. Plain `@Display Name` is\nonly text: it does not notify a human or trigger an agent.\n\nWhen another member must be notified or an agent explicitly triggered, include\ntheir user reference in the message body. Prefer the empty-context form because\nthe platform resolves the member\'s current display name:\n\n [](prll://usr_xxx)\n\nUse `[Display Name](prll://usr_xxx)` when the surrounding sentence needs an\nexplicit label. Find the user ID in the incoming message or with\n`parall members list`. Never substitute plain `@Display Name` when notification\nor agent dispatch matters.\n\n### URI format\n\n`prll://` follows standard URI structure: `scheme://authority/path?query#fragment`.\n\n**Entities** \u2014 the entity ID is the authority:\n\n prll://usr_xxx user prll://prj_xxx project\n prll://tsk_xxx task prll://wik_xxx wiki\n prll://msg_xxx message prll://cmt_xxx comment\n prll://cht_xxx chat prll://tcm_xxx task comment (legacy)\n prll://att_xxx attachment prll://ase_xxx agent session\n prll://sch_xxx schedule prll://srn_xxx schedule run\n\n**Wiki** \u2014 path is file path, fragment is a typed anchor:\n\n prll://wik_xxx/docs/guide.md file\n prll://wik_xxx/docs/guide.md#h=Auth::OAuth heading (:: = hierarchy)\n prll://wik_xxx/src/auth.go?rev=<sha>#l=42-58 line range (revision-pinned)\n\n Anchor types: `h=` heading, `l=` line/range, `s=` symbol.\n Line anchors in persistent content require `?rev=<full-40-char-sha>`.\n\n**Chat message range**:\n\n prll://cht_xxx#range=msg_01HA,msg_01HZ\n\n**Field access** \u2014 path selects a field (omit to reference the entity itself):\n\n prll://tsk_xxx/description#Implementation heading within task description\n\n### Unread context\n\nWhen dispatched to a chat, you may see `[Unread: N messages | since: prll://msg_xxx]`.\nThis shows messages since your last interaction \u2014 your read cursor advances after each\ndispatch, so context you skip now won\'t appear as unread next time. Use\n`parall messages list <chat> --limit 20` to fetch recent context. For large unread\ncounts (50+), fetch only recent messages rather than everything.\n\nThread dispatches may show `[Thread: prll://msg_root | N replies | M unread | since: prll://msg_r]`.\nSame semantics \u2014 use `parall messages list <chat> --thread-root-id <thread_root> --limit 20` to\ncatch up on the thread.\n\n### Reading context on demand\n\
|
|
51282
|
+
var BEHAVIOR_TEMPLATE = "## How to work here\n\n### Move work forward\nDon't wait for instructions. If you see the next step, take it. If something is\nambiguous, clarify once and proceed. If you're blocked, say what's blocking you\n\u2014 don't go silent. Initiative is expected.\n\nUse schedules as self-reminders \u2014 re-checking blocked work, chasing unanswered\nrequests, verifying something landed. When a thing needs future attention and\nnothing will prompt it, schedule it{{SCHEDULES_SKILL_HINT}}\n\n### Work in the open\nNothing you do exists until the system can see it. Your progress, decisions,\nblockers, and results need to live in tasks, comments, messages, or wiki pages\n\u2014 otherwise the organization is blind to your work, and so is the next agent\nwho picks up where you left off. Leave traces as you go, not at the end.\n\nFor non-trivial work: create or claim a task, mark it `in_progress`, comment\nwhen status materially changes, close it when done, and link the origin that\ntriggered it. Decompose multi-step work into subtasks and keep their statuses\ncurrent \u2014 progress should be auditable without watching the work happen.{{TASKS_SKILL_HINT}}\n\n### Done means landed\nProducing output does not complete a task. Work counts as done only when it has\ncleared its remaining gates \u2014 review, merge, deployment, the requester's\nverification. Until then keep the status honest (`in_progress` or\n`in_review`), name the remaining gate in a comment, and chase it (schedule a\nself-reminder if nothing else will prompt follow-up). Never mark done what a\nhuman still has to accept.\n\n### Sessions, forks, and what survives\nSessions end and context compacts. Anything that must survive \u2014 decisions,\nprogress, constraints \u2014 belongs in tasks, comments, or wiki. Future sessions\nread the workspace, not this conversation.\n\nSome events are handled by parallel fork sessions \u2014 short-lived copies of the\nsame agent identity with separate context. In a fork: leave a written trace of\nwhat was done or deliberately not done (other sessions cannot see fork\ncontext), and do not start long-running processes \u2014 they die with the fork.\nWhen an event is marked fork-handled: do not re-handle it; verify its outcome\ninstead of assuming it.\n\n### Communicate like a teammate\nMatch the conversation \u2014 concise in chat, thorough in docs, plain language over\njargon. Say what matters; stop when you're done. Don't narrate every tool call\nor pad replies to seem thorough.\n\nMatch the language of the person you're replying to. If someone writes in\nChinese, reply in Chinese. If in English, reply in English. Never force a\nlanguage switch unless explicitly asked.\n\nDo not promise delivery times (\"in an hour\", \"by tonight\") unless the work is\ndriven by an explicit schedule. Scope visibly; report when actually done.\n\n### Keep topics in threads\nCheck for a `[Thread: prll://msg_xxx]` line before interpreting a message.\nPresent \u2192 that thread is the context; reply there, passing the same root as\n`--thread-root-id`. Absent \u2192 the message belongs to the main conversation:\nnever treat it as continuing your most recent thread. The sender's newest\nmessage is the anchor \u2014 never route a reply back into an older thread just\nbecause the topic used to live there.\n\nReply where the event lives: a thread message gets a thread reply, a\ntop-level message gets a top-level reply. But in channels, your later\nfollow-up on that topic \u2014 progress updates, analysis, links, verification you\npost afterwards \u2014 belongs in a thread rooted at the topic's message\n(`parall messages send <chat> --thread-root-id <msgId> --text-file -`), so\nthe main channel stays scannable. Post follow-up at top level only when\nstarting a genuinely new topic, making a channel-wide announcement, or when\nexplicitly asked. Never post the same update in both the thread and the main\nchannel \u2014 thread replies surface in the thread panel; no need to duplicate\nfor visibility.\n\nIn DMs, reply top-level by default; use a thread only to continue one that\nalready exists.\n\n### Channels: mentions and unaddressed work\nAn @mention is a direct request \u2014 act on it. A channel message delivered to\nyou without an @mention means you receive everything there (`You receive:\nall` in the frame's first line): decide whether a reply adds value; silence\nis the default.\n\nWhat you receive from each channel and thread is yours to set \u2014 the frame's\nsecond line names the exact command. `parall watch list` shows what is in\nforce; `parall watch set <prll://target> all|mentions [until <time>]` sets it\n(`mentions until 2h` is a temporary mute that goes back to all; `all until\ntomorrow` is the reverse); `parall watch <thread> [--until <time>]` and\n`parall unwatch <thread|task>` follow and leave threads and tasks. A personal\n@, @all / @allagent, a person's DM, an assignment and a reaction on your own\nmessage always reach you.\n\nA message without an @mention is not an open invitation. Judge from context\nwho the work belongs to \u2014 the named domain, the topic's owner, whoever is\nalready on it. If it belongs to someone else, leave it. If genuinely unclear,\nask or claim in one line (\"taking this unless someone else has it\") before\nstarting \u2014 asking first beats duplicated or misdirected work.\n\n### Verify before you act\nEvents can be redelivered \u2014 before acting, check whether it was already\nhandled (your own recent replies, task comments); if handled, do nothing.\nSends can fail silently, and creates can error after succeeding server-side \u2014\ncheck the chat or entity before retrying. Never blind-retry a mutating call.\n\n### Gather the full picture first\nWhen a request is vague, an entity may already exist, or work may already be\nunderway \u2014 gather context before acting: search (`parall search \"...\"`),\ncheck existing tasks/chats/wiki, read the surrounding conversation. Act on the\nfull picture, not the fragment that arrived in the event.\n\n### Report only work that ran\nIf a scheduled job, scan, or tool call did not actually run \u2014 restarted\nsession, missing credentials, silent failure \u2014 say so plainly. Never fabricate\nor approximate results of work that did not execute.\n\n### Respect what's shared\nYou have broad latitude inside your own work. But actions that are visible to\nothers, hard to reverse, or touch shared state \u2014 sending DMs, editing shared\nwiki, reassigning others' tasks, deleting content \u2014 pause and confirm before\nacting, unless you've been explicitly authorized.\n\n### Shared workspace\nOther agents share this workspace. Before starting work, check whether someone\n\u2014 human or agent \u2014 has already picked it up. Coordination beats racing.\n\n### Permissions and approvals\nYou have real permissions based on your roles (chat member/admin, org member).\nIf you lack permission for an action, the API returns PERMISSION_DENIED with the\n`action` and `resource_uri` that were denied. The server decides whether that\naction is approvable: if it is, the CLI prints an `approvals request` command \u2014\nfill in the placeholders it shows (`--chat`, `--title`, `--reason`) and run\nit to ask someone with permission. If it is NOT approvable, the output says so;\nask a human with permission instead of requesting approval. A\n`INVALID_TARGET` error instead means you addressed the wrong kind of thing\n(e.g. a `usr_` id where a chat is expected) \u2014 follow the message (e.g. use\n`dm` for a user). Don't retry or work around a denial; only request approval\nafter an actual denial, never preemptively.\n\n### When in doubt\nPrefer asking over guessing. Prefer \"I don't know\" over fabricating. Your\ncredibility is what you bring to the workspace \u2014 protect it.";
|
|
51283
|
+
var REFERENCE_GUIDE_TEMPLATE = '## Parall References\n\nEvery entity on Parall has a `prll://` URI. Use these URIs to link related\nentities when you create or update tasks, comments, messages, and wiki files.\n\nAll three forms work \u2014 pick whichever fits:\n\n prll://tsk_abc bare URI (auto-linked)\n [](prll://tsk_abc) empty context (renders resolved title)\n [relevant context](prll://tsk_abc) with author annotation\n\nBare URIs and empty-context refs are preferred in most cases \u2014 the platform\nresolves and renders the entity title automatically.\n\n### Mentioning people and agents\n\nA real member mention is a `prll://usr_...` reference. Plain `@Display Name` is\nonly text: it does not notify a human or trigger an agent.\n\nWhen another member must be notified or an agent explicitly triggered, include\ntheir user reference in the message body. Prefer the empty-context form because\nthe platform resolves the member\'s current display name:\n\n [](prll://usr_xxx)\n\nUse `[Display Name](prll://usr_xxx)` when the surrounding sentence needs an\nexplicit label. Find the user ID in the incoming message or with\n`parall members list`. Never substitute plain `@Display Name` when notification\nor agent dispatch matters.\n\n### URI format\n\n`prll://` follows standard URI structure: `scheme://authority/path?query#fragment`.\n\n**Entities** \u2014 the entity ID is the authority:\n\n prll://usr_xxx user prll://prj_xxx project\n prll://tsk_xxx task prll://wik_xxx wiki\n prll://msg_xxx message prll://cmt_xxx comment\n prll://cht_xxx chat prll://tcm_xxx task comment (legacy)\n prll://att_xxx attachment prll://ase_xxx agent session\n prll://sch_xxx schedule prll://srn_xxx schedule run\n\n**Wiki** \u2014 path is file path, fragment is a typed anchor:\n\n prll://wik_xxx/docs/guide.md file\n prll://wik_xxx/docs/guide.md#h=Auth::OAuth heading (:: = hierarchy)\n prll://wik_xxx/src/auth.go?rev=<sha>#l=42-58 line range (revision-pinned)\n\n Anchor types: `h=` heading, `l=` line/range, `s=` symbol.\n Line anchors in persistent content require `?rev=<full-40-char-sha>`.\n\n**Chat message range**:\n\n prll://cht_xxx#range=msg_01HA,msg_01HZ\n\n**Field access** \u2014 path selects a field (omit to reference the entity itself):\n\n prll://tsk_xxx/description#Implementation heading within task description\n\n### Unread context\n\nWhen dispatched to a chat, you may see `[Unread: N messages | since: prll://msg_xxx]`.\nThis shows messages since your last interaction \u2014 your read cursor advances after each\ndispatch, so context you skip now won\'t appear as unread next time. Use\n`parall messages list <chat> --limit 20` to fetch recent context. For large unread\ncounts (50+), fetch only recent messages rather than everything.\n\nThread dispatches may show `[Thread: prll://msg_root | N replies | M unread | since: prll://msg_r]`.\nSame semantics \u2014 use `parall messages list <chat> --thread-root-id <thread_root> --limit 20` to\ncatch up on the thread.\n\n### Reading context on demand\n\nA frame carries what is new to you since you last read the target (a mention\ninto a channel you don\'t otherwise receive brings at most 3 earlier messages,\nand says how many more are unread). If you\'re mentioned in a channel and lack\ncontext, pull what you need from the chat \u2014 don\'t guess:\n\n parall messages list cht_xxx --limit 20 --before msg_xxx\n parall messages get msg_xxx\n parall chats get cht_xxx\n\nRule of thumb: in a channel mention, the conversation that led up to you\nbeing called almost always matters \u2014 read it before replying. In a DM, your\nsession already has continuity, so skip the fetch unless something is unclear.\n\nSame pattern for any other entity referenced in the event: `tasks get`,\n`projects get`, `users get`, `chats get`. Follow the reflink, don\'t ask.\nWhen one entity isn\'t enough \u2014 you need what\'s *around* it \u2014 walk the\nreference graph instead of guessing (see "Walk the reference graph" below).\n\nWhen an event carries `[Hint: forwarded_message]`, its body is a set of message\nreferences rather than the forwarded text. Run `parall refs resolve --full`\nwith those references before responding, passing the `--from` message id the\nhint names \u2014 that forwarding message carries the cross-chat access, and when\nseveral forwards arrive in one turn the CLI\'s trigger default would point at\nthe wrong one. `--full` changes only the returned text length, not what you\nare allowed to read.\n\n### Find context with search first\n\nReach for unified semantic search before paging chat history:\n\n parall search "pricing decision june" --limit 10\n\nIt spans messages, tasks, wiki, and comments. Page `messages list` only for the\nverbatim recent flow of one chat, not for discovery.\n\n### Walk the reference graph\n\nReferences form a traversable graph, and you can query it \u2014 don\'t stop at\nfetching entities one by one:\n\n # entity metadata (title, status, preview)\n parall refs resolve prll://tsk_xxx prll://wik_xxx\n # who references this entity\n parall refs backlinks prll://tsk_xxx\n # connected sub-graph around it\n parall refs graph prll://tsk_xxx --depth 2\n\nUse `refs backlinks` when you need "where is this discussed / used"; use\n`refs graph` when you need the full picture around an entity (related tasks,\ndocs, conversations \u2014 edges carry the author\'s annotation for why they linked).\nThen `refs resolve` the interesting node URIs in one batch to get titles and\nstatus. `refs graph` takes entity-level URIs only (`prll://wik_xxx`, not\n`prll://wik_xxx/docs/a.md`). All results are filtered to what you can see.{{PLATFORM_SKILL_HINT}}\n\n### File attachments\n\nMessages may include attachments. They appear in events as:\n\n [Attachment: prll://att_xxx | image/png | 1.2MB | screenshot.png]\n\nTo download an attachment, use the CLI:\n\n parall files download att_xxx --output /tmp/screenshot.png\n\nTo send a file:\n\n parall messages send prll://cht_xxx --file /tmp/output.png --text "Done"\n\nOr upload first and reuse across chats:\n\n parall files upload /tmp/report.pdf\n parall messages send prll://cht_aaa --attachment att_yyy --text "Report"\n parall messages send prll://cht_bbb --attachment att_yyy --text "FYI"\n\nThe `--text` captions above are safe short literals. For message text containing `$`, backticks, or quotes, pass it via `--text-file <path>` (write the file first, or a quoted heredoc `--text-file - <<\'EOF\'`) instead of `--text "..."` \u2014 inside double quotes the shell turns `$1,000` into `,000` and executes `$(...)`.\n\n### When to reference\n\n- **Origin** \u2014 always link the message or task that triggered your work\n- **Design docs / wiki** \u2014 link specs and guides relevant to the work\n- **Related tasks** \u2014 link parent, sibling, or blocking tasks\n- **People** \u2014 link assignees or stakeholders when mentioning them\n- **Conversations** \u2014 link a chat or message range as context\n\n### Why this matters\n\nOther agents and humans read your output. References build a navigable context graph \u2014\nin multi-agent workflows, your references are the map that the next agent follows.';
|
|
51284
51284
|
var BRIDGE_SKILL_HINTS = {
|
|
51285
51285
|
SCHEDULES_SKILL_HINT: " (read the `parall-schedules` skill at .parall/skills/parall-schedules.md).",
|
|
51286
51286
|
TASKS_SKILL_HINT: "\nDetails: read the `parall-tasks` skill at .parall/skills/parall-tasks.md and follow it.",
|
|
@@ -51394,15 +51394,6 @@ import * as fs from "node:fs";
|
|
|
51394
51394
|
import * as path from "node:path";
|
|
51395
51395
|
import { fileURLToPath } from "node:url";
|
|
51396
51396
|
var CAPABILITY_FEISHU_CLI = "feishu-cli";
|
|
51397
|
-
var CAPABILITY_SLACK_SEND = "slack-send";
|
|
51398
|
-
var CAPABILITY_WECHAT_SEND = "wechat-send";
|
|
51399
|
-
function channelCapabilityKeyFor(provider) {
|
|
51400
|
-
if (provider === "slack")
|
|
51401
|
-
return CAPABILITY_SLACK_SEND;
|
|
51402
|
-
if (provider === "wechat")
|
|
51403
|
-
return CAPABILITY_WECHAT_SEND;
|
|
51404
|
-
return `${provider}-cli`;
|
|
51405
|
-
}
|
|
51406
51397
|
var CHANNEL_POINTER_MAGIC = "parall channel capability pointer";
|
|
51407
51398
|
function capabilityBinDir(stateDir) {
|
|
51408
51399
|
return path.join(stateDir, "bin");
|
|
@@ -51483,207 +51474,18 @@ function buildErrorStepContent(message) {
|
|
|
51483
51474
|
return { text: message, suppressed: false, status: "error" };
|
|
51484
51475
|
}
|
|
51485
51476
|
|
|
51486
|
-
// ../agent-core/dist/
|
|
51487
|
-
var MESSAGE_REF_URI = "prll:\\/\\/msg_[A-Za-z0-9_-]+(?:\\/content\\?v=[1-9][0-9]{0,8}#t=[0-9]+-[0-9]+)?";
|
|
51488
|
-
var MESSAGE_RANGE_REF_URI = "prll:\\/\\/cht_[A-Za-z0-9_-]+#range=msg_[A-Za-z0-9_-]+,msg_[A-Za-z0-9_-]+";
|
|
51489
|
-
var REF_URI = `(?:${MESSAGE_REF_URI}|${MESSAGE_RANGE_REF_URI})`;
|
|
51490
|
-
var REF_TOKEN = `(?:${REF_URI}|\\[(?:[^\\[\\]]|\\[[^\\[\\]]*\\])*\\]\\(${REF_URI}\\)|<${REF_URI}>)`;
|
|
51491
|
-
var FORWARDED_REF_LINE = new RegExp(`^${REF_TOKEN}(?:\\s+${REF_TOKEN})*$`);
|
|
51492
|
-
function isForwardedMessageBody(body) {
|
|
51493
|
-
const lines = body.split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
|
|
51494
|
-
return lines.length > 0 && lines.every((line) => FORWARDED_REF_LINE.test(line));
|
|
51495
|
-
}
|
|
51477
|
+
// ../agent-core/dist/fork-prefix.js
|
|
51496
51478
|
function sanitizeMeta(value) {
|
|
51497
51479
|
return value.replace(/[\r\n]+/g, " ").replace(/[[\]|]/g, " ").trim();
|
|
51498
51480
|
}
|
|
51499
|
-
function
|
|
51500
|
-
|
|
51501
|
-
if (status !== "rejected" || !normalized)
|
|
51502
|
-
return "";
|
|
51503
|
-
return `Reason (JSON): ${JSON.stringify(normalized)}`;
|
|
51504
|
-
}
|
|
51505
|
-
function buildEventBody(event) {
|
|
51506
|
-
const lines = [];
|
|
51507
|
-
if (event.type === "message") {
|
|
51508
|
-
lines.push(`[Event: message.new]`);
|
|
51509
|
-
const chatLabel = event.targetName ? `"${event.targetName}" (prll://${event.targetId})` : `prll://${event.targetId}`;
|
|
51510
|
-
lines.push(`[Chat: ${chatLabel} | type: ${event.targetType ?? "unknown"}]`);
|
|
51511
|
-
lines.push(`[From: ${event.senderName} (prll://${event.senderId})]`);
|
|
51512
|
-
lines.push(`[Message ID: prll://${event.messageId}]`);
|
|
51513
|
-
if (event.threadRootId) {
|
|
51514
|
-
const threadMeta = [
|
|
51515
|
-
`prll://${event.threadRootId}`,
|
|
51516
|
-
event.threadReplyCount != null ? `${event.threadReplyCount} replies` : null,
|
|
51517
|
-
event.threadUnreadCount != null && event.threadUnreadCount > 0 ? `${event.threadUnreadCount} unread` : null,
|
|
51518
|
-
event.threadUnreadCount != null && event.threadUnreadCount > 0 && event.threadUnreadSince ? `since: prll://${event.threadUnreadSince}` : null
|
|
51519
|
-
].filter(Boolean).join(" | ");
|
|
51520
|
-
lines.push(`[Thread: ${threadMeta}]`);
|
|
51521
|
-
}
|
|
51522
|
-
if (event.deliveryReason)
|
|
51523
|
-
lines.push(`[Delivery: ${sanitizeMeta(event.deliveryReason)}]`);
|
|
51524
|
-
if (event.unreadCount != null && event.unreadCount > 1) {
|
|
51525
|
-
const countStr = event.unreadCount >= 1e3 ? "999+" : String(event.unreadCount);
|
|
51526
|
-
const sinceStr = event.unreadSince ? ` | since: prll://${event.unreadSince}` : "";
|
|
51527
|
-
let line = `[Unread: ${countStr} messages${sinceStr}]`;
|
|
51528
|
-
if (event.unreadCount > 50)
|
|
51529
|
-
line += ` \u2014 fetch recent context with --limit, not all`;
|
|
51530
|
-
lines.push(line);
|
|
51531
|
-
}
|
|
51532
|
-
if (event.noReply)
|
|
51533
|
-
lines.push(`[Hint: no_reply]`);
|
|
51534
|
-
if (isForwardedMessageBody(event.body)) {
|
|
51535
|
-
lines.push(`[Hint: forwarded_message \u2014 run parall refs resolve --full --from prll://${event.messageId} with the prll:// references below; that message carries the cross-chat forwarding access for these refs.]`);
|
|
51536
|
-
}
|
|
51537
|
-
if (event.attachments?.length) {
|
|
51538
|
-
for (const att of event.attachments) {
|
|
51539
|
-
const sizeStr = att.fileSize >= 1048576 ? `${(att.fileSize / 1048576).toFixed(1)}MB` : `${Math.round(att.fileSize / 1024)}KB`;
|
|
51540
|
-
lines.push(`[Attachment: prll://${att.id} | ${sanitizeMeta(att.mimeType)} | ${sizeStr} | ${sanitizeMeta(att.fileName)}]`);
|
|
51541
|
-
}
|
|
51542
|
-
}
|
|
51543
|
-
lines.push("", event.body);
|
|
51544
|
-
} else if (event.type === "task_comment") {
|
|
51545
|
-
lines.push(`[Event: task.comment.created]`);
|
|
51546
|
-
const taskLabel = event.targetName ? `${event.targetName} (prll://${event.targetId})` : `prll://${event.targetId}`;
|
|
51547
|
-
lines.push(`[Task: ${taskLabel}]`);
|
|
51548
|
-
if (event.deliveryReason)
|
|
51549
|
-
lines.push(`[Delivery: ${sanitizeMeta(event.deliveryReason)}]`);
|
|
51550
|
-
lines.push(`[From: ${event.senderName} (prll://${event.senderId})]`);
|
|
51551
|
-
lines.push(`[Comment ID: prll://${event.messageId}]`);
|
|
51552
|
-
lines.push("", event.body);
|
|
51553
|
-
} else if (event.type === "wiki_comment") {
|
|
51554
|
-
lines.push(`[Event: wiki.comment.created]`);
|
|
51555
|
-
const target = event.replyTargetUri ?? `prll://${event.targetId}`;
|
|
51556
|
-
if (event.targetType === "changeset") {
|
|
51557
|
-
lines.push(`[Wiki Changeset: ${target}]`);
|
|
51558
|
-
} else {
|
|
51559
|
-
lines.push(`[Wiki: ${event.targetName ? `${sanitizeMeta(event.targetName)} (${target})` : target}]`);
|
|
51560
|
-
}
|
|
51561
|
-
if (event.deliveryReason)
|
|
51562
|
-
lines.push(`[Delivery: ${sanitizeMeta(event.deliveryReason)}]`);
|
|
51563
|
-
lines.push(`[From: ${event.senderName} (prll://${event.senderId})]`);
|
|
51564
|
-
lines.push(`[Comment ID: prll://${event.messageId}]`);
|
|
51565
|
-
lines.push("", event.body);
|
|
51566
|
-
} else if (event.type === "approval") {
|
|
51567
|
-
lines.push(`[Event: approval.decided]`);
|
|
51568
|
-
lines.push(`[Approval: prll://${event.messageId}]`);
|
|
51569
|
-
lines.push(`[Chat: prll://${event.targetId}]`);
|
|
51570
|
-
lines.push(`[Decided by: ${event.senderName} (prll://${event.senderId})]`);
|
|
51571
|
-
lines.push("", event.body);
|
|
51572
|
-
} else if (event.type === "schedule") {
|
|
51573
|
-
lines.push(`[Event: schedule.fired]`);
|
|
51574
|
-
lines.push(`[Schedule: prll://${event.targetId}]`);
|
|
51575
|
-
lines.push(`[Run: prll://${event.messageId}]`);
|
|
51576
|
-
if (event.scheduledFireAt)
|
|
51577
|
-
lines.push(`[Scheduled at: ${sanitizeMeta(event.scheduledFireAt)}]`);
|
|
51578
|
-
if (event.attachedUri)
|
|
51579
|
-
lines.push(`[Attached: ${sanitizeMeta(event.attachedUri)}]`);
|
|
51580
|
-
lines.push("", event.body);
|
|
51581
|
-
} else if (event.type === "channel_message") {
|
|
51582
|
-
lines.push(`[Event: channel.message]`);
|
|
51583
|
-
const providerLabel = sanitizeMeta(event.channelProvider ?? "external IM");
|
|
51584
|
-
const convType = sanitizeMeta(event.channelConversationType ?? "conversation");
|
|
51585
|
-
const convId = event.channelExternalConversationId ? sanitizeMeta(event.channelExternalConversationId) : void 0;
|
|
51586
|
-
const convName = event.channelExternalConversationName ? sanitizeMeta(event.channelExternalConversationName) : void 0;
|
|
51587
|
-
const convLabel = convName ? `${convName} (${convId ? `${convId}, ` : ""}${convType})` : convId ? `${convId} (${convType})` : convType;
|
|
51588
|
-
lines.push(`[Channel: ${providerLabel} | conversation: ${convLabel}]`);
|
|
51589
|
-
lines.push(`[From: ${sanitizeMeta(event.senderName)} (external user, not a Parall member)]`);
|
|
51590
|
-
if (event.channelExternalMessageId) {
|
|
51591
|
-
lines.push(`[External message ID: ${sanitizeMeta(event.channelExternalMessageId)}]`);
|
|
51592
|
-
}
|
|
51593
|
-
lines.push(`[Audience: this conversation lives on ${providerLabel}, OUTSIDE Parall. Readers cannot open prll:// links, Parall cards, or internal attachments \u2014 never include them in replies. Write plain conversational text.]`);
|
|
51594
|
-
lines.push("", event.body);
|
|
51595
|
-
} else if (event.type === "external_trigger") {
|
|
51596
|
-
lines.push(`[Event: external.trigger]`);
|
|
51597
|
-
lines.push(`[Trigger: prll://${event.targetId}]`);
|
|
51598
|
-
lines.push(`[Run: prll://${event.messageId}]`);
|
|
51599
|
-
if (event.externalConnectionId) {
|
|
51600
|
-
const label = event.externalConnectionDisplayName ? `${sanitizeMeta(event.externalConnectionDisplayName)} (prll://${event.externalConnectionId})` : `prll://${event.externalConnectionId}`;
|
|
51601
|
-
lines.push(`[Connection: ${label}]`);
|
|
51602
|
-
}
|
|
51603
|
-
if (event.externalIngressEventId)
|
|
51604
|
-
lines.push(`[Ingress: prll://${event.externalIngressEventId}]`);
|
|
51605
|
-
if (event.attachedUri)
|
|
51606
|
-
lines.push(`[Attached: ${sanitizeMeta(event.attachedUri)}]`);
|
|
51607
|
-
if (event.externalConnectionSourceType) {
|
|
51608
|
-
lines.push(`[Source: ${sanitizeMeta(event.externalConnectionSourceType)}]`);
|
|
51609
|
-
}
|
|
51610
|
-
if (event.externalIngressEventType) {
|
|
51611
|
-
lines.push(`[External event: ${sanitizeMeta(event.externalIngressEventType)}]`);
|
|
51612
|
-
}
|
|
51613
|
-
lines.push("", event.body);
|
|
51614
|
-
} else {
|
|
51615
|
-
lines.push(`[Event: task.assigned]`);
|
|
51616
|
-
const taskLabel = event.targetName ? `${event.targetName} (prll://${event.targetId})` : `prll://${event.targetId}`;
|
|
51617
|
-
lines.push(`[Task: ${taskLabel}]`);
|
|
51618
|
-
lines.push(`[Assigned by: ${event.senderName} (prll://${event.senderId})]`);
|
|
51619
|
-
lines.push("", event.body);
|
|
51620
|
-
}
|
|
51621
|
-
return lines.join("\n") + buildSendMessageHint(event);
|
|
51622
|
-
}
|
|
51623
|
-
function buildEventBodyForForkResult(event) {
|
|
51624
|
-
return buildEventBody(event).replace(/\n<system-reminder>[\s\S]*<\/system-reminder>$/, "");
|
|
51481
|
+
function eventBody(event) {
|
|
51482
|
+
return event.frame ?? "";
|
|
51625
51483
|
}
|
|
51626
|
-
function
|
|
51627
|
-
|
|
51628
|
-
return "";
|
|
51629
|
-
if (event.type === "wiki_comment" && event.replyTargetUri) {
|
|
51630
|
-
const where = event.targetType === "changeset" ? "this changeset comment" : "this wiki page";
|
|
51631
|
-
return `
|
|
51632
|
-
<system-reminder>To reply on ${where}, run: \`parall comments add --target "${event.replyTargetUri}" --body "..."\` (read the thread first with \`parall comments list --target "${event.replyTargetUri}"\`). To message someone instead, use \`parall messages send\` / \`parall dm\`. Your plain text output is not delivered.</system-reminder>`;
|
|
51633
|
-
}
|
|
51634
|
-
if (event.targetId.startsWith("cht_")) {
|
|
51635
|
-
if (event.threadRootId) {
|
|
51636
|
-
return `
|
|
51637
|
-
<system-reminder>To reply in this thread, run \`parall messages send prll://${event.targetId} --thread-root-id ${sanitizeMeta(event.threadRootId)} --text-file - <<'EOF'\` \u2026 \`EOF\` \u2014 the quoted heredoc keeps \`$\`, backticks and apostrophes literal (plain \`--text "$1,000"\` sends \`,000\`). Your plain text output is not delivered to the chat.</system-reminder>`;
|
|
51638
|
-
}
|
|
51639
|
-
return `
|
|
51640
|
-
<system-reminder>To reply, run \`parall messages send prll://${event.targetId} --text-file - <<'EOF'\` \u2026 \`EOF\` \u2014 the quoted heredoc keeps \`$\`, backticks and apostrophes literal (plain \`--text "$1,000"\` sends \`,000\`). Your plain text output is not delivered to the chat.</system-reminder>`;
|
|
51641
|
-
}
|
|
51642
|
-
if (event.targetId.startsWith("tsk_")) {
|
|
51643
|
-
return `
|
|
51644
|
-
<system-reminder>To respond, use the CLI: \`parall tasks update\` / \`parall tasks comments add\`. To message someone, use \`parall messages send\` / \`parall dm\`. Your plain text output is not delivered.</system-reminder>`;
|
|
51645
|
-
}
|
|
51646
|
-
if (event.targetId.startsWith("sch_")) {
|
|
51647
|
-
return `
|
|
51648
|
-
<system-reminder>To communicate, use the CLI: \`parall messages send\` / \`parall dm\`. Your plain text output is not delivered.</system-reminder>`;
|
|
51649
|
-
}
|
|
51650
|
-
if (event.type === "channel_message") {
|
|
51651
|
-
if (event.channelCliCapable) {
|
|
51652
|
-
if (event.channelProvider === "slack") {
|
|
51653
|
-
const channelArg = event.channelExternalConversationId ? ` --channel "${event.channelExternalConversationId}"` : " --channel <conversation id from this event>";
|
|
51654
|
-
const replyTo = event.channelExternalMessageId ? ` --reply-to "${event.channelExternalMessageId}"` : "";
|
|
51655
|
-
return `
|
|
51656
|
-
<system-reminder>To reply, use the platform verb: \`parall slack send${channelArg}${replyTo} --text <your reply>\`. In channels --reply-to is REQUIRED (the reply lands in that message's thread); in DMs it is optional (DMs are linear). \`parall slack send\` is the ONLY outbound path \u2014 your plain text output is NOT delivered to the external conversation.</system-reminder>`;
|
|
51657
|
-
}
|
|
51658
|
-
if (event.channelProvider === "wechat") {
|
|
51659
|
-
const toArg = event.channelExternalConversationId ? ` --to "${event.channelExternalConversationId}"` : " --to <wxid from this event>";
|
|
51660
|
-
const atArg = event.channelConversationType === "group" ? event.senderId && event.senderId !== "external" ? ` --at "${event.senderId}"` : " --at <wxid of the person you are answering>" : "";
|
|
51661
|
-
const historyArg = event.channelExternalConversationId ? ` --conversation "${event.channelExternalConversationId}"` : " --conversation <wxid from this event>";
|
|
51662
|
-
return `
|
|
51663
|
-
<system-reminder>Need earlier context? Run \`parall wechat history${historyArg}\`; history is not inserted automatically. To reply, use the platform verb: \`parall wechat send${toArg}${atArg} --text-file - <<'EOF'\` \u2026 \`EOF\` (or --text "<short text>" for simple literals \u2014 the quoted heredoc keeps $, backticks and apostrophes literal). In group chats, --at @-mentions the person you are answering. \`parall wechat send\` is the ONLY outbound path \u2014 your plain text output is NOT delivered to the external conversation.</system-reminder>`;
|
|
51664
|
-
}
|
|
51665
|
-
if (!event.channelProvider) {
|
|
51666
|
-
return `
|
|
51667
|
-
<system-reminder>To reply, use the channel capability granted in your system prompt \u2014 for Feishu conversations that is \`lark-cli im\`, for Slack it is \`parall slack send\` (pass the message id from this event as --reply-to), for WeChat it is \`parall wechat send\`. That capability is the ONLY outbound path \u2014 your plain text output is NOT delivered to the external conversation.</system-reminder>`;
|
|
51668
|
-
}
|
|
51669
|
-
const convRef = event.channelExternalConversationId ? `chat_id "${event.channelExternalConversationId}"` : "the conversation id named in this event";
|
|
51670
|
-
const threadAlt = event.channelExternalMessageId ? ` To reply threaded to this specific message, reference message_id "${event.channelExternalMessageId}".` : "";
|
|
51671
|
-
return `
|
|
51672
|
-
<system-reminder>To reply, use the official Feishu CLI on your PATH: send a message to ${convRef} with \`lark-cli im\` (see \`lark-cli im --help\` for send syntax; auth is provisioned automatically).${threadAlt} lark-cli is the ONLY outbound path \u2014 your plain text output is NOT delivered to the external conversation.</system-reminder>`;
|
|
51673
|
-
}
|
|
51674
|
-
const platform = event.channelProvider ?? "the external platform";
|
|
51675
|
-
return `
|
|
51676
|
-
<system-reminder>This message arrived from ${platform}, but outbound replies are currently disabled for this org (no channel capability granted). Do NOT attempt to reply on the external platform. If action is needed, surface it inside Parall (\`parall messages send\` / \`parall dm\`). Your plain text output is not delivered anywhere.</system-reminder>`;
|
|
51677
|
-
}
|
|
51678
|
-
if (event.type === "external_trigger" || event.targetId.startsWith("xtr_")) {
|
|
51679
|
-
return `
|
|
51680
|
-
<system-reminder>This external trigger is incoming-only. Your plain text output is not sent back to the external provider. To communicate in Parall, use \`parall messages send\` / \`parall dm\`; provider-specific outbound actions require a separate capability.</system-reminder>`;
|
|
51681
|
-
}
|
|
51682
|
-
return "";
|
|
51484
|
+
function forkResultBody(event) {
|
|
51485
|
+
return eventBody(event).replace(/\n\[Reminder[^\n]*\]$/, "");
|
|
51683
51486
|
}
|
|
51684
51487
|
function buildForkScopePrefix(event) {
|
|
51685
|
-
|
|
51686
|
-
return `[Fork scope: You are a parallel worker forked from the main session to handle ${targetLabel}. The conversation history above belongs to the main session's in-progress dispatch \u2014 do NOT continue it or complete it, or produce external output (comments, messages) for work visible there. The main session owns its own output.
|
|
51488
|
+
return `[Fork scope: You are a parallel worker forked from the main session to handle prll://${event.targetId}. The conversation history above belongs to the main session's in-progress dispatch \u2014 do NOT continue it or complete it, or produce external output (comments, messages) for work visible there. The main session owns its own output.
|
|
51687
51489
|
|
|
51688
51490
|
Only act on the event below within your target scope. If your event reveals findings about the main session's work, report them in your summary \u2014 do not post them externally.
|
|
51689
51491
|
|
|
@@ -51712,6 +51514,26 @@ function buildForkResultPrefix(results) {
|
|
|
51712
51514
|
|
|
51713
51515
|
// ../agent-core/dist/gateway-base.js
|
|
51714
51516
|
import * as os from "node:os";
|
|
51517
|
+
|
|
51518
|
+
// ../agent-core/dist/change-source.js
|
|
51519
|
+
var CHANGE_REASONS = /* @__PURE__ */ new Set([
|
|
51520
|
+
"edited",
|
|
51521
|
+
"deleted",
|
|
51522
|
+
"unmentioned",
|
|
51523
|
+
"mention",
|
|
51524
|
+
"reaction"
|
|
51525
|
+
]);
|
|
51526
|
+
function splitChangeSource(sourceId) {
|
|
51527
|
+
const i = sourceId.indexOf("~");
|
|
51528
|
+
if (i <= 0)
|
|
51529
|
+
return { messageId: sourceId };
|
|
51530
|
+
const [reason] = sourceId.slice(i + 1).split("~");
|
|
51531
|
+
if (!reason || !CHANGE_REASONS.has(reason))
|
|
51532
|
+
return { messageId: sourceId };
|
|
51533
|
+
return { messageId: sourceId.slice(0, i), reason };
|
|
51534
|
+
}
|
|
51535
|
+
|
|
51536
|
+
// ../agent-core/dist/gateway-base.js
|
|
51715
51537
|
import * as fs3 from "node:fs";
|
|
51716
51538
|
import * as path3 from "node:path";
|
|
51717
51539
|
import { randomUUID } from "node:crypto";
|
|
@@ -51826,6 +51648,8 @@ var ENDPOINTS = {
|
|
|
51826
51648
|
MESSAGE_WATCH: (id) => `${API_BASE}/messages/${id}/watch`,
|
|
51827
51649
|
MESSAGE_WATCHERS: (id) => `${API_BASE}/messages/${id}/watchers`,
|
|
51828
51650
|
MESSAGE_WATCHING: (id) => `${API_BASE}/messages/${id}/watching`,
|
|
51651
|
+
/** Caller's attention levels across chats / threads / tasks. */
|
|
51652
|
+
WATCHES: (orgId) => `${API_BASE}/orgs/${orgId}/watches`,
|
|
51829
51653
|
MESSAGE_REACTIONS: (id) => `${API_BASE}/messages/${id}/reactions`,
|
|
51830
51654
|
MESSAGE_REACTION: (id, emoji) => `${API_BASE}/messages/${id}/reactions/${encodeURIComponent(emoji)}`,
|
|
51831
51655
|
// Upload (org-scoped)
|
|
@@ -51848,6 +51672,7 @@ var ENDPOINTS = {
|
|
|
51848
51672
|
AGENT_ACTIVITY: (orgId, agentId) => `${API_BASE}/orgs/${orgId}/agents/${agentId}/activity`,
|
|
51849
51673
|
AGENT_MONITOR: (orgId, agentId) => `${API_BASE}/orgs/${orgId}/agents/${agentId}/monitor`,
|
|
51850
51674
|
AGENT_ME: (orgId) => `${API_BASE}/orgs/${orgId}/agents/me`,
|
|
51675
|
+
AGENT_REPLY_POLICY_CAPABILITY: (orgId) => `${API_BASE}/orgs/${orgId}/agents/me/reply-policy-capability`,
|
|
51851
51676
|
AGENT_NEW_SESSION: (orgId, agentId) => `${API_BASE}/orgs/${orgId}/agents/${agentId}/new-session`,
|
|
51852
51677
|
AGENT_DEEP_RESET: (orgId, agentId) => `${API_BASE}/orgs/${orgId}/agents/${agentId}/deep-reset`,
|
|
51853
51678
|
AGENT_SESSIONS: (orgId, agentId) => `${API_BASE}/orgs/${orgId}/agents/${agentId}/sessions`,
|
|
@@ -51884,6 +51709,7 @@ var ENDPOINTS = {
|
|
|
51884
51709
|
MACHINE_AGENT_WORKSPACE_SETUP: (orgId, machineId, agentId) => `${API_BASE}/orgs/${orgId}/machines/${machineId}/agents/${agentId}/workspace/setup`,
|
|
51885
51710
|
MACHINE_LLM_SOURCE: (orgId, machineId) => `${API_BASE}/orgs/${orgId}/machines/${machineId}/llm-source`,
|
|
51886
51711
|
MACHINE_PROVIDER_ENABLED: (orgId, machineId) => `${API_BASE}/orgs/${orgId}/machines/${machineId}/provider-enabled`,
|
|
51712
|
+
MACHINE_MANAGED_BY: (orgId, machineId) => `${API_BASE}/orgs/${orgId}/machines/${machineId}/managed-by`,
|
|
51887
51713
|
MACHINE_CAPABILITIES: (orgId, machineId) => `${API_BASE}/orgs/${orgId}/machines/${machineId}/capabilities`,
|
|
51888
51714
|
MACHINE_RUNTIME_AUTH: (orgId, machineId) => `${API_BASE}/orgs/${orgId}/machines/${machineId}/runtime-auth`,
|
|
51889
51715
|
MACHINE_KEYS: (orgId, machineId) => `${API_BASE}/orgs/${orgId}/machines/${machineId}/keys`,
|
|
@@ -52017,6 +51843,7 @@ var ENDPOINTS = {
|
|
|
52017
51843
|
WIKI: (orgId, wikiId) => `${WIKI_BASE}/orgs/${orgId}/wikis/${wikiId}`,
|
|
52018
51844
|
WIKI_RESTORE: (orgId, wikiId) => `${WIKI_BASE}/orgs/${orgId}/wikis/${wikiId}/restore`,
|
|
52019
51845
|
WIKI_TREE: (orgId, wikiId) => `${WIKI_BASE}/orgs/${orgId}/wikis/${wikiId}/tree`,
|
|
51846
|
+
WIKI_TREE_LAST_COMMITS: (orgId, wikiId) => `${WIKI_BASE}/orgs/${orgId}/wikis/${wikiId}/tree/last-commits`,
|
|
52020
51847
|
WIKI_BLOB: (orgId, wikiId) => `${WIKI_BASE}/orgs/${orgId}/wikis/${wikiId}/blob`,
|
|
52021
51848
|
WIKI_COPY: (orgId, wikiId) => `${WIKI_BASE}/orgs/${orgId}/wikis/${wikiId}/copy`,
|
|
52022
51849
|
WIKI_NODE_SECTIONS: (orgId, wikiId) => `${WIKI_BASE}/orgs/${orgId}/wikis/${wikiId}/node-sections`,
|
|
@@ -52363,8 +52190,22 @@ var ProjectTaskClient = class {
|
|
|
52363
52190
|
async unsubscribeTaskMember(orgId, taskId, userId) {
|
|
52364
52191
|
return this.request("DELETE", ENDPOINTS.TASK_SUBSCRIBER(orgId, taskId, userId));
|
|
52365
52192
|
}
|
|
52366
|
-
async watchThread(threadRootId) {
|
|
52367
|
-
return this.request("POST", ENDPOINTS.MESSAGE_WATCH(threadRootId));
|
|
52193
|
+
async watchThread(threadRootId, body) {
|
|
52194
|
+
return this.request("POST", ENDPOINTS.MESSAGE_WATCH(threadRootId), body);
|
|
52195
|
+
}
|
|
52196
|
+
// ---- Attention settings (agent-attention-design.md §4) ----
|
|
52197
|
+
/** The caller's watch rows: the setting per chat / thread. */
|
|
52198
|
+
async listWatches(orgId) {
|
|
52199
|
+
const res = await this.request("GET", ENDPOINTS.WATCHES(orgId));
|
|
52200
|
+
return res.data;
|
|
52201
|
+
}
|
|
52202
|
+
/**
|
|
52203
|
+
* Set the caller's setting on one target (prll://cht_ / msg_ root).
|
|
52204
|
+
* Threads are watched first when not yet; chats require membership (404
|
|
52205
|
+
* NOT_A_MEMBER otherwise). Tasks carry no setting (watch / unwatch only).
|
|
52206
|
+
*/
|
|
52207
|
+
async setWatchLevel(orgId, body) {
|
|
52208
|
+
return this.request("PUT", ENDPOINTS.WATCHES(orgId), body);
|
|
52368
52209
|
}
|
|
52369
52210
|
async unwatchThread(threadRootId) {
|
|
52370
52211
|
return this.request("DELETE", ENDPOINTS.MESSAGE_WATCH(threadRootId));
|
|
@@ -53413,6 +53254,15 @@ var ParallClient = class _ParallClient extends AttachmentClient {
|
|
|
53413
53254
|
const res = await this.request("GET", ENDPOINTS.APPROVALS_ACTIONS);
|
|
53414
53255
|
return res.data;
|
|
53415
53256
|
}
|
|
53257
|
+
/**
|
|
53258
|
+
* Action names plus the payload contract each documented action publishes
|
|
53259
|
+
* (field names, types, and where a CAS base like expected_version is read
|
|
53260
|
+
* from). Additive over getApprovableActions(): older servers omit
|
|
53261
|
+
* `contracts`.
|
|
53262
|
+
*/
|
|
53263
|
+
async getApprovableActionCatalog() {
|
|
53264
|
+
return this.request("GET", ENDPOINTS.APPROVALS_ACTIONS);
|
|
53265
|
+
}
|
|
53416
53266
|
// ---- Agents (org-scoped) ----
|
|
53417
53267
|
async createAgent(orgId, req, opts) {
|
|
53418
53268
|
return this.request("POST", ENDPOINTS.AGENTS(orgId), req, void 0, false, opts);
|
|
@@ -53637,6 +53487,19 @@ var ParallClient = class _ParallClient extends AttachmentClient {
|
|
|
53637
53487
|
provider_enabled: providerEnabled
|
|
53638
53488
|
});
|
|
53639
53489
|
}
|
|
53490
|
+
/**
|
|
53491
|
+
* Convert a member's personal device into an organization machine
|
|
53492
|
+
* (PATCH /machines/{id}/managed-by). One-way and idempotent; org admins only
|
|
53493
|
+
* (an admin-role agent qualifies). After conversion every org admin manages
|
|
53494
|
+
* the machine and the registrant is just a member. 'member' is rejected —
|
|
53495
|
+
* an org machine cannot become a personal device again. See
|
|
53496
|
+
* docs/engineering-design/org-machine-assets-design.md §4.
|
|
53497
|
+
*/
|
|
53498
|
+
async convertMachineToOrgManaged(orgId, machineId) {
|
|
53499
|
+
return this.request("PATCH", ENDPOINTS.MACHINE_MANAGED_BY(orgId, machineId), {
|
|
53500
|
+
managed_by: "org"
|
|
53501
|
+
});
|
|
53502
|
+
}
|
|
53640
53503
|
/**
|
|
53641
53504
|
* Replace the machine's capability set (admin). Primary use: healing a
|
|
53642
53505
|
* machine that registered without `browser_provider` during the capability
|
|
@@ -53886,6 +53749,18 @@ var ParallClient = class _ParallClient extends AttachmentClient {
|
|
|
53886
53749
|
async steerDispatch(orgId, req) {
|
|
53887
53750
|
return this.request("POST", ENDPOINTS.DISPATCH_STEER(orgId), req);
|
|
53888
53751
|
}
|
|
53752
|
+
/**
|
|
53753
|
+
* Declare the runtime contract for this WS connection: the runtime runs
|
|
53754
|
+
* what the server decides and takes the server-rendered wake frame from
|
|
53755
|
+
* claim / steer responses instead of filtering and rendering locally.
|
|
53756
|
+
* Bound to the connection's session id; re-declare on every hello.
|
|
53757
|
+
* 409 STALE_WS_SESSION when the id is not the agent's current connection.
|
|
53758
|
+
*/
|
|
53759
|
+
async declareReplyPolicyCapability(orgId, wsSessionId) {
|
|
53760
|
+
await this.request("PUT", ENDPOINTS.AGENT_REPLY_POLICY_CAPABILITY(orgId), {
|
|
53761
|
+
ws_session_id: wsSessionId
|
|
53762
|
+
});
|
|
53763
|
+
}
|
|
53889
53764
|
/** Advance exact runtime-input lifecycle for members of an explicit lane. */
|
|
53890
53765
|
async updateDispatchInputState(orgId, req) {
|
|
53891
53766
|
return this.request("POST", ENDPOINTS.DISPATCH_INPUT_STATE(orgId), req);
|
|
@@ -54158,8 +54033,27 @@ var ParallClient = class _ParallClient extends AttachmentClient {
|
|
|
54158
54033
|
const res = await this.request("GET", ENDPOINTS.WIKIS_DELETED(orgId));
|
|
54159
54034
|
return res.data;
|
|
54160
54035
|
}
|
|
54161
|
-
|
|
54162
|
-
|
|
54036
|
+
/**
|
|
54037
|
+
* List the direct children of a wiki directory. The response carries
|
|
54038
|
+
* `head_sha`, the immutable commit it was read at; render the rows first
|
|
54039
|
+
* and fetch their dates with `getWikiTreeLastCommits` pinned to it.
|
|
54040
|
+
* `last_commit: true` is the legacy single-request form (dates composed
|
|
54041
|
+
* server-side); prefer the two-phase flow so the structure is never held
|
|
54042
|
+
* back by history reads. Pass `signal` to abort on navigation.
|
|
54043
|
+
*/
|
|
54044
|
+
async getWikiTree(orgId, wikiId, params, opts) {
|
|
54045
|
+
return this.request("GET", ENDPOINTS.WIKI_TREE(orgId, wikiId), void 0, params, false, opts);
|
|
54046
|
+
}
|
|
54047
|
+
/**
|
|
54048
|
+
* Second phase of a directory listing: last-commit dates for the direct
|
|
54049
|
+
* children of `path` at `ref`, which must be the `head_sha` a
|
|
54050
|
+
* `getWikiTree` response carried (a branch name is rejected). Merge the
|
|
54051
|
+
* dates only while the returned `head_sha` still matches the rows on
|
|
54052
|
+
* screen; a failure just leaves the dates blank. Pass `signal` to abort
|
|
54053
|
+
* on navigation.
|
|
54054
|
+
*/
|
|
54055
|
+
async getWikiTreeLastCommits(orgId, wikiId, params, opts) {
|
|
54056
|
+
return this.request("GET", ENDPOINTS.WIKI_TREE_LAST_COMMITS(orgId, wikiId), void 0, params, false, opts);
|
|
54163
54057
|
}
|
|
54164
54058
|
/**
|
|
54165
54059
|
* Resolve a server-returned, host-relative media URL (a wiki `signed_url`
|
|
@@ -55198,20 +55092,6 @@ function buildApiError(res, rawErrorBody) {
|
|
|
55198
55092
|
return apiError;
|
|
55199
55093
|
}
|
|
55200
55094
|
|
|
55201
|
-
// ../sdk/dist/types.js
|
|
55202
|
-
var MENTION_ALL_USER_ID = "all";
|
|
55203
|
-
var MENTION_ALL_HUMANS_USER_ID = "allhuman";
|
|
55204
|
-
var MENTION_ALL_AGENTS_USER_ID = "allagent";
|
|
55205
|
-
function mentionTargetsUser(mentionUserId, userId, userType) {
|
|
55206
|
-
if (mentionUserId === userId || mentionUserId === MENTION_ALL_USER_ID)
|
|
55207
|
-
return true;
|
|
55208
|
-
if (mentionUserId === MENTION_ALL_HUMANS_USER_ID)
|
|
55209
|
-
return userType === "human";
|
|
55210
|
-
if (mentionUserId === MENTION_ALL_AGENTS_USER_ID)
|
|
55211
|
-
return userType === "agent";
|
|
55212
|
-
return false;
|
|
55213
|
-
}
|
|
55214
|
-
|
|
55215
55095
|
// ../sdk/dist/ws.js
|
|
55216
55096
|
function isRetryableNetworkError(err) {
|
|
55217
55097
|
return err instanceof Error && err.name === "ApiError" && "status" in err && err.status === 0;
|
|
@@ -55643,7 +55523,7 @@ var LaneLedger = class {
|
|
|
55643
55523
|
get contextDir() {
|
|
55644
55524
|
return this.opts.contextDir;
|
|
55645
55525
|
}
|
|
55646
|
-
/**
|
|
55526
|
+
/** Chat message events ride (target, thread) lanes; typed events ride single-member dsp lanes (claimTyped). */
|
|
55647
55527
|
handles(event) {
|
|
55648
55528
|
return event.type === "message" && event.targetId.startsWith("cht_");
|
|
55649
55529
|
}
|
|
@@ -55659,6 +55539,75 @@ var LaneLedger = class {
|
|
|
55659
55539
|
laneContextPath(lane) {
|
|
55660
55540
|
return laneContextFilePath(this.opts.contextDir, lane.targetUri, lane.threadRootId);
|
|
55661
55541
|
}
|
|
55542
|
+
/**
|
|
55543
|
+
* Whether the server already rendered this message into a frame the model
|
|
55544
|
+
* saw on its live lane. The row is folded there and resolves with that
|
|
55545
|
+
* lane's turn — a local copy has nothing left to deliver.
|
|
55546
|
+
*/
|
|
55547
|
+
seenInFrame(targetId, threadRootId, messageId) {
|
|
55548
|
+
const lane = this.lanes.get(laneKeyForTarget(`prll://${targetId}`, threadRootId));
|
|
55549
|
+
return lane?.seen.has(messageId) ?? false;
|
|
55550
|
+
}
|
|
55551
|
+
/**
|
|
55552
|
+
* Hand the pending frame to the caller (once) with the members it covers
|
|
55553
|
+
* and what the claim said about the wake, and record those members as
|
|
55554
|
+
* seen. Absent frame ⇒ nothing new to render (every member already seen).
|
|
55555
|
+
*/
|
|
55556
|
+
takeFrame(lane) {
|
|
55557
|
+
const frame = lane.frame;
|
|
55558
|
+
const ids = lane.framed;
|
|
55559
|
+
for (const id of ids)
|
|
55560
|
+
lane.seen.add(id);
|
|
55561
|
+
lane.frame = void 0;
|
|
55562
|
+
lane.framed = [];
|
|
55563
|
+
const { input, noReply, attachments } = lane;
|
|
55564
|
+
lane.input = void 0;
|
|
55565
|
+
lane.noReply = void 0;
|
|
55566
|
+
lane.attachments = void 0;
|
|
55567
|
+
return { frame, ids, input, noReply, attachments };
|
|
55568
|
+
}
|
|
55569
|
+
/** Record what the claim response said about the wake alongside its frame. */
|
|
55570
|
+
recordWake(lane, res) {
|
|
55571
|
+
if (res.input)
|
|
55572
|
+
lane.input = res.input;
|
|
55573
|
+
if (res.no_reply != null)
|
|
55574
|
+
lane.noReply = res.no_reply;
|
|
55575
|
+
if (res.attachments?.length) {
|
|
55576
|
+
lane.attachments = res.attachments.map((a) => ({
|
|
55577
|
+
id: a.id,
|
|
55578
|
+
fileName: a.file_name ?? "",
|
|
55579
|
+
fileSize: a.file_size ?? 0,
|
|
55580
|
+
mimeType: a.mime_type ?? ""
|
|
55581
|
+
}));
|
|
55582
|
+
}
|
|
55583
|
+
}
|
|
55584
|
+
/** The injection landed: the model has seen these members. */
|
|
55585
|
+
markSeen(event, ids) {
|
|
55586
|
+
const lane = this.lanes.get(this.laneKeyFor(event));
|
|
55587
|
+
if (!lane)
|
|
55588
|
+
return;
|
|
55589
|
+
for (const id of ids)
|
|
55590
|
+
lane.seen.add(id);
|
|
55591
|
+
}
|
|
55592
|
+
/**
|
|
55593
|
+
* The injection did not land (turn already over, process gone): keep the
|
|
55594
|
+
* server's increment as the lane's pending frame so the buffered copy's
|
|
55595
|
+
* drain renders it as its own turn instead of skipping it as seen.
|
|
55596
|
+
*/
|
|
55597
|
+
deferFrame(event, frame, ids) {
|
|
55598
|
+
const lane = this.lanes.get(this.laneKeyFor(event));
|
|
55599
|
+
if (!lane)
|
|
55600
|
+
return;
|
|
55601
|
+
this.recordFrame(lane, frame, ids);
|
|
55602
|
+
}
|
|
55603
|
+
recordFrame(lane, frame, ids) {
|
|
55604
|
+
if (!frame)
|
|
55605
|
+
return;
|
|
55606
|
+
lane.frame = lane.frame ? `${lane.frame}
|
|
55607
|
+
|
|
55608
|
+
${frame}` : frame;
|
|
55609
|
+
lane.framed.push(...ids);
|
|
55610
|
+
}
|
|
55662
55611
|
/**
|
|
55663
55612
|
* Claim (or reuse) the lane for a group of same-lane message events and
|
|
55664
55613
|
* fold every group member into it. Returns 'foreign' when a healthy
|
|
@@ -55708,11 +55657,15 @@ var LaneLedger = class {
|
|
|
55708
55657
|
threadRootId: trigger.threadRootId,
|
|
55709
55658
|
coverageMode: actualCoverage,
|
|
55710
55659
|
folded: /* @__PURE__ */ new Map(),
|
|
55660
|
+
framed: [],
|
|
55661
|
+
seen: /* @__PURE__ */ new Set(),
|
|
55711
55662
|
...Number.isNaN(leaseUntilMs) ? {} : { leaseUntilMs, leaseTtlMs: Math.max(leaseUntilMs - Date.now(), 6e4) }
|
|
55712
55663
|
};
|
|
55713
55664
|
for (const ev of res.events ?? []) {
|
|
55714
55665
|
lane.folded.set(ev.source_id, ev.id);
|
|
55715
55666
|
}
|
|
55667
|
+
this.recordFrame(lane, res.frame, (res.events ?? []).map((ev) => ev.source_id));
|
|
55668
|
+
this.recordWake(lane, res);
|
|
55716
55669
|
this.lanes.set(laneKey, lane);
|
|
55717
55670
|
}
|
|
55718
55671
|
for (const ev of events) {
|
|
@@ -55726,6 +55679,7 @@ var LaneLedger = class {
|
|
|
55726
55679
|
...ev.dispatchEventId ? { dispatch_event_id: ev.dispatchEventId } : { source_type: "message", source_id: ev.messageId }
|
|
55727
55680
|
});
|
|
55728
55681
|
lane.folded.set(ev.messageId, res.dispatch_event_id);
|
|
55682
|
+
this.recordFrame(lane, res.frame, [ev.messageId]);
|
|
55729
55683
|
} catch (err) {
|
|
55730
55684
|
if (isStaleLane(err)) {
|
|
55731
55685
|
this.lanes.delete(laneKey);
|
|
@@ -55749,8 +55703,13 @@ var LaneLedger = class {
|
|
|
55749
55703
|
const lane = this.lanes.get(laneKey);
|
|
55750
55704
|
if (!lane)
|
|
55751
55705
|
return null;
|
|
55706
|
+
if (lane.seen.has(event.messageId))
|
|
55707
|
+
return null;
|
|
55752
55708
|
if (lane.folded.has(event.messageId)) {
|
|
55753
|
-
return {
|
|
55709
|
+
return {
|
|
55710
|
+
inputLifecycle: this.inputLifecycleFor(lane, [event.messageId]),
|
|
55711
|
+
covered: [event.messageId]
|
|
55712
|
+
};
|
|
55754
55713
|
}
|
|
55755
55714
|
try {
|
|
55756
55715
|
const res = await this.opts.client.steerDispatch(this.opts.orgId, {
|
|
@@ -55760,7 +55719,12 @@ var LaneLedger = class {
|
|
|
55760
55719
|
...event.dispatchEventId ? { dispatch_event_id: event.dispatchEventId } : { source_type: "message", source_id: event.messageId }
|
|
55761
55720
|
});
|
|
55762
55721
|
lane.folded.set(event.messageId, res.dispatch_event_id);
|
|
55763
|
-
|
|
55722
|
+
const covered = [event.messageId];
|
|
55723
|
+
return {
|
|
55724
|
+
inputLifecycle: this.inputLifecycleFor(lane, covered),
|
|
55725
|
+
frame: res.frame,
|
|
55726
|
+
covered
|
|
55727
|
+
};
|
|
55764
55728
|
} catch (err) {
|
|
55765
55729
|
if (isStaleLane(err)) {
|
|
55766
55730
|
this.lanes.delete(laneKey);
|
|
@@ -55775,10 +55739,18 @@ var LaneLedger = class {
|
|
|
55775
55739
|
* batched prompt covers every WorkItem represented in that single frame.
|
|
55776
55740
|
*/
|
|
55777
55741
|
inputLifecycle(lane, events) {
|
|
55742
|
+
return this.inputLifecycleFor(lane, events.map((event) => event.messageId));
|
|
55743
|
+
}
|
|
55744
|
+
/**
|
|
55745
|
+
* Exact lifecycle over a set of folded members by message id — the set a
|
|
55746
|
+
* prompt or injection actually delivers (frame coverage ∪ buffered group).
|
|
55747
|
+
*/
|
|
55748
|
+
inputLifecycleFor(lane, messageIds) {
|
|
55778
55749
|
if (lane.coverageMode !== "explicit")
|
|
55779
55750
|
return void 0;
|
|
55780
|
-
const
|
|
55781
|
-
|
|
55751
|
+
const unique = [...new Set(messageIds)];
|
|
55752
|
+
const dispatchEventIds = unique.map((messageId) => lane.folded.get(messageId)).filter((id) => Boolean(id));
|
|
55753
|
+
if (dispatchEventIds.length !== unique.length) {
|
|
55782
55754
|
throw new Error(`explicit lane ${lane.lane} is missing a folded WorkItem mapping`);
|
|
55783
55755
|
}
|
|
55784
55756
|
return {
|
|
@@ -55976,10 +55948,12 @@ var LaneLedger = class {
|
|
|
55976
55948
|
return this.lanes.size;
|
|
55977
55949
|
}
|
|
55978
55950
|
/**
|
|
55979
|
-
* Claim the single-member lane of one typed WorkItem (resource = dsp:<id>)
|
|
55980
|
-
* by WorkItem id
|
|
55981
|
-
*
|
|
55982
|
-
*
|
|
55951
|
+
* Claim the single-member lane of one typed WorkItem (resource = dsp:<id>)
|
|
55952
|
+
* by WorkItem id. The server renders the wake frame on claim (or resolves
|
|
55953
|
+
* the item as stale and answers `claimed: false, reason: "stale"`).
|
|
55954
|
+
* Returns null when a healthy incumbent (another pod) holds it, the
|
|
55955
|
+
* WorkItem is already resolved, or the server found nothing to wake for
|
|
55956
|
+
* — the caller must skip processing.
|
|
55983
55957
|
*/
|
|
55984
55958
|
async claimTyped(ref) {
|
|
55985
55959
|
let res;
|
|
@@ -55994,8 +55968,15 @@ var LaneLedger = class {
|
|
|
55994
55968
|
throw new LedgerUnsupportedError("claim endpoint unavailable");
|
|
55995
55969
|
throw err;
|
|
55996
55970
|
}
|
|
55997
|
-
if (!res.claimed || !res.lane || !res.events?.length)
|
|
55971
|
+
if (!res.claimed || !res.lane || !res.events?.length) {
|
|
55972
|
+
if (res.reason === "stale") {
|
|
55973
|
+
this.opts.log?.info(`typed dispatch ${ref.dispatchEventId ?? `${ref.sourceType}:${ref.sourceId}`} resolved by the server as stale (${res.stale_reason ?? "unspecified"})`);
|
|
55974
|
+
} else if (res.claimed && res.lane) {
|
|
55975
|
+
await this.opts.client.releaseDispatchLane(this.opts.orgId, res.lane).catch(() => {
|
|
55976
|
+
});
|
|
55977
|
+
}
|
|
55998
55978
|
return null;
|
|
55979
|
+
}
|
|
55999
55980
|
const workItem = res.events[0];
|
|
56000
55981
|
const targetUri = `dsp:${workItem.id}`;
|
|
56001
55982
|
const leaseUntilMs = Date.parse(res.lease_until ?? "");
|
|
@@ -56005,9 +55986,13 @@ var LaneLedger = class {
|
|
|
56005
55986
|
targetUri,
|
|
56006
55987
|
coverageMode: "implicit",
|
|
56007
55988
|
folded: /* @__PURE__ */ new Map([[workItem.source_id, workItem.id]]),
|
|
55989
|
+
framed: [],
|
|
55990
|
+
seen: /* @__PURE__ */ new Set(),
|
|
56008
55991
|
typedDispatchEventId: workItem.id,
|
|
56009
55992
|
...Number.isNaN(leaseUntilMs) ? {} : { leaseUntilMs, leaseTtlMs: Math.max(leaseUntilMs - Date.now(), 6e4) }
|
|
56010
55993
|
};
|
|
55994
|
+
this.recordFrame(lane, res.frame, [workItem.source_id]);
|
|
55995
|
+
this.recordWake(lane, res);
|
|
56011
55996
|
this.lanes.set(lane.laneKey, lane);
|
|
56012
55997
|
return lane;
|
|
56013
55998
|
}
|
|
@@ -56050,6 +56035,19 @@ function shiftMainBufferGroup(host, groupKey, preserveInjectedFrameBoundary) {
|
|
|
56050
56035
|
}
|
|
56051
56036
|
return events;
|
|
56052
56037
|
}
|
|
56038
|
+
function applyWake(event, wake) {
|
|
56039
|
+
if (wake.frame)
|
|
56040
|
+
event.frame = wake.frame;
|
|
56041
|
+
if (wake.input) {
|
|
56042
|
+
event.input = wake.input;
|
|
56043
|
+
if (wake.input.sender_id)
|
|
56044
|
+
event.senderId = wake.input.sender_id;
|
|
56045
|
+
}
|
|
56046
|
+
if (wake.noReply != null)
|
|
56047
|
+
event.noReply = wake.noReply;
|
|
56048
|
+
if (wake.attachments?.length)
|
|
56049
|
+
event.attachments = wake.attachments;
|
|
56050
|
+
}
|
|
56053
56051
|
function hasUninjectedSameLaneEventAhead(host, event) {
|
|
56054
56052
|
const eventIndex = host.dispatchState.mainBuffer.lastIndexOf(event);
|
|
56055
56053
|
if (eventIndex <= 0)
|
|
@@ -56067,10 +56065,17 @@ async function steerLaneMessage(host, event) {
|
|
|
56067
56065
|
const folded = await ledger.steerLive(event);
|
|
56068
56066
|
if (!folded)
|
|
56069
56067
|
return;
|
|
56070
|
-
|
|
56068
|
+
if (!folded.frame)
|
|
56069
|
+
return;
|
|
56070
|
+
event.frame = folded.frame;
|
|
56071
|
+
const injected = await adapter.enqueueDuringDispatch(opts.runtimeKey, eventBody(event), folded.inputLifecycle);
|
|
56071
56072
|
if (injected) {
|
|
56072
56073
|
host.injectedMainBufferEvents.add(event);
|
|
56074
|
+
ledger.markSeen(event, folded.covered);
|
|
56073
56075
|
opts.log?.info(`steer folded+injected for ${event.messageId} (will drain for bookkeeping)`);
|
|
56076
|
+
} else if (folded.frame) {
|
|
56077
|
+
ledger.deferFrame(event, folded.frame, folded.covered);
|
|
56078
|
+
opts.log?.info(`steer folded but not injected for ${event.messageId} \u2014 frame deferred to the drain`);
|
|
56074
56079
|
}
|
|
56075
56080
|
}
|
|
56076
56081
|
async function dispatchLaneGroup(host, opts) {
|
|
@@ -56083,18 +56088,9 @@ async function dispatchLaneGroup(host, opts) {
|
|
|
56083
56088
|
if (!(err instanceof LedgerUnsupportedError))
|
|
56084
56089
|
throw err;
|
|
56085
56090
|
host.disableLedger("claim endpoint missing");
|
|
56086
|
-
|
|
56087
|
-
|
|
56088
|
-
|
|
56089
|
-
return "shutdown";
|
|
56090
|
-
for (const ev of opts.events) {
|
|
56091
|
-
host.opts.client.ackDispatch(host.opts.config.org_id, {
|
|
56092
|
-
source_type: ev.ackSourceType ?? "message",
|
|
56093
|
-
source_id: ev.ackSourceId ?? ev.messageId
|
|
56094
|
-
}).catch(() => {
|
|
56095
|
-
});
|
|
56096
|
-
}
|
|
56097
|
-
return "dispatched";
|
|
56091
|
+
for (const ev of opts.events)
|
|
56092
|
+
host.dispatchedMessages.delete(ev.messageId);
|
|
56093
|
+
return "foreign";
|
|
56098
56094
|
}
|
|
56099
56095
|
if (!lane) {
|
|
56100
56096
|
for (const ev of opts.events) {
|
|
@@ -56102,11 +56098,32 @@ async function dispatchLaneGroup(host, opts) {
|
|
|
56102
56098
|
}
|
|
56103
56099
|
return "foreign";
|
|
56104
56100
|
}
|
|
56101
|
+
const pending = ledger.takeFrame(lane);
|
|
56102
|
+
const frame = pending.frame;
|
|
56103
|
+
if (!frame && opts.events.every((ev) => lane.seen.has(ev.messageId))) {
|
|
56104
|
+
host.opts.log?.info(`lane group for ${event.messageId} already rendered by the server frame \u2014 no turn`);
|
|
56105
|
+
const pendingInjections2 = host.opts.dispatchAdapter.hasPendingInjections?.(opts.sessionKey) ?? false;
|
|
56106
|
+
await ledger.completeIfIdle(lane.laneKey, pendingInjections2 || opts.hasMoreLocal());
|
|
56107
|
+
return "dispatched";
|
|
56108
|
+
}
|
|
56109
|
+
if (!frame) {
|
|
56110
|
+
host.opts.log?.warn(`lane group for ${event.messageId} claimed without a frame \u2014 releasing the members instead of running`);
|
|
56111
|
+
for (const ev of opts.events)
|
|
56112
|
+
host.dispatchedMessages.delete(ev.messageId);
|
|
56113
|
+
await ledger.release(lane.laneKey).catch(() => {
|
|
56114
|
+
});
|
|
56115
|
+
return "foreign";
|
|
56116
|
+
}
|
|
56117
|
+
applyWake(event, pending);
|
|
56105
56118
|
host.noteSessionLane(opts.sessionKey, lane.laneKey);
|
|
56106
56119
|
let dispatched = false;
|
|
56107
56120
|
try {
|
|
56108
|
-
const inputLifecycle = ledger.
|
|
56109
|
-
|
|
56121
|
+
const inputLifecycle = ledger.inputLifecycleFor(lane, [
|
|
56122
|
+
...opts.earlier.map((ev) => ev.messageId),
|
|
56123
|
+
event.messageId,
|
|
56124
|
+
...frame ? pending.ids : []
|
|
56125
|
+
]);
|
|
56126
|
+
dispatched = await host.runDispatch(event, opts.sessionKey, opts.bodyPrefix + eventBody(event), opts.earlier, opts.captureText, inputLifecycle);
|
|
56110
56127
|
} catch (err) {
|
|
56111
56128
|
host.noteSessionLane(opts.sessionKey, null);
|
|
56112
56129
|
await ledger.release(lane.laneKey).catch(() => {
|
|
@@ -56174,50 +56191,16 @@ async function resolveDispatchByID(host, dispatchEventId, lane) {
|
|
|
56174
56191
|
return "failed";
|
|
56175
56192
|
}
|
|
56176
56193
|
}
|
|
56177
|
-
function clearTypedDedupeForEvent(host, event) {
|
|
56178
|
-
const sourceId = event.ackSourceId;
|
|
56179
|
-
if (!sourceId)
|
|
56180
|
-
return;
|
|
56181
|
-
switch (event.ackSourceType) {
|
|
56182
|
-
case "task_activity": {
|
|
56183
|
-
const prefix = `${event.targetId}:`;
|
|
56184
|
-
for (const key of host.dispatchedTasks) {
|
|
56185
|
-
if (key.startsWith(prefix))
|
|
56186
|
-
host.dispatchedTasks.delete(key);
|
|
56187
|
-
}
|
|
56188
|
-
break;
|
|
56189
|
-
}
|
|
56190
|
-
case "comment":
|
|
56191
|
-
host.dispatchedTasks.delete(`comment:${sourceId}`);
|
|
56192
|
-
break;
|
|
56193
|
-
case "schedule_run":
|
|
56194
|
-
host.dispatchedTasks.delete(`schedule_run:${sourceId}`);
|
|
56195
|
-
break;
|
|
56196
|
-
case "external_trigger_run":
|
|
56197
|
-
host.dispatchedTasks.delete(`external_trigger_run:${sourceId}`);
|
|
56198
|
-
break;
|
|
56199
|
-
case "channel_message":
|
|
56200
|
-
host.dispatchedMessages.delete(`channel_message:${sourceId}`);
|
|
56201
|
-
break;
|
|
56202
|
-
case "approval":
|
|
56203
|
-
host.dispatchedTasks.delete(`approval:${sourceId}`);
|
|
56204
|
-
break;
|
|
56205
|
-
}
|
|
56206
|
-
}
|
|
56207
56194
|
async function settleDrainedTypedGroup(host, events, ids, turnErrored) {
|
|
56208
56195
|
if (turnErrored) {
|
|
56209
56196
|
host.opts.log?.info(`buffered typed turn for ${events[events.length - 1]?.messageId} surfaced a runtime error \u2014 leaving for re-drive`);
|
|
56210
|
-
for (const event of events)
|
|
56211
|
-
clearTypedDedupeForEvent(host, event);
|
|
56212
56197
|
return;
|
|
56213
56198
|
}
|
|
56214
56199
|
const legacyAckFrom = async (start) => {
|
|
56215
|
-
for (const
|
|
56200
|
+
for (const id of ids.slice(start)) {
|
|
56216
56201
|
try {
|
|
56217
56202
|
await host.opts.client.ackDispatchByID(host.opts.config.org_id, id);
|
|
56218
56203
|
} catch {
|
|
56219
|
-
} finally {
|
|
56220
|
-
clearTypedDedupeForEvent(host, events[start + j]);
|
|
56221
56204
|
}
|
|
56222
56205
|
}
|
|
56223
56206
|
};
|
|
@@ -56233,7 +56216,6 @@ async function settleDrainedTypedGroup(host, events, ids, turnErrored) {
|
|
|
56233
56216
|
await legacyAckFrom(i);
|
|
56234
56217
|
return;
|
|
56235
56218
|
}
|
|
56236
|
-
clearTypedDedupeForEvent(host, events[i]);
|
|
56237
56219
|
}
|
|
56238
56220
|
}
|
|
56239
56221
|
var TYPED_BACKOFF_BASE_MS = 2e3;
|
|
@@ -56269,18 +56251,8 @@ async function consumeTypedDispatch(host, ref, run, hooks) {
|
|
|
56269
56251
|
}
|
|
56270
56252
|
host.typedRedriveBackoff.set(backoffKey, { failures, until: Date.now() + backoffMs });
|
|
56271
56253
|
};
|
|
56272
|
-
const runLegacy = async () => {
|
|
56273
|
-
let acked = false;
|
|
56274
|
-
try {
|
|
56275
|
-
if (await run(ref.dispatchEventId)) {
|
|
56276
|
-
acked = settleAck(await hooks.legacyAck(ref.dispatchEventId));
|
|
56277
|
-
}
|
|
56278
|
-
} finally {
|
|
56279
|
-
settle(acked);
|
|
56280
|
-
}
|
|
56281
|
-
};
|
|
56282
56254
|
if (!host.laneLedger || host.ledgerDisabled) {
|
|
56283
|
-
|
|
56255
|
+
host.opts.log?.info(`typed dispatch ${backoffKey} skipped \u2014 the server renders no wake frame`);
|
|
56284
56256
|
return;
|
|
56285
56257
|
}
|
|
56286
56258
|
let lane;
|
|
@@ -56289,7 +56261,6 @@ async function consumeTypedDispatch(host, ref, run, hooks) {
|
|
|
56289
56261
|
} catch (err) {
|
|
56290
56262
|
if (err instanceof LedgerUnsupportedError) {
|
|
56291
56263
|
host.disableLedger("claim endpoint missing");
|
|
56292
|
-
await runLegacy();
|
|
56293
56264
|
return;
|
|
56294
56265
|
}
|
|
56295
56266
|
throw err;
|
|
@@ -56301,7 +56272,7 @@ async function consumeTypedDispatch(host, ref, run, hooks) {
|
|
|
56301
56272
|
let resolved = false;
|
|
56302
56273
|
let viaLegacyAck = false;
|
|
56303
56274
|
try {
|
|
56304
|
-
if (await run(lane
|
|
56275
|
+
if (await run(lane)) {
|
|
56305
56276
|
if (host.typedByIdCompleteUnsupported || !lane.typedDispatchEventId) {
|
|
56306
56277
|
viaLegacyAck = true;
|
|
56307
56278
|
resolved = settleAck(await hooks.legacyAck(lane.typedDispatchEventId));
|
|
@@ -56313,13 +56284,9 @@ async function consumeTypedDispatch(host, ref, run, hooks) {
|
|
|
56313
56284
|
viaLegacyAck = true;
|
|
56314
56285
|
resolved = settleAck(await hooks.legacyAck(lane.typedDispatchEventId));
|
|
56315
56286
|
} else if (outcome === "stale") {
|
|
56316
|
-
hooks.clearDedupe?.();
|
|
56317
56287
|
resolved = true;
|
|
56318
56288
|
} else {
|
|
56319
56289
|
resolved = outcome === "ok";
|
|
56320
|
-
if (!resolved) {
|
|
56321
|
-
hooks.clearDedupe?.();
|
|
56322
|
-
}
|
|
56323
56290
|
}
|
|
56324
56291
|
}
|
|
56325
56292
|
}
|
|
@@ -56338,56 +56305,27 @@ async function consumeMessageWorkItem(host, item) {
|
|
|
56338
56305
|
return;
|
|
56339
56306
|
if (!host.tryClaimMessage(item.source_id))
|
|
56340
56307
|
return;
|
|
56341
|
-
if (host.dispatchState.mainBuffer.some((
|
|
56308
|
+
if (host.dispatchState.mainBuffer.some((event2) => event2.messageId === item.source_id))
|
|
56342
56309
|
return;
|
|
56343
|
-
|
|
56344
|
-
if (host.laneLedger && !host.ledgerDisabled && !host.typedByIdCompleteUnsupported) {
|
|
56345
|
-
void resolveDispatchByID(host, item.id).then((outcome) => {
|
|
56346
|
-
if (outcome === "unsupported") {
|
|
56347
|
-
host.typedByIdCompleteUnsupported = true;
|
|
56348
|
-
host.opts.client.ackDispatchByID(host.opts.config.org_id, item.id).catch(() => {
|
|
56349
|
-
});
|
|
56350
|
-
}
|
|
56351
|
-
});
|
|
56352
|
-
return;
|
|
56353
|
-
}
|
|
56354
|
-
host.opts.client.ackDispatchByID(host.opts.config.org_id, item.id).catch(() => {
|
|
56355
|
-
});
|
|
56356
|
-
};
|
|
56357
|
-
let msg = null;
|
|
56358
|
-
try {
|
|
56359
|
-
msg = await host.opts.client.getMessage(item.source_id);
|
|
56360
|
-
} catch (err) {
|
|
56361
|
-
const status = err?.status;
|
|
56362
|
-
if (status !== 404) {
|
|
56363
|
-
host.opts.log?.warn(`message fetch failed for ${item.source_id}, leaving pending: ${String(err)}`);
|
|
56364
|
-
host.dispatchedMessages.delete(item.source_id);
|
|
56365
|
-
return;
|
|
56366
|
-
}
|
|
56367
|
-
}
|
|
56368
|
-
if (!msg || msg.sender_id === host.opts.agentUserId) {
|
|
56369
|
-
host.dispatchedMessages.delete(item.source_id);
|
|
56370
|
-
ackItem();
|
|
56310
|
+
if (host.laneLedger && !host.ledgerDisabled && host.laneLedger.seenInFrame(item.chat_id, item.thread_root_id ?? void 0, item.source_id)) {
|
|
56371
56311
|
return;
|
|
56372
56312
|
}
|
|
56373
|
-
const
|
|
56374
|
-
|
|
56375
|
-
|
|
56376
|
-
|
|
56377
|
-
|
|
56378
|
-
|
|
56379
|
-
|
|
56380
|
-
|
|
56381
|
-
|
|
56382
|
-
|
|
56383
|
-
|
|
56384
|
-
|
|
56313
|
+
const change = splitChangeSource(item.source_id);
|
|
56314
|
+
const event = {
|
|
56315
|
+
type: "message",
|
|
56316
|
+
targetId: item.chat_id,
|
|
56317
|
+
targetType: "chat",
|
|
56318
|
+
senderId: item.actor_id ?? "",
|
|
56319
|
+
messageId: item.source_id,
|
|
56320
|
+
threadRootId: item.thread_root_id ?? void 0,
|
|
56321
|
+
deliveryReason: item.delivery_reason ?? change.reason ?? void 0,
|
|
56322
|
+
ackSourceType: "message",
|
|
56323
|
+
ackSourceId: item.source_id,
|
|
56324
|
+
dispatchEventId: item.id
|
|
56325
|
+
};
|
|
56385
56326
|
try {
|
|
56386
|
-
const dispatched = await host.handleInboundEvent(
|
|
56387
|
-
if (dispatched) {
|
|
56388
|
-
if (!laneResolved)
|
|
56389
|
-
ackItem();
|
|
56390
|
-
} else {
|
|
56327
|
+
const dispatched = await host.handleInboundEvent(event);
|
|
56328
|
+
if (!dispatched) {
|
|
56391
56329
|
host.dispatchedMessages.delete(item.source_id);
|
|
56392
56330
|
}
|
|
56393
56331
|
} catch (err) {
|
|
@@ -57592,6 +57530,16 @@ function createOtelLogger(layer, prefix) {
|
|
|
57592
57530
|
|
|
57593
57531
|
// ../agent-core/dist/gateway-base.js
|
|
57594
57532
|
var LIVE_SESSION_STATUSES = /* @__PURE__ */ new Set(["open", "active", "idle"]);
|
|
57533
|
+
var TYPED_EVENT_KINDS = {
|
|
57534
|
+
task_assign: { type: "task", ackSourceType: "task_activity" },
|
|
57535
|
+
task_update: { type: "task", ackSourceType: "task_activity" },
|
|
57536
|
+
task_comment: { type: "task_comment", ackSourceType: "comment" },
|
|
57537
|
+
wiki_comment: { type: "wiki_comment", ackSourceType: "comment" },
|
|
57538
|
+
"schedule.fire": { type: "schedule", ackSourceType: "schedule_run" },
|
|
57539
|
+
external_trigger: { type: "external_trigger", ackSourceType: "external_trigger_run" },
|
|
57540
|
+
channel_message: { type: "channel_message", ackSourceType: "channel_message" },
|
|
57541
|
+
approval_decided: { type: "approval", ackSourceType: "approval" }
|
|
57542
|
+
};
|
|
57595
57543
|
function parseShutdownDeadlineMs(raw) {
|
|
57596
57544
|
if (!raw)
|
|
57597
57545
|
return void 0;
|
|
@@ -57625,6 +57573,9 @@ function inputStepIdempotencyKey(event) {
|
|
|
57625
57573
|
return randomUUID();
|
|
57626
57574
|
}
|
|
57627
57575
|
function resolveStepTarget(event) {
|
|
57576
|
+
if (event.input?.step_target) {
|
|
57577
|
+
return { target_type: event.input.step_target.type, target_id: event.input.step_target.id };
|
|
57578
|
+
}
|
|
57628
57579
|
if (event.type === "task" || event.targetId.startsWith("tsk_")) {
|
|
57629
57580
|
return { target_type: "task", target_id: event.targetId };
|
|
57630
57581
|
}
|
|
@@ -57645,48 +57596,63 @@ function resolveStepTarget(event) {
|
|
|
57645
57596
|
}
|
|
57646
57597
|
return { target_type: "", target_id: event.targetId || void 0 };
|
|
57647
57598
|
}
|
|
57648
|
-
function
|
|
57649
|
-
|
|
57650
|
-
|
|
57651
|
-
|
|
57652
|
-
|
|
57653
|
-
|
|
57654
|
-
|
|
57655
|
-
|
|
57656
|
-
|
|
57657
|
-
|
|
57658
|
-
|
|
57659
|
-
|
|
57660
|
-
|
|
57661
|
-
|
|
57599
|
+
function inputTriggerTypeFor(type) {
|
|
57600
|
+
switch (type) {
|
|
57601
|
+
case "task":
|
|
57602
|
+
return "task_assign";
|
|
57603
|
+
case "task_comment":
|
|
57604
|
+
return "task_comment";
|
|
57605
|
+
case "wiki_comment":
|
|
57606
|
+
return "wiki_comment";
|
|
57607
|
+
case "schedule":
|
|
57608
|
+
return "schedule_fire";
|
|
57609
|
+
case "external_trigger":
|
|
57610
|
+
return "external_trigger";
|
|
57611
|
+
case "channel_message":
|
|
57612
|
+
return "channel_message";
|
|
57613
|
+
case "approval":
|
|
57614
|
+
return "approval_decided";
|
|
57615
|
+
default:
|
|
57616
|
+
return "mention";
|
|
57617
|
+
}
|
|
57618
|
+
}
|
|
57619
|
+
function inputTriggerRef(event) {
|
|
57620
|
+
const sourceId = event.ackSourceId ?? event.messageId;
|
|
57621
|
+
switch (event.type) {
|
|
57622
|
+
case "task":
|
|
57623
|
+
return { task_id: event.targetId };
|
|
57624
|
+
case "task_comment":
|
|
57625
|
+
return { comment_id: sourceId, task_id: event.targetId };
|
|
57626
|
+
case "wiki_comment":
|
|
57627
|
+
return { comment_id: sourceId, target_uri: `prll://${event.targetId}` };
|
|
57628
|
+
case "schedule":
|
|
57629
|
+
return { schedule_id: event.targetId, run_id: sourceId };
|
|
57630
|
+
case "external_trigger":
|
|
57631
|
+
return { trigger_id: event.targetId, run_id: sourceId };
|
|
57632
|
+
case "channel_message":
|
|
57633
|
+
return { conversation_id: event.targetId, channel_message_id: sourceId };
|
|
57634
|
+
case "approval":
|
|
57635
|
+
return { approval_id: sourceId };
|
|
57636
|
+
default:
|
|
57637
|
+
return {
|
|
57638
|
+
message_id: splitChangeSource(event.messageId).messageId,
|
|
57639
|
+
// Thread context for the session→chat backlink: a thread reply can
|
|
57640
|
+
// only be navigated to with its thread root.
|
|
57641
|
+
...event.threadRootId ? { thread_root_id: event.threadRootId } : {}
|
|
57642
|
+
};
|
|
57662
57643
|
}
|
|
57663
|
-
return { routingKey, label, targetType };
|
|
57664
|
-
}
|
|
57665
|
-
async function fetchAllChats(client, orgId, chatInfoMap) {
|
|
57666
|
-
let cursor;
|
|
57667
|
-
let total = 0;
|
|
57668
|
-
do {
|
|
57669
|
-
const res = await client.getChats(orgId, { limit: 100, cursor });
|
|
57670
|
-
for (const chat of res.data) {
|
|
57671
|
-
chatInfoMap.set(chat.id, {
|
|
57672
|
-
type: chat.type,
|
|
57673
|
-
name: chat.name ?? null,
|
|
57674
|
-
agentRoutingMode: chat.agent_routing_mode
|
|
57675
|
-
});
|
|
57676
|
-
}
|
|
57677
|
-
total += res.data.length;
|
|
57678
|
-
cursor = res.has_more ? res.next_cursor : void 0;
|
|
57679
|
-
} while (cursor);
|
|
57680
|
-
return total;
|
|
57681
57644
|
}
|
|
57682
57645
|
var ParallAgentGateway = class {
|
|
57683
57646
|
opts;
|
|
57684
|
-
|
|
57685
|
-
dispatchedTasks = /* @__PURE__ */ new Set();
|
|
57686
|
-
// connection id → provider alias, for channel_message prompt labeling
|
|
57687
|
-
// (stable mapping; avoids one connection fetch per inbound message).
|
|
57688
|
-
channelConnectionProviders = /* @__PURE__ */ new Map();
|
|
57647
|
+
// In-process in-flight guard for message WorkItems (see LaneFlowHost).
|
|
57689
57648
|
dispatchedMessages = /* @__PURE__ */ new Set();
|
|
57649
|
+
/**
|
|
57650
|
+
* Consumption fence: no WorkItem is claimed before this connection's
|
|
57651
|
+
* runtime contract is declared (handleHello). A claim made before the
|
|
57652
|
+
* declaration would get no frame — and a frameless claim has nothing to
|
|
57653
|
+
* run. Open until the first hello starts a declaration.
|
|
57654
|
+
*/
|
|
57655
|
+
contractReady = Promise.resolve();
|
|
57690
57656
|
injectedMainBufferEvents = /* @__PURE__ */ new WeakSet();
|
|
57691
57657
|
// Per-WorkItem failure backoff for typed dispatch consumption — see
|
|
57692
57658
|
// LaneFlowHost.typedRedriveBackoff in gateway-lane-flow.ts.
|
|
@@ -57798,29 +57764,6 @@ var ParallAgentGateway = class {
|
|
|
57798
57764
|
ws.on("hello", async (data) => {
|
|
57799
57765
|
await this.handleHello(data);
|
|
57800
57766
|
});
|
|
57801
|
-
ws.on("chat.update", (data) => {
|
|
57802
|
-
const changes = data.changes;
|
|
57803
|
-
if (!changes)
|
|
57804
|
-
return;
|
|
57805
|
-
const existing = this.chatInfoMap.get(data.chat_id);
|
|
57806
|
-
if (existing) {
|
|
57807
|
-
this.chatInfoMap.set(data.chat_id, {
|
|
57808
|
-
...existing,
|
|
57809
|
-
...typeof changes.type === "string" ? { type: changes.type } : {},
|
|
57810
|
-
...typeof changes.name === "string" ? { name: changes.name } : {},
|
|
57811
|
-
...typeof changes.agent_routing_mode === "string" ? { agentRoutingMode: changes.agent_routing_mode } : {}
|
|
57812
|
-
});
|
|
57813
|
-
} else if (typeof changes.type === "string") {
|
|
57814
|
-
this.chatInfoMap.set(data.chat_id, {
|
|
57815
|
-
type: changes.type,
|
|
57816
|
-
name: typeof changes.name === "string" ? changes.name : null,
|
|
57817
|
-
agentRoutingMode: typeof changes.agent_routing_mode === "string" ? changes.agent_routing_mode : "passive"
|
|
57818
|
-
});
|
|
57819
|
-
}
|
|
57820
|
-
});
|
|
57821
|
-
ws.on("message.new", async (data) => {
|
|
57822
|
-
await this.handleMessage(data);
|
|
57823
|
-
});
|
|
57824
57767
|
ws.on("agent_config.update", async (data) => {
|
|
57825
57768
|
this.opts.log?.info(`config update notification (version=${data.version})`);
|
|
57826
57769
|
try {
|
|
@@ -57848,135 +57791,11 @@ var ParallAgentGateway = class {
|
|
|
57848
57791
|
this.opts.log?.warn(`recovery.overflow \u2014 triggering full catch-up`);
|
|
57849
57792
|
this.catchUpFromDispatch().catch((err) => this.opts.log?.warn(`overflow catch-up failed: ${String(err)}`));
|
|
57850
57793
|
});
|
|
57851
|
-
ws.on("
|
|
57852
|
-
if (data.assignee_id !== this.opts.agentUserId)
|
|
57853
|
-
return;
|
|
57854
|
-
if (data.status !== "todo" && data.status !== "in_progress")
|
|
57855
|
-
return;
|
|
57794
|
+
ws.on("dispatch.new", async (data) => {
|
|
57856
57795
|
try {
|
|
57857
|
-
await this.
|
|
57858
|
-
legacyAck: (dispatchEventId) => {
|
|
57859
|
-
if (dispatchEventId) {
|
|
57860
|
-
return this.ackDispatchEvent(dispatchEventId, () => {
|
|
57861
|
-
this.dispatchedTasks.delete(`${data.id}:${data.updated_at}`);
|
|
57862
|
-
});
|
|
57863
|
-
}
|
|
57864
|
-
return this.opts.client.ackDispatch(this.opts.config.org_id, {
|
|
57865
|
-
source_type: "task_activity",
|
|
57866
|
-
source_id: data.id
|
|
57867
|
-
}).then(() => true, (err) => {
|
|
57868
|
-
this.dispatchedTasks.delete(`${data.id}:${data.updated_at}`);
|
|
57869
|
-
this.opts.log?.warn(`dispatch ack failed for task ${data.id}, releasing for re-drive: ${String(err)}`);
|
|
57870
|
-
return false;
|
|
57871
|
-
});
|
|
57872
|
-
},
|
|
57873
|
-
clearDedupe: () => this.dispatchedTasks.delete(`${data.id}:${data.updated_at}`)
|
|
57874
|
-
});
|
|
57796
|
+
await this.consumeWorkItem(data);
|
|
57875
57797
|
} catch (err) {
|
|
57876
|
-
this.opts.log?.error(`
|
|
57877
|
-
}
|
|
57878
|
-
});
|
|
57879
|
-
ws.on("dispatch.new", async (data) => {
|
|
57880
|
-
if (data.event_type !== "message" && this.isBufferedTypedWorkItem(data.id)) {
|
|
57881
|
-
this.opts.log?.info(`typed dispatch ${data.id} already buffered for the drain \u2014 skipping re-claim`);
|
|
57882
|
-
return;
|
|
57883
|
-
}
|
|
57884
|
-
if (data.event_type === "task_assign") {
|
|
57885
|
-
if (!data.task_id)
|
|
57886
|
-
return;
|
|
57887
|
-
try {
|
|
57888
|
-
await this.handleTaskAssignmentRedrive(data);
|
|
57889
|
-
} catch (err) {
|
|
57890
|
-
this.opts.log?.error(`task assignment re-drive failed for ${data.task_id}: ${String(err)}`);
|
|
57891
|
-
}
|
|
57892
|
-
} else if (data.event_type === "task_comment") {
|
|
57893
|
-
if (!data.source_id || !data.task_id)
|
|
57894
|
-
return;
|
|
57895
|
-
try {
|
|
57896
|
-
await this.consumeTypedDispatch({ dispatchEventId: data.id }, (dispatchEventId) => this.handleTaskComment(data.source_id, data.task_id ?? "", data.actor_id, data.delivery_reason, dispatchEventId), {
|
|
57897
|
-
legacyAck: () => this.ackDispatchEvent(data.id, () => this.clearTypedDispatchDedupe(data)),
|
|
57898
|
-
clearDedupe: () => this.clearTypedDispatchDedupe(data)
|
|
57899
|
-
});
|
|
57900
|
-
} catch (err) {
|
|
57901
|
-
this.opts.log?.error(`task comment dispatch failed for ${data.source_id}: ${String(err)}`);
|
|
57902
|
-
}
|
|
57903
|
-
} else if (data.event_type === "wiki_comment") {
|
|
57904
|
-
if (!data.source_id)
|
|
57905
|
-
return;
|
|
57906
|
-
try {
|
|
57907
|
-
await this.consumeTypedDispatch({ dispatchEventId: data.id }, (dispatchEventId) => this.handleWikiComment(data.source_id, data.actor_id, data.delivery_reason, dispatchEventId), {
|
|
57908
|
-
legacyAck: () => this.ackDispatchEvent(data.id, () => this.clearTypedDispatchDedupe(data)),
|
|
57909
|
-
clearDedupe: () => this.clearTypedDispatchDedupe(data)
|
|
57910
|
-
});
|
|
57911
|
-
} catch (err) {
|
|
57912
|
-
this.opts.log?.error(`wiki comment dispatch failed for ${data.source_id}: ${String(err)}`);
|
|
57913
|
-
}
|
|
57914
|
-
} else if (data.event_type === "task_update") {
|
|
57915
|
-
if (!data.task_id)
|
|
57916
|
-
return;
|
|
57917
|
-
try {
|
|
57918
|
-
await this.consumeTypedDispatch({ dispatchEventId: data.id }, (dispatchEventId) => this.handleTaskDispatch(data.task_id ?? "", data.source_id ?? data.task_id ?? "", {
|
|
57919
|
-
allowCreator: true,
|
|
57920
|
-
dispatchEventId
|
|
57921
|
-
}), {
|
|
57922
|
-
legacyAck: () => this.ackDispatchEvent(data.id, () => this.clearTypedDispatchDedupe(data)),
|
|
57923
|
-
clearDedupe: () => this.clearTypedDispatchDedupe(data)
|
|
57924
|
-
});
|
|
57925
|
-
} catch (err) {
|
|
57926
|
-
this.opts.log?.error(`task update dispatch failed for ${data.task_id}: ${String(err)}`);
|
|
57927
|
-
}
|
|
57928
|
-
} else if (data.event_type === "schedule.fire") {
|
|
57929
|
-
if (!data.source_id)
|
|
57930
|
-
return;
|
|
57931
|
-
try {
|
|
57932
|
-
await this.consumeTypedDispatch({ dispatchEventId: data.id }, (dispatchEventId) => this.fetchAndHandleScheduleFire(data.source_id, data.actor_id, dispatchEventId), {
|
|
57933
|
-
legacyAck: () => this.ackDispatchEvent(data.id, () => this.clearTypedDispatchDedupe(data)),
|
|
57934
|
-
clearDedupe: () => this.clearTypedDispatchDedupe(data)
|
|
57935
|
-
});
|
|
57936
|
-
} catch (err) {
|
|
57937
|
-
this.opts.log?.error(`schedule fire dispatch failed for ${data.source_id}: ${String(err)}`);
|
|
57938
|
-
}
|
|
57939
|
-
} else if (data.event_type === "external_trigger") {
|
|
57940
|
-
if (!data.source_id)
|
|
57941
|
-
return;
|
|
57942
|
-
try {
|
|
57943
|
-
await this.consumeTypedDispatch({ dispatchEventId: data.id }, (dispatchEventId) => this.fetchAndHandleExternalTriggerRun(data.source_id, dispatchEventId), {
|
|
57944
|
-
legacyAck: () => this.ackDispatchEvent(data.id, () => this.clearTypedDispatchDedupe(data)),
|
|
57945
|
-
clearDedupe: () => this.clearTypedDispatchDedupe(data)
|
|
57946
|
-
});
|
|
57947
|
-
} catch (err) {
|
|
57948
|
-
this.opts.log?.error(`external trigger dispatch failed for ${data.source_id}: ${String(err)}`);
|
|
57949
|
-
}
|
|
57950
|
-
} else if (data.event_type === "channel_message") {
|
|
57951
|
-
if (!data.source_id)
|
|
57952
|
-
return;
|
|
57953
|
-
try {
|
|
57954
|
-
await this.consumeTypedDispatch({ dispatchEventId: data.id }, (dispatchEventId) => this.fetchAndHandleChannelMessage(data.source_id, dispatchEventId), {
|
|
57955
|
-
legacyAck: () => this.ackDispatchEvent(data.id, () => this.clearTypedDispatchDedupe(data)),
|
|
57956
|
-
clearDedupe: () => this.clearTypedDispatchDedupe(data)
|
|
57957
|
-
});
|
|
57958
|
-
} catch (err) {
|
|
57959
|
-
this.opts.log?.error(`channel message dispatch failed for ${data.source_id}: ${String(err)}`);
|
|
57960
|
-
}
|
|
57961
|
-
} else if (data.event_type === "approval_decided") {
|
|
57962
|
-
if (!data.source_id)
|
|
57963
|
-
return;
|
|
57964
|
-
try {
|
|
57965
|
-
await this.consumeTypedDispatch({ dispatchEventId: data.id }, (dispatchEventId) => this.fetchAndHandleApprovalDecided(data.source_id, data.actor_id, data.chat_id ?? null, dispatchEventId), {
|
|
57966
|
-
legacyAck: () => this.ackDispatchEvent(data.id, () => this.clearTypedDispatchDedupe(data)),
|
|
57967
|
-
clearDedupe: () => this.clearTypedDispatchDedupe(data)
|
|
57968
|
-
});
|
|
57969
|
-
} catch (err) {
|
|
57970
|
-
this.opts.log?.error(`approval decided dispatch failed for ${data.source_id}: ${String(err)}`);
|
|
57971
|
-
}
|
|
57972
|
-
} else if (data.event_type === "message" && this.laneLedger && data.source_id && data.chat_id) {
|
|
57973
|
-
try {
|
|
57974
|
-
await this.handleMessageRedrive(data);
|
|
57975
|
-
} catch (err) {
|
|
57976
|
-
this.opts.log?.error(`message re-drive failed for ${data.source_id}: ${String(err)}`);
|
|
57977
|
-
}
|
|
57978
|
-
} else if (data.event_type !== "message") {
|
|
57979
|
-
this.opts.log?.info(`dispatch.new with unhandled event_type=${String(data.event_type)} (id=${data.id}) \u2014 no-op`);
|
|
57798
|
+
this.opts.log?.error(`dispatch ${data.id} (${String(data.event_type)}) failed: ${String(err)}`);
|
|
57980
57799
|
}
|
|
57981
57800
|
});
|
|
57982
57801
|
this.opts.log?.info(`connecting to ${this.opts.connectionLabel ?? "Parall WS"}...`);
|
|
@@ -58161,44 +57980,6 @@ var ParallAgentGateway = class {
|
|
|
58161
57980
|
isTypedEventBuffered(event) {
|
|
58162
57981
|
return this.isBufferedTypedWorkItem(event.dispatchEventId);
|
|
58163
57982
|
}
|
|
58164
|
-
// PARITY: this switch and gateway-lane-flow's clearTypedDedupeForEvent must
|
|
58165
|
-
// handle the same typed source families — extend BOTH when adding a typed
|
|
58166
|
-
// event type (same dedupe entries, keyed from different event shapes).
|
|
58167
|
-
clearTypedDispatchDedupe(item) {
|
|
58168
|
-
switch (item.event_type) {
|
|
58169
|
-
case "task_assign":
|
|
58170
|
-
case "task_update":
|
|
58171
|
-
if (item.task_id) {
|
|
58172
|
-
const prefix = `${item.task_id}:`;
|
|
58173
|
-
for (const key of this.dispatchedTasks) {
|
|
58174
|
-
if (key.startsWith(prefix))
|
|
58175
|
-
this.dispatchedTasks.delete(key);
|
|
58176
|
-
}
|
|
58177
|
-
}
|
|
58178
|
-
break;
|
|
58179
|
-
case "task_comment":
|
|
58180
|
-
case "wiki_comment":
|
|
58181
|
-
if (item.source_id)
|
|
58182
|
-
this.dispatchedTasks.delete(`comment:${item.source_id}`);
|
|
58183
|
-
break;
|
|
58184
|
-
case "schedule.fire":
|
|
58185
|
-
if (item.source_id)
|
|
58186
|
-
this.dispatchedTasks.delete(`schedule_run:${item.source_id}`);
|
|
58187
|
-
break;
|
|
58188
|
-
case "external_trigger":
|
|
58189
|
-
if (item.source_id)
|
|
58190
|
-
this.dispatchedTasks.delete(`external_trigger_run:${item.source_id}`);
|
|
58191
|
-
break;
|
|
58192
|
-
case "channel_message":
|
|
58193
|
-
if (item.source_id)
|
|
58194
|
-
this.dispatchedMessages.delete(`channel_message:${item.source_id}`);
|
|
58195
|
-
break;
|
|
58196
|
-
case "approval_decided":
|
|
58197
|
-
if (item.source_id)
|
|
58198
|
-
this.dispatchedTasks.delete(`approval:${item.source_id}`);
|
|
58199
|
-
break;
|
|
58200
|
-
}
|
|
58201
|
-
}
|
|
58202
57983
|
buildDispatchContext(event, sessionKey) {
|
|
58203
57984
|
const binding = this.sessionBindings.get(sessionKey);
|
|
58204
57985
|
return {
|
|
@@ -58211,7 +57992,7 @@ var ParallAgentGateway = class {
|
|
|
58211
57992
|
runtimeKey: this.opts.runtimeKey,
|
|
58212
57993
|
sessionId: binding?.agentSessionId,
|
|
58213
57994
|
chatId: event.type === "message" || event.type === "approval" ? event.targetId : void 0,
|
|
58214
|
-
triggerMessageId: event.messageId,
|
|
57995
|
+
triggerMessageId: splitChangeSource(event.messageId).messageId,
|
|
58215
57996
|
noReply: event.noReply ?? false,
|
|
58216
57997
|
contextFilePath: this.opts.contextFilePathForSession?.(sessionKey),
|
|
58217
57998
|
stepIdFilePath: this.opts.stepIdFilePathForSession?.(sessionKey),
|
|
@@ -58225,35 +58006,24 @@ var ParallAgentGateway = class {
|
|
|
58225
58006
|
}
|
|
58226
58007
|
async createInputStep(sessionId, event) {
|
|
58227
58008
|
const target = resolveStepTarget(event);
|
|
58009
|
+
const input = event.input;
|
|
58228
58010
|
await this.stepPersister.persist(sessionId, "input", {
|
|
58229
58011
|
step_type: "input",
|
|
58230
58012
|
target_type: target.target_type,
|
|
58231
58013
|
target_id: target.target_id,
|
|
58232
58014
|
idempotency_key: inputStepIdempotencyKey(event),
|
|
58233
58015
|
content: {
|
|
58234
|
-
|
|
58235
|
-
|
|
58236
|
-
|
|
58237
|
-
|
|
58238
|
-
|
|
58239
|
-
|
|
58240
|
-
|
|
58241
|
-
conversation_id: event.targetId,
|
|
58242
|
-
channel_message_id: event.messageId,
|
|
58243
|
-
provider: event.channelProvider,
|
|
58244
|
-
external_conversation_id: event.channelExternalConversationId
|
|
58245
|
-
} : event.type === "approval" ? { approval_id: event.messageId } : {
|
|
58246
|
-
message_id: event.messageId,
|
|
58247
|
-
// Thread context for the session→chat backlink:
|
|
58248
|
-
// a thread reply can only be navigated to with
|
|
58249
|
-
// its thread root (the chat surface rejects
|
|
58250
|
-
// bare thread-message targets).
|
|
58251
|
-
...event.threadRootId ? { thread_root_id: event.threadRootId } : {}
|
|
58252
|
-
},
|
|
58016
|
+
// What the server said about the wake (claim `input`), plus the
|
|
58017
|
+
// source pointer and the anchor the web needs to link a chat
|
|
58018
|
+
// message or a task to this session.
|
|
58019
|
+
trigger_type: input?.trigger_type ?? inputTriggerTypeFor(event.type),
|
|
58020
|
+
trigger_ref: inputTriggerRef(event),
|
|
58021
|
+
source_type: event.ackSourceType,
|
|
58022
|
+
source_id: event.ackSourceId ?? event.messageId,
|
|
58253
58023
|
sender_id: event.senderId,
|
|
58254
|
-
sender_name:
|
|
58255
|
-
summary: event.
|
|
58256
|
-
...
|
|
58024
|
+
...input?.sender_name ? { sender_name: input.sender_name } : {},
|
|
58025
|
+
summary: (input?.summary ?? eventBody(event)).substring(0, 200),
|
|
58026
|
+
...input?.sent_at ? { sent_at: input.sent_at } : {}
|
|
58257
58027
|
}
|
|
58258
58028
|
});
|
|
58259
58029
|
}
|
|
@@ -58765,13 +58535,14 @@ var ParallAgentGateway = class {
|
|
|
58765
58535
|
retainForkContinuationRetries(this.forkContinuationRetries, events, fork.continuationPrefix);
|
|
58766
58536
|
try {
|
|
58767
58537
|
const batchText = [];
|
|
58768
|
-
const
|
|
58538
|
+
const bodyPrefix = (fork.continuationPrefix ?? "") + buildForkScopePrefix(last);
|
|
58539
|
+
const body = bodyPrefix + eventBody(last);
|
|
58769
58540
|
let dispatched;
|
|
58770
58541
|
if (this.usesLaneLedger(last)) {
|
|
58771
58542
|
const outcome = await this.dispatchLaneGroup({
|
|
58772
58543
|
events,
|
|
58773
58544
|
sessionKey: fork.fork.sessionKey,
|
|
58774
|
-
|
|
58545
|
+
bodyPrefix,
|
|
58775
58546
|
earlier,
|
|
58776
58547
|
captureText: batchText,
|
|
58777
58548
|
// Per-LANE residue check (parity with the main-buffer path):
|
|
@@ -58846,9 +58617,9 @@ var ParallAgentGateway = class {
|
|
|
58846
58617
|
sourceEvent: {
|
|
58847
58618
|
type: first.type,
|
|
58848
58619
|
targetId: fork.targetId,
|
|
58849
|
-
summary: fork.processedEvents.length === 1 ? `${first.type}
|
|
58620
|
+
summary: fork.processedEvents.length === 1 ? `${first.type} in ${fork.targetId}` : `${fork.processedEvents.length} events in ${fork.targetId}`
|
|
58850
58621
|
},
|
|
58851
|
-
eventBodies: fork.processedEvents.map((e) =>
|
|
58622
|
+
eventBodies: fork.processedEvents.map((e) => forkResultBody(e)),
|
|
58852
58623
|
actions: [],
|
|
58853
58624
|
agentSummary,
|
|
58854
58625
|
historyPath
|
|
@@ -58919,7 +58690,7 @@ var ParallAgentGateway = class {
|
|
|
58919
58690
|
outcome = await this.dispatchLaneGroup({
|
|
58920
58691
|
events,
|
|
58921
58692
|
sessionKey: this.opts.runtimeKey,
|
|
58922
|
-
|
|
58693
|
+
bodyPrefix: forkPrefix,
|
|
58923
58694
|
earlier,
|
|
58924
58695
|
hasMoreLocal: () => this.dispatchState.mainBuffer.some((e) => this.dispatchGroupKey(e) === groupKey)
|
|
58925
58696
|
});
|
|
@@ -58961,16 +58732,14 @@ var ParallAgentGateway = class {
|
|
|
58961
58732
|
}
|
|
58962
58733
|
}
|
|
58963
58734
|
const isTypedGroup = events.every((ev) => ev.type !== "message");
|
|
58964
|
-
const body = isTypedGroup && events.length > 1 && this.opts.dispatchAdapter.earlierEventsInPrompt !== true ? events.map((ev) =>
|
|
58735
|
+
const body = isTypedGroup && events.length > 1 && this.opts.dispatchAdapter.earlierEventsInPrompt !== true ? events.map((ev) => eventBody(ev)).join("\n\n") : eventBody(event);
|
|
58965
58736
|
let dispatched;
|
|
58966
58737
|
try {
|
|
58967
58738
|
dispatched = await this.runDispatch(event, this.opts.runtimeKey, forkPrefix + body, earlier);
|
|
58968
58739
|
} catch (err) {
|
|
58969
58740
|
if (!isTypedGroup)
|
|
58970
58741
|
throw err;
|
|
58971
|
-
this.opts.log?.error(`typed drain dispatch failed for ${event.messageId} (group of ${events.length}
|
|
58972
|
-
for (const ev of events)
|
|
58973
|
-
clearTypedDedupeForEvent(this.laneFlowHost(), ev);
|
|
58742
|
+
this.opts.log?.error(`typed drain dispatch failed for ${event.messageId} (group of ${events.length}): ${String(err)}`);
|
|
58974
58743
|
this.dispatchState.pendingForkResults.unshift(...pendingFork);
|
|
58975
58744
|
continue;
|
|
58976
58745
|
}
|
|
@@ -58991,7 +58760,6 @@ var ParallAgentGateway = class {
|
|
|
58991
58760
|
source_id: sourceId
|
|
58992
58761
|
}).catch(() => {
|
|
58993
58762
|
});
|
|
58994
|
-
clearTypedDedupeForEvent(this.laneFlowHost(), bufferedEvent);
|
|
58995
58763
|
}
|
|
58996
58764
|
} finally {
|
|
58997
58765
|
for (const id of drainingIds)
|
|
@@ -59034,7 +58802,7 @@ var ParallAgentGateway = class {
|
|
|
59034
58802
|
outcome = await this.dispatchLaneGroup({
|
|
59035
58803
|
events: [event],
|
|
59036
58804
|
sessionKey: this.opts.runtimeKey,
|
|
59037
|
-
|
|
58805
|
+
bodyPrefix: forkPrefix,
|
|
59038
58806
|
earlier: [],
|
|
59039
58807
|
hasMoreLocal: () => this.dispatchState.mainBuffer.some((e) => this.dispatchGroupKey(e) === this.dispatchGroupKey(event))
|
|
59040
58808
|
});
|
|
@@ -59066,7 +58834,7 @@ var ParallAgentGateway = class {
|
|
|
59066
58834
|
}
|
|
59067
58835
|
let dispatched = false;
|
|
59068
58836
|
try {
|
|
59069
|
-
dispatched = await this.runDispatch(event, this.opts.runtimeKey, forkPrefix +
|
|
58837
|
+
dispatched = await this.runDispatch(event, this.opts.runtimeKey, forkPrefix + eventBody(event));
|
|
59070
58838
|
if (dispatched && typedRefs && this.consumeTurnError(this.opts.runtimeKey)) {
|
|
59071
58839
|
this.opts.log?.info(`typed dispatch turn for ${event.messageId} surfaced a runtime error \u2014 releasing for retry`);
|
|
59072
58840
|
dispatched = false;
|
|
@@ -59100,7 +58868,7 @@ var ParallAgentGateway = class {
|
|
|
59100
58868
|
// the WorkItem stays live, and every re-drive injects it AGAIN (the
|
|
59101
58869
|
// 7/16 watcher duplicate-delivery loop, #1149). Typed events stay
|
|
59102
58870
|
// buffered; the drain claims them as their own turn.
|
|
59103
|
-
event.type === "message" && !typedAheadInBuffer && this.dispatchState.mainCurrentTargetId === event.targetId && await this.opts.dispatchAdapter.enqueueDuringDispatch?.(this.opts.runtimeKey,
|
|
58871
|
+
event.type === "message" && event.frame != null && !typedAheadInBuffer && this.dispatchState.mainCurrentTargetId === event.targetId && await this.opts.dispatchAdapter.enqueueDuringDispatch?.(this.opts.runtimeKey, eventBody(event))
|
|
59104
58872
|
) {
|
|
59105
58873
|
this.opts.log?.info(`steer injected for ${event.messageId} (will drain for bookkeeping)`);
|
|
59106
58874
|
}
|
|
@@ -59161,605 +58929,75 @@ var ParallAgentGateway = class {
|
|
|
59161
58929
|
}
|
|
59162
58930
|
}
|
|
59163
58931
|
}
|
|
59164
|
-
|
|
59165
|
-
|
|
59166
|
-
|
|
59167
|
-
|
|
59168
|
-
|
|
59169
|
-
|
|
59170
|
-
|
|
59171
|
-
|
|
59172
|
-
|
|
59173
|
-
|
|
59174
|
-
};
|
|
59175
|
-
this.chatInfoMap.set(chatId, chatInfo);
|
|
59176
|
-
return chatInfo;
|
|
59177
|
-
} catch (err) {
|
|
59178
|
-
this.opts.log?.warn(`failed to resolve chat ${chatId}: ${String(err)}`);
|
|
59179
|
-
return null;
|
|
59180
|
-
}
|
|
59181
|
-
}
|
|
59182
|
-
async buildMessageDispatchDecision(chatId, message) {
|
|
59183
|
-
if (message.message_type !== "text") {
|
|
59184
|
-
return { action: "skip" };
|
|
59185
|
-
}
|
|
59186
|
-
const chatInfo = await this.getOrFetchChatInfo(chatId);
|
|
59187
|
-
if (!chatInfo)
|
|
59188
|
-
return { action: "retry" };
|
|
59189
|
-
const content = message.content;
|
|
59190
|
-
const body = content.text?.trim() ?? "";
|
|
59191
|
-
const hasAttachments = message.attachments?.length;
|
|
59192
|
-
if (!body && !hasAttachments)
|
|
59193
|
-
return { action: "skip" };
|
|
59194
|
-
const mentions = content.mentions ?? [];
|
|
59195
|
-
const isMentioned = mentions.some((mention) => mentionTargetsUser(mention.user_id, this.opts.agentUserId, "agent"));
|
|
59196
|
-
let deliveryReason;
|
|
59197
|
-
if (message.thread_root_id) {
|
|
59198
|
-
if (isMentioned) {
|
|
59199
|
-
deliveryReason = "mention";
|
|
59200
|
-
} else {
|
|
59201
|
-
let watching;
|
|
59202
|
-
try {
|
|
59203
|
-
watching = await this.opts.client.isWatchingThread(message.thread_root_id);
|
|
59204
|
-
} catch {
|
|
59205
|
-
return { action: "retry" };
|
|
59206
|
-
}
|
|
59207
|
-
if (!watching)
|
|
59208
|
-
return { action: "skip" };
|
|
59209
|
-
deliveryReason = "watcher";
|
|
59210
|
-
}
|
|
59211
|
-
} else if (chatInfo.type === "group") {
|
|
59212
|
-
if (chatInfo.agentRoutingMode !== "active" && !isMentioned)
|
|
59213
|
-
return { action: "skip" };
|
|
59214
|
-
if (isMentioned)
|
|
59215
|
-
deliveryReason = "mention";
|
|
59216
|
-
}
|
|
59217
|
-
const attachments = (message.attachments ?? []).map((a) => ({
|
|
59218
|
-
id: a.id,
|
|
59219
|
-
fileName: a.file_name,
|
|
59220
|
-
fileSize: a.file_size,
|
|
59221
|
-
mimeType: a.mime_type
|
|
59222
|
-
}));
|
|
59223
|
-
let unreadCount;
|
|
59224
|
-
let unreadSince;
|
|
59225
|
-
let threadReplyCount;
|
|
59226
|
-
let threadUnreadCount;
|
|
59227
|
-
let threadUnreadSince;
|
|
59228
|
-
const isPassiveOrSmart = chatInfo.type === "group" && chatInfo.agentRoutingMode !== "active";
|
|
59229
|
-
const unreadPromise = isPassiveOrSmart ? this.opts.client.getUnreadCounts(this.opts.config.org_id).catch(() => void 0) : Promise.resolve(void 0);
|
|
59230
|
-
const threadPromise = message.thread_root_id ? this.opts.client.getThreadUnread(this.opts.config.org_id, chatId, message.thread_root_id).catch(() => void 0) : Promise.resolve(void 0);
|
|
59231
|
-
const [counts, threadUnread] = await Promise.all([unreadPromise, threadPromise]);
|
|
59232
|
-
if (counts) {
|
|
59233
|
-
const entry = counts[chatId];
|
|
59234
|
-
if (entry && entry.count > 1) {
|
|
59235
|
-
unreadCount = entry.count;
|
|
59236
|
-
unreadSince = entry.since;
|
|
59237
|
-
}
|
|
59238
|
-
}
|
|
59239
|
-
if (threadUnread) {
|
|
59240
|
-
threadReplyCount = threadUnread.total;
|
|
59241
|
-
threadUnreadCount = threadUnread.unread > 0 ? threadUnread.unread : void 0;
|
|
59242
|
-
threadUnreadSince = threadUnread.since ?? void 0;
|
|
59243
|
-
}
|
|
59244
|
-
return {
|
|
59245
|
-
action: "dispatch",
|
|
59246
|
-
event: {
|
|
59247
|
-
type: "message",
|
|
59248
|
-
targetId: chatId,
|
|
59249
|
-
targetName: chatInfo.name ?? void 0,
|
|
59250
|
-
targetType: chatInfo.type,
|
|
59251
|
-
senderId: message.sender_id,
|
|
59252
|
-
senderName: message.sender?.display_name ?? message.sender_id,
|
|
59253
|
-
messageId: message.id,
|
|
59254
|
-
body: body || "[attachment]",
|
|
59255
|
-
threadRootId: message.thread_root_id ?? void 0,
|
|
59256
|
-
deliveryReason,
|
|
59257
|
-
noReply: message.hints?.no_reply ?? false,
|
|
59258
|
-
attachments: attachments.length > 0 ? attachments : void 0,
|
|
59259
|
-
sentAt: message.created_at,
|
|
59260
|
-
ackSourceType: "message",
|
|
59261
|
-
ackSourceId: message.id,
|
|
59262
|
-
unreadCount,
|
|
59263
|
-
unreadSince,
|
|
59264
|
-
threadReplyCount,
|
|
59265
|
-
threadUnreadCount,
|
|
59266
|
-
threadUnreadSince
|
|
59267
|
-
}
|
|
59268
|
-
};
|
|
59269
|
-
}
|
|
59270
|
-
async handleMessage(data) {
|
|
58932
|
+
/**
|
|
58933
|
+
* One WorkItem the server pushed (dispatch.new) or a catch-up page
|
|
58934
|
+
* listed: messages ride their (chat, thread) lane; every other family
|
|
58935
|
+
* rides its own dsp lane, claimed, run on the server frame, resolved by
|
|
58936
|
+
* id. A typed WorkItem whose event copy is already buffered for the
|
|
58937
|
+
* drain is left to the drain (re-claiming it would race the drain's
|
|
58938
|
+
* fence-less settlement).
|
|
58939
|
+
*/
|
|
58940
|
+
async consumeWorkItem(item) {
|
|
58941
|
+
await this.contractReady;
|
|
59271
58942
|
if (this.shuttingDown)
|
|
59272
58943
|
return;
|
|
59273
|
-
|
|
59274
|
-
|
|
59275
|
-
|
|
59276
|
-
|
|
59277
|
-
|
|
59278
|
-
|
|
59279
|
-
|
|
59280
|
-
|
|
59281
|
-
|
|
59282
|
-
|
|
58944
|
+
if (item.event_type === "message") {
|
|
58945
|
+
if (!item.chat_id || !item.source_id)
|
|
58946
|
+
return;
|
|
58947
|
+
await this.consumeMessageWorkItem({
|
|
58948
|
+
id: item.id,
|
|
58949
|
+
source_id: item.source_id,
|
|
58950
|
+
chat_id: item.chat_id,
|
|
58951
|
+
actor_id: item.actor_id,
|
|
58952
|
+
thread_root_id: item.thread_root_id,
|
|
58953
|
+
delivery_reason: item.delivery_reason
|
|
58954
|
+
});
|
|
59283
58955
|
return;
|
|
59284
58956
|
}
|
|
59285
|
-
|
|
59286
|
-
|
|
59287
|
-
const dispatched = await this.handleInboundEvent(event);
|
|
59288
|
-
if (dispatched) {
|
|
59289
|
-
if (!this.usesLaneLedger(event)) {
|
|
59290
|
-
this.opts.client.ackDispatch(this.opts.config.org_id, { source_type: "message", source_id: data.id }).catch(() => {
|
|
59291
|
-
});
|
|
59292
|
-
}
|
|
59293
|
-
} else {
|
|
59294
|
-
this.dispatchedMessages.delete(data.id);
|
|
59295
|
-
}
|
|
59296
|
-
} catch (err) {
|
|
59297
|
-
this.opts.log?.error(`event dispatch failed for ${data.id}: ${String(err)}`);
|
|
59298
|
-
this.dispatchedMessages.delete(data.id);
|
|
59299
|
-
}
|
|
59300
|
-
}
|
|
59301
|
-
// Ledger re-drive consumption: dispatch.new message hints re-enter the
|
|
59302
|
-
// shared WorkItem consumption path (same protocol as catch-up).
|
|
59303
|
-
async handleMessageRedrive(item) {
|
|
59304
|
-
if (!item.chat_id || !item.source_id)
|
|
58957
|
+
if (!TYPED_EVENT_KINDS[item.event_type]) {
|
|
58958
|
+
this.opts.log?.info(`dispatch with unhandled event_type=${String(item.event_type)} (id=${item.id}) \u2014 no-op`);
|
|
59305
58959
|
return;
|
|
59306
|
-
|
|
59307
|
-
|
|
59308
|
-
|
|
59309
|
-
chat_id: item.chat_id
|
|
59310
|
-
});
|
|
59311
|
-
}
|
|
59312
|
-
// A task assignment's first delivery rides task.assigned, but a typed lane
|
|
59313
|
-
// released without an effect is re-driven as dispatch.new. Reuse the exact
|
|
59314
|
-
// typed claim path used by catch-up so that recovery does not require a
|
|
59315
|
-
// runtime reconnect.
|
|
59316
|
-
async handleTaskAssignmentRedrive(item) {
|
|
59317
|
-
if (!item.task_id)
|
|
58960
|
+
}
|
|
58961
|
+
if (this.isBufferedTypedWorkItem(item.id)) {
|
|
58962
|
+
this.opts.log?.info(`typed dispatch ${item.id} already buffered for the drain \u2014 skipping re-claim`);
|
|
59318
58963
|
return;
|
|
59319
|
-
|
|
59320
|
-
|
|
59321
|
-
}), {
|
|
59322
|
-
legacyAck: (dispatchEventId) => this.ackDispatchEvent(dispatchEventId ?? item.id, () => this.clearTypedDispatchDedupe(item)),
|
|
59323
|
-
clearDedupe: () => this.clearTypedDispatchDedupe(item)
|
|
59324
|
-
});
|
|
58964
|
+
}
|
|
58965
|
+
await this.consumeTypedDispatch({ dispatchEventId: item.id }, (lane) => this.runTypedFrame(item, lane), { legacyAck: () => this.ackDispatchEvent(item.id) });
|
|
59325
58966
|
}
|
|
59326
58967
|
consumeMessageWorkItem(item) {
|
|
59327
58968
|
return consumeMessageWorkItem(this.laneFlowHost(), item);
|
|
59328
58969
|
}
|
|
59329
|
-
async handleTaskAssignment(task, ackSourceId, dispatchEventId) {
|
|
59330
|
-
if (this.shuttingDown)
|
|
59331
|
-
return false;
|
|
59332
|
-
const dedupeKey = `${task.id}:${task.updated_at}`;
|
|
59333
|
-
if (this.dispatchedTasks.has(dedupeKey)) {
|
|
59334
|
-
this.opts.log?.info(`skipping already-dispatched task ${task.identifier ?? task.id}`);
|
|
59335
|
-
return false;
|
|
59336
|
-
}
|
|
59337
|
-
this.dispatchedTasks.add(dedupeKey);
|
|
59338
|
-
this.opts.log?.info(`task assigned: ${task.identifier ?? task.id} "${task.title}"`);
|
|
59339
|
-
const parts = [`Title: ${task.title}`];
|
|
59340
|
-
parts.push(`Status: ${task.status}`, `Priority: ${task.priority}`);
|
|
59341
|
-
if (task.project_id)
|
|
59342
|
-
parts.push(`Project: prll://${task.project_id}`);
|
|
59343
|
-
if (task.parent_id)
|
|
59344
|
-
parts.push(`Parent: prll://${task.parent_id}`);
|
|
59345
|
-
if (task.description)
|
|
59346
|
-
parts.push("", task.description);
|
|
59347
|
-
const event = {
|
|
59348
|
-
type: "task",
|
|
59349
|
-
targetId: task.id,
|
|
59350
|
-
targetName: task.identifier ?? void 0,
|
|
59351
|
-
targetType: "task",
|
|
59352
|
-
senderId: task.creator_id,
|
|
59353
|
-
senderName: "system",
|
|
59354
|
-
messageId: task.id,
|
|
59355
|
-
body: parts.join("\n"),
|
|
59356
|
-
sentAt: task.updated_at ?? task.created_at,
|
|
59357
|
-
ackSourceType: "task_activity",
|
|
59358
|
-
ackSourceId,
|
|
59359
|
-
dispatchEventId
|
|
59360
|
-
};
|
|
59361
|
-
const dispatched = await this.handleInboundEvent(event);
|
|
59362
|
-
if (!dispatched && !this.isTypedEventBuffered(event)) {
|
|
59363
|
-
this.dispatchedTasks.delete(dedupeKey);
|
|
59364
|
-
}
|
|
59365
|
-
return dispatched;
|
|
59366
|
-
}
|
|
59367
|
-
async handleTaskDispatch(taskId, ackSourceId, opts = {}) {
|
|
59368
|
-
let task = null;
|
|
59369
|
-
try {
|
|
59370
|
-
task = await this.opts.client.getTask(this.opts.config.org_id, taskId);
|
|
59371
|
-
} catch (err) {
|
|
59372
|
-
const status = err?.status;
|
|
59373
|
-
if (status === 404)
|
|
59374
|
-
return true;
|
|
59375
|
-
throw err;
|
|
59376
|
-
}
|
|
59377
|
-
const isAssignee = task.assignee_id === this.opts.agentUserId;
|
|
59378
|
-
const isCreatorUpdate = opts.allowCreator === true && task.creator_id === this.opts.agentUserId;
|
|
59379
|
-
if (!isAssignee && !isCreatorUpdate) {
|
|
59380
|
-
this.opts.log?.info(`skipping stale task dispatch ${ackSourceId ?? taskId} \u2014 assigned to ${task.assignee_id}, creator ${task.creator_id}`);
|
|
59381
|
-
return true;
|
|
59382
|
-
}
|
|
59383
|
-
return this.handleTaskAssignment(task, ackSourceId, opts.dispatchEventId);
|
|
59384
|
-
}
|
|
59385
|
-
async handleTaskComment(commentId, taskId, actorId, deliveryReason, dispatchEventId) {
|
|
59386
|
-
if (this.shuttingDown)
|
|
59387
|
-
return false;
|
|
59388
|
-
const dedupeKey = `comment:${commentId}`;
|
|
59389
|
-
if (this.dispatchedTasks.has(dedupeKey))
|
|
59390
|
-
return false;
|
|
59391
|
-
this.dispatchedTasks.add(dedupeKey);
|
|
59392
|
-
let comment = null;
|
|
59393
|
-
try {
|
|
59394
|
-
comment = await this.opts.client.getComment(this.opts.config.org_id, commentId);
|
|
59395
|
-
} catch (err) {
|
|
59396
|
-
const status = err?.status;
|
|
59397
|
-
if (status === 404) {
|
|
59398
|
-
this.opts.log?.info(`skipping deleted comment ${commentId}, acking stale dispatch`);
|
|
59399
|
-
this.dispatchedTasks.delete(dedupeKey);
|
|
59400
|
-
return true;
|
|
59401
|
-
}
|
|
59402
|
-
this.dispatchedTasks.delete(dedupeKey);
|
|
59403
|
-
return false;
|
|
59404
|
-
}
|
|
59405
|
-
if (!comment) {
|
|
59406
|
-
this.dispatchedTasks.delete(dedupeKey);
|
|
59407
|
-
return true;
|
|
59408
|
-
}
|
|
59409
|
-
if (comment.hints?.no_reply) {
|
|
59410
|
-
this.opts.log?.info(`skipping no_reply task comment ${commentId}, acking stale dispatch`);
|
|
59411
|
-
this.dispatchedTasks.delete(dedupeKey);
|
|
59412
|
-
return true;
|
|
59413
|
-
}
|
|
59414
|
-
let task = null;
|
|
59415
|
-
try {
|
|
59416
|
-
task = await this.opts.client.getTask(this.opts.config.org_id, taskId);
|
|
59417
|
-
} catch {
|
|
59418
|
-
}
|
|
59419
|
-
const taskLabel = task ? `${task.identifier ?? task.id} "${task.title}"` : taskId;
|
|
59420
|
-
this.opts.log?.info(`task comment on ${taskLabel} by ${actorId ?? "unknown"}`);
|
|
59421
|
-
const parts = [];
|
|
59422
|
-
if (task) {
|
|
59423
|
-
parts.push(`Task: ${task.title} (prll://${task.id})`);
|
|
59424
|
-
parts.push(`Status: ${task.status}`, `Priority: ${task.priority}`);
|
|
59425
|
-
} else {
|
|
59426
|
-
parts.push(`Task: prll://${taskId}`);
|
|
59427
|
-
}
|
|
59428
|
-
parts.push(`Comment by: ${comment.author?.display_name ?? actorId ?? "unknown"} (prll://${comment.author_id})`);
|
|
59429
|
-
parts.push("", comment.body);
|
|
59430
|
-
const event = {
|
|
59431
|
-
type: "task_comment",
|
|
59432
|
-
targetId: taskId,
|
|
59433
|
-
targetName: task?.identifier ?? void 0,
|
|
59434
|
-
targetType: "task",
|
|
59435
|
-
senderId: comment.author_id,
|
|
59436
|
-
senderName: comment.author?.display_name ?? actorId ?? "unknown",
|
|
59437
|
-
messageId: commentId,
|
|
59438
|
-
body: parts.join("\n"),
|
|
59439
|
-
deliveryReason: deliveryReason ?? void 0,
|
|
59440
|
-
ackSourceType: "comment",
|
|
59441
|
-
ackSourceId: commentId,
|
|
59442
|
-
dispatchEventId
|
|
59443
|
-
};
|
|
59444
|
-
let dispatched;
|
|
59445
|
-
try {
|
|
59446
|
-
dispatched = await this.handleInboundEvent(event);
|
|
59447
|
-
} catch (err) {
|
|
59448
|
-
this.dispatchedTasks.delete(dedupeKey);
|
|
59449
|
-
throw err;
|
|
59450
|
-
}
|
|
59451
|
-
if (!dispatched && !this.isTypedEventBuffered(event)) {
|
|
59452
|
-
this.dispatchedTasks.delete(dedupeKey);
|
|
59453
|
-
}
|
|
59454
|
-
return dispatched;
|
|
59455
|
-
}
|
|
59456
|
-
async handleWikiComment(commentId, actorId, deliveryReason, dispatchEventId) {
|
|
59457
|
-
if (this.shuttingDown)
|
|
59458
|
-
return false;
|
|
59459
|
-
const dedupeKey = `comment:${commentId}`;
|
|
59460
|
-
if (this.dispatchedTasks.has(dedupeKey))
|
|
59461
|
-
return false;
|
|
59462
|
-
this.dispatchedTasks.add(dedupeKey);
|
|
59463
|
-
let comment = null;
|
|
59464
|
-
try {
|
|
59465
|
-
comment = await this.opts.client.getComment(this.opts.config.org_id, commentId);
|
|
59466
|
-
} catch (err) {
|
|
59467
|
-
const status = err?.status;
|
|
59468
|
-
if (status === 404 || status === 403) {
|
|
59469
|
-
this.opts.log?.info(`skipping inaccessible wiki comment ${commentId} (status ${status}), acking stale dispatch`);
|
|
59470
|
-
this.dispatchedTasks.delete(dedupeKey);
|
|
59471
|
-
return true;
|
|
59472
|
-
}
|
|
59473
|
-
this.dispatchedTasks.delete(dedupeKey);
|
|
59474
|
-
return false;
|
|
59475
|
-
}
|
|
59476
|
-
if (!comment) {
|
|
59477
|
-
this.dispatchedTasks.delete(dedupeKey);
|
|
59478
|
-
return true;
|
|
59479
|
-
}
|
|
59480
|
-
if (comment.hints?.no_reply) {
|
|
59481
|
-
this.opts.log?.info(`skipping no_reply wiki comment ${commentId}, acking stale dispatch`);
|
|
59482
|
-
this.dispatchedTasks.delete(dedupeKey);
|
|
59483
|
-
return true;
|
|
59484
|
-
}
|
|
59485
|
-
const target = parseWikiCommentTarget(comment.target_uri);
|
|
59486
|
-
this.opts.log?.info(`wiki comment on ${target.label} by ${actorId ?? "unknown"}`);
|
|
59487
|
-
const event = {
|
|
59488
|
-
type: "wiki_comment",
|
|
59489
|
-
// Full target_uri (scheme-stripped) is the routing key so different
|
|
59490
|
-
// pages / inline anchors / changesets in the same wiki don't collide on
|
|
59491
|
-
// one gateway lane. replyTargetUri keeps the canonical prll:// form.
|
|
59492
|
-
targetId: target.routingKey,
|
|
59493
|
-
targetName: target.label,
|
|
59494
|
-
targetType: target.targetType,
|
|
59495
|
-
senderId: comment.author_id,
|
|
59496
|
-
senderName: comment.author?.display_name ?? actorId ?? "unknown",
|
|
59497
|
-
messageId: commentId,
|
|
59498
|
-
body: comment.body,
|
|
59499
|
-
deliveryReason: deliveryReason ?? void 0,
|
|
59500
|
-
replyTargetUri: comment.target_uri,
|
|
59501
|
-
ackSourceType: "comment",
|
|
59502
|
-
ackSourceId: commentId,
|
|
59503
|
-
dispatchEventId
|
|
59504
|
-
};
|
|
59505
|
-
let dispatched;
|
|
59506
|
-
try {
|
|
59507
|
-
dispatched = await this.handleInboundEvent(event);
|
|
59508
|
-
} catch (err) {
|
|
59509
|
-
this.dispatchedTasks.delete(dedupeKey);
|
|
59510
|
-
throw err;
|
|
59511
|
-
}
|
|
59512
|
-
if (!dispatched && !this.isTypedEventBuffered(event)) {
|
|
59513
|
-
this.dispatchedTasks.delete(dedupeKey);
|
|
59514
|
-
}
|
|
59515
|
-
return dispatched;
|
|
59516
|
-
}
|
|
59517
58970
|
/**
|
|
59518
|
-
*
|
|
59519
|
-
*
|
|
59520
|
-
*
|
|
59521
|
-
*
|
|
59522
|
-
*
|
|
59523
|
-
* or retry forever in that case.
|
|
58971
|
+
* Run one claimed typed WorkItem on the frame the claim returned. The
|
|
58972
|
+
* event is addressing only: the routing target the server named
|
|
58973
|
+
* (`input.subject` — the task, the wiki target, the schedule, the
|
|
58974
|
+
* conversation, the chat an approval belongs to), the ids the ledger
|
|
58975
|
+
* keys on, and the input-step metadata. No frame means nothing to run.
|
|
59524
58976
|
*/
|
|
59525
|
-
async
|
|
59526
|
-
let run = null;
|
|
59527
|
-
try {
|
|
59528
|
-
run = await this.opts.client.getScheduleRun(this.opts.config.org_id, runId);
|
|
59529
|
-
} catch (err) {
|
|
59530
|
-
const status = err?.status;
|
|
59531
|
-
if (status === 404) {
|
|
59532
|
-
this.opts.log?.warn(`schedule run ${runId} not accessible (404), acking stale dispatch`);
|
|
59533
|
-
return true;
|
|
59534
|
-
}
|
|
59535
|
-
this.opts.log?.warn(`schedule run fetch failed for ${runId}, leaving pending: ${String(err)}`);
|
|
59536
|
-
return false;
|
|
59537
|
-
}
|
|
59538
|
-
if (!run)
|
|
59539
|
-
return true;
|
|
59540
|
-
return this.handleScheduleFire(run, actorId, dispatchEventId);
|
|
59541
|
-
}
|
|
59542
|
-
async handleScheduleFire(run, actorId, dispatchEventId) {
|
|
58977
|
+
async runTypedFrame(item, lane) {
|
|
59543
58978
|
if (this.shuttingDown)
|
|
59544
58979
|
return false;
|
|
59545
|
-
const
|
|
59546
|
-
if (
|
|
59547
|
-
|
|
59548
|
-
this.dispatchedTasks.add(dedupeKey);
|
|
59549
|
-
this.opts.log?.info(`schedule fired: ${run.id} (schedule ${run.schedule_id})`);
|
|
59550
|
-
const event = {
|
|
59551
|
-
type: "schedule",
|
|
59552
|
-
// Route by schedule_id (not attached chat_id) so concurrent fires of
|
|
59553
|
-
// different schedules can fork independently — matches the PR1 primitive
|
|
59554
|
-
// design where "schedule triggers; target decides response" and fire
|
|
59555
|
-
// semantics are independent of any attached conversation.
|
|
59556
|
-
targetId: run.schedule_id,
|
|
59557
|
-
targetType: "schedule",
|
|
59558
|
-
senderId: actorId ?? "system",
|
|
59559
|
-
senderName: "schedule",
|
|
59560
|
-
messageId: run.id,
|
|
59561
|
-
body: run.fired_description ?? "",
|
|
59562
|
-
scheduledFireAt: run.scheduled_fire_at,
|
|
59563
|
-
attachedUri: run.fired_attached_uri ?? void 0,
|
|
59564
|
-
ackSourceType: "schedule_run",
|
|
59565
|
-
ackSourceId: run.id,
|
|
59566
|
-
dispatchEventId
|
|
59567
|
-
};
|
|
59568
|
-
let dispatched;
|
|
59569
|
-
try {
|
|
59570
|
-
dispatched = await this.handleInboundEvent(event);
|
|
59571
|
-
} catch (err) {
|
|
59572
|
-
this.dispatchedTasks.delete(dedupeKey);
|
|
59573
|
-
throw err;
|
|
59574
|
-
}
|
|
59575
|
-
if (!dispatched && !this.isTypedEventBuffered(event)) {
|
|
59576
|
-
this.dispatchedTasks.delete(dedupeKey);
|
|
59577
|
-
}
|
|
59578
|
-
return dispatched;
|
|
59579
|
-
}
|
|
59580
|
-
async fetchAndHandleExternalTriggerRun(runId, dispatchEventId) {
|
|
59581
|
-
let run = null;
|
|
59582
|
-
try {
|
|
59583
|
-
run = await this.opts.client.getExternalTriggerRun(this.opts.config.org_id, runId);
|
|
59584
|
-
} catch (err) {
|
|
59585
|
-
const status = err?.status;
|
|
59586
|
-
if (status === 404) {
|
|
59587
|
-
this.opts.log?.warn(`external trigger run ${runId} not accessible (404), acking stale dispatch`);
|
|
59588
|
-
return true;
|
|
59589
|
-
}
|
|
59590
|
-
this.opts.log?.warn(`external trigger run fetch failed for ${runId}, leaving pending: ${String(err)}`);
|
|
59591
|
-
return false;
|
|
59592
|
-
}
|
|
59593
|
-
if (!run)
|
|
59594
|
-
return true;
|
|
59595
|
-
return this.handleExternalTriggerRun(run, dispatchEventId);
|
|
59596
|
-
}
|
|
59597
|
-
// fetchAndHandleChannelMessage resolves a channel_message dispatch to its
|
|
59598
|
-
// durable ChannelMessage + conversation and hands it to the inbound
|
|
59599
|
-
// pipeline. targetId = the ChannelConversation id, so per-conversation
|
|
59600
|
-
// multi-turn continuity rides the same per-target session mechanics as
|
|
59601
|
-
// chats. Design: docs/engineering-design/external-im-channel-design.md.
|
|
59602
|
-
async fetchAndHandleChannelMessage(messageId, dispatchEventId) {
|
|
59603
|
-
if (this.shuttingDown)
|
|
59604
|
-
return false;
|
|
59605
|
-
const claimKey = `channel_message:${messageId}`;
|
|
59606
|
-
if (!this.tryClaimMessage(claimKey))
|
|
59607
|
-
return false;
|
|
59608
|
-
let msg = null;
|
|
59609
|
-
let conv = null;
|
|
59610
|
-
try {
|
|
59611
|
-
msg = await this.opts.client.getChannelMessage(this.opts.config.org_id, messageId);
|
|
59612
|
-
conv = await this.opts.client.getChannelConversation(this.opts.config.org_id, msg.conversation_id);
|
|
59613
|
-
} catch (err) {
|
|
59614
|
-
const status = err?.status;
|
|
59615
|
-
if (status === 404) {
|
|
59616
|
-
this.opts.log?.warn(`channel message ${messageId} not accessible (404), acking stale dispatch`);
|
|
59617
|
-
return true;
|
|
59618
|
-
}
|
|
59619
|
-
this.dispatchedMessages.delete(claimKey);
|
|
59620
|
-
this.opts.log?.warn(`channel message fetch failed for ${messageId}, leaving pending: ${String(err)}`);
|
|
59621
|
-
return false;
|
|
59622
|
-
}
|
|
59623
|
-
if (!msg || !conv) {
|
|
59624
|
-
return true;
|
|
59625
|
-
}
|
|
59626
|
-
this.opts.log?.info(`channel message: ${msg.id} (conversation ${conv.id})`);
|
|
59627
|
-
let provider = this.channelConnectionProviders.get(conv.connection_id);
|
|
59628
|
-
if (!provider) {
|
|
59629
|
-
try {
|
|
59630
|
-
const connection = await this.opts.client.getChannelConnection(this.opts.config.org_id, conv.connection_id);
|
|
59631
|
-
provider = connection.provider;
|
|
59632
|
-
this.channelConnectionProviders.set(conv.connection_id, provider);
|
|
59633
|
-
} catch {
|
|
59634
|
-
provider = void 0;
|
|
59635
|
-
}
|
|
59636
|
-
}
|
|
59637
|
-
const keys = this.opts.getCapabilityKeys?.() ?? [];
|
|
59638
|
-
const cliCapable = provider ? keys.includes(channelCapabilityKeyFor(provider)) : keys.some((k) => k.endsWith("-cli") || k === CAPABILITY_SLACK_SEND || k === CAPABILITY_WECHAT_SEND);
|
|
59639
|
-
const event = {
|
|
59640
|
-
type: "channel_message",
|
|
59641
|
-
targetId: conv.id,
|
|
59642
|
-
targetName: conv.external_conversation_name || conv.external_user_name || conv.external_conversation_id,
|
|
59643
|
-
targetType: "channel_conversation",
|
|
59644
|
-
senderId: msg.external_user_id || "external",
|
|
59645
|
-
senderName: msg.external_user_name || msg.external_user_id || "external user",
|
|
59646
|
-
messageId: msg.id,
|
|
59647
|
-
body: msg.text,
|
|
59648
|
-
sentAt: msg.received_at,
|
|
59649
|
-
channelProvider: provider,
|
|
59650
|
-
channelConversationType: conv.conversation_type || void 0,
|
|
59651
|
-
channelExternalConversationId: conv.external_conversation_id,
|
|
59652
|
-
channelExternalConversationName: conv.external_conversation_name || void 0,
|
|
59653
|
-
channelExternalMessageId: msg.external_message_id,
|
|
59654
|
-
channelCliCapable: cliCapable,
|
|
59655
|
-
ackSourceType: "channel_message",
|
|
59656
|
-
ackSourceId: msg.id,
|
|
59657
|
-
dispatchEventId
|
|
59658
|
-
};
|
|
59659
|
-
let dispatched;
|
|
59660
|
-
try {
|
|
59661
|
-
dispatched = await this.handleInboundEvent(event);
|
|
59662
|
-
} catch (err) {
|
|
59663
|
-
this.dispatchedMessages.delete(claimKey);
|
|
59664
|
-
throw err;
|
|
59665
|
-
}
|
|
59666
|
-
if (!dispatched && !this.isTypedEventBuffered(event)) {
|
|
59667
|
-
this.dispatchedMessages.delete(claimKey);
|
|
59668
|
-
}
|
|
59669
|
-
return dispatched;
|
|
59670
|
-
}
|
|
59671
|
-
async handleExternalTriggerRun(run, dispatchEventId) {
|
|
59672
|
-
if (this.shuttingDown)
|
|
59673
|
-
return false;
|
|
59674
|
-
const dedupeKey = `external_trigger_run:${run.id}`;
|
|
59675
|
-
if (this.dispatchedTasks.has(dedupeKey))
|
|
59676
|
-
return false;
|
|
59677
|
-
this.dispatchedTasks.add(dedupeKey);
|
|
59678
|
-
this.opts.log?.info(`external trigger fired: ${run.id} (trigger ${run.trigger_id})`);
|
|
59679
|
-
const attachedUri = typeof run.trigger_snapshot?.attached_to_uri === "string" ? run.trigger_snapshot.attached_to_uri : void 0;
|
|
59680
|
-
const event = {
|
|
59681
|
-
type: "external_trigger",
|
|
59682
|
-
targetId: run.trigger_id,
|
|
59683
|
-
targetName: run.trigger_name || void 0,
|
|
59684
|
-
targetType: "external_trigger",
|
|
59685
|
-
senderId: "system",
|
|
59686
|
-
senderName: "external",
|
|
59687
|
-
messageId: run.id,
|
|
59688
|
-
body: run.agent_input_body ?? "",
|
|
59689
|
-
externalConnectionId: run.connection_id,
|
|
59690
|
-
externalConnectionSourceType: run.connection_source_type || void 0,
|
|
59691
|
-
externalConnectionDisplayName: run.connection_display_name || void 0,
|
|
59692
|
-
externalIngressEventId: run.ingress_event_id,
|
|
59693
|
-
externalIngressEventType: run.ingress_event_type || void 0,
|
|
59694
|
-
attachedUri,
|
|
59695
|
-
ackSourceType: "external_trigger_run",
|
|
59696
|
-
ackSourceId: run.id,
|
|
59697
|
-
dispatchEventId
|
|
59698
|
-
};
|
|
59699
|
-
let dispatched;
|
|
59700
|
-
try {
|
|
59701
|
-
dispatched = await this.handleInboundEvent(event);
|
|
59702
|
-
} catch (err) {
|
|
59703
|
-
this.dispatchedTasks.delete(dedupeKey);
|
|
59704
|
-
throw err;
|
|
59705
|
-
}
|
|
59706
|
-
if (!dispatched && !this.isTypedEventBuffered(event)) {
|
|
59707
|
-
this.dispatchedTasks.delete(dedupeKey);
|
|
59708
|
-
}
|
|
59709
|
-
return dispatched;
|
|
59710
|
-
}
|
|
59711
|
-
async fetchAndHandleApprovalDecided(approvalId, actorId, chatId, dispatchEventId) {
|
|
59712
|
-
let approval = null;
|
|
59713
|
-
try {
|
|
59714
|
-
approval = await this.opts.client.getApproval(approvalId);
|
|
59715
|
-
} catch (err) {
|
|
59716
|
-
const status = err?.status;
|
|
59717
|
-
if (status === 404 || status === 403) {
|
|
59718
|
-
this.opts.log?.warn(`approval ${approvalId} not accessible (${status}), acking stale dispatch`);
|
|
59719
|
-
return true;
|
|
59720
|
-
}
|
|
59721
|
-
this.opts.log?.warn(`approval fetch failed for ${approvalId}, leaving pending: ${String(err)}`);
|
|
58980
|
+
const wake = this.laneLedger?.takeFrame(lane);
|
|
58981
|
+
if (!wake?.frame) {
|
|
58982
|
+
this.opts.log?.warn(`typed dispatch ${item.id} (${String(item.event_type)}) claimed without a frame \u2014 leaving it pending`);
|
|
59722
58983
|
return false;
|
|
59723
58984
|
}
|
|
59724
|
-
|
|
59725
|
-
|
|
59726
|
-
if (this.shuttingDown)
|
|
59727
|
-
return false;
|
|
59728
|
-
const dedupeKey = `approval:${approval.id}`;
|
|
59729
|
-
if (this.dispatchedTasks.has(dedupeKey))
|
|
59730
|
-
return false;
|
|
59731
|
-
this.dispatchedTasks.add(dedupeKey);
|
|
59732
|
-
this.opts.log?.info(`approval decided: ${approval.id} (${approval.status})`);
|
|
59733
|
-
const statusLabel = approval.status === "approved" ? "Approved" : "Rejected";
|
|
59734
|
-
const execInfo = approval.execution_status ? ` | execution: ${approval.execution_status}` : "";
|
|
59735
|
-
const reasonLine = formatApprovalDecisionReason(approval.status, approval.decision_reason);
|
|
59736
|
-
const reasonInfo = reasonLine ? `
|
|
59737
|
-
${reasonLine}` : "";
|
|
59738
|
-
const body = `${statusLabel}: ${approval.title}${execInfo}${reasonInfo}`;
|
|
58985
|
+
const kind = TYPED_EVENT_KINDS[item.event_type];
|
|
58986
|
+
const targetId = wake.input?.subject || item.task_id || item.chat_id || item.source_id || item.id;
|
|
59739
58987
|
const event = {
|
|
59740
|
-
type:
|
|
59741
|
-
targetId
|
|
59742
|
-
|
|
59743
|
-
|
|
59744
|
-
messageId:
|
|
59745
|
-
|
|
59746
|
-
|
|
59747
|
-
|
|
59748
|
-
|
|
59749
|
-
|
|
59750
|
-
|
|
59751
|
-
};
|
|
59752
|
-
|
|
59753
|
-
try {
|
|
59754
|
-
dispatched = await this.handleInboundEvent(event);
|
|
59755
|
-
} catch (err) {
|
|
59756
|
-
this.dispatchedTasks.delete(dedupeKey);
|
|
59757
|
-
throw err;
|
|
59758
|
-
}
|
|
59759
|
-
if (!dispatched && !this.isTypedEventBuffered(event)) {
|
|
59760
|
-
this.dispatchedTasks.delete(dedupeKey);
|
|
59761
|
-
}
|
|
59762
|
-
return dispatched;
|
|
58988
|
+
type: kind.type,
|
|
58989
|
+
targetId,
|
|
58990
|
+
targetType: wake.input?.step_target?.type,
|
|
58991
|
+
senderId: wake.input?.sender_id ?? item.actor_id ?? "system",
|
|
58992
|
+
messageId: item.source_id,
|
|
58993
|
+
deliveryReason: item.delivery_reason ?? void 0,
|
|
58994
|
+
ackSourceType: kind.ackSourceType,
|
|
58995
|
+
ackSourceId: item.source_id,
|
|
58996
|
+
dispatchEventId: item.id
|
|
58997
|
+
};
|
|
58998
|
+
applyWake(event, wake);
|
|
58999
|
+
this.opts.log?.info(`${String(item.event_type)} ${item.source_id} \u2192 ${targetId}`);
|
|
59000
|
+
return this.handleInboundEvent(event);
|
|
59763
59001
|
}
|
|
59764
59002
|
async catchUpFromDispatch() {
|
|
59765
59003
|
const OVERFLOW_THRESHOLD = 500;
|
|
@@ -59813,54 +59051,9 @@ ${reasonLine}` : "";
|
|
|
59813
59051
|
}
|
|
59814
59052
|
continue;
|
|
59815
59053
|
}
|
|
59816
|
-
if (item.event_type !== "message" && this.isBufferedTypedWorkItem(item.id)) {
|
|
59817
|
-
this.opts.log?.info(`typed dispatch ${item.id} already buffered for the drain \u2014 skipping catch-up claim`);
|
|
59818
|
-
continue;
|
|
59819
|
-
}
|
|
59820
59054
|
processed++;
|
|
59821
59055
|
try {
|
|
59822
|
-
|
|
59823
|
-
legacyAck: () => this.ackDispatchEvent(item.id, () => this.clearTypedDispatchDedupe(item)),
|
|
59824
|
-
clearDedupe: () => this.clearTypedDispatchDedupe(item)
|
|
59825
|
-
};
|
|
59826
|
-
if (item.event_type === "task_assign" && item.task_id) {
|
|
59827
|
-
try {
|
|
59828
|
-
await this.consumeTypedDispatch({ dispatchEventId: item.id }, (dispatchEventId) => this.handleTaskDispatch(item.task_id ?? "", item.source_id ?? item.task_id ?? "", {
|
|
59829
|
-
dispatchEventId
|
|
59830
|
-
}), typedHooks);
|
|
59831
|
-
} catch (err) {
|
|
59832
|
-
this.opts.log?.warn(`catch-up task fetch failed for ${item.task_id}, leaving pending: ${String(err)}`);
|
|
59833
|
-
continue;
|
|
59834
|
-
}
|
|
59835
|
-
} else if (item.event_type === "task_update" && item.task_id) {
|
|
59836
|
-
try {
|
|
59837
|
-
await this.consumeTypedDispatch({ dispatchEventId: item.id }, (dispatchEventId) => this.handleTaskDispatch(item.task_id ?? "", item.source_id ?? item.task_id ?? "", {
|
|
59838
|
-
allowCreator: true,
|
|
59839
|
-
dispatchEventId
|
|
59840
|
-
}), typedHooks);
|
|
59841
|
-
} catch (err) {
|
|
59842
|
-
this.opts.log?.warn(`catch-up task fetch failed for ${item.task_id}, leaving pending: ${String(err)}`);
|
|
59843
|
-
continue;
|
|
59844
|
-
}
|
|
59845
|
-
} else if (item.event_type === "task_comment" && item.source_id && item.task_id) {
|
|
59846
|
-
await this.consumeTypedDispatch({ dispatchEventId: item.id }, (dispatchEventId) => this.handleTaskComment(item.source_id, item.task_id ?? "", item.actor_id, item.delivery_reason, dispatchEventId), typedHooks);
|
|
59847
|
-
} else if (item.event_type === "wiki_comment" && item.source_id) {
|
|
59848
|
-
await this.consumeTypedDispatch({ dispatchEventId: item.id }, (dispatchEventId) => this.handleWikiComment(item.source_id, item.actor_id, item.delivery_reason, dispatchEventId), typedHooks);
|
|
59849
|
-
} else if (item.event_type === "schedule.fire" && item.source_id) {
|
|
59850
|
-
await this.consumeTypedDispatch({ dispatchEventId: item.id }, (dispatchEventId) => this.fetchAndHandleScheduleFire(item.source_id, item.actor_id, dispatchEventId), typedHooks);
|
|
59851
|
-
} else if (item.event_type === "external_trigger" && item.source_id) {
|
|
59852
|
-
await this.consumeTypedDispatch({ dispatchEventId: item.id }, (dispatchEventId) => this.fetchAndHandleExternalTriggerRun(item.source_id, dispatchEventId), typedHooks);
|
|
59853
|
-
} else if (item.event_type === "channel_message" && item.source_id) {
|
|
59854
|
-
await this.consumeTypedDispatch({ dispatchEventId: item.id }, (dispatchEventId) => this.fetchAndHandleChannelMessage(item.source_id, dispatchEventId), typedHooks);
|
|
59855
|
-
} else if (item.event_type === "approval_decided" && item.source_id) {
|
|
59856
|
-
await this.consumeTypedDispatch({ dispatchEventId: item.id }, (dispatchEventId) => this.fetchAndHandleApprovalDecided(item.source_id, item.actor_id, item.chat_id ?? null, dispatchEventId), typedHooks);
|
|
59857
|
-
} else if (item.event_type === "message" && item.source_id && item.chat_id) {
|
|
59858
|
-
await this.consumeMessageWorkItem({
|
|
59859
|
-
id: item.id,
|
|
59860
|
-
source_id: item.source_id,
|
|
59861
|
-
chat_id: item.chat_id
|
|
59862
|
-
});
|
|
59863
|
-
}
|
|
59056
|
+
await this.consumeWorkItem(item);
|
|
59864
59057
|
} catch (err) {
|
|
59865
59058
|
this.opts.log?.warn(`catch-up dispatch ${item.id} (${item.event_type}) failed: ${String(err)}`);
|
|
59866
59059
|
}
|
|
@@ -59933,9 +59126,18 @@ ${fullSummary}` : fullSummary;
|
|
|
59933
59126
|
this.ledgerDisabled = false;
|
|
59934
59127
|
}
|
|
59935
59128
|
const intervalSec = data.heartbeat_interval > 0 ? data.heartbeat_interval : 30;
|
|
59129
|
+
let openFence = () => {
|
|
59130
|
+
};
|
|
59131
|
+
this.contractReady = new Promise((resolve3) => {
|
|
59132
|
+
openFence = resolve3;
|
|
59133
|
+
});
|
|
59936
59134
|
try {
|
|
59937
|
-
|
|
59938
|
-
|
|
59135
|
+
log?.info("WebSocket connected");
|
|
59136
|
+
try {
|
|
59137
|
+
await this.declareRuntimeContract();
|
|
59138
|
+
} finally {
|
|
59139
|
+
openFence();
|
|
59140
|
+
}
|
|
59939
59141
|
await this.opts.onSessionReady?.({
|
|
59940
59142
|
activeSessionId: this.activeSessionId,
|
|
59941
59143
|
ws: this.opts.ws,
|
|
@@ -59969,6 +59171,44 @@ ${fullSummary}` : fullSummary;
|
|
|
59969
59171
|
log?.error(`failed to fetch chats: ${String(err)}`);
|
|
59970
59172
|
}
|
|
59971
59173
|
}
|
|
59174
|
+
/**
|
|
59175
|
+
* Declare the runtime contract for this connection: the server decides
|
|
59176
|
+
* who runs and renders the wake frame; this runtime only runs. Bound to
|
|
59177
|
+
* the WS session id, so it repeats on every hello. Retried with backoff
|
|
59178
|
+
* until it lands — WorkItems wait behind the fence meanwhile, nothing is
|
|
59179
|
+
* claimed without a frame. A server without the endpoint renders no
|
|
59180
|
+
* frames: the runtime runs nothing and WorkItems stay pending. A
|
|
59181
|
+
* stale-session 409 means a newer connection already declared.
|
|
59182
|
+
*/
|
|
59183
|
+
async declareRuntimeContract() {
|
|
59184
|
+
const session = this.sessionId;
|
|
59185
|
+
if (!session)
|
|
59186
|
+
return;
|
|
59187
|
+
for (let attempt = 0; ; attempt++) {
|
|
59188
|
+
try {
|
|
59189
|
+
await this.opts.client.declareReplyPolicyCapability(this.opts.config.org_id, session);
|
|
59190
|
+
this.opts.log?.info("runtime contract declared (server-rendered frames)");
|
|
59191
|
+
return;
|
|
59192
|
+
} catch (err) {
|
|
59193
|
+
if (err instanceof ApiError && err.status === 404) {
|
|
59194
|
+
this.opts.log?.warn("server predates the runtime contract \u2014 it renders no wake frames; WorkItems stay pending");
|
|
59195
|
+
return;
|
|
59196
|
+
}
|
|
59197
|
+
if (err instanceof ApiError && err.status === 409) {
|
|
59198
|
+
this.opts.log?.info("runtime contract already declared by a newer connection");
|
|
59199
|
+
return;
|
|
59200
|
+
}
|
|
59201
|
+
const delayMs = Math.min(3e4, 2e3 * 2 ** Math.min(attempt, 4));
|
|
59202
|
+
this.opts.log?.warn(`runtime contract declaration failed (retry in ${delayMs / 1e3}s): ${String(err)}`);
|
|
59203
|
+
await new Promise((resolve3) => {
|
|
59204
|
+
const timer = setTimeout(resolve3, delayMs);
|
|
59205
|
+
timer.unref?.();
|
|
59206
|
+
});
|
|
59207
|
+
if (this.shuttingDown || this.sessionId !== session)
|
|
59208
|
+
return;
|
|
59209
|
+
}
|
|
59210
|
+
}
|
|
59211
|
+
}
|
|
59972
59212
|
// Resolves when in-flight dispatches hit 0 or the deadline elapses.
|
|
59973
59213
|
// Deadline arming the resolver rather than rejecting keeps shutdown() linear
|
|
59974
59214
|
// — callers don't need to try/catch.
|
|
@@ -61431,11 +60671,12 @@ async function getAgentMeWithLegacyFallback(client, orgId) {
|
|
|
61431
60671
|
}
|
|
61432
60672
|
function buildInboundCtx(core, accountId, event, sessionKey, bodyForAgent, earlierEvents = []) {
|
|
61433
60673
|
const inboundHistory = earlierEvents.length > 0 ? buildInboundHistory(earlierEvents) : void 0;
|
|
60674
|
+
const body = event.frame ?? "";
|
|
61434
60675
|
return core.channel.reply.finalizeInboundContext({
|
|
61435
|
-
Body:
|
|
60676
|
+
Body: body,
|
|
61436
60677
|
BodyForAgent: bodyForAgent,
|
|
61437
|
-
RawBody:
|
|
61438
|
-
CommandBody:
|
|
60678
|
+
RawBody: body,
|
|
60679
|
+
CommandBody: body,
|
|
61439
60680
|
// Attachment metadata is now in event.attachments (structured), not mediaFields
|
|
61440
60681
|
...inboundHistory?.length ? { InboundHistory: inboundHistory } : {},
|
|
61441
60682
|
From: `parall:${event.senderId}`,
|
|
@@ -61443,7 +60684,7 @@ function buildInboundCtx(core, accountId, event, sessionKey, bodyForAgent, earli
|
|
|
61443
60684
|
SessionKey: sessionKey,
|
|
61444
60685
|
AccountId: accountId,
|
|
61445
60686
|
ChatType: event.targetType ?? "unknown",
|
|
61446
|
-
SenderName: event.
|
|
60687
|
+
SenderName: event.senderId,
|
|
61447
60688
|
SenderId: event.senderId,
|
|
61448
60689
|
Provider: "parall",
|
|
61449
60690
|
Surface: "parall",
|
|
@@ -61455,25 +60696,7 @@ function buildInboundCtx(core, accountId, event, sessionKey, bodyForAgent, earli
|
|
|
61455
60696
|
});
|
|
61456
60697
|
}
|
|
61457
60698
|
function buildInboundHistory(events) {
|
|
61458
|
-
return events.map((event) => {
|
|
61459
|
-
const meta2 = [];
|
|
61460
|
-
meta2.push(`[Message ID: ${event.messageId}]`);
|
|
61461
|
-
if (event.noReply)
|
|
61462
|
-
meta2.push(`[Hint: no_reply]`);
|
|
61463
|
-
if (event.threadRootId)
|
|
61464
|
-
meta2.push(`[Thread: ${event.threadRootId}]`);
|
|
61465
|
-
if (event.attachments?.length) {
|
|
61466
|
-
for (const att of event.attachments) {
|
|
61467
|
-
const safeMime = att.mimeType.replace(/[\r\n[\]|]/g, " ").trim();
|
|
61468
|
-
meta2.push(`[Attachment: prll://${att.id} | ${safeMime}]`);
|
|
61469
|
-
}
|
|
61470
|
-
}
|
|
61471
|
-
return {
|
|
61472
|
-
sender: event.senderName,
|
|
61473
|
-
body: meta2.length > 0 ? `${meta2.join(" ")}
|
|
61474
|
-
${event.body}` : event.body
|
|
61475
|
-
};
|
|
61476
|
-
});
|
|
60699
|
+
return events.map((event) => ({ sender: event.senderId, body: event.frame ?? "" }));
|
|
61477
60700
|
}
|
|
61478
60701
|
var OC_AUTH_TEXT = /unauthorized|401|403|invalid api key|authentication/i;
|
|
61479
60702
|
var OC_CONTEXT_TEXT = /context (window|length)|prompt is too long|request too large|413/i;
|