libretto 0.4.4 → 0.5.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/dist/cli/cli.js +20 -19
- package/dist/cli/commands/ai.js +1 -1
- package/dist/cli/commands/browser.js +3 -3
- package/dist/cli/commands/execution.js +3 -3
- package/dist/cli/commands/logs.js +1 -1
- package/dist/cli/core/browser.js +11 -6
- package/dist/cli/core/context.js +4 -18
- package/dist/cli/core/session.js +2 -2
- package/dist/cli/core/snapshot-analyzer.js +2 -2
- package/dist/cli/router.js +1 -1
- package/dist/cli/workers/run-integration-runtime.js +2 -2
- package/dist/shared/paths/paths.js +2 -1
- package/dist/shared/paths/repo-root.d.ts +3 -0
- package/dist/shared/paths/repo-root.js +24 -0
- package/package.json +6 -7
- package/scripts/postinstall.mjs +12 -3
- package/skills/libretto/SKILL.md +93 -404
- package/skills/libretto/references/auth-profiles.md +30 -0
- package/skills/libretto/references/pages-and-page-targeting.md +29 -0
- package/skills/libretto/references/reverse-engineering-network-requests.md +39 -0
- package/skills/libretto/references/user-action-log.md +31 -0
- package/src/cli/cli.ts +173 -0
- package/src/cli/commands/ai.ts +35 -0
- package/src/cli/commands/browser.ts +165 -0
- package/src/cli/commands/execution.ts +691 -0
- package/src/cli/commands/init.ts +327 -0
- package/src/cli/commands/logs.ts +128 -0
- package/src/cli/commands/shared.ts +70 -0
- package/src/cli/commands/snapshot.ts +327 -0
- package/src/cli/core/ai-config.ts +255 -0
- package/src/cli/core/api-snapshot-analyzer.ts +97 -0
- package/src/cli/core/browser.ts +839 -0
- package/src/cli/core/context.ts +122 -0
- package/src/cli/core/pause-signals.ts +35 -0
- package/src/cli/core/session-telemetry.ts +553 -0
- package/src/cli/core/session.ts +209 -0
- package/src/cli/core/snapshot-analyzer.ts +875 -0
- package/src/cli/core/snapshot-api-config.ts +236 -0
- package/src/cli/core/telemetry.ts +446 -0
- package/src/cli/framework/simple-cli.ts +1273 -0
- package/src/cli/index.ts +13 -0
- package/src/cli/router.ts +28 -0
- package/src/cli/workers/run-integration-runtime.ts +311 -0
- package/src/cli/workers/run-integration-worker-protocol.ts +14 -0
- package/src/cli/workers/run-integration-worker.ts +75 -0
- package/src/index.ts +120 -0
- package/src/runtime/download/download.ts +100 -0
- package/src/runtime/download/index.ts +7 -0
- package/src/runtime/extract/extract.ts +92 -0
- package/src/runtime/extract/index.ts +1 -0
- package/src/runtime/network/index.ts +5 -0
- package/src/runtime/network/network.ts +113 -0
- package/src/runtime/recovery/agent.ts +256 -0
- package/src/runtime/recovery/errors.ts +152 -0
- package/src/runtime/recovery/index.ts +7 -0
- package/src/runtime/recovery/recovery.ts +50 -0
- package/{dist/shared/condense-dom/condense-dom.cjs → src/shared/condense-dom/condense-dom.ts} +243 -115
- package/src/shared/config/config.ts +22 -0
- package/src/shared/config/index.ts +5 -0
- package/src/shared/debug/index.ts +1 -0
- package/src/shared/debug/pause.ts +85 -0
- package/src/shared/instrumentation/errors.ts +82 -0
- package/src/shared/instrumentation/index.ts +9 -0
- package/src/shared/instrumentation/instrument.ts +276 -0
- package/src/shared/llm/ai-sdk-adapter.ts +78 -0
- package/src/shared/llm/client.ts +217 -0
- package/src/shared/llm/index.ts +3 -0
- package/src/shared/llm/types.ts +63 -0
- package/src/shared/logger/index.ts +6 -0
- package/src/shared/logger/logger.ts +352 -0
- package/src/shared/logger/sinks.ts +144 -0
- package/src/shared/paths/paths.ts +109 -0
- package/src/shared/paths/repo-root.ts +27 -0
- package/src/shared/run/api.ts +2 -0
- package/src/shared/run/browser.ts +98 -0
- package/src/shared/state/index.ts +11 -0
- package/src/shared/state/session-state.ts +74 -0
- package/src/shared/visualization/ghost-cursor.ts +200 -0
- package/src/shared/visualization/highlight.ts +146 -0
- package/src/shared/visualization/index.ts +18 -0
- package/src/shared/workflow/workflow.ts +42 -0
- package/dist/index.cjs +0 -144
- package/dist/index.d.cts +0 -21
- package/dist/runtime/download/download.cjs +0 -70
- package/dist/runtime/download/download.d.cts +0 -35
- package/dist/runtime/download/index.cjs +0 -30
- package/dist/runtime/download/index.d.cts +0 -3
- package/dist/runtime/extract/extract.cjs +0 -88
- package/dist/runtime/extract/extract.d.cts +0 -23
- package/dist/runtime/extract/index.cjs +0 -28
- package/dist/runtime/extract/index.d.cts +0 -5
- package/dist/runtime/network/index.cjs +0 -28
- package/dist/runtime/network/index.d.cts +0 -4
- package/dist/runtime/network/network.cjs +0 -91
- package/dist/runtime/network/network.d.cts +0 -28
- package/dist/runtime/recovery/agent.cjs +0 -223
- package/dist/runtime/recovery/agent.d.cts +0 -13
- package/dist/runtime/recovery/errors.cjs +0 -124
- package/dist/runtime/recovery/errors.d.cts +0 -31
- package/dist/runtime/recovery/index.cjs +0 -34
- package/dist/runtime/recovery/index.d.cts +0 -7
- package/dist/runtime/recovery/recovery.cjs +0 -55
- package/dist/runtime/recovery/recovery.d.cts +0 -12
- package/dist/shared/condense-dom/condense-dom.d.cts +0 -34
- package/dist/shared/config/config.cjs +0 -44
- package/dist/shared/config/config.d.cts +0 -10
- package/dist/shared/config/index.cjs +0 -32
- package/dist/shared/config/index.d.cts +0 -1
- package/dist/shared/debug/index.cjs +0 -28
- package/dist/shared/debug/index.d.cts +0 -1
- package/dist/shared/debug/pause.cjs +0 -86
- package/dist/shared/debug/pause.d.cts +0 -12
- package/dist/shared/instrumentation/errors.cjs +0 -81
- package/dist/shared/instrumentation/errors.d.cts +0 -12
- package/dist/shared/instrumentation/index.cjs +0 -35
- package/dist/shared/instrumentation/index.d.cts +0 -6
- package/dist/shared/instrumentation/instrument.cjs +0 -206
- package/dist/shared/instrumentation/instrument.d.cts +0 -32
- package/dist/shared/llm/ai-sdk-adapter.cjs +0 -71
- package/dist/shared/llm/ai-sdk-adapter.d.cts +0 -22
- package/dist/shared/llm/client.cjs +0 -218
- package/dist/shared/llm/client.d.cts +0 -13
- package/dist/shared/llm/index.cjs +0 -31
- package/dist/shared/llm/index.d.cts +0 -5
- package/dist/shared/llm/types.cjs +0 -16
- package/dist/shared/llm/types.d.cts +0 -67
- package/dist/shared/logger/index.cjs +0 -37
- package/dist/shared/logger/index.d.cts +0 -2
- package/dist/shared/logger/logger.cjs +0 -232
- package/dist/shared/logger/logger.d.cts +0 -86
- package/dist/shared/logger/sinks.cjs +0 -160
- package/dist/shared/logger/sinks.d.cts +0 -9
- package/dist/shared/paths/paths.cjs +0 -104
- package/dist/shared/paths/paths.d.cts +0 -10
- package/dist/shared/run/api.cjs +0 -28
- package/dist/shared/run/api.d.cts +0 -2
- package/dist/shared/run/browser.cjs +0 -98
- package/dist/shared/run/browser.d.cts +0 -22
- package/dist/shared/state/index.cjs +0 -38
- package/dist/shared/state/index.d.cts +0 -2
- package/dist/shared/state/session-state.cjs +0 -92
- package/dist/shared/state/session-state.d.cts +0 -40
- package/dist/shared/visualization/ghost-cursor.cjs +0 -174
- package/dist/shared/visualization/ghost-cursor.d.cts +0 -37
- package/dist/shared/visualization/highlight.cjs +0 -134
- package/dist/shared/visualization/highlight.d.cts +0 -22
- package/dist/shared/visualization/index.cjs +0 -45
- package/dist/shared/visualization/index.d.cts +0 -3
- package/dist/shared/workflow/workflow.cjs +0 -47
- package/dist/shared/workflow/workflow.d.cts +0 -21
- package/skills/libretto/code-generation-rules.md +0 -223
- package/skills/libretto/integration-approach-selection.md +0 -174
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var ai_sdk_adapter_exports = {};
|
|
20
|
-
__export(ai_sdk_adapter_exports, {
|
|
21
|
-
createLLMClientFromModel: () => createLLMClientFromModel
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(ai_sdk_adapter_exports);
|
|
24
|
-
var import_ai = require("ai");
|
|
25
|
-
function createLLMClientFromModel(model) {
|
|
26
|
-
return {
|
|
27
|
-
async generateObject(opts) {
|
|
28
|
-
const { object } = await (0, import_ai.generateObject)({
|
|
29
|
-
model,
|
|
30
|
-
schema: opts.schema,
|
|
31
|
-
prompt: opts.prompt,
|
|
32
|
-
temperature: opts.temperature ?? 0
|
|
33
|
-
});
|
|
34
|
-
return object;
|
|
35
|
-
},
|
|
36
|
-
async generateObjectFromMessages(opts) {
|
|
37
|
-
const messages = opts.messages.map((msg) => {
|
|
38
|
-
if (typeof msg.content === "string") {
|
|
39
|
-
return { role: msg.role, content: msg.content };
|
|
40
|
-
}
|
|
41
|
-
if (msg.role === "assistant") {
|
|
42
|
-
return {
|
|
43
|
-
role: "assistant",
|
|
44
|
-
content: msg.content.filter((part) => part.type === "text").map((part) => ({ type: "text", text: part.text }))
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
return {
|
|
48
|
-
role: "user",
|
|
49
|
-
content: msg.content.map(
|
|
50
|
-
(part) => part.type === "text" ? { type: "text", text: part.text } : {
|
|
51
|
-
type: "image",
|
|
52
|
-
image: part.image,
|
|
53
|
-
...part.mediaType ? { mediaType: part.mediaType } : {}
|
|
54
|
-
}
|
|
55
|
-
)
|
|
56
|
-
};
|
|
57
|
-
});
|
|
58
|
-
const { object } = await (0, import_ai.generateObject)({
|
|
59
|
-
model,
|
|
60
|
-
schema: opts.schema,
|
|
61
|
-
messages,
|
|
62
|
-
temperature: opts.temperature ?? 0
|
|
63
|
-
});
|
|
64
|
-
return object;
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
69
|
-
0 && (module.exports = {
|
|
70
|
-
createLLMClientFromModel
|
|
71
|
-
});
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { LanguageModel } from 'ai';
|
|
2
|
-
import { LLMClient } from './types.cjs';
|
|
3
|
-
import 'zod';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Creates a libretto LLMClient from a Vercel AI SDK LanguageModel.
|
|
7
|
-
*
|
|
8
|
-
* This eliminates the need for consumers to write their own adapter
|
|
9
|
-
* when using @ai-sdk/openai, @ai-sdk/anthropic, @ai-sdk/google-vertex,
|
|
10
|
-
* or any other Vercel AI SDK-compatible provider.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```typescript
|
|
14
|
-
* import { createLLMClientFromModel } from "libretto/llm";
|
|
15
|
-
* import { openai } from "@ai-sdk/openai";
|
|
16
|
-
*
|
|
17
|
-
* const llmClient = createLLMClientFromModel(openai("gpt-4o"));
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
declare function createLLMClientFromModel(model: LanguageModel): LLMClient;
|
|
21
|
-
|
|
22
|
-
export { createLLMClientFromModel };
|
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var client_exports = {};
|
|
30
|
-
__export(client_exports, {
|
|
31
|
-
createLLMClient: () => createLLMClient,
|
|
32
|
-
hasProviderCredentials: () => hasProviderCredentials,
|
|
33
|
-
missingProviderCredentialsMessage: () => missingProviderCredentialsMessage,
|
|
34
|
-
parseModel: () => parseModel
|
|
35
|
-
});
|
|
36
|
-
module.exports = __toCommonJS(client_exports);
|
|
37
|
-
var import_ai = require("ai");
|
|
38
|
-
const GEMINI_API_KEY_ENV_VARS = [
|
|
39
|
-
"GEMINI_API_KEY",
|
|
40
|
-
"GOOGLE_GENERATIVE_AI_API_KEY"
|
|
41
|
-
];
|
|
42
|
-
const VERTEX_PROJECT_ENV_VARS = [
|
|
43
|
-
"GOOGLE_CLOUD_PROJECT",
|
|
44
|
-
"GCLOUD_PROJECT"
|
|
45
|
-
];
|
|
46
|
-
const SUPPORTED_PROVIDER_ALIASES = {
|
|
47
|
-
google: "google",
|
|
48
|
-
gemini: "google",
|
|
49
|
-
vertex: "vertex",
|
|
50
|
-
anthropic: "anthropic",
|
|
51
|
-
codex: "openai",
|
|
52
|
-
openai: "openai"
|
|
53
|
-
};
|
|
54
|
-
function readFirstEnvValue(env, names) {
|
|
55
|
-
for (const name of names) {
|
|
56
|
-
const value = env[name]?.trim();
|
|
57
|
-
if (value) return value;
|
|
58
|
-
}
|
|
59
|
-
return null;
|
|
60
|
-
}
|
|
61
|
-
function parseModel(model) {
|
|
62
|
-
const slashIndex = model.indexOf("/");
|
|
63
|
-
if (slashIndex === -1) {
|
|
64
|
-
throw new Error(
|
|
65
|
-
`Invalid model string "${model}". Expected format: "provider/model-id" (for example "openai/gpt-5.4", "anthropic/claude-sonnet-4-6", "google/gemini-3-flash-preview", or "vertex/gemini-2.5-pro").`
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
const providerInput = model.slice(0, slashIndex).toLowerCase();
|
|
69
|
-
const provider = SUPPORTED_PROVIDER_ALIASES[providerInput];
|
|
70
|
-
const modelId = model.slice(slashIndex + 1);
|
|
71
|
-
if (!provider) {
|
|
72
|
-
throw new Error(
|
|
73
|
-
`Unsupported provider "${providerInput}". Supported providers: openai/codex, anthropic, google (Gemini API), and vertex.`
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
return { provider, modelId };
|
|
77
|
-
}
|
|
78
|
-
function hasProviderCredentials(provider, env = process.env) {
|
|
79
|
-
switch (provider) {
|
|
80
|
-
case "google":
|
|
81
|
-
return readFirstEnvValue(env, GEMINI_API_KEY_ENV_VARS) !== null;
|
|
82
|
-
case "vertex":
|
|
83
|
-
return readFirstEnvValue(env, VERTEX_PROJECT_ENV_VARS) !== null;
|
|
84
|
-
case "anthropic":
|
|
85
|
-
return Boolean(env.ANTHROPIC_API_KEY?.trim());
|
|
86
|
-
case "openai":
|
|
87
|
-
return Boolean(env.OPENAI_API_KEY?.trim());
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
function missingProviderCredentialsMessage(provider) {
|
|
91
|
-
switch (provider) {
|
|
92
|
-
case "google":
|
|
93
|
-
return "Gemini API key is missing. Set GEMINI_API_KEY or GOOGLE_GENERATIVE_AI_API_KEY.";
|
|
94
|
-
case "vertex":
|
|
95
|
-
return "Vertex AI project is missing. Set GOOGLE_CLOUD_PROJECT (or GCLOUD_PROJECT) and ensure application default credentials are configured.";
|
|
96
|
-
case "anthropic": {
|
|
97
|
-
return "Anthropic API key is missing. Set ANTHROPIC_API_KEY.";
|
|
98
|
-
}
|
|
99
|
-
case "openai": {
|
|
100
|
-
return "OpenAI API key is missing. Set OPENAI_API_KEY.";
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
async function getProviderModel(provider, modelId) {
|
|
105
|
-
switch (provider) {
|
|
106
|
-
case "google": {
|
|
107
|
-
const apiKey = readFirstEnvValue(process.env, GEMINI_API_KEY_ENV_VARS);
|
|
108
|
-
if (!apiKey) {
|
|
109
|
-
throw new Error(missingProviderCredentialsMessage(provider));
|
|
110
|
-
}
|
|
111
|
-
const { createGoogleGenerativeAI } = await import("@ai-sdk/google");
|
|
112
|
-
const google = createGoogleGenerativeAI({ apiKey });
|
|
113
|
-
return google(modelId);
|
|
114
|
-
}
|
|
115
|
-
case "vertex": {
|
|
116
|
-
const project = readFirstEnvValue(process.env, VERTEX_PROJECT_ENV_VARS);
|
|
117
|
-
if (!project) {
|
|
118
|
-
throw new Error(missingProviderCredentialsMessage(provider));
|
|
119
|
-
}
|
|
120
|
-
const { createVertex } = await import("@ai-sdk/google-vertex");
|
|
121
|
-
const vertex = createVertex({
|
|
122
|
-
project,
|
|
123
|
-
location: process.env.GOOGLE_CLOUD_LOCATION || "global"
|
|
124
|
-
});
|
|
125
|
-
return vertex(modelId);
|
|
126
|
-
}
|
|
127
|
-
case "anthropic": {
|
|
128
|
-
const apiKey = process.env.ANTHROPIC_API_KEY?.trim();
|
|
129
|
-
if (!apiKey) {
|
|
130
|
-
throw new Error(missingProviderCredentialsMessage(provider));
|
|
131
|
-
}
|
|
132
|
-
const { createAnthropic } = await import("@ai-sdk/anthropic");
|
|
133
|
-
const anthropic = createAnthropic({ apiKey });
|
|
134
|
-
return anthropic(modelId);
|
|
135
|
-
}
|
|
136
|
-
case "openai": {
|
|
137
|
-
const apiKey = process.env.OPENAI_API_KEY?.trim();
|
|
138
|
-
if (!apiKey) {
|
|
139
|
-
throw new Error(missingProviderCredentialsMessage(provider));
|
|
140
|
-
}
|
|
141
|
-
const { createOpenAI } = await import("@ai-sdk/openai");
|
|
142
|
-
const openai = createOpenAI({ apiKey });
|
|
143
|
-
return openai(modelId);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
function convertUserContentParts(parts) {
|
|
148
|
-
return parts.map((part) => {
|
|
149
|
-
if (part.type === "text") {
|
|
150
|
-
return { type: "text", text: part.text };
|
|
151
|
-
}
|
|
152
|
-
return {
|
|
153
|
-
type: "image",
|
|
154
|
-
image: part.image,
|
|
155
|
-
...part.mediaType ? { mediaType: part.mediaType } : {}
|
|
156
|
-
};
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
function convertAssistantContentParts(parts) {
|
|
160
|
-
return parts.filter((part) => part.type === "text").map((part) => ({ type: "text", text: part.text }));
|
|
161
|
-
}
|
|
162
|
-
function convertMessages(messages) {
|
|
163
|
-
return messages.map((msg) => {
|
|
164
|
-
if (msg.role === "user") {
|
|
165
|
-
if (typeof msg.content === "string") {
|
|
166
|
-
return { role: "user", content: msg.content };
|
|
167
|
-
}
|
|
168
|
-
return {
|
|
169
|
-
role: "user",
|
|
170
|
-
content: convertUserContentParts(msg.content)
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
if (typeof msg.content === "string") {
|
|
174
|
-
return { role: "assistant", content: msg.content };
|
|
175
|
-
}
|
|
176
|
-
return {
|
|
177
|
-
role: "assistant",
|
|
178
|
-
content: convertAssistantContentParts(msg.content)
|
|
179
|
-
};
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
function createLLMClient(model) {
|
|
183
|
-
const { provider, modelId } = parseModel(model);
|
|
184
|
-
let modelPromise = null;
|
|
185
|
-
const getModel = () => {
|
|
186
|
-
modelPromise ??= getProviderModel(provider, modelId);
|
|
187
|
-
return modelPromise;
|
|
188
|
-
};
|
|
189
|
-
return {
|
|
190
|
-
async generateObject(opts) {
|
|
191
|
-
const aiModel = await getModel();
|
|
192
|
-
const result = await (0, import_ai.generateObject)({
|
|
193
|
-
model: aiModel,
|
|
194
|
-
prompt: opts.prompt,
|
|
195
|
-
schema: opts.schema,
|
|
196
|
-
temperature: opts.temperature ?? 0
|
|
197
|
-
});
|
|
198
|
-
return result.object;
|
|
199
|
-
},
|
|
200
|
-
async generateObjectFromMessages(opts) {
|
|
201
|
-
const aiModel = await getModel();
|
|
202
|
-
const result = await (0, import_ai.generateObject)({
|
|
203
|
-
model: aiModel,
|
|
204
|
-
messages: convertMessages(opts.messages),
|
|
205
|
-
schema: opts.schema,
|
|
206
|
-
temperature: opts.temperature ?? 0
|
|
207
|
-
});
|
|
208
|
-
return result.object;
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
213
|
-
0 && (module.exports = {
|
|
214
|
-
createLLMClient,
|
|
215
|
-
hasProviderCredentials,
|
|
216
|
-
missingProviderCredentialsMessage,
|
|
217
|
-
parseModel
|
|
218
|
-
});
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { LLMClient } from './types.cjs';
|
|
2
|
-
import 'zod';
|
|
3
|
-
|
|
4
|
-
type Provider = "google" | "vertex" | "anthropic" | "openai";
|
|
5
|
-
declare function parseModel(model: string): {
|
|
6
|
-
provider: Provider;
|
|
7
|
-
modelId: string;
|
|
8
|
-
};
|
|
9
|
-
declare function hasProviderCredentials(provider: Provider, env?: NodeJS.ProcessEnv): boolean;
|
|
10
|
-
declare function missingProviderCredentialsMessage(provider: Provider): string;
|
|
11
|
-
declare function createLLMClient(model: string): LLMClient;
|
|
12
|
-
|
|
13
|
-
export { type Provider, createLLMClient, hasProviderCredentials, missingProviderCredentialsMessage, parseModel };
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var llm_exports = {};
|
|
20
|
-
__export(llm_exports, {
|
|
21
|
-
createLLMClient: () => import_client.createLLMClient,
|
|
22
|
-
createLLMClientFromModel: () => import_ai_sdk_adapter.createLLMClientFromModel
|
|
23
|
-
});
|
|
24
|
-
module.exports = __toCommonJS(llm_exports);
|
|
25
|
-
var import_client = require("./client.js");
|
|
26
|
-
var import_ai_sdk_adapter = require("./ai-sdk-adapter.js");
|
|
27
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
28
|
-
0 && (module.exports = {
|
|
29
|
-
createLLMClient,
|
|
30
|
-
createLLMClientFromModel
|
|
31
|
-
});
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __copyProps = (to, from, except, desc) => {
|
|
7
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
-
for (let key of __getOwnPropNames(from))
|
|
9
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
-
}
|
|
12
|
-
return to;
|
|
13
|
-
};
|
|
14
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
var types_exports = {};
|
|
16
|
-
module.exports = __toCommonJS(types_exports);
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import z from 'zod';
|
|
2
|
-
|
|
3
|
-
type MessageContentPart = {
|
|
4
|
-
type: "text";
|
|
5
|
-
text: string;
|
|
6
|
-
} | {
|
|
7
|
-
type: "image";
|
|
8
|
-
image: string | Uint8Array;
|
|
9
|
-
mediaType?: string;
|
|
10
|
-
};
|
|
11
|
-
type Message = {
|
|
12
|
-
role: "user" | "assistant";
|
|
13
|
-
content: string | MessageContentPart[];
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Pluggable LLM client interface.
|
|
17
|
-
*
|
|
18
|
-
* Users provide their own implementation backed by any LLM provider
|
|
19
|
-
* (OpenAI, Anthropic, etc.). Libretto uses this interface for AI extraction,
|
|
20
|
-
* recovery agents, and error detection.
|
|
21
|
-
*
|
|
22
|
-
* **Error handling:** implementations should throw on failure rather than
|
|
23
|
-
* returning sentinel values (e.g. `null` or `undefined`). Libretto relies
|
|
24
|
-
* on exceptions to trigger retry/recovery logic.
|
|
25
|
-
*
|
|
26
|
-
* A ready-made adapter for the Vercel AI SDK is available via
|
|
27
|
-
* {@link createLLMClientFromModel} in `libretto/llm`.
|
|
28
|
-
*/
|
|
29
|
-
interface LLMClient {
|
|
30
|
-
/**
|
|
31
|
-
* Generate a structured object from a single text prompt.
|
|
32
|
-
*
|
|
33
|
-
* The underlying model **must** support structured / JSON output so that
|
|
34
|
-
* the response can be parsed and validated against the provided Zod schema.
|
|
35
|
-
*
|
|
36
|
-
* @param opts.prompt - The text prompt sent to the model.
|
|
37
|
-
* @param opts.schema - A Zod schema describing the expected response shape.
|
|
38
|
-
* @param opts.temperature - Sampling temperature (default chosen by implementation, typically 0).
|
|
39
|
-
* @returns The parsed object matching the schema.
|
|
40
|
-
* @throws On LLM or parsing failure.
|
|
41
|
-
*/
|
|
42
|
-
generateObject<T extends z.ZodType>(opts: {
|
|
43
|
-
prompt: string;
|
|
44
|
-
schema: T;
|
|
45
|
-
temperature?: number;
|
|
46
|
-
}): Promise<z.output<T>>;
|
|
47
|
-
/**
|
|
48
|
-
* Generate a structured object from a conversation-style message array.
|
|
49
|
-
*
|
|
50
|
-
* Messages may contain **image content** (base64 data URIs via
|
|
51
|
-
* {@link MessageContentPart}), so the backing model must support
|
|
52
|
-
* vision / multimodal input when images are present.
|
|
53
|
-
*
|
|
54
|
-
* @param opts.messages - Ordered list of user/assistant messages, potentially multimodal.
|
|
55
|
-
* @param opts.schema - A Zod schema describing the expected response shape.
|
|
56
|
-
* @param opts.temperature - Sampling temperature (default chosen by implementation, typically 0).
|
|
57
|
-
* @returns The parsed object matching the schema.
|
|
58
|
-
* @throws On LLM or parsing failure.
|
|
59
|
-
*/
|
|
60
|
-
generateObjectFromMessages<T extends z.ZodType>(opts: {
|
|
61
|
-
messages: Message[];
|
|
62
|
-
schema: T;
|
|
63
|
-
temperature?: number;
|
|
64
|
-
}): Promise<z.output<T>>;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export type { LLMClient, Message, MessageContentPart };
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var logger_exports = {};
|
|
20
|
-
__export(logger_exports, {
|
|
21
|
-
Logger: () => import_logger.Logger,
|
|
22
|
-
createFileLogSink: () => import_sinks.createFileLogSink,
|
|
23
|
-
defaultLogger: () => import_logger.defaultLogger,
|
|
24
|
-
jsonlConsoleSink: () => import_sinks.jsonlConsoleSink,
|
|
25
|
-
prettyConsoleSink: () => import_sinks.prettyConsoleSink
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(logger_exports);
|
|
28
|
-
var import_logger = require("./logger.js");
|
|
29
|
-
var import_sinks = require("./sinks.js");
|
|
30
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
31
|
-
0 && (module.exports = {
|
|
32
|
-
Logger,
|
|
33
|
-
createFileLogSink,
|
|
34
|
-
defaultLogger,
|
|
35
|
-
jsonlConsoleSink,
|
|
36
|
-
prettyConsoleSink
|
|
37
|
-
});
|