@dahura/super-agent-runtime 0.1.1
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/LICENSE +21 -0
- package/dist/ask.d.ts +75 -0
- package/dist/ask.d.ts.map +1 -0
- package/dist/ask.js +140 -0
- package/dist/ask.js.map +1 -0
- package/dist/builder.d.ts +73 -0
- package/dist/builder.d.ts.map +1 -0
- package/dist/builder.js +477 -0
- package/dist/builder.js.map +1 -0
- package/dist/env.d.ts +36 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +63 -0
- package/dist/env.js.map +1 -0
- package/dist/errors.d.ts +40 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +43 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/loaders.d.ts +39 -0
- package/dist/loaders.d.ts.map +1 -0
- package/dist/loaders.js +113 -0
- package/dist/loaders.js.map +1 -0
- package/dist/model.d.ts +64 -0
- package/dist/model.d.ts.map +1 -0
- package/dist/model.js +2 -0
- package/dist/model.js.map +1 -0
- package/dist/providers/anthropic.d.ts +14 -0
- package/dist/providers/anthropic.d.ts.map +1 -0
- package/dist/providers/anthropic.js +19 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/anthropic.provider.d.ts +22 -0
- package/dist/providers/anthropic.provider.d.ts.map +1 -0
- package/dist/providers/anthropic.provider.js +62 -0
- package/dist/providers/anthropic.provider.js.map +1 -0
- package/dist/providers/audio-local.d.ts +21 -0
- package/dist/providers/audio-local.d.ts.map +1 -0
- package/dist/providers/audio-local.js +451 -0
- package/dist/providers/audio-local.js.map +1 -0
- package/dist/providers/audio-local.provider.d.ts +15 -0
- package/dist/providers/audio-local.provider.d.ts.map +1 -0
- package/dist/providers/audio-local.provider.js +137 -0
- package/dist/providers/audio-local.provider.js.map +1 -0
- package/dist/providers/index.d.ts +30 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +56 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/llama-server.d.ts +57 -0
- package/dist/providers/llama-server.d.ts.map +1 -0
- package/dist/providers/llama-server.js +231 -0
- package/dist/providers/llama-server.js.map +1 -0
- package/dist/providers/llama-server.provider.d.ts +34 -0
- package/dist/providers/llama-server.provider.d.ts.map +1 -0
- package/dist/providers/llama-server.provider.js +147 -0
- package/dist/providers/llama-server.provider.js.map +1 -0
- package/dist/providers/openai-compatible.d.ts +32 -0
- package/dist/providers/openai-compatible.d.ts.map +1 -0
- package/dist/providers/openai-compatible.js +53 -0
- package/dist/providers/openai-compatible.js.map +1 -0
- package/dist/providers/openai-compatible.provider.d.ts +24 -0
- package/dist/providers/openai-compatible.provider.d.ts.map +1 -0
- package/dist/providers/openai-compatible.provider.js +76 -0
- package/dist/providers/openai-compatible.provider.js.map +1 -0
- package/dist/providers/openai.d.ts +14 -0
- package/dist/providers/openai.d.ts.map +1 -0
- package/dist/providers/openai.js +24 -0
- package/dist/providers/openai.js.map +1 -0
- package/dist/providers/openai.provider.d.ts +23 -0
- package/dist/providers/openai.provider.d.ts.map +1 -0
- package/dist/providers/openai.provider.js +68 -0
- package/dist/providers/openai.provider.js.map +1 -0
- package/dist/providers/whisper-cpp.d.ts +23 -0
- package/dist/providers/whisper-cpp.d.ts.map +1 -0
- package/dist/providers/whisper-cpp.js +110 -0
- package/dist/providers/whisper-cpp.js.map +1 -0
- package/dist/providers/whisper-cpp.provider.d.ts +27 -0
- package/dist/providers/whisper-cpp.provider.d.ts.map +1 -0
- package/dist/providers/whisper-cpp.provider.js +139 -0
- package/dist/providers/whisper-cpp.provider.js.map +1 -0
- package/dist/proxy.d.ts +11 -0
- package/dist/proxy.d.ts.map +1 -0
- package/dist/proxy.js +12 -0
- package/dist/proxy.js.map +1 -0
- package/dist/registry.d.ts +111 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +328 -0
- package/dist/registry.js.map +1 -0
- package/dist/resolver.d.ts +47 -0
- package/dist/resolver.d.ts.map +1 -0
- package/dist/resolver.js +365 -0
- package/dist/resolver.js.map +1 -0
- package/dist/workflow.d.ts +86 -0
- package/dist/workflow.d.ts.map +1 -0
- package/dist/workflow.js +343 -0
- package/dist/workflow.js.map +1 -0
- package/package.json +57 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 SuperAgent contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/ask.d.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { SubagentTraceEntry } from "@dahura/super-agent-kit";
|
|
2
|
+
import type { z } from "zod";
|
|
3
|
+
/**
|
|
4
|
+
* The producer function backs every `Ask` instance. It MUST be safe to call
|
|
5
|
+
* exactly once per Ask object — Ask methods (`text`, `stream`, `iter`, ...)
|
|
6
|
+
* are mutually exclusive consumers of the producer.
|
|
7
|
+
*/
|
|
8
|
+
export type AskProducer = () => Promise<AskProduction>;
|
|
9
|
+
/**
|
|
10
|
+
* What the producer returns. Two shapes:
|
|
11
|
+
* - text: complete string, no streaming required
|
|
12
|
+
* - stream: an async iterable of string chunks
|
|
13
|
+
*
|
|
14
|
+
* Plus optional structured metadata that `.full()` exposes.
|
|
15
|
+
*/
|
|
16
|
+
export type AskProduction = {
|
|
17
|
+
text?: string;
|
|
18
|
+
stream?: AsyncIterable<string>;
|
|
19
|
+
meta?: AskMeta;
|
|
20
|
+
};
|
|
21
|
+
export type AskMeta = {
|
|
22
|
+
usage?: {
|
|
23
|
+
promptTokens?: number;
|
|
24
|
+
completionTokens?: number;
|
|
25
|
+
totalTokens?: number;
|
|
26
|
+
};
|
|
27
|
+
finishReason?: string;
|
|
28
|
+
durationMs?: number;
|
|
29
|
+
raw?: unknown;
|
|
30
|
+
trace?: ReadonlyArray<SubagentTraceEntry>;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* The "smart object" returned from `agent.ask(query)`.
|
|
34
|
+
*
|
|
35
|
+
* Consumers can use it as a Promise (`await result` -> string) OR as an
|
|
36
|
+
* AsyncIterable (`for await (const chunk of result)`) OR call any of the
|
|
37
|
+
* terminal methods. Pick exactly one form per Ask instance.
|
|
38
|
+
*
|
|
39
|
+
* Naming convention enforced by the codebase: this object is always
|
|
40
|
+
* named `result` in examples / docs (NEVER abbreviated to `r`).
|
|
41
|
+
*/
|
|
42
|
+
export declare class Ask implements PromiseLike<string>, AsyncIterable<string> {
|
|
43
|
+
private readonly producer;
|
|
44
|
+
/** Cached production — set on first consumption. */
|
|
45
|
+
private produced;
|
|
46
|
+
private producing;
|
|
47
|
+
constructor(producer: AskProducer);
|
|
48
|
+
private produce;
|
|
49
|
+
/** Return the full text. Awaits the entire stream if streaming. */
|
|
50
|
+
text(): Promise<string>;
|
|
51
|
+
/**
|
|
52
|
+
* Return a Web ReadableStream of UTF-8 text chunks.
|
|
53
|
+
*
|
|
54
|
+
* If the underlying producer is non-streaming (text-only), the stream emits
|
|
55
|
+
* the full text once and closes.
|
|
56
|
+
*/
|
|
57
|
+
stream(): Promise<ReadableStream<string>>;
|
|
58
|
+
/** Async-iterate over text chunks. */
|
|
59
|
+
iter(): AsyncGenerator<string, void, void>;
|
|
60
|
+
/** Pipe text chunks into a writable stream and return when finished. */
|
|
61
|
+
pipeTo(writable: WritableStream<string>): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Parse the full text response as JSON and validate against a zod schema.
|
|
64
|
+
* Throws `OutputValidationError` if parsing or validation fails.
|
|
65
|
+
*/
|
|
66
|
+
json<TSchema extends z.ZodTypeAny>(schema: TSchema): Promise<z.infer<TSchema>>;
|
|
67
|
+
/** Return text + metadata (usage, finishReason, raw provider response). */
|
|
68
|
+
full(): Promise<{
|
|
69
|
+
text: string;
|
|
70
|
+
meta: AskMeta;
|
|
71
|
+
}>;
|
|
72
|
+
then<TResolve = string, TReject = never>(onfulfilled?: ((value: string) => TResolve | PromiseLike<TResolve>) | null | undefined, onrejected?: ((reason: unknown) => TReject | PromiseLike<TReject>) | null | undefined): Promise<TResolve | TReject>;
|
|
73
|
+
[Symbol.asyncIterator](): AsyncGenerator<string, void, void>;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=ask.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ask.d.ts","sourceRoot":"","sources":["../src/ask.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAG7B;;;;GAIG;AACH,MAAM,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AC,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAqBpF,2EAA2E;IACrE,IAAI,IAAI,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,OAAO,CAAA;KAAE,CAAC;IAOtD,IAAI,CAAC,QAAQ,GAAG,MAAM,EAAE,OAAO,GAAG,KAAK,EACrC,WAAW,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,EACtF,UAAU,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,GACpF,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC;IAK9B,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,cAAc,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC;CAG7D"}
|
package/dist/ask.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { OutputValidationError } from "./errors";
|
|
2
|
+
/**
|
|
3
|
+
* The "smart object" returned from `agent.ask(query)`.
|
|
4
|
+
*
|
|
5
|
+
* Consumers can use it as a Promise (`await result` -> string) OR as an
|
|
6
|
+
* AsyncIterable (`for await (const chunk of result)`) OR call any of the
|
|
7
|
+
* terminal methods. Pick exactly one form per Ask instance.
|
|
8
|
+
*
|
|
9
|
+
* Naming convention enforced by the codebase: this object is always
|
|
10
|
+
* named `result` in examples / docs (NEVER abbreviated to `r`).
|
|
11
|
+
*/
|
|
12
|
+
export class Ask {
|
|
13
|
+
producer;
|
|
14
|
+
/** Cached production — set on first consumption. */
|
|
15
|
+
produced = null;
|
|
16
|
+
producing = null;
|
|
17
|
+
constructor(producer) {
|
|
18
|
+
this.producer = producer;
|
|
19
|
+
}
|
|
20
|
+
produce() {
|
|
21
|
+
if (this.produced)
|
|
22
|
+
return Promise.resolve(this.produced);
|
|
23
|
+
if (this.producing)
|
|
24
|
+
return this.producing;
|
|
25
|
+
this.producing = this.producer().then((result) => {
|
|
26
|
+
this.produced = result;
|
|
27
|
+
return result;
|
|
28
|
+
});
|
|
29
|
+
return this.producing;
|
|
30
|
+
}
|
|
31
|
+
/** Return the full text. Awaits the entire stream if streaming. */
|
|
32
|
+
async text() {
|
|
33
|
+
const production = await this.produce();
|
|
34
|
+
if (typeof production.text === "string") {
|
|
35
|
+
return production.text;
|
|
36
|
+
}
|
|
37
|
+
if (production.stream) {
|
|
38
|
+
let acc = "";
|
|
39
|
+
for await (const chunk of production.stream) {
|
|
40
|
+
acc += chunk;
|
|
41
|
+
}
|
|
42
|
+
return acc;
|
|
43
|
+
}
|
|
44
|
+
return "";
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Return a Web ReadableStream of UTF-8 text chunks.
|
|
48
|
+
*
|
|
49
|
+
* If the underlying producer is non-streaming (text-only), the stream emits
|
|
50
|
+
* the full text once and closes.
|
|
51
|
+
*/
|
|
52
|
+
async stream() {
|
|
53
|
+
const production = await this.produce();
|
|
54
|
+
if (production.stream) {
|
|
55
|
+
return iterableToStream(production.stream);
|
|
56
|
+
}
|
|
57
|
+
const text = production.text ?? "";
|
|
58
|
+
return new ReadableStream({
|
|
59
|
+
start(controller) {
|
|
60
|
+
if (text.length > 0)
|
|
61
|
+
controller.enqueue(text);
|
|
62
|
+
controller.close();
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/** Async-iterate over text chunks. */
|
|
67
|
+
async *iter() {
|
|
68
|
+
const production = await this.produce();
|
|
69
|
+
if (production.stream) {
|
|
70
|
+
for await (const chunk of production.stream) {
|
|
71
|
+
yield chunk;
|
|
72
|
+
}
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (production.text)
|
|
76
|
+
yield production.text;
|
|
77
|
+
}
|
|
78
|
+
/** Pipe text chunks into a writable stream and return when finished. */
|
|
79
|
+
async pipeTo(writable) {
|
|
80
|
+
const stream = await this.stream();
|
|
81
|
+
await stream.pipeTo(writable);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Parse the full text response as JSON and validate against a zod schema.
|
|
85
|
+
* Throws `OutputValidationError` if parsing or validation fails.
|
|
86
|
+
*/
|
|
87
|
+
async json(schema) {
|
|
88
|
+
const text = await this.text();
|
|
89
|
+
let parsed;
|
|
90
|
+
try {
|
|
91
|
+
parsed = JSON.parse(text);
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
throw new OutputValidationError(`Output is not valid JSON: ${error.message}`, error);
|
|
95
|
+
}
|
|
96
|
+
const result = schema.safeParse(parsed);
|
|
97
|
+
if (!result.success) {
|
|
98
|
+
throw new OutputValidationError(`Output failed schema validation: ${result.error.message}`, result.error);
|
|
99
|
+
}
|
|
100
|
+
return result.data;
|
|
101
|
+
}
|
|
102
|
+
/** Return text + metadata (usage, finishReason, raw provider response). */
|
|
103
|
+
async full() {
|
|
104
|
+
const text = await this.text();
|
|
105
|
+
const production = this.produced ?? (await this.produce());
|
|
106
|
+
return { text, meta: production.meta ?? {} };
|
|
107
|
+
}
|
|
108
|
+
// --- thenable: makes `await result` resolve to a string ---
|
|
109
|
+
then(onfulfilled, onrejected) {
|
|
110
|
+
return this.text().then(onfulfilled, onrejected);
|
|
111
|
+
}
|
|
112
|
+
// --- async iterable: makes `for await (const chunk of result)` work ---
|
|
113
|
+
[Symbol.asyncIterator]() {
|
|
114
|
+
return this.iter();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function iterableToStream(iter) {
|
|
118
|
+
const iterator = iter[Symbol.asyncIterator]();
|
|
119
|
+
return new ReadableStream({
|
|
120
|
+
async pull(controller) {
|
|
121
|
+
try {
|
|
122
|
+
const { value, done } = await iterator.next();
|
|
123
|
+
if (done) {
|
|
124
|
+
controller.close();
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
controller.enqueue(value);
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
controller.error(error);
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
async cancel(reason) {
|
|
134
|
+
if (typeof iterator.return === "function") {
|
|
135
|
+
await iterator.return(reason);
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=ask.js.map
|
package/dist/ask.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ask.js","sourceRoot":"","sources":["../src/ask.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AA8BjD;;;;;;;;;GASG;AACH,MAAM,OAAO,GAAG;IAKe;IAJ7B,oDAAoD;IAC5C,QAAQ,GAAyB,IAAI,CAAC;IACtC,SAAS,GAAkC,IAAI,CAAC;IAExD,YAA6B,QAAqB;QAArB,aAAQ,GAAR,QAAQ,CAAa;IAAG,CAAC;IAE9C,OAAO;QACb,IAAI,IAAI,CAAC,QAAQ;YAAE,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACzD,IAAI,IAAI,CAAC,SAAS;YAAE,OAAO,IAAI,CAAC,SAAS,CAAC;QAC1C,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;YAC/C,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC;YACvB,OAAO,MAAM,CAAC;QAChB,CAAC,CAAC,CAAC;QACH,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED,mEAAmE;IACnE,KAAK,CAAC,IAAI;QACR,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;QACxC,IAAI,OAAO,UAAU,CAAC,IAAI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AAC,MAAM,CAAC,aAAa,CAAC;QACpB,OAAO,IAAI,CAAC,IAAI,EAAE,CAAC;IACrB,CAAC;CACF;AAED,SAAS,gBAAgB,CAAC,IAA2B;IACnD,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC;IAC9C,OAAO,IAAI,cAAc,CAAS;QAChC,KAAK,CAAC,IAAI,CAAC,UAAU;YACnB,IAAI,CAAC;gBACH,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;gBAC9C,IAAI,IAAI,EAAE,CAAC;oBACT,UAAU,CAAC,KAAK,EAAE,CAAC;oBACnB,OAAO;gBACT,CAAC;gBACD,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;YAC5B,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAC1B,CAAC;QACH,CAAC;QACD,KAAK,CAAC,MAAM,CAAC,MAAM;YACjB,IAAI,OAAO,QAAQ,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;gBAC1C,MAAM,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAChC,CAAC;QACH,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { AgentDefinition, AgentLogger, InputsSchema, ProcessorSelection, SubagentSelection } from "@dahura/super-agent-kit";
|
|
2
|
+
import { Ask } from "./ask";
|
|
3
|
+
import { type SingleAudioInput, type SingleFileInput, type SingleImageInput, type SingleTextInput } from "./loaders";
|
|
4
|
+
import type { ResolvedModel } from "./model";
|
|
5
|
+
/**
|
|
6
|
+
* Hook the runtime gives the builder so it can resolve a model when an ask
|
|
7
|
+
* fires. Implemented by the resolver in `./resolver.ts`. Kept abstract here
|
|
8
|
+
* to make the builder unit-testable without spinning up real providers.
|
|
9
|
+
*/
|
|
10
|
+
export type ModelResolver = (input: {
|
|
11
|
+
exportName: string;
|
|
12
|
+
policy: AgentDefinition["model"];
|
|
13
|
+
override?: string;
|
|
14
|
+
}) => Promise<ResolvedModel>;
|
|
15
|
+
/**
|
|
16
|
+
* Options passed to `createAgentClient`. Holds dependencies the builder
|
|
17
|
+
* needs at run time but not at definition time.
|
|
18
|
+
*/
|
|
19
|
+
export type AgentClientOptions = {
|
|
20
|
+
resolver: ModelResolver;
|
|
21
|
+
logger?: AgentLogger;
|
|
22
|
+
/** Override for the resolved model id (typically from .env or UI selector). */
|
|
23
|
+
modelOverride?: string;
|
|
24
|
+
/** Per-run processor selection overrides. */
|
|
25
|
+
processorSelection?: ProcessorSelection;
|
|
26
|
+
/** Per-run subagent selection overrides. */
|
|
27
|
+
subagentSelection?: SubagentSelection;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* The agent client surface that consumer code holds:
|
|
31
|
+
* client.loadAudio(...).loadImage(...).ask(query).text()
|
|
32
|
+
* client.withModel('local/qwen2.5-vl').ask(query).text()
|
|
33
|
+
* client.ask(query).json(schema)
|
|
34
|
+
*
|
|
35
|
+
* Designed to be immutable: every loadXxx / withModel returns a NEW instance.
|
|
36
|
+
*/
|
|
37
|
+
export declare class AgentClient<TInputs extends InputsSchema = InputsSchema> {
|
|
38
|
+
private readonly definition;
|
|
39
|
+
private readonly opts;
|
|
40
|
+
private readonly accumulated;
|
|
41
|
+
constructor(definition: AgentDefinition<TInputs>, opts: AgentClientOptions, accumulated?: AccumulatedInputs);
|
|
42
|
+
loadImage(input: SingleImageInput | ReadonlyArray<SingleImageInput>): AgentClient<TInputs>;
|
|
43
|
+
loadAudio(input: SingleAudioInput | ReadonlyArray<SingleAudioInput>): AgentClient<TInputs>;
|
|
44
|
+
loadText(input: SingleTextInput | ReadonlyArray<SingleTextInput>): AgentClient<TInputs>;
|
|
45
|
+
loadFile(input: SingleFileInput | ReadonlyArray<SingleFileInput>): AgentClient<TInputs>;
|
|
46
|
+
/**
|
|
47
|
+
* Override the model for this and downstream calls without mutating the
|
|
48
|
+
* agent definition. Useful for the Playground UI selector and for
|
|
49
|
+
* per-call overrides like `agent.withModel('local/qwen2.5-vl').ask(q)`.
|
|
50
|
+
*/
|
|
51
|
+
withModel(modelId: string): AgentClient<TInputs>;
|
|
52
|
+
/**
|
|
53
|
+
* Override which processors are active for this and downstream calls without
|
|
54
|
+
* mutating the underlying client.
|
|
55
|
+
*/
|
|
56
|
+
withProcessors(selection: ProcessorSelection): AgentClient<TInputs>;
|
|
57
|
+
/**
|
|
58
|
+
* Override which subagents are active for this and downstream calls without
|
|
59
|
+
* mutating the underlying client.
|
|
60
|
+
*/
|
|
61
|
+
withSubagents(selection: SubagentSelection): AgentClient<TInputs>;
|
|
62
|
+
/** Fire the ask and return the smart Ask result. */
|
|
63
|
+
ask(query: string): Ask;
|
|
64
|
+
private cloneWithLoader;
|
|
65
|
+
}
|
|
66
|
+
type AccumulatedInputs = {
|
|
67
|
+
image: SingleImageInput[];
|
|
68
|
+
audio: SingleAudioInput[];
|
|
69
|
+
text: SingleTextInput[];
|
|
70
|
+
file: SingleFileInput[];
|
|
71
|
+
};
|
|
72
|
+
export {};
|
|
73
|
+
//# sourceMappingURL=builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,WAAW,EAGX,YAAY,EAEZ,kBAAkB,EAElB,iBAAiB,EAIlB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,GAAG,EAAsB,MAAM,OAAO,CAAC;AAEhD,OAAO,EAML,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACrB,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C;;;;GAIG;AACH,MAAM,M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