@nylorun/runtime 0.28.0-beta → 0.29.0-beta

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.
@@ -0,0 +1,4 @@
1
+ ALTER TABLE "nylorun"."model_usage" ADD COLUMN "cost_input_usd" double precision;--> statement-breakpoint
2
+ ALTER TABLE "nylorun"."model_usage" ADD COLUMN "cost_cache_read_usd" double precision;--> statement-breakpoint
3
+ ALTER TABLE "nylorun"."model_usage" ADD COLUMN "cost_cache_write_usd" double precision;--> statement-breakpoint
4
+ ALTER TABLE "nylorun"."model_usage" ADD COLUMN "cost_output_usd" double precision;
@@ -260,6 +260,13 @@
260
260
  "when": 1792172016681,
261
261
  "tag": "0036_t5_memories",
262
262
  "breakpoints": true
263
+ },
264
+ {
265
+ "idx": 37,
266
+ "version": "7",
267
+ "when": 1792238141315,
268
+ "tag": "0037_model_usage_cost_split",
269
+ "breakpoints": true
263
270
  }
264
271
  ]
265
272
  }
@@ -32,6 +32,18 @@ function grantsWhere(column, grants) {
32
32
  function accessWhere(access) {
33
33
  return and(access.owner === undefined ? undefined : eq(sessions.ownerUserId, access.owner), access.agents === undefined ? undefined : grantsWhere(sessions.agentId, access.agents));
34
34
  }
35
+ /** A row's cost by token kind, when the adapter kept it (migration 0037). */
36
+ function costSplitOf(row) {
37
+ const { costInputUsd, costCacheReadUsd, costCacheWriteUsd, costOutputUsd } = row;
38
+ if (costInputUsd === null || costCacheReadUsd === null || costCacheWriteUsd === null || costOutputUsd === null)
39
+ return null;
40
+ return {
41
+ input: costInputUsd,
42
+ cacheRead: costCacheReadUsd,
43
+ cacheWrite: costCacheWriteUsd,
44
+ output: costOutputUsd,
45
+ };
46
+ }
35
47
  function publicCall(row) {
36
48
  return {
37
49
  id: row.id,
@@ -42,6 +54,8 @@ function publicCall(row) {
42
54
  provider: row.provider,
43
55
  model: row.model,
44
56
  at: row.createdAt,
57
+ startedAt: row.startedAt,
58
+ endedAt: row.endedAt,
45
59
  outcome: "completed",
46
60
  usage: {
47
61
  inputTokens: row.inputTokens,
@@ -54,6 +68,7 @@ function publicCall(row) {
54
68
  duplicate: row.duplicate,
55
69
  tokensReported: row.tokensReported,
56
70
  costKnown: row.costKnown,
71
+ costSplit: costSplitOf(row),
57
72
  },
58
73
  };
59
74
  }
@@ -225,11 +240,26 @@ export function createPostgresReadStore(source, tenantId) {
225
240
  unpricedCalls: sql `count(*) filter (where ${modelUsage.costKnown} = false)`.mapWith(Number),
226
241
  unreportedCalls: sql `count(*) filter (where ${modelUsage.tokensReported} = false)`.mapWith(Number),
227
242
  unknownQualityCalls: sql `count(*) filter (where ${modelUsage.tokensReported} is null or ${modelUsage.costKnown} is null)`.mapWith(Number),
243
+ costInput: sum(modelUsage.costInputUsd),
244
+ costCacheRead: sum(modelUsage.costCacheReadUsd),
245
+ costCacheWrite: sum(modelUsage.costCacheWriteUsd),
246
+ costOutput: sum(modelUsage.costOutputUsd),
247
+ splitCalls: sql `count(${modelUsage.costInputUsd})`.mapWith(Number),
248
+ // The gate's timing is ISO text; a row timed before migration 0022 has none.
249
+ modelTimeMs: sql `coalesce(round(sum(extract(epoch from (${modelUsage.endedAt}::timestamptz - ${modelUsage.startedAt}::timestamptz)) * 1000)), 0)`.mapWith(Number),
250
+ timedCalls: sql `count(*) filter (where ${modelUsage.startedAt} is not null and ${modelUsage.endedAt} is not null)`.mapWith(Number),
228
251
  })
229
252
  .from(modelUsage)
230
253
  .where(and(eq(modelUsage.sessionId, id), turnId === undefined ? undefined : eq(modelUsage.turnId, turnId)));
254
+ const { costInput, costCacheRead, costCacheWrite, costOutput, ...rest } = totals;
231
255
  return {
232
- ...totals,
256
+ ...rest,
257
+ costSplit: {
258
+ input: costInput,
259
+ cacheRead: costCacheRead,
260
+ cacheWrite: costCacheWrite,
261
+ output: costOutput,
262
+ },
233
263
  sessionId: id,
234
264
  turnId: turnId ?? null,
235
265
  asOf: new Date().toISOString(),
@@ -1793,7 +1793,7 @@ export declare const agentTriggers: import("drizzle-orm/pg-core").PgTableWithCol
1793
1793
  }>;
1794
1794
  /**
1795
1795
  * An Agent's memories (track T5, D72): one row per Markdown file under `/memories`, its content
1796
- * inline (the Runtime limit `memoryBytes`, 100 KB by default, bounds it). `version` counts the
1796
+ * inline (the Runtime limit `memoryBytes`, 100 KiB by default, bounds it). `version` counts the
1797
1797
  * changes to this path; `description` is its frontmatter's, for the pinned index. A write locks the
1798
1798
  * one row it changes, so writes to different memories never wait on each other.
1799
1799
  */
@@ -3401,7 +3401,8 @@ export declare const signingKeys: import("drizzle-orm/pg-core").PgTableWithColum
3401
3401
  * flagged `duplicate`; both were billed. Budgets read their spend from it. Token counts are 0
3402
3402
  * when the provider sent none. `startedAt`, `endedAt` and `firstTokenMs` are the gate's own
3403
3403
  * timing of the call (R7.1, migration 0022); null on rows written before, and `firstTokenMs`
3404
- * when the provider streamed nothing.
3404
+ * when the provider streamed nothing. The `cost*Usd` columns split `costUsd` by token kind, at the
3405
+ * prices the adapter applied (migration 0037); null on rows written before.
3405
3406
  */
3406
3407
  export declare const modelUsage: import("drizzle-orm/pg-core").PgTableWithColumns<{
3407
3408
  name: "model_usage";
@@ -3793,6 +3794,74 @@ export declare const modelUsage: import("drizzle-orm/pg-core").PgTableWithColumn
3793
3794
  identity: undefined;
3794
3795
  generated: undefined;
3795
3796
  }, {}, {}>;
3797
+ costInputUsd: import("drizzle-orm/pg-core").PgColumn<{
3798
+ name: "costInputUsd";
3799
+ tableName: "model_usage";
3800
+ dataType: "number";
3801
+ columnType: "PgDoublePrecision";
3802
+ data: number;
3803
+ driverParam: string | number;
3804
+ notNull: false;
3805
+ hasDefault: false;
3806
+ isPrimaryKey: false;
3807
+ isAutoincrement: false;
3808
+ hasRuntimeDefault: false;
3809
+ enumValues: undefined;
3810
+ baseColumn: never;
3811
+ identity: undefined;
3812
+ generated: undefined;
3813
+ }, {}, {}>;
3814
+ costCacheReadUsd: import("drizzle-orm/pg-core").PgColumn<{
3815
+ name: "costCacheReadUsd";
3816
+ tableName: "model_usage";
3817
+ dataType: "number";
3818
+ columnType: "PgDoublePrecision";
3819
+ data: number;
3820
+ driverParam: string | number;
3821
+ notNull: false;
3822
+ hasDefault: false;
3823
+ isPrimaryKey: false;
3824
+ isAutoincrement: false;
3825
+ hasRuntimeDefault: false;
3826
+ enumValues: undefined;
3827
+ baseColumn: never;
3828
+ identity: undefined;
3829
+ generated: undefined;
3830
+ }, {}, {}>;
3831
+ costCacheWriteUsd: import("drizzle-orm/pg-core").PgColumn<{
3832
+ name: "costCacheWriteUsd";
3833
+ tableName: "model_usage";
3834
+ dataType: "number";
3835
+ columnType: "PgDoublePrecision";
3836
+ data: number;
3837
+ driverParam: string | number;
3838
+ notNull: false;
3839
+ hasDefault: false;
3840
+ isPrimaryKey: false;
3841
+ isAutoincrement: false;
3842
+ hasRuntimeDefault: false;
3843
+ enumValues: undefined;
3844
+ baseColumn: never;
3845
+ identity: undefined;
3846
+ generated: undefined;
3847
+ }, {}, {}>;
3848
+ costOutputUsd: import("drizzle-orm/pg-core").PgColumn<{
3849
+ name: "costOutputUsd";
3850
+ tableName: "model_usage";
3851
+ dataType: "number";
3852
+ columnType: "PgDoublePrecision";
3853
+ data: number;
3854
+ driverParam: string | number;
3855
+ notNull: false;
3856
+ hasDefault: false;
3857
+ isPrimaryKey: false;
3858
+ isAutoincrement: false;
3859
+ hasRuntimeDefault: false;
3860
+ enumValues: undefined;
3861
+ baseColumn: never;
3862
+ identity: undefined;
3863
+ generated: undefined;
3864
+ }, {}, {}>;
3796
3865
  };
3797
3866
  dialect: 'pg';
3798
3867
  }>;
