@betterlu/agentlu 1.1.0 → 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 CHANGED
@@ -40,7 +40,17 @@ export interface ClientDefaults {
40
40
  export interface RunOptions {
41
41
  agent?: string;
42
42
  model?: string;
43
- input: string;
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;
@@ -55,6 +65,8 @@ export interface RunOptions {
55
65
  include?: string[];
56
66
  temperature?: number;
57
67
  max_output_tokens?: number;
68
+ /** Caller metadata stored on the response row (console visibility). */
69
+ metadata?: Record<string, string>;
58
70
  /** JSON Schema. When set, `data` on the result is the validated object. */
59
71
  schema?: Record<string, unknown>;
60
72
  schemaName?: string;
@@ -109,6 +121,13 @@ export declare class AgentLu {
109
121
  person?: string | null;
110
122
  defaults?: ClientDefaults;
111
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
+ }>;
112
131
  me(): Promise<unknown>;
113
132
  /**
114
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: opts.input,
98
+ input,
76
99
  agent: opts.agent,
77
100
  model: opts.model,
78
101
  instructions: opts.instructions,
@@ -87,6 +110,7 @@ export class AgentLu {
87
110
  temperature: opts.temperature,
88
111
  max_output_tokens: opts.max_output_tokens,
89
112
  background: opts.background,
113
+ metadata: opts.metadata,
90
114
  };
91
115
  if (opts.schema) {
92
116
  body.text = {
@@ -200,14 +224,16 @@ export class AgentLu {
200
224
  }
201
225
  async raw(method, path, body, opts) {
202
226
  const headers = {};
203
- if (body !== undefined)
227
+ const isForm = typeof FormData !== "undefined" && body instanceof FormData;
228
+ if (body !== undefined && !isForm) {
204
229
  headers["Content-Type"] = "application/json";
230
+ }
205
231
  if (opts?.auth !== false && this.apiKey)
206
232
  headers.Authorization = `Bearer ${this.apiKey}`;
207
233
  const res = await this.fetchImpl(`${this.baseUrl}${path}`, {
208
234
  method,
209
235
  headers,
210
- body: body === undefined ? undefined : JSON.stringify(body),
236
+ body: body === undefined ? undefined : isForm ? body : JSON.stringify(body),
211
237
  });
212
238
  if (!res.ok) {
213
239
  let code = `http_${res.status}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@betterlu/agentlu",
3
- "version": "1.1.0",
3
+ "version": "1.2.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",