@intelligo-dev/executions 1.0.0-beta.1 → 1.0.0-beta.13
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/NOTICE +6 -0
- package/README.md +121 -0
- package/dist/db/schema.d.ts +32 -21
- package/dist/db/schema.d.ts.map +1 -1
- package/dist/db/schema.js +23 -23
- package/dist/db/schema.js.map +1 -1
- package/dist/index.d.ts +10 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/lifecycle.d.ts +31 -5
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +179 -18
- package/dist/lifecycle.js.map +1 -1
- package/dist/ports.d.ts +33 -14
- package/dist/ports.d.ts.map +1 -1
- package/dist/ports.js +3 -8
- package/dist/ports.js.map +1 -1
- package/dist/pricing.d.ts +107 -137
- package/dist/pricing.d.ts.map +1 -1
- package/dist/pricing.js +129 -85
- package/dist/pricing.js.map +1 -1
- package/dist/queries.d.ts +39 -26
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +96 -39
- package/dist/queries.js.map +1 -1
- package/package.json +41 -13
- package/src/db/schema.ts +87 -0
- package/src/index.ts +73 -0
- package/src/lifecycle.ts +525 -0
- package/src/ports.ts +100 -0
- package/src/pricing.ts +322 -0
- package/src/queries.ts +235 -0
package/NOTICE
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
Intelligo
|
|
2
|
+
Copyright 2026 Turtuvshin Byambaa and the Intelligo contributors
|
|
3
|
+
|
|
4
|
+
This product is licensed under the Apache License, Version 2.0 (see
|
|
5
|
+
LICENSE). The Intelligo name and logo are trademarks; see TRADEMARK.md
|
|
6
|
+
in the source repository, https://github.com/intelligo-dev/intelligo.
|
package/README.md
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# @intelligo-dev/executions
|
|
2
|
+
|
|
3
|
+
The execution lifecycle (admission, running, settlement) and the model cost registry.
|
|
4
|
+
|
|
5
|
+
Part of [Intelligo](https://intelligo.dev), an application framework and
|
|
6
|
+
operational platform for vertical AI SaaS products. Every `@intelligo-dev/*`
|
|
7
|
+
package is released at one version and shares one database schema;
|
|
8
|
+
`pnpm dlx @intelligo-dev/cli@beta create my-app` installs the set an
|
|
9
|
+
application needs. Documentation:
|
|
10
|
+
[intelligo.dev/docs/packages/executions](https://intelligo.dev/docs/packages/executions).
|
|
11
|
+
|
|
12
|
+
## Install
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pnpm add @intelligo-dev/executions@beta drizzle-orm
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
`drizzle-orm` is a peer. The `executions` table is part of the framework's
|
|
19
|
+
schema, which `intelligo migrate` from
|
|
20
|
+
[`@intelligo-dev/cli`](https://www.npmjs.com/package/@intelligo-dev/cli)
|
|
21
|
+
applies.
|
|
22
|
+
|
|
23
|
+
## The boundary
|
|
24
|
+
|
|
25
|
+
Intelligo records what an AI execution cost and whether it was allowed. It does
|
|
26
|
+
not wrap the AI framework: prompts, tools and orchestration stay native.
|
|
27
|
+
|
|
28
|
+
## Use
|
|
29
|
+
|
|
30
|
+
The composition root builds one instance, with the ports bound:
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
// lib/intelligo.ts
|
|
34
|
+
import {
|
|
35
|
+
DEFAULT_MODELS,
|
|
36
|
+
createExecutions,
|
|
37
|
+
registerModels,
|
|
38
|
+
} from "@intelligo-dev/executions";
|
|
39
|
+
|
|
40
|
+
registerModels(DEFAULT_MODELS);
|
|
41
|
+
|
|
42
|
+
export const executions = createExecutions({
|
|
43
|
+
checkEntitlement, // may this workspace run this model? takes the hold
|
|
44
|
+
settleUsage, // charge what the run used
|
|
45
|
+
findSettlement, // did that charge already commit?
|
|
46
|
+
releaseHold, // the run failed: give the hold back
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
A run is one `begin`, then exactly one `complete` or `fail`:
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
const run = await executions.begin({
|
|
54
|
+
workspaceId,
|
|
55
|
+
userId,
|
|
56
|
+
capability: "support.reply",
|
|
57
|
+
model: "google/gemini-2.5-flash",
|
|
58
|
+
});
|
|
59
|
+
if (!run.allowed) return refuse(run.code, run.reason);
|
|
60
|
+
|
|
61
|
+
try {
|
|
62
|
+
const result = await agent.generate(messages); // your framework, natively
|
|
63
|
+
await run.complete({ usage: result.usage, model: "google/gemini-2.5-flash" });
|
|
64
|
+
} catch (error) {
|
|
65
|
+
await run.fail({ error });
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
All four ports are optional, so this package never imports billing; the
|
|
71
|
+
reference composition root binds them to `@intelligo-dev/billing`. The
|
|
72
|
+
lifecycle claims each transition with a compare-and-swap before money is
|
|
73
|
+
spent, so a late `complete` racing a `fail` cannot charge twice or release
|
|
74
|
+
twice.
|
|
75
|
+
|
|
76
|
+
`executions.reconcile(executionId, { abandonRunningAfterMs? })` repairs a run
|
|
77
|
+
whose process died: it asks `findSettlement` whether the charge committed,
|
|
78
|
+
confirms it onto the row or re-runs settlement from the recorded usage, and
|
|
79
|
+
fails a `running` row that outlived the threshold. `findStaleExecutions` finds
|
|
80
|
+
the candidates; `listExecutions`, `summarizeExecutions` and
|
|
81
|
+
`summarizeExecutionsByDay` read the record for a usage page.
|
|
82
|
+
|
|
83
|
+
## Model pricing
|
|
84
|
+
|
|
85
|
+
`@intelligo-dev/executions/pricing` is a deliberate zero-import leaf that
|
|
86
|
+
client bundles can reach. Model ids are registry keys: an unregistered id has
|
|
87
|
+
no price, and guessing one is how a model runs on the cheapest provider and
|
|
88
|
+
bills at the most expensive rate. Pricing throws `UnknownModelError` instead.
|
|
89
|
+
|
|
90
|
+
Nothing self-registers. `DEFAULT_MODELS` is the catalogue the framework ships,
|
|
91
|
+
as data; a deployment registers it, its own contracted rates, or a model the
|
|
92
|
+
framework has never heard of:
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
import { registerModel } from "@intelligo-dev/executions/pricing";
|
|
96
|
+
|
|
97
|
+
registerModel({
|
|
98
|
+
id: "acme/large-1",
|
|
99
|
+
provider: "acme",
|
|
100
|
+
model: "large-1-2026-08",
|
|
101
|
+
displayName: "Acme Large",
|
|
102
|
+
costPerMInputTokens: 1.25, // USD per million, as the provider quotes it
|
|
103
|
+
costPerMOutputTokens: 5,
|
|
104
|
+
maxOutputTokens: 8_192, // sizes the worst-case hold at admission
|
|
105
|
+
capabilities: {
|
|
106
|
+
thinking: false,
|
|
107
|
+
toolCall: true,
|
|
108
|
+
vision: false,
|
|
109
|
+
webSearch: false,
|
|
110
|
+
codeExec: false,
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
`providerCost` is what a run cost the deployment; `chargeFor` applies the
|
|
116
|
+
deployment's currency, rate and margin (`BillingRate`) and returns both
|
|
117
|
+
figures as money in micros.
|
|
118
|
+
|
|
119
|
+
## Licence
|
|
120
|
+
|
|
121
|
+
Apache-2.0
|
package/dist/db/schema.d.ts
CHANGED
|
@@ -1,21 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @intelligo-dev/executions database schema.
|
|
3
|
-
*
|
|
4
2
|
* One row per AI execution: who ran what capability, whether it was
|
|
5
|
-
* admitted, how it ended, and what it cost.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* chosen AI framework.
|
|
3
|
+
* admitted, how it ended, and what it cost. It deliberately records
|
|
4
|
+
* nothing about agents, tools, workflows, or messages, which stay
|
|
5
|
+
* native to the chosen AI framework.
|
|
9
6
|
*
|
|
10
|
-
*
|
|
11
|
-
* - `usage_records` is the per-request usage/cost detail
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* - `credit_reservations` (owned by credits/billing today) holds the
|
|
17
|
-
* admission hold; `executions.request_id` is the correlation key
|
|
18
|
-
* between the two.
|
|
7
|
+
* Related tables:
|
|
8
|
+
* - `usage_records` is the per-request usage/cost detail, linked by
|
|
9
|
+
* `execution_id`.
|
|
10
|
+
* - `monthly_usage` is the O(1) rollup.
|
|
11
|
+
* - `credit_reservations` holds the admission hold;
|
|
12
|
+
* `executions.request_id` is the correlation key between the two.
|
|
19
13
|
*
|
|
20
14
|
* Scanned by drizzle-kit alongside the core schema directory — see
|
|
21
15
|
* packages/core/drizzle.config.ts.
|
|
@@ -194,11 +188,11 @@ export declare const executions: import("drizzle-orm/pg-core").PgTableWithColumn
|
|
|
194
188
|
identity: undefined;
|
|
195
189
|
generated: undefined;
|
|
196
190
|
}, {}, {}>;
|
|
197
|
-
|
|
198
|
-
name: "
|
|
191
|
+
chargedMicros: import("drizzle-orm/pg-core").PgColumn<{
|
|
192
|
+
name: "charged_micros";
|
|
199
193
|
tableName: "executions";
|
|
200
194
|
dataType: "number";
|
|
201
|
-
columnType: "
|
|
195
|
+
columnType: "PgBigInt53";
|
|
202
196
|
data: number;
|
|
203
197
|
driverParam: string | number;
|
|
204
198
|
notNull: false;
|
|
@@ -211,11 +205,11 @@ export declare const executions: import("drizzle-orm/pg-core").PgTableWithColumn
|
|
|
211
205
|
identity: undefined;
|
|
212
206
|
generated: undefined;
|
|
213
207
|
}, {}, {}>;
|
|
214
|
-
|
|
215
|
-
name: "
|
|
208
|
+
reservedMicros: import("drizzle-orm/pg-core").PgColumn<{
|
|
209
|
+
name: "reserved_micros";
|
|
216
210
|
tableName: "executions";
|
|
217
211
|
dataType: "number";
|
|
218
|
-
columnType: "
|
|
212
|
+
columnType: "PgBigInt53";
|
|
219
213
|
data: number;
|
|
220
214
|
driverParam: string | number;
|
|
221
215
|
notNull: false;
|
|
@@ -228,6 +222,23 @@ export declare const executions: import("drizzle-orm/pg-core").PgTableWithColumn
|
|
|
228
222
|
identity: undefined;
|
|
229
223
|
generated: undefined;
|
|
230
224
|
}, {}, {}>;
|
|
225
|
+
currency: import("drizzle-orm/pg-core").PgColumn<{
|
|
226
|
+
name: "currency";
|
|
227
|
+
tableName: "executions";
|
|
228
|
+
dataType: "string";
|
|
229
|
+
columnType: "PgText";
|
|
230
|
+
data: string;
|
|
231
|
+
driverParam: string;
|
|
232
|
+
notNull: false;
|
|
233
|
+
hasDefault: false;
|
|
234
|
+
isPrimaryKey: false;
|
|
235
|
+
isAutoincrement: false;
|
|
236
|
+
hasRuntimeDefault: false;
|
|
237
|
+
enumValues: [string, ...string[]];
|
|
238
|
+
baseColumn: never;
|
|
239
|
+
identity: undefined;
|
|
240
|
+
generated: undefined;
|
|
241
|
+
}, {}, {}>;
|
|
231
242
|
refusalReason: import("drizzle-orm/pg-core").PgColumn<{
|
|
232
243
|
name: "refusal_reason";
|
|
233
244
|
tableName: "executions";
|
package/dist/db/schema.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/db/schema.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/db/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAaH,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuDtB,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,OAAO,UAAU,CAAC,YAAY,CAAC;AACvD,MAAM,MAAM,eAAe,GAAG,OAAO,UAAU,CAAC,YAAY,CAAC"}
|
package/dist/db/schema.js
CHANGED
|
@@ -1,26 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @intelligo-dev/executions database schema.
|
|
3
|
-
*
|
|
4
2
|
* One row per AI execution: who ran what capability, whether it was
|
|
5
|
-
* admitted, how it ended, and what it cost.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* chosen AI framework.
|
|
3
|
+
* admitted, how it ended, and what it cost. It deliberately records
|
|
4
|
+
* nothing about agents, tools, workflows, or messages, which stay
|
|
5
|
+
* native to the chosen AI framework.
|
|
9
6
|
*
|
|
10
|
-
*
|
|
11
|
-
* - `usage_records` is the per-request usage/cost detail
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* - `credit_reservations` (owned by credits/billing today) holds the
|
|
17
|
-
* admission hold; `executions.request_id` is the correlation key
|
|
18
|
-
* between the two.
|
|
7
|
+
* Related tables:
|
|
8
|
+
* - `usage_records` is the per-request usage/cost detail, linked by
|
|
9
|
+
* `execution_id`.
|
|
10
|
+
* - `monthly_usage` is the O(1) rollup.
|
|
11
|
+
* - `credit_reservations` holds the admission hold;
|
|
12
|
+
* `executions.request_id` is the correlation key between the two.
|
|
19
13
|
*
|
|
20
14
|
* Scanned by drizzle-kit alongside the core schema directory — see
|
|
21
15
|
* packages/core/drizzle.config.ts.
|
|
22
16
|
*/
|
|
23
|
-
import { pgTable, text, timestamp, integer, jsonb, index, } from "drizzle-orm/pg-core";
|
|
17
|
+
import { pgTable, text, timestamp, integer, bigint, jsonb, index, } from "drizzle-orm/pg-core";
|
|
24
18
|
import { organization, users } from "@intelligo-dev/core/db/schema";
|
|
25
19
|
export const executions = pgTable("executions", {
|
|
26
20
|
id: text("id").primaryKey(),
|
|
@@ -32,8 +26,8 @@ export const executions = pgTable("executions", {
|
|
|
32
26
|
}),
|
|
33
27
|
/**
|
|
34
28
|
* What the caller asked for, in the product's own vocabulary:
|
|
35
|
-
* "
|
|
36
|
-
*
|
|
29
|
+
* "support.reply", "chat.message". Opaque to the framework — used for
|
|
30
|
+
* entitlement decisions, grouping, and admin filtering.
|
|
37
31
|
*/
|
|
38
32
|
capability: text("capability").notNull(),
|
|
39
33
|
/**
|
|
@@ -41,17 +35,23 @@ export const executions = pgTable("executions", {
|
|
|
41
35
|
* usage_records. Unique per execution attempt.
|
|
42
36
|
*/
|
|
43
37
|
requestId: text("request_id").notNull().unique(),
|
|
44
|
-
/**
|
|
38
|
+
/**
|
|
39
|
+
* running | settling | succeeded | failed | refused.
|
|
40
|
+
* `settling` is the window between claiming the row and confirming
|
|
41
|
+
* the charge; a row that stays there needs an operator.
|
|
42
|
+
*/
|
|
45
43
|
status: text("status").notNull().default("running"),
|
|
46
44
|
/** Model actually used; null until the run reports one. */
|
|
47
45
|
model: text("model"),
|
|
48
46
|
inputTokens: integer("input_tokens"),
|
|
49
47
|
outputTokens: integer("output_tokens"),
|
|
50
48
|
totalTokens: integer("total_tokens"),
|
|
51
|
-
/** Authoritative charge in
|
|
52
|
-
|
|
53
|
-
/** Worst-case estimate held at admission
|
|
54
|
-
|
|
49
|
+
/** Authoritative charge in micros of `currency`, mirrored from usage_records. */
|
|
50
|
+
chargedMicros: bigint("charged_micros", { mode: "number" }),
|
|
51
|
+
/** Worst-case estimate held at admission, in micros of `currency`. */
|
|
52
|
+
reservedMicros: bigint("reserved_micros", { mode: "number" }),
|
|
53
|
+
/** What this row's amounts are denominated in; null until one is set. */
|
|
54
|
+
currency: text("currency"),
|
|
55
55
|
/** Populated on status=refused: why entitlement said no. */
|
|
56
56
|
refusalReason: text("refusal_reason"),
|
|
57
57
|
/** Populated on status=failed. */
|
package/dist/db/schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/db/schema.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,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C;IAC3D,sEAAsE;IACtE,cAAc,EAAE,MAAM,CAAC,iBAAiB,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;IAC7D,yEAAyE;IACzE,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC;IAC1B,4DAA4D;IAC5D,aAAa,EAAE,IAAI,CAAC,gBAAgB,CAAC;IACrC,kCAAkC;IAClC,YAAY,EAAE,IAAI,CAAC,eAAe,CAAC;IACnC,SAAS,EAAE,SAAS,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE,CAAC,UAAU,EAAE;IACzD,UAAU,EAAE,SAAS,CAAC,aAAa,CAAC;IACpC,UAAU,EAAE,OAAO,CAAC,aAAa,CAAC;IAClC,QAAQ,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC,KAAK,EAA2B;CAC7D,EACD,CAAC,KAAK,EAAE,EAAE,CAAC;IACT,KAAK,CAAC,kCAAkC,CAAC,CAAC,EAAE,CAC1C,KAAK,CAAC,WAAW,EACjB,KAAK,CAAC,SAAS,CAChB;IACD,KAAK,CAAC,uBAAuB,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,SAAS,CAAC;IAChE,KAAK,CAAC,2BAA2B,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC;CACzE,CACF,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Wraps a native AI run (Mastra, AI SDK, anything) with entitlement,
|
|
5
5
|
* credit hold, usage/cost recording, and audit — and records nothing
|
|
6
|
-
* about agents, tools, or messages
|
|
6
|
+
* about agents, tools, or messages.
|
|
7
7
|
*
|
|
8
8
|
* The composition root builds one instance with the ports bound:
|
|
9
9
|
*
|
|
@@ -12,18 +12,18 @@
|
|
|
12
12
|
* settleUsage: billingSettlementPort,
|
|
13
13
|
* });
|
|
14
14
|
*/
|
|
15
|
-
export { createExecutions } from "./lifecycle";
|
|
16
|
-
export type { Executions, ExecutionStatus, ExecutionRun, BeginExecutionInput, CompleteExecutionInput, } from "./lifecycle";
|
|
17
|
-
export type { ExecutionPorts, EntitlementDecision, EntitlementRequest, UsageSettlement, SettlementResult, } from "./ports";
|
|
18
|
-
export { listExecutions, getExecutionByRequestId, summarizeExecutions, findStaleExecutions, summarizeExecutionsByDay, } from "./queries";
|
|
19
|
-
export type { ListExecutionsOptions } from "./queries";
|
|
20
|
-
export { executions } from "./db/schema";
|
|
21
|
-
export type { Execution, InsertExecution } from "./db/schema";
|
|
15
|
+
export { createExecutions } from "./lifecycle.js";
|
|
16
|
+
export type { Executions, ExecutionStatus, ExecutionRun, ReconcileResult, BeginExecutionInput, CompleteExecutionInput, } from "./lifecycle.js";
|
|
17
|
+
export type { ExecutionPorts, EntitlementDecision, EntitlementRequest, UsageSettlement, SettlementResult, SettlementQuery, } from "./ports.js";
|
|
18
|
+
export { listExecutions, getExecutionByRequestId, summarizeExecutions, findStaleExecutions, summarizeExecutionsByDay, } from "./queries.js";
|
|
19
|
+
export type { ListExecutionsOptions } from "./queries.js";
|
|
20
|
+
export { executions } from "./db/schema.js";
|
|
21
|
+
export type { Execution, InsertExecution } from "./db/schema.js";
|
|
22
22
|
/**
|
|
23
23
|
* Model registry and cost accounting. Also reachable as
|
|
24
24
|
* `@intelligo-dev/executions/pricing`, which is the import to use from
|
|
25
25
|
* anything that reaches a browser — this barrel pulls in the database.
|
|
26
26
|
*/
|
|
27
|
-
export {
|
|
28
|
-
export type { ModelId,
|
|
27
|
+
export { DEFAULT_MODELS, UnknownModelError, registerModel, registerModels, getModelPricing, isModelRegistered, listModels, registeredModelIds, clearModels, DEFAULT_MARGIN_BP, PROVIDER_CURRENCY, providerCost, chargeFor, estimateWorstCaseCharge, } from "./pricing.js";
|
|
28
|
+
export type { ModelId, ModelPricing, ModelCapabilities, BillingRate, } from "./pricing.js";
|
|
29
29
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EACV,UAAU,EACV,eAAe,EACf,YAAY,EACZ,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,aAAa,CAAC;AAErB,YAAY,EACV,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAClB,eAAe,EACf,gBAAgB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,YAAY,EACV,UAAU,EACV,eAAe,EACf,YAAY,EACZ,eAAe,EACf,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,aAAa,CAAC;AAErB,YAAY,EACV,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAClB,eAAe,EACf,gBAAgB,EAChB,eAAe,GAChB,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,cAAc,EACd,uBAAuB,EACvB,mBAAmB,EACnB,mBAAmB,EACnB,wBAAwB,GACzB,MAAM,WAAW,CAAC;AACnB,YAAY,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAEvD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9D;;;;GAIG;AACH,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,UAAU,EACV,kBAAkB,EAClB,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,YAAY,EACZ,SAAS,EACT,uBAAuB,GACxB,MAAM,WAAW,CAAC;AACnB,YAAY,EACV,OAAO,EACP,YAAY,EACZ,iBAAiB,EACjB,WAAW,GACZ,MAAM,WAAW,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Wraps a native AI run (Mastra, AI SDK, anything) with entitlement,
|
|
5
5
|
* credit hold, usage/cost recording, and audit — and records nothing
|
|
6
|
-
* about agents, tools, or messages
|
|
6
|
+
* about agents, tools, or messages.
|
|
7
7
|
*
|
|
8
8
|
* The composition root builds one instance with the ports bound:
|
|
9
9
|
*
|
|
@@ -12,13 +12,13 @@
|
|
|
12
12
|
* settleUsage: billingSettlementPort,
|
|
13
13
|
* });
|
|
14
14
|
*/
|
|
15
|
-
export { createExecutions } from "./lifecycle";
|
|
16
|
-
export { listExecutions, getExecutionByRequestId, summarizeExecutions, findStaleExecutions, summarizeExecutionsByDay, } from "./queries";
|
|
17
|
-
export { executions } from "./db/schema";
|
|
15
|
+
export { createExecutions } from "./lifecycle.js";
|
|
16
|
+
export { listExecutions, getExecutionByRequestId, summarizeExecutions, findStaleExecutions, summarizeExecutionsByDay, } from "./queries.js";
|
|
17
|
+
export { executions } from "./db/schema.js";
|
|
18
18
|
/**
|
|
19
19
|
* Model registry and cost accounting. Also reachable as
|
|
20
20
|
* `@intelligo-dev/executions/pricing`, which is the import to use from
|
|
21
21
|
* anything that reaches a browser — this barrel pulls in the database.
|
|
22
22
|
*/
|
|
23
|
-
export {
|
|
23
|
+
export { DEFAULT_MODELS, UnknownModelError, registerModel, registerModels, getModelPricing, isModelRegistered, listModels, registeredModelIds, clearModels, DEFAULT_MARGIN_BP, PROVIDER_CURRENCY, providerCost, chargeFor, estimateWorstCaseCharge, } from "./pricing.js";
|
|
24
24
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAmB/C,OAAO,EACL,cAAc,EACd,uBAAuB,EACvB,mBAAmB,EACnB,mBAAmB,EACnB,wBAAwB,GACzB,MAAM,WAAW,CAAC;AAGnB,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC;;;;GAIG;AACH,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,UAAU,EACV,kBAAkB,EAClB,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,YAAY,EACZ,SAAS,EACT,uBAAuB,GACxB,MAAM,WAAW,CAAC"}
|
package/dist/lifecycle.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* const run = await executions.begin({ workspaceId, userId, capability });
|
|
5
5
|
* if (!run.allowed) return refuse(run.reason);
|
|
6
6
|
* try {
|
|
7
|
-
* const result = await
|
|
7
|
+
* const result = await supportAgent.generate(messages); // native
|
|
8
8
|
* await run.complete({ usage: result.usage, model: result.model });
|
|
9
9
|
* return result;
|
|
10
10
|
* } catch (error) {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
*
|
|
15
15
|
* The handle knows nothing about agents, tools, messages, or streams —
|
|
16
16
|
* only actor, workspace, capability, entitlement, status, usage, cost,
|
|
17
|
-
* credits, and audit
|
|
17
|
+
* credits, and audit.
|
|
18
18
|
*
|
|
19
19
|
* Every terminal transition is idempotent: calling complete() twice, or
|
|
20
20
|
* fail() after complete(), leaves the first outcome in place. Streaming
|
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
* abort, error) and must be able to fire whichever arrives first
|
|
23
23
|
* without racing.
|
|
24
24
|
*/
|
|
25
|
-
import type {
|
|
25
|
+
import type { Money } from "@intelligo-dev/core/money";
|
|
26
|
+
import type { ExecutionPorts } from "./ports.js";
|
|
26
27
|
/**
|
|
27
28
|
* Row lifecycle. `settling` is non-terminal and deliberate: it marks
|
|
28
29
|
* the window where usage is being charged, so a second complete() or a
|
|
@@ -34,7 +35,7 @@ export type ExecutionStatus = "running" | "settling" | "succeeded" | "failed" |
|
|
|
34
35
|
export type BeginExecutionInput = {
|
|
35
36
|
workspaceId: string;
|
|
36
37
|
userId?: string | null;
|
|
37
|
-
/** Product-defined verb, e.g. "
|
|
38
|
+
/** Product-defined verb, e.g. "support.reply". */
|
|
38
39
|
capability: string;
|
|
39
40
|
/** Supply to reuse an existing correlation id; generated otherwise. */
|
|
40
41
|
requestId?: string;
|
|
@@ -56,9 +57,12 @@ export type ExecutionRun = {
|
|
|
56
57
|
requestId: string;
|
|
57
58
|
/** False when entitlement refused; complete()/fail() are then no-ops. */
|
|
58
59
|
allowed: boolean;
|
|
60
|
+
/** Stable refusal code from the entitlement port; set when allowed is false. */
|
|
61
|
+
code?: string;
|
|
59
62
|
/** Set when allowed is false. */
|
|
60
63
|
reason?: string;
|
|
61
|
-
|
|
64
|
+
/** The hold entitlement took for this run. */
|
|
65
|
+
estimated?: Money;
|
|
62
66
|
usingTrialCredits: boolean;
|
|
63
67
|
complete(input?: CompleteExecutionInput): Promise<void>;
|
|
64
68
|
fail(input: {
|
|
@@ -67,6 +71,28 @@ export type ExecutionRun = {
|
|
|
67
71
|
};
|
|
68
72
|
export declare function createExecutions(ports?: ExecutionPorts): {
|
|
69
73
|
begin: (input: BeginExecutionInput) => Promise<ExecutionRun>;
|
|
74
|
+
reconcile: (executionId: string, options?: {
|
|
75
|
+
abandonRunningAfterMs?: number;
|
|
76
|
+
}) => Promise<ReconcileResult>;
|
|
77
|
+
};
|
|
78
|
+
export type ReconcileResult = {
|
|
79
|
+
action: "noop";
|
|
80
|
+
status: ExecutionStatus | "missing";
|
|
81
|
+
reason?: string;
|
|
82
|
+
}
|
|
83
|
+
/** The ledger already held the charge; the row now says so. */
|
|
84
|
+
| {
|
|
85
|
+
action: "confirmed";
|
|
86
|
+
charged?: Money;
|
|
87
|
+
}
|
|
88
|
+
/** Settlement was re-run from the recorded usage. */
|
|
89
|
+
| {
|
|
90
|
+
action: "settled";
|
|
91
|
+
charged?: Money;
|
|
92
|
+
}
|
|
93
|
+
/** A stale `running` row was failed and its hold released. */
|
|
94
|
+
| {
|
|
95
|
+
action: "abandoned";
|
|
70
96
|
};
|
|
71
97
|
export type Executions = ReturnType<typeof createExecutions>;
|
|
72
98
|
//# sourceMappingURL=lifecycle.d.ts.map
|
package/dist/lifecycle.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../src/lifecycle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;
|
|
1
|
+
{"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../src/lifecycle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAIH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAKvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAI9C;;;;;;GAMG;AACH,MAAM,MAAM,eAAe,GACzB,SAAS,GAAG,UAAU,GAAG,WAAW,GAAG,QAAQ,GAAG,SAAS,CAAC;AAE9D,MAAM,MAAM,mBAAmB,GAAG;IAChC,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,kDAAkD;IAClD,UAAU,EAAE,MAAM,CAAC;IACnB,uEAAuE;IACvE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sEAAsE;IACtE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM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