@nxisai/agent-harness 0.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/README.md +434 -0
- package/dist/a2ui/cards.d.ts +55 -0
- package/dist/a2ui/cards.d.ts.map +1 -0
- package/dist/a2ui/cards.js +133 -0
- package/dist/a2ui/cards.js.map +1 -0
- package/dist/a2ui/emit.d.ts +33 -0
- package/dist/a2ui/emit.d.ts.map +1 -0
- package/dist/a2ui/emit.js +116 -0
- package/dist/a2ui/emit.js.map +1 -0
- package/dist/a2ui/form.d.ts +20 -0
- package/dist/a2ui/form.d.ts.map +1 -0
- package/dist/a2ui/form.js +92 -0
- package/dist/a2ui/form.js.map +1 -0
- package/dist/a2ui/host.d.ts +34 -0
- package/dist/a2ui/host.d.ts.map +1 -0
- package/dist/a2ui/host.js +47 -0
- package/dist/a2ui/host.js.map +1 -0
- package/dist/a2ui/index.d.ts +23 -0
- package/dist/a2ui/index.d.ts.map +1 -0
- package/dist/a2ui/index.js +20 -0
- package/dist/a2ui/index.js.map +1 -0
- package/dist/a2ui/stepper.d.ts +26 -0
- package/dist/a2ui/stepper.d.ts.map +1 -0
- package/dist/a2ui/stepper.js +162 -0
- package/dist/a2ui/stepper.js.map +1 -0
- package/dist/a2ui/theme.d.ts +21 -0
- package/dist/a2ui/theme.d.ts.map +1 -0
- package/dist/a2ui/theme.js +134 -0
- package/dist/a2ui/theme.js.map +1 -0
- package/dist/a2ui/to-v09.d.ts +31 -0
- package/dist/a2ui/to-v09.d.ts.map +1 -0
- package/dist/a2ui/to-v09.js +104 -0
- package/dist/a2ui/to-v09.js.map +1 -0
- package/dist/engine.d.ts +209 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +505 -0
- package/dist/engine.js.map +1 -0
- package/dist/harness/harness.d.ts +284 -0
- package/dist/harness/harness.d.ts.map +1 -0
- package/dist/harness/harness.js +568 -0
- package/dist/harness/harness.js.map +1 -0
- package/dist/harness/plan.d.ts +32 -0
- package/dist/harness/plan.d.ts.map +1 -0
- package/dist/harness/plan.js +68 -0
- package/dist/harness/plan.js.map +1 -0
- package/dist/harness/policy.d.ts +49 -0
- package/dist/harness/policy.d.ts.map +1 -0
- package/dist/harness/policy.js +34 -0
- package/dist/harness/policy.js.map +1 -0
- package/dist/harness/renderer.d.ts +163 -0
- package/dist/harness/renderer.d.ts.map +1 -0
- package/dist/harness/renderer.js +12 -0
- package/dist/harness/renderer.js.map +1 -0
- package/dist/harness/router/coordinator.d.ts +120 -0
- package/dist/harness/router/coordinator.d.ts.map +1 -0
- package/dist/harness/router/coordinator.js +145 -0
- package/dist/harness/router/coordinator.js.map +1 -0
- package/dist/harness/router/rules.d.ts +48 -0
- package/dist/harness/router/rules.d.ts.map +1 -0
- package/dist/harness/router/rules.js +38 -0
- package/dist/harness/router/rules.js.map +1 -0
- package/dist/harness/slots.d.ts +73 -0
- package/dist/harness/slots.d.ts.map +1 -0
- package/dist/harness/slots.js +68 -0
- package/dist/harness/slots.js.map +1 -0
- package/dist/harness/tools/bridge.d.ts +71 -0
- package/dist/harness/tools/bridge.d.ts.map +1 -0
- package/dist/harness/tools/bridge.js +271 -0
- package/dist/harness/tools/bridge.js.map +1 -0
- package/dist/harness/tools/client.d.ts +11 -0
- package/dist/harness/tools/client.d.ts.map +1 -0
- package/dist/harness/tools/client.js +21 -0
- package/dist/harness/tools/client.js.map +1 -0
- package/dist/harness/tools/discovery.d.ts +13 -0
- package/dist/harness/tools/discovery.d.ts.map +1 -0
- package/dist/harness/tools/discovery.js +43 -0
- package/dist/harness/tools/discovery.js.map +1 -0
- package/dist/harness/tools/local-context.d.ts +38 -0
- package/dist/harness/tools/local-context.d.ts.map +1 -0
- package/dist/harness/tools/local-context.js +55 -0
- package/dist/harness/tools/local-context.js.map +1 -0
- package/dist/harness/tools/schema.d.ts +52 -0
- package/dist/harness/tools/schema.d.ts.map +1 -0
- package/dist/harness/tools/schema.js +175 -0
- package/dist/harness/tools/schema.js.map +1 -0
- package/dist/harness/tools/source.d.ts +65 -0
- package/dist/harness/tools/source.d.ts.map +1 -0
- package/dist/harness/tools/source.js +89 -0
- package/dist/harness/tools/source.js.map +1 -0
- package/dist/harness/tools/webmcp.d.ts +50 -0
- package/dist/harness/tools/webmcp.d.ts.map +1 -0
- package/dist/harness/tools/webmcp.js +114 -0
- package/dist/harness/tools/webmcp.js.map +1 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -0
- package/dist/providers/types.d.ts +123 -0
- package/dist/providers/types.d.ts.map +1 -0
- package/dist/providers/types.js +2 -0
- package/dist/providers/types.js.map +1 -0
- package/dist/types.d.ts +223 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/dist/ui/agent-fullscreen.d.ts +41 -0
- package/dist/ui/agent-fullscreen.d.ts.map +1 -0
- package/dist/ui/agent-fullscreen.js +2821 -0
- package/dist/ui/agent-fullscreen.js.map +1 -0
- package/dist/ui/config.d.ts +88 -0
- package/dist/ui/config.d.ts.map +1 -0
- package/dist/ui/config.js +96 -0
- package/dist/ui/config.js.map +1 -0
- package/dist/ui/index.d.ts +22 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +19 -0
- package/dist/ui/index.js.map +1 -0
- package/dist/ui/tailwind.generated.d.ts +2 -0
- package/dist/ui/tailwind.generated.d.ts.map +1 -0
- package/dist/ui/tailwind.generated.js +3 -0
- package/dist/ui/tailwind.generated.js.map +1 -0
- package/dist/webmcp-contract.d.ts +57 -0
- package/dist/webmcp-contract.d.ts.map +1 -0
- package/dist/webmcp-contract.js +11 -0
- package/dist/webmcp-contract.js.map +1 -0
- package/package.json +39 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool discovery and execution over WebMCP.
|
|
3
|
+
*
|
|
4
|
+
* Discovery and execution work the same way whichever model is answering, so
|
|
5
|
+
* they sit with the harness rather than behind {@link ModelProvider}.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import { TOOLS_TIMEOUT_MS } from '../../engine.js';
|
|
10
|
+
/**
|
|
11
|
+
* The default tool source, backed by the page's `document.modelContext`.
|
|
12
|
+
*
|
|
13
|
+
* Supply an instance as {@link HarnessOptions.toolSource}, or substitute any
|
|
14
|
+
* object with the same shape to draw tools from somewhere else.
|
|
15
|
+
*/
|
|
16
|
+
export class WebMcpTools {
|
|
17
|
+
/**
|
|
18
|
+
* The page's model context.
|
|
19
|
+
*
|
|
20
|
+
* @returns The context, or null on a page where WebMCP is not present.
|
|
21
|
+
*/
|
|
22
|
+
modelContext() {
|
|
23
|
+
return document.modelContext || navigator.modelContext || null;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Wait for tools to appear on a model context.
|
|
27
|
+
*
|
|
28
|
+
* Tools register asynchronously, so a context can be present but empty for a
|
|
29
|
+
* short time after page load. Polls, and also listens for `toolchange`.
|
|
30
|
+
*
|
|
31
|
+
* @param mc - The context to watch.
|
|
32
|
+
* @param signal - Abort to stop waiting early. Resolves empty when aborted.
|
|
33
|
+
* @returns The registered tools, or an empty array if none appear within
|
|
34
|
+
* {@link TOOLS_TIMEOUT_MS}.
|
|
35
|
+
*/
|
|
36
|
+
waitForTools(mc, signal) {
|
|
37
|
+
return new Promise((resolve) => {
|
|
38
|
+
let done = false;
|
|
39
|
+
const finish = async (tools) => {
|
|
40
|
+
if (done)
|
|
41
|
+
return;
|
|
42
|
+
done = true;
|
|
43
|
+
clearInterval(iv);
|
|
44
|
+
clearTimeout(to);
|
|
45
|
+
mc.removeEventListener('toolchange', onChange);
|
|
46
|
+
signal?.removeEventListener('abort', onAbort);
|
|
47
|
+
resolve(tools || (await mc.getTools()));
|
|
48
|
+
};
|
|
49
|
+
const onAbort = () => finish([]);
|
|
50
|
+
if (signal?.aborted)
|
|
51
|
+
return finish([]);
|
|
52
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
53
|
+
const check = async () => {
|
|
54
|
+
const tools = await mc.getTools();
|
|
55
|
+
if (tools && tools.length)
|
|
56
|
+
finish(tools);
|
|
57
|
+
};
|
|
58
|
+
const onChange = () => check();
|
|
59
|
+
mc.addEventListener('toolchange', onChange);
|
|
60
|
+
const iv = setInterval(check, 800);
|
|
61
|
+
const to = setTimeout(() => finish(), TOOLS_TIMEOUT_MS);
|
|
62
|
+
check();
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Every tool registered on the page.
|
|
67
|
+
*
|
|
68
|
+
* @param signal - Abort to stop waiting for tools to appear.
|
|
69
|
+
* @returns The registered tools, or an empty array when WebMCP is absent,
|
|
70
|
+
* discovery fails, or the wait is aborted.
|
|
71
|
+
*/
|
|
72
|
+
async discoverTools(signal) {
|
|
73
|
+
const mc = this.modelContext();
|
|
74
|
+
if (!mc)
|
|
75
|
+
return [];
|
|
76
|
+
try {
|
|
77
|
+
return await this.waitForTools(mc, signal);
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
return [];
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Call a tool.
|
|
85
|
+
*
|
|
86
|
+
* Handles both the native calling convention (a registered tool object and a
|
|
87
|
+
* JSON string) and the polyfill's (a name and an object), trying the native
|
|
88
|
+
* form first and falling back when the context rejects it.
|
|
89
|
+
*
|
|
90
|
+
* @param toolObj - The tool as reported by discovery, or null to call by name.
|
|
91
|
+
* @param name - The tool's name, used for the fallback call.
|
|
92
|
+
* @param args - The arguments to send.
|
|
93
|
+
* @returns The tool's response.
|
|
94
|
+
* @throws If WebMCP is not available, or the tool itself throws.
|
|
95
|
+
*/
|
|
96
|
+
async execTool(toolObj, name, args) {
|
|
97
|
+
const mc = this.modelContext();
|
|
98
|
+
if (!mc)
|
|
99
|
+
throw new Error('WebMCP is not available on this page.');
|
|
100
|
+
const json = JSON.stringify(args ?? {});
|
|
101
|
+
if (toolObj) {
|
|
102
|
+
try {
|
|
103
|
+
return await mc.executeTool(toolObj, json);
|
|
104
|
+
}
|
|
105
|
+
catch (e) {
|
|
106
|
+
const msg = String(e?.message || e);
|
|
107
|
+
if (!/RegisteredTool|not of type|No tool registered|NotFound/i.test(msg))
|
|
108
|
+
throw e;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return await mc.executeTool(name, args);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=webmcp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webmcp.js","sourceRoot":"","sources":["../../../src/harness/tools/webmcp.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAOnD;;;;;GAKG;AACH,MAAM,OAAO,WAAW;IACtB;;;;OAIG;IACH,YAAY;QACV,OAAO,QAAQ,CAAC,YAAY,IAAI,SAAS,CAAC,YAAY,IAAI,IAAI,CAAC;IACjE,CAAC;IAED;;;;;;;;;;OAUG;IACH,YAAY,CAAC,EAAgB,EAAE,MAAoB;QACjD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC7B,IAAI,IAAI,GAAG,KAAK,CAAC;YACjB,MAAM,MAAM,GAAG,KAAK,EAAE,KAA8B,EAAE,EAAE;gBACtD,IAAI,IAAI;oBAAE,OAAO;gBACjB,IAAI,GAAG,IAAI,CAAC;gBACZ,aAAa,CAAC,EAAE,CAAC,CAAC;gBAClB,YAAY,CAAC,EAAE,CAAC,CAAC;gBACjB,EAAE,CAAC,mBAAmB,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;gBAC/C,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;gBAC9C,OAAO,CAAC,KAAK,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,CAA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7B,MAAM,EAAE,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QAC/B,IAAI,CAAC,EAAE;YAAE,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;QAClE,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;QACxC,IAAI,OAAO,EAAE,CAAC;YACZ,IAAI,CAAC;gBACH,OAAO,MAAM,EAAE,CAAC,WAAW,CAAC,OAA4B,EAAE,IAAI,CAAC,CAAC;YAClE,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,MAAM,GAAG,GAAG,MAAM,CAAE,CAAW,EAAE,OAAO,IAAI,CAAC,CAAC,CAAC;gBAC/C,IAAI,CAAC,yDAAyD,CAAC,IAAI,CAAC,GAAG,CAAC;oBAAE,MAAM,CAAC,CAAC;YACpF,CAAC;QACH,CAAC;QACD,OAAO,MAAM,EAAE,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC1C,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Headless entry point for `@nxisai/agent-harness`.
|
|
3
|
+
*
|
|
4
|
+
* Everything exported here runs without a UI. For the packaged chat element,
|
|
5
|
+
* import `@nxisai/agent-harness/ui`; to keep this decision logic behind an
|
|
6
|
+
* interface of your own, implement {@link HarnessRenderer}.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { AgentHarness } from '@nxisai/agent-harness';
|
|
11
|
+
*
|
|
12
|
+
* const harness = new AgentHarness({ renderer });
|
|
13
|
+
* await harness.turn('book me in for Thursday', messages);
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @module
|
|
17
|
+
*/
|
|
18
|
+
export { AgentHarness } from './harness/harness.js';
|
|
19
|
+
export { LocalGemmaProvider, AgentEngine } from './engine.js';
|
|
20
|
+
export type { ModelProvider, CompletionRequest, Completion, CacheHint, } from './providers/types.js';
|
|
21
|
+
export { WebMcpTools } from './harness/tools/webmcp.js';
|
|
22
|
+
export { toolSchema, missingRequired, reconcileArgs, extractResult, } from './harness/tools/schema.js';
|
|
23
|
+
export type { HarnessOptions, TurnResult } from './harness/harness.js';
|
|
24
|
+
export { policyFor, decide } from './harness/policy.js';
|
|
25
|
+
export type { ToolPolicy, Decision } from './harness/policy.js';
|
|
26
|
+
export { resolveSlots, summarySlots } from './harness/slots.js';
|
|
27
|
+
export type { Slot, Resolution, ResolveSources } from './harness/slots.js';
|
|
28
|
+
export { buildPlan } from './harness/plan.js';
|
|
29
|
+
export { AgentCoordinator } from './harness/router/coordinator.js';
|
|
30
|
+
export type { CoordinatorOptions, RoutedTurn, RouteSource } from './harness/router/coordinator.js';
|
|
31
|
+
export { matchRoute } from './harness/router/rules.js';
|
|
32
|
+
export type { RouteRule, RouteDecision } from './harness/router/rules.js';
|
|
33
|
+
export type { ClarificationPlan, PlanStep } from './harness/plan.js';
|
|
34
|
+
export type { HarnessRenderer, AskRequest, ConfirmRequest, StreamingBubble, } from './harness/renderer.js';
|
|
35
|
+
export { parseToolCall, stripMarkers, humanize, lcFirst, escapeHtml, MODEL_ID, MODEL_HOST, MODEL_PATH_TEMPLATE, SYSTEM_PROMPT, MAX_STEPS, MAX_NEW_TOKENS, TOOLS_TIMEOUT_MS, } from './engine.js';
|
|
36
|
+
/**
|
|
37
|
+
* Brand marks and icons used by the packaged UI.
|
|
38
|
+
*
|
|
39
|
+
* Exported for custom renderers. Inline SVG using `currentColor`, so each icon
|
|
40
|
+
* takes the surrounding text colour.
|
|
41
|
+
*/
|
|
42
|
+
export { NXIS_LOGO_SVG, ICON_CHECK, ICON_WARN, ICON_ARROW, ICON_PLUS, ICON_MENU, ICON_TRASH, ICON_STOP, ICON_COPY, ICON_PENCIL, ICON_REDO, ICON_CHECK_MARK, } from './engine.js';
|
|
43
|
+
export type { AgentEngineOptions, ChatMessage, ToolDef, GenerationUsage, ParsedToolCall, ProgressDetail, PreloadMode, } from './engine.js';
|
|
44
|
+
export { connectTools, waitForModelContext } from './harness/tools/source.js';
|
|
45
|
+
export type { ConnectResult, ConnectOptions } from './harness/tools/source.js';
|
|
46
|
+
export type { BridgeOptions } from './harness/tools/bridge.js';
|
|
47
|
+
export type { JsonSchema, ModelContext, ModelContextTool, ModelContextToolInfo, ModelContextToolResponse, McpServerInfo, NxisConfig, } from './types.js';
|
|
48
|
+
export type { NxisAction, NxisEntryPoint, NxisPropertyValueSpecification, NxisValueOption, } from './webmcp-contract.js';
|
|
49
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGpD,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC9D,YAAY,EACV,aAAa,EACb,iBAAiB,EACjB,UAAU,EACV,SAAS,GACV,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EACL,UAAU,EACV,eAAe,EACf,aAAa,EACb,aAAa,GACd,MAAM,2BAA2B,CAAC;AACnC,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEvE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AACxD,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEhE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAChE,YAAY,EAAE,IAAI,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAE3E,OAAO,EAAE,SAAS,EAAE,MAAM,mBA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AC9B,eAAe,GAChB,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Headless entry point for `@nxisai/agent-harness`.
|
|
3
|
+
*
|
|
4
|
+
* Everything exported here runs without a UI. For the packaged chat element,
|
|
5
|
+
* import `@nxisai/agent-harness/ui`; to keep this decision logic behind an
|
|
6
|
+
* interface of your own, implement {@link HarnessRenderer}.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { AgentHarness } from '@nxisai/agent-harness';
|
|
11
|
+
*
|
|
12
|
+
* const harness = new AgentHarness({ renderer });
|
|
13
|
+
* await harness.turn('book me in for Thursday', messages);
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @module
|
|
17
|
+
*/
|
|
18
|
+
export { AgentHarness } from './harness/harness.js';
|
|
19
|
+
// ── Model providers ──────────────────────────────────────────────────────────
|
|
20
|
+
export { LocalGemmaProvider, AgentEngine } from './engine.js';
|
|
21
|
+
// ── Tools, as the harness sees them ──────────────────────────────────────────
|
|
22
|
+
export { WebMcpTools } from './harness/tools/webmcp.js';
|
|
23
|
+
export { toolSchema, missingRequired, reconcileArgs, extractResult, } from './harness/tools/schema.js';
|
|
24
|
+
export { policyFor, decide } from './harness/policy.js';
|
|
25
|
+
export { resolveSlots, summarySlots } from './harness/slots.js';
|
|
26
|
+
export { buildPlan } from './harness/plan.js';
|
|
27
|
+
export { AgentCoordinator } from './harness/router/coordinator.js';
|
|
28
|
+
export { matchRoute } from './harness/router/rules.js';
|
|
29
|
+
export { parseToolCall, stripMarkers, humanize, lcFirst, escapeHtml, MODEL_ID, MODEL_HOST, MODEL_PATH_TEMPLATE, SYSTEM_PROMPT, MAX_STEPS, MAX_NEW_TOKENS, TOOLS_TIMEOUT_MS, } from './engine.js';
|
|
30
|
+
/**
|
|
31
|
+
* Brand marks and icons used by the packaged UI.
|
|
32
|
+
*
|
|
33
|
+
* Exported for custom renderers. Inline SVG using `currentColor`, so each icon
|
|
34
|
+
* takes the surrounding text colour.
|
|
35
|
+
*/
|
|
36
|
+
export { NXIS_LOGO_SVG, ICON_CHECK, ICON_WARN, ICON_ARROW, ICON_PLUS, ICON_MENU, ICON_TRASH, ICON_STOP, ICON_COPY, ICON_PENCIL, ICON_REDO, ICON_CHECK_MARK, } from './engine.js';
|
|
37
|
+
export { connectTools, waitForModelContext } from './harness/tools/source.js';
|
|
38
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,gFAAgF;AAChF,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAQ9D,gFAAgF;AAChF,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EACL,UAAU,EACV,eAAe,EACf,aAAa,EACb,aAAa,GACd,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAGxD,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAGhE,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAEnE,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAWvD,OAAO,EACL,aAAa,EACb,YAAY,EACZ,QAAQ,EACR,OAAO,EACP,UAAU,EACV,QAAQ,EACR,UAAU,EACV,mBAAmB,EACnB,aAAa,EACb,SAAS,EACT,cAAc,EACd,gBAAgB,GACjB,MAAM,aAAa,CAAC;AAErB;;;;;GAKG;AACH,OAAO,EACL,aAAa,EACb,UAAU,EACV,SAAS,EACT,UAAU,EACV,SAAS,EACT,SAAS,EACT,UAAU,EACV,SAAS,EACT,SAAS,EACT,WAAW,EACX,SAAS,EACT,eAAe,GAChB,MAAM,aAAa,CAAC;AAWrB,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The model provider interface.
|
|
3
|
+
*
|
|
4
|
+
* A provider supplies one completion at a time. Everything else the harness
|
|
5
|
+
* does (discovering tools, reading their schemas, deciding whether to ask,
|
|
6
|
+
* confirm or run) is the same whichever model answers.
|
|
7
|
+
*
|
|
8
|
+
* Completions are structured rather than plain text: a provider reports a tool
|
|
9
|
+
* call as {@link Completion.call}, whether its model expresses that as a native
|
|
10
|
+
* tool-use block or as markers in the text it generates.
|
|
11
|
+
*
|
|
12
|
+
* @see The bundled {@link LocalGemmaProvider}, and `docs/remote-providers.md`
|
|
13
|
+
* for a worked remote implementation.
|
|
14
|
+
*
|
|
15
|
+
* @module
|
|
16
|
+
*/
|
|
17
|
+
import type { ChatMessage, GenerationUsage, ModelContextToolInfo, ParsedToolCall, PreloadMode } from '../types.js';
|
|
18
|
+
/**
|
|
19
|
+
* What the harness knows about which parts of a request will repeat.
|
|
20
|
+
*
|
|
21
|
+
* Advisory. The harness caches nothing itself; acting on the hint is a
|
|
22
|
+
* provider's decision, and only worthwhile where the backend supports prompt
|
|
23
|
+
* caching. Both fields go false when a handoff between agents changes the
|
|
24
|
+
* system prompt and the tool set.
|
|
25
|
+
*/
|
|
26
|
+
export interface CacheHint {
|
|
27
|
+
/** How many leading messages will be identical on the next request. */
|
|
28
|
+
stableMessages: number;
|
|
29
|
+
/** Whether the tool definitions are unchanged since the previous request. */
|
|
30
|
+
toolsStable: boolean;
|
|
31
|
+
}
|
|
32
|
+
/** One request for a completion. */
|
|
33
|
+
export interface CompletionRequest {
|
|
34
|
+
/** The conversation so far, including the system prompt. */
|
|
35
|
+
messages: ChatMessage[];
|
|
36
|
+
/**
|
|
37
|
+
* The tools available for this turn, as raw WebMCP entries.
|
|
38
|
+
*
|
|
39
|
+
* Providers translate these into whatever their model expects.
|
|
40
|
+
*/
|
|
41
|
+
tools: ModelContextToolInfo[];
|
|
42
|
+
/** Ceiling on generated tokens. Providers may apply their own default. */
|
|
43
|
+
maxTokens?: number;
|
|
44
|
+
/**
|
|
45
|
+
* Aborts when the user stops the turn, closes the panel, or starts another.
|
|
46
|
+
*
|
|
47
|
+
* Honour it: pass it to `fetch`, or interrupt local generation. Rejecting
|
|
48
|
+
* with an `AbortError` is correct, and the harness treats it as a
|
|
49
|
+
* cancellation rather than a failure.
|
|
50
|
+
*/
|
|
51
|
+
signal?: AbortSignal;
|
|
52
|
+
/**
|
|
53
|
+
* Called as text arrives, with the whole answer so far rather than the newest
|
|
54
|
+
* fragment. Optional: a provider that does not stream simply omits it.
|
|
55
|
+
*/
|
|
56
|
+
onToken?(textSoFar: string): void;
|
|
57
|
+
/** What the harness knows about reuse. Advisory; see {@link CacheHint}. */
|
|
58
|
+
cache?: CacheHint;
|
|
59
|
+
}
|
|
60
|
+
/** What a provider returns for one request. */
|
|
61
|
+
export interface Completion {
|
|
62
|
+
/**
|
|
63
|
+
* Text to show the user, rendered verbatim. Strip any protocol markers in the
|
|
64
|
+
* provider: the harness does no parsing of its own.
|
|
65
|
+
*/
|
|
66
|
+
text: string;
|
|
67
|
+
/**
|
|
68
|
+
* The tool the model asked for, if any. At most one per completion; a model
|
|
69
|
+
* that returns several calls should report the first and drop the rest.
|
|
70
|
+
*/
|
|
71
|
+
call?: ParsedToolCall;
|
|
72
|
+
/** Token counts, when the provider can report them. */
|
|
73
|
+
usage?: GenerationUsage;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* A source of model completions.
|
|
77
|
+
*
|
|
78
|
+
* Implement `complete` and the four readonly fields; everything else is
|
|
79
|
+
* optional. See `docs/remote-providers.md` for a worked example.
|
|
80
|
+
*/
|
|
81
|
+
export interface ModelProvider {
|
|
82
|
+
/** Identifies the provider in logs and debug output, not to end users. */
|
|
83
|
+
readonly name: string;
|
|
84
|
+
/**
|
|
85
|
+
* Whether inference happens on the user's device.
|
|
86
|
+
*
|
|
87
|
+
* Surfaced in the UI, so that a page sending conversations to a remote
|
|
88
|
+
* service says so.
|
|
89
|
+
*/
|
|
90
|
+
readonly local: boolean;
|
|
91
|
+
/** Whether the provider can answer a request right now. */
|
|
92
|
+
readonly ready: boolean;
|
|
93
|
+
/** Whether a load is in flight. Always false when there is nothing to load. */
|
|
94
|
+
readonly loading: boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Prepare the model, resolving once it is ready.
|
|
97
|
+
*
|
|
98
|
+
* Omit it entirely when there is nothing to prepare: its absence is what
|
|
99
|
+
* tells the UI to skip the download progress treatment.
|
|
100
|
+
*/
|
|
101
|
+
load?(): Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Begin loading ahead of the first turn.
|
|
104
|
+
*
|
|
105
|
+
* @param mode - How eagerly to load, from the element's `preload` attribute.
|
|
106
|
+
*/
|
|
107
|
+
preload?(mode: Exclude<PreloadMode, 'none'>): void;
|
|
108
|
+
/**
|
|
109
|
+
* Produce one completion.
|
|
110
|
+
*
|
|
111
|
+
* @param req - The conversation, the available tools, and the abort signal.
|
|
112
|
+
* @returns The generated text and the tool call it implies, if any.
|
|
113
|
+
*/
|
|
114
|
+
complete(req: CompletionRequest): Promise<Completion>;
|
|
115
|
+
/**
|
|
116
|
+
* Count tokens in a string.
|
|
117
|
+
*
|
|
118
|
+
* Optional. A provider that cannot count causes token metrics to be hidden
|
|
119
|
+
* rather than estimated.
|
|
120
|
+
*/
|
|
121
|
+
countTokens?(text: string): Promise<number>;
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/providers/types.ts"],"names":[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I,EAAE,OAAO,CAAC,WAAW,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC;IAEnD;;;;;OAKG;IACH,QAAQ,CAAC,GAAG,EAAE,iBAAiB,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IACtD;;;;;OAKG;IACH,WAAW,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC7C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/providers/types.ts"],"names":[],"mappings":""}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared types: the WebMCP surface (`document.modelContext`), MCP discovery
|
|
3
|
+
* (catalogs and server cards), and the model and tool-call shapes.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
/** A JSON Schema fragment, as carried by a tool's input schema. */
|
|
8
|
+
export interface JsonSchema {
|
|
9
|
+
type?: string;
|
|
10
|
+
properties?: Record<string, JsonSchema>;
|
|
11
|
+
required?: string[];
|
|
12
|
+
enum?: unknown[];
|
|
13
|
+
items?: JsonSchema;
|
|
14
|
+
format?: string;
|
|
15
|
+
description?: string;
|
|
16
|
+
default?: unknown;
|
|
17
|
+
[key: string]: unknown;
|
|
18
|
+
}
|
|
19
|
+
/** Behavioural hints a tool declares about itself. */
|
|
20
|
+
export interface ModelContextToolAnnotations {
|
|
21
|
+
/** True when calling the tool has no side effects. Drives {@link policyFor}. */
|
|
22
|
+
readOnlyHint?: boolean;
|
|
23
|
+
[key: string]: unknown;
|
|
24
|
+
}
|
|
25
|
+
/** One block of a tool response. */
|
|
26
|
+
export interface ModelContextContent {
|
|
27
|
+
/** The block's kind, commonly `'text'`. */
|
|
28
|
+
type: string;
|
|
29
|
+
/** The block's text, when it has one. */
|
|
30
|
+
text?: string;
|
|
31
|
+
[key: string]: unknown;
|
|
32
|
+
}
|
|
33
|
+
/** What a tool returns. */
|
|
34
|
+
export interface ModelContextToolResponse {
|
|
35
|
+
/** The response blocks, in order. */
|
|
36
|
+
content: ModelContextContent[];
|
|
37
|
+
/** True when the tool reports a failure. */
|
|
38
|
+
isError?: boolean;
|
|
39
|
+
/** A parsed form of the response, preferred over the text when present. */
|
|
40
|
+
structuredContent?: Record<string, unknown>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* A tool as reported by `getTools()`.
|
|
44
|
+
*
|
|
45
|
+
* Implementations differ over where the schema lives and whether it arrives
|
|
46
|
+
* parsed or as a JSON string, so several keys are accepted. Use
|
|
47
|
+
* {@link toolSchema} to read it rather than these fields directly.
|
|
48
|
+
*/
|
|
49
|
+
export interface ModelContextToolInfo {
|
|
50
|
+
/** The tool's unique name, as used to call it. */
|
|
51
|
+
name: string;
|
|
52
|
+
/** What the tool does, shown to the model. */
|
|
53
|
+
description?: string;
|
|
54
|
+
/** The input schema. See also the aliases below. */
|
|
55
|
+
inputSchema?: JsonSchema | string;
|
|
56
|
+
/** Alias for {@link ModelContextToolInfo.inputSchema}. */
|
|
57
|
+
input_schema?: JsonSchema | string;
|
|
58
|
+
/** Alias for {@link ModelContextToolInfo.inputSchema}. */
|
|
59
|
+
parameters?: JsonSchema | string;
|
|
60
|
+
/** Alias for {@link ModelContextToolInfo.inputSchema}. */
|
|
61
|
+
schema?: JsonSchema | string;
|
|
62
|
+
/** Behavioural hints, notably `readOnlyHint`. */
|
|
63
|
+
annotations?: ModelContextToolAnnotations;
|
|
64
|
+
/** Where the tool came from, when the registry records it. */
|
|
65
|
+
origin?: string;
|
|
66
|
+
}
|
|
67
|
+
/** A tool as passed to `registerTool()`. */
|
|
68
|
+
export interface ModelContextTool {
|
|
69
|
+
/** The tool's unique name. */
|
|
70
|
+
name: string;
|
|
71
|
+
/** What the tool does, shown to the model. */
|
|
72
|
+
description?: string;
|
|
73
|
+
/** The parsed input schema. */
|
|
74
|
+
inputSchema?: JsonSchema;
|
|
75
|
+
/** Behavioural hints, notably `readOnlyHint`. */
|
|
76
|
+
annotations?: ModelContextToolAnnotations;
|
|
77
|
+
/** Called to run the tool. */
|
|
78
|
+
execute(input: Record<string, unknown>, context?: unknown): ModelContextToolResponse | Promise<ModelContextToolResponse>;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The page's model context, per the W3C draft ModelContext API.
|
|
82
|
+
*
|
|
83
|
+
* Emits `toolchange` when the set of registered tools changes.
|
|
84
|
+
*/
|
|
85
|
+
export interface ModelContext extends EventTarget {
|
|
86
|
+
/** Add a tool to the page's registry. */
|
|
87
|
+
registerTool(tool: ModelContextTool, options?: unknown): void;
|
|
88
|
+
/** Supply page context to the registry, where the implementation supports it. */
|
|
89
|
+
provideContext?(context?: unknown): void;
|
|
90
|
+
/** Call a tool, by registered object or by name. */
|
|
91
|
+
executeTool(nameOrTool: string | object, input?: string | Record<string, unknown> | null, options?: unknown): Promise<ModelContextToolResponse>;
|
|
92
|
+
/** Every tool currently registered on the page. */
|
|
93
|
+
getTools(options?: unknown): Promise<ModelContextToolInfo[]>;
|
|
94
|
+
}
|
|
95
|
+
/** One entry in a discovery catalog. */
|
|
96
|
+
export interface CatalogEntry {
|
|
97
|
+
identifier?: string;
|
|
98
|
+
displayName?: string;
|
|
99
|
+
mediaType?: string;
|
|
100
|
+
type?: string;
|
|
101
|
+
url?: string;
|
|
102
|
+
}
|
|
103
|
+
/** A `.well-known` discovery catalog. */
|
|
104
|
+
export interface CatalogFile {
|
|
105
|
+
/** The catalog spec version the file claims. */
|
|
106
|
+
specVersion?: string;
|
|
107
|
+
/** The catalog's entries. */
|
|
108
|
+
entries?: CatalogEntry[];
|
|
109
|
+
}
|
|
110
|
+
/** A header a remote expects on each request, such as an API key. */
|
|
111
|
+
export interface ServerCardRemoteHeader {
|
|
112
|
+
name: string;
|
|
113
|
+
description?: string;
|
|
114
|
+
isSecret?: boolean;
|
|
115
|
+
isRequired?: boolean;
|
|
116
|
+
format?: string;
|
|
117
|
+
}
|
|
118
|
+
/** One way of reaching an MCP server. */
|
|
119
|
+
export interface ServerCardRemote {
|
|
120
|
+
type?: string;
|
|
121
|
+
url?: string;
|
|
122
|
+
headers?: ServerCardRemoteHeader[];
|
|
123
|
+
supportedProtocolVersions?: string[];
|
|
124
|
+
}
|
|
125
|
+
/** An MCP server's published description. */
|
|
126
|
+
export interface ServerCard {
|
|
127
|
+
name?: string;
|
|
128
|
+
title?: string;
|
|
129
|
+
description?: string;
|
|
130
|
+
websiteUrl?: string;
|
|
131
|
+
remotes?: ServerCardRemote[];
|
|
132
|
+
_meta?: Record<string, unknown>;
|
|
133
|
+
}
|
|
134
|
+
/** The connection details an MCP client needs, distilled from a server card. */
|
|
135
|
+
export interface McpServerInfo {
|
|
136
|
+
/** The server's Streamable HTTP endpoint. */
|
|
137
|
+
endpoint: string;
|
|
138
|
+
/** Header carrying the API key, when one is required. */
|
|
139
|
+
authHeaderName?: string;
|
|
140
|
+
/** Whether calls need an API key. */
|
|
141
|
+
authRequired: boolean;
|
|
142
|
+
/** Tools callable without authentication. */
|
|
143
|
+
publicTools: string[];
|
|
144
|
+
/** Protocol versions the server accepts. */
|
|
145
|
+
protocolVersions: string[];
|
|
146
|
+
/** Where the card was fetched from. */
|
|
147
|
+
cardUrl: string;
|
|
148
|
+
/** The server's display title. */
|
|
149
|
+
title?: string;
|
|
150
|
+
}
|
|
151
|
+
/** The `window.__NXIS_CONFIG__` global, when the host page defines one. */
|
|
152
|
+
export interface NxisConfig {
|
|
153
|
+
/** Organisation identifier. */
|
|
154
|
+
org_id?: string;
|
|
155
|
+
/** Site identifier. */
|
|
156
|
+
site_id?: string;
|
|
157
|
+
/** Subscription identifier. */
|
|
158
|
+
sub_id?: string;
|
|
159
|
+
/** WebMCP settings for the page. */
|
|
160
|
+
webmcp?: {
|
|
161
|
+
mode?: string;
|
|
162
|
+
};
|
|
163
|
+
/** Optional MCP API key for private tools; public typed-retrieval needs none. */
|
|
164
|
+
mcp_api_key?: string;
|
|
165
|
+
}
|
|
166
|
+
declare global {
|
|
167
|
+
interface Document {
|
|
168
|
+
modelContext?: ModelContext;
|
|
169
|
+
}
|
|
170
|
+
interface Navigator {
|
|
171
|
+
modelContext?: ModelContext;
|
|
172
|
+
}
|
|
173
|
+
interface Window {
|
|
174
|
+
__NXIS_CONFIG__?: NxisConfig;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
/** One message in a conversation. */
|
|
178
|
+
export interface ChatMessage {
|
|
179
|
+
/** Who produced the message. */
|
|
180
|
+
role: 'system' | 'user' | 'assistant';
|
|
181
|
+
/** The message text. */
|
|
182
|
+
content: string;
|
|
183
|
+
}
|
|
184
|
+
/** A tool definition in the form a chat template expects. */
|
|
185
|
+
export interface ToolDef {
|
|
186
|
+
/** Always `'function'`. */
|
|
187
|
+
type: 'function';
|
|
188
|
+
/** The callable's name, description and parameter schema. */
|
|
189
|
+
function: {
|
|
190
|
+
name: string;
|
|
191
|
+
description?: string;
|
|
192
|
+
parameters: JsonSchema;
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
/** A tool call the model asked for. */
|
|
196
|
+
export interface ParsedToolCall {
|
|
197
|
+
/** The tool's name. */
|
|
198
|
+
name: string;
|
|
199
|
+
/** The arguments, as supplied by the model. */
|
|
200
|
+
args: Record<string, unknown>;
|
|
201
|
+
}
|
|
202
|
+
/** Token counts for one generation. */
|
|
203
|
+
export interface GenerationUsage {
|
|
204
|
+
/** Tokens in the prompt, including tools and history. */
|
|
205
|
+
promptTokens: number;
|
|
206
|
+
/** Tokens generated. */
|
|
207
|
+
outputTokens: number;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Byte counts behind a load percentage.
|
|
211
|
+
*
|
|
212
|
+
* `total` covers only the files announced so far and grows as further shards
|
|
213
|
+
* register, which is why progress is reported per stage and left unclamped.
|
|
214
|
+
*/
|
|
215
|
+
export interface ProgressDetail {
|
|
216
|
+
/** Bytes received so far in this stage. */
|
|
217
|
+
loaded: number;
|
|
218
|
+
/** Bytes expected, across the files announced so far. */
|
|
219
|
+
total: number;
|
|
220
|
+
}
|
|
221
|
+
/** How eagerly to fetch model weights. */
|
|
222
|
+
export type PreloadMode = 'eager' | 'idle' | 'none';
|
|
223
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,mEAAmE;AACnE,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACxC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC;IACjB,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,sDAAsD;AACtD,MAAM,WAAW,2BAA2B;IAC1C,gFAAgF;IAChF,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,oCAAoC;AACpC,MAAM,WAAW,mBAAmB;IAClC,2CAA2C;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,yCAAyC;IACzC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,2BAA2B;AAC3B,MAAM,WAAW,wBAAwB;IACvC,qCAAqC;IACrC,OAAO,EAAE,mBAAmB,EAAE,CAAC;IAC/B,4CAA4C;IAC5C,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,2EAA2E;IAC3E,iBAA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ACtC,wBAAwB;IACxB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,6DAA6D;AAC7D,MAAM,WAAW,OAAO;IACtB,2BAA2B;IAC3B,IAAI,EAAE,UAAU,CAAC;IACjB,6DAA6D;IAC7D,QAAQ,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,UAAU,CAAA;KAAE,CAAC;CAC1E;AAED,uCAAuC;AACvC,MAAM,WAAW,cAAc;IAC7B,uBAAuB;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,+CAA+C;IAC/C,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B;AAED,uCAAuC;AACvC,MAAM,WAAW,eAAe;IAC9B,yDAAyD;IACzD,YAAY,EAAE,MAAM,CAAC;IACrB,wBAAwB;IACxB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;;;;GAKG;AACH,MAAM,WAAW,cAAc;IAC7B,2CAA2C;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,yDAAyD;IACzD,KAAK,EAAE,MAAM,CAAC;CACf;AAED,0CAA0C;AAC1C,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ModelContextToolInfo } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Stored values the agent reuses across turns, exposed as `element.preferences`.
|
|
4
|
+
*
|
|
5
|
+
* The host page supplies what it already knows about the visitor, and the agent
|
|
6
|
+
* uses it to fill forms and to answer in context.
|
|
7
|
+
*/
|
|
8
|
+
export interface AgentPreferences {
|
|
9
|
+
/** All values, or one by key. */
|
|
10
|
+
get(): Record<string, string>;
|
|
11
|
+
get(key: string): string | undefined;
|
|
12
|
+
/** Set one key, or merge an object. An empty value clears the key. */
|
|
13
|
+
set(key: string, value: string): void;
|
|
14
|
+
set(values: Record<string, string>): void;
|
|
15
|
+
/** Forget one key, or everything. */
|
|
16
|
+
clear(key?: string): void;
|
|
17
|
+
/** Keys the agent can map onto form fields. */
|
|
18
|
+
keys(): string[];
|
|
19
|
+
/** Survive reloads. Off by default — see the `preferences` getter. */
|
|
20
|
+
persist: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* One specialist agent, as declared by the host page.
|
|
24
|
+
*
|
|
25
|
+
* The prompt and the tool filter are what specialise it. The description is
|
|
26
|
+
* read only when the model is asked to route a turn.
|
|
27
|
+
*/
|
|
28
|
+
export interface AgentDefinition {
|
|
29
|
+
systemPrompt?: string;
|
|
30
|
+
tools?(tool: ModelContextToolInfo): boolean;
|
|
31
|
+
description?: string;
|
|
32
|
+
/**
|
|
33
|
+
* What this agent says when its tools are not on the page.
|
|
34
|
+
*
|
|
35
|
+
* Worth writing: the useful sentence names what cannot be done and where it
|
|
36
|
+
* can be, and it is the difference between an agent that admits a limit and
|
|
37
|
+
* one that answers a booking request by searching the site.
|
|
38
|
+
*/
|
|
39
|
+
unavailable?: string;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=agent-fullscreen.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-fullscreen.d.ts","sourceRoot":"","sources":["../../src/ui/agent-fullscreen.ts"],"names":[],"mappings":"AA6EA,OAAO,KAAK,EAAc,oBAAoB,EAA4B,MAAM,aAAa,CAAC;AAuE9F;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC/B,iCAAiC;IACjC,GAAG,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IACrC,sEAAsE;IACtE,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACtC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC;IAC1C,qCAAqC;IACrC,KAAK,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,+CAA+C;IAC/C,IAAI,IAAI,MAAM,EAAE,CAAC;IACjB,sEAAsE;IACtE,OAAO,EAAE,OAAO,CAAC;CAClB;AA4DD;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,CAAC,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC;IAC5C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB"}
|