@inkeep/agents-core 0.0.0-dev-20260113131806 → 0.0.0-dev-20260114183157
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.d.ts +67 -39
- package/dist/auth/auth.js +17 -1
- package/dist/auth/permissions.d.ts +13 -13
- package/dist/client-exports.d.ts +4 -4
- package/dist/client-exports.js +2 -1
- package/dist/constants/context-breakdown.d.ts +61 -0
- package/dist/constants/context-breakdown.js +124 -0
- package/dist/data-access/agents.d.ts +41 -41
- package/dist/data-access/apiKeys.d.ts +20 -20
- package/dist/data-access/artifactComponents.d.ts +12 -12
- package/dist/data-access/contextConfigs.d.ts +12 -12
- package/dist/data-access/conversations.d.ts +12 -12
- package/dist/data-access/dataComponents.d.ts +6 -6
- package/dist/data-access/functionTools.d.ts +8 -8
- package/dist/data-access/messages.d.ts +15 -15
- package/dist/data-access/subAgentExternalAgentRelations.d.ts +24 -24
- package/dist/data-access/subAgentRelations.d.ts +30 -30
- package/dist/data-access/subAgentTeamAgentRelations.d.ts +18 -18
- package/dist/data-access/subAgents.d.ts +15 -15
- package/dist/data-access/tasks.d.ts +4 -4
- package/dist/data-access/tools.d.ts +36 -36
- package/dist/db/schema.d.ts +289 -289
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/utils/colors.d.ts +34 -0
- package/dist/utils/colors.js +49 -0
- package/dist/validation/schemas.d.ts +758 -758
- package/package.json +2 -1
package/dist/auth/auth.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { DatabaseClient } from "../db/client.js";
|
|
|
2
2
|
import * as _better_auth_sso0 from "@better-auth/sso";
|
|
3
3
|
import * as better_auth0 from "better-auth";
|
|
4
4
|
import { BetterAuthAdvancedOptions } from "better-auth";
|
|
5
|
-
import * as
|
|
5
|
+
import * as better_auth_plugins0 from "better-auth/plugins";
|
|
6
6
|
import * as zod0 from "zod";
|
|
7
7
|
import { GoogleOptions } from "better-auth/social-providers";
|
|
8
8
|
|
|
@@ -81,6 +81,34 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
|
|
|
81
81
|
requireEmailVerification: false;
|
|
82
82
|
autoSignIn: true;
|
|
83
83
|
};
|
|
84
|
+
databaseHooks: {
|
|
85
|
+
session: {
|
|
86
|
+
create: {
|
|
87
|
+
before: (session: {
|
|
88
|
+
id: string;
|
|
89
|
+
createdAt: Date;
|
|
90
|
+
updatedAt: Date;
|
|
91
|
+
userId: string;
|
|
92
|
+
expiresAt: Date;
|
|
93
|
+
token: string;
|
|
94
|
+
ipAddress?: string | null | undefined;
|
|
95
|
+
userAgent?: string | null | undefined;
|
|
96
|
+
} & Record<string, unknown>) => Promise<{
|
|
97
|
+
data: {
|
|
98
|
+
activeOrganizationId: string | null;
|
|
99
|
+
id: string;
|
|
100
|
+
createdAt: Date;
|
|
101
|
+
updatedAt: Date;
|
|
102
|
+
userId: string;
|
|
103
|
+
expiresAt: Date;
|
|
104
|
+
token: string;
|
|
105
|
+
ipAddress?: string | null | undefined;
|
|
106
|
+
userAgent?: string | null | undefined;
|
|
107
|
+
};
|
|
108
|
+
}>;
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
};
|
|
84
112
|
socialProviders: {
|
|
85
113
|
google: {
|
|
86
114
|
redirectURI?: string | undefined;
|
|
@@ -185,7 +213,7 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
|
|
|
185
213
|
handler: (inputContext: better_auth0.MiddlewareInputContext<better_auth0.MiddlewareOptions>) => Promise<void>;
|
|
186
214
|
}[];
|
|
187
215
|
};
|
|
188
|
-
options:
|
|
216
|
+
options: better_auth_plugins0.BearerOptions | undefined;
|
|
189
217
|
}, {
|
|
190
218
|
id: "sso";
|
|
191
219
|
endpoints: {
|
|
@@ -813,30 +841,30 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
|
|
|
813
841
|
};
|
|
814
842
|
}, {
|
|
815
843
|
id: "organization";
|
|
816
|
-
endpoints:
|
|
844
|
+
endpoints: better_auth_plugins0.OrganizationEndpoints<{
|
|
817
845
|
allowUserToCreateOrganization: true;
|
|
818
|
-
ac:
|
|
846
|
+
ac: better_auth_plugins0.AccessControl;
|
|
819
847
|
roles: {
|
|
820
848
|
member: {
|
|
821
|
-
authorize<K_1 extends "function" | "organization" | "
|
|
822
|
-
actions:
|
|
849
|
+
authorize<K_1 extends "function" | "organization" | "member" | "invitation" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"function" | "organization" | "member" | "invitation" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>[key] | {
|
|
850
|
+
actions: better_auth_plugins0.Subset<"function" | "organization" | "member" | "invitation" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>[key];
|
|
823
851
|
connector: "OR" | "AND";
|
|
824
|
-
} | undefined } : never, connector?: "OR" | "AND"):
|
|
825
|
-
statements:
|
|
852
|
+
} | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
|
|
853
|
+
statements: better_auth_plugins0.Subset<"function" | "organization" | "member" | "invitation" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>;
|
|
826
854
|
};
|
|
827
855
|
admin: {
|
|
828
|
-
authorize<K_1 extends "function" | "organization" | "
|
|
829
|
-
actions:
|
|
856
|
+
authorize<K_1 extends "function" | "organization" | "member" | "invitation" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"function" | "organization" | "member" | "invitation" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>[key] | {
|
|
857
|
+
actions: better_auth_plugins0.Subset<"function" | "organization" | "member" | "invitation" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>[key];
|
|
830
858
|
connector: "OR" | "AND";
|
|
831
|
-
} | undefined } : never, connector?: "OR" | "AND"):
|
|
832
|
-
statements:
|
|
859
|
+
} | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
|
|
860
|
+
statements: better_auth_plugins0.Subset<"function" | "organization" | "member" | "invitation" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>;
|
|
833
861
|
};
|
|
834
862
|
owner: {
|
|
835
|
-
authorize<K_1 extends "function" | "organization" | "
|
|
836
|
-
actions:
|
|
863
|
+
authorize<K_1 extends "function" | "organization" | "member" | "invitation" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"function" | "organization" | "member" | "invitation" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>[key] | {
|
|
864
|
+
actions: better_auth_plugins0.Subset<"function" | "organization" | "member" | "invitation" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>[key];
|
|
837
865
|
connector: "OR" | "AND";
|
|
838
|
-
} | undefined } : never, connector?: "OR" | "AND"):
|
|
839
|
-
statements:
|
|
866
|
+
} | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
|
|
867
|
+
statements: better_auth_plugins0.Subset<"function" | "organization" | "member" | "invitation" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>;
|
|
840
868
|
};
|
|
841
869
|
};
|
|
842
870
|
membershipLimit: number;
|
|
@@ -846,9 +874,9 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
|
|
|
846
874
|
id: string;
|
|
847
875
|
role: string;
|
|
848
876
|
email: string;
|
|
849
|
-
organization:
|
|
850
|
-
invitation:
|
|
851
|
-
inviter:
|
|
877
|
+
organization: better_auth_plugins0.Organization;
|
|
878
|
+
invitation: better_auth_plugins0.Invitation;
|
|
879
|
+
inviter: better_auth_plugins0.Member & {
|
|
852
880
|
user: better_auth0.User;
|
|
853
881
|
};
|
|
854
882
|
}): Promise<void>;
|
|
@@ -981,7 +1009,7 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
|
|
|
981
1009
|
organizationId: string;
|
|
982
1010
|
email: string;
|
|
983
1011
|
role: "member" | "admin" | "owner";
|
|
984
|
-
status:
|
|
1012
|
+
status: better_auth_plugins0.InvitationStatus;
|
|
985
1013
|
inviterId: string;
|
|
986
1014
|
expiresAt: Date;
|
|
987
1015
|
createdAt: Date;
|
|
@@ -1020,7 +1048,7 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
|
|
|
1020
1048
|
organizationId: string;
|
|
1021
1049
|
email: string;
|
|
1022
1050
|
role: "member" | "admin" | "owner";
|
|
1023
|
-
status:
|
|
1051
|
+
status: better_auth_plugins0.InvitationStatus;
|
|
1024
1052
|
inviterId: string;
|
|
1025
1053
|
expiresAt: Date;
|
|
1026
1054
|
createdAt: Date;
|
|
@@ -1094,28 +1122,28 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
|
|
|
1094
1122
|
};
|
|
1095
1123
|
options: NoInfer<{
|
|
1096
1124
|
allowUserToCreateOrganization: true;
|
|
1097
|
-
ac:
|
|
1125
|
+
ac: better_auth_plugins0.AccessControl;
|
|
1098
1126
|
roles: {
|
|
1099
1127
|
member: {
|
|
1100
|
-
authorize<K_1 extends "function" | "organization" | "
|
|
1101
|
-
actions:
|
|
1128
|
+
authorize<K_1 extends "function" | "organization" | "member" | "invitation" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"function" | "organization" | "member" | "invitation" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>[key] | {
|
|
1129
|
+
actions: better_auth_plugins0.Subset<"function" | "organization" | "member" | "invitation" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>[key];
|
|
1102
1130
|
connector: "OR" | "AND";
|
|
1103
|
-
} | undefined } : never, connector?: "OR" | "AND"):
|
|
1104
|
-
statements:
|
|
1131
|
+
} | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
|
|
1132
|
+
statements: better_auth_plugins0.Subset<"function" | "organization" | "member" | "invitation" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>;
|
|
1105
1133
|
};
|
|
1106
1134
|
admin: {
|
|
1107
|
-
authorize<K_1 extends "function" | "organization" | "
|
|
1108
|
-
actions:
|
|
1135
|
+
authorize<K_1 extends "function" | "organization" | "member" | "invitation" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"function" | "organization" | "member" | "invitation" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>[key] | {
|
|
1136
|
+
actions: better_auth_plugins0.Subset<"function" | "organization" | "member" | "invitation" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>[key];
|
|
1109
1137
|
connector: "OR" | "AND";
|
|
1110
|
-
} | undefined } : never, connector?: "OR" | "AND"):
|
|
1111
|
-
statements:
|
|
1138
|
+
} | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
|
|
1139
|
+
statements: better_auth_plugins0.Subset<"function" | "organization" | "member" | "invitation" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>;
|
|
1112
1140
|
};
|
|
1113
1141
|
owner: {
|
|
1114
|
-
authorize<K_1 extends "function" | "organization" | "
|
|
1115
|
-
actions:
|
|
1142
|
+
authorize<K_1 extends "function" | "organization" | "member" | "invitation" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins0.Subset<"function" | "organization" | "member" | "invitation" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>[key] | {
|
|
1143
|
+
actions: better_auth_plugins0.Subset<"function" | "organization" | "member" | "invitation" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>[key];
|
|
1116
1144
|
connector: "OR" | "AND";
|
|
1117
|
-
} | undefined } : never, connector?: "OR" | "AND"):
|
|
1118
|
-
statements:
|
|
1145
|
+
} | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins0.AuthorizeResponse;
|
|
1146
|
+
statements: better_auth_plugins0.Subset<"function" | "organization" | "member" | "invitation" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins0.Statements>;
|
|
1119
1147
|
};
|
|
1120
1148
|
};
|
|
1121
1149
|
membershipLimit: number;
|
|
@@ -1125,9 +1153,9 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
|
|
|
1125
1153
|
id: string;
|
|
1126
1154
|
role: string;
|
|
1127
1155
|
email: string;
|
|
1128
|
-
organization:
|
|
1129
|
-
invitation:
|
|
1130
|
-
inviter:
|
|
1156
|
+
organization: better_auth_plugins0.Organization;
|
|
1157
|
+
invitation: better_auth_plugins0.Invitation;
|
|
1158
|
+
inviter: better_auth_plugins0.Member & {
|
|
1131
1159
|
user: better_auth0.User;
|
|
1132
1160
|
};
|
|
1133
1161
|
}): Promise<void>;
|
|
@@ -1465,8 +1493,8 @@ declare function createAuth(config: BetterAuthConfig): better_auth0.Auth<{
|
|
|
1465
1493
|
readonly AUTHENTICATION_REQUIRED: "Authentication required";
|
|
1466
1494
|
};
|
|
1467
1495
|
options: Partial<{
|
|
1468
|
-
expiresIn:
|
|
1469
|
-
interval:
|
|
1496
|
+
expiresIn: better_auth_plugins0.TimeString;
|
|
1497
|
+
interval: better_auth_plugins0.TimeString;
|
|
1470
1498
|
deviceCodeLength: number;
|
|
1471
1499
|
userCodeLength: number;
|
|
1472
1500
|
schema: {
|
package/dist/auth/auth.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ssoProvider } from "./auth-schema.js";
|
|
1
|
+
import { member, ssoProvider } from "./auth-schema.js";
|
|
2
2
|
import { env } from "../env.js";
|
|
3
3
|
import { generateId } from "../utils/conversations.js";
|
|
4
4
|
import "../utils/index.js";
|
|
@@ -11,6 +11,15 @@ import { bearer, deviceAuthorization, oAuthProxy, organization } from "better-au
|
|
|
11
11
|
|
|
12
12
|
//#region src/auth/auth.ts
|
|
13
13
|
/**
|
|
14
|
+
* Get the user's initial organization for a new session.
|
|
15
|
+
* Returns the oldest organization the user is a member of.
|
|
16
|
+
* See: https://www.better-auth.com/docs/plugins/organization#active-organization
|
|
17
|
+
*/
|
|
18
|
+
async function getInitialOrganization(dbClient, userId) {
|
|
19
|
+
const [membership] = await dbClient.select({ organizationId: member.organizationId }).from(member).where(eq(member.userId, userId)).orderBy(member.createdAt).limit(1);
|
|
20
|
+
return membership ? { id: membership.organizationId } : null;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
14
23
|
* Extracts the root domain from a URL for cross-subdomain cookie sharing.
|
|
15
24
|
* For example:
|
|
16
25
|
* - https://manage-api.pilot.inkeep.com -> .pilot.inkeep.com
|
|
@@ -67,6 +76,13 @@ function createAuth(config) {
|
|
|
67
76
|
requireEmailVerification: false,
|
|
68
77
|
autoSignIn: true
|
|
69
78
|
},
|
|
79
|
+
databaseHooks: { session: { create: { before: async (session) => {
|
|
80
|
+
const organization$1 = await getInitialOrganization(config.dbClient, session.userId);
|
|
81
|
+
return { data: {
|
|
82
|
+
...session,
|
|
83
|
+
activeOrganizationId: organization$1?.id ?? null
|
|
84
|
+
} };
|
|
85
|
+
} } } },
|
|
70
86
|
socialProviders: config.socialProviders?.google && { google: {
|
|
71
87
|
...config.socialProviders.google,
|
|
72
88
|
...env.OAUTH_PROXY_PRODUCTION_URL && { redirectURI: `${env.OAUTH_PROXY_PRODUCTION_URL}/api/auth/callback/google` }
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as better_auth_plugins55 from "better-auth/plugins";
|
|
2
2
|
import { AccessControl } from "better-auth/plugins/access";
|
|
3
3
|
import { organizationClient } from "better-auth/client/plugins";
|
|
4
4
|
|
|
5
5
|
//#region src/auth/permissions.d.ts
|
|
6
6
|
declare const ac: AccessControl;
|
|
7
7
|
declare const memberRole: {
|
|
8
|
-
authorize<K_1 extends "function" | "organization" | "
|
|
9
|
-
actions:
|
|
8
|
+
authorize<K_1 extends "function" | "organization" | "member" | "invitation" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins55.Subset<"function" | "organization" | "member" | "invitation" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins55.Statements>[key] | {
|
|
9
|
+
actions: better_auth_plugins55.Subset<"function" | "organization" | "member" | "invitation" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins55.Statements>[key];
|
|
10
10
|
connector: "OR" | "AND";
|
|
11
|
-
} | undefined } : never, connector?: "OR" | "AND"):
|
|
12
|
-
statements:
|
|
11
|
+
} | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins55.AuthorizeResponse;
|
|
12
|
+
statements: better_auth_plugins55.Subset<"function" | "organization" | "member" | "invitation" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins55.Statements>;
|
|
13
13
|
};
|
|
14
14
|
declare const adminRole: {
|
|
15
|
-
authorize<K_1 extends "function" | "organization" | "
|
|
16
|
-
actions:
|
|
15
|
+
authorize<K_1 extends "function" | "organization" | "member" | "invitation" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins55.Subset<"function" | "organization" | "member" | "invitation" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins55.Statements>[key] | {
|
|
16
|
+
actions: better_auth_plugins55.Subset<"function" | "organization" | "member" | "invitation" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins55.Statements>[key];
|
|
17
17
|
connector: "OR" | "AND";
|
|
18
|
-
} | undefined } : never, connector?: "OR" | "AND"):
|
|
19
|
-
statements:
|
|
18
|
+
} | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins55.AuthorizeResponse;
|
|
19
|
+
statements: better_auth_plugins55.Subset<"function" | "organization" | "member" | "invitation" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins55.Statements>;
|
|
20
20
|
};
|
|
21
21
|
declare const ownerRole: {
|
|
22
|
-
authorize<K_1 extends "function" | "organization" | "
|
|
23
|
-
actions:
|
|
22
|
+
authorize<K_1 extends "function" | "organization" | "member" | "invitation" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team">(request: K_1 extends infer T extends K ? { [key in T]?: better_auth_plugins55.Subset<"function" | "organization" | "member" | "invitation" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins55.Statements>[key] | {
|
|
23
|
+
actions: better_auth_plugins55.Subset<"function" | "organization" | "member" | "invitation" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins55.Statements>[key];
|
|
24
24
|
connector: "OR" | "AND";
|
|
25
|
-
} | undefined } : never, connector?: "OR" | "AND"):
|
|
26
|
-
statements:
|
|
25
|
+
} | undefined } : never, connector?: "OR" | "AND"): better_auth_plugins55.AuthorizeResponse;
|
|
26
|
+
statements: better_auth_plugins55.Subset<"function" | "organization" | "member" | "invitation" | "ac" | "project" | "agent" | "sub_agent" | "tool" | "api_key" | "credential" | "data_component" | "artifact_component" | "external_agent" | "context_config" | "team", better_auth_plugins55.Statements>;
|
|
27
27
|
};
|
|
28
28
|
//#endregion
|
|
29
29
|
export { ac, adminRole, memberRole, organizationClient, ownerRole };
|
package/dist/client-exports.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BreakdownComponentDef, CONTEXT_BREAKDOWN_TOTAL_SPAN_ATTRIBUTE, ContextBreakdown, V1_BREAKDOWN_SCHEMA, calculateBreakdownTotal, createEmptyBreakdown, parseContextBreakdownFromSpan } from "./constants/context-breakdown.js";
|
|
1
2
|
import { ACTIVITY_NAMES, ACTIVITY_STATUS, ACTIVITY_TYPES, AGENT_IDS, AI_OPERATIONS, AI_TOOL_TYPES, DELEGATION_FROM_SUB_AGENT_ID, DELEGATION_ID, DELEGATION_TO_SUB_AGENT_ID, SPAN_KEYS, SPAN_NAMES, TRANSFER_FROM_SUB_AGENT_ID, TRANSFER_TO_SUB_AGENT_ID, UNKNOWN_VALUE } from "./constants/otel-attributes.js";
|
|
2
3
|
import { AGGREGATE_OPERATORS, DATA_SOURCES, DATA_TYPES, FIELD_TYPES, OPERATORS, ORDER_DIRECTIONS, PANEL_TYPES, QUERY_DEFAULTS, QUERY_EXPRESSIONS, QUERY_FIELD_CONFIGS, QUERY_TYPES, REDUCE_OPERATIONS } from "./constants/signoz-queries.js";
|
|
3
4
|
import { AgentStopWhen, AgentStopWhenSchema, ApiKeyApiUpdateSchema, FullAgentAgentInsertSchema, FunctionApiInsertSchema, FunctionApiSelectSchema, FunctionApiUpdateSchema, ModelSettings, ModelSettingsSchema, StopWhen, StopWhenSchema, SubAgentStopWhen, SubAgentStopWhenSchema } from "./validation/schemas.js";
|
|
@@ -5,7 +6,6 @@ import "./types/index.js";
|
|
|
5
6
|
import { DEFAULT_NANGO_STORE_ID } from "./credential-stores/default-constants.js";
|
|
6
7
|
import { detectAuthenticationRequired } from "./utils/auth-detection.js";
|
|
7
8
|
import { validatePropsAsJsonSchema } from "./validation/props-validation.js";
|
|
8
|
-
import "./index.js";
|
|
9
9
|
import { ConversationHistoryConfig, CredentialStoreType, MCPTransportType } from "./types/utility.js";
|
|
10
10
|
import { z } from "@hono/zod-openapi";
|
|
11
11
|
|
|
@@ -64,8 +64,8 @@ declare const AgentApiInsertSchema: z.ZodObject<{
|
|
|
64
64
|
canTransferTo: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
65
65
|
canDelegateTo: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
66
66
|
type: z.ZodOptional<z.ZodEnum<{
|
|
67
|
-
internal: "internal";
|
|
68
67
|
external: "external";
|
|
68
|
+
internal: "internal";
|
|
69
69
|
}>>;
|
|
70
70
|
}, z.core.$strip>;
|
|
71
71
|
declare const ToolApiInsertSchema: z.ZodObject<{
|
|
@@ -192,9 +192,9 @@ declare const FullAgentDefinitionSchema: z.ZodObject<{
|
|
|
192
192
|
subAgents: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodObject<{
|
|
193
193
|
id: z.ZodString;
|
|
194
194
|
name: z.ZodString;
|
|
195
|
-
description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
196
195
|
createdAt: z.ZodOptional<z.ZodString>;
|
|
197
196
|
updatedAt: z.ZodOptional<z.ZodString>;
|
|
197
|
+
description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
198
198
|
models: z.ZodOptional<z.ZodObject<{
|
|
199
199
|
base: z.ZodOptional<z.ZodObject<{
|
|
200
200
|
model: z.ZodOptional<z.ZodString>;
|
|
@@ -309,4 +309,4 @@ declare function generateIdFromName(name: string): string;
|
|
|
309
309
|
type ToolInsert = ToolApiInsert;
|
|
310
310
|
type AgentAgentInsert = AgentAgentApiInsert;
|
|
311
311
|
//#endregion
|
|
312
|
-
export { ACTIVITY_NAMES, ACTIVITY_STATUS, ACTIVITY_TYPES, AGENT_IDS, AGGREGATE_OPERATORS, AI_OPERATIONS, AI_TOOL_TYPES, AgentAgentApiInsert, AgentAgentApiInsertSchema, AgentAgentInsert, AgentApiInsert, AgentApiInsertSchema, type AgentStopWhen, AgentStopWhenSchema, ApiKeyApiCreationResponse, ApiKeyApiCreationResponseSchema, ApiKeyApiSelect, ApiKeyApiSelectSchema, ApiKeyApiUpdateResponse, ArtifactComponentApiInsert, ArtifactComponentApiInsertSchema, ContextConfigApiInsert, ContextConfigApiInsertSchema, CredentialReferenceApiInsert, CredentialReferenceApiInsertSchema, CredentialStoreType, DATA_SOURCES, DATA_TYPES, DEFAULT_NANGO_STORE_ID, DELEGATION_FROM_SUB_AGENT_ID, DELEGATION_ID, DELEGATION_TO_SUB_AGENT_ID, DataComponentApiInsert, DataComponentApiInsertSchema, ErrorResponse, ErrorResponseSchema, ExternalAgentApiInsert, ExternalAgentApiInsertSchema, ExternalAgentDefinition, FIELD_TYPES, FullAgentDefinition, FullAgentDefinitionSchema, FunctionApiInsert, FunctionApiInsertSchema, FunctionApiSelectSchema, FunctionApiUpdateSchema, IdParamsSchema, InternalAgentDefinition, ListResponseSchema, MAX_ID_LENGTH, MCPTransportType, MIN_ID_LENGTH, type ModelSettings, ModelSettingsSchema, OPERATORS, ORDER_DIRECTIONS, PANEL_TYPES, PaginationSchema, QUERY_DEFAULTS, QUERY_EXPRESSIONS, QUERY_FIELD_CONFIGS, QUERY_TYPES, REDUCE_OPERATIONS, SPAN_KEYS, SPAN_NAMES, SingleResponseSchema, type StopWhen, StopWhenSchema, type SubAgentStopWhen, SubAgentStopWhenSchema, TRANSFER_FROM_SUB_AGENT_ID, TRANSFER_TO_SUB_AGENT_ID, TenantParams, TenantParamsSchema, TenantProjectIdParamsSchema, TenantProjectParamsSchema, ToolApiInsert, ToolApiInsertSchema, ToolInsert, UNKNOWN_VALUE, URL_SAFE_ID_PATTERN, detectAuthenticationRequired, generateIdFromName, resourceIdSchema, validatePropsAsJsonSchema };
|
|
312
|
+
export { ACTIVITY_NAMES, ACTIVITY_STATUS, ACTIVITY_TYPES, AGENT_IDS, AGGREGATE_OPERATORS, AI_OPERATIONS, AI_TOOL_TYPES, AgentAgentApiInsert, AgentAgentApiInsertSchema, AgentAgentInsert, AgentApiInsert, AgentApiInsertSchema, type AgentStopWhen, AgentStopWhenSchema, ApiKeyApiCreationResponse, ApiKeyApiCreationResponseSchema, ApiKeyApiSelect, ApiKeyApiSelectSchema, ApiKeyApiUpdateResponse, ArtifactComponentApiInsert, ArtifactComponentApiInsertSchema, BreakdownComponentDef, CONTEXT_BREAKDOWN_TOTAL_SPAN_ATTRIBUTE, ContextBreakdown, ContextConfigApiInsert, ContextConfigApiInsertSchema, CredentialReferenceApiInsert, CredentialReferenceApiInsertSchema, CredentialStoreType, DATA_SOURCES, DATA_TYPES, DEFAULT_NANGO_STORE_ID, DELEGATION_FROM_SUB_AGENT_ID, DELEGATION_ID, DELEGATION_TO_SUB_AGENT_ID, DataComponentApiInsert, DataComponentApiInsertSchema, ErrorResponse, ErrorResponseSchema, ExternalAgentApiInsert, ExternalAgentApiInsertSchema, ExternalAgentDefinition, FIELD_TYPES, FullAgentDefinition, FullAgentDefinitionSchema, FunctionApiInsert, FunctionApiInsertSchema, FunctionApiSelectSchema, FunctionApiUpdateSchema, IdParamsSchema, InternalAgentDefinition, ListResponseSchema, MAX_ID_LENGTH, MCPTransportType, MIN_ID_LENGTH, type ModelSettings, ModelSettingsSchema, OPERATORS, ORDER_DIRECTIONS, PANEL_TYPES, PaginationSchema, QUERY_DEFAULTS, QUERY_EXPRESSIONS, QUERY_FIELD_CONFIGS, QUERY_TYPES, REDUCE_OPERATIONS, SPAN_KEYS, SPAN_NAMES, SingleResponseSchema, type StopWhen, StopWhenSchema, type SubAgentStopWhen, SubAgentStopWhenSchema, TRANSFER_FROM_SUB_AGENT_ID, TRANSFER_TO_SUB_AGENT_ID, TenantParams, TenantParamsSchema, TenantProjectIdParamsSchema, TenantProjectParamsSchema, ToolApiInsert, ToolApiInsertSchema, ToolInsert, UNKNOWN_VALUE, URL_SAFE_ID_PATTERN, V1_BREAKDOWN_SCHEMA, calculateBreakdownTotal, createEmptyBreakdown, detectAuthenticationRequired, generateIdFromName, parseContextBreakdownFromSpan, resourceIdSchema, validatePropsAsJsonSchema };
|
package/dist/client-exports.js
CHANGED
|
@@ -3,6 +3,7 @@ import { CredentialStoreType, MCPTransportType } from "./types/utility.js";
|
|
|
3
3
|
import { AgentStopWhenSchema, ArtifactComponentApiInsertSchema as ArtifactComponentApiInsertSchema$1, FullAgentAgentInsertSchema, FunctionApiInsertSchema, FunctionApiSelectSchema, FunctionApiUpdateSchema, ModelSettingsSchema, StopWhenSchema, SubAgentStopWhenSchema } from "./validation/schemas.js";
|
|
4
4
|
import { DEFAULT_NANGO_STORE_ID } from "./credential-stores/default-constants.js";
|
|
5
5
|
import { validatePropsAsJsonSchema } from "./validation/props-validation.js";
|
|
6
|
+
import { CONTEXT_BREAKDOWN_TOTAL_SPAN_ATTRIBUTE, V1_BREAKDOWN_SCHEMA, calculateBreakdownTotal, createEmptyBreakdown, parseContextBreakdownFromSpan } from "./constants/context-breakdown.js";
|
|
6
7
|
import { ACTIVITY_NAMES, ACTIVITY_STATUS, ACTIVITY_TYPES, AGENT_IDS, AI_OPERATIONS, AI_TOOL_TYPES, DELEGATION_FROM_SUB_AGENT_ID, DELEGATION_ID, DELEGATION_TO_SUB_AGENT_ID, SPAN_KEYS, SPAN_NAMES, TRANSFER_FROM_SUB_AGENT_ID, TRANSFER_TO_SUB_AGENT_ID, UNKNOWN_VALUE } from "./constants/otel-attributes.js";
|
|
7
8
|
import { AGGREGATE_OPERATORS, DATA_SOURCES, DATA_TYPES, FIELD_TYPES, OPERATORS, ORDER_DIRECTIONS, PANEL_TYPES, QUERY_DEFAULTS, QUERY_EXPRESSIONS, QUERY_FIELD_CONFIGS, QUERY_TYPES, REDUCE_OPERATIONS } from "./constants/signoz-queries.js";
|
|
8
9
|
import { detectAuthenticationRequired } from "./utils/auth-detection.js";
|
|
@@ -167,4 +168,4 @@ function generateIdFromName(name) {
|
|
|
167
168
|
}
|
|
168
169
|
|
|
169
170
|
//#endregion
|
|
170
|
-
export { ACTIVITY_NAMES, ACTIVITY_STATUS, ACTIVITY_TYPES, AGENT_IDS, AGGREGATE_OPERATORS, AI_OPERATIONS, AI_TOOL_TYPES, AgentAgentApiInsertSchema, AgentApiInsertSchema, AgentStopWhenSchema, ApiKeyApiCreationResponseSchema, ApiKeyApiSelectSchema, ArtifactComponentApiInsertSchema, ContextConfigApiInsertSchema, CredentialReferenceApiInsertSchema, CredentialStoreType, DATA_SOURCES, DATA_TYPES, DEFAULT_NANGO_STORE_ID, DELEGATION_FROM_SUB_AGENT_ID, DELEGATION_ID, DELEGATION_TO_SUB_AGENT_ID, DataComponentApiInsertSchema, ErrorResponseSchema, ExternalAgentApiInsertSchema, FIELD_TYPES, FullAgentDefinitionSchema, FunctionApiInsertSchema, FunctionApiSelectSchema, FunctionApiUpdateSchema, IdParamsSchema, ListResponseSchema, MAX_ID_LENGTH, MCPTransportType, MIN_ID_LENGTH, ModelSettingsSchema, OPERATORS, ORDER_DIRECTIONS, PANEL_TYPES, PaginationSchema, QUERY_DEFAULTS, QUERY_EXPRESSIONS, QUERY_FIELD_CONFIGS, QUERY_TYPES, REDUCE_OPERATIONS, SPAN_KEYS, SPAN_NAMES, SingleResponseSchema, StopWhenSchema, SubAgentStopWhenSchema, TRANSFER_FROM_SUB_AGENT_ID, TRANSFER_TO_SUB_AGENT_ID, TenantParamsSchema, TenantProjectIdParamsSchema, TenantProjectParamsSchema, ToolApiInsertSchema, UNKNOWN_VALUE, URL_SAFE_ID_PATTERN, detectAuthenticationRequired, generateIdFromName, resourceIdSchema, validatePropsAsJsonSchema };
|
|
171
|
+
export { ACTIVITY_NAMES, ACTIVITY_STATUS, ACTIVITY_TYPES, AGENT_IDS, AGGREGATE_OPERATORS, AI_OPERATIONS, AI_TOOL_TYPES, AgentAgentApiInsertSchema, AgentApiInsertSchema, AgentStopWhenSchema, ApiKeyApiCreationResponseSchema, ApiKeyApiSelectSchema, ArtifactComponentApiInsertSchema, CONTEXT_BREAKDOWN_TOTAL_SPAN_ATTRIBUTE, ContextConfigApiInsertSchema, CredentialReferenceApiInsertSchema, CredentialStoreType, DATA_SOURCES, DATA_TYPES, DEFAULT_NANGO_STORE_ID, DELEGATION_FROM_SUB_AGENT_ID, DELEGATION_ID, DELEGATION_TO_SUB_AGENT_ID, DataComponentApiInsertSchema, ErrorResponseSchema, ExternalAgentApiInsertSchema, FIELD_TYPES, FullAgentDefinitionSchema, FunctionApiInsertSchema, FunctionApiSelectSchema, FunctionApiUpdateSchema, IdParamsSchema, ListResponseSchema, MAX_ID_LENGTH, MCPTransportType, MIN_ID_LENGTH, ModelSettingsSchema, OPERATORS, ORDER_DIRECTIONS, PANEL_TYPES, PaginationSchema, QUERY_DEFAULTS, QUERY_EXPRESSIONS, QUERY_FIELD_CONFIGS, QUERY_TYPES, REDUCE_OPERATIONS, SPAN_KEYS, SPAN_NAMES, SingleResponseSchema, StopWhenSchema, SubAgentStopWhenSchema, TRANSFER_FROM_SUB_AGENT_ID, TRANSFER_TO_SUB_AGENT_ID, TenantParamsSchema, TenantProjectIdParamsSchema, TenantProjectParamsSchema, ToolApiInsertSchema, UNKNOWN_VALUE, URL_SAFE_ID_PATTERN, V1_BREAKDOWN_SCHEMA, calculateBreakdownTotal, createEmptyBreakdown, detectAuthenticationRequired, generateIdFromName, parseContextBreakdownFromSpan, resourceIdSchema, validatePropsAsJsonSchema };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
//#region src/constants/context-breakdown.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Context breakdown schema definitions.
|
|
4
|
+
*
|
|
5
|
+
* This module defines the breakdown components tracked for each system prompt version.
|
|
6
|
+
* It serves as the single source of truth for:
|
|
7
|
+
* - Component keys and labels
|
|
8
|
+
* - OpenTelemetry span attribute keys
|
|
9
|
+
* - UI visualization colors (auto-generated)
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Defines a single breakdown component for a system prompt version.
|
|
13
|
+
* Each version can define its own set of components.
|
|
14
|
+
*/
|
|
15
|
+
interface BreakdownComponentDef {
|
|
16
|
+
/** Unique key for this component (used in breakdown.components map) */
|
|
17
|
+
key: string;
|
|
18
|
+
/** Human-readable label for UI display */
|
|
19
|
+
label: string;
|
|
20
|
+
/** OpenTelemetry span attribute key for this component */
|
|
21
|
+
spanAttribute: string;
|
|
22
|
+
/** Hex color for UI visualization (auto-generated) */
|
|
23
|
+
color: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* V1 Breakdown Schema - defines all context components tracked for V1 system prompts.
|
|
27
|
+
* Colors are automatically generated for visual distinction.
|
|
28
|
+
*/
|
|
29
|
+
declare const V1_BREAKDOWN_SCHEMA: BreakdownComponentDef[];
|
|
30
|
+
/** Span attribute key for total tokens */
|
|
31
|
+
declare const CONTEXT_BREAKDOWN_TOTAL_SPAN_ATTRIBUTE = "context.breakdown.total_tokens";
|
|
32
|
+
/**
|
|
33
|
+
* Dynamic context breakdown interface.
|
|
34
|
+
* Uses a components map to support different system prompt versions.
|
|
35
|
+
*/
|
|
36
|
+
interface ContextBreakdown {
|
|
37
|
+
/** Token counts by component key (version-specific) */
|
|
38
|
+
components: Record<string, number>;
|
|
39
|
+
/** Total estimated tokens */
|
|
40
|
+
total: number;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Creates an empty context breakdown from a schema definition.
|
|
44
|
+
* @param schema - Array of breakdown component definitions
|
|
45
|
+
*/
|
|
46
|
+
declare function createEmptyBreakdown(schema: BreakdownComponentDef[]): ContextBreakdown;
|
|
47
|
+
/**
|
|
48
|
+
* Calculates the total from all breakdown components and updates the total field.
|
|
49
|
+
* @param breakdown - The context breakdown to calculate total for
|
|
50
|
+
* @returns The breakdown with updated total
|
|
51
|
+
*/
|
|
52
|
+
declare function calculateBreakdownTotal(breakdown: ContextBreakdown): ContextBreakdown;
|
|
53
|
+
/**
|
|
54
|
+
* Parses a context breakdown from span attributes using a schema.
|
|
55
|
+
* @param data - Span attribute data record
|
|
56
|
+
* @param schema - Breakdown schema to use for parsing
|
|
57
|
+
* @returns Parsed context breakdown
|
|
58
|
+
*/
|
|
59
|
+
declare function parseContextBreakdownFromSpan(data: Record<string, unknown>, schema?: BreakdownComponentDef[]): ContextBreakdown;
|
|
60
|
+
//#endregion
|
|
61
|
+
export { BreakdownComponentDef, CONTEXT_BREAKDOWN_TOTAL_SPAN_ATTRIBUTE, ContextBreakdown, V1_BREAKDOWN_SCHEMA, calculateBreakdownTotal, createEmptyBreakdown, parseContextBreakdownFromSpan };
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { generateDistinctColors } from "../utils/colors.js";
|
|
2
|
+
|
|
3
|
+
//#region src/constants/context-breakdown.ts
|
|
4
|
+
/**
|
|
5
|
+
* Context breakdown schema definitions.
|
|
6
|
+
*
|
|
7
|
+
* This module defines the breakdown components tracked for each system prompt version.
|
|
8
|
+
* It serves as the single source of truth for:
|
|
9
|
+
* - Component keys and labels
|
|
10
|
+
* - OpenTelemetry span attribute keys
|
|
11
|
+
* - UI visualization colors (auto-generated)
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Base schema without colors - colors are auto-generated based on index
|
|
15
|
+
*/
|
|
16
|
+
const V1_BREAKDOWN_SCHEMA_BASE = [
|
|
17
|
+
{
|
|
18
|
+
key: "systemPromptTemplate",
|
|
19
|
+
label: "System Prompt Template",
|
|
20
|
+
spanAttribute: "context.breakdown.system_template_tokens"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
key: "coreInstructions",
|
|
24
|
+
label: "Core Instructions",
|
|
25
|
+
spanAttribute: "context.breakdown.core_instructions_tokens"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
key: "agentPrompt",
|
|
29
|
+
label: "Agent Prompt",
|
|
30
|
+
spanAttribute: "context.breakdown.agent_prompt_tokens"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
key: "toolsSection",
|
|
34
|
+
label: "Tools (MCP/Function/Relation)",
|
|
35
|
+
spanAttribute: "context.breakdown.tools_tokens"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
key: "artifactsSection",
|
|
39
|
+
label: "Artifacts",
|
|
40
|
+
spanAttribute: "context.breakdown.artifacts_tokens"
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
key: "dataComponents",
|
|
44
|
+
label: "Data Components",
|
|
45
|
+
spanAttribute: "context.breakdown.data_components_tokens"
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
key: "artifactComponents",
|
|
49
|
+
label: "Artifact Components",
|
|
50
|
+
spanAttribute: "context.breakdown.artifact_components_tokens"
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
key: "transferInstructions",
|
|
54
|
+
label: "Transfer Instructions",
|
|
55
|
+
spanAttribute: "context.breakdown.transfer_instructions_tokens"
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
key: "delegationInstructions",
|
|
59
|
+
label: "Delegation Instructions",
|
|
60
|
+
spanAttribute: "context.breakdown.delegation_instructions_tokens"
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
key: "thinkingPreparation",
|
|
64
|
+
label: "Thinking Preparation",
|
|
65
|
+
spanAttribute: "context.breakdown.thinking_preparation_tokens"
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
key: "conversationHistory",
|
|
69
|
+
label: "Conversation History",
|
|
70
|
+
spanAttribute: "context.breakdown.conversation_history_tokens"
|
|
71
|
+
}
|
|
72
|
+
];
|
|
73
|
+
/** Pre-generated distinct colors for the schema */
|
|
74
|
+
const SCHEMA_COLORS = generateDistinctColors(V1_BREAKDOWN_SCHEMA_BASE.length);
|
|
75
|
+
/**
|
|
76
|
+
* V1 Breakdown Schema - defines all context components tracked for V1 system prompts.
|
|
77
|
+
* Colors are automatically generated for visual distinction.
|
|
78
|
+
*/
|
|
79
|
+
const V1_BREAKDOWN_SCHEMA = V1_BREAKDOWN_SCHEMA_BASE.map((def, index) => ({
|
|
80
|
+
...def,
|
|
81
|
+
color: SCHEMA_COLORS[index]
|
|
82
|
+
}));
|
|
83
|
+
/** Span attribute key for total tokens */
|
|
84
|
+
const CONTEXT_BREAKDOWN_TOTAL_SPAN_ATTRIBUTE = "context.breakdown.total_tokens";
|
|
85
|
+
/**
|
|
86
|
+
* Creates an empty context breakdown from a schema definition.
|
|
87
|
+
* @param schema - Array of breakdown component definitions
|
|
88
|
+
*/
|
|
89
|
+
function createEmptyBreakdown(schema) {
|
|
90
|
+
const components = {};
|
|
91
|
+
for (const def of schema) components[def.key] = 0;
|
|
92
|
+
return {
|
|
93
|
+
components,
|
|
94
|
+
total: 0
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Calculates the total from all breakdown components and updates the total field.
|
|
99
|
+
* @param breakdown - The context breakdown to calculate total for
|
|
100
|
+
* @returns The breakdown with updated total
|
|
101
|
+
*/
|
|
102
|
+
function calculateBreakdownTotal(breakdown) {
|
|
103
|
+
breakdown.total = Object.values(breakdown.components).reduce((sum, val) => sum + val, 0);
|
|
104
|
+
return breakdown;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Parses a context breakdown from span attributes using a schema.
|
|
108
|
+
* @param data - Span attribute data record
|
|
109
|
+
* @param schema - Breakdown schema to use for parsing
|
|
110
|
+
* @returns Parsed context breakdown
|
|
111
|
+
*/
|
|
112
|
+
function parseContextBreakdownFromSpan(data, schema = V1_BREAKDOWN_SCHEMA) {
|
|
113
|
+
const breakdown = createEmptyBreakdown(schema);
|
|
114
|
+
for (const def of schema) {
|
|
115
|
+
const value = data[def.spanAttribute];
|
|
116
|
+
breakdown.components[def.key] = typeof value === "number" ? value : Number(value) || 0;
|
|
117
|
+
}
|
|
118
|
+
const totalValue = data[CONTEXT_BREAKDOWN_TOTAL_SPAN_ATTRIBUTE];
|
|
119
|
+
breakdown.total = typeof totalValue === "number" ? totalValue : Number(totalValue) || 0;
|
|
120
|
+
return breakdown;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
//#endregion
|
|
124
|
+
export { CONTEXT_BREAKDOWN_TOTAL_SPAN_ATTRIBUTE, V1_BREAKDOWN_SCHEMA, calculateBreakdownTotal, createEmptyBreakdown, parseContextBreakdownFromSpan };
|