Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 38 additions & 29 deletions api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3338,7 +3338,7 @@ paths:
- Conversations
operationId: createConversationJoinToken
summary: Get a token to watch a conversation live
description: 'Make a join token for the conversation''s thread, and say where to use it. The token opens the threadStream channel of api/asyncapi.yaml: a WebSocket that replays the Bot''s runs in the conversation, a run in progress from its start, and then carries on live. The token works once and for about half a minute, so ask for a new one for every connection, and again to reconnect. Only a person in the conversation may have one, and it opens the thread they see there and no other. A conversation no Bot has run in yet has nothing to join (409). Where realtime.clientUrl is on this server, open it with the same credential that made the token: the session, an app''s access token, or an API key, as Authorization: Bearer or x-api-key. So a script that holds only an API key can watch a conversation live.'
description: 'Make a join token for the conversation''s thread, and say where to use it. The token opens the threadStream channel of api/asyncapi.yaml: a WebSocket that replays the Bot''s runs in the conversation, a run in progress from its start, and then carries on live. The token works once and for about half a minute, so ask for a new one for every connection, and again to reconnect. Only a person in the conversation may have one, and it opens the thread they see there and no other. A conversation no Bot has run in yet has nothing to join (409). Where realtime.clientUrl is on this server, open it with the same credential that made the token: the session, an app''s access token, or an API key, as Authorization: Bearer or x-api-key. So a script that holds only an API key can watch a conversation live. The answer also names the thread''s last run and how it ended (lastRun), as a thread''s status says whether its last run failed.'
security:
- webSession: []
- appOAuth:
Expand Down Expand Up @@ -33580,6 +33580,11 @@ components:
- string
- 'null'
description: The run in progress in the thread, or null when the Bot is not working.
lastRun:
oneOf:
- $ref: '#/components/schemas/ConversationRun'
- type: 'null'
description: 'The Bot''s most recent run in the thread, and how it ended, as getConversationRun says it: the run in progress, while one is (its outcome null), and otherwise the last one. Null when this server keeps no record of a run in the thread. Absent from a server before it said this. A client that opens the conversation without replaying its runs to the end reads here whether the last one failed, so it can say so and offer to carry on, as it would had it heard the run''s RUN_ERROR.'
realtime:
type: object
description: Where to use the token.
Expand Down Expand Up @@ -34236,6 +34241,34 @@ components:
description: True uses OpenBot's list, false hands each computer back its own.
apps:
$ref: '#/components/schemas/WindowsAllowlistApps'
ConversationRun:
type: object
description: One of a Bot's runs in a conversation, and how it ended.
required:
- id
- outcome
- endedAt
properties:
id:
type: string
minLength: 1
description: The run's id, as its events carry it.
outcome:
type:
- string
- 'null'
x-extensible-enum:
- succeeded
- interrupted
- cancelled
- failed
description: 'How the run ended, as its own last event said. succeeded: it finished. interrupted: it stopped to ask a person (an approval, a missing value). cancelled: it was stopped. failed: it ended with an error, or its stream failed, or its server ended it on the way down. Null while the run is going, and for a run that ended without saying how.'
endedAt:
type:
- string
- 'null'
format: date-time
description: When the run ended, or null while outcome is null.
ConversationWork:
type: object
description: 'Something still owed an answer in a conversation: another Bot that was asked and has not answered (handoff), a routine running into it (routine), or the person''s own turn, which the server is carrying on with no page open (turn).'
Expand Down Expand Up @@ -49493,34 +49526,6 @@ components:
description: The apps that came across connected.
items:
$ref: '#/components/schemas/CarriedApp'
ConversationRun:
type: object
description: One of a Bot's runs in a conversation, and how it ended.
required:
- id
- outcome
- endedAt
properties:
id:
type: string
minLength: 1
description: The run's id, as its events carry it.
outcome:
type:
- string
- 'null'
x-extensible-enum:
- succeeded
- interrupted
- cancelled
- failed
description: 'How the run ended, as its own last event said. succeeded: it finished. interrupted: it stopped to ask a person (an approval, a missing value). cancelled: it was stopped. failed: it ended with an error, or its stream failed, or its server ended it on the way down. Null while the run is going, and for a run that ended without saying how.'
endedAt:
type:
- string
- 'null'
format: date-time
description: When the run ended, or null while outcome is null.
ConversationRunResponse:
type: object
required:
Expand Down Expand Up @@ -61028,6 +61033,10 @@ components:
expiresAt: '2026-11-14T12:00:30.000Z'
threadId: 6f3d6b1f-6f10-8a53-9d51-5f0d6c0e2f1a
runId: 0b1c6f0e-7f0e-4c1e-9d55-2f4a8c1b6e21
lastRun:
id: 0b1c6f0e-7f0e-4c1e-9d55-2f4a8c1b6e21
outcome: null
endedAt: null
realtime:
clientUrl: wss://realtime.example.com/client
topic: thread:6f3d6b1f-6f10-8a53-9d51-5f0d6c0e2f1a
Expand Down
21 changes: 20 additions & 1 deletion api/openapi/conversations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ paths:
realtime.clientUrl is on this server, open it with the same
credential that made the token: the session, an app's access token,
or an API key, as Authorization: Bearer or x-api-key. So a script
that holds only an API key can watch a conversation live.
that holds only an API key can watch a conversation live. The answer
also names the thread's last run and how it ended (lastRun), as a
thread's status says whether its last run failed.
security:
- webSession: []
- appOAuth: [conversations:read]
Expand Down Expand Up @@ -2381,6 +2383,19 @@ components:
- string
- 'null'
description: The run in progress in the thread, or null when the Bot is not working.
lastRun:
oneOf:
- $ref: '#/components/schemas/ConversationRun'
- type: 'null'
description: >-
The Bot's most recent run in the thread, and how it ended, as
getConversationRun says it: the run in progress, while one is (its
outcome null), and otherwise the last one. Null when this server
keeps no record of a run in the thread. Absent from a server
before it said this. A client that opens the conversation without
replaying its runs to the end reads here whether the last one
failed, so it can say so and offer to carry on, as it would had it
heard the run's RUN_ERROR.
realtime:
type: object
description: Where to use the token.
Expand Down Expand Up @@ -4125,6 +4140,10 @@ components:
expiresAt: '2026-11-14T12:00:30.000Z'
threadId: 6f3d6b1f-6f10-8a53-9d51-5f0d6c0e2f1a
runId: 0b1c6f0e-7f0e-4c1e-9d55-2f4a8c1b6e21
lastRun:
id: 0b1c6f0e-7f0e-4c1e-9d55-2f4a8c1b6e21
outcome: null
endedAt: null
realtime:
clientUrl: wss://realtime.example.com/client
topic: thread:6f3d6b1f-6f10-8a53-9d51-5f0d6c0e2f1a
Expand Down
66 changes: 40 additions & 26 deletions app/src/components/channels/channel-chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ import {
askRunLiveness,
askTimes,
finishedRunId,
lastRunFailure,
type QuietEnding,
quietRunPeriod,
RUN_ENDED_UNHEARD,
Expand Down Expand Up @@ -1419,33 +1420,46 @@ export function ChannelChat({
* heard that RUN_ERROR, but the join that resumed the thread took longer than its deadline,
* and a failure is said above only from a join that finished.
*
* So when the join did not finish and heard no run of its own, the last run the kept agent
* heard is asked about: said again if the server has no run going and says that run did not
* finish. Asked after the history is in, so the conversation is never held for it.
* AND A RELOAD ON A SLOW LINK. With no agent kept (a reload, a page opened again) the join is
* the only record of how the last run ended, and one cut at its deadline may not have reached
* it: the conversation opened on its history with nothing said, as above.
*
* So when the join did not finish, the server is asked how the thread's last run ended
* (`lastRun` on the join token, as a thread's status says whether its last run failed). A last
* run that failed is said again: in its own words where this page heard them (the replay, or
* the kept agent), otherwise as a turn that stopped part way, with Carry on. A server from
* before `lastRun` is asked about the run the kept agent heard fail. Asked after the history
* is in, so the conversation is never held for it.
*/
const keptStory = heardRuns(agent);
const keptFailure = keptStory?.failure() ?? null;
const keptFailedRun = keptStory?.runId() ?? null;
if (
joined !== "connected" &&
lastRun.runId() === null &&
keptFailure !== null &&
keptFailedRun !== null &&
current &&
turnsRef.current === 0
) {
const going = await askRunGoing(channel.id);
const ended =
going.liveness === "over"
? await askRunEnding(channel.id, keptFailedRun)
: null;
if (ended === "stopped" && current && turnsRef.current === 0) {
const code = keptStory?.failureCode();
setRunError(
(shown) =>
shown ?? { message: keptFailure, ...(code ? { code } : {}) },
);
}
if (joined !== "connected" && current && turnsRef.current === 0) {
// What this page heard of the last run: the join's own, or else the kept agent's.
const replayHeard = lastRun.runId() !== null;
const heard = replayHeard ? lastRun : (heardRuns(agent) ?? lastRun);
const said = await lastRunFailure({
conversationId: channel.id,
heardByKeptAgent: !replayHeard,
heardRun: heard.runId(),
heardFailure: heard.failure(),
heardCode: heard.failureCode(),
// Kept from a turn the server refused: drawn under its message (`refusedRun`).
refusedAt: async () => {
try {
const turns = await queryClient.fetchQuery(
refusedTurnsQueryOptions(channel.id),
);
return turns.map((turn) => turn.createdAt);
} catch {
return [];
}
},
});
if (
said !== null &&
current &&
turnsRef.current === 0 &&
!carriedByServerRef.current
)
setRunError((shown) => shown ?? said);
}
/*
* A TURN THE SERVER IS STILL CARRYING ON IS FOLLOWED FROM HERE. The join above streams the run
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ export const getCreateConversationJoinTokenResponseMock =
expiresAt: "2026-11-14T12:00:30.000Z",
threadId: "6f3d6b1f-6f10-8a53-9d51-5f0d6c0e2f1a",
runId: "0b1c6f0e-7f0e-4c1e-9d55-2f4a8c1b6e21",
lastRun: {
id: "0b1c6f0e-7f0e-4c1e-9d55-2f4a8c1b6e21",
outcome: null,
endedAt: null,
},
realtime: {
clientUrl: "wss://realtime.example.com/client",
topic: "thread:6f3d6b1f-6f10-8a53-9d51-5f0d6c0e2f1a",
Expand Down
2 changes: 1 addition & 1 deletion app/src/lib/api/generated/conversations/conversations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export const getCreateConversationJoinTokenUrl = (
};

/**
* Make a join token for the conversation's thread, and say where to use it. The token opens the threadStream channel of api/asyncapi.yaml: a WebSocket that replays the Bot's runs in the conversation, a run in progress from its start, and then carries on live. The token works once and for about half a minute, so ask for a new one for every connection, and again to reconnect. Only a person in the conversation may have one, and it opens the thread they see there and no other. A conversation no Bot has run in yet has nothing to join (409). Where realtime.clientUrl is on this server, open it with the same credential that made the token: the session, an app's access token, or an API key, as Authorization: Bearer or x-api-key. So a script that holds only an API key can watch a conversation live.
* Make a join token for the conversation's thread, and say where to use it. The token opens the threadStream channel of api/asyncapi.yaml: a WebSocket that replays the Bot's runs in the conversation, a run in progress from its start, and then carries on live. The token works once and for about half a minute, so ask for a new one for every connection, and again to reconnect. Only a person in the conversation may have one, and it opens the thread they see there and no other. A conversation no Bot has run in yet has nothing to join (409). Where realtime.clientUrl is on this server, open it with the same credential that made the token: the session, an app's access token, or an API key, as Authorization: Bearer or x-api-key. So a script that holds only an API key can watch a conversation live. The answer also names the thread's last run and how it ended (lastRun), as a thread's status says whether its last run failed.
* @summary Get a token to watch a conversation live
*/
export const createConversationJoinToken = async (
Expand Down
28 changes: 27 additions & 1 deletion app/src/lib/api/generated/conversations/conversations.zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import * as zod from "zod";

/**
* Make a join token for the conversation's thread, and say where to use it. The token opens the threadStream channel of api/asyncapi.yaml: a WebSocket that replays the Bot's runs in the conversation, a run in progress from its start, and then carries on live. The token works once and for about half a minute, so ask for a new one for every connection, and again to reconnect. Only a person in the conversation may have one, and it opens the thread they see there and no other. A conversation no Bot has run in yet has nothing to join (409). Where realtime.clientUrl is on this server, open it with the same credential that made the token: the session, an app's access token, or an API key, as Authorization: Bearer or x-api-key. So a script that holds only an API key can watch a conversation live.
* Make a join token for the conversation's thread, and say where to use it. The token opens the threadStream channel of api/asyncapi.yaml: a WebSocket that replays the Bot's runs in the conversation, a run in progress from its start, and then carries on live. The token works once and for about half a minute, so ask for a new one for every connection, and again to reconnect. Only a person in the conversation may have one, and it opens the thread they see there and no other. A conversation no Bot has run in yet has nothing to join (409). Where realtime.clientUrl is on this server, open it with the same credential that made the token: the session, an app's access token, or an API key, as Authorization: Bearer or x-api-key. So a script that holds only an API key can watch a conversation live. The answer also names the thread's last run and how it ended (lastRun), as a thread's status says whether its last run failed.
* @summary Get a token to watch a conversation live
*/

Expand Down Expand Up @@ -64,6 +64,32 @@ export const CreateConversationJoinTokenResponse = zod
.describe(
"The run in progress in the thread, or null when the Bot is not working.",
),
lastRun: zod
.union([
zod
.object({
id: zod
.string()
.min(1)
.describe("The run's id, as its events carry it."),
outcome: zod
.string()
.nullable()
.describe(
"How the run ended, as its own last event said. succeeded: it finished. interrupted: it stopped to ask a person (an approval, a missing value). cancelled: it was stopped. failed: it ended with an error, or its stream failed, or its server ended it on the way down. Null while the run is going, and for a run that ended without saying how.",
),
endedAt: zod.iso
.datetime({ offset: true })
.nullable()
.describe("When the run ended, or null while outcome is null."),
})
.describe("One of a Bot's runs in a conversation, and how it ended."),
zod.null(),
])
.optional()
.describe(
"The Bot's most recent run in the thread, and how it ended, as getConversationRun says it: the run in progress, while one is (its outcome null), and otherwise the last one. Null when this server keeps no record of a run in the thread. Absent from a server before it said this. A client that opens the conversation without replaying its runs to the end reads here whether the last one failed, so it can say so and offer to carry on, as it would had it heard the run's RUN_ERROR.",
),
realtime: zod
.object({
clientUrl: zod
Expand Down
3 changes: 3 additions & 0 deletions app/src/lib/api/generated/model/conversationJoinToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Generated by Orval from api/openapi.yaml. Do not edit: change the spec and run `bun run api:generate`.
*/
import type { ConversationJoinTokenRealtime } from "./conversationJoinTokenRealtime";
import type { ConversationRun } from "./conversationRun";

/**
* What a client needs to watch a conversation live: a token, and the socket and topic to use it on (the threadStream channel of api/asyncapi.yaml).
Expand All @@ -24,6 +25,8 @@ export interface ConversationJoinToken {
* @nullable
*/
runId: string | null;
/** The Bot's most recent run in the thread, and how it ended, as getConversationRun says it: the run in progress, while one is (its outcome null), and otherwise the last one. Null when this server keeps no record of a run in the thread. Absent from a server before it said this. A client that opens the conversation without replaying its runs to the end reads here whether the last one failed, so it can say so and offer to carry on, as it would had it heard the run's RUN_ERROR. */
lastRun?: ConversationRun | null;
/** Where to use the token. */
realtime: ConversationJoinTokenRealtime;
}
Loading
Loading