@yak-io/javascript 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.
Files changed (44) hide show
  1. package/LICENSE +36 -0
  2. package/dist/client.d.ts +175 -0
  3. package/dist/client.d.ts.map +1 -0
  4. package/dist/client.js +504 -0
  5. package/dist/index.d.ts +9 -0
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js +9 -0
  8. package/dist/index.server.d.ts +2 -0
  9. package/dist/index.server.d.ts.map +1 -0
  10. package/dist/index.server.js +1 -0
  11. package/dist/logger.d.ts +12 -0
  12. package/dist/logger.d.ts.map +1 -0
  13. package/dist/logger.js +44 -0
  14. package/dist/page-context.d.ts +10 -0
  15. package/dist/page-context.d.ts.map +1 -0
  16. package/dist/page-context.js +69 -0
  17. package/dist/schema-parser.d.ts +21 -0
  18. package/dist/schema-parser.d.ts.map +1 -0
  19. package/dist/schema-parser.js +341 -0
  20. package/dist/server/createYakHandler.d.ts +19 -0
  21. package/dist/server/createYakHandler.d.ts.map +1 -0
  22. package/dist/server/createYakHandler.js +185 -0
  23. package/dist/server/index.d.ts +8 -0
  24. package/dist/server/index.d.ts.map +1 -0
  25. package/dist/server/index.js +2 -0
  26. package/dist/server/sources.d.ts +24 -0
  27. package/dist/server/sources.d.ts.map +1 -0
  28. package/dist/server/sources.js +116 -0
  29. package/dist/types/config.d.ts +19 -0
  30. package/dist/types/config.d.ts.map +1 -0
  31. package/dist/types/config.js +1 -0
  32. package/dist/types/messaging.d.ts +153 -0
  33. package/dist/types/messaging.d.ts.map +1 -0
  34. package/dist/types/messaging.js +1 -0
  35. package/dist/types/routes.d.ts +26 -0
  36. package/dist/types/routes.d.ts.map +1 -0
  37. package/dist/types/routes.js +1 -0
  38. package/dist/types/tools.d.ts +137 -0
  39. package/dist/types/tools.d.ts.map +1 -0
  40. package/dist/types/tools.js +1 -0
  41. package/dist/version.d.ts +23 -0
  42. package/dist/version.d.ts.map +1 -0
  43. package/dist/version.js +18 -0
  44. package/package.json +53 -0
