stitchkit 0.42.0 → 0.43.1
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 +22 -5
- package/dist/browser/client.d.ts.map +1 -1
- package/dist/browser/http.d.ts +2 -1
- package/dist/browser/http.d.ts.map +1 -1
- package/dist/browser/request-id.d.ts +3 -0
- package/dist/browser/request-id.d.ts.map +1 -0
- package/dist/cli.js +1 -1
- package/dist/contract/factory.d.ts +29 -2
- package/dist/contract/factory.d.ts.map +1 -1
- package/dist/contract/index.d.ts +1 -1
- package/dist/contract/index.d.ts.map +1 -1
- package/dist/contract/index.js +1 -1
- package/dist/{index-181aebw8.js → index-esqmem78.js} +100 -66
- package/dist/{index-p9vkwns1.js → index-h2wdcsby.js} +93 -15
- package/dist/{index-11x5dts2.js → index-r6czv7yt.js} +14 -9
- package/dist/index.js +16 -7
- package/dist/node.js +1 -1
- package/dist/observability/audit.d.ts +27 -15
- package/dist/observability/audit.d.ts.map +1 -1
- package/dist/observability/event.d.ts +2 -2
- package/dist/observability/index.d.ts +4 -4
- package/dist/observability/index.d.ts.map +1 -1
- package/dist/observability/index.js +69 -58
- package/dist/server/create.d.ts.map +1 -1
- package/dist/server/index.js +1 -1
- package/dist/server/logger.d.ts +0 -1
- package/dist/server/logger.d.ts.map +1 -1
- package/dist/server/types.d.ts +8 -13
- package/dist/server/types.d.ts.map +1 -1
- package/dist/tools/flatten-join.d.ts.map +1 -1
- package/dist/tools/runtime-tool.d.ts +31 -0
- package/dist/tools/runtime-tool.d.ts.map +1 -1
- package/dist/tools.d.ts +1 -1
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +52 -4
- package/llms-full.txt +272 -88
- package/llms.txt +1 -0
- package/package.json +2 -2
package/dist/tools.js
CHANGED
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
toolErrorFromResult,
|
|
26
26
|
toolResultFromError,
|
|
27
27
|
writeDownload
|
|
28
|
-
} from "./index-
|
|
28
|
+
} from "./index-h2wdcsby.js";
|
|
29
29
|
import {
|
|
30
30
|
toJsonSchema
|
|
31
31
|
} from "./index-frfyw9fa.js";
|
|
@@ -51,6 +51,43 @@ function defineRuntimeTool(definition) {
|
|
|
51
51
|
}
|
|
52
52
|
return definition;
|
|
53
53
|
}
|
|
54
|
+
function createRuntimeToolFactory(config) {
|
|
55
|
+
function parseContext(context) {
|
|
56
|
+
const parsed = config.context.parse(context);
|
|
57
|
+
return { ...parsed, params: undefined, input: context.input };
|
|
58
|
+
}
|
|
59
|
+
function define(definition) {
|
|
60
|
+
if (definition.output !== undefined) {
|
|
61
|
+
const { action: action2, method: method2, meta: meta2, handler: handler2, ...tool2 } = definition;
|
|
62
|
+
const identity2 = {
|
|
63
|
+
serviceName: config.serviceName,
|
|
64
|
+
action: action2,
|
|
65
|
+
method: method2,
|
|
66
|
+
...config.scope !== undefined && { scope: config.scope },
|
|
67
|
+
...(meta2 ?? config.meta) !== undefined && { meta: meta2 ?? config.meta }
|
|
68
|
+
};
|
|
69
|
+
return defineRuntimeTool({
|
|
70
|
+
...tool2,
|
|
71
|
+
identity: identity2,
|
|
72
|
+
handler: (context) => handler2(parseContext(context))
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
const { action, method, meta, handler, ...tool } = definition;
|
|
76
|
+
const identity = {
|
|
77
|
+
serviceName: config.serviceName,
|
|
78
|
+
action,
|
|
79
|
+
method,
|
|
80
|
+
...config.scope !== undefined && { scope: config.scope },
|
|
81
|
+
...(meta ?? config.meta) !== undefined && { meta: meta ?? config.meta }
|
|
82
|
+
};
|
|
83
|
+
return defineRuntimeTool({
|
|
84
|
+
...tool,
|
|
85
|
+
identity,
|
|
86
|
+
handler: (context) => handler(parseContext(context))
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
return { define };
|
|
90
|
+
}
|
|
54
91
|
function runtimeToolSupports(definition, transport) {
|
|
55
92
|
if (definition.transports?.length === 0) {
|
|
56
93
|
throw new Error(`Runtime tool "${definition.name}" must expose at least one transport`);
|
|
@@ -1550,17 +1587,27 @@ function joinClientBaseUrl(baseUrl, relativeUrl) {
|
|
|
1550
1587
|
|
|
1551
1588
|
// src/browser/http.ts
|
|
1552
1589
|
import ky, { isHTTPError } from "ky";
|
|
1590
|
+
|
|
1591
|
+
// src/browser/request-id.ts
|
|
1592
|
+
var REQUEST_ID_HEADER = "x-request-id";
|
|
1593
|
+
function responseTraceId(response) {
|
|
1594
|
+
return response?.headers.get(REQUEST_ID_HEADER) ?? undefined;
|
|
1595
|
+
}
|
|
1596
|
+
|
|
1597
|
+
// src/browser/http.ts
|
|
1553
1598
|
class ApiError extends Error {
|
|
1554
1599
|
code;
|
|
1555
1600
|
status;
|
|
1556
1601
|
details;
|
|
1557
1602
|
hint;
|
|
1558
|
-
|
|
1603
|
+
traceId;
|
|
1604
|
+
constructor(code, status = 0, details, message, hint, traceId) {
|
|
1559
1605
|
super(message ?? `API Error: ${code}`);
|
|
1560
1606
|
this.code = code;
|
|
1561
1607
|
this.status = status;
|
|
1562
1608
|
this.details = details;
|
|
1563
1609
|
this.hint = hint;
|
|
1610
|
+
this.traceId = traceId;
|
|
1564
1611
|
this.name = "ApiError";
|
|
1565
1612
|
}
|
|
1566
1613
|
static is(error) {
|
|
@@ -1721,9 +1768,9 @@ async function throwForErrorResponse(res, config, fallbackBody) {
|
|
|
1721
1768
|
config.onError?.(res.status, body);
|
|
1722
1769
|
const parsed = parseApiErrorBody(body);
|
|
1723
1770
|
if (parsed) {
|
|
1724
|
-
throw new ApiError(parsed.code, res.status, parsed.details, parsed.message, parsed.hint);
|
|
1771
|
+
throw new ApiError(parsed.code, res.status, parsed.details, parsed.message, parsed.hint, responseTraceId(res));
|
|
1725
1772
|
}
|
|
1726
|
-
throw new ApiError("HTTP_ERROR", res.status, { body });
|
|
1773
|
+
throw new ApiError("HTTP_ERROR", res.status, { body }, undefined, undefined, responseTraceId(res));
|
|
1727
1774
|
}
|
|
1728
1775
|
|
|
1729
1776
|
// src/tools/remote.ts
|
|
@@ -2034,6 +2081,7 @@ export {
|
|
|
2034
2081
|
createToolLogger,
|
|
2035
2082
|
createToolInvoker,
|
|
2036
2083
|
createStdioMcpServer,
|
|
2084
|
+
createRuntimeToolFactory,
|
|
2037
2085
|
createMcpHandler,
|
|
2038
2086
|
createCli,
|
|
2039
2087
|
collectTools,
|