@voyant-travel/max-sdk 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.
- package/README.md +131 -0
- package/dist/cards.d.ts +1141 -0
- package/dist/cards.d.ts.map +1 -0
- package/dist/cards.js +462 -0
- package/dist/define-tool.d.ts +32 -0
- package/dist/define-tool.d.ts.map +1 -0
- package/dist/define-tool.js +37 -0
- package/dist/handler.d.ts +32 -0
- package/dist/handler.d.ts.map +1 -0
- package/dist/handler.js +108 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/manifest.d.ts +25 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/manifest.js +40 -0
- package/dist/types.d.ts +101 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/package.json +47 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { type AgentCard, type AgentCardKind, type Block, extractCard, parseCard, } from "./cards.js";
|
|
2
|
+
export { defineTool, file } from "./define-tool.js";
|
|
3
|
+
export { type CreateHandlerOptions, createMaxToolsHandler } from "./handler.js";
|
|
4
|
+
export { type ManifestOptions, toManifest, toToolDefinition } from "./manifest.js";
|
|
5
|
+
export type { MaxTool, RemoteToolDefinition, RemoteToolsConfig, ToolCallContext, ToolConfig, ToolExample, ToolFileResult, ToolHandler, ToolTier, WithCard, } from "./types.js";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,KAAK,EACV,WAAW,EACX,SAAS,GACV,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,EAAE,KAAK,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAA;AAC/E,OAAO,EAAE,KAAK,eAAe,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAClF,YAAY,EACV,OAAO,EACP,oBAAoB,EACpB,iBAAiB,EACjB,eAAe,EACf,UAAU,EACV,WAAW,EACX,cAAc,EACd,WAAW,EACX,QAAQ,EACR,QAAQ,GACT,MAAM,YAAY,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// The generative-UI card contract — optional. Tools can attach a `card` to
|
|
2
|
+
// their result to render a rich widget instead of plain JSON.
|
|
3
|
+
export { extractCard, parseCard, } from "./cards.js";
|
|
4
|
+
export { defineTool, file } from "./define-tool.js";
|
|
5
|
+
export { createMaxToolsHandler } from "./handler.js";
|
|
6
|
+
export { toManifest, toToolDefinition } from "./manifest.js";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { MaxTool, RemoteToolDefinition, RemoteToolsConfig } from "./types.js";
|
|
2
|
+
/** Convert a single tool into its manifest (wire) definition. */
|
|
3
|
+
export declare function toToolDefinition(tool: MaxTool): RemoteToolDefinition;
|
|
4
|
+
export type ManifestOptions = {
|
|
5
|
+
/** Manifest version string. Defaults to `"1"`. */
|
|
6
|
+
version?: string;
|
|
7
|
+
/** Public base URL Voyant should call your tools at. */
|
|
8
|
+
callBaseUrl?: string;
|
|
9
|
+
/** Header Voyant sends the auth token in. Defaults to `Authorization`. */
|
|
10
|
+
authHeaderName?: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Build the manifest you register with Voyant from a set of tools. Each tool's
|
|
14
|
+
* Zod schema is converted to JSON Schema for the model.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const manifest = toManifest([lookupBooking, createQuote], {
|
|
19
|
+
* callBaseUrl: "https://acme.example.com",
|
|
20
|
+
* })
|
|
21
|
+
* // -> register `manifest` with Voyant for your operator
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function toManifest(tools: readonly MaxTool[], options?: ManifestOptions): RemoteToolsConfig;
|
|
25
|
+
//# sourceMappingURL=manifest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../src/manifest.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAElF,iEAAiE;AACjE,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,OAAO,GAAG,oBAAoB,CAWpE;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,kDAAkD;IAClD,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,wDAAwD;IACxD,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,0EAA0E;IAC1E,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB,CAAA;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE,SAAS,OAAO,EAAE,EACzB,OAAO,GAAE,eAAoB,GAC5B,iBAAiB,CAOnB"}
|
package/dist/manifest.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** Convert a single tool into its manifest (wire) definition. */
|
|
3
|
+
export function toToolDefinition(tool) {
|
|
4
|
+
return {
|
|
5
|
+
name: tool.name,
|
|
6
|
+
description: tool.description,
|
|
7
|
+
...(tool.usageHints ? { usageHints: tool.usageHints } : {}),
|
|
8
|
+
...(tool.examples ? { examples: tool.examples } : {}),
|
|
9
|
+
inputSchema: jsonSchema(tool.input),
|
|
10
|
+
...(tool.outputKind ? { outputKind: tool.outputKind } : {}),
|
|
11
|
+
tier: tool.tier ?? "read",
|
|
12
|
+
requiredScopes: tool.requiredScopes ?? [],
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Build the manifest you register with Voyant from a set of tools. Each tool's
|
|
17
|
+
* Zod schema is converted to JSON Schema for the model.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* const manifest = toManifest([lookupBooking, createQuote], {
|
|
22
|
+
* callBaseUrl: "https://acme.example.com",
|
|
23
|
+
* })
|
|
24
|
+
* // -> register `manifest` with Voyant for your operator
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export function toManifest(tools, options = {}) {
|
|
28
|
+
return {
|
|
29
|
+
version: options.version ?? "1",
|
|
30
|
+
...(options.callBaseUrl ? { callBaseUrl: options.callBaseUrl } : {}),
|
|
31
|
+
...(options.authHeaderName ? { authHeaderName: options.authHeaderName } : {}),
|
|
32
|
+
tools: tools.map(toToolDefinition),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/** Zod -> JSON Schema, stripped of the `$schema` preamble. */
|
|
36
|
+
function jsonSchema(schema) {
|
|
37
|
+
const out = z.toJSONSchema(schema, { target: "draft-7" });
|
|
38
|
+
delete out.$schema;
|
|
39
|
+
return out;
|
|
40
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
import type { AgentCard } from "./cards.js";
|
|
3
|
+
/**
|
|
4
|
+
* How risky a tool is. Voyant uses this to decide whether a call runs
|
|
5
|
+
* automatically (`read`), is allowed with light guarding (`routine-write`), or
|
|
6
|
+
* needs explicit user approval before it executes (`destructive`).
|
|
7
|
+
*/
|
|
8
|
+
export type ToolTier = "read" | "routine-write" | "destructive";
|
|
9
|
+
/** A worked example that helps the model call the tool with the right args. */
|
|
10
|
+
export type ToolExample = {
|
|
11
|
+
/** Something a user might say that should trigger this tool. */
|
|
12
|
+
userMessage: string;
|
|
13
|
+
/** The arguments the model should produce for that message. */
|
|
14
|
+
args: Record<string, unknown>;
|
|
15
|
+
/** Optional note explaining the example. */
|
|
16
|
+
notes?: string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Context Voyant sends with every tool call. Use it to scope the work to the
|
|
20
|
+
* calling operator / organization / end user. These ids come from Voyant — your
|
|
21
|
+
* webhook never has to supply them.
|
|
22
|
+
*/
|
|
23
|
+
export type ToolCallContext = {
|
|
24
|
+
/** The tool being invoked. */
|
|
25
|
+
toolName: string;
|
|
26
|
+
operatorId: string;
|
|
27
|
+
organizationId: string;
|
|
28
|
+
userId: string;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Return this from a handler (via {@link file}) to hand back a downloadable
|
|
32
|
+
* file — a generated PDF, an export, an image — instead of a JSON payload. Set
|
|
33
|
+
* the tool's `outputKind: "file"` so Voyant renders it as an attachment.
|
|
34
|
+
*/
|
|
35
|
+
export type ToolFileResult = {
|
|
36
|
+
type: "file";
|
|
37
|
+
label: string;
|
|
38
|
+
filename: string;
|
|
39
|
+
mediaType: string;
|
|
40
|
+
downloadUrl: string;
|
|
41
|
+
expiresAt?: string;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* A plain JSON result optionally carrying a rich {@link AgentCard} that renders
|
|
45
|
+
* as a widget in the Max chat. Attach a card by returning `{ ...data, card }`.
|
|
46
|
+
*/
|
|
47
|
+
export type WithCard<T extends Record<string, unknown> = Record<string, unknown>> = T & {
|
|
48
|
+
card?: AgentCard;
|
|
49
|
+
};
|
|
50
|
+
export type ToolHandler<TInput> = (args: TInput, ctx: ToolCallContext) => unknown | Promise<unknown>;
|
|
51
|
+
export type ToolConfig<TSchema extends z.ZodType> = {
|
|
52
|
+
/** Unique name. Letters, digits, `_` and `-` only. */
|
|
53
|
+
name: string;
|
|
54
|
+
/** What the tool does — shown to the model to decide when to call it. */
|
|
55
|
+
description: string;
|
|
56
|
+
/** Zod schema for the tool's arguments. Doubles as runtime validation. */
|
|
57
|
+
input: TSchema;
|
|
58
|
+
/** Defaults to `read`. */
|
|
59
|
+
tier?: ToolTier;
|
|
60
|
+
/** Voyant capability scopes the caller must hold to use the tool. */
|
|
61
|
+
requiredScopes?: readonly string[];
|
|
62
|
+
/** Short hints that nudge the model toward correct usage. */
|
|
63
|
+
usageHints?: readonly string[];
|
|
64
|
+
/** Worked examples (user message -> args). */
|
|
65
|
+
examples?: readonly ToolExample[];
|
|
66
|
+
/** `json` (default) or `file` when the handler returns a {@link ToolFileResult}. */
|
|
67
|
+
outputKind?: "json" | "file";
|
|
68
|
+
/** Runs when the tool is called. Receives validated args + call context. */
|
|
69
|
+
handler: ToolHandler<z.infer<TSchema>>;
|
|
70
|
+
};
|
|
71
|
+
export type MaxTool<TSchema extends z.ZodType = z.ZodType> = ToolConfig<TSchema>;
|
|
72
|
+
/**
|
|
73
|
+
* The wire shape of a single tool in the manifest Voyant stores for an
|
|
74
|
+
* operator. Produced by {@link toToolDefinition}; you rarely build it by hand.
|
|
75
|
+
*/
|
|
76
|
+
export type RemoteToolDefinition = {
|
|
77
|
+
name: string;
|
|
78
|
+
description: string;
|
|
79
|
+
usageHints?: readonly string[];
|
|
80
|
+
examples?: readonly ToolExample[];
|
|
81
|
+
inputSchema: Record<string, unknown>;
|
|
82
|
+
outputSchema?: Record<string, unknown>;
|
|
83
|
+
outputKind?: "json" | "file";
|
|
84
|
+
tier: ToolTier;
|
|
85
|
+
requiredScopes: readonly string[];
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* The manifest you register with Voyant so Max knows your tools exist and where
|
|
89
|
+
* to call them. Produced by {@link toManifest}.
|
|
90
|
+
*/
|
|
91
|
+
export type RemoteToolsConfig = {
|
|
92
|
+
version: string;
|
|
93
|
+
/** Base URL Voyant calls; tools are invoked at `{callBaseUrl}/v1/max/tools/{name}/call`. */
|
|
94
|
+
callBaseUrl?: string;
|
|
95
|
+
/** Header Voyant sends the auth token in. Defaults to `Authorization`. */
|
|
96
|
+
authHeaderName?: string;
|
|
97
|
+
/** Secret Voyant presents to your webhook. Stored encrypted by Voyant. */
|
|
98
|
+
authToken?: string;
|
|
99
|
+
tools: RemoteToolDefinition[];
|
|
100
|
+
};
|
|
101
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAE5B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAE3C;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,eAAe,GAAG,aAAa,CAAA;AAE/D,+EAA+E;AAC/E,MAAM,MAAM,WAAW,GAAG;IACxB,gEAAgE;IAChE,WAAW,EAAE,MAAM,CAAA;IACnB,+DAA+D;IAC/D,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,4CAA4C;IAC5C,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAED;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,8BAA8B;IAC9B,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE,MAAM,CAAA;IAClB,cAAc,EAAE,MAAM,CAAA;IACtB,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAED;;;;GAIG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA;AAED;;;GAGG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG;IACtF,IAAI,CAAC,EAAE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C,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IAC5B,IAAI,EAAE,QAAQ,CAAA;IACd,cAAc,EAAE,SAAS,MAAM,EAAE,CAAA;CAClC,CAAA;AAED;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,EAAE,MAAM,CAAA;IACf,4FAA4F;IAC5F,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,0EAA0E;IAC1E,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,0EAA0E;IAC1E,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,EAAE,oBAAoB,EAAE,CAAA;CAC9B,CAAA"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@voyant-travel/max-sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"description": "Write custom tools for Max, Voyant's AI travel agent. Define tools with Zod, generate the manifest Voyant registers, and serve calls with a framework-agnostic request handler.",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc -p tsconfig.build.json",
|
|
21
|
+
"check-types": "tsc --noEmit",
|
|
22
|
+
"lint": "biome check src",
|
|
23
|
+
"format": "biome check --write src",
|
|
24
|
+
"test": "vitest run --passWithNoTests",
|
|
25
|
+
"clean": "rm -rf dist",
|
|
26
|
+
"prepack": "pnpm run build"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"zod": "4.3.6"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@voyant-travel/max-tsconfig": "workspace:*",
|
|
33
|
+
"typescript": "5.9.2",
|
|
34
|
+
"vitest": "^4.1.8"
|
|
35
|
+
},
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=20"
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"repository": {
|
|
43
|
+
"type": "git",
|
|
44
|
+
"url": "https://github.com/voyant-travel/max.git",
|
|
45
|
+
"directory": "packages/sdk"
|
|
46
|
+
}
|
|
47
|
+
}
|