@avow-finance/sdk 0.0.0-stage → 0.2.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 +201 -0
- package/README.md +122 -2
- package/dist/agent-entry.d.ts +15 -0
- package/dist/agent-entry.d.ts.map +1 -0
- package/dist/agent-entry.js +11 -0
- package/dist/agent-entry.js.map +1 -0
- package/dist/agent-key.d.ts +34 -0
- package/dist/agent-key.d.ts.map +1 -0
- package/dist/agent-key.js +33 -0
- package/dist/agent-key.js.map +1 -0
- package/dist/agent.d.ts +261 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +493 -0
- package/dist/agent.js.map +1 -0
- package/dist/avow-api.d.ts +78 -0
- package/dist/avow-api.d.ts.map +1 -0
- package/dist/avow-api.js +2 -0
- package/dist/avow-api.js.map +1 -0
- package/dist/contest.d.ts +135 -0
- package/dist/contest.d.ts.map +1 -0
- package/dist/contest.js +186 -0
- package/dist/contest.js.map +1 -0
- package/dist/http.d.ts +161 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +311 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -0
- package/dist/job/accept.d.ts +84 -0
- package/dist/job/accept.d.ts.map +1 -0
- package/dist/job/accept.js +136 -0
- package/dist/job/accept.js.map +1 -0
- package/dist/job/customer.d.ts +43 -0
- package/dist/job/customer.d.ts.map +1 -0
- package/dist/job/customer.js +83 -0
- package/dist/job/customer.js.map +1 -0
- package/dist/job/quote.d.ts +34 -0
- package/dist/job/quote.d.ts.map +1 -0
- package/dist/job/quote.js +37 -0
- package/dist/job/quote.js.map +1 -0
- package/dist/lock.d.ts +269 -0
- package/dist/lock.d.ts.map +1 -0
- package/dist/lock.js +283 -0
- package/dist/lock.js.map +1 -0
- package/dist/moderato.d.ts +27 -0
- package/dist/moderato.d.ts.map +1 -0
- package/dist/moderato.js +34 -0
- package/dist/moderato.js.map +1 -0
- package/dist/node/cli.d.ts +3 -0
- package/dist/node/cli.d.ts.map +1 -0
- package/dist/node/cli.js +346 -0
- package/dist/node/cli.js.map +1 -0
- package/dist/node/connect.d.ts +15 -0
- package/dist/node/connect.d.ts.map +1 -0
- package/dist/node/connect.js +91 -0
- package/dist/node/connect.js.map +1 -0
- package/dist/node/eval.d.ts +3 -0
- package/dist/node/eval.d.ts.map +1 -0
- package/dist/node/eval.js +67 -0
- package/dist/node/eval.js.map +1 -0
- package/dist/node/first-run.d.ts +50 -0
- package/dist/node/first-run.d.ts.map +1 -0
- package/dist/node/first-run.js +149 -0
- package/dist/node/first-run.js.map +1 -0
- package/dist/node/job.d.ts +50 -0
- package/dist/node/job.d.ts.map +1 -0
- package/dist/node/job.js +176 -0
- package/dist/node/job.js.map +1 -0
- package/dist/node/mailbox.d.ts +19 -0
- package/dist/node/mailbox.d.ts.map +1 -0
- package/dist/node/mailbox.js +81 -0
- package/dist/node/mailbox.js.map +1 -0
- package/dist/node/mcp.d.ts +74 -0
- package/dist/node/mcp.d.ts.map +1 -0
- package/dist/node/mcp.js +367 -0
- package/dist/node/mcp.js.map +1 -0
- package/dist/node/platform.d.ts +35 -0
- package/dist/node/platform.d.ts.map +1 -0
- package/dist/node/platform.js +102 -0
- package/dist/node/platform.js.map +1 -0
- package/dist/node/runner-session.d.ts +41 -0
- package/dist/node/runner-session.d.ts.map +1 -0
- package/dist/node/runner-session.js +100 -0
- package/dist/node/runner-session.js.map +1 -0
- package/dist/node/runner.d.ts +63 -0
- package/dist/node/runner.d.ts.map +1 -0
- package/dist/node/runner.js +341 -0
- package/dist/node/runner.js.map +1 -0
- package/dist/node/service-child.d.ts +2 -0
- package/dist/node/service-child.d.ts.map +1 -0
- package/dist/node/service-child.js +40 -0
- package/dist/node/service-child.js.map +1 -0
- package/dist/node/service-excerpt.d.ts +21 -0
- package/dist/node/service-excerpt.d.ts.map +1 -0
- package/dist/node/service-excerpt.js +32 -0
- package/dist/node/service-excerpt.js.map +1 -0
- package/dist/node/service-process.d.ts +12 -0
- package/dist/node/service-process.d.ts.map +1 -0
- package/dist/node/service-process.js +132 -0
- package/dist/node/service-process.js.map +1 -0
- package/dist/node/session-input.d.ts +12 -0
- package/dist/node/session-input.d.ts.map +1 -0
- package/dist/node/session-input.js +42 -0
- package/dist/node/session-input.js.map +1 -0
- package/dist/node/session-view.d.ts +20 -0
- package/dist/node/session-view.d.ts.map +1 -0
- package/dist/node/session-view.js +198 -0
- package/dist/node/session-view.js.map +1 -0
- package/dist/node-agent.d.ts +2 -0
- package/dist/node-agent.d.ts.map +1 -0
- package/dist/node-agent.js +6 -0
- package/dist/node-agent.js.map +1 -0
- package/dist/node.d.ts +2 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +9 -0
- package/dist/node.js.map +1 -0
- package/dist/sandbox/agent.d.ts +187 -0
- package/dist/sandbox/agent.d.ts.map +1 -0
- package/dist/sandbox/agent.js +468 -0
- package/dist/sandbox/agent.js.map +1 -0
- package/dist/sandbox/business-store.d.ts +19 -0
- package/dist/sandbox/business-store.d.ts.map +1 -0
- package/dist/sandbox/business-store.js +19 -0
- package/dist/sandbox/business-store.js.map +1 -0
- package/dist/sandbox/business.d.ts +70 -0
- package/dist/sandbox/business.d.ts.map +1 -0
- package/dist/sandbox/business.js +115 -0
- package/dist/sandbox/business.js.map +1 -0
- package/dist/sandbox/connect.d.ts +64 -0
- package/dist/sandbox/connect.d.ts.map +1 -0
- package/dist/sandbox/connect.js +182 -0
- package/dist/sandbox/connect.js.map +1 -0
- package/dist/sandbox/deployment.d.ts +14 -0
- package/dist/sandbox/deployment.d.ts.map +1 -0
- package/dist/sandbox/deployment.js +38 -0
- package/dist/sandbox/deployment.js.map +1 -0
- package/dist/sandbox/keys.d.ts +45 -0
- package/dist/sandbox/keys.d.ts.map +1 -0
- package/dist/sandbox/keys.js +132 -0
- package/dist/sandbox/keys.js.map +1 -0
- package/dist/sandbox/mailbox.d.ts +90 -0
- package/dist/sandbox/mailbox.d.ts.map +1 -0
- package/dist/sandbox/mailbox.js +400 -0
- package/dist/sandbox/mailbox.js.map +1 -0
- package/dist/sandbox/mandate.d.ts +84 -0
- package/dist/sandbox/mandate.d.ts.map +1 -0
- package/dist/sandbox/mandate.js +107 -0
- package/dist/sandbox/mandate.js.map +1 -0
- package/dist/sandbox/namespace.d.ts +16 -0
- package/dist/sandbox/namespace.d.ts.map +1 -0
- package/dist/sandbox/namespace.js +16 -0
- package/dist/sandbox/namespace.js.map +1 -0
- package/dist/sandbox/session.d.ts +60 -0
- package/dist/sandbox/session.d.ts.map +1 -0
- package/dist/sandbox/session.js +94 -0
- package/dist/sandbox/session.js.map +1 -0
- package/dist/sandbox/setup.d.ts +136 -0
- package/dist/sandbox/setup.d.ts.map +1 -0
- package/dist/sandbox/setup.js +490 -0
- package/dist/sandbox/setup.js.map +1 -0
- package/dist/sandbox/store.d.ts +69 -0
- package/dist/sandbox/store.d.ts.map +1 -0
- package/dist/sandbox/store.js +115 -0
- package/dist/sandbox/store.js.map +1 -0
- package/dist/sandbox/supplier-key.d.ts +73 -0
- package/dist/sandbox/supplier-key.d.ts.map +1 -0
- package/dist/sandbox/supplier-key.js +180 -0
- package/dist/sandbox/supplier-key.js.map +1 -0
- package/dist/sandbox/suppliers.d.ts +7 -0
- package/dist/sandbox/suppliers.d.ts.map +1 -0
- package/dist/sandbox/suppliers.js +29 -0
- package/dist/sandbox/suppliers.js.map +1 -0
- package/dist/sandbox/terms.d.ts +32 -0
- package/dist/sandbox/terms.d.ts.map +1 -0
- package/dist/sandbox/terms.js +58 -0
- package/dist/sandbox/terms.js.map +1 -0
- package/dist/sandbox/vault.d.ts +24 -0
- package/dist/sandbox/vault.d.ts.map +1 -0
- package/dist/sandbox/vault.js +54 -0
- package/dist/sandbox/vault.js.map +1 -0
- package/dist/send.d.ts +122 -0
- package/dist/send.d.ts.map +1 -0
- package/dist/send.js +328 -0
- package/dist/send.js.map +1 -0
- package/dist/service-entry.d.ts +6 -0
- package/dist/service-entry.d.ts.map +1 -0
- package/dist/service-entry.js +6 -0
- package/dist/service-entry.js.map +1 -0
- package/dist/session/anthropic.d.ts +17 -0
- package/dist/session/anthropic.d.ts.map +1 -0
- package/dist/session/anthropic.js +215 -0
- package/dist/session/anthropic.js.map +1 -0
- package/dist/session/charge.d.ts +13 -0
- package/dist/session/charge.d.ts.map +1 -0
- package/dist/session/charge.js +33 -0
- package/dist/session/charge.js.map +1 -0
- package/dist/session/data.d.ts +8 -0
- package/dist/session/data.d.ts.map +1 -0
- package/dist/session/data.js +20 -0
- package/dist/session/data.js.map +1 -0
- package/dist/session/eval.d.ts +41 -0
- package/dist/session/eval.d.ts.map +1 -0
- package/dist/session/eval.js +281 -0
- package/dist/session/eval.js.map +1 -0
- package/dist/session/executor.d.ts +80 -0
- package/dist/session/executor.d.ts.map +1 -0
- package/dist/session/executor.js +381 -0
- package/dist/session/executor.js.map +1 -0
- package/dist/session/fixture-world.d.ts +29 -0
- package/dist/session/fixture-world.d.ts.map +1 -0
- package/dist/session/fixture-world.js +708 -0
- package/dist/session/fixture-world.js.map +1 -0
- package/dist/session/live-world.d.ts +22 -0
- package/dist/session/live-world.d.ts.map +1 -0
- package/dist/session/live-world.js +329 -0
- package/dist/session/live-world.js.map +1 -0
- package/dist/session/ollama.d.ts +29 -0
- package/dist/session/ollama.d.ts.map +1 -0
- package/dist/session/ollama.js +177 -0
- package/dist/session/ollama.js.map +1 -0
- package/dist/session/provider.d.ts +79 -0
- package/dist/session/provider.d.ts.map +1 -0
- package/dist/session/provider.js +19 -0
- package/dist/session/provider.js.map +1 -0
- package/dist/session/scripted.d.ts +45 -0
- package/dist/session/scripted.d.ts.map +1 -0
- package/dist/session/scripted.js +236 -0
- package/dist/session/scripted.js.map +1 -0
- package/dist/session/selection.d.ts +37 -0
- package/dist/session/selection.d.ts.map +1 -0
- package/dist/session/selection.js +104 -0
- package/dist/session/selection.js.map +1 -0
- package/dist/session/service-check.d.ts +48 -0
- package/dist/session/service-check.d.ts.map +1 -0
- package/dist/session/service-check.js +86 -0
- package/dist/session/service-check.js.map +1 -0
- package/dist/session/service.d.ts +128 -0
- package/dist/session/service.d.ts.map +1 -0
- package/dist/session/service.js +150 -0
- package/dist/session/service.js.map +1 -0
- package/dist/session/session.d.ts +95 -0
- package/dist/session/session.d.ts.map +1 -0
- package/dist/session/session.js +312 -0
- package/dist/session/session.js.map +1 -0
- package/dist/session/toolbox.d.ts +69 -0
- package/dist/session/toolbox.d.ts.map +1 -0
- package/dist/session/toolbox.js +391 -0
- package/dist/session/toolbox.js.map +1 -0
- package/dist/session/tools.d.ts +45 -0
- package/dist/session/tools.d.ts.map +1 -0
- package/dist/session/tools.js +137 -0
- package/dist/session/tools.js.map +1 -0
- package/dist/session/world.d.ts +188 -0
- package/dist/session/world.d.ts.map +1 -0
- package/dist/session/world.js +2 -0
- package/dist/session/world.js.map +1 -0
- package/dist/sign.d.ts +19 -0
- package/dist/sign.d.ts.map +1 -0
- package/dist/sign.js +33 -0
- package/dist/sign.js.map +1 -0
- package/dist/supplier.d.ts +41 -0
- package/dist/supplier.d.ts.map +1 -0
- package/dist/supplier.js +57 -0
- package/dist/supplier.js.map +1 -0
- package/package.json +56 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ollama.js","sourceRoot":"","sources":["../../src/session/ollama.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,aAAa,GAEd,MAAM,eAAe,CAAA;AAEtB;;;GAGG;AAEH,uCAAuC;AACvC,MAAM,CAAC,MAAM,UAAU,GAAG,wBAAwB,CAAA;AAElD,sFAAsF;AACtF,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,UAAU,EAAE,aAAa,EAAE,UAAU,CAAU,CAAA;AAEtF,oGAAoG;AACpG,MAAM,cAAc,GAAG,MAAM,CAAA;AAE7B;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,IAAI,GAAG,UAAU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0 +1,79 @@
|
|
|
1
|
+
import type { ToolSpec } from './tools.js';
|
|
2
|
+
/**
|
|
3
|
+
* One interface for every model the session can talk to. The session keeps the conversation in
|
|
4
|
+
* this neutral shape and each provider maps it to its own wire form, so the tool layer, the
|
|
5
|
+
* executor and the eval never depend on which model is speaking.
|
|
6
|
+
*/
|
|
7
|
+
/** The providers the session knows, as `--provider` names them. */
|
|
8
|
+
export declare const PROVIDER_KINDS: readonly ['local', 'anthropic', 'scripted'];
|
|
9
|
+
export type ProviderKind = (typeof PROVIDER_KINDS)[number];
|
|
10
|
+
/** A tool call a model asked for, with the id its provider pairs the result by. */
|
|
11
|
+
export interface ModelToolCall {
|
|
12
|
+
id: string;
|
|
13
|
+
name: string;
|
|
14
|
+
/** The model's input as its provider parsed it. It's untrusted until the tool layer reads it. */
|
|
15
|
+
input: unknown;
|
|
16
|
+
}
|
|
17
|
+
/** One turn of the conversation, as the session replays it to the provider. */
|
|
18
|
+
export type ChatTurn = {
|
|
19
|
+
role: 'user';
|
|
20
|
+
text: string;
|
|
21
|
+
} | {
|
|
22
|
+
role: 'assistant';
|
|
23
|
+
text: string;
|
|
24
|
+
calls: readonly ModelToolCall[];
|
|
25
|
+
/** What the provider needs to replay the turn exactly, such as Anthropic's content blocks. */
|
|
26
|
+
native: unknown;
|
|
27
|
+
} | {
|
|
28
|
+
role: 'tool';
|
|
29
|
+
call: ModelToolCall;
|
|
30
|
+
content: string;
|
|
31
|
+
ok: boolean;
|
|
32
|
+
};
|
|
33
|
+
/** What one model turn gave back. */
|
|
34
|
+
export interface ModelReply {
|
|
35
|
+
text: string;
|
|
36
|
+
calls: ModelToolCall[];
|
|
37
|
+
native: unknown;
|
|
38
|
+
/** Whether the model ended its turn, asked for tools, or ran out of room. */
|
|
39
|
+
stop: 'end' | 'tools' | 'length';
|
|
40
|
+
/** Timings for the eval's speed report, when the provider measures them. */
|
|
41
|
+
timing: ReplyTiming | null;
|
|
42
|
+
}
|
|
43
|
+
export interface ReplyTiming {
|
|
44
|
+
/** Milliseconds from the request to the first piece of the reply. */
|
|
45
|
+
firstTokenMs: number | null;
|
|
46
|
+
/** Tokens the model generated, and the milliseconds it spent generating them. */
|
|
47
|
+
tokens: number | null;
|
|
48
|
+
generatingMs: number | null;
|
|
49
|
+
totalMs: number;
|
|
50
|
+
}
|
|
51
|
+
export interface ReplyRequest {
|
|
52
|
+
system: string;
|
|
53
|
+
turns: readonly ChatTurn[];
|
|
54
|
+
tools: readonly ToolSpec[];
|
|
55
|
+
/** Each piece of the model's words as it arrives, for the terminal to draw. */
|
|
56
|
+
onText: (piece: string) => void;
|
|
57
|
+
signal?: AbortSignal;
|
|
58
|
+
}
|
|
59
|
+
export interface ModelProvider {
|
|
60
|
+
readonly kind: ProviderKind;
|
|
61
|
+
/** The model's id, which names every line it speaks. */
|
|
62
|
+
readonly model: string;
|
|
63
|
+
/** The line the session shows before the first call: the model, where it runs and who pays. */
|
|
64
|
+
readonly line: string;
|
|
65
|
+
/** Whether the conversation leaves this machine, and for whom. */
|
|
66
|
+
readonly reaches: 'this machine' | 'Anthropic';
|
|
67
|
+
reply(request: ReplyRequest): Promise<ModelReply>;
|
|
68
|
+
}
|
|
69
|
+
/** A provider that failed, with what the developer can do about it. */
|
|
70
|
+
export declare class ProviderError extends Error {
|
|
71
|
+
/** Whether asking again later can work, as after a rate limit or a model still loading. */
|
|
72
|
+
readonly retryable: boolean;
|
|
73
|
+
constructor(message: string,
|
|
74
|
+
/** Whether asking again later can work, as after a rate limit or a model still loading. */
|
|
75
|
+
retryable: boolean, options?: {
|
|
76
|
+
cause?: unknown;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/session/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAE1C;;;;GAIG;AAEH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AC3B,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,SAAS,QAAQ,EAAE,CAAA;IAC1B,KAAK,EAAE,SAAS,QAAQ,EAAE,CAAA;IAC1B,+EAA+E;IAC/E,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IAC/B,MAAM,CAAC,EAAE,WAAW,CAAA;CACrB;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAA;IAC3B,wDAAwD;IACxD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,+FAA+F;IAC/F,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,kEAAkE;IAClE,QAAQ,CAAC,OAAO,EAAE,cAAc,GAAG,WAAW,CAAA;IAC9C,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;CAClD;AAED,uEAAuE;AACvE,qBAAa,aAAc,SAAQ,KAAK;IAGpC,2FAA2F;IAC3F,QAAQ,CAAC,SAAS,EAAE,OAAO;IAH7B,YACE,OAAO,EAAE,MAAM;IACf,2FAA2F;IAClF,SAAS,EAAE,OAAO,EAC3B,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,EAI9B;CACF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One interface for every model the session can talk to. The session keeps the conversation in
|
|
3
|
+
* this neutral shape and each provider maps it to its own wire form, so the tool layer, the
|
|
4
|
+
* executor and the eval never depend on which model is speaking.
|
|
5
|
+
*/
|
|
6
|
+
/** The providers the session knows, as `--provider` names them. */
|
|
7
|
+
export const PROVIDER_KINDS = ['local', 'anthropic', 'scripted'];
|
|
8
|
+
/** A provider that failed, with what the developer can do about it. */
|
|
9
|
+
export class ProviderError extends Error {
|
|
10
|
+
retryable;
|
|
11
|
+
constructor(message,
|
|
12
|
+
/** Whether asking again later can work, as after a rate limit or a model still loading. */
|
|
13
|
+
retryable, options) {
|
|
14
|
+
super(message, options);
|
|
15
|
+
this.retryable = retryable;
|
|
16
|
+
this.name = 'ProviderError';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../src/session/provider.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH,mEAAmE;AACnE,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,OAAO,EAAE,WAAW,EAAE,UAAU,CAAU,CAAA;AA+DzE,uEAAuE;AACvE,MAAM,OAAO,aAAc,SAAQ,KAAK;IAI3B,SAAS;IAHpB,YACE,OAAe;IACf,2FAA2F;IAClF,SAAkB,EAC3B,OAA6B;QAE7B,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;yBAHd,SAAS;QAIlB,IAAI,CAAC,IAAI,GAAG,eAAe,CAAA;IAC7B,CAAC;CACF"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { ModelProvider } from './provider.js';
|
|
2
|
+
/**
|
|
3
|
+
* Scripted decisions in place of a model, so a run is the same every time. It reads the tool
|
|
4
|
+
* results the session gave it and decides as a careful agent would: the cheapest firm offer that
|
|
5
|
+
* holds the job's GPUs for its whole run within the budget, then a quote naming that booking. It
|
|
6
|
+
* speaks as `scripted`, so nothing it says can pass for a model's words.
|
|
7
|
+
*/
|
|
8
|
+
/** What the session says when an order comes in, which starts a job's run. */
|
|
9
|
+
export declare const ORDER_PROMPT = "New order";
|
|
10
|
+
/** What the session says when the developer switched compute off and still wants a quote. */
|
|
11
|
+
export declare const SWITCH_OFF_PROMPT = "switched compute off";
|
|
12
|
+
/** How the session's prompt starts when the customer refused a quote and the agent explains it. */
|
|
13
|
+
export declare const CUSTOMER_REFUSED_PROMPT = "The customer refused the quote";
|
|
14
|
+
interface OfferSeen {
|
|
15
|
+
id: string;
|
|
16
|
+
gpusPerBooking: string;
|
|
17
|
+
windowStarts: string;
|
|
18
|
+
windowEnds: string;
|
|
19
|
+
pricePerGpuHour: string;
|
|
20
|
+
freeCancellation: string;
|
|
21
|
+
}
|
|
22
|
+
interface ListingSeen {
|
|
23
|
+
offers: OfferSeen[];
|
|
24
|
+
limits: {
|
|
25
|
+
computeBudgetPerGpuHour: string;
|
|
26
|
+
computeSwitch: 'on' | 'off';
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
interface OrderSeen {
|
|
30
|
+
orderId: string;
|
|
31
|
+
needs: {
|
|
32
|
+
gpu: string;
|
|
33
|
+
gpus: number;
|
|
34
|
+
};
|
|
35
|
+
deliverBy: string;
|
|
36
|
+
}
|
|
37
|
+
/** The offer a careful agent books for the order, or why there's none. */
|
|
38
|
+
export declare function chooseOffer(order: OrderSeen, listing: ListingSeen): {
|
|
39
|
+
offer: OfferSeen;
|
|
40
|
+
} | {
|
|
41
|
+
none: string;
|
|
42
|
+
};
|
|
43
|
+
export declare function scriptedProvider(): ModelProvider;
|
|
44
|
+
export {};
|
|
45
|
+
//# sourceMappingURL=scripted.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scripted.d.ts","sourceRoot":"","sources":["../../src/session/scripted.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAEV,aAAa,EAId,MAAM,eAAe,CAAA;AAEtB;;;;;GAKG;AAEH,8EAA8E;AAC9E,eAAO,MAAM,YAAY,cAAc,CAAA;AACvC,6FAA6F;AAC7F,eAAO,MAAM,iBAAiB,yBAAyB,CAAA;AACvD,mGAAmG;AACnG,eAAO,MAAM,uBAAuB,mCAAmC,CAAA;AAEvE,UAAU,SAAS;IACjB,EAAE,EAAE,MAAM,CAAA;IACV,cAAc,EAAE,MAAM,CAAA;IACtB,YAAY,EAAE,MAAM,CAAA;IACpB,UAAU,EAAE,MAAM,CAAA;IAClB,eAAe,EAAE,MAAM,CAAA;IACvB,gBAAgB,EAAE,MAAM,CAAA;CACzB;AAED,UAAU,WAAW;IACnB,MAAM,EAAE,SAAS,EAAE,CAAA;IACnB,MAAM,EAAE;QAAE,uBAAuB,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,IAAI,GAAG,KAAK,CAAA;KAAE,CAAA;CACzE;AAED,UAAU,SAAS;IACjB,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAA;IACpC,SAAS,EAAE,MAAM,CAAA;CAClB;AAoBD,0EAA0E;AAC1E,wBAAgB,WAAW,CACzB,KAAK,EAAE,SAAS,EAChB,OAAO,EAAE,WAAW,GACnB;IAAE,KAAK,EAAE,SAAS,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAyBzC;AA2KD,wBAAgB,gBAAgB,IAAI,aAAa,CAwBhD"}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { SCRIPTED_MODEL } from '@avow-finance/spec';
|
|
2
|
+
/**
|
|
3
|
+
* Scripted decisions in place of a model, so a run is the same every time. It reads the tool
|
|
4
|
+
* results the session gave it and decides as a careful agent would: the cheapest firm offer that
|
|
5
|
+
* holds the job's GPUs for its whole run within the budget, then a quote naming that booking. It
|
|
6
|
+
* speaks as `scripted`, so nothing it says can pass for a model's words.
|
|
7
|
+
*/
|
|
8
|
+
/** What the session says when an order comes in, which starts a job's run. */
|
|
9
|
+
export const ORDER_PROMPT = 'New order';
|
|
10
|
+
/** What the session says when the developer switched compute off and still wants a quote. */
|
|
11
|
+
export const SWITCH_OFF_PROMPT = 'switched compute off';
|
|
12
|
+
/** How the session's prompt starts when the customer refused a quote and the agent explains it. */
|
|
13
|
+
export const CUSTOMER_REFUSED_PROMPT = 'The customer refused the quote';
|
|
14
|
+
const dollars = (text) => Number(text.replace(/[^0-9.]/g, ''));
|
|
15
|
+
/** Minutes after the job starts that a time the tool layer wrote names, negative before it. */
|
|
16
|
+
function minutesFromStart(text) {
|
|
17
|
+
if (text.includes('when the job starts'))
|
|
18
|
+
return 0;
|
|
19
|
+
const m = /(\d+) min (before|after) the job starts/.exec(text);
|
|
20
|
+
if (!m)
|
|
21
|
+
return null;
|
|
22
|
+
return Number(m[1]) * (m[2] === 'before' ? -1 : 1);
|
|
23
|
+
}
|
|
24
|
+
/** Whether an offer takes a booking of `count` GPUs, as the tool layer wrote its range. */
|
|
25
|
+
function takes(offer, count) {
|
|
26
|
+
const exactly = /^exactly (\d+)$/.exec(offer.gpusPerBooking);
|
|
27
|
+
if (exactly)
|
|
28
|
+
return Number(exactly[1]) === count;
|
|
29
|
+
const range = /^(\d+) to (\d+)$/.exec(offer.gpusPerBooking);
|
|
30
|
+
return range ? count >= Number(range[1]) && count <= Number(range[2]) : false;
|
|
31
|
+
}
|
|
32
|
+
/** The offer a careful agent books for the order, or why there's none. */
|
|
33
|
+
export function chooseOffer(order, listing) {
|
|
34
|
+
const due = minutesFromStart(order.deliverBy) ?? 0;
|
|
35
|
+
const budget = dollars(listing.limits.computeBudgetPerGpuHour);
|
|
36
|
+
const fits = listing.offers.filter((o) => {
|
|
37
|
+
const from = minutesFromStart(o.windowStarts);
|
|
38
|
+
const to = minutesFromStart(o.windowEnds);
|
|
39
|
+
return (o.freeCancellation.startsWith('none') &&
|
|
40
|
+
from !== null &&
|
|
41
|
+
to !== null &&
|
|
42
|
+
from <= 0 &&
|
|
43
|
+
to >= due &&
|
|
44
|
+
takes(o, order.needs.gpus));
|
|
45
|
+
});
|
|
46
|
+
if (fits.length === 0) {
|
|
47
|
+
return { none: 'none of the offers is firm and holds the GPUs for the whole job' };
|
|
48
|
+
}
|
|
49
|
+
const affordable = fits.filter((o) => dollars(o.pricePerGpuHour) <= budget);
|
|
50
|
+
const [cheapest] = [...affordable].sort((a, b) => dollars(a.pricePerGpuHour) - dollars(b.pricePerGpuHour));
|
|
51
|
+
if (!cheapest)
|
|
52
|
+
return { none: `every offer that fits costs more than the $${budget.toFixed(2)} budget` };
|
|
53
|
+
return { offer: cheapest };
|
|
54
|
+
}
|
|
55
|
+
/** The turns since the latest thing the developer or the session said. */
|
|
56
|
+
function sinceAsked(turns) {
|
|
57
|
+
let i = turns.length - 1;
|
|
58
|
+
while (i >= 0 && turns[i]?.role !== 'user')
|
|
59
|
+
i--;
|
|
60
|
+
const asked = turns[i];
|
|
61
|
+
return {
|
|
62
|
+
prompt: asked?.role === 'user' ? asked.text : '',
|
|
63
|
+
results: turns
|
|
64
|
+
.slice(i + 1)
|
|
65
|
+
.filter((t) => t.role === 'tool'),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/** The latest result of a tool anywhere in the conversation, as the JSON it carried. */
|
|
69
|
+
function latest(turns, tool, ok = true) {
|
|
70
|
+
for (let i = turns.length - 1; i >= 0; i--) {
|
|
71
|
+
const t = turns[i];
|
|
72
|
+
if (t?.role === 'tool' && t.call.name === tool && t.ok === ok) {
|
|
73
|
+
try {
|
|
74
|
+
return JSON.parse(t.content);
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
let nextCall = 1;
|
|
84
|
+
const call = (name, input = {}) => ({
|
|
85
|
+
id: `scripted_${nextCall++}`,
|
|
86
|
+
name,
|
|
87
|
+
input,
|
|
88
|
+
});
|
|
89
|
+
/**
|
|
90
|
+
* A refusal a tool gave, said as its layer and code and what would let it pass. The refusal's own
|
|
91
|
+
* sentence is already on the screen, so only its last sentence, which says what would let the same
|
|
92
|
+
* thing pass, is said again.
|
|
93
|
+
*/
|
|
94
|
+
function refusalLine(content) {
|
|
95
|
+
try {
|
|
96
|
+
const r = JSON.parse(content);
|
|
97
|
+
const passes = (r.sentence ?? r.why ?? '').split(/(?<=\.)\s+/).at(-1) ?? '';
|
|
98
|
+
return `It was refused at the ${r.layer} layer with ${r.code}. ${passes}`.trim();
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
return 'It was refused.';
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/** The next step for the run the latest prompt started, given what the tools gave back so far. */
|
|
105
|
+
function decide(turns) {
|
|
106
|
+
const { prompt, results } = sinceAsked(turns);
|
|
107
|
+
const last = results.at(-1);
|
|
108
|
+
const done = (tool) => results.find((r) => r.call.name === tool);
|
|
109
|
+
if (prompt.startsWith(ORDER_PROMPT) || prompt.includes(SWITCH_OFF_PROMPT)) {
|
|
110
|
+
if (!done('read_order'))
|
|
111
|
+
return { text: '', calls: [call('read_order')] };
|
|
112
|
+
if (!done('compute_offers'))
|
|
113
|
+
return { text: '', calls: [call('compute_offers')] };
|
|
114
|
+
const order = latest(turns, 'read_order');
|
|
115
|
+
const listing = latest(turns, 'compute_offers');
|
|
116
|
+
if (!order || !listing)
|
|
117
|
+
return { text: "I couldn't read the order or the offers.", calls: [] };
|
|
118
|
+
const quoted = done('submit_quote');
|
|
119
|
+
if (quoted) {
|
|
120
|
+
return quoted.ok
|
|
121
|
+
? {
|
|
122
|
+
text: `I quoted order ${order.orderId}. The customer checks the quote and the booking it names before it commits.`,
|
|
123
|
+
calls: [],
|
|
124
|
+
}
|
|
125
|
+
: { text: `The quote didn't go out. ${refusalLine(quoted.content)}`, calls: [] };
|
|
126
|
+
}
|
|
127
|
+
if (listing.limits.computeSwitch === 'off') {
|
|
128
|
+
return {
|
|
129
|
+
text: 'Compute booking is off for this order, so I book nothing and quote without a booking, as you asked. The customer requires a compute booking, so I expect it to refuse.',
|
|
130
|
+
calls: [call('submit_quote')],
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
const booked = done('book_compute');
|
|
134
|
+
if (!booked) {
|
|
135
|
+
const choice = chooseOffer(order, listing);
|
|
136
|
+
if ('none' in choice)
|
|
137
|
+
return { text: `I booked nothing, since ${choice.none}.`, calls: [] };
|
|
138
|
+
return {
|
|
139
|
+
text: `I'll book ${order.needs.gpus} ${order.needs.gpu} of ${choice.offer.id} at ${choice.offer.pricePerGpuHour} per GPU-hour, the cheapest firm offer that holds the GPUs from the job's start past its deadline.`,
|
|
140
|
+
calls: [call('book_compute', { offer: choice.offer.id, quantity: order.needs.gpus })],
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
if (!booked.ok)
|
|
144
|
+
return { text: `I couldn't book the compute. ${refusalLine(booked.content)}`, calls: [] };
|
|
145
|
+
const booking = JSON.parse(booked.content).booking;
|
|
146
|
+
return { text: '', calls: [call('submit_quote', { booking })] };
|
|
147
|
+
}
|
|
148
|
+
// The quote went out and the customer answered it, so the agent explains and quotes nothing again.
|
|
149
|
+
if (prompt.startsWith(CUSTOMER_REFUSED_PROMPT)) {
|
|
150
|
+
const refused = /with ([a-z_.]+), at the ([a-z]+) layer/.exec(prompt);
|
|
151
|
+
return {
|
|
152
|
+
text: refused
|
|
153
|
+
? `The customer refused my quote with ${refused[1]} at the ${refused[2]} layer, so no work started and nothing was charged. The order is closed, and the next one comes with job.`
|
|
154
|
+
: 'The customer refused my quote, so no work started and nothing was charged.',
|
|
155
|
+
calls: [],
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
if (/\bwhy\b/i.test(prompt)) {
|
|
159
|
+
const booking = latest(turns, 'book_compute');
|
|
160
|
+
const listing = latest(turns, 'compute_offers');
|
|
161
|
+
if (!booking || !listing)
|
|
162
|
+
return { text: "I haven't booked any compute yet.", calls: [] };
|
|
163
|
+
const chosen = listing.offers.find((o) => o.id === booking.offer);
|
|
164
|
+
const others = listing.offers.filter((o) => o.id !== booking.offer);
|
|
165
|
+
const why = others.map((o) => !o.freeCancellation.startsWith('none')
|
|
166
|
+
? `${o.id} could still be cancelled for free, and the customer won't rely on that`
|
|
167
|
+
: !takes(o, 1)
|
|
168
|
+
? `${o.id} only takes ${o.gpusPerBooking} GPUs in one booking`
|
|
169
|
+
: `${o.id} doesn't hold the GPUs for the whole job`);
|
|
170
|
+
return {
|
|
171
|
+
text: `I chose ${booking.offer} at ${chosen?.pricePerGpuHour ?? 'its rate'} per GPU-hour, under the ${listing.limits.computeBudgetPerGpuHour} budget in service.ts, with a ${booking.reserve} reserve inside my authority. ${why.join('. ')}.`,
|
|
172
|
+
calls: [],
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
const gpus = /(\d+)\s*(?:H100s?|GPUs?)/i.exec(prompt);
|
|
176
|
+
if (gpus) {
|
|
177
|
+
if (last?.call.name === 'book_compute') {
|
|
178
|
+
return last.ok
|
|
179
|
+
? { text: 'That booking went through.', calls: [] }
|
|
180
|
+
: { text: `I couldn't book ${gpus[1]} GPUs. ${refusalLine(last.content)}`, calls: [] };
|
|
181
|
+
}
|
|
182
|
+
const listing = latest(turns, 'compute_offers');
|
|
183
|
+
const offer = listing?.offers.find((o) => takes(o, Number(gpus[1])) && o.freeCancellation.startsWith('none'));
|
|
184
|
+
if (!offer)
|
|
185
|
+
return { text: `No offer I've seen takes ${gpus[1]} GPUs.`, calls: [] };
|
|
186
|
+
return {
|
|
187
|
+
text: `I'll try to book ${gpus[1]} GPUs of ${offer.id}.`,
|
|
188
|
+
calls: [call('book_compute', { offer: offer.id, quantity: Number(gpus[1]) })],
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
if (/\bquote\b/i.test(prompt)) {
|
|
192
|
+
if (last?.call.name === 'submit_quote') {
|
|
193
|
+
return last.ok
|
|
194
|
+
? { text: 'The quote went out, and the customer checks it now.', calls: [] }
|
|
195
|
+
: { text: `The quote didn't go out. ${refusalLine(last.content)}`, calls: [] };
|
|
196
|
+
}
|
|
197
|
+
const listing = latest(turns, 'compute_offers');
|
|
198
|
+
const booking = latest(turns, 'book_compute');
|
|
199
|
+
const off = listing?.limits.computeSwitch === 'off';
|
|
200
|
+
return {
|
|
201
|
+
text: off ? 'I quote without a booking, since compute is switched off.' : '',
|
|
202
|
+
calls: [call('submit_quote', off || !booking ? {} : { booking: booking.booking })],
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
return {
|
|
206
|
+
text: "I take orders from Avow's test customer, compare compute offers, book compute and quote. Ask me why I chose an offer, or ask for a booking.",
|
|
207
|
+
calls: [],
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
export function scriptedProvider() {
|
|
211
|
+
return {
|
|
212
|
+
kind: 'scripted',
|
|
213
|
+
model: SCRIPTED_MODEL,
|
|
214
|
+
line: 'scripted decisions, the same every run, with no model and no charge',
|
|
215
|
+
reaches: 'this machine',
|
|
216
|
+
async reply(request) {
|
|
217
|
+
const started = performance.now();
|
|
218
|
+
const { text, calls } = decide(request.turns);
|
|
219
|
+
if (text)
|
|
220
|
+
request.onText(text);
|
|
221
|
+
return {
|
|
222
|
+
text,
|
|
223
|
+
calls,
|
|
224
|
+
native: null,
|
|
225
|
+
stop: calls.length > 0 ? 'tools' : 'end',
|
|
226
|
+
timing: {
|
|
227
|
+
firstTokenMs: 0,
|
|
228
|
+
tokens: null,
|
|
229
|
+
generatingMs: null,
|
|
230
|
+
totalMs: performance.now() - started,
|
|
231
|
+
},
|
|
232
|
+
};
|
|
233
|
+
},
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
//# sourceMappingURL=scripted.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scripted.js","sourceRoot":"","sources":["../../src/session/scripted.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AASnD;;;;;GAKG;AAEH,8EAA8E;AAC9E,MAAM,CAAC,MAAM,YAAY,GAAG,WAAW,CAAA;AACvC,6FAA6F;AAC7F,MAAM,CAAC,MAAM,iBAAiB,GAAG,sBAAsB,CAAA;AACvD,mGAAmG;AACnG,MAAM,CAAC,MAAM,uBAAuB,GAAG,gCAAgC,CAAA;AAsBvE,MAAM,OAAO,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,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,CAAC,GAAG,EAAE,GAAG,OAAO;iBACrC;aACF,CAAA;QACH,CAAC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type ModelProvider } from './provider.js';
|
|
2
|
+
/**
|
|
3
|
+
* Picks the model the session talks to, so nobody is surprised by a bill. An explicit choice wins,
|
|
4
|
+
* and when it can't be used it stays a visible failure and nothing switches. With nothing explicit,
|
|
5
|
+
* only a free model on this machine is picked: Ollama, running, with a supported model pulled. A
|
|
6
|
+
* paid provider runs only once it's chosen, so a key in the environment is never enough. With no
|
|
7
|
+
* free model ready, it runs the scripted decisions, which cost nothing, and says so before the first
|
|
8
|
+
* turn, with how to get a model.
|
|
9
|
+
*/
|
|
10
|
+
export interface SelectionInput {
|
|
11
|
+
/** `--provider`, or `AVOW_MODEL_PROVIDER`. */
|
|
12
|
+
provider: string | null;
|
|
13
|
+
/** `--model`, or `AVOW_MODEL`. */
|
|
14
|
+
model: string | null;
|
|
15
|
+
/** `--scripted`. */
|
|
16
|
+
scripted: boolean;
|
|
17
|
+
/** The environment, for the Anthropic key, which is only ever read from there. */
|
|
18
|
+
env: Readonly<Record<string, string | undefined>>;
|
|
19
|
+
ollamaUrl?: string;
|
|
20
|
+
fetch?: typeof fetch;
|
|
21
|
+
}
|
|
22
|
+
export type Selection = {
|
|
23
|
+
ok: true;
|
|
24
|
+
provider: ModelProvider;
|
|
25
|
+
chosen: 'explicit' | 'automatic';
|
|
26
|
+
/** Set when no free model was ready and the scripted decisions run in its place. */
|
|
27
|
+
fallback?: {
|
|
28
|
+
why: string;
|
|
29
|
+
help: string[];
|
|
30
|
+
};
|
|
31
|
+
} | {
|
|
32
|
+
ok: false;
|
|
33
|
+
why: string;
|
|
34
|
+
help: string[];
|
|
35
|
+
};
|
|
36
|
+
export declare function selectProvider(input: SelectionInput): Promise<Selection>;
|
|
37
|
+
//# sourceMappingURL=selection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selection.d.ts","sourceRoot":"","sources":["../../src/session/selection.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,KAAK,aAAa,EAAkB,MAAM,eAAe,CAAA;AAGlE;;;;;;;GAOG;AAEH,MAAM,WAAW,cAAc;IAC7B,8CAA8C;IAC9C,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,kCAAkC;IAClC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IACpB,oBAAoB;IACpB,QAAQ,EAAE,OAAO,CAAA;IACjB,kFAAkF;IAClF,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAA;IACjD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,OAAO,KAAK,CAAA;CACrB;AAED,MAAM,MAAM,SAAS,GACjB;IACE,EAAE,EAAE,IAAI,CAAA;IACR,QAAQ,EAAE,aAAa,CAAA;IACvB,MAAM,EAAE,UAAU,GAAG,WAAW,CAAA;IAChC,oFAAoF;IACpF,QAAQ,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE,CAAA;CAC3C,GACD;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,CAAA;AAoE9C,wBAAsB,cAAc,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,SAAS,CAAC,CA4C9E"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { ANTHROPIC_MODEL, anthropicProvider } from './anthropic.js';
|
|
2
|
+
import { localCapabilities, localModels, localProvider, OLLAMA_URL, SUPPORTED_LOCAL_MODELS, sameLocalModel, } from './ollama.js';
|
|
3
|
+
import { PROVIDER_KINDS } from './provider.js';
|
|
4
|
+
import { scriptedProvider } from './scripted.js';
|
|
5
|
+
/** How to get a model, said when none is ready. */
|
|
6
|
+
function helpLines(env) {
|
|
7
|
+
return [
|
|
8
|
+
`For a model on this machine at no charge, install Ollama from https://ollama.com and run ollama pull ${SUPPORTED_LOCAL_MODELS[0]}.`,
|
|
9
|
+
`For Claude, run npm start -- --provider anthropic with ANTHROPIC_API_KEY set. Each call is billed to that key.${env.ANTHROPIC_API_KEY ? ' The key is set, but the session uses it only when you choose it.' : ''}`,
|
|
10
|
+
];
|
|
11
|
+
}
|
|
12
|
+
/** The scripted decisions, run because no free model was ready and nothing was chosen. */
|
|
13
|
+
const scriptedInstead = (why, env) => ({
|
|
14
|
+
ok: true,
|
|
15
|
+
provider: scriptedProvider(),
|
|
16
|
+
chosen: 'automatic',
|
|
17
|
+
fallback: { why, help: helpLines(env) },
|
|
18
|
+
});
|
|
19
|
+
async function local(model, explicit, input) {
|
|
20
|
+
const base = input.ollamaUrl ?? OLLAMA_URL;
|
|
21
|
+
const pulled = await localModels(base, input.fetch);
|
|
22
|
+
if (pulled === null) {
|
|
23
|
+
return explicit
|
|
24
|
+
? {
|
|
25
|
+
ok: false,
|
|
26
|
+
why: `You chose Ollama, and it isn't answering at ${base}. Open the Ollama app or run ollama serve.`,
|
|
27
|
+
help: [],
|
|
28
|
+
}
|
|
29
|
+
: scriptedInstead('No model is running on this machine, so your agent runs scripted decisions, the same every run and free.', input.env);
|
|
30
|
+
}
|
|
31
|
+
const name = model
|
|
32
|
+
? pulled.find((p) => sameLocalModel(p, model))
|
|
33
|
+
: SUPPORTED_LOCAL_MODELS.map((s) => pulled.find((p) => sameLocalModel(p, s))).find(Boolean);
|
|
34
|
+
if (!name) {
|
|
35
|
+
return model
|
|
36
|
+
? {
|
|
37
|
+
ok: false,
|
|
38
|
+
why: `Ollama has no model ${model}. Pull it with ollama pull ${model}.`,
|
|
39
|
+
help: [],
|
|
40
|
+
}
|
|
41
|
+
: scriptedInstead(`Ollama has none of the supported models pulled (${SUPPORTED_LOCAL_MODELS.join(', ')}), so your agent runs scripted decisions, the same every run and free.`, input.env);
|
|
42
|
+
}
|
|
43
|
+
const capabilities = await localCapabilities(name, base, input.fetch);
|
|
44
|
+
if (capabilities && !capabilities.includes('tools')) {
|
|
45
|
+
return { ok: false, why: `${name} can't call tools, which the session needs.`, help: [] };
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
ok: true,
|
|
49
|
+
provider: localProvider({
|
|
50
|
+
model: name,
|
|
51
|
+
thinks: capabilities?.includes('thinking') ?? false,
|
|
52
|
+
base,
|
|
53
|
+
...(input.fetch ? { fetch: input.fetch } : {}),
|
|
54
|
+
}),
|
|
55
|
+
chosen: explicit ? 'explicit' : 'automatic',
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export async function selectProvider(input) {
|
|
59
|
+
if (input.scripted) {
|
|
60
|
+
if (input.provider && input.provider !== 'scripted') {
|
|
61
|
+
return {
|
|
62
|
+
ok: false,
|
|
63
|
+
why: `--scripted and --provider ${input.provider} can't both be chosen.`,
|
|
64
|
+
help: [],
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
return { ok: true, provider: scriptedProvider(), chosen: 'explicit' };
|
|
68
|
+
}
|
|
69
|
+
const kind = input.provider;
|
|
70
|
+
if (kind === null)
|
|
71
|
+
return local(input.model, input.model !== null, input);
|
|
72
|
+
switch (kind) {
|
|
73
|
+
case 'local':
|
|
74
|
+
return local(input.model, true, input);
|
|
75
|
+
case 'scripted':
|
|
76
|
+
return { ok: true, provider: scriptedProvider(), chosen: 'explicit' };
|
|
77
|
+
case 'anthropic': {
|
|
78
|
+
const apiKey = input.env.ANTHROPIC_API_KEY;
|
|
79
|
+
if (!apiKey) {
|
|
80
|
+
return {
|
|
81
|
+
ok: false,
|
|
82
|
+
why: "You chose Anthropic, and ANTHROPIC_API_KEY isn't set in this environment. Set it there, and the session reads it from there only.",
|
|
83
|
+
help: [],
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
ok: true,
|
|
88
|
+
provider: anthropicProvider({
|
|
89
|
+
apiKey,
|
|
90
|
+
model: input.model ?? ANTHROPIC_MODEL,
|
|
91
|
+
...(input.fetch ? { fetch: input.fetch } : {}),
|
|
92
|
+
}),
|
|
93
|
+
chosen: 'explicit',
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
default:
|
|
97
|
+
return {
|
|
98
|
+
ok: false,
|
|
99
|
+
why: `There's no provider ${kind}. Choose one of ${PROVIDER_KINDS.join(', ')}.`,
|
|
100
|
+
help: [],
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=selection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selection.js","sourceRoot":"","sources":["../../src/session/selection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AACnE,OAAO,EACL,iBAAiB,EACjB,WAAW,EACX,aAAa,EACb,UAAU,EACV,sBAAsB,EACtB,cAAc,GACf,MAAM,aAAa,CAAA;AACpB,OAAO,EAAsB,cAAc,EAAE,MAAM,eAAe,CAAA;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAkChD,mDAAmD;AACnD,SAAS,SAAS,CAAC,GAA0B;IAC3C,OAAO;QACL,wGAAwG,sBAAsB,CAAC,CAAC,CAAC,GAAG;QACpI,iHAAiH,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC,mEAAmE,CAAC,CAAC,CAAC,EAAE,EAAE;KACpN,CAAA;AACH,CAAC;AAED,0FAA0F;AAC1F,MAAM,eAAe,GAAG,CAAC,GAAW,EAAE,GAA0B,EAAa,EAAE,CAAC,CAAC;IAC/E,EAAE,EAAE,IAAI;IACR,QAAQ,EAAE,gBAAgB,EAAE;IAC5B,MAAM,EAAE,WAAW;IACnB,QAAQ,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,SAAS,CAAC,GAAG,CAAC,EAA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zE,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,OAAO;YACV,OAAO,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,CAAC,CAAA;QACxC,KAAK,UAAU;YACb,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,gBAAgB,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,CAAA;QACvE,KAAK,WAAW,EAAE,CAAC;YACjB,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,iBAAiB,CAAA;YAC1C,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,OAAO;oBACL,EAAE,EAAE,KAAK;oBACT,GAAG,EAAE,mIAAmI;oBACxI,IAAI,EAAE,EAAE;iBACT,CAAA;YACH,CAAC;YACD,OAAO;gBACL,EAAE,EAAE,IAAI;gBACR,QAAQ,EAAE,iBAAiB,CAAC;oBAC1B,MAAM;oBACN,KAAK,EAAE,KAAK,CAAC,KAAK,IAAI,eAAe;oBACrC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;iBAC/C,CAAC;gBACF,MAAM,EAAE,UAAU;aACnB,CAAA;QACH,CAAC;QACD;YACE,OAAO;gBACL,EAAE,EAAE,KAAK;gBACT,GAAG,EAAE,uBAAuB,IAAI,mBAAmB,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;gBAC/E,IAAI,EAAE,EAAE;aACT,CAAA;IACL,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type CommitmentReference, type PinnedBlock, type Side } from '@avow-finance/spec';
|
|
2
|
+
import { type LockedBacking, type PinnedLockReader } from '@avow-finance/verifier';
|
|
3
|
+
import { type Address, type Hex } from 'viem';
|
|
4
|
+
import type { CommitmentCheck, ReservedJob, ServiceChecks } from './service.js';
|
|
5
|
+
/**
|
|
6
|
+
* The read-only checks `checkBeforeWork` gets as `avow`. They read the chain at one finalized block
|
|
7
|
+
* and nothing else, and they hold no key, so the developer's own code can run them in a process
|
|
8
|
+
* with none.
|
|
9
|
+
*/
|
|
10
|
+
/** Where the checks read the chain: a reader pinned to finalized blocks, and full lock records. */
|
|
11
|
+
export interface CommitmentChain {
|
|
12
|
+
readers: readonly PinnedLockReader[];
|
|
13
|
+
/** A lock's whole record of one side of a commitment as of a block, or null when it holds none. */
|
|
14
|
+
backing(lock: Address, commitmentId: Hex, side: Side, at: bigint): Promise<LockedBacking | null>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The customer's commitment and its reserve, read at one finalized block. `verifyJobVerification`
|
|
18
|
+
* reads the commitment and each compute booking the job relies on at that block, and the lock's
|
|
19
|
+
* whole record is read at the same block, so every field the lock enforces is checked against the
|
|
20
|
+
* job's terms as of the block the check names.
|
|
21
|
+
*/
|
|
22
|
+
export declare function verifyCommitment(job: ReservedJob, chain: CommitmentChain, now: bigint): Promise<CommitmentCheck>;
|
|
23
|
+
/** The checks bound to one chain, as `checkBeforeWork` gets them. */
|
|
24
|
+
export declare function serviceChecks(chain: CommitmentChain, now: () => bigint): ServiceChecks;
|
|
25
|
+
/**
|
|
26
|
+
* The chain at one block as a test or the eval holds it in memory, which a child process can't
|
|
27
|
+
* read. The parent hands it over as data, and the checks read it through the same interfaces they
|
|
28
|
+
* read a live chain through.
|
|
29
|
+
*/
|
|
30
|
+
export interface ChainSnapshot {
|
|
31
|
+
chainId: number;
|
|
32
|
+
factory: Address;
|
|
33
|
+
block: PinnedBlock;
|
|
34
|
+
locks: {
|
|
35
|
+
address: Address;
|
|
36
|
+
account: Address;
|
|
37
|
+
records: {
|
|
38
|
+
commitmentId: Hex;
|
|
39
|
+
side: Side;
|
|
40
|
+
record: LockedBacking;
|
|
41
|
+
}[];
|
|
42
|
+
}[];
|
|
43
|
+
}
|
|
44
|
+
/** A snapshot's chain, read as a live one is. */
|
|
45
|
+
export declare function snapshotChain(snapshot: ChainSnapshot): CommitmentChain;
|
|
46
|
+
/** The references of a job's commitment and its bookings, whose records a snapshot has to hold. */
|
|
47
|
+
export declare const snapshotReferences: (job: ReservedJob) => CommitmentReference[];
|
|
48
|
+
//# sourceMappingURL=service-check.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-check.d.ts","sourceRoot":"","sources":["../../src/session/service-check.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,mBAAmB,EAGxB,KAAK,WAAW,EAChB,KAAK,IAAI,EACV,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAEL,KAAK,aAAa,EAClB,KAAK,gBAAgB,EAEtB,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAAE,KAAK,OAAO,EAAE,KAAK,GAAG,EAAkB,MAAM,MAAM,CAAA;AAC7D,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAE/E;;;;GAIG;AAEH,mGAAmG;AACnG,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,SAAS,gBAAgB,EAAE,CAAA;IACpC,mGAAmG;IACnG,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAAA;CACjG;AAED;;;;;GAKG;AACH,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,WAAW,EAChB,KAAK,EAAE,eAAe,EACtB,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,eAAe,CAAC,CAuC1B;AAED,qEAAqE;AACrE,wBAAgB,aAAa,CAAC,KAAK,EAAE,eAAe,EAAE,GAAG,EAAE,MAAM,MAAM,GAAG,aAAa,CAEtF;AAED;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EA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