@@ -0,0 +1,116 @@
1
+ function isRouteSource(value) {
2
+ return Boolean(value && typeof value === "object" && "getRoutes" in value && typeof value.getRoutes === "function");
3
+ }
4
+ function isRouteInfoArray(value) {
5
+ return Array.isArray(value) && value.every((route) => route && typeof route.path === "string");
6
+ }
7
+ function normalizeRouteSourceItem(item, index) {
8
+ if (isRouteSource(item)) {
9
+ return {
10
+ id: item.id ?? `route-source-${index}`,
11
+ getRoutes: item.getRoutes,
12
+ };
13
+ }
14
+ if (typeof item === "function") {
15
+ return {
16
+ id: `route-fn-${index}`,
17
+ getRoutes: item,
18
+ };
19
+ }
20
+ if (isRouteInfoArray(item)) {
21
+ return {
22
+ id: `route-static-${index}`,
23
+ getRoutes: async () => item,
24
+ };
25
+ }
26
+ throw new Error("Unsupported route source input");
27
+ }
28
+ export function normalizeRouteSources(input) {
29
+ if (Array.isArray(input)) {
30
+ if (input.length === 0) {
31
+ return [];
32
+ }
33
+ if (isRouteInfoArray(input)) {
34
+ return [normalizeRouteSourceItem(input, 0)];
35
+ }
36
+ return input.map((item, index) => normalizeRouteSourceItem(item, index));
37
+ }
38
+ return [normalizeRouteSourceItem(input, 0)];
39
+ }
40
+ function isToolSource(value) {
41
+ return Boolean(value && typeof value === "object" && "getTools" in value && typeof value.getTools === "function");
42
+ }
43
+ function isToolManifest(value) {
44
+ return Boolean(value && typeof value === "object" && "tools" in value);
45
+ }
46
+ function isToolDefinitionArray(value) {
47
+ return Array.isArray(value) && value.every((tool) => tool && typeof tool.name === "string");
48
+ }
49
+ function toToolDefinitions(result) {
50
+ if (isToolDefinitionArray(result)) {
51
+ return result;
52
+ }
53
+ if (isToolManifest(result)) {
54
+ return result.tools;
55
+ }
56
+ throw new Error("Tool source must resolve to ToolDefinition[] or ToolManifest");
57
+ }
58
+ function normalizeToolSourceItem(item, index) {
59
+ if (isToolSource(item)) {
60
+ return {
61
+ id: item.id ?? `tool-source-${index}`,
62
+ getTools: async () => {
63
+ const result = await item.getTools();
64
+ return toToolDefinitions(result);
65
+ },
66
+ executeTool: item.executeTool,
67
+ };
68
+ }
69
+ if (typeof item === "function") {
70
+ return {
71
+ id: `tool-fn-${index}`,
72
+ getTools: async () => {
73
+ const result = await item();
74
+ return toToolDefinitions(result);
75
+ },
76
+ };
77
+ }
78
+ if (isToolDefinitionArray(item)) {
79
+ return {
80
+ id: `tool-static-${index}`,
81
+ getTools: async () => item,
82
+ };
83
+ }
84
+ if (isToolManifest(item)) {
85
+ return {
86
+ id: `tool-manifest-${index}`,
87
+ getTools: async () => item.tools,
88
+ };
89
+ }
90
+ if (item && typeof item === "object" && "getTools" in item && typeof item.getTools === "function") {
91
+ return {
92
+ id: item.id ?? `tool-wrapper-${index}`,
93
+ getTools: async () => {
94
+ const result = await item.getTools();
95
+ return toToolDefinitions(result);
96
+ },
97
+ executeTool: item.executeTool,
98
+ };
99
+ }
100
+ throw new Error("Unsupported tool source input");
101
+ }
102
+ export function normalizeToolSources(input) {
103
+ if (!input) {
104
+ return [];
105
+ }
106
+ if (Array.isArray(input)) {
107
+ if (input.length === 0) {
108
+ return [];
109
+ }
110
+ if (isToolDefinitionArray(input)) {
111
+ return [normalizeToolSourceItem(input, 0)];
112
+ }
113
+ return input.map((item, index) => normalizeToolSourceItem(item, index));
114
+ }
115
+ return [normalizeToolSourceItem(input, 0)];
116
+ }
@@ -0,0 +1,19 @@
1
+ import type { SchemaSource, ToolManifest } from "./tools.js";
2
+ import type { RouteManifest } from "./routes.js";
3
+ /**
4
+ * Combined configuration for the chatbot including routes, tools, and schema sources
5
+ */
6
+ export type ChatConfig = {
7
+ /** Route manifest */
8
+ routes: RouteManifest;
9
+ /** Optional tool manifest (tRPC, GraphQL, etc.) */
10
+ tools?: ToolManifest;
11
+ /** Optional schema sources (GraphQL SDL, OpenAPI specs) passed as context to the LLM */
12
+ schemaSources?: SchemaSource[];
13
+ };
14
+ /**
15
+ * Function that provides the chat configuration.
16
+ * The consuming platform decides how to get the config (static, fetch, etc.)
17
+ */
18
+ export type ChatConfigProvider = () => Promise<ChatConfig> | ChatConfig;
19
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/types/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC7D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,qBAAqB;IACrB,MAAM,EAAE,aAAa,CAAC;IACtB,mDAAmD;IACnD,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB,wFAAwF;IACxF,aAAa,CAAC,EAAE,YAAY,EAAE,CAAC;CAChC,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG,MAAM,OAAO,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,153 @@
1
+ import type { SchemaSource, ToolManifest, GraphQLRequest, RESTRequest } from "./tools.js";
2
+ import type { RouteManifest } from "./routes.js";
3
+ import type { EmbedProtocolVersion } from "../version.js";
4
+ /**
5
+ * Button/launcher style for a single color mode.
6
+ */
7
+ export type ButtonColors = {
8
+ /** Button background color */
9
+ background?: string;
10
+ /** Button text/icon color */
11
+ color?: string;
12
+ /** Button border color */
13
+ border?: string;
14
+ };
15
+ /**
16
+ * Color values for a single mode (light or dark).
17
+ * Applied as CSS variables within the chat UI.
18
+ */
19
+ export type ThemeColors = {
20
+ /** Main background color of the chat panel */
21
+ background?: string;
22
+ /** Border color for the chat panel and elements */
23
+ border?: string;
24
+ /** Button/launcher customization for this color mode */
25
+ button?: ButtonColors;
26
+ /** User message bubble background color */
27
+ messageBackground?: string;
28
+ /** Input placeholder text color */
29
+ placeholderColor?: string;
30
+ /** Submit button background color */
31
+ submitButtonColor?: string;
32
+ /** Submit button text/icon color */
33
+ submitButtonTextColor?: string;
34
+ /** Header icon color (restart and close buttons) */
35
+ headerIconColor?: string;
36
+ };
37
+ /**
38
+ * Theme configuration for the chatbot widget
39
+ */
40
+ export type Theme = {
41
+ /** Widget position: for chatbox mode this is the corner, for drawer mode this is the side */
42
+ position?: "right" | "left";
43
+ /** Force a specific color mode instead of following system preference */
44
+ colorMode?: "light" | "dark" | "system";
45
+ /** Display mode: chatbox (floating corner panel) or drawer (full-height side panel) */
46
+ displayMode?: "chatbox" | "drawer";
47
+ /** Color customization for light mode (applied when colorMode is "light" or system prefers light) */
48
+ light?: ThemeColors;
49
+ /** Color customization for dark mode (applied when colorMode is "dark" or system prefers dark) */
50
+ dark?: ThemeColors;
51
+ };
52
+ /**
53
+ * Page context information from the host page
54
+ */
55
+ export type PageContext = {
56
+ url: string;
57
+ title: string;
58
+ text: string;
59
+ timestamp: number;
60
+ };
61
+ /**
62
+ * Chat configuration options passed from host to chat-ui.
63
+ * Grouped to minimize contract changes when adding new options.
64
+ */
65
+ export type ChatOptions = {
66
+ /** Disable the restart session button in the header */
67
+ disableRestartButton?: boolean;
68
+ };
69
+ /**
70
+ * Messages sent FROM the host application TO the iframe
71
+ */
72
+ export type IframeMessageFromHost = {
73
+ type: "yak:config";
74
+ payload: {
75
+ /** Protocol version for compatibility checking */
76
+ version?: EmbedProtocolVersion;
77
+ appId: string;
78
+ theme?: Theme;
79
+ toolManifest?: ToolManifest;
80
+ routeManifest?: RouteManifest;
81
+ /** Schema sources passed as context to the LLM */
82
+ schemaSources?: SchemaSource[];
83
+ /** Chat configuration options */
84
+ options?: ChatOptions;
85
+ };
86
+ } | {
87
+ type: "yak:tool_result";
88
+ payload: {
89
+ id: string;
90
+ ok: true;
91
+ result: unknown;
92
+ };
93
+ } | {
94
+ type: "yak:tool_result";
95
+ payload: {
96
+ id: string;
97
+ ok: false;
98
+ error: string;
99
+ };
100
+ } | {
101
+ type: "yak:page_context";
102
+ payload: PageContext;
103
+ } | {
104
+ type: "yak:prompt";
105
+ payload: {
106
+ prompt: string;
107
+ };
108
+ } | {
109
+ type: "yak:focus";
110
+ };
111
+ /**
112
+ * Messages sent FROM the iframe TO the host application
113
+ */
114
+ export type IframeMessageToHost = {
115
+ type: "yak:ready";
116
+ /** Protocol version supported by the embed page */
117
+ payload?: {
118
+ version: EmbedProtocolVersion;
119
+ };
120
+ } | {
121
+ type: "yak:tool_call";
122
+ payload: {
123
+ id: string;
124
+ name: string;
125
+ args: unknown;
126
+ };
127
+ } | {
128
+ type: "yak:graphql_schema_call";
129
+ payload: {
130
+ id: string;
131
+ schemaName: string;
132
+ request: GraphQLRequest;
133
+ };
134
+ } | {
135
+ type: "yak:rest_schema_call";
136
+ payload: {
137
+ id: string;
138
+ schemaName: string;
139
+ request: RESTRequest;
140
+ };
141
+ } | {
142
+ type: "yak:redirect";
143
+ payload: {
144
+ path: string;
145
+ };
146
+ } | {
147
+ type: "yak:close";
148
+ };
149
+ /**
150
+ * Union of all message types (for type guards)
151
+ */
152
+ export type IframeMessage = IframeMessageFromHost | IframeMessageToHost;
153
+ //# sourceMappingURL=messaging.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"messaging.d.ts","sourceRoot":"","sources":["../../src/types/messaging.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC1F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAE1D;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,8BAA8B;IAC9B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,6BAA6B;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,0BAA0B;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,WAAW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AE,MAAM,CAAC;QACnB,OAAO,EAAE,cAAc,CAAC;KACzB,CAAC;CACH,GACD;IACE,IAAI,EAAE,sBAAsB,CAAC;IAC7B,OAAO,EAAE;QACP,EAAE,EAAE,MAAM,CAAC;QACX,UAAU,EAAE,MAAM,CAAC;QACnB,OAAO,EAAE,WAAW,CAAC;KACtB,CAAC;CACH,GACD;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,GACnD;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE,CAAC;AAE1B;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,qBAAqB,GAAG,mBAAmB,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Information about a single route in the host application
3
+ */
4
+ export type RouteInfo = {
5
+ /** The route path, e.g., "/dashboard" or "/posts/[id]" */
6
+ path: string;
7
+ /** Human-readable title extracted from page metadata */
8
+ title?: string;
9
+ /** Description extracted from page metadata */
10
+ description?: string;
11
+ };
12
+ /**
13
+ * Manifest of all routes that can be shared with Yak
14
+ */
15
+ export type RouteManifest = {
16
+ /** List of all discovered routes */
17
+ routes: RouteInfo[];
18
+ /** ISO timestamp when the manifest was generated */
19
+ generated_at: string;
20
+ /** Optional metadata about which adapters produced the routes */
21
+ sources?: Array<{
22
+ id: string;
23
+ count: number;
24
+ }>;
25
+ };
26
+ //# sourceMappingURL=routes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/types/routes.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB,0DAA0D;IAC1D,IAAI,EAAE,MAAM,CAAC;IACb,wDAAwD;IACxD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,+CAA+C;IAC/C,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,oCAAoC;IACpC,MAAM,EAAE,SAAS,EAAE,CAAC;IACpB,oDAAoD;IACpD,YAAY,EAAE,MAAM,CAAC;IACrB,iEAAiE;IACjE,OAAO,CAAC,EAAE,KAAK,CAAC;QACd,EAAE,EAAE,MAAM,CAAC;QACX,KAAK,EAAE,MAAM,CAAC;KACf,CAAC,CAAC;CACJ,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,137 @@
1
+ /**
2
+ * Generic JSON Schema type
3
+ */
4
+ export type JSONSchema = Record<string, unknown>;
5
+ /**
6
+ * GraphQL schema source for providing API context to the LLM
7
+ */
8
+ export type GraphQLSchemaSource = {
9
+ /** Unique identifier for this schema (used in callbacks) */
10
+ name: string;
11
+ type: "graphql";
12
+ /** The GraphQL schema in SDL format */
13
+ schema: string;
14
+ };
15
+ /**
16
+ * OpenAPI spec source for providing API context to the LLM
17
+ */
18
+ export type OpenAPISchemaSource = {
19
+ /** Unique identifier for this schema (used in callbacks) */
20
+ name: string;
21
+ type: "openapi";
22
+ /** OpenAPI spec as JSON object or YAML string */
23
+ spec: Record<string, unknown> | string;
24
+ };
25
+ /**
26
+ * Union type for schema sources
27
+ */
28
+ export type SchemaSource = GraphQLSchemaSource | OpenAPISchemaSource;
29
+ /**
30
+ * GraphQL request generated by the LLM
31
+ */
32
+ export type GraphQLRequest = {
33
+ /** The GraphQL query or mutation string */
34
+ query: string;
35
+ /** Variables for the operation */
36
+ variables?: Record<string, unknown>;
37
+ /** Optional operation name if multiple operations in query */
38
+ operationName?: string;
39
+ };
40
+ /**
41
+ * REST request generated by the LLM
42
+ */
43
+ export type RESTRequest = {
44
+ /** HTTP method */
45
+ method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
46
+ /** Path (e.g., "/users/123") */
47
+ path: string;
48
+ /** Query parameters */
49
+ query?: Record<string, string>;
50
+ /** Request body */
51
+ body?: unknown;
52
+ };
53
+ /**
54
+ * Handler for GraphQL schema tool calls.
55
+ * The LLM generates the query based on the schema context.
56
+ *
57
+ * @param schemaName - The name of the schema (from SchemaSource.name)
58
+ * @param request - The GraphQL request generated by the LLM
59
+ * @returns The result of executing the GraphQL operation
60
+ */
61
+ export type GraphQLSchemaHandler = (schemaName: string, request: GraphQLRequest) => Promise<unknown>;
62
+ /**
63
+ * Handler for OpenAPI/REST schema tool calls.
64
+ * The LLM generates the request based on the schema context.
65
+ *
66
+ * @param schemaName - The name of the schema (from SchemaSource.name)
67
+ * @param request - The REST request generated by the LLM
68
+ * @returns The result of executing the REST request
69
+ */
70
+ export type RESTSchemaHandler = (schemaName: string, request: RESTRequest) => Promise<unknown>;
71
+ /**
72
+ * Payload for a tool call request from the iframe
73
+ */
74
+ export type ToolCallPayload = {
75
+ id: string;
76
+ name: string;
77
+ args: unknown;
78
+ };
79
+ /**
80
+ * Successful tool call result
81
+ */
82
+ export type ToolCallSuccess = {
83
+ ok: true;
84
+ result: unknown;
85
+ };
86
+ /**
87
+ * Failed tool call result
88
+ */
89
+ export type ToolCallError = {
90
+ ok: false;
91
+ error: string;
92
+ };
93
+ /**
94
+ * Union type for tool call responses
95
+ */
96
+ export type ToolCallResult = ToolCallSuccess | ToolCallError;
97
+ /**
98
+ * Definition of a single tool available to the LLM
99
+ */
100
+ export type ToolDefinition = {
101
+ /** Fully qualified procedure name, e.g. "orders.list" */
102
+ name: string;
103
+ /** Human friendly label */
104
+ displayName?: string;
105
+ /** Description shown to the LLM as a tool description */
106
+ description?: string;
107
+ /** Optional JSON Schema for input args */
108
+ inputSchema?: JSONSchema;
109
+ /** Optional JSON Schema for output shape */
110
+ outputSchema?: JSONSchema;
111
+ };
112
+ /**
113
+ * Manifest of all tools available to the chatbot
114
+ */
115
+ export type ToolManifest = {
116
+ tools: ToolDefinition[];
117
+ generated_at?: string;
118
+ sources?: Array<{
119
+ id: string;
120
+ count: number;
121
+ }>;
122
+ };
123
+ /**
124
+ * Tool executor function type (server-side, receives Request object)
125
+ */
126
+ export type ToolExecutor = (name: string, args: unknown, req: Request) => Promise<unknown>;
127
+ /**
128
+ * Tool call handler for client-side integration.
129
+ * The consuming app decides how to execute the tool call.
130
+ *
131
+ * @param name - The tool name being called
132
+ * @param args - The arguments for the tool
133
+ * @returns The result of the tool execution
134
+ * @throws Error if the tool call fails
135
+ */
136
+ export type ToolCallHandler = (name: string, args: unknown) => Promise<unknown>;
137
+ //# sourceMappingURL=tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/types/tools.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAEjD;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,4DAA4D;IAC5D,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,SAAS,CAAC;IAChB,uCAAuC;IACvC,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,4DAA4D;IAC5D,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,SAAS,CAAC;IAChB,iDAAiD;IACjD,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC;CACxC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,mBAAmB,GAAG,mBAAmB,CAAC;AAErE;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,2CAA2C;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,kCAAkC;IAClC,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpC,8DAA8D;IAC9D,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,kBAAkB;IAClB,MAAM,EAAE,KAAK,GAAG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U,CAAC;CAC3B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,KAAK,EAAE,cAAc,EAAE,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,KAAK,CAAC;QACd,EAAE,EAAE,MAAM,CAAC;QACX,KAAK,EAAE,MAAM,CAAC;KACf,CAAC,CAAC;CACJ,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAE3F;;;;;;;;GAQG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Embed protocol version.
3
+ *
4
+ * This version is used in the embed URL path (e.g., /embed/v1/[appId])
5
+ * and in the message protocol to ensure compatibility between the
6
+ * host packages (@yak-io/javascript, @yak-io/react, @yak-io/nextjs)
7
+ * and the embedded chat UI.
8
+ *
9
+ * Increment this version when making breaking changes to:
10
+ * - The postMessage protocol (IframeMessageFromHost, IframeMessageToHost)
11
+ * - The tool manifest format
12
+ * - The route manifest format
13
+ * - The config payload structure
14
+ *
15
+ * Version history:
16
+ * - v1: Initial versioned protocol
17
+ */
18
+ export declare const EMBED_PROTOCOL_VERSION: "1";
19
+ /**
20
+ * Type for the embed protocol version
21
+ */
22
+ export type EmbedProtocolVersion = typeof EMBED_PROTOCOL_VERSION;
23
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,sBAAsB,EAAG,GAAY,CAAC;AAEnD;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,OAAO,sBAAsB,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Embed protocol version.
3
+ *
4
+ * This version is used in the embed URL path (e.g., /embed/v1/[appId])
5
+ * and in the message protocol to ensure compatibility between the
6
+ * host packages (@yak-io/javascript, @yak-io/react, @yak-io/nextjs)
7
+ * and the embedded chat UI.
8
+ *
9
+ * Increment this version when making breaking changes to:
10
+ * - The postMessage protocol (IframeMessageFromHost, IframeMessageToHost)
11
+ * - The tool manifest format
12
+ * - The route manifest format
13
+ * - The config payload structure
14
+ *
15
+ * Version history:
16
+ * - v1: Initial versioned protocol
17
+ */
18
+ export const EMBED_PROTOCOL_VERSION = "1";
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@yak-io/javascript",
3
+ "version": "0.1.0",
4
+ "description": "Core JavaScript SDK for embedding yak chatbot",
5
+ "type": "module",
6
+ "license": "SEE LICENSE IN LICENSE",
7
+ "author": "Yak <support@yak.io>",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/9f-au/yak.git",
11
+ "directory": "packages/javascript"
12
+ },
13
+ "publishConfig": {
14
+ "access": "public",
15
+ "provenance": false
16
+ },
17
+ "keywords": [
18
+ "yak",
19
+ "chatbot",
20
+ "ai",
21
+ "widget",
22
+ "chat",
23
+ "embed"
24
+ ],
25
+ "engines": {
26
+ "node": ">=18"
27
+ },
28
+ "files": [
29
+ "dist",
30
+ "LICENSE"
31
+ ],
32
+ "sideEffects": false,
33
+ "exports": {
34
+ ".": {
35
+ "types": "./dist/index.d.ts",
36
+ "import": "./dist/index.js"
37
+ },
38
+ "./server": {
39
+ "types": "./dist/index.server.d.ts",
40
+ "import": "./dist/index.server.js"
41
+ },
42
+ "./package.json": "./package.json"
43
+ },
44
+ "devDependencies": {
45
+ "@types/node": "^24.10.2",
46
+ "typescript": "^5.3.0",
47
+ "@repo/typescript-config": "0.0.0"
48
+ },
49
+ "scripts": {
50
+ "build": "tsc",
51
+ "check-types": "tsc --noEmit"
52
+ }
53
+ }