@kairos-computer/core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent.d.ts +27 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +53 -0
- package/dist/agent.js.map +1 -0
- package/dist/cleanup.d.ts +24 -0
- package/dist/cleanup.d.ts.map +1 -0
- package/dist/cleanup.js +146 -0
- package/dist/cleanup.js.map +1 -0
- package/dist/convert.d.ts +31 -0
- package/dist/convert.d.ts.map +1 -0
- package/dist/convert.js +235 -0
- package/dist/convert.js.map +1 -0
- package/dist/errors.d.ts +33 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +10 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/loop.d.ts +25 -0
- package/dist/loop.d.ts.map +1 -0
- package/dist/loop.js +407 -0
- package/dist/loop.js.map +1 -0
- package/dist/prompt.d.ts +10 -0
- package/dist/prompt.d.ts.map +1 -0
- package/dist/prompt.js +21 -0
- package/dist/prompt.js.map +1 -0
- package/dist/services/MessageQueue.d.ts +13 -0
- package/dist/services/MessageQueue.d.ts.map +1 -0
- package/dist/services/MessageQueue.js +8 -0
- package/dist/services/MessageQueue.js.map +1 -0
- package/dist/services/Persistence.d.ts +12 -0
- package/dist/services/Persistence.d.ts.map +1 -0
- package/dist/services/Persistence.js +8 -0
- package/dist/services/Persistence.js.map +1 -0
- package/dist/services/StopSignal.d.ts +12 -0
- package/dist/services/StopSignal.d.ts.map +1 -0
- package/dist/services/StopSignal.js +8 -0
- package/dist/services/StopSignal.js.map +1 -0
- package/dist/services/Streaming.d.ts +11 -0
- package/dist/services/Streaming.d.ts.map +1 -0
- package/dist/services/Streaming.js +7 -0
- package/dist/services/Streaming.js.map +1 -0
- package/dist/services/index.d.ts +5 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +5 -0
- package/dist/services/index.js.map +1 -0
- package/dist/stream.d.ts +8 -0
- package/dist/stream.d.ts.map +1 -0
- package/dist/stream.js +36 -0
- package/dist/stream.js.map +1 -0
- package/dist/tools.d.ts +14 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +60 -0
- package/dist/tools.js.map +1 -0
- package/dist/types.d.ts +112 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +38 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { MessageQueue, NoopMessageQueueLayer } from "./MessageQueue.js";
|
|
2
|
+
export { NoopPersistenceLayer, Persistence } from "./Persistence.js";
|
|
3
|
+
export { NoopStopSignalLayer, StopSignal } from "./StopSignal.js";
|
|
4
|
+
export { NoopStreamingLayer, Streaming } from "./Streaming.js";
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AACvE,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AACpE,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AACjE,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA"}
|
package/dist/stream.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Stream } from "effect";
|
|
2
|
+
import { StreamError } from "./errors.js";
|
|
3
|
+
/**
|
|
4
|
+
* Convert a ReadableStream into an Effect Stream.
|
|
5
|
+
* Bridge between Web Streams API and Effect's stream processing.
|
|
6
|
+
*/
|
|
7
|
+
export declare function fromReadableStream<A>(rs: ReadableStream<A>): Stream.Stream<A, StreamError>;
|
|
8
|
+
//# sourceMappingURL=stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,MAAM,EAAE,MAAM,QAAQ,CAAA;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAEzC;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAClC,EAAE,EAAE,cAAc,CAAC,CAAC,CAAC,GACpB,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,WAAW,CAAC,CA6B/B"}
|
package/dist/stream.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Effect, Stream } from "effect";
|
|
2
|
+
import { StreamError } from "./errors.js";
|
|
3
|
+
/**
|
|
4
|
+
* Convert a ReadableStream into an Effect Stream.
|
|
5
|
+
* Bridge between Web Streams API and Effect's stream processing.
|
|
6
|
+
*/
|
|
7
|
+
export function fromReadableStream(rs) {
|
|
8
|
+
return Stream.async((emit) => {
|
|
9
|
+
const reader = rs.getReader();
|
|
10
|
+
const pump = async () => {
|
|
11
|
+
try {
|
|
12
|
+
while (true) {
|
|
13
|
+
const { done, value } = await reader.read();
|
|
14
|
+
if (done) {
|
|
15
|
+
emit.end();
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
emit.single(value);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
emit.fail(new StreamError({ cause: e }));
|
|
23
|
+
}
|
|
24
|
+
finally {
|
|
25
|
+
reader.releaseLock();
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
pump().catch((e) => {
|
|
29
|
+
emit.fail(new StreamError({ cause: e }));
|
|
30
|
+
});
|
|
31
|
+
return Effect.sync(() => {
|
|
32
|
+
reader.cancel().catch(() => { });
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=stream.js.map
|
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,CAAC,CAAA;QACjC,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
package/dist/tools.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ModelMessage, ToolSet, UIMessage } from "ai";
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
import { ToolExecutionError } from "./errors.js";
|
|
4
|
+
import type { ParsedToolCall, ToolCallResult } from "./types.js";
|
|
5
|
+
/**
|
|
6
|
+
* Execute a single tool call against the ToolSet.
|
|
7
|
+
*/
|
|
8
|
+
export declare function executeTool(tools: ToolSet, toolCall: ParsedToolCall, modelMessages: ModelMessage[], abortSignal?: AbortSignal): Effect.Effect<ToolCallResult, ToolExecutionError>;
|
|
9
|
+
/**
|
|
10
|
+
* Execute all tool calls concurrently. Errors are caught per-tool
|
|
11
|
+
* and returned as `isError: true` results.
|
|
12
|
+
*/
|
|
13
|
+
export declare function executeToolCalls(tools: ToolSet, toolCalls: ParsedToolCall[], messages: UIMessage[], abortSignal?: AbortSignal): Effect.Effect<ToolCallResult[]>;
|
|
14
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAA;AAE1D,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAEhE;;GAEG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,OAAO,EACd,QAAQ,EAAE,cAAc,EACxB,aAAa,EAAE,YAAY,EAAE,EAC7B,WAAW,CAAC,EAAE,WAAW,GACxB,MAAM,CAAC,MAAM,CAAC,cAAc,EAAE,kBAAkB,CAAC,CAwCnD;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,OAAO,EACd,SAAS,EAAE,cAAc,EAAE,EAC3B,QAAQ,EAAE,SAAS,EAAE,EACrB,WAAW,CAAC,EAAE,WAAW,GACxB,MAAM,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC,CAwBjC"}
|
package/dist/tools.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { convertToModelMessages } from "ai";
|
|
2
|
+
import { Effect } from "effect";
|
|
3
|
+
import { ToolExecutionError } from "./errors.js";
|
|
4
|
+
/**
|
|
5
|
+
* Execute a single tool call against the ToolSet.
|
|
6
|
+
*/
|
|
7
|
+
export function executeTool(tools, toolCall, modelMessages, abortSignal) {
|
|
8
|
+
return Effect.gen(function* () {
|
|
9
|
+
const tool = tools[toolCall.toolName];
|
|
10
|
+
const start = Date.now();
|
|
11
|
+
if (!tool?.execute) {
|
|
12
|
+
return {
|
|
13
|
+
toolCallId: toolCall.toolCallId,
|
|
14
|
+
toolName: toolCall.toolName,
|
|
15
|
+
input: toolCall.input,
|
|
16
|
+
output: `Tool "${toolCall.toolName}" not found or has no execute function`,
|
|
17
|
+
isError: true,
|
|
18
|
+
durationMs: Date.now() - start,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const result = yield* Effect.tryPromise({
|
|
22
|
+
try: () => tool.execute(toolCall.input, {
|
|
23
|
+
toolCallId: toolCall.toolCallId,
|
|
24
|
+
messages: modelMessages,
|
|
25
|
+
abortSignal: abortSignal ?? new AbortController().signal,
|
|
26
|
+
}),
|
|
27
|
+
catch: (cause) => new ToolExecutionError({
|
|
28
|
+
toolName: toolCall.toolName,
|
|
29
|
+
toolCallId: toolCall.toolCallId,
|
|
30
|
+
cause,
|
|
31
|
+
}),
|
|
32
|
+
});
|
|
33
|
+
return {
|
|
34
|
+
toolCallId: toolCall.toolCallId,
|
|
35
|
+
toolName: toolCall.toolName,
|
|
36
|
+
input: toolCall.input,
|
|
37
|
+
output: result,
|
|
38
|
+
isError: false,
|
|
39
|
+
durationMs: Date.now() - start,
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Execute all tool calls concurrently. Errors are caught per-tool
|
|
45
|
+
* and returned as `isError: true` results.
|
|
46
|
+
*/
|
|
47
|
+
export function executeToolCalls(tools, toolCalls, messages, abortSignal) {
|
|
48
|
+
return Effect.gen(function* () {
|
|
49
|
+
const modelMessages = yield* Effect.promise(() => convertToModelMessages(messages));
|
|
50
|
+
return yield* Effect.forEach(toolCalls, (tc) => executeTool(tools, tc, modelMessages, abortSignal).pipe(Effect.catchAll((error) => Effect.succeed({
|
|
51
|
+
toolCallId: tc.toolCallId,
|
|
52
|
+
toolName: tc.toolName,
|
|
53
|
+
input: tc.input,
|
|
54
|
+
output: error.cause,
|
|
55
|
+
isError: true,
|
|
56
|
+
durationMs: 0,
|
|
57
|
+
}))), { concurrency: "unbounded" });
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,IAAI,CAAA;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAGhD;;GAEG;AACH,MAAM,UAAU,WAAW,CACzB,KAAc,EACd,QAAwB,EACxB,aAA6B,EAC7B,WAAyB;IAEzB,OAAO,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;QACzB,MAAM,IAAI,GAAG,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;QACrC,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QAExB,IAAI,CAAC,IAAI,E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AG,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAC/C,sBAAsB,CAAC,QAAQ,CAAC,CACjC,CAAA;QAED,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAC1B,SAAS,EACT,CAAC,EAAE,EAAE,EAAE,CACL,WAAW,CAAC,KAAK,EAAE,EAAE,EAAE,aAAa,EAAE,WAAW,CAAC,CAAC,IAAI,CACrD,MAAM,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CACxB,MAAM,CAAC,OAAO,CAAC;YACb,UAAU,EAAE,EAAE,CAAC,UAAU;YACzB,QAAQ,EAAE,EAAE,CAAC,QAAQ;YACrB,KAAK,EAAE,EAAE,CAAC,KAAK;YACf,MAAM,EAAE,KAAK,CAAC,KAAK;YACnB,OAAO,EAAE,IAAI;YACb,UAAU,EAAE,CAAC;SACd,CAAC,CACH,CACF,EACH,EAAE,WAAW,EAAE,WAAW,EAAE,CAC7B,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { LanguageModelV3 } from "@ai-sdk/provider";
|
|
2
|
+
import type { FinishReason, LanguageModelUsage, ToolSet, UIMessage, UIMessageChunk } from "ai";
|
|
3
|
+
import type { Effect } from "effect";
|
|
4
|
+
export type { FinishReason, LanguageModelUsage, LanguageModelV3, ToolSet, UIMessage, UIMessageChunk, };
|
|
5
|
+
/**
|
|
6
|
+
* A streaming chunk wrapped with routing metadata.
|
|
7
|
+
* The Streaming service publishes these. The frontend groups by responseId.
|
|
8
|
+
*/
|
|
9
|
+
export interface StreamChunk {
|
|
10
|
+
conversationId: string;
|
|
11
|
+
responseId: string;
|
|
12
|
+
chunk: UIMessageChunk;
|
|
13
|
+
/** Monotonic sequence number for dedup and ordering. */
|
|
14
|
+
seq: number;
|
|
15
|
+
}
|
|
16
|
+
/** Result of executing a single tool call. */
|
|
17
|
+
export interface ToolCallResult {
|
|
18
|
+
toolCallId: string;
|
|
19
|
+
toolName: string;
|
|
20
|
+
input: unknown;
|
|
21
|
+
output: unknown;
|
|
22
|
+
isError: boolean;
|
|
23
|
+
durationMs: number;
|
|
24
|
+
}
|
|
25
|
+
/** A tool call parsed from the model response. */
|
|
26
|
+
export interface ParsedToolCall {
|
|
27
|
+
type: "tool-call";
|
|
28
|
+
toolCallId: string;
|
|
29
|
+
toolName: string;
|
|
30
|
+
input: unknown;
|
|
31
|
+
}
|
|
32
|
+
/** Result of a single LLM call + any tool execution that followed. */
|
|
33
|
+
export interface StepResult {
|
|
34
|
+
stepNumber: number;
|
|
35
|
+
finishReason: FinishReason;
|
|
36
|
+
text: string;
|
|
37
|
+
toolCalls: ToolCallResult[];
|
|
38
|
+
usage: LanguageModelUsage;
|
|
39
|
+
durationMs: number;
|
|
40
|
+
}
|
|
41
|
+
/** Passed to `prepareStep`, hooks, and system prompt functions. */
|
|
42
|
+
export interface StepContext {
|
|
43
|
+
stepNumber: number;
|
|
44
|
+
steps: StepResult[];
|
|
45
|
+
messages: UIMessage[];
|
|
46
|
+
}
|
|
47
|
+
/** Override model, tools, or system prompt for a single step. */
|
|
48
|
+
export interface StepConfig {
|
|
49
|
+
model?: LanguageModelV3;
|
|
50
|
+
tools?: ToolSet;
|
|
51
|
+
system?: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* - `"stop"`: model finished naturally
|
|
55
|
+
* - `"tool-calls"`: model wants tool execution but `executeTools` is `false`
|
|
56
|
+
* - `"aborted"`: stopped by external signal
|
|
57
|
+
* - `"error"`: model returned an error finish reason
|
|
58
|
+
*/
|
|
59
|
+
export type LoopFinishReason = "stop" | "aborted" | "error" | "tool-calls";
|
|
60
|
+
/** Final result of a complete agent run. */
|
|
61
|
+
export interface LoopResult {
|
|
62
|
+
responseId: string;
|
|
63
|
+
messages: UIMessage[];
|
|
64
|
+
steps: StepResult[];
|
|
65
|
+
totalUsage: LanguageModelUsage;
|
|
66
|
+
finishReason: LoopFinishReason;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Called before each LLM step. Return a partial config to override
|
|
70
|
+
* the model, tools, or system prompt for that step.
|
|
71
|
+
*/
|
|
72
|
+
export type PrepareStepFn = (ctx: StepContext) => Effect.Effect<StepConfig> | StepConfig;
|
|
73
|
+
export interface CallSettings {
|
|
74
|
+
maxOutputTokens?: number;
|
|
75
|
+
temperature?: number;
|
|
76
|
+
topP?: number;
|
|
77
|
+
topK?: number;
|
|
78
|
+
stopSequences?: string[];
|
|
79
|
+
providerOptions?: Record<string, Record<string, unknown>>;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Controls how tool calls are handled:
|
|
83
|
+
* - `true` (default): auto-execute all tools, continue the loop
|
|
84
|
+
* - `false`: stop the loop and return with pending tool call parts in messages
|
|
85
|
+
* - function: you provide custom execution logic, loop continues with your results
|
|
86
|
+
*/
|
|
87
|
+
export type ExecuteToolsFn = (toolCalls: ParsedToolCall[], tools: ToolSet, abortSignal?: AbortSignal) => Effect.Effect<ToolCallResult[]>;
|
|
88
|
+
export interface AgentConfig {
|
|
89
|
+
/** Any AI SDK LanguageModelV3 provider (Anthropic, OpenAI, Bedrock, etc.). */
|
|
90
|
+
model: LanguageModelV3;
|
|
91
|
+
/** Static string or dynamic function called once at the start. */
|
|
92
|
+
system?: string | ((ctx: StepContext) => string);
|
|
93
|
+
/** Tools available to the model. Define with `tool()` from `ai`. */
|
|
94
|
+
tools?: ToolSet;
|
|
95
|
+
/** How to handle tool calls. Default: `true` (auto-execute). */
|
|
96
|
+
executeTools?: boolean | ExecuteToolsFn;
|
|
97
|
+
/** Override model/tools/system per step. */
|
|
98
|
+
prepareStep?: PrepareStepFn;
|
|
99
|
+
/** Model call settings (temperature, max tokens, etc.). */
|
|
100
|
+
callSettings?: CallSettings;
|
|
101
|
+
/** Called when `finishReason` is `"length"`. Return compacted messages to continue. */
|
|
102
|
+
onContextOverflow?: (messages: UIMessage[]) => Effect.Effect<UIMessage[]>;
|
|
103
|
+
/** Lifecycle hooks. */
|
|
104
|
+
hooks?: AgentHooks;
|
|
105
|
+
}
|
|
106
|
+
export interface AgentHooks {
|
|
107
|
+
onStepStart?: (stepNumber: number) => Effect.Effect<void>;
|
|
108
|
+
onStepFinish?: (result: StepResult) => Effect.Effect<void>;
|
|
109
|
+
onToolCall?: (toolCall: ParsedToolCall) => Effect.Effect<void>;
|
|
110
|
+
onToolResult?: (result: ToolCallResult) => Effect.Effect<void>;
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AACvD,OAAO,KAAK,EACV,YAAY,EACZ,kBAAkB,EAClB,OAAO,EACP,SAAS,EACT,cAAc,EACf,MAAM,IAAI,CAAA;AACX,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAGpC,YAAY,EACV,YAAY,EACZ,kBAAkB,EAClB,eAAe,EACf,OAAO,EACP,SAAS,EACT,cAAc,GACf,CAAA;AAID;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B,cAAc,EAAE,MAAM,CAAA;IACtB,UAAU,EAAE,MAAM,CAAA;IAClB,KAAK,EAAE,cAAc,CAAA;IACrB,wDAAwD;IACxD,GAAG,EAAE,MAAM,CAAA;CACZ;AAID,8CAA8C;AAC9C,MAAM,WAAW,cAAc;IAC7B,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,OAAO,CAAA;IACd,MAAM,EAAE,OAAO,CAAA;IACf,OAAO,EAAE,OAAO,CAAA;IAChB,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,kDAAkD;AAClD,MAAM,WAAW,cAAc;IAC7B,IAAI,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CAAC,CAAA;IAC9D,YAAY,CAAC,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;CAC/D"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kairos-computer/core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"files": ["dist"],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc",
|
|
16
|
+
"prepublishOnly": "tsc"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@ai-sdk/provider": "^3.0.8",
|
|
20
|
+
"ai": "^6.0.116",
|
|
21
|
+
"effect": "^3.20.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@ai-sdk/anthropic": "^3.0.58",
|
|
25
|
+
"@types/bun": "^1.3.11",
|
|
26
|
+
"typescript": "^5.9.3",
|
|
27
|
+
"zod": "^4.3.6"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "git+https://github.com/kairos-computer/kai.git",
|
|
36
|
+
"directory": "packages/core"
|
|
37
|
+
}
|
|
38
|
+
}
|