@sentry/junior 0.311.0 → 0.313.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/{adapter-B1wujchl.js → adapter-CYAvJzZS.js} +1 -1
- package/dist/{adapter-context-G2M0y6rP.js → adapter-context-CVsHoVSf.js} +2 -2
- package/dist/{admin-DCiBhUT1.js → admin-Cyhb4TwZ.js} +1 -1
- package/dist/{agent-runner-BVHPUIc8.js → agent-runner-B5y9MsT-.js} +3487 -3493
- package/dist/api/schema.d.ts +2 -2
- package/dist/api/schema.js +6 -6
- package/dist/api.d.ts +2 -2
- package/dist/api.js +294 -311
- package/dist/{app-Cw5Vy6H6.d.ts → app-DA8-hCMj.d.ts} +2 -9
- package/dist/app.d.ts +1 -1
- package/dist/app.js +336 -604
- package/dist/{background-compaction-queue-CJDnWVOJ.js → background-compaction-queue-iZXadLV3.js} +60 -85
- package/dist/{catalog-runtime-DMY3VV-D.js → catalog-runtime-kkE3hvCX.js} +1 -1
- package/dist/channel-access-mt7K6dPh.js +221 -0
- package/dist/cli/chat.js +18 -19
- package/dist/cli/check.js +3 -3
- package/dist/cli/init.js +0 -1
- package/dist/cli/main.js +3 -7
- package/dist/cli/plugins.js +4 -4
- package/dist/cli/run.d.ts +1 -2
- package/dist/cli/run.js +1 -2
- package/dist/cli/snapshot-create.js +5 -5
- package/dist/cli/upgrade.d.ts +1 -1
- package/dist/cli/upgrade.js +3 -3
- package/dist/{config-BrXDQefC.js → config-CWbwKj0j.js} +59 -27
- package/dist/{continue-in-slack-DNXSC9So.js → continue-in-slack-CxyFzdlF.js} +7 -8
- package/dist/{conversation-feed-DkinDu5o.js → conversation-feed-BEXLD3Me.js} +86 -21
- package/dist/{conversation-privacy-DxttrKb9.js → conversation-privacy-BrMiDN61.js} +1 -1
- package/dist/{conversation-turn-DWw7Xhdr.js → conversation-turn-B35eu0uz.js} +78 -56
- package/dist/{credential-sync-Bk8wGb8Y.js → credential-sync-DWTOEQrm.js} +15 -15
- package/dist/{projection-Cns7XwWa.js → credentialed-Dyv8b-lu.js} +16306 -20732
- package/dist/{db-7ETESH44.d.ts → db-DYGcXYl3.d.ts} +11 -6
- package/dist/{db-DTxzH7u5.js → db-PwSRzWWn.js} +181 -100
- package/dist/{executor-DqTiYj9S.js → executor-CgWyWfYz.js} +117 -99
- package/dist/{html-B9Sl4Axb.js → html-DidUcRhI.js} +6 -6
- package/dist/ingest-B0AggUEC.js +7931 -0
- package/dist/{install-Sg4ePfLl.js → install-2urLLXNt.js} +2 -2
- package/dist/instrumentation.js +3 -3
- package/dist/{lineage-BHAMpNKr.js → lineage-BXplQAVH.js} +2 -2
- package/dist/{stop-CYsfc0Ed.js → list-DyIyReSV.js} +709 -475
- package/dist/{logging-FjclQsXu.js → logging-DNt-qOIO.js} +1 -1
- package/dist/{schedule-BLJ476XQ.js → media-B0pZJ0bG.js} +1058 -11
- package/dist/{message-CJ7_RL50.js → message-Z5YKC-Af.js} +35 -28
- package/dist/{model-input-CMLh4Cwq.js → model-input-BhPJYdSV.js} +3 -3
- package/dist/nitro.d.ts +1 -1
- package/dist/nitro.js +4 -3
- package/dist/{oauth-callback-server-RVcbiDjL.js → oauth-callback-server-ByvDdcdY.js} +2 -2
- package/dist/{oauth-relay-Bu9kkaQu.js → oauth-relay-D-kK0yoN.js} +1 -1
- package/dist/{registry-BPwuOP2O.js → registry-POH4bZC4.js} +1 -1
- package/dist/reporting-window-C4dbzDiR.js +124 -0
- package/dist/request-deadline-BUiRYQYj.js +24 -0
- package/dist/{resolve-BK29bBry.js → resolve-CWtBNSKP.js} +3 -3
- package/dist/{runner-BcAE-cJm.js → runner-CsZ_VRxp.js} +14 -16
- package/dist/{sandbox-egress-signals-C-q0go5b.js → sandbox-egress-signals-FbCk1FkN.js} +1 -1
- package/dist/{schema-DYcJeV7d.d.ts → schema-DBf18QPS.d.ts} +2773 -3630
- package/dist/{schema-BLgSZXcL.js → schema-DojR2uCL.js} +106 -121
- package/dist/{service-account-iJoCtkHR.js → service-account-CDYb9hfX.js} +3 -3
- package/dist/{service-account-gN0zqf0S.js → service-account-o15pZWcJ.js} +5 -5
- package/dist/{skills-BoZ80epJ.js → skills-B0jP4whm.js} +2 -2
- package/dist/{slack-conversation-unfurl-CogYrITA.js → slack-conversation-unfurl-D26t9kBC.js} +9 -9
- package/dist/{spawn-Dk92r7mX.js → spawn-BjljgExZ.js} +14 -32
- package/dist/start-conversation-DbVujrwO.js +755 -0
- package/dist/{state-DH3Cmgp3.js → state-BTawTCme.js} +4 -4
- package/dist/statuses-BKwqCPhj.js +69 -0
- package/dist/store-CjXrp-Up.js +492 -0
- package/dist/task-queue-Cwlatjz3.js +90 -0
- package/dist/task-runner--Ke8KSMf.js +1432 -0
- package/dist/{thread-context-BW2BsQbH.js → thread-context-B8exINEe.js} +6 -7
- package/dist/turn-membership-DTR3SaKD.js +5859 -0
- package/dist/{validation-DrJd0nnq.js → validation-Ce0qbMlT.js} +1 -1
- package/dist/{task-queue-C_zldF5J.js → vercel-queue-q4z8w5QO.js} +93 -172
- package/dist/{version-CNKZ8owc.js → version-DFh4n9nr.js} +1 -1
- package/dist/version.js +1 -1
- package/dist/{warmup-BWdHew2H.js → warmup-D5hzqTcp.js} +4853 -13605
- package/dist/web-message-id-C6P83ans.js +10 -0
- package/dist/{worker-t9qpu_Zx.js → worker-CDg9Lbpg.js} +20 -7
- package/migrations/0143_todos.sql +14 -0
- package/migrations/0144_inbox_items.sql +32 -0
- package/migrations/0145_todo_changed_by_agent.sql +1 -0
- package/migrations/0146_inbox_item_subject_title_parts.sql +1 -0
- package/migrations/0147_inbox_snooze_wake_reason.sql +1 -0
- package/migrations/0148_authorization_request_index.sql +1 -0
- package/migrations/0149_conversation_metadata.sql +10 -0
- package/migrations/0150_conversation_metadata_fill.sql +39 -0
- package/migrations/0151_conversation_search_index.sql +1 -0
- package/migrations/0152_inbox_item_legacy_automation_keys.sql +21 -0
- package/migrations/0153_artifact_expiry.sql +1 -0
- package/migrations/0154_artifact_permanent_sha_index.sql +1 -0
- package/migrations/0155_artifact_drop_public_sha_index.sql +3 -0
- package/migrations/0156_conversation_kind_lead.sql +6 -0
- package/migrations/0157_conversation_lead_actor_index.sql +1 -0
- package/migrations/0158_keep_legacy_archive_columns.sql +5 -0
- package/migrations/0159_conversation_embeddings_fk_validate.sql +5 -0
- package/migrations/meta/0143_snapshot.json +6434 -0
- package/migrations/meta/0144_snapshot.json +6434 -0
- package/migrations/meta/0145_snapshot.json +6440 -0
- package/migrations/meta/0146_snapshot.json +6446 -0
- package/migrations/meta/0147_snapshot.json +6452 -0
- package/migrations/meta/0148_snapshot.json +6474 -0
- package/migrations/meta/0149_snapshot.json +6490 -0
- package/migrations/meta/0150_snapshot.json +6490 -0
- package/migrations/meta/0151_snapshot.json +6505 -0
- package/migrations/meta/0152_snapshot.json +6505 -0
- package/migrations/meta/0153_snapshot.json +6511 -0
- package/migrations/meta/0154_snapshot.json +6533 -0
- package/migrations/meta/0155_snapshot.json +6511 -0
- package/migrations/meta/0156_snapshot.json +6511 -0
- package/migrations/meta/0157_snapshot.json +6527 -0
- package/migrations/meta/0158_snapshot.json +6515 -0
- package/migrations/meta/0159_snapshot.json +6515 -0
- package/migrations/meta/_journal.json +120 -1
- package/package.json +6 -6
- package/skills/design-automation-skill/SKILL.md +108 -0
- package/dist/briefs-BDjnug6Y.js +0 -395
- package/dist/conversation-ca__NDQW.js +0 -1063
- package/dist/prompt-CDqcsDYC.js +0 -910
- package/dist/store-DmmMIrQi.js +0 -335
- package/dist/task-runner-C7oCJQIx.js +0 -294
- package/dist/turn-session-routing-Xh_2nSQe.js +0 -261
- package/dist/web-message-id-Ch5dPq-a.js +0 -306
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import "./schema-
|
|
1
|
+
import "./schema-DBf18QPS.js";
|
|
2
2
|
import * as z from "zod";
|
|
3
3
|
import "@earendil-works/pi-ai";
|
|
4
4
|
import { Destination, Source, locationSchema } from "@sentry/junior-plugin-api";
|
|
@@ -53,11 +53,14 @@ type Usage = z.output<typeof usageSchema>;
|
|
|
53
53
|
type AgentTurnUsage = Usage;
|
|
54
54
|
type ConversationSource = "api" | "internal" | "local" | "plugin" | "event" | "scheduler" | "slack" | "web";
|
|
55
55
|
/**
|
|
56
|
-
* Where a Conversation sits in its tree. A root
|
|
57
|
-
* parent. A Thread is a child that people can message. A Task
|
|
58
|
-
* only its parent messages. A Conversation never changes
|
|
56
|
+
* Where a Conversation sits in its tree. A root, an Automation run, and a
|
|
57
|
+
* Lead have no parent. A Thread is a child that people can message. A Task
|
|
58
|
+
* is a child that only its parent messages. A Conversation never changes
|
|
59
|
+
* kind.
|
|
59
60
|
*/
|
|
60
|
-
type ConversationKind = "root" | "automation" | "thread" | "task";
|
|
61
|
+
type ConversationKind = "root" | "automation" | "lead" | "thread" | "task";
|
|
62
|
+
/** The kind of a Conversation that has no parent. */
|
|
63
|
+
type TopLevelConversationKind = Exclude<ConversationKind, ChildConversationKind>;
|
|
61
64
|
/** The kind of a Conversation that has a parent. */
|
|
62
65
|
type ChildConversationKind = "thread" | "task";
|
|
63
66
|
type ConversationStatus = "paused" | "failed" | "idle" | "pending" | "running";
|
|
@@ -119,6 +122,8 @@ interface Conversation {
|
|
|
119
122
|
*/
|
|
120
123
|
sessionSource?: SessionSource;
|
|
121
124
|
title?: string | undefined;
|
|
125
|
+
/** Conversation metadata. Only the metadata task writes it. */
|
|
126
|
+
summary?: string;
|
|
122
127
|
updatedAtMs: number;
|
|
123
128
|
/**
|
|
124
129
|
* When retention purged this conversation's content. Set means messages and
|
|
@@ -227,7 +232,7 @@ interface ConversationStore {
|
|
|
227
232
|
* Kind of a new Conversation. Default `root`. An existing Conversation
|
|
228
233
|
* keeps its kind.
|
|
229
234
|
*/
|
|
230
|
-
kind?:
|
|
235
|
+
kind?: TopLevelConversationKind;
|
|
231
236
|
/**
|
|
232
237
|
* Current visibility from its owner, such as a Slack event channel type. It
|
|
233
238
|
* replaces the visibility of the shared Destination row. Omit it for saved
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-BKpuH2hG.js";
|
|
2
|
-
import {
|
|
2
|
+
import { N as cacheKeyPrefix, P as createCache, r as getChatConfig } from "./config-CWbwKj0j.js";
|
|
3
3
|
import { a as isSlackUserId, d as parseSlackChannelReferenceId, f as parseSlackTeamId, s as parseActorUserId } from "./actor-BsBdxDXQ.js";
|
|
4
|
-
import { A as juniorConversationMetrics, B as juniorAttachments, C as juniorConversationParticipants, H as juniorConversations, K as juniorUsers, M as juniorConversationEvents,
|
|
4
|
+
import { A as juniorConversationMetrics, B as juniorAttachments, C as juniorConversationParticipants, H as juniorConversations, K as juniorUsers, M as juniorConversationEvents, P as juniorConversationAnnotations, S as juniorConversationReadPositions, T as juniorConversationBriefs, U as juniorIdentities, V as juniorMessageAttachments, _ as juniorAutomationRuns, f as juniorInboxItemAssignees, g as juniorAutomations, h as juniorInboxItems, j as isUserInstruction, k as CONVERSATION_METRICS, p as juniorInboxItemConversations, q as juniorDestinations, t as createJuniorSqlExecutor, w as juniorConversationBindings } from "./executor-CgWyWfYz.js";
|
|
5
5
|
import { c as newConversationEventSchema, h as usageSchema, l as encodeHistoryPayload, o as decodeStoredConversationEvent, r as conversationEventDataSchema, s as historyReplacementSchema } from "./history-CYstOMKX.js";
|
|
6
|
-
import { t as canExposeConversationPayload } from "./conversation-privacy-
|
|
6
|
+
import { t as canExposeConversationPayload } from "./conversation-privacy-BrMiDN61.js";
|
|
7
7
|
import { t as mapBounded } from "./fan-out-Cod-yEHG.js";
|
|
8
|
-
import { J as normalizeIdentityEmail, K as GOOGLE_IDENTITY_PROVIDER, h as logWarn } from "./logging-
|
|
9
|
-
import { i as getStateAdapter } from "./adapter-
|
|
8
|
+
import { J as normalizeIdentityEmail, K as GOOGLE_IDENTITY_PROVIDER, h as logWarn } from "./logging-DNt-qOIO.js";
|
|
9
|
+
import { i as getStateAdapter } from "./adapter-CYAvJzZS.js";
|
|
10
10
|
import * as z from "zod";
|
|
11
11
|
import { createHash, randomUUID } from "node:crypto";
|
|
12
12
|
import { PluginToolInputError, destinationSchema, identitySchema, locationSchema, sourceSchema, userSchema } from "@sentry/junior-plugin-api";
|
|
13
|
-
import { and, asc, desc, eq, exists, gt, gte, inArray, isNotNull, isNull, lt, lte, ne, not, or, sql } from "drizzle-orm";
|
|
13
|
+
import { SQL, and, asc, desc, eq, exists, gt, gte, inArray, isNotNull, isNull, lt, lte, ne, not, or, sql } from "drizzle-orm";
|
|
14
14
|
import { alias } from "drizzle-orm/pg-core";
|
|
15
15
|
// src/chat/destination.ts
|
|
16
16
|
/** Build Junior's canonical destination from Slack workspace and channel ids. */
|
|
@@ -398,7 +398,20 @@ function canAccessConversation(args) {
|
|
|
398
398
|
if (requester.destinationId !== void 0 && requester.destinationId === target.destinationId) return true;
|
|
399
399
|
return target.visibility === "public";
|
|
400
400
|
}
|
|
401
|
-
|
|
401
|
+
/**
|
|
402
|
+
* Whether work in `requesterConversationId` may read `conversationId`, by
|
|
403
|
+
* `canAccessConversation`. A missing target is not readable. A requester that
|
|
404
|
+
* is not stored yet reaches only public targets.
|
|
405
|
+
*/
|
|
406
|
+
async function canReadConversation(db, requesterConversationId, conversationId) {
|
|
407
|
+
const access = await readConversationAccessFromSql(db, [requesterConversationId, conversationId]);
|
|
408
|
+
const target = access.get(conversationId);
|
|
409
|
+
return target !== void 0 && canAccessConversation({
|
|
410
|
+
requester: access.get(requesterConversationId) ?? { visibility: null },
|
|
411
|
+
target
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
// src/chat/tool-support/tool-input-error.ts
|
|
402
415
|
/** Thrown when a tool fails due to invalid model/user input, not a system error. */
|
|
403
416
|
var ToolInputError = class extends Error {
|
|
404
417
|
constructor(message, options) {
|
|
@@ -1057,7 +1070,7 @@ async function readIdentityByIdFromSql(db, identityId) {
|
|
|
1057
1070
|
async function readIdentityById(identityId) {
|
|
1058
1071
|
return await readIdentityByIdFromSql(getDb(), identityId);
|
|
1059
1072
|
}
|
|
1060
|
-
// src/chat/
|
|
1073
|
+
// src/chat/inbox-items/assignees.ts
|
|
1061
1074
|
/** Text that the agent writes to assign Everyone. */
|
|
1062
1075
|
const EVERYONE_ASSIGNEE = "everyone";
|
|
1063
1076
|
/**
|
|
@@ -1076,9 +1089,9 @@ async function resolveAssignee(db, value, tenant, findMentionedUserId) {
|
|
|
1076
1089
|
}
|
|
1077
1090
|
throw new ToolInputError(`Unknown assignee ${JSON.stringify(text)}. Use ${EVERYONE_ASSIGNEE}, an email, or a mention such as <@U123>.`);
|
|
1078
1091
|
}
|
|
1079
|
-
/** Resolve the assignees of
|
|
1092
|
+
/** Resolve the assignees of an Inbox item. One is required. */
|
|
1080
1093
|
async function resolveAssignees(db, values, tenant, findMentionedUserId) {
|
|
1081
|
-
if (values.length === 0) throw new ToolInputError("
|
|
1094
|
+
if (values.length === 0) throw new ToolInputError("An inbox item needs at least one assignee.");
|
|
1082
1095
|
const resolved = await mapBounded(values, (value) => resolveAssignee(db, value, tenant, findMentionedUserId));
|
|
1083
1096
|
return {
|
|
1084
1097
|
everyone: resolved.some((assignee) => "everyone" in assignee),
|
|
@@ -1105,7 +1118,7 @@ async function automationCreatorUserId(db, automationId) {
|
|
|
1105
1118
|
const [row] = await db.select({ userId: juniorIdentities.userId }).from(juniorAutomations).innerJoin(juniorIdentities, eq(juniorIdentities.id, juniorAutomations.creatorIdentityId)).where(eq(juniorAutomations.id, automationId)).limit(1);
|
|
1106
1119
|
return row?.userId ?? void 0;
|
|
1107
1120
|
}
|
|
1108
|
-
// src/chat/
|
|
1121
|
+
// src/chat/inbox-items/access.ts
|
|
1109
1122
|
/** Return whether two tenants are the same. Two missing tenants match. */
|
|
1110
1123
|
function isSameTenant(a, b) {
|
|
1111
1124
|
return a?.provider === b?.provider && a?.providerTenantId === b?.providerTenantId;
|
|
@@ -1114,7 +1127,7 @@ function isSameTenant(a, b) {
|
|
|
1114
1127
|
* The reader for one person: items assigned to them, and public items in the
|
|
1115
1128
|
* provider tenants of their identities.
|
|
1116
1129
|
*/
|
|
1117
|
-
function
|
|
1130
|
+
function inboxItemReaderForUser(user) {
|
|
1118
1131
|
return {
|
|
1119
1132
|
tenants: user.identities.flatMap((identity) => identity.providerTenantId ? [{
|
|
1120
1133
|
provider: identity.provider,
|
|
@@ -1124,88 +1137,81 @@ function reviewItemReaderForUser(user) {
|
|
|
1124
1137
|
};
|
|
1125
1138
|
}
|
|
1126
1139
|
/**
|
|
1127
|
-
* SQL: a Conversation owns the
|
|
1140
|
+
* SQL: a Conversation owns the Inbox item. The Conversation status and
|
|
1128
1141
|
* feeds read the items that each Conversation owns.
|
|
1129
1142
|
*/
|
|
1130
|
-
function
|
|
1131
|
-
return and(eq(
|
|
1143
|
+
function inboxItemOwnedByConversation(conversationId) {
|
|
1144
|
+
return and(eq(juniorInboxItems.ownerKind, "conversation"), eq(juniorInboxItems.ownerId, conversationId));
|
|
1132
1145
|
}
|
|
1133
|
-
/** SQL: the
|
|
1134
|
-
function
|
|
1135
|
-
return sql`exists (select 1 from ${
|
|
1146
|
+
/** SQL: the Inbox item has this assigned User. */
|
|
1147
|
+
function inboxItemAssignedTo(userId) {
|
|
1148
|
+
return sql`exists (select 1 from ${juniorInboxItemAssignees} where ${juniorInboxItemAssignees.itemId} = ${juniorInboxItems.id} and ${juniorInboxItemAssignees.userId} = ${userId})`;
|
|
1136
1149
|
}
|
|
1137
1150
|
/**
|
|
1138
|
-
* SQL: the
|
|
1151
|
+
* SQL: the Inbox item needs this User. Only an open `action` item that is
|
|
1139
1152
|
* assigned to the User needs them. A notice, an item for Everyone, and an
|
|
1140
1153
|
* item without assignees need no one. An assigned User can always see the
|
|
1141
1154
|
* item, so this rule needs no visibility check. The nav count and the
|
|
1142
1155
|
* "Waiting on you" marker use this rule.
|
|
1143
1156
|
*/
|
|
1144
|
-
function
|
|
1145
|
-
return and(eq(
|
|
1157
|
+
function inboxItemNeedsUser(userId) {
|
|
1158
|
+
return and(eq(juniorInboxItems.status, "open"), eq(juniorInboxItems.kind, "action"), inboxItemAssignedTo(userId));
|
|
1146
1159
|
}
|
|
1147
1160
|
/**
|
|
1148
|
-
* SQL: the
|
|
1149
|
-
* assigned User. It is `reviewItemNeedsUser` for any User.
|
|
1150
|
-
*/
|
|
1151
|
-
function reviewItemNeedsSomeone() {
|
|
1152
|
-
return and(eq(juniorReviewItems.status, "open"), eq(juniorReviewItems.kind, "action"), sql`exists (select 1 from ${juniorReviewItemAssignees} where ${juniorReviewItemAssignees.itemId} = ${juniorReviewItems.id})`);
|
|
1153
|
-
}
|
|
1154
|
-
/**
|
|
1155
|
-
* SQL: the Review item waits for a person's input: an open `action` item,
|
|
1161
|
+
* SQL: the Inbox item waits for a person's input: an open `action` item,
|
|
1156
1162
|
* whoever it is assigned to. An item with no assignees still waits for
|
|
1157
1163
|
* anyone who can answer it. The Conversation that added it shows
|
|
1158
|
-
* `needs_input`. `
|
|
1164
|
+
* `needs_input`. `junior_inbox_items_open_action_added_by_idx` has this
|
|
1159
1165
|
* predicate.
|
|
1160
1166
|
*/
|
|
1161
|
-
function
|
|
1162
|
-
return and(eq(
|
|
1167
|
+
function inboxItemNeedsInput() {
|
|
1168
|
+
return and(eq(juniorInboxItems.status, "open"), eq(juniorInboxItems.kind, "action"));
|
|
1163
1169
|
}
|
|
1164
1170
|
/**
|
|
1165
|
-
* SQL: the
|
|
1171
|
+
* SQL: the Inbox item is not assigned only to other people. It is assigned
|
|
1166
1172
|
* to this User, to Everyone, or to no one. This is the assignee rule of
|
|
1167
|
-
* `
|
|
1173
|
+
* `canActOnInboxItem`; keep the two the same.
|
|
1168
1174
|
*/
|
|
1169
|
-
function
|
|
1170
|
-
return or(eq(
|
|
1175
|
+
function inboxItemForUser(userId) {
|
|
1176
|
+
return or(eq(juniorInboxItems.assignedToEveryone, true), sql`not exists (select 1 from ${juniorInboxItemAssignees} where ${juniorInboxItemAssignees.itemId} = ${juniorInboxItems.id})`, inboxItemAssignedTo(userId));
|
|
1171
1177
|
}
|
|
1172
|
-
/** SQL: the
|
|
1173
|
-
function
|
|
1174
|
-
return sql`exists (select 1 from ${
|
|
1178
|
+
/** SQL: the Inbox item links this Conversation. */
|
|
1179
|
+
function inboxItemLinkedTo(conversationId) {
|
|
1180
|
+
return sql`exists (select 1 from ${juniorInboxItemConversations} where ${juniorInboxItemConversations.itemId} = ${juniorInboxItems.id} and ${juniorInboxItemConversations.conversationId} = ${conversationId})`;
|
|
1175
1181
|
}
|
|
1176
1182
|
function publicIn(tenants) {
|
|
1177
|
-
return tenants.map((tenant) => and(eq(
|
|
1183
|
+
return tenants.map((tenant) => and(eq(juniorInboxItems.visibility, "public"), eq(juniorInboxItems.provider, tenant.provider), eq(juniorInboxItems.providerTenantId, tenant.providerTenantId)));
|
|
1178
1184
|
}
|
|
1179
1185
|
/**
|
|
1180
|
-
* SQL form of `
|
|
1181
|
-
*
|
|
1186
|
+
* SQL form of `canReadInboxItem`, for search. Keep the two the same; the
|
|
1187
|
+
* Inbox item access test checks that they agree.
|
|
1182
1188
|
*/
|
|
1183
|
-
function
|
|
1184
|
-
return or(...publicIn(reader.tenants ?? []), ...reader.userId ? [
|
|
1189
|
+
function inboxItemVisibleTo(reader) {
|
|
1190
|
+
return or(...publicIn(reader.tenants ?? []), ...reader.userId ? [inboxItemAssignedTo(reader.userId)] : [], ...reader.conversationId ? [inboxItemLinkedTo(reader.conversationId)] : [], ...reader.automationId ? [eq(juniorInboxItems.automationId, reader.automationId)] : []) ?? sql`false`;
|
|
1185
1191
|
}
|
|
1186
|
-
/** Return whether a reader can see one
|
|
1187
|
-
function
|
|
1192
|
+
/** Return whether a reader can see one Inbox item. */
|
|
1193
|
+
function canReadInboxItem(item, reader) {
|
|
1188
1194
|
return item.visibility === "public" && item.tenant !== void 0 && (reader.tenants ?? []).some((tenant) => isSameTenant(tenant, item.tenant)) || reader.userId !== void 0 && item.assignees.some((assignee) => assignee.userId === reader.userId) || reader.conversationId !== void 0 && item.conversationIds.includes(reader.conversationId) || reader.automationId !== void 0 && item.automationId === reader.automationId;
|
|
1189
1195
|
}
|
|
1190
1196
|
/**
|
|
1191
|
-
* Return whether a person can read one
|
|
1197
|
+
* Return whether a person can read one Inbox item: by the reader rule, or
|
|
1192
1198
|
* because they take part in a Conversation that the item links. The second
|
|
1193
1199
|
* part is the person rule of `policies/conversation-access.md`; it lets the
|
|
1194
1200
|
* Conversation view show its items. Viewing a public Conversation is not
|
|
1195
1201
|
* enough: a private item stays private when its Conversation becomes public.
|
|
1196
1202
|
*/
|
|
1197
|
-
async function
|
|
1198
|
-
if (
|
|
1203
|
+
async function canUserReadInboxItem(item, user) {
|
|
1204
|
+
if (canReadInboxItem(item, inboxItemReaderForUser(user))) return true;
|
|
1199
1205
|
const access = await readConversationAccessFromSql(getDb(), item.conversationIds, user);
|
|
1200
1206
|
return item.conversationIds.some((id) => access.get(id)?.isParticipant === true);
|
|
1201
1207
|
}
|
|
1202
1208
|
/**
|
|
1203
1209
|
* The reader for one person who looks at one Conversation: the person's
|
|
1204
1210
|
* reader, plus the items linked to the Conversation when they take part in
|
|
1205
|
-
* it. It is the list form of `
|
|
1211
|
+
* it. It is the list form of `canUserReadInboxItem`.
|
|
1206
1212
|
*/
|
|
1207
|
-
async function
|
|
1208
|
-
const reader =
|
|
1213
|
+
async function inboxItemReaderForUserInConversation(user, conversationId) {
|
|
1214
|
+
const reader = inboxItemReaderForUser(user);
|
|
1209
1215
|
return (await readConversationAccessFromSql(getDb(), [conversationId], user)).get(conversationId)?.isParticipant ? {
|
|
1210
1216
|
...reader,
|
|
1211
1217
|
conversationId
|
|
@@ -1216,7 +1222,7 @@ async function reviewItemReaderForUserInConversation(user, conversationId) {
|
|
|
1216
1222
|
* Automation, not as its Actor: an assignment lets a person see the item on
|
|
1217
1223
|
* the Inbox, not let an agent read it into another Conversation.
|
|
1218
1224
|
*/
|
|
1219
|
-
async function
|
|
1225
|
+
async function readInboxItemAgentScope(context) {
|
|
1220
1226
|
const actor = await context.resolveActorIdentity?.();
|
|
1221
1227
|
const user = actor?.user;
|
|
1222
1228
|
const automationId = context.source.kind === "scheduled_automation" || context.source.kind === "event_automation" ? context.source.automationId : void 0;
|
|
@@ -1238,24 +1244,24 @@ async function readReviewItemAgentScope(context) {
|
|
|
1238
1244
|
* Dedupe keys with this prefix belong to plugins. Only the plugin that added
|
|
1239
1245
|
* the item, or a person, can change it. An agent cannot use the prefix.
|
|
1240
1246
|
*/
|
|
1241
|
-
const
|
|
1247
|
+
const PLUGIN_INBOX_ITEM_KEY_PREFIX = "plugin:";
|
|
1242
1248
|
/**
|
|
1243
1249
|
* Dedupe keys with this prefix belong to Automation alerts, which core adds
|
|
1244
1250
|
* and closes. An agent cannot use the prefix.
|
|
1245
1251
|
*/
|
|
1246
|
-
const
|
|
1252
|
+
const AUTOMATION_INBOX_ITEM_KEY_PREFIX = "automation:";
|
|
1247
1253
|
/** Return the plugin that owns a dedupe key, or undefined for an agent's key. */
|
|
1248
|
-
function
|
|
1254
|
+
function inboxItemPlugin(dedupeKey) {
|
|
1249
1255
|
if (!dedupeKey.startsWith("plugin:")) return void 0;
|
|
1250
1256
|
return dedupeKey.slice(7).split(":", 1)[0] || void 0;
|
|
1251
1257
|
}
|
|
1252
1258
|
/** Return whether the item is an Automation alert. Core takes its answer. */
|
|
1253
1259
|
function isAutomationAlertItem(item) {
|
|
1254
|
-
return item.dedupeKey.startsWith(
|
|
1260
|
+
return item.dedupeKey.startsWith(AUTOMATION_INBOX_ITEM_KEY_PREFIX);
|
|
1255
1261
|
}
|
|
1256
1262
|
/** Return whether a plugin added the item. Its answer goes to the plugin. */
|
|
1257
|
-
function
|
|
1258
|
-
return
|
|
1263
|
+
function isPluginInboxItem(item) {
|
|
1264
|
+
return inboxItemPlugin(item.dedupeKey) !== void 0;
|
|
1259
1265
|
}
|
|
1260
1266
|
/**
|
|
1261
1267
|
* Whether an agent can change an item. Only an agent in the tenant of the
|
|
@@ -1265,7 +1271,7 @@ function isPluginReviewItem(item) {
|
|
|
1265
1271
|
* agent never changes an item that a plugin added, or an item that another
|
|
1266
1272
|
* owner kind, such as an Automation, owns.
|
|
1267
1273
|
*/
|
|
1268
|
-
function
|
|
1274
|
+
function canAgentChangeInboxItem(item, scope) {
|
|
1269
1275
|
if (item.dedupeKey.startsWith("plugin:")) return false;
|
|
1270
1276
|
if (item.owner.kind !== "conversation") return false;
|
|
1271
1277
|
if (!isSameTenant(item.tenant, scope.tenant)) return false;
|
|
@@ -1278,7 +1284,7 @@ function canAgentChangeReviewItem(item, scope) {
|
|
|
1278
1284
|
* that the item already has) always pass. A private item gets no other
|
|
1279
1285
|
* links. A public item can get other links only to public Conversations.
|
|
1280
1286
|
*/
|
|
1281
|
-
async function
|
|
1287
|
+
async function requireInboxItemLinks(args) {
|
|
1282
1288
|
const access = await readConversationAccessFromSql(getDb(), args.conversationIds, args.scope.user);
|
|
1283
1289
|
for (const conversationId of args.conversationIds) {
|
|
1284
1290
|
const conversation = access.get(conversationId);
|
|
@@ -1296,7 +1302,7 @@ async function requireReviewItemLinks(args) {
|
|
|
1296
1302
|
* Automation run often has no Actor and no people yet, and its creator wrote
|
|
1297
1303
|
* the work. A public item can go to anyone.
|
|
1298
1304
|
*/
|
|
1299
|
-
async function
|
|
1305
|
+
async function requireInboxItemAssignees(args) {
|
|
1300
1306
|
if (args.visibility === "public") return;
|
|
1301
1307
|
if (args.assignees.everyone) throw new ToolInputError("A private item cannot be assigned to Everyone. Assign Users instead.");
|
|
1302
1308
|
const creatorId = args.automationId ? await automationCreatorUserId(getDb(), args.automationId) : void 0;
|
|
@@ -1305,20 +1311,20 @@ async function requireReviewItemAssignees(args) {
|
|
|
1305
1311
|
if (others.some((id) => !inConversation.has(id))) throw new ToolInputError("A private item can be assigned only to people in its Conversation.");
|
|
1306
1312
|
}
|
|
1307
1313
|
/**
|
|
1308
|
-
* Return whether a User can act on an open
|
|
1314
|
+
* Return whether a User can act on an open Inbox item: an assigned User,
|
|
1309
1315
|
* anyone for an item assigned to Everyone, and anyone for an item with no
|
|
1310
1316
|
* assignees. The caller checks that the User can see the item.
|
|
1311
|
-
* `
|
|
1317
|
+
* `inboxItemForUser` is the SQL form of the assignee rule.
|
|
1312
1318
|
*/
|
|
1313
|
-
function
|
|
1319
|
+
function canActOnInboxItem(item, userId) {
|
|
1314
1320
|
if (item.status !== "open") return false;
|
|
1315
1321
|
if (item.assignedToEveryone) return true;
|
|
1316
1322
|
if (item.assignees.length === 0) return true;
|
|
1317
1323
|
return item.assignees.some((assignee) => assignee.userId === userId);
|
|
1318
1324
|
}
|
|
1319
1325
|
/**
|
|
1320
|
-
* Return whether
|
|
1321
|
-
* assigned to them. `
|
|
1326
|
+
* Return whether an Inbox item needs a User: an open `action` item that is
|
|
1327
|
+
* assigned to them. `inboxItemNeedsUser` is the SQL form; keep the two the
|
|
1322
1328
|
* same.
|
|
1323
1329
|
*/
|
|
1324
1330
|
function itemNeedsUser(item, userId) {
|
|
@@ -1375,16 +1381,18 @@ function awaitsAuthorizationFrom(conversationId, userId) {
|
|
|
1375
1381
|
/** SQL: the newest wait event is a live request that `requester` matches. */
|
|
1376
1382
|
function authorizationWait(conversationId, requester) {
|
|
1377
1383
|
const events = juniorConversationEvents;
|
|
1378
|
-
|
|
1384
|
+
const start = authorizationWaitStart();
|
|
1385
|
+
const recentRequest = sql`(select true from ${events} where ${events.conversationId} = ${conversationId} and ${events.type} = 'authorization_requested' and ${events.createdAt} > ${start}::timestamptz limit 1)`;
|
|
1386
|
+
return sql`(coalesce(${recentRequest}, false) and coalesce((
|
|
1379
1387
|
select ${events.type} = 'authorization_requested'
|
|
1380
|
-
and ${events.createdAt} > ${
|
|
1388
|
+
and ${events.createdAt} > ${start}::timestamptz
|
|
1381
1389
|
and ${requester}
|
|
1382
1390
|
from ${events}
|
|
1383
1391
|
where ${events.conversationId} = ${conversationId}
|
|
1384
1392
|
and ${events.type} in (${sql.join(AUTHORIZATION_WAIT_EVENT_TYPES.map((type) => sql`${type}`), sql`, `)})
|
|
1385
1393
|
order by ${events.seq} desc
|
|
1386
1394
|
limit 1
|
|
1387
|
-
), false)`;
|
|
1395
|
+
), false))`;
|
|
1388
1396
|
}
|
|
1389
1397
|
/**
|
|
1390
1398
|
* SQL: the root or a child Conversation of `rootConversationId` waits on a
|
|
@@ -1440,6 +1448,7 @@ async function ensureConversationRow(executor, conversationId, atMs, options = {
|
|
|
1440
1448
|
const CONVERSATION_KINDS = /* @__PURE__ */ new Set([
|
|
1441
1449
|
"root",
|
|
1442
1450
|
"automation",
|
|
1451
|
+
"lead",
|
|
1443
1452
|
"thread",
|
|
1444
1453
|
"task"
|
|
1445
1454
|
]);
|
|
@@ -1499,7 +1508,9 @@ function conversationStarterUserIdSql(conversation) {
|
|
|
1499
1508
|
* `working`, not waiting. One of these applies:
|
|
1500
1509
|
*
|
|
1501
1510
|
* - The latest Turn failed.
|
|
1502
|
-
* - The latest Brief outcome is `partial` or `blocked
|
|
1511
|
+
* - The latest Brief outcome is `partial` or `blocked`, and that Brief
|
|
1512
|
+
* covers the latest assistant Message. Turns no longer store Briefs, so a
|
|
1513
|
+
* legacy Brief stops deciding once the Conversation moves on.
|
|
1503
1514
|
* - The latest assistant Message is an answer that the starter has not
|
|
1504
1515
|
* read. It is an answer when the latest Brief is `answered` or does not
|
|
1505
1516
|
* cover it. A `done` Brief that covers it needs no read. The starter read
|
|
@@ -1509,22 +1520,28 @@ function conversationStarterUserIdSql(conversation) {
|
|
|
1509
1520
|
*/
|
|
1510
1521
|
function conversationWaitsOnStarterSql(conversation) {
|
|
1511
1522
|
const id = conversation.conversationId;
|
|
1512
|
-
const
|
|
1513
|
-
const
|
|
1514
|
-
const
|
|
1515
|
-
const
|
|
1516
|
-
const
|
|
1517
|
-
const
|
|
1518
|
-
const
|
|
1523
|
+
const starter = sql.identifier("status_starter");
|
|
1524
|
+
const brief = sql.identifier("status_brief");
|
|
1525
|
+
const reply = sql.identifier("status_reply");
|
|
1526
|
+
const starterUserId = sql`${starter}.user_id`;
|
|
1527
|
+
const briefStatus = sql`${brief}.status`;
|
|
1528
|
+
const briefThroughSeq = sql`${brief}.through_seq`;
|
|
1529
|
+
const replySeq = sql`${reply}.seq`;
|
|
1530
|
+
const replyInSlack = sql`${reply}.in_slack`;
|
|
1531
|
+
const latestBrief = sql`(select ${juniorConversationBriefs.content}->'outcome'->>'status' as status, ${juniorConversationBriefs.throughSeq} as through_seq from ${juniorConversationBriefs} where ${eq(juniorConversationBriefs.conversationId, id)} order by ${desc(juniorConversationBriefs.version)} limit 1)`;
|
|
1532
|
+
const latestReply = sql`(select ${juniorConversationEvents.seq} as seq, coalesce(${juniorConversationEvents.payload}->'meta'->>'source' = 'slack', ${juniorConversationEvents.createdAt} < ${DELIVERY_PAUSE_START}) as in_slack from ${juniorConversationEvents} where ${and(eq(juniorConversationEvents.conversationId, id), eq(juniorConversationEvents.type, "message"), sql`${juniorConversationEvents.payload}->>'role' = 'assistant'`)} order by ${desc(juniorConversationEvents.seq)} limit 1)`;
|
|
1519
1533
|
const readByStarter = or(and(sql`${conversation.parentConversationId} is null`, sql`${conversation.location} is not null`, sql`coalesce(${replyInSlack}, false)`), sql`exists (select 1 from ${juniorConversationEvents} join ${juniorIdentities} as ${replyReader} on ${eq(replyReader.id, juniorConversationEvents.actorIdentityId)} where ${and(eq(juniorConversationEvents.conversationId, id), eq(juniorConversationEvents.type, "message"), gt(juniorConversationEvents.seq, replySeq), eq(replyReader.userId, starterUserId))})`, sql`exists (select 1 from ${juniorConversationReadPositions} where ${and(eq(juniorConversationReadPositions.conversationId, id), eq(juniorConversationReadPositions.userId, starterUserId), gte(juniorConversationReadPositions.lastReadSeq, replySeq))})`);
|
|
1520
1534
|
const unreadAnswer = sql`${replySeq} is not null and ${starterUserId} is not null and (coalesce(${briefStatus}, 'answered') = 'answered' or ${briefThroughSeq} < ${replySeq}) and not (${readByStarter})`;
|
|
1535
|
+
const waitsOnFacts = sql`(select (${briefStatus} in ('partial', 'blocked') and (${replySeq} is null or ${briefThroughSeq} >= ${replySeq})) or (${unreadAnswer})
|
|
1536
|
+
from (select ${conversationStarterUserIdSql(conversation)} as user_id offset 0) as ${starter}
|
|
1537
|
+
left join lateral ${latestBrief} as ${brief} on true
|
|
1538
|
+
left join lateral ${latestReply} as ${reply} on true)`;
|
|
1521
1539
|
return sql`(${conversation.stoppedAt} is null
|
|
1522
1540
|
and ${conversationKindSql(conversation)} <> 'task'
|
|
1523
1541
|
and not ${conversationIsActiveSql(conversation)}
|
|
1524
1542
|
and (
|
|
1525
1543
|
${conversationTurnFailedSql(conversation)}
|
|
1526
|
-
or ${
|
|
1527
|
-
or (${unreadAnswer})
|
|
1544
|
+
or ${waitsOnFacts}
|
|
1528
1545
|
))`;
|
|
1529
1546
|
}
|
|
1530
1547
|
/**
|
|
@@ -1532,7 +1549,7 @@ function conversationWaitsOnStarterSql(conversation) {
|
|
|
1532
1549
|
* This is the only place that derives it; readers, counts, and feed tokens
|
|
1533
1550
|
* select it. When more than one applies: `needs_input` > `working` > `done`.
|
|
1534
1551
|
*
|
|
1535
|
-
* - `needs_input`: an open action
|
|
1552
|
+
* - `needs_input`: an open action Inbox item that this Conversation added
|
|
1536
1553
|
* waits on its assignees or Everyone, a Turn waits on a person to sign in
|
|
1537
1554
|
* (`awaitsAuthorization`), or the work waits on its starter
|
|
1538
1555
|
* (`conversationWaitsOnStarterSql`).
|
|
@@ -1541,7 +1558,7 @@ function conversationWaitsOnStarterSql(conversation) {
|
|
|
1541
1558
|
* or an idle Conversation.
|
|
1542
1559
|
*/
|
|
1543
1560
|
function conversationStatusSql(conversation) {
|
|
1544
|
-
const needsInput = sql`exists (select 1 from ${
|
|
1561
|
+
const needsInput = sql`exists (select 1 from ${juniorInboxItems} where ${and(inboxItemOwnedByConversation(conversation.conversationId), inboxItemNeedsInput())})`;
|
|
1545
1562
|
return sql`case
|
|
1546
1563
|
when ${needsInput} or ${awaitsAuthorization(conversation.conversationId)} or ${conversationWaitsOnStarterSql(conversation)} then 'needs_input'
|
|
1547
1564
|
when ${conversationIsActiveSql(conversation)} then 'working'
|
|
@@ -2044,6 +2061,7 @@ const ROOT = {
|
|
|
2044
2061
|
gated: false,
|
|
2045
2062
|
failureNotice: "none",
|
|
2046
2063
|
sessionTasks: true,
|
|
2064
|
+
relatedConversations: true,
|
|
2047
2065
|
tools: {
|
|
2048
2066
|
agents: "children",
|
|
2049
2067
|
inbox: true,
|
|
@@ -2054,11 +2072,16 @@ const ROOT = {
|
|
|
2054
2072
|
noReply: true
|
|
2055
2073
|
}
|
|
2056
2074
|
};
|
|
2075
|
+
const ROOT_RUNTIME_TURN = {
|
|
2076
|
+
...ROOT,
|
|
2077
|
+
relatedConversations: false
|
|
2078
|
+
};
|
|
2057
2079
|
const PERSON_IN_THREAD = {
|
|
2058
2080
|
...ROOT,
|
|
2059
2081
|
promptMode: "thread",
|
|
2060
2082
|
sender: "person",
|
|
2061
2083
|
sessionTasks: false,
|
|
2084
|
+
relatedConversations: false,
|
|
2062
2085
|
tools: {
|
|
2063
2086
|
...ROOT.tools,
|
|
2064
2087
|
agents: "none"
|
|
@@ -2072,6 +2095,7 @@ const CHILD_AGENT_TURN = {
|
|
|
2072
2095
|
gated: true,
|
|
2073
2096
|
failureNotice: "none",
|
|
2074
2097
|
sessionTasks: false,
|
|
2098
|
+
relatedConversations: false,
|
|
2075
2099
|
tools: {
|
|
2076
2100
|
agents: "children_and_parent",
|
|
2077
2101
|
inbox: false,
|
|
@@ -2107,6 +2131,7 @@ const AUTOMATION_RUN = {
|
|
|
2107
2131
|
gated: true,
|
|
2108
2132
|
failureNotice: "none",
|
|
2109
2133
|
sessionTasks: true,
|
|
2134
|
+
relatedConversations: false,
|
|
2110
2135
|
tools: {
|
|
2111
2136
|
...ROOT.tools,
|
|
2112
2137
|
reply: "automation",
|
|
@@ -2116,15 +2141,47 @@ const AUTOMATION_RUN = {
|
|
|
2116
2141
|
const PERSON_IN_AUTOMATION = {
|
|
2117
2142
|
...ROOT,
|
|
2118
2143
|
promptMode: "automation",
|
|
2119
|
-
sender: "person"
|
|
2144
|
+
sender: "person",
|
|
2145
|
+
relatedConversations: false
|
|
2146
|
+
};
|
|
2147
|
+
const LEAD_TOOLS = [
|
|
2148
|
+
"startConversation",
|
|
2149
|
+
"messageAgent",
|
|
2150
|
+
"searchConversations",
|
|
2151
|
+
"searchConversationEvents",
|
|
2152
|
+
"readConversationEvent",
|
|
2153
|
+
"searchInboxItems",
|
|
2154
|
+
"searchEventTypes",
|
|
2155
|
+
"watchEvents",
|
|
2156
|
+
"watchTimer",
|
|
2157
|
+
"listWatches",
|
|
2158
|
+
"stopWatchingResources",
|
|
2159
|
+
"systemTime",
|
|
2160
|
+
"updateUserCustomization",
|
|
2161
|
+
"noReply"
|
|
2162
|
+
];
|
|
2163
|
+
const LEAD = {
|
|
2164
|
+
...ROOT,
|
|
2165
|
+
promptMode: "lead",
|
|
2166
|
+
sessionTasks: false,
|
|
2167
|
+
tools: {
|
|
2168
|
+
...ROOT.tools,
|
|
2169
|
+
agents: "lead",
|
|
2170
|
+
subscriptions: false,
|
|
2171
|
+
only: LEAD_TOOLS
|
|
2172
|
+
}
|
|
2120
2173
|
};
|
|
2121
2174
|
/** Return the behavior of one Turn. */
|
|
2122
2175
|
function turnBehavior(args) {
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2176
|
+
switch (args.kind) {
|
|
2177
|
+
case "root": return args.personInput ? ROOT : ROOT_RUNTIME_TURN;
|
|
2178
|
+
case "automation": return args.personInput ? PERSON_IN_AUTOMATION : AUTOMATION_RUN;
|
|
2179
|
+
case "thread": return args.personInput ? PERSON_IN_THREAD : AGENT_IN_THREAD;
|
|
2180
|
+
case "task":
|
|
2181
|
+
if (!args.personInput) return AGENT_IN_TASK;
|
|
2182
|
+
throw new Error("A task Conversation cannot have a person's input");
|
|
2183
|
+
case "lead": return LEAD;
|
|
2184
|
+
}
|
|
2128
2185
|
}
|
|
2129
2186
|
/**
|
|
2130
2187
|
* Return the tools that every Turn of one Prompt mode lists. A Turn of a mode
|
|
@@ -2132,14 +2189,31 @@ function turnBehavior(args) {
|
|
|
2132
2189
|
* cannot use are disabled.
|
|
2133
2190
|
*/
|
|
2134
2191
|
function promptModeTurnTools(mode) {
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2192
|
+
switch (mode) {
|
|
2193
|
+
case "automation": return AUTOMATION_RUN.tools;
|
|
2194
|
+
case "child_agent": return AGENT_IN_TASK.tools;
|
|
2195
|
+
case "thread": return THREAD_TOOLS;
|
|
2196
|
+
case "conversation": return ROOT.tools;
|
|
2197
|
+
case "lead": return LEAD.tools;
|
|
2198
|
+
}
|
|
2199
|
+
}
|
|
2200
|
+
/**
|
|
2201
|
+
* Return whether Turns update the Conversation metadata of this kind. Only
|
|
2202
|
+
* its parent reads a Task, so a Task has no summary.
|
|
2203
|
+
*/
|
|
2204
|
+
function hasConversationMetadata(kind) {
|
|
2205
|
+
return kind !== "task";
|
|
2139
2206
|
}
|
|
2140
2207
|
/** Return whether a Conversation of this kind has no parent. */
|
|
2141
2208
|
function isTopLevelKind(kind) {
|
|
2142
|
-
return kind === "root" || kind === "automation";
|
|
2209
|
+
return kind === "root" || kind === "automation" || kind === "lead";
|
|
2210
|
+
}
|
|
2211
|
+
/**
|
|
2212
|
+
* Return whether a Watch on this Conversation would repeat what already
|
|
2213
|
+
* reaches the watcher: a child agent's results and messages go to its parent.
|
|
2214
|
+
*/
|
|
2215
|
+
function watchRepeatsChildResults(target, watcherConversationId) {
|
|
2216
|
+
return target.parentConversationId === watcherConversationId;
|
|
2143
2217
|
}
|
|
2144
2218
|
/** Return whether a person sent input from this Source. */
|
|
2145
2219
|
function isPersonInput(source) {
|
|
@@ -2320,6 +2394,7 @@ function conversationFromRow(readRow) {
|
|
|
2320
2394
|
...source ? { source } : void 0,
|
|
2321
2395
|
...sessionSource ? { sessionSource } : void 0,
|
|
2322
2396
|
...row.title ? { title: row.title } : void 0,
|
|
2397
|
+
...row.summary ? { summary: row.summary } : void 0,
|
|
2323
2398
|
...msFromDate(row.transcriptPurgedAt) !== void 0 ? { transcriptPurgedAtMs: msFromDate(row.transcriptPurgedAt) } : void 0,
|
|
2324
2399
|
...msFromDate(row.stoppedAt) !== void 0 ? { stoppedAtMs: msFromDate(row.stoppedAt) } : void 0,
|
|
2325
2400
|
...msFromDate(row.deliveryPausedAt) !== void 0 ? { deliveryPausedAtMs: msFromDate(row.deliveryPausedAt) } : void 0,
|
|
@@ -2883,13 +2958,18 @@ function conversationDescendants(tree, conversationId) {
|
|
|
2883
2958
|
}
|
|
2884
2959
|
return descendants;
|
|
2885
2960
|
}
|
|
2886
|
-
/**
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2961
|
+
/**
|
|
2962
|
+
* Set or clear the shared archive and count the rows written. This is the
|
|
2963
|
+
* only write of `archived_at`. `conversations` names the rows by id or by a
|
|
2964
|
+
* condition. `guard` is a condition that each row must still meet when it is
|
|
2965
|
+
* written, so a stale read loses to a newer change.
|
|
2966
|
+
*/
|
|
2967
|
+
async function setArchivedAt(db, conversations, archivedAt, guard) {
|
|
2968
|
+
if (!(conversations instanceof SQL) && conversations.length === 0) return 0;
|
|
2969
|
+
return (await db.update(juniorConversations).set({
|
|
2890
2970
|
archivedAt,
|
|
2891
2971
|
detailVersion: nextDetailVersion
|
|
2892
|
-
}).where(inArray(juniorConversations.conversationId, [...
|
|
2972
|
+
}).where(and(conversations instanceof SQL ? conversations : inArray(juniorConversations.conversationId, [...conversations]), guard)).returning({ conversationId: juniorConversations.conversationId })).length;
|
|
2893
2973
|
}
|
|
2894
2974
|
/**
|
|
2895
2975
|
* Restore one archived Conversation and its archived ancestors, so it shows
|
|
@@ -3249,7 +3329,8 @@ var SqlConversationEventStore = class {
|
|
|
3249
3329
|
await db.with(conversationDetailTouch(db, [conversationId])).insert(juniorConversationEvents).values(insertFromEvent(conversationId, cursor.nextSeq, historyVersion, parsed));
|
|
3250
3330
|
return {
|
|
3251
3331
|
status: "replaced",
|
|
3252
|
-
historyVersion
|
|
3332
|
+
historyVersion,
|
|
3333
|
+
seq: cursor.nextSeq
|
|
3253
3334
|
};
|
|
3254
3335
|
});
|
|
3255
3336
|
}
|
|
@@ -3523,4 +3604,4 @@ async function closeDb() {
|
|
|
3523
3604
|
current = void 0;
|
|
3524
3605
|
await previous?.db.close();
|
|
3525
3606
|
}
|
|
3526
|
-
export {
|
|
3607
|
+
export { conversationWaitsOnUserSql as $, saveActorAvatar as $t, isTopLevelKind as A, agentTurnUsageSchema as An, automationCreatorUserId as At, claimProviderConversation as B, sameDestination as Bn, readViewerAvatarUrl as Bt, createSqlStore as C, conversationPinnedForUser as Cn, isPluginInboxItem as Ct, hasConversationMetadata as D, addAgentTurnUsage as Dn, requireInboxItemLinks as Dt, dispatchInstructionsInvokeSkills as E, viewerMarksFromParticipant as En, requireInboxItemAssignees as Et, turnBehavior as F, nextDetailVersion as Fn, listAdminUsersFromSql as Ft, microUsdToUsd as G, identityAvatarUrl as Gt, parseSessionSource as H, setUserAdminFromSql as Ht, watchRepeatsChildResults as I, touchConversationDetail as In, readActorIdentity as It, conversationRangeColumns as J, readUserAvatarUrls as Jt, usdToMicroUsd as K, parseAvatarUrl as Kt, locationFromRow as L, createSlackDestination as Ln, readActorIdentityFromSql as Lt, postsRunNotices as M, resolveRootConversationId as Mn, resolveAssignees as Mt, promptModeTurnTools as N, rootConversationIsArchived as Nn, findUserByEmail as Nt, isPersonInput as O, agentTurnCostUsd as On, EVERYONE_ASSIGNEE as Ot, sourceLabel as P, conversationDetailTouch as Pn, findUserByEmailFromSql as Pt, conversationTurnFailedSql as Q, resolveActorIdentityId as Qt, setFirstConversationLocation as R, parseDestination as Rn, readIdentityById as Rt, userMessageQueries as S, conversationIsNotUnsubscribedRoot as Sn, isOnlyAssignee as St, deliversFinalText as T, rootVisibleToViewer as Tn, readInboxItemAgentScope as Tt, conversationCostOf as U, updateViewerDisplayName as Ut, getConversationIdByProviderConversation as V, resolveViewerUser as Vt, microUsdSql as W, hasUserPhoto as Wt, conversationIsActiveSql as X, userAvatarUrlsFromJoinedPhotos as Xt, conversationUsageCostExpr as Y, userAvatarUrlsFromIdentities as Yt, conversationStatusSql as Z, SYSTEM_IDENTITY_ID as Zt, readConversationTrees as _, createConversationAccessReader as _n, inboxItemPlugin as _t, getConversationStore as a, linkedSlackUser as an, AUTOMATION_INBOX_ITEM_KEY_PREFIX as at, loadConversationSlackTenantIds as b, readableSlackTeamId as bn, inboxItemVisibleTo as bt, hasAnnotationKey as c, saveUserTimezone as cn, canAgentChangeInboxItem as ct, eventFromRow as d, ToolInputError as dn, inboxItemAssignedTo as dt, deleteProviderIdentityForSlackUser as en, executionIsActive as et, copyMessageLinks as f, isToolInputError as fn, inboxItemForUser as ft, conversationDescendants as g, conversationAccessFromRows as gn, inboxItemOwnedByConversation as gt, conversationAncestors as h, canReadConversation as hn, inboxItemNeedsUser as ht, getConversationMessageSearchStore as i, findUserByVerifiedEmails as in, treeAwaitsAuthorization as it, personSourcePlatform as j, hasAgentTurnUsage as jn, resolveAssignee as jt, isPersonSource as k, agentTurnTotalTokens as kn, activeParticipantUserIds as kt, treeHasAnnotationKey as l, upsertLinkedIdentity as ln, canReadInboxItem as lt, withConversationEventLock as m, canAddConversationMessages as mn, inboxItemNeedsInput as mt, db_exports as n, findLinkedSlackUser as nn, conversationKindSql as nt, getDb as o, readUserTimezone as on, PLUGIN_INBOX_ITEM_KEY_PREFIX as ot, deleteMessageLinks as p, canAccessConversation as pn, inboxItemLinkedTo as pt, conversationAggregateColumns as q, readAvatarFetch as qt, getConversationEventStore as r, findSlackUserByPrimaryEmail as rn, awaitsAuthorizationFrom as rt, getSqlExecutor as s, recordGoogleSignIn as sn, canActOnInboxItem as st, closeDb as t, deleteProviderIdentityForUser as tn, conversationKindFromRow as tt, createSqlConversationEventStore as u, readCachedUserByEmail as un, canUserReadInboxItem as ut, setArchivedAt as v, readConversationAccessFromSql as vn, inboxItemReaderForUser as vt, withConversationMutationLock as w, readMemberParticipants as wn, itemNeedsUser as wt, lastMessageAtSql as x, conversationIsMemberRoot as xn, isAutomationAlertItem as xt, conversationSlackTenantId as y, readConversationAccessRows as yn, inboxItemReaderForUserInConversation as yt, startLocationThread as z, requireSlackDestination as zn, readIdentityByIdFromSql as zt };
|