@dot-agent/sdk 0.10.1 → 0.10.3

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/dist/index.cjs CHANGED
@@ -1,181 +1,160 @@
1
- "use strict";
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region \0rolldown/runtime.js
2
3
  var __create = Object.create;
3
4
  var __defProp = Object.defineProperty;
4
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
7
  var __getProtoOf = Object.getPrototypeOf;
7
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
9
  var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
10
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
+ get: ((k) => from[k]).bind(null, key),
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
16
+ }
17
+ return to;
19
18
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/index.ts
31
- var index_exports = {};
32
- __export(index_exports, {
33
- AgentSession: () => AgentSession,
34
- loadAgent: () => loadAgent
35
- });
36
- module.exports = __toCommonJS(index_exports);
37
-
38
- // src/load.ts
39
- var import_jszip = __toESM(require("jszip"), 1);
40
- var import_core = require("@dot-agent/compiler/core");
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
20
+ value: mod,
21
+ enumerable: true
22
+ }) : target, mod));
23
+ //#endregion
24
+ let jszip = require("jszip");
25
+ jszip = __toESM(jszip, 1);
26
+ let _dot_agent_compiler_core = require("@dot-agent/compiler/core");
27
+ let _dot_agent_kernel_dsl = require("@dot-agent/kernel-dsl");
28
+ //#region src/load.ts
41
29
  async function loadAgent(input) {
42
- const bytes = input instanceof Uint8Array ? input : new Uint8Array(input);
43
- (0, import_core.validateMagicBytes)(bytes);
44
- const zip = await import_jszip.default.loadAsync(bytes);
45
- (0, import_core.validateZipBomb)(zip, bytes.length);
46
- const aboutmeFile = zip.file(".agent/aboutme.json");
47
- if (!aboutmeFile) throw new Error("Missing .agent/aboutme.json in bundle");
48
- const aboutme = (0, import_core.parseAboutme)(JSON.parse(await aboutmeFile.async("text")));
49
- const filesJsonFile = zip.file(".agent/files.json");
50
- if (!filesJsonFile) throw new Error("Missing .agent/files.json in bundle");
51
- const filesJson = JSON.parse(await filesJsonFile.async("text"));
52
- const descFile = zip.file(filesJson.description);
53
- const behavFile = zip.file(filesJson.behavior);
54
- if (!descFile) throw new Error(`Missing ${filesJson.description} in bundle`);
55
- if (!behavFile) throw new Error(`Missing ${filesJson.behavior} in bundle`);
56
- const personaFile = filesJson.persona ? zip.file(filesJson.persona) : null;
57
- const allFiles = await (0, import_core.extractFiles)(zip);
58
- const guides = [];
59
- const knowledge = [];
60
- const behaviors = [];
61
- for (const [path, content] of allFiles) {
62
- if (path.startsWith("guides/") && path !== "guides/.gitkeep") {
63
- guides.push({ path, content });
64
- } else if (path.startsWith("knowledge/") && path !== "knowledge/.gitkeep") {
65
- knowledge.push({ path, content });
66
- } else if (path.startsWith("behaviors/") && path !== "behaviors/.gitkeep") {
67
- behaviors.push({ path, content });
68
- }
69
- }
70
- return {
71
- id: aboutme.id,
72
- aboutme,
73
- files: {
74
- description: await descFile.async("text"),
75
- behavior: await behavFile.async("text"),
76
- persona: personaFile ? await personaFile.async("text") : void 0,
77
- guides,
78
- knowledge,
79
- behaviors
80
- }
81
- };
30
+ const bytes = input instanceof Uint8Array ? input : new Uint8Array(input);
31
+ (0, _dot_agent_compiler_core.validateMagicBytes)(bytes);
32
+ const zip = await jszip.default.loadAsync(bytes);
33
+ (0, _dot_agent_compiler_core.validateZipBomb)(zip, bytes.length);
34
+ const aboutmeFile = zip.file(".agent/aboutme.json");
35
+ if (!aboutmeFile) throw new Error("Missing .agent/aboutme.json in bundle");
36
+ const aboutme = (0, _dot_agent_compiler_core.parseAboutme)(JSON.parse(await aboutmeFile.async("text")));
37
+ const filesJsonFile = zip.file(".agent/files.json");
38
+ if (!filesJsonFile) throw new Error("Missing .agent/files.json in bundle");
39
+ const filesJson = JSON.parse(await filesJsonFile.async("text"));
40
+ const descFile = zip.file(filesJson.description);
41
+ const behavFile = zip.file(filesJson.behavior);
42
+ if (!descFile) throw new Error(`Missing ${filesJson.description} in bundle`);
43
+ if (!behavFile) throw new Error(`Missing ${filesJson.behavior} in bundle`);
44
+ const personaFile = filesJson.persona ? zip.file(filesJson.persona) : null;
45
+ const allFiles = await (0, _dot_agent_compiler_core.extractFiles)(zip);
46
+ const guides = [];
47
+ const knowledge = [];
48
+ const behaviors = [];
49
+ for (const [path, content] of allFiles) {
50
+ const ns = (0, _dot_agent_compiler_core.classifyContentPath)(path);
51
+ if (ns === "guides" && path !== "guides/.gitkeep") guides.push({
52
+ path,
53
+ content
54
+ });
55
+ else if (ns === "knowledge" && path !== "knowledge/.gitkeep") knowledge.push({
56
+ path,
57
+ content
58
+ });
59
+ else if (path.startsWith("behaviors/") && path !== "behaviors/.gitkeep") behaviors.push({
60
+ path,
61
+ content
62
+ });
63
+ }
64
+ return {
65
+ id: aboutme.id,
66
+ aboutme,
67
+ files: {
68
+ description: await descFile.async("text"),
69
+ behavior: await behavFile.async("text"),
70
+ persona: personaFile ? await personaFile.async("text") : void 0,
71
+ guides,
72
+ knowledge,
73
+ behaviors
74
+ }
75
+ };
82
76
  }
