@fonoster/common 0.27.0 → 0.31.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 (209) hide show
  1. package/dist/{voice/PlayDtmf.d.ts → agents/index.d.ts} +3 -5
  2. package/dist/{assistants → agents}/index.js +2 -6
  3. package/dist/agents/sessionAgentSchema.d.ts +755 -0
  4. package/dist/agents/sessionAgentSchema.js +117 -0
  5. package/dist/{voice/Dial.d.ts → calls/index.d.ts} +16 -13
  6. package/dist/calls/index.js +44 -0
  7. package/dist/cellsecrets/index.d.ts +91 -0
  8. package/dist/cellsecrets/index.js +299 -0
  9. package/dist/config/cli/check.d.ts +6 -0
  10. package/dist/config/cli/check.js +202 -0
  11. package/dist/config/cli/envFile.d.ts +23 -0
  12. package/dist/config/cli/envFile.js +81 -0
  13. package/dist/config/cli/exposure.d.ts +10 -0
  14. package/dist/config/cli/exposure.js +93 -0
  15. package/dist/config/cli/index.d.ts +2 -0
  16. package/dist/{identity/tokenHasAccessKeyId.js → config/cli/index.js} +7 -8
  17. package/dist/config/cli/info.d.ts +6 -0
  18. package/dist/config/cli/info.js +62 -0
  19. package/dist/config/cli/init.d.ts +9 -0
  20. package/dist/config/cli/init.js +152 -0
  21. package/dist/config/cli/main.d.ts +11 -0
  22. package/dist/config/cli/main.js +155 -0
  23. package/dist/config/cli/render.d.ts +44 -0
  24. package/dist/config/cli/render.js +129 -0
  25. package/dist/config/cli/secrets.d.ts +21 -0
  26. package/dist/config/cli/secrets.js +117 -0
  27. package/dist/config/cli/types.d.ts +24 -0
  28. package/dist/config/cli/types.js +7 -0
  29. package/dist/{assistants/index.d.ts → config/configHints.d.ts} +8 -7
  30. package/dist/config/configHints.js +47 -0
  31. package/dist/{voice → config}/index.d.ts +11 -13
  32. package/dist/{voice → config}/index.js +11 -13
  33. package/dist/config/interpolateEnv.d.ts +34 -0
  34. package/dist/config/interpolateEnv.js +70 -0
  35. package/dist/config/loadServiceConfig.d.ts +28 -0
  36. package/dist/config/loadServiceConfig.js +112 -0
  37. package/dist/config/logsSchema.d.ts +76 -0
  38. package/dist/config/logsSchema.js +49 -0
  39. package/dist/config/natsConnection.d.ts +53 -0
  40. package/dist/config/natsConnection.js +58 -0
  41. package/dist/config/parseConfigFile.d.ts +7 -0
  42. package/dist/config/parseConfigFile.js +60 -0
  43. package/dist/config/resolveConfigFile.d.ts +17 -0
  44. package/dist/config/resolveConfigFile.js +54 -0
  45. package/dist/config/resolveSecretRefs.d.ts +35 -0
  46. package/dist/config/resolveSecretRefs.js +129 -0
  47. package/dist/{assistants/audioFiltersSchema.d.ts → config/strictDeep.d.ts} +9 -12
  48. package/dist/config/strictDeep.js +58 -0
  49. package/dist/config/telemetrySchema.d.ts +39 -0
  50. package/dist/config/telemetrySchema.js +44 -0
  51. package/dist/config/toJsonSchema.d.ts +30 -0
  52. package/dist/config/toJsonSchema.js +161 -0
  53. package/dist/constants.d.ts +1 -6
  54. package/dist/constants.js +4 -7
  55. package/dist/envs.d.ts +2 -1
  56. package/dist/envs.js +13 -11
  57. package/dist/errors/handleZodError.js +3 -1
  58. package/dist/filters/index.d.ts +70 -0
  59. package/dist/filters/index.js +101 -0
  60. package/dist/identity/createAuthInterceptor.d.ts +9 -2
  61. package/dist/identity/createAuthInterceptor.js +36 -30
  62. package/dist/identity/hasAccess.d.ts +9 -3
  63. package/dist/identity/hasAccess.js +32 -8
  64. package/dist/identity/index.d.ts +1 -0
  65. package/dist/identity/index.js +1 -0
  66. package/dist/identity/isValidToken.d.ts +12 -2
  67. package/dist/identity/isValidToken.js +25 -9
  68. package/dist/identity/roles.js +33 -7
  69. package/dist/identity/types.d.ts +6 -1
  70. package/dist/identity/types.js +1 -0
  71. package/dist/{assistants/LanguageModelProvider.js → identity/verifyAccessToken.d.ts} +10 -11
  72. package/dist/identity/verifyAccessToken.js +44 -0
  73. package/dist/index.d.ts +15 -2
  74. package/dist/index.js +18 -3
  75. package/dist/net/assertPublicDestination.d.ts +52 -0
  76. package/dist/net/assertPublicDestination.js +342 -0
  77. package/dist/{voice/StopSay.d.ts → net/index.d.ts} +1 -6
  78. package/dist/net/index.js +35 -0
  79. package/dist/notifications/createSendEmail.js +3 -1
  80. package/dist/protos/applications.proto +138 -3
  81. package/dist/protos/authz.proto +26 -4
  82. package/dist/protos/billing.proto +92 -0
  83. package/dist/protos/calls.proto +4 -0
  84. package/dist/protos/capabilities.proto +102 -0
  85. package/dist/protos/identity.proto +26 -1
  86. package/dist/protos/providers.proto +139 -0
  87. package/dist/protos/roomr.proto +146 -0
  88. package/dist/protos/session.proto +194 -0
  89. package/dist/protos/usage.proto +59 -0
  90. package/dist/protos/webhooks.proto +140 -0
  91. package/dist/{utils/types.d.ts → regions/hub/index.d.ts} +1 -5
  92. package/dist/regions/hub/index.js +35 -0
  93. package/dist/regions/hub/natsJwt.d.ts +63 -0
  94. package/dist/regions/hub/natsJwt.js +195 -0
  95. package/dist/registry/Registry.d.ts +87 -0
  96. package/dist/registry/Registry.js +432 -0
  97. package/dist/registry/cli.d.ts +20 -0
  98. package/dist/registry/cli.js +436 -0
  99. package/dist/registry/features.d.ts +31 -0
  100. package/dist/registry/features.js +38 -0
  101. package/dist/registry/index.d.ts +24 -0
  102. package/dist/registry/index.js +40 -0
  103. package/dist/registry/prisma.d.ts +67 -0
  104. package/dist/registry/prisma.js +399 -0
  105. package/dist/registry/stores.d.ts +21 -0
  106. package/dist/{assistants/languageModelConfigSchema.js → registry/stores.js} +55 -38
  107. package/dist/registry/types.d.ts +110 -0
  108. package/dist/{assistants/LanguageModelProvider.d.ts → registry/types.js} +6 -8
  109. package/dist/registry/workspaceKeys.d.ts +41 -0
  110. package/dist/registry/workspaceKeys.js +64 -0
  111. package/dist/roomr/health.d.ts +9 -0
  112. package/dist/{assistants/eventsHookSchema.js → roomr/health.js} +22 -18
  113. package/dist/roomr/index.d.ts +75 -0
  114. package/dist/roomr/index.js +146 -0
  115. package/dist/roomr/session.d.ts +133 -0
  116. package/dist/roomr/session.js +132 -0
  117. package/dist/session/index.d.ts +19 -0
  118. package/dist/session/index.js +35 -0
  119. package/dist/session/schema.d.ts +2140 -0
  120. package/dist/session/schema.js +448 -0
  121. package/dist/sessions/index.d.ts +96 -0
  122. package/dist/sessions/index.js +197 -0
  123. package/dist/telemetry.d.ts +76 -0
  124. package/dist/telemetry.js +360 -0
  125. package/dist/types.d.ts +3 -5
  126. package/dist/{voice/Gather.d.ts → usage/CallUsage.d.ts} +19 -18
  127. package/dist/usage/CallUsage.js +76 -0
  128. package/dist/usage/index.d.ts +22 -0
  129. package/dist/usage/index.js +38 -0
  130. package/dist/usage/meters.d.ts +113 -0
  131. package/dist/usage/meters.js +90 -0
  132. package/dist/usage/types.d.ts +159 -0
  133. package/dist/usage/types.js +84 -0
  134. package/dist/usage/usageId.d.ts +6 -0
  135. package/dist/usage/usageId.js +45 -0
  136. package/dist/utils/{findIntegrationsCredentials.js → WriteBehind.d.ts} +13 -10
  137. package/dist/utils/WriteBehind.js +64 -0
  138. package/dist/utils/index.d.ts +1 -3
  139. package/dist/utils/index.js +1 -3
  140. package/dist/utils/{createFetchSingleCallByCallId.d.ts → logUnhandledRejections.d.ts} +8 -4
  141. package/dist/{assistants/audioFiltersSchema.js → utils/logUnhandledRejections.js} +17 -12
  142. package/dist/utils/withErrorHandling.js +1 -1
  143. package/dist/validators/calls.d.ts +3 -0
  144. package/dist/validators/calls.js +12 -2
  145. package/dist/validators/identity.d.ts +37 -8
  146. package/dist/validators/identity.js +22 -3
  147. package/dist/validators/index.d.ts +1 -0
  148. package/dist/validators/index.js +1 -0
  149. package/dist/validators/sip.d.ts +40 -0
  150. package/dist/validators/sip.js +99 -0
  151. package/dist/validators/sipnet/credentials.d.ts +2 -2
  152. package/dist/validators/sipnet/domains.js +7 -7
  153. package/dist/validators/sipnet/trunks.d.ts +14 -14
  154. package/dist/validators/sipnet/trunks.js +4 -2
  155. package/dist/webhooks/Dispatcher.d.ts +87 -0
  156. package/dist/webhooks/Dispatcher.js +225 -0
  157. package/dist/webhooks/bus.d.ts +68 -0
  158. package/dist/webhooks/bus.js +178 -0
  159. package/dist/webhooks/events.d.ts +66 -0
  160. package/dist/webhooks/events.js +62 -0
  161. package/dist/webhooks/index.d.ts +23 -0
  162. package/dist/webhooks/index.js +39 -0
  163. package/dist/webhooks/prisma.d.ts +55 -0
  164. package/dist/webhooks/prisma.js +242 -0
  165. package/dist/webhooks/signing.d.ts +8 -0
  166. package/dist/webhooks/signing.js +53 -0
  167. package/package.json +25 -11
  168. package/schema/session.v1.json +871 -0
  169. package/dist/assistants/assistantSchema.d.ts +0 -739
  170. package/dist/assistants/assistantSchema.js +0 -37
  171. package/dist/assistants/conversationSettingsSchema.d.ts +0 -122
  172. package/dist/assistants/conversationSettingsSchema.js +0 -133
  173. package/dist/assistants/eventsHookSchema.d.ts +0 -38
  174. package/dist/assistants/languageModelConfigSchema.d.ts +0 -206
  175. package/dist/identity/tokenHasAccessKeyId.d.ts +0 -2
  176. package/dist/protos/voice.proto +0 -557
  177. package/dist/utils/createFetchSingleCallByCallId.js +0 -33
  178. package/dist/utils/findIntegrationsCredentials.d.ts +0 -23
  179. package/dist/utils/types.js +0 -2
  180. package/dist/voice/Dial.js +0 -20
  181. package/dist/voice/Gather.js +0 -9
  182. package/dist/voice/Mute.d.ts +0 -31
  183. package/dist/voice/Mute.js +0 -9
  184. package/dist/voice/Play.d.ts +0 -30
  185. package/dist/voice/Play.js +0 -2
  186. package/dist/voice/PlayDtmf.js +0 -2
  187. package/dist/voice/PlaybackControl.d.ts +0 -31
  188. package/dist/voice/PlaybackControl.js +0 -11
  189. package/dist/voice/Record.d.ts +0 -36
  190. package/dist/voice/Record.js +0 -7
  191. package/dist/voice/Say.d.ts +0 -28
  192. package/dist/voice/Say.js +0 -2
  193. package/dist/voice/StopSay.js +0 -2
  194. package/dist/voice/Stream.d.ts +0 -53
  195. package/dist/voice/Stream.js +0 -19
  196. package/dist/voice/StreamGather.d.ts +0 -34
  197. package/dist/voice/StreamGather.js +0 -9
  198. package/dist/voice/Verb.d.ts +0 -27
  199. package/dist/voice/Verb.js +0 -2
  200. package/dist/voice/voice.d.ts +0 -171
  201. package/dist/voice/voice.js +0 -65
  202. package/dist/{assistants → agents}/testCasesSchema.d.ts +4 -4
  203. /package/dist/{assistants → agents}/testCasesSchema.js +0 -0
  204. /package/dist/{assistants → agents}/tools/index.d.ts +0 -0
  205. /package/dist/{assistants → agents}/tools/index.js +0 -0
  206. /package/dist/{assistants → agents}/tools/propertySchema.d.ts +0 -0
  207. /package/dist/{assistants → agents}/tools/propertySchema.js +0 -0
  208. /package/dist/{assistants → agents}/tools/toolSchema.d.ts +0 -0
  209. /package/dist/{assistants → agents}/tools/toolSchema.js +0 -0
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CallUsage = void 0;
4
+ /**
5
+ * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
6
+ * http://github.com/fonoster/fonoster
7
+ *
8
+ * This file is part of Fonoster
9
+ *
10
+ * Licensed under the MIT License (the "License");
11
+ * you may not use this file except in compliance with
12
+ * the License. You may obtain a copy of the License at
13
+ *
14
+ * https://opensource.org/licenses/MIT
15
+ *
16
+ * Unless required by applicable law or agreed to in writing, software
17
+ * distributed under the License is distributed on an "AS IS" BASIS,
18
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ * See the License for the specific language governing permissions and
20
+ * limitations under the License.
21
+ */
22
+ const meters_1 = require("./meters");
23
+ const types_1 = require("./types");
24
+ /**
25
+ * A call's usage, accumulated in memory while it runs (design D1). One entry per meter, provider,
26
+ * model and key source; seconds are kept exact and rounded up only when lines are taken.
27
+ */
28
+ class CallUsage {
29
+ constructor() {
30
+ this.entries = new Map();
31
+ }
32
+ add(line) {
33
+ var _a, _b, _c;
34
+ const parsed = (0, types_1.parseUsageLine)(line);
35
+ const key = [
36
+ parsed.meter,
37
+ (_a = parsed.provider) !== null && _a !== void 0 ? _a : "",
38
+ (_b = parsed.model) !== null && _b !== void 0 ? _b : "",
39
+ (_c = parsed.keySource) !== null && _c !== void 0 ? _c : ""
40
+ ].join("|");
41
+ const entry = this.entries.get(key);
42
+ if (entry)
43
+ entry.quantity += parsed.quantity;
44
+ else
45
+ this.entries.set(key, {
46
+ meter: parsed.meter,
47
+ provider: parsed.provider,
48
+ model: parsed.model,
49
+ keySource: parsed.keySource,
50
+ quantity: parsed.quantity
51
+ });
52
+ }
53
+ /** Adds seconds of a meter measured as a duration in milliseconds. */
54
+ addMillis(key, ms) {
55
+ if (ms > 0)
56
+ this.add(Object.assign(Object.assign({}, key), { quantity: ms / 1000 }));
57
+ }
58
+ lines() {
59
+ return Array.from(this.entries.values())
60
+ .map((e) => {
61
+ const quantity = (0, meters_1.meterOf)(e.meter).unit === "second"
62
+ ? Math.ceil(e.quantity - 1e-9)
63
+ : Math.round(e.quantity);
64
+ const line = { meter: e.meter, quantity };
65
+ if (e.provider)
66
+ line.provider = e.provider;
67
+ if (e.model)
68
+ line.model = e.model;
69
+ if (e.keySource)
70
+ line.keySource = e.keySource;
71
+ return line;
72
+ })
73
+ .filter((line) => line.quantity > 0);
74
+ }
75
+ }
76
+ exports.CallUsage = CallUsage;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
3
+ * http://github.com/fonoster/fonoster
4
+ *
5
+ * This file is part of Fonoster
6
+ *
7
+ * Licensed under the MIT License (the "License");
8
+ * you may not use this file except in compliance with
9
+ * the License. You may obtain a copy of the License at
10
+ *
11
+ * https://opensource.org/licenses/MIT
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ export * from "./CallUsage";
20
+ export * from "./meters";
21
+ export * from "./types";
22
+ export * from "./usageId";
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ /**
18
+ * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
19
+ * http://github.com/fonoster/fonoster
20
+ *
21
+ * This file is part of Fonoster
22
+ *
23
+ * Licensed under the MIT License (the "License");
24
+ * you may not use this file except in compliance with
25
+ * the License. You may obtain a copy of the License at
26
+ *
27
+ * https://opensource.org/licenses/MIT
28
+ *
29
+ * Unless required by applicable law or agreed to in writing, software
30
+ * distributed under the License is distributed on an "AS IS" BASIS,
31
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
32
+ * See the License for the specific language governing permissions and
33
+ * limitations under the License.
34
+ */
35
+ __exportStar(require("./CallUsage"), exports);
36
+ __exportStar(require("./meters"), exports);
37
+ __exportStar(require("./types"), exports);
38
+ __exportStar(require("./usageId"), exports);
@@ -0,0 +1,113 @@
1
+ /**
2
+ * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
3
+ * http://github.com/fonoster/fonoster
4
+ *
5
+ * This file is part of Fonoster
6
+ *
7
+ * Licensed under the MIT License (the "License");
8
+ * you may not use this file except in compliance with
9
+ * the License. You may obtain a copy of the License at
10
+ *
11
+ * https://opensource.org/licenses/MIT
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ /** The unit a meter counts in. */
20
+ export type UsageUnit = "second" | "character" | "token" | "count" | "byte";
21
+ /** How a meter's lines combine: added up, or a point-in-time reading (take the latest). */
22
+ export type UsageAggregation = "sum" | "snapshot";
23
+ /** The component that measures a meter. */
24
+ export type UsageReporter = "appbridge" | "autopilot" | "apiserver";
25
+ export type MeterDefinition = {
26
+ unit: UsageUnit;
27
+ aggregation: UsageAggregation;
28
+ reporter: UsageReporter;
29
+ /** A third-party vendor does the work, so every line says whose key was used. */
30
+ vendor: boolean;
31
+ };
32
+ /**
33
+ * The declared meters (add-usage-metering, usage-metering spec). Usage for any other name is
34
+ * rejected. Adding a meter is adding an entry here.
35
+ */
36
+ export declare const METERS: {
37
+ readonly "call.seconds": {
38
+ readonly unit: "second";
39
+ readonly aggregation: "sum";
40
+ readonly reporter: "appbridge";
41
+ readonly vendor: false;
42
+ };
43
+ readonly "stt.seconds": {
44
+ readonly unit: "second";
45
+ readonly aggregation: "sum";
46
+ readonly reporter: "appbridge";
47
+ readonly vendor: true;
48
+ };
49
+ readonly "tts.characters": {
50
+ readonly unit: "character";
51
+ readonly aggregation: "sum";
52
+ readonly reporter: "appbridge";
53
+ readonly vendor: true;
54
+ };
55
+ readonly "llm.tokens.in": {
56
+ readonly unit: "token";
57
+ readonly aggregation: "sum";
58
+ readonly reporter: "autopilot";
59
+ readonly vendor: true;
60
+ };
61
+ readonly "llm.tokens.out": {
62
+ readonly unit: "token";
63
+ readonly aggregation: "sum";
64
+ readonly reporter: "autopilot";
65
+ readonly vendor: true;
66
+ };
67
+ readonly "llm.tokens.cached": {
68
+ readonly unit: "token";
69
+ readonly aggregation: "sum";
70
+ readonly reporter: "autopilot";
71
+ readonly vendor: true;
72
+ };
73
+ readonly "embedding.tokens": {
74
+ readonly unit: "token";
75
+ readonly aggregation: "sum";
76
+ readonly reporter: "autopilot";
77
+ readonly vendor: true;
78
+ };
79
+ readonly "nc.seconds": {
80
+ readonly unit: "second";
81
+ readonly aggregation: "sum";
82
+ readonly reporter: "appbridge";
83
+ readonly vendor: true;
84
+ };
85
+ readonly "amd.detections": {
86
+ readonly unit: "count";
87
+ readonly aggregation: "sum";
88
+ readonly reporter: "appbridge";
89
+ readonly vendor: false;
90
+ };
91
+ readonly "amd.seconds": {
92
+ readonly unit: "second";
93
+ readonly aggregation: "sum";
94
+ readonly reporter: "appbridge";
95
+ readonly vendor: false;
96
+ };
97
+ readonly "recording.seconds": {
98
+ readonly unit: "second";
99
+ readonly aggregation: "sum";
100
+ readonly reporter: "appbridge";
101
+ readonly vendor: false;
102
+ };
103
+ readonly "storage.bytes": {
104
+ readonly unit: "byte";
105
+ readonly aggregation: "snapshot";
106
+ readonly reporter: "apiserver";
107
+ readonly vendor: false;
108
+ };
109
+ };
110
+ export type MeterName = keyof typeof METERS;
111
+ export declare const METER_NAMES: MeterName[];
112
+ export declare function isMeter(name: string): name is MeterName;
113
+ export declare function meterOf(name: MeterName): MeterDefinition;
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.METER_NAMES = exports.METERS = void 0;
4
+ exports.isMeter = isMeter;
5
+ exports.meterOf = meterOf;
6
+ /**
7
+ * The declared meters (add-usage-metering, usage-metering spec). Usage for any other name is
8
+ * rejected. Adding a meter is adding an entry here.
9
+ */
10
+ exports.METERS = {
11
+ "call.seconds": {
12
+ unit: "second",
13
+ aggregation: "sum",
14
+ reporter: "appbridge",
15
+ vendor: false
16
+ },
17
+ "stt.seconds": {
18
+ unit: "second",
19
+ aggregation: "sum",
20
+ reporter: "appbridge",
21
+ vendor: true
22
+ },
23
+ "tts.characters": {
24
+ unit: "character",
25
+ aggregation: "sum",
26
+ reporter: "appbridge",
27
+ vendor: true
28
+ },
29
+ "llm.tokens.in": {
30
+ unit: "token",
31
+ aggregation: "sum",
32
+ reporter: "autopilot",
33
+ vendor: true
34
+ },
35
+ "llm.tokens.out": {
36
+ unit: "token",
37
+ aggregation: "sum",
38
+ reporter: "autopilot",
39
+ vendor: true
40
+ },
41
+ "llm.tokens.cached": {
42
+ unit: "token",
43
+ aggregation: "sum",
44
+ reporter: "autopilot",
45
+ vendor: true
46
+ },
47
+ "embedding.tokens": {
48
+ unit: "token",
49
+ aggregation: "sum",
50
+ reporter: "autopilot",
51
+ vendor: true
52
+ },
53
+ "nc.seconds": {
54
+ unit: "second",
55
+ aggregation: "sum",
56
+ reporter: "appbridge",
57
+ vendor: true
58
+ },
59
+ "amd.detections": {
60
+ unit: "count",
61
+ aggregation: "sum",
62
+ reporter: "appbridge",
63
+ vendor: false
64
+ },
65
+ "amd.seconds": {
66
+ unit: "second",
67
+ aggregation: "sum",
68
+ reporter: "appbridge",
69
+ vendor: false
70
+ },
71
+ "recording.seconds": {
72
+ unit: "second",
73
+ aggregation: "sum",
74
+ reporter: "appbridge",
75
+ vendor: false
76
+ },
77
+ "storage.bytes": {
78
+ unit: "byte",
79
+ aggregation: "snapshot",
80
+ reporter: "apiserver",
81
+ vendor: false
82
+ }
83
+ };
84
+ exports.METER_NAMES = Object.keys(exports.METERS);
85
+ function isMeter(name) {
86
+ return Object.prototype.hasOwnProperty.call(exports.METERS, name);
87
+ }
88
+ function meterOf(name) {
89
+ return exports.METERS[name];
90
+ }
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
3
+ * http://github.com/fonoster/fonoster
4
+ *
5
+ * This file is part of Fonoster
6
+ *
7
+ * Licensed under the MIT License (the "License");
8
+ * you may not use this file except in compliance with
9
+ * the License. You may obtain a copy of the License at
10
+ *
11
+ * https://opensource.org/licenses/MIT
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ import { z } from "zod";
20
+ import { MeterName } from "./meters";
21
+ export declare const KEY_SOURCES: readonly ["platform", "workspace"];
22
+ export type KeySource = (typeof KEY_SOURCES)[number];
23
+ export declare const ORIGINS: readonly ["call", "browser_test", "eval", "api"];
24
+ export type UsageOrigin = (typeof ORIGINS)[number];
25
+ export declare const REGION_KINDS: readonly ["public", "private"];
26
+ export type RegionKind = (typeof REGION_KINDS)[number];
27
+ /** One quantity of one meter. Facts only: strict, so no price or billable flag can ride along. */
28
+ export declare const usageLineSchema: z.ZodEffects<z.ZodObject<{
29
+ meter: z.ZodEffects<z.ZodString, "llm.tokens.in" | "llm.tokens.out" | "llm.tokens.cached" | "embedding.tokens" | "call.seconds" | "stt.seconds" | "tts.characters" | "nc.seconds" | "amd.detections" | "amd.seconds" | "recording.seconds" | "storage.bytes", string>;
30
+ quantity: z.ZodNumber;
31
+ provider: z.ZodOptional<z.ZodString>;
32
+ model: z.ZodOptional<z.ZodString>;
33
+ keySource: z.ZodOptional<z.ZodEnum<["platform", "workspace"]>>;
34
+ }, "strict", z.ZodTypeAny, {
35
+ model?: string;
36
+ provider?: string;
37
+ meter?: "llm.tokens.in" | "llm.tokens.out" | "llm.tokens.cached" | "embedding.tokens" | "call.seconds" | "stt.seconds" | "tts.characters" | "nc.seconds" | "amd.detections" | "amd.seconds" | "recording.seconds" | "storage.bytes";
38
+ quantity?: number;
39
+ keySource?: "platform" | "workspace";
40
+ }, {
41
+ model?: string;
42
+ provider?: string;
43
+ meter?: string;
44
+ quantity?: number;
45
+ keySource?: "platform" | "workspace";
46
+ }>, {
47
+ model?: string;
48
+ provider?: string;
49
+ meter?: "llm.tokens.in" | "llm.tokens.out" | "llm.tokens.cached" | "embedding.tokens" | "call.seconds" | "stt.seconds" | "tts.characters" | "nc.seconds" | "amd.detections" | "amd.seconds" | "recording.seconds" | "storage.bytes";
50
+ quantity?: number;
51
+ keySource?: "platform" | "workspace";
52
+ }, {
53
+ model?: string;
54
+ provider?: string;
55
+ meter?: string;
56
+ quantity?: number;
57
+ keySource?: "platform" | "workspace";
58
+ }>;
59
+ /** A usage line with its attribution, as stored and as published on `usage.>`. */
60
+ export declare const usageEventSchema: z.ZodEffects<z.ZodObject<{
61
+ id: z.ZodString;
62
+ /** Resolved from the workspace at ingest when the reporter does not know it. */
63
+ ownerRef: z.ZodOptional<z.ZodString>;
64
+ workspaceRef: z.ZodString;
65
+ appRef: z.ZodOptional<z.ZodString>;
66
+ callRef: z.ZodOptional<z.ZodString>;
67
+ region: z.ZodString;
68
+ regionKind: z.ZodEnum<["public", "private"]>;
69
+ origin: z.ZodEnum<["call", "browser_test", "eval", "api"]>;
70
+ occurredAt: z.ZodString;
71
+ meter: z.ZodEffects<z.ZodString, "llm.tokens.in" | "llm.tokens.out" | "llm.tokens.cached" | "embedding.tokens" | "call.seconds" | "stt.seconds" | "tts.characters" | "nc.seconds" | "amd.detections" | "amd.seconds" | "recording.seconds" | "storage.bytes", string>;
72
+ quantity: z.ZodNumber;
73
+ provider: z.ZodOptional<z.ZodString>;
74
+ model: z.ZodOptional<z.ZodString>;
75
+ keySource: z.ZodOptional<z.ZodEnum<["platform", "workspace"]>>;
76
+ }, "strict", z.ZodTypeAny, {
77
+ model?: string;
78
+ provider?: string;
79
+ id?: string;
80
+ appRef?: string;
81
+ region?: string;
82
+ callRef?: string;
83
+ meter?: "llm.tokens.in" | "llm.tokens.out" | "llm.tokens.cached" | "embedding.tokens" | "call.seconds" | "stt.seconds" | "tts.characters" | "nc.seconds" | "amd.detections" | "amd.seconds" | "recording.seconds" | "storage.bytes";
84
+ quantity?: number;
85
+ keySource?: "platform" | "workspace";
86
+ origin?: "call" | "browser_test" | "eval" | "api";
87
+ workspaceRef?: string;
88
+ ownerRef?: string;
89
+ regionKind?: "public" | "private";
90
+ occurredAt?: string;
91
+ }, {
92
+ model?: string;
93
+ provider?: string;
94
+ id?: string;
95
+ appRef?: string;
96
+ region?: string;
97
+ callRef?: string;
98
+ meter?: string;
99
+ quantity?: number;
100
+ keySource?: "platform" | "workspace";
101
+ origin?: "call" | "browser_test" | "eval" | "api";
102
+ workspaceRef?: string;
103
+ ownerRef?: string;
104
+ regionKind?: "public" | "private";
105
+ occurredAt?: string;
106
+ }>, {
107
+ model?: string;
108
+ provider?: string;
109
+ id?: string;
110
+ appRef?: string;
111
+ region?: string;
112
+ callRef?: string;
113
+ meter?: "llm.tokens.in" | "llm.tokens.out" | "llm.tokens.cached" | "embedding.tokens" | "call.seconds" | "stt.seconds" | "tts.characters" | "nc.seconds" | "amd.detections" | "amd.seconds" | "recording.seconds" | "storage.bytes";
114
+ quantity?: number;
115
+ keySource?: "platform" | "workspace";
116
+ origin?: "call" | "browser_test" | "eval" | "api";
117
+ workspaceRef?: string;
118
+ ownerRef?: string;
119
+ regionKind?: "public" | "private";
120
+ occurredAt?: string;
121
+ }, {
122
+ model?: string;
123
+ provider?: string;
124
+ id?: string;
125
+ appRef?: string;
126
+ region?: string;
127
+ callRef?: string;
128
+ meter?: string;
129
+ quantity?: number;
130
+ keySource?: "platform" | "workspace";
131
+ origin?: "call" | "browser_test" | "eval" | "api";
132
+ workspaceRef?: string;
133
+ ownerRef?: string;
134
+ regionKind?: "public" | "private";
135
+ occurredAt?: string;
136
+ }>;
137
+ export type UsageLine = {
138
+ meter: MeterName;
139
+ quantity: number;
140
+ provider?: string;
141
+ model?: string;
142
+ keySource?: KeySource;
143
+ };
144
+ export type UsageEvent = UsageLine & {
145
+ id: string;
146
+ ownerRef?: string;
147
+ workspaceRef: string;
148
+ appRef?: string;
149
+ callRef?: string;
150
+ region: string;
151
+ regionKind: RegionKind;
152
+ origin: UsageOrigin;
153
+ occurredAt: string;
154
+ };
155
+ /** A usage line or event that failed validation; the message names every problem. */
156
+ export declare class InvalidUsageError extends Error {
157
+ }
158
+ export declare function parseUsageLine(input: unknown): UsageLine;
159
+ export declare function parseUsageEvent(input: unknown): UsageEvent;
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InvalidUsageError = exports.usageEventSchema = exports.usageLineSchema = exports.REGION_KINDS = exports.ORIGINS = exports.KEY_SOURCES = void 0;
4
+ exports.parseUsageLine = parseUsageLine;
5
+ exports.parseUsageEvent = parseUsageEvent;
6
+ /**
7
+ * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
8
+ * http://github.com/fonoster/fonoster
9
+ *
10
+ * This file is part of Fonoster
11
+ *
12
+ * Licensed under the MIT License (the "License");
13
+ * you may not use this file except in compliance with
14
+ * the License. You may obtain a copy of the License at
15
+ *
16
+ * https://opensource.org/licenses/MIT
17
+ *
18
+ * Unless required by applicable law or agreed to in writing, software
19
+ * distributed under the License is distributed on an "AS IS" BASIS,
20
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
+ * See the License for the specific language governing permissions and
22
+ * limitations under the License.
23
+ */
24
+ const zod_1 = require("zod");
25
+ const meters_1 = require("./meters");
26
+ exports.KEY_SOURCES = ["platform", "workspace"];
27
+ exports.ORIGINS = ["call", "browser_test", "eval", "api"];
28
+ exports.REGION_KINDS = ["public", "private"];
29
+ const lineFields = {
30
+ meter: zod_1.z
31
+ .string()
32
+ .refine(meters_1.isMeter, (m) => ({ message: `undeclared meter "${m}"` })),
33
+ quantity: zod_1.z.number().finite().nonnegative(),
34
+ provider: zod_1.z.string().min(1).optional(),
35
+ model: zod_1.z.string().min(1).optional(),
36
+ keySource: zod_1.z.enum(exports.KEY_SOURCES).optional()
37
+ };
38
+ function checkKeySource(line, ctx) {
39
+ if (!line.meter || !(0, meters_1.isMeter)(line.meter))
40
+ return;
41
+ const vendor = meters_1.METERS[line.meter].vendor;
42
+ if (vendor && !line.keySource)
43
+ ctx.addIssue({
44
+ code: zod_1.z.ZodIssueCode.custom,
45
+ path: ["keySource"],
46
+ message: `${line.meter} needs a keySource`
47
+ });
48
+ if (!vendor && line.keySource)
49
+ ctx.addIssue({
50
+ code: zod_1.z.ZodIssueCode.custom,
51
+ path: ["keySource"],
52
+ message: `${line.meter} is not a vendor meter and takes no keySource`
53
+ });
54
+ }
55
+ /** One quantity of one meter. Facts only: strict, so no price or billable flag can ride along. */
56
+ exports.usageLineSchema = zod_1.z
57
+ .object(lineFields)
58
+ .strict()
59
+ .superRefine(checkKeySource);
60
+ /** A usage line with its attribution, as stored and as published on `usage.>`. */
61
+ exports.usageEventSchema = zod_1.z
62
+ .object(Object.assign(Object.assign({}, lineFields), { id: zod_1.z.string().regex(/^usg_[a-z2-7]{26}$/),
63
+ /** Resolved from the workspace at ingest when the reporter does not know it. */
64
+ ownerRef: zod_1.z.string().min(1).optional(), workspaceRef: zod_1.z.string().min(1), appRef: zod_1.z.string().min(1).optional(), callRef: zod_1.z.string().min(1).optional(), region: zod_1.z.string().min(1), regionKind: zod_1.z.enum(exports.REGION_KINDS), origin: zod_1.z.enum(exports.ORIGINS), occurredAt: zod_1.z.string().datetime() }))
65
+ .strict()
66
+ .superRefine(checkKeySource);
67
+ /** A usage line or event that failed validation; the message names every problem. */
68
+ class InvalidUsageError extends Error {
69
+ }
70
+ exports.InvalidUsageError = InvalidUsageError;
71
+ function parseWith(schema, input) {
72
+ const result = schema.safeParse(input);
73
+ if (result.success)
74
+ return result.data;
75
+ throw new InvalidUsageError(result.error.issues
76
+ .map((i) => i.path.length ? `${i.path.join(".")}: ${i.message}` : i.message)
77
+ .join("; "));
78
+ }
79
+ function parseUsageLine(input) {
80
+ return parseWith(exports.usageLineSchema, input);
81
+ }
82
+ function parseUsageEvent(input) {
83
+ return parseWith(exports.usageEventSchema, input);
84
+ }
@@ -0,0 +1,6 @@
1
+ import { UsageLine } from "./types";
2
+ /**
3
+ * The id of a usage line (design D7): derived from what it measures, so reporting the same usage
4
+ * twice yields the same id. `scope` is the callRef, the eval step key, or workspaceRef + day.
5
+ */
6
+ export declare function usageId(scope: string, line: Pick<UsageLine, "meter" | "provider" | "model" | "keySource">): string;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.usageId = usageId;
4
+ /**
5
+ * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
6
+ * http://github.com/fonoster/fonoster
7
+ *
8
+ * This file is part of Fonoster
9
+ *
10
+ * Licensed under the MIT License (the "License");
11
+ * you may not use this file except in compliance with
12
+ * the License. You may obtain a copy of the License at
13
+ *
14
+ * https://opensource.org/licenses/MIT
15
+ *
16
+ * Unless required by applicable law or agreed to in writing, software
17
+ * distributed under the License is distributed on an "AS IS" BASIS,
18
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ * See the License for the specific language governing permissions and
20
+ * limitations under the License.
21
+ */
22
+ const node_crypto_1 = require("node:crypto");
23
+ const ALPHABET = "abcdefghijklmnopqrstuvwxyz234567";
24
+ function base32(bytes) {
25
+ var _a;
26
+ const bits = Array.from(bytes, (b) => b.toString(2).padStart(8, "0")).join("");
27
+ return ((_a = bits.match(/.{1,5}/g)) !== null && _a !== void 0 ? _a : [])
28
+ .map((chunk) => ALPHABET[parseInt(chunk.padEnd(5, "0"), 2)])
29
+ .join("");
30
+ }
31
+ /**
32
+ * The id of a usage line (design D7): derived from what it measures, so reporting the same usage
33
+ * twice yields the same id. `scope` is the callRef, the eval step key, or workspaceRef + day.
34
+ */
35
+ function usageId(scope, line) {
36
+ var _a, _b, _c;
37
+ const key = [
38
+ scope,
39
+ line.meter,
40
+ (_a = line.provider) !== null && _a !== void 0 ? _a : "",
41
+ (_b = line.model) !== null && _b !== void 0 ? _b : "",
42
+ (_c = line.keySource) !== null && _c !== void 0 ? _c : ""
43
+ ].join("|");
44
+ return ("usg_" + base32((0, node_crypto_1.createHash)("sha256").update(key).digest()).slice(0, 26));
45
+ }
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.findIntegrationsCredentials = findIntegrationsCredentials;
4
1
  /**
5
2
  * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
6
3
  * http://github.com/fonoster/fonoster
@@ -19,11 +16,17 @@ exports.findIntegrationsCredentials = findIntegrationsCredentials;
19
16
  * See the License for the specific language governing permissions and
20
17
  * limitations under the License.
21
18
  */
22
- function findIntegrationsCredentials(integrations, engine) {
23
- var _a;
24
- const integration = (_a = integrations.find((i) => i.productRef === engine)) === null || _a === void 0 ? void 0 : _a.credentials;
25
- if (!integration) {
26
- throw new Error(`Integration ${engine} not found`);
27
- }
28
- return integration;
19
+ /**
20
+ * Runs database writes one after another, in the order they were queued, behind a synchronous
21
+ * store interface (the registry and webhook stores are synchronous; see P-B1 in
22
+ * add-provider-registry/build-log.md). `flush()` waits for every queued write and throws the
23
+ * first failure.
24
+ */
25
+ export declare class WriteBehind {
26
+ private readonly onError?;
27
+ private tail;
28
+ private failure?;
29
+ constructor(onError?: (e: unknown) => void);
30
+ push(write: () => Promise<unknown>): void;
31
+ flush(): Promise<void>;
29
32
  }