@nexface/tools 0.1.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.
Files changed (82) hide show
  1. package/dist/browser/controller.d.ts +30 -0
  2. package/dist/browser/controller.js +783 -0
  3. package/dist/browser/controller.js.map +1 -0
  4. package/dist/browser/dom.d.ts +43 -0
  5. package/dist/browser/dom.js +438 -0
  6. package/dist/browser/dom.js.map +1 -0
  7. package/dist/browser/feedback.d.ts +4 -0
  8. package/dist/browser/feedback.js +5 -0
  9. package/dist/browser/feedback.js.map +1 -0
  10. package/dist/browser/locator.d.ts +19 -0
  11. package/dist/browser/locator.js +277 -0
  12. package/dist/browser/locator.js.map +1 -0
  13. package/dist/browser/prompt.d.ts +5 -0
  14. package/dist/browser/prompt.generated.d.ts +1 -0
  15. package/dist/browser/prompt.generated.js +50 -0
  16. package/dist/browser/prompt.generated.js.map +1 -0
  17. package/dist/browser/prompt.js +9 -0
  18. package/dist/browser/prompt.js.map +1 -0
  19. package/dist/browser/snapshot.d.ts +7 -0
  20. package/dist/browser/snapshot.js +424 -0
  21. package/dist/browser/snapshot.js.map +1 -0
  22. package/dist/browser/toolset.d.ts +35 -0
  23. package/dist/browser/toolset.js +383 -0
  24. package/dist/browser/toolset.js.map +1 -0
  25. package/dist/browser/types.d.ts +129 -0
  26. package/dist/browser/types.js +2 -0
  27. package/dist/browser/types.js.map +1 -0
  28. package/dist/browser/worker-runner.d.ts +11 -0
  29. package/dist/browser/worker-runner.js +400 -0
  30. package/dist/browser/worker-runner.js.map +1 -0
  31. package/dist/definition.d.ts +16 -0
  32. package/dist/definition.js +72 -0
  33. package/dist/definition.js.map +1 -0
  34. package/dist/index.d.ts +7 -0
  35. package/dist/index.js +4 -0
  36. package/dist/index.js.map +1 -0
  37. package/dist/internal-react.d.ts +12 -0
  38. package/dist/internal-react.js +23 -0
  39. package/dist/internal-react.js.map +1 -0
  40. package/dist/internal-types.d.ts +11 -0
  41. package/dist/internal-types.js +2 -0
  42. package/dist/internal-types.js.map +1 -0
  43. package/dist/internal.d.ts +9 -0
  44. package/dist/internal.js +5 -0
  45. package/dist/internal.js.map +1 -0
  46. package/dist/react.d.ts +25 -0
  47. package/dist/react.js +258 -0
  48. package/dist/react.js.map +1 -0
  49. package/dist/runtime.d.ts +93 -0
  50. package/dist/runtime.js +492 -0
  51. package/dist/runtime.js.map +1 -0
  52. package/dist/schema.d.ts +2 -0
  53. package/dist/schema.js +46 -0
  54. package/dist/schema.js.map +1 -0
  55. package/dist/types.d.ts +80 -0
  56. package/dist/types.js +2 -0
  57. package/dist/types.js.map +1 -0
  58. package/dist/webmcp.d.ts +2 -0
  59. package/dist/webmcp.js +73 -0
  60. package/dist/webmcp.js.map +1 -0
  61. package/package.json +26 -0
  62. package/src/browser/controller.ts +984 -0
  63. package/src/browser/dom.ts +507 -0
  64. package/src/browser/feedback.ts +5 -0
  65. package/src/browser/locator.ts +383 -0
  66. package/src/browser/prompt.generated.ts +50 -0
  67. package/src/browser/prompt.ts +10 -0
  68. package/src/browser/snapshot.ts +542 -0
  69. package/src/browser/toolset.ts +522 -0
  70. package/src/browser/types.ts +172 -0
  71. package/src/browser/worker-runner.ts +468 -0
  72. package/src/definition.ts +115 -0
  73. package/src/index.ts +35 -0
  74. package/src/internal-react.tsx +62 -0
  75. package/src/internal-types.ts +12 -0
  76. package/src/internal.ts +36 -0
  77. package/src/react.tsx +397 -0
  78. package/src/runtime.ts +722 -0
  79. package/src/schema.ts +52 -0
  80. package/src/types.ts +123 -0
  81. package/src/webmcp.ts +102 -0
  82. package/tsconfig.json +8 -0
@@ -0,0 +1,400 @@
1
+ export function createWorkerRuntimeSource(executionId, code) {
2
+ return `
3
+ const executionId = ${JSON.stringify(executionId)};
4
+ let requestId = 0;
5
+ let commandSeq = 0;
6
+ const pending = new Map();
7
+
8
+ self.onmessage = (event) => {
9
+ const message = event.data;
10
+ if (message.type !== "response") return;
11
+ const entry = pending.get(message.requestId);
12
+ if (!entry) return;
13
+ pending.delete(message.requestId);
14
+ if (message.response.ok) entry.resolve(message.response.value);
15
+ else {
16
+ const error = new Error(message.response.error?.message || "Page command failed");
17
+ error.code = message.response.error?.code || "PAGE_COMMAND_FAILED";
18
+ error.candidates = message.response.error?.candidates;
19
+ entry.reject(error);
20
+ }
21
+ };
22
+
23
+ function normalizeRPCValue(value) {
24
+ if (value instanceof RegExp) {
25
+ return { source: value.source, flags: value.flags };
26
+ }
27
+ if (
28
+ value === null ||
29
+ typeof value === "string" ||
30
+ typeof value === "boolean" ||
31
+ (typeof value === "number" && Number.isFinite(value))
32
+ ) {
33
+ return value;
34
+ }
35
+ if (Array.isArray(value)) return value.map(normalizeRPCValue);
36
+ if (value && typeof value === "object") {
37
+ const prototype = Object.getPrototypeOf(value);
38
+ if (prototype !== Object.prototype && prototype !== null) {
39
+ throw new Error("Page API arguments must be plain JSON values or RegExp.");
40
+ }
41
+ return Object.fromEntries(
42
+ Object.entries(value).map(([key, item]) => [key, normalizeRPCValue(item)])
43
+ );
44
+ }
45
+ throw new Error("Page API arguments contain an unsupported value.");
46
+ }
47
+
48
+ function normalizeResult(value, seen = new Set()) {
49
+ if (
50
+ value === null ||
51
+ typeof value === "string" ||
52
+ typeof value === "boolean" ||
53
+ (typeof value === "number" && Number.isFinite(value))
54
+ ) {
55
+ return value;
56
+ }
57
+ if (Array.isArray(value)) {
58
+ if (seen.has(value)) throw new Error("executeCode returned a cyclic value.");
59
+ seen.add(value);
60
+ const result = value.map((item) => normalizeResult(item, seen));
61
+ seen.delete(value);
62
+ return result;
63
+ }
64
+ if (value && typeof value === "object") {
65
+ const prototype = Object.getPrototypeOf(value);
66
+ if (prototype !== Object.prototype && prototype !== null) {
67
+ throw new Error("executeCode must return JSON-serializable data.");
68
+ }
69
+ if (seen.has(value)) throw new Error("executeCode returned a cyclic value.");
70
+ seen.add(value);
71
+ const result = Object.fromEntries(
72
+ Object.entries(value).map(([key, item]) => [key, normalizeResult(item, seen)])
73
+ );
74
+ seen.delete(value);
75
+ return result;
76
+ }
77
+ throw new Error("executeCode must return JSON-serializable data.");
78
+ }
79
+
80
+ function rpc(target, method, args) {
81
+ if (pending.size > 0) {
82
+ const error = new Error("Page API operations must be awaited sequentially.");
83
+ error.code = "CONCURRENT_PAGE_OPERATION";
84
+ throw error;
85
+ }
86
+ const id = ++requestId;
87
+ const command = {
88
+ executionId,
89
+ commandSeq: ++commandSeq,
90
+ target: normalizeRPCValue(target),
91
+ method,
92
+ args: normalizeRPCValue(args)
93
+ };
94
+ self.postMessage({ type: "command", requestId: id, command });
95
+ return new Promise((resolve, reject) =>
96
+ pending.set(id, { resolve, reject })
97
+ );
98
+ }
99
+
100
+ class Locator {
101
+ constructor(steps) { this.steps = steps; }
102
+ getByRole(role, options = {}) {
103
+ return new Locator([...this.steps, { kind: "role", role, options }]);
104
+ }
105
+ getByText(text, options = {}) {
106
+ return new Locator([...this.steps, { kind: "text", text, options }]);
107
+ }
108
+ getByLabel(text, options = {}) {
109
+ return new Locator([...this.steps, { kind: "label", text, options }]);
110
+ }
111
+ filter(options) {
112
+ return new Locator([...this.steps, { kind: "filter", hasText: options.hasText }]);
113
+ }
114
+ call(method, ...args) {
115
+ return rpc(
116
+ { type: "locator", locator: { steps: this.steps } },
117
+ method,
118
+ args
119
+ );
120
+ }
121
+ click() { return this.call("click"); }
122
+ fill(value) { return this.call("fill", value); }
123
+ press(key) { return this.call("press", key); }
124
+ check() { return this.call("check"); }
125
+ uncheck() { return this.call("uncheck"); }
126
+ selectOption(value) { return this.call("selectOption", value); }
127
+ hover() { return this.call("hover"); }
128
+ focus() { return this.call("focus"); }
129
+ blur() { return this.call("blur"); }
130
+ scrollBy(value) { return this.call("scrollBy", value); }
131
+ scrollTo(value) { return this.call("scrollTo", value); }
132
+ scrollIntoView() { return this.call("scrollIntoView"); }
133
+ exists() { return this.call("exists"); }
134
+ text() { return this.call("text"); }
135
+ waitFor(options = {}) { return this.call("waitFor", options); }
136
+ }
137
+
138
+ const uiTarget = Object.freeze({
139
+ ref: (ref) => {
140
+ if (typeof ref !== "string" || !/^@\\d+$/.test(ref)) {
141
+ throw new Error("ui.ref(ref) requires a Snapshot ref such as @12.");
142
+ }
143
+ return new LocatorProxy({ type: "ref", ref });
144
+ },
145
+ getByRole: (role, options = {}) =>
146
+ new Locator([{ kind: "role", role, options }]),
147
+ getByText: (text, options = {}) =>
148
+ new Locator([{ kind: "text", text, options }]),
149
+ getByLabel: (text, options = {}) =>
150
+ new Locator([{ kind: "label", text, options }]),
151
+ scrollBy: (value) => rpc({ type: "page" }, "scrollBy", [value]),
152
+ waitForTimeout: (ms) => rpc({ type: "page" }, "waitForTimeout", [ms]),
153
+ waitForURL: (url, options = {}) =>
154
+ rpc({ type: "page" }, "waitForURL", [url, options])
155
+ });
156
+ const ui = new Proxy(uiTarget, {
157
+ get(target, property, receiver) {
158
+ if (typeof property !== "string" || Object.hasOwn(target, property)) {
159
+ return Reflect.get(target, property, receiver);
160
+ }
161
+ const error = new Error(
162
+ 'UI API method "' + property + '" is not available. Supported methods: '
163
+ + Object.keys(uiTarget).join(", ") + "."
164
+ );
165
+ error.code = "UI_API_NOT_AVAILABLE";
166
+ throw error;
167
+ }
168
+ });
169
+
170
+ function LocatorProxy(target) {
171
+ this.target = target;
172
+ }
173
+ LocatorProxy.prototype.call = function(method, ...args) {
174
+ return rpc(this.target, method, args);
175
+ };
176
+ for (const method of [
177
+ "click",
178
+ "check",
179
+ "uncheck",
180
+ "hover",
181
+ "focus",
182
+ "blur",
183
+ "scrollIntoView",
184
+ "exists",
185
+ "text"
186
+ ]) {
187
+ LocatorProxy.prototype[method] = function() {
188
+ return this.call(method);
189
+ };
190
+ }
191
+ LocatorProxy.prototype.fill = function(value) { return this.call("fill", value); };
192
+ LocatorProxy.prototype.press = function(key) { return this.call("press", key); };
193
+ LocatorProxy.prototype.selectOption = function(value) {
194
+ return this.call("selectOption", value);
195
+ };
196
+ LocatorProxy.prototype.scrollBy = function(value) {
197
+ return this.call("scrollBy", value);
198
+ };
199
+ LocatorProxy.prototype.scrollTo = function(value) {
200
+ return this.call("scrollTo", value);
201
+ };
202
+ LocatorProxy.prototype.waitFor = function(options = {}) {
203
+ return this.call("waitFor", options);
204
+ };
205
+
206
+ (async () => {
207
+ try {
208
+ const rawResult = await (async () => {
209
+ ${code}
210
+ })();
211
+ if (pending.size > 0) {
212
+ const error = new Error("Every Page API operation must be awaited before executeCode returns.");
213
+ error.code = "UNAWAITED_PAGE_OPERATION";
214
+ throw error;
215
+ }
216
+ const hasValue = rawResult !== undefined;
217
+ const value = hasValue ? normalizeResult(rawResult) : undefined;
218
+ self.postMessage({ type: "done", hasValue, value });
219
+ } catch (error) {
220
+ self.postMessage({
221
+ type: "error",
222
+ error: {
223
+ code: error?.code || "CODE_EXECUTION_FAILED",
224
+ message: error?.message || String(error),
225
+ statement: error?.statement || error?.stack?.split("\\n")[1]?.trim()
226
+ }
227
+ });
228
+ }
229
+ })();`;
230
+ }
231
+ function validateJSONValue(value, maxChars) {
232
+ const serialized = JSON.stringify(value);
233
+ if (serialized === undefined) {
234
+ throw new Error("executeCode returned a non-JSON value.");
235
+ }
236
+ if (serialized.length > maxChars) {
237
+ throw new Error(`executeCode result exceeds ${maxChars} serialized characters.`);
238
+ }
239
+ return JSON.parse(serialized);
240
+ }
241
+ export class WorkerRunner {
242
+ controller;
243
+ limits;
244
+ active;
245
+ constructor(controller, limits) {
246
+ this.controller = controller;
247
+ this.limits = limits;
248
+ }
249
+ async execute(code, registry, maxDurationMs = this.limits.maxDurationMs) {
250
+ if (code.length > this.limits.maxCodeLength) {
251
+ return {
252
+ executionId: "rejected",
253
+ ok: false,
254
+ completedActions: [],
255
+ error: {
256
+ code: "CODE_TOO_LONG",
257
+ message: `Code exceeds ${this.limits.maxCodeLength} characters.`,
258
+ },
259
+ };
260
+ }
261
+ if (this.active && !this.active.settled) {
262
+ return {
263
+ executionId: "rejected",
264
+ ok: false,
265
+ completedActions: [],
266
+ error: {
267
+ code: "EXECUTION_IN_PROGRESS",
268
+ message: "Another executeCode call is still running.",
269
+ },
270
+ };
271
+ }
272
+ const executionId = crypto.randomUUID();
273
+ const source = createWorkerRuntimeSource(executionId, code);
274
+ const blob = new Blob([source], {
275
+ type: "text/javascript",
276
+ });
277
+ const objectUrl = URL.createObjectURL(blob);
278
+ const worker = new Worker(objectUrl, {
279
+ name: `nexface-${executionId}`,
280
+ });
281
+ this.controller.beginExecution(executionId, registry);
282
+ return new Promise((resolve) => {
283
+ const active = {
284
+ executionId,
285
+ worker,
286
+ objectUrl,
287
+ settled: false,
288
+ cancel: () => { },
289
+ };
290
+ this.active = active;
291
+ const settle = (partial) => {
292
+ if (active.settled)
293
+ return;
294
+ active.settled = true;
295
+ window.clearTimeout(timer);
296
+ worker.terminate();
297
+ URL.revokeObjectURL(objectUrl);
298
+ const receipt = this.controller.completeExecution(executionId);
299
+ if (this.active === active)
300
+ this.active = undefined;
301
+ resolve({
302
+ executionId,
303
+ ...partial,
304
+ completedActions: receipt.completedActions,
305
+ ...(receipt.failedCall ? { failedCall: receipt.failedCall } : {}),
306
+ });
307
+ };
308
+ active.cancel = () => {
309
+ this.controller.cancelExecution(executionId);
310
+ settle({
311
+ ok: false,
312
+ error: {
313
+ code: "EXECUTION_CANCELLED",
314
+ message: "Execution was cancelled.",
315
+ },
316
+ });
317
+ };
318
+ const timer = window.setTimeout(() => {
319
+ this.controller.cancelExecution(executionId);
320
+ settle({
321
+ ok: false,
322
+ error: {
323
+ code: "EXECUTION_TIMEOUT",
324
+ message: `Execution exceeded ${maxDurationMs}ms.`,
325
+ },
326
+ });
327
+ }, maxDurationMs);
328
+ worker.onmessage = async (event) => {
329
+ const message = event.data;
330
+ if (message.type === "command") {
331
+ let response = await this.controller.execute(message.command);
332
+ if (response.ok && response.value !== undefined) {
333
+ try {
334
+ response = {
335
+ ...response,
336
+ value: validateJSONValue(response.value, this.limits.maxResultChars),
337
+ };
338
+ }
339
+ catch (error) {
340
+ response = {
341
+ ok: false,
342
+ error: {
343
+ code: "RESULT_TOO_LARGE",
344
+ message: error instanceof Error ? error.message : String(error),
345
+ },
346
+ };
347
+ }
348
+ }
349
+ if (!active.settled) {
350
+ worker.postMessage({
351
+ type: "response",
352
+ requestId: message.requestId,
353
+ response,
354
+ });
355
+ }
356
+ return;
357
+ }
358
+ if (message.type === "done") {
359
+ if (!message.hasValue) {
360
+ settle({ ok: true });
361
+ return;
362
+ }
363
+ try {
364
+ settle({
365
+ ok: true,
366
+ value: validateJSONValue(message.value, this.limits.maxResultChars),
367
+ });
368
+ }
369
+ catch (error) {
370
+ settle({
371
+ ok: false,
372
+ error: {
373
+ code: "RESULT_INVALID",
374
+ message: error instanceof Error ? error.message : String(error),
375
+ },
376
+ });
377
+ }
378
+ return;
379
+ }
380
+ settle({ ok: false, error: message.error });
381
+ };
382
+ worker.onerror = (event) => {
383
+ settle({
384
+ ok: false,
385
+ error: {
386
+ code: "WORKER_ERROR",
387
+ message: event.message || "Worker execution failed.",
388
+ },
389
+ });
390
+ };
391
+ });
392
+ }
393
+ cancel() {
394
+ const active = this.active;
395
+ if (!active || active.settled)
396
+ return;
397
+ active.cancel();
398
+ }
399
+ }
400
+ //# sourceMappingURL=worker-runner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker-runner.js","sourceRoot":"","sources":["../../src/browser/worker-runner.ts"],"names":[],"mappings":"AA+BA,MAAM,UAAU,yBAAyB,CACvC,WAAmB,EACnB,IAAY;IAEZ,OAAO;sBACa,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8M/C,IAAI;;;;;;;;;;;;;;;;;;;;MAoBA,CA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oBACD,OAAO;gBACT,CAAC;gBACD,MAAM,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;YAC9C,CAAC,CAAC;YAEF,MAAM,CAAC,OAAO,GAAG,CAAC,KAAK,EAAE,EAAE;gBACzB,MAAM,CAAC;oBACL,EAAE,EAAE,KAAK;oBACT,KAAK,EAAE;wBACL,IAAI,EAAE,cAAc;wBACpB,OAAO,EAAE,KAAK,CAAC,OAAO,IAAI,0BAA0B;qBACrD;iBACF,CAAC,CAAC;YACL,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAED,MAAM;QACJ,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC3B,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,OAAO;YAAE,OAAO;QACtC,MAAM,CAAC,MAAM,EAAE,CAAC;IAClB,CAAC;CACF"}
@@ -0,0 +1,16 @@
1
+ import type { AgentToolDefinition, AgentToolInputSchema, InferJsonSchema } from "./types.js";
2
+ interface AgentToolMetadataInput {
3
+ name: string;
4
+ description: string;
5
+ }
6
+ export declare function isValidAgentContextName(name: string): boolean;
7
+ export declare function defineAgentTool<TResult = unknown>(metadata: AgentToolMetadataInput): AgentToolDefinition<Record<string, never>, TResult>;
8
+ export declare function defineAgentTool<TInput = never, TResult = unknown, const TSchema extends AgentToolInputSchema = AgentToolInputSchema>(metadata: AgentToolMetadataInput & {
9
+ inputSchema: TSchema;
10
+ }): AgentToolDefinition<[
11
+ TInput
12
+ ] extends [never] ? InferJsonSchema<TSchema> : TInput, TResult>;
13
+ export declare function defineSystemAgentTool<TInput, TResult>(metadata: AgentToolMetadataInput & {
14
+ inputSchema: AgentToolInputSchema;
15
+ }): AgentToolDefinition<TInput, TResult>;
16
+ export {};
@@ -0,0 +1,72 @@
1
+ const emptyInputSchema = Object.freeze({
2
+ type: "object",
3
+ properties: Object.freeze({}),
4
+ additionalProperties: false,
5
+ });
6
+ const agentNamePattern = /^[A-Za-z0-9_-]{1,64}$/;
7
+ const reservedContextNames = new Set([
8
+ "callAppTool",
9
+ "finish",
10
+ "getSnapshot",
11
+ "executeCode",
12
+ ]);
13
+ const reservedToolNames = new Set([
14
+ ...reservedContextNames,
15
+ "loadSkill",
16
+ ]);
17
+ export function isValidAgentContextName(name) {
18
+ return agentNamePattern.test(name) && !reservedContextNames.has(name);
19
+ }
20
+ function assertName(name) {
21
+ if (!agentNamePattern.test(name) || reservedToolNames.has(name)) {
22
+ throw new Error(`Invalid or reserved agent tool name: ${name}.`);
23
+ }
24
+ }
25
+ function assertSystemName(name) {
26
+ if (!agentNamePattern.test(name)) {
27
+ throw new Error(`Invalid system agent tool name: ${name}.`);
28
+ }
29
+ }
30
+ export function defineAgentTool(metadata) {
31
+ assertName(metadata.name);
32
+ if (!metadata.description.trim())
33
+ throw new Error("Tool description is required.");
34
+ const inputSchema = metadata.inputSchema ?? emptyInputSchema;
35
+ if (inputSchema.type !== "object") {
36
+ throw new Error("Tool inputSchema root type must be object.");
37
+ }
38
+ return freezeAgentToolDefinition({
39
+ ...metadata,
40
+ inputSchema,
41
+ });
42
+ }
43
+ export function defineSystemAgentTool(metadata) {
44
+ assertSystemName(metadata.name);
45
+ if (!metadata.description.trim()) {
46
+ throw new Error("Tool description is required.");
47
+ }
48
+ if (metadata.inputSchema.type !== "object") {
49
+ throw new Error("Tool inputSchema root type must be object.");
50
+ }
51
+ return freezeAgentToolDefinition(metadata);
52
+ }
53
+ function cloneAndFreeze(value) {
54
+ if (Array.isArray(value)) {
55
+ return Object.freeze(value.map(cloneAndFreeze));
56
+ }
57
+ if (value && typeof value === "object") {
58
+ return Object.freeze(Object.fromEntries(Object.entries(value).map(([key, item]) => [
59
+ key,
60
+ cloneAndFreeze(item),
61
+ ])));
62
+ }
63
+ return value;
64
+ }
65
+ function freezeAgentToolDefinition(definition) {
66
+ return Object.freeze({
67
+ name: definition.name,
68
+ description: definition.description,
69
+ inputSchema: cloneAndFreeze(definition.inputSchema),
70
+ });
71
+ }
72
+ //# sourceMappingURL=definition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"definition.js","sourceRoot":"","sources":["../src/definition.ts"],"names":[],"mappings":"AAMA,MAAM,gBAAgB,GAAyB,MAAM,CAAC,MAAM,CAAC;IAC3D,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;IAC7B,oBAAoB,EAAE,KAAK;CAC5B,CAAC,CAAC;AAOH,MAAM,gBAAgB,GAAG,uBAAuB,CAAC;AAEjD,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC;IACnC,aAAa;IACb,QAAQ;IACR,aAAa;IACb,aAAa;CACd,CAAC,CAAC;AAEH,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAC;IAChC,GAAG,oBAAoB;IACvB,WAAW;CACZ,CAAC,CAAC;AAEH,MAAM,UAAU,uBAAuB,CAAC,IAAY;IAClD,OAAO,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AACxE,CAAC;AAED,SAAS,UAAU,CAAC,IAAY;IAC9B,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,iBAAiB,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;QAChE,MAAM,IAAI,KAAK,CAAC,wCAAwC,IAAI,GAAG,CAAC,CAAC;IACnE,CAAC;AACH,CAAC;AAED,SAAS,gBAAgB,CAAC,IAAY;IACpC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACjC,MAAM,IAAI,KAAK,CAAC,mCAAmC,IAAI,GAAG,CAAC,CAAC;IAC9D,CAAC;AACH,CAAC;AAeD,MAAM,UAAU,eAAe,CAC7B,QAAyE;IAEzE,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC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CAAC;SACrB,CAAC,CACH,CAAM,CAAC;IACV,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,yBAAyB,CAIhC,UAAgD;IAEhD,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,IAAI,EAAE,UAAU,CAAC,IAAI;QACrB,WAAW,EAAE,UAAU,CAAC,WAAW;QACnC,WAAW,EAAE,cAAc,CAAC,UAAU,CAAC,WAAW,CAAC;KACpD,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,7 @@
1
+ export { defineAgentTool } from "./definition.js";
2
+ export { createToolRuntime, isToolRuntimeError, } from "./runtime.js";
3
+ export { AgentContext, AgentToolsProvider, AgentUIAction, useAgentContext, useAgentTool, } from "./react.js";
4
+ export type { AgentUIActionChildProps, AgentUIActionEvent, AgentUIActionProps, } from "./react.js";
5
+ export type { ToolRuntime, ToolRuntimeOptions, } from "./runtime.js";
6
+ export type { BrowserToolsConfig, BrowserToolsOptions, } from "./browser/toolset.js";
7
+ export type { AgentContextEntry, AgentContextValue, AgentToolDefinition, AgentToolExecutionContext, AgentToolExecutor, AgentToolInputSchema, InferJsonSchema, JsonSchema, } from "./types.js";
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export { defineAgentTool } from "./definition.js";
2
+ export { createToolRuntime, isToolRuntimeError, } from "./runtime.js";
3
+ export { AgentContext, AgentToolsProvider, AgentUIAction, useAgentContext, useAgentTool, } from "./react.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EACL,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,aAAa,EACb,eAAe,EACf,YAAY,GACb,MAAM,YAAY,CAAC"}
@@ -0,0 +1,12 @@
1
+ import { type ReactNode } from "react";
2
+ import { type ToolRuntime, type InternalToolRuntime } from "./runtime.js";
3
+ export interface InternalToolRuntimeHostProps {
4
+ children: ReactNode;
5
+ }
6
+ export declare function InternalToolRuntimeHost({ children, }: InternalToolRuntimeHostProps): import("react").JSX.Element;
7
+ export declare function InternalToolRuntimeScope({ children, runtime, }: {
8
+ children: ReactNode;
9
+ runtime: ToolRuntime;
10
+ }): import("react").JSX.Element;
11
+ export declare function useInternalToolRuntime(): InternalToolRuntime;
12
+ export declare function useOptionalInternalToolRuntime(): InternalToolRuntime | null;
@@ -0,0 +1,23 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext, useMemo, } from "react";
3
+ import { createToolRuntime, getInternalToolRuntime, } from "./runtime.js";
4
+ const InternalToolRuntimeContext = createContext(null);
5
+ export function InternalToolRuntimeHost({ children, }) {
6
+ const runtime = useMemo(() => createToolRuntime(), []);
7
+ return (_jsx(InternalToolRuntimeScope, { runtime: runtime, children: children }));
8
+ }
9
+ export function InternalToolRuntimeScope({ children, runtime, }) {
10
+ const internalRuntime = getInternalToolRuntime(runtime);
11
+ return (_jsx(InternalToolRuntimeContext.Provider, { value: internalRuntime, children: children }));
12
+ }
13
+ export function useInternalToolRuntime() {
14
+ const runtime = useContext(InternalToolRuntimeContext);
15
+ if (!runtime) {
16
+ throw new Error("Nexface components must be rendered inside AgentToolsProvider, AgentProvider, or ChatProvider.");
17
+ }
18
+ return runtime;
19
+ }
20
+ export function useOptionalInternalToolRuntime() {
21
+ return useContext(InternalToolRuntimeContext);
22
+ }
23
+ //# sourceMappingURL=internal-react.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal-react.js","sourceRoot":"","sources":["../src/internal-react.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,aAAa,EACb,UAAU,EACV,OAAO,GAER,MAAM,OAAO,CAAC;AAEf,OAAO,EACL,iBAAiB,EACjB,sBAAsB,GAGvB,MAAM,cAAc,CAAC;AAEtB,MAAM,0BAA0B,GAC9B,aAAa,CAA6B,IAAI,CAAC,CAAC;AAMlD,MAAM,UAAU,uBAAuB,CAAC,EACtC,QAAQ,GACqB;IAC7B,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,iBAAiB,EAAE,EAAE,EAAE,CAAC,CAAC;IACvD,OAAO,CACL,KAAC,wBAAwB,IAAC,OAAO,EAAE,OAAO,YACvC,QAAQ,GACgB,CAC5B,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,EACvC,QAAQ,EACR,OAAO,GAIR;IACC,MAAM,eAAe,GAAG,sBAAsB,CAAC,OAAO,CAAC,CAAC;IACxD,OAAO,CACL,KAAC,0BAA0B,CAAC,QAAQ,IAAC,KAAK,EAAE,eAAe,YACxD,QAAQ,GAC2B,CACvC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,sBAAsB;IACpC,MAAM,OAAO,GAAG,UAAU,CAAC,0BAA0B,CAAC,CAAC;IACvD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,gGAAgG,CACjG,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,8BAA8B;IAG5C,OAAO,UAAU,CAAC,0BAA0B,CAAC,CAAC;AAChD,CAAC"}
@@ -0,0 +1,11 @@
1
+ export type AgentToolExecutionStatus = "running" | "success" | "error";
2
+ export interface AgentToolExecutionEvent {
3
+ id: string;
4
+ name: string;
5
+ status: AgentToolExecutionStatus;
6
+ startedAt: number;
7
+ finishedAt?: number;
8
+ input: unknown;
9
+ result?: unknown;
10
+ error?: unknown;
11
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=internal-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal-types.js","sourceRoot":"","sources":["../src/internal-types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ export { AgentContextError, ToolRuntimeImplementation, ToolRuntimeImplementation as ToolRuntime, AgentToolError, createToolRuntime, getInternalToolRuntime, } from "./runtime.js";
2
+ export type { ToolRuntime as PublicToolRuntime, ToolRuntimeOptions, InternalToolRuntime, } from "./runtime.js";
3
+ export type { AgentToolExecutionEvent } from "./internal-types.js";
4
+ export { defineSystemAgentTool } from "./definition.js";
5
+ export { browserToolsAvailable, createBrowserToolset, executeCodeTool, getSnapshotTool, startPageTransitionTracker, } from "./browser/toolset.js";
6
+ export { BROWSER_TOOLS_SKILL, serializeBrowserToolsSkill, } from "./browser/prompt.js";
7
+ export type { BrowserToolHandler, BrowserToolsConfig, BrowserToolsOptions, BrowserToolset, PageTransitionSettleResult, PageTransitionTracker, } from "./browser/toolset.js";
8
+ export type * from "./browser/types.js";
9
+ export type { AgentContextRegistration } from "./types.js";
@@ -0,0 +1,5 @@
1
+ export { AgentContextError, ToolRuntimeImplementation, ToolRuntimeImplementation as ToolRuntime, AgentToolError, createToolRuntime, getInternalToolRuntime, } from "./runtime.js";
2
+ export { defineSystemAgentTool } from "./definition.js";
3
+ export { browserToolsAvailable, createBrowserToolset, executeCodeTool, getSnapshotTool, startPageTransitionTracker, } from "./browser/toolset.js";
4
+ export { BROWSER_TOOLS_SKILL, serializeBrowserToolsSkill, } from "./browser/prompt.js";
5
+ //# sourceMappingURL=internal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,yBAAyB,EACzB,yBAAyB,IAAI,WAAW,EACxC,cAAc,EACd,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,cAAc,CAAC;AAOtB,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,eAAe,EACf,eAAe,EACf,0BAA0B,GAC3B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,mBAAmB,EACnB,0BAA0B,GAC3B,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { type MouseEvent, type ReactElement, type ReactNode } from "react";
2
+ import type { ToolRuntime } from "./runtime.js";
3
+ import type { AgentContextEntry, AgentToolDefinition, AgentToolExecutor } from "./types.js";
4
+ export declare function useAgentTool<TInput, TResult>(definition: AgentToolDefinition<TInput, TResult>, execute: AgentToolExecutor<TInput, TResult>): void;
5
+ export declare function AgentToolsProvider({ children, toolRuntime, webMcp, }: {
6
+ children: ReactNode;
7
+ toolRuntime: ToolRuntime;
8
+ webMcp?: boolean;
9
+ }): import("react").JSX.Element;
10
+ export declare function useAgentContext(context: AgentContextEntry): void;
11
+ export declare function AgentContext(context: AgentContextEntry): null;
12
+ export type AgentUIActionEvent = "click";
13
+ type Awaitable<TResult> = TResult | Promise<TResult>;
14
+ export interface AgentUIActionChildProps<TResult = void> {
15
+ onClick: (event: MouseEvent<HTMLElement>) => Awaitable<TResult>;
16
+ disabled?: boolean;
17
+ }
18
+ export interface AgentUIActionProps<TResult = void> {
19
+ name: string;
20
+ description: string;
21
+ event?: AgentUIActionEvent;
22
+ children: ReactElement<AgentUIActionChildProps<TResult>>;
23
+ }
24
+ export declare function AgentUIAction<TResult = void>({ name, description, event, children, }: AgentUIActionProps<TResult>): ReactElement<AgentUIActionChildProps<TResult>, string | import("react").JSXElementConstructor<any>>;
25
+ export type { AgentContextValue, AgentToolDefinition, AgentToolExecutor, } from "./types.js";