@runlot/ai-sdk-provider 0.0.0-stage → 0.1.0-rc.206
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/README.md +50 -2
- package/dist/binding.d.ts +128 -0
- package/dist/binding.d.ts.map +1 -0
- package/dist/binding.js +7 -0
- package/dist/binding.js.map +1 -0
- package/dist/embedding-model.d.ts +21 -0
- package/dist/embedding-model.d.ts.map +1 -0
- package/dist/embedding-model.js +37 -0
- package/dist/embedding-model.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +47 -0
- package/dist/index.js.map +1 -0
- package/dist/language-model.d.ts +50 -0
- package/dist/language-model.d.ts.map +1 -0
- package/dist/language-model.js +503 -0
- package/dist/language-model.js.map +1 -0
- package/dist/lower.d.ts +23 -0
- package/dist/lower.d.ts.map +1 -0
- package/dist/lower.js +165 -0
- package/dist/lower.js.map +1 -0
- package/dist/sse.d.ts +13 -0
- package/dist/sse.d.ts.map +1 -0
- package/dist/sse.js +64 -0
- package/dist/sse.js.map +1 -0
- package/dist/structured.d.ts +31 -0
- package/dist/structured.d.ts.map +1 -0
- package/dist/structured.js +192 -0
- package/dist/structured.js.map +1 -0
- package/package.json +34 -3
package/README.md
CHANGED
|
@@ -1,3 +1,51 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @runlot/ai-sdk-provider
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An [AI SDK](https://ai-sdk.dev) provider over a Runlot worker's `env.ai` binding. Any framework
|
|
4
|
+
that takes an AI SDK model — the AI SDK itself, Mastra, the OpenAI Agents SDK through its AI SDK
|
|
5
|
+
adapter, LangGraph through its AI SDK chat model — calls Runlot's models with it, billed to your
|
|
6
|
+
organization's AI credit or served by your team's lent subscriptions.
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
npm install @runlot/ai-sdk-provider ai@7
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
```ts
|
|
13
|
+
import { generateText, stepCountIs, tool } from "ai";
|
|
14
|
+
import { z } from "zod";
|
|
15
|
+
import { createRunlot } from "@runlot/ai-sdk-provider";
|
|
16
|
+
|
|
17
|
+
export default {
|
|
18
|
+
async fetch(request: Request, env: Env): Promise<Response> {
|
|
19
|
+
const runlot = createRunlot({ ai: env.ai });
|
|
20
|
+
const r = await generateText({
|
|
21
|
+
model: runlot("anthropic/claude-sonnet-5"),
|
|
22
|
+
prompt: "Weather in Seoul?",
|
|
23
|
+
tools: {
|
|
24
|
+
weather: tool({
|
|
25
|
+
description: "Current weather for a city",
|
|
26
|
+
inputSchema: z.object({ city: z.string() }),
|
|
27
|
+
execute: async ({ city }) => ({ city, tempC: 18 }),
|
|
28
|
+
}),
|
|
29
|
+
},
|
|
30
|
+
stopWhen: stepCountIs(4),
|
|
31
|
+
});
|
|
32
|
+
return Response.json({ text: r.text });
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
- **AI SDK 7.** The provider implements the AI SDK's provider specification v4, which AI SDK 7
|
|
38
|
+
reads; AI SDK 5 and 6 refuse it with `UnsupportedModelVersionError`.
|
|
39
|
+
- Models: `runlot("<model id>")` for chat, `runlot.embeddingModel("<model id>")` for embeddings.
|
|
40
|
+
The ids are those of `runlot ai models`.
|
|
41
|
+
- Tool calls run in your code, the framework's loop: the provider asks `env.ai` to return the
|
|
42
|
+
model's tool calls (`toolMode: "return"`) and sends the results back as structured parts.
|
|
43
|
+
On a runtime that does not announce `contentParts` in `env.ai.features`, it falls back to
|
|
44
|
+
writing earlier calls and results into the text, returns at most one tool call per step, and
|
|
45
|
+
labels each such result with a `compatibility` warning.
|
|
46
|
+
- Usage, including `usage.unreported` for cache counts the provider did not report, is passed
|
|
47
|
+
through on every step.
|
|
48
|
+
- Frameworks that need Node built-ins (Mastra, the OpenAI Agents SDK, LangGraph) need a
|
|
49
|
+
`compatibilityDate` that provides them; `runlot deploy` names the date when one is missing.
|
|
50
|
+
|
|
51
|
+
Documentation: <https://docs.runlot.io/docs/data/ai/agent-frameworks>
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One content part of a message (docs/ai.md §2.1): text anywhere, a tool call and a
|
|
3
|
+
* reasoning block on an assistant turn, a tool result on a user turn.
|
|
4
|
+
*/
|
|
5
|
+
export type RunlotAIPart = {
|
|
6
|
+
type: "text";
|
|
7
|
+
text: string;
|
|
8
|
+
} | {
|
|
9
|
+
type: "tool_call";
|
|
10
|
+
id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
args: Record<string, unknown>;
|
|
13
|
+
} | {
|
|
14
|
+
type: "tool_result";
|
|
15
|
+
callId: string;
|
|
16
|
+
text?: string;
|
|
17
|
+
data?: unknown;
|
|
18
|
+
isError?: boolean;
|
|
19
|
+
} | {
|
|
20
|
+
type: "reasoning";
|
|
21
|
+
text?: string;
|
|
22
|
+
signature?: string;
|
|
23
|
+
redacted?: string;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* One conversational message: a role and a string, or — on a runtime whose
|
|
27
|
+
* `features` lists `contentParts` — an array of parts.
|
|
28
|
+
*/
|
|
29
|
+
export interface RunlotAIMessage {
|
|
30
|
+
role: "user" | "assistant";
|
|
31
|
+
content: string | RunlotAIPart[];
|
|
32
|
+
cacheBreakpoint?: boolean;
|
|
33
|
+
}
|
|
34
|
+
export interface RunlotAIUsage {
|
|
35
|
+
inputTokens?: number;
|
|
36
|
+
outputTokens?: number;
|
|
37
|
+
/** The part of `inputTokens` read from the provider's prompt cache. */
|
|
38
|
+
cachedInputTokens?: number;
|
|
39
|
+
/** The part of `inputTokens` written to the provider's prompt cache. */
|
|
40
|
+
cacheWriteInputTokens?: number;
|
|
41
|
+
}
|
|
42
|
+
export interface RunlotAIToolContext {
|
|
43
|
+
signal: AbortSignal;
|
|
44
|
+
callId: string;
|
|
45
|
+
model: string;
|
|
46
|
+
}
|
|
47
|
+
export interface RunlotAITool {
|
|
48
|
+
name: string;
|
|
49
|
+
description: string;
|
|
50
|
+
inputJsonSchema: Record<string, unknown>;
|
|
51
|
+
/** Run by `env.ai`'s own loop; absent with `toolMode: "return"`. */
|
|
52
|
+
execute?(args: unknown, ctx: RunlotAIToolContext): Promise<unknown> | unknown;
|
|
53
|
+
}
|
|
54
|
+
export interface RunlotAICacheOptions {
|
|
55
|
+
mode?: "implicit" | "explicit";
|
|
56
|
+
ttl?: string;
|
|
57
|
+
key?: string;
|
|
58
|
+
system?: boolean;
|
|
59
|
+
}
|
|
60
|
+
export interface RunlotAIMetadata {
|
|
61
|
+
sessionId?: string;
|
|
62
|
+
userId?: string;
|
|
63
|
+
tags?: string[];
|
|
64
|
+
}
|
|
65
|
+
export interface RunlotAIRunOptions {
|
|
66
|
+
messages: RunlotAIMessage[];
|
|
67
|
+
system?: string;
|
|
68
|
+
maxTokens?: number;
|
|
69
|
+
temperature?: number;
|
|
70
|
+
stream?: boolean;
|
|
71
|
+
tools?: RunlotAITool[];
|
|
72
|
+
/** `"return"`: one model call; the answer carries the tool calls instead of running them. */
|
|
73
|
+
toolMode?: "execute" | "return";
|
|
74
|
+
maxToolRounds?: number;
|
|
75
|
+
reasoning?: {
|
|
76
|
+
effort: string;
|
|
77
|
+
};
|
|
78
|
+
responseFormat?: {
|
|
79
|
+
type: "json_schema";
|
|
80
|
+
name?: string;
|
|
81
|
+
schema: unknown;
|
|
82
|
+
};
|
|
83
|
+
cache?: RunlotAICacheOptions;
|
|
84
|
+
metadata?: RunlotAIMetadata;
|
|
85
|
+
signal?: AbortSignal;
|
|
86
|
+
}
|
|
87
|
+
export interface RunlotAIFinalTool {
|
|
88
|
+
id: string;
|
|
89
|
+
name: string;
|
|
90
|
+
args: unknown;
|
|
91
|
+
result: unknown;
|
|
92
|
+
}
|
|
93
|
+
export interface RunlotAIRunResult {
|
|
94
|
+
text: string;
|
|
95
|
+
model?: string;
|
|
96
|
+
stopReason?: string;
|
|
97
|
+
usage?: RunlotAIUsage;
|
|
98
|
+
usageComplete?: boolean;
|
|
99
|
+
finalTool?: RunlotAIFinalTool;
|
|
100
|
+
/** `toolMode: "return"`: every tool call of the round, `[]` when none. */
|
|
101
|
+
toolCalls?: {
|
|
102
|
+
id: string;
|
|
103
|
+
name: string;
|
|
104
|
+
args: Record<string, unknown>;
|
|
105
|
+
}[];
|
|
106
|
+
/** `toolMode: "return"`: the assistant turn as parts, in the model's order. */
|
|
107
|
+
content?: RunlotAIPart[];
|
|
108
|
+
}
|
|
109
|
+
export interface RunlotAIEmbedResult {
|
|
110
|
+
vectors: number[][];
|
|
111
|
+
dimensions?: number;
|
|
112
|
+
model?: string;
|
|
113
|
+
usage?: {
|
|
114
|
+
inputTokens?: number;
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/** `env.ai`, as far as this provider uses it. */
|
|
118
|
+
export interface RunlotAIBinding {
|
|
119
|
+
/** What this runtime takes beyond string messages: `contentParts`, `toolModeReturn`. Absent on an older one. */
|
|
120
|
+
readonly features?: readonly string[];
|
|
121
|
+
run(model: string, options: RunlotAIRunOptions): Promise<RunlotAIRunResult | ReadableStream<Uint8Array>>;
|
|
122
|
+
embed(model: string, input: string | string[], options?: {
|
|
123
|
+
dimensions?: number;
|
|
124
|
+
taskType?: string;
|
|
125
|
+
metadata?: RunlotAIMetadata;
|
|
126
|
+
}): Promise<RunlotAIEmbedResult>;
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=binding.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binding.d.ts","sourceRoot":"","sources":["../src/binding.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,MAAM,MAAM,YAAY,GACpB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,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,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,SAAS,CAAC,EAAE,iBAAiB,CAAC;IAC9B,0EAA0E;IAC1E,SAAS,CAAC,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,EAAE,CAAC;IAC1E,+EAA+E;IAC/E,OAAO,CAAC,EAAE,YAAY,EAAE,CAAC;CAC1B;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAClC;AAED,iDAAiD;AACjD,MAAM,WAAW,eAAe;IAC9B,gHAAgH;IAChH,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,GAAG,cAAc,CAAC,UAAU,CAAC,CAAC,CAAC;IACzG,KAAK,CACH,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,EACxB,OAAO,CAAC,EAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,gBAAgB,CAAA;KAAE,GAChF,OAAO,CAAC,mBAAmB,CAAC,CAAC;CACjC"}
|
package/dist/binding.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// The part of a worker's `env.ai` this provider calls, typed structurally so that the
|
|
2
|
+
// package depends on no Runlot runtime package. The authority is the generated facade
|
|
3
|
+
// (`node/internal/workerd/ai.go`, `aiJS`) and the entry wrapper that runs tools
|
|
4
|
+
// (`node/internal/workerd/email.go`, `wrapAI`); `binding.test.ts` runs this provider
|
|
5
|
+
// against both sources, so a field either of them drops fails there.
|
|
6
|
+
export {};
|
|
7
|
+
//# sourceMappingURL=binding.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"binding.js","sourceRoot":"","sources":["../src/binding.ts"],"names":[],"mappings":"AAAA,sFAAsF;AACtF,sFAAsF;AACtF,gFAAgF;AAChF,qFAAqF;AACrF,qEAAqE"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { EmbeddingModelV4, EmbeddingModelV4CallOptions, EmbeddingModelV4Result } from "@ai-sdk/provider";
|
|
2
|
+
import type { RunlotAIBinding, RunlotAIMetadata } from "./binding.js";
|
|
3
|
+
export interface RunlotEmbeddingSettings {
|
|
4
|
+
/** `env.ai.embed`'s `taskType` (what the vectors are for). Absent means the model's default. */
|
|
5
|
+
taskType?: string;
|
|
6
|
+
/** `env.ai.embed`'s `dimensions`, when the call does not name its own. */
|
|
7
|
+
dimensions?: number;
|
|
8
|
+
metadata?: RunlotAIMetadata;
|
|
9
|
+
}
|
|
10
|
+
export declare class RunlotEmbeddingModel implements EmbeddingModelV4 {
|
|
11
|
+
readonly modelId: string;
|
|
12
|
+
private readonly ai;
|
|
13
|
+
private readonly settings;
|
|
14
|
+
readonly specificationVersion: "v4";
|
|
15
|
+
readonly provider = "runlot";
|
|
16
|
+
readonly maxEmbeddingsPerCall: undefined;
|
|
17
|
+
readonly supportsParallelCalls = true;
|
|
18
|
+
constructor(modelId: string, ai: RunlotAIBinding, settings?: RunlotEmbeddingSettings);
|
|
19
|
+
doEmbed(opts: EmbeddingModelV4CallOptions): Promise<EmbeddingModelV4Result>;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=embedding-model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embedding-model.d.ts","sourceRoot":"","sources":["../src/embedding-model.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,2BAA2B,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC9G,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAGtE,MAAM,WAAW,uBAAuB;IACtC,gGAAgG;IAChG,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,0EAA0E;IAC1E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,gBAAgB,CAAC;CAC7B;AAED,qBAAa,oBAAqB,YAAW,gBAAgB;IAOzD,QAAQ,CAAC,OAAO,EAAE,MAAM;IACxB,OAAO,CAAC,QAAQ,CAAC,EAAE;IACnB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAR3B,QAAQ,CAAC,oBAAoB,EAAG,IAAI,CAAU;IAC9C,QAAQ,CAAC,QAAQ,YAAY;IAC7B,QAAQ,CAAC,oBAAoB,YAAa;IAC1C,QAAQ,CAAC,qBAAqB,QAAQ;gBAG3B,OAAO,EAAE,MAAM,EACP,EAAE,EAAE,eAAe,EACnB,QAAQ,GAAE,uBAA4B;IAGnD,OAAO,CAAC,IAAI,EAAE,2BAA2B,GAAG,OAAO,CAAC,sBAAsB,CAAC;CAoBlF"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { toAPICallError } from "./language-model.js";
|
|
2
|
+
export class RunlotEmbeddingModel {
|
|
3
|
+
modelId;
|
|
4
|
+
ai;
|
|
5
|
+
settings;
|
|
6
|
+
specificationVersion = "v4";
|
|
7
|
+
provider = "runlot";
|
|
8
|
+
maxEmbeddingsPerCall = undefined;
|
|
9
|
+
supportsParallelCalls = true;
|
|
10
|
+
constructor(modelId, ai, settings = {}) {
|
|
11
|
+
this.modelId = modelId;
|
|
12
|
+
this.ai = ai;
|
|
13
|
+
this.settings = settings;
|
|
14
|
+
}
|
|
15
|
+
async doEmbed(opts) {
|
|
16
|
+
opts.abortSignal?.throwIfAborted();
|
|
17
|
+
const dimensions = opts.dimensions ?? this.settings.dimensions;
|
|
18
|
+
const options = {
|
|
19
|
+
...(dimensions === undefined ? {} : { dimensions }),
|
|
20
|
+
...(this.settings.taskType === undefined ? {} : { taskType: this.settings.taskType }),
|
|
21
|
+
...(this.settings.metadata === undefined ? {} : { metadata: this.settings.metadata }),
|
|
22
|
+
};
|
|
23
|
+
try {
|
|
24
|
+
const r = await this.ai.embed(this.modelId, opts.values, options);
|
|
25
|
+
const tokens = r.usage?.inputTokens;
|
|
26
|
+
return {
|
|
27
|
+
embeddings: r.vectors,
|
|
28
|
+
...(typeof tokens === "number" ? { usage: { tokens } } : {}),
|
|
29
|
+
warnings: [],
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
throw toAPICallError(e, { model: this.modelId, input: opts.values, ...options });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=embedding-model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embedding-model.js","sourceRoot":"","sources":["../src/embedding-model.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAUrD,MAAM,OAAO,oBAAoB;IAOpB;IACQ;IACA;IARV,oBAAoB,GAAG,IAAa,CAAC;IACrC,QAAQ,GAAG,QAAQ,CAAC;IACpB,oBAAoB,GAAG,SAAS,CAAC;IACjC,qBAAqB,GAAG,IAAI,CAAC;IAEtC,YACW,OAAe,EACP,EAAmB,EACnB,WAAoC,EAAE;QAF9C,YAAO,GAAP,OAAO,CAAQ;QACP,OAAE,GAAF,EAAE,CAAiB;QACnB,aAAQ,GAAR,QAAQ,CAA8B;IACtD,CAAC;IAEJ,KAAK,CAAC,OAAO,CAAC,IAAiC;QAC7C,IAAI,CAAC,WAAW,EAAE,cAAc,EAAE,CAAC;QAC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-0,0 +1,23 @@
|
|
|
1
|
+
import { type ProviderV4 } from "@ai-sdk/provider";
|
|
2
|
+
import type { RunlotAIBinding } from "./binding.js";
|
|
3
|
+
import { RunlotEmbeddingModel, type RunlotEmbeddingSettings } from "./embedding-model.js";
|
|
4
|
+
import { RunlotLanguageModel, type RunlotModelSettings } from "./language-model.js";
|
|
5
|
+
export type * from "./binding.js";
|
|
6
|
+
export { RunlotEmbeddingModel, type RunlotEmbeddingSettings } from "./embedding-model.js";
|
|
7
|
+
export { RunlotLanguageModel, toAPICallError, type RunlotModelSettings, type RunlotProviderMetadata, } from "./language-model.js";
|
|
8
|
+
export { lowerPrompt, TRANSCRIPT } from "./lower.js";
|
|
9
|
+
export { STRUCTURED, supportsStructured, toStructured, type RunlotReasoningMetadata } from "./structured.js";
|
|
10
|
+
export interface RunlotProviderOptions {
|
|
11
|
+
/** The worker's `env.ai` binding. */
|
|
12
|
+
ai: RunlotAIBinding;
|
|
13
|
+
}
|
|
14
|
+
export interface RunlotProvider extends ProviderV4 {
|
|
15
|
+
(modelId: string, settings?: RunlotModelSettings): RunlotLanguageModel;
|
|
16
|
+
languageModel(modelId: string, settings?: RunlotModelSettings): RunlotLanguageModel;
|
|
17
|
+
embeddingModel(modelId: string, settings?: RunlotEmbeddingSettings): RunlotEmbeddingModel;
|
|
18
|
+
/** The AI SDK's older name for `embeddingModel`. */
|
|
19
|
+
textEmbeddingModel(modelId: string, settings?: RunlotEmbeddingSettings): RunlotEmbeddingModel;
|
|
20
|
+
}
|
|
21
|
+
/** A provider over `env.ai`. Model ids are the catalog's (`env.ai.models()`, `runlot ai models`). */
|
|
22
|
+
export declare function createRunlot(options: RunlotProviderOptions): RunlotProvider;
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAoB,KAAK,UAAU,EAAE,MAAM,kB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an AI SDK provider over a Runlot worker's `env.ai`
|
|
2
|
+
// (docs/agent-frameworks.md §6). Every framework that takes an AI SDK model — the AI SDK
|
|
3
|
+
// itself, Mastra, the OpenAI Agents SDK through `aisdk()` — runs on it:
|
|
4
|
+
//
|
|
5
|
+
// import { createRunlot } from "@runlot/ai-sdk-provider";
|
|
6
|
+
// const runlot = createRunlot({ ai: env.ai });
|
|
7
|
+
// await generateText({ model: runlot("anthropic/claude-sonnet-5"), prompt });
|
|
8
|
+
//
|
|
9
|
+
// The binding is the credential: there is no key, and the call is metered and billed
|
|
10
|
+
// like any other `env.ai.run`.
|
|
11
|
+
//
|
|
12
|
+
// **Tool transcript: structured.** On a runtime whose `env.ai.features` lists
|
|
13
|
+
// `contentParts` and `toolModeReturn` (docs/ai.md §2.1), each step is one
|
|
14
|
+
// `env.ai.run` with `toolMode: "return"`: every tool call of the round comes back, and
|
|
15
|
+
// the calls, their results and a Claude turn's signed thinking go back to the model as
|
|
16
|
+
// native parts (`structured.ts`). On an older runtime the provider falls back to the
|
|
17
|
+
// lowered transcript — labelled text, one call per step, a `compatibility` warning
|
|
18
|
+
// (`lower.ts`). `providerMetadata.runlot.transcript` says which: `"structured"` or
|
|
19
|
+
// `"lowered-text"`.
|
|
20
|
+
import { NoSuchModelError } from "@ai-sdk/provider";
|
|
21
|
+
import { RunlotEmbeddingModel } from "./embedding-model.js";
|
|
22
|
+
import { RunlotLanguageModel } from "./language-model.js";
|
|
23
|
+
export { RunlotEmbeddingModel } from "./embedding-model.js";
|
|
24
|
+
export { RunlotLanguageModel, toAPICallError, } from "./language-model.js";
|
|
25
|
+
export { lowerPrompt, TRANSCRIPT } from "./lower.js";
|
|
26
|
+
export { STRUCTURED, supportsStructured, toStructured } from "./structured.js";
|
|
27
|
+
/** A provider over `env.ai`. Model ids are the catalog's (`env.ai.models()`, `runlot ai models`). */
|
|
28
|
+
export function createRunlot(options) {
|
|
29
|
+
const { ai } = options;
|
|
30
|
+
if (ai == null || typeof ai.run !== "function") {
|
|
31
|
+
throw new TypeError("createRunlot: pass the worker's env.ai binding as { ai: env.ai }");
|
|
32
|
+
}
|
|
33
|
+
const languageModel = (modelId, settings) => new RunlotLanguageModel(modelId, ai, settings);
|
|
34
|
+
const embeddingModel = (modelId, settings) => new RunlotEmbeddingModel(modelId, ai, settings);
|
|
35
|
+
const provider = ((modelId, settings) => languageModel(modelId, settings));
|
|
36
|
+
Object.assign(provider, {
|
|
37
|
+
specificationVersion: "v4",
|
|
38
|
+
languageModel,
|
|
39
|
+
embeddingModel,
|
|
40
|
+
textEmbeddingModel: embeddingModel,
|
|
41
|
+
imageModel(modelId) {
|
|
42
|
+
throw new NoSuchModelError({ modelId, modelType: "imageModel", message: "env.ai has no image models" });
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
return provider;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,yFAAyF;AACzF,wEAAwE;AACxE,EAAE;AACF,4DAA4D;AAC5D,iDAAiD;AACjD,gFAAgF;AAChF,EAAE;AACF,qFAAqF;AACrF,+BAA+B;AAC/B,EAAE;AACF,8EAA8E;AAC9E,0EAA0E;AAC1E,uFAAuF;AACvF,uFAAuF;AACvF,qFAAqF;AACrF,mFAAmF;AACnF,mFAAmF;AACnF,oBAAoB;AACpB,OAAO,EAAE,gBAAgB,EAAmB,MAAM,kBAAkB,CAAC;AAErE,OAAO,EAAE,oBAAoB,EAAgC,MAAM,sBAAsB,CAAC;AAC1F,OAAO,EAAE,mBAAmB,EAA4B,MAAM,qBAAqB,CAAC;AAGpF,OAAO,EAAE,oBAAoB,EAAgC,MAAM,sBAAsB,CAAC;AAC1F,OAAO,EACL,mBAAmB,EACnB,cAAc,GAGf,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,YAAY,EAAgC,MAAM,iBAAiB,CAAC;AAe7G,qGAAqG;AACrG,MAAM,UAAU,YAAY,CAAC,OAA8B;IACzD,MAAM,EAAE,EAAE,EAAE,GAAG,OAAO,CAAC;IACvB,IAAI,EAAE,IAAI,IAAI,IAAI,OAAO,EAAE,CAAC,GAAG,KAAK,UAAU,EAAE,CAAC;QAC/C,MAAM,IAAI,SAAS,CAAC,kEAAkE,CAAC,CAAC;IAC1F,CAAC;IACD,MAAM,aAAa,GAAG,CAAC,OAAe,EAAE,QAA8B,EAAuB,EAAE,CAC7F,IAAI,mBAAmB,CAAC,OAAO,EAAE,EAAE,EAAE,QAAQ,CAAC,CAAC;IACjD,MAAM,cAAc,GAAG,CAAC,OAAe,EAAE,QAAkC,EAAwB,EAAE,CACnG,IAAI,oBAAoB,CAAC,OAAO,EAAE,EAAE,EAAE,QAAQ,CAAC,CAAC;IAClD,MAAM,QAAQ,GAAG,CAAC,CAAC,OAAe,EAAE,QAA8B,EAAE,EAAE,CAAC,aAAa,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAmB,CAAC;IAC3H,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE;QACtB,oBAAoB,EAAE,IAAa;QACnC,aAAa;QACb,cAAc;QACd,kBAAkB,EAAE,cAAc;QAClC,UAAU,CAAC,OAAe;YACxB,MAAM,IAAI,gBAAgB,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,OAAO,EAAE,4BAA4B,EAAE,CAAC,CAAC;QAC1G,CAAC;KACF,CAAC,CAAC;IACH,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { APICallError, type LanguageModelV4, type LanguageModelV4CallOptions, type LanguageModelV4GenerateResult, type LanguageModelV4StreamResult } from "@ai-sdk/provider";
|
|
2
|
+
import type { RunlotAIBinding, RunlotAICacheOptions, RunlotAIMetadata } from "./binding.js";
|
|
3
|
+
import { TRANSCRIPT } from "./lower.js";
|
|
4
|
+
import { STRUCTURED } from "./structured.js";
|
|
5
|
+
/** Per-model settings that ride on every call made through the model. */
|
|
6
|
+
export interface RunlotModelSettings {
|
|
7
|
+
/** `env.ai.run`'s `cache` (the explicit prompt cache; only on models whose catalog row lists `cacheTTLs`). */
|
|
8
|
+
cache?: RunlotAICacheOptions;
|
|
9
|
+
/** `env.ai.run`'s `metadata`: the app's own session, user and tags on the call's record (docs/ai-observability.md). */
|
|
10
|
+
metadata?: RunlotAIMetadata;
|
|
11
|
+
}
|
|
12
|
+
/** The `providerMetadata.runlot` every result carries. */
|
|
13
|
+
export interface RunlotProviderMetadata {
|
|
14
|
+
/** False when `usage` is an observed subtotal, not the exact total (docs/ai.md `usageComplete`). */
|
|
15
|
+
usageComplete: boolean | null;
|
|
16
|
+
/** `env.ai.run`'s own stop reason (`end_turn`, `max_tokens`, `tool_stop`, …). */
|
|
17
|
+
stopReason: string | null;
|
|
18
|
+
/**
|
|
19
|
+
* How earlier tool calls and results reach the model: as native parts (`structured.ts`),
|
|
20
|
+
* or as labelled text on a runtime that predates them (`lower.ts`).
|
|
21
|
+
*/
|
|
22
|
+
transcript: typeof STRUCTURED | typeof TRANSCRIPT;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* `env.ai`'s error as the `APICallError` frameworks know how to read: the gateway's
|
|
26
|
+
* status as `statusCode`, its code on `data.code` (and on the error itself), and
|
|
27
|
+
* `isRetryable` from the code — so a retry loop backs off on `rate_limited` and stops
|
|
28
|
+
* on `no_credit`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function toAPICallError(e: unknown, body: unknown): APICallError;
|
|
31
|
+
export declare class RunlotLanguageModel implements LanguageModelV4 {
|
|
32
|
+
readonly modelId: string;
|
|
33
|
+
private readonly ai;
|
|
34
|
+
private readonly settings;
|
|
35
|
+
readonly specificationVersion: "v4";
|
|
36
|
+
readonly provider = "runlot";
|
|
37
|
+
readonly supportedUrls: Record<string, RegExp[]>;
|
|
38
|
+
constructor(modelId: string, ai: RunlotAIBinding, settings?: RunlotModelSettings);
|
|
39
|
+
private prepare;
|
|
40
|
+
/** A return-mode answer's calls: every call of the round, as `env.ai` returned them. */
|
|
41
|
+
private returnedCalls;
|
|
42
|
+
/** The run's tool calls: every call `env.ai` dispatched before the first stop ended the run. */
|
|
43
|
+
private toolCalls;
|
|
44
|
+
private call;
|
|
45
|
+
doGenerate(opts: LanguageModelV4CallOptions): Promise<LanguageModelV4GenerateResult>;
|
|
46
|
+
doStream(opts: LanguageModelV4CallOptions): Promise<LanguageModelV4StreamResult>;
|
|
47
|
+
/** `env.ai`'s SSE (`{"delta"}`, `usage`, `done`, `error`) as AI SDK stream parts. */
|
|
48
|
+
private translate;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=language-model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"language-model.d.ts","sourceRoot":"","sources":["../src/language-model.ts"],"names":[],"mappings":"AAYA,OAAO,EACL,YAAY,EAGZ,KAAK,eAAe,EACpB,KAAK,0BAA0B,EAG/B,KAAK,6BAA6B,EAElC,KAAK,2BAA2B,EAIjC,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EACV,eAAe,EACf,oBAAoB,EAEpB,gBAAgB,EAMjB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAe,UAAU,EAAE,MAAM,YAAY,CAAC;AAErD,OAAO,EAAa,UAAU,EAAkE,MAAM,iBAAiB,CAAC;AAExH,yEAAyE;AACzE,MAAM,WAAW,mBAAmB;IAClC,8GAA8G;IAC9G,KAAK,CAAC,EAAE,oBAAoB,CAAC;IAC7B,uHAAuH;IACvH,QAAQ,CAAC,EAAE,gBAAgB,CAAC;CAC7B;AAED,0DAA0D;AAC1D,MAAM,WAAW,sBAAsB;IACrC,oGAAoG;IACpG,aAAa,EAAE,OAAO,GAAG,IAAI,CAA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