@lowire/loop 0.0.1 → 0.0.2
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/LICENSE +201 -0
- package/README.md +1 -0
- package/githubAuth.js +17 -0
- package/index.d.ts +18 -0
- package/index.js +17 -0
- package/index.mjs +17 -0
- package/lib/auth/githubAuth.d.ts +16 -0
- package/lib/auth/githubAuth.js +81 -0
- package/lib/cache.d.ts +18 -0
- package/lib/cache.js +58 -0
- package/lib/loop.d.ts +47 -0
- package/lib/loop.js +150 -0
- package/lib/providers/anthropic.d.ts +23 -0
- package/lib/providers/anthropic.js +179 -0
- package/lib/providers/github.d.ts +33 -0
- package/lib/providers/github.js +68 -0
- package/lib/providers/google.d.ts +23 -0
- package/lib/providers/google.js +186 -0
- package/lib/providers/openai.d.ts +23 -0
- package/lib/providers/openai.js +172 -0
- package/lib/providers/openaiCompletions.d.ts +33 -0
- package/lib/providers/openaiCompletions.js +174 -0
- package/lib/providers/registry.d.ts +17 -0
- package/lib/providers/registry.js +33 -0
- package/lib/types.d.ts +108 -0
- package/lib/types.js +17 -0
- package/package.json +54 -7
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Microsoft Corporation.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.OpenAI = void 0;
|
|
19
|
+
class OpenAI {
|
|
20
|
+
name = 'openai';
|
|
21
|
+
async complete(conversation, options) {
|
|
22
|
+
const inputItems = conversation.messages.map(toResponseInputItems).flat();
|
|
23
|
+
const tools = conversation.tools.map(toOpenAIFunctionTool);
|
|
24
|
+
const response = await create({
|
|
25
|
+
model: options.model,
|
|
26
|
+
temperature: options.temperature,
|
|
27
|
+
input: inputItems,
|
|
28
|
+
instructions: systemPrompt(conversation.systemPrompt),
|
|
29
|
+
tools: tools.length > 0 ? tools : undefined,
|
|
30
|
+
tool_choice: conversation.tools.length > 0 ? 'auto' : undefined,
|
|
31
|
+
parallel_tool_calls: false,
|
|
32
|
+
});
|
|
33
|
+
// Parse response output items
|
|
34
|
+
const result = { role: 'assistant', content: [] };
|
|
35
|
+
for (const item of response.output) {
|
|
36
|
+
if (item.type === 'message' && item.role === 'assistant') {
|
|
37
|
+
result.openaiId = item.id;
|
|
38
|
+
result.openaiStatus = item.status;
|
|
39
|
+
for (const contentPart of item.content) {
|
|
40
|
+
if (contentPart.type === 'output_text') {
|
|
41
|
+
result.content.push({
|
|
42
|
+
type: 'text',
|
|
43
|
+
text: contentPart.text,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else if (item.type === 'function_call') {
|
|
49
|
+
// Add tool call
|
|
50
|
+
result.content.push(toToolCall(item));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const usage = {
|
|
54
|
+
input: response.usage?.input_tokens ?? 0,
|
|
55
|
+
output: response.usage?.output_tokens ?? 0,
|
|
56
|
+
};
|
|
57
|
+
return { result, usage };
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.OpenAI = OpenAI;
|
|
61
|
+
async function create(body) {
|
|
62
|
+
const apiKey = process.env.OPENAI_API_KEY;
|
|
63
|
+
const headers = {
|
|
64
|
+
'Content-Type': 'application/json',
|
|
65
|
+
'Authorization': `Bearer ${apiKey}`,
|
|
66
|
+
'Copilot-Vision-Request': 'true',
|
|
67
|
+
};
|
|
68
|
+
const response = await fetch(`https://api.openai.com/v1/responses`, {
|
|
69
|
+
method: 'POST',
|
|
70
|
+
headers,
|
|
71
|
+
body: JSON.stringify(body)
|
|
72
|
+
});
|
|
73
|
+
if (!response.ok)
|
|
74
|
+
throw new Error(`API error: ${response.status} ${response.statusText} ${await response.text()}`);
|
|
75
|
+
return await response.json();
|
|
76
|
+
}
|
|
77
|
+
function toResultContentPart(part) {
|
|
78
|
+
if (part.type === 'text') {
|
|
79
|
+
return {
|
|
80
|
+
type: 'input_text',
|
|
81
|
+
text: part.text,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
if (part.type === 'image') {
|
|
85
|
+
return {
|
|
86
|
+
type: 'input_image',
|
|
87
|
+
image_url: `data:${part.mimeType};base64,${part.data}`,
|
|
88
|
+
detail: 'auto',
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
throw new Error(`Cannot convert content part of type ${part.type} to response content part`);
|
|
92
|
+
}
|
|
93
|
+
function toResponseInputItems(message) {
|
|
94
|
+
if (message.role === 'user') {
|
|
95
|
+
return [{
|
|
96
|
+
type: 'message',
|
|
97
|
+
role: 'user',
|
|
98
|
+
content: message.content
|
|
99
|
+
}];
|
|
100
|
+
}
|
|
101
|
+
if (message.role === 'assistant') {
|
|
102
|
+
const textParts = message.content.filter(part => part.type === 'text');
|
|
103
|
+
const toolCallParts = message.content.filter(part => part.type === 'tool_call');
|
|
104
|
+
const items = [];
|
|
105
|
+
// Add assistant message with text content
|
|
106
|
+
if (textParts.length > 0) {
|
|
107
|
+
const outputMessage = {
|
|
108
|
+
id: message.openaiId,
|
|
109
|
+
status: message.openaiStatus,
|
|
110
|
+
type: 'message',
|
|
111
|
+
role: 'assistant',
|
|
112
|
+
content: textParts.map(part => ({
|
|
113
|
+
type: 'output_text',
|
|
114
|
+
text: part.text,
|
|
115
|
+
annotations: [],
|
|
116
|
+
logprobs: []
|
|
117
|
+
}))
|
|
118
|
+
};
|
|
119
|
+
items.push(outputMessage);
|
|
120
|
+
}
|
|
121
|
+
items.push(...toolCallParts.map(toFunctionToolCall));
|
|
122
|
+
return items;
|
|
123
|
+
}
|
|
124
|
+
if (message.role === 'tool_result') {
|
|
125
|
+
return [{
|
|
126
|
+
type: 'function_call_output',
|
|
127
|
+
call_id: message.toolCallId,
|
|
128
|
+
output: message.result.content.map(toResultContentPart),
|
|
129
|
+
}];
|
|
130
|
+
}
|
|
131
|
+
throw new Error(`Unsupported message role: ${message.role}`);
|
|
132
|
+
}
|
|
133
|
+
function toOpenAIFunctionTool(tool) {
|
|
134
|
+
return {
|
|
135
|
+
type: 'function',
|
|
136
|
+
name: tool.name,
|
|
137
|
+
description: tool.description ?? null,
|
|
138
|
+
parameters: tool.inputSchema,
|
|
139
|
+
strict: null,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
function toFunctionToolCall(toolCall) {
|
|
143
|
+
return {
|
|
144
|
+
type: 'function_call',
|
|
145
|
+
call_id: toolCall.id,
|
|
146
|
+
name: toolCall.name,
|
|
147
|
+
arguments: JSON.stringify(toolCall.arguments),
|
|
148
|
+
id: toolCall.openaiId,
|
|
149
|
+
status: toolCall.openaiStatus,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
function toToolCall(functionCall) {
|
|
153
|
+
return {
|
|
154
|
+
type: 'tool_call',
|
|
155
|
+
name: functionCall.name,
|
|
156
|
+
arguments: JSON.parse(functionCall.arguments),
|
|
157
|
+
id: functionCall.call_id,
|
|
158
|
+
openaiId: functionCall.id,
|
|
159
|
+
openaiStatus: functionCall.status,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
const systemPrompt = (prompt) => `
|
|
163
|
+
### System instructions
|
|
164
|
+
|
|
165
|
+
${prompt}
|
|
166
|
+
|
|
167
|
+
### Tool calling instructions
|
|
168
|
+
- Make sure every message contains a tool call.
|
|
169
|
+
- When you use a tool, you may provide a brief thought or explanation in the content field
|
|
170
|
+
immediately before the tool_call. Do not split this into separate messages.
|
|
171
|
+
- Every reply must include a tool call.
|
|
172
|
+
`;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import type * as types from '../types';
|
|
17
|
+
export type Endpoint = {
|
|
18
|
+
baseUrl: string;
|
|
19
|
+
apiKey: string;
|
|
20
|
+
headers: Record<string, string>;
|
|
21
|
+
};
|
|
22
|
+
export declare class OpenAICompletions implements types.Provider {
|
|
23
|
+
readonly name: string;
|
|
24
|
+
private _endpoint;
|
|
25
|
+
endpoint(): Promise<Endpoint>;
|
|
26
|
+
connect(): Promise<Endpoint>;
|
|
27
|
+
complete(conversation: types.Conversation, options: types.CompletionOptions & {
|
|
28
|
+
injectIntent?: boolean;
|
|
29
|
+
}): Promise<{
|
|
30
|
+
result: types.AssistantMessage;
|
|
31
|
+
usage: types.Usage;
|
|
32
|
+
}>;
|
|
33
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Microsoft Corporation.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.OpenAICompletions = void 0;
|
|
19
|
+
class OpenAICompletions {
|
|
20
|
+
name = 'openai';
|
|
21
|
+
_endpoint;
|
|
22
|
+
async endpoint() {
|
|
23
|
+
if (!this._endpoint)
|
|
24
|
+
this._endpoint = await this.connect();
|
|
25
|
+
return this._endpoint;
|
|
26
|
+
}
|
|
27
|
+
async connect() {
|
|
28
|
+
return {
|
|
29
|
+
baseUrl: 'https://api.openai.com/v1',
|
|
30
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
31
|
+
headers: {}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
async complete(conversation, options) {
|
|
35
|
+
// Convert generic messages to OpenAI format
|
|
36
|
+
const systemMessage = {
|
|
37
|
+
role: 'system',
|
|
38
|
+
content: systemPrompt(conversation.systemPrompt)
|
|
39
|
+
};
|
|
40
|
+
const openaiMessages = [systemMessage, ...conversation.messages.map(toOpenAIMessage)];
|
|
41
|
+
const openaiTools = conversation.tools.map(t => toOpenAITool(t, options));
|
|
42
|
+
const endpoint = await this.endpoint();
|
|
43
|
+
const response = await create({
|
|
44
|
+
model: options.model,
|
|
45
|
+
max_tokens: options.maxTokens,
|
|
46
|
+
temperature: options.temperature,
|
|
47
|
+
messages: openaiMessages,
|
|
48
|
+
tools: openaiTools,
|
|
49
|
+
tool_choice: conversation.tools.length > 0 ? 'auto' : undefined,
|
|
50
|
+
reasoning_effort: options.reasoning ? 'medium' : undefined,
|
|
51
|
+
}, endpoint);
|
|
52
|
+
const result = { role: 'assistant', content: [] };
|
|
53
|
+
const message = response.choices[0].message;
|
|
54
|
+
if (message.content)
|
|
55
|
+
result.content.push({ type: 'text', text: message.content });
|
|
56
|
+
result.content.push(...(message.tool_calls || []).map(toToolCall));
|
|
57
|
+
const usage = {
|
|
58
|
+
input: response.usage?.prompt_tokens ?? 0,
|
|
59
|
+
output: response.usage?.completion_tokens ?? 0,
|
|
60
|
+
};
|
|
61
|
+
return { result, usage };
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.OpenAICompletions = OpenAICompletions;
|
|
65
|
+
async function create(body, endpoint) {
|
|
66
|
+
const headers = {
|
|
67
|
+
'Content-Type': 'application/json',
|
|
68
|
+
'Authorization': `Bearer ${endpoint.apiKey}`,
|
|
69
|
+
'Copilot-Vision-Request': 'true',
|
|
70
|
+
...endpoint.headers
|
|
71
|
+
};
|
|
72
|
+
const response = await fetch(`${endpoint.baseUrl}/chat/completions`, {
|
|
73
|
+
method: 'POST',
|
|
74
|
+
headers,
|
|
75
|
+
body: JSON.stringify(body)
|
|
76
|
+
});
|
|
77
|
+
if (!response.ok)
|
|
78
|
+
throw new Error(`API error: ${response.status} ${response.statusText} ${await response.text()}`);
|
|
79
|
+
return await response.json();
|
|
80
|
+
}
|
|
81
|
+
function toOpenAIResultContentPart(part) {
|
|
82
|
+
if (part.type === 'text') {
|
|
83
|
+
return {
|
|
84
|
+
type: 'text',
|
|
85
|
+
text: part.text,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
if (part.type === 'image') {
|
|
89
|
+
return {
|
|
90
|
+
type: 'image_url',
|
|
91
|
+
image_url: {
|
|
92
|
+
url: `data:${part.mimeType};base64,${part.data}`,
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
throw new Error(`Cannot convert content part of type ${part.type} to text content part`);
|
|
97
|
+
}
|
|
98
|
+
function toOpenAIMessage(message) {
|
|
99
|
+
if (message.role === 'user') {
|
|
100
|
+
return {
|
|
101
|
+
role: 'user',
|
|
102
|
+
content: message.content
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
if (message.role === 'assistant') {
|
|
106
|
+
const assistantMessage = {
|
|
107
|
+
role: 'assistant'
|
|
108
|
+
};
|
|
109
|
+
const textParts = message.content.filter(part => part.type === 'text');
|
|
110
|
+
const toolCallParts = message.content.filter(part => part.type === 'tool_call');
|
|
111
|
+
if (textParts.length === 1)
|
|
112
|
+
assistantMessage.content = textParts[0].text;
|
|
113
|
+
else
|
|
114
|
+
assistantMessage.content = textParts;
|
|
115
|
+
const toolCalls = [];
|
|
116
|
+
for (const toolCall of toolCallParts) {
|
|
117
|
+
toolCalls.push({
|
|
118
|
+
id: toolCall.id,
|
|
119
|
+
type: 'function',
|
|
120
|
+
function: {
|
|
121
|
+
name: toolCall.name,
|
|
122
|
+
arguments: JSON.stringify(toolCall.arguments)
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
if (toolCalls.length > 0)
|
|
127
|
+
assistantMessage.tool_calls = toolCalls;
|
|
128
|
+
return assistantMessage;
|
|
129
|
+
}
|
|
130
|
+
if (message.role === 'tool_result') {
|
|
131
|
+
return {
|
|
132
|
+
role: 'tool',
|
|
133
|
+
tool_call_id: message.toolCallId,
|
|
134
|
+
content: message.result.content.map(toOpenAIResultContentPart),
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
throw new Error(`Unsupported message role: ${message.role}`);
|
|
138
|
+
}
|
|
139
|
+
function toOpenAITool(tool, options) {
|
|
140
|
+
const parameters = { ...tool.inputSchema };
|
|
141
|
+
if (options.injectIntent) {
|
|
142
|
+
parameters.properties = {
|
|
143
|
+
_intent: { type: 'string', description: 'Describe the intent of this tool call' },
|
|
144
|
+
...parameters.properties || {},
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
type: 'function',
|
|
149
|
+
function: {
|
|
150
|
+
name: tool.name,
|
|
151
|
+
description: tool.description,
|
|
152
|
+
parameters,
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
function toToolCall(toolCall) {
|
|
157
|
+
return {
|
|
158
|
+
type: 'tool_call',
|
|
159
|
+
name: toolCall.type === 'function' ? toolCall.function.name : toolCall.custom.name,
|
|
160
|
+
arguments: JSON.parse(toolCall.type === 'function' ? toolCall.function.arguments : toolCall.custom.input),
|
|
161
|
+
id: toolCall.id,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
const systemPrompt = (prompt) => `
|
|
165
|
+
### System instructions
|
|
166
|
+
|
|
167
|
+
${prompt}
|
|
168
|
+
|
|
169
|
+
### Tool calling instructions
|
|
170
|
+
- Your reply MUST be a tool call and nothing but the tool call.
|
|
171
|
+
- NEVER respond with text content, only tool calls.
|
|
172
|
+
- Do NOT describe your plan, do NOT explain what you are doing, do NOT describe what you see, call tools.
|
|
173
|
+
- Provide thoughts in the '_intent' property of the tool calls instead.
|
|
174
|
+
`;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
import * as types from '../types';
|
|
17
|
+
export declare function getProvider(loopName: 'openai' | 'github' | 'anthropic' | 'google'): types.Provider;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Microsoft Corporation.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.getProvider = getProvider;
|
|
19
|
+
const openai_1 = require("./openai");
|
|
20
|
+
const github_1 = require("./github");
|
|
21
|
+
const anthropic_1 = require("./anthropic");
|
|
22
|
+
const google_1 = require("./google");
|
|
23
|
+
function getProvider(loopName) {
|
|
24
|
+
if (loopName === 'openai')
|
|
25
|
+
return new openai_1.OpenAI();
|
|
26
|
+
if (loopName === 'github')
|
|
27
|
+
return new github_1.Github();
|
|
28
|
+
if (loopName === 'anthropic')
|
|
29
|
+
return new anthropic_1.Anthropic();
|
|
30
|
+
if (loopName === 'google')
|
|
31
|
+
return new google_1.Google();
|
|
32
|
+
throw new Error(`Unknown loop LLM: ${loopName}`);
|
|
33
|
+
}
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Microsoft Corporation.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
export type Schema = {
|
|
17
|
+
type: 'object';
|
|
18
|
+
properties?: unknown | null;
|
|
19
|
+
required?: Array<string> | null;
|
|
20
|
+
};
|
|
21
|
+
export type Tool = {
|
|
22
|
+
name: string;
|
|
23
|
+
description?: string;
|
|
24
|
+
inputSchema: Schema;
|
|
25
|
+
};
|
|
26
|
+
export type ToolCallPart = {
|
|
27
|
+
type: 'tool_call';
|
|
28
|
+
name: string;
|
|
29
|
+
arguments: any;
|
|
30
|
+
id: string;
|
|
31
|
+
googleThoughtSignature?: string;
|
|
32
|
+
openaiId?: string;
|
|
33
|
+
openaiStatus?: 'completed' | 'incomplete' | 'in_progress';
|
|
34
|
+
};
|
|
35
|
+
export type ToolCallback = (params: {
|
|
36
|
+
name: string;
|
|
37
|
+
arguments: any;
|
|
38
|
+
}) => Promise<ToolResult>;
|
|
39
|
+
export type Usage = {
|
|
40
|
+
input: number;
|
|
41
|
+
output: number;
|
|
42
|
+
};
|
|
43
|
+
export type BaseMessage = {
|
|
44
|
+
role: 'user' | 'assistant' | 'tool_result';
|
|
45
|
+
};
|
|
46
|
+
export type UserMessage = BaseMessage & {
|
|
47
|
+
role: 'user';
|
|
48
|
+
content: string;
|
|
49
|
+
};
|
|
50
|
+
export type AssistantMessage = BaseMessage & {
|
|
51
|
+
role: 'assistant';
|
|
52
|
+
content: (TextContentPart | ToolCallPart | ThinkingContentPart)[];
|
|
53
|
+
openaiId?: string;
|
|
54
|
+
openaiStatus?: 'completed' | 'incomplete' | 'in_progress';
|
|
55
|
+
};
|
|
56
|
+
export type TextContentPart = {
|
|
57
|
+
type: 'text';
|
|
58
|
+
text: string;
|
|
59
|
+
googleThoughtSignature?: string;
|
|
60
|
+
};
|
|
61
|
+
export type ImageContentPart = {
|
|
62
|
+
type: 'image';
|
|
63
|
+
data: string;
|
|
64
|
+
mimeType: string;
|
|
65
|
+
};
|
|
66
|
+
export type ThinkingContentPart = {
|
|
67
|
+
type: 'thinking';
|
|
68
|
+
thinking: string;
|
|
69
|
+
signature: string;
|
|
70
|
+
};
|
|
71
|
+
export type ResultContentPart = TextContentPart | ImageContentPart;
|
|
72
|
+
export type ToolResult = {
|
|
73
|
+
content: ResultContentPart[];
|
|
74
|
+
isError?: boolean;
|
|
75
|
+
};
|
|
76
|
+
export type ToolResultMessage = BaseMessage & {
|
|
77
|
+
role: 'tool_result';
|
|
78
|
+
toolName: string;
|
|
79
|
+
toolCallId: string;
|
|
80
|
+
result: ToolResult;
|
|
81
|
+
};
|
|
82
|
+
export type Message = UserMessage | AssistantMessage | ToolResultMessage;
|
|
83
|
+
export type Conversation = {
|
|
84
|
+
systemPrompt: string;
|
|
85
|
+
messages: Message[];
|
|
86
|
+
tools: Tool[];
|
|
87
|
+
};
|
|
88
|
+
export type CompletionOptions = {
|
|
89
|
+
model: string;
|
|
90
|
+
maxTokens?: number;
|
|
91
|
+
reasoning?: boolean;
|
|
92
|
+
temperature?: number;
|
|
93
|
+
};
|
|
94
|
+
export interface Provider {
|
|
95
|
+
name: string;
|
|
96
|
+
complete(conversation: Conversation, options: CompletionOptions): Promise<{
|
|
97
|
+
result: AssistantMessage;
|
|
98
|
+
usage: Usage;
|
|
99
|
+
}>;
|
|
100
|
+
}
|
|
101
|
+
export type ReplayCache = Record<string, {
|
|
102
|
+
result: AssistantMessage;
|
|
103
|
+
usage: Usage;
|
|
104
|
+
}>;
|
|
105
|
+
export type ReplayCaches = {
|
|
106
|
+
before: ReplayCache;
|
|
107
|
+
after: ReplayCache;
|
|
108
|
+
};
|
package/lib/types.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Microsoft Corporation.
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/package.json
CHANGED
|
@@ -1,12 +1,59 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowire/loop",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "Small agentic loop",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/pavelfeldman/lowire.git"
|
|
8
|
+
},
|
|
9
|
+
"homepage": "https://github.com/pavelfeldman/lowire",
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=20"
|
|
12
|
+
},
|
|
13
|
+
"author": {
|
|
14
|
+
"name": "Microsoft Corporation"
|
|
15
|
+
},
|
|
16
|
+
"license": "Apache-2.0",
|
|
5
17
|
"scripts": {
|
|
6
|
-
"
|
|
18
|
+
"build": "tsc --project tsconfig.src.json",
|
|
19
|
+
"lint": "eslint . && tsc --project tsconfig.src.json --noEmit && tsc --project tsconfig.tests.json --noEmit",
|
|
20
|
+
"lint-fix": "eslint . --fix",
|
|
21
|
+
"watch": "tsc --project tsconfig.src.json --watch",
|
|
22
|
+
"clean": "rm -rf ./lib",
|
|
23
|
+
"test": "playwright test",
|
|
24
|
+
"ctest": "playwright test --project=copilot",
|
|
25
|
+
"deploy": "npm run clean && npm run build && npm publish"
|
|
26
|
+
},
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"import": "./index.mjs",
|
|
30
|
+
"require": "./index.js",
|
|
31
|
+
"types": "./index.d.ts"
|
|
32
|
+
}
|
|
7
33
|
},
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@anthropic-ai/sdk": "^0.70.0",
|
|
36
|
+
"@eslint/eslintrc": "^3.2.0",
|
|
37
|
+
"@eslint/js": "^9.19.0",
|
|
38
|
+
"@google/generative-ai": "^0.24.1",
|
|
39
|
+
"@modelcontextprotocol/sdk": "^1.17.5",
|
|
40
|
+
"@playwright/test": "^1.56.1",
|
|
41
|
+
"@stylistic/eslint-plugin": "^3.0.1",
|
|
42
|
+
"@types/colors": "^1.1.3",
|
|
43
|
+
"@types/debug": "^4.1.12",
|
|
44
|
+
"@types/dotenv": "^6.1.1",
|
|
45
|
+
"@types/glob": "^8.1.0",
|
|
46
|
+
"@types/node": "^22.13.10",
|
|
47
|
+
"@typescript-eslint/eslint-plugin": "^8.26.1",
|
|
48
|
+
"@typescript-eslint/parser": "^8.26.1",
|
|
49
|
+
"@typescript-eslint/utils": "^8.26.1",
|
|
50
|
+
"colors": "^1.4.0",
|
|
51
|
+
"debug": "^4.4.3",
|
|
52
|
+
"dotenv": "^17.2.3",
|
|
53
|
+
"eslint": "^9.19.0",
|
|
54
|
+
"eslint-plugin-import": "^2.31.0",
|
|
55
|
+
"eslint-plugin-notice": "^1.0.0",
|
|
56
|
+
"openai": "^6.9.1",
|
|
57
|
+
"typescript": "^5.8.2"
|
|
58
|
+
}
|
|
12
59
|
}
|