@rpcbase/agents-sdk 0.20.0 → 0.22.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.
Files changed (60) hide show
  1. package/dist/agents-sdk.css +1 -1
  2. package/dist/api/chat/handler.d.ts.map +1 -1
  3. package/dist/api/chat/runtimeConfig.d.ts +7 -0
  4. package/dist/api/chat/runtimeConfig.d.ts.map +1 -1
  5. package/dist/api/chat/toolApproval.d.ts.map +1 -1
  6. package/dist/api/chat/usageAccumulator.d.ts +3 -0
  7. package/dist/api/chat/usageAccumulator.d.ts.map +1 -0
  8. package/dist/api/chatDb.d.ts +5 -0
  9. package/dist/api/chatDb.d.ts.map +1 -1
  10. package/dist/client-routes.browser.js +36 -34
  11. package/dist/client-routes.d.ts +3 -1
  12. package/dist/client-routes.d.ts.map +1 -1
  13. package/dist/client-routes.js +36 -34
  14. package/dist/components/ai-elements/prompt-input.d.ts.map +1 -1
  15. package/dist/components/ai-elements/tool.d.ts.map +1 -1
  16. package/dist/components/document.d.ts.map +1 -1
  17. package/dist/components/elements/prompt-input.d.ts.map +1 -1
  18. package/dist/components/elements/response.d.ts +1 -1
  19. package/dist/components/elements/response.d.ts.map +1 -1
  20. package/dist/components/icons.d.ts +0 -3
  21. package/dist/components/icons.d.ts.map +1 -1
  22. package/dist/components/image-editor.d.ts.map +1 -1
  23. package/dist/components/messages.d.ts.map +1 -1
  24. package/dist/components/preview-attachment.d.ts.map +1 -1
  25. package/dist/components/sidebar-history-item.d.ts.map +1 -1
  26. package/dist/components/sidebar-history.d.ts.map +1 -1
  27. package/dist/components/spinner.d.ts +6 -0
  28. package/dist/components/spinner.d.ts.map +1 -0
  29. package/dist/components/submit-button.d.ts.map +1 -1
  30. package/dist/components/version-footer.d.ts.map +1 -1
  31. package/dist/{data-stream-handler-DQ9kBtgD.js → data-stream-handler-BbCmRDVC.js} +6046 -6179
  32. package/dist/{data-stream-handler-CNyBIzQ7.js → data-stream-handler-CwI5YJZh.js} +6076 -6209
  33. package/dist/{handler-DS4HXmLA.js → handler-D6etcNwD.js} +567 -519
  34. package/dist/{handler-akLHP-CG.js → handler-Qw_JrLDo.js} +532 -457
  35. package/dist/index.browser.js +1 -1
  36. package/dist/index.js +1 -1
  37. package/dist/lib/db/schema.d.ts +5 -0
  38. package/dist/lib/db/schema.d.ts.map +1 -1
  39. package/dist/models/RBAgentsUsageEvent.d.ts +5 -0
  40. package/dist/models/RBAgentsUsageEvent.d.ts.map +1 -1
  41. package/dist/models.browser.js +5 -0
  42. package/dist/models.js +33 -0
  43. package/dist/pages/ChatNewPage.d.ts +3 -1
  44. package/dist/pages/ChatNewPage.d.ts.map +1 -1
  45. package/dist/pages/ChatPage.d.ts +3 -1
  46. package/dist/pages/ChatPage.d.ts.map +1 -1
  47. package/dist/routes.browser.js +1 -1
  48. package/dist/routes.js +1 -1
  49. package/dist/runtime.d.ts +2 -2
  50. package/dist/runtime.d.ts.map +1 -1
  51. package/dist/runtime.js +1 -1
  52. package/dist/tailwind-source.js +1 -1
  53. package/dist/usage.d.ts +55 -0
  54. package/dist/usage.d.ts.map +1 -0
  55. package/dist/usage.js +124 -0
  56. package/package.json +6 -1
  57. package/dist/components/ai-elements/loader.d.ts +0 -6
  58. package/dist/components/ai-elements/loader.d.ts.map +0 -1
  59. package/dist/components/elements/loader.d.ts +0 -6
  60. package/dist/components/elements/loader.d.ts.map +0 -1