@@ -5656,10 +5725,14 @@ export type EnvironmentRowColumns = typeof agents.$inferSelect;
5656
5725
  export type ArtifactRow = typeof artifacts.$inferSelect;
5657
5726
  export type ArtifactVersionRow = typeof artifactVersions.$inferSelect;
5658
5727
  export type DefinitionFileRow = typeof definitionFiles.$inferSelect;
5659
- export type ModelUsageWrite = Omit<ModelUsageRow, "duplicate" | "txid" | "tokensReported" | "costKnown" | "startedAt" | "endedAt" | "firstTokenMs"> & {
5728
+ export type ModelUsageWrite = Omit<ModelUsageRow, "duplicate" | "txid" | "tokensReported" | "costKnown" | "startedAt" | "endedAt" | "firstTokenMs" | "costInputUsd" | "costCacheReadUsd" | "costCacheWriteUsd" | "costOutputUsd"> & {
5660
5729
  tokensReported?: boolean | null;
5661
5730
  costKnown?: boolean | null;
5662
5731
  startedAt?: string | null;
5663
5732
  endedAt?: string | null;
5664
5733
  firstTokenMs?: number | null;
5734
+ costInputUsd?: number | null;
5735
+ costCacheReadUsd?: number | null;
5736
+ costCacheWriteUsd?: number | null;
5737
+ costOutputUsd?: number | null;
5665
5738
  };
@@ -251,7 +251,7 @@ export const agentTriggers = nylorun.table("agent_triggers", {
251
251
  ]);
252
252
  /**
253
253
  * An Agent's memories (track T5, D72): one row per Markdown file under `/memories`, its content
254
- * inline (the Runtime limit `memoryBytes`, 100 KB by default, bounds it). `version` counts the
254
+ * inline (the Runtime limit `memoryBytes`, 100 KiB by default, bounds it). `version` counts the
255
255
  * changes to this path; `description` is its frontmatter's, for the pinned index. A write locks the
256
256
  * one row it changes, so writes to different memories never wait on each other.
257
257
  */
@@ -425,7 +425,8 @@ export const signingKeys = nylorun.table("signing_keys", {
425
425
  * flagged `duplicate`; both were billed. Budgets read their spend from it. Token counts are 0
426
426
  * when the provider sent none. `startedAt`, `endedAt` and `firstTokenMs` are the gate's own
427
427
  * timing of the call (R7.1, migration 0022); null on rows written before, and `firstTokenMs`
428
- * when the provider streamed nothing.
428
+ * when the provider streamed nothing. The `cost*Usd` columns split `costUsd` by token kind, at the
429
+ * prices the adapter applied (migration 0037); null on rows written before.
429
430
  */
430
431
  export const modelUsage = nylorun.table("model_usage", {
431
432
  id: textC().primaryKey(),
@@ -459,6 +460,14 @@ export const modelUsage = nylorun.table("model_usage", {
459
460
  endedAt: text(),
460
461
  /** From `startedAt` to the provider's first stream event. */
461
462
  firstTokenMs: integer(),
463
+ /** What the uncached input cost. */
464
+ costInputUsd: doublePrecision(),
465
+ /** What the input read from the provider's cache cost. */
466
+ costCacheReadUsd: doublePrecision(),
467
+ /** What the input written to the provider's cache cost. */
468
+ costCacheWriteUsd: doublePrecision(),
469
+ /** What the output cost. */
470
+ costOutputUsd: doublePrecision(),
462
471
  }, (t) => [
463
472
  index("model_usage_session").on(t.sessionId, t.createdAt, t.id),
464
473
  index("model_usage_export").on(t.txid, t.id),
@@ -74,6 +74,11 @@ export interface TenantConfig {
74
74
  * the identity file (`NYLORUN_IDENTITY_FILE`). Absent: none.
75
75
  */
76
76
  issuers?: import("./issuers.js").TrustedIssuers;
77
+ /**
78
+ * The URL clients reach the Runtime API at (`NYLORUN_PUBLIC_URL`, no trailing slash): the base
79
+ * of webhook URLs and the OAuth resource. Absent: the origin each request reached.
80
+ */
81
+ publicUrl?: string;
77
82
  logger: Logger;
78
83
  }
79
84
  export interface Logger {
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const RUNTIME_VERSION = "0.28.0-beta";
1
+ export declare const RUNTIME_VERSION = "0.29.0-beta";
package/dist/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  // Kept in step with package.json by runtime/server/scripts/check-package.mjs, which runs in npm run check.
2
2
  // release:prepare also rewrites this when it bumps @nylorun/runtime.
3
- export const RUNTIME_VERSION = "0.28.0-beta";
3
+ export const RUNTIME_VERSION = "0.29.0-beta";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nylorun/runtime",
3
- "version": "0.28.0-beta",
3
+ "version": "0.29.0-beta",
4
4
  "description": "Nylorun Runtime: the agent execution Host on Postgres, Restate and S2, and model providers.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -65,8 +65,8 @@
65
65
  "@hono/node-server": "^2.1.5",
66
66
  "@hono/zod-openapi": "^1.6.3",
67
67
  "@modelcontextprotocol/sdk": "^1.32.1",
68
- "@nylorun/core": "0.24.0-beta",
69
- "@nylorun/harness": "0.29.0-beta",
68
+ "@nylorun/core": "0.25.0-beta",
69
+ "@nylorun/harness": "0.29.1-beta",
70
70
  "@restatedev/restate-sdk": "1.17.3",
71
71
  "@restatedev/restate-sdk-clients": "1.17.3",
72
72
  "@s2-dev/streamstore": "0.28.0",