@todoist/automations-sdk 0.0.0 → 1.0.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/README.md +20 -33
- package/dist/authoring.d.ts +76 -0
- package/dist/authoring.js +162 -0
- package/dist/automations-api-CLcJvEjY.d.ts +6093 -0
- package/dist/base-client.d.ts +2 -0
- package/dist/base-client.js +1 -0
- package/dist/chat-turn.d.ts +314 -0
- package/dist/chat-turn.js +710 -0
- package/dist/connection-selection-BjNp9A-d.js +226 -0
- package/dist/connection-selection-C9yMkCvL.d.ts +29 -0
- package/dist/context-CxEkwuyE.js +109 -0
- package/dist/context-DsrXdqq8.d.ts +65 -0
- package/dist/index.d.ts +1060 -0
- package/dist/index.js +6030 -0
- package/dist/request-error-DoLXUa2p.js +34 -0
- package/dist/webhook-event-subscription.constants-CBmz0huQ.js +31 -0
- package/dist/webhooks.d.ts +52 -0
- package/dist/webhooks.js +83 -0
- package/package.json +83 -8
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { i as BaseClient, r as createClientContext } from "./context-CxEkwuyE.js";
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import { A as ConnectionsClient, Ct as ChatStreamRequestErrorResponse, Nt as getChatBillingRefusal, St as ChatMessageDto, bt as ConnectionSetupDto, t as AutomationsApi, yt as ConnectionDto } from "./automations-api-CLcJvEjY.js";
|
|
2
|
+
import { s as RequestOptions } from "./context-DsrXdqq8.js";
|
|
3
|
+
import { n as ConnectionSelection } from "./connection-selection-C9yMkCvL.js";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { UIMessage } from "ai";
|
|
6
|
+
//#region ../core/dist/types/chat-tools/prompt-enable-push.d.ts
|
|
7
|
+
declare const PromptEnablePushOutputSchema: z.ZodObject<{
|
|
8
|
+
enabled: z.ZodBoolean;
|
|
9
|
+
deviceCount: z.ZodNumber;
|
|
10
|
+
message: z.ZodString;
|
|
11
|
+
}, z.core.$strip>;
|
|
12
|
+
type PromptEnablePushOutput = z.infer<typeof PromptEnablePushOutputSchema>;
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region ../core/dist/types/chat-tools/select-connections.d.ts
|
|
15
|
+
declare const ConnectionItemSchema: z.ZodObject<{
|
|
16
|
+
connectorId: z.ZodString;
|
|
17
|
+
serviceName: z.ZodString;
|
|
18
|
+
connectionType: z.ZodEnum<{
|
|
19
|
+
mcp: "mcp";
|
|
20
|
+
trigger: "trigger";
|
|
21
|
+
}>;
|
|
22
|
+
}, z.core.$strip>;
|
|
23
|
+
declare const SelectConnectionsOutputSchema: z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
24
|
+
type: z.ZodLiteral<"success">;
|
|
25
|
+
connectionId: z.ZodString;
|
|
26
|
+
connectorId: z.ZodString;
|
|
27
|
+
connectionType: z.ZodEnum<{
|
|
28
|
+
mcp: "mcp";
|
|
29
|
+
trigger: "trigger";
|
|
30
|
+
}>;
|
|
31
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
32
|
+
type: z.ZodLiteral<"error">;
|
|
33
|
+
message: z.ZodString;
|
|
34
|
+
connectorId: z.ZodString;
|
|
35
|
+
connectionType: z.ZodEnum<{
|
|
36
|
+
mcp: "mcp";
|
|
37
|
+
trigger: "trigger";
|
|
38
|
+
}>;
|
|
39
|
+
}, z.core.$strip>]>>;
|
|
40
|
+
type ConnectionItem = z.infer<typeof ConnectionItemSchema>;
|
|
41
|
+
type SelectConnectionsOutput = z.infer<typeof SelectConnectionsOutputSchema>;
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region src/chat-turn/types.d.ts
|
|
44
|
+
/** Terminal outcomes of one server turn. */
|
|
45
|
+
type TurnOutcome = 'awaiting_input' | 'action_required' | 'published';
|
|
46
|
+
/** A client-owned tool action on an assistant message that must be resolved before the agent can continue. */
|
|
47
|
+
type PendingClientAction = {
|
|
48
|
+
kind: 'select_connections';
|
|
49
|
+
message: UIMessage;
|
|
50
|
+
toolCallId: string;
|
|
51
|
+
draftId: string;
|
|
52
|
+
connections: ConnectionItem[];
|
|
53
|
+
} | {
|
|
54
|
+
kind: 'enable_push';
|
|
55
|
+
message: UIMessage;
|
|
56
|
+
toolCallId: string;
|
|
57
|
+
draftId?: string;
|
|
58
|
+
};
|
|
59
|
+
/** A tool call the agent made during a turn, reported once per state change. */
|
|
60
|
+
type ToolActivity = {
|
|
61
|
+
tool: string;
|
|
62
|
+
toolCallId: string;
|
|
63
|
+
state: string;
|
|
64
|
+
};
|
|
65
|
+
type AvailableConnection = {
|
|
66
|
+
id: string;
|
|
67
|
+
label: string;
|
|
68
|
+
};
|
|
69
|
+
/** One service the agent needs a connection for, with the authorised connections that could satisfy it. */
|
|
70
|
+
type ConnectionRequirement = ConnectionItem & {
|
|
71
|
+
availableConnections: AvailableConnection[];
|
|
72
|
+
};
|
|
73
|
+
/** A connection whose setup the user has to complete before it can be used. */
|
|
74
|
+
type ConnectionSetupStart = {
|
|
75
|
+
connectionId: string;
|
|
76
|
+
setup: ConnectionSetupDto | null;
|
|
77
|
+
/** True when an existing pending connection was picked up rather than a new one created. */
|
|
78
|
+
resumed: boolean;
|
|
79
|
+
};
|
|
80
|
+
/** The pending action a turn ended on, without the message it was read from. */
|
|
81
|
+
type PendingActionSummary = {
|
|
82
|
+
kind: 'select_connections';
|
|
83
|
+
toolCallId: string;
|
|
84
|
+
draftId: string;
|
|
85
|
+
requirements: Array<ConnectionRequirement & {
|
|
86
|
+
/** Present when a connection was created for the user to authorise. */
|
|
87
|
+
setup?: ConnectionSetupStart;
|
|
88
|
+
}>;
|
|
89
|
+
} | {
|
|
90
|
+
kind: 'enable_push';
|
|
91
|
+
toolCallId: string;
|
|
92
|
+
draftId?: string;
|
|
93
|
+
};
|
|
94
|
+
type TurnResult = {
|
|
95
|
+
conversationId: string;
|
|
96
|
+
outcome: TurnOutcome;
|
|
97
|
+
assistantText: string;
|
|
98
|
+
/** Set when the outcome is `published`. */
|
|
99
|
+
automationId?: string;
|
|
100
|
+
/** Whether archiving the published conversation succeeded. */
|
|
101
|
+
conversationArchived?: boolean;
|
|
102
|
+
/** Why archiving failed, when it did. Publication itself succeeded. */
|
|
103
|
+
conversationArchiveError?: string;
|
|
104
|
+
/** Set when the outcome is `action_required`. */
|
|
105
|
+
pendingAction?: PendingActionSummary;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* What the turn sends. A message starts or continues the conversation;
|
|
109
|
+
* selections answer a pending `select_connections` action, and an empty list
|
|
110
|
+
* lets the runner resolve it on its own.
|
|
111
|
+
*/
|
|
112
|
+
type TurnInput = {
|
|
113
|
+
message: string;
|
|
114
|
+
} | {
|
|
115
|
+
selections: readonly ConnectionSelection[];
|
|
116
|
+
};
|
|
117
|
+
/** Why a turn could not be started from the given input. */
|
|
118
|
+
type ChatTurnInputErrorCode = 'awaiting_selection' | 'awaiting_push' | 'not_awaiting_selection' | 'input_required' | 'ambiguous_selection' | 'unknown_connection' |
|
|
119
|
+
/** A required connector needs a tenant or server URL, so it cannot be set up automatically. */
|
|
120
|
+
'connection_input_required';
|
|
121
|
+
export declare class ChatTurnInputError extends Error {
|
|
122
|
+
readonly code: ChatTurnInputErrorCode;
|
|
123
|
+
constructor(code: ChatTurnInputErrorCode, message: string);
|
|
124
|
+
}
|
|
125
|
+
//#endregion
|
|
126
|
+
//#region src/chat-turn/transport.d.ts
|
|
127
|
+
type ChatTurnTransportOptions = {
|
|
128
|
+
token: string;
|
|
129
|
+
baseUrl: string;
|
|
130
|
+
headers?: Record<string, string>;
|
|
131
|
+
fetch?: typeof fetch;
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* Adapts the AI SDK message stream to the Automations chat request contract.
|
|
135
|
+
*
|
|
136
|
+
* A turn on a workspace conversation goes to that workspace's chat route, so the
|
|
137
|
+
* access guard revalidates membership per turn; the scope is chosen per turn because
|
|
138
|
+
* a caller resuming a conversation only learns it once the conversation has been fetched.
|
|
139
|
+
*/
|
|
140
|
+
export declare class ChatTurnTransport {
|
|
141
|
+
private readonly transport;
|
|
142
|
+
constructor({ token, baseUrl, headers, fetch }: ChatTurnTransportOptions);
|
|
143
|
+
/** Streams one server turn, reporting incremental text and deduplicated tool state changes. */
|
|
144
|
+
streamTurn({ conversationId, workspaceId, message, signal, onText, onToolActivity }: {
|
|
145
|
+
conversationId: string;
|
|
146
|
+
/** The workspace the conversation lives in; null is the personal space. */
|
|
147
|
+
workspaceId?: string | null;
|
|
148
|
+
message: UIMessage;
|
|
149
|
+
signal?: AbortSignal;
|
|
150
|
+
onText?: (delta: string) => void;
|
|
151
|
+
onToolActivity?: (activity: ToolActivity) => void;
|
|
152
|
+
}): Promise<UIMessage>;
|
|
153
|
+
}
|
|
154
|
+
//#endregion
|
|
155
|
+
//#region src/chat-turn/run-conversation-turn.d.ts
|
|
156
|
+
type TurnApi = Pick<AutomationsApi, 'chat' | 'connections' | 'automationDraftConnections' | 'workspaceAutomationDraftConnections' | 'notifications'>;
|
|
157
|
+
type TurnOptions = {
|
|
158
|
+
/** REST calls: messages, draft connections, connection lookup and creation. */
|
|
159
|
+
api: TurnApi;
|
|
160
|
+
/** The chat stream. Separate from `api` because the API object does not expose the credentials the transport needs. */
|
|
161
|
+
transport: Pick<ChatTurnTransport, 'streamTurn'>;
|
|
162
|
+
conversationId: string;
|
|
163
|
+
/** The workspace the conversation lives in; null or absent is the personal space. */
|
|
164
|
+
workspaceId?: string | null;
|
|
165
|
+
input: TurnInput;
|
|
166
|
+
/**
|
|
167
|
+
* The persisted pending action, when the caller has already read it. Absent means the
|
|
168
|
+
* runner reads it; null means there is none, which a freshly created conversation can assert.
|
|
169
|
+
*/
|
|
170
|
+
pendingAction?: PendingClientAction | null;
|
|
171
|
+
onText?: (delta: string) => void;
|
|
172
|
+
onToolActivity?: (activity: ToolActivity) => void;
|
|
173
|
+
/** Called once the agent has published an automation, before the conversation is archived. */
|
|
174
|
+
onPublished?: (automationId: string) => void;
|
|
175
|
+
/**
|
|
176
|
+
* Several authorised connections satisfy a requirement. Return the chosen id, or undefined
|
|
177
|
+
* to end the turn as `action_required` listing them. Absent: the turn ends as `action_required`.
|
|
178
|
+
*/
|
|
179
|
+
chooseConnection?: (requirement: ConnectionRequirement) => Promise<string | undefined>;
|
|
180
|
+
/**
|
|
181
|
+
* No authorised connection exists. Return the id of one the caller has just had authorised,
|
|
182
|
+
* or undefined to end the turn as `action_required` without creating anything. Absent: a
|
|
183
|
+
* connection is created and the turn ends as `action_required` carrying its setup.
|
|
184
|
+
*/
|
|
185
|
+
authorizeConnection?: (requirement: ConnectionRequirement) => Promise<string | undefined>;
|
|
186
|
+
signal?: AbortSignal;
|
|
187
|
+
};
|
|
188
|
+
/**
|
|
189
|
+
* Runs one server turn on a persisted conversation until it reaches a terminal outcome.
|
|
190
|
+
*
|
|
191
|
+
* A turn may span several server round trips: when the agent asks for connections and every
|
|
192
|
+
* requirement can be satisfied without the user, the answer is fed straight back in.
|
|
193
|
+
*/
|
|
194
|
+
export declare function runConversationTurn(options: TurnOptions): Promise<TurnResult>;
|
|
195
|
+
//#endregion
|
|
196
|
+
//#region src/chat-turn/errors.d.ts
|
|
197
|
+
/**
|
|
198
|
+
* How far a failed turn got. A `request` failure was refused or lost before the
|
|
199
|
+
* reply began. A `stream` failure ended a reply partway; the server keeps what
|
|
200
|
+
* it had said by then.
|
|
201
|
+
*/
|
|
202
|
+
type ChatTurnFailureStage = 'request' | 'stream';
|
|
203
|
+
/**
|
|
204
|
+
* A chat turn that failed once it was sent. `requestId` is the `X-Request-Id`
|
|
205
|
+
* the request carried, which the backend logs the turn under.
|
|
206
|
+
*/
|
|
207
|
+
export declare class ChatTurnError extends Error {
|
|
208
|
+
readonly conversationId: string;
|
|
209
|
+
readonly requestId: string;
|
|
210
|
+
readonly stage: ChatTurnFailureStage;
|
|
211
|
+
/** The API's error body, when it refused the request with one. */
|
|
212
|
+
readonly response: ChatStreamRequestErrorResponse | undefined;
|
|
213
|
+
constructor({ conversationId, requestId, stage, cause }: {
|
|
214
|
+
conversationId: string;
|
|
215
|
+
requestId: string;
|
|
216
|
+
stage: ChatTurnFailureStage;
|
|
217
|
+
cause: unknown;
|
|
218
|
+
});
|
|
219
|
+
get httpStatus(): number | undefined;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Reads the API's error body out of the error a refused chat request throws,
|
|
223
|
+
* which carries the response body as its message.
|
|
224
|
+
*/
|
|
225
|
+
export declare function parseChatStreamRequestError(error: unknown): ChatStreamRequestErrorResponse | undefined;
|
|
226
|
+
/**
|
|
227
|
+
* The usage billing refusal a failed turn carries. A refused request's own error,
|
|
228
|
+
* whose message is the response body, is the cause of the ChatTurnError wrapping it.
|
|
229
|
+
*/
|
|
230
|
+
export declare function getChatTurnBillingRefusal(error: unknown): ReturnType<typeof getChatBillingRefusal>;
|
|
231
|
+
/** The request id and HTTP status a failed turn, or a request made during it, carries. */
|
|
232
|
+
export declare function readFailedRequest(error: unknown): {
|
|
233
|
+
requestId?: string;
|
|
234
|
+
httpStatus?: number;
|
|
235
|
+
};
|
|
236
|
+
/**
|
|
237
|
+
* Whether a turn broke on the way (a server error, a lost connection, a reply
|
|
238
|
+
* cut off) and is worth retrying, was refused as sent (a 4xx), or failed for a
|
|
239
|
+
* reason that is not the API's at all.
|
|
240
|
+
*/
|
|
241
|
+
export declare function classifyChatTurnFailure(error: unknown): 'broken' | 'refused' | 'other';
|
|
242
|
+
//#endregion
|
|
243
|
+
//#region src/chat-turn/messages.d.ts
|
|
244
|
+
type ChatTextPart = Extract<UIMessage['parts'][number], {
|
|
245
|
+
type: 'text';
|
|
246
|
+
}>;
|
|
247
|
+
type ChatStepStartPart = Extract<UIMessage['parts'][number], {
|
|
248
|
+
type: 'step-start';
|
|
249
|
+
}>;
|
|
250
|
+
type ChatReasoningPart = Extract<UIMessage['parts'][number], {
|
|
251
|
+
type: 'reasoning';
|
|
252
|
+
}>;
|
|
253
|
+
export declare function createUserMessage(text: string): UIMessage;
|
|
254
|
+
export declare function toUiMessage(message: ChatMessageDto): UIMessage;
|
|
255
|
+
/** Filters saved parts by their minimal replay shape, preserving accepted objects and metadata. */
|
|
256
|
+
export declare function normalizePersistedMessageParts(parts: readonly unknown[]): UIMessage['parts'];
|
|
257
|
+
export declare function isTextPart(part: unknown): part is ChatTextPart;
|
|
258
|
+
export declare function isStepStartPart(part: unknown): part is ChatStepStartPart;
|
|
259
|
+
export declare function isReasoningPart(part: unknown): part is ChatReasoningPart;
|
|
260
|
+
export declare function getVisibleText(message: UIMessage): string;
|
|
261
|
+
/** Finds the latest tool action that must be performed by the client. */
|
|
262
|
+
export declare function getPendingClientAction(message: UIMessage): PendingClientAction | null;
|
|
263
|
+
/** The pending client action on the last persisted message, if that message is the assistant's. */
|
|
264
|
+
export declare function getPendingActionFromMessages(messages: readonly ChatMessageDto[]): PendingClientAction | null;
|
|
265
|
+
export declare function getPublishedAutomationId(message: UIMessage): string | undefined;
|
|
266
|
+
/** Reconstructs the assistant tool-call message expected when answering the push notification prompt. */
|
|
267
|
+
export declare function createEnablePushContinuation(action: Extract<PendingClientAction, {
|
|
268
|
+
kind: 'enable_push';
|
|
269
|
+
}>, output: PromptEnablePushOutput): UIMessage;
|
|
270
|
+
/** Reconstructs the assistant tool-call message expected when returning connection selections. */
|
|
271
|
+
export declare function createSelectConnectionsContinuation(action: Extract<PendingClientAction, {
|
|
272
|
+
kind: 'select_connections';
|
|
273
|
+
}>, output: SelectConnectionsOutput): UIMessage;
|
|
274
|
+
//#endregion
|
|
275
|
+
//#region src/chat-turn/connection-requirements.d.ts
|
|
276
|
+
/** Removes repeated connector and connection-type requirements, preserving their first occurrence. */
|
|
277
|
+
export declare function deduplicateConnectionRequirements(requirements: readonly ConnectionItem[]): ConnectionItem[];
|
|
278
|
+
/** Looks up the authorised connections that could satisfy each distinct requirement. */
|
|
279
|
+
export declare function loadConnectionRequirements(connections: Pick<ConnectionsClient, 'list'>, requirements: readonly ConnectionItem[], options?: RequestOptions): Promise<ConnectionRequirement[]>;
|
|
280
|
+
//#endregion
|
|
281
|
+
//#region src/chat-turn/connection-setup.d.ts
|
|
282
|
+
type StartConnectionSetupRequest = {
|
|
283
|
+
connectorId: string;
|
|
284
|
+
capability: 'mcp' | 'trigger';
|
|
285
|
+
/** Automations to move onto the new connection once it is authorised, when replacing a broken one. */
|
|
286
|
+
automationIds?: readonly string[];
|
|
287
|
+
/** The slug for a connector whose MCP server URL is a `{tenant}` template, e.g. `acme`. */
|
|
288
|
+
tenant?: string;
|
|
289
|
+
/** A full MCP server URL, for a self-hosted server or to reuse a connection's own URL. */
|
|
290
|
+
serverUrl?: string;
|
|
291
|
+
};
|
|
292
|
+
/** Creates a connection and returns what the user has to complete to authorise it. */
|
|
293
|
+
export declare function startConnectionSetup(connections: Pick<ConnectionsClient, 'create'>, request: StartConnectionSetupRequest, options?: RequestOptions): Promise<ConnectionSetupStart>;
|
|
294
|
+
/**
|
|
295
|
+
* The backend's sentence when a connection could not be created because its
|
|
296
|
+
* connector needs a tenant name or server URL, otherwise undefined.
|
|
297
|
+
*/
|
|
298
|
+
export declare function getConnectionInputRequiredMessage(error: unknown): string | undefined;
|
|
299
|
+
/** Picks up the setup of a connection that is still waiting on the user. */
|
|
300
|
+
export declare function resumeConnectionSetup(connection: Pick<ConnectionDto, 'id' | 'setup'>): ConnectionSetupStart;
|
|
301
|
+
/** The pieces of a setup a client can show or open, flattened so callers need not switch on `kind`. */
|
|
302
|
+
type ConnectionSetupSummary = {
|
|
303
|
+
setupKind: 'oauth' | 'managed' | 'none';
|
|
304
|
+
authorizationUrl?: string;
|
|
305
|
+
instructions?: string;
|
|
306
|
+
code?: string;
|
|
307
|
+
deepLinkUrl?: string | null;
|
|
308
|
+
expiresAt?: string;
|
|
309
|
+
};
|
|
310
|
+
export declare function summarizeConnectionSetup(setup: ConnectionSetupDto | null): ConnectionSetupSummary;
|
|
311
|
+
/** The URL a client can open to let the user complete setup, when the setup has one. */
|
|
312
|
+
export declare function getConnectionSetupUrl(setup: ConnectionSetupDto | null): string | null;
|
|
313
|
+
//#endregion
|
|
314
|
+
export type { AvailableConnection, ChatReasoningPart, ChatStepStartPart, ChatTextPart, ChatTurnFailureStage, ChatTurnInputErrorCode, ChatTurnTransportOptions, ConnectionRequirement, ConnectionSelection, ConnectionSetupStart, ConnectionSetupSummary, PendingActionSummary, PendingClientAction, StartConnectionSetupRequest, ToolActivity, TurnInput, TurnOptions, TurnOutcome, TurnResult };
|