@@ -43,6 +43,11 @@ import {
4343 participantsOf ,
4444 resolveContextWindow ,
4545} from "./workbench-settings" ;
46+ import {
47+ AGENT_DM_DEFINITION_ID_KEY ,
48+ AGENT_DM_KIND ,
49+ definitionIdOfSettings ,
50+ } from "./agent-dm-mode" ;
4651import { presetForKind } from "./kinds" ;
4752import type {
4853 WorkbenchLauncher ,
@@ -232,9 +237,11 @@ export type FindExistingAgentChatDeps = {
232237 * tenant with that agent. Uniqueness is per (bench, definitionId).
233238 * Product reopens; it does not clone.
234239 *
235- * Matches forward, by the `chat/definitionId` every agent chat has
236- * carried in its settings since this landed, and falls back to
237- * `matchesLegacyAgentChat` for a chat minted before that key existed.
240+ * Matches forward, by the DM pin (`definitionIdOfSettings` in
241+ * `./agent-dm-mode.ts` — the one place that says what an agent DM is)
242+ * every agent chat has carried in its settings since this landed, and
243+ * falls back to `matchesLegacyAgentChat` for a chat minted before that
244+ * key existed.
238245 * The comparison is on the definition's ASSET, not the row id: a
239246 * code-sourced deploy projects a new `workflow_definition` row per
240247 * frozen wire projection, so the id a chat recorded at creation and the
@@ -255,11 +262,10 @@ export async function findExistingAgentChat(
255262 const assetId = await deps . platform . resolveDefinitionAssetId ( definitionId ) ;
256263 const matches : { row : WorkbenchSettingsRow ; createdAt : Date } [ ] = [ ] ;
257264 for ( const row of chats ) {
258- const storedDefinitionId = row . settings [ "chat/definitionId" ] ;
265+ const storedDefinitionId = definitionIdOfSettings ( row . settings ) ;
259266 const isMatch =
260267 storedDefinitionId !== undefined
261- ? typeof storedDefinitionId === "string" &&
262- ( await sameAgent ( deps , storedDefinitionId , definitionId , assetId ) )
268+ ? await sameAgent ( deps , storedDefinitionId , definitionId , assetId )
263269 : await matchesLegacyAgentChat ( deps , row , definitionId ) ;
264270 if ( ! isMatch ) continue ;
265271 const link = await deps . tenancy . getWorkbenchTenancy ( row . workbenchId ) ;
@@ -384,10 +390,10 @@ export async function mintAgentDm(
384390
385391 const preset = presetForKind ( "chat" ) ;
386392 const baseSettings : Record < string , unknown > = {
387- "chat/kind" : "chat" ,
393+ "chat/kind" : AGENT_DM_KIND ,
388394 "chat/pinned" : preset . pinned ,
389395 "chat/participants" : [ ] ,
390- "chat/definitionId" : input . definitionId ,
396+ [ AGENT_DM_DEFINITION_ID_KEY ] : input . definitionId ,
391397 } ;
392398 const settings : Record < string , unknown > =
393399 chatTitle !== undefined
@@ -680,8 +686,8 @@ export async function launchAndJoinAgent(
680686 } ;
681687 }
682688
683- if ( kindOf ( input . existingSettings ) === "chat" ) {
684- const boundDefinitionId = input . existingSettings [ "chat/definitionId" ] ;
689+ if ( kindOf ( input . existingSettings ) === AGENT_DM_KIND ) {
690+ const boundDefinitionId = definitionIdOfSettings ( input . existingSettings ) ;
685691 const alreadyHasAgent = participants . some ( ( participant ) =>
686692 isAgentAddress ( participant . address ) ,
687693 ) ;
@@ -1980,9 +1986,9 @@ export type DispatchTurnInput = {
19801986 * Asks one agent for a turn — the seam between the room (rows on a
19811987 * timeline) and the execution plane.
19821988 *
1983- * A room agent deploys as an `onTrigger` section (CL-6329, see
1984- * `./standalone-launch.ts` 's `AGENT_SECTION_MODE`) , so this fires that
1985- * section's trigger: one occurrence, running as its own child run
1989+ * An agent runs as one warm folded run provisioned from the
1990+ * conversation 's definition asset , so this fires that run's mail trigger:
1991+ * one occurrence, running as its own child run
19861992 * (`turn__<n>`) with its own event log, against the one warm run the
19871993 * (agent, workbench) pair already holds. The trigger is a mail trigger —
19881994 * that is the primitive the section subscribes on — so `sendMail`
0 commit comments