@vgai/sdk 0.4.1-canary.20260715.0 → 0.4.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/package.json +4 -3
- package/src/errors.ts +19 -0
- package/src/index.ts +12 -0
- package/src/registry.ts +2 -2
- package/src/tools.ts +24 -0
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@vgai/sdk",
|
|
3
3
|
"author": "Volter AI, Inc.",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
|
-
"version": "0.4.1
|
|
5
|
+
"version": "0.4.1",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -17,10 +17,11 @@
|
|
|
17
17
|
],
|
|
18
18
|
"exports": {
|
|
19
19
|
".": "./src/index.ts",
|
|
20
|
-
"./registry": "./src/registry.ts"
|
|
20
|
+
"./registry": "./src/registry.ts",
|
|
21
|
+
"./tools": "./src/tools.ts"
|
|
21
22
|
},
|
|
22
23
|
"dependencies": {
|
|
23
|
-
"@vgai/engine": "0.4.1
|
|
24
|
+
"@vgai/engine": "0.4.1",
|
|
24
25
|
"playwright": "^1.58.2",
|
|
25
26
|
"zod": "^4.3.6"
|
|
26
27
|
}
|
package/src/errors.ts
CHANGED
|
@@ -41,6 +41,13 @@ export interface StructuredOperationError {
|
|
|
41
41
|
data?: unknown;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
/**
|
|
45
|
+
* A global brand keeps expected errors recognizable across separately loaded
|
|
46
|
+
* copies of @vgai/sdk (for example, an editor host dispatching a standalone
|
|
47
|
+
* project's tool). `instanceof` alone cannot cross that package boundary.
|
|
48
|
+
*/
|
|
49
|
+
export const OPERATION_ERROR_BRAND = Symbol.for('@vgai/sdk.OperationError');
|
|
50
|
+
|
|
44
51
|
/**
|
|
45
52
|
* The only way an operation `impl` should signal an EXPECTED, contractual
|
|
46
53
|
* failure (as opposed to an unexpected bug/exception). `code` must be one
|
|
@@ -51,6 +58,7 @@ export interface StructuredOperationError {
|
|
|
51
58
|
* `normalizeThrown`).
|
|
52
59
|
*/
|
|
53
60
|
export class OperationError extends Error {
|
|
61
|
+
readonly [OPERATION_ERROR_BRAND] = true;
|
|
54
62
|
readonly code: string;
|
|
55
63
|
readonly data: unknown;
|
|
56
64
|
|
|
@@ -62,6 +70,17 @@ export class OperationError extends Error {
|
|
|
62
70
|
}
|
|
63
71
|
}
|
|
64
72
|
|
|
73
|
+
export function isOperationError(value: unknown): value is OperationError {
|
|
74
|
+
if (value instanceof OperationError) return true;
|
|
75
|
+
if (value === null || typeof value !== 'object') return false;
|
|
76
|
+
const candidate = value as Record<PropertyKey, unknown>;
|
|
77
|
+
return (
|
|
78
|
+
candidate[OPERATION_ERROR_BRAND] === true &&
|
|
79
|
+
typeof candidate['code'] === 'string' &&
|
|
80
|
+
typeof candidate['message'] === 'string'
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
65
84
|
/** Reduce a `ZodError`'s issues to the structured, serializable shape above. */
|
|
66
85
|
export function toStructuredIssues(issues: readonly z.ZodIssue[]): StructuredIssue[] {
|
|
67
86
|
return issues.map((issue) => ({
|
package/src/index.ts
CHANGED
|
@@ -27,6 +27,18 @@ export {
|
|
|
27
27
|
type OperationSummary,
|
|
28
28
|
} from './registry.js';
|
|
29
29
|
export * from './render/index.js';
|
|
30
|
+
export type {
|
|
31
|
+
ToolContext,
|
|
32
|
+
ToolDefinition,
|
|
33
|
+
ToolErrorDefinition,
|
|
34
|
+
ToolHost,
|
|
35
|
+
ToolOutcome,
|
|
36
|
+
ToolPermission,
|
|
37
|
+
ToolPermissionRisk,
|
|
38
|
+
ToolRequirements,
|
|
39
|
+
ToolSummary,
|
|
40
|
+
} from './tools.js';
|
|
41
|
+
export { defineTool, ToolError, ToolRegistry } from './tools.js';
|
|
30
42
|
export {
|
|
31
43
|
type ExecutionHost,
|
|
32
44
|
type ExecutionRequirements,
|
package/src/registry.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { z } from 'zod';
|
|
2
2
|
import {
|
|
3
3
|
CORE_ERROR_CODES,
|
|
4
|
-
|
|
4
|
+
isOperationError,
|
|
5
5
|
type StructuredOperationError,
|
|
6
6
|
toStructuredIssues,
|
|
7
7
|
} from './errors.js';
|
|
@@ -141,7 +141,7 @@ export type OperationOutcome<TResult = unknown> =
|
|
|
141
141
|
* the identifying `code`.
|
|
142
142
|
*/
|
|
143
143
|
function normalizeThrown(def: OperationDefinition, err: unknown): StructuredOperationError {
|
|
144
|
-
if (err
|
|
144
|
+
if (isOperationError(err)) {
|
|
145
145
|
const declared = def.errors.find((e) => e.code === err.code);
|
|
146
146
|
if (!declared) {
|
|
147
147
|
return {
|
package/src/tools.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public project-tool contract.
|
|
3
|
+
*
|
|
4
|
+
* A tool is an ordinary registered JavaScript/TypeScript function. The SDK's
|
|
5
|
+
* operation registry remains the internal validated dispatcher used by every
|
|
6
|
+
* projection, but projects should not need a second public ontology merely
|
|
7
|
+
* because the host calls their function through a transport.
|
|
8
|
+
*/
|
|
9
|
+
export { OperationError as ToolError } from './errors.js';
|
|
10
|
+
export {
|
|
11
|
+
defineOperation as defineTool,
|
|
12
|
+
type ErrorDefinition as ToolErrorDefinition,
|
|
13
|
+
type OperationDefinition as ToolDefinition,
|
|
14
|
+
type OperationOutcome as ToolOutcome,
|
|
15
|
+
OperationRegistry as ToolRegistry,
|
|
16
|
+
type OperationSummary as ToolSummary,
|
|
17
|
+
} from './registry.js';
|
|
18
|
+
export type {
|
|
19
|
+
ExecutionHost as ToolHost,
|
|
20
|
+
ExecutionRequirements as ToolRequirements,
|
|
21
|
+
OperationContext as ToolContext,
|
|
22
|
+
PermissionMetadata as ToolPermission,
|
|
23
|
+
PermissionRisk as ToolPermissionRisk,
|
|
24
|
+
} from './types.js';
|