package/dist/usage.js ADDED
@@ -0,0 +1,124 @@
1
+ import { models as e } from "@rpcbase/db";
2
+ //#region src/usage.ts
3
+ var t = 1e6, n = 1e6, r = {
4
+ requestCount: 0,
5
+ inputTokens: 0,
6
+ outputTokens: 0,
7
+ totalTokens: 0,
8
+ billingAmountMicros: 0
9
+ }, i = (e) => typeof e != "number" || !Number.isFinite(e) || e <= 0 ? 0 : Math.trunc(e), a = (e) => {
10
+ if (!e || typeof e != "object" || Array.isArray(e)) return;
11
+ let t = e, n = t.totalUsage ?? t.usage;
12
+ if (n !== void 0) return n;
13
+ if (!t.error || typeof t.error != "object" || Array.isArray(t.error)) return;
14
+ let r = t.error;
15
+ return r.totalUsage ?? r.usage;
16
+ }, o = (e, t) => {
17
+ if (typeof e != "number" || !Number.isSafeInteger(e) || e < 0) throw Error(`${t} must be a non-negative safe integer.`);
18
+ return e;
19
+ }, s = (e) => {
20
+ let t = typeof e == "string" ? e.trim().toUpperCase() : "";
21
+ if (!/^[A-Z]{3}$/.test(t)) throw Error("Agent usage billing currency must be a three-letter ISO code.");
22
+ return t;
23
+ }, c = (e) => {
24
+ let t = typeof e == "string" ? e.trim() : "";
25
+ if (!t) throw Error("Agent usage billing price version is required.");
26
+ return t;
27
+ }, l = (e, t) => {
28
+ let r = i(e.inputTokens), a = i(e.outputTokens), l = o(t.inputPriceMicrosPerMillion, "inputPriceMicrosPerMillion"), u = o(t.outputPriceMicrosPerMillion, "outputPriceMicrosPerMillion"), d = (r * l + a * u) / n, f = Math.round(d);
29
+ if (!Number.isSafeInteger(f)) throw Error("Agent usage billing amount exceeds the supported integer range.");
30
+ return {
31
+ billingCurrency: s(t.currency),
32
+ billingPriceVersion: c(t.version),
33
+ inputPriceMicrosPerMillion: l,
34
+ outputPriceMicrosPerMillion: u,
35
+ billingAmountMicros: f
36
+ };
37
+ }, u = (e) => Number.isFinite(e) ? e / t : 0, d = (e) => {
38
+ let t = typeof e == "string" ? e.trim() : "";
39
+ if (!t) return "UTC";
40
+ try {
41
+ return new Intl.DateTimeFormat("en", { timeZone: t }).format(), t;
42
+ } catch {
43
+ return "UTC";
44
+ }
45
+ }, f = (e) => ({
46
+ requestCount: { $sum: 1 },
47
+ inputTokens: { $sum: { $ifNull: ["$inputTokens", 0] } },
48
+ outputTokens: { $sum: { $ifNull: ["$outputTokens", 0] } },
49
+ totalTokens: { $sum: { $ifNull: ["$totalTokens", { $add: [{ $ifNull: ["$inputTokens", 0] }, { $ifNull: ["$outputTokens", 0] }] }] } },
50
+ billingAmountMicros: { $sum: { $cond: [
51
+ { $eq: ["$billingCurrency", e] },
52
+ { $ifNull: ["$billingAmountMicros", 0] },
53
+ 0
54
+ ] } }
55
+ }), p = (e) => {
56
+ let t = i(e?.inputTokens), n = i(e?.outputTokens), r = e?.totalTokens === void 0 || e.totalTokens === null ? t + n : i(e.totalTokens);
57
+ return {
58
+ requestCount: i(e?.requestCount),
59
+ inputTokens: t,
60
+ outputTokens: n,
61
+ totalTokens: r,
62
+ billingAmountMicros: i(e?.billingAmountMicros)
63
+ };
64
+ }, m = async (t) => {
65
+ let n = t.tenantId.trim(), i = t.workspaceId.trim();
66
+ if (!n || !i) throw Error("Agent usage summary requires tenantId and workspaceId.");
67
+ if (!(t.startAt instanceof Date) || !Number.isFinite(t.startAt.getTime())) throw Error("Agent usage summary startAt must be a valid date.");
68
+ if (!(t.endAt instanceof Date) || !Number.isFinite(t.endAt.getTime())) throw Error("Agent usage summary endAt must be a valid date.");
69
+ if (t.startAt >= t.endAt) throw Error("Agent usage summary endAt must be after startAt.");
70
+ let a = s(t.currency ?? "EUR"), o = f(a), [c] = await (await e.get("RBAgentsUsageEvent", t.ctx)).aggregate([{ $match: {
71
+ tenantId: n,
72
+ workspaceId: i,
73
+ createdAt: {
74
+ $gte: t.startAt,
75
+ $lt: t.endAt
76
+ }
77
+ } }, { $facet: {
78
+ summary: [{ $group: {
79
+ _id: null,
80
+ ...o
81
+ } }],
82
+ dailyUsage: [{ $group: {
83
+ _id: { $dateToString: {
84
+ date: "$createdAt",
85
+ format: "%Y-%m-%d",
86
+ timezone: d(t.timeZone)
87
+ } },
88
+ ...o
89
+ } }, { $sort: { _id: 1 } }],
90
+ byModel: [{ $group: {
91
+ _id: {
92
+ provider: "$provider",
93
+ model: "$model"
94
+ },
95
+ ...o
96
+ } }, { $sort: {
97
+ billingAmountMicros: -1,
98
+ inputTokens: -1,
99
+ outputTokens: -1,
100
+ "_id.model": 1
101
+ } }]
102
+ } }]);
103
+ return {
104
+ currency: a,
105
+ summary: c?.summary?.[0] ? p(c.summary[0]) : { ...r },
106
+ dailyUsage: (c?.dailyUsage ?? []).flatMap((e) => {
107
+ let t = typeof e._id == "string" ? e._id : "";
108
+ return t ? [{
109
+ date: t,
110
+ ...p(e)
111
+ }] : [];
112
+ }),
113
+ byModel: (c?.byModel ?? []).flatMap((e) => {
114
+ let t = typeof e._id?.provider == "string" ? e._id.provider : "", n = typeof e._id?.model == "string" ? e._id.model : "";
115
+ return n ? [{
116
+ provider: t,
117
+ model: n,
118
+ ...p(e)
119
+ }] : [];
120
+ })
121
+ };
122
+ };
123
+ //#endregion
124
+ export { u as agentUsageMicrosToMajor, l as calculateAgentUsageBilling, m as getAgentUsageSummary, a as getReportedAgentUsage };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/agents-sdk",
3
- "version": "0.20.0",
3
+ "version": "0.22.0",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "registry": "https://registry.npmjs.org/"
@@ -65,6 +65,11 @@
65
65
  "types": "./dist/runtime.d.ts",
