@inkeep/agents-core 0.59.4 → 0.61.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/auth/auth-validation-schemas.d.ts +154 -154
- package/dist/auth/init.js +42 -0
- package/dist/auth/wait-for-spicedb.d.ts +1 -0
- package/dist/auth/wait-for-spicedb.js +51 -0
- package/dist/client-exports.d.ts +4 -107
- package/dist/client-exports.js +3 -61
- package/dist/constants/context-breakdown.js +5 -0
- package/dist/constants/otel-attributes.d.ts +25 -1
- package/dist/constants/otel-attributes.js +25 -1
- package/dist/data-access/index.d.ts +4 -3
- package/dist/data-access/index.js +4 -3
- package/dist/data-access/manage/agentFull.js +15 -10
- package/dist/data-access/manage/agents.d.ts +69 -63
- package/dist/data-access/manage/agents.js +2 -0
- package/dist/data-access/manage/artifactComponents.d.ts +12 -12
- package/dist/data-access/manage/contextConfigs.d.ts +12 -12
- package/dist/data-access/manage/dataComponents.d.ts +6 -6
- package/dist/data-access/manage/functionTools.d.ts +18 -18
- package/dist/data-access/manage/functionTools.js +2 -2
- package/dist/data-access/manage/projectFull.js +24 -3
- package/dist/data-access/manage/skills.d.ts +14 -14
- package/dist/data-access/manage/skills.js +2 -3
- package/dist/data-access/manage/subAgentExternalAgentRelations.d.ts +27 -27
- package/dist/data-access/manage/subAgentExternalAgentRelations.js +2 -2
- package/dist/data-access/manage/subAgentRelations.d.ts +29 -29
- package/dist/data-access/manage/subAgentRelations.js +2 -2
- package/dist/data-access/manage/subAgentTeamAgentRelations.d.ts +30 -30
- package/dist/data-access/manage/subAgentTeamAgentRelations.js +2 -2
- package/dist/data-access/manage/subAgents.d.ts +36 -36
- package/dist/data-access/manage/tools.d.ts +21 -21
- package/dist/data-access/manage/tools.js +2 -2
- package/dist/data-access/manage/triggers.d.ts +2 -2
- package/dist/data-access/runtime/apiKeys.d.ts +16 -16
- package/dist/data-access/runtime/apps.d.ts +61 -13
- package/dist/data-access/runtime/apps.js +15 -1
- package/dist/data-access/runtime/conversations.d.ts +23 -23
- package/dist/data-access/runtime/conversations.js +18 -1
- package/dist/data-access/runtime/ledgerArtifacts.d.ts +11 -2
- package/dist/data-access/runtime/ledgerArtifacts.js +12 -1
- package/dist/data-access/runtime/messages.d.ts +18 -18
- package/dist/data-access/runtime/scheduledTriggerInvocations.d.ts +3 -3
- package/dist/data-access/runtime/tasks.d.ts +4 -4
- package/dist/data-access/runtime/workflowExecutions.d.ts +25 -0
- package/dist/data-access/runtime/workflowExecutions.js +32 -0
- package/dist/db/manage/manage-schema.d.ts +495 -475
- package/dist/db/manage/manage-schema.js +1 -0
- package/dist/db/runtime/runtime-schema.d.ts +568 -334
- package/dist/db/runtime/runtime-schema.js +19 -2
- package/dist/dolt/fk-map.d.ts +5 -0
- package/dist/dolt/fk-map.js +34 -0
- package/dist/dolt/index.d.ts +3 -2
- package/dist/dolt/index.js +3 -2
- package/dist/dolt/resolve-conflicts.d.ts +11 -1
- package/dist/dolt/resolve-conflicts.js +105 -47
- package/dist/index.d.ts +15 -10
- package/dist/index.js +13 -8
- package/dist/types/entities.d.ts +5 -2
- package/dist/types/index.d.ts +3 -3
- package/dist/types/utility.d.ts +11 -3
- package/dist/utils/apiKeys.js +1 -1
- package/dist/utils/conversations.d.ts +10 -1
- package/dist/utils/conversations.js +19 -1
- package/dist/utils/error.d.ts +51 -51
- package/dist/utils/index.d.ts +7 -2
- package/dist/utils/index.js +5 -2
- package/dist/utils/model-factory.js +35 -10
- package/dist/utils/token-estimator.d.ts +19 -0
- package/dist/utils/token-estimator.js +17 -0
- package/dist/utils/usage-cost-middleware.d.ts +13 -0
- package/dist/utils/usage-cost-middleware.js +60 -0
- package/dist/utils/usage-tracker.d.ts +2 -0
- package/dist/utils/usage-tracker.js +1 -0
- package/dist/utils/validate-public-key.d.ts +10 -0
- package/dist/utils/validate-public-key.js +89 -0
- package/dist/validation/agentFull.js +0 -1
- package/dist/validation/drizzle-schema-helpers.d.ts +3 -3
- package/dist/validation/index.d.ts +2 -2
- package/dist/validation/index.js +2 -2
- package/dist/validation/schemas.d.ts +3518 -2682
- package/dist/validation/schemas.js +104 -36
- package/drizzle/manage/0013_gorgeous_umar.sql +1 -0
- package/drizzle/manage/meta/0013_snapshot.json +3704 -0
- package/drizzle/manage/meta/_journal.json +7 -0
- package/drizzle/runtime/0025_faulty_kylun.sql +1 -0
- package/drizzle/runtime/0026_graceful_scorpion.sql +15 -0
- package/drizzle/runtime/meta/0026_snapshot.json +4389 -0
- package/drizzle/runtime/meta/_journal.json +14 -0
- package/package.json +1 -1
package/dist/utils/apiKeys.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getLogger } from "./logger.js";
|
|
2
2
|
import { generateId } from "./conversations.js";
|
|
3
|
-
import { customAlphabet } from "nanoid";
|
|
4
3
|
import { randomBytes, scrypt, timingSafeEqual } from "node:crypto";
|
|
4
|
+
import { customAlphabet } from "nanoid";
|
|
5
5
|
import { promisify } from "node:util";
|
|
6
6
|
|
|
7
7
|
//#region src/utils/apiKeys.ts
|
|
@@ -1,5 +1,13 @@
|
|
|
1
|
+
import { BaseExecutionContext, ConversationMetadata } from "../types/utility.js";
|
|
2
|
+
|
|
1
3
|
//#region src/utils/conversations.d.ts
|
|
2
4
|
declare const generateId: (size?: number) => string;
|
|
5
|
+
/**
|
|
6
|
+
* Derive a deterministic 32-character hex ID from natural key parts.
|
|
7
|
+
* Used for junction/relation table IDs so the same logical relation
|
|
8
|
+
* always produces the same ID regardless of which branch creates it.
|
|
9
|
+
*/
|
|
10
|
+
declare function deriveRelationId(...parts: string[]): string;
|
|
3
11
|
/**
|
|
4
12
|
* Generates a standardized conversation ID.
|
|
5
13
|
*
|
|
@@ -15,5 +23,6 @@ declare const generateId: (size?: number) => string;
|
|
|
15
23
|
* ```
|
|
16
24
|
*/
|
|
17
25
|
declare function getConversationId(): string;
|
|
26
|
+
declare function buildConversationMetadata(executionContext: BaseExecutionContext, userProperties?: Record<string, unknown>): ConversationMetadata | undefined;
|
|
18
27
|
//#endregion
|
|
19
|
-
export { generateId, getConversationId };
|
|
28
|
+
export { buildConversationMetadata, deriveRelationId, generateId, getConversationId };
|
|
@@ -1,8 +1,17 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
1
2
|
import { customAlphabet } from "nanoid";
|
|
2
3
|
|
|
3
4
|
//#region src/utils/conversations.ts
|
|
4
5
|
const generateId = customAlphabet("abcdefghijklmnopqrstuvwxyz0123456789", 21);
|
|
5
6
|
/**
|
|
7
|
+
* Derive a deterministic 32-character hex ID from natural key parts.
|
|
8
|
+
* Used for junction/relation table IDs so the same logical relation
|
|
9
|
+
* always produces the same ID regardless of which branch creates it.
|
|
10
|
+
*/
|
|
11
|
+
function deriveRelationId(...parts) {
|
|
12
|
+
return createHash("sha256").update(parts.join("\0")).digest("hex").slice(0, 32);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
6
15
|
* Generates a standardized conversation ID.
|
|
7
16
|
*
|
|
8
17
|
* The generated ID follows these rules:
|
|
@@ -19,6 +28,15 @@ const generateId = customAlphabet("abcdefghijklmnopqrstuvwxyz0123456789", 21);
|
|
|
19
28
|
function getConversationId() {
|
|
20
29
|
return generateId();
|
|
21
30
|
}
|
|
31
|
+
function buildConversationMetadata(executionContext, userProperties) {
|
|
32
|
+
const meta = executionContext.metadata;
|
|
33
|
+
const isAuthenticated = meta?.authMethod === "app_credential_web_client_authenticated";
|
|
34
|
+
const result = {};
|
|
35
|
+
if (userProperties) result.userContext = userProperties;
|
|
36
|
+
if (meta?.verifiedClaims) result.verifiedClaims = meta.verifiedClaims;
|
|
37
|
+
if (isAuthenticated && meta?.endUserId) result.externalUserId = meta.endUserId;
|
|
38
|
+
return Object.keys(result).length > 0 ? result : void 0;
|
|
39
|
+
}
|
|
22
40
|
|
|
23
41
|
//#endregion
|
|
24
|
-
export { generateId, getConversationId };
|
|
42
|
+
export { buildConversationMetadata, deriveRelationId, generateId, getConversationId };
|
package/dist/utils/error.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { HTTPException } from "hono/http-exception";
|
|
|
3
3
|
|
|
4
4
|
//#region src/utils/error.d.ts
|
|
5
5
|
declare const ErrorCode: z.ZodEnum<{
|
|
6
|
-
unauthorized: "unauthorized";
|
|
7
6
|
bad_request: "bad_request";
|
|
7
|
+
unauthorized: "unauthorized";
|
|
8
8
|
forbidden: "forbidden";
|
|
9
9
|
not_found: "not_found";
|
|
10
10
|
conflict: "conflict";
|
|
@@ -20,8 +20,8 @@ declare const problemDetailsSchema: z.ZodObject<{
|
|
|
20
20
|
instance: z.ZodOptional<z.ZodString>;
|
|
21
21
|
requestId: z.ZodOptional<z.ZodString>;
|
|
22
22
|
code: z.ZodEnum<{
|
|
23
|
-
unauthorized: "unauthorized";
|
|
24
23
|
bad_request: "bad_request";
|
|
24
|
+
unauthorized: "unauthorized";
|
|
25
25
|
forbidden: "forbidden";
|
|
26
26
|
not_found: "not_found";
|
|
27
27
|
conflict: "conflict";
|
|
@@ -35,8 +35,8 @@ type ErrorCodes = z.infer<typeof ErrorCode>;
|
|
|
35
35
|
declare const errorResponseSchema: z.ZodObject<{
|
|
36
36
|
error: z.ZodObject<{
|
|
37
37
|
code: z.ZodEnum<{
|
|
38
|
-
unauthorized: "unauthorized";
|
|
39
38
|
bad_request: "bad_request";
|
|
39
|
+
unauthorized: "unauthorized";
|
|
40
40
|
forbidden: "forbidden";
|
|
41
41
|
not_found: "not_found";
|
|
42
42
|
conflict: "conflict";
|
|
@@ -74,12 +74,12 @@ declare const errorSchemaFactory: (code: ErrorCodes, description: string) => {
|
|
|
74
74
|
schema: z.ZodObject<{
|
|
75
75
|
instance: z.ZodOptional<z.ZodString>;
|
|
76
76
|
requestId: z.ZodOptional<z.ZodString>;
|
|
77
|
-
code: z.ZodLiteral<"
|
|
77
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
78
78
|
detail: z.ZodString;
|
|
79
79
|
title: z.ZodString;
|
|
80
80
|
status: z.ZodNumber;
|
|
81
81
|
error: z.ZodObject<{
|
|
82
|
-
code: z.ZodLiteral<"
|
|
82
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
83
83
|
message: z.ZodString;
|
|
84
84
|
}, z.core.$strip>;
|
|
85
85
|
}, z.core.$strip>;
|
|
@@ -96,12 +96,12 @@ declare const commonCreateErrorResponses: {
|
|
|
96
96
|
schema: z.ZodObject<{
|
|
97
97
|
instance: z.ZodOptional<z.ZodString>;
|
|
98
98
|
requestId: z.ZodOptional<z.ZodString>;
|
|
99
|
-
code: z.ZodLiteral<"
|
|
99
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
100
100
|
detail: z.ZodString;
|
|
101
101
|
title: z.ZodString;
|
|
102
102
|
status: z.ZodNumber;
|
|
103
103
|
error: z.ZodObject<{
|
|
104
|
-
code: z.ZodLiteral<"
|
|
104
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
105
105
|
message: z.ZodString;
|
|
106
106
|
}, z.core.$strip>;
|
|
107
107
|
}, z.core.$strip>;
|
|
@@ -115,12 +115,12 @@ declare const commonCreateErrorResponses: {
|
|
|
115
115
|
schema: z.ZodObject<{
|
|
116
116
|
instance: z.ZodOptional<z.ZodString>;
|
|
117
117
|
requestId: z.ZodOptional<z.ZodString>;
|
|
118
|
-
code: z.ZodLiteral<"
|
|
118
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
119
119
|
detail: z.ZodString;
|
|
120
120
|
title: z.ZodString;
|
|
121
121
|
status: z.ZodNumber;
|
|
122
122
|
error: z.ZodObject<{
|
|
123
|
-
code: z.ZodLiteral<"
|
|
123
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
124
124
|
message: z.ZodString;
|
|
125
125
|
}, z.core.$strip>;
|
|
126
126
|
}, z.core.$strip>;
|
|
@@ -134,12 +134,12 @@ declare const commonCreateErrorResponses: {
|
|
|
134
134
|
schema: z.ZodObject<{
|
|
135
135
|
instance: z.ZodOptional<z.ZodString>;
|
|
136
136
|
requestId: z.ZodOptional<z.ZodString>;
|
|
137
|
-
code: z.ZodLiteral<"
|
|
137
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
138
138
|
detail: z.ZodString;
|
|
139
139
|
title: z.ZodString;
|
|
140
140
|
status: z.ZodNumber;
|
|
141
141
|
error: z.ZodObject<{
|
|
142
|
-
code: z.ZodLiteral<"
|
|
142
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
143
143
|
message: z.ZodString;
|
|
144
144
|
}, z.core.$strip>;
|
|
145
145
|
}, z.core.$strip>;
|
|
@@ -153,12 +153,12 @@ declare const commonCreateErrorResponses: {
|
|
|
153
153
|
schema: z.ZodObject<{
|
|
154
154
|
instance: z.ZodOptional<z.ZodString>;
|
|
155
155
|
requestId: z.ZodOptional<z.ZodString>;
|
|
156
|
-
code: z.ZodLiteral<"
|
|
156
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
157
157
|
detail: z.ZodString;
|
|
158
158
|
title: z.ZodString;
|
|
159
159
|
status: z.ZodNumber;
|
|
160
160
|
error: z.ZodObject<{
|
|
161
|
-
code: z.ZodLiteral<"
|
|
161
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
162
162
|
message: z.ZodString;
|
|
163
163
|
}, z.core.$strip>;
|
|
164
164
|
}, z.core.$strip>;
|
|
@@ -172,12 +172,12 @@ declare const commonCreateErrorResponses: {
|
|
|
172
172
|
schema: z.ZodObject<{
|
|
173
173
|
instance: z.ZodOptional<z.ZodString>;
|
|
174
174
|
requestId: z.ZodOptional<z.ZodString>;
|
|
175
|
-
code: z.ZodLiteral<"
|
|
175
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
176
176
|
detail: z.ZodString;
|
|
177
177
|
title: z.ZodString;
|
|
178
178
|
status: z.ZodNumber;
|
|
179
179
|
error: z.ZodObject<{
|
|
180
|
-
code: z.ZodLiteral<"
|
|
180
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
181
181
|
message: z.ZodString;
|
|
182
182
|
}, z.core.$strip>;
|
|
183
183
|
}, z.core.$strip>;
|
|
@@ -193,12 +193,12 @@ declare const commonUpdateErrorResponses: {
|
|
|
193
193
|
schema: z.ZodObject<{
|
|
194
194
|
instance: z.ZodOptional<z.ZodString>;
|
|
195
195
|
requestId: z.ZodOptional<z.ZodString>;
|
|
196
|
-
code: z.ZodLiteral<"
|
|
196
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
197
197
|
detail: z.ZodString;
|
|
198
198
|
title: z.ZodString;
|
|
199
199
|
status: z.ZodNumber;
|
|
200
200
|
error: z.ZodObject<{
|
|
201
|
-
code: z.ZodLiteral<"
|
|
201
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
202
202
|
message: z.ZodString;
|
|
203
203
|
}, z.core.$strip>;
|
|
204
204
|
}, z.core.$strip>;
|
|
@@ -212,12 +212,12 @@ declare const commonUpdateErrorResponses: {
|
|
|
212
212
|
schema: z.ZodObject<{
|
|
213
213
|
instance: z.ZodOptional<z.ZodString>;
|
|
214
214
|
requestId: z.ZodOptional<z.ZodString>;
|
|
215
|
-
code: z.ZodLiteral<"
|
|
215
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
216
216
|
detail: z.ZodString;
|
|
217
217
|
title: z.ZodString;
|
|
218
218
|
status: z.ZodNumber;
|
|
219
219
|
error: z.ZodObject<{
|
|
220
|
-
code: z.ZodLiteral<"
|
|
220
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
221
221
|
message: z.ZodString;
|
|
222
222
|
}, z.core.$strip>;
|
|
223
223
|
}, z.core.$strip>;
|
|
@@ -231,12 +231,12 @@ declare const commonUpdateErrorResponses: {
|
|
|
231
231
|
schema: z.ZodObject<{
|
|
232
232
|
instance: z.ZodOptional<z.ZodString>;
|
|
233
233
|
requestId: z.ZodOptional<z.ZodString>;
|
|
234
|
-
code: z.ZodLiteral<"
|
|
234
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
235
235
|
detail: z.ZodString;
|
|
236
236
|
title: z.ZodString;
|
|
237
237
|
status: z.ZodNumber;
|
|
238
238
|
error: z.ZodObject<{
|
|
239
|
-
code: z.ZodLiteral<"
|
|
239
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
240
240
|
message: z.ZodString;
|
|
241
241
|
}, z.core.$strip>;
|
|
242
242
|
}, z.core.$strip>;
|
|
@@ -250,12 +250,12 @@ declare const commonUpdateErrorResponses: {
|
|
|
250
250
|
schema: z.ZodObject<{
|
|
251
251
|
instance: z.ZodOptional<z.ZodString>;
|
|
252
252
|
requestId: z.ZodOptional<z.ZodString>;
|
|
253
|
-
code: z.ZodLiteral<"
|
|
253
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
254
254
|
detail: z.ZodString;
|
|
255
255
|
title: z.ZodString;
|
|
256
256
|
status: z.ZodNumber;
|
|
257
257
|
error: z.ZodObject<{
|
|
258
|
-
code: z.ZodLiteral<"
|
|
258
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
259
259
|
message: z.ZodString;
|
|
260
260
|
}, z.core.$strip>;
|
|
261
261
|
}, z.core.$strip>;
|
|
@@ -269,12 +269,12 @@ declare const commonUpdateErrorResponses: {
|
|
|
269
269
|
schema: z.ZodObject<{
|
|
270
270
|
instance: z.ZodOptional<z.ZodString>;
|
|
271
271
|
requestId: z.ZodOptional<z.ZodString>;
|
|
272
|
-
code: z.ZodLiteral<"
|
|
272
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
273
273
|
detail: z.ZodString;
|
|
274
274
|
title: z.ZodString;
|
|
275
275
|
status: z.ZodNumber;
|
|
276
276
|
error: z.ZodObject<{
|
|
277
|
-
code: z.ZodLiteral<"
|
|
277
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
278
278
|
message: z.ZodString;
|
|
279
279
|
}, z.core.$strip>;
|
|
280
280
|
}, z.core.$strip>;
|
|
@@ -288,12 +288,12 @@ declare const commonUpdateErrorResponses: {
|
|
|
288
288
|
schema: z.ZodObject<{
|
|
289
289
|
instance: z.ZodOptional<z.ZodString>;
|
|
290
290
|
requestId: z.ZodOptional<z.ZodString>;
|
|
291
|
-
code: z.ZodLiteral<"
|
|
291
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
292
292
|
detail: z.ZodString;
|
|
293
293
|
title: z.ZodString;
|
|
294
294
|
status: z.ZodNumber;
|
|
295
295
|
error: z.ZodObject<{
|
|
296
|
-
code: z.ZodLiteral<"
|
|
296
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
297
297
|
message: z.ZodString;
|
|
298
298
|
}, z.core.$strip>;
|
|
299
299
|
}, z.core.$strip>;
|
|
@@ -309,12 +309,12 @@ declare const commonGetErrorResponses: {
|
|
|
309
309
|
schema: z.ZodObject<{
|
|
310
310
|
instance: z.ZodOptional<z.ZodString>;
|
|
311
311
|
requestId: z.ZodOptional<z.ZodString>;
|
|
312
|
-
code: z.ZodLiteral<"
|
|
312
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
313
313
|
detail: z.ZodString;
|
|
314
314
|
title: z.ZodString;
|
|
315
315
|
status: z.ZodNumber;
|
|
316
316
|
error: z.ZodObject<{
|
|
317
|
-
code: z.ZodLiteral<"
|
|
317
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
318
318
|
message: z.ZodString;
|
|
319
319
|
}, z.core.$strip>;
|
|
320
320
|
}, z.core.$strip>;
|
|
@@ -328,12 +328,12 @@ declare const commonGetErrorResponses: {
|
|
|
328
328
|
schema: z.ZodObject<{
|
|
329
329
|
instance: z.ZodOptional<z.ZodString>;
|
|
330
330
|
requestId: z.ZodOptional<z.ZodString>;
|
|
331
|
-
code: z.ZodLiteral<"
|
|
331
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
332
332
|
detail: z.ZodString;
|
|
333
333
|
title: z.ZodString;
|
|
334
334
|
status: z.ZodNumber;
|
|
335
335
|
error: z.ZodObject<{
|
|
336
|
-
code: z.ZodLiteral<"
|
|
336
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
337
337
|
message: z.ZodString;
|
|
338
338
|
}, z.core.$strip>;
|
|
339
339
|
}, z.core.$strip>;
|
|
@@ -347,12 +347,12 @@ declare const commonGetErrorResponses: {
|
|
|
347
347
|
schema: z.ZodObject<{
|
|
348
348
|
instance: z.ZodOptional<z.ZodString>;
|
|
349
349
|
requestId: z.ZodOptional<z.ZodString>;
|
|
350
|
-
code: z.ZodLiteral<"
|
|
350
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
351
351
|
detail: z.ZodString;
|
|
352
352
|
title: z.ZodString;
|
|
353
353
|
status: z.ZodNumber;
|
|
354
354
|
error: z.ZodObject<{
|
|
355
|
-
code: z.ZodLiteral<"
|
|
355
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
356
356
|
message: z.ZodString;
|
|
357
357
|
}, z.core.$strip>;
|
|
358
358
|
}, z.core.$strip>;
|
|
@@ -366,12 +366,12 @@ declare const commonGetErrorResponses: {
|
|
|
366
366
|
schema: z.ZodObject<{
|
|
367
367
|
instance: z.ZodOptional<z.ZodString>;
|
|
368
368
|
requestId: z.ZodOptional<z.ZodString>;
|
|
369
|
-
code: z.ZodLiteral<"
|
|
369
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
370
370
|
detail: z.ZodString;
|
|
371
371
|
title: z.ZodString;
|
|
372
372
|
status: z.ZodNumber;
|
|
373
373
|
error: z.ZodObject<{
|
|
374
|
-
code: z.ZodLiteral<"
|
|
374
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
375
375
|
message: z.ZodString;
|
|
376
376
|
}, z.core.$strip>;
|
|
377
377
|
}, z.core.$strip>;
|
|
@@ -385,12 +385,12 @@ declare const commonGetErrorResponses: {
|
|
|
385
385
|
schema: z.ZodObject<{
|
|
386
386
|
instance: z.ZodOptional<z.ZodString>;
|
|
387
387
|
requestId: z.ZodOptional<z.ZodString>;
|
|
388
|
-
code: z.ZodLiteral<"
|
|
388
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
389
389
|
detail: z.ZodString;
|
|
390
390
|
title: z.ZodString;
|
|
391
391
|
status: z.ZodNumber;
|
|
392
392
|
error: z.ZodObject<{
|
|
393
|
-
code: z.ZodLiteral<"
|
|
393
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
394
394
|
message: z.ZodString;
|
|
395
395
|
}, z.core.$strip>;
|
|
396
396
|
}, z.core.$strip>;
|
|
@@ -404,12 +404,12 @@ declare const commonGetErrorResponses: {
|
|
|
404
404
|
schema: z.ZodObject<{
|
|
405
405
|
instance: z.ZodOptional<z.ZodString>;
|
|
406
406
|
requestId: z.ZodOptional<z.ZodString>;
|
|
407
|
-
code: z.ZodLiteral<"
|
|
407
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
408
408
|
detail: z.ZodString;
|
|
409
409
|
title: z.ZodString;
|
|
410
410
|
status: z.ZodNumber;
|
|
411
411
|
error: z.ZodObject<{
|
|
412
|
-
code: z.ZodLiteral<"
|
|
412
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
413
413
|
message: z.ZodString;
|
|
414
414
|
}, z.core.$strip>;
|
|
415
415
|
}, z.core.$strip>;
|
|
@@ -425,12 +425,12 @@ declare const commonDeleteErrorResponses: {
|
|
|
425
425
|
schema: z.ZodObject<{
|
|
426
426
|
instance: z.ZodOptional<z.ZodString>;
|
|
427
427
|
requestId: z.ZodOptional<z.ZodString>;
|
|
428
|
-
code: z.ZodLiteral<"
|
|
428
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
429
429
|
detail: z.ZodString;
|
|
430
430
|
title: z.ZodString;
|
|
431
431
|
status: z.ZodNumber;
|
|
432
432
|
error: z.ZodObject<{
|
|
433
|
-
code: z.ZodLiteral<"
|
|
433
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
434
434
|
message: z.ZodString;
|
|
435
435
|
}, z.core.$strip>;
|
|
436
436
|
}, z.core.$strip>;
|
|
@@ -444,12 +444,12 @@ declare const commonDeleteErrorResponses: {
|
|
|
444
444
|
schema: z.ZodObject<{
|
|
445
445
|
instance: z.ZodOptional<z.ZodString>;
|
|
446
446
|
requestId: z.ZodOptional<z.ZodString>;
|
|
447
|
-
code: z.ZodLiteral<"
|
|
447
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
448
448
|
detail: z.ZodString;
|
|
449
449
|
title: z.ZodString;
|
|
450
450
|
status: z.ZodNumber;
|
|
451
451
|
error: z.ZodObject<{
|
|
452
|
-
code: z.ZodLiteral<"
|
|
452
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
453
453
|
message: z.ZodString;
|
|
454
454
|
}, z.core.$strip>;
|
|
455
455
|
}, z.core.$strip>;
|
|
@@ -463,12 +463,12 @@ declare const commonDeleteErrorResponses: {
|
|
|
463
463
|
schema: z.ZodObject<{
|
|
464
464
|
instance: z.ZodOptional<z.ZodString>;
|
|
465
465
|
requestId: z.ZodOptional<z.ZodString>;
|
|
466
|
-
code: z.ZodLiteral<"
|
|
466
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
467
467
|
detail: z.ZodString;
|
|
468
468
|
title: z.ZodString;
|
|
469
469
|
status: z.ZodNumber;
|
|
470
470
|
error: z.ZodObject<{
|
|
471
|
-
code: z.ZodLiteral<"
|
|
471
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
472
472
|
message: z.ZodString;
|
|
473
473
|
}, z.core.$strip>;
|
|
474
474
|
}, z.core.$strip>;
|
|
@@ -482,12 +482,12 @@ declare const commonDeleteErrorResponses: {
|
|
|
482
482
|
schema: z.ZodObject<{
|
|
483
483
|
instance: z.ZodOptional<z.ZodString>;
|
|
484
484
|
requestId: z.ZodOptional<z.ZodString>;
|
|
485
|
-
code: z.ZodLiteral<"
|
|
485
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
486
486
|
detail: z.ZodString;
|
|
487
487
|
title: z.ZodString;
|
|
488
488
|
status: z.ZodNumber;
|
|
489
489
|
error: z.ZodObject<{
|
|
490
|
-
code: z.ZodLiteral<"
|
|
490
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
491
491
|
message: z.ZodString;
|
|
492
492
|
}, z.core.$strip>;
|
|
493
493
|
}, z.core.$strip>;
|
|
@@ -501,12 +501,12 @@ declare const commonDeleteErrorResponses: {
|
|
|
501
501
|
schema: z.ZodObject<{
|
|
502
502
|
instance: z.ZodOptional<z.ZodString>;
|
|
503
503
|
requestId: z.ZodOptional<z.ZodString>;
|
|
504
|
-
code: z.ZodLiteral<"
|
|
504
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
505
505
|
detail: z.ZodString;
|
|
506
506
|
title: z.ZodString;
|
|
507
507
|
status: z.ZodNumber;
|
|
508
508
|
error: z.ZodObject<{
|
|
509
|
-
code: z.ZodLiteral<"
|
|
509
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
510
510
|
message: z.ZodString;
|
|
511
511
|
}, z.core.$strip>;
|
|
512
512
|
}, z.core.$strip>;
|
|
@@ -520,12 +520,12 @@ declare const commonDeleteErrorResponses: {
|
|
|
520
520
|
schema: z.ZodObject<{
|
|
521
521
|
instance: z.ZodOptional<z.ZodString>;
|
|
522
522
|
requestId: z.ZodOptional<z.ZodString>;
|
|
523
|
-
code: z.ZodLiteral<"
|
|
523
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
524
524
|
detail: z.ZodString;
|
|
525
525
|
title: z.ZodString;
|
|
526
526
|
status: z.ZodNumber;
|
|
527
527
|
error: z.ZodObject<{
|
|
528
|
-
code: z.ZodLiteral<"
|
|
528
|
+
code: z.ZodLiteral<"bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "too_many_requests" | "internal_server_error" | "unprocessable_entity">;
|
|
529
529
|
message: z.ZodString;
|
|
530
530
|
}, z.core.$strip>;
|
|
531
531
|
}, z.core.$strip>;
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -2,9 +2,10 @@ import { JwtVerifyResult, SignJwtOptions, VerifyJwtOptions, decodeJwtPayload, ex
|
|
|
2
2
|
import { GenerateInternalServiceTokenParams, InternalServiceId, InternalServiceTokenPayload, InternalServices, VerifyInternalServiceTokenResult, generateInternalServiceToken, isInternalServiceToken, validateInternalServiceProjectAccess, validateInternalServiceTenantAccess, verifyInternalServiceAuthHeader, verifyInternalServiceToken } from "./internal-service-auth.js";
|
|
3
3
|
import { LoggerFactoryConfig, PinoLogger, PinoLoggerConfig, getLogger, loggerFactory } from "./logger.js";
|
|
4
4
|
import { McpClient, McpClientOptions, McpSSEConfig, McpServerConfig, McpStreamableHttpConfig, activeMcpClients } from "./mcp-client.js";
|
|
5
|
+
import { GenerationType } from "../db/runtime/runtime-schema.js";
|
|
5
6
|
import { ApiKeyGenerationResult, AppCredentialResult, extractPublicId, generateApiKey, generateAppCredential, getMetadataFromApiKey, hashApiKey, isApiKeyExpired, maskApiKey, sanitizeAppConfig, validateApiKey } from "./apiKeys.js";
|
|
6
7
|
import { McpOAuthFlowResult, McpTokenExchangeResult, OAuthConfig, detectAuthenticationRequired, exchangeMcpAuthorizationCode, initiateMcpOAuthFlow } from "./auth-detection.js";
|
|
7
|
-
import { generateId, getConversationId } from "./conversations.js";
|
|
8
|
+
import { buildConversationMetadata, deriveRelationId, generateId, getConversationId } from "./conversations.js";
|
|
8
9
|
import { getCredentialStoreLookupKeyFromRetrievalParams } from "./credential-store-utils.js";
|
|
9
10
|
import { normalizeDateString, toISODateString } from "./date.js";
|
|
10
11
|
import { validateOrigin } from "./domain-validation.js";
|
|
@@ -28,8 +29,12 @@ import { interpolateTemplate } from "./template-interpolation.js";
|
|
|
28
29
|
import { ComposioAuthResult, CredentialScope, configureComposioMCPServer, deleteComposioConnectedAccount, extractComposioServerId, fetchComposioServers, fetchSingleComposioServer, getComposioInstance, getComposioOAuthRedirectUrl, getComposioUserId, isComposioMCPServerAuthenticated } from "./third-party-mcp-servers/composio-client.js";
|
|
29
30
|
import { isThirdPartyMCPServerAuthenticated } from "./third-party-mcp-servers/third-party-check.js";
|
|
30
31
|
import "./third-party-mcp-servers/index.js";
|
|
32
|
+
import { AssembleResult, estimateTokens } from "./token-estimator.js";
|
|
31
33
|
import { flushTraces, getTracer, setSpanWithError, unwrapError } from "./tracer-factory.js";
|
|
32
34
|
import { HashedHeaderValue, SignatureVerificationErrorCode, SignatureVerificationResult, TriggerAuthResult, hashAuthenticationHeaders, hashTriggerHeaderValue, validateTriggerHeaderValue, verifySignatureWithConfig, verifyTriggerAuth } from "./trigger-auth.js";
|
|
35
|
+
import { extractUsageTokens, gatewayCostMiddleware } from "./usage-cost-middleware.js";
|
|
36
|
+
import "./usage-tracker.js";
|
|
37
|
+
import { ValidatePublicKeyResult, validatePublicKey } from "./validate-public-key.js";
|
|
33
38
|
import { _resetWaitUntilCache, getWaitUntil } from "./wait-until.js";
|
|
34
39
|
import { TRUSTED_WORK_APP_MCP_PATHS, isTrustedWorkAppMcpUrl } from "./work-app-mcp.js";
|
|
35
|
-
export { ApiKeyGenerationResult, AppCredentialResult, CommonCreateErrorResponses, CommonDeleteErrorResponses, CommonGetErrorResponses, CommonUpdateErrorResponses, ComposioAuthResult, CredentialScope, ERROR_DOCS_BASE_URL, ErrorCode, ErrorCodes, ErrorResponse, GenerateInternalServiceTokenParams, GenerateServiceTokenParams, HashedHeaderValue, InternalServiceId, InternalServiceTokenPayload, InternalServices, JsonTransformer, JwtVerifyResult, LLMMessage, LoggerFactoryConfig, McpClient, McpClientOptions, McpOAuthFlowResult, McpSSEConfig, McpServerConfig, McpStreamableHttpConfig, McpTokenExchangeResult, MockLanguageModel, ModelFactory, OAuthConfig, ParsedSSEResponse, PinoLogger, PinoLoggerConfig, PoWError, PoWResult, ProblemDetails, ServiceTokenPayload, SignJwtOptions, SignSlackLinkTokenParams, SignSlackUserTokenParams, SignatureVerificationErrorCode, SignatureVerificationResult, SignedTempToken, SlackAccessTokenPayload, SlackAccessTokenPayloadSchema, SlackLinkIntent, SlackLinkIntentSchema, SlackLinkTokenPayload, SlackLinkTokenPayloadSchema, TRUSTED_WORK_APP_MCP_PATHS, TempTokenPayload, TriggerAuthResult, VerifyInternalServiceTokenResult, VerifyJwtOptions, VerifyServiceTokenResult, VerifySlackLinkTokenResult, VerifySlackUserTokenResult, _resetWaitUntilCache, activeMcpClients, commonCreateErrorResponses, commonDeleteErrorResponses, commonGetErrorResponses, commonUpdateErrorResponses, configureComposioMCPServer, convertZodToJsonSchema, convertZodToJsonSchemaWithPreview, createApiError, createMockModel, decodeJwtPayload, deleteComposioConnectedAccount, detectAuthenticationRequired, errorResponseSchema, errorSchemaFactory, exchangeMcpAuthorizationCode, extractBearerToken, extractComposioServerId, extractPreviewFields, extractPublicId, fetchComposioServers, fetchSingleComposioServer, flushTraces, formatMessagesForLLM, formatMessagesForLLMContext, generateApiKey, generateAppCredential, generateId, generateInternalServiceToken, generateServiceToken, getComposioInstance, getComposioOAuthRedirectUrl, getComposioUserId, getConversationId, getCredentialStoreLookupKeyFromRetrievalParams, getInProcessFetch, getJwtSecret, getLogger, getMetadataFromApiKey, getPoWErrorMessage, getTracer, getWaitUntil, handleApiError, hasIssuer, hashApiKey, hashAuthenticationHeaders, hashTriggerHeaderValue, initiateMcpOAuthFlow, interpolateTemplate, isApiKeyExpired, isComposioMCPServerAuthenticated, isDevelopment, isInternalServiceToken, isPoWEnabled, isProduction, isSlackUserToken, isTest, isThirdPartyMCPServerAuthenticated, isTrustedWorkAppMcpUrl, isUniqueConstraintError, isZodSchema, loggerFactory, makeAllPropertiesRequired, maskApiKey, normalizeDataComponentSchema, normalizeDateString, parseEmbeddedJson, parseSSEResponse, preview, problemDetailsSchema, registerAppFetch, retryWithBackoff, sanitizeAppConfig, setSpanWithError, signJwt, signSlackLinkToken, signSlackUserToken, signTempToken, stripUnsupportedConstraints, throwIfUniqueConstraintError, toISODateString, unwrapError, validateApiKey, validateInternalServiceProjectAccess, validateInternalServiceTenantAccess, validateOrigin, validateTargetAgent, validateTenantId, validateTriggerHeaderValue, verifyAuthorizationHeader, verifyInternalServiceAuthHeader, verifyInternalServiceToken, verifyJwt, verifyPoW, verifyServiceToken, verifySignatureWithConfig, verifySlackLinkToken, verifySlackUserToken, verifyTempToken, verifyTriggerAuth };
|
|
40
|
+
export { ApiKeyGenerationResult, AppCredentialResult, AssembleResult, CommonCreateErrorResponses, CommonDeleteErrorResponses, CommonGetErrorResponses, CommonUpdateErrorResponses, ComposioAuthResult, CredentialScope, ERROR_DOCS_BASE_URL, ErrorCode, ErrorCodes, ErrorResponse, GenerateInternalServiceTokenParams, GenerateServiceTokenParams, GenerationType, HashedHeaderValue, InternalServiceId, InternalServiceTokenPayload, InternalServices, JsonTransformer, JwtVerifyResult, LLMMessage, LoggerFactoryConfig, McpClient, McpClientOptions, McpOAuthFlowResult, McpSSEConfig, McpServerConfig, McpStreamableHttpConfig, McpTokenExchangeResult, MockLanguageModel, ModelFactory, OAuthConfig, ParsedSSEResponse, PinoLogger, PinoLoggerConfig, PoWError, PoWResult, ProblemDetails, ServiceTokenPayload, SignJwtOptions, SignSlackLinkTokenParams, SignSlackUserTokenParams, SignatureVerificationErrorCode, SignatureVerificationResult, SignedTempToken, SlackAccessTokenPayload, SlackAccessTokenPayloadSchema, SlackLinkIntent, SlackLinkIntentSchema, SlackLinkTokenPayload, SlackLinkTokenPayloadSchema, TRUSTED_WORK_APP_MCP_PATHS, TempTokenPayload, TriggerAuthResult, ValidatePublicKeyResult, VerifyInternalServiceTokenResult, VerifyJwtOptions, VerifyServiceTokenResult, VerifySlackLinkTokenResult, VerifySlackUserTokenResult, _resetWaitUntilCache, activeMcpClients, buildConversationMetadata, commonCreateErrorResponses, commonDeleteErrorResponses, commonGetErrorResponses, commonUpdateErrorResponses, configureComposioMCPServer, convertZodToJsonSchema, convertZodToJsonSchemaWithPreview, createApiError, createMockModel, decodeJwtPayload, deleteComposioConnectedAccount, deriveRelationId, detectAuthenticationRequired, errorResponseSchema, errorSchemaFactory, estimateTokens, exchangeMcpAuthorizationCode, extractBearerToken, extractComposioServerId, extractPreviewFields, extractPublicId, extractUsageTokens, fetchComposioServers, fetchSingleComposioServer, flushTraces, formatMessagesForLLM, formatMessagesForLLMContext, gatewayCostMiddleware, generateApiKey, generateAppCredential, generateId, generateInternalServiceToken, generateServiceToken, getComposioInstance, getComposioOAuthRedirectUrl, getComposioUserId, getConversationId, getCredentialStoreLookupKeyFromRetrievalParams, getInProcessFetch, getJwtSecret, getLogger, getMetadataFromApiKey, getPoWErrorMessage, getTracer, getWaitUntil, handleApiError, hasIssuer, hashApiKey, hashAuthenticationHeaders, hashTriggerHeaderValue, initiateMcpOAuthFlow, interpolateTemplate, isApiKeyExpired, isComposioMCPServerAuthenticated, isDevelopment, isInternalServiceToken, isPoWEnabled, isProduction, isSlackUserToken, isTest, isThirdPartyMCPServerAuthenticated, isTrustedWorkAppMcpUrl, isUniqueConstraintError, isZodSchema, loggerFactory, makeAllPropertiesRequired, maskApiKey, normalizeDataComponentSchema, normalizeDateString, parseEmbeddedJson, parseSSEResponse, preview, problemDetailsSchema, registerAppFetch, retryWithBackoff, sanitizeAppConfig, setSpanWithError, signJwt, signSlackLinkToken, signSlackUserToken, signTempToken, stripUnsupportedConstraints, throwIfUniqueConstraintError, toISODateString, unwrapError, validateApiKey, validateInternalServiceProjectAccess, validateInternalServiceTenantAccess, validateOrigin, validatePublicKey, validateTargetAgent, validateTenantId, validateTriggerHeaderValue, verifyAuthorizationHeader, verifyInternalServiceAuthHeader, verifyInternalServiceToken, verifyJwt, verifyPoW, verifyServiceToken, verifySignatureWithConfig, verifySlackLinkToken, verifySlackUserToken, verifyTempToken, verifyTriggerAuth };
|
package/dist/utils/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import { configureComposioMCPServer, deleteComposioConnectedAccount, extractComp
|
|
|
7
7
|
import { isThirdPartyMCPServerAuthenticated } from "./third-party-mcp-servers/third-party-check.js";
|
|
8
8
|
import "./third-party-mcp-servers/index.js";
|
|
9
9
|
import { getCredentialStoreLookupKeyFromRetrievalParams } from "./credential-store-utils.js";
|
|
10
|
-
import { generateId, getConversationId } from "./conversations.js";
|
|
10
|
+
import { buildConversationMetadata, deriveRelationId, generateId, getConversationId } from "./conversations.js";
|
|
11
11
|
import { ERROR_DOCS_BASE_URL, ErrorCode, commonCreateErrorResponses, commonDeleteErrorResponses, commonGetErrorResponses, commonUpdateErrorResponses, createApiError, errorResponseSchema, errorSchemaFactory, handleApiError, isUniqueConstraintError, problemDetailsSchema, throwIfUniqueConstraintError } from "./error.js";
|
|
12
12
|
import { extractPublicId, generateApiKey, generateAppCredential, getMetadataFromApiKey, hashApiKey, isApiKeyExpired, maskApiKey, sanitizeAppConfig, validateApiKey } from "./apiKeys.js";
|
|
13
13
|
import { normalizeDateString, toISODateString } from "./date.js";
|
|
@@ -19,6 +19,7 @@ import { JsonTransformer } from "./JsonTransformer.js";
|
|
|
19
19
|
import { parseEmbeddedJson } from "./json-parser.js";
|
|
20
20
|
import { McpClient, activeMcpClients } from "./mcp-client.js";
|
|
21
21
|
import { MockLanguageModel, createMockModel } from "./mock-provider.js";
|
|
22
|
+
import { extractUsageTokens, gatewayCostMiddleware } from "./usage-cost-middleware.js";
|
|
22
23
|
import { ModelFactory } from "./model-factory.js";
|
|
23
24
|
import { getPoWErrorMessage, isPoWEnabled, verifyPoW } from "./pow.js";
|
|
24
25
|
import { retryWithBackoff } from "./retry.js";
|
|
@@ -28,9 +29,11 @@ import { SlackAccessTokenPayloadSchema, isSlackUserToken, signSlackUserToken, ve
|
|
|
28
29
|
import { parseSSEResponse } from "./sse-parser.js";
|
|
29
30
|
import { signTempToken, verifyTempToken } from "./temp-jwt.js";
|
|
30
31
|
import { interpolateTemplate } from "./template-interpolation.js";
|
|
32
|
+
import { estimateTokens } from "./token-estimator.js";
|
|
31
33
|
import { flushTraces, getTracer, setSpanWithError, unwrapError } from "./tracer-factory.js";
|
|
32
34
|
import { hashAuthenticationHeaders, hashTriggerHeaderValue, validateTriggerHeaderValue, verifySignatureWithConfig, verifyTriggerAuth } from "./trigger-auth.js";
|
|
35
|
+
import { validatePublicKey } from "./validate-public-key.js";
|
|
33
36
|
import { _resetWaitUntilCache, getWaitUntil } from "./wait-until.js";
|
|
34
37
|
import { TRUSTED_WORK_APP_MCP_PATHS, isTrustedWorkAppMcpUrl } from "./work-app-mcp.js";
|
|
35
38
|
|
|
36
|
-
export { ERROR_DOCS_BASE_URL, ErrorCode, InternalServices, JsonTransformer, McpClient, MockLanguageModel, ModelFactory, PinoLogger, SlackAccessTokenPayloadSchema, SlackLinkIntentSchema, SlackLinkTokenPayloadSchema, TRUSTED_WORK_APP_MCP_PATHS, _resetWaitUntilCache, activeMcpClients, commonCreateErrorResponses, commonDeleteErrorResponses, commonGetErrorResponses, commonUpdateErrorResponses, configureComposioMCPServer, convertZodToJsonSchema, convertZodToJsonSchemaWithPreview, createApiError, createMockModel, decodeJwtPayload, deleteComposioConnectedAccount, detectAuthenticationRequired, errorResponseSchema, errorSchemaFactory, exchangeMcpAuthorizationCode, extractBearerToken, extractComposioServerId, extractPreviewFields, extractPublicId, fetchComposioServers, fetchSingleComposioServer, flushTraces, formatMessagesForLLM, formatMessagesForLLMContext, generateApiKey, generateAppCredential, generateId, generateInternalServiceToken, generateServiceToken, getComposioInstance, getComposioOAuthRedirectUrl, getComposioUserId, getConversationId, getCredentialStoreLookupKeyFromRetrievalParams, getInProcessFetch, getJwtSecret, getLogger, getMetadataFromApiKey, getPoWErrorMessage, getTracer, getWaitUntil, handleApiError, hasIssuer, hashApiKey, hashAuthenticationHeaders, hashTriggerHeaderValue, initiateMcpOAuthFlow, interpolateTemplate, isApiKeyExpired, isComposioMCPServerAuthenticated, isDevelopment, isInternalServiceToken, isPoWEnabled, isProduction, isSlackUserToken, isTest, isThirdPartyMCPServerAuthenticated, isTrustedWorkAppMcpUrl, isUniqueConstraintError, isZodSchema, loggerFactory, makeAllPropertiesRequired, maskApiKey, normalizeDataComponentSchema, normalizeDateString, parseEmbeddedJson, parseSSEResponse, preview, problemDetailsSchema, registerAppFetch, retryWithBackoff, sanitizeAppConfig, setSpanWithError, signJwt, signSlackLinkToken, signSlackUserToken, signTempToken, stripUnsupportedConstraints, throwIfUniqueConstraintError, toISODateString, unwrapError, validateApiKey, validateInternalServiceProjectAccess, validateInternalServiceTenantAccess, validateOrigin, validateTargetAgent, validateTenantId, validateTriggerHeaderValue, verifyAuthorizationHeader, verifyInternalServiceAuthHeader, verifyInternalServiceToken, verifyJwt, verifyPoW, verifyServiceToken, verifySignatureWithConfig, verifySlackLinkToken, verifySlackUserToken, verifyTempToken, verifyTriggerAuth };
|
|
39
|
+
export { ERROR_DOCS_BASE_URL, ErrorCode, InternalServices, JsonTransformer, McpClient, MockLanguageModel, ModelFactory, PinoLogger, SlackAccessTokenPayloadSchema, SlackLinkIntentSchema, SlackLinkTokenPayloadSchema, TRUSTED_WORK_APP_MCP_PATHS, _resetWaitUntilCache, activeMcpClients, buildConversationMetadata, commonCreateErrorResponses, commonDeleteErrorResponses, commonGetErrorResponses, commonUpdateErrorResponses, configureComposioMCPServer, convertZodToJsonSchema, convertZodToJsonSchemaWithPreview, createApiError, createMockModel, decodeJwtPayload, deleteComposioConnectedAccount, deriveRelationId, detectAuthenticationRequired, errorResponseSchema, errorSchemaFactory, estimateTokens, exchangeMcpAuthorizationCode, extractBearerToken, extractComposioServerId, extractPreviewFields, extractPublicId, extractUsageTokens, fetchComposioServers, fetchSingleComposioServer, flushTraces, formatMessagesForLLM, formatMessagesForLLMContext, gatewayCostMiddleware, generateApiKey, generateAppCredential, generateId, generateInternalServiceToken, generateServiceToken, getComposioInstance, getComposioOAuthRedirectUrl, getComposioUserId, getConversationId, getCredentialStoreLookupKeyFromRetrievalParams, getInProcessFetch, getJwtSecret, getLogger, getMetadataFromApiKey, getPoWErrorMessage, getTracer, getWaitUntil, handleApiError, hasIssuer, hashApiKey, hashAuthenticationHeaders, hashTriggerHeaderValue, initiateMcpOAuthFlow, interpolateTemplate, isApiKeyExpired, isComposioMCPServerAuthenticated, isDevelopment, isInternalServiceToken, isPoWEnabled, isProduction, isSlackUserToken, isTest, isThirdPartyMCPServerAuthenticated, isTrustedWorkAppMcpUrl, isUniqueConstraintError, isZodSchema, loggerFactory, makeAllPropertiesRequired, maskApiKey, normalizeDataComponentSchema, normalizeDateString, parseEmbeddedJson, parseSSEResponse, preview, problemDetailsSchema, registerAppFetch, retryWithBackoff, sanitizeAppConfig, setSpanWithError, signJwt, signSlackLinkToken, signSlackUserToken, signTempToken, stripUnsupportedConstraints, throwIfUniqueConstraintError, toISODateString, unwrapError, validateApiKey, validateInternalServiceProjectAccess, validateInternalServiceTenantAccess, validateOrigin, validatePublicKey, validateTargetAgent, validateTenantId, validateTriggerHeaderValue, verifyAuthorizationHeader, verifyInternalServiceAuthHeader, verifyInternalServiceToken, verifyJwt, verifyPoW, verifyServiceToken, verifySignatureWithConfig, verifySlackLinkToken, verifySlackUserToken, verifyTempToken, verifyTriggerAuth };
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { getLogger } from "./logger.js";
|
|
2
2
|
import { createMockModel } from "./mock-provider.js";
|
|
3
|
+
import { gatewayCostMiddleware } from "./usage-cost-middleware.js";
|
|
4
|
+
import { wrapLanguageModel } from "ai";
|
|
3
5
|
import { anthropic, createAnthropic } from "@ai-sdk/anthropic";
|
|
4
6
|
import { createAzure } from "@ai-sdk/azure";
|
|
5
7
|
import { createGateway, gateway } from "@ai-sdk/gateway";
|
|
@@ -10,6 +12,11 @@ import { createOpenRouter, openrouter } from "@openrouter/ai-sdk-provider";
|
|
|
10
12
|
|
|
11
13
|
//#region src/utils/model-factory.ts
|
|
12
14
|
const logger = getLogger("ModelFactory");
|
|
15
|
+
const GATEWAY_ROUTABLE_PROVIDERS = [
|
|
16
|
+
"anthropic",
|
|
17
|
+
"openai",
|
|
18
|
+
"google"
|
|
19
|
+
];
|
|
13
20
|
const nimDefault = createOpenAICompatible({
|
|
14
21
|
name: "nim",
|
|
15
22
|
baseURL: "https://integrate.api.nvidia.com/v1",
|
|
@@ -107,21 +114,39 @@ var ModelFactory = class ModelFactory {
|
|
|
107
114
|
hasProviderOptions: !!modelSettings.providerOptions
|
|
108
115
|
}, "Creating language model from config");
|
|
109
116
|
const providerConfig = ModelFactory.extractProviderConfig(modelSettings.providerOptions);
|
|
110
|
-
|
|
117
|
+
const shouldRouteViaGateway = !!process.env.AI_GATEWAY_API_KEY && GATEWAY_ROUTABLE_PROVIDERS.includes(provider) && Object.keys(providerConfig).length === 0;
|
|
118
|
+
let model;
|
|
119
|
+
if (shouldRouteViaGateway) model = gateway(`${provider}/${modelName}`);
|
|
120
|
+
else if (provider !== "mock" && (provider === "azure" || Object.keys(providerConfig).length > 0)) {
|
|
111
121
|
logger.info({ config: providerConfig }, `Applying custom ${provider} provider configuration`);
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
case "
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
case "
|
|
122
|
+
model = ModelFactory.createProvider(provider, providerConfig).languageModel(modelName);
|
|
123
|
+
} else switch (provider) {
|
|
124
|
+
case "anthropic":
|
|
125
|
+
model = anthropic(modelName);
|
|
126
|
+
break;
|
|
127
|
+
case "openai":
|
|
128
|
+
model = openai(modelName);
|
|
129
|
+
break;
|
|
130
|
+
case "google":
|
|
131
|
+
model = google(modelName);
|
|
132
|
+
break;
|
|
133
|
+
case "openrouter":
|
|
134
|
+
model = openrouter(modelName);
|
|
135
|
+
break;
|
|
136
|
+
case "gateway":
|
|
137
|
+
model = gateway(modelName);
|
|
138
|
+
break;
|
|
139
|
+
case "nim":
|
|
140
|
+
model = nimDefault(modelName);
|
|
141
|
+
break;
|
|
121
142
|
case "mock": return createMockModel(modelName);
|
|
122
143
|
case "custom": throw new Error("Custom provider requires configuration. Please provide baseURL in providerOptions.baseURL");
|
|
123
144
|
default: throw new Error(`Unsupported provider: ${provider}. Supported providers are: ${ModelFactory.BUILT_IN_PROVIDERS.join(", ")}. To access other models, use OpenRouter (openrouter/model-id), Vercel AI Gateway (gateway/model-id), NVIDIA NIM (nim/model-id), or Custom OpenAI-compatible (custom/model-id).`);
|
|
124
145
|
}
|
|
146
|
+
return wrapLanguageModel({
|
|
147
|
+
model,
|
|
148
|
+
middleware: gatewayCostMiddleware
|
|
149
|
+
});
|
|
125
150
|
}
|
|
126
151
|
/**
|
|
127
152
|
* Built-in providers that have special handling
|