twenty-sdk 2.55.0 → 2.56.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.
@@ -1,10 +1,10 @@
1
- import { isNonEmptyString as e, isNull as t, isObject as n, isString as r, isUndefined as i } from "@sniptt/guards";
2
- import { MetadataApiClient as a } from "twenty-client-sdk/metadata";
3
- import { RestApiClient as o } from "twenty-client-sdk/rest";
1
+ import { isArray as e, isNonEmptyString as t, isNull as n, isObject as r, isString as i, isUndefined as a } from "@sniptt/guards";
2
+ import { MetadataApiClient as o } from "twenty-client-sdk/metadata";
3
+ import { RestApiClient as s } from "twenty-client-sdk/rest";
4
4
  //#region ../twenty-shared/dist/isDefined-Dtu5EYqP.mjs
5
- var s = (e) => !i(e) && !t(e), c = (t) => {
5
+ var c = (e) => !a(e) && !n(e), l = (e) => {
6
6
  let n = { type: "unknown" };
7
- switch (t.type) {
7
+ switch (e.type) {
8
8
  case "string":
9
9
  n.type = "string";
10
10
  break;
@@ -16,10 +16,10 @@ var s = (e) => !i(e) && !t(e), c = (t) => {
16
16
  n.type = "boolean";
17
17
  break;
18
18
  case "array":
19
- n.type = "array", t.items && (n.items = c(t.items));
19
+ n.type = "array", e.items && (n.items = l(e.items));
20
20
  break;
21
21
  case "object":
22
- n.type = "object", t.properties && (n.properties = Object.fromEntries(Object.entries(t.properties).map(([e, t]) => [e, c(t)])));
22
+ n.type = "object", e.properties && (n.properties = Object.fromEntries(Object.entries(e.properties).map(([e, t]) => [e, l(t)])));
23
23
  break;
24
24
  case "record":
25
25
  n.type = "record";
@@ -29,93 +29,102 @@ var s = (e) => !i(e) && !t(e), c = (t) => {
29
29
  break;
30
30
  default: n.type = "unknown";
31
31
  }
32
- return Array.isArray(t.enum) && (n.enum = t.enum.filter((e) => typeof e == "string")), t.multiline === !0 && (n.multiline = !0), e(t.label) && (n.label = t.label), e(t.objectUniversalIdentifier) && (n.objectUniversalIdentifier = t.objectUniversalIdentifier), n;
33
- }, l = (e) => [c(e)];
34
- l({
32
+ return Array.isArray(e.enum) && (n.enum = e.enum.filter((e) => typeof e == "string")), e.multiline === !0 && (n.multiline = !0), t(e.label) && (n.label = e.label), t(e.objectUniversalIdentifier) && (n.objectUniversalIdentifier = e.objectUniversalIdentifier), n;
33
+ }, u = (e) => [l(e)];
34
+ u({
35
35
  type: "object",
36
36
  properties: {
37
37
  a: { type: "string" },
38
38
  b: { type: "number" }
39
39
  }
40
40
  });
41
- var u = "RetryableLogicFunctionError", d = class extends Error {
41
+ var d = "RetryableLogicFunctionError", f = class extends Error {
42
42
  constructor(e) {
43
- super(e), this.name = u;
43
+ super(e), this.name = d;
44
44
  }
45
- }, f = class extends Error {
45
+ }, p = class extends Error {
46
46
  constructor(e) {
47
47
  super(`App connection ${e} requires the user to reconnect (authFailedAt is set). Surface a "Reconnect" prompt in your UI.`), this.name = "AppConnectionAuthFailedError", this.connectionId = e;
48
48
  }
49
- }, p = {
49
+ }, m = {
50
50
  user: "USER",
51
51
  workspace: "WORKSPACE"
52
- }, m = "TWENTY_API_URL", h = "TWENTY_APP_APPLICATION_ACCESS_TOKEN", g = {
52
+ }, h = "TWENTY_API_URL", ee = "TWENTY_APP_ACCESS_TOKEN", g = "TWENTY_APP_APPLICATION_ACCESS_TOKEN", _ = {
53
53
  USER: "user",
54
54
  WORKSPACE: "workspace"
55
- }, _ = (e) => ({
55
+ }, v = (e) => ({
56
56
  ...e,
57
- visibility: g[e.scope]
58
- }), v = () => process.env.TWENTY_APP_APPLICATION_ACCESS_TOKEN ?? process.env.TWENTY_APP_ACCESS_TOKEN, y = async ({ query: e, variables: t, caller: n }) => {
59
- let r = process.env[m], i = v();
60
- if (!r || !i) throw Error(`${n}() requires the app runtime env vars ${m} and ${h}.`);
61
- let a = await fetch(`${r}/metadata`, {
57
+ visibility: _[e.scope]
58
+ }), te = () => process.env.TWENTY_APP_APPLICATION_ACCESS_TOKEN ?? process.env.TWENTY_APP_ACCESS_TOKEN, ne = () => process.env.TWENTY_APP_ACCESS_TOKEN ?? process.env.TWENTY_APP_APPLICATION_ACCESS_TOKEN, y = ({ caller: e, isActingAsCaller: n = !1 }) => {
59
+ let r = process.env[h], i = n ? ne() : te();
60
+ if (!t(r) || !t(i)) throw Error(`${e}() requires the app runtime env vars ${h} and ${g} (or ${ee}).`);
61
+ return {
62
+ apiUrl: r,
63
+ accessToken: i
64
+ };
65
+ }, b = async ({ query: e, variables: t, caller: n, signal: r, isActingAsCaller: i = !1 }) => {
66
+ let { apiUrl: a, accessToken: o } = y({
67
+ caller: n,
68
+ isActingAsCaller: i
69
+ }), s = await fetch(`${a}/metadata`, {
62
70
  method: "POST",
63
71
  headers: {
64
72
  "Content-Type": "application/json",
65
- Authorization: `Bearer ${i}`
73
+ Authorization: `Bearer ${o}`
66
74
  },
67
75
  body: JSON.stringify({
68
76
  query: e,
69
77
  variables: t
70
- })
78
+ }),
79
+ signal: r
71
80
  });
72
- if (!a.ok) throw Error(`${n}() failed: HTTP ${a.status} ${a.statusText}`);
73
- let o = await a.json();
74
- if (o.errors && o.errors.length > 0) throw Error(`${n}() failed: ${o.errors.map((e) => e.message).join(", ")}`);
75
- if (!o.data) throw Error(`${n}() failed: response contained no data.`);
76
- return o.data;
77
- }, b = "\n query GetAppConnection($id: ID!) {\n appConnection(id: $id) {\n id\n providerName\n name\n handle\n externalAccountId\n scope\n userWorkspaceId\n workspaceMemberId\n providerType\n accessToken\n scopes\n authFailedAt\n authFailedReason\n }\n }\n", x = async (e) => {
78
- let { appConnection: t } = await y({
79
- query: b,
81
+ if (!s.ok) throw Error(`${n}() failed: HTTP ${s.status} ${s.statusText}`);
82
+ let c = await s.json();
83
+ if (c.errors && c.errors.length > 0) throw Error(`${n}() failed: ${c.errors.map((e) => e.message).join(", ")}`);
84
+ if (!c.data) throw Error(`${n}() failed: response contained no data.`);
85
+ return c.data;
86
+ }, x = "\n query GetAppConnection($id: ID!) {\n appConnection(id: $id) {\n id\n providerName\n name\n handle\n externalAccountId\n scope\n userWorkspaceId\n workspaceMemberId\n providerType\n accessToken\n scopes\n authFailedAt\n authFailedReason\n }\n }\n", re = async (e) => {
87
+ let { appConnection: t } = await b({
88
+ query: x,
80
89
  variables: { id: e },
81
90
  caller: "getConnection"
82
91
  });
83
- if (t.authFailedAt !== null) throw new f(t.id);
84
- return _(t);
85
- }, S = "agentChatAssistant", C = ({ objectNameSingular: e, recordId: t, displayName: n }) => e === "agentChatAssistant" ? `@${n}` : `[[record:${e}:${t}:${n}]]`, ee = (t) => e(t) ? t.charAt(0).toUpperCase() + t.slice(1) : "", te = "\n query ListAppConnections($filter: ListAppConnectionsInput) {\n appConnections(filter: $filter) {\n id\n providerName\n name\n handle\n externalAccountId\n scope\n userWorkspaceId\n workspaceMemberId\n providerType\n accessToken\n scopes\n authFailedAt\n authFailedReason\n }\n }\n", w = async ({ visibility: e, ...t } = {}) => {
86
- let { appConnections: n } = await y({
87
- query: te,
92
+ if (t.authFailedAt !== null) throw new p(t.id);
93
+ return v(t);
94
+ }, S = "agentChatAssistant", C = ({ objectNameSingular: e, recordId: t, displayName: n }) => e === "agentChatAssistant" ? `@${n}` : `[[record:${e}:${t}:${n}]]`, ie = (e) => t(e) ? e.charAt(0).toUpperCase() + e.slice(1) : "", ae = "\n query ListAppConnections($filter: ListAppConnectionsInput) {\n appConnections(filter: $filter) {\n id\n providerName\n name\n handle\n externalAccountId\n scope\n userWorkspaceId\n workspaceMemberId\n providerType\n accessToken\n scopes\n authFailedAt\n authFailedReason\n }\n }\n", oe = async ({ visibility: e, ...t } = {}) => {
95
+ let { appConnections: n } = await b({
96
+ query: ae,
88
97
  variables: { filter: {
89
98
  ...t,
90
- scope: t.scope ?? (s(e) ? p[e] : void 0)
99
+ scope: t.scope ?? (c(e) ? m[e] : void 0)
91
100
  } },
92
101
  caller: "listConnections"
93
102
  });
94
- return n.map(_);
95
- }, T = (e, t) => {
103
+ return n.map(v);
104
+ }, se = (e, t) => {
96
105
  if (t.userWorkspaceId !== null) {
97
106
  let n = e.find((e) => e.scope === "USER" && e.userWorkspaceId === t.userWorkspaceId);
98
107
  if (n) return n;
99
108
  }
100
109
  return e.find((e) => e.scope === "WORKSPACE") ?? null;
101
- }, E = "\n mutation ReportAppConnectionAuthFailure($input: ReportAppConnectionAuthFailureInput!) {\n reportAppConnectionAuthFailure(input: $input)\n }\n", D = async ({ connectionId: e, reason: t }) => {
102
- await y({
103
- query: E,
110
+ }, ce = "\n mutation ReportAppConnectionAuthFailure($input: ReportAppConnectionAuthFailureInput!) {\n reportAppConnectionAuthFailure(input: $input)\n }\n", le = async ({ connectionId: e, reason: t }) => {
111
+ await b({
112
+ query: ce,
104
113
  variables: { input: {
105
114
  id: e,
106
115
  reason: t
107
116
  } },
108
117
  caller: "reportConnectionAuthFailure"
109
118
  });
110
- }, O = "\n id\n handle\n displayName\n visibility\n connectedAccountId\n isSyncEnabled\n participantHandleFieldUniversalIdentifier\n messagingProviderUniversalIdentifier\n", k = `
119
+ }, w = "\n id\n handle\n displayName\n visibility\n connectedAccountId\n isSyncEnabled\n participantHandleFieldUniversalIdentifier\n messagingProviderUniversalIdentifier\n", T = `
111
120
  mutation CreateAppMessageChannel($input: CreateAppMessageChannelInput!) {
112
121
  createAppMessageChannel(input: $input) {
113
- ${O}
122
+ ${w}
114
123
  }
115
124
  }
116
- `, A = async ({ messagingProvider: e, ...t }) => {
117
- let { createAppMessageChannel: n } = await y({
118
- query: k,
125
+ `, E = async ({ messagingProvider: e, ...t }) => {
126
+ let { createAppMessageChannel: n } = await b({
127
+ query: T,
119
128
  variables: { input: {
120
129
  ...t,
121
130
  messagingProviderUniversalIdentifier: e?.universalIdentifier
@@ -123,28 +132,28 @@ var u = "RetryableLogicFunctionError", d = class extends Error {
123
132
  caller: "createMessageChannel"
124
133
  });
125
134
  return n;
126
- }, j = `
135
+ }, D = `
127
136
  query ListAppMessageChannels($filter: ListAppMessageChannelsInput) {
128
137
  appMessageChannels(filter: $filter) {
129
- ${O}
138
+ ${w}
130
139
  }
131
140
  }
132
- `, M = async (e = {}) => {
133
- let { appMessageChannels: t } = await y({
134
- query: j,
141
+ `, O = async (e = {}) => {
142
+ let { appMessageChannels: t } = await b({
143
+ query: D,
135
144
  variables: { filter: e },
136
145
  caller: "listMessageChannels"
137
146
  });
138
147
  return t;
139
- }, N = `
148
+ }, k = `
140
149
  mutation UpdateAppMessageChannel($input: UpdateAppMessageChannelInput!) {
141
150
  updateAppMessageChannel(input: $input) {
142
- ${O}
151
+ ${w}
143
152
  }
144
153
  }
145
- `, P = async ({ messagingProvider: e, ...t }) => {
146
- let { updateAppMessageChannel: n } = await y({
147
- query: N,
154
+ `, A = async ({ messagingProvider: e, ...t }) => {
155
+ let { updateAppMessageChannel: n } = await b({
156
+ query: k,
148
157
  variables: { input: {
149
158
  ...t,
150
159
  messagingProviderUniversalIdentifier: e === void 0 ? void 0 : e?.universalIdentifier ?? null
@@ -152,22 +161,22 @@ var u = "RetryableLogicFunctionError", d = class extends Error {
152
161
  caller: "updateMessageChannel"
153
162
  });
154
163
  return n;
155
- }, F = `
164
+ }, j = `
156
165
  mutation DeleteAppMessageChannel($id: UUID!) {
157
166
  deleteAppMessageChannel(id: $id) {
158
- ${O}
167
+ ${w}
159
168
  }
160
169
  }
161
- `, I = async (e) => {
162
- let { deleteAppMessageChannel: t } = await y({
163
- query: F,
170
+ `, M = async (e) => {
171
+ let { deleteAppMessageChannel: t } = await b({
172
+ query: j,
164
173
  variables: { id: e },
165
174
  caller: "deleteMessageChannel"
166
175
  });
167
176
  return t;
168
- }, L = "\n mutation IngestAppMessages($input: IngestAppMessagesInput!) {\n ingestAppMessages(input: $input) {\n messages {\n externalId\n messageId\n messageThreadId\n }\n }\n }\n", R = async ({ messageChannelId: e, messages: t }) => {
169
- let { ingestAppMessages: n } = await y({
170
- query: L,
177
+ }, N = "\n mutation IngestAppMessages($input: IngestAppMessagesInput!) {\n ingestAppMessages(input: $input) {\n messages {\n externalId\n messageId\n messageThreadId\n }\n }\n }\n", P = async ({ messageChannelId: e, messages: t }) => {
178
+ let { ingestAppMessages: n } = await b({
179
+ query: N,
171
180
  variables: { input: {
172
181
  messageChannelId: e,
173
182
  messages: t
@@ -175,63 +184,283 @@ var u = "RetryableLogicFunctionError", d = class extends Error {
175
184
  caller: "ingestMessages"
176
185
  });
177
186
  return n.messages;
178
- }, z = "\n id\n externalId\n name\n isSynced\n messageChannelId\n", B = `
187
+ }, F = "\n id\n externalId\n name\n isSynced\n messageChannelId\n", I = `
179
188
  query ListAppMessageFolders($filter: ListAppMessageFoldersInput) {
180
189
  appMessageFolders(filter: $filter) {
181
- ${z}
190
+ ${F}
182
191
  }
183
192
  }
184
- `, V = async (e = {}) => {
185
- let { appMessageFolders: t } = await y({
186
- query: B,
193
+ `, L = async (e = {}) => {
194
+ let { appMessageFolders: t } = await b({
195
+ query: I,
187
196
  variables: { filter: e },
188
197
  caller: "listMessageFolders"
189
198
  });
190
199
  return t;
191
- }, H = `
200
+ }, R = `
192
201
  mutation SyncAppMessageFolders($input: SyncAppMessageFoldersInput!) {
193
202
  syncAppMessageFolders(input: $input) {
194
- ${z}
203
+ ${F}
195
204
  }
196
205
  }
197
- `, U = async (e) => {
198
- let { syncAppMessageFolders: t } = await y({
199
- query: H,
206
+ `, z = async (e) => {
207
+ let { syncAppMessageFolders: t } = await b({
208
+ query: R,
200
209
  variables: { input: e },
201
210
  caller: "syncMessageFolders"
202
211
  });
203
212
  return t;
204
- }, W = "\n mutation RunAgent($input: RunAgentInput!) {\n runAgent(input: $input) {\n threadId\n status\n result\n error\n success\n }\n }\n", G = async ({ input: e, ...t }) => {
205
- let { runAgent: n } = await y({
206
- query: W,
207
- variables: { input: s(e) ? {
213
+ }, B = (e) => i(e) ? [{
214
+ role: "user",
215
+ content: e
216
+ }] : e, V = "\n mutation RunAgent($input: RunAgentInput!) {\n runAgent(input: $input) {\n threadId\n runId\n status\n result\n error\n success\n }\n }\n", H = async ({ input: e, ...t }) => {
217
+ let { runAgent: n } = await b({
218
+ query: V,
219
+ variables: { input: c(e) ? {
208
220
  ...t,
209
- input: typeof e == "string" ? [{
210
- role: "user",
211
- content: e
212
- }] : e
221
+ input: B(e)
213
222
  } : t },
214
223
  caller: "runAgent"
215
224
  });
216
225
  return n;
217
- }, K = async (e) => {
218
- let { sendInboxMessage: t } = await new a().mutation({ sendInboxMessage: {
226
+ }, U = (e) => e.type === "message-persisted" && c(e.turnId) || e.type === "stream-ended" || e.type === "run-finished" || e.type === "credits-exhausted" || e.type === "stream-error", W = (e) => {
227
+ let t = e.providerMetadata ?? void 0;
228
+ switch (e.type) {
229
+ case "text": return {
230
+ type: "text",
231
+ text: e.textContent ?? ""
232
+ };
233
+ case "reasoning": return {
234
+ type: "reasoning",
235
+ text: e.reasoningContent ?? "",
236
+ state: e.state ?? "done",
237
+ providerMetadata: t
238
+ };
239
+ case "file": return {
240
+ type: "file",
241
+ mediaType: e.fileMediaType ?? "application/octet-stream",
242
+ filename: e.fileFilename ?? "",
243
+ url: e.fileUrl ?? "",
244
+ fileId: e.fileId ?? ""
245
+ };
246
+ case "source-url": return {
247
+ type: "source-url",
248
+ sourceId: e.sourceUrlSourceId ?? "",
249
+ url: e.sourceUrlUrl ?? "",
250
+ title: e.sourceUrlTitle ?? "",
251
+ providerMetadata: t
252
+ };
253
+ case "source-document": return {
254
+ type: "source-document",
255
+ sourceId: e.sourceDocumentSourceId ?? "",
256
+ mediaType: e.sourceDocumentMediaType ?? "",
257
+ title: e.sourceDocumentTitle ?? "",
258
+ filename: e.sourceDocumentFilename ?? "",
259
+ providerMetadata: t
260
+ };
261
+ case "step-start": return { type: "step-start" };
262
+ default: {
263
+ let t = e.type.startsWith("tool-"), n = e.type === "dynamic-tool";
264
+ return !t && !n || !c(e.toolCallId) ? null : {
265
+ type: e.type,
266
+ ...n && { toolName: e.toolName ?? "" },
267
+ toolCallId: e.toolCallId,
268
+ input: e.toolInput ?? {},
269
+ output: e.toolOutput,
270
+ errorText: e.errorMessage ?? "",
271
+ state: e.state,
272
+ ...c(e.providerExecuted) && { providerExecuted: e.providerExecuted },
273
+ ...c(e.providerMetadata) && { callProviderMetadata: e.providerMetadata }
274
+ };
275
+ }
276
+ }
277
+ }, ue = (e) => e.map((e) => ({
278
+ id: e.id,
279
+ role: e.role,
280
+ status: e.status,
281
+ parts: [...e.parts].sort((e, t) => e.orderIndex - t.orderIndex).map(W).filter(c),
282
+ metadata: {
283
+ createdAt: e.createdAt,
284
+ senderWorkspaceMemberId: e.senderWorkspaceMemberId,
285
+ turnId: e.turnId,
286
+ ...e.role === "assistant" ? {
287
+ startedAt: e.createdAt,
288
+ finishedAt: e.processedAt ?? void 0
289
+ } : {}
290
+ },
291
+ threadId: e.threadId
292
+ })), de = "\n query ConversationMessages($agentUniversalIdentifier: UUID!, $threadKey: String!) {\n messages: chatMessages(agentUniversalIdentifier: $agentUniversalIdentifier, threadKey: $threadKey) {\n id\n threadId\n turnId\n senderWorkspaceMemberId\n role\n status\n createdAt\n processedAt\n parts {\n orderIndex\n type\n textContent\n reasoningContent\n toolName\n toolCallId\n toolInput\n toolOutput\n state\n providerExecuted\n errorMessage\n sourceUrlSourceId\n sourceUrlUrl\n sourceUrlTitle\n sourceDocumentSourceId\n sourceDocumentMediaType\n sourceDocumentTitle\n sourceDocumentFilename\n fileMediaType\n fileFilename\n fileUrl\n fileId\n providerMetadata\n }\n }\n streamCatchup: chatStreamCatchupChunks(agentUniversalIdentifier: $agentUniversalIdentifier, threadKey: $threadKey) {\n chunks\n maxSeq\n error {\n code\n message\n }\n }\n }\n", fe = async (e) => {
293
+ let { messages: t, streamCatchup: n } = await b({
294
+ query: de,
295
+ variables: e,
296
+ caller: "listConversationMessages"
297
+ });
298
+ return {
299
+ messages: ue(t),
300
+ streamCatchup: n
301
+ };
302
+ }, G = (t) => r(t) && !e(t), K = (e) => e.map((e) => G(e) && i(e.message) ? e.message : JSON.stringify(e)), pe = (e) => G(e) && i(e.type), me = ({ block: n, caller: r }) => {
303
+ let i = n.split("\n");
304
+ if (i.includes("event: complete")) return { type: "complete" };
305
+ let a = i.filter((e) => e.startsWith("data:")).map((e) => e.slice(5).trimStart()).join("\n");
306
+ if (!t(a)) return null;
307
+ let o = JSON.parse(a);
308
+ if (!G(o)) throw Error(`${r}() failed: unexpected result ${a}`);
309
+ if (e(o.errors)) return {
310
+ type: "errors",
311
+ messages: K(o.errors)
312
+ };
313
+ let s = G(o.data) && G(o.data.onAgentChatEvent) ? o.data.onAgentChatEvent.event : void 0;
314
+ if (!pe(s)) throw Error(`${r}() failed: unexpected result ${a}`);
315
+ return {
316
+ type: "event",
317
+ event: s
318
+ };
319
+ }, he = async (t) => {
320
+ let n = await t.json().catch(() => void 0);
321
+ return G(n) && e(n.errors) ? K(n.errors).join(", ") : `HTTP ${t.status} ${t.statusText}`;
322
+ };
323
+ async function* q({ query: e, variables: t, caller: n, signal: r, closedEarlyAdvice: i = "", isActingAsCaller: a = !1 }) {
324
+ let { apiUrl: o, accessToken: s } = y({
325
+ caller: n,
326
+ isActingAsCaller: a
327
+ }), l;
328
+ if (!r?.aborted) try {
329
+ let a = await fetch(`${o}/metadata`, {
330
+ method: "POST",
331
+ headers: {
332
+ Accept: "text/event-stream",
333
+ "Content-Type": "application/json",
334
+ Authorization: `Bearer ${s}`
335
+ },
336
+ body: JSON.stringify({
337
+ query: e,
338
+ variables: t
339
+ }),
340
+ signal: r
341
+ });
342
+ if (!a.ok || !c(a.body)) throw Error(`${n}() failed: ${await he(a)}`);
343
+ l = a.body.pipeThrough(new TextDecoderStream()).getReader();
344
+ let u = "";
345
+ for (;;) {
346
+ let { done: e, value: t } = await l.read();
347
+ if (e) throw Error(`${n}() failed: the stream closed early${i}`);
348
+ u = (u + t).replace(/\r\n/g, "\n");
349
+ let r = u.indexOf("\n\n");
350
+ for (; r !== -1;) {
351
+ let e = me({
352
+ block: u.slice(0, r),
353
+ caller: n
354
+ });
355
+ if (u = u.slice(r + 2), r = u.indexOf("\n\n"), e?.type === "complete") return;
356
+ if (e?.type === "errors") throw Error(`${n}() failed: ${e.messages.join(", ")}`);
357
+ e?.type === "event" && (yield e.event);
358
+ }
359
+ }
360
+ } catch (e) {
361
+ if (r?.aborted) return;
362
+ throw e;
363
+ } finally {
364
+ await l?.cancel().catch(() => {});
365
+ }
366
+ }
367
+ //#endregion
368
+ //#region src/sdk/logic-function/agents/stream-conversation.ts
369
+ var ge = "\n subscription OnAgentChatEvent($agentUniversalIdentifier: UUID!, $threadKey: String!) {\n onAgentChatEvent(agentUniversalIdentifier: $agentUniversalIdentifier, threadKey: $threadKey) {\n event\n }\n }\n", _e = ({ signal: e, ...t }) => q({
370
+ query: ge,
371
+ variables: t,
372
+ caller: "streamConversation",
373
+ signal: e,
374
+ closedEarlyAdvice: "; read the history and stream again to resume"
375
+ }), ve = "\n mutation Generate($input: GenerateInput!) {\n generate(input: $input) {\n success\n text\n object\n error\n runId\n usage {\n inputTokens\n outputTokens\n }\n }\n }\n", ye = "\n subscription OnAgentRunEvent($runId: UUID!) {\n onAgentChatEvent(runId: $runId) {\n event\n }\n }\n", be = 5e3, J = async ({ variables: e, signal: t }) => {
376
+ let { generate: n } = await b({
377
+ query: ve,
378
+ variables: e,
379
+ caller: "ai.generate",
380
+ signal: t,
381
+ isActingAsCaller: !0
382
+ });
383
+ return n;
384
+ }, xe = (e) => i(e.type), Y = (e) => {
385
+ let t, n = !0;
386
+ return {
387
+ quiet: new Promise((r) => {
388
+ e.then(() => {
389
+ n && (t = setTimeout(() => r(void 0), be));
390
+ }, () => void 0);
391
+ }),
392
+ stop: () => {
393
+ n = !1, clearTimeout(t);
394
+ }
395
+ };
396
+ }, Se = async ({ variables: e, onChunk: t, signal: n }) => {
397
+ let r = crypto.randomUUID(), i = new AbortController(), a = c(n) ? AbortSignal.any([n, i.signal]) : i.signal, o = new Promise((e, t) => n?.addEventListener("abort", () => t(n.reason), {
398
+ once: !0,
399
+ signal: i.signal
400
+ }));
401
+ o.catch(() => void 0);
402
+ try {
403
+ let i = q({
404
+ query: ye,
405
+ variables: { runId: r },
406
+ caller: "ai.generate",
407
+ signal: a,
408
+ isActingAsCaller: !0
409
+ });
410
+ if ((await i.next()).done) throw n?.throwIfAborted(), Error("ai.generate() failed: the stream ended before the run");
411
+ let s = J({
412
+ variables: { input: {
413
+ ...e.input,
414
+ runId: r
415
+ } },
416
+ signal: a
417
+ }), [l] = await Promise.race([Promise.all([s, (async () => {
418
+ let e = Y(s);
419
+ try {
420
+ for (;;) {
421
+ let n = await Promise.race([i.next(), e.quiet]).catch(() => void 0);
422
+ if (!c(n) || n.done || a.aborted || U(n.value)) return;
423
+ n.value.type === "stream-chunk" && xe(n.value.chunk) && (e.stop(), await t(n.value.chunk), e = Y(s));
424
+ }
425
+ } finally {
426
+ e.stop(), i.return(void 0).catch(() => void 0);
427
+ }
428
+ })()]), o]);
429
+ return n?.throwIfAborted(), l;
430
+ } finally {
431
+ i.abort();
432
+ }
433
+ }, Ce = { generate: async ({ input: e, onChunk: t, signal: n, ...r }) => {
434
+ let i = { input: {
435
+ ...r,
436
+ input: B(e)
437
+ } };
438
+ return c(t) ? Se({
439
+ variables: i,
440
+ onChunk: t,
441
+ signal: n
442
+ }) : J({
443
+ variables: i,
444
+ signal: n
445
+ });
446
+ } }, we = async (e) => {
447
+ let { sendInboxMessage: t } = await new o().mutation({ sendInboxMessage: {
219
448
  __args: { input: e },
220
449
  threadId: !0
221
450
  } });
222
451
  return t;
223
- }, q = /\[/g, ne = /\]/g, J = /\r?\n/g, Y = (e) => e.replace(q, "(").replace(ne, ")").replace(J, " ").trim(), X = async ({ workspaceMemberId: t }) => {
224
- let { data: { workspaceMember: n } } = await new o().get(`/rest/workspaceMembers/${t}`), r = `${n.name.firstName ?? ""} ${n.name.lastName ?? ""}`.trim();
452
+ }, Te = /\[/g, Ee = /\]/g, De = /\r?\n/g, X = (e) => e.replace(Te, "(").replace(Ee, ")").replace(De, " ").trim(), Oe = async ({ workspaceMemberId: e }) => {
453
+ let { data: { workspaceMember: n } } = await new s().get(`/rest/workspaceMembers/${e}`), r = `${n.name.firstName ?? ""} ${n.name.lastName ?? ""}`.trim();
225
454
  return C({
226
455
  objectNameSingular: "workspaceMember",
227
- recordId: t,
228
- displayName: Y(e(r) ? r : n.userEmail)
456
+ recordId: e,
457
+ displayName: X(t(r) ? r : n.userEmail)
229
458
  });
230
459
  }, Z = ({ fullName: e, partName: t }) => {
231
- let i = n(e) ? Reflect.get(e, t) : void 0;
232
- return r(i) ? i : "";
233
- }, re = ({ record: e, recordId: t, labelIdentifierField: n }) => {
234
- if (!s(n)) return t;
460
+ let n = r(e) ? Reflect.get(e, t) : void 0;
461
+ return i(n) ? n : "";
462
+ }, ke = ({ record: e, recordId: t, labelIdentifierField: n }) => {
463
+ if (!c(n)) return t;
235
464
  let r = e[n.name];
236
465
  return n.type === "FULL_NAME" ? `${Z({
237
466
  fullName: r,
@@ -239,9 +468,9 @@ var u = "RetryableLogicFunctionError", d = class extends Error {
239
468
  })} ${Z({
240
469
  fullName: r,
241
470
  partName: "lastName"
242
- })}`.trim() : s(r) ? String(r) : "";
243
- }, ie = async ({ metadataClient: e, objectMetadata: t }) => {
244
- if (!s(t.labelIdentifierFieldMetadataId)) return;
471
+ })}`.trim() : c(r) ? String(r) : "";
472
+ }, Ae = async ({ metadataClient: e, objectMetadata: t }) => {
473
+ if (!c(t.labelIdentifierFieldMetadataId)) return;
245
474
  let { object: n } = await e.query({ object: {
246
475
  __args: { id: t.id },
247
476
  fields: {
@@ -256,11 +485,11 @@ var u = "RetryableLogicFunctionError", d = class extends Error {
256
485
  }
257
486
  } });
258
487
  return n.fields.edges[0]?.node;
259
- }, ae = 1e3, oe = async ({ metadataClient: e, objectNameSingular: t }) => {
488
+ }, je = 1e3, Me = async ({ metadataClient: e, objectNameSingular: t }) => {
260
489
  let { objects: n } = await e.query({ objects: {
261
490
  __args: {
262
491
  filter: {},
263
- paging: { first: ae }
492
+ paging: { first: je }
264
493
  },
265
494
  edges: { node: {
266
495
  id: !0,
@@ -269,43 +498,43 @@ var u = "RetryableLogicFunctionError", d = class extends Error {
269
498
  labelIdentifierFieldMetadataId: !0
270
499
  } }
271
500
  } }), r = n.edges.find(({ node: e }) => e.nameSingular === t)?.node;
272
- if (!s(r)) throw Error(`This workspace has no ${t} object.`);
501
+ if (!c(r)) throw Error(`This workspace has no ${t} object.`);
273
502
  return r;
274
- }, se = async ({ objectNameSingular: e, recordId: t }) => {
275
- let n = new a(), r = await oe({
503
+ }, Ne = async ({ objectNameSingular: e, recordId: t }) => {
504
+ let n = new o(), r = await Me({
276
505
  metadataClient: n,
277
506
  objectNameSingular: e
278
- }), [i, s] = await Promise.all([ie({
507
+ }), [i, a] = await Promise.all([Ae({
279
508
  metadataClient: n,
280
509
  objectMetadata: r
281
- }), new o().get(`/rest/${r.namePlural}/${t}`)]);
510
+ }), new s().get(`/rest/${r.namePlural}/${t}`)]);
282
511
  return C({
283
512
  objectNameSingular: e,
284
513
  recordId: t,
285
- displayName: Y(re({
286
- record: s.data[e],
514
+ displayName: X(ke({
515
+ record: a.data[e],
287
516
  recordId: t,
288
517
  labelIdentifierField: i
289
518
  }))
290
519
  });
291
- }, ce = C({
520
+ }, Pe = C({
292
521
  objectNameSingular: S,
293
522
  recordId: S,
294
523
  displayName: "Ada"
295
- }), le = async (e) => {
296
- await new a().mutation({ attachRecordToInboxThread: { __args: { input: e } } });
297
- }, ue = async (e) => {
298
- await new a().mutation({ detachRecordFromInboxThread: { __args: { input: e } } });
299
- }, de = async (e) => {
300
- let { enqueueJob: t } = await new a().mutation({ enqueueJob: {
524
+ }), Fe = async (e) => {
525
+ await new o().mutation({ attachRecordToInboxThread: { __args: { input: e } } });
526
+ }, Q = async (e) => {
527
+ await new o().mutation({ detachRecordFromInboxThread: { __args: { input: e } } });
528
+ }, Ie = async (e) => {
529
+ let { enqueueJob: t } = await new o().mutation({ enqueueJob: {
301
530
  __args: { input: e },
302
531
  enqueued: !0,
303
532
  logicFunctionUniversalIdentifier: !0,
304
533
  jobId: !0
305
534
  } });
306
535
  return t;
307
- }, fe = async (e) => {
308
- let { enqueueJobs: t } = await new a().mutation({ enqueueJobs: {
536
+ }, Le = async (e) => {
537
+ let { enqueueJobs: t } = await new o().mutation({ enqueueJobs: {
309
538
  __args: { input: e },
310
539
  enqueued: !0,
311
540
  logicFunctionUniversalIdentifier: !0,
@@ -313,8 +542,8 @@ var u = "RetryableLogicFunctionError", d = class extends Error {
313
542
  jobIds: !0
314
543
  } });
315
544
  return t;
316
- }, pe = async (e) => {
317
- let { getJobs: t } = await new a().query({ getJobs: {
545
+ }, Re = async (e) => {
546
+ let { getJobs: t } = await new o().query({ getJobs: {
318
547
  __args: { jobIds: e },
319
548
  jobId: !0,
320
549
  state: !0,
@@ -325,7 +554,7 @@ var u = "RetryableLogicFunctionError", d = class extends Error {
325
554
  finishedAt: !0
326
555
  } });
327
556
  return t;
328
- }, me = (e) => ({
557
+ }, ze = (e) => ({
329
558
  __args: {
330
559
  paging: { first: e.length },
331
560
  filter: { universalIdentifier: { in: e } }
@@ -335,31 +564,31 @@ var u = "RetryableLogicFunctionError", d = class extends Error {
335
564
  universalIdentifier: !0,
336
565
  nameSingular: !0
337
566
  } }
338
- }), Q = async ({ timelineActivityTypeUniversalIdentifier: e, targetObjectUniversalIdentifier: t, linkedObjectMetadataUniversalIdentifier: n, targetRecordId: r, ...i }) => {
339
- let c = [...new Set([t, n].filter(s))], { timelineActivityTypes: l, objects: u } = await new a().query({
567
+ }), Be = async ({ timelineActivityTypeUniversalIdentifier: e, targetObjectUniversalIdentifier: t, linkedObjectMetadataUniversalIdentifier: n, targetRecordId: r, ...i }) => {
568
+ let a = [...new Set([t, n].filter(c))], { timelineActivityTypes: l, objects: u } = await new o().query({
340
569
  timelineActivityTypes: {
341
570
  id: !0,
342
571
  universalIdentifier: !0,
343
572
  isActive: !0
344
573
  },
345
- objects: me(c)
574
+ objects: ze(a)
346
575
  }), d = l.find(({ universalIdentifier: t }) => t === e);
347
- if (!s(d)) throw Error(`Timeline activity type ${e} is not installed`);
576
+ if (!c(d)) throw Error(`Timeline activity type ${e} is not installed`);
348
577
  if (!d.isActive) throw Error(`Timeline activity type ${e} is inactive`);
349
578
  let f = new Map(u.edges.map(({ node: e }) => [e.universalIdentifier, e])), p = f.get(t);
350
- if (!s(p)) throw Error(`Timeline activity target object ${t} is not installed`);
351
- let m = `target${ee(p.nameSingular)}Id`, h = s(n) ? f.get(n) : void 0;
352
- if (s(n) && !s(h)) throw Error(`Timeline activity linked object ${n} is not installed`);
353
- return (await new o().post("/rest/timelineActivities", {
579
+ if (!c(p)) throw Error(`Timeline activity target object ${t} is not installed`);
580
+ let m = `target${ie(p.nameSingular)}Id`, h = c(n) ? f.get(n) : void 0;
581
+ if (c(n) && !c(h)) throw Error(`Timeline activity linked object ${n} is not installed`);
582
+ return (await new s().post("/rest/timelineActivities", {
354
583
  ...i,
355
584
  timelineActivityTypeId: d.id,
356
585
  linkedObjectMetadataId: h?.id,
357
586
  [m]: r
358
587
  })).data.createTimelineActivity;
359
- }, he = "\n query GetAppKeyValue($key: String!, $scope: AppKeyValueScope) {\n appKeyValue(key: $key, scope: $scope) {\n key\n value\n scope\n }\n }\n", ge = "\n mutation SetAppKeyValue($input: SetAppKeyValueInput!) {\n setAppKeyValue(input: $input) {\n key\n value\n scope\n }\n }\n", _e = "\n mutation DeleteAppKeyValue($key: String!, $scope: AppKeyValueScope) {\n deleteAppKeyValue(key: $key, scope: $scope)\n }\n", $ = "WORKSPACE", ve = {
588
+ }, Ve = "\n query GetAppKeyValue($key: String!, $scope: AppKeyValueScope) {\n appKeyValue(key: $key, scope: $scope) {\n key\n value\n scope\n }\n }\n", He = "\n mutation SetAppKeyValue($input: SetAppKeyValueInput!) {\n setAppKeyValue(input: $input) {\n key\n value\n scope\n }\n }\n", Ue = "\n mutation DeleteAppKeyValue($key: String!, $scope: AppKeyValueScope) {\n deleteAppKeyValue(key: $key, scope: $scope)\n }\n", $ = "WORKSPACE", We = {
360
589
  async get(e, t) {
361
- let { appKeyValue: n } = await y({
362
- query: he,
590
+ let { appKeyValue: n } = await b({
591
+ query: Ve,
363
592
  variables: {
364
593
  key: e,
365
594
  scope: t?.scope ?? $
@@ -369,8 +598,8 @@ var u = "RetryableLogicFunctionError", d = class extends Error {
369
598
  return n?.value ?? null;
370
599
  },
371
600
  async set(e, t, n) {
372
- await y({
373
- query: ge,
601
+ await b({
602
+ query: He,
374
603
  variables: { input: {
375
604
  key: e,
376
605
  value: t,
@@ -380,8 +609,8 @@ var u = "RetryableLogicFunctionError", d = class extends Error {
380
609
  });
381
610
  },
382
611
  async delete(e, t) {
383
- let { deleteAppKeyValue: n } = await y({
384
- query: _e,
612
+ let { deleteAppKeyValue: n } = await b({
613
+ query: Ue,
385
614
  variables: {
386
615
  key: e,
387
616
  scope: t?.scope ?? $
@@ -390,12 +619,12 @@ var u = "RetryableLogicFunctionError", d = class extends Error {
390
619
  });
391
620
  return n;
392
621
  }
393
- }, ye = class {
622
+ }, Ge = class {
394
623
  constructor(e, t) {
395
624
  this.__twentyHttpResponse = !0, this.body = e, this.status = t?.status, this.headers = t?.headers;
396
625
  }
397
626
  };
398
627
  //#endregion
399
- export { f as AppConnectionAuthFailedError, ce as INBOX_ASSISTANT_MENTION, ye as Response, d as RetryableLogicFunctionError, le as attachRecordToInboxThread, A as createMessageChannel, Q as createTimelineActivity, I as deleteMessageChannel, ue as detachRecordFromInboxThread, de as enqueueJob, fe as enqueueJobs, T as findConnectionForRequest, x as getConnection, pe as getJobs, X as inboxMention, se as inboxReferenceRecord, R as ingestMessages, l as jsonSchemaToInputSchema, ve as kv, w as listConnections, M as listMessageChannels, V as listMessageFolders, D as reportConnectionAuthFailure, G as runAgent, K as sendInboxMessage, U as syncMessageFolders, P as updateMessageChannel };
628
+ export { p as AppConnectionAuthFailedError, Pe as INBOX_ASSISTANT_MENTION, Ge as Response, f as RetryableLogicFunctionError, Ce as ai, Fe as attachRecordToInboxThread, E as createMessageChannel, Be as createTimelineActivity, M as deleteMessageChannel, Q as detachRecordFromInboxThread, Ie as enqueueJob, Le as enqueueJobs, se as findConnectionForRequest, re as getConnection, Re as getJobs, Oe as inboxMention, Ne as inboxReferenceRecord, P as ingestMessages, U as isAgentChatTurnEndEvent, u as jsonSchemaToInputSchema, We as kv, oe as listConnections, fe as listConversationMessages, O as listMessageChannels, L as listMessageFolders, le as reportConnectionAuthFailure, H as runAgent, we as sendInboxMessage, _e as streamConversation, z as syncMessageFolders, A as updateMessageChannel };
400
629
 
401
630
  //# sourceMappingURL=index.mjs.map