actorctl 0.3.0-rc.16 → 0.3.0-rc.18
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/dist/actorctl.js +184 -10
- package/dist/worker/models.ts +35 -7
- package/package.json +2 -2
package/dist/actorctl.js
CHANGED
|
@@ -21214,6 +21214,10 @@ var codeByLiteral = {
|
|
|
21214
21214
|
NetworkAuthenticationRequired: 511
|
|
21215
21215
|
};
|
|
21216
21216
|
var fromLiteral = (literal) => codeByLiteral[literal];
|
|
21217
|
+
// src/chatgpt.ts
|
|
21218
|
+
import { createServer } from "http";
|
|
21219
|
+
import { createInterface as createInterface2 } from "readline";
|
|
21220
|
+
|
|
21217
21221
|
// ../../node_modules/.bun/effect@4.1.2/node_modules/effect/dist/encoding/Sse.js
|
|
21218
21222
|
var SseErrorTypeId = "~effect/encoding/Sse/SseError";
|
|
21219
21223
|
|
|
@@ -26167,7 +26171,7 @@ var Credits = Struct({
|
|
|
26167
26171
|
entries: ArraySchema(CreditEntry),
|
|
26168
26172
|
cursor: optionalKey2(NonEmptyString)
|
|
26169
26173
|
}).annotate({ identifier: "Credits" });
|
|
26170
|
-
var UsageGroup = Union2([Literals(["day", "model", "actor"]), String5.check(isPattern2(/^metadata\.[\s\S]{1,64}$/))]);
|
|
26174
|
+
var UsageGroup = Union2([Literals(["day", "model", "actor", "provider"]), String5.check(isPattern2(/^metadata\.[\s\S]{1,64}$/))]);
|
|
26171
26175
|
var UsageRow = Struct({
|
|
26172
26176
|
key: NullOr(String5),
|
|
26173
26177
|
requests: Int,
|
|
@@ -26195,6 +26199,22 @@ var CreditGrant = Struct({
|
|
|
26195
26199
|
var InsufficientCredits = Struct({
|
|
26196
26200
|
error: Struct({ type: Literal2("insufficient_credits"), message: String5, balanceMicros: Micros })
|
|
26197
26201
|
}).annotate({ identifier: "InsufficientCredits" });
|
|
26202
|
+
|
|
26203
|
+
// ../../src/inference/chatgpt-api.ts
|
|
26204
|
+
var ChatGptName = String5.check(isPattern2(/^[a-z0-9-]{1,64}$/));
|
|
26205
|
+
var ChatGptConnectionInfo = Struct({
|
|
26206
|
+
id: NonEmptyString,
|
|
26207
|
+
name: ChatGptName,
|
|
26208
|
+
label: String5,
|
|
26209
|
+
owner: String5,
|
|
26210
|
+
state: Literals(["connected", "reconnect_required"]),
|
|
26211
|
+
updatedAt: Number6,
|
|
26212
|
+
email: optionalKey2(String5)
|
|
26213
|
+
});
|
|
26214
|
+
var ChatGptStatus = Struct({ available: Boolean3, connections: ArraySchema(ChatGptConnectionInfo) });
|
|
26215
|
+
var ChatGptAuthorization = Struct({ authorizationUrl: String5 });
|
|
26216
|
+
var ChatGptDisconnected = Struct({ revoked: Boolean3, warning: optionalKey2(String5) });
|
|
26217
|
+
var ChatGptConnectCode = Struct({ code: String5, expiresAt: Number6, name: ChatGptName, connectionId: optionalKey2(String5) });
|
|
26198
26218
|
// ../../src/api.ts
|
|
26199
26219
|
var Health = Struct({ status: Literal2("ok") });
|
|
26200
26220
|
var Unauthorized = Struct({ code: Literal2("unauthorized"), message: String5 }).pipe(status(401));
|
|
@@ -26427,7 +26447,24 @@ var Admin = make37("admin").add(get7("listAccounts", "/v1/admin/accounts", { suc
|
|
|
26427
26447
|
success: CreditEntry,
|
|
26428
26448
|
error: errors
|
|
26429
26449
|
}));
|
|
26430
|
-
var
|
|
26450
|
+
var chatGptPath = "/v1/accounts/:account/chatgpt";
|
|
26451
|
+
var ChatGpt = make37("chatgpt").add(get7("status", chatGptPath, { params: accountParams, success: ChatGptStatus, error: errors }), post("issueConnectCode", `${chatGptPath}/connect-codes`, {
|
|
26452
|
+
params: accountParams,
|
|
26453
|
+
payload: Struct({ personalDevelopment: Boolean3, name: optionalKey2(ChatGptName), connectionId: optionalKey2(NonEmptyString), label: optionalKey2(NonEmptyString) }),
|
|
26454
|
+
success: ChatGptConnectCode,
|
|
26455
|
+
error: errors
|
|
26456
|
+
}), post("authorize", `${chatGptPath}/authorize`, {
|
|
26457
|
+
params: accountParams,
|
|
26458
|
+
payload: Struct({ redirectUri: NonEmptyString, personalDevelopment: Boolean3, code: optionalKey2(NonEmptyString), reconnect: optionalKey2(ChatGptName), name: optionalKey2(ChatGptName) }),
|
|
26459
|
+
success: ChatGptAuthorization,
|
|
26460
|
+
error: errors
|
|
26461
|
+
}), post("callback", `${chatGptPath}/callback`, {
|
|
26462
|
+
params: accountParams,
|
|
26463
|
+
payload: Struct({ callbackUrl: NonEmptyString }),
|
|
26464
|
+
success: ChatGptConnectionInfo,
|
|
26465
|
+
error: errors
|
|
26466
|
+
}), patch("rename", `${chatGptPath}/:connection`, { params: { ...accountParams, connection: NonEmptyString }, payload: Struct({ label: NonEmptyString }), success: ChatGptConnectionInfo, error: errors }), del("disconnect", `${chatGptPath}/:connection`, { params: { ...accountParams, connection: NonEmptyString }, success: ChatGptDisconnected, error: errors }));
|
|
26467
|
+
var Api = make35("tardigrade-cloud").add(make37("health").add(get7("healthz", "/healthz", { success: Health })), Actors, Versions, Deployments, Secrets, Runtime, Webhooks, Query, Models, Credits2, ChatGpt, Admin);
|
|
26431
26468
|
|
|
26432
26469
|
// src/credentials.ts
|
|
26433
26470
|
import { chmod as chmod3, mkdir as mkdir2, readFile as readFile3, rm as rm2, writeFile as writeFile3, rename as rename3 } from "fs/promises";
|
|
@@ -26547,6 +26584,140 @@ var print = (json, value, lines) => log(json ? JSON.stringify(value) : lines.joi
|
|
|
26547
26584
|
`));
|
|
26548
26585
|
var next = (cursor) => cursor === undefined ? [] : [`Next page: --cursor ${JSON.stringify(cursor)}`];
|
|
26549
26586
|
|
|
26587
|
+
// ../../src/inference/chatgpt-errors.ts
|
|
26588
|
+
var invalid5 = new Set(["subscription_sharing_user_not_eligible", "subscription_sharing_unsupported_capability", "subscription_sharing_route_not_supported"]);
|
|
26589
|
+
|
|
26590
|
+
// ../../src/inference/chatgpt-plan.ts
|
|
26591
|
+
var CHATGPT_USAGE_URL = "https://chatgpt.com/#settings/Usage";
|
|
26592
|
+
var CHATGPT_PLAN_WARNING = "For personal development or internal benchmark actors only, not released agents or production traffic. Naming a chatgpt/<name> connection in actor code means anyone who calls that actor, or deploys that code to this workspace, uses that account\u2019s ChatGPT plan. Without gateway routing options, requests use API pricing (credits). Tardigrade stores and refreshes your OpenAI credentials on its servers. Plan limits apply; Use gateway.only to prevent paid fallback; gateway.order permits fallback within its routing policy.";
|
|
26593
|
+
var unsupported = new Set([
|
|
26594
|
+
"background",
|
|
26595
|
+
"conversation",
|
|
26596
|
+
"max_output_tokens",
|
|
26597
|
+
"max_tool_calls",
|
|
26598
|
+
"metadata",
|
|
26599
|
+
"moderation",
|
|
26600
|
+
"multi_agent",
|
|
26601
|
+
"prompt",
|
|
26602
|
+
"prompt_cache_retention",
|
|
26603
|
+
"safety_identifier",
|
|
26604
|
+
"temperature",
|
|
26605
|
+
"top_logprobs",
|
|
26606
|
+
"top_p",
|
|
26607
|
+
"truncation",
|
|
26608
|
+
"user",
|
|
26609
|
+
"previous_response_id",
|
|
26610
|
+
"service_tier",
|
|
26611
|
+
"prompt_cache_options"
|
|
26612
|
+
]);
|
|
26613
|
+
|
|
26614
|
+
// src/chatgpt.ts
|
|
26615
|
+
var loopbackCallback = async () => {
|
|
26616
|
+
let state;
|
|
26617
|
+
let resolveCallback;
|
|
26618
|
+
const result = new Promise((resolve) => {
|
|
26619
|
+
resolveCallback = resolve;
|
|
26620
|
+
});
|
|
26621
|
+
const server = createServer((request, response) => {
|
|
26622
|
+
const url = new URL(request.url ?? "/", "http://127.0.0.1");
|
|
26623
|
+
if (url.pathname !== "/auth/callback" || !state || url.searchParams.get("state") !== state) {
|
|
26624
|
+
response.writeHead(400).end("Invalid sign-in callback.");
|
|
26625
|
+
return;
|
|
26626
|
+
}
|
|
26627
|
+
response.writeHead(200, { "content-type": "text/plain", "cache-control": "no-store", "referrer-policy": "no-referrer" }).end("Return to actorctl to finish connecting ChatGPT.");
|
|
26628
|
+
resolveCallback(`${redirectUri}${url.search}`);
|
|
26629
|
+
});
|
|
26630
|
+
await new Promise((resolve, reject) => {
|
|
26631
|
+
server.once("error", reject);
|
|
26632
|
+
server.listen(0, "127.0.0.1", resolve);
|
|
26633
|
+
});
|
|
26634
|
+
const address = server.address();
|
|
26635
|
+
if (!address || typeof address === "string")
|
|
26636
|
+
throw new Error("Could not start a loopback listener.");
|
|
26637
|
+
const redirectUri = `http://127.0.0.1:${address.port}/auth/callback`;
|
|
26638
|
+
let readline;
|
|
26639
|
+
let timer;
|
|
26640
|
+
return {
|
|
26641
|
+
redirectUri,
|
|
26642
|
+
wait: (expectedState) => {
|
|
26643
|
+
state = expectedState;
|
|
26644
|
+
readline = createInterface2({ input: process.stdin, output: process.stderr, terminal: !!process.stdin.isTTY });
|
|
26645
|
+
readline.on("line", (line) => {
|
|
26646
|
+
try {
|
|
26647
|
+
const callback = new URL(line.trim());
|
|
26648
|
+
if (`${callback.origin}${callback.pathname}` !== redirectUri || callback.searchParams.get("state") !== state)
|
|
26649
|
+
return;
|
|
26650
|
+
resolveCallback(callback.toString());
|
|
26651
|
+
} catch {}
|
|
26652
|
+
});
|
|
26653
|
+
return Promise.race([result, new Promise((_, reject) => {
|
|
26654
|
+
timer = setTimeout(() => reject(new Error("ChatGPT sign-in timed out. Run actorctl chatgpt login again.")), 600000);
|
|
26655
|
+
})]);
|
|
26656
|
+
},
|
|
26657
|
+
close: () => {
|
|
26658
|
+
if (timer)
|
|
26659
|
+
clearTimeout(timer);
|
|
26660
|
+
readline?.close();
|
|
26661
|
+
server.closeAllConnections();
|
|
26662
|
+
server.close();
|
|
26663
|
+
}
|
|
26664
|
+
};
|
|
26665
|
+
};
|
|
26666
|
+
var login = make30("login", {
|
|
26667
|
+
...remote,
|
|
26668
|
+
name: optional6("name", "Connection name chosen in console: lowercase letters, digits and dashes."),
|
|
26669
|
+
reconnect: optional6("reconnect", "Reconnect an existing connection by name; keeps that name."),
|
|
26670
|
+
code: optional6("code", "Single-use connect code from workspace settings; expires after 10 minutes. Uses your saved workspace API key or password."),
|
|
26671
|
+
personalDevelopment: Boolean6("personal-development").pipe(withDefault5(false), withDescription3("Acknowledge personal development or internal benchmark actor use.")),
|
|
26672
|
+
browser: Boolean6("browser").pipe(withDefault5(true), withDescription3("Open the authorization URL in a browser."))
|
|
26673
|
+
}, (flags) => gen2(function* () {
|
|
26674
|
+
const config = yield* resolveConfig(flags);
|
|
26675
|
+
yield* error(CHATGPT_PLAN_WARNING);
|
|
26676
|
+
if (!flags.personalDevelopment && isNone2(flags.code)) {
|
|
26677
|
+
if (!process.stdin.isTTY || !(yield* run3(Confirm({ message: "Use this workspace only for personal development and connect your ChatGPT plan?" })))) {
|
|
26678
|
+
return yield* fail7(new Error("Connect only after acknowledging personal development use; pass --personal-development in a noninteractive terminal."));
|
|
26679
|
+
}
|
|
26680
|
+
}
|
|
26681
|
+
const client = yield* cloudClient(config.url);
|
|
26682
|
+
yield* acquireUseRelease2(tryPromise2(loopbackCallback), (listener) => gen2(function* () {
|
|
26683
|
+
const authorization = yield* client.chatgpt.authorize({ params: { account: config.account }, payload: { redirectUri: listener.redirectUri, personalDevelopment: true, ...isSome2(flags.code) ? { code: flags.code.value } : {}, ...isSome2(flags.reconnect) ? { reconnect: flags.reconnect.value } : {}, ...isSome2(flags.name) ? { name: flags.name.value } : {} } });
|
|
26684
|
+
const state = new URL(authorization.authorizationUrl).searchParams.get("state");
|
|
26685
|
+
if (!state)
|
|
26686
|
+
return yield* fail7(new Error("Cloud did not return an authorization state."));
|
|
26687
|
+
const callback = listener.wait(state);
|
|
26688
|
+
yield* error(`Continue with ChatGPT:
|
|
26689
|
+
${authorization.authorizationUrl}
|
|
26690
|
+
|
|
26691
|
+
If the browser cannot reach this machine, paste its full callback URL here and press Enter.`);
|
|
26692
|
+
if (flags.browser)
|
|
26693
|
+
yield* sync2(() => {
|
|
26694
|
+
const command = process.platform === "darwin" ? "open" : process.platform === "win32" ? undefined : "xdg-open";
|
|
26695
|
+
if (command && Bun.which(command))
|
|
26696
|
+
Bun.spawn([command, authorization.authorizationUrl], { stdout: "ignore", stderr: "ignore" }).unref();
|
|
26697
|
+
});
|
|
26698
|
+
const callbackUrl = yield* tryPromise2(() => callback);
|
|
26699
|
+
const result = yield* client.chatgpt.callback({ params: { account: config.account }, payload: { callbackUrl } });
|
|
26700
|
+
yield* print(flags.json, result, [`Connected ${result.name} to this workspace. Select options.gateway.only: ["chatgpt/${result.name}"] in managedModels for openai/* models.`, `Manage usage: ${CHATGPT_USAGE_URL}`]);
|
|
26701
|
+
}), (listener) => sync2(() => listener.close()));
|
|
26702
|
+
}).pipe(mapError2(userError))).pipe(withDescription4("Connect a ChatGPT plan using --code from workspace settings and your existing workspace login."));
|
|
26703
|
+
var status2 = make30("status", remote, (flags) => gen2(function* () {
|
|
26704
|
+
const config = yield* resolveConfig(flags);
|
|
26705
|
+
const client = yield* cloudClient(config.url);
|
|
26706
|
+
const result = yield* client.chatgpt.status({ params: { account: config.account } });
|
|
26707
|
+
yield* print(flags.json, result, [
|
|
26708
|
+
...result.connections.length ? result.connections.map((connection) => `chatgpt/${connection.name} ${connection.label} ${connection.owner} ${connection.state}`) : ["No ChatGPT connections."],
|
|
26709
|
+
...!result.available ? ["ChatGPT plan usage is disabled by the operator."] : [],
|
|
26710
|
+
`Manage usage: ${CHATGPT_USAGE_URL}`
|
|
26711
|
+
]);
|
|
26712
|
+
}).pipe(mapError2(userError))).pipe(withDescription4("Show the workspace's ChatGPT plan connection using your existing workspace login."));
|
|
26713
|
+
var logout = make30("logout", { ...remote, connection: String11("connection").pipe(withDescription3("Connection name to disconnect.")) }, (flags) => gen2(function* () {
|
|
26714
|
+
const config = yield* resolveConfig(flags);
|
|
26715
|
+
const client = yield* cloudClient(config.url);
|
|
26716
|
+
const result = yield* client.chatgpt.disconnect({ params: { account: config.account, connection: (yield* client.chatgpt.status({ params: { account: config.account } })).connections.find((connection) => connection.name === flags.connection)?.id ?? flags.connection } });
|
|
26717
|
+
yield* print(flags.json, result, [`Disconnected ${flags.connection}; code still naming this connection will fail closed.`, ...result.warning ? [result.warning] : []]);
|
|
26718
|
+
}).pipe(mapError2(userError))).pipe(withDescription4("Disconnect as a WorkOS owner/admin; with a workspace API key, use Disconnect in console settings."));
|
|
26719
|
+
var chatgpt = make30("chatgpt").pipe(withSubcommands([login, status2, logout]));
|
|
26720
|
+
|
|
26550
26721
|
// src/runtime.ts
|
|
26551
26722
|
var DEFAULT_EVENT_POLL_INTERVAL_MS = 1000;
|
|
26552
26723
|
var nonempty = (name) => String11(name).pipe(withSchema2(NonEmptyString));
|
|
@@ -26856,13 +27027,15 @@ import { modelActs, modelInfo, toolActs } from "tardie/agent/services"
|
|
|
26856
27027
|
import { weather } from "./actor"
|
|
26857
27028
|
import { managedModels, type ModelBinding } from "./tardigrade/models"
|
|
26858
27029
|
|
|
26859
|
-
//
|
|
27030
|
+
// Models use API pricing (workspace credits) by default. Set options.gateway.only to
|
|
27031
|
+
// ["chatgpt/henry"] to use a named plan, or gateway.order to choose an explicit fallback order.
|
|
27032
|
+
// ChatGPT connections only serve openai/* models; anyone calling/deploying this code uses that plan.
|
|
26860
27033
|
// Model IDs are OpenRouter IDs; GET ${options.url}/v1/models lists them.
|
|
26861
27034
|
export const MODEL = ${JSON.stringify(DEFAULT_MODEL)}
|
|
26862
27035
|
|
|
26863
27036
|
export function services(env: { readonly INFERENCE: ModelBinding }, thread?: string) {
|
|
26864
27037
|
// session lets the platform keep an upstream connection warm for this thread.
|
|
26865
|
-
const model = managedModels(env.INFERENCE, {
|
|
27038
|
+
const model = managedModels(env.INFERENCE, { model: MODEL, ...(thread === undefined ? {} : { session: thread }) })
|
|
26866
27039
|
const tools = weather.implement({
|
|
26867
27040
|
current: ({ city }) => Effect.succeed({ city, temperature: 21 }),
|
|
26868
27041
|
})
|
|
@@ -27130,8 +27303,8 @@ var init = make30("init", {
|
|
|
27130
27303
|
" actorctl events main --last 20"
|
|
27131
27304
|
].join(`
|
|
27132
27305
|
`));
|
|
27133
|
-
}).pipe(mapError2(userError))).pipe(withDescription4("Create a tardie agent project
|
|
27134
|
-
var
|
|
27306
|
+
}).pipe(mapError2(userError))).pipe(withDescription4("Create a tardie agent project using managedModels({ model }); options.gateway.only/order selects providers."));
|
|
27307
|
+
var login2 = make30("login", {
|
|
27135
27308
|
url: optional6("url", "Cloud API URL to save with the login.")
|
|
27136
27309
|
}, (flags) => gen2(function* () {
|
|
27137
27310
|
const url = getOrUndefined(flags.url) ?? DEFAULT_CLOUD_URL;
|
|
@@ -27143,11 +27316,12 @@ var login = make30("login", {
|
|
|
27143
27316
|
yield* saveCredentials({ password, ...isSome2(flags.url) ? { url } : {} });
|
|
27144
27317
|
yield* log(`Logged in to ${url} (account ${account}). Saved to ${credentialsDirectory()}/credentials.json.`);
|
|
27145
27318
|
}).pipe(mapError2(userError))).pipe(withDescription4("Save an API key or password to ~/.actorctl."));
|
|
27146
|
-
var
|
|
27319
|
+
var logout2 = make30("logout", {}, () => removeCredentials.pipe(andThen2(log(`Removed ${credentialsDirectory()}/credentials.json.`)), mapError2(userError))).pipe(withDescription4("Remove the saved password."));
|
|
27147
27320
|
var actorctl = make30("actorctl").pipe(withDescription4("Deploy actors, run threads, and read events on Tardigrade Cloud."), withSubcommands([
|
|
27148
27321
|
init,
|
|
27149
|
-
|
|
27150
|
-
|
|
27322
|
+
login2,
|
|
27323
|
+
logout2,
|
|
27324
|
+
chatgpt,
|
|
27151
27325
|
deploy,
|
|
27152
27326
|
threads2,
|
|
27153
27327
|
call,
|
|
@@ -27159,7 +27333,7 @@ var actorctl = make30("actorctl").pipe(withDescription4("Deploy actors, run thre
|
|
|
27159
27333
|
make30("secrets").pipe(withSubcommands([secretsPut, secretsDelete]))
|
|
27160
27334
|
]));
|
|
27161
27335
|
// package.json
|
|
27162
|
-
var version2 = "0.3.0-rc.
|
|
27336
|
+
var version2 = "0.3.0-rc.18";
|
|
27163
27337
|
|
|
27164
27338
|
// src/main.ts
|
|
27165
27339
|
run5(actorctl, { version: version2 }).pipe(provide4(mergeAll2(layer10, layer12)), runMain2);
|
package/dist/worker/models.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Managed models for actors deployed to Tardigrade Cloud. An actor names a catalog model, e.g.
|
|
2
|
-
// "anthropic/claude-sonnet-5.5"
|
|
2
|
+
// "anthropic/claude-sonnet-5.5". API pricing (credits) is the default. options.gateway.only/order
|
|
3
|
+
// select catalog hosts or workspace connections such as "chatgpt/henry" for openai/* models.
|
|
3
4
|
// The actor always sends its full prompt; the binding may send less upstream, but never needs the actor's help.
|
|
4
5
|
import { Effect, Layer, Schema, Stream } from "effect"
|
|
5
6
|
import { AiError, LanguageModel, Prompt, Response, Tool } from "effect/ai"
|
|
@@ -29,8 +30,9 @@ export type ResponseFormatSpec =
|
|
|
29
30
|
| { readonly type: "text" }
|
|
30
31
|
| { readonly type: "json"; readonly objectName: string; readonly schema: JsonObject }
|
|
31
32
|
|
|
32
|
-
// ModelOptions
|
|
33
|
+
// ModelOptions configure generation and how the request is routed.
|
|
33
34
|
export interface ModelOptions {
|
|
35
|
+
readonly gateway?: { readonly order?: ReadonlyArray<string>; readonly only?: ReadonlyArray<string> }
|
|
34
36
|
readonly maxOutputTokens?: number
|
|
35
37
|
readonly temperature?: number
|
|
36
38
|
readonly serviceTier?: "auto" | "default" | "flex" | "priority"
|
|
@@ -110,8 +112,29 @@ const failure = (method: string, description: string) => AiError.make({
|
|
|
110
112
|
|
|
111
113
|
const invalid = (method: string, description: string) => AiError.make({ module: "TardigradeModels", method, reason: new AiError.InvalidRequestError({ description }) })
|
|
112
114
|
|
|
115
|
+
// Actor-side validation uses the model families it knows; the engine also checks exact catalog routes.
|
|
116
|
+
export const validateGateway = (model: string, gateway: ModelOptions["gateway"]): string | undefined => {
|
|
117
|
+
if (gateway === undefined) return undefined
|
|
118
|
+
if (!gateway || typeof gateway !== "object" || Array.isArray(gateway)) return "gateway must contain order and/or only arrays."
|
|
119
|
+
const hosts = ["openai", "azure", "bedrock", "anthropic", "baseten", "cheaperinference", "google"]
|
|
120
|
+
const family = model.startsWith("openai/") ? ["openai", "azure"] : model.startsWith("anthropic/") ? ["bedrock", "anthropic"] : model.startsWith("google/") ? ["cheaperinference", "google"] : undefined
|
|
121
|
+
for (const list of [gateway.order, gateway.only]) {
|
|
122
|
+
if (list === undefined) continue
|
|
123
|
+
if (!Array.isArray(list)) return "gateway.order and gateway.only must be arrays of provider slugs."
|
|
124
|
+
for (const slug of list) {
|
|
125
|
+
if (typeof slug !== "string") return "Gateway provider slugs must be strings."
|
|
126
|
+
if (/^chatgpt\/[a-z0-9-]{1,64}$/.test(slug)) {
|
|
127
|
+
if (!model.startsWith("openai/")) return `Gateway slug '${slug}' cannot serve ${model}; ChatGPT connections require openai/* models.`
|
|
128
|
+
} else if (!hosts.includes(slug)) return `Unknown gateway slug '${slug}'. Use a catalog host or chatgpt/<name>.`
|
|
129
|
+
else if (family && !family.includes(slug)) return `Gateway slug '${slug}' does not serve ${model}.`
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
113
134
|
// requestOf turns effect/ai provider options into the wire request. Tools travel as JSON Schema; the host rebuilds them.
|
|
114
135
|
export const requestOf = (provider: LanguageModel.ProviderOptions, model: string, options: ModelOptions | undefined, session: string | undefined, method: string) => Effect.gen(function* () {
|
|
136
|
+
const routingError = validateGateway(model, options?.gateway)
|
|
137
|
+
if (routingError) return yield* invalid(method, routingError)
|
|
115
138
|
const tools: ToolSpec[] = []
|
|
116
139
|
for (const tool of provider.tools) {
|
|
117
140
|
if (Tool.isProviderDefined(tool)) return yield* invalid(method, `Provider-defined tool ${tool.name} is not served by managed models.`)
|
|
@@ -153,9 +176,11 @@ export const managedLanguageModel = (binding: ModelBinding, model: string, optio
|
|
|
153
176
|
})
|
|
154
177
|
|
|
155
178
|
export interface ManagedModelsOptions {
|
|
156
|
-
//
|
|
157
|
-
readonly
|
|
158
|
-
|
|
179
|
+
// model is the main catalog model; see GET /v1/models.
|
|
180
|
+
readonly model?: string
|
|
181
|
+
/** @deprecated Use model. Providing both is an error. */
|
|
182
|
+
readonly default?: string
|
|
183
|
+
// allow lists the other catalog models the actor may select. The main model is always allowed.
|
|
159
184
|
readonly allow?: ReadonlyArray<string>
|
|
160
185
|
// options apply to every model, or per model ID.
|
|
161
186
|
readonly options?: ModelOptions | Readonly<Record<string, ModelOptions>>
|
|
@@ -204,13 +229,16 @@ const catalogOf = (binding: ModelBinding) => {
|
|
|
204
229
|
|
|
205
230
|
// managedModels supplies tardie's model services from the platform catalog, read through the binding.
|
|
206
231
|
export const managedModels = (binding: ModelBinding, settings: ManagedModelsOptions) => Layer.unwrap(Effect.gen(function* () {
|
|
207
|
-
|
|
232
|
+
if (settings.model !== undefined && settings.default !== undefined) return yield* Effect.fail(new Error("Use model or deprecated default, not both."))
|
|
233
|
+
const main = settings.model ?? settings.default
|
|
234
|
+
if (!main) return yield* Effect.fail(new Error("managedModels requires model (or deprecated default)."))
|
|
235
|
+
const wanted = [...new Set([main, ...(settings.allow ?? [])])]
|
|
208
236
|
const listed = yield* Effect.tryPromise({ try: () => catalogOf(binding), catch: error => new Error(`Managed model catalog is unavailable: ${String(error)}`) })
|
|
209
237
|
const models = wanted.map(id => listed.data.find(model => model.id === id))
|
|
210
238
|
const missing = wanted.filter((_, index) => models[index] === undefined)
|
|
211
239
|
if (missing.length > 0) return yield* Effect.fail(new Error(`Not managed models: ${missing.join(", ")}. See GET /v1/models.`))
|
|
212
240
|
const catalog = models as ReadonlyArray<ListedModel>
|
|
213
|
-
const config = modelConfigOf({ allow: "*", providers: { [MANAGED_PROVIDER]: CONNECTION }, default: { provider: MANAGED_PROVIDER, model_id:
|
|
241
|
+
const config = modelConfigOf({ allow: "*", providers: { [MANAGED_PROVIDER]: CONNECTION }, default: { provider: MANAGED_PROVIDER, model_id: main } })
|
|
214
242
|
const lock = layerModelLock(lockOf(catalog), config)
|
|
215
243
|
const structured = new Set(catalog.filter(model => model.structuredOutput).map(model => model.id))
|
|
216
244
|
return liveModelServices({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "actorctl",
|
|
3
|
-
"version": "0.3.0-rc.
|
|
3
|
+
"version": "0.3.0-rc.18",
|
|
4
4
|
"description": "Deploy actors, run threads, and read events on Tardigrade Cloud.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -26,6 +26,6 @@
|
|
|
26
26
|
"tardie": "*"
|
|
27
27
|
},
|
|
28
28
|
"tardigrade": {
|
|
29
|
-
"sourceTree": "
|
|
29
|
+
"sourceTree": "b59a7f38fabba8fc1e2f4460bcc8b06e6d038b92"
|
|
30
30
|
}
|
|
31
31
|
}
|