83
-
84
- // src/session.ts
85
- var import_kernel_dsl = require("@dot-agent/kernel-dsl");
86
- var AgentSession = class _AgentSession {
87
- kernel;
88
- handlers = /* @__PURE__ */ new Map();
89
- effectListener;
90
- bundle;
91
- constructor(kernel, bundle) {
92
- this.kernel = kernel;
93
- this.bundle = bundle;
94
- }
95
- static async create(bundle) {
96
- await (0, import_kernel_dsl.init)();
97
- const kernel = new import_kernel_dsl.AgentDSLKernel();
98
- return new _AgentSession(kernel, bundle);
99
- }
100
- // Register a synchronous fallback called when a `merge "…"` path is not in the bundle.
101
- // Must be called before start(). Return null/undefined if the path cannot be resolved.
102
- setFileResolver(resolver) {
103
- this.kernel.set_file_resolver(resolver);
104
- }
105
- // Call after registerHandler() — loads the behavior and fires initial effects.
106
- // Passes all merged behavior files as a bundle so the kernel can resolve `merge "…"` paths.
107
- start() {
108
- const bundle = {};
109
- for (const { path, content } of this.bundle.files.behaviors) {
110
- bundle[path] = content;
111
- }
112
- this.dispatchRaw(
113
- this.kernel.load_behavior_with_bundle(
114
- this.bundle.files.behavior,
115
- JSON.stringify(bundle)
116
- )
117
- );
118
- }
119
- registerHandler(effectType, handler) {
120
- this.handlers.set(effectType, handler);
121
- }
122
- setEffectListener(listener) {
123
- this.effectListener = listener;
124
- }
125
- dispatchRaw(raw) {
126
- if (!raw) return;
127
- let effects;
128
- try {
129
- effects = JSON.parse(raw);
130
- } catch {
131
- console.error("[AgentSession] failed to parse effects JSON:", raw);
132
- return;
133
- }
134
- if (!Array.isArray(effects)) return;
135
- for (const effect of effects) {
136
- this.effectListener?.(effect);
137
- const handler = this.handlers.get(effect.type);
138
- if (handler) {
139
- Promise.resolve(handler(effect)).catch((err) => {
140
- console.error(`[AgentSession] handler error for effect "${effect.type}":`, err);
141
- });
142
- }
143
- }
144
- }
145
- sendIntent(intent) {
146
- this.dispatchRaw(this.kernel.send_intent(intent));
147
- }
148
- sendEvent(event) {
149
- this.dispatchRaw(this.kernel.send_event(event));
150
- }
151
- sendOfftopic() {
152
- this.dispatchRaw(this.kernel.send_offtopic());
153
- }
154
- tickPrompt() {
155
- this.dispatchRaw(this.kernel.tick_prompt());
156
- }
157
- getState() {
158
- return this.kernel.get_current_state();
159
- }
160
- getValidIntents() {
161
- return this.kernel.get_valid_intents();
162
- }
163
- getGraph() {
164
- return this.kernel.get_graph();
165
- }
166
- getMemory() {
167
- return JSON.parse(this.kernel.get_memory());
168
- }
169
- injectMemory(domain, key, value) {
170
- this.kernel.set_memory(domain, key, value);
171
- }
172
- dispose() {
173
- this.kernel.free();
174
- }
77
+ //#endregion
78
+ //#region src/session.ts
79
+ var AgentSession = class AgentSession {
80
+ kernel;
81
+ handlers = /* @__PURE__ */ new Map();
82
+ effectListener;
83
+ bundle;
84
+ constructor(kernel, bundle) {
85
+ this.kernel = kernel;
86
+ this.bundle = bundle;
87
+ }
88
+ static async create(bundle) {
89
+ await (0, _dot_agent_kernel_dsl.init)();
90
+ const kernel = new _dot_agent_kernel_dsl.AgentDSLKernel();
91
+ return new AgentSession(kernel, bundle);
92
+ }
93
+ setFileResolver(resolver) {
94
+ this.kernel.set_file_resolver(resolver);
95
+ }
96
+ start() {
97
+ const bundle = {};
98
+ for (const { path, content } of this.bundle.files.behaviors) bundle[path] = content;
99
+ this.dispatchRaw(this.kernel.load_behavior_with_bundle(this.bundle.files.behavior, JSON.stringify(bundle)));
100
+ }
101
+ registerHandler(effectType, handler) {
102
+ this.handlers.set(effectType, handler);
103
+ }
104
+ setEffectListener(listener) {
105
+ this.effectListener = listener;
106
+ }
107
+ dispatchRaw(raw) {
108
+ if (!raw) return;
109
+ let effects;
110
+ try {
111
+ effects = JSON.parse(raw);
112
+ } catch {
113
+ console.error("[AgentSession] failed to parse effects JSON:", raw);
114
+ return;
115
+ }
116
+ if (!Array.isArray(effects)) return;
117
+ for (const effect of effects) {
118
+ this.effectListener?.(effect);
119
+ const handler = this.handlers.get(effect.type);
120
+ if (handler) Promise.resolve(handler(effect)).catch((err) => {
121
+ console.error(`[AgentSession] handler error for effect "${effect.type}":`, err);
122
+ });
123
+ }
124
+ }
125
+ sendIntent(intent) {
126
+ this.dispatchRaw(this.kernel.send_intent(intent));
127
+ }
128
+ sendEvent(event) {
129
+ this.dispatchRaw(this.kernel.send_event(event));
130
+ }
131
+ sendOfftopic() {
132
+ this.dispatchRaw(this.kernel.send_offtopic());
133
+ }
134
+ tickPrompt() {
135
+ this.dispatchRaw(this.kernel.tick_prompt());
136
+ }
137
+ getState() {
138
+ return this.kernel.get_current_state();
139
+ }
140
+ getValidIntents() {
141
+ return this.kernel.get_valid_intents();
142
+ }
143
+ getGraph() {
144
+ return this.kernel.get_graph();
145
+ }
146
+ getMemory() {
147
+ return JSON.parse(this.kernel.get_memory());
148
+ }
149
+ injectMemory(domain, key, value) {
150
+ this.kernel.set_memory(domain, key, value);
151
+ }
152
+ dispose() {
153
+ this.kernel.free();
154
+ }
175
155
  };
176
- // Annotate the CommonJS export names for ESM import in node:
177
- 0 && (module.exports = {
178
- AgentSession,
179
- loadAgent
180
- });
156
+ //#endregion
157
+ exports.AgentSession = AgentSession;
158
+ exports.loadAgent = loadAgent;
159
+
181
160
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/load.ts","../src/session.ts"],"sourcesContent":["// Copyright 2026 Danilo Borges\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport { loadAgent } from './load.js'\nexport { AgentSession } from './session.js'\nexport type { AgentBundle, AgentFiles, Effect, EffectHandler, AboutMe } from './types.js'\n","// Copyright 2026 Danilo Borges\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport JSZip from 'jszip'\nimport { parseAboutme, extractFiles, validateMagicBytes, validateZipBomb } from '@dot-agent/compiler/core'\nimport type { AgentBundle } from './types.js'\n\nexport async function loadAgent(input: Uint8Array | ArrayBuffer): Promise<AgentBundle> {\n const bytes = input instanceof Uint8Array ? input : new Uint8Array(input)\n\n validateMagicBytes(bytes)\n\n const zip = await JSZip.loadAsync(bytes)\n validateZipBomb(zip, bytes.length)\n\n const aboutmeFile = zip.file('.agent/aboutme.json')\n if (!aboutmeFile) throw new Error('Missing .agent/aboutme.json in bundle')\n const aboutme = parseAboutme(JSON.parse(await aboutmeFile.async('text')))\n\n const filesJsonFile = zip.file('.agent/files.json')\n if (!filesJsonFile) throw new Error('Missing .agent/files.json in bundle')\n const filesJson = JSON.parse(await filesJsonFile.async('text')) as {\n description: string\n behavior: string\n persona?: string\n behaviors?: string[]\n guides?: string[]\n knowledge?: string[]\n }\n\n const descFile = zip.file(filesJson.description)\n const behavFile = zip.file(filesJson.behavior)\n if (!descFile) throw new Error(`Missing ${filesJson.description} in bundle`)\n if (!behavFile) throw new Error(`Missing ${filesJson.behavior} in bundle`)\n\n const personaFile = filesJson.persona ? zip.file(filesJson.persona) : null\n const allFiles = await extractFiles(zip)\n\n const guides: Array<{ path: string; content: string }> = []\n const knowledge: Array<{ path: string; content: string }> = []\n const behaviors: Array<{ path: string; content: string }> = []\n\n for (const [path, content] of allFiles) {\n if (path.startsWith('guides/') && path !== 'guides/.gitkeep') {\n guides.push({ path, content })\n } else if (path.startsWith('knowledge/') && path !== 'knowledge/.gitkeep') {\n knowledge.push({ path, content })\n } else if (path.startsWith('behaviors/') && path !== 'behaviors/.gitkeep') {\n behaviors.push({ path, content })\n }\n }\n\n return {\n id: aboutme.id,\n aboutme,\n files: {\n description: await descFile.async('text'),\n behavior: await behavFile.async('text'),\n persona: personaFile ? await personaFile.async('text') : undefined,\n guides,\n knowledge,\n behaviors,\n },\n }\n}\n","// Copyright 2026 Danilo Borges\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { AgentDSLKernel, init as initKernel } from '@dot-agent/kernel-dsl'\nimport type { AgentBundle, Effect, EffectHandler } from './types.js'\n\nexport class AgentSession {\n private kernel: AgentDSLKernel\n private handlers = new Map<string, EffectHandler>()\n private effectListener?: (effect: Effect) => void\n readonly bundle: AgentBundle\n\n private constructor(kernel: AgentDSLKernel, bundle: AgentBundle) {\n this.kernel = kernel\n this.bundle = bundle\n }\n\n static async create(bundle: AgentBundle): Promise<AgentSession> {\n await initKernel()\n const kernel = new AgentDSLKernel()\n return new AgentSession(kernel, bundle)\n }\n\n // Register a synchronous fallback called when a `merge \"…\"` path is not in the bundle.\n // Must be called before start(). Return null/undefined if the path cannot be resolved.\n setFileResolver(resolver: (path: string) => string | null | undefined): void {\n this.kernel.set_file_resolver(resolver as unknown as Function)\n }\n\n // Call after registerHandler() — loads the behavior and fires initial effects.\n // Passes all merged behavior files as a bundle so the kernel can resolve `merge \"…\"` paths.\n start(): void {\n const bundle: Record<string, string> = {}\n for (const { path, content } of this.bundle.files.behaviors) {\n bundle[path] = content\n }\n this.dispatchRaw(\n this.kernel.load_behavior_with_bundle(\n this.bundle.files.behavior,\n JSON.stringify(bundle),\n )\n )\n }\n\n registerHandler(effectType: string, handler: EffectHandler): void {\n this.handlers.set(effectType, handler)\n }\n\n setEffectListener(listener: ((effect: Effect) => void) | undefined): void {\n this.effectListener = listener\n }\n\n private dispatchRaw(raw: string): void {\n if (!raw) return\n let effects: Effect[]\n try {\n effects = JSON.parse(raw)\n } catch {\n console.error('[AgentSession] failed to parse effects JSON:', raw)\n return\n }\n if (!Array.isArray(effects)) return\n for (const effect of effects) {\n this.effectListener?.(effect)\n const handler = this.handlers.get(effect.type)\n if (handler) {\n Promise.resolve(handler(effect)).catch(err => {\n console.error(`[AgentSession] handler error for effect \"${effect.type}\":`, err)\n })\n }\n }\n }\n\n sendIntent(intent: string): void { this.dispatchRaw(this.kernel.send_intent(intent)) }\n sendEvent(event: string): void { this.dispatchRaw(this.kernel.send_event(event)) }\n sendOfftopic(): void { this.dispatchRaw(this.kernel.send_offtopic()) }\n tickPrompt(): void { this.dispatchRaw(this.kernel.tick_prompt()) }\n\n getState(): string { return this.kernel.get_current_state() }\n getValidIntents(): Array<any> { return this.kernel.get_valid_intents() }\n getGraph(): string { return this.kernel.get_graph() }\n getMemory(): Array<{ domain: string; key: string; value: unknown }> {\n return JSON.parse(this.kernel.get_memory())\n }\n\n injectMemory(domain: string, key: string, value: string): void {\n this.kernel.set_memory(domain, key, value)\n }\n\n dispose(): void { this.kernel.free() }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACcA,mBAAkB;AAClB,kBAAgF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"sources":["../src/load.ts","../src/session.ts"],"sourcesContent":["// Copyright 2026 Danilo Borges\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport JSZip from 'jszip'\nimport { parseAboutme, extractFiles, validateMagicBytes, validateZipBomb, classifyContentPath } from '@dot-agent/compiler/core'\nimport type { AgentBundle } from './types.js'\n\nexport async function loadAgent(input: Uint8Array | ArrayBuffer): Promise<AgentBundle> {\n const bytes = input instanceof Uint8Array ? input : new Uint8Array(input)\n\n validateMagicBytes(bytes)\n\n const zip = await JSZip.loadAsync(bytes)\n validateZipBomb(zip, bytes.length)\n\n const aboutmeFile = zip.file('.agent/aboutme.json')\n if (!aboutmeFile) throw new Error('Missing .agent/aboutme.json in bundle')\n const aboutme = parseAboutme(JSON.parse(await aboutmeFile.async('text')))\n\n const filesJsonFile = zip.file('.agent/files.json')\n if (!filesJsonFile) throw new Error('Missing .agent/files.json in bundle')\n const filesJson = JSON.parse(await filesJsonFile.async('text')) as {\n description: string\n behavior: string\n persona?: string\n behaviors?: string[]\n guides?: string[]\n knowledge?: string[]\n }\n\n const descFile = zip.file(filesJson.description)\n const behavFile = zip.file(filesJson.behavior)\n if (!descFile) throw new Error(`Missing ${filesJson.description} in bundle`)\n if (!behavFile) throw new Error(`Missing ${filesJson.behavior} in bundle`)\n\n const personaFile = filesJson.persona ? zip.file(filesJson.persona) : null\n const allFiles = await extractFiles(zip)\n\n const guides: Array<{ path: string; content: string }> = []\n const knowledge: Array<{ path: string; content: string }> = []\n const behaviors: Array<{ path: string; content: string }> = []\n\n for (const [path, content] of allFiles) {\n const ns = classifyContentPath(path)\n if (ns === 'guides' && path !== 'guides/.gitkeep') {\n guides.push({ path, content })\n } else if (ns === 'knowledge' && path !== 'knowledge/.gitkeep') {\n knowledge.push({ path, content })\n } else if (path.startsWith('behaviors/') && path !== 'behaviors/.gitkeep') {\n behaviors.push({ path, content })\n }\n }\n\n return {\n id: aboutme.id,\n aboutme,\n files: {\n description: await descFile.async('text'),\n behavior: await behavFile.async('text'),\n persona: personaFile ? await personaFile.async('text') : undefined,\n guides,\n knowledge,\n behaviors,\n },\n }\n}\n","// Copyright 2026 Danilo Borges\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { AgentDSLKernel, init as initKernel } from '@dot-agent/kernel-dsl'\nimport type { AgentBundle, Effect, EffectHandler } from './types.js'\n\nexport class AgentSession {\n private kernel: AgentDSLKernel\n private handlers = new Map<string, EffectHandler>()\n private effectListener?: (effect: Effect) => void\n readonly bundle: AgentBundle\n\n private constructor(kernel: AgentDSLKernel, bundle: AgentBundle) {\n this.kernel = kernel\n this.bundle = bundle\n }\n\n static async create(bundle: AgentBundle): Promise<AgentSession> {\n await initKernel()\n const kernel = new AgentDSLKernel()\n return new AgentSession(kernel, bundle)\n }\n\n // Register a synchronous fallback called when a `merge \"…\"` path is not in the bundle.\n // Must be called before start(). Return null/undefined if the path cannot be resolved.\n setFileResolver(resolver: (path: string) => string | null | undefined): void {\n this.kernel.set_file_resolver(resolver as unknown as Function)\n }\n\n // Call after registerHandler() — loads the behavior and fires initial effects.\n // Passes all merged behavior files as a bundle so the kernel can resolve `merge \"…\"` paths.\n start(): void {\n const bundle: Record<string, string> = {}\n for (const { path, content } of this.bundle.files.behaviors) {\n bundle[path] = content\n }\n this.dispatchRaw(\n this.kernel.load_behavior_with_bundle(\n this.bundle.files.behavior,\n JSON.stringify(bundle),\n )\n )\n }\n\n registerHandler(effectType: string, handler: EffectHandler): void {\n this.handlers.set(effectType, handler)\n }\n\n setEffectListener(listener: ((effect: Effect) => void) | undefined): void {\n this.effectListener = listener\n }\n\n private dispatchRaw(raw: string): void {\n if (!raw) return\n let effects: Effect[]\n try {\n effects = JSON.parse(raw)\n } catch {\n console.error('[AgentSession] failed to parse effects JSON:', raw)\n return\n }\n if (!Array.isArray(effects)) return\n for (const effect of effects) {\n this.effectListener?.(effect)\n const handler = this.handlers.get(effect.type)\n if (handler) {\n Promise.resolve(handler(effect)).catch(err => {\n console.error(`[AgentSession] handler error for effect \"${effect.type}\":`, err)\n })\n }\n }\n }\n\n sendIntent(intent: string): void { this.dispatchRaw(this.kernel.send_intent(intent)) }\n sendEvent(event: string): void { this.dispatchRaw(this.kernel.send_event(event)) }\n sendOfftopic(): void { this.dispatchRaw(this.kernel.send_offtopic()) }\n tickPrompt(): void { this.dispatchRaw(this.kernel.tick_prompt()) }\n\n getState(): string { return this.kernel.get_current_state() }\n getValidIntents(): Array<any> { return this.kernel.get_valid_intents() }\n getGraph(): string { return this.kernel.get_graph() }\n getMemory(): Array<{ domain: string; key: string; value: unknown }> {\n return JSON.parse(this.kernel.get_memory())\n }\n\n injectMemory(domain: string, key: string, value: string): void {\n this.kernel.set_memory(domain, key, value)\n }\n\n dispose(): void { this.kernel.free() }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBA,eAAsB,UAAU,OAAuD;CACrF,MAAM,QAAQ,iBAAiB,aAAa,QAAQ,IAAI,WAAW,KAAK;CAExE,CAAA,GAAA,yBAAA,mBAAA,CAAmB,KAAK;CAExB,MAAM,MAAM,MAAMA,MAAAA,QAAM,UAAU,KAAK;CACvC,CAAA,GAAA,yBAAA,gBAAA,CAAgB,KAAK,MAAM,MAAM;CAEjC,MAAM,cAAc,IAAI,KAAK,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,CAAC;CAAE;CACtF,UAAU,OAAwB;EAAE,KAAK,YAAY,KAAK,OAAO,WAAW,KAAK,CAAC;CAAE;CACpF,eAAkC;EAAE,KAAK,YAAY,KAAK,OAAO,cAAc,CAAC;CAAE;CAClF,aAAkC;EAAE,KAAK,YAAY,KAAK,OAAO,YAAY,CAAC;CAAE;CAEhF,WAA8B;EAAE,OAAO,KAAK,OAAO,kBAAkB;CAAE;CACvE,kBAA8B;EAAE,OAAO,KAAK,OAAO,kBAAkB;CAAE;CACvE,WAA8B;EAAE,OAAO,KAAK,OAAO,UAAU;CAAE;CAC/D,YAAoE;EAClE,OAAO,KAAK,MAAM,KAAK,OAAO,WAAW,CAAC;CAC5C;CAEA,aAAa,QAAgB,KAAa,OAAqB;EAC7D,KAAK,OAAO,WAAW,QAAQ,KAAK,KAAK;CAC3C;CAEA,UAAgB;EAAE,KAAK,OAAO,KAAK;CAAE;AACvC"}
package/dist/index.d.cts CHANGED
@@ -1,40 +1,42 @@
1
- import { AgentBundle } from '@dot-agent/compiler/core';
2
- export { AboutMe, AgentBundle, AgentFiles } from '@dot-agent/compiler/core';
3
-
1
+ import { AboutMe, AgentBundle, AgentFiles } from "@dot-agent/compiler/core";
2
+ //#region src/types.d.ts
4
3
  type EffectHandler = (effect: Effect) => void | Promise<void>;
5
4
  interface Effect {
6
- type: string;
7
- [key: string]: unknown;
5
+ type: string;
6
+ [key: string]: unknown;
8
7
  }
9
-
8
+ //#endregion
9
+ //#region src/load.d.ts
10
10
  declare function loadAgent(input: Uint8Array | ArrayBuffer): Promise<AgentBundle>;
11
-
11
+ //#endregion
12
+ //#region src/session.d.ts
12
13
  declare class AgentSession {
13
- private kernel;
14
- private handlers;
15
- private effectListener?;
16
- readonly bundle: AgentBundle;
17
- private constructor();
18
- static create(bundle: AgentBundle): Promise<AgentSession>;
19
- setFileResolver(resolver: (path: string) => string | null | undefined): void;
20
- start(): void;
21
- registerHandler(effectType: string, handler: EffectHandler): void;
22
- setEffectListener(listener: ((effect: Effect) => void) | undefined): void;
23
- private dispatchRaw;
24
- sendIntent(intent: string): void;
25
- sendEvent(event: string): void;
26
- sendOfftopic(): void;
27
- tickPrompt(): void;
28
- getState(): string;
29
- getValidIntents(): Array<any>;
30
- getGraph(): string;
31
- getMemory(): Array<{
32
- domain: string;
33
- key: string;
34
- value: unknown;
35
- }>;
36
- injectMemory(domain: string, key: string, value: string): void;
37
- dispose(): void;
14
+ private kernel;
15
+ private handlers;
16
+ private effectListener?;
17
+ readonly bundle: AgentBundle;
18
+ private constructor();
19
+ static create(bundle: AgentBundle): Promise<AgentSession>;
20
+ setFileResolver(resolver: (path: string) => string | null | undefined): void;
21
+ start(): void;
22
+ registerHandler(effectType: string, handler: EffectHandler): void;
23
+ setEffectListener(listener: ((effect: Effect) => void) | undefined): void;
24
+ private dispatchRaw;
25
+ sendIntent(intent: string): void;
26
+ sendEvent(event: string): void;
27
+ sendOfftopic(): void;
28
+ tickPrompt(): void;
29
+ getState(): string;
30
+ getValidIntents(): Array<any>;
31
+ getGraph(): string;
32
+ getMemory(): Array<{
33
+ domain: string;
34
+ key: string;
35
+ value: unknown;
36
+ }>;
37
+ injectMemory(domain: string, key: string, value: string): void;
38
+ dispose(): void;
38
39
  }
39
-
40
- export { AgentSession, type Effect, type EffectHandler, loadAgent };
40
+ //#endregion
41
+ export { type AboutMe, type AgentBundle, type AgentFiles, AgentSession, type Effect, type EffectHandler, loadAgent };
42
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/load.ts","../src/session.ts"],"mappings":";;KAkBY,iBAAiB,QAAQ,kBAAkB;UAEtC;EACf;GACC;;;;iBCJmB,UAAU,OAAO,aAAa,cAAc,QAAQ;;;cCD7D;UACH;UACA;UACA;WACC,QAAQ;UAEV;SAKM,OAAO,QAAQ,cAAc,QAAQ;EAQlD,gBAAgB,WAAW;EAM3B;EAaA,gBAAgB,oBAAoB,SAAS;EAI7C,kBAAkB,YAAY,QAAQ;UAI9B;EAqBR,WAAW;EACX,UAAU;EACV;EACA;EAEA;EACA,mBAAmB;EACnB;EACA,aAAa;IAAQ;IAAgB;IAAa;;EAIlD,aAAa,gBAAgB,aAAa;EAI1C"}
@@ -0,0 +1,42 @@
1
+ import { AboutMe, AgentBundle, AgentFiles } from "@dot-agent/compiler/core";
2
+ //#region src/types.d.ts
3
+ type EffectHandler = (effect: Effect) => void | Promise<void>;
4
+ interface Effect {
5
+ type: string;
6
+ [key: string]: unknown;
7
+ }
8
+ //#endregion
9
+ //#region src/load.d.ts
10
+ declare function loadAgent(input: Uint8Array | ArrayBuffer): Promise<AgentBundle>;
11
+ //#endregion
12
+ //#region src/session.d.ts
13
+ declare class AgentSession {
14
+ private kernel;
15
+ private handlers;
16
+ private effectListener?;
17
+ readonly bundle: AgentBundle;
18
+ private constructor();
19
+ static create(bundle: AgentBundle): Promise<AgentSession>;
20
+ setFileResolver(resolver: (path: string) => string | null | undefined): void;
21
+ start(): void;
22
+ registerHandler(effectType: string, handler: EffectHandler): void;
23
+ setEffectListener(listener: ((effect: Effect) => void) | undefined): void;
24
+ private dispatchRaw;
25
+ sendIntent(intent: string): void;
26
+ sendEvent(event: string): void;
27
+ sendOfftopic(): void;
28
+ tickPrompt(): void;
29
+ getState(): string;
30
+ getValidIntents(): Array<any>;
31
+ getGraph(): string;
32
+ getMemory(): Array<{
33
+ domain: string;
34
+ key: string;
35
+ value: unknown;
36
+ }>;
37
+ injectMemory(domain: string, key: string, value: string): void;
38
+ dispose(): void;
39
+ }
40
+ //#endregion
41
+ export { type AboutMe, type AgentBundle, type AgentFiles, AgentSession, type Effect, type EffectHandler, loadAgent };
42
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/load.ts","../src/session.ts"],"mappings":";;KAkBY,iBAAiB,QAAQ,kBAAkB;UAEtC;EACf;GACC;;;;iBCJmB,UAAU,OAAO,aAAa,cAAc,QAAQ;;;cCD7D;UACH;UACA;UACA;WACC,QAAQ;UAEV;SAKM,OAAO,QAAQ,cAAc,QAAQ;EAQlD,gBAAgB,WAAW;EAM3B;EAaA,gBAAgB,oBAAoB,SAAS;EAI7C,kBAAkB,YAAY,QAAQ;UAI9B;EAqBR,WAAW;EACX,UAAU;EACV;EACA;EAEA;EACA,mBAAmB;EACnB;EACA,aAAa;IAAQ;IAAgB;IAAa;;EAIlD,aAAa,gBAAgB,aAAa;EAI1C"}
package/dist/index.mjs ADDED
@@ -0,0 +1,135 @@
1
+ import JSZip from "jszip";
2
+ import { classifyContentPath, extractFiles, parseAboutme, validateMagicBytes, validateZipBomb } from "@dot-agent/compiler/core";
3
+ import { AgentDSLKernel, init } from "@dot-agent/kernel-dsl";
4
+ //#region src/load.ts
5
+ async function loadAgent(input) {
6
+ const bytes = input instanceof Uint8Array ? input : new Uint8Array(input);
7
+ validateMagicBytes(bytes);
8
+ const zip = await JSZip.loadAsync(bytes);
9
+ validateZipBomb(zip, bytes.length);
10
+ const aboutmeFile = zip.file(".agent/aboutme.json");
11
+ if (!aboutmeFile) throw new Error("Missing .agent/aboutme.json in bundle");
12
+ const aboutme = parseAboutme(JSON.parse(await aboutmeFile.async("text")));
13
+ const filesJsonFile = zip.file(".agent/files.json");
14
+ if (!filesJsonFile) throw new Error("Missing .agent/files.json in bundle");
15
+ const filesJson = JSON.parse(await filesJsonFile.async("text"));
16
+ const descFile = zip.file(filesJson.description);
17
+ const behavFile = zip.file(filesJson.behavior);
18
+ if (!descFile) throw new Error(`Missing ${filesJson.description} in bundle`);
19
+ if (!behavFile) throw new Error(`Missing ${filesJson.behavior} in bundle`);
20
+ const personaFile = filesJson.persona ? zip.file(filesJson.persona) : null;
21
+ const allFiles = await extractFiles(zip);
22
+ const guides = [];
23
+ const knowledge = [];
24
+ const behaviors = [];
25
+ for (const [path, content] of allFiles) {
26
+ const ns = classifyContentPath(path);
27
+ if (ns === "guides" && path !== "guides/.gitkeep") guides.push({
28
+ path,
29
+ content
30
+ });
31
+ else if (ns === "knowledge" && path !== "knowledge/.gitkeep") knowledge.push({
32
+ path,
33
+ content
34
+ });
35
+ else if (path.startsWith("behaviors/") && path !== "behaviors/.gitkeep") behaviors.push({
36
+ path,
37
+ content
38
+ });
39
+ }
40
+ return {
41
+ id: aboutme.id,
42
+ aboutme,
43
+ files: {
44
+ description: await descFile.async("text"),
45
+ behavior: await behavFile.async("text"),
46
+ persona: personaFile ? await personaFile.async("text") : void 0,
47
+ guides,
48
+ knowledge,
49
+ behaviors
50
+ }
51
+ };
52
+ }
53
+ //#endregion
54
+ //#region src/session.ts
55
+ var AgentSession = class AgentSession {
56
+ kernel;
57
+ handlers = /* @__PURE__ */ new Map();
58
+ effectListener;
59
+ bundle;
60
+ constructor(kernel, bundle) {
61
+ this.kernel = kernel;
62
+ this.bundle = bundle;
63
+ }
64
+ static async create(bundle) {
65
+ await init();
66
+ const kernel = new AgentDSLKernel();
67
+ return new AgentSession(kernel, bundle);
68
+ }
69
+ setFileResolver(resolver) {
70
+ this.kernel.set_file_resolver(resolver);
71
+ }
72
+ start() {
73
+ const bundle = {};
74
+ for (const { path, content } of this.bundle.files.behaviors) bundle[path] = content;
75
+ this.dispatchRaw(this.kernel.load_behavior_with_bundle(this.bundle.files.behavior, JSON.stringify(bundle)));
76
+ }
77
+ registerHandler(effectType, handler) {
78
+ this.handlers.set(effectType, handler);
79
+ }
80
+ setEffectListener(listener) {
81
+ this.effectListener = listener;
82
+ }
83
+ dispatchRaw(raw) {
84
+ if (!raw) return;
85
+ let effects;
86
+ try {
87
+ effects = JSON.parse(raw);
88
+ } catch {
89
+ console.error("[AgentSession] failed to parse effects JSON:", raw);
90
+ return;
91
+ }
92
+ if (!Array.isArray(effects)) return;
93
+ for (const effect of effects) {
94
+ this.effectListener?.(effect);
95
+ const handler = this.handlers.get(effect.type);
96
+ if (handler) Promise.resolve(handler(effect)).catch((err) => {
97
+ console.error(`[AgentSession] handler error for effect "${effect.type}":`, err);
98
+ });
99
+ }
100
+ }
101
+ sendIntent(intent) {
102
+ this.dispatchRaw(this.kernel.send_intent(intent));
103
+ }
104
+ sendEvent(event) {
105
+ this.dispatchRaw(this.kernel.send_event(event));
106
+ }
107
+ sendOfftopic() {
108
+ this.dispatchRaw(this.kernel.send_offtopic());
109
+ }
110
+ tickPrompt() {
111
+ this.dispatchRaw(this.kernel.tick_prompt());
112
+ }
113
+ getState() {
114
+ return this.kernel.get_current_state();
115
+ }
116
+ getValidIntents() {
117
+ return this.kernel.get_valid_intents();
118
+ }
119
+ getGraph() {
120
+ return this.kernel.get_graph();
121
+ }
122
+ getMemory() {
123
+ return JSON.parse(this.kernel.get_memory());
124
+ }
125
+ injectMemory(domain, key, value) {
126
+ this.kernel.set_memory(domain, key, value);
127
+ }
128
+ dispose() {
129
+ this.kernel.free();
130
+ }
131
+ };
132
+ //#endregion
133
+ export { AgentSession, loadAgent };
134
+
135
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["initKernel"],"sources":["../src/load.ts","../src/session.ts"],"sourcesContent":["// Copyright 2026 Danilo Borges\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport JSZip from 'jszip'\nimport { parseAboutme, extractFiles, validateMagicBytes, validateZipBomb, classifyContentPath } from '@dot-agent/compiler/core'\nimport type { AgentBundle } from './types.js'\n\nexport async function loadAgent(input: Uint8Array | ArrayBuffer): Promise<AgentBundle> {\n const bytes = input instanceof Uint8Array ? input : new Uint8Array(input)\n\n validateMagicBytes(bytes)\n\n const zip = await JSZip.loadAsync(bytes)\n validateZipBomb(zip, bytes.length)\n\n const aboutmeFile = zip.file('.agent/aboutme.json')\n if (!aboutmeFile) throw new Error('Missing .agent/aboutme.json in bundle')\n const aboutme = parseAboutme(JSON.parse(await aboutmeFile.async('text')))\n\n const filesJsonFile = zip.file('.agent/files.json')\n if (!filesJsonFile) throw new Error('Missing .agent/files.json in bundle')\n const filesJson = JSON.parse(await filesJsonFile.async('text')) as {\n description: string\n behavior: string\n persona?: string\n behaviors?: string[]\n guides?: string[]\n knowledge?: string[]\n }\n\n const descFile = zip.file(filesJson.description)\n const behavFile = zip.file(filesJson.behavior)\n if (!descFile) throw new Error(`Missing ${filesJson.description} in bundle`)\n if (!behavFile) throw new Error(`Missing ${filesJson.behavior} in bundle`)\n\n const personaFile = filesJson.persona ? zip.file(filesJson.persona) : null\n const allFiles = await extractFiles(zip)\n\n const guides: Array<{ path: string; content: string }> = []\n const knowledge: Array<{ path: string; content: string }> = []\n const behaviors: Array<{ path: string; content: string }> = []\n\n for (const [path, content] of allFiles) {\n const ns = classifyContentPath(path)\n if (ns === 'guides' && path !== 'guides/.gitkeep') {\n guides.push({ path, content })\n } else if (ns === 'knowledge' && path !== 'knowledge/.gitkeep') {\n knowledge.push({ path, content })\n } else if (path.startsWith('behaviors/') && path !== 'behaviors/.gitkeep') {\n behaviors.push({ path, content })\n }\n }\n\n return {\n id: aboutme.id,\n aboutme,\n files: {\n description: await descFile.async('text'),\n behavior: await behavFile.async('text'),\n persona: personaFile ? await personaFile.async('text') : undefined,\n guides,\n knowledge,\n behaviors,\n },\n }\n}\n","// Copyright 2026 Danilo Borges\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { AgentDSLKernel, init as initKernel } from '@dot-agent/kernel-dsl'\nimport type { AgentBundle, Effect, EffectHandler } from './types.js'\n\nexport class AgentSession {\n private kernel: AgentDSLKernel\n private handlers = new Map<string, EffectHandler>()\n private effectListener?: (effect: Effect) => void\n readonly bundle: AgentBundle\n\n private constructor(kernel: AgentDSLKernel, bundle: AgentBundle) {\n this.kernel = kernel\n this.bundle = bundle\n }\n\n static async create(bundle: AgentBundle): Promise<AgentSession> {\n await initKernel()\n const kernel = new AgentDSLKernel()\n return new AgentSession(kernel, bundle)\n }\n\n // Register a synchronous fallback called when a `merge \"…\"` path is not in the bundle.\n // Must be called before start(). Return null/undefined if the path cannot be resolved.\n setFileResolver(resolver: (path: string) => string | null | undefined): void {\n this.kernel.set_file_resolver(resolver as unknown as Function)\n }\n\n // Call after registerHandler() — loads the behavior and fires initial effects.\n // Passes all merged behavior files as a bundle so the kernel can resolve `merge \"…\"` paths.\n start(): void {\n const bundle: Record<string, string> = {}\n for (const { path, content } of this.bundle.files.behaviors) {\n bundle[path] = content\n }\n this.dispatchRaw(\n this.kernel.load_behavior_with_bundle(\n this.bundle.files.behavior,\n JSON.stringify(bundle),\n )\n )\n }\n\n registerHandler(effectType: string, handler: EffectHandler): void {\n this.handlers.set(effectType, handler)\n }\n\n setEffectListener(listener: ((effect: Effect) => void) | undefined): void {\n this.effectListener = listener\n }\n\n private dispatchRaw(raw: string): void {\n if (!raw) return\n let effects: Effect[]\n try {\n effects = JSON.parse(raw)\n } catch {\n console.error('[AgentSession] failed to parse effects JSON:', raw)\n return\n }\n if (!Array.isArray(effects)) return\n for (const effect of effects) {\n this.effectListener?.(effect)\n const handler = this.handlers.get(effect.type)\n if (handler) {\n Promise.resolve(handler(effect)).catch(err => {\n console.error(`[AgentSession] handler error for effect \"${effect.type}\":`, err)\n })\n }\n }\n }\n\n sendIntent(intent: string): void { this.dispatchRaw(this.kernel.send_intent(intent)) }\n sendEvent(event: string): void { this.dispatchRaw(this.kernel.send_event(event)) }\n sendOfftopic(): void { this.dispatchRaw(this.kernel.send_offtopic()) }\n tickPrompt(): void { this.dispatchRaw(this.kernel.tick_prompt()) }\n\n getState(): string { return this.kernel.get_current_state() }\n getValidIntents(): Array<any> { return this.kernel.get_valid_intents() }\n getGraph(): string { return this.kernel.get_graph() }\n getMemory(): Array<{ domain: string; key: string; value: unknown }> {\n return JSON.parse(this.kernel.get_memory())\n }\n\n injectMemory(domain: string, key: string, value: string): void {\n this.kernel.set_memory(domain, key, value)\n }\n\n dispose(): void { this.kernel.free() }\n}\n"],"mappings":";;;;AAkBA,eAAsB,UAAU,OAAuD;CACrF,MAAM,QAAQ,iBAAiB,aAAa,QAAQ,IAAI,WAAW,KAAK;CAExE,mBAAmB,KAAK;CAExB,MAAM,MAAM,MAAM,MAAM,UAAU,KAAK;CACvC,gBAAgB,KAAK,MAAM,MAAM;CAEjC,MAAM,cAAc,IAAI,KAAK,qBAAqB;CAClD,IAAI,CAAC,aAAa,MAAM,IAAI,MAAM,uCAAuC;CACzE,MAAM,UAAU,aAAa,KAAK,MAAM,MAAM,YAAY,MAAM,MAAM,CAAC,CAAC;CAExE,MAAM,gBAAgB,IAAI,KAAK,mBAAmB;CAClD,IAAI,CAAC,eAAe,MAAM,IAAI,MAAM,qCAAqC;CACzE,MAAM,YAAY,KAAK,MAAM,MAAM,cAAc,MAAM,MAAM,CAAC;CAS9D,MAAM,WAAW,IAAI,KAAK,UAAU,WAAW;CAC/C,MAAM,YAAY,IAAI,KAAK,UAAU,QAAQ;CAC7C,IAAI,CAAC,UAAU,MAAM,IAAI,MAAM,WAAW,UAAU,YAAY,WAAW;CAC3E,IAAI,CAAC,WAAW,MAAM,IAAI,MAAM,WAAW,UAAU,SAAS,WAAW;CAEzE,MAAM,cAAc,UAAU,UAAU,IAAI,KAAK,UAAU,OAAO,IAAI;CACtE,MAAM,WAAW,MAAM,aAAa,GAAG;CAEvC,MAAM,SAAmD,CAAC;CAC1D,MAAM,YAAsD,CAAC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AAI,CAAC,KAAK;EACV,IAAI;EACJ,IAAI;GACF,UAAU,KAAK,MAAM,GAAG;EAC1B,QAAQ;GACN,QAAQ,MAAM,gDAAgD,GAAG;GACjE;EACF;EACA,IAAI,CAAC,MAAM,QAAQ,OAAO,GAAG;EAC7B,KAAK,MAAM,UAAU,SAAS;GAC5B,KAAK,iBAAiB,MAAM;GAC5B,MAAM,UAAU,KAAK,SAAS,IAAI,OAAO,IAAI;GAC7C,IAAI,SACF,QAAQ,QAAQ,QAAQ,MAAM,CAAC,CAAC,CAAC,OAAM,QAAO;IAC5C,QAAQ,MAAM,4CAA4C,OAAO,KAAK,KAAK,GAAG;GAChF,CAAC;EAEL;CACF;CAEA,WAAW,QAAuB;EAAE,KAAK,YAAY,KAAK,OAAO,YAAY,MAAM,CAAC;CAAE;CACtF,UAAU,OAAwB;EAAE,KAAK,YAAY,KAAK,OAAO,WAAW,KAAK,CAAC;CAAE;CACpF,eAAkC;EAAE,KAAK,YAAY,KAAK,OAAO,cAAc,CAAC;CAAE;CAClF,aAAkC;EAAE,KAAK,YAAY,KAAK,OAAO,YAAY,CAAC;CAAE;CAEhF,WAA8B;EAAE,OAAO,KAAK,OAAO,kBAAkB;CAAE;CACvE,kBAA8B;EAAE,OAAO,KAAK,OAAO,kBAAkB;CAAE;CACvE,WAA8B;EAAE,OAAO,KAAK,OAAO,UAAU;CAAE;CAC/D,YAAoE;EAClE,OAAO,KAAK,MAAM,KAAK,OAAO,WAAW,CAAC;CAC5C;CAEA,aAAa,QAAgB,KAAa,OAAqB;EAC7D,KAAK,OAAO,WAAW,QAAQ,KAAK,KAAK;CAC3C;CAEA,UAAgB;EAAE,KAAK,OAAO,KAAK;CAAE;AACvC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dot-agent/sdk",
3
- "version": "0.10.1",
3
+ "version": "0.10.3",
4
4
  "description": "Browser-compatible SDK for loading and running dot-agent bundles",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -37,33 +37,40 @@
37
37
  "dot-agent"
38
38
  ],
