@gajae-code/agent-core 0.1.2 → 0.2.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/CHANGELOG.md +18 -0
- package/dist/types/agent.d.ts +2 -0
- package/dist/types/compaction/compaction.d.ts +2 -0
- package/dist/types/compaction/openai.d.ts +3 -1
- package/dist/types/types.d.ts +2 -0
- package/package.json +6 -6
- package/src/agent-loop.ts +3 -0
- package/src/agent.ts +4 -0
- package/src/compaction/compaction.ts +3 -0
- package/src/compaction/openai.ts +14 -5
- package/src/types.ts +3 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [0.2.0] - 2026-05-28
|
|
6
|
+
|
|
7
|
+
### Changed
|
|
8
|
+
|
|
9
|
+
- Refreshed agent-core package metadata for the GJC 0.2.0 release.
|
|
10
|
+
|
|
11
|
+
## [0.1.3] - 2026-05-28
|
|
12
|
+
|
|
13
|
+
### Changed
|
|
14
|
+
|
|
15
|
+
- Released the current dev branch fixes with refreshed 0.1.3 package metadata.
|
|
16
|
+
|
|
17
|
+
## [0.1.2] - 2026-05-28
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
|
|
21
|
+
- Updated package metadata for the Gajae Code npm publication.
|
|
22
|
+
|
|
5
23
|
## [0.1.1] - 2026-05-28
|
|
6
24
|
|
|
7
25
|
### Added
|
package/dist/types/agent.d.ts
CHANGED
|
@@ -58,6 +58,7 @@ export interface AgentOptions {
|
|
|
58
58
|
* Useful for expiring tokens (e.g., GitHub Copilot OAuth).
|
|
59
59
|
*/
|
|
60
60
|
getApiKey?: (provider: string) => Promise<string | undefined> | string | undefined;
|
|
61
|
+
getAuthCredentialType?: (provider: string) => "api_key" | "oauth" | undefined;
|
|
61
62
|
/**
|
|
62
63
|
* Inspect or replace provider payloads before they are sent.
|
|
63
64
|
*/
|
|
@@ -158,6 +159,7 @@ export declare class Agent {
|
|
|
158
159
|
#private;
|
|
159
160
|
streamFn: StreamFn;
|
|
160
161
|
getApiKey?: (provider: string) => Promise<string | undefined> | string | undefined;
|
|
162
|
+
getAuthCredentialType?: (provider: string) => "api_key" | "oauth" | undefined;
|
|
161
163
|
/**
|
|
162
164
|
* Hook invoked after tool arguments are validated and before execution.
|
|
163
165
|
* Reassign at any time to swap the implementation (e.g. on extension reload).
|
|
@@ -115,6 +115,7 @@ export interface SummaryOptions {
|
|
|
115
115
|
* or `compaction_turn_prefix`). `undefined` keeps the call paths zero-cost.
|
|
116
116
|
*/
|
|
117
117
|
telemetry?: AgentTelemetry;
|
|
118
|
+
authCredentialType?: "api_key" | "oauth";
|
|
118
119
|
}
|
|
119
120
|
export declare function generateSummary(currentMessages: AgentMessage[], model: Model, reserveTokens: number, apiKey: string, signal?: AbortSignal, customInstructions?: string, previousSummary?: string, options?: SummaryOptions): Promise<string>;
|
|
120
121
|
export interface HandoffOptions {
|
|
@@ -131,6 +132,7 @@ export interface HandoffOptions {
|
|
|
131
132
|
* wrapped in an OTEL chat span tagged with `pi.gen_ai.oneshot.kind = "handoff"`.
|
|
132
133
|
*/
|
|
133
134
|
telemetry?: AgentTelemetry;
|
|
135
|
+
authCredentialType?: "api_key" | "oauth";
|
|
134
136
|
}
|
|
135
137
|
export declare function renderHandoffPrompt(customInstructions?: string): string;
|
|
136
138
|
export declare function generateHandoff(messages: AgentMessage[], model: Model, apiKey: string, options: HandoffOptions, signal?: AbortSignal): Promise<string>;
|
|
@@ -54,5 +54,7 @@ export declare function withOpenAiRemoteCompactionPreserveData(preserveData: Rec
|
|
|
54
54
|
* encrypted reasoning we want to preserve.
|
|
55
55
|
*/
|
|
56
56
|
export declare function buildOpenAiNativeHistory(messages: Message[], model: Model, previousReplacementHistory?: Array<Record<string, unknown>>): Array<Record<string, unknown>>;
|
|
57
|
-
export declare function requestOpenAiRemoteCompaction(model: Model, apiKey: string, compactInput: Array<Record<string, unknown>>, instructions: string, signal?: AbortSignal
|
|
57
|
+
export declare function requestOpenAiRemoteCompaction(model: Model, apiKey: string, compactInput: Array<Record<string, unknown>>, instructions: string, signal?: AbortSignal, options?: {
|
|
58
|
+
authCredentialType?: "api_key" | "oauth";
|
|
59
|
+
}): Promise<OpenAiRemoteCompactionResponse>;
|
|
58
60
|
export declare function requestRemoteCompaction(endpoint: string, request: RemoteCompactionRequest, signal?: AbortSignal): Promise<RemoteCompactionResponse>;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -79,6 +79,8 @@ export interface AgentLoopConfig extends SimpleStreamOptions {
|
|
|
79
79
|
* during long-running tool execution phases.
|
|
80
80
|
*/
|
|
81
81
|
getApiKey?: (provider: string) => Promise<string | undefined> | string | undefined;
|
|
82
|
+
/** Returns the credential type selected by the most recent getApiKey call for this session/provider. */
|
|
83
|
+
getAuthCredentialType?: (provider: string) => "api_key" | "oauth" | undefined;
|
|
82
84
|
/**
|
|
83
85
|
* Returns steering messages to inject into the conversation mid-run.
|
|
84
86
|
*
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@gajae-code/agent-core",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.0",
|
|
5
5
|
"description": "General-purpose agent with transport abstraction, state management, and attachment support",
|
|
6
|
-
"homepage": "https://gajae
|
|
7
|
-
"author": "
|
|
6
|
+
"homepage": "https://gaebal-gajae.dev",
|
|
7
|
+
"author": "Yeachan-Heo",
|
|
8
8
|
"contributors": [
|
|
9
9
|
"Mario Zechner"
|
|
10
10
|
],
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
"fmt": "biome format --write ."
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@gajae-code/ai": "0.
|
|
39
|
-
"@gajae-code/natives": "0.
|
|
40
|
-
"@gajae-code/utils": "0.
|
|
38
|
+
"@gajae-code/ai": "0.2.0",
|
|
39
|
+
"@gajae-code/natives": "0.2.0",
|
|
40
|
+
"@gajae-code/utils": "0.2.0",
|
|
41
41
|
"@opentelemetry/api": "^1.9.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
package/src/agent-loop.ts
CHANGED
|
@@ -671,6 +671,8 @@ async function streamAssistantResponse(
|
|
|
671
671
|
|
|
672
672
|
// Re-resolve metadata after credential selection so the per-request value
|
|
673
673
|
// reflects the credential actually used, not the snapshot from AgentLoopConfig construction.
|
|
674
|
+
const authCredentialType = config.getAuthCredentialType?.(config.model.provider);
|
|
675
|
+
|
|
674
676
|
const resolvedMetadata = config.metadataResolver ? config.metadataResolver(config.model.provider) : config.metadata;
|
|
675
677
|
|
|
676
678
|
const dynamicToolChoice = config.getToolChoice?.();
|
|
@@ -731,6 +733,7 @@ async function streamAssistantResponse(
|
|
|
731
733
|
const response = await streamFunction(config.model, llmContext, {
|
|
732
734
|
...config,
|
|
733
735
|
apiKey: resolvedApiKey,
|
|
736
|
+
authCredentialType,
|
|
734
737
|
metadata: resolvedMetadata,
|
|
735
738
|
toolChoice: effectiveToolChoice,
|
|
736
739
|
reasoning: effectiveReasoning,
|
package/src/agent.ts
CHANGED
|
@@ -128,6 +128,7 @@ export interface AgentOptions {
|
|
|
128
128
|
* Useful for expiring tokens (e.g., GitHub Copilot OAuth).
|
|
129
129
|
*/
|
|
130
130
|
getApiKey?: (provider: string) => Promise<string | undefined> | string | undefined;
|
|
131
|
+
getAuthCredentialType?: (provider: string) => "api_key" | "oauth" | undefined;
|
|
131
132
|
|
|
132
133
|
/**
|
|
133
134
|
* Inspect or replace provider payloads before they are sent.
|
|
@@ -307,6 +308,7 @@ export class Agent {
|
|
|
307
308
|
|
|
308
309
|
streamFn: StreamFn;
|
|
309
310
|
getApiKey?: (provider: string) => Promise<string | undefined> | string | undefined;
|
|
311
|
+
getAuthCredentialType?: (provider: string) => "api_key" | "oauth" | undefined;
|
|
310
312
|
/**
|
|
311
313
|
* Hook invoked after tool arguments are validated and before execution.
|
|
312
314
|
* Reassign at any time to swap the implementation (e.g. on extension reload).
|
|
@@ -339,6 +341,7 @@ export class Agent {
|
|
|
339
341
|
this.#hideThinkingSummary = opts.hideThinkingSummary;
|
|
340
342
|
this.#maxRetryDelayMs = opts.maxRetryDelayMs;
|
|
341
343
|
this.getApiKey = opts.getApiKey;
|
|
344
|
+
this.getAuthCredentialType = opts.getAuthCredentialType;
|
|
342
345
|
this.#onPayload = opts.onPayload;
|
|
343
346
|
this.#onResponse = opts.onResponse;
|
|
344
347
|
this.#onSseEvent = opts.onSseEvent;
|
|
@@ -1081,6 +1084,7 @@ export class Agent {
|
|
|
1081
1084
|
onSseEvent: this.#onSseEvent,
|
|
1082
1085
|
signal: abortController.signal,
|
|
1083
1086
|
getApiKey: this.getApiKey,
|
|
1087
|
+
getAuthCredentialType: this.getAuthCredentialType,
|
|
1084
1088
|
getToolContext: this.#getToolContext,
|
|
1085
1089
|
syncContextBeforeModelCall: async context => {
|
|
1086
1090
|
if (this.#listeners.size > 0) {
|
|
@@ -521,6 +521,7 @@ export interface SummaryOptions {
|
|
|
521
521
|
* or `compaction_turn_prefix`). `undefined` keeps the call paths zero-cost.
|
|
522
522
|
*/
|
|
523
523
|
telemetry?: AgentTelemetry;
|
|
524
|
+
authCredentialType?: "api_key" | "oauth";
|
|
524
525
|
}
|
|
525
526
|
|
|
526
527
|
export async function generateSummary(
|
|
@@ -621,6 +622,7 @@ export interface HandoffOptions {
|
|
|
621
622
|
* wrapped in an OTEL chat span tagged with `pi.gen_ai.oneshot.kind = "handoff"`.
|
|
622
623
|
*/
|
|
623
624
|
telemetry?: AgentTelemetry;
|
|
625
|
+
authCredentialType?: "api_key" | "oauth";
|
|
624
626
|
}
|
|
625
627
|
|
|
626
628
|
export function renderHandoffPrompt(customInstructions?: string): string {
|
|
@@ -928,6 +930,7 @@ export async function compact(
|
|
|
928
930
|
remoteHistory,
|
|
929
931
|
summaryOptions.remoteInstructions ?? SUMMARIZATION_SYSTEM_PROMPT,
|
|
930
932
|
signal,
|
|
933
|
+
{ authCredentialType: options?.authCredentialType },
|
|
931
934
|
);
|
|
932
935
|
preserveData = withOpenAiRemoteCompactionPreserveData(previousPreserveData, remote);
|
|
933
936
|
} catch (err) {
|
package/src/compaction/openai.ts
CHANGED
|
@@ -26,7 +26,9 @@ import {
|
|
|
26
26
|
getOpenAIResponsesHistoryPayload,
|
|
27
27
|
normalizeResponsesToolCallId,
|
|
28
28
|
} from "@gajae-code/ai/utils";
|
|
29
|
-
import { logger } from "@gajae-code/utils";
|
|
29
|
+
import { $env, logger } from "@gajae-code/utils";
|
|
30
|
+
|
|
31
|
+
const OPENAI_DEFAULT_BASE_URL = "https://api.openai.com/v1";
|
|
30
32
|
|
|
31
33
|
// ============================================================================
|
|
32
34
|
// Public types
|
|
@@ -72,13 +74,19 @@ export function shouldUseOpenAiRemoteCompaction(model: Model): boolean {
|
|
|
72
74
|
return model.provider === "openai" || model.provider === "openai-codex";
|
|
73
75
|
}
|
|
74
76
|
|
|
75
|
-
function resolveOpenAiCompactEndpoint(model: Model): string {
|
|
77
|
+
function resolveOpenAiCompactEndpoint(model: Model, authCredentialType?: "api_key" | "oauth"): string {
|
|
76
78
|
if (model.provider === "openai-codex") {
|
|
77
79
|
return resolveOpenAiCodexCompactEndpoint(model.baseUrl);
|
|
78
80
|
}
|
|
79
81
|
|
|
80
|
-
const
|
|
81
|
-
const
|
|
82
|
+
const envBaseUrl = $env.OPENAI_BASE_URL?.trim();
|
|
83
|
+
const configuredBaseUrl = model.baseUrl?.trim();
|
|
84
|
+
const rawBase =
|
|
85
|
+
authCredentialType === "oauth"
|
|
86
|
+
? OPENAI_DEFAULT_BASE_URL
|
|
87
|
+
: envBaseUrl && (!configuredBaseUrl || configuredBaseUrl.toLowerCase().includes("api.openai.com"))
|
|
88
|
+
? envBaseUrl
|
|
89
|
+
: configuredBaseUrl || envBaseUrl || OPENAI_DEFAULT_BASE_URL;
|
|
82
90
|
const normalizedBase = rawBase.endsWith("/") ? rawBase.slice(0, -1) : rawBase;
|
|
83
91
|
if (normalizedBase.endsWith("/v1")) return `${normalizedBase}/responses/compact`;
|
|
84
92
|
return `${normalizedBase}/v1/responses/compact`;
|
|
@@ -451,8 +459,9 @@ export async function requestOpenAiRemoteCompaction(
|
|
|
451
459
|
compactInput: Array<Record<string, unknown>>,
|
|
452
460
|
instructions: string,
|
|
453
461
|
signal?: AbortSignal,
|
|
462
|
+
options?: { authCredentialType?: "api_key" | "oauth" },
|
|
454
463
|
): Promise<OpenAiRemoteCompactionResponse> {
|
|
455
|
-
const endpoint = resolveOpenAiCompactEndpoint(model);
|
|
464
|
+
const endpoint = resolveOpenAiCompactEndpoint(model, options?.authCredentialType);
|
|
456
465
|
const request: OpenAiRemoteCompactionRequest = {
|
|
457
466
|
model: model.id,
|
|
458
467
|
input: trimOpenAiCompactInput(compactInput, model.contextWindow, instructions),
|
package/src/types.ts
CHANGED
|
@@ -106,6 +106,9 @@ export interface AgentLoopConfig extends SimpleStreamOptions {
|
|
|
106
106
|
*/
|
|
107
107
|
getApiKey?: (provider: string) => Promise<string | undefined> | string | undefined;
|
|
108
108
|
|
|
109
|
+
/** Returns the credential type selected by the most recent getApiKey call for this session/provider. */
|
|
110
|
+
getAuthCredentialType?: (provider: string) => "api_key" | "oauth" | undefined;
|
|
111
|
+
|
|
109
112
|
/**
|
|
110
113
|
* Returns steering messages to inject into the conversation mid-run.
|
|
111
114
|
*
|