@alisio/core 0.1.0-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +25 -0
  3. package/dist/application.d.ts +225 -0
  4. package/dist/application.js +950 -0
  5. package/dist/config.d.ts +481 -0
  6. package/dist/config.js +592 -0
  7. package/dist/core/compaction.d.ts +136 -0
  8. package/dist/core/compaction.js +404 -0
  9. package/dist/core/contracts.d.ts +147 -0
  10. package/dist/core/contracts.js +1 -0
  11. package/dist/core/registry.d.ts +8 -0
  12. package/dist/core/registry.js +54 -0
  13. package/dist/core/runner.d.ts +160 -0
  14. package/dist/core/runner.js +625 -0
  15. package/dist/extensions/registry.d.ts +28 -0
  16. package/dist/extensions/registry.js +58 -0
  17. package/dist/index.d.ts +29 -0
  18. package/dist/index.js +28 -0
  19. package/dist/integrations/herdr.d.ts +34 -0
  20. package/dist/integrations/herdr.js +174 -0
  21. package/dist/mcp/connector.d.ts +65 -0
  22. package/dist/mcp/connector.js +423 -0
  23. package/dist/plugins/host.d.ts +169 -0
  24. package/dist/plugins/host.js +585 -0
  25. package/dist/plugins/install.d.ts +100 -0
  26. package/dist/plugins/install.js +322 -0
  27. package/dist/providers/openai-compatible.d.ts +14 -0
  28. package/dist/providers/openai-compatible.js +228 -0
  29. package/dist/providers/registry.d.ts +35 -0
  30. package/dist/providers/registry.js +74 -0
  31. package/dist/providers/routing.d.ts +11 -0
  32. package/dist/providers/routing.js +41 -0
  33. package/dist/providers/settings.d.ts +30 -0
  34. package/dist/providers/settings.js +80 -0
  35. package/dist/resources/context.d.ts +44 -0
  36. package/dist/resources/context.js +171 -0
  37. package/dist/resources/prompts.d.ts +77 -0
  38. package/dist/resources/prompts.js +182 -0
  39. package/dist/resources/skills.d.ts +82 -0
  40. package/dist/resources/skills.js +214 -0
  41. package/dist/runtime/fs.d.ts +9 -0
  42. package/dist/runtime/fs.js +73 -0
  43. package/dist/runtime/modules.d.ts +16 -0
  44. package/dist/runtime/modules.js +83 -0
  45. package/dist/runtime/paths.d.ts +4 -0
  46. package/dist/runtime/paths.js +42 -0
  47. package/dist/runtime/process.d.ts +25 -0
  48. package/dist/runtime/process.js +122 -0
  49. package/dist/runtime/sqlite.d.ts +3 -0
  50. package/dist/runtime/sqlite.js +85 -0
  51. package/dist/runtime/store.d.ts +38 -0
  52. package/dist/runtime/store.js +259 -0
  53. package/dist/sessions/children.d.ts +55 -0
  54. package/dist/sessions/children.js +233 -0
  55. package/dist/startup/index.d.ts +41 -0
  56. package/dist/startup/index.js +105 -0
  57. package/dist/startup/mascot.d.ts +6 -0
  58. package/dist/startup/mascot.js +30 -0
  59. package/dist/startup/screen.d.ts +18 -0
  60. package/dist/startup/screen.js +117 -0
  61. package/dist/startup/text.d.ts +19 -0
  62. package/dist/startup/text.js +68 -0
  63. package/dist/tools/execute.d.ts +16 -0
  64. package/dist/tools/execute.js +96 -0
  65. package/dist/tools/search.d.ts +69 -0
  66. package/dist/tools/search.js +232 -0
  67. package/dist/tools/standard.d.ts +22 -0
  68. package/dist/tools/standard.js +419 -0
  69. package/dist/tools/webfetch.d.ts +26 -0
  70. package/dist/tools/webfetch.js +119 -0
  71. package/dist/trust.d.ts +34 -0
  72. package/dist/trust.js +113 -0
  73. package/dist/version.d.ts +7 -0
  74. package/dist/version.js +26 -0
  75. package/package.json +62 -0
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ import type { ToolDefinition } from "@alisio/sdk";
2
+ export declare class ToolRegistry {
3
+ private entries;
4
+ register(tool: ToolDefinition): () => void;
5
+ list(): ToolDefinition[];
6
+ get(name: string): ToolDefinition;
7
+ parse(name: string, argumentsText: string): Record<string, unknown>;
8
+ }
@@ -0,0 +1,54 @@
1
+ import Ajv from "ajv";
2
+ import Ajv2020 from "ajv/dist/2020.js";
3
+ const ajv2020 = new Ajv2020({ allErrors: true, strict: true });
4
+ const ajv = new Ajv({ allErrors: true, strict: true });
5
+ function rejectReferences(value) {
6
+ if (!value || typeof value !== "object")
7
+ return;
8
+ for (const [k, v] of Object.entries(value)) {
9
+ if (["$ref", "$id", "$async"].includes(k))
10
+ throw new Error(`Schema keyword ${k} is not supported`);
11
+ rejectReferences(v);
12
+ }
13
+ }
14
+ export class ToolRegistry {
15
+ entries = new Map();
16
+ register(tool) {
17
+ if (!/^[a-zA-Z0-9_-]{1,64}$/.test(tool.name))
18
+ throw new Error(`Invalid tool name: ${tool.name}`);
19
+ if (this.entries.has(tool.name))
20
+ throw new Error(`Duplicate tool: ${tool.name}`);
21
+ if (tool.inputSchema.type !== "object")
22
+ throw new Error("Tool input schema must be an object");
23
+ rejectReferences(tool.inputSchema);
24
+ const entry = {
25
+ tool,
26
+ validate: (tool.inputSchema.$schema === "https://json-schema.org/draft/2020-12/schema"
27
+ ? ajv2020
28
+ : ajv).compile(tool.inputSchema),
29
+ };
30
+ this.entries.set(tool.name, entry);
31
+ return () => {
32
+ if (this.entries.get(tool.name) === entry)
33
+ this.entries.delete(tool.name);
34
+ };
35
+ }
36
+ list() {
37
+ return [...this.entries.values()].map((x) => x.tool);
38
+ }
39
+ get(name) {
40
+ const e = this.entries.get(name);
41
+ if (!e)
42
+ throw new Error(`Unknown tool: ${name}`);
43
+ return e.tool;
44
+ }
45
+ parse(name, argumentsText) {
46
+ const e = this.entries.get(name);
47
+ if (!e)
48
+ throw new Error(`Unknown tool: ${name}`);
49
+ const value = JSON.parse(argumentsText);
50
+ if (!e.validate(value))
51
+ throw new Error(ajv.errorsText(e.validate.errors));
52
+ return value;
53
+ }
54
+ }
@@ -0,0 +1,160 @@
1
+ import { type Attachment, type Message, type ModelProvider, type RunEvent, type ToolDefinition } from "@alisio/sdk";
2
+ import type { ApprovalHandler, ContextSource, Policy, RunnerExtensions, SessionStore } from "./contracts.ts";
3
+ import type { ToolRegistry } from "./registry.ts";
4
+ export interface CompactionSettings {
5
+ /** Compact automatically when context usage crosses `threshold` of a known window. */
6
+ auto?: boolean;
7
+ threshold?: number;
8
+ keepTurns?: number;
9
+ /**
10
+ * Per-call output token budget for the summarizer. Defaults to 4096 when unset; never falls
11
+ * back to the agent-loop `maxOutputTokens`. A truncated summary is accepted as partial.
12
+ */
13
+ maxOutputTokens?: number;
14
+ }
15
+ export interface RunnerOptions {
16
+ /** Provider bound to this persisted session. */
17
+ provider: ModelProvider;
18
+ providerFor?: (session: import("./contracts.ts").Session) => Promise<ModelProvider>;
19
+ registry: ToolRegistry;
20
+ store: SessionStore;
21
+ context: ContextSource;
22
+ policy: Policy;
23
+ workspace: string;
24
+ maxTurns?: number;
25
+ timeoutMs?: number;
26
+ maxContextChars?: number;
27
+ maxOutputTokens?: number;
28
+ maxTokens?: number;
29
+ onEvent?: (event: RunEvent) => void;
30
+ readConcurrency?: number;
31
+ /** Context window in tokens for a model, when known. Drives auto-compaction at `threshold`; when
32
+ * unknown (or absurdly large, see `MAX_TRUSTED_WINDOW`) the char budget falls back. */
33
+ contextWindow?: (model: string) => number | undefined;
34
+ compaction?: CompactionSettings;
35
+ /** When set, write/process tools not allowed by the policy are offered and ask first. */
36
+ approve?: ApprovalHandler;
37
+ /** Generic hooks (implemented by the plugin host) for compaction and session start. */
38
+ extensions?: RunnerExtensions;
39
+ /**
40
+ * Provider-native tool definitions (for example a hosted `web_search` tool) appended to every
41
+ * request's `tools` alongside the registry's function tools. Opt-in, set once for the whole
42
+ * runner; only meaningful for a provider that documents an equivalent server-side tool.
43
+ */
44
+ nativeTools?: Array<Record<string, unknown>>;
45
+ }
46
+ /** The settings a running TUI can change live; merged into the runner options on apply. */
47
+ export interface RunnerSettingsPatch {
48
+ /** Compaction settings; merged over the current ones (any subset). */
49
+ compaction?: Partial<CompactionSettings>;
50
+ /** Maximum turns per run. */
51
+ maxTurns?: number;
52
+ /** Per-call max output tokens budget. */
53
+ maxOutputTokens?: number;
54
+ /** Post-compaction context budget in characters. */
55
+ maxContextChars?: number;
56
+ /** Per-run timeout in milliseconds; the next run honors it. */
57
+ timeoutMs?: number;
58
+ }
59
+ /**
60
+ * Per-run overrides used by embedders and child sessions. Callers must only NARROW: `policy`
61
+ * and `toolFilter` are applied on top of the runner's policy and tools.
62
+ */
63
+ export interface RunOptions {
64
+ /** What UIs show instead of the prompt (e.g. `/init`). */
65
+ display?: string;
66
+ /** Images attached to this turn's user message, sent as vision content parts. */
67
+ attachments?: Attachment[];
68
+ /** Extra system instructions for this run (e.g. an agent persona). */
69
+ instructions?: string;
70
+ toolFilter?: (tool: ToolDefinition) => boolean;
71
+ policy?: Policy;
72
+ /** Allow interactive approvals for this run (default: when the runner has a handler). */
73
+ approvals?: boolean;
74
+ /** Shown with approval requests, e.g. the agent path of a child session. */
75
+ label?: string;
76
+ workspace?: string;
77
+ context?: ContextSource;
78
+ maxTurns?: number;
79
+ maxTokens?: number;
80
+ /** Per-call output token budget for this run; beats the runner-level budget when set. */
81
+ maxOutputTokens?: number;
82
+ timeoutMs?: number;
83
+ }
84
+ /**
85
+ * Default cumulative token budget for one run: several context windows (each turn re-sends the
86
+ * context), clamped; 1M tokens when the window is unknown.
87
+ */
88
+ export declare function defaultTokenBudget(contextWindow?: number): number;
89
+ export interface CompactionResult {
90
+ replaced: number;
91
+ before: number;
92
+ after: number;
93
+ summary: Extract<Message, {
94
+ role: "user";
95
+ }>;
96
+ }
97
+ export declare class AgentRunner {
98
+ private options;
99
+ /** Sessions with an active run or compaction (one at a time per session). */
100
+ private active;
101
+ /** Messages queued for a session's next turn (e.g. input for a running child). */
102
+ private inbox;
103
+ /** Last provider-reported context size per session and the history length it covered. */
104
+ private reported;
105
+ constructor(options: RunnerOptions);
106
+ /** Current capability policy (may widen when the user approves an effect for the session). */
107
+ get policy(): Readonly<Policy>;
108
+ /** Whether write/process tools can be approved interactively. */
109
+ get approvals(): boolean;
110
+ /**
111
+ * Live-update runnable settings so the next `run`/`compact` call honors them without restarting
112
+ * Alisio. Every patch field is merged over the current options; unrelated settings are kept.
113
+ */
114
+ applySettings(patch: RunnerSettingsPatch): void;
115
+ private emitter;
116
+ /** Tools offered to the model under the current policy (and optional run narrowing). */
117
+ availableTools(run?: RunOptions): ToolDefinition[];
118
+ /** Abort signal of the session's active run, if any (used to cascade cancellation). */
119
+ signal(sessionId: string): AbortSignal | undefined;
120
+ isRunning(sessionId: string): boolean;
121
+ /** Aborts the active run (or compaction) of a session. */
122
+ abort(sessionId: string, reason?: unknown): boolean;
123
+ /** Queues text as a user message for the session's next turn (or next run when idle). */
124
+ enqueue(sessionId: string, text: string): void;
125
+ private drain;
126
+ private claim;
127
+ private toolsText;
128
+ /** Estimated tokens the next request of a session would send. */
129
+ estimateContext(sessionId: string): Promise<number>;
130
+ /**
131
+ * The effective context budget the TUI context bar displays. The model window is the total
132
+ * when known (and not beyond `MAX_TRUSTED_WINDOW`); otherwise the bar reports an honest
133
+ * unknown (`basis: "unknown"`, no fabricated total). `compactionAt` is the percentage of
134
+ * `total` where auto-compaction triggers, so the bar turns red exactly where the engine
135
+ * compacts. The engine's own auto-compaction guardrail still falls back to the char budget
136
+ * internally (see `shouldCompactContext`) — that fallback is never shown as a fake total.
137
+ */
138
+ contextBudget(model: string): {
139
+ total?: number;
140
+ basis: "window" | "unknown";
141
+ compactionAt: number;
142
+ };
143
+ /** Change the model used by subsequent turns of a session; recorded in the store. */
144
+ setModel(sessionId: string, model: string): void;
145
+ /** Manually compact a session outside a run. */
146
+ compact(sessionId: string, request?: {
147
+ focus?: string;
148
+ signal?: AbortSignal;
149
+ }): Promise<CompactionResult | undefined>;
150
+ private compactLocked;
151
+ run(sessionId: string, prompt: string, signal?: AbortSignal, options?: RunOptions): Promise<{
152
+ sessionId: string;
153
+ text: string;
154
+ status: string;
155
+ usage: {
156
+ input: number;
157
+ output: number;
158
+ };
159
+ }>;
160
+ }