@spendgraph/sdk 0.7.0 → 0.8.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.
|
@@ -4,7 +4,7 @@ export declare const PUBLISH_TO: readonly ["md", "html", "txt", "pdf"];
|
|
|
4
4
|
export type PublishFrom = (typeof PUBLISH_FROM)[number];
|
|
5
5
|
export type PublishTo = (typeof PUBLISH_TO)[number];
|
|
6
6
|
export interface PublishInput {
|
|
7
|
-
projectId
|
|
7
|
+
projectId?: string;
|
|
8
8
|
content: string;
|
|
9
9
|
from: PublishFrom;
|
|
10
10
|
to: PublishTo;
|
|
@@ -19,6 +19,15 @@ export interface IngestResult {
|
|
|
19
19
|
rejected: number;
|
|
20
20
|
/** Ids nothing could price. Stored at $0 and counted, never rejected. */
|
|
21
21
|
unpricedModels: string[];
|
|
22
|
+
/**
|
|
23
|
+
* What each event was priced at, by the `eventId` it was sent with.
|
|
24
|
+
*
|
|
25
|
+
* The server prices from the project's resolved offer as it writes the row,
|
|
26
|
+
* so this is the figure that was stored rather than a second calculation of
|
|
27
|
+
* it. A caller reporting usage rather than a rollout has no other way to put
|
|
28
|
+
* a cost on the call it just made.
|
|
29
|
+
*/
|
|
30
|
+
costs: Record<string, number>;
|
|
22
31
|
}
|
|
23
32
|
/** The route takes up to this many events per request. */
|
|
24
33
|
export declare const MAX_EVENTS = 100;
|
|
@@ -31,12 +40,22 @@ export declare const MAX_EVENTS = 100;
|
|
|
31
40
|
export interface Sender {
|
|
32
41
|
send(events: UsageEvent[]): Promise<void>;
|
|
33
42
|
}
|
|
43
|
+
/** What one event cost, for a caller that sent exactly one. */
|
|
44
|
+
export type OneCost = number | undefined;
|
|
34
45
|
/** Posts usage straight through, chunked to what the route accepts. */
|
|
35
46
|
export declare class Ingest implements Sender {
|
|
36
47
|
private readonly client;
|
|
37
48
|
private readonly project?;
|
|
38
49
|
constructor(client: Client, project?: string | undefined);
|
|
39
50
|
send(events: UsageEvent[]): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* One event, and what it cost — for a caller that wants the figure back.
|
|
53
|
+
*
|
|
54
|
+
* `undefined` where the server could not price the model, which it counts at
|
|
55
|
+
* zero rather than rejecting. A caller can then say "unpriced" instead of
|
|
56
|
+
* showing a zero that looks measured.
|
|
57
|
+
*/
|
|
58
|
+
priced(event: UsageEvent): Promise<OneCost>;
|
|
40
59
|
/** The same write, with the server's answer — which ids went unpriced. */
|
|
41
60
|
report(events: UsageEvent[]): Promise<IngestResult>;
|
|
42
61
|
}
|
package/dist/resources/ingest.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const i=100;class p{client;project;constructor(
|
|
1
|
+
const i=100;class p{client;project;constructor(e,t){this.client=e,this.project=t}async send(e){await this.report(e)}async priced(e){const t=e.eventId??crypto.randomUUID();return(await this.report([{...e,eventId:t}])).costs[t]}async report(e){const t={accepted:0,rejected:0,unpricedModels:[],costs:{}};if(e.length===0)return t;const r=new Set,o=e.map(c=>({...c,eventId:c.eventId??crypto.randomUUID()}));for(let c=0;c<o.length;c+=100){const s=await this.client.post("/api/v1/ingest",{events:o.slice(c,c+100)},{project:this.project});t.accepted+=s?.accepted??0,t.rejected+=s?.rejected??0;for(const n of s?.unpricedModels??[])r.add(n);Object.assign(t.costs,s?.costs??{})}return t.unpricedModels=[...r],t}}export{p as Ingest,i as MAX_EVENTS};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Typed prompt fields — what a `{placeholder}` accepts, and how it renders.
|
|
3
3
|
*
|
|
4
|
-
* Deliberately a copy of `lib/fields.ts` rather than an import. This package is
|
|
4
|
+
* Deliberately a copy of `lib/prompts/fields.ts` rather than an import. This package is
|
|
5
5
|
* published and depends on nothing; reaching into the app for a type would make
|
|
6
6
|
* every installed copy break the next time the app moved a file. The two are
|
|
7
7
|
* kept in step by the wire format, which is the only contract that matters.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spendgraph/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Track LLM input/output tokens and cost. Three functions, zero dependencies, fail-open.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"README.md"
|
|
47
47
|
],
|
|
48
48
|
"devDependencies": {
|
|
49
|
+
"@spendgraph/config": "0.8.0",
|
|
49
50
|
"typescript": "^5"
|
|
50
51
|
},
|
|
51
52
|
"engines": {
|
|
@@ -56,6 +57,7 @@
|
|
|
56
57
|
},
|
|
57
58
|
"scripts": {
|
|
58
59
|
"build": "rm -rf dist && tsc -p tsconfig.json --emitDeclarationOnly && tsc -p tsconfig.json --declaration false --removeComments && node ../../scripts/minify.mjs dist",
|
|
59
|
-
"test": "vitest run"
|
|
60
|
+
"test": "vitest run",
|
|
61
|
+
"typecheck": "tsc -p tsconfig.tests.json"
|
|
60
62
|
}
|
|
61
63
|
}
|