@lowire/loop 0.0.1 → 0.0.3
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 +19 -0
- package/index.js +18 -0
- package/index.mjs +18 -0
- package/lib/auth/githubAuth.d.ts +16 -0
- package/lib/auth/githubAuth.js +81 -0
- package/lib/cache.d.ts +23 -0
- package/lib/cache.js +57 -0
- package/lib/jsx/jsx-runtime.d.ts +17 -0
- package/lib/jsx/jsx-runtime.js +33 -0
- package/lib/loop.d.ts +38 -0
- package/lib/loop.js +138 -0
- package/lib/mcp/index.d.ts +34 -0
- package/lib/mcp/index.js +109 -0
- package/lib/providers/anthropic.d.ts +23 -0
- package/lib/providers/anthropic.js +195 -0
- package/lib/providers/github.d.ts +33 -0
- package/lib/providers/github.js +229 -0
- package/lib/providers/google.d.ts +23 -0
- package/lib/providers/google.js +204 -0
- package/lib/providers/openai.d.ts +23 -0
- package/lib/providers/openai.js +186 -0
- package/lib/providers/registry.d.ts +17 -0
- package/lib/providers/registry.js +33 -0
- package/lib/summary.d.ts +20 -0
- package/lib/summary.js +56 -0
- package/lib/types.d.ts +114 -0
- package/lib/types.js +17 -0
- package/package.json +21 -7
|
@@ -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/summary.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
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 declare function summarizeConversation(task: string, conversation: types.Conversation, options: Pick<types.CompletionOptions, 'debug'>): {
|
|
18
|
+
summary: string;
|
|
19
|
+
lastMessage: types.AssistantMessage;
|
|
20
|
+
};
|
package/lib/summary.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.summarizeConversation = summarizeConversation;
|
|
4
|
+
const jsx_runtime_1 = require("./jsx/jsx-runtime");
|
|
5
|
+
/**
|
|
6
|
+
* Copyright (c) Microsoft Corporation.
|
|
7
|
+
*
|
|
8
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
|
+
* you may not use this file except in compliance with the License.
|
|
10
|
+
* You may obtain a copy of the License at
|
|
11
|
+
*
|
|
12
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
+
*
|
|
14
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
15
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17
|
+
* See the License for the specific language governing permissions and
|
|
18
|
+
* limitations under the License.
|
|
19
|
+
*/
|
|
20
|
+
const jsx_runtime_2 = require("./jsx/jsx-runtime");
|
|
21
|
+
function summarizeConversation(task, conversation, options) {
|
|
22
|
+
const summary = ['## Task', task];
|
|
23
|
+
const combinedState = {};
|
|
24
|
+
const assistantMessages = conversation.messages.filter(message => message.role === 'assistant');
|
|
25
|
+
for (let turn = 0; turn < assistantMessages.length - 1; ++turn) {
|
|
26
|
+
if (turn === 0) {
|
|
27
|
+
summary.push('');
|
|
28
|
+
summary.push('## History');
|
|
29
|
+
}
|
|
30
|
+
summary.push(``);
|
|
31
|
+
const text = assistantMessages[turn].content.filter(part => part.type === 'text').map(part => part.text).join('\n');
|
|
32
|
+
const toolCalls = assistantMessages[turn].content.filter(part => part.type === 'tool_call');
|
|
33
|
+
for (const toolCall of toolCalls) {
|
|
34
|
+
if (toolCall.result) {
|
|
35
|
+
for (const [name, state] of Object.entries(toolCall.result._meta?.['dev.lowire/state'] || {}))
|
|
36
|
+
combinedState[name] = state;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const message = assistantMessages[turn];
|
|
40
|
+
summary.push((0, jsx_runtime_1.jsxs)("step", { turn: turn + 1, children: [(0, jsx_runtime_1.jsx)("title", { children: text }), toolCalls.map(toolCall => (0, jsx_runtime_1.jsxs)("tool-call", { children: [(0, jsx_runtime_1.jsx)("name", { children: toolCall.name }), Object.keys(toolCall.arguments).length > 0 && (0, jsx_runtime_1.jsx)("arguments", { children: Object.entries(toolCall.arguments).map(([key, value]) => (0, jsx_runtime_2.jsx)(key, { children: [JSON.stringify(value)] })) })] })), toolCalls.map(toolCall => toolCall.result?._meta?.['dev.lowire/history'] || []).flat().map(h => (0, jsx_runtime_2.jsx)(h.category, { children: [h.content] })), message.toolError && (0, jsx_runtime_1.jsx)("error", { children: message.toolError })] }));
|
|
41
|
+
}
|
|
42
|
+
const lastMessage = assistantMessages[assistantMessages.length - 1];
|
|
43
|
+
if (lastMessage) { // Remove state from combined state as it'll be a part of the last assistant message.
|
|
44
|
+
for (const part of lastMessage.content.filter(part => part.type === 'tool_call')) {
|
|
45
|
+
for (const name of Object.keys(part.result?._meta?.['dev.lowire/state'] || {}))
|
|
46
|
+
delete combinedState[name];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
for (const [name, state] of Object.entries(combinedState)) {
|
|
50
|
+
summary.push('');
|
|
51
|
+
summary.push((0, jsx_runtime_1.jsx)("state", { name: name, children: state }));
|
|
52
|
+
}
|
|
53
|
+
options.debug?.('lowire:summary')(summary.join('\n'));
|
|
54
|
+
options.debug?.('lowire:summary')(JSON.stringify(lastMessage, null, 2));
|
|
55
|
+
return { summary: summary.join('\n'), lastMessage };
|
|
56
|
+
}
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
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 ToolCallback = (params: {
|
|
27
|
+
name: string;
|
|
28
|
+
arguments: any;
|
|
29
|
+
}) => Promise<ToolResult>;
|
|
30
|
+
export type BaseMessage = {
|
|
31
|
+
role: 'user' | 'assistant';
|
|
32
|
+
};
|
|
33
|
+
export type Message = UserMessage | AssistantMessage;
|
|
34
|
+
export type UserMessage = BaseMessage & {
|
|
35
|
+
role: 'user';
|
|
36
|
+
content: string;
|
|
37
|
+
};
|
|
38
|
+
export type AssistantMessage = BaseMessage & {
|
|
39
|
+
role: 'assistant';
|
|
40
|
+
content: (TextContentPart | ToolCallContentPart | ThinkingContentPart)[];
|
|
41
|
+
openaiId?: string;
|
|
42
|
+
openaiStatus?: 'completed' | 'incomplete' | 'in_progress';
|
|
43
|
+
toolError?: string;
|
|
44
|
+
};
|
|
45
|
+
export type TextContentPart = {
|
|
46
|
+
type: 'text';
|
|
47
|
+
text: string;
|
|
48
|
+
googleThoughtSignature?: string;
|
|
49
|
+
copilotToolCallId?: string;
|
|
50
|
+
};
|
|
51
|
+
export type ThinkingContentPart = {
|
|
52
|
+
type: 'thinking';
|
|
53
|
+
thinking: string;
|
|
54
|
+
signature: string;
|
|
55
|
+
};
|
|
56
|
+
export type ToolCallContentPart = {
|
|
57
|
+
type: 'tool_call';
|
|
58
|
+
name: string;
|
|
59
|
+
arguments: any;
|
|
60
|
+
id: string;
|
|
61
|
+
googleThoughtSignature?: string;
|
|
62
|
+
openaiId?: string;
|
|
63
|
+
openaiStatus?: 'completed' | 'incomplete' | 'in_progress';
|
|
64
|
+
result?: ToolResult;
|
|
65
|
+
};
|
|
66
|
+
export type TextResultPart = {
|
|
67
|
+
type: 'text';
|
|
68
|
+
text: string;
|
|
69
|
+
};
|
|
70
|
+
export type ImageResultPart = {
|
|
71
|
+
type: 'image';
|
|
72
|
+
data: string;
|
|
73
|
+
mimeType: string;
|
|
74
|
+
};
|
|
75
|
+
export type ResultPart = TextResultPart | ImageResultPart;
|
|
76
|
+
export type ToolResult = {
|
|
77
|
+
_meta?: {
|
|
78
|
+
'dev.lowire/history'?: {
|
|
79
|
+
category: string;
|
|
80
|
+
content: string;
|
|
81
|
+
}[];
|
|
82
|
+
'dev.lowire/state'?: Record<string, string>;
|
|
83
|
+
};
|
|
84
|
+
content: ResultPart[];
|
|
85
|
+
isError?: boolean;
|
|
86
|
+
};
|
|
87
|
+
export type Conversation = {
|
|
88
|
+
systemPrompt: string;
|
|
89
|
+
messages: Message[];
|
|
90
|
+
tools: Tool[];
|
|
91
|
+
};
|
|
92
|
+
export type Debug = (category: string) => (...args: any[]) => void;
|
|
93
|
+
export type CompletionOptions = {
|
|
94
|
+
model: string;
|
|
95
|
+
maxTokens?: number;
|
|
96
|
+
reasoning?: boolean;
|
|
97
|
+
temperature?: number;
|
|
98
|
+
debug?: Debug;
|
|
99
|
+
};
|
|
100
|
+
export interface Provider {
|
|
101
|
+
name: string;
|
|
102
|
+
complete(conversation: Conversation, options: CompletionOptions): Promise<{
|
|
103
|
+
result: AssistantMessage;
|
|
104
|
+
usage: Usage;
|
|
105
|
+
}>;
|
|
106
|
+
}
|
|
107
|
+
export type Usage = {
|
|
108
|
+
input: number;
|
|
109
|
+
output: number;
|
|
110
|
+
};
|
|
111
|
+
export type ReplayCache = Record<string, {
|
|
112
|
+
result: AssistantMessage;
|
|
113
|
+
usage: Usage;
|
|
114
|
+
}>;
|
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,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowire/loop",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
3
|
+
"version": "0.0.3",
|
|
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
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
7
18
|
},
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"import": "./index.mjs",
|
|
22
|
+
"require": "./index.js",
|
|
23
|
+
"types": "./index.d.ts"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
12
26
|
}
|