@betterlu/agentlu 1.2.0 → 1.3.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 +21 -6
- package/dist/index.js +31 -4
- package/package.json +14 -4
package/dist/index.d.ts
CHANGED
|
@@ -42,10 +42,12 @@ export interface RunOptions {
|
|
|
42
42
|
model?: string;
|
|
43
43
|
input?: string;
|
|
44
44
|
/**
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
* Attachments previously uploaded via `upload()`. Prepended to the user
|
|
46
|
+
* turn using each file's `kind` (`input_image` / `input_video` / `input_file`).
|
|
47
|
+
*/
|
|
48
48
|
fileIds?: string[];
|
|
49
|
+
/** Optional kinds aligned with `fileIds` (from `upload()`). Defaults to image. */
|
|
50
|
+
fileKinds?: Array<"image" | "video" | "text" | "document">;
|
|
49
51
|
/** Structured input messages (OpenAI shape) - overrides `input`. */
|
|
50
52
|
inputMessages?: Array<{
|
|
51
53
|
role: string;
|
|
@@ -116,17 +118,22 @@ export declare class AgentLu {
|
|
|
116
118
|
person?: string | null;
|
|
117
119
|
defaults?: ClientDefaults;
|
|
118
120
|
}): UseCaseRunner;
|
|
119
|
-
/**
|
|
121
|
+
/**
|
|
122
|
+
* Register a use-case client and resolve to its api key. The key is cached
|
|
123
|
+
* on this instance (same semantics as `register`), so a following
|
|
124
|
+
* `responses.create` is authorized.
|
|
125
|
+
*/
|
|
120
126
|
useCaseClient(name: string, opts?: {
|
|
121
127
|
person?: string | null;
|
|
122
128
|
defaults?: ClientDefaults;
|
|
123
129
|
}): Promise<string>;
|
|
124
130
|
/**
|
|
125
|
-
* Upload an image
|
|
126
|
-
*
|
|
131
|
+
* Upload an image, video, or document for use with `run({ fileIds })`.
|
|
132
|
+
* Returns the `file_id` and stored `kind`.
|
|
127
133
|
*/
|
|
128
134
|
upload(data: Uint8Array | Blob, filename: string, mime?: string): Promise<{
|
|
129
135
|
id: string;
|
|
136
|
+
kind?: string;
|
|
130
137
|
}>;
|
|
131
138
|
me(): Promise<unknown>;
|
|
132
139
|
/**
|
|
@@ -197,4 +204,12 @@ export declare class UseCaseRunner {
|
|
|
197
204
|
response: ResponseObject;
|
|
198
205
|
}>;
|
|
199
206
|
stream(body: Record<string, unknown>): Promise<AsyncGenerator<Record<string, unknown>, any, any>>;
|
|
207
|
+
/**
|
|
208
|
+
* Upload with this use-case's key, so the file is owned by the same
|
|
209
|
+
* service client that will reference it via `run({ fileIds })`.
|
|
210
|
+
*/
|
|
211
|
+
upload(data: Uint8Array | Blob, filename: string, mime?: string): Promise<{
|
|
212
|
+
id: string;
|
|
213
|
+
kind?: string;
|
|
214
|
+
}>;
|
|
200
215
|
}
|
package/dist/index.js
CHANGED
|
@@ -55,16 +55,21 @@ export class AgentLu {
|
|
|
55
55
|
useCase(name, opts) {
|
|
56
56
|
return new UseCaseRunner(this, name, opts);
|
|
57
57
|
}
|
|
58
|
-
/**
|
|
58
|
+
/**
|
|
59
|
+
* Register a use-case client and resolve to its api key. The key is cached
|
|
60
|
+
* on this instance (same semantics as `register`), so a following
|
|
61
|
+
* `responses.create` is authorized.
|
|
62
|
+
*/
|
|
59
63
|
async useCaseClient(name, opts) {
|
|
60
64
|
const res = await this.request("POST", "/clients", { name, ...opts }, { auth: false });
|
|
61
65
|
if (!res.api_key)
|
|
62
66
|
throw new AgentLuError(500, "internal_error", "register returned no key", true);
|
|
67
|
+
this.apiKey = res.api_key;
|
|
63
68
|
return res.api_key;
|
|
64
69
|
}
|
|
65
70
|
/**
|
|
66
|
-
* Upload an image
|
|
67
|
-
*
|
|
71
|
+
* Upload an image, video, or document for use with `run({ fileIds })`.
|
|
72
|
+
* Returns the `file_id` and stored `kind`.
|
|
68
73
|
*/
|
|
69
74
|
async upload(data, filename, mime) {
|
|
70
75
|
const form = new FormData();
|
|
@@ -88,7 +93,14 @@ export class AgentLu {
|
|
|
88
93
|
{
|
|
89
94
|
role: "user",
|
|
90
95
|
content: [
|
|
91
|
-
...opts.fileIds.map((file_id) =>
|
|
96
|
+
...opts.fileIds.map((file_id, i) => {
|
|
97
|
+
const kind = opts.fileKinds?.[i];
|
|
98
|
+
if (kind === "video")
|
|
99
|
+
return { type: "input_video", file_id };
|
|
100
|
+
if (kind === "text" || kind === "document")
|
|
101
|
+
return { type: "input_file", file_id };
|
|
102
|
+
return { type: "input_image", file_id };
|
|
103
|
+
}),
|
|
92
104
|
{ type: "input_text", text: opts.input ?? "" },
|
|
93
105
|
],
|
|
94
106
|
},
|
|
@@ -321,6 +333,21 @@ export class UseCaseRunner {
|
|
|
321
333
|
this.parent.apiKey = parentKey;
|
|
322
334
|
}
|
|
323
335
|
}
|
|
336
|
+
/**
|
|
337
|
+
* Upload with this use-case's key, so the file is owned by the same
|
|
338
|
+
* service client that will reference it via `run({ fileIds })`.
|
|
339
|
+
*/
|
|
340
|
+
async upload(data, filename, mime) {
|
|
341
|
+
await this.ensure();
|
|
342
|
+
const parentKey = this.parent.apiKey;
|
|
343
|
+
this.parent.apiKey = this.apiKey ?? undefined;
|
|
344
|
+
try {
|
|
345
|
+
return await this.parent.upload(data, filename, mime);
|
|
346
|
+
}
|
|
347
|
+
finally {
|
|
348
|
+
this.parent.apiKey = parentKey;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
324
351
|
}
|
|
325
352
|
function parseRetryAfter(res) {
|
|
326
353
|
const header = res.headers.get("retry-after");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@betterlu/agentlu",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Client for the agentlu service API (/v1). Or just use the openai SDK pointed at http://localhost:8912/v1.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -11,8 +11,12 @@
|
|
|
11
11
|
"import": "./dist/index.js"
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
|
-
"files": [
|
|
15
|
-
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=18"
|
|
19
|
+
},
|
|
16
20
|
"scripts": {
|
|
17
21
|
"build": "tsc -p tsconfig.json",
|
|
18
22
|
"prepublishOnly": "npm run build"
|
|
@@ -20,7 +24,13 @@
|
|
|
20
24
|
"publishConfig": {
|
|
21
25
|
"access": "public"
|
|
22
26
|
},
|
|
23
|
-
"keywords": [
|
|
27
|
+
"keywords": [
|
|
28
|
+
"agentlu",
|
|
29
|
+
"openai",
|
|
30
|
+
"responses",
|
|
31
|
+
"llm",
|
|
32
|
+
"agent"
|
|
33
|
+
],
|
|
24
34
|
"repository": {
|
|
25
35
|
"type": "git",
|
|
26
36
|
"url": "git+https://github.com/betterlu/agentlu.git",
|