66
66
  "default": "./dist/runtime.js"
67
67
  },
68
+ "./usage": {
69
+ "import": "./dist/usage.js",
70
+ "types": "./dist/usage.d.ts",
71
+ "default": "./dist/usage.js"
72
+ },
68
73
  "./api-catalog-search": {
69
74
  "import": "./dist/api-catalog-search.js",
70
75
  "types": "./dist/api-catalog-search.d.ts",
@@ -1,6 +0,0 @@
1
- import type { HTMLAttributes } from "react";
2
- export type LoaderProps = HTMLAttributes<HTMLDivElement> & {
3
- size?: number;
4
- };
5
- export declare const Loader: ({ className, size, ...props }: LoaderProps) => import("react").JSX.Element;
6
- //# sourceMappingURL=loader.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../../src/components/ai-elements/loader.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AAmF3C,MAAM,MAAM,WAAW,GAAG,cAAc,CAAC,cAAc,CAAC,GAAG;IACzD,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,eAAO,MAAM,MAAM,kCAAwC,WAAW,gCAUrE,CAAA"}
@@ -1,6 +0,0 @@
1
- import type { HTMLAttributes } from "react";
2
- export type LoaderProps = HTMLAttributes<HTMLDivElement> & {
3
- size?: number;
4
- };
5
- export declare const Loader: ({ className, size, ...props }: LoaderProps) => import("react").JSX.Element;
6
- //# sourceMappingURL=loader.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../../src/components/elements/loader.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AAmF3C,MAAM,MAAM,WAAW,GAAG,cAAc,CAAC,cAAc,CAAC,GAAG;IACzD,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,eAAO,MAAM,MAAM,kCAAwC,WAAW,gCAUrE,CAAA"}