@segmentstream/agent 0.55.0 → 0.56.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +45 -0
- package/README.md +2 -0
- package/dist/_chunks/{build-metadata-CYSFZe6f.mjs → build-metadata-KEBi2lXS.mjs} +1 -1
- package/dist/_chunks/{principal-DIgU-kPR.mjs → principal-TJ6zB2rF.mjs} +6 -2
- package/dist/extension/config.d.ts +54 -7
- package/dist/extension/config.mjs +65 -6
- package/dist/extension/connections/ontology.mjs +1 -1
- package/dist/extension/extension.d.ts +7 -1
- package/dist/extension/extension.mjs +2 -1
- package/dist/extension/hooks/authorization.mjs +1 -1
- package/dist/extension/instructions/persona.mjs +1 -1
- package/dist/extension/instructions.md +5 -3
- package/dist/extension/lib/actor.mjs +1 -1
- package/dist/extension/lib/attachment-tools.mjs +1 -1
- package/dist/extension/lib/attachments-send.mjs +1 -1
- package/dist/extension/lib/attachments.d.ts +1 -1
- package/dist/extension/lib/attachments.mjs +1 -1
- package/dist/extension/lib/build-metadata.mjs +1 -1
- package/dist/extension/lib/chat-address.d.ts +10 -2
- package/dist/extension/lib/chat-address.mjs +1 -1
- package/dist/extension/lib/chat-archive.d.ts +18 -0
- package/dist/extension/lib/chat-archive.mjs +19 -1
- package/dist/extension/lib/chat-context.mjs +5 -5
- package/dist/extension/lib/chat-post-confirmation.d.ts +1 -1
- package/dist/extension/lib/chat-post-confirmation.mjs +3 -2
- package/dist/extension/lib/chat-recorder.mjs +7 -3
- package/dist/extension/lib/confirmations.mjs +1 -1
- package/dist/extension/lib/email/attachments-send.mjs +1 -1
- package/dist/extension/lib/email/channel.mjs +1 -1
- package/dist/extension/lib/guest-usage.mjs +1 -1
- package/dist/extension/lib/inbound-media/files.mjs +1 -1
- package/dist/extension/lib/inbound-media/index.mjs +1 -1
- package/dist/extension/lib/ontology-connection.mjs +1 -1
- package/dist/extension/lib/ontology-file-call.mjs +1 -1
- package/dist/extension/lib/ontology-tools.mjs +1 -1
- package/dist/extension/lib/review/hold.d.ts +1 -1
- package/dist/extension/lib/review/hold.mjs +3 -2
- package/dist/extension/lib/review/judge.mjs +6 -3
- package/dist/extension/lib/review/reply.mjs +1 -1
- package/dist/extension/lib/role-skill.mjs +1 -1
- package/dist/extension/lib/runtime-envelope.mjs +1 -1
- package/dist/extension/lib/sent-files.mjs +1 -1
- package/dist/extension/lib/slack/adapter.mjs +1 -1
- package/dist/extension/lib/slack/attachments-send.mjs +1 -1
- package/dist/extension/lib/stored-files.mjs +1 -1
- package/dist/extension/lib/telegram/adapter.mjs +2 -2
- package/dist/extension/lib/telegram/attachment-description.mjs +1 -1
- package/dist/extension/lib/telegram/attachments-send.mjs +1 -1
- package/dist/extension/lib/telegram/callbacks.mjs +1 -1
- package/dist/extension/lib/telegram/chat-archive.mjs +1 -1
- package/dist/extension/lib/telegram/confirmations.mjs +1 -1
- package/dist/extension/lib/telegram/customer-text.mjs +1 -1
- package/dist/extension/lib/telegram/files.mjs +1 -1
- package/dist/extension/lib/telegram/health.mjs +1 -1
- package/dist/extension/lib/telegram/held-approvals.mjs +1 -1
- package/dist/extension/lib/telegram/inbound-request.mjs +1 -1
- package/dist/extension/lib/telegram/inbound.mjs +1 -1
- package/dist/extension/lib/telegram/lifecycle.mjs +2 -2
- package/dist/extension/lib/telegram/principal.mjs +1 -1
- package/dist/extension/lib/telegram/session-recovery.mjs +1 -1
- package/dist/extension/lib/telegram/silent.mjs +1 -1
- package/dist/extension/lib/telegram/structured.mjs +1 -1
- package/dist/extension/lib/telegram/turn-errors.mjs +1 -1
- package/dist/extension/lib/telegram/workspace-action.mjs +1 -1
- package/dist/extension/lib/web/auth.mjs +1 -1
- package/dist/extension/lib/web/channel.mjs +1 -1
- package/dist/extension/lib/whatsapp/adapter.mjs +1 -1
- package/dist/extension/lib/whatsapp/attachments-send.mjs +1 -1
- package/dist/extension/lib/whatsapp/files.mjs +1 -1
- package/dist/extension/lib/workspace-channel/attachments-send.d.ts +35 -0
- package/dist/extension/lib/workspace-channel/attachments-send.mjs +119 -0
- package/dist/extension/lib/workspace-channel/channel.d.ts +229 -0
- package/dist/extension/lib/workspace-channel/channel.mjs +525 -0
- package/dist/extension/lib/workspace-channel/connection.d.ts +55 -0
- package/dist/extension/lib/workspace-channel/connection.mjs +68 -0
- package/dist/extension/lib/workspace-channel/secrets.d.ts +32 -0
- package/dist/extension/lib/workspace-channel/secrets.mjs +55 -0
- package/dist/extension/lib/workspace-source.mjs +1 -1
- package/dist/extension/model.mjs +1 -1
- package/dist/extension/tools/attachments_discard.mjs +1 -1
- package/dist/extension/tools/attachments_list.mjs +1 -1
- package/dist/extension/tools/attachments_promote.mjs +1 -1
- package/dist/extension/tools/attachments_read.mjs +1 -1
- package/dist/extension/tools/attachments_send.mjs +6 -2
- package/dist/extension/tools/attachments_stage.mjs +1 -1
- package/dist/extension/tools/attachments_table.mjs +1 -1
- package/dist/extension/tools/questions_ask.mjs +1 -1
- package/dist/extension/tools/workspace_source.mjs +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { fileURLToPath as __eveFileURLToPath } from "node:url";
|
|
2
|
+
import { dirname as __eveDirname } from "node:path";
|
|
3
|
+
import { createRequire as __eveCreateRequire } from "node:module";
|
|
4
|
+
const __filename = __eveFileURLToPath(import.meta.url);
|
|
5
|
+
__eveDirname(__filename);
|
|
6
|
+
__eveCreateRequire(import.meta.url);
|
|
7
|
+
import { _ as AttachmentError, _t as chatChannel } from "../../../_chunks/principal-TJ6zB2rF.mjs";
|
|
8
|
+
import { sendStoredAttachments } from "../attachments-send.mjs";
|
|
9
|
+
import { redactDiagnostic } from "../diagnostics.mjs";
|
|
10
|
+
import { StoredFileError, fetchStoredFile } from "../sent-files.mjs";
|
|
11
|
+
import { randomUUID } from "node:crypto";
|
|
12
|
+
import { workspaceChannelSendRoute } from "@segmentstream/ontology/workspace-channel";
|
|
13
|
+
const MAXIMUM_SENT_FILE_BYTES = 3145728;
|
|
14
|
+
const TOO_LARGE = `One message carries at most ${MAXIMUM_SENT_FILE_BYTES / 1024 / 1024} MiB of files.`;
|
|
15
|
+
function reportChannelError(operation, error, secrets) {
|
|
16
|
+
const reference = randomUUID();
|
|
17
|
+
console.error("[segmentstream] workspace channel delivery diagnostic", {
|
|
18
|
+
operation,
|
|
19
|
+
reference,
|
|
20
|
+
error: redactDiagnostic(error, secrets)
|
|
21
|
+
});
|
|
22
|
+
return reference;
|
|
23
|
+
}
|
|
24
|
+
async function sendChannelAttachments(options) {
|
|
25
|
+
return sendStoredAttachments({
|
|
26
|
+
...options,
|
|
27
|
+
provider: "custom",
|
|
28
|
+
channel: "custom",
|
|
29
|
+
report: (operation, error, _metadata, secrets) => reportChannelError(operation, error, secrets),
|
|
30
|
+
async send(context) {
|
|
31
|
+
const { input, chat, owner, origin, fetch, token, secrets, failed } = context;
|
|
32
|
+
const results = input.documentIds.map(({ id }) => ({
|
|
33
|
+
id,
|
|
34
|
+
filename: ""
|
|
35
|
+
}));
|
|
36
|
+
const read = [];
|
|
37
|
+
let total = 0;
|
|
38
|
+
for (const [index, reference] of input.documentIds.entries()) try {
|
|
39
|
+
const file = await fetchStoredFile({
|
|
40
|
+
reference,
|
|
41
|
+
owner,
|
|
42
|
+
origin,
|
|
43
|
+
token,
|
|
44
|
+
fetch,
|
|
45
|
+
secrets,
|
|
46
|
+
tooLarge: () => new AttachmentError({
|
|
47
|
+
code: "too_large",
|
|
48
|
+
message: TOO_LARGE
|
|
49
|
+
}),
|
|
50
|
+
limit: ({ size }) => {
|
|
51
|
+
if (total + size > 3145728) throw new AttachmentError({
|
|
52
|
+
code: "too_large",
|
|
53
|
+
message: TOO_LARGE
|
|
54
|
+
});
|
|
55
|
+
return MAXIMUM_SENT_FILE_BYTES - total;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
total += file.bytes.byteLength;
|
|
59
|
+
read.push({
|
|
60
|
+
index,
|
|
61
|
+
file
|
|
62
|
+
});
|
|
63
|
+
results[index] = {
|
|
64
|
+
id: reference.id,
|
|
65
|
+
filename: file.filename
|
|
66
|
+
};
|
|
67
|
+
} catch (error) {
|
|
68
|
+
results[index] = {
|
|
69
|
+
id: reference.id,
|
|
70
|
+
filename: error instanceof StoredFileError ? error.filename : "",
|
|
71
|
+
...failed(error, "stored_attachment_fetch_failed")
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
if (read.length === 0) return { files: results };
|
|
75
|
+
let messageId;
|
|
76
|
+
let failure;
|
|
77
|
+
try {
|
|
78
|
+
const bearer = await token();
|
|
79
|
+
const response = await fetch(new URL(workspaceChannelSendRoute(chatChannel(chat)), origin), {
|
|
80
|
+
method: "POST",
|
|
81
|
+
headers: {
|
|
82
|
+
authorization: `Bearer ${bearer}`,
|
|
83
|
+
"content-type": "application/json"
|
|
84
|
+
},
|
|
85
|
+
body: JSON.stringify({
|
|
86
|
+
operation_id: `${options.sessionId}:files:${randomUUID()}`,
|
|
87
|
+
chat_id: chat.chatId,
|
|
88
|
+
recipient: chat.peer ?? chat.chatId,
|
|
89
|
+
thread_id: null,
|
|
90
|
+
reply_to: null,
|
|
91
|
+
text: input.caption ?? "",
|
|
92
|
+
files: read.map(({ file }) => ({
|
|
93
|
+
filename: file.filename,
|
|
94
|
+
content_type: file.contentType,
|
|
95
|
+
data: Buffer.from(file.bytes).toString("base64")
|
|
96
|
+
}))
|
|
97
|
+
})
|
|
98
|
+
});
|
|
99
|
+
const answer = await response.json().catch(() => ({}));
|
|
100
|
+
if (!response.ok) throw new AttachmentError({
|
|
101
|
+
code: answer.error === "files_unsupported" ? "unsupported" : "send_failed",
|
|
102
|
+
message: `The channel did not take the files (${String(answer.error ?? response.status)}).`
|
|
103
|
+
});
|
|
104
|
+
messageId = typeof answer.message_id === "string" ? answer.message_id : void 0;
|
|
105
|
+
} catch (error) {
|
|
106
|
+
failure = failed(error, "channel_attachment_send_failed");
|
|
107
|
+
}
|
|
108
|
+
for (const { index } of read) results[index] = failure === void 0 ? {
|
|
109
|
+
...results[index],
|
|
110
|
+
...messageId === void 0 ? {} : { messageId }
|
|
111
|
+
} : {
|
|
112
|
+
...results[index],
|
|
113
|
+
...failure
|
|
114
|
+
};
|
|
115
|
+
return { files: results };
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
export { MAXIMUM_SENT_FILE_BYTES, sendChannelAttachments };
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { type Channel, type ChannelEvents } from "eve/channels";
|
|
2
|
+
import type { SessionAuthContext } from "eve/context";
|
|
3
|
+
import { type SegmentStreamAgentConfigInput } from "../../config.js";
|
|
4
|
+
import { type AgentAttachments } from "../attachments.js";
|
|
5
|
+
import { type ChatArchive } from "../chat-archive.js";
|
|
6
|
+
import { type Environment } from "../environment.js";
|
|
7
|
+
import { type AgentIdentities, type PairedMember } from "../identities.js";
|
|
8
|
+
import { type CapabilityLookup } from "../inbound-media/plan.js";
|
|
9
|
+
import { type ImageDescriber } from "../inbound-media/images.js";
|
|
10
|
+
import { type Transcriber } from "../inbound-media/speech.js";
|
|
11
|
+
import type { HoldReply } from "../review/hold.js";
|
|
12
|
+
import type { ReviewDecideFunction } from "../review/judge.js";
|
|
13
|
+
import { type RuntimeTokenVerifier } from "../runtime-identity.js";
|
|
14
|
+
import { type RuntimeToken } from "../runtime-token.js";
|
|
15
|
+
import { type ChannelConnection } from "./connection.js";
|
|
16
|
+
import { type ChannelChecks } from "./secrets.js";
|
|
17
|
+
export type { ChannelChecks } from "./secrets.js";
|
|
18
|
+
/**
|
|
19
|
+
* A channel the workspace defines in its own code (`docs/agent.md`, "Workspace channels"), for any
|
|
20
|
+
* provider with an API: a CRM inbox, a marketplace's buyer chat, an in-house messenger. The
|
|
21
|
+
* workspace supplies only the provider's part, receiving, reading a message and sending a reply;
|
|
22
|
+
* the platform does the rest as on its own channels: admission and sign-up through the ontology's
|
|
23
|
+
* identities, limits, sessions and chat keys, the archive, review holds, attachments, chat
|
|
24
|
+
* provenance and figures.
|
|
25
|
+
*
|
|
26
|
+
* The channel is a file of the agent, `agent/agent/channels/<name>.ts`, and its `name` is its entry
|
|
27
|
+
* under `channels` in `agent/segmentstream.json`, with `kind: "custom"`, its connection and how
|
|
28
|
+
* it receives. Its routes are under {@link workspaceChannelRoute}: the provider's webhook, or the
|
|
29
|
+
* platform's wake as for a mailbox; and the send route the ontology delivers an approved reply or
|
|
30
|
+
* a chat post through.
|
|
31
|
+
*
|
|
32
|
+
* Its chats are private, one person's each. People's accounts are the channel's own,
|
|
33
|
+
* `channel:<name>`: the channel can claim no Telegram, WhatsApp or email account, and a person
|
|
34
|
+
* becomes a member only by signing up there, or by pairing as on every channel.
|
|
35
|
+
*/
|
|
36
|
+
/** The authenticator of a workspace channel session's principal. */
|
|
37
|
+
export declare const WORKSPACE_CHANNEL_AUTHENTICATOR = "segmentstream-channel";
|
|
38
|
+
/** What the provider's webhook sent, for the channel's code to verify. */
|
|
39
|
+
export interface ChannelRequest {
|
|
40
|
+
readonly method: string;
|
|
41
|
+
readonly url: string;
|
|
42
|
+
readonly headers: Headers;
|
|
43
|
+
/** The body as it arrived, for a signature over it. */
|
|
44
|
+
readonly body: string;
|
|
45
|
+
}
|
|
46
|
+
/** A file a message carries: the channel's code reads it from the provider when asked. */
|
|
47
|
+
export interface ChannelFile {
|
|
48
|
+
readonly filename: string;
|
|
49
|
+
readonly contentType: string;
|
|
50
|
+
/** The size in bytes, when the provider tells it before the file is read. */
|
|
51
|
+
readonly size?: number;
|
|
52
|
+
read(): Promise<Uint8Array>;
|
|
53
|
+
}
|
|
54
|
+
/** Who wrote a message: their account on the provider, and how the provider names them. */
|
|
55
|
+
export interface ChannelSender {
|
|
56
|
+
/** Letters, digits and `:_.@+-`, at most 256 characters. */
|
|
57
|
+
readonly id: string;
|
|
58
|
+
readonly name?: string;
|
|
59
|
+
}
|
|
60
|
+
/** One message a person wrote, as the channel's code reads it from a provider's event. */
|
|
61
|
+
export interface ChannelMessage {
|
|
62
|
+
/**
|
|
63
|
+
* The provider's id of the message: one turn, whichever webhook delivery or wake reads it again.
|
|
64
|
+
* Letters, digits and `:_.@+-`, at most 256 characters, as every id here.
|
|
65
|
+
*/
|
|
66
|
+
readonly id: string;
|
|
67
|
+
/** The person's chat with the channel. */
|
|
68
|
+
readonly chatId: string;
|
|
69
|
+
readonly sender: ChannelSender;
|
|
70
|
+
readonly text: string;
|
|
71
|
+
/** Files the message carries; read only when `limits.files` is on. */
|
|
72
|
+
readonly files?: ReadonlyArray<ChannelFile>;
|
|
73
|
+
}
|
|
74
|
+
/** A file the agent sends, its bytes read. */
|
|
75
|
+
export interface ChannelReplyFile {
|
|
76
|
+
readonly filename: string;
|
|
77
|
+
readonly contentType: string;
|
|
78
|
+
readonly bytes: Uint8Array;
|
|
79
|
+
}
|
|
80
|
+
/** A message the channel's code sends: the agent's reply, a reviewed one, or a chat post. */
|
|
81
|
+
export interface ChannelReply {
|
|
82
|
+
/** The person's chat; for a chat post, the one they last wrote from on the channel. */
|
|
83
|
+
readonly chatId: string;
|
|
84
|
+
/** The person, by their account on the provider. */
|
|
85
|
+
readonly to: string;
|
|
86
|
+
readonly text: string;
|
|
87
|
+
/** The message a chat post answers, when it names one. */
|
|
88
|
+
readonly replyTo?: string;
|
|
89
|
+
/** With `limits.files`, the files `attachments_send` sends, with the caption as `text`. */
|
|
90
|
+
readonly files?: ReadonlyArray<ChannelReplyFile>;
|
|
91
|
+
}
|
|
92
|
+
/** What the channel's code gives each of its functions. */
|
|
93
|
+
export interface ChannelContext {
|
|
94
|
+
/** The channel's connection, from `agent/segmentstream.json`. */
|
|
95
|
+
readonly connection: ChannelConnection;
|
|
96
|
+
}
|
|
97
|
+
/** What a poll read from the source since the cursor. */
|
|
98
|
+
export interface ChannelRead {
|
|
99
|
+
/**
|
|
100
|
+
* The provider's events, each read as {@link ChannelDefinition.parse} reads a webhook's, holding
|
|
101
|
+
* at most 50 messages together: a larger read is refused whole and its cursor kept.
|
|
102
|
+
*/
|
|
103
|
+
readonly events: ReadonlyArray<unknown>;
|
|
104
|
+
/** Where the next read starts; the platform keeps it, at most 16,384 characters. */
|
|
105
|
+
readonly cursor: string | null;
|
|
106
|
+
/** Whether more is waiting: the platform wakes the channel again at once. */
|
|
107
|
+
readonly more?: boolean;
|
|
108
|
+
}
|
|
109
|
+
export interface ChannelDefinition {
|
|
110
|
+
/** The channel's name under `channels` in `agent/segmentstream.json`, where its kind is `custom`. */
|
|
111
|
+
readonly name: string;
|
|
112
|
+
/**
|
|
113
|
+
* `agent/segmentstream.json`, whose channel, admission, review and models the channel follows.
|
|
114
|
+
* A channel's file does not see the extension's configuration, so it passes the same JSON.
|
|
115
|
+
*/
|
|
116
|
+
readonly config: SegmentStreamAgentConfigInput;
|
|
117
|
+
/**
|
|
118
|
+
* How messages arrive, as the channel's `receive` says: the provider calls the channel's route,
|
|
119
|
+
* which `verify` checks, such as a signature with a workspace secret; or the platform wakes the
|
|
120
|
+
* channel and `read` reads what arrived since the cursor. The first read has none: start at now,
|
|
121
|
+
* so old messages are never answered.
|
|
122
|
+
*/
|
|
123
|
+
readonly receive: {
|
|
124
|
+
readonly webhook: {
|
|
125
|
+
/**
|
|
126
|
+
* Whether the request comes from the provider. `checks` checks it against the workspace
|
|
127
|
+
* secret `channels.<name>.secret` names, which the platform reads: `signedWith` an HMAC
|
|
128
|
+
* of the body, or `matches` a token.
|
|
129
|
+
*/
|
|
130
|
+
verify(request: ChannelRequest, checks: ChannelChecks): boolean | Promise<boolean>;
|
|
131
|
+
};
|
|
132
|
+
} | {
|
|
133
|
+
readonly poll: {
|
|
134
|
+
read(input: ChannelContext & {
|
|
135
|
+
readonly cursor: string | null;
|
|
136
|
+
}): Promise<ChannelRead>;
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* The messages one provider event holds: a webhook's body, parsed as JSON when it is JSON, or an
|
|
141
|
+
* event a poll read. Events that are no person's message, such as delivery receipts or the
|
|
142
|
+
* channel's own replies, hold none.
|
|
143
|
+
*/
|
|
144
|
+
parse(event: unknown, context: ChannelContext): ReadonlyArray<ChannelMessage> | Promise<ReadonlyArray<ChannelMessage>>;
|
|
145
|
+
/** Sends one message; answers the provider's id of it, when it gives one. */
|
|
146
|
+
send(reply: ChannelReply, context: ChannelContext): Promise<{
|
|
147
|
+
readonly id?: string;
|
|
148
|
+
} | undefined | void>;
|
|
149
|
+
/**
|
|
150
|
+
* What the provider takes: `maxLength`, the most characters of one message, longer replies leave
|
|
151
|
+
* in several; `files`, whether messages carry files both ways. Without them, any length and no
|
|
152
|
+
* files.
|
|
153
|
+
*/
|
|
154
|
+
readonly limits?: {
|
|
155
|
+
readonly maxLength?: number;
|
|
156
|
+
readonly files?: boolean;
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
export interface WorkspaceChannelOptions extends ChannelDefinition {
|
|
160
|
+
readonly review?: {
|
|
161
|
+
readonly decide: ReviewDecideFunction;
|
|
162
|
+
/** Tests pass an archive and a hold in place of the ontology's. */
|
|
163
|
+
readonly archive?: ChatArchive;
|
|
164
|
+
readonly hold?: HoldReply;
|
|
165
|
+
};
|
|
166
|
+
readonly environment?: Environment;
|
|
167
|
+
readonly token?: RuntimeToken;
|
|
168
|
+
readonly fetch?: typeof fetch;
|
|
169
|
+
/** Tests pass fakes for the connection, the archive, the identities and attachments. */
|
|
170
|
+
readonly connection?: ChannelConnection;
|
|
171
|
+
readonly archive?: ChatArchive;
|
|
172
|
+
readonly identities?: AgentIdentities;
|
|
173
|
+
readonly attachments?: AgentAttachments;
|
|
174
|
+
readonly transcribe?: Transcriber;
|
|
175
|
+
readonly describeImage?: ImageDescriber;
|
|
176
|
+
readonly modelCapabilities?: CapabilityLookup;
|
|
177
|
+
/** Verifies the send route's callers; tests pass one on a local key set. */
|
|
178
|
+
readonly verify?: RuntimeTokenVerifier;
|
|
179
|
+
/** The checks of a delivery against the channel's secret; tests pass fakes. */
|
|
180
|
+
readonly checks?: (body: string) => ChannelChecks;
|
|
181
|
+
readonly log?: (message: string, detail: unknown) => void;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* The most messages one webhook delivery or one read may hold. A larger one is refused whole,
|
|
185
|
+
* before any of it starts a turn: its cursor stays, and the provider's delivery is answered 413.
|
|
186
|
+
*/
|
|
187
|
+
export declare const MAXIMUM_MESSAGES = 50;
|
|
188
|
+
/**
|
|
189
|
+
* A reply in parts of at most `maxLength` characters: at a paragraph, else a line, else a space,
|
|
190
|
+
* else where the length ends.
|
|
191
|
+
*/
|
|
192
|
+
export declare function splitReply(text: string, maxLength: number | undefined): ReadonlyArray<string>;
|
|
193
|
+
/**
|
|
194
|
+
* The principal of a workspace channel's session: the member who writes from the account, on the
|
|
195
|
+
* channel, in their private chat with it.
|
|
196
|
+
*/
|
|
197
|
+
export declare function workspaceChannelPrincipal(channel: string, member: PairedMember, sender: ChannelSender, chatId: string): SessionAuthContext;
|
|
198
|
+
/**
|
|
199
|
+
* A channel the workspace defines in its own code: its file, `agent/agent/channels/<name>.ts`,
|
|
200
|
+
* exports it as default.
|
|
201
|
+
*
|
|
202
|
+
* ```ts
|
|
203
|
+
* import { defineChannel } from "@segmentstream/agent";
|
|
204
|
+
*
|
|
205
|
+
* import config from "../../segmentstream.json";
|
|
206
|
+
*
|
|
207
|
+
* export default defineChannel({
|
|
208
|
+
* name: "zernio",
|
|
209
|
+
* config,
|
|
210
|
+
* receive: {
|
|
211
|
+
* webhook: { verify: ({ headers }, { signedWith }) => signedWith(headers.get("x-signature") ?? "") },
|
|
212
|
+
* },
|
|
213
|
+
* parse: (event) => messagesOf(event),
|
|
214
|
+
* send: ({ chatId, text }, { connection }) =>
|
|
215
|
+
* connection.post("/messages", { json: { conversation: chatId, text } }),
|
|
216
|
+
* });
|
|
217
|
+
* ```
|
|
218
|
+
*/
|
|
219
|
+
export declare function defineChannel(definition: ChannelDefinition): Channel;
|
|
220
|
+
/** The workspace channel's routes and events, which {@link defineChannel} defines as a channel. */
|
|
221
|
+
export declare function workspaceChannelDefinition(options: WorkspaceChannelOptions): {
|
|
222
|
+
routes: import("eve/channels").HttpRouteDefinition<unknown>[];
|
|
223
|
+
events: ChannelEvents;
|
|
224
|
+
fetchFile: (url: string, context?: unknown) => Promise<{
|
|
225
|
+
readonly bytes: Buffer;
|
|
226
|
+
readonly mediaType: string;
|
|
227
|
+
readonly filename: string;
|
|
228
|
+
} | null>;
|
|
229
|
+
};
|