@appliqation/agent-core 0.1.6 → 0.1.7
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/providers/index.d.ts +1 -0
- package/dist/providers/index.d.ts.map +1 -1
- package/dist/providers/index.js +1 -0
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/openaiCompatible.d.ts +11 -0
- package/dist/providers/openaiCompatible.d.ts.map +1 -0
- package/dist/providers/openaiCompatible.js +98 -0
- package/dist/providers/openaiCompatible.js.map +1 -0
- package/package.json +1 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { createAnthropicAdapter, DEFAULT_ANTHROPIC_MODEL } from './anthropic.js';
|
|
2
2
|
export { createOpenAiAdapter, DEFAULT_OPENAI_MODEL } from './openai.js';
|
|
3
|
+
export { createOpenAiCompatibleAdapter, type OpenAiCompatibleConfig } from './openaiCompatible.js';
|
|
3
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AACjF,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AACjF,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,EAAE,6BAA6B,EAAE,KAAK,sBAAsB,EAAE,MAAM,uBAAuB,CAAC"}
|
package/dist/providers/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AACjF,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AACjF,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,EAAE,6BAA6B,EAA+B,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ProviderAdapter } from '../types.js';
|
|
2
|
+
export interface OpenAiCompatibleConfig {
|
|
3
|
+
apiKey: string;
|
|
4
|
+
baseURL: string;
|
|
5
|
+
model: string;
|
|
6
|
+
maxTokens?: number;
|
|
7
|
+
/** Only used in error messages, e.g. 'DeepSeek'/'GLM' — no behavioral effect. */
|
|
8
|
+
providerLabel?: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function createOpenAiCompatibleAdapter(config: OpenAiCompatibleConfig): ProviderAdapter;
|
|
11
|
+
//# sourceMappingURL=openaiCompatible.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openaiCompatible.d.ts","sourceRoot":"","sources":["../../src/providers/openaiCompatible.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAiC,eAAe,EAAE,MAAM,aAAa,CAAC;AAqDlF,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iFAAiF;IACjF,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,wBAAgB,6BAA6B,CAAC,MAAM,EAAE,sBAAsB,GAAG,eAAe,CAsD7F"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import OpenAI from 'openai';
|
|
2
|
+
// A generic adapter for any provider exposing an OpenAI Chat Completions-shaped
|
|
3
|
+
// API — DeepSeek and Zhipu's GLM both do, via the `openai` SDK pointed at a
|
|
4
|
+
// different baseURL. Deliberately NOT a wrapper around openai.ts: that file
|
|
5
|
+
// talks to OpenAI's newer Responses API (client.responses.create), which
|
|
6
|
+
// neither DeepSeek nor GLM implement — only the older Chat Completions
|
|
7
|
+
// surface (client.chat.completions.create), a materially different wire
|
|
8
|
+
// format (system role lives in the messages array, not a separate
|
|
9
|
+
// instructions field; tool defs are nested {type:'function', function:{...}}
|
|
10
|
+
// rather than flat; tool calls round-trip via `tool_calls`/`role:'tool'`
|
|
11
|
+
// messages keyed by tool_call_id).
|
|
12
|
+
function toChatCompletionMessages(system, messages) {
|
|
13
|
+
const out = [{ role: 'system', content: system }];
|
|
14
|
+
for (const m of messages) {
|
|
15
|
+
if (m.role === 'user') {
|
|
16
|
+
out.push({ role: 'user', content: m.content });
|
|
17
|
+
}
|
|
18
|
+
else if (m.role === 'assistant') {
|
|
19
|
+
const toolCalls = (m.toolCalls ?? []).map((call) => ({
|
|
20
|
+
id: call.id,
|
|
21
|
+
type: 'function',
|
|
22
|
+
function: { name: call.name, arguments: JSON.stringify(call.arguments) },
|
|
23
|
+
}));
|
|
24
|
+
out.push({
|
|
25
|
+
role: 'assistant',
|
|
26
|
+
content: m.content || null,
|
|
27
|
+
...(toolCalls.length ? { tool_calls: toolCalls } : {}),
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
else if (m.role === 'tool') {
|
|
31
|
+
out.push({ role: 'tool', tool_call_id: m.toolCallId ?? '', content: m.content });
|
|
32
|
+
// Chat Completions' tool-role messages are text-only, same limitation
|
|
33
|
+
// as the Responses API — see openai.ts's identical workaround. A bare
|
|
34
|
+
// image_url part isn't valid inside a tool message, so it goes in a
|
|
35
|
+
// synthetic follow-up user turn instead.
|
|
36
|
+
if (m.images?.length) {
|
|
37
|
+
out.push({
|
|
38
|
+
role: 'user',
|
|
39
|
+
content: m.images.map((img) => ({
|
|
40
|
+
type: 'image_url',
|
|
41
|
+
image_url: { url: `data:${img.mimeType};base64,${img.data}` },
|
|
42
|
+
})),
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
export function createOpenAiCompatibleAdapter(config) {
|
|
50
|
+
const { apiKey, baseURL, model, maxTokens = 4096, providerLabel = baseURL } = config;
|
|
51
|
+
const client = new OpenAI({ apiKey, baseURL });
|
|
52
|
+
return {
|
|
53
|
+
async complete({ system, messages, tools, signal }) {
|
|
54
|
+
let response;
|
|
55
|
+
try {
|
|
56
|
+
response = await client.chat.completions.create({
|
|
57
|
+
model,
|
|
58
|
+
max_tokens: maxTokens,
|
|
59
|
+
messages: toChatCompletionMessages(system, messages),
|
|
60
|
+
tools: tools.map((t) => ({
|
|
61
|
+
type: 'function',
|
|
62
|
+
function: { name: t.name, description: t.description, parameters: t.inputSchema },
|
|
63
|
+
})),
|
|
64
|
+
}, { signal });
|
|
65
|
+
}
|
|
66
|
+
catch (err) {
|
|
67
|
+
throw new Error(`${providerLabel} completion failed: ${err.message}`);
|
|
68
|
+
}
|
|
69
|
+
const message = response.choices[0]?.message;
|
|
70
|
+
const toolCalls = (message?.tool_calls ?? [])
|
|
71
|
+
.filter((tc) => tc.type === 'function')
|
|
72
|
+
.map((tc) => ({
|
|
73
|
+
id: tc.id,
|
|
74
|
+
name: tc.function.name,
|
|
75
|
+
arguments: JSON.parse(tc.function.arguments || '{}'),
|
|
76
|
+
}));
|
|
77
|
+
// prompt_cache_hit_tokens is a real DeepSeek response field, not part
|
|
78
|
+
// of the base OpenAI usage type — read it defensively via an index
|
|
79
|
+
// signature rather than widening the shared type for one provider's
|
|
80
|
+
// extension. Left undefined (never a fabricated 0) for providers that
|
|
81
|
+
// don't send it, matching cost.ts's own "undefined means unknown, not
|
|
82
|
+
// zero" convention.
|
|
83
|
+
const usageRaw = response.usage;
|
|
84
|
+
return {
|
|
85
|
+
text: message?.content ?? '',
|
|
86
|
+
toolCalls,
|
|
87
|
+
usage: usageRaw
|
|
88
|
+
? {
|
|
89
|
+
inputTokens: usageRaw.prompt_tokens,
|
|
90
|
+
outputTokens: usageRaw.completion_tokens,
|
|
91
|
+
cacheReadTokens: usageRaw.prompt_cache_hit_tokens,
|
|
92
|
+
}
|
|
93
|
+
: undefined,
|
|
94
|
+
};
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=openaiCompatible.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openaiCompatible.js","sourceRoot":"","sources":["../../src/providers/openaiCompatible.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAG5B,gFAAgF;AAChF,4EAA4E;AAC5E,4EAA4E;AAC5E,yEAAyE;AACzE,uEAAuE;AACvE,wEAAwE;AACxE,kEAAkE;AAClE,6EAA6E;AAC7E,yEAAyE;AACzE,mCAAmC;AAEnC,SAAS,wBAAwB,CAAC,MAAc,EAAE,QAAsB;IACtE,MAAM,GAAG,GAA6C,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;IAC5F,KAAK,MAAM,CAAC,IAAI,QAAQ,EAAE,CAAC;QACzB,IAAI,CAAC,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YACtB,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;QACjD,CAAC;aAAM,IAAI,CAAC,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;YAClC,MAAM,SAAS,GAAG,CAAC,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,GAAG,CAC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AAE,EAAE,EAAE,CAAC,CAAC;gBACZ,EAAE,EAAE,EAAE,CAAC,EAAE;gBACT,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI;gBACtB,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,QAAQ,CAAC,SAAS,IAAI,IAAI,CAAC;aACrD,CAAC,CAAC,CAAC;YAEN,sEAAsE;YACtE,mEAAmE;YACnE,oEAAoE;YACpE,sEAAsE;YACtE,sEAAsE;YACtE,oBAAoB;YACpB,MAAM,QAAQ,GAAG,QAAQ,CAAC,KAAoF,CAAC;YAE/G,OAAO;gBACL,IAAI,EAAE,OAAO,EAAE,OAAO,IAAI,EAAE;gBAC5B,SAAS;gBACT,KAAK,EAAE,QAAQ;oBACb,CAAC,CAAC;wBACE,WAAW,EAAE,QAAQ,CAAC,aAAa;wBACnC,YAAY,EAAE,QAAQ,CAAC,iBAAiB;wBACxC,eAAe,EAAE,QAAQ,CAAC,uBAAuB;qBAClD;oBACH,CAAC,CAAC,SAAS;aACd,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appliqation/agent-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "Shared engine (think->act->observe loop, budget tracking, appq MCP client, gated tool dispatch, Playwright browser tools, evidence capture) for Appliqation's family of standalone agents.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|