@hypen-space/gloop-effect 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/README.md +422 -0
- package/dist/AIProvider.d.ts +43 -0
- package/dist/AIProvider.d.ts.map +1 -0
- package/dist/AIProvider.js +27 -0
- package/dist/AIProvider.js.map +1 -0
- package/dist/Agent.d.ts +91 -0
- package/dist/Agent.d.ts.map +1 -0
- package/dist/Agent.js +378 -0
- package/dist/Agent.js.map +1 -0
- package/dist/Conversation.d.ts +44 -0
- package/dist/Conversation.d.ts.map +1 -0
- package/dist/Conversation.js +124 -0
- package/dist/Conversation.js.map +1 -0
- package/dist/Errors.d.ts +102 -0
- package/dist/Errors.d.ts.map +1 -0
- package/dist/Errors.js +80 -0
- package/dist/Errors.js.map +1 -0
- package/dist/Interpreter.d.ts +62 -0
- package/dist/Interpreter.d.ts.map +1 -0
- package/dist/Interpreter.js +217 -0
- package/dist/Interpreter.js.map +1 -0
- package/dist/Schema.d.ts +188 -0
- package/dist/Schema.d.ts.map +1 -0
- package/dist/Schema.js +135 -0
- package/dist/Schema.js.map +1 -0
- package/dist/Tool.d.ts +70 -0
- package/dist/Tool.d.ts.map +1 -0
- package/dist/Tool.js +138 -0
- package/dist/Tool.js.map +1 -0
- package/dist/defaults/Builtins.d.ts +23 -0
- package/dist/defaults/Builtins.d.ts.map +1 -0
- package/dist/defaults/Builtins.js +38 -0
- package/dist/defaults/Builtins.js.map +1 -0
- package/dist/defaults/FileMemory.d.ts +16 -0
- package/dist/defaults/FileMemory.d.ts.map +1 -0
- package/dist/defaults/FileMemory.js +32 -0
- package/dist/defaults/FileMemory.js.map +1 -0
- package/dist/defaults/OpenRouter.d.ts +20 -0
- package/dist/defaults/OpenRouter.d.ts.map +1 -0
- package/dist/defaults/OpenRouter.js +68 -0
- package/dist/defaults/OpenRouter.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +42 -0
- package/dist/index.js.map +1 -0
- package/package.json +33 -0
package/dist/Schema.d.ts
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* gloop-effect/Schema — Data schemas for everything that crosses a boundary.
|
|
3
|
+
*
|
|
4
|
+
* This module is the single source of truth for:
|
|
5
|
+
* - Branded entity IDs (MessageId, ToolCallId, RequestId, ModelId)
|
|
6
|
+
* - Conversation value types (Message, AgentMessage)
|
|
7
|
+
* - Tool data types (ToolCall, ToolResult, ToolArgument)
|
|
8
|
+
* - The `AgentEvent` discriminated union emitted by the actor
|
|
9
|
+
* - The `AgentError` union (re-exported as a Schema so events can carry
|
|
10
|
+
* typed errors over the wire)
|
|
11
|
+
*
|
|
12
|
+
* Service interfaces (Agent, ConversationHandle, AIProviderImpl, …) stay as
|
|
13
|
+
* TypeScript interfaces — they carry methods and can't be Schemas.
|
|
14
|
+
*/
|
|
15
|
+
import { Schema } from "effect";
|
|
16
|
+
import { AIProviderError, AgentInterruptedError, FatalAgentError, FileIOError, MemoryError, ShellExecError, ToolExecutionError, ToolNotFoundError, ToolPermissionDeniedError } from "./Errors.js";
|
|
17
|
+
export declare const MessageId: Schema.brand<typeof Schema.String, "@gloop/MessageId">;
|
|
18
|
+
export type MessageId = Schema.Schema.Type<typeof MessageId>;
|
|
19
|
+
export declare const ToolCallId: Schema.brand<typeof Schema.String, "@gloop/ToolCallId">;
|
|
20
|
+
export type ToolCallId = Schema.Schema.Type<typeof ToolCallId>;
|
|
21
|
+
export declare const RequestId: Schema.brand<typeof Schema.String, "@gloop/RequestId">;
|
|
22
|
+
export type RequestId = Schema.Schema.Type<typeof RequestId>;
|
|
23
|
+
export declare const ModelId: Schema.brand<typeof Schema.String, "@gloop/ModelId">;
|
|
24
|
+
export type ModelId = Schema.Schema.Type<typeof ModelId>;
|
|
25
|
+
export declare const MessageRole: Schema.Literal<["system", "user", "assistant"]>;
|
|
26
|
+
export type MessageRole = Schema.Schema.Type<typeof MessageRole>;
|
|
27
|
+
export declare const Message: Schema.Struct<{
|
|
28
|
+
role: Schema.Literal<["system", "user", "assistant"]>;
|
|
29
|
+
content: typeof Schema.String;
|
|
30
|
+
}>;
|
|
31
|
+
export type Message = Schema.Schema.Type<typeof Message>;
|
|
32
|
+
export declare const AgentMessageRole: Schema.Literal<["user", "system"]>;
|
|
33
|
+
export type AgentMessageRole = Schema.Schema.Type<typeof AgentMessageRole>;
|
|
34
|
+
/** Inbound message (id may be absent — the actor assigns one on enqueue). */
|
|
35
|
+
export declare const AgentMessage: Schema.Struct<{
|
|
36
|
+
id: Schema.optional<Schema.brand<typeof Schema.String, "@gloop/MessageId">>;
|
|
37
|
+
role: Schema.Literal<["user", "system"]>;
|
|
38
|
+
content: typeof Schema.String;
|
|
39
|
+
}>;
|
|
40
|
+
export type AgentMessage = Schema.Schema.Type<typeof AgentMessage>;
|
|
41
|
+
/** An enqueued message: id is always populated. */
|
|
42
|
+
export declare const EnqueuedAgentMessage: Schema.Struct<{
|
|
43
|
+
id: Schema.brand<typeof Schema.String, "@gloop/MessageId">;
|
|
44
|
+
role: Schema.Literal<["user", "system"]>;
|
|
45
|
+
content: typeof Schema.String;
|
|
46
|
+
}>;
|
|
47
|
+
export type EnqueuedAgentMessage = Schema.Schema.Type<typeof EnqueuedAgentMessage>;
|
|
48
|
+
export declare const ToolArgument: Schema.Struct<{
|
|
49
|
+
name: typeof Schema.String;
|
|
50
|
+
description: typeof Schema.String;
|
|
51
|
+
}>;
|
|
52
|
+
export type ToolArgument = Schema.Schema.Type<typeof ToolArgument>;
|
|
53
|
+
export declare const ToolCall: Schema.Struct<{
|
|
54
|
+
name: typeof Schema.String;
|
|
55
|
+
args: Schema.Record$<typeof Schema.String, typeof Schema.String>;
|
|
56
|
+
}>;
|
|
57
|
+
export type ToolCall = Schema.Schema.Type<typeof ToolCall>;
|
|
58
|
+
export declare const ToolResult: Schema.Struct<{
|
|
59
|
+
name: typeof Schema.String;
|
|
60
|
+
output: typeof Schema.String;
|
|
61
|
+
success: typeof Schema.Boolean;
|
|
62
|
+
}>;
|
|
63
|
+
export type ToolResult = Schema.Schema.Type<typeof ToolResult>;
|
|
64
|
+
export declare const SpawnResult: Schema.Struct<{
|
|
65
|
+
success: typeof Schema.Boolean;
|
|
66
|
+
summary: typeof Schema.String;
|
|
67
|
+
exitCode: typeof Schema.Number;
|
|
68
|
+
stdout: typeof Schema.String;
|
|
69
|
+
stderr: typeof Schema.String;
|
|
70
|
+
}>;
|
|
71
|
+
export type SpawnResult = Schema.Schema.Type<typeof SpawnResult>;
|
|
72
|
+
export declare const AgentErrorSchema: Schema.Union<[typeof AIProviderError, typeof ToolNotFoundError, typeof ToolExecutionError, typeof ToolPermissionDeniedError, typeof AgentInterruptedError, typeof FatalAgentError, typeof FileIOError, typeof ShellExecError, typeof MemoryError]>;
|
|
73
|
+
export type AgentErrorSchema = Schema.Schema.Type<typeof AgentErrorSchema>;
|
|
74
|
+
export declare const TurnStartEvent: Schema.TaggedStruct<"TurnStart", {
|
|
75
|
+
message: Schema.Struct<{
|
|
76
|
+
id: Schema.brand<typeof Schema.String, "@gloop/MessageId">;
|
|
77
|
+
role: Schema.Literal<["user", "system"]>;
|
|
78
|
+
content: typeof Schema.String;
|
|
79
|
+
}>;
|
|
80
|
+
}>;
|
|
81
|
+
export type TurnStartEvent = Schema.Schema.Type<typeof TurnStartEvent>;
|
|
82
|
+
export declare const TurnEndEvent: Schema.TaggedStruct<"TurnEnd", {}>;
|
|
83
|
+
export type TurnEndEvent = Schema.Schema.Type<typeof TurnEndEvent>;
|
|
84
|
+
export declare const BusyEvent: Schema.TaggedStruct<"Busy", {}>;
|
|
85
|
+
export type BusyEvent = Schema.Schema.Type<typeof BusyEvent>;
|
|
86
|
+
export declare const IdleEvent: Schema.TaggedStruct<"Idle", {}>;
|
|
87
|
+
export type IdleEvent = Schema.Schema.Type<typeof IdleEvent>;
|
|
88
|
+
export declare const QueueChangedEvent: Schema.TaggedStruct<"QueueChanged", {
|
|
89
|
+
pending: typeof Schema.Number;
|
|
90
|
+
}>;
|
|
91
|
+
export type QueueChangedEvent = Schema.Schema.Type<typeof QueueChangedEvent>;
|
|
92
|
+
export declare const StreamChunkEvent: Schema.TaggedStruct<"StreamChunk", {
|
|
93
|
+
text: typeof Schema.String;
|
|
94
|
+
}>;
|
|
95
|
+
export type StreamChunkEvent = Schema.Schema.Type<typeof StreamChunkEvent>;
|
|
96
|
+
export declare const StreamDoneEvent: Schema.TaggedStruct<"StreamDone", {}>;
|
|
97
|
+
export type StreamDoneEvent = Schema.Schema.Type<typeof StreamDoneEvent>;
|
|
98
|
+
export declare const ToolStartEvent: Schema.TaggedStruct<"ToolStart", {
|
|
99
|
+
id: Schema.brand<typeof Schema.String, "@gloop/ToolCallId">;
|
|
100
|
+
name: typeof Schema.String;
|
|
101
|
+
preview: typeof Schema.String;
|
|
102
|
+
}>;
|
|
103
|
+
export type ToolStartEvent = Schema.Schema.Type<typeof ToolStartEvent>;
|
|
104
|
+
export declare const ToolDoneEvent: Schema.TaggedStruct<"ToolDone", {
|
|
105
|
+
id: Schema.brand<typeof Schema.String, "@gloop/ToolCallId">;
|
|
106
|
+
name: typeof Schema.String;
|
|
107
|
+
ok: typeof Schema.Boolean;
|
|
108
|
+
output: typeof Schema.String;
|
|
109
|
+
}>;
|
|
110
|
+
export type ToolDoneEvent = Schema.Schema.Type<typeof ToolDoneEvent>;
|
|
111
|
+
export declare const MemoryEvent: Schema.TaggedStruct<"Memory", {
|
|
112
|
+
op: Schema.Literal<["remember", "forget"]>;
|
|
113
|
+
content: typeof Schema.String;
|
|
114
|
+
}>;
|
|
115
|
+
export type MemoryEvent = Schema.Schema.Type<typeof MemoryEvent>;
|
|
116
|
+
export declare const SystemRefreshedEvent: Schema.TaggedStruct<"SystemRefreshed", {}>;
|
|
117
|
+
export type SystemRefreshedEvent = Schema.Schema.Type<typeof SystemRefreshedEvent>;
|
|
118
|
+
export declare const TaskCompleteEvent: Schema.TaggedStruct<"TaskComplete", {
|
|
119
|
+
summary: typeof Schema.String;
|
|
120
|
+
}>;
|
|
121
|
+
export type TaskCompleteEvent = Schema.Schema.Type<typeof TaskCompleteEvent>;
|
|
122
|
+
export declare const InterruptedEvent: Schema.TaggedStruct<"Interrupted", {}>;
|
|
123
|
+
export type InterruptedEvent = Schema.Schema.Type<typeof InterruptedEvent>;
|
|
124
|
+
export declare const ErrorEvent: Schema.TaggedStruct<"Error", {
|
|
125
|
+
error: Schema.Union<[typeof AIProviderError, typeof ToolNotFoundError, typeof ToolExecutionError, typeof ToolPermissionDeniedError, typeof AgentInterruptedError, typeof FatalAgentError, typeof FileIOError, typeof ShellExecError, typeof MemoryError]>;
|
|
126
|
+
}>;
|
|
127
|
+
export type ErrorEvent = Schema.Schema.Type<typeof ErrorEvent>;
|
|
128
|
+
export declare const FatalEvent: Schema.TaggedStruct<"Fatal", {
|
|
129
|
+
error: Schema.Union<[typeof AIProviderError, typeof ToolNotFoundError, typeof ToolExecutionError, typeof ToolPermissionDeniedError, typeof AgentInterruptedError, typeof FatalAgentError, typeof FileIOError, typeof ShellExecError, typeof MemoryError]>;
|
|
130
|
+
}>;
|
|
131
|
+
export type FatalEvent = Schema.Schema.Type<typeof FatalEvent>;
|
|
132
|
+
export declare const ConfirmRequestEvent: Schema.TaggedStruct<"ConfirmRequest", {
|
|
133
|
+
id: Schema.brand<typeof Schema.String, "@gloop/RequestId">;
|
|
134
|
+
command: typeof Schema.String;
|
|
135
|
+
}>;
|
|
136
|
+
export type ConfirmRequestEvent = Schema.Schema.Type<typeof ConfirmRequestEvent>;
|
|
137
|
+
export declare const AskRequestEvent: Schema.TaggedStruct<"AskRequest", {
|
|
138
|
+
id: Schema.brand<typeof Schema.String, "@gloop/RequestId">;
|
|
139
|
+
question: typeof Schema.String;
|
|
140
|
+
}>;
|
|
141
|
+
export type AskRequestEvent = Schema.Schema.Type<typeof AskRequestEvent>;
|
|
142
|
+
export declare const AgentEvent: Schema.Union<[Schema.TaggedStruct<"TurnStart", {
|
|
143
|
+
message: Schema.Struct<{
|
|
144
|
+
id: Schema.brand<typeof Schema.String, "@gloop/MessageId">;
|
|
145
|
+
role: Schema.Literal<["user", "system"]>;
|
|
146
|
+
content: typeof Schema.String;
|
|
147
|
+
}>;
|
|
148
|
+
}>, Schema.TaggedStruct<"TurnEnd", {}>, Schema.TaggedStruct<"Busy", {}>, Schema.TaggedStruct<"Idle", {}>, Schema.TaggedStruct<"QueueChanged", {
|
|
149
|
+
pending: typeof Schema.Number;
|
|
150
|
+
}>, Schema.TaggedStruct<"StreamChunk", {
|
|
151
|
+
text: typeof Schema.String;
|
|
152
|
+
}>, Schema.TaggedStruct<"StreamDone", {}>, Schema.TaggedStruct<"ToolStart", {
|
|
153
|
+
id: Schema.brand<typeof Schema.String, "@gloop/ToolCallId">;
|
|
154
|
+
name: typeof Schema.String;
|
|
155
|
+
preview: typeof Schema.String;
|
|
156
|
+
}>, Schema.TaggedStruct<"ToolDone", {
|
|
157
|
+
id: Schema.brand<typeof Schema.String, "@gloop/ToolCallId">;
|
|
158
|
+
name: typeof Schema.String;
|
|
159
|
+
ok: typeof Schema.Boolean;
|
|
160
|
+
output: typeof Schema.String;
|
|
161
|
+
}>, Schema.TaggedStruct<"Memory", {
|
|
162
|
+
op: Schema.Literal<["remember", "forget"]>;
|
|
163
|
+
content: typeof Schema.String;
|
|
164
|
+
}>, Schema.TaggedStruct<"SystemRefreshed", {}>, Schema.TaggedStruct<"TaskComplete", {
|
|
165
|
+
summary: typeof Schema.String;
|
|
166
|
+
}>, Schema.TaggedStruct<"Interrupted", {}>, Schema.TaggedStruct<"Error", {
|
|
167
|
+
error: Schema.Union<[typeof AIProviderError, typeof ToolNotFoundError, typeof ToolExecutionError, typeof ToolPermissionDeniedError, typeof AgentInterruptedError, typeof FatalAgentError, typeof FileIOError, typeof ShellExecError, typeof MemoryError]>;
|
|
168
|
+
}>, Schema.TaggedStruct<"Fatal", {
|
|
169
|
+
error: Schema.Union<[typeof AIProviderError, typeof ToolNotFoundError, typeof ToolExecutionError, typeof ToolPermissionDeniedError, typeof AgentInterruptedError, typeof FatalAgentError, typeof FileIOError, typeof ShellExecError, typeof MemoryError]>;
|
|
170
|
+
}>, Schema.TaggedStruct<"ConfirmRequest", {
|
|
171
|
+
id: Schema.brand<typeof Schema.String, "@gloop/RequestId">;
|
|
172
|
+
command: typeof Schema.String;
|
|
173
|
+
}>, Schema.TaggedStruct<"AskRequest", {
|
|
174
|
+
id: Schema.brand<typeof Schema.String, "@gloop/RequestId">;
|
|
175
|
+
question: typeof Schema.String;
|
|
176
|
+
}>]>;
|
|
177
|
+
export type AgentEvent = Schema.Schema.Type<typeof AgentEvent>;
|
|
178
|
+
export type AgentEventOf<T extends AgentEvent["_tag"]> = Extract<AgentEvent, {
|
|
179
|
+
_tag: T;
|
|
180
|
+
}>;
|
|
181
|
+
export declare const AgentConfig: Schema.Struct<{
|
|
182
|
+
model: Schema.brand<typeof Schema.String, "@gloop/ModelId">;
|
|
183
|
+
system: Schema.optional<typeof Schema.String>;
|
|
184
|
+
maxTokens: Schema.optional<typeof Schema.Number>;
|
|
185
|
+
contextPruneInterval: Schema.optional<typeof Schema.Number>;
|
|
186
|
+
}>;
|
|
187
|
+
export type AgentConfig = Schema.Schema.Type<typeof AgentConfig>;
|
|
188
|
+
//# sourceMappingURL=Schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../src/Schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,eAAe,EACf,WAAW,EACX,WAAW,EACX,cAAc,EACd,kBAAkB,EAClB,iBAAiB,EACjB,yBAAyB,EAC1B,MAAM,aAAa,CAAA;AAMpB,eAAO,MAAM,SAAS,wDAAuD,CAAA;AAC7E,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM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,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,UAAU,CAAC,CAAA;AAE9D,eAAO,MAAM,mBAAmB;;;EAG9B,CAAA;AACF,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,mBAAmB,CAAC,CAAA;AAEhF,eAAO,MAAM,eAAe;;;EAG1B,CAAA;AACF,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,eAAe,CAAC,CAAA;AAExE,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAkBtB,CAAA;AACD,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,UAAU,CAAC,CAAA;AAE9D,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,UAAU,CAAC,MAAM,CAAC,IAAI,OAAO,CAC9D,UAAU,EACV;IAAE,IAAI,EAAE,CAAC,CAAA;CAAE,CACZ,CAAA;AAMD,eAAO,MAAM,WAAW;;;;;EAKtB,CAAA;AACF,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,WAAW,CAAC,CAAA"}
|
package/dist/Schema.js
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* gloop-effect/Schema — Data schemas for everything that crosses a boundary.
|
|
3
|
+
*
|
|
4
|
+
* This module is the single source of truth for:
|
|
5
|
+
* - Branded entity IDs (MessageId, ToolCallId, RequestId, ModelId)
|
|
6
|
+
* - Conversation value types (Message, AgentMessage)
|
|
7
|
+
* - Tool data types (ToolCall, ToolResult, ToolArgument)
|
|
8
|
+
* - The `AgentEvent` discriminated union emitted by the actor
|
|
9
|
+
* - The `AgentError` union (re-exported as a Schema so events can carry
|
|
10
|
+
* typed errors over the wire)
|
|
11
|
+
*
|
|
12
|
+
* Service interfaces (Agent, ConversationHandle, AIProviderImpl, …) stay as
|
|
13
|
+
* TypeScript interfaces — they carry methods and can't be Schemas.
|
|
14
|
+
*/
|
|
15
|
+
import { Schema } from "effect";
|
|
16
|
+
import { AIProviderError, AgentInterruptedError, FatalAgentError, FileIOError, MemoryError, ShellExecError, ToolExecutionError, ToolNotFoundError, ToolPermissionDeniedError, } from "./Errors.js";
|
|
17
|
+
// ============================================================================
|
|
18
|
+
// Branded IDs
|
|
19
|
+
// ============================================================================
|
|
20
|
+
export const MessageId = Schema.String.pipe(Schema.brand("@gloop/MessageId"));
|
|
21
|
+
export const ToolCallId = Schema.String.pipe(Schema.brand("@gloop/ToolCallId"));
|
|
22
|
+
export const RequestId = Schema.String.pipe(Schema.brand("@gloop/RequestId"));
|
|
23
|
+
export const ModelId = Schema.String.pipe(Schema.brand("@gloop/ModelId"));
|
|
24
|
+
// ============================================================================
|
|
25
|
+
// Message
|
|
26
|
+
// ============================================================================
|
|
27
|
+
export const MessageRole = Schema.Literal("system", "user", "assistant");
|
|
28
|
+
export const Message = Schema.Struct({
|
|
29
|
+
role: MessageRole,
|
|
30
|
+
content: Schema.String,
|
|
31
|
+
});
|
|
32
|
+
export const AgentMessageRole = Schema.Literal("user", "system");
|
|
33
|
+
/** Inbound message (id may be absent — the actor assigns one on enqueue). */
|
|
34
|
+
export const AgentMessage = Schema.Struct({
|
|
35
|
+
id: Schema.optional(MessageId),
|
|
36
|
+
role: AgentMessageRole,
|
|
37
|
+
content: Schema.String,
|
|
38
|
+
});
|
|
39
|
+
/** An enqueued message: id is always populated. */
|
|
40
|
+
export const EnqueuedAgentMessage = Schema.Struct({
|
|
41
|
+
id: MessageId,
|
|
42
|
+
role: AgentMessageRole,
|
|
43
|
+
content: Schema.String,
|
|
44
|
+
});
|
|
45
|
+
// ============================================================================
|
|
46
|
+
// Tool value types
|
|
47
|
+
// ============================================================================
|
|
48
|
+
export const ToolArgument = Schema.Struct({
|
|
49
|
+
name: Schema.String,
|
|
50
|
+
description: Schema.String,
|
|
51
|
+
});
|
|
52
|
+
export const ToolCall = Schema.Struct({
|
|
53
|
+
name: Schema.String,
|
|
54
|
+
args: Schema.Record({ key: Schema.String, value: Schema.String }),
|
|
55
|
+
});
|
|
56
|
+
export const ToolResult = Schema.Struct({
|
|
57
|
+
name: Schema.String,
|
|
58
|
+
output: Schema.String,
|
|
59
|
+
success: Schema.Boolean,
|
|
60
|
+
});
|
|
61
|
+
// ============================================================================
|
|
62
|
+
// SpawnResult
|
|
63
|
+
// ============================================================================
|
|
64
|
+
export const SpawnResult = Schema.Struct({
|
|
65
|
+
success: Schema.Boolean,
|
|
66
|
+
summary: Schema.String,
|
|
67
|
+
exitCode: Schema.Number,
|
|
68
|
+
stdout: Schema.String,
|
|
69
|
+
stderr: Schema.String,
|
|
70
|
+
});
|
|
71
|
+
// ============================================================================
|
|
72
|
+
// AgentError — re-exported as a Schema so events can carry typed errors
|
|
73
|
+
// ============================================================================
|
|
74
|
+
export const AgentErrorSchema = Schema.Union(AIProviderError, ToolNotFoundError, ToolExecutionError, ToolPermissionDeniedError, AgentInterruptedError, FatalAgentError, FileIOError, ShellExecError, MemoryError);
|
|
75
|
+
// ============================================================================
|
|
76
|
+
// Agent events — discriminated union with `_tag`
|
|
77
|
+
// ============================================================================
|
|
78
|
+
export const TurnStartEvent = Schema.TaggedStruct("TurnStart", {
|
|
79
|
+
message: EnqueuedAgentMessage,
|
|
80
|
+
});
|
|
81
|
+
export const TurnEndEvent = Schema.TaggedStruct("TurnEnd", {});
|
|
82
|
+
export const BusyEvent = Schema.TaggedStruct("Busy", {});
|
|
83
|
+
export const IdleEvent = Schema.TaggedStruct("Idle", {});
|
|
84
|
+
export const QueueChangedEvent = Schema.TaggedStruct("QueueChanged", {
|
|
85
|
+
pending: Schema.Number,
|
|
86
|
+
});
|
|
87
|
+
export const StreamChunkEvent = Schema.TaggedStruct("StreamChunk", {
|
|
88
|
+
text: Schema.String,
|
|
89
|
+
});
|
|
90
|
+
export const StreamDoneEvent = Schema.TaggedStruct("StreamDone", {});
|
|
91
|
+
export const ToolStartEvent = Schema.TaggedStruct("ToolStart", {
|
|
92
|
+
id: ToolCallId,
|
|
93
|
+
name: Schema.String,
|
|
94
|
+
preview: Schema.String,
|
|
95
|
+
});
|
|
96
|
+
export const ToolDoneEvent = Schema.TaggedStruct("ToolDone", {
|
|
97
|
+
id: ToolCallId,
|
|
98
|
+
name: Schema.String,
|
|
99
|
+
ok: Schema.Boolean,
|
|
100
|
+
output: Schema.String,
|
|
101
|
+
});
|
|
102
|
+
export const MemoryEvent = Schema.TaggedStruct("Memory", {
|
|
103
|
+
op: Schema.Literal("remember", "forget"),
|
|
104
|
+
content: Schema.String,
|
|
105
|
+
});
|
|
106
|
+
export const SystemRefreshedEvent = Schema.TaggedStruct("SystemRefreshed", {});
|
|
107
|
+
export const TaskCompleteEvent = Schema.TaggedStruct("TaskComplete", {
|
|
108
|
+
summary: Schema.String,
|
|
109
|
+
});
|
|
110
|
+
export const InterruptedEvent = Schema.TaggedStruct("Interrupted", {});
|
|
111
|
+
export const ErrorEvent = Schema.TaggedStruct("Error", {
|
|
112
|
+
error: AgentErrorSchema,
|
|
113
|
+
});
|
|
114
|
+
export const FatalEvent = Schema.TaggedStruct("Fatal", {
|
|
115
|
+
error: AgentErrorSchema,
|
|
116
|
+
});
|
|
117
|
+
export const ConfirmRequestEvent = Schema.TaggedStruct("ConfirmRequest", {
|
|
118
|
+
id: RequestId,
|
|
119
|
+
command: Schema.String,
|
|
120
|
+
});
|
|
121
|
+
export const AskRequestEvent = Schema.TaggedStruct("AskRequest", {
|
|
122
|
+
id: RequestId,
|
|
123
|
+
question: Schema.String,
|
|
124
|
+
});
|
|
125
|
+
export const AgentEvent = Schema.Union(TurnStartEvent, TurnEndEvent, BusyEvent, IdleEvent, QueueChangedEvent, StreamChunkEvent, StreamDoneEvent, ToolStartEvent, ToolDoneEvent, MemoryEvent, SystemRefreshedEvent, TaskCompleteEvent, InterruptedEvent, ErrorEvent, FatalEvent, ConfirmRequestEvent, AskRequestEvent);
|
|
126
|
+
// ============================================================================
|
|
127
|
+
// Agent config
|
|
128
|
+
// ============================================================================
|
|
129
|
+
export const AgentConfig = Schema.Struct({
|
|
130
|
+
model: ModelId,
|
|
131
|
+
system: Schema.optional(Schema.String),
|
|
132
|
+
maxTokens: Schema.optional(Schema.Number),
|
|
133
|
+
contextPruneInterval: Schema.optional(Schema.Number),
|
|
134
|
+
});
|
|
135
|
+
//# sourceMappingURL=Schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Schema.js","sourceRoot":"","sources":["../src/Schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,eAAe,EACf,WAAW,EACX,WAAW,EACX,cAAc,EACd,kBAAkB,EAClB,iBAAiB,EACjB,yBAAyB,GAC1B,MAAM,aAAa,CAAA;AAEpB,+EAA+E;AAC/E,cAAc;AACd,+EAA+E;AAE/E,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC,CAAA;AAG7E,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC,CAAA;AAG/E,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC,CAAA;AAG7E,MAAM,CAAC,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAA;AAGzE,+EAA+E;AAC/E,UAAU;AACV,+EAA+E;AAE/E,MAAM,CAAC,MAAM,WAAW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M,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE;IACrD,KAAK,EAAE,gBAAgB;CACxB,CAAC,CAAA;AAGF,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAC,YAAY,CAAC,gBAAgB,EAAE;IACvE,EAAE,EAAE,SAAS;IACb,OAAO,EAAE,MAAM,CAAC,MAAM;CACvB,CAAC,CAAA;AAGF,MAAM,CAAC,MAAM,eAAe,GAAG,MAAM,CAAC,YAAY,CAAC,YAAY,EAAE;IAC/D,EAAE,EAAE,SAAS;IACb,QAAQ,EAAE,MAAM,CAAC,MAAM;CACxB,CAAC,CAAA;AAGF,MAAM,CAAC,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,CACpC,cAAc,EACd,YAAY,EACZ,SAAS,EACT,SAAS,EACT,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,cAAc,EACd,aAAa,EACb,WAAW,EACX,oBAAoB,EACpB,iBAAiB,EACjB,gBAAgB,EAChB,UAAU,EACV,UAAU,EACV,mBAAmB,EACnB,eAAe,CAChB,CAAA;AAQD,+EAA+E;AAC/E,eAAe;AACf,+EAA+E;AAE/E,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC;IACvC,KAAK,EAAE,OAAO;IACd,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC;IACtC,SAAS,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC;IACzC,oBAAoB,EAAE,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC;CACrD,CAAC,CAAA"}
|
package/dist/Tool.d.ts
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* gloop-effect/Tool — Tools and the runtime registry.
|
|
3
|
+
*
|
|
4
|
+
* A `Tool<E>` is an Effect-native description of a callable side-effect:
|
|
5
|
+
* its `execute` returns an `Effect` instead of a `Promise`, so hosts can
|
|
6
|
+
* plug in errors and interruption without wrapping. The error channel is
|
|
7
|
+
* constrained to `AgentError` so failures fit the interpreter's union.
|
|
8
|
+
*
|
|
9
|
+
* `ToolCall`, `ToolResult`, and `ToolArgument` are shared with `gloop-loop`
|
|
10
|
+
* as plain value types — the shapes match so the same builtins work on both
|
|
11
|
+
* sides of the fence.
|
|
12
|
+
*/
|
|
13
|
+
import { Effect, Option } from "effect";
|
|
14
|
+
import type { JsonTool, JsonToolCall, ToolArgument, ToolCall, ToolResult } from "@hypen-space/gloop-loop";
|
|
15
|
+
import type { AgentError } from "./Errors.js";
|
|
16
|
+
export type { ToolArgument, ToolCall, ToolResult };
|
|
17
|
+
/**
|
|
18
|
+
* Tool — a named effectful operation.
|
|
19
|
+
*
|
|
20
|
+
* - `execute` returns an Effect whose error channel is a subtype of
|
|
21
|
+
* `AgentError`. Failures fold into `ToolResult { success: false }` at
|
|
22
|
+
* the interpreter boundary — the model can retry.
|
|
23
|
+
* - `askPermission` returns `Some(reason)` to gate the call behind a
|
|
24
|
+
* confirmation prompt, or `None` to run immediately.
|
|
25
|
+
*
|
|
26
|
+
* `R = never` by default: tools with service dependencies should bake
|
|
27
|
+
* them in via `Effect.provide` before registering.
|
|
28
|
+
*/
|
|
29
|
+
export interface Tool<E extends AgentError = AgentError, R = never> {
|
|
30
|
+
readonly name: string;
|
|
31
|
+
readonly description: string;
|
|
32
|
+
readonly arguments: ReadonlyArray<ToolArgument>;
|
|
33
|
+
readonly askPermission?: (args: Record<string, string>) => Option.Option<string>;
|
|
34
|
+
readonly execute: (args: Record<string, string>) => Effect.Effect<string, E, R>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Max-permissive form used internally by the registry — tools of any
|
|
38
|
+
* error subtype can be stored together because the caller widens at the
|
|
39
|
+
* `register` boundary.
|
|
40
|
+
*/
|
|
41
|
+
export type AnyTool = Tool<AgentError, never>;
|
|
42
|
+
export declare const toJsonTool: (tool: AnyTool) => JsonTool;
|
|
43
|
+
/**
|
|
44
|
+
* Convert provider-reported JSON tool calls into the `ToolCall` shape used
|
|
45
|
+
* by the interpreter. Unknown tools collapse to an empty arg map so the
|
|
46
|
+
* interpreter can emit a clean ToolNotFoundError downstream.
|
|
47
|
+
*/
|
|
48
|
+
export declare const jsonToolCallsToToolCalls: (calls: ReadonlyArray<JsonToolCall>, lookup: (name: string) => Option.Option<AnyTool>) => ReadonlyArray<ToolCall>;
|
|
49
|
+
/** Returns the reason to confirm, or None if the call can run as-is. */
|
|
50
|
+
export declare const legacyBashConfirm: (call: ToolCall) => Option.Option<string>;
|
|
51
|
+
export interface ToolRegistry {
|
|
52
|
+
readonly register: <E extends AgentError>(tool: Tool<E>) => Effect.Effect<void>;
|
|
53
|
+
readonly unregister: (name: string) => Effect.Effect<void>;
|
|
54
|
+
readonly get: (name: string) => Effect.Effect<Option.Option<AnyTool>>;
|
|
55
|
+
readonly has: (name: string) => Effect.Effect<boolean>;
|
|
56
|
+
readonly all: Effect.Effect<ReadonlyArray<AnyTool>>;
|
|
57
|
+
readonly names: Effect.Effect<ReadonlyArray<string>>;
|
|
58
|
+
readonly clear: Effect.Effect<void>;
|
|
59
|
+
readonly replace: (tools: ReadonlyArray<AnyTool>) => Effect.Effect<void>;
|
|
60
|
+
readonly toJsonTools: Effect.Effect<ReadonlyArray<JsonTool>>;
|
|
61
|
+
/** Snapshot the current lookup function for sync consumers (e.g. parsers). */
|
|
62
|
+
readonly snapshotLookup: Effect.Effect<(name: string) => Option.Option<AnyTool>>;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Build a per-agent tool registry backed by a `Ref<Map>`. Each `Agent.make`
|
|
66
|
+
* owns its own registry so tool mutations (`addTool` / `removeTool`) on one
|
|
67
|
+
* agent don't leak into another.
|
|
68
|
+
*/
|
|
69
|
+
export declare const makeToolRegistry: (initial?: ReadonlyArray<AnyTool>) => Effect.Effect<ToolRegistry>;
|
|
70
|
+
//# sourceMappingURL=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AE,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAA;CACjF;AAED;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAC3B,UAAS,aAAa,CAAC,OAAO,CAAM,KACnC,MAAM,CAAC,MAAM,CAAC,YAAY,CA4DzB,CAAA"}
|
package/dist/Tool.js
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* gloop-effect/Tool — Tools and the runtime registry.
|
|
3
|
+
*
|
|
4
|
+
* A `Tool<E>` is an Effect-native description of a callable side-effect:
|
|
5
|
+
* its `execute` returns an `Effect` instead of a `Promise`, so hosts can
|
|
6
|
+
* plug in errors and interruption without wrapping. The error channel is
|
|
7
|
+
* constrained to `AgentError` so failures fit the interpreter's union.
|
|
8
|
+
*
|
|
9
|
+
* `ToolCall`, `ToolResult`, and `ToolArgument` are shared with `gloop-loop`
|
|
10
|
+
* as plain value types — the shapes match so the same builtins work on both
|
|
11
|
+
* sides of the fence.
|
|
12
|
+
*/
|
|
13
|
+
import { Effect, Either, Option, Ref } from "effect";
|
|
14
|
+
// ============================================================================
|
|
15
|
+
// JSON bridge
|
|
16
|
+
// ============================================================================
|
|
17
|
+
export const toJsonTool = (tool) => ({
|
|
18
|
+
type: "function",
|
|
19
|
+
function: {
|
|
20
|
+
name: tool.name,
|
|
21
|
+
description: tool.description,
|
|
22
|
+
parameters: {
|
|
23
|
+
type: "object",
|
|
24
|
+
properties: Object.fromEntries(tool.arguments.map((a) => [a.name, { type: "string", description: a.description }])),
|
|
25
|
+
required: tool.arguments.map((a) => a.name),
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
/**
|
|
30
|
+
* Safely parse a JSON string into a plain record. Malformed input yields
|
|
31
|
+
* `None` — callers fall back to empty args.
|
|
32
|
+
*/
|
|
33
|
+
const parseJsonObject = (raw) => {
|
|
34
|
+
const result = Either.try({
|
|
35
|
+
try: () => JSON.parse(raw),
|
|
36
|
+
catch: () => "invalid json",
|
|
37
|
+
});
|
|
38
|
+
if (Either.isLeft(result))
|
|
39
|
+
return Option.none();
|
|
40
|
+
const value = result.right;
|
|
41
|
+
if (typeof value !== "object" || value === null)
|
|
42
|
+
return Option.none();
|
|
43
|
+
return Option.some(value);
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Convert provider-reported JSON tool calls into the `ToolCall` shape used
|
|
47
|
+
* by the interpreter. Unknown tools collapse to an empty arg map so the
|
|
48
|
+
* interpreter can emit a clean ToolNotFoundError downstream.
|
|
49
|
+
*/
|
|
50
|
+
export const jsonToolCallsToToolCalls = (calls, lookup) => calls.map((call) => {
|
|
51
|
+
const tool = lookup(call.function.name);
|
|
52
|
+
const parsed = Option.getOrElse(parseJsonObject(call.function.arguments), () => ({}));
|
|
53
|
+
const args = {};
|
|
54
|
+
if (Option.isSome(tool)) {
|
|
55
|
+
for (const arg of tool.value.arguments) {
|
|
56
|
+
const v = parsed[arg.name];
|
|
57
|
+
if (v !== undefined)
|
|
58
|
+
args[arg.name] = String(v);
|
|
59
|
+
}
|
|
60
|
+
if (tool.value.arguments.length === 0 && Object.keys(parsed).length > 0) {
|
|
61
|
+
// Single-arg fallback: first parsed value.
|
|
62
|
+
const first = Object.values(parsed)[0];
|
|
63
|
+
if (first !== undefined)
|
|
64
|
+
args[tool.value.arguments[0]?.name ?? "arg"] = String(first);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return { name: call.function.name, args };
|
|
68
|
+
});
|
|
69
|
+
// ============================================================================
|
|
70
|
+
// Confirmation heuristics — shared with gloop-loop's Bash rm guard
|
|
71
|
+
// ============================================================================
|
|
72
|
+
const DANGEROUS_BASH_PATTERNS = [
|
|
73
|
+
/\brm\s+-rf?\b/,
|
|
74
|
+
/\brm\s+-fr?\b/,
|
|
75
|
+
/\brmdir\s/,
|
|
76
|
+
/>\s*\/dev\/sd[a-z]/,
|
|
77
|
+
/\bmkfs\b/,
|
|
78
|
+
/\bdd\s+.*of=/,
|
|
79
|
+
];
|
|
80
|
+
/** Returns the reason to confirm, or None if the call can run as-is. */
|
|
81
|
+
export const legacyBashConfirm = (call) => {
|
|
82
|
+
if (call.name !== "Bash")
|
|
83
|
+
return Option.none();
|
|
84
|
+
const cmd = call.args.command ?? "";
|
|
85
|
+
for (const pat of DANGEROUS_BASH_PATTERNS) {
|
|
86
|
+
if (pat.test(cmd))
|
|
87
|
+
return Option.some(`Run potentially destructive command: ${cmd}`);
|
|
88
|
+
}
|
|
89
|
+
return Option.none();
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Build a per-agent tool registry backed by a `Ref<Map>`. Each `Agent.make`
|
|
93
|
+
* owns its own registry so tool mutations (`addTool` / `removeTool`) on one
|
|
94
|
+
* agent don't leak into another.
|
|
95
|
+
*/
|
|
96
|
+
export const makeToolRegistry = (initial = []) => Effect.gen(function* () {
|
|
97
|
+
const ref = yield* Ref.make(new Map(initial.map((t) => [t.name, t])));
|
|
98
|
+
const register = Effect.fn("ToolRegistry.register")(function* (tool) {
|
|
99
|
+
yield* Effect.annotateCurrentSpan("toolName", tool.name);
|
|
100
|
+
yield* Ref.update(ref, (m) => {
|
|
101
|
+
const next = new Map(m);
|
|
102
|
+
// Widen at the storage boundary: every E extends AgentError.
|
|
103
|
+
next.set(tool.name, tool);
|
|
104
|
+
return next;
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
const unregister = Effect.fn("ToolRegistry.unregister")(function* (name) {
|
|
108
|
+
yield* Effect.annotateCurrentSpan("toolName", name);
|
|
109
|
+
yield* Ref.update(ref, (m) => {
|
|
110
|
+
if (!m.has(name))
|
|
111
|
+
return m;
|
|
112
|
+
const next = new Map(m);
|
|
113
|
+
next.delete(name);
|
|
114
|
+
return next;
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
const get = (name) => Ref.get(ref).pipe(Effect.map((m) => Option.fromNullable(m.get(name))));
|
|
118
|
+
const has = (name) => Ref.get(ref).pipe(Effect.map((m) => m.has(name)));
|
|
119
|
+
const all = Ref.get(ref).pipe(Effect.map((m) => Array.from(m.values())));
|
|
120
|
+
const names = Ref.get(ref).pipe(Effect.map((m) => Array.from(m.keys())));
|
|
121
|
+
const clear = Ref.set(ref, new Map());
|
|
122
|
+
const replace = (tools) => Ref.set(ref, new Map(tools.map((t) => [t.name, t])));
|
|
123
|
+
const toJsonTools = Ref.get(ref).pipe(Effect.map((m) => Array.from(m.values()).map(toJsonTool)));
|
|
124
|
+
const snapshotLookup = Ref.get(ref).pipe(Effect.map((m) => (name) => Option.fromNullable(m.get(name))));
|
|
125
|
+
return {
|
|
126
|
+
register,
|
|
127
|
+
unregister,
|
|
128
|
+
get,
|
|
129
|
+
has,
|
|
130
|
+
all,
|
|
131
|
+
names,
|
|
132
|
+
clear,
|
|
133
|
+
replace,
|
|
134
|
+
toJsonTools,
|
|
135
|
+
snapshotLookup,
|
|
136
|
+
};
|
|
137
|
+
});
|
|
138
|
+
//# 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;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAA;AA2CpD,+EAA+E;AAC/E,cAAc;AACd,+EAA+E;AAE/E,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,IAAa,EAAY,EAAE,CAAC,CAAC;IACtD,IAAI,EAAE,UAAU;IAChB,QAAQ,EAAE;QACR,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,UAAU,EAAE;YACV,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE,MAAM,CAAC,WAAW,CAC5B,IAAI,CAAC,SA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AK,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAA;IACxE,MAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,GAAG,EAAE,CAAC,CAAA;IAErC,MAAM,OAAO,GAAG,CAAC,KAA6B,EAAE,EAAE,CAChD,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAU,CAAC,CAAC,CAAC,CAAA;IAE/D,MAAM,WAAW,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,CACnC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAC1D,CAAA;IAED,MAAM,cAAc,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,CACtC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAY,EAAE,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CACtE,CAAA;IAED,OAAO;QACL,QAAQ;QACR,UAAU;QACV,GAAG;QACH,GAAG;QACH,GAAG;QACH,KAAK;QACL,KAAK;QACL,OAAO;QACP,WAAW;QACX,cAAc;KACf,CAAA;AACH,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Effect-native adapters for gloop-loop's builtin tools.
|
|
3
|
+
*
|
|
4
|
+
* `toEffectTool` wraps any Promise-returning `ToolDefinition` into the
|
|
5
|
+
* Effect-native `Tool` shape. `primitiveTools` applies the adapter to the
|
|
6
|
+
* full portable builtin set (ReadFile, WriteFile, Patch_file, Bash,
|
|
7
|
+
* CompleteTask, AskUser, Remember, Forget, ManageContext).
|
|
8
|
+
*
|
|
9
|
+
* `createNodeIO` is re-exported unchanged — it's a plain object with the
|
|
10
|
+
* Promise API surface and works unmodified for adapted tools.
|
|
11
|
+
*/
|
|
12
|
+
import { createNodeIO, type BuiltinIO, type ToolDefinition } from "@hypen-space/gloop-loop";
|
|
13
|
+
import type { Tool } from "../Tool.js";
|
|
14
|
+
import { ToolExecutionError } from "../Errors.js";
|
|
15
|
+
export { createNodeIO, type BuiltinIO };
|
|
16
|
+
export declare const toEffectTool: (def: ToolDefinition) => Tool<ToolExecutionError>;
|
|
17
|
+
/**
|
|
18
|
+
* Full set of portable built-ins, adapted to Effect tools. Pass a custom
|
|
19
|
+
* `BuiltinIO` to override file/shell semantics (e.g. browser or sandboxed
|
|
20
|
+
* environments).
|
|
21
|
+
*/
|
|
22
|
+
export declare const primitiveTools: (io?: BuiltinIO) => ReadonlyArray<Tool<ToolExecutionError>>;
|
|
23
|
+
//# sourceMappingURL=Builtins.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Builtins.d.ts","sourceRoot":"","sources":["../../src/defaults/Builtins.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EACL,YAAY,EAEZ,KAAK,SAAS,EACd,KAAK,cAAc,EACpB,MAAM,yBAAyB,CAAA;AAChC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AACtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAEjD,OAAO,EAAE,YAAY,EAAE,KAAK,SAAS,EAAE,CAAA;AAEvC,eAAO,MAAM,YAAY,GACvB,KAAK,cAAc,KAClB,IAAI,CAAC,kBAAkB,CAiBxB,CAAA;AAEF;;;;GAIG;AACH,eAAO,MAAM,cAAc,GACzB,KAAK,SAAS,KACb,aAAa,CAAC,IAAI,CAAC,kBAAkB,CAAC,CACC,CAAA"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Effect-native adapters for gloop-loop's builtin tools.
|
|
3
|
+
*
|
|
4
|
+
* `toEffectTool` wraps any Promise-returning `ToolDefinition` into the
|
|
5
|
+
* Effect-native `Tool` shape. `primitiveTools` applies the adapter to the
|
|
6
|
+
* full portable builtin set (ReadFile, WriteFile, Patch_file, Bash,
|
|
7
|
+
* CompleteTask, AskUser, Remember, Forget, ManageContext).
|
|
8
|
+
*
|
|
9
|
+
* `createNodeIO` is re-exported unchanged — it's a plain object with the
|
|
10
|
+
* Promise API surface and works unmodified for adapted tools.
|
|
11
|
+
*/
|
|
12
|
+
import { Effect, Option } from "effect";
|
|
13
|
+
import { createNodeIO, primitiveTools as loopPrimitiveTools, } from "@hypen-space/gloop-loop";
|
|
14
|
+
import { ToolExecutionError } from "../Errors.js";
|
|
15
|
+
export { createNodeIO };
|
|
16
|
+
export const toEffectTool = (def) => ({
|
|
17
|
+
name: def.name,
|
|
18
|
+
description: def.description,
|
|
19
|
+
arguments: def.arguments,
|
|
20
|
+
askPermission: def.askPermission
|
|
21
|
+
? (args) => Option.fromNullable(def.askPermission(args))
|
|
22
|
+
: undefined,
|
|
23
|
+
execute: (args) => Effect.tryPromise({
|
|
24
|
+
try: () => def.execute(args),
|
|
25
|
+
catch: (e) => new ToolExecutionError({
|
|
26
|
+
name: def.name,
|
|
27
|
+
message: e instanceof Error ? e.message : String(e),
|
|
28
|
+
cause: e,
|
|
29
|
+
}),
|
|
30
|
+
}),
|
|
31
|
+
});
|
|
32
|
+
/**
|
|
33
|
+
* Full set of portable built-ins, adapted to Effect tools. Pass a custom
|
|
34
|
+
* `BuiltinIO` to override file/shell semantics (e.g. browser or sandboxed
|
|
35
|
+
* environments).
|
|
36
|
+
*/
|
|
37
|
+
export const primitiveTools = (io) => loopPrimitiveTools(io).map(toEffectTool);
|
|
38
|
+
//# sourceMappingURL=Builtins.js.map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