39
39
  "type": "module",
40
- "main": "dist/index.js",
41
- "types": "dist/index.d.ts",
40
+ "main": "dist/index.cjs",
41
+ "module": "dist/index.mjs",
42
+ "types": "dist/index.d.mts",
42
43
  "exports": {
43
44
  ".": {
44
- "types": "./dist/index.d.ts",
45
- "import": "./dist/index.js",
46
- "require": "./dist/index.cjs"
45
+ "import": {
46
+ "types": "./dist/index.d.mts",
47
+ "default": "./dist/index.mjs"
48
+ },
49
+ "require": {
50
+ "types": "./dist/index.d.cts",
51
+ "default": "./dist/index.cjs"
52
+ }
47
53
  }
48
54
  },
49
55
  "files": [
50
56
  "dist"
51
57
  ],
58
+ "engines": {
59
+ "node": ">=24.0.0"
60
+ },
52
61
  "scripts": {
53
- "build": "tsup",
54
- "dev": "tsup --watch",
62
+ "build": "tsdown",
63
+ "dev": "tsdown --watch",
55
64
  "typecheck": "tsc --noEmit",
56
- "test": "node --test tests/node.test.js"
65
+ "test": "node --test tests/*.test.js"
57
66
  },
58
67
  "dependencies": {
59
- "@dot-agent/compiler": "0.10.0",
60
- "@dot-agent/kernel-dsl": "0.10.1",
68
+ "@dot-agent/compiler": "0.10.2",
69
+ "@dot-agent/kernel-dsl": "0.10.3",
61
70
  "jszip": "^3.10.1"
62
71
  },
63
72
  "devDependencies": {
64
- "@types/node": "^20.0.0",
65
- "tsup": "^8.0.0",
66
- "typescript": "^5.0.0"
73
+ "esbuild": "^0.21.5"
67
74
  },
68
75
  "publishConfig": {
69
76
  "access": "public"
package/dist/index.d.ts DELETED
@@ -1,40 +0,0 @@
1
- import { AgentBundle } from '@dot-agent/compiler/core';
2
- export { AboutMe, AgentBundle, AgentFiles } from '@dot-agent/compiler/core';
3
-
4
- type EffectHandler = (effect: Effect) => void | Promise<void>;
5
- interface Effect {
6
- type: string;
7
- [key: string]: unknown;
8
- }
9
-
10
- declare function loadAgent(input: Uint8Array | ArrayBuffer): Promise<AgentBundle>;
11
-
12
- declare class AgentSession {
13
- private kernel;
14
- private handlers;
15
- private effectListener?;
16
- readonly bundle: AgentBundle;
17
- private constructor();
18
- static create(bundle: AgentBundle): Promise<AgentSession>;
19
- setFileResolver(resolver: (path: string) => string | null | undefined): void;
20
- start(): void;
21
- registerHandler(effectType: string, handler: EffectHandler): void;
22
- setEffectListener(listener: ((effect: Effect) => void) | undefined): void;
23
- private dispatchRaw;
24
- sendIntent(intent: string): void;
25
- sendEvent(event: string): void;
26
- sendOfftopic(): void;
27
- tickPrompt(): void;
28
- getState(): string;
29
- getValidIntents(): Array<any>;
30
- getGraph(): string;
31
- getMemory(): Array<{
32
- domain: string;
33
- key: string;
34
- value: unknown;
35
- }>;
36
- injectMemory(domain: string, key: string, value: string): void;
37
- dispose(): void;
38
- }
39
-
40
- export { AgentSession, type Effect, type EffectHandler, loadAgent };
package/dist/index.js DELETED
@@ -1,143 +0,0 @@
1
- // src/load.ts
2
- import JSZip from "jszip";
3
- import { parseAboutme, extractFiles, validateMagicBytes, validateZipBomb } from "@dot-agent/compiler/core";
4
- async function loadAgent(input) {
5
- const bytes = input instanceof Uint8Array ? input : new Uint8Array(input);
6
- validateMagicBytes(bytes);
7
- const zip = await JSZip.loadAsync(bytes);
8
- validateZipBomb(zip, bytes.length);
9
- const aboutmeFile = zip.file(".agent/aboutme.json");
10
- if (!aboutmeFile) throw new Error("Missing .agent/aboutme.json in bundle");
11
- const aboutme = parseAboutme(JSON.parse(await aboutmeFile.async("text")));
12
- const filesJsonFile = zip.file(".agent/files.json");
13
- if (!filesJsonFile) throw new Error("Missing .agent/files.json in bundle");
14
- const filesJson = JSON.parse(await filesJsonFile.async("text"));
15
- const descFile = zip.file(filesJson.description);
16
- const behavFile = zip.file(filesJson.behavior);
17
- if (!descFile) throw new Error(`Missing ${filesJson.description} in bundle`);
18
- if (!behavFile) throw new Error(`Missing ${filesJson.behavior} in bundle`);
19
- const personaFile = filesJson.persona ? zip.file(filesJson.persona) : null;
20
- const allFiles = await extractFiles(zip);
21
- const guides = [];
22
- const knowledge = [];
23
- const behaviors = [];
24
- for (const [path, content] of allFiles) {
25
- if (path.startsWith("guides/") && path !== "guides/.gitkeep") {
26
- guides.push({ path, content });
27
- } else if (path.startsWith("knowledge/") && path !== "knowledge/.gitkeep") {
28
- knowledge.push({ path, content });
29
- } else if (path.startsWith("behaviors/") && path !== "behaviors/.gitkeep") {
30
- behaviors.push({ path, content });
31
- }
32
- }
33
- return {
34
- id: aboutme.id,
35
- aboutme,
36
- files: {
37
- description: await descFile.async("text"),
38
- behavior: await behavFile.async("text"),
39
- persona: personaFile ? await personaFile.async("text") : void 0,
40
- guides,
41
- knowledge,
42
- behaviors
43
- }
44
- };
45
- }
46
-
47
- // src/session.ts
48
- import { AgentDSLKernel, init as initKernel } from "@dot-agent/kernel-dsl";
49
- var AgentSession = class _AgentSession {
50
- kernel;
51
- handlers = /* @__PURE__ */ new Map();
52
- effectListener;
53
- bundle;
54
- constructor(kernel, bundle) {
55
- this.kernel = kernel;
56
- this.bundle = bundle;
57
- }
58
- static async create(bundle) {
59
- await initKernel();
60
- const kernel = new AgentDSLKernel();
61
- return new _AgentSession(kernel, bundle);
62
- }
63
- // Register a synchronous fallback called when a `merge "…"` path is not in the bundle.
64
- // Must be called before start(). Return null/undefined if the path cannot be resolved.
65
- setFileResolver(resolver) {
66
- this.kernel.set_file_resolver(resolver);
67
- }
68
- // Call after registerHandler() — loads the behavior and fires initial effects.
69
- // Passes all merged behavior files as a bundle so the kernel can resolve `merge "…"` paths.
70
- start() {
71
- const bundle = {};
72
- for (const { path, content } of this.bundle.files.behaviors) {
73
- bundle[path] = content;
74
- }
75
- this.dispatchRaw(
76
- this.kernel.load_behavior_with_bundle(
77
- this.bundle.files.behavior,
78
- JSON.stringify(bundle)
79
- )
80
- );
81
- }
82
- registerHandler(effectType, handler) {
83
- this.handlers.set(effectType, handler);
84
- }
85
- setEffectListener(listener) {
86
- this.effectListener = listener;
87
- }
88
- dispatchRaw(raw) {
89
- if (!raw) return;
90
- let effects;
91
- try {
92
- effects = JSON.parse(raw);
93
- } catch {
94
- console.error("[AgentSession] failed to parse effects JSON:", raw);
95
- return;
96
- }
97
- if (!Array.isArray(effects)) return;
98
- for (const effect of effects) {
99
- this.effectListener?.(effect);
100
- const handler = this.handlers.get(effect.type);
101
- if (handler) {
102
- Promise.resolve(handler(effect)).catch((err) => {
103
- console.error(`[AgentSession] handler error for effect "${effect.type}":`, err);
104
- });
105
- }
106
- }
107
- }
108
- sendIntent(intent) {
109
- this.dispatchRaw(this.kernel.send_intent(intent));
110
- }
111
- sendEvent(event) {
112
- this.dispatchRaw(this.kernel.send_event(event));
113
- }
114
- sendOfftopic() {
115
- this.dispatchRaw(this.kernel.send_offtopic());
116
- }
117
- tickPrompt() {
118
- this.dispatchRaw(this.kernel.tick_prompt());
119
- }
120
- getState() {
121
- return this.kernel.get_current_state();
122
- }
123
- getValidIntents() {
124
- return this.kernel.get_valid_intents();
125
- }
126
- getGraph() {
127
- return this.kernel.get_graph();
128
- }
129
- getMemory() {
130
- return JSON.parse(this.kernel.get_memory());
131
- }
132
- injectMemory(domain, key, value) {
133
- this.kernel.set_memory(domain, key, value);
134
- }
135
- dispose() {
136
- this.kernel.free();
137
- }
138
- };
139
- export {
140
- AgentSession,
141
- loadAgent
142
- };
143
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/load.ts","../src/session.ts"],"sourcesContent":["// Copyright 2026 Danilo Borges\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport JSZip from 'jszip'\nimport { parseAboutme, extractFiles, validateMagicBytes, validateZipBomb } from '@dot-agent/compiler/core'\nimport type { AgentBundle } from './types.js'\n\nexport async function loadAgent(input: Uint8Array | ArrayBuffer): Promise<AgentBundle> {\n const bytes = input instanceof Uint8Array ? input : new Uint8Array(input)\n\n validateMagicBytes(bytes)\n\n const zip = await JSZip.loadAsync(bytes)\n validateZipBomb(zip, bytes.length)\n\n const aboutmeFile = zip.file('.agent/aboutme.json')\n if (!aboutmeFile) throw new Error('Missing .agent/aboutme.json in bundle')\n const aboutme = parseAboutme(JSON.parse(await aboutmeFile.async('text')))\n\n const filesJsonFile = zip.file('.agent/files.json')\n if (!filesJsonFile) throw new Error('Missing .agent/files.json in bundle')\n const filesJson = JSON.parse(await filesJsonFile.async('text')) as {\n description: string\n behavior: string\n persona?: string\n behaviors?: string[]\n guides?: string[]\n knowledge?: string[]\n }\n\n const descFile = zip.file(filesJson.description)\n const behavFile = zip.file(filesJson.behavior)\n if (!descFile) throw new Error(`Missing ${filesJson.description} in bundle`)\n if (!behavFile) throw new Error(`Missing ${filesJson.behavior} in bundle`)\n\n const personaFile = filesJson.persona ? zip.file(filesJson.persona) : null\n const allFiles = await extractFiles(zip)\n\n const guides: Array<{ path: string; content: string }> = []\n const knowledge: Array<{ path: string; content: string }> = []\n const behaviors: Array<{ path: string; content: string }> = []\n\n for (const [path, content] of allFiles) {\n if (path.startsWith('guides/') && path !== 'guides/.gitkeep') {\n guides.push({ path, content })\n } else if (path.startsWith('knowledge/') && path !== 'knowledge/.gitkeep') {\n knowledge.push({ path, content })\n } else if (path.startsWith('behaviors/') && path !== 'behaviors/.gitkeep') {\n behaviors.push({ path, content })\n }\n }\n\n return {\n id: aboutme.id,\n aboutme,\n files: {\n description: await descFile.async('text'),\n behavior: await behavFile.async('text'),\n persona: personaFile ? await personaFile.async('text') : undefined,\n guides,\n knowledge,\n behaviors,\n },\n }\n}\n","// Copyright 2026 Danilo Borges\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { AgentDSLKernel, init as initKernel } from '@dot-agent/kernel-dsl'\nimport type { AgentBundle, Effect, EffectHandler } from './types.js'\n\nexport class AgentSession {\n private kernel: AgentDSLKernel\n private handlers = new Map<string, EffectHandler>()\n private effectListener?: (effect: Effect) => void\n readonly bundle: AgentBundle\n\n private constructor(kernel: AgentDSLKernel, bundle: AgentBundle) {\n this.kernel = kernel\n this.bundle = bundle\n }\n\n static async create(bundle: AgentBundle): Promise<AgentSession> {\n await initKernel()\n const kernel = new AgentDSLKernel()\n return new AgentSession(kernel, bundle)\n }\n\n // Register a synchronous fallback called when a `merge \"…\"` path is not in the bundle.\n // Must be called before start(). Return null/undefined if the path cannot be resolved.\n setFileResolver(resolver: (path: string) => string | null | undefined): void {\n this.kernel.set_file_resolver(resolver as unknown as Function)\n }\n\n // Call after registerHandler() — loads the behavior and fires initial effects.\n // Passes all merged behavior files as a bundle so the kernel can resolve `merge \"…\"` paths.\n start(): void {\n const bundle: Record<string, string> = {}\n for (const { path, content } of this.bundle.files.behaviors) {\n bundle[path] = content\n }\n this.dispatchRaw(\n this.kernel.load_behavior_with_bundle(\n this.bundle.files.behavior,\n JSON.stringify(bundle),\n )\n )\n }\n\n registerHandler(effectType: string, handler: EffectHandler): void {\n this.handlers.set(effectType, handler)\n }\n\n setEffectListener(listener: ((effect: Effect) => void) | undefined): void {\n this.effectListener = listener\n }\n\n private dispatchRaw(raw: string): void {\n if (!raw) return\n let effects: Effect[]\n try {\n effects = JSON.parse(raw)\n } catch {\n console.error('[AgentSession] failed to parse effects JSON:', raw)\n return\n }\n if (!Array.isArray(effects)) return\n for (const effect of effects) {\n this.effectListener?.(effect)\n const handler = this.handlers.get(effect.type)\n if (handler) {\n Promise.resolve(handler(effect)).catch(err => {\n console.error(`[AgentSession] handler error for effect \"${effect.type}\":`, err)\n })\n }\n }\n }\n\n sendIntent(intent: string): void { this.dispatchRaw(this.kernel.send_intent(intent)) }\n sendEvent(event: string): void { this.dispatchRaw(this.kernel.send_event(event)) }\n sendOfftopic(): void { this.dispatchRaw(this.kernel.send_offtopic()) }\n tickPrompt(): void { this.dispatchRaw(this.kernel.tick_prompt()) }\n\n getState(): string { return this.kernel.get_current_state() }\n getValidIntents(): Array<any> { return this.kernel.get_valid_intents() }\n getGraph(): string { return this.kernel.get_graph() }\n getMemory(): Array<{ domain: string; key: string; value: unknown }> {\n return JSON.parse(this.kernel.get_memory())\n }\n\n injectMemory(domain: string, key: string, value: string): void {\n this.kernel.set_memory(domain, key, value)\n }\n\n dispose(): void { this.kernel.free() }\n}\n"],"mappings":";AAcA,OAAO,WAAW;AAClB,SAAS,cAAc,cAAc,oBAAoB,uBAAuB;AAGhF,eAAsB,UAAU,OAAuD;AACrF,QAAM,QAAQ,iBAAiB,aAAa,QAAQ,IAAI,WAAW,KAAK;AAExE,qBAAmB,KAAK;AAExB,QAAM,MAAM,MAAM,MAAM,UAAU,KAAK;AACvC,kBAAgB,KAAK,MAAM,MAAM;AAEjC,QAAM,cAAc,IAAI,KAAK,qBAAqB;AAClD,MAAI,CAAC,YAAa,OAAM,IAAI,MAAM,uCAAuC;AACzE,QAAM,UAAU,aAAa,KAAK,MAAM,MAAM,YAAY,MAAM,MAAM,CAAC,CAAC;AAExE,QAAM,gBAAgB,IAAI,KAAK,mBAAmB;AAClD,MAAI,CAAC,cAAe,OAAM,IAAI,MAAM,qCAAqC;AACzE,QAAM,YAAY,KAAK,MAAM,MAAM,cAAc,MAAM,MAAM,CAAC;AAS9D,QAAM,WAAW,IAAI,KAAK,UAAU,WAAW;AAC/C,QAAM,YAAY,IAAI,KAAK,UAAU,QAAQ;AAC7C,MAAI,CAAC,SAAU,OAAM,IAAI,MAAM,WAAW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