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.
- package/dist/billing/index.cjs.map +1 -1
- package/dist/billing/index.mjs.map +1 -1
- package/dist/define/index.cjs +11 -11
- package/dist/define/index.cjs.map +1 -1
- package/dist/define/index.d.ts +493 -339
- package/dist/define/index.mjs +3507 -3375
- package/dist/define/index.mjs.map +1 -1
- package/dist/front-component/index.cjs +1 -1
- package/dist/front-component/index.cjs.map +1 -1
- package/dist/front-component/index.d.ts +2 -0
- package/dist/front-component/index.mjs +3 -3
- package/dist/front-component/index.mjs.map +1 -1
- package/dist/logic-function/index.cjs +103 -23
- package/dist/logic-function/index.cjs.map +1 -1
- package/dist/logic-function/index.d.ts +179 -30
- package/dist/logic-function/index.mjs +363 -134
- 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 +3 -3
|
@@ -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", _ = {
|
|
53
53
|
USER: "user",
|
|
54
54
|
WORKSPACE: "workspace"
|
|
55
|
-
},
|
|
55
|
+
}, v = (e) => ({
|
|
56
56
|
...e,
|
|
57
|
-
visibility:
|
|
58
|
-
}),
|
|
59
|
-
let r = process.env[
|
|
60
|
-
if (!r || !i) throw Error(`${
|
|
61
|
-
|
|
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 ${
|
|
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
|
-
},
|
|
78
|
-
let { appConnection: t } = await
|
|
79
|
-
query:
|
|
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
|
|
84
|
-
return
|
|
85
|
-
}, S = "agentChatAssistant", C = ({ objectNameSingular: e, recordId: t, displayName: n }) => e === "agentChatAssistant" ? `@${n}` : `[[record:${e}:${t}:${n}]]`,
|
|
86
|
-
let { appConnections: n } = await
|
|
87
|
-
query:
|
|
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 ?? (
|
|
99
|
+
scope: t.scope ?? (c(e) ? m[e] : void 0)
|
|
91
100
|
} },
|
|
92
101
|
caller: "listConnections"
|
|
93
102
|
});
|
|
94
|
-
return n.map(
|
|
95
|
-
},
|
|
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
|
-
},
|
|
102
|
-
await
|
|
103
|
-
query:
|
|
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
|
-
},
|
|
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
|
-
${
|
|
122
|
+
${w}
|
|
114
123
|
}
|
|
115
124
|
}
|
|
116
|
-
`,
|
|
117
|
-
let { createAppMessageChannel: n } = await
|
|
118
|
-
query:
|
|
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
|
-
},
|
|
135
|
+
}, D = `
|
|
127
136
|
query ListAppMessageChannels($filter: ListAppMessageChannelsInput) {
|
|
128
137
|
appMessageChannels(filter: $filter) {
|
|
129
|
-
${
|
|
138
|
+
${w}
|
|
130
139
|
}
|
|
131
140
|
}
|
|
132
|
-
`,
|
|
133
|
-
let { appMessageChannels: t } = await
|
|
134
|
-
query:
|
|
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
|
-
},
|
|
148
|
+
}, k = `
|
|
140
149
|
mutation UpdateAppMessageChannel($input: UpdateAppMessageChannelInput!) {
|
|
141
150
|
updateAppMessageChannel(input: $input) {
|
|
142
|
-
${
|
|
151
|
+
${w}
|
|
143
152
|
}
|
|
144
153
|
}
|
|
145
|
-
`,
|
|
146
|
-
let { updateAppMessageChannel: n } = await
|
|
147
|
-
query:
|
|
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
|
-
},
|
|
164
|
+
}, j = `
|
|
156
165
|
mutation DeleteAppMessageChannel($id: UUID!) {
|
|
157
166
|
deleteAppMessageChannel(id: $id) {
|
|
158
|
-
${
|
|
167
|
+
${w}
|
|
159
168
|
}
|
|
160
169
|
}
|
|
161
|
-
`,
|
|
162
|
-
let { deleteAppMessageChannel: t } = await
|
|
163
|
-
query:
|
|
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
|
-
},
|
|
169
|
-
let { ingestAppMessages: n } = await
|
|
170
|
-
query:
|
|
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
|
-
},
|
|
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
|
-
${
|
|
190
|
+
${F}
|
|
182
191
|
}
|
|
183
192
|
}
|
|
184
|
-
`,
|
|
185
|
-
let { appMessageFolders: t } = await
|
|
186
|
-
query:
|
|
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
|
-
},
|
|
200
|
+
}, R = `
|
|
192
201
|
mutation SyncAppMessageFolders($input: SyncAppMessageFoldersInput!) {
|
|
193
202
|
syncAppMessageFolders(input: $input) {
|
|
194
|
-
${
|
|
203
|
+
${F}
|
|
195
204
|
}
|
|
196
205
|
}
|
|
197
|
-
`,
|
|
198
|
-
let { syncAppMessageFolders: t } = await
|
|
199
|
-
query:
|
|
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
|
-
},
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
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:
|
|
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
|
-
},
|
|
218
|
-
let
|
|
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
|
-
},
|
|
224
|
-
let { data: { workspaceMember: n } } = await new
|
|
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:
|
|
228
|
-
displayName:
|
|
456
|
+
recordId: e,
|
|
457
|
+
displayName: X(t(r) ? r : n.userEmail)
|
|
229
458
|
});
|
|
230
459
|
}, Z = ({ fullName: e, partName: t }) => {
|
|
231
|
-
let
|
|
232
|
-
return
|
|
233
|
-
},
|
|
234
|
-
if (!
|
|
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() :
|
|
243
|
-
},
|
|
244
|
-
if (!
|
|
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
|
-
},
|
|
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:
|
|
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 (!
|
|
501
|
+
if (!c(r)) throw Error(`This workspace has no ${t} object.`);
|
|
273
502
|
return r;
|
|
274
|
-
},
|
|
275
|
-
let n = new
|
|
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,
|
|
507
|
+
}), [i, a] = await Promise.all([Ae({
|
|
279
508
|
metadataClient: n,
|
|
280
509
|
objectMetadata: r
|
|
281
|
-
}), new
|
|
510
|
+
}), new s().get(`/rest/${r.namePlural}/${t}`)]);
|
|
282
511
|
return C({
|
|
283
512
|
objectNameSingular: e,
|
|
284
513
|
recordId: t,
|
|
285
|
-
displayName:
|
|
286
|
-
record:
|
|
514
|
+
displayName: X(ke({
|
|
515
|
+
record: a.data[e],
|
|
287
516
|
recordId: t,
|
|
288
517
|
labelIdentifierField: i
|
|
289
518
|
}))
|
|
290
519
|
});
|
|
291
|
-
},
|
|
520
|
+
}, Pe = C({
|
|
292
521
|
objectNameSingular: S,
|
|
293
522
|
recordId: S,
|
|
294
523
|
displayName: "Ada"
|
|
295
|
-
}),
|
|
296
|
-
await new
|
|
297
|
-
},
|
|
298
|
-
await new
|
|
299
|
-
},
|
|
300
|
-
let { enqueueJob: t } = await new
|
|
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
|
-
},
|
|
308
|
-
let { enqueueJobs: t } = await new
|
|
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
|
-
},
|
|
317
|
-
let { getJobs: t } = await new
|
|
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
|
-
},
|
|
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
|
-
}),
|
|
339
|
-
let
|
|
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:
|
|
574
|
+
objects: ze(a)
|
|
346
575
|
}), d = l.find(({ universalIdentifier: t }) => t === e);
|
|
347
|
-
if (!
|
|
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 (!
|
|
351
|
-
let m = `target${
|
|
352
|
-
if (
|
|
353
|
-
return (await new
|
|
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
|
-
},
|
|
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
|
|
362
|
-
query:
|
|
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
|
|
373
|
-
query:
|
|
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
|
|
384
|
-
query:
|
|
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
|
-
},
|
|
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 {
|
|
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
|