@betterlu/agentlu 1.1.1 → 1.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/dist/index.d.ts +18 -1
- package/dist/index.js +28 -3
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -40,7 +40,17 @@ export interface ClientDefaults {
|
|
|
40
40
|
export interface RunOptions {
|
|
41
41
|
agent?: string;
|
|
42
42
|
model?: string;
|
|
43
|
-
input
|
|
43
|
+
input?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Image attachments previously uploaded via `upload()`. Prepended to the
|
|
46
|
+
* user turn as `input_image` parts; `input` becomes the accompanying text.
|
|
47
|
+
*/
|
|
48
|
+
fileIds?: string[];
|
|
49
|
+
/** Structured input messages (OpenAI shape) - overrides `input`. */
|
|
50
|
+
inputMessages?: Array<{
|
|
51
|
+
role: string;
|
|
52
|
+
content: string | Array<Record<string, unknown>>;
|
|
53
|
+
}>;
|
|
44
54
|
instructions?: string;
|
|
45
55
|
tools?: Array<string | {
|
|
46
56
|
type: string;
|
|
@@ -111,6 +121,13 @@ export declare class AgentLu {
|
|
|
111
121
|
person?: string | null;
|
|
112
122
|
defaults?: ClientDefaults;
|
|
113
123
|
}): Promise<string>;
|
|
124
|
+
/**
|
|
125
|
+
* Upload an image (or document) for use with `run({ fileIds })` /
|
|
126
|
+
* `input_image`. Returns the `file_id` to reference.
|
|
127
|
+
*/
|
|
128
|
+
upload(data: Uint8Array | Blob, filename: string, mime?: string): Promise<{
|
|
129
|
+
id: string;
|
|
130
|
+
}>;
|
|
114
131
|
me(): Promise<unknown>;
|
|
115
132
|
/**
|
|
116
133
|
* One-shot helper. When `schema` is given, returns the validated object as
|
package/dist/index.js
CHANGED
|
@@ -62,6 +62,17 @@ export class AgentLu {
|
|
|
62
62
|
throw new AgentLuError(500, "internal_error", "register returned no key", true);
|
|
63
63
|
return res.api_key;
|
|
64
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Upload an image (or document) for use with `run({ fileIds })` /
|
|
67
|
+
* `input_image`. Returns the `file_id` to reference.
|
|
68
|
+
*/
|
|
69
|
+
async upload(data, filename, mime) {
|
|
70
|
+
const form = new FormData();
|
|
71
|
+
const blob = data instanceof Blob ? data : new Blob([new Uint8Array(data)], { type: mime ?? "application/octet-stream" });
|
|
72
|
+
form.append("file", blob, filename);
|
|
73
|
+
const res = await this.raw("POST", "/files", form);
|
|
74
|
+
return (await res.json());
|
|
75
|
+
}
|
|
65
76
|
async me() {
|
|
66
77
|
return this.request("GET", "/me");
|
|
67
78
|
}
|
|
@@ -71,8 +82,20 @@ export class AgentLu {
|
|
|
71
82
|
* could not produce matching JSON.
|
|
72
83
|
*/
|
|
73
84
|
async run(opts) {
|
|
85
|
+
let input = opts.inputMessages ?? opts.input;
|
|
86
|
+
if (opts.fileIds?.length) {
|
|
87
|
+
input = [
|
|
88
|
+
{
|
|
89
|
+
role: "user",
|
|
90
|
+
content: [
|
|
91
|
+
...opts.fileIds.map((file_id) => ({ type: "input_image", file_id })),
|
|
92
|
+
{ type: "input_text", text: opts.input ?? "" },
|
|
93
|
+
],
|
|
94
|
+
},
|
|
95
|
+
];
|
|
96
|
+
}
|
|
74
97
|
const body = {
|
|
75
|
-
input
|
|
98
|
+
input,
|
|
76
99
|
agent: opts.agent,
|
|
77
100
|
model: opts.model,
|
|
78
101
|
instructions: opts.instructions,
|
|
@@ -201,14 +224,16 @@ export class AgentLu {
|
|
|
201
224
|
}
|
|
202
225
|
async raw(method, path, body, opts) {
|
|
203
226
|
const headers = {};
|
|
204
|
-
|
|
227
|
+
const isForm = typeof FormData !== "undefined" && body instanceof FormData;
|
|
228
|
+
if (body !== undefined && !isForm) {
|
|
205
229
|
headers["Content-Type"] = "application/json";
|
|
230
|
+
}
|
|
206
231
|
if (opts?.auth !== false && this.apiKey)
|
|
207
232
|
headers.Authorization = `Bearer ${this.apiKey}`;
|
|
208
233
|
const res = await this.fetchImpl(`${this.baseUrl}${path}`, {
|
|
209
234
|
method,
|
|
210
235
|
headers,
|
|
211
|
-
body: body === undefined ? undefined : JSON.stringify(body),
|
|
236
|
+
body: body === undefined ? undefined : isForm ? body : JSON.stringify(body),
|
|
212
237
|
});
|
|
213
238
|
if (!res.ok) {
|
|
214
239
|
let code = `http_${res.status}`;
|
package/package.json
CHANGED