@smooai/smooth-operator-core 0.1.1 → 0.9.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/package.json +7 -2
- package/dist/agent.d.ts +0 -276
- package/dist/agent.d.ts.map +0 -1
- package/dist/agent.js +0 -450
- package/dist/agent.js.map +0 -1
- package/dist/cast.d.ts +0 -81
- package/dist/cast.d.ts.map +0 -1
- package/dist/cast.js +0 -103
- package/dist/cast.js.map +0 -1
- package/dist/checkpoint.d.ts +0 -25
- package/dist/checkpoint.d.ts.map +0 -1
- package/dist/checkpoint.js +0 -23
- package/dist/checkpoint.js.map +0 -1
- package/dist/compaction.d.ts +0 -21
- package/dist/compaction.d.ts.map +0 -1
- package/dist/compaction.js +0 -50
- package/dist/compaction.js.map +0 -1
- package/dist/cost.d.ts +0 -34
- package/dist/cost.d.ts.map +0 -1
- package/dist/cost.js +0 -42
- package/dist/cost.js.map +0 -1
- package/dist/humanGate.d.ts +0 -44
- package/dist/humanGate.d.ts.map +0 -1
- package/dist/humanGate.js +0 -30
- package/dist/humanGate.js.map +0 -1
- package/dist/index.d.ts +0 -32
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -21
- package/dist/index.js.map +0 -1
- package/dist/knowledge.d.ts +0 -30
- package/dist/knowledge.d.ts.map +0 -1
- package/dist/knowledge.js +0 -43
- package/dist/knowledge.js.map +0 -1
- package/dist/llmProvider.d.ts +0 -106
- package/dist/llmProvider.d.ts.map +0 -1
- package/dist/llmProvider.js +0 -160
- package/dist/llmProvider.js.map +0 -1
- package/dist/memory.d.ts +0 -23
- package/dist/memory.d.ts.map +0 -1
- package/dist/memory.js +0 -40
- package/dist/memory.js.map +0 -1
- package/dist/rerank.d.ts +0 -27
- package/dist/rerank.d.ts.map +0 -1
- package/dist/rerank.js +0 -45
- package/dist/rerank.js.map +0 -1
- package/dist/thread.d.ts +0 -43
- package/dist/thread.d.ts.map +0 -1
- package/dist/thread.js +0 -60
- package/dist/thread.js.map +0 -1
- package/dist/toolSearch.d.ts +0 -55
- package/dist/toolSearch.d.ts.map +0 -1
- package/dist/toolSearch.js +0 -110
- package/dist/toolSearch.js.map +0 -1
- package/dist/vector.d.ts +0 -36
- package/dist/vector.d.ts.map +0 -1
- package/dist/vector.js +0 -75
- package/dist/vector.js.map +0 -1
- package/dist/workflow.d.ts +0 -62
- package/dist/workflow.d.ts.map +0 -1
- package/dist/workflow.js +0 -109
- package/dist/workflow.js.map +0 -1
package/dist/llmProvider.d.ts
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* An `LlmProvider` seam over the LLM call so the agentic loop can be unit-tested
|
|
3
|
-
* deterministically, without a live model or network.
|
|
4
|
-
*
|
|
5
|
-
* The agent already takes an injected OpenAI-compatible chat client
|
|
6
|
-
* ({@link ChatClientLike}). This module *formalizes* that as the provider seam —
|
|
7
|
-
* `LlmProvider` is an alias of `ChatClientLike`, so the existing `SmoothAgent`
|
|
8
|
-
* constructor is unchanged and backward compatible (the real `openai` SDK still
|
|
9
|
-
* satisfies it).
|
|
10
|
-
*
|
|
11
|
-
* It also ships a reusable, exported {@link MockLlmProvider} that replaces the
|
|
12
|
-
* ad-hoc fake clients the tests rolled by hand. The mock:
|
|
13
|
-
*
|
|
14
|
-
* - is constructed with a script of responses — plain text, tool-call responses,
|
|
15
|
-
* and errors;
|
|
16
|
-
* - returns them in FIFO order across calls;
|
|
17
|
-
* - records each request (the messages + tool specs it was given) so a test can
|
|
18
|
-
* assert on what the agent sent.
|
|
19
|
-
*
|
|
20
|
-
* This mirrors the BEHAVIOR of the Rust reference's `MockLlmClient`
|
|
21
|
-
* (`rust/smooth-operator-core/src/llm_provider.rs`). The mock implements both the
|
|
22
|
-
* non-streaming `create` seam (used by {@link SmoothAgent.run}) and the streaming
|
|
23
|
-
* `createStream` seam (used by {@link SmoothAgent.runStream}): it replays the SAME
|
|
24
|
-
* FIFO script as chunked deltas — text split into a few pieces, tool-call
|
|
25
|
-
* `arguments` split across two chunks to exercise the accumulator, and a final
|
|
26
|
-
* chunk carrying usage. Structured-output lands when that feature lands here.
|
|
27
|
-
*/
|
|
28
|
-
import type { ChatChunk, ChatClientLike } from './agent.js';
|
|
29
|
-
/** The LLM call surface the agent loop depends on. Identical to {@link ChatClientLike}. */
|
|
30
|
-
export type LlmProvider = ChatClientLike;
|
|
31
|
-
/** An OpenAI-shaped assistant message — the `choices[0].message` the agent reads. */
|
|
32
|
-
export interface ScriptedMessage {
|
|
33
|
-
content: string | null;
|
|
34
|
-
tool_calls?: Array<{
|
|
35
|
-
id: string;
|
|
36
|
-
function: {
|
|
37
|
-
name: string;
|
|
38
|
-
arguments: string;
|
|
39
|
-
};
|
|
40
|
-
}> | null;
|
|
41
|
-
}
|
|
42
|
-
/** Build a plain-text scripted response (no tool calls). */
|
|
43
|
-
export declare function textResponse(content: string): ScriptedMessage;
|
|
44
|
-
/** Build a scripted response that requests a single tool call. */
|
|
45
|
-
export declare function toolCallResponse(id: string, name: string, args: string): ScriptedMessage;
|
|
46
|
-
/** One request the mock received, captured for assertions. */
|
|
47
|
-
export interface RecordedCall {
|
|
48
|
-
/** The full request body passed to `chat.completions.create`. */
|
|
49
|
-
body: Record<string, unknown>;
|
|
50
|
-
/** The messages passed on this call. */
|
|
51
|
-
messages: Array<Record<string, unknown>>;
|
|
52
|
-
/** The tool specs offered to the model, if any. */
|
|
53
|
-
tools?: Array<Record<string, unknown>>;
|
|
54
|
-
}
|
|
55
|
-
/** Optional token usage to attach to a scripted response (the model/gateway reports it). */
|
|
56
|
-
export interface ScriptedUsage {
|
|
57
|
-
prompt_tokens?: number;
|
|
58
|
-
completion_tokens?: number;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* A deterministic {@link LlmProvider} for tests. Script the responses it should
|
|
62
|
-
* return (FIFO), drive your code, then assert on {@link MockLlmProvider.calls}.
|
|
63
|
-
*
|
|
64
|
-
* Construct empty and build up fluently (`pushText` / `pushToolCall` / `pushError`),
|
|
65
|
-
* or pass an initial script of {@link ScriptedMessage}s.
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* const mock = new MockLlmProvider();
|
|
69
|
-
* mock.pushText('hello there');
|
|
70
|
-
* const agent = new SmoothAgent(mock, {});
|
|
71
|
-
* const result = await agent.run('hi');
|
|
72
|
-
* expect(result.text).toBe('hello there');
|
|
73
|
-
* expect(mock.callCount).toBe(1);
|
|
74
|
-
*/
|
|
75
|
-
export declare class MockLlmProvider implements ChatClientLike {
|
|
76
|
-
private readonly script;
|
|
77
|
-
private readonly recorded;
|
|
78
|
-
constructor(script?: ScriptedMessage[]);
|
|
79
|
-
/** Queue a raw OpenAI-shaped assistant message (with optional usage) for the next call. */
|
|
80
|
-
pushResponse(message: ScriptedMessage, usage?: ScriptedUsage): this;
|
|
81
|
-
/** Queue a plain-text response (with optional usage) for the next call. */
|
|
82
|
-
pushText(content: string, usage?: ScriptedUsage): this;
|
|
83
|
-
/** Queue a single-tool-call response (with optional usage) for the next call. */
|
|
84
|
-
pushToolCall(id: string, name: string, args: string, usage?: ScriptedUsage): this;
|
|
85
|
-
/** Queue an error to be thrown on the next call. */
|
|
86
|
-
pushError(message: string): this;
|
|
87
|
-
/** Every request the mock has received so far, in order. */
|
|
88
|
-
get calls(): readonly RecordedCall[];
|
|
89
|
-
/** Number of requests received. */
|
|
90
|
-
get callCount(): number;
|
|
91
|
-
/** The most recent request, if any. */
|
|
92
|
-
get lastCall(): RecordedCall | undefined;
|
|
93
|
-
private record;
|
|
94
|
-
readonly chat: {
|
|
95
|
-
completions: {
|
|
96
|
-
create: (body: Record<string, unknown>) => Promise<{
|
|
97
|
-
choices: {
|
|
98
|
-
message: ScriptedMessage;
|
|
99
|
-
}[];
|
|
100
|
-
usage: ScriptedUsage | null;
|
|
101
|
-
}>;
|
|
102
|
-
createStream: (body: Record<string, unknown>) => AsyncIterable<ChatChunk>;
|
|
103
|
-
};
|
|
104
|
-
};
|
|
105
|
-
}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B;AAKD;;;;;;;;;;;;;;GAcG;AACH,qBAAa,eAAgB,YAAW,cAAc;IAClD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAiB;IACxC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAsB;gBAEnC,MAAM,GAAE,eAAe,EAAO;IAM1C,2FAA2F;IAC3F,YAAY,CAAC,OAAO,EAAE,eAAe,EAAE,KAAK,CAAC,EAAE,aAAa,GAAG,IAAI;IAKnE,2EAA2E;IAC3E,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,aAAa,GAAG,IAAI;IAItD,iFAAiF;IACjF,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,aAAa,GAAG,IAAI;IAIjF,oDAAoD;IACpD,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAOhC,4DAA4D;IAC5D,IAAI,KAAK,IAAI,SAAS,YAAY,EAAE,CAEnC;IAED,mCAAmC;IACnC,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED,uCAAuC;IACvC,IAAI,QAAQ,IAAI,YAAY,GAAG,SAAS,CAEvC;IAID,OAAO,CAAC,MAAM;IAQd,QAAQ,CAAC,IAAI;;2BAEgB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;;;;iCAcvB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAG,aAAa,CAAC,SAAS,CAAC;;MAiC7E;CACL"}
|
package/dist/llmProvider.js
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* An `LlmProvider` seam over the LLM call so the agentic loop can be unit-tested
|
|
3
|
-
* deterministically, without a live model or network.
|
|
4
|
-
*
|
|
5
|
-
* The agent already takes an injected OpenAI-compatible chat client
|
|
6
|
-
* ({@link ChatClientLike}). This module *formalizes* that as the provider seam —
|
|
7
|
-
* `LlmProvider` is an alias of `ChatClientLike`, so the existing `SmoothAgent`
|
|
8
|
-
* constructor is unchanged and backward compatible (the real `openai` SDK still
|
|
9
|
-
* satisfies it).
|
|
10
|
-
*
|
|
11
|
-
* It also ships a reusable, exported {@link MockLlmProvider} that replaces the
|
|
12
|
-
* ad-hoc fake clients the tests rolled by hand. The mock:
|
|
13
|
-
*
|
|
14
|
-
* - is constructed with a script of responses — plain text, tool-call responses,
|
|
15
|
-
* and errors;
|
|
16
|
-
* - returns them in FIFO order across calls;
|
|
17
|
-
* - records each request (the messages + tool specs it was given) so a test can
|
|
18
|
-
* assert on what the agent sent.
|
|
19
|
-
*
|
|
20
|
-
* This mirrors the BEHAVIOR of the Rust reference's `MockLlmClient`
|
|
21
|
-
* (`rust/smooth-operator-core/src/llm_provider.rs`). The mock implements both the
|
|
22
|
-
* non-streaming `create` seam (used by {@link SmoothAgent.run}) and the streaming
|
|
23
|
-
* `createStream` seam (used by {@link SmoothAgent.runStream}): it replays the SAME
|
|
24
|
-
* FIFO script as chunked deltas — text split into a few pieces, tool-call
|
|
25
|
-
* `arguments` split across two chunks to exercise the accumulator, and a final
|
|
26
|
-
* chunk carrying usage. Structured-output lands when that feature lands here.
|
|
27
|
-
*/
|
|
28
|
-
/** Build a plain-text scripted response (no tool calls). */
|
|
29
|
-
export function textResponse(content) {
|
|
30
|
-
return { content };
|
|
31
|
-
}
|
|
32
|
-
/** Build a scripted response that requests a single tool call. */
|
|
33
|
-
export function toolCallResponse(id, name, args) {
|
|
34
|
-
return { content: null, tool_calls: [{ id, function: { name, arguments: args } }] };
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* A deterministic {@link LlmProvider} for tests. Script the responses it should
|
|
38
|
-
* return (FIFO), drive your code, then assert on {@link MockLlmProvider.calls}.
|
|
39
|
-
*
|
|
40
|
-
* Construct empty and build up fluently (`pushText` / `pushToolCall` / `pushError`),
|
|
41
|
-
* or pass an initial script of {@link ScriptedMessage}s.
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* const mock = new MockLlmProvider();
|
|
45
|
-
* mock.pushText('hello there');
|
|
46
|
-
* const agent = new SmoothAgent(mock, {});
|
|
47
|
-
* const result = await agent.run('hi');
|
|
48
|
-
* expect(result.text).toBe('hello there');
|
|
49
|
-
* expect(mock.callCount).toBe(1);
|
|
50
|
-
*/
|
|
51
|
-
export class MockLlmProvider {
|
|
52
|
-
script = [];
|
|
53
|
-
recorded = [];
|
|
54
|
-
constructor(script = []) {
|
|
55
|
-
this.script = script.map((message) => ({ kind: 'message', message }));
|
|
56
|
-
}
|
|
57
|
-
// ── scripting (fluent: each returns this) ────────────────────────────────
|
|
58
|
-
/** Queue a raw OpenAI-shaped assistant message (with optional usage) for the next call. */
|
|
59
|
-
pushResponse(message, usage) {
|
|
60
|
-
this.script.push({ kind: 'message', message, usage });
|
|
61
|
-
return this;
|
|
62
|
-
}
|
|
63
|
-
/** Queue a plain-text response (with optional usage) for the next call. */
|
|
64
|
-
pushText(content, usage) {
|
|
65
|
-
return this.pushResponse(textResponse(content), usage);
|
|
66
|
-
}
|
|
67
|
-
/** Queue a single-tool-call response (with optional usage) for the next call. */
|
|
68
|
-
pushToolCall(id, name, args, usage) {
|
|
69
|
-
return this.pushResponse(toolCallResponse(id, name, args), usage);
|
|
70
|
-
}
|
|
71
|
-
/** Queue an error to be thrown on the next call. */
|
|
72
|
-
pushError(message) {
|
|
73
|
-
this.script.push({ kind: 'error', message });
|
|
74
|
-
return this;
|
|
75
|
-
}
|
|
76
|
-
// ── recordings ───────────────────────────────────────────────────────────
|
|
77
|
-
/** Every request the mock has received so far, in order. */
|
|
78
|
-
get calls() {
|
|
79
|
-
return this.recorded;
|
|
80
|
-
}
|
|
81
|
-
/** Number of requests received. */
|
|
82
|
-
get callCount() {
|
|
83
|
-
return this.recorded.length;
|
|
84
|
-
}
|
|
85
|
-
/** The most recent request, if any. */
|
|
86
|
-
get lastCall() {
|
|
87
|
-
return this.recorded[this.recorded.length - 1];
|
|
88
|
-
}
|
|
89
|
-
// ── the ChatClientLike surface ───────────────────────────────────────────
|
|
90
|
-
record(body) {
|
|
91
|
-
this.recorded.push({
|
|
92
|
-
body,
|
|
93
|
-
messages: body.messages ?? [],
|
|
94
|
-
tools: body.tools,
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
chat = {
|
|
98
|
-
completions: {
|
|
99
|
-
create: async (body) => {
|
|
100
|
-
this.record(body);
|
|
101
|
-
const outcome = this.script.shift();
|
|
102
|
-
if (outcome?.kind === 'error')
|
|
103
|
-
throw new Error(outcome.message);
|
|
104
|
-
// Empty script: a benign terminal text response so loops don't hang.
|
|
105
|
-
const message = outcome?.message ?? { content: '' };
|
|
106
|
-
const usage = outcome?.kind === 'message' ? outcome.usage : undefined;
|
|
107
|
-
return { choices: [{ message }], usage: usage ?? null };
|
|
108
|
-
},
|
|
109
|
-
// Streaming seam: replays the SAME FIFO script as chunked deltas. Text is
|
|
110
|
-
// split into a few pieces (so consumers see multiple `text` events); a
|
|
111
|
-
// tool call's `arguments` is split across two chunks (so the agent's
|
|
112
|
-
// accumulator is exercised); a final empty-delta chunk carries usage.
|
|
113
|
-
createStream: (body) => {
|
|
114
|
-
this.record(body);
|
|
115
|
-
const outcome = this.script.shift();
|
|
116
|
-
const message = outcome?.kind === 'message' ? outcome.message : { content: '' };
|
|
117
|
-
const usage = outcome?.kind === 'message' ? outcome.usage : undefined;
|
|
118
|
-
const error = outcome?.kind === 'error' ? outcome.message : undefined;
|
|
119
|
-
async function* gen() {
|
|
120
|
-
if (error)
|
|
121
|
-
throw new Error(error);
|
|
122
|
-
// Text content → 2-3 deltas.
|
|
123
|
-
const content = message.content ?? '';
|
|
124
|
-
for (const piece of splitIntoChunks(content, 3)) {
|
|
125
|
-
if (piece)
|
|
126
|
-
yield { choices: [{ delta: { content: piece } }] };
|
|
127
|
-
}
|
|
128
|
-
// Tool calls → opening chunk (id + name + first arg half), then a
|
|
129
|
-
// second chunk with the rest of the arguments. Exercises the
|
|
130
|
-
// index-keyed accumulator on the agent side.
|
|
131
|
-
for (const [index, tc] of (message.tool_calls ?? []).entries()) {
|
|
132
|
-
const args = tc.function.arguments ?? '';
|
|
133
|
-
const mid = Math.floor(args.length / 2);
|
|
134
|
-
yield {
|
|
135
|
-
choices: [{ delta: { tool_calls: [{ index, id: tc.id, function: { name: tc.function.name, arguments: args.slice(0, mid) } }] } }],
|
|
136
|
-
};
|
|
137
|
-
yield {
|
|
138
|
-
choices: [{ delta: { tool_calls: [{ index, function: { arguments: args.slice(mid) } }] } }],
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
// Final chunk carries usage (gateways send it on the last chunk).
|
|
142
|
-
yield { choices: [{ delta: {} }], usage: usage ? { prompt_tokens: usage.prompt_tokens ?? 0, completion_tokens: usage.completion_tokens ?? 0 } : null };
|
|
143
|
-
}
|
|
144
|
-
return gen();
|
|
145
|
-
},
|
|
146
|
-
},
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
/** Split `s` into up to `n` roughly-equal non-empty pieces (≥2 when long enough). */
|
|
150
|
-
function splitIntoChunks(s, n) {
|
|
151
|
-
if (s.length === 0)
|
|
152
|
-
return [];
|
|
153
|
-
const parts = Math.min(n, Math.max(1, s.length));
|
|
154
|
-
const size = Math.ceil(s.length / parts);
|
|
155
|
-
const out = [];
|
|
156
|
-
for (let i = 0; i < s.length; i += size)
|
|
157
|
-
out.push(s.slice(i, i + size));
|
|
158
|
-
return out;
|
|
159
|
-
}
|
|
160
|
-
//# sourceMappingURL=llmProvider.js.map
|
package/dist/llmProvider.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"llmProvider.js","sourceRoot":"","sources":["../src/llmProvider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAaH,4DAA4D;AAC5D,MAAM,UAAU,YAAY,CAAC,OAAe;IACxC,OAAO,EAAE,OAAO,EAAE,CAAC;AACvB,CAAC;AAED,kEAAkE;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C,CAAC,MAAM,CAAC,CAAC,CAAC;IACjD,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,GAAG,KAAK,CAAC,CAAC;IACzC,MAAM,GAAG,GAAa,EAAE,CAAC;IACzB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,IAAI;QAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;IACxE,OAAO,GAAG,CAAC;AACf,CAAC"}
|
package/dist/memory.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Long-term memory — facts the agent carries across conversations.
|
|
3
|
-
*
|
|
4
|
-
* Phase-1 sibling of the reference engines' memory. Distinct from checkpointing
|
|
5
|
-
* (which persists a single conversation's messages): `Memory` is a durable pool of
|
|
6
|
-
* standalone facts the agent recalls into context on any turn, keyed by relevance
|
|
7
|
-
* to the current message. `InMemoryMemory` is the zero-dependency default (lexical
|
|
8
|
-
* recall); a vector-backed memory drops in behind the interface.
|
|
9
|
-
*/
|
|
10
|
-
export interface MemoryEntry {
|
|
11
|
-
text: string;
|
|
12
|
-
}
|
|
13
|
-
export interface Memory {
|
|
14
|
-
remember(text: string): void;
|
|
15
|
-
recall(query: string, topK?: number): MemoryEntry[];
|
|
16
|
-
}
|
|
17
|
-
/** A process-local memory pool with lexical-overlap recall. */
|
|
18
|
-
export declare class InMemoryMemory implements Memory {
|
|
19
|
-
private readonly entries;
|
|
20
|
-
remember(text: string): void;
|
|
21
|
-
recall(query: string, topK?: number): MemoryEntry[];
|
|
22
|
-
}
|
|
23
|
-
//# sourceMappingURL=memory.d.ts.map
|
package/dist/memory.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH,MAAM,WAAW,WAAW;IACxB,IAAI,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,MAAM;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,WAAW,EAAE,CAAC;CACvD;AAED,+DAA+D;AAC/D,qBAAa,cAAe,YAAW,MAAM;IACzC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;IAE7C,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAK5B,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,SAAI,GAAG,WAAW,EAAE;CAejD"}
|
package/dist/memory.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Long-term memory — facts the agent carries across conversations.
|
|
3
|
-
*
|
|
4
|
-
* Phase-1 sibling of the reference engines' memory. Distinct from checkpointing
|
|
5
|
-
* (which persists a single conversation's messages): `Memory` is a durable pool of
|
|
6
|
-
* standalone facts the agent recalls into context on any turn, keyed by relevance
|
|
7
|
-
* to the current message. `InMemoryMemory` is the zero-dependency default (lexical
|
|
8
|
-
* recall); a vector-backed memory drops in behind the interface.
|
|
9
|
-
*/
|
|
10
|
-
function tokens(text) {
|
|
11
|
-
return text.toLowerCase().match(/[a-z0-9]+/g) ?? [];
|
|
12
|
-
}
|
|
13
|
-
/** A process-local memory pool with lexical-overlap recall. */
|
|
14
|
-
export class InMemoryMemory {
|
|
15
|
-
entries = [];
|
|
16
|
-
remember(text) {
|
|
17
|
-
const t = text.trim();
|
|
18
|
-
if (t)
|
|
19
|
-
this.entries.push({ text: t });
|
|
20
|
-
}
|
|
21
|
-
recall(query, topK = 4) {
|
|
22
|
-
if (topK <= 0)
|
|
23
|
-
return [];
|
|
24
|
-
const qTerms = new Set(tokens(query));
|
|
25
|
-
return this.entries
|
|
26
|
-
.map((e, i) => {
|
|
27
|
-
const docTerms = new Set(tokens(e.text));
|
|
28
|
-
let overlap = 0;
|
|
29
|
-
for (const t of qTerms)
|
|
30
|
-
if (docTerms.has(t))
|
|
31
|
-
overlap++;
|
|
32
|
-
return { e, i, overlap };
|
|
33
|
-
})
|
|
34
|
-
.filter((x) => x.overlap > 0)
|
|
35
|
-
.sort((a, b) => b.overlap - a.overlap || a.i - b.i)
|
|
36
|
-
.slice(0, topK)
|
|
37
|
-
.map((x) => x.e);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
//# sourceMappingURL=memory.js.map
|
package/dist/memory.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"memory.js","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,SAAS,MAAM,CAAC,IAAY;IACxB,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;AACxD,CAAC;AAWD,+DAA+D;AAC/D,MAAM,OAAO,cAAc;IACN,OAAO,GAAkB,EAAE,CAAC;IAE7C,QAAQ,CAAC,IAAY;QACjB,MAAM,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QACtB,IAAI,CAAC;YAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC;IAC1C,CAAC;IAED,MAAM,CAAC,KAAa,EAAE,IAAI,GAAG,CAAC;QAC1B,IAAI,IAAI,IAAI,CAAC;YAAE,OAAO,EAAE,CAAC;QACzB,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QACtC,OAAO,IAAI,CAAC,OAAO;aACd,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;YACV,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;YACzC,IAAI,OAAO,GAAG,CAAC,CAAC;YAChB,KAAK,MAAM,CAAC,IAAI,MAAM;gBAAE,IAAI,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;oBAAE,OAAO,EAAE,CAAC;YACvD,OAAO,EAAE,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC;QAC7B,CAAC,CAAC;aACD,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC;aAC5B,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;aAClD,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC;aACd,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACzB,CAAC;CACJ"}
|
package/dist/rerank.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Knowledge reranking — reorder retrieved documents by relevance.
|
|
3
|
-
*
|
|
4
|
-
* Phase-1 sibling of the reference engines' reranking. A `Reranker` takes the
|
|
5
|
-
* query and the retriever's candidate hits and returns them reordered (and
|
|
6
|
-
* possibly trimmed). `NoopReranker` is the default passthrough; `LexicalReranker`
|
|
7
|
-
* re-scores by query-term coverage normalized for document length, so a concise
|
|
8
|
-
* on-topic doc outranks a long one with the same raw overlap. A cross-encoder or
|
|
9
|
-
* gateway reranker drops in behind the same interface.
|
|
10
|
-
*/
|
|
11
|
-
import type { KnowledgeHit } from './knowledge.js';
|
|
12
|
-
export interface Reranker {
|
|
13
|
-
rerank(query: string, hits: KnowledgeHit[]): KnowledgeHit[];
|
|
14
|
-
}
|
|
15
|
-
/** Returns the hits unchanged — the zero-cost default. */
|
|
16
|
-
export declare class NoopReranker implements Reranker {
|
|
17
|
-
rerank(_query: string, hits: KnowledgeHit[]): KnowledgeHit[];
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Reorders by query-term coverage normalized by document length:
|
|
21
|
-
* `coverage / log2(2 + docTokenCount)`, so coverage is rewarded but long docs are
|
|
22
|
-
* penalized relative to concise ones with the same coverage. Stable for ties.
|
|
23
|
-
*/
|
|
24
|
-
export declare class LexicalReranker implements Reranker {
|
|
25
|
-
rerank(query: string, hits: KnowledgeHit[]): KnowledgeHit[];
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=rerank.d.ts.map
|
package/dist/rerank.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rerank.d.ts","sourceRoot":"","sources":["../src/rerank.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAMnD,MAAM,WAAW,QAAQ;IACrB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,YAAY,EAAE,CAAC;CAC/D;AAED,0DAA0D;AAC1D,qBAAa,YAAa,YAAW,QAAQ;IACzC,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,YAAY,EAAE;CAG/D;AAED;;;;GAIG;AACH,qBAAa,eAAgB,YAAW,QAAQ;IAC5C,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,YAAY,EAAE;CAiB9D"}
|
package/dist/rerank.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Knowledge reranking — reorder retrieved documents by relevance.
|
|
3
|
-
*
|
|
4
|
-
* Phase-1 sibling of the reference engines' reranking. A `Reranker` takes the
|
|
5
|
-
* query and the retriever's candidate hits and returns them reordered (and
|
|
6
|
-
* possibly trimmed). `NoopReranker` is the default passthrough; `LexicalReranker`
|
|
7
|
-
* re-scores by query-term coverage normalized for document length, so a concise
|
|
8
|
-
* on-topic doc outranks a long one with the same raw overlap. A cross-encoder or
|
|
9
|
-
* gateway reranker drops in behind the same interface.
|
|
10
|
-
*/
|
|
11
|
-
function tokens(text) {
|
|
12
|
-
return text.toLowerCase().match(/[a-z0-9]+/g) ?? [];
|
|
13
|
-
}
|
|
14
|
-
/** Returns the hits unchanged — the zero-cost default. */
|
|
15
|
-
export class NoopReranker {
|
|
16
|
-
rerank(_query, hits) {
|
|
17
|
-
return hits;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Reorders by query-term coverage normalized by document length:
|
|
22
|
-
* `coverage / log2(2 + docTokenCount)`, so coverage is rewarded but long docs are
|
|
23
|
-
* penalized relative to concise ones with the same coverage. Stable for ties.
|
|
24
|
-
*/
|
|
25
|
-
export class LexicalReranker {
|
|
26
|
-
rerank(query, hits) {
|
|
27
|
-
const qTerms = new Set(tokens(query));
|
|
28
|
-
if (qTerms.size === 0)
|
|
29
|
-
return hits;
|
|
30
|
-
const score = (hit) => {
|
|
31
|
-
const docTokens = tokens(hit.content);
|
|
32
|
-
let coverage = 0;
|
|
33
|
-
for (const t of new Set(docTokens))
|
|
34
|
-
if (qTerms.has(t))
|
|
35
|
-
coverage++;
|
|
36
|
-
return coverage / Math.log2(2 + docTokens.length);
|
|
37
|
-
};
|
|
38
|
-
// Stable sort by descending score (decorate with index to preserve ties).
|
|
39
|
-
return hits
|
|
40
|
-
.map((hit, i) => ({ hit, i, s: score(hit) }))
|
|
41
|
-
.sort((a, b) => b.s - a.s || a.i - b.i)
|
|
42
|
-
.map((x) => x.hit);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
//# sourceMappingURL=rerank.js.map
|
package/dist/rerank.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rerank.js","sourceRoot":"","sources":["../src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AAC,CAAC,CAAC;aACtC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;CACJ"}
|
package/dist/thread.d.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Conversation threads — carry message history across `SmoothAgent.run` calls.
|
|
3
|
-
*
|
|
4
|
-
* Phase-2 sibling of the C# `SmoothAgentThread` (`dotnet/core`) and the reference
|
|
5
|
-
* engine's persisted `Conversation`. A {@link SmoothAgentThread} is the in-memory
|
|
6
|
-
* handle you hold per user conversation and pass to each run: the agent seeds the
|
|
7
|
-
* turn from the thread's messages, runs, and appends this turn's user/assistant/tool
|
|
8
|
-
* messages back to it, so the next turn has the full context. The system prompt is
|
|
9
|
-
* supplied per-run from instructions/knowledge/memory and is *never* stored here.
|
|
10
|
-
*
|
|
11
|
-
* This complements checkpointing (`./checkpoint.ts`): a checkpoint *persists* a
|
|
12
|
-
* conversation to a store keyed by id; a thread is the live in-memory object you
|
|
13
|
-
* pass between runs. The thread's {@link SmoothAgentThread.id} is the natural key
|
|
14
|
-
* to checkpoint under.
|
|
15
|
-
*/
|
|
16
|
-
type Message = Record<string, unknown>;
|
|
17
|
-
/**
|
|
18
|
-
* A conversation thread: a stable id plus the ordered non-system messages so far.
|
|
19
|
-
*
|
|
20
|
-
* Construct fresh (a new id is generated) or pass an `id` to resume one (e.g. a key
|
|
21
|
-
* recovered from a checkpoint):
|
|
22
|
-
*
|
|
23
|
-
* ```ts
|
|
24
|
-
* const thread = new SmoothAgentThread(); // fresh conversation
|
|
25
|
-
* const resumed = new SmoothAgentThread('conv-42'); // resume by id
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
export declare class SmoothAgentThread {
|
|
29
|
-
readonly id: string;
|
|
30
|
-
/** Ordered history, oldest first, never including a system message. */
|
|
31
|
-
private readonly _messages;
|
|
32
|
-
constructor(id?: string, messages?: Message[]);
|
|
33
|
-
/** The accumulated history, oldest first (no system prompt). */
|
|
34
|
-
get messages(): readonly Message[];
|
|
35
|
-
/** Number of messages currently in the thread. */
|
|
36
|
-
get length(): number;
|
|
37
|
-
/** Append one message, skipping any system message (rebuilt per-run). */
|
|
38
|
-
add(message: Message): void;
|
|
39
|
-
/** Append several messages, skipping any system messages. */
|
|
40
|
-
extend(messages: readonly Message[]): void;
|
|
41
|
-
}
|
|
42
|
-
export {};
|
|
43
|
-
//# sourceMappingURL=thread.d.ts.map
|
package/dist/thread.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"thread.d.ts","sourceRoot":"","sources":["../src/thread.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,KAAK,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAOvC;;;;;;;;;;GAUG;AACH,qBAAa,iBAAiB;IAC1B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,uEAAuE;IACvE,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAiB;gBAE/B,EAAE,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,OAAO,EAAE;IAK7C,gEAAgE;IAChE,IAAI,QAAQ,IAAI,SAAS,OAAO,EAAE,CAEjC;IAED,kDAAkD;IAClD,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,yEAAyE;IACzE,GAAG,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAK3B,6DAA6D;IAC7D,MAAM,CAAC,QAAQ,EAAE,SAAS,OAAO,EAAE,GAAG,IAAI;CAG7C"}
|
package/dist/thread.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Conversation threads — carry message history across `SmoothAgent.run` calls.
|
|
3
|
-
*
|
|
4
|
-
* Phase-2 sibling of the C# `SmoothAgentThread` (`dotnet/core`) and the reference
|
|
5
|
-
* engine's persisted `Conversation`. A {@link SmoothAgentThread} is the in-memory
|
|
6
|
-
* handle you hold per user conversation and pass to each run: the agent seeds the
|
|
7
|
-
* turn from the thread's messages, runs, and appends this turn's user/assistant/tool
|
|
8
|
-
* messages back to it, so the next turn has the full context. The system prompt is
|
|
9
|
-
* supplied per-run from instructions/knowledge/memory and is *never* stored here.
|
|
10
|
-
*
|
|
11
|
-
* This complements checkpointing (`./checkpoint.ts`): a checkpoint *persists* a
|
|
12
|
-
* conversation to a store keyed by id; a thread is the live in-memory object you
|
|
13
|
-
* pass between runs. The thread's {@link SmoothAgentThread.id} is the natural key
|
|
14
|
-
* to checkpoint under.
|
|
15
|
-
*/
|
|
16
|
-
/** Generate a random hex id (crypto.randomUUID without the dashes). */
|
|
17
|
-
function newThreadId() {
|
|
18
|
-
return globalThis.crypto.randomUUID().replace(/-/g, '');
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* A conversation thread: a stable id plus the ordered non-system messages so far.
|
|
22
|
-
*
|
|
23
|
-
* Construct fresh (a new id is generated) or pass an `id` to resume one (e.g. a key
|
|
24
|
-
* recovered from a checkpoint):
|
|
25
|
-
*
|
|
26
|
-
* ```ts
|
|
27
|
-
* const thread = new SmoothAgentThread(); // fresh conversation
|
|
28
|
-
* const resumed = new SmoothAgentThread('conv-42'); // resume by id
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
export class SmoothAgentThread {
|
|
32
|
-
id;
|
|
33
|
-
/** Ordered history, oldest first, never including a system message. */
|
|
34
|
-
_messages = [];
|
|
35
|
-
constructor(id, messages) {
|
|
36
|
-
this.id = id && id.length > 0 ? id : newThreadId();
|
|
37
|
-
if (messages)
|
|
38
|
-
this.extend(messages);
|
|
39
|
-
}
|
|
40
|
-
/** The accumulated history, oldest first (no system prompt). */
|
|
41
|
-
get messages() {
|
|
42
|
-
return this._messages;
|
|
43
|
-
}
|
|
44
|
-
/** Number of messages currently in the thread. */
|
|
45
|
-
get length() {
|
|
46
|
-
return this._messages.length;
|
|
47
|
-
}
|
|
48
|
-
/** Append one message, skipping any system message (rebuilt per-run). */
|
|
49
|
-
add(message) {
|
|
50
|
-
if (message.role === 'system')
|
|
51
|
-
return;
|
|
52
|
-
this._messages.push(message);
|
|
53
|
-
}
|
|
54
|
-
/** Append several messages, skipping any system messages. */
|
|
55
|
-
extend(messages) {
|
|
56
|
-
for (const m of messages)
|
|
57
|
-
this.add(m);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
//# sourceMappingURL=thread.js.map
|
package/dist/thread.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"thread.js","sourceRoot":"","sources":["../src/thread.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,uEAAuE;AACvE,SAAS,WAAW;IAChB,OAAO,UAAU,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;AAC5D,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,OAAO,iBAAiB;IACjB,EAAE,CAAS;IACpB,uEAAuE;IACtD,SAAS,GAAc,EAAE,CAAC;IAE3C,YAAY,EAAW,EAAE,QAAoB;QACzC,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;QACnD,IAAI,QAAQ;YAAE,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACxC,CAAC;IAED,gEAAgE;IAChE,IAAI,QAAQ;QACR,OAAO,IAAI,CAAC,SAAS,CAAC;IAC1B,CAAC;IAED,kDAAkD;IAClD,IAAI,MAAM;QACN,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC;IACjC,CAAC;IAED,yEAAyE;IACzE,GAAG,CAAC,OAAgB;QAChB,IAAI,OAAO,CAAC,IAAI,KAAK,QAAQ;YAAE,OAAO;QACtC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACjC,CAAC;IAED,6DAA6D;IAC7D,MAAM,CAAC,QAA4B;QAC/B,KAAK,MAAM,CAAC,IAAI,QAAQ;YAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAC1C,CAAC;CACJ"}
|
package/dist/toolSearch.d.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The `tool_search` meta-tool — promotes deferred tools on demand.
|
|
3
|
-
*
|
|
4
|
-
* Phase-3 sibling of the Rust reference `tool_search.rs`. Mirrors the behaviour,
|
|
5
|
-
* not the type shapes (this core has no `ToolRegistry` — tools are a plain array
|
|
6
|
-
* on {@link AgentOptions}).
|
|
7
|
-
*
|
|
8
|
-
* As a tool set grows past ~20-30 entries, every model turn pays tokens to read
|
|
9
|
-
* schemas it isn't going to use, diluting the model's attention budget. So a caller
|
|
10
|
-
* can register some tools as **deferred** (`AgentOptions.deferredTools`): their
|
|
11
|
-
* schemas are hidden from the model. Instead the agent advertises a single built-in
|
|
12
|
-
* `tool_search(query)` meta-tool. When the model calls it, this fuzzy-matches the
|
|
13
|
-
* query against the deferred tools' names + descriptions, **promotes** the matches
|
|
14
|
-
* into the visible set (so the model can call them on subsequent turns), and returns
|
|
15
|
-
* each match's name + description as JSON.
|
|
16
|
-
*
|
|
17
|
-
* A deferred tool that has not been promoted is *not* dispatchable — calling it
|
|
18
|
-
* surfaces as an unknown tool until `tool_search` adds it to the promoted set.
|
|
19
|
-
*/
|
|
20
|
-
import type { Tool } from './agent.js';
|
|
21
|
-
/** The built-in meta-tool's name. Reserved when deferred tools are in play. */
|
|
22
|
-
export declare const TOOL_SEARCH_NAME = "tool_search";
|
|
23
|
-
/**
|
|
24
|
-
* Cap on how many deferred tools a single `tool_search` call may promote, so a
|
|
25
|
-
* generic query like "tool" doesn't promote the entire deferred set in one shot.
|
|
26
|
-
*/
|
|
27
|
-
export declare const MAX_MATCHES = 8;
|
|
28
|
-
/**
|
|
29
|
-
* Drives deferred-tool promotion for one agent run. Implements {@link Tool} so the
|
|
30
|
-
* agent can advertise + dispatch it like any other tool. Holds the deferred tools
|
|
31
|
-
* (by name) and the mutable set of promoted names; the agent consults
|
|
32
|
-
* {@link promotedTools} each iteration to decide which deferred schemas are now
|
|
33
|
-
* visible/dispatchable.
|
|
34
|
-
*/
|
|
35
|
-
export declare class ToolSearch implements Tool {
|
|
36
|
-
readonly name = "tool_search";
|
|
37
|
-
readonly description: string;
|
|
38
|
-
readonly parameters: Record<string, unknown>;
|
|
39
|
-
private readonly deferredByName;
|
|
40
|
-
private readonly promoted;
|
|
41
|
-
constructor(deferred: Tool[]);
|
|
42
|
-
/** True if any tool was registered deferred (the meta-tool is advertised only then). */
|
|
43
|
-
hasDeferred(): boolean;
|
|
44
|
-
/** True if a deferred tool has been promoted and is now dispatchable. */
|
|
45
|
-
isPromoted(name: string): boolean;
|
|
46
|
-
/** The deferred tools that have been promoted — their schemas join the visible set. */
|
|
47
|
-
promotedTools(): Tool[];
|
|
48
|
-
/** Resolve a promoted deferred tool for dispatch. Unpromoted deferred tools are invisible. */
|
|
49
|
-
toolByName(name: string): Tool | undefined;
|
|
50
|
-
/** Mark a deferred tool promoted. Returns false if no such deferred tool. */
|
|
51
|
-
promote(name: string): boolean;
|
|
52
|
-
/** Fuzzy-match the query, promote matches, and return their schemas as JSON. */
|
|
53
|
-
execute(args: Record<string, unknown>): Promise<string>;
|
|
54
|
-
}
|
|
55
|
-
//# sourceMappingURL=toolSearch.d.ts.map
|
package/dist/toolSearch.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"toolSearch.d.ts","sourceRoot":"","sources":["../src/toolSearch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAEvC,+EAA+E;AAC/E,eAAO,MAAM,gBAAgB,gBAAgB,CAAC;AAE9C;;;GAGG;AACH,eAAO,MAAM,WAAW,IAAI,CAAC;AAmB7B;;;;;;GAMG;AACH,qBAAa,UAAW,YAAW,IAAI;IACnC,QAAQ,CAAC,IAAI,iBAAoB;IACjC,QAAQ,CAAC,WAAW,SAAe;IACnC,QAAQ,CAAC,UAAU,0BAAU;IAE7B,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAoB;IACnD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqB;gBAElC,QAAQ,EAAE,IAAI,EAAE;IAI5B,wFAAwF;IACxF,WAAW,IAAI,OAAO;IAItB,yEAAyE;IACzE,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAIjC,uFAAuF;IACvF,aAAa,IAAI,IAAI,EAAE;IASvB,8FAA8F;IAC9F,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS;IAI1C,6EAA6E;IAC7E,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAM9B,gFAAgF;IAC1E,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;CAuBhE"}
|