@onkeiki/agents 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Alert.d.ts +56 -0
- package/dist/Alert.d.ts.map +1 -0
- package/dist/Alert.js +8 -0
- package/dist/Alert.js.map +1 -0
- package/dist/Entity.d.ts +158 -0
- package/dist/Entity.d.ts.map +1 -0
- package/dist/Entity.js +289 -0
- package/dist/Entity.js.map +1 -0
- package/dist/Kit.d.ts +138 -0
- package/dist/Kit.d.ts.map +1 -0
- package/dist/Kit.js +517 -0
- package/dist/Kit.js.map +1 -0
- package/dist/OpenApi.d.ts +151 -0
- package/dist/OpenApi.d.ts.map +1 -0
- package/dist/OpenApi.js +222 -0
- package/dist/OpenApi.js.map +1 -0
- package/dist/Plugin.d.ts +183 -0
- package/dist/Plugin.d.ts.map +1 -0
- package/dist/Plugin.js +10 -0
- package/dist/Plugin.js.map +1 -0
- package/dist/Server.d.ts +71 -0
- package/dist/Server.d.ts.map +1 -0
- package/dist/Server.js +476 -0
- package/dist/Server.js.map +1 -0
- package/dist/Tool.d.ts +86 -0
- package/dist/Tool.d.ts.map +1 -0
- package/dist/Tool.js +27 -0
- package/dist/Tool.js.map +1 -0
- package/dist/bundle.d.ts +17 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +101 -0
- package/dist/bundle.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/services/Blackboard.d.ts +18 -0
- package/dist/services/Blackboard.d.ts.map +1 -0
- package/dist/services/Blackboard.js +4 -0
- package/dist/services/Blackboard.js.map +1 -0
- package/dist/services/Observability.d.ts +102 -0
- package/dist/services/Observability.d.ts.map +1 -0
- package/dist/services/Observability.js +238 -0
- package/dist/services/Observability.js.map +1 -0
- package/dist/services/Platform.d.ts +112 -0
- package/dist/services/Platform.d.ts.map +1 -0
- package/dist/services/Platform.js +13 -0
- package/dist/services/Platform.js.map +1 -0
- package/dist/services/PluginDb.d.ts +44 -0
- package/dist/services/PluginDb.d.ts.map +1 -0
- package/dist/services/PluginDb.js +5 -0
- package/dist/services/PluginDb.js.map +1 -0
- package/dist/services/Sandbox.d.ts +68 -0
- package/dist/services/Sandbox.d.ts.map +1 -0
- package/dist/services/Sandbox.js +4 -0
- package/dist/services/Sandbox.js.map +1 -0
- package/dist/services/Steering.d.ts +46 -0
- package/dist/services/Steering.d.ts.map +1 -0
- package/dist/services/Steering.js +4 -0
- package/dist/services/Steering.js.map +1 -0
- package/dist/services/Storage.d.ts +63 -0
- package/dist/services/Storage.d.ts.map +1 -0
- package/dist/services/Storage.js +13 -0
- package/dist/services/Storage.js.map +1 -0
- package/dist/services/Transport.d.ts +19 -0
- package/dist/services/Transport.d.ts.map +1 -0
- package/dist/services/Transport.js +4 -0
- package/dist/services/Transport.js.map +1 -0
- package/dist/services/index.d.ts +9 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +9 -0
- package/dist/services/index.js.map +1 -0
- package/dist/types/config.d.ts +526 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +2 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +4 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/message.d.ts +54 -0
- package/dist/types/message.d.ts.map +1 -0
- package/dist/types/message.js +47 -0
- package/dist/types/message.js.map +1 -0
- package/dist/types/user.d.ts +16 -0
- package/dist/types/user.d.ts.map +1 -0
- package/dist/types/user.js +14 -0
- package/dist/types/user.js.map +1 -0
- package/package.json +39 -0
- package/src/Alert.ts +51 -0
- package/src/Entity.ts +543 -0
- package/src/Kit.ts +705 -0
- package/src/OpenApi.ts +343 -0
- package/src/Plugin.ts +209 -0
- package/src/Server.ts +618 -0
- package/src/Tool.ts +110 -0
- package/src/bundle.ts +114 -0
- package/src/index.ts +209 -0
- package/src/services/Blackboard.ts +19 -0
- package/src/services/Observability.ts +320 -0
- package/src/services/Platform.ts +125 -0
- package/src/services/PluginDb.ts +48 -0
- package/src/services/Sandbox.ts +74 -0
- package/src/services/Steering.ts +45 -0
- package/src/services/Storage.ts +76 -0
- package/src/services/Transport.ts +21 -0
- package/src/services/index.ts +8 -0
- package/src/types/config.ts +531 -0
- package/src/types/index.ts +3 -0
- package/src/types/message.ts +60 -0
- package/src/types/user.ts +17 -0
package/dist/Tool.d.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { Effect, Schema } from 'effect';
|
|
2
|
+
import type { UserProfile } from './types/index.js';
|
|
3
|
+
import type { BlackboardService } from './services/Blackboard.js';
|
|
4
|
+
import type { PlatformService } from './services/Platform.js';
|
|
5
|
+
import type { PluginDbService } from './services/PluginDb.js';
|
|
6
|
+
import type { SandboxHandle } from './services/Sandbox.js';
|
|
7
|
+
import type { EntityStore } from './Entity.js';
|
|
8
|
+
/**
|
|
9
|
+
* Per-user KV state backed by a Rivet UserState actor.
|
|
10
|
+
* One instance per (apiKey, phone) pair.
|
|
11
|
+
*/
|
|
12
|
+
export interface UserStateService {
|
|
13
|
+
readonly get: (key: string) => Effect.Effect<unknown>;
|
|
14
|
+
readonly set: (key: string, value: unknown) => Effect.Effect<void>;
|
|
15
|
+
readonly delete: (key: string) => Effect.Effect<boolean>;
|
|
16
|
+
readonly getAll: () => Effect.Effect<Record<string, unknown>>;
|
|
17
|
+
readonly setMany: (entries: Record<string, unknown>) => Effect.Effect<void>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Developer secrets — encrypted KV stored on the platform.
|
|
21
|
+
* Synced via kit.sync() and accessible at runtime.
|
|
22
|
+
*/
|
|
23
|
+
export interface SecretsService {
|
|
24
|
+
readonly get: (name: string) => Effect.Effect<string | null>;
|
|
25
|
+
readonly getAll: () => Effect.Effect<Record<string, string>>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Where the turn calling a tool came from: the channel plus the provider ids
|
|
29
|
+
* naming the sender and the thread. Flat so it reads the same on a trace and in
|
|
30
|
+
* a tool. `userId` is the sender in the channel's own terms — a Slack user id,
|
|
31
|
+
* an email address, a phone number, a Telegram chat id.
|
|
32
|
+
*/
|
|
33
|
+
export type ChannelEnvelope = {
|
|
34
|
+
readonly channel: 'sms' | 'telegram' | 'whatsapp' | 'xchat' | 'slack' | 'agentmail' | 'api' | 'agent' | 'synthetic';
|
|
35
|
+
/** Text of the messages a person sent this turn, joined; platform notices excluded. */
|
|
36
|
+
readonly inboundText: string;
|
|
37
|
+
/** Provider id of the last inbound message (Slack `ts`, email `message_id`, …). */
|
|
38
|
+
readonly messageId?: string;
|
|
39
|
+
readonly userId?: string;
|
|
40
|
+
readonly teamId?: string;
|
|
41
|
+
readonly channelId?: string;
|
|
42
|
+
readonly threadTs?: string;
|
|
43
|
+
readonly threadId?: string;
|
|
44
|
+
readonly inboxId?: string;
|
|
45
|
+
/** WhatsApp: Meta's phone number id the conversation runs on. */
|
|
46
|
+
readonly phoneNumberId?: string;
|
|
47
|
+
/** X Chat: the canonical conversation id. */
|
|
48
|
+
readonly chatConversationId?: string;
|
|
49
|
+
/** `ask_agent`: the agent asking. */
|
|
50
|
+
readonly fromAgentId?: string;
|
|
51
|
+
};
|
|
52
|
+
export type ToolContext = {
|
|
53
|
+
readonly phone: string;
|
|
54
|
+
readonly user: UserProfile;
|
|
55
|
+
/** Set when the tool runs on the platform for a turn; absent in a local runtime. */
|
|
56
|
+
readonly channel?: ChannelEnvelope;
|
|
57
|
+
readonly blackboard: BlackboardService;
|
|
58
|
+
readonly platform: PlatformService;
|
|
59
|
+
readonly userState: UserStateService;
|
|
60
|
+
readonly secrets: SecretsService;
|
|
61
|
+
readonly db: PluginDbService;
|
|
62
|
+
/**
|
|
63
|
+
* Entity persistence bridge for cloud (actor) execution, where `db` is not
|
|
64
|
+
* reachable. Entity helpers use `contextEntityStore(ctx)`, which prefers
|
|
65
|
+
* this and falls back to SQL over `db`.
|
|
66
|
+
*/
|
|
67
|
+
readonly entityStore?: EntityStore;
|
|
68
|
+
readonly sandbox: SandboxHandle;
|
|
69
|
+
};
|
|
70
|
+
export type ToolDefinition<I = unknown, O = unknown> = {
|
|
71
|
+
readonly name: string;
|
|
72
|
+
readonly description: string;
|
|
73
|
+
readonly input: Schema.Schema<I>;
|
|
74
|
+
readonly execute: (input: I, ctx: ToolContext) => Effect.Effect<O>;
|
|
75
|
+
/**
|
|
76
|
+
* Absolute path to the module that defined this tool. Captured automatically
|
|
77
|
+
* by {@link defineTool} so `kit.sync()` can bundle the tool into a standalone
|
|
78
|
+
* actor artifact. Not set by hand.
|
|
79
|
+
*/
|
|
80
|
+
readonly sourceFile?: string;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Define a type-safe tool for your agent.
|
|
84
|
+
*/
|
|
85
|
+
export declare function defineTool<I, O>(def: ToolDefinition<I, O>): ToolDefinition<I, O>;
|
|
86
|
+
//# sourceMappingURL=Tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Tool.d.ts","sourceRoot":"","sources":["../src/Tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAEvC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AACjE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAC1D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAE9C;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,GAAG,EAAE,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AAE,GAAG,EAAE,WAAW,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;IAClE;;;;OAIG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAC7B,CAAA;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,CAEhF"}
|
package/dist/Tool.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Effect, Schema } from 'effect';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
/**
|
|
4
|
+
* Define a type-safe tool for your agent.
|
|
5
|
+
*/
|
|
6
|
+
export function defineTool(def) {
|
|
7
|
+
return { ...def, sourceFile: def.sourceFile ?? captureSourceFile() };
|
|
8
|
+
}
|
|
9
|
+
const THIS_FILE = import.meta.url;
|
|
10
|
+
function captureSourceFile() {
|
|
11
|
+
const stack = new Error().stack;
|
|
12
|
+
if (!stack)
|
|
13
|
+
return undefined;
|
|
14
|
+
for (const line of stack.split('\n').slice(1)) {
|
|
15
|
+
const match = line.match(/(?:\(|@|\s)((?:file:\/\/)?\/[^\s()]+?\.[cm]?[jt]sx?):\d+:\d+/);
|
|
16
|
+
if (!match)
|
|
17
|
+
continue;
|
|
18
|
+
let file = match[1];
|
|
19
|
+
if (file.startsWith('file://'))
|
|
20
|
+
file = fileURLToPath(file);
|
|
21
|
+
if (file === fileURLToPath(THIS_FILE))
|
|
22
|
+
continue;
|
|
23
|
+
return file;
|
|
24
|
+
}
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=Tool.js.map
|
package/dist/Tool.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Tool.js","sourceRoot":"","sources":["../src/Tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAuFxC;;GAEG;AACH,MAAM,UAAU,UAAU,CAAO,GAAyB;IACxD,OAAO,EAAE,GAAG,GAAG,EAAE,UAAU,EAAE,GAAG,CAAC,UAAU,IAAI,iBAAiB,EAAE,EAAE,CAAA;AACtE,CAAC;AAED,MAAM,SAAS,GAAG,OAAO,IAAI,CAAC,GAAG,CAAA;AAEjC,SAAS,iBAAiB;IACxB,MAAM,KAAK,GAAG,IAAI,KAAK,EAAE,CAAC,KAAK,CAAA;IAC/B,IAAI,CAAC,KAAK;QAAE,OAAO,SAAS,CAAA;IAC5B,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;QAC9C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,8DAA8D,CAAC,CAAA;QACxF,IAAI,CAAC,KAAK;YAAE,SAAQ;QACpB,IAAI,IAAI,GAAG,KAAK,CAAC,CAAC,CAAE,CAAA;QACpB,IAAI,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC;YAAE,IAAI,GAAG,aAAa,CAAC,IAAI,CAAC,CAAA;QAC1D,IAAI,IAAI,KAAK,aAAa,CAAC,SAAS,CAAC;YAAE,SAAQ;QAC/C,OAAO,IAAI,CAAA;IACb,CAAC;IACD,OAAO,SAAS,CAAA;AAClB,CAAC"}
|
package/dist/bundle.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ToolDefinition } from './Tool.js';
|
|
2
|
+
/**
|
|
3
|
+
* Bundle a single tool into a standalone, dependency-free ESM artifact that the
|
|
4
|
+
* platform deploys and runs as a per-tool actor.
|
|
5
|
+
*
|
|
6
|
+
* The artifact exports `__run(input, host)`:
|
|
7
|
+
* - `input` — raw tool arguments (validated against the tool's Schema here)
|
|
8
|
+
* - `host` — actor-provided bridge: `{ phone, user, channel, userState, secrets, entities }`
|
|
9
|
+
* with async methods backed by the platform's Rivet UserState
|
|
10
|
+
* actor, developer secrets, and entity storage.
|
|
11
|
+
*
|
|
12
|
+
* Bundling requires Bun (developers run `kit.sync()` under Bun) and the tool's
|
|
13
|
+
* captured `sourceFile`, since `execute` is a live closure that imports helpers
|
|
14
|
+
* and cannot be serialized from the tool object alone.
|
|
15
|
+
*/
|
|
16
|
+
export declare function bundleTool(tool: ToolDefinition): Promise<string>;
|
|
17
|
+
//# sourceMappingURL=bundle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../src/bundle.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAE/C;;;;;;;;;;;;;GAaG;AACH,wBAAsB,UAAU,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAmCtE"}
|
package/dist/bundle.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { writeFile, rm } from 'node:fs/promises';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { randomUUID } from 'node:crypto';
|
|
4
|
+
/**
|
|
5
|
+
* Bundle a single tool into a standalone, dependency-free ESM artifact that the
|
|
6
|
+
* platform deploys and runs as a per-tool actor.
|
|
7
|
+
*
|
|
8
|
+
* The artifact exports `__run(input, host)`:
|
|
9
|
+
* - `input` — raw tool arguments (validated against the tool's Schema here)
|
|
10
|
+
* - `host` — actor-provided bridge: `{ phone, user, channel, userState, secrets, entities }`
|
|
11
|
+
* with async methods backed by the platform's Rivet UserState
|
|
12
|
+
* actor, developer secrets, and entity storage.
|
|
13
|
+
*
|
|
14
|
+
* Bundling requires Bun (developers run `kit.sync()` under Bun) and the tool's
|
|
15
|
+
* captured `sourceFile`, since `execute` is a live closure that imports helpers
|
|
16
|
+
* and cannot be serialized from the tool object alone.
|
|
17
|
+
*/
|
|
18
|
+
export async function bundleTool(tool) {
|
|
19
|
+
const bun = globalThis.Bun;
|
|
20
|
+
if (!bun) {
|
|
21
|
+
throw new Error(`kit.sync() must run under Bun to bundle tool "${tool.name}" into an actor artifact.`);
|
|
22
|
+
}
|
|
23
|
+
if (!tool.sourceFile) {
|
|
24
|
+
throw new Error(`Cannot bundle tool "${tool.name}": its source file was not captured. ` +
|
|
25
|
+
`Define it with defineTool() from '@onkeiki/agents'.`);
|
|
26
|
+
}
|
|
27
|
+
const entryDir = dirname(tool.sourceFile);
|
|
28
|
+
const entryPath = join(entryDir, `.smskit-actor-${sanitize(tool.name)}-${randomUUID()}.mjs`);
|
|
29
|
+
await writeFile(entryPath, buildEntrySource(tool.name, tool.sourceFile), 'utf8');
|
|
30
|
+
try {
|
|
31
|
+
const built = await bun.build({
|
|
32
|
+
entrypoints: [entryPath],
|
|
33
|
+
target: 'node',
|
|
34
|
+
format: 'esm',
|
|
35
|
+
minify: true,
|
|
36
|
+
});
|
|
37
|
+
if (!built.success) {
|
|
38
|
+
const detail = built.logs.map((l) => String(l)).join('\n');
|
|
39
|
+
throw new Error(`Failed to bundle tool "${tool.name}":\n${detail}`);
|
|
40
|
+
}
|
|
41
|
+
const output = built.outputs[0];
|
|
42
|
+
if (!output)
|
|
43
|
+
throw new Error(`Bundling tool "${tool.name}" produced no output`);
|
|
44
|
+
return await output.text();
|
|
45
|
+
}
|
|
46
|
+
finally {
|
|
47
|
+
await rm(entryPath, { force: true });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function buildEntrySource(toolName, sourceFile) {
|
|
51
|
+
const name = JSON.stringify(toolName);
|
|
52
|
+
const source = JSON.stringify(sourceFile);
|
|
53
|
+
return `import { Effect, Schema } from 'effect'
|
|
54
|
+
import * as __mod from ${source}
|
|
55
|
+
|
|
56
|
+
const __toolName = ${name}
|
|
57
|
+
const __isTool = (t) => t && typeof t === 'object' && typeof t.execute === 'function' && t.name === __toolName
|
|
58
|
+
const __exports = Object.values(__mod)
|
|
59
|
+
const __tool =
|
|
60
|
+
__exports.find(__isTool)
|
|
61
|
+
?? __exports.flatMap((e) => (e && typeof e === 'object' && Array.isArray(e.tools) ? e.tools : [])).find(__isTool)
|
|
62
|
+
if (!__tool) throw new Error('Tool ' + __toolName + ' not found in ' + ${source})
|
|
63
|
+
|
|
64
|
+
const fromPromise = (run) => Effect.tryPromise({ try: run, catch: (e) => e })
|
|
65
|
+
|
|
66
|
+
function buildContext(host) {
|
|
67
|
+
const unavailable = (what) => {
|
|
68
|
+
throw new Error(what + ' is not available in actor tool execution')
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
phone: host.phone,
|
|
72
|
+
user: host.user,
|
|
73
|
+
channel: host.channel,
|
|
74
|
+
get blackboard() { return unavailable('ctx.blackboard') },
|
|
75
|
+
get platform() { return unavailable('ctx.platform') },
|
|
76
|
+
userState: {
|
|
77
|
+
get: (k) => fromPromise(() => host.userState.get(k)),
|
|
78
|
+
set: (k, v) => fromPromise(() => host.userState.set(k, v)),
|
|
79
|
+
delete: (k) => fromPromise(() => host.userState.delete(k)),
|
|
80
|
+
getAll: () => fromPromise(() => host.userState.getAll()),
|
|
81
|
+
setMany: (e) => fromPromise(() => host.userState.setMany(e)),
|
|
82
|
+
},
|
|
83
|
+
secrets: {
|
|
84
|
+
get: (n) => fromPromise(() => host.secrets.get(n)),
|
|
85
|
+
getAll: () => fromPromise(() => host.secrets.getAll()),
|
|
86
|
+
},
|
|
87
|
+
get db() { return unavailable('ctx.db (use entity helpers, which route through ctx.entityStore)') },
|
|
88
|
+
entityStore: host.entities,
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export async function __run(input, host) {
|
|
93
|
+
const decoded = Schema.decodeUnknownSync(__tool.input)(input)
|
|
94
|
+
return await Effect.runPromise(__tool.execute(decoded, buildContext(host)))
|
|
95
|
+
}
|
|
96
|
+
`;
|
|
97
|
+
}
|
|
98
|
+
function sanitize(name) {
|
|
99
|
+
return name.replace(/[^a-zA-Z0-9_-]/g, '_');
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=bundle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle.js","sourceRoot":"","sources":["../src/bundle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAA;AAChD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAGxC;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,IAAoB;IACnD,MAAM,GAAG,GAAI,UAA8E,CAAC,GAAG,CAAA;IAC/F,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,KAAK,CACb,iDAAiD,IAAI,CAAC,IAAI,2BAA2B,CACtF,CAAA;IACH,CAAC;IACD,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CACb,uBAAuB,IAAI,CAAC,IAAI,uCAAuC;YACrE,qDAAqD,CACxD,CAAA;IACH,CAAC;IAED,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;IACzC,MAAM,SAAS,GAAG,IAAI,CAAC,QAAQ,EAAE,iBAAiB,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,UAAU,EAAE,MAAM,CAAC,CAAA;IAE5F,MAAM,SAAS,CAAC,SAAS,EAAE,gBAAgB,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC,CAAA;IAChF,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,MAAM,GAAG,CAAC,KAAK,CAAC;YAC5B,WAAW,EAAE,CAAC,SAAS,CAAC;YACxB,MAAM,EAAE,MAAM;YACd,MA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Instance, } from './Kit.js';
|
|
2
|
+
export { defineTool, type ToolDefinition, type ToolContext, type ChannelEnvelope, type UserStateService, type SecretsService, } from './Tool.js';
|
|
3
|
+
export { defineAlert, type AlertDefinition, type AlertSchedule, type AlertContent, type AlertContext, type AlertMedia, type AlertMessage, type AlertStateService, } from './Alert.js';
|
|
4
|
+
export { defineEntity, entityMigrations, entityTools, createEntityDb, contextEntityStore, sqlEntityStore, EntityError, type EntityStore, type EntityStoreRow, type EntityDefinition, type EntityRow, type EntityAccessor, type EntityDb, } from './Entity.js';
|
|
5
|
+
export { definePlugin, type AgentKitPlugin, type SmsKitPlugin, type Plugin, type TurnEvent, type TurnResult, type ToolCallEvent, type ToolCallResult, type RouteContext, type PluginContext, type SyncPayload, type PluginInitResult, } from './Plugin.js';
|
|
6
|
+
export { oauthOpenApiSpec, googleOpenApiSpec, microsoftOpenApiSpec, OpenApiSpecError, GOOGLE_AUTHORIZATION_URL, GOOGLE_TOKEN_URL, MICROSOFT_AUTHORIZATION_URL, MICROSOFT_TOKEN_URL, type OpenApiMethod, type OpenApiOperation, type OpenApiParameter, type OpenApiParameterRef, type OAuthOpenApiSpec, type OAuthOpenApiSpecInput, } from './OpenApi.js';
|
|
7
|
+
export { createServer, executeAlert, type TurnRequest, type TurnResponse, type AlertDelivery, type AlertExecuteBody, } from './Server.js';
|
|
8
|
+
export { Storage, StorageError, type StorageService, type NewMessage, type DeliveryClaim, type UsageEvent, type BillingPeriod, type UsageSummary, } from './services/Storage.js';
|
|
9
|
+
export { Transport, type TransportService, } from './services/Transport.js';
|
|
10
|
+
export { Platform, PlatformError, type PlatformService, type MemoryFact, type BrowseResult, type SandboxExecResult, type HandoffResult, type EscalationResult, type BackgroundJobResult, } from './services/Platform.js';
|
|
11
|
+
export { Steering, type SteeringService, type SteeringDecision, type TurnState, } from './services/Steering.js';
|
|
12
|
+
export { Blackboard, type BlackboardService, } from './services/Blackboard.js';
|
|
13
|
+
export { Observability, ObservabilityError, braintrustExporter, axiomExporter, otelExporter, customExporter, type TraceExporter, type TraceEvent, type SpanEvent, type SpanKind, type SpanStatus, } from './services/Observability.js';
|
|
14
|
+
export { SandboxProvider, type SandboxProviderService, type SandboxHandle, } from './services/Sandbox.js';
|
|
15
|
+
export { PluginDb, type PluginDbService, type PluginMigration, } from './services/PluginDb.js';
|
|
16
|
+
export type { AgentKitConfig, SmsKitConfig, AgentConfig, MemoryConfig, BrowserConfig, SandboxConfig, ExecutorConfig, SteeringConfig, MediaConfig, MediaActionConfig, EscalationConfig, EscalationRoute, EventHandlers, ObservabilityConfig, PromptContext, TurnHooks, TurnHookState, TurnReviewState, RetrievedContext, ResolveNumberContext, AcquireLineOpts, PhoneLine, DurationInput, HarnessConfig, StorageBundle, ChannelType, ChannelConfig, SmsChannelConfig, TelegramChannelConfig, CapabilityRef, CapabilityManifest, CapabilityRuntime, CapabilityNamespace, CapabilitySecret, CapabilityField, CapabilityTool, CapabilityToolRun, CapabilityTemplate, CapabilityEntity, CapabilityLoop, CapabilityLoopProbe, CapabilityLoopTrigger, CapabilityInput, } from './types/config.js';
|
|
17
|
+
export type { InboundMessage, OutboundMessage, StoredMessage, MediaPayload, SendResult, DeliveryStatus, Direction, } from './types/message.js';
|
|
18
|
+
export type { UserProfile, Subscriber, } from './types/user.js';
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,QAAQ,EACR,MAAM,EACN,MAAM,EACN,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,cAAc,GACpB,MAAM,UAAU,CAAA;AACjB,OAAO,EACL,UAAU,EACV,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,cAAc,GACpB,MAAM,WAAW,CAAA;AAClB,OAAO,EACL,WAAW,EACX,KAAK,eAAe,EACp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EAClB,gBAAgB,EAChB,cAAc,EACd,mBAAmB,EACnB,qBAAqB,EACrB,eAAe,GAChB,MAAM,mBAAmB,CAAA;AAE1B,YAAY,EACV,cAAc,EACd,eAAe,EACf,aAAa,EACb,YAAY,EACZ,UAAU,EACV,cAAc,EACd,SAAS,GACV,MAAM,oBAAoB,CAAA;AAE3B,YAAY,EACV,WAAW,EACX,UAAU,GACX,MAAM,iBAAiB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Main entry point for @onkeiki/agents
|
|
2
|
+
export { AgentKit, SmsKit, create, } from './Kit.js';
|
|
3
|
+
export { defineTool, } from './Tool.js';
|
|
4
|
+
export { defineAlert, } from './Alert.js';
|
|
5
|
+
export { defineEntity, entityMigrations, entityTools, createEntityDb, contextEntityStore, sqlEntityStore, EntityError, } from './Entity.js';
|
|
6
|
+
export { definePlugin, } from './Plugin.js';
|
|
7
|
+
export { oauthOpenApiSpec, googleOpenApiSpec, microsoftOpenApiSpec, OpenApiSpecError, GOOGLE_AUTHORIZATION_URL, GOOGLE_TOKEN_URL, MICROSOFT_AUTHORIZATION_URL, MICROSOFT_TOKEN_URL, } from './OpenApi.js';
|
|
8
|
+
export { createServer, executeAlert, } from './Server.js';
|
|
9
|
+
// Services (for advanced use / custom adapters)
|
|
10
|
+
export { Storage, StorageError, } from './services/Storage.js';
|
|
11
|
+
export { Transport, } from './services/Transport.js';
|
|
12
|
+
export { Platform, PlatformError, } from './services/Platform.js';
|
|
13
|
+
export { Steering, } from './services/Steering.js';
|
|
14
|
+
export { Blackboard, } from './services/Blackboard.js';
|
|
15
|
+
export { Observability, ObservabilityError, braintrustExporter, axiomExporter, otelExporter, customExporter, } from './services/Observability.js';
|
|
16
|
+
export { SandboxProvider, } from './services/Sandbox.js';
|
|
17
|
+
export { PluginDb, } from './services/PluginDb.js';
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,OAAO,EACL,QAAQ,EACR,MAAM,EACN,MAAM,GAIP,MAAM,UAAU,CAAA;AACjB,OAAO,EACL,UAAU,GAMX,MAAM,WAAW,CAAA;AAClB,OAAO,EACL,WAAW,GAQZ,MAAM,YAAY,CAAA;AACnB,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,WAAW,EACX,cAAc,EACd,kBAAkB,EAClB,cAAc,EACd,WAAW,GAOZ,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,YAAY,GAYb,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EACpB,gBAAgB,EAChB,wBAAwB,EACxB,gBAAgB,EAChB,2BAA2B,EAC3B,mBAAmB,GAOpB,MAAM,cAAc,CAAA;AACrB,OAAO,EACL,YAAY,EACZ,YAAY,GAKb,MAAM,aAAa,CAAA;AAEpB,gDAAgD;AAChD,OAAO,EACL,OAAO,EACP,YAAY,GAOb,MAAM,uBAAuB,CAAA;AAE9B,OAAO,EACL,SAAS,GAEV,MAAM,yBAAyB,CAAA;AAEhC,OAAO,EACL,QAAQ,EACR,aAAa,GAQd,MAAM,wBAAwB,CAAA;AAE/B,OAAO,EACL,QAAQ,GAIT,MAAM,wBAAwB,CAAA;AAE/B,OAAO,EACL,UAAU,GAEX,MAAM,0BAA0B,CAAA;AAEjC,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EAClB,aAAa,EACb,YAAY,EACZ,cAAc,GAMf,MAAM,6BAA6B,CAAA;AAEpC,OAAO,EACL,eAAe,GAGhB,MAAM,uBAAuB,CAAA;AAE9B,OAAO,EACL,QAAQ,GAGT,MAAM,wBAAwB,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Context, Effect } from 'effect';
|
|
2
|
+
/**
|
|
3
|
+
* Cross-step key-value scratchpad within a single turn.
|
|
4
|
+
* Tools can read/write state that persists across tool steps
|
|
5
|
+
* but is cleared when the turn ends.
|
|
6
|
+
*/
|
|
7
|
+
export interface BlackboardService {
|
|
8
|
+
readonly read: (key: string) => Effect.Effect<unknown | null>;
|
|
9
|
+
readonly write: (key: string, value: unknown) => Effect.Effect<void>;
|
|
10
|
+
readonly delete: (key: string) => Effect.Effect<void>;
|
|
11
|
+
readonly entries: () => Effect.Effect<ReadonlyArray<[string, unknown]>>;
|
|
12
|
+
readonly clear: () => Effect.Effect<void>;
|
|
13
|
+
}
|
|
14
|
+
declare const Blackboard_base: Context.TagClass<Blackboard, "@onkeiki/agents/Blackboard", BlackboardService>;
|
|
15
|
+
export declare class Blackboard extends Blackboard_base {
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=Blackboard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Blackboard.d.ts","sourceRoot":"","sources":["../../src/services/Blackboard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAExC;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,OAAO,GAAG,IAAI,CAAC,CAAA;IAC7D,QAAQ,CAAC,KAAK,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IACpE,QAAQ,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IACrD,QAAQ,CAAC,OAAO,EAAE,MAAM,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAA;IACvE,QAAQ,CAAC,KAAK,EAAE,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;CAC1C;;AAED,qBAAa,UAAW,SAAQ,eAG7B;CAAG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Blackboard.js","sourceRoot":"","sources":["../../src/services/Blackboard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAexC,MAAM,OAAO,UAAW,SAAQ,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,EAGtE;CAAG"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Observability Service
|
|
3
|
+
*
|
|
4
|
+
* Allows developers to export turn traces to external providers:
|
|
5
|
+
* - Braintrust (AI-specific tracing, evals, scoring)
|
|
6
|
+
* - Axiom (structured log ingestion)
|
|
7
|
+
* - Generic OTEL (any OpenTelemetry-compatible backend)
|
|
8
|
+
* - Custom (developer-provided exporter function)
|
|
9
|
+
*
|
|
10
|
+
* The platform always records traces internally (14-day retention).
|
|
11
|
+
* This service ADDITIONALLY exports to the developer's chosen provider.
|
|
12
|
+
*/
|
|
13
|
+
import { Effect, Context } from 'effect';
|
|
14
|
+
export type SpanKind = 'llm' | 'tool' | 'retrieval' | 'generation' | 'internal';
|
|
15
|
+
export type SpanStatus = 'running' | 'completed' | 'error';
|
|
16
|
+
export type TraceEvent = {
|
|
17
|
+
traceId: string;
|
|
18
|
+
apiKey: string;
|
|
19
|
+
phone: string;
|
|
20
|
+
startedAt: Date;
|
|
21
|
+
endedAt?: Date;
|
|
22
|
+
durationMs?: number;
|
|
23
|
+
status: SpanStatus;
|
|
24
|
+
model?: string;
|
|
25
|
+
tokensIn: number;
|
|
26
|
+
tokensOut: number;
|
|
27
|
+
totalSteps: number;
|
|
28
|
+
error?: string;
|
|
29
|
+
metadata: Record<string, unknown>;
|
|
30
|
+
spans: SpanEvent[];
|
|
31
|
+
};
|
|
32
|
+
export type SpanEvent = {
|
|
33
|
+
spanId: string;
|
|
34
|
+
traceId: string;
|
|
35
|
+
parentSpanId?: string;
|
|
36
|
+
name: string;
|
|
37
|
+
kind: SpanKind;
|
|
38
|
+
startedAt: Date;
|
|
39
|
+
endedAt?: Date;
|
|
40
|
+
durationMs?: number;
|
|
41
|
+
status: SpanStatus;
|
|
42
|
+
input?: unknown;
|
|
43
|
+
output?: unknown;
|
|
44
|
+
error?: string;
|
|
45
|
+
metadata: Record<string, unknown>;
|
|
46
|
+
};
|
|
47
|
+
export type TraceExporter = {
|
|
48
|
+
name: string;
|
|
49
|
+
exportTrace: (trace: TraceEvent) => Effect.Effect<void, ObservabilityError>;
|
|
50
|
+
flush?: () => Effect.Effect<void, ObservabilityError>;
|
|
51
|
+
shutdown?: () => Effect.Effect<void, ObservabilityError>;
|
|
52
|
+
};
|
|
53
|
+
export declare class ObservabilityError {
|
|
54
|
+
readonly provider: string;
|
|
55
|
+
readonly message: string;
|
|
56
|
+
readonly cause?: unknown;
|
|
57
|
+
readonly _tag = "ObservabilityError";
|
|
58
|
+
constructor(provider: string, message: string, cause?: unknown);
|
|
59
|
+
}
|
|
60
|
+
declare const Observability_base: Context.TagClass<Observability, "Observability", {
|
|
61
|
+
exporters: TraceExporter[];
|
|
62
|
+
}>;
|
|
63
|
+
export declare class Observability extends Observability_base {
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Braintrust exporter.
|
|
67
|
+
* Sends traces as Braintrust spans for AI observability, evals, and scoring.
|
|
68
|
+
*/
|
|
69
|
+
export declare function braintrustExporter(config: {
|
|
70
|
+
apiKey: string;
|
|
71
|
+
projectName: string;
|
|
72
|
+
baseUrl?: string;
|
|
73
|
+
}): TraceExporter;
|
|
74
|
+
/**
|
|
75
|
+
* Axiom exporter.
|
|
76
|
+
* Sends traces as structured events to an Axiom dataset.
|
|
77
|
+
*/
|
|
78
|
+
export declare function axiomExporter(config: {
|
|
79
|
+
apiToken: string;
|
|
80
|
+
dataset: string;
|
|
81
|
+
orgId?: string;
|
|
82
|
+
baseUrl?: string;
|
|
83
|
+
}): TraceExporter;
|
|
84
|
+
/**
|
|
85
|
+
* OpenTelemetry (OTLP) exporter.
|
|
86
|
+
* Sends traces via OTLP/HTTP (JSON) to any OTEL-compatible backend
|
|
87
|
+
* (Grafana Tempo, Jaeger, Honeycomb, Datadog, etc.)
|
|
88
|
+
*/
|
|
89
|
+
export declare function otelExporter(config: {
|
|
90
|
+
endpoint: string;
|
|
91
|
+
headers?: Record<string, string>;
|
|
92
|
+
serviceName?: string;
|
|
93
|
+
}): TraceExporter;
|
|
94
|
+
/**
|
|
95
|
+
* Custom exporter — developer provides their own export function.
|
|
96
|
+
*/
|
|
97
|
+
export declare function customExporter(config: {
|
|
98
|
+
name: string;
|
|
99
|
+
exportFn: (trace: TraceEvent) => Promise<void>;
|
|
100
|
+
}): TraceExporter;
|
|
101
|
+
export {};
|
|
102
|
+
//# sourceMappingURL=Observability.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Observability.d.ts","sourceRoot":"","sources":["../../src/services/Observability.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAIxC,MAAM,MAAM,QAAQ,GAAG,KAAK,GAAG,MAAM,GAAG,WAAW,GAAG,YAAY,GAAG,UAAU,CAAA;AAC/E,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,WAAW,GAAG,OAAO,CAAA;AAE1D,MAAM,MAAM,UAAU,GAAG;IACvB,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,IAAI,CAAA;IACf,OAAO,CAAC,EAAE,IAAI,CAAA;IACd,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,UAAU,CAAA;IAClB,KAAK,CAAC,EAAE,MAAM,CAAA;I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