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