@spendgraph/sdk 0.5.1 → 0.7.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.
- package/LICENSE +202 -0
- package/README.md +25 -80
- package/dist/ai.js +1 -25
- package/dist/client.d.ts +2 -1
- package/dist/client.js +1 -38
- package/dist/core/client/client.d.ts +2 -0
- package/dist/core/client/client.js +1 -132
- package/dist/core/client/errors.js +1 -17
- package/dist/core/client/index.js +1 -2
- package/dist/core/concurrency.d.ts +2 -0
- package/dist/core/concurrency.js +1 -0
- package/dist/core/money.d.ts +23 -0
- package/dist/core/money.js +1 -0
- package/dist/core/types.d.ts +4 -0
- package/dist/core/types.js +0 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +1 -5
- package/dist/langchain.js +1 -69
- package/dist/resources/alerts.js +1 -9
- package/dist/resources/cli.js +1 -21
- package/dist/resources/credentials.js +1 -15
- package/dist/resources/events.js +1 -18
- package/dist/resources/files.d.ts +35 -0
- package/dist/resources/files.js +1 -0
- package/dist/resources/index.d.ts +4 -2
- package/dist/resources/index.js +1 -13
- package/dist/resources/ingest.js +1 -27
- package/dist/resources/keys.js +1 -15
- package/dist/resources/playground.js +1 -9
- package/dist/resources/pricing.js +1 -36
- package/dist/resources/projects.js +1 -49
- package/dist/resources/prompts-admin.js +1 -21
- package/dist/resources/prompts.d.ts +13 -1
- package/dist/resources/prompts.js +1 -49
- package/dist/resources/stats.js +1 -21
- package/dist/resources/tools.d.ts +1 -1
- package/dist/resources/tools.js +1 -21
- package/dist/rollout/index.d.ts +1 -0
- package/dist/rollout/index.js +1 -1
- package/dist/rollout/rollout.d.ts +30 -0
- package/dist/rollout/rollout.js +1 -1
- package/dist/schema/index.d.ts +1 -1
- package/dist/schema/index.js +1 -2
- package/dist/schema/serialize/index.js +1 -1
- package/dist/schema/serialize/serialize.js +1 -31
- package/dist/schema/types/index.js +0 -1
- package/dist/schema/types/types.js +0 -1
- package/dist/schema/validate/index.js +1 -1
- package/dist/schema/validate/validate.d.ts +4 -0
- package/dist/schema/validate/validate.js +1 -92
- package/dist/track/index.js +1 -1
- package/dist/track/track.js +1 -331
- package/docs/client.mdx +85 -0
- package/docs/errors.mdx +82 -0
- package/docs/tracking.mdx +62 -0
- package/package.json +11 -8
package/dist/index.js
CHANGED
|
@@ -1,5 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { Client, queryString, SpendgraphError } from "./core/client/index.js";
|
|
3
|
-
export * from "./resources/index.js";
|
|
4
|
-
export { FieldValidationError, serializeFields, validateFields, } from "./schema/index.js";
|
|
5
|
-
export { SpendGraph } from "./track/index.js";
|
|
1
|
+
import{Spendgraph as e}from"./client.js";import{Client as i,queryString as p,SpendgraphError as m}from"./core/client/index.js";import{mapLimit as s}from"./core/concurrency.js";import{formatMicros as f,microsFromUsd as l}from"./core/money.js";export*from"./resources/index.js";import{totalTokens as g}from"./rollout/index.js";import{FieldValidationError as S,isMissing as h,serializeFields as c,toBoolean as u,toNumber as E,validateFields as M}from"./schema/index.js";import{SpendGraph as k}from"./track/index.js";export{i as Client,S as FieldValidationError,k as SpendGraph,e as Spendgraph,m as SpendgraphError,f as formatMicros,h as isMissing,s as mapLimit,l as microsFromUsd,p as queryString,c as serializeFields,u as toBoolean,E as toNumber,g as totalTokens,M as validateFields};
|
package/dist/langchain.js
CHANGED
|
@@ -1,69 +1 @@
|
|
|
1
|
-
|
|
2
|
-
const models = new Map();
|
|
3
|
-
const rememberModel = (llm, runId, extraParams) => {
|
|
4
|
-
try {
|
|
5
|
-
const model = extraParams?.invocation_params?.model ??
|
|
6
|
-
extraParams?.invocation_params?.model_name ??
|
|
7
|
-
extraParams?.invocation_params?.modelId ??
|
|
8
|
-
llm?.kwargs?.model ??
|
|
9
|
-
llm?.kwargs?.model_name;
|
|
10
|
-
if (model)
|
|
11
|
-
models.set(runId, model);
|
|
12
|
-
}
|
|
13
|
-
catch {
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
return {
|
|
17
|
-
name: "spendgraph",
|
|
18
|
-
handleLLMStart(llm, _prompts, runId, _parentRunId, extraParams) {
|
|
19
|
-
rememberModel(llm, runId, extraParams);
|
|
20
|
-
},
|
|
21
|
-
handleChatModelStart(llm, _messages, runId, _parentRunId, extraParams) {
|
|
22
|
-
rememberModel(llm, runId, extraParams);
|
|
23
|
-
},
|
|
24
|
-
handleLLMEnd(output, runId) {
|
|
25
|
-
const startedAs = models.get(runId);
|
|
26
|
-
models.delete(runId);
|
|
27
|
-
try {
|
|
28
|
-
const msg = output.generations?.[0]?.[0]?.message;
|
|
29
|
-
const um = msg?.usage_metadata;
|
|
30
|
-
const tu = output.llmOutput?.tokenUsage;
|
|
31
|
-
const au = output.llmOutput?.usage;
|
|
32
|
-
let inputTokens = um?.input_tokens ?? au?.input_tokens ?? tu?.promptTokens;
|
|
33
|
-
const outputTokens = um?.output_tokens ?? au?.output_tokens ?? tu?.completionTokens;
|
|
34
|
-
if (typeof inputTokens !== "number" || typeof outputTokens !== "number")
|
|
35
|
-
return;
|
|
36
|
-
let cacheReadTokens = 0;
|
|
37
|
-
let cacheWriteTokens = 0;
|
|
38
|
-
if (um?.input_token_details && typeof um.input_tokens === "number") {
|
|
39
|
-
cacheReadTokens = um.input_token_details.cache_read ?? 0;
|
|
40
|
-
cacheWriteTokens = um.input_token_details.cache_creation ?? 0;
|
|
41
|
-
inputTokens = Math.max(0, inputTokens - cacheReadTokens - cacheWriteTokens);
|
|
42
|
-
}
|
|
43
|
-
else if (au) {
|
|
44
|
-
cacheReadTokens = au.cache_read_input_tokens ?? 0;
|
|
45
|
-
cacheWriteTokens = au.cache_creation_input_tokens ?? 0;
|
|
46
|
-
}
|
|
47
|
-
const model = msg?.response_metadata?.model ??
|
|
48
|
-
msg?.response_metadata?.model_name ??
|
|
49
|
-
output.llmOutput?.model ??
|
|
50
|
-
startedAs ??
|
|
51
|
-
options.defaultModel ??
|
|
52
|
-
"unknown";
|
|
53
|
-
meter.track({
|
|
54
|
-
model,
|
|
55
|
-
inputTokens,
|
|
56
|
-
outputTokens,
|
|
57
|
-
cacheReadTokens,
|
|
58
|
-
cacheWriteTokens,
|
|
59
|
-
metadata: options.metadata,
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
catch {
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
handleLLMError(_err, runId) {
|
|
66
|
-
models.delete(runId);
|
|
67
|
-
},
|
|
68
|
-
};
|
|
69
|
-
}
|
|
1
|
+
function h(i,l={}){const d=new Map,_=(e,a,n)=>{try{const o=n?.invocation_params?.model??n?.invocation_params?.model_name??n?.invocation_params?.modelId??e?.kwargs?.model??e?.kwargs?.model_name;o&&d.set(a,o)}catch{}};return{name:"spendgraph",handleLLMStart(e,a,n,o,t){_(e,n,t)},handleChatModelStart(e,a,n,o,t){_(e,n,t)},handleLLMEnd(e,a){const n=d.get(a);d.delete(a);try{const o=e.generations?.[0]?.[0]?.message,t=o?.usage_metadata,p=e.llmOutput?.tokenUsage,s=e.llmOutput?.usage;let m=t?.input_tokens??s?.input_tokens??p?.promptTokens;const u=t?.output_tokens??s?.output_tokens??p?.completionTokens;if(typeof m!="number"||typeof u!="number")return;let r=0,c=0;t?.input_token_details&&typeof t.input_tokens=="number"?(r=t.input_token_details.cache_read??0,c=t.input_token_details.cache_creation??0,m=Math.max(0,m-r-c)):s&&(r=s.cache_read_input_tokens??0,c=s.cache_creation_input_tokens??0);const k=o?.response_metadata?.model??o?.response_metadata?.model_name??e.llmOutput?.model??n??l.defaultModel??"unknown";i.track({model:k,inputTokens:m,outputTokens:u,cacheReadTokens:r,cacheWriteTokens:c,metadata:l.metadata})}catch{}},handleLLMError(e,a){d.delete(a)}}}export{h as spendGraphHandler};
|
package/dist/resources/alerts.js
CHANGED
|
@@ -1,9 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
client;
|
|
3
|
-
constructor(client) {
|
|
4
|
-
this.client = client;
|
|
5
|
-
}
|
|
6
|
-
list(query = {}) {
|
|
7
|
-
return this.client.get("/api/v1/alerts", { ...query });
|
|
8
|
-
}
|
|
9
|
-
}
|
|
1
|
+
class s{client;constructor(t){this.client=t}list(t={}){return this.client.get("/api/v1/alerts",{...t})}}export{s as Alerts};
|
package/dist/resources/cli.js
CHANGED
|
@@ -1,21 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
client;
|
|
3
|
-
constructor(client) {
|
|
4
|
-
this.client = client;
|
|
5
|
-
}
|
|
6
|
-
start(body) {
|
|
7
|
-
return this.client.postAnonymous("/api/v1/cli/auth", body);
|
|
8
|
-
}
|
|
9
|
-
exchange(body) {
|
|
10
|
-
return this.client.postAnonymous("/api/v1/cli/token", body);
|
|
11
|
-
}
|
|
12
|
-
terminals() {
|
|
13
|
-
return this.client.get("/api/v1/cli/tokens");
|
|
14
|
-
}
|
|
15
|
-
revoke(id) {
|
|
16
|
-
return this.client.delete(`/api/v1/cli/tokens/${encodeURIComponent(id)}`);
|
|
17
|
-
}
|
|
18
|
-
revokeSelf() {
|
|
19
|
-
return this.client.delete("/api/v1/cli/tokens/current");
|
|
20
|
-
}
|
|
21
|
-
}
|
|
1
|
+
class n{client;constructor(e){this.client=e}start(e){return this.client.postAnonymous("/api/v1/cli/auth",e)}exchange(e){return this.client.postAnonymous("/api/v1/cli/token",e)}terminals(){return this.client.get("/api/v1/cli/tokens")}revoke(e){return this.client.delete(`/api/v1/cli/tokens/${encodeURIComponent(e)}`)}revokeSelf(){return this.client.delete("/api/v1/cli/tokens/current")}}export{n as Cli};
|
|
@@ -1,15 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
client;
|
|
3
|
-
constructor(client) {
|
|
4
|
-
this.client = client;
|
|
5
|
-
}
|
|
6
|
-
list() {
|
|
7
|
-
return this.client.get("/api/v1/credentials");
|
|
8
|
-
}
|
|
9
|
-
set(body) {
|
|
10
|
-
return this.client.put("/api/v1/credentials", body);
|
|
11
|
-
}
|
|
12
|
-
remove(provider) {
|
|
13
|
-
return this.client.delete("/api/v1/credentials", { provider });
|
|
14
|
-
}
|
|
15
|
-
}
|
|
1
|
+
class i{client;constructor(e){this.client=e}list(){return this.client.get("/api/v1/credentials")}set(e){return this.client.put("/api/v1/credentials",e)}remove(e){return this.client.delete("/api/v1/credentials",{provider:e})}}export{i as Credentials};
|
package/dist/resources/events.js
CHANGED
|
@@ -1,18 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
client;
|
|
3
|
-
constructor(client) {
|
|
4
|
-
this.client = client;
|
|
5
|
-
}
|
|
6
|
-
list(query = {}) {
|
|
7
|
-
return this.client.get("/api/v1/events", { ...query });
|
|
8
|
-
}
|
|
9
|
-
async *all(query = {}) {
|
|
10
|
-
let cursor = query.cursor;
|
|
11
|
-
do {
|
|
12
|
-
const page = await this.list({ ...query, cursor });
|
|
13
|
-
for (const event of page.events)
|
|
14
|
-
yield event;
|
|
15
|
-
cursor = page.nextCursor ?? undefined;
|
|
16
|
-
} while (cursor);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
1
|
+
class c{client;constructor(t){this.client=t}list(t={}){return this.client.get("/api/v1/events",{...t})}async*all(t={}){let e=t.cursor;do{const s=await this.list({...t,cursor:e});for(const n of s.events)yield n;e=s.nextCursor??void 0}while(e)}}export{c as Events};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Client } from "../core/client/index.js";
|
|
2
|
+
export declare const PUBLISH_FROM: readonly ["text", "md", "html"];
|
|
3
|
+
export declare const PUBLISH_TO: readonly ["md", "html", "txt", "pdf"];
|
|
4
|
+
export type PublishFrom = (typeof PUBLISH_FROM)[number];
|
|
5
|
+
export type PublishTo = (typeof PUBLISH_TO)[number];
|
|
6
|
+
export interface PublishInput {
|
|
7
|
+
projectId: string;
|
|
8
|
+
content: string;
|
|
9
|
+
from: PublishFrom;
|
|
10
|
+
to: PublishTo;
|
|
11
|
+
/** The file's name without its extension; `document` when unset. */
|
|
12
|
+
name?: string;
|
|
13
|
+
}
|
|
14
|
+
/** A file the app rendered and stored, and the public URL it answers on. */
|
|
15
|
+
export interface PublishedFile {
|
|
16
|
+
id: string;
|
|
17
|
+
name: string;
|
|
18
|
+
type: string;
|
|
19
|
+
bytes: number;
|
|
20
|
+
key: string;
|
|
21
|
+
url: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Files the app renders from content and stores for anyone with the link.
|
|
25
|
+
*
|
|
26
|
+
* An API key publishes into the one project it is pinned to. Nothing is read
|
|
27
|
+
* back through here: a published file is public, so its URL is the way in.
|
|
28
|
+
*/
|
|
29
|
+
export declare class Files {
|
|
30
|
+
private readonly client;
|
|
31
|
+
constructor(client: Client);
|
|
32
|
+
publish(body: PublishInput): Promise<{
|
|
33
|
+
file: PublishedFile;
|
|
34
|
+
}>;
|
|
35
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=["text","md","html"],i=["md","html","txt","pdf"];class l{client;constructor(t){this.client=t}publish(t){return this.client.post("/api/v1/files",t)}}export{l as Files,e as PUBLISH_FROM,i as PUBLISH_TO};
|
|
@@ -5,6 +5,8 @@ export { Cli } from "./cli.js";
|
|
|
5
5
|
export { Credentials } from "./credentials.js";
|
|
6
6
|
export type { EventsPage, EventsQuery, UsageEventRow } from "./events.js";
|
|
7
7
|
export { Events } from "./events.js";
|
|
8
|
+
export type { PublishedFile, PublishFrom, PublishInput, PublishTo } from "./files.js";
|
|
9
|
+
export { Files, PUBLISH_FROM, PUBLISH_TO } from "./files.js";
|
|
8
10
|
export type { IngestResult, Sender, UsageEvent } from "./ingest.js";
|
|
9
11
|
export { Ingest, MAX_EVENTS } from "./ingest.js";
|
|
10
12
|
export type { ApiKeyRow } from "./keys.js";
|
|
@@ -17,7 +19,7 @@ export { Invites, Projects } from "./projects.js";
|
|
|
17
19
|
export type { DatasetCase, PromptBlock, RenderedMessage, ReportRolloutInput, Role, RunPromptInput, SavePromptInput, Scoped, } from "./prompts.js";
|
|
18
20
|
export { Prompts } from "./prompts.js";
|
|
19
21
|
export { PromptsAdmin } from "./prompts-admin.js";
|
|
20
|
-
export type { SaveToolInput, ToolEffect, ToolRow } from "./tools.js";
|
|
21
|
-
export { Tools } from "./tools.js";
|
|
22
22
|
export type { ModelRow, RangeQuery, Summary, Timeseries, TimeseriesPoint, Totals, } from "./stats.js";
|
|
23
23
|
export { Stats } from "./stats.js";
|
|
24
|
+
export type { SaveToolInput, ToolEffect, ToolRow } from "./tools.js";
|
|
25
|
+
export { Tools } from "./tools.js";
|
package/dist/resources/index.js
CHANGED
|
@@ -1,13 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { Cli } from "./cli.js";
|
|
3
|
-
export { Credentials } from "./credentials.js";
|
|
4
|
-
export { Events } from "./events.js";
|
|
5
|
-
export { Ingest, MAX_EVENTS } from "./ingest.js";
|
|
6
|
-
export { Keys } from "./keys.js";
|
|
7
|
-
export { Playground } from "./playground.js";
|
|
8
|
-
export { Models, Pricing } from "./pricing.js";
|
|
9
|
-
export { Invites, Projects } from "./projects.js";
|
|
10
|
-
export { Prompts } from "./prompts.js";
|
|
11
|
-
export { PromptsAdmin } from "./prompts-admin.js";
|
|
12
|
-
export { Tools } from "./tools.js";
|
|
13
|
-
export { Stats } from "./stats.js";
|
|
1
|
+
import{Alerts as e}from"./alerts.js";import{Cli as m}from"./cli.js";import{Credentials as f}from"./credentials.js";import{Events as s}from"./events.js";import{Files as l,PUBLISH_FROM as n,PUBLISH_TO as P}from"./files.js";import{Ingest as I,MAX_EVENTS as S}from"./ingest.js";import{Keys as g}from"./keys.js";import{Playground as E}from"./playground.js";import{Models as T,Pricing as _}from"./pricing.js";import{Invites as v,Projects as y}from"./projects.js";import{Prompts as C}from"./prompts.js";import{PromptsAdmin as H}from"./prompts-admin.js";import{Stats as O}from"./stats.js";import{Tools as j}from"./tools.js";export{e as Alerts,m as Cli,f as Credentials,s as Events,l as Files,I as Ingest,v as Invites,g as Keys,S as MAX_EVENTS,T as Models,n as PUBLISH_FROM,P as PUBLISH_TO,E as Playground,_ as Pricing,y as Projects,C as Prompts,H as PromptsAdmin,O as Stats,j as Tools};
|
package/dist/resources/ingest.js
CHANGED
|
@@ -1,27 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export class Ingest {
|
|
3
|
-
client;
|
|
4
|
-
project;
|
|
5
|
-
constructor(client, project) {
|
|
6
|
-
this.client = client;
|
|
7
|
-
this.project = project;
|
|
8
|
-
}
|
|
9
|
-
async send(events) {
|
|
10
|
-
await this.report(events);
|
|
11
|
-
}
|
|
12
|
-
async report(events) {
|
|
13
|
-
const total = { accepted: 0, rejected: 0, unpricedModels: [] };
|
|
14
|
-
if (events.length === 0)
|
|
15
|
-
return total;
|
|
16
|
-
const unpriced = new Set();
|
|
17
|
-
for (let i = 0; i < events.length; i += MAX_EVENTS) {
|
|
18
|
-
const res = await this.client.post("/api/v1/ingest", { events: events.slice(i, i + MAX_EVENTS) }, { project: this.project });
|
|
19
|
-
total.accepted += res?.accepted ?? 0;
|
|
20
|
-
total.rejected += res?.rejected ?? 0;
|
|
21
|
-
for (const model of res?.unpricedModels ?? [])
|
|
22
|
-
unpriced.add(model);
|
|
23
|
-
}
|
|
24
|
-
total.unpricedModels = [...unpriced];
|
|
25
|
-
return total;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
1
|
+
const i=100;class p{client;project;constructor(c,e){this.client=c,this.project=e}async send(c){await this.report(c)}async report(c){const e={accepted:0,rejected:0,unpricedModels:[]};if(c.length===0)return e;const r=new Set,o=c.map(t=>({...t,eventId:t.eventId??crypto.randomUUID()}));for(let t=0;t<o.length;t+=100){const n=await this.client.post("/api/v1/ingest",{events:o.slice(t,t+100)},{project:this.project});e.accepted+=n?.accepted??0,e.rejected+=n?.rejected??0;for(const s of n?.unpricedModels??[])r.add(s)}return e.unpricedModels=[...r],e}}export{p as Ingest,i as MAX_EVENTS};
|
package/dist/resources/keys.js
CHANGED
|
@@ -1,15 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
client;
|
|
3
|
-
constructor(client) {
|
|
4
|
-
this.client = client;
|
|
5
|
-
}
|
|
6
|
-
list(query = {}) {
|
|
7
|
-
return this.client.get("/api/v1/keys", { ...query });
|
|
8
|
-
}
|
|
9
|
-
create(body) {
|
|
10
|
-
return this.client.post("/api/v1/keys", body);
|
|
11
|
-
}
|
|
12
|
-
revoke(keyId) {
|
|
13
|
-
return this.client.delete(`/api/v1/keys/${encodeURIComponent(keyId)}`);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
1
|
+
class i{client;constructor(e){this.client=e}list(e={}){return this.client.get("/api/v1/keys",{...e})}create(e){return this.client.post("/api/v1/keys",e)}revoke(e){return this.client.delete(`/api/v1/keys/${encodeURIComponent(e)}`)}}export{i as Keys};
|
|
@@ -1,9 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
client;
|
|
3
|
-
constructor(client) {
|
|
4
|
-
this.client = client;
|
|
5
|
-
}
|
|
6
|
-
run(body) {
|
|
7
|
-
return this.client.post("/api/v1/playground/run", body);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
1
|
+
class r{client;constructor(t){this.client=t}run(t){return this.client.post("/api/v1/playground/run",t)}}export{r as Playground};
|
|
@@ -1,36 +1 @@
|
|
|
1
|
-
|
|
2
|
-
client;
|
|
3
|
-
constructor(client) {
|
|
4
|
-
this.client = client;
|
|
5
|
-
}
|
|
6
|
-
list() {
|
|
7
|
-
return this.client.get("/api/v1/pricing");
|
|
8
|
-
}
|
|
9
|
-
override(model, body) {
|
|
10
|
-
return this.client.put(`/api/v1/pricing/${encodeURIComponent(model)}`, body);
|
|
11
|
-
}
|
|
12
|
-
coverage() {
|
|
13
|
-
return this.client.get("/api/v1/pricing/coverage");
|
|
14
|
-
}
|
|
15
|
-
readiness() {
|
|
16
|
-
return this.client.get("/api/v1/pricing/readiness");
|
|
17
|
-
}
|
|
18
|
-
sync(body = {}) {
|
|
19
|
-
return this.client.post("/api/v1/pricing/sync", body);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
export class Models {
|
|
23
|
-
client;
|
|
24
|
-
constructor(client) {
|
|
25
|
-
this.client = client;
|
|
26
|
-
}
|
|
27
|
-
list(query = {}) {
|
|
28
|
-
return this.client.get("/api/v1/models", { ...query });
|
|
29
|
-
}
|
|
30
|
-
offers(query = {}) {
|
|
31
|
-
return this.client.get("/api/v1/offers", { ...query });
|
|
32
|
-
}
|
|
33
|
-
compare(query = {}) {
|
|
34
|
-
return this.client.get("/api/v1/compare", { ...query });
|
|
35
|
-
}
|
|
36
|
-
}
|
|
1
|
+
class r{client;constructor(e){this.client=e}list(){return this.client.get("/api/v1/pricing")}override(e,t){return this.client.put(`/api/v1/pricing/${encodeURIComponent(e)}`,t)}coverage(){return this.client.get("/api/v1/pricing/coverage")}readiness(){return this.client.get("/api/v1/pricing/readiness")}sync(e={}){return this.client.post("/api/v1/pricing/sync",e)}}class n{client;constructor(e){this.client=e}list(e={}){return this.client.get("/api/v1/models",{...e})}offers(e={}){return this.client.get("/api/v1/offers",{...e})}compare(e={}){return this.client.get("/api/v1/compare",{...e})}}export{n as Models,r as Pricing};
|
|
@@ -1,49 +1 @@
|
|
|
1
|
-
|
|
2
|
-
client;
|
|
3
|
-
constructor(client) {
|
|
4
|
-
this.client = client;
|
|
5
|
-
}
|
|
6
|
-
list() {
|
|
7
|
-
return this.client.get("/api/v1/projects");
|
|
8
|
-
}
|
|
9
|
-
create(body) {
|
|
10
|
-
return this.client.post("/api/v1/projects", body);
|
|
11
|
-
}
|
|
12
|
-
budget(projectId) {
|
|
13
|
-
return this.client.get(`/api/v1/projects/${encodeURIComponent(projectId)}/budget`);
|
|
14
|
-
}
|
|
15
|
-
setBudget(projectId, body) {
|
|
16
|
-
return this.client.put(`/api/v1/projects/${encodeURIComponent(projectId)}/budget`, body);
|
|
17
|
-
}
|
|
18
|
-
members(projectId) {
|
|
19
|
-
return this.client.get(`/api/v1/projects/${encodeURIComponent(projectId)}/members`);
|
|
20
|
-
}
|
|
21
|
-
addMember(projectId, body) {
|
|
22
|
-
return this.client.post(`/api/v1/projects/${encodeURIComponent(projectId)}/members`, body);
|
|
23
|
-
}
|
|
24
|
-
removeMember(projectId, userId) {
|
|
25
|
-
return this.client.delete(`/api/v1/projects/${encodeURIComponent(projectId)}/members`, {
|
|
26
|
-
userId,
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
invite(projectId, body) {
|
|
30
|
-
return this.client.post(`/api/v1/projects/${encodeURIComponent(projectId)}/invites`, body);
|
|
31
|
-
}
|
|
32
|
-
revokeInvite(projectId, inviteId) {
|
|
33
|
-
return this.client.delete(`/api/v1/projects/${encodeURIComponent(projectId)}/invites`, {
|
|
34
|
-
inviteId,
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
export class Invites {
|
|
39
|
-
client;
|
|
40
|
-
constructor(client) {
|
|
41
|
-
this.client = client;
|
|
42
|
-
}
|
|
43
|
-
preview(token) {
|
|
44
|
-
return this.client.get("/api/v1/invites/accept", { token });
|
|
45
|
-
}
|
|
46
|
-
accept(token) {
|
|
47
|
-
return this.client.post("/api/v1/invites/accept", { token });
|
|
48
|
-
}
|
|
49
|
-
}
|
|
1
|
+
class i{client;constructor(e){this.client=e}list(){return this.client.get("/api/v1/projects")}create(e){return this.client.post("/api/v1/projects",e)}budget(e){return this.client.get(`/api/v1/projects/${encodeURIComponent(e)}/budget`)}setBudget(e,t){return this.client.put(`/api/v1/projects/${encodeURIComponent(e)}/budget`,t)}members(e){return this.client.get(`/api/v1/projects/${encodeURIComponent(e)}/members`)}addMember(e,t){return this.client.post(`/api/v1/projects/${encodeURIComponent(e)}/members`,t)}removeMember(e,t){return this.client.delete(`/api/v1/projects/${encodeURIComponent(e)}/members`,{userId:t})}invite(e,t){return this.client.post(`/api/v1/projects/${encodeURIComponent(e)}/invites`,t)}revokeInvite(e,t){return this.client.delete(`/api/v1/projects/${encodeURIComponent(e)}/invites`,{inviteId:t})}}class r{client;constructor(e){this.client=e}preview(e){return this.client.get("/api/v1/invites/accept",{token:e})}accept(e){return this.client.post("/api/v1/invites/accept",{token:e})}}export{r as Invites,i as Projects};
|
|
@@ -1,21 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
client;
|
|
3
|
-
constructor(client) {
|
|
4
|
-
this.client = client;
|
|
5
|
-
}
|
|
6
|
-
publish(promptId, body = {}) {
|
|
7
|
-
return this.client.post(`/api/v1/prompts/${encodeURIComponent(promptId)}/publish`, body);
|
|
8
|
-
}
|
|
9
|
-
archive(promptId, query = {}) {
|
|
10
|
-
return this.client.post(`/api/v1/prompts/${encodeURIComponent(promptId)}/archive`, {}, { ...query });
|
|
11
|
-
}
|
|
12
|
-
assay(promptId, body) {
|
|
13
|
-
return this.client.post(`/api/v1/prompts/${encodeURIComponent(promptId)}/assay`, body);
|
|
14
|
-
}
|
|
15
|
-
runs(query = {}) {
|
|
16
|
-
return this.client.get("/api/v1/prompts/runs", { ...query });
|
|
17
|
-
}
|
|
18
|
-
run(runId) {
|
|
19
|
-
return this.client.get(`/api/v1/prompts/runs/${encodeURIComponent(runId)}`);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
1
|
+
class s{client;constructor(t){this.client=t}publish(t,n={}){return this.client.post(`/api/v1/prompts/${encodeURIComponent(t)}/publish`,n)}archive(t,n={}){return this.client.post(`/api/v1/prompts/${encodeURIComponent(t)}/archive`,{},{...n})}assay(t,n){return this.client.post(`/api/v1/prompts/${encodeURIComponent(t)}/assay`,n)}runs(t={}){return this.client.get("/api/v1/prompts/runs",{...t})}run(t){return this.client.get(`/api/v1/prompts/runs/${encodeURIComponent(t)}`)}}export{s as PromptsAdmin};
|
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
import type { Client } from "../core/client/index.js";
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* A turn as a rollout records it.
|
|
4
|
+
*
|
|
5
|
+
* `tool` is here because a conversation that used tools is not three roles
|
|
6
|
+
* pretending to be two. Narrating a result into a `user` message kept the words
|
|
7
|
+
* and lost the fact — and it misled the one reader that cared: the summary
|
|
8
|
+
* takes the last user message as the question when a prompt names no
|
|
9
|
+
* `question` field, so a tool-using run was captioned with whatever the tool
|
|
10
|
+
* said back.
|
|
11
|
+
*/
|
|
12
|
+
export type Role = "system" | "user" | "assistant" | "tool";
|
|
3
13
|
export interface RenderedMessage {
|
|
4
14
|
role: Role;
|
|
5
15
|
content: string;
|
|
16
|
+
/** Which tool answered, on a `tool` turn. Absent on the other three. */
|
|
17
|
+
name?: string;
|
|
6
18
|
}
|
|
7
19
|
export interface PromptBlock {
|
|
8
20
|
title?: string;
|
|
@@ -1,49 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
client;
|
|
3
|
-
constructor(client) {
|
|
4
|
-
this.client = client;
|
|
5
|
-
}
|
|
6
|
-
list(query = {}) {
|
|
7
|
-
return this.client.get("/api/v1/prompts", { ...query });
|
|
8
|
-
}
|
|
9
|
-
create(body) {
|
|
10
|
-
return this.client.post("/api/v1/prompts", body);
|
|
11
|
-
}
|
|
12
|
-
get(promptId, query = {}) {
|
|
13
|
-
return this.client.get(`/api/v1/prompts/${encodeURIComponent(promptId)}`, { ...query });
|
|
14
|
-
}
|
|
15
|
-
update(promptId, body, query = {}) {
|
|
16
|
-
return this.client.put(`/api/v1/prompts/${encodeURIComponent(promptId)}`, body, { ...query });
|
|
17
|
-
}
|
|
18
|
-
versions(promptId, query = {}) {
|
|
19
|
-
return this.client.get(`/api/v1/prompts/${encodeURIComponent(promptId)}/versions`, {
|
|
20
|
-
...query,
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
promote(promptId, versionId, query = {}) {
|
|
24
|
-
return this.client.post(`/api/v1/prompts/${encodeURIComponent(promptId)}/versions`, { versionId }, { ...query });
|
|
25
|
-
}
|
|
26
|
-
cases(promptId, query = {}) {
|
|
27
|
-
return this.client.get(`/api/v1/prompts/${encodeURIComponent(promptId)}/cases`, {
|
|
28
|
-
...query,
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
putCases(promptId, cases, query = {}) {
|
|
32
|
-
return this.client.put(`/api/v1/prompts/${encodeURIComponent(promptId)}/cases`, { cases }, { ...query });
|
|
33
|
-
}
|
|
34
|
-
rollouts(promptId, query = {}) {
|
|
35
|
-
return this.client.get(`/api/v1/prompts/${encodeURIComponent(promptId)}/rollouts`, {
|
|
36
|
-
...query,
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
report(promptId, body, query = {}) {
|
|
40
|
-
return this.client.post(`/api/v1/prompts/${encodeURIComponent(promptId)}/rollouts`, body, {
|
|
41
|
-
...query,
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
run(promptId, body, query = {}) {
|
|
45
|
-
return this.client.post(`/api/v1/prompts/${encodeURIComponent(promptId)}/run`, body, {
|
|
46
|
-
...query,
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
}
|
|
1
|
+
class p{client;constructor(t){this.client=t}list(t={}){return this.client.get("/api/v1/prompts",{...t})}create(t){return this.client.post("/api/v1/prompts",t)}get(t,e={}){return this.client.get(`/api/v1/prompts/${encodeURIComponent(t)}`,{...e})}update(t,e,o={}){return this.client.put(`/api/v1/prompts/${encodeURIComponent(t)}`,e,{...o})}versions(t,e={}){return this.client.get(`/api/v1/prompts/${encodeURIComponent(t)}/versions`,{...e})}promote(t,e,o={}){return this.client.post(`/api/v1/prompts/${encodeURIComponent(t)}/versions`,{versionId:e},{...o})}cases(t,e={}){return this.client.get(`/api/v1/prompts/${encodeURIComponent(t)}/cases`,{...e})}putCases(t,e,o={}){return this.client.put(`/api/v1/prompts/${encodeURIComponent(t)}/cases`,{cases:e},{...o})}rollouts(t,e={}){return this.client.get(`/api/v1/prompts/${encodeURIComponent(t)}/rollouts`,{...e})}report(t,e,o={}){return this.client.post(`/api/v1/prompts/${encodeURIComponent(t)}/rollouts`,e,{...o})}run(t,e,o={}){return this.client.post(`/api/v1/prompts/${encodeURIComponent(t)}/run`,e,{...o})}}export{p as Prompts};
|
package/dist/resources/stats.js
CHANGED
|
@@ -1,21 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
client;
|
|
3
|
-
constructor(client) {
|
|
4
|
-
this.client = client;
|
|
5
|
-
}
|
|
6
|
-
summary(query = {}) {
|
|
7
|
-
return this.client.get("/api/v1/stats/summary", { ...query });
|
|
8
|
-
}
|
|
9
|
-
timeseries(query = {}) {
|
|
10
|
-
return this.client.get("/api/v1/stats/timeseries", { ...query });
|
|
11
|
-
}
|
|
12
|
-
byModel(query = {}) {
|
|
13
|
-
return this.client.get("/api/v1/stats/by-model", { ...query });
|
|
14
|
-
}
|
|
15
|
-
byKey(query = {}) {
|
|
16
|
-
return this.client.get("/api/v1/stats/by-key", { ...query });
|
|
17
|
-
}
|
|
18
|
-
byTag(query = {}) {
|
|
19
|
-
return this.client.get("/api/v1/stats/by-tag", { ...query });
|
|
20
|
-
}
|
|
21
|
-
}
|
|
1
|
+
class s{client;constructor(t){this.client=t}summary(t={}){return this.client.get("/api/v1/stats/summary",{...t})}timeseries(t={}){return this.client.get("/api/v1/stats/timeseries",{...t})}byModel(t={}){return this.client.get("/api/v1/stats/by-model",{...t})}byKey(t={}){return this.client.get("/api/v1/stats/by-key",{...t})}byTag(t={}){return this.client.get("/api/v1/stats/by-tag",{...t})}}export{s as Stats};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { FieldSpec } from "../schema/index.js";
|
|
2
1
|
import type { Client } from "../core/client/index.js";
|
|
2
|
+
import type { FieldSpec } from "../schema/index.js";
|
|
3
3
|
import type { Scoped } from "./prompts.js";
|
|
4
4
|
/** What calling a tool does outside the process. Null means nobody has said. */
|
|
5
5
|
export type ToolEffect = "readonly" | "idempotent" | "destructive";
|
package/dist/resources/tools.js
CHANGED
|
@@ -1,21 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
client;
|
|
3
|
-
constructor(client) {
|
|
4
|
-
this.client = client;
|
|
5
|
-
}
|
|
6
|
-
list(query = {}) {
|
|
7
|
-
return this.client.get("/api/v1/tools", { ...query });
|
|
8
|
-
}
|
|
9
|
-
get(name, query = {}) {
|
|
10
|
-
return this.client.get(`/api/v1/tools/${encodeURIComponent(name)}`, { ...query });
|
|
11
|
-
}
|
|
12
|
-
create(body) {
|
|
13
|
-
return this.client.post("/api/v1/tools", body);
|
|
14
|
-
}
|
|
15
|
-
update(id, body, query = {}) {
|
|
16
|
-
return this.client.patch(`/api/v1/tools/${encodeURIComponent(id)}`, body, { ...query });
|
|
17
|
-
}
|
|
18
|
-
archive(id, archived, query = {}) {
|
|
19
|
-
return this.client.post(`/api/v1/tools/${encodeURIComponent(id)}/archive`, { archived }, { ...query });
|
|
20
|
-
}
|
|
21
|
-
}
|
|
1
|
+
class i{client;constructor(t){this.client=t}list(t={}){return this.client.get("/api/v1/tools",{...t})}get(t,e={}){return this.client.get(`/api/v1/tools/${encodeURIComponent(t)}`,{...e})}create(t){return this.client.post("/api/v1/tools",t)}update(t,e,o={}){return this.client.patch(`/api/v1/tools/${encodeURIComponent(t)}`,e,{...o})}archive(t,e,o={}){return this.client.post(`/api/v1/tools/${encodeURIComponent(t)}/archive`,{archived:e},{...o})}}export{i as Tools};
|
package/dist/rollout/index.d.ts
CHANGED
package/dist/rollout/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
import{totalTokens as e}from"./rollout.js";export{e as totalTokens};
|
|
@@ -21,8 +21,37 @@ export interface RolloutStep {
|
|
|
21
21
|
error?: string;
|
|
22
22
|
inputTokens?: number;
|
|
23
23
|
outputTokens?: number;
|
|
24
|
+
/**
|
|
25
|
+
* The four counts a provider bills apart from input and output.
|
|
26
|
+
*
|
|
27
|
+
* Optional and usually absent: most steps are a tool call, which has no
|
|
28
|
+
* tokens at all. A step that made a model call and left them off is saying
|
|
29
|
+
* the reply did not carry them — which is not the same as a workload that
|
|
30
|
+
* used no cache, and is why a rollup leaves the key out rather than adding a
|
|
31
|
+
* zero. The write is billed at a premium and the read at a discount, so a
|
|
32
|
+
* total built from the first two alone is wrong in both directions at once.
|
|
33
|
+
*/
|
|
34
|
+
cacheReadTokens?: number;
|
|
35
|
+
cacheWriteTokens?: number;
|
|
36
|
+
citationTokens?: number;
|
|
37
|
+
reasoningTokens?: number;
|
|
24
38
|
latencyMs?: number;
|
|
25
39
|
}
|
|
40
|
+
/** The counts beyond input and output, in the order a report reads them. */
|
|
41
|
+
declare const EXTRA: readonly ["cacheReadTokens", "cacheWriteTokens", "citationTokens", "reasoningTokens"];
|
|
42
|
+
type Extra = (typeof EXTRA)[number];
|
|
43
|
+
/**
|
|
44
|
+
* What every step in a rollout adds up to.
|
|
45
|
+
*
|
|
46
|
+
* Here rather than in each caller for the reason `RolloutStep` is: a second
|
|
47
|
+
* copy is how two capabilities end up disagreeing about what a run cost. They
|
|
48
|
+
* had — one guarded the counts and one did not, so the same nested steps
|
|
49
|
+
* totalled a number in a graph run and `NaN` in a refine loop.
|
|
50
|
+
*/
|
|
51
|
+
export declare function totalTokens(steps: RolloutStep[]): {
|
|
52
|
+
inputTokens: number;
|
|
53
|
+
outputTokens: number;
|
|
54
|
+
} & Partial<Record<Extra, number>>;
|
|
26
55
|
/** What a caller hands back after running something itself. */
|
|
27
56
|
export interface RolloutInput {
|
|
28
57
|
/** Dedupe key. Generated if omitted; supply your own to make a retry safe. */
|
|
@@ -73,3 +102,4 @@ export interface RolloutRecord {
|
|
|
73
102
|
inputTokens: number;
|
|
74
103
|
outputTokens: number;
|
|
75
104
|
}
|
|
105
|
+
export {};
|
package/dist/rollout/rollout.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
const c=["cacheReadTokens","cacheWriteTokens","citationTokens","reasoningTokens"];function s(n){return typeof n!="number"||!Number.isFinite(n)||n<0?0:Math.trunc(n)}function u(n){let i=0,r=0;const o={};for(const t of n){i+=s(t.inputTokens),r+=s(t.outputTokens);for(const e of c)t[e]!==void 0&&(o[e]=(o[e]??0)+s(t[e]))}return{inputTokens:i,outputTokens:r,...o}}export{u as totalTokens};
|
package/dist/schema/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { serializeFields } from "./serialize/index.js";
|
|
2
2
|
export type { FieldSpec, FieldType } from "./types/index.js";
|
|
3
|
-
export { type FieldError, FieldValidationError, validateFields } from "./validate/index.js";
|
|
3
|
+
export { type FieldError, FieldValidationError, isMissing, toBoolean, toNumber, validateFields, } from "./validate/index.js";
|
package/dist/schema/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { FieldValidationError, validateFields } from "./validate/index.js";
|
|
1
|
+
import{serializeFields as o}from"./serialize/index.js";import{FieldValidationError as l,isMissing as a,toBoolean as s,toNumber as t,validateFields as d}from"./validate/index.js";export{l as FieldValidationError,a as isMissing,o as serializeFields,s as toBoolean,t as toNumber,d as validateFields};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{serializeFields as r}from"./serialize.js";export{r as serializeFields};
|