@aexhq/sdk 0.62.1 → 0.64.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 +15 -49
- package/dist/index.d.ts +6 -19
- package/dist/index.js +9 -22
- package/package.json +3 -8
- package/dist/errors.d.ts +0 -39
- package/dist/errors.js +0 -69
- package/dist/json.d.ts +0 -4
- package/dist/json.js +0 -46
- package/dist/resources.d.ts +0 -162
- package/dist/resources.js +0 -442
- package/dist/session.d.ts +0 -137
- package/dist/session.js +0 -658
- package/dist/tools.d.ts +0 -48
- package/dist/tools.js +0 -119
- package/dist/transport.d.ts +0 -31
- package/dist/transport.js +0 -744
package/dist/tools.d.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import type { ComponentExtension } from "@aexhq/brain";
|
|
2
|
-
import type { ToolDefinition } from "@aexhq/brain/session";
|
|
3
|
-
import * as z from "zod";
|
|
4
|
-
export type JsonSchema = Record<string, unknown>;
|
|
5
|
-
export interface ToolContext {
|
|
6
|
-
readonly signal: AbortSignal;
|
|
7
|
-
readonly operationId: string;
|
|
8
|
-
readonly sessionId: string;
|
|
9
|
-
readonly deadlineMs: number;
|
|
10
|
-
}
|
|
11
|
-
export type ToolHandler<Input extends z.ZodType, Output = unknown> = (input: z.output<Input>, context: ToolContext) => Output | Promise<Output>;
|
|
12
|
-
export interface ToolContract {
|
|
13
|
-
readonly name: string;
|
|
14
|
-
readonly description?: string;
|
|
15
|
-
readonly inputSchema: JsonSchema;
|
|
16
|
-
readonly outputSchema?: JsonSchema;
|
|
17
|
-
readonly contractDigest: string;
|
|
18
|
-
}
|
|
19
|
-
export interface Tool<Input extends z.ZodType = z.ZodType, Output = unknown> {
|
|
20
|
-
readonly kind: "aex.tool";
|
|
21
|
-
readonly name?: string;
|
|
22
|
-
readonly description?: string;
|
|
23
|
-
readonly input: Input;
|
|
24
|
-
readonly output?: z.ZodType;
|
|
25
|
-
readonly handler: ToolHandler<Input, Output>;
|
|
26
|
-
describe(description: string): Tool<Input, Output>;
|
|
27
|
-
named(name: string): Tool<Input, Output>;
|
|
28
|
-
returns<Schema extends z.ZodType>(schema: Schema): Tool<Input, z.output<Schema>>;
|
|
29
|
-
}
|
|
30
|
-
declare const EMPTY_INPUT: z.ZodObject<{}, z.core.$strip>;
|
|
31
|
-
export declare function tool<Output>(handler: ToolHandler<typeof EMPTY_INPUT, Output>): Tool<typeof EMPTY_INPUT, Output>;
|
|
32
|
-
export declare function tool<Input extends z.ZodType, Output>(input: Input, handler: ToolHandler<Input, Output>): Tool<Input, Output>;
|
|
33
|
-
export interface ClientRegistration {
|
|
34
|
-
readonly registration: string;
|
|
35
|
-
readonly name: string;
|
|
36
|
-
readonly contractDigest: string;
|
|
37
|
-
readonly input: z.ZodType;
|
|
38
|
-
readonly output?: z.ZodType;
|
|
39
|
-
readonly handler: ToolHandler<z.ZodType>;
|
|
40
|
-
}
|
|
41
|
-
export interface CompiledCallbacks {
|
|
42
|
-
readonly components: readonly ComponentExtension<"tool", Readonly<Record<string, unknown>> & {
|
|
43
|
-
readonly definition: ToolDefinition;
|
|
44
|
-
}>[];
|
|
45
|
-
readonly registrations: readonly ClientRegistration[];
|
|
46
|
-
}
|
|
47
|
-
export declare function compileCallbacks(selections: readonly Tool[]): Promise<CompiledCallbacks>;
|
|
48
|
-
export {};
|
package/dist/tools.js
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { callback as callbackComponent } from "@aexhq/env-app";
|
|
2
|
-
import * as z from "zod";
|
|
3
|
-
import { jcsSha256 } from "./json.js";
|
|
4
|
-
const EMPTY_INPUT = z.object({});
|
|
5
|
-
const TOOL_NAME = /^[A-Za-z_][A-Za-z0-9_-]{0,63}$/u;
|
|
6
|
-
export function tool(inputOrHandler, maybeHandler) {
|
|
7
|
-
if (typeof inputOrHandler === "function") {
|
|
8
|
-
return makeTool({
|
|
9
|
-
...(inputOrHandler.name === "" ? {} : { name: inputOrHandler.name }),
|
|
10
|
-
input: EMPTY_INPUT,
|
|
11
|
-
handler: inputOrHandler,
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
if (typeof maybeHandler !== "function")
|
|
15
|
-
throw new TypeError("tool(schema, handler) requires a function");
|
|
16
|
-
return makeTool({
|
|
17
|
-
...(maybeHandler.name === "" ? {} : { name: maybeHandler.name }),
|
|
18
|
-
input: inputOrHandler,
|
|
19
|
-
handler: maybeHandler,
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
function makeTool(draft) {
|
|
23
|
-
return Object.freeze({
|
|
24
|
-
kind: "aex.tool",
|
|
25
|
-
...(draft.name === undefined ? {} : { name: draft.name }),
|
|
26
|
-
...(draft.description === undefined ? {} : { description: draft.description }),
|
|
27
|
-
input: draft.input,
|
|
28
|
-
...(draft.output === undefined ? {} : { output: draft.output }),
|
|
29
|
-
handler: draft.handler,
|
|
30
|
-
describe(description) {
|
|
31
|
-
if (description.trim() === "" || description.length > 4096) {
|
|
32
|
-
throw new TypeError("Tool description must contain 1 through 4096 characters");
|
|
33
|
-
}
|
|
34
|
-
return makeTool({ ...draft, description });
|
|
35
|
-
},
|
|
36
|
-
named(name) {
|
|
37
|
-
assertToolName(name);
|
|
38
|
-
return makeTool({ ...draft, name });
|
|
39
|
-
},
|
|
40
|
-
returns(output) {
|
|
41
|
-
schemaOf(output, `${draft.name ?? "Tool"} output`);
|
|
42
|
-
return makeTool({ ...draft, output });
|
|
43
|
-
},
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
export async function compileCallbacks(selections) {
|
|
47
|
-
const components = [];
|
|
48
|
-
const registrations = [];
|
|
49
|
-
const names = new Set();
|
|
50
|
-
for (const value of selections) {
|
|
51
|
-
assertTool(value);
|
|
52
|
-
const contract = await compileContract(value);
|
|
53
|
-
if (names.has(contract.name)) {
|
|
54
|
-
throw new TypeError(`Tool ${JSON.stringify(contract.name)} was selected twice`);
|
|
55
|
-
}
|
|
56
|
-
names.add(contract.name);
|
|
57
|
-
const definition = {
|
|
58
|
-
name: contract.name,
|
|
59
|
-
...(contract.description === undefined ? {} : { description: contract.description }),
|
|
60
|
-
input_schema: contract.inputSchema,
|
|
61
|
-
output_schema: contract.outputSchema ?? {},
|
|
62
|
-
contract_digest: contract.contractDigest,
|
|
63
|
-
};
|
|
64
|
-
const registration = `tool:${contract.contractDigest}`;
|
|
65
|
-
components.push(callbackComponent(definition, registration));
|
|
66
|
-
registrations.push(Object.freeze({
|
|
67
|
-
registration,
|
|
68
|
-
name: contract.name,
|
|
69
|
-
contractDigest: contract.contractDigest,
|
|
70
|
-
input: value.input,
|
|
71
|
-
...(value.output === undefined ? {} : { output: value.output }),
|
|
72
|
-
handler: value.handler,
|
|
73
|
-
}));
|
|
74
|
-
}
|
|
75
|
-
return {
|
|
76
|
-
components: Object.freeze(components),
|
|
77
|
-
registrations: Object.freeze(registrations),
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
async function compileContract(value) {
|
|
81
|
-
const name = value.name;
|
|
82
|
-
if (name === undefined)
|
|
83
|
-
throw new TypeError("Tool functions must be named; use .named(name) when build tooling removes the name");
|
|
84
|
-
assertToolName(name);
|
|
85
|
-
const inputSchema = schemaOf(value.input, `${name} input`);
|
|
86
|
-
const outputSchema = value.output === undefined ? undefined : schemaOf(value.output, `${name} output`);
|
|
87
|
-
const canonical = {
|
|
88
|
-
name,
|
|
89
|
-
...(value.description === undefined ? {} : { description: value.description }),
|
|
90
|
-
input_schema: inputSchema,
|
|
91
|
-
...(outputSchema === undefined ? {} : { output_schema: outputSchema }),
|
|
92
|
-
};
|
|
93
|
-
return {
|
|
94
|
-
name,
|
|
95
|
-
...(value.description === undefined ? {} : { description: value.description }),
|
|
96
|
-
inputSchema,
|
|
97
|
-
...(outputSchema === undefined ? {} : { outputSchema }),
|
|
98
|
-
contractDigest: await jcsSha256(canonical),
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
function schemaOf(schema, label) {
|
|
102
|
-
try {
|
|
103
|
-
const value = z.toJSONSchema(schema, { target: "draft-2020-12", unrepresentable: "throw" });
|
|
104
|
-
if (Object.keys(value).length === 0)
|
|
105
|
-
throw new TypeError(`${label} schema is empty`);
|
|
106
|
-
return value;
|
|
107
|
-
}
|
|
108
|
-
catch (cause) {
|
|
109
|
-
throw new TypeError(`${label} cannot be represented as JSON Schema`, { cause });
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
function assertTool(value) {
|
|
113
|
-
if (value?.kind !== "aex.tool")
|
|
114
|
-
throw new TypeError("Tool selection is invalid");
|
|
115
|
-
}
|
|
116
|
-
function assertToolName(name) {
|
|
117
|
-
if (!TOOL_NAME.test(name))
|
|
118
|
-
throw new TypeError(`Invalid Tool name ${JSON.stringify(name)}`);
|
|
119
|
-
}
|
package/dist/transport.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { Event } from "@aexhq/brain/session";
|
|
2
|
-
import type { JsonRequestOptions, TransferTicket } from "@aexhq/brain";
|
|
3
|
-
export type Fetch = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
4
|
-
export interface EventOptions {
|
|
5
|
-
after?: number;
|
|
6
|
-
follow?: boolean;
|
|
7
|
-
signal?: AbortSignal | undefined;
|
|
8
|
-
}
|
|
9
|
-
export declare class Transport {
|
|
10
|
-
#private;
|
|
11
|
-
readonly baseUrl: string;
|
|
12
|
-
constructor(apiKey: string, baseUrl: string, fetchImplementation: Fetch);
|
|
13
|
-
customerEnvironmentGrant(clientId: string, signal?: AbortSignal): Promise<{
|
|
14
|
-
url: string;
|
|
15
|
-
protocol: string;
|
|
16
|
-
expiresAt: string;
|
|
17
|
-
observationUrl: string;
|
|
18
|
-
observationToken: string;
|
|
19
|
-
}>;
|
|
20
|
-
customerEnvironmentObserve(url: string, token: string, observation: unknown): Promise<void>;
|
|
21
|
-
downloadTransfer(ticket: TransferTicket, signal?: AbortSignal, expectedBytes?: number): Promise<Uint8Array>;
|
|
22
|
-
downloadTransferStream(ticket: TransferTicket, signal?: AbortSignal, expectedBytes?: number): Promise<ReadableStream<Uint8Array>>;
|
|
23
|
-
uploadTransfer(ticket: TransferTicket, content: Uint8Array | (() => ReadableStream<Uint8Array>), bytes: number, signal?: AbortSignal): Promise<void>;
|
|
24
|
-
json<T>(method: "GET" | "POST" | "DELETE", path: string, options?: JsonRequestOptions): Promise<T>;
|
|
25
|
-
/** Accept one durable deletion job; strict callers poll its short status resource client-side. */
|
|
26
|
-
deleteSession(sessionId: string, waitForCompletion: boolean, signal?: AbortSignal): Promise<void>;
|
|
27
|
-
events(sessionId: string, options?: EventOptions): AsyncGenerator<Event>;
|
|
28
|
-
private responseError;
|
|
29
|
-
}
|
|
30
|
-
/** @internal Incremental, constant-space decoder for Brain's bounded public SSE events. */
|
|
31
|
-
export declare function parseEventStream(stream: ReadableStream<Uint8Array>): AsyncGenerator<Event>;
|