@aprovan/stitchery 0.1.0-dev.6bd527d → 0.1.0-dev.f456953
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/.turbo/turbo-build.log +17 -17
- package/dist/cli.cjs +4 -7
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +4 -7
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +3 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/server/index.cjs +3 -2
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.js +3 -2
- package/dist/server/index.js.map +1 -1
- package/package.json +2 -2
- package/src/cli.ts +34 -38
- package/src/prompts.ts +2 -1
- package/src/server/services.ts +27 -27
package/src/server/services.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* Provides unified interface for calling services and exposing metadata.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
import { jsonSchema, type Tool } from
|
|
11
|
+
import { jsonSchema, type Tool } from "ai";
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Service backend interface - abstracts service call mechanisms
|
|
@@ -70,7 +70,7 @@ export class ServiceRegistry {
|
|
|
70
70
|
this.tools.set(name, tool);
|
|
71
71
|
|
|
72
72
|
// Parse namespace and procedure from the full name using '.' separator
|
|
73
|
-
const dotIndex = name.indexOf(
|
|
73
|
+
const dotIndex = name.indexOf(".");
|
|
74
74
|
const ns = dotIndex > 0 ? name.substring(0, dotIndex) : name;
|
|
75
75
|
const procedure = dotIndex > 0 ? name.substring(dotIndex + 1) : name;
|
|
76
76
|
|
|
@@ -103,7 +103,7 @@ export class ServiceRegistry {
|
|
|
103
103
|
const tool: Tool = {
|
|
104
104
|
description: info.description,
|
|
105
105
|
inputSchema: jsonSchema(
|
|
106
|
-
info.parameters ?? { type:
|
|
106
|
+
info.parameters ?? { type: "object", properties: {} },
|
|
107
107
|
),
|
|
108
108
|
execute: async (args: unknown) => {
|
|
109
109
|
return backend.call(info.namespace, info.procedure, [args]);
|
|
@@ -127,25 +127,25 @@ export class ServiceRegistry {
|
|
|
127
127
|
|
|
128
128
|
const params = Object.entries(props)
|
|
129
129
|
.map(([key, val]) => {
|
|
130
|
-
const optional = !required.includes(key) ?
|
|
130
|
+
const optional = !required.includes(key) ? "?" : "";
|
|
131
131
|
const type =
|
|
132
|
-
val.type ===
|
|
133
|
-
?
|
|
134
|
-
: val.type ===
|
|
135
|
-
?
|
|
136
|
-
: val.type ===
|
|
137
|
-
?
|
|
138
|
-
: val.type ===
|
|
139
|
-
?
|
|
140
|
-
:
|
|
141
|
-
const comment = val.description ? ` // ${val.description}` :
|
|
132
|
+
val.type === "number"
|
|
133
|
+
? "number"
|
|
134
|
+
: val.type === "boolean"
|
|
135
|
+
? "boolean"
|
|
136
|
+
: val.type === "array"
|
|
137
|
+
? "unknown[]"
|
|
138
|
+
: val.type === "object"
|
|
139
|
+
? "Record<string, unknown>"
|
|
140
|
+
: "string";
|
|
141
|
+
const comment = val.description ? ` // ${val.description}` : "";
|
|
142
142
|
return ` ${key}${optional}: ${type};${comment}`;
|
|
143
143
|
})
|
|
144
|
-
.join(
|
|
144
|
+
.join("\n");
|
|
145
145
|
|
|
146
146
|
return `interface ${name.replace(
|
|
147
147
|
/[^a-zA-Z0-9]/g,
|
|
148
|
-
|
|
148
|
+
"_",
|
|
149
149
|
)}Args {\n${params}\n}`;
|
|
150
150
|
}
|
|
151
151
|
|
|
@@ -154,7 +154,7 @@ export class ServiceRegistry {
|
|
|
154
154
|
* OpenAI-compatible APIs require tool names to match ^[a-zA-Z0-9_-]+$
|
|
155
155
|
*/
|
|
156
156
|
private toLLMToolName(internalName: string): string {
|
|
157
|
-
return internalName.replace(/\./g,
|
|
157
|
+
return internalName.replace(/\./g, "_");
|
|
158
158
|
}
|
|
159
159
|
|
|
160
160
|
/**
|
|
@@ -169,11 +169,11 @@ export class ServiceRegistry {
|
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
171
|
// Fallback: convert first underscore to dot
|
|
172
|
-
const underscoreIndex = llmName.indexOf(
|
|
172
|
+
const underscoreIndex = llmName.indexOf("_");
|
|
173
173
|
if (underscoreIndex > 0) {
|
|
174
174
|
return (
|
|
175
175
|
llmName.substring(0, underscoreIndex) +
|
|
176
|
-
|
|
176
|
+
"." +
|
|
177
177
|
llmName.substring(underscoreIndex + 1)
|
|
178
178
|
);
|
|
179
179
|
}
|
|
@@ -231,7 +231,7 @@ export class ServiceRegistry {
|
|
|
231
231
|
.map((info) => {
|
|
232
232
|
const searchText = `${info.name} ${info.namespace} ${
|
|
233
233
|
info.procedure
|
|
234
|
-
} ${info.description ??
|
|
234
|
+
} ${info.description ?? ""}`.toLowerCase();
|
|
235
235
|
const matchCount = keywords.filter((kw) =>
|
|
236
236
|
searchText.includes(kw),
|
|
237
237
|
).length;
|
|
@@ -304,7 +304,7 @@ export class ServiceRegistry {
|
|
|
304
304
|
this.tools.keys(),
|
|
305
305
|
)
|
|
306
306
|
.slice(0, 10)
|
|
307
|
-
.join(
|
|
307
|
+
.join(", ")}`,
|
|
308
308
|
);
|
|
309
309
|
}
|
|
310
310
|
|
|
@@ -342,7 +342,7 @@ export class ServiceRegistry {
|
|
|
342
342
|
*/
|
|
343
343
|
export function generateServicesPrompt(registry: ServiceRegistry): string {
|
|
344
344
|
const namespaces = registry.getNamespaces();
|
|
345
|
-
if (namespaces.length === 0) return
|
|
345
|
+
if (namespaces.length === 0) return "";
|
|
346
346
|
|
|
347
347
|
const services = registry.getServiceInfo();
|
|
348
348
|
const byNamespace = new Map<string, ServiceToolInfo[]>();
|
|
@@ -353,7 +353,7 @@ export function generateServicesPrompt(registry: ServiceRegistry): string {
|
|
|
353
353
|
byNamespace.set(service.namespace, existing);
|
|
354
354
|
}
|
|
355
355
|
|
|
356
|
-
let prompt = `##
|
|
356
|
+
let prompt = `## Services\n\nThe following services are available for generated widgets to call:\n\n`;
|
|
357
357
|
|
|
358
358
|
for (const [ns, tools] of byNamespace) {
|
|
359
359
|
prompt += `### \`${ns}\`\n`;
|
|
@@ -362,16 +362,16 @@ export function generateServicesPrompt(registry: ServiceRegistry): string {
|
|
|
362
362
|
if (tool.description) {
|
|
363
363
|
prompt += `: ${tool.description}`;
|
|
364
364
|
}
|
|
365
|
-
prompt +=
|
|
365
|
+
prompt += "\n";
|
|
366
366
|
}
|
|
367
|
-
prompt +=
|
|
367
|
+
prompt += "\n";
|
|
368
368
|
}
|
|
369
369
|
|
|
370
370
|
prompt += `**Usage in widgets:**
|
|
371
371
|
\`\`\`tsx
|
|
372
372
|
// Services are available as global namespaces
|
|
373
|
-
const result = await ${namespaces[0] ??
|
|
374
|
-
byNamespace.get(namespaces[0] ??
|
|
373
|
+
const result = await ${namespaces[0] ?? "service"}.${
|
|
374
|
+
byNamespace.get(namespaces[0] ?? "")?.[0]?.procedure ?? "example"
|
|
375
375
|
}({ /* args */ });
|
|
376
376
|
\`\`\`
|
|
377
377
|
|