@callsitehq/core 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.
@@ -0,0 +1,64 @@
1
+ type JsonPrimitive = string | number | boolean | null;
2
+ type JsonValue = JsonPrimitive | JsonValue[] | {
3
+ [key: string]: JsonValue;
4
+ };
5
+ type JsonObject = {
6
+ [key: string]: JsonValue;
7
+ };
8
+ interface Schema<T> {
9
+ readonly description?: string;
10
+ readonly jsonSchema?: JsonObject;
11
+ readonly parse: (value: unknown) => T;
12
+ }
13
+ interface CapabilityContext {
14
+ readonly request: Request;
15
+ }
16
+ type CapabilityRun<Input, Output> = (input: Input, context: CapabilityContext) => Output | Promise<Output>;
17
+ interface CapabilityDefinition<Input, Output> {
18
+ readonly id: string;
19
+ readonly intent: string;
20
+ readonly input: Schema<Input>;
21
+ readonly output: Schema<Output>;
22
+ readonly destructive?: boolean;
23
+ readonly examples?: readonly CapabilityExample<Input, Output>[];
24
+ readonly run: CapabilityRun<Input, Output>;
25
+ }
26
+ interface CapabilityExample<Input, Output> {
27
+ readonly input: Input;
28
+ readonly output?: Output;
29
+ readonly intent?: string;
30
+ }
31
+ interface Capability<Input = unknown, Output = unknown> extends CapabilityDefinition<Input, Output> {
32
+ readonly kind: "callsite.capability";
33
+ }
34
+ type AnyCapability = Capability<any, any>;
35
+ interface CapabilityIR {
36
+ readonly version: 1;
37
+ readonly capabilities: readonly CapabilityIRNode[];
38
+ }
39
+ interface CapabilityIRNode {
40
+ readonly id: string;
41
+ readonly intent: string;
42
+ readonly inputSchema: JsonObject;
43
+ readonly outputSchema: JsonObject;
44
+ readonly destructive: boolean;
45
+ readonly examples: readonly CapabilityIRExample[];
46
+ }
47
+ interface CapabilityIRExample {
48
+ readonly input: JsonValue;
49
+ readonly output?: JsonValue;
50
+ readonly intent?: string;
51
+ }
52
+ declare class CapabilityError extends Error {
53
+ readonly code: CapabilityErrorCode;
54
+ readonly details: JsonValue | undefined;
55
+ constructor(code: CapabilityErrorCode, message: string, options?: CapabilityErrorOptions);
56
+ }
57
+ type CapabilityErrorCode = "bad_request" | "unauthorized" | "forbidden" | "not_found" | "conflict" | "rate_limited" | "internal";
58
+ interface CapabilityErrorOptions {
59
+ readonly details?: JsonValue;
60
+ }
61
+ declare function capability<Input, Output>(definition: CapabilityDefinition<Input, Output>): Capability<Input, Output>;
62
+ declare function defineCallsite(capabilities: readonly AnyCapability[]): CapabilityIR;
63
+
64
+ export { type AnyCapability, type Capability, type CapabilityContext, type CapabilityDefinition, CapabilityError, type CapabilityErrorCode, type CapabilityErrorOptions, type CapabilityExample, type CapabilityIR, type CapabilityIRExample, type CapabilityIRNode, type CapabilityRun, type JsonObject, type JsonPrimitive, type JsonValue, type Schema, capability, defineCallsite };
package/dist/index.js ADDED
@@ -0,0 +1,49 @@
1
+ // src/index.ts
2
+ var CapabilityError = class extends Error {
3
+ code;
4
+ details;
5
+ constructor(code, message, options = {}) {
6
+ super(message);
7
+ this.name = "CapabilityError";
8
+ this.code = code;
9
+ this.details = options.details;
10
+ }
11
+ };
12
+ function capability(definition) {
13
+ assertCapabilityId(definition.id);
14
+ return {
15
+ ...definition,
16
+ kind: "callsite.capability"
17
+ };
18
+ }
19
+ function defineCallsite(capabilities) {
20
+ return {
21
+ version: 1,
22
+ capabilities: capabilities.map(toIRNode)
23
+ };
24
+ }
25
+ function toIRNode(capabilityDefinition) {
26
+ return {
27
+ id: capabilityDefinition.id,
28
+ intent: capabilityDefinition.intent,
29
+ inputSchema: capabilityDefinition.input.jsonSchema ?? {},
30
+ outputSchema: capabilityDefinition.output.jsonSchema ?? {},
31
+ destructive: capabilityDefinition.destructive ?? false,
32
+ examples: (capabilityDefinition.examples ?? []).map((example) => ({
33
+ input: example.input,
34
+ ...example.output === void 0 ? {} : { output: example.output },
35
+ ...example.intent === void 0 ? {} : { intent: example.intent }
36
+ }))
37
+ };
38
+ }
39
+ function assertCapabilityId(id) {
40
+ if (!/^[a-z][a-z0-9_]*(\.[a-z][a-z0-9_]*)*$/.test(id)) {
41
+ throw new TypeError(`Invalid capability id "${id}". Use lowercase dot-separated identifiers.`);
42
+ }
43
+ }
44
+ export {
45
+ CapabilityError,
46
+ capability,
47
+ defineCallsite
48
+ };
49
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export type JsonPrimitive = string | number | boolean | null;\nexport type JsonValue = JsonPrimitive | JsonValue[] | { [key: string]: JsonValue };\nexport type JsonObject = { [key: string]: JsonValue };\n\nexport interface Schema<T> {\n readonly description?: string;\n readonly jsonSchema?: JsonObject;\n readonly parse: (value: unknown) => T;\n}\n\nexport interface CapabilityContext {\n readonly request: Request;\n}\n\nexport type CapabilityRun<Input, Output> = (\n input: Input,\n context: CapabilityContext\n) => Output | Promise<Output>;\n\nexport interface CapabilityDefinition<Input, Output> {\n readonly id: string;\n readonly intent: string;\n readonly input: Schema<Input>;\n readonly output: Schema<Output>;\n readonly destructive?: boolean;\n readonly examples?: readonly CapabilityExample<Input, Output>[];\n readonly run: CapabilityRun<Input, Output>;\n}\n\nexport interface CapabilityExample<Input, Output> {\n readonly input: Input;\n readonly output?: Output;\n readonly intent?: string;\n}\n\nexport interface Capability<Input = unknown, Output = unknown> extends CapabilityDefinition<\n Input,\n Output\n> {\n readonly kind: \"callsite.capability\";\n}\n\nexport type AnyCapability = Capability<any, any>;\n\nexport interface CapabilityIR {\n readonly version: 1;\n readonly capabilities: readonly CapabilityIRNode[];\n}\n\nexport interface CapabilityIRNode {\n readonly id: string;\n readonly intent: string;\n readonly inputSchema: JsonObject;\n readonly outputSchema: JsonObject;\n readonly destructive: boolean;\n readonly examples: readonly CapabilityIRExample[];\n}\n\nexport interface CapabilityIRExample {\n readonly input: JsonValue;\n readonly output?: JsonValue;\n readonly intent?: string;\n}\n\nexport class CapabilityError extends Error {\n public readonly code: CapabilityErrorCode;\n public readonly details: JsonValue | undefined;\n\n public constructor(\n code: CapabilityErrorCode,\n message: string,\n options: CapabilityErrorOptions = {}\n ) {\n super(message);\n this.name = \"CapabilityError\";\n this.code = code;\n this.details = options.details;\n }\n}\n\nexport type CapabilityErrorCode =\n | \"bad_request\"\n | \"unauthorized\"\n | \"forbidden\"\n | \"not_found\"\n | \"conflict\"\n | \"rate_limited\"\n | \"internal\";\n\nexport interface CapabilityErrorOptions {\n readonly details?: JsonValue;\n}\n\nexport function capability<Input, Output>(\n definition: CapabilityDefinition<Input, Output>\n): Capability<Input, Output> {\n assertCapabilityId(definition.id);\n\n return {\n ...definition,\n kind: \"callsite.capability\"\n };\n}\n\nexport function defineCallsite(capabilities: readonly AnyCapability[]): CapabilityIR {\n return {\n version: 1,\n capabilities: capabilities.map(toIRNode)\n };\n}\n\nfunction toIRNode(capabilityDefinition: AnyCapability): CapabilityIRNode {\n return {\n id: capabilityDefinition.id,\n intent: capabilityDefinition.intent,\n inputSchema: capabilityDefinition.input.jsonSchema ?? {},\n outputSchema: capabilityDefinition.output.jsonSchema ?? {},\n destructive: capabilityDefinition.destructive ?? false,\n examples: (capabilityDefinition.examples ?? []).map((example) => ({\n input: example.input,\n ...(example.output === undefined ? {} : { output: example.output }),\n ...(example.intent === undefined ? {} : { intent: example.intent })\n }))\n };\n}\n\nfunction assertCapabilityId(id: string): void {\n if (!/^[a-z][a-z0-9_]*(\\.[a-z][a-z0-9_]*)*$/.test(id)) {\n throw new TypeError(`Invalid capability id \"${id}\". Use lowercase dot-separated identifiers.`);\n }\n}\n"],"mappings":";AAgEO,IAAM,kBAAN,cAA8B,MAAM;AAAA,EACzB;AAAA,EACA;AAAA,EAET,YACL,MACA,SACA,UAAkC,CAAC,GACnC;AACA,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,OAAO;AACZ,SAAK,UAAU,QAAQ;AAAA,EACzB;AACF;AAeO,SAAS,WACd,YAC2B;AAC3B,qBAAmB,WAAW,EAAE;AAEhC,SAAO;AAAA,IACL,GAAG;AAAA,IACH,MAAM;AAAA,EACR;AACF;AAEO,SAAS,eAAe,cAAsD;AACnF,SAAO;AAAA,IACL,SAAS;AAAA,IACT,cAAc,aAAa,IAAI,QAAQ;AAAA,EACzC;AACF;AAEA,SAAS,SAAS,sBAAuD;AACvE,SAAO;AAAA,IACL,IAAI,qBAAqB;AAAA,IACzB,QAAQ,qBAAqB;AAAA,IAC7B,aAAa,qBAAqB,MAAM,cAAc,CAAC;AAAA,IACvD,cAAc,qBAAqB,OAAO,cAAc,CAAC;AAAA,IACzD,aAAa,qBAAqB,eAAe;AAAA,IACjD,WAAW,qBAAqB,YAAY,CAAC,GAAG,IAAI,CAAC,aAAa;AAAA,MAChE,OAAO,QAAQ;AAAA,MACf,GAAI,QAAQ,WAAW,SAAY,CAAC,IAAI,EAAE,QAAQ,QAAQ,OAAO;AAAA,MACjE,GAAI,QAAQ,WAAW,SAAY,CAAC,IAAI,EAAE,QAAQ,QAAQ,OAAO;AAAA,IACnE,EAAE;AAAA,EACJ;AACF;AAEA,SAAS,mBAAmB,IAAkB;AAC5C,MAAI,CAAC,wCAAwC,KAAK,EAAE,GAAG;AACrD,UAAM,IAAI,UAAU,0BAA0B,EAAE,6CAA6C;AAAA,EAC/F;AACF;","names":[]}
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "@callsitehq/core",
3
+ "version": "0.1.0",
4
+ "description": "Authoring API and IR types for Callsite capabilities.",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/index.d.ts",
9
+ "default": "./dist/index.js"
10
+ }
11
+ },
12
+ "files": [
13
+ "dist"
14
+ ],
15
+ "sideEffects": false,
16
+ "scripts": {
17
+ "build": "tsup",
18
+ "clean": "rm -rf dist *.tsbuildinfo",
19
+ "typecheck": "tsc -p tsconfig.json --noEmit"
20
+ }
21
+ }