@tpmjs/registry-execute 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -17,9 +17,23 @@ type RegistryExecuteInput = {
17
17
  * - TPMJS_EXECUTOR_URL: Sandbox executor (default: https://executor.tpmjs.com)
18
18
  */
19
19
  export declare const registryExecuteTool: import("ai").Tool<RegistryExecuteInput, {
20
+ error: boolean;
21
+ message: string;
22
+ toolId: string;
23
+ executionTimeMs?: undefined;
24
+ output?: undefined;
25
+ } | {
26
+ error: boolean;
27
+ message: any;
28
+ toolId: string;
29
+ executionTimeMs: any;
30
+ output?: undefined;
31
+ } | {
20
32
  toolId: string;
21
33
  executionTimeMs: any;
22
34
  output: any;
35
+ error?: undefined;
36
+ message?: undefined;
23
37
  }>;
24
38
  export {};
25
39
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,KAAK,oBAAoB,GAAG;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB;;;;EA+F9B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,KAAK,oBAAoB,GAAG;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC9B,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;EA4H9B,CAAC"}
package/dist/index.js CHANGED
@@ -37,59 +37,89 @@ export const registryExecuteTool = tool({
37
37
  additionalProperties: false,
38
38
  }),
39
39
  async execute({ toolId, params, env }) {
40
- // Parse toolId format: "package::name"
41
- const separatorIndex = toolId.lastIndexOf('::');
42
- if (separatorIndex === -1) {
43
- throw new Error(`Invalid toolId format. Expected "package::name", got "${toolId}"`);
40
+ try {
41
+ // Parse toolId format: "package::name"
42
+ const separatorIndex = toolId.lastIndexOf('::');
43
+ if (separatorIndex === -1) {
44
+ return {
45
+ error: true,
46
+ message: `Invalid toolId format. Expected "package::name", got "${toolId}"`,
47
+ toolId,
48
+ };
49
+ }
50
+ const packageName = toolId.substring(0, separatorIndex);
51
+ const name = toolId.substring(separatorIndex + 2);
52
+ if (!packageName || !name) {
53
+ return {
54
+ error: true,
55
+ message: `Invalid toolId format. Expected "package::name", got "${toolId}"`,
56
+ toolId,
57
+ };
58
+ }
59
+ // Fetch tool metadata to get version and importUrl
60
+ const metaParams = new URLSearchParams({
61
+ q: name,
62
+ limit: '10',
63
+ });
64
+ const metaResponse = await fetch(`${TPMJS_API_URL}/api/tools/search?${metaParams}`);
65
+ if (!metaResponse.ok) {
66
+ return {
67
+ error: true,
68
+ message: `Failed to fetch tool metadata: ${metaResponse.statusText}`,
69
+ toolId,
70
+ };
71
+ }
72
+ // biome-ignore lint/suspicious/noExplicitAny: API response types vary
73
+ const metaData = (await metaResponse.json());
74
+ const toolsArray = metaData.results?.tools || [];
75
+ // Find the exact tool match
76
+ // biome-ignore lint/suspicious/noExplicitAny: API response types vary
77
+ const toolMeta = toolsArray.find((t) => t.package.npmPackageName === packageName && t.name === name);
78
+ if (!toolMeta) {
79
+ return {
80
+ error: true,
81
+ message: `Tool not found: ${toolId}. Try using registrySearchTool to find available tools.`,
82
+ toolId,
83
+ };
84
+ }
85
+ const version = toolMeta.package.npmVersion;
86
+ const importUrl = `https://esm.sh/${packageName}@${version}`;
87
+ // Execute via sandbox executor
88
+ const response = await fetch(`${TPMJS_EXECUTOR_URL}/execute-tool`, {
89
+ method: 'POST',
90
+ headers: { 'Content-Type': 'application/json' },
91
+ body: JSON.stringify({
92
+ packageName,
93
+ name,
94
+ version,
95
+ importUrl,
96
+ params,
97
+ env: env || {},
98
+ }),
99
+ });
100
+ // biome-ignore lint/suspicious/noExplicitAny: API response types vary
101
+ const result = (await response.json());
102
+ if (!result.success) {
103
+ return {
104
+ error: true,
105
+ message: result.error || 'Tool execution failed',
106
+ toolId,
107
+ executionTimeMs: result.executionTimeMs,
108
+ };
109
+ }
110
+ return {
111
+ toolId,
112
+ executionTimeMs: result.executionTimeMs,
113
+ output: result.output,
114
+ };
44
115
  }
45
- const packageName = toolId.substring(0, separatorIndex);
46
- const name = toolId.substring(separatorIndex + 2);
47
- if (!packageName || !name) {
48
- throw new Error(`Invalid toolId format. Expected "package::name", got "${toolId}"`);
116
+ catch (error) {
117
+ return {
118
+ error: true,
119
+ message: error instanceof Error ? error.message : 'Unknown execution error',
120
+ toolId,
121
+ };
49
122
  }
50
- // Fetch tool metadata to get version and importUrl
51
- const metaParams = new URLSearchParams({
52
- q: name,
53
- limit: '10',
54
- });
55
- const metaResponse = await fetch(`${TPMJS_API_URL}/api/tools/search?${metaParams}`);
56
- if (!metaResponse.ok) {
57
- throw new Error(`Failed to fetch tool metadata: ${metaResponse.statusText}`);
58
- }
59
- // biome-ignore lint/suspicious/noExplicitAny: API response types vary
60
- const metaData = (await metaResponse.json());
61
- const toolsArray = metaData.results?.tools || [];
62
- // Find the exact tool match
63
- // biome-ignore lint/suspicious/noExplicitAny: API response types vary
64
- const toolMeta = toolsArray.find((t) => t.package.npmPackageName === packageName && t.name === name);
65
- if (!toolMeta) {
66
- throw new Error(`Tool not found: ${toolId}`);
67
- }
68
- const version = toolMeta.package.npmVersion;
69
- const importUrl = `https://esm.sh/${packageName}@${version}`;
70
- // Execute via sandbox executor
71
- const response = await fetch(`${TPMJS_EXECUTOR_URL}/execute-tool`, {
72
- method: 'POST',
73
- headers: { 'Content-Type': 'application/json' },
74
- body: JSON.stringify({
75
- packageName,
76
- name,
77
- version,
78
- importUrl,
79
- params,
80
- env: env || {},
81
- }),
82
- });
83
- // biome-ignore lint/suspicious/noExplicitAny: API response types vary
84
- const result = (await response.json());
85
- if (!result.success) {
86
- throw new Error(result.error || 'Tool execution failed');
87
- }
88
- return {
89
- toolId,
90
- executionTimeMs: result.executionTimeMs,
91
- output: result.output,
92
- };
93
123
  },
94
124
  });
95
125
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAEtC,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI,mBAAmB,CAAC;AACvE,MAAM,kBAAkB,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,4BAA4B,CAAC;AAW1F;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,CAAC;IACtC,WAAW,EACT,yHAAyH;IAC3H,WAAW,EAAE,UAAU,CAAuB;QAC5C,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,MAAM,EAAE;gBACN,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,mEAAmE;aACjF;YACD,MAAM,EAAE;gBACN,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,gCAAgC;gBAC7C,oBAAoB,EAAE,IAAI;aAC3B;YACD,GAAG,EAAE;gBACH,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,0DAA0D;gBACvE,oBAAoB,EAAE;oBACpB,IAAI,EAAE,QAAQ;iBACf;aACF;SACF;QACD,QAAQ,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC;QAC9B,oBAAoB,EAAE,KAAK;KAC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C,SAAS,CAAC;oBACnB,WAAW;oBACX,IAAI;oBACJ,OAAO;oBACP,SAAS;oBACT,MAAM;oBACN,GAAG,EAAE,GAAG,IAAI,EAAE;iBACf,CAAC;aACH,CAAC,CAAC;YAEH,sEAAsE;YACtE,MAAM,MAAM,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAQ,CAAC;YAE9C,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;gBACpB,OAAO;oBACL,KAAK,EAAE,IAAI;oBACX,OAAO,EAAE,MAAM,CAAC,KAAK,IAAI,uBAAuB;oBAChD,MAAM;oBACN,eAAe,EAAE,MAAM,CAAC,eAAe;iBACxC,CAAC;YACJ,CAAC;YAED,OAAO;gBACL,MAAM;gBACN,eAAe,EAAE,MAAM,CAAC,eAAe;gBACvC,MAAM,EAAE,MAAM,CAAC,MAAM;aACtB,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO;gBACL,KAAK,EAAE,IAAI;gBACX,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,yBAAyB;gBAC3E,MAAM;aACP,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tpmjs/registry-execute",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Execute tools from the TPMJS registry in any AI SDK agent",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",