@combycode/llm-sdk 1.0.0-rc.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 +19 -0
- package/LICENSE +21 -0
- package/README.md +103 -0
- package/dist/agent/approval-types.d.ts +49 -0
- package/dist/agent/context-registry/layers.d.ts +39 -0
- package/dist/agent/context-registry/registry-internal.d.ts +14 -0
- package/dist/agent/context-registry/registry.d.ts +104 -0
- package/dist/agent/context-registry/types.d.ts +110 -0
- package/dist/agent/guardrail-types.d.ts +58 -0
- package/dist/agent/history-types.d.ts +40 -0
- package/dist/agent/history.d.ts +111 -0
- package/dist/agent/loop-config.d.ts +67 -0
- package/dist/agent/loop-internals.d.ts +46 -0
- package/dist/agent/loop-step-state.d.ts +20 -0
- package/dist/agent/loop.d.ts +133 -0
- package/dist/agent/tool-key.d.ts +3 -0
- package/dist/agent/types.d.ts +138 -0
- package/dist/bus/agent-bus.d.ts +99 -0
- package/dist/bus/async-context.browser.d.ts +13 -0
- package/dist/bus/async-context.d.ts +11 -0
- package/dist/bus/async-context.types.d.ts +14 -0
- package/dist/bus/hook-bus.d.ts +43 -0
- package/dist/bus/hook-map.d.ts +592 -0
- package/dist/helpers/agent.d.ts +32 -0
- package/dist/helpers/batch.d.ts +74 -0
- package/dist/helpers/calibration-store.d.ts +27 -0
- package/dist/helpers/calibration-types.d.ts +64 -0
- package/dist/helpers/chain.d.ts +30 -0
- package/dist/helpers/client-pool.d.ts +15 -0
- package/dist/helpers/client-resolver.d.ts +62 -0
- package/dist/helpers/collection.d.ts +19 -0
- package/dist/helpers/consolidate.d.ts +66 -0
- package/dist/helpers/content.d.ts +25 -0
- package/dist/helpers/conversation-export.d.ts +14 -0
- package/dist/helpers/conversation-zip.d.ts +28 -0
- package/dist/helpers/count-tokens.d.ts +26 -0
- package/dist/helpers/define-tool.d.ts +66 -0
- package/dist/helpers/delegate.d.ts +6 -0
- package/dist/helpers/embed.d.ts +24 -0
- package/dist/helpers/engine.d.ts +121 -0
- package/dist/helpers/estimate-types.d.ts +67 -0
- package/dist/helpers/estimate.d.ts +45 -0
- package/dist/helpers/estimator.d.ts +48 -0
- package/dist/helpers/handoff-types.d.ts +18 -0
- package/dist/helpers/handoff.d.ts +14 -0
- package/dist/helpers/llm.d.ts +24 -0
- package/dist/helpers/mcp.d.ts +82 -0
- package/dist/helpers/media.d.ts +58 -0
- package/dist/helpers/models.d.ts +36 -0
- package/dist/helpers/moderate-types.d.ts +73 -0
- package/dist/helpers/moderate.d.ts +13 -0
- package/dist/helpers/moderation-guardrail.d.ts +29 -0
- package/dist/helpers/observer.d.ts +36 -0
- package/dist/helpers/one-shot.d.ts +86 -0
- package/dist/helpers/parallel.d.ts +16 -0
- package/dist/helpers/realtime.d.ts +25 -0
- package/dist/helpers/route.d.ts +29 -0
- package/dist/helpers/select-model.d.ts +41 -0
- package/dist/helpers/server.d.ts +32 -0
- package/dist/helpers/transcribe.d.ts +36 -0
- package/dist/index.browser.js +38047 -0
- package/dist/index.d.ts +275 -0
- package/dist/index.js +37974 -0
- package/dist/llm/audio/voices.d.ts +7 -0
- package/dist/llm/client-config.d.ts +37 -0
- package/dist/llm/client-internal.d.ts +28 -0
- package/dist/llm/client.d.ts +68 -0
- package/dist/llm/providers/_shared/constants.d.ts +5 -0
- package/dist/llm/providers/_shared/response-utils.d.ts +8 -0
- package/dist/llm/providers/anthropic/batch.d.ts +19 -0
- package/dist/llm/providers/anthropic/constants.d.ts +13 -0
- package/dist/llm/providers/anthropic/files.d.ts +23 -0
- package/dist/llm/providers/anthropic/messages.d.ts +30 -0
- package/dist/llm/providers/google/batch.d.ts +20 -0
- package/dist/llm/providers/google/constants.d.ts +6 -0
- package/dist/llm/providers/google/embeddings.d.ts +15 -0
- package/dist/llm/providers/google/files.d.ts +22 -0
- package/dist/llm/providers/google/generate.d.ts +27 -0
- package/dist/llm/providers/google/interactions.d.ts +30 -0
- package/dist/llm/providers/google/media.d.ts +27 -0
- package/dist/llm/providers/google/realtime.d.ts +27 -0
- package/dist/llm/providers/openai/batch.d.ts +19 -0
- package/dist/llm/providers/openai/completions.d.ts +25 -0
- package/dist/llm/providers/openai/embeddings.d.ts +16 -0
- package/dist/llm/providers/openai/files.d.ts +23 -0
- package/dist/llm/providers/openai/media.d.ts +28 -0
- package/dist/llm/providers/openai/moderations.d.ts +19 -0
- package/dist/llm/providers/openai/realtime.d.ts +24 -0
- package/dist/llm/providers/openai/responses.d.ts +29 -0
- package/dist/llm/providers/openai/tiers.d.ts +13 -0
- package/dist/llm/providers/openai/transcription.d.ts +20 -0
- package/dist/llm/providers/openrouter/completions.d.ts +15 -0
- package/dist/llm/providers/openrouter/embeddings.d.ts +7 -0
- package/dist/llm/providers/openrouter/media.d.ts +25 -0
- package/dist/llm/providers/openrouter/responses.d.ts +17 -0
- package/dist/llm/providers/xai/batch.d.ts +19 -0
- package/dist/llm/providers/xai/completions.d.ts +24 -0
- package/dist/llm/providers/xai/files.d.ts +23 -0
- package/dist/llm/providers/xai/media.d.ts +27 -0
- package/dist/llm/providers/xai/responses.d.ts +20 -0
- package/dist/llm/realtime/session.d.ts +34 -0
- package/dist/llm/realtime/types.d.ts +66 -0
- package/dist/llm/server-state.d.ts +32 -0
- package/dist/llm/types/audio.d.ts +18 -0
- package/dist/llm/types/messages.d.ts +125 -0
- package/dist/llm/types/options.d.ts +51 -0
- package/dist/llm/types/provider.d.ts +39 -0
- package/dist/llm/types/request.d.ts +51 -0
- package/dist/llm/types/response.d.ts +36 -0
- package/dist/llm/types/schema-utils.d.ts +8 -0
- package/dist/llm/types/stream.d.ts +42 -0
- package/dist/llm/types/tiers.d.ts +11 -0
- package/dist/llm/types/tools.d.ts +20 -0
- package/dist/network/engine.d.ts +87 -0
- package/dist/network/errors.d.ts +14 -0
- package/dist/network/queue-state-config.d.ts +41 -0
- package/dist/network/queue-state.d.ts +45 -0
- package/dist/network/rate-limiter.d.ts +49 -0
- package/dist/network/realtime-connection.d.ts +40 -0
- package/dist/network/request-queue.d.ts +40 -0
- package/dist/network/semaphore.d.ts +12 -0
- package/dist/network/sse.d.ts +3 -0
- package/dist/network/types.d.ts +127 -0
- package/dist/plugins/batch/batcher.d.ts +45 -0
- package/dist/plugins/batch/strategy.d.ts +20 -0
- package/dist/plugins/batch/types.d.ts +54 -0
- package/dist/plugins/cache/cache.d.ts +50 -0
- package/dist/plugins/cache/file-store.d.ts +15 -0
- package/dist/plugins/cache/memory-store.d.ts +10 -0
- package/dist/plugins/cache/types.d.ts +28 -0
- package/dist/plugins/configuration/configuration.d.ts +71 -0
- package/dist/plugins/context-guard/facts.d.ts +14 -0
- package/dist/plugins/context-guard/guard.d.ts +27 -0
- package/dist/plugins/context-guard/strategies/layered.d.ts +24 -0
- package/dist/plugins/context-guard/strategies/truncate.d.ts +19 -0
- package/dist/plugins/context-guard/tools.d.ts +50 -0
- package/dist/plugins/context-guard/types.d.ts +110 -0
- package/dist/plugins/context-measurer/calibration/store.d.ts +19 -0
- package/dist/plugins/context-measurer/counter/count-api.d.ts +41 -0
- package/dist/plugins/context-measurer/counter/heuristic.d.ts +25 -0
- package/dist/plugins/context-measurer/counter/hybrid.d.ts +33 -0
- package/dist/plugins/context-measurer/counter/tiktoken.d.ts +13 -0
- package/dist/plugins/context-measurer/measurer.d.ts +49 -0
- package/dist/plugins/context-measurer/types.d.ts +40 -0
- package/dist/plugins/cost-collector/collector.d.ts +42 -0
- package/dist/plugins/cost-collector/cost-collector-internal.d.ts +58 -0
- package/dist/plugins/cost-collector/cost-collector-types.d.ts +42 -0
- package/dist/plugins/embeddings/types.d.ts +23 -0
- package/dist/plugins/files/attachment.d.ts +79 -0
- package/dist/plugins/files/provider-adapter.d.ts +37 -0
- package/dist/plugins/files/registry.d.ts +48 -0
- package/dist/plugins/files/strategy.d.ts +38 -0
- package/dist/plugins/internal-tools/backends/local.d.ts +12 -0
- package/dist/plugins/internal-tools/builtin/builtin.d.ts +21 -0
- package/dist/plugins/internal-tools/builtin/clarify.d.ts +12 -0
- package/dist/plugins/internal-tools/builtin/classify.d.ts +12 -0
- package/dist/plugins/internal-tools/builtin/score.d.ts +13 -0
- package/dist/plugins/internal-tools/builtin/structure.d.ts +11 -0
- package/dist/plugins/internal-tools/builtin/summarize.d.ts +19 -0
- package/dist/plugins/internal-tools/id.d.ts +12 -0
- package/dist/plugins/internal-tools/registry.d.ts +24 -0
- package/dist/plugins/internal-tools/runner/define.d.ts +7 -0
- package/dist/plugins/internal-tools/runner/json-enforcement.d.ts +3 -0
- package/dist/plugins/internal-tools/runner/runner.d.ts +47 -0
- package/dist/plugins/internal-tools/runner/template.d.ts +10 -0
- package/dist/plugins/internal-tools/runner/types.d.ts +57 -0
- package/dist/plugins/internal-tools/runner/variants.d.ts +34 -0
- package/dist/plugins/internal-tools/types.d.ts +80 -0
- package/dist/plugins/logger/console-sink.d.ts +26 -0
- package/dist/plugins/logger/logger.d.ts +38 -0
- package/dist/plugins/logger/types.d.ts +25 -0
- package/dist/plugins/mcp/base-transport.d.ts +58 -0
- package/dist/plugins/mcp/client.d.ts +92 -0
- package/dist/plugins/mcp/jsonrpc.d.ts +20 -0
- package/dist/plugins/mcp/oauth.d.ts +122 -0
- package/dist/plugins/mcp/sampling.d.ts +17 -0
- package/dist/plugins/mcp/tools.d.ts +20 -0
- package/dist/plugins/mcp/transport-http.d.ts +50 -0
- package/dist/plugins/mcp/transport-stdio.d.ts +23 -0
- package/dist/plugins/mcp/transport-ws.d.ts +32 -0
- package/dist/plugins/mcp/transport.d.ts +29 -0
- package/dist/plugins/mcp/types.d.ts +202 -0
- package/dist/plugins/mcp/url-guard.d.ts +70 -0
- package/dist/plugins/mcp/win-spawn.d.ts +20 -0
- package/dist/plugins/media/file-store.d.ts +24 -0
- package/dist/plugins/media/memory-store.d.ts +17 -0
- package/dist/plugins/media/output.d.ts +44 -0
- package/dist/plugins/media/source-image.d.ts +36 -0
- package/dist/plugins/media/types.d.ts +146 -0
- package/dist/plugins/model-catalog/catalog.d.ts +152 -0
- package/dist/plugins/permissions/glob.d.ts +6 -0
- package/dist/plugins/permissions/matchers.d.ts +7 -0
- package/dist/plugins/permissions/policy.d.ts +10 -0
- package/dist/plugins/permissions/types.d.ts +22 -0
- package/dist/plugins/persistence/file.d.ts +25 -0
- package/dist/plugins/persistence/memory.d.ts +23 -0
- package/dist/plugins/persistence/types.d.ts +21 -0
- package/dist/plugins/retrieval/chunker.d.ts +28 -0
- package/dist/plugins/retrieval/hosted-google.d.ts +60 -0
- package/dist/plugins/retrieval/hosted-openai.d.ts +45 -0
- package/dist/plugins/retrieval/hosted-xai.d.ts +57 -0
- package/dist/plugins/retrieval/index.d.ts +70 -0
- package/dist/plugins/retrieval/local.d.ts +50 -0
- package/dist/plugins/retrieval/types.d.ts +161 -0
- package/dist/plugins/retrieval/vector-store.d.ts +70 -0
- package/dist/plugins/scheduler/scheduler.d.ts +31 -0
- package/dist/plugins/telemetry/telemetry.d.ts +118 -0
- package/dist/plugins/tool-catalog/catalog.d.ts +31 -0
- package/dist/plugins/tool-catalog/errors.d.ts +22 -0
- package/dist/plugins/tool-catalog/types.d.ts +44 -0
- package/dist/runtime/runtime.d.ts +20 -0
- package/dist/server/auth.d.ts +25 -0
- package/dist/server/dispatch.d.ts +35 -0
- package/dist/server/loaders.d.ts +26 -0
- package/dist/server/oai-adapter.d.ts +30 -0
- package/dist/server/oai-types.d.ts +114 -0
- package/dist/server/response-store.d.ts +59 -0
- package/dist/server/router.d.ts +59 -0
- package/dist/server/server.d.ts +61 -0
- package/dist/types/request-context.d.ts +46 -0
- package/dist/util/async.d.ts +3 -0
- package/dist/util/base64.d.ts +8 -0
- package/dist/util/duration.d.ts +12 -0
- package/dist/util/http.d.ts +9 -0
- package/dist/util/image-mime.d.ts +8 -0
- package/dist/util/json-schema.d.ts +7 -0
- package/dist/util/wav.d.ts +20 -0
- package/package.json +95 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** ContextMeasurer — auto-wires measurement + calibration learning.
|
|
2
|
+
* Pattern matches CostCollector / FilesRegistry: instantiate → hooks attach. */
|
|
3
|
+
import type { HookBus } from '../../bus/hook-bus';
|
|
4
|
+
import type { Message } from '../../llm/types/messages';
|
|
5
|
+
import type { TokenCounter } from '../../agent/types';
|
|
6
|
+
import type { ConversationHistory } from '../../agent/history';
|
|
7
|
+
import type { ModelCatalog } from '../model-catalog/catalog';
|
|
8
|
+
import type { Persistence } from '../persistence/types';
|
|
9
|
+
import type { CalibrationStore, ContextThresholds, CalibrationConfig } from './types';
|
|
10
|
+
export interface ContextMeasurerConfig {
|
|
11
|
+
hooks: HookBus;
|
|
12
|
+
catalog: ModelCatalog;
|
|
13
|
+
/** Use an explicit counter, else a HybridTokenCounter is built from catalog. */
|
|
14
|
+
counter?: TokenCounter;
|
|
15
|
+
/** Persistence for calibration. If absent, no calibration learning occurs. */
|
|
16
|
+
persistence?: Persistence;
|
|
17
|
+
/** Explicit calibration store (overrides persistence). */
|
|
18
|
+
calibrationStore?: CalibrationStore;
|
|
19
|
+
/** API keys for exact counting endpoints. */
|
|
20
|
+
countApiKeys?: {
|
|
21
|
+
anthropic?: string;
|
|
22
|
+
google?: string;
|
|
23
|
+
};
|
|
24
|
+
/** Thresholds for warning/exact escalation. */
|
|
25
|
+
thresholds?: Partial<ContextThresholds>;
|
|
26
|
+
/** Calibration tuning (EMA alpha, confidence samples). */
|
|
27
|
+
calibration?: Partial<CalibrationConfig>;
|
|
28
|
+
}
|
|
29
|
+
export declare class ContextMeasurer {
|
|
30
|
+
readonly counter: TokenCounter;
|
|
31
|
+
readonly calibrationStore: CalibrationStore | null;
|
|
32
|
+
readonly thresholds: ContextThresholds;
|
|
33
|
+
private hooks;
|
|
34
|
+
private catalog;
|
|
35
|
+
private unsubscribers;
|
|
36
|
+
constructor(config: ContextMeasurerConfig);
|
|
37
|
+
private wire;
|
|
38
|
+
destroy(): void;
|
|
39
|
+
/** Pre-warm calibration cache on startup. */
|
|
40
|
+
warmCache(): Promise<void>;
|
|
41
|
+
/** Measure + emit onContextMeasure. Returns final state including any abort
|
|
42
|
+
* set by listeners (ContextGuard may set it). */
|
|
43
|
+
measureAndEmit(provider: string, model: string, messages: Message[], history?: ConversationHistory, system?: string): Promise<{
|
|
44
|
+
total: number;
|
|
45
|
+
abort: boolean;
|
|
46
|
+
abortReason?: string;
|
|
47
|
+
}>;
|
|
48
|
+
private learnFromCompletion;
|
|
49
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** ContextMeasurer plugin types — calibration shapes + measurer config. */
|
|
2
|
+
import type { ContentClass } from '../../agent/types';
|
|
3
|
+
export interface CalibrationEntry {
|
|
4
|
+
provider: string;
|
|
5
|
+
model: string;
|
|
6
|
+
contentClass?: ContentClass;
|
|
7
|
+
charsPerToken: number;
|
|
8
|
+
samples: number;
|
|
9
|
+
confidence: number;
|
|
10
|
+
lastUpdated: number;
|
|
11
|
+
}
|
|
12
|
+
export interface CalibrationStore {
|
|
13
|
+
get(provider: string, model: string, contentClass?: ContentClass): Promise<CalibrationEntry | null>;
|
|
14
|
+
update(entry: Omit<CalibrationEntry, 'lastUpdated' | 'confidence'>): Promise<CalibrationEntry>;
|
|
15
|
+
list(opts?: {
|
|
16
|
+
provider?: string;
|
|
17
|
+
model?: string;
|
|
18
|
+
}): Promise<CalibrationEntry[]>;
|
|
19
|
+
reset(opts?: {
|
|
20
|
+
provider?: string;
|
|
21
|
+
model?: string;
|
|
22
|
+
}): Promise<void>;
|
|
23
|
+
}
|
|
24
|
+
export interface ContextThresholds {
|
|
25
|
+
/** Percentage (0-1) at which to warn. Default 0.80. */
|
|
26
|
+
warn: number;
|
|
27
|
+
/** Percentage (0-1) at which to upgrade to exact measurement. Default 0.90. */
|
|
28
|
+
exact: number;
|
|
29
|
+
}
|
|
30
|
+
export interface CalibrationConfig {
|
|
31
|
+
/** EMA weight for new samples (0-1). Default 0.2. */
|
|
32
|
+
emaAlpha: number;
|
|
33
|
+
/** Samples needed to reach full confidence. Default 10. */
|
|
34
|
+
minSamplesForConfidence: number;
|
|
35
|
+
}
|
|
36
|
+
export declare const CONTEXT_DEFAULTS: {
|
|
37
|
+
readonly thresholds: ContextThresholds;
|
|
38
|
+
readonly calibration: CalibrationConfig;
|
|
39
|
+
readonly charsPerTokenFallback: 4;
|
|
40
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** CostCollector — listens to onCompletion, computes cost from ModelCatalog
|
|
2
|
+
* pricing or provider-reported totals, emits onCostEntry/onBudgetWarning/
|
|
3
|
+
* onBudgetExceeded. */
|
|
4
|
+
import type { CostEntry } from '../../bus/hook-map';
|
|
5
|
+
import type { ModelCatalog } from '../model-catalog/catalog';
|
|
6
|
+
import type { Budget, CostCollectorConfig, CostFilter, CostSummary } from './cost-collector-types';
|
|
7
|
+
export declare class CostCollector {
|
|
8
|
+
private ledger;
|
|
9
|
+
private hooks;
|
|
10
|
+
private catalog;
|
|
11
|
+
private sessionId?;
|
|
12
|
+
private defaultTags;
|
|
13
|
+
private budgets;
|
|
14
|
+
private triggeredThresholds;
|
|
15
|
+
private _runningTotal;
|
|
16
|
+
private watchedAgents;
|
|
17
|
+
private unsub;
|
|
18
|
+
private unsubMedia;
|
|
19
|
+
constructor(config: CostCollectorConfig);
|
|
20
|
+
destroy(): void;
|
|
21
|
+
addBudget(budget: Budget): void;
|
|
22
|
+
removeBudget(id: string): void;
|
|
23
|
+
watchAgent(agent: {
|
|
24
|
+
stop(): void;
|
|
25
|
+
}): void;
|
|
26
|
+
setTag(key: string, value: string): void;
|
|
27
|
+
total(filter?: CostFilter): CostSummary;
|
|
28
|
+
byProvider(filter?: CostFilter): Record<string, CostSummary>;
|
|
29
|
+
byModel(filter?: CostFilter): Record<string, CostSummary>;
|
|
30
|
+
byTag(tagName: string, filter?: CostFilter): Record<string, CostSummary>;
|
|
31
|
+
entries(filter?: CostFilter): CostEntry[];
|
|
32
|
+
get entryCount(): number;
|
|
33
|
+
get runningTotal(): number;
|
|
34
|
+
get modelCatalog(): ModelCatalog;
|
|
35
|
+
export(): CostEntry[];
|
|
36
|
+
import(entries: CostEntry[]): void;
|
|
37
|
+
private handleMediaGenerated;
|
|
38
|
+
private handleCompletion;
|
|
39
|
+
private checkBudgets;
|
|
40
|
+
private filterEntries;
|
|
41
|
+
private groupBy;
|
|
42
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/** CostCollector internals — pure cost-math + filtering helpers, split out of
|
|
2
|
+
* the class so each is independently testable. */
|
|
3
|
+
import type { CostEntry } from '../../bus/hook-map';
|
|
4
|
+
import type { ModelCatalog } from '../model-catalog/catalog';
|
|
5
|
+
import type { CostFilter, CostSummary } from './cost-collector-types';
|
|
6
|
+
/** Pull provider-reported cost evidence out of a raw response body. */
|
|
7
|
+
export declare function extractProviderCost(provider: string, raw: unknown): Record<string, unknown>;
|
|
8
|
+
/** The provider's own total cost (USD), when it reports one. */
|
|
9
|
+
export declare function getProviderTotal(provider: string, evidence: Record<string, unknown>): number | null;
|
|
10
|
+
/** Compute a CostEntry cost: provider total when reported, else catalog pricing
|
|
11
|
+
* at the billed service tier (tier rates overlay the flat standard rates). */
|
|
12
|
+
export declare function calculateCost(catalog: ModelCatalog, provider: string, model: string, tokens: CostEntry['tokens'], providerEvidence: Record<string, unknown>, tier?: string): CostEntry['cost'];
|
|
13
|
+
/** Media units for unit-priced generation (image count / video seconds / TTS
|
|
14
|
+
* chars), plus the resolution that selects a `perUnit` rate. */
|
|
15
|
+
export interface MediaCostUnits {
|
|
16
|
+
type: 'image' | 'audio' | 'video';
|
|
17
|
+
count?: number;
|
|
18
|
+
durationSeconds?: number;
|
|
19
|
+
textChars?: number;
|
|
20
|
+
resolution?: string;
|
|
21
|
+
}
|
|
22
|
+
/** Everything `computeCost` needs to price one generation (chat OR media). */
|
|
23
|
+
export interface CostComputeInput {
|
|
24
|
+
provider: string;
|
|
25
|
+
model: string;
|
|
26
|
+
/** Token usage — chat, and token-priced media (gpt-image, gemini-tts). */
|
|
27
|
+
tokens?: CostEntry['tokens'];
|
|
28
|
+
/** Unit-priced media facts. */
|
|
29
|
+
media?: MediaCostUnits;
|
|
30
|
+
providerEvidence?: Record<string, unknown>;
|
|
31
|
+
tier?: string;
|
|
32
|
+
}
|
|
33
|
+
/** Compute cost for a speech-to-text transcription billed by audio duration
|
|
34
|
+
* (whisper, gpt-4o-transcribe). Returns a zero-cost entry with `source:
|
|
35
|
+
* 'unknown'` when the catalog has no `perMinute` rate for this model, so the
|
|
36
|
+
* cost pipeline can attach a note instead of emitting nothing.
|
|
37
|
+
*
|
|
38
|
+
* `durationSeconds` is the audio duration measured or derived by the caller
|
|
39
|
+
* (WAV header parse, or a caller-supplied hint). */
|
|
40
|
+
export declare function calculateTranscriptionCost(catalog: ModelCatalog, provider: string, model: string, durationSeconds: number | undefined): {
|
|
41
|
+
cost: CostEntry['cost'];
|
|
42
|
+
note?: string;
|
|
43
|
+
};
|
|
44
|
+
/** The single cost engine for the whole SDK. Priority ladder:
|
|
45
|
+
* 1. provider-reported total (when the response carries one)
|
|
46
|
+
* 2. token cost — usage × per-MTok rates (chat, gpt-image, gemini-tts)
|
|
47
|
+
* 3. media unit cost — perUnit[resolution] → perImage/perSecond/perMChars
|
|
48
|
+
* 4. unknown (0)
|
|
49
|
+
* Token pricing wins over unit pricing only when the model actually has
|
|
50
|
+
* per-token rates, so unit-priced media with incidental usage still prices by
|
|
51
|
+
* unit. */
|
|
52
|
+
export declare function computeCost(catalog: ModelCatalog, input: CostComputeInput): CostEntry['cost'];
|
|
53
|
+
/** Does an entry fall within a budget scope (all defined scope keys match)? */
|
|
54
|
+
export declare function matchesScope(entry: CostEntry, scope: Record<string, string | undefined>): boolean;
|
|
55
|
+
/** Predicate for CostFilter (provider/model/time/run/conversation/session). */
|
|
56
|
+
export declare function applyFilter(e: CostEntry, filter: CostFilter): boolean;
|
|
57
|
+
/** Sum a set of entries into a CostSummary. */
|
|
58
|
+
export declare function summarize(entries: CostEntry[]): CostSummary;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** CostCollector public types: config, budgets, filters, summaries. */
|
|
2
|
+
import type { HookBus } from '../../bus/hook-bus';
|
|
3
|
+
import type { ModelCatalog } from '../model-catalog/catalog';
|
|
4
|
+
export interface CostCollectorConfig {
|
|
5
|
+
hooks: HookBus;
|
|
6
|
+
catalog: ModelCatalog;
|
|
7
|
+
sessionId?: string;
|
|
8
|
+
defaultTags?: Record<string, string>;
|
|
9
|
+
}
|
|
10
|
+
export interface Budget {
|
|
11
|
+
id: string;
|
|
12
|
+
limit: number;
|
|
13
|
+
scope: Record<string, string | undefined>;
|
|
14
|
+
thresholds: number[];
|
|
15
|
+
action: 'warn' | 'stop';
|
|
16
|
+
}
|
|
17
|
+
export interface CostFilter {
|
|
18
|
+
provider?: string;
|
|
19
|
+
model?: string;
|
|
20
|
+
runId?: string;
|
|
21
|
+
conversationId?: string;
|
|
22
|
+
sessionId?: string;
|
|
23
|
+
after?: number;
|
|
24
|
+
before?: number;
|
|
25
|
+
[key: string]: string | number | undefined;
|
|
26
|
+
}
|
|
27
|
+
export interface CostSummary {
|
|
28
|
+
input: number;
|
|
29
|
+
output: number;
|
|
30
|
+
cacheRead: number;
|
|
31
|
+
cacheWrite: number;
|
|
32
|
+
reasoning: number;
|
|
33
|
+
total: number;
|
|
34
|
+
tokens: {
|
|
35
|
+
input: number;
|
|
36
|
+
output: number;
|
|
37
|
+
cached: number;
|
|
38
|
+
cacheWrite: number;
|
|
39
|
+
reasoning: number;
|
|
40
|
+
};
|
|
41
|
+
entries: number;
|
|
42
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Embeddings subsystem — text → vector. Mirrors the media adapter contract:
|
|
2
|
+
* a thin per-provider adapter whose HTTP flows through the injected EngineFetch
|
|
3
|
+
* (so it shares the NetworkEngine queue / retry / hooks). */
|
|
4
|
+
import type { EngineFetch } from '../../network/types';
|
|
5
|
+
export interface EmbedRequest {
|
|
6
|
+
model: string;
|
|
7
|
+
/** One string or a batch. */
|
|
8
|
+
input: string | string[];
|
|
9
|
+
}
|
|
10
|
+
export interface EmbedResult {
|
|
11
|
+
/** One vector per input, in order. */
|
|
12
|
+
embeddings: number[][];
|
|
13
|
+
model: string;
|
|
14
|
+
/** Vector length (0 when empty). */
|
|
15
|
+
dimensions: number;
|
|
16
|
+
usage?: {
|
|
17
|
+
inputTokens: number;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export interface EmbeddingProviderAdapter {
|
|
21
|
+
readonly name: string;
|
|
22
|
+
embed(req: EmbedRequest, fetch: EngineFetch): Promise<EmbedResult>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/** FileAttachment — represents a file with upload state tracking per provider. */
|
|
2
|
+
export type FileContent = {
|
|
3
|
+
type: 'buffer';
|
|
4
|
+
mimeType: string;
|
|
5
|
+
data: Uint8Array;
|
|
6
|
+
} | {
|
|
7
|
+
type: 'path';
|
|
8
|
+
mimeType: string;
|
|
9
|
+
path: string;
|
|
10
|
+
} | {
|
|
11
|
+
type: 'blob';
|
|
12
|
+
mimeType: string;
|
|
13
|
+
data: Blob;
|
|
14
|
+
} | {
|
|
15
|
+
type: 'url';
|
|
16
|
+
url: string;
|
|
17
|
+
mimeType?: string;
|
|
18
|
+
} | {
|
|
19
|
+
type: 'base64';
|
|
20
|
+
mimeType: string;
|
|
21
|
+
data: string;
|
|
22
|
+
};
|
|
23
|
+
export interface FileUploadState {
|
|
24
|
+
provider: string;
|
|
25
|
+
status: 'pending' | 'uploaded' | 'expired' | 'deleted' | 'error';
|
|
26
|
+
remoteId: string | null;
|
|
27
|
+
uploadedAt: number | null;
|
|
28
|
+
expiresAt: number | null;
|
|
29
|
+
error: string | null;
|
|
30
|
+
}
|
|
31
|
+
export interface FileAttachmentSnapshot {
|
|
32
|
+
id: string;
|
|
33
|
+
filename: string;
|
|
34
|
+
mimeType: string;
|
|
35
|
+
sizeBytes: number;
|
|
36
|
+
uploads: Array<Omit<FileUploadState, 'provider'> & {
|
|
37
|
+
provider: string;
|
|
38
|
+
}>;
|
|
39
|
+
metadata: Record<string, unknown>;
|
|
40
|
+
createdAt: number;
|
|
41
|
+
}
|
|
42
|
+
export declare class FileAttachment {
|
|
43
|
+
readonly id: string;
|
|
44
|
+
readonly filename: string;
|
|
45
|
+
readonly mimeType: string;
|
|
46
|
+
readonly sizeBytes: number;
|
|
47
|
+
readonly content: FileContent;
|
|
48
|
+
readonly createdAt: number;
|
|
49
|
+
readonly metadata: Record<string, unknown>;
|
|
50
|
+
readonly uploads: Map<string, FileUploadState>;
|
|
51
|
+
constructor(opts: {
|
|
52
|
+
id?: string;
|
|
53
|
+
filename: string;
|
|
54
|
+
mimeType: string;
|
|
55
|
+
sizeBytes: number;
|
|
56
|
+
content: FileContent;
|
|
57
|
+
metadata?: Record<string, unknown>;
|
|
58
|
+
});
|
|
59
|
+
/** Build an attachment from a browser File/Blob (e.g. an <input type="file">
|
|
60
|
+
* or drag-drop). Works on Node/Bun too (Blob is a global there). filename /
|
|
61
|
+
* mimeType / sizeBytes are taken from the Blob unless overridden. */
|
|
62
|
+
static fromBlob(blob: Blob, opts?: {
|
|
63
|
+
id?: string;
|
|
64
|
+
filename?: string;
|
|
65
|
+
mimeType?: string;
|
|
66
|
+
metadata?: Record<string, unknown>;
|
|
67
|
+
}): FileAttachment;
|
|
68
|
+
isAvailable(provider: string): boolean;
|
|
69
|
+
needsUpload(provider: string): boolean;
|
|
70
|
+
getRef(provider: string): string | null;
|
|
71
|
+
setUploaded(provider: string, remoteId: string, expiresAt: number | null): void;
|
|
72
|
+
setError(provider: string, error: string): void;
|
|
73
|
+
setDeleted(provider: string): void;
|
|
74
|
+
/** Load file content as base64 */
|
|
75
|
+
toBase64(): Promise<string>;
|
|
76
|
+
/** Load raw bytes */
|
|
77
|
+
toBuffer(): Promise<Uint8Array>;
|
|
78
|
+
export(): FileAttachmentSnapshot;
|
|
79
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** FileProviderAdapter — provider-specific file operations.
|
|
2
|
+
* Implemented by per-provider files.ts (anthropic/openai/google/xai).
|
|
3
|
+
*
|
|
4
|
+
* All HTTP calls flow through an injected EngineFetch (NetworkEngine queue)
|
|
5
|
+
* — adapters do not hold their own fetch fn. FilesRegistry threads
|
|
6
|
+
* `engine.fetch` into adapter methods on every call, so rate-limit, retry,
|
|
7
|
+
* and observability hooks apply uniformly. */
|
|
8
|
+
import type { EngineFetch } from '../../network/types';
|
|
9
|
+
import type { FileAttachment } from './attachment';
|
|
10
|
+
export interface FileUploadResult {
|
|
11
|
+
remoteId: string;
|
|
12
|
+
expiresAt: number | null;
|
|
13
|
+
}
|
|
14
|
+
export interface RemoteFileInfo {
|
|
15
|
+
remoteId: string;
|
|
16
|
+
filename: string;
|
|
17
|
+
sizeBytes: number;
|
|
18
|
+
createdAt: number;
|
|
19
|
+
expiresAt?: number;
|
|
20
|
+
}
|
|
21
|
+
export interface FileProviderAdapter {
|
|
22
|
+
readonly name: string;
|
|
23
|
+
/** Upload a file. Returns remote id + optional expiry. */
|
|
24
|
+
upload(file: FileAttachment, fetch: EngineFetch): Promise<FileUploadResult>;
|
|
25
|
+
/** Delete a remote file. */
|
|
26
|
+
delete(remoteId: string, fetch: EngineFetch): Promise<void>;
|
|
27
|
+
/** Get info about a remote file. Returns null if not found. */
|
|
28
|
+
getInfo(remoteId: string, fetch: EngineFetch): Promise<RemoteFileInfo | null>;
|
|
29
|
+
/** List all remote files for the configured account. */
|
|
30
|
+
list(fetch: EngineFetch): Promise<RemoteFileInfo[]>;
|
|
31
|
+
/** Auto-expiry window in ms, or null for persistent. */
|
|
32
|
+
expiresAfter: number | null;
|
|
33
|
+
/** Max file size in bytes. */
|
|
34
|
+
maxFileSize: number;
|
|
35
|
+
/** Supported MIME types — null means accept all. */
|
|
36
|
+
supportedTypes: string[] | null;
|
|
37
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** FilesRegistry — manages files across providers. Subscribes to
|
|
2
|
+
* onMessageResolve and resolves file refs into provider-friendly content
|
|
3
|
+
* parts (provider_ref / inline base64 / url). */
|
|
4
|
+
import type { HookBus } from '../../bus/hook-bus';
|
|
5
|
+
import type { EngineFetch } from '../../network/types';
|
|
6
|
+
import type { ModelCatalog } from '../model-catalog/catalog';
|
|
7
|
+
import { FileAttachment, type FileContent } from './attachment';
|
|
8
|
+
import type { FileProviderAdapter, RemoteFileInfo } from './provider-adapter';
|
|
9
|
+
import { type FileStrategy } from './strategy';
|
|
10
|
+
export interface FilesRegistryConfig {
|
|
11
|
+
hooks: HookBus;
|
|
12
|
+
catalog?: ModelCatalog;
|
|
13
|
+
strategy?: FileStrategy;
|
|
14
|
+
/** Engine fetch — every adapter HTTP call dispatches through this so it
|
|
15
|
+
* inherits NetworkEngine queue semantics (rate limits, retry, hooks). */
|
|
16
|
+
fetch: EngineFetch;
|
|
17
|
+
}
|
|
18
|
+
export declare class FilesRegistry {
|
|
19
|
+
private files;
|
|
20
|
+
private providers;
|
|
21
|
+
private hooks;
|
|
22
|
+
private catalog;
|
|
23
|
+
private strategy;
|
|
24
|
+
private fetch;
|
|
25
|
+
private unsub;
|
|
26
|
+
constructor(config: FilesRegistryConfig);
|
|
27
|
+
destroy(): void;
|
|
28
|
+
registerProvider(name: string, adapter: FileProviderAdapter): void;
|
|
29
|
+
add(opts: {
|
|
30
|
+
filename: string;
|
|
31
|
+
mimeType: string;
|
|
32
|
+
content: FileContent;
|
|
33
|
+
sizeBytes?: number;
|
|
34
|
+
metadata?: Record<string, unknown>;
|
|
35
|
+
}): FileAttachment;
|
|
36
|
+
get(id: string): FileAttachment | null;
|
|
37
|
+
list(): FileAttachment[];
|
|
38
|
+
remove(id: string): void;
|
|
39
|
+
upload(fileId: string, provider: string): Promise<string>;
|
|
40
|
+
deleteRemote(fileId: string, provider: string): Promise<void>;
|
|
41
|
+
listRemote(provider: string): Promise<RemoteFileInfo[]>;
|
|
42
|
+
private resolveMessages;
|
|
43
|
+
private hasFileSource;
|
|
44
|
+
private resolveFilePart;
|
|
45
|
+
private executeDecision;
|
|
46
|
+
private makeInlinePart;
|
|
47
|
+
private estimateSize;
|
|
48
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** FileStrategy — pluggable decision maker for how to attach files. */
|
|
2
|
+
import type { ModelInfo } from '../model-catalog/catalog';
|
|
3
|
+
import type { FileAttachment } from './attachment';
|
|
4
|
+
export interface FileStrategyContext {
|
|
5
|
+
file: FileAttachment;
|
|
6
|
+
provider: string;
|
|
7
|
+
model: string;
|
|
8
|
+
isUploaded: boolean;
|
|
9
|
+
isExpired: boolean;
|
|
10
|
+
providerMaxSize: number;
|
|
11
|
+
providerSupportsType: boolean;
|
|
12
|
+
modelInfo: ModelInfo | null;
|
|
13
|
+
}
|
|
14
|
+
export type FileDecision = {
|
|
15
|
+
action: 'upload';
|
|
16
|
+
reason: string;
|
|
17
|
+
} | {
|
|
18
|
+
action: 'reupload';
|
|
19
|
+
reason: string;
|
|
20
|
+
} | {
|
|
21
|
+
action: 'inline';
|
|
22
|
+
reason: string;
|
|
23
|
+
} | {
|
|
24
|
+
action: 'url';
|
|
25
|
+
reason: string;
|
|
26
|
+
} | {
|
|
27
|
+
action: 'skip';
|
|
28
|
+
reason: string;
|
|
29
|
+
};
|
|
30
|
+
export interface FileStrategy {
|
|
31
|
+
decide(ctx: FileStrategyContext): FileDecision;
|
|
32
|
+
}
|
|
33
|
+
/** Default: upload large files, inline small ones, use URL when available. */
|
|
34
|
+
export declare class DefaultFileStrategy implements FileStrategy {
|
|
35
|
+
private inlineThreshold;
|
|
36
|
+
constructor(inlineThreshold?: number);
|
|
37
|
+
decide(ctx: FileStrategyContext): FileDecision;
|
|
38
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** LocalBackend — in-repo tool library. Synchronous registration, async access. */
|
|
2
|
+
import type { ToolBackend, InternalTool } from '../types';
|
|
3
|
+
export declare class LocalBackend implements ToolBackend {
|
|
4
|
+
readonly name = "local";
|
|
5
|
+
private tools;
|
|
6
|
+
register(tool: InternalTool): this;
|
|
7
|
+
replace(tool: InternalTool): this;
|
|
8
|
+
unregister(id: string): boolean;
|
|
9
|
+
get size(): number;
|
|
10
|
+
list(): Promise<InternalTool[]>;
|
|
11
|
+
get(id: string): Promise<InternalTool | null>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** Core built-in tool library. Five tools every LLM app eventually needs:
|
|
2
|
+
*
|
|
3
|
+
* summarize — universal compaction primitive (used by ContextGuard, RAG, output)
|
|
4
|
+
* classify — routing / intent / moderation
|
|
5
|
+
* structure — extract typed structured data from prose
|
|
6
|
+
* score — self-evaluation, judge-LLM patterns, ranking
|
|
7
|
+
* clarify — interactive flows (mate to ask events)
|
|
8
|
+
*
|
|
9
|
+
* Application-specific or domain-heavy tools (fact-extract, format-question,
|
|
10
|
+
* format-response, prompt-improve, enhance, variation, title) ship separately
|
|
11
|
+
* under `extensions/builtin-tools/` and must be registered manually if needed. */
|
|
12
|
+
import type { LocalBackend } from '../backends/local';
|
|
13
|
+
export { summarizeTool, type SummarizeInput, type SummarizeOutput } from './summarize';
|
|
14
|
+
export { classifyTool, type ClassifyInput, type ClassifyOutput } from './classify';
|
|
15
|
+
export { scoreTool, type ScoreInput, type ScoreOutput } from './score';
|
|
16
|
+
export { structureTool, type StructureInput, type StructureOutput } from './structure';
|
|
17
|
+
export { clarifyTool, type ClarifyInput, type ClarifyOutput } from './clarify';
|
|
18
|
+
/** Core built-in tools shipped with the SDK. */
|
|
19
|
+
export declare const BUILTIN_TOOLS: readonly [import("../types").InternalTool, import("../types").InternalTool, import("../types").InternalTool, import("../types").InternalTool, import("../types").InternalTool];
|
|
20
|
+
/** Register all SDK-core built-in tools on a LocalBackend. */
|
|
21
|
+
export declare function registerBuiltinTools(backend: LocalBackend): void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** orxa:clarify@1.0.0 — validate prompt against requirements, produce questions for gaps. */
|
|
2
|
+
import type { InternalTool } from '../types';
|
|
3
|
+
export interface ClarifyInput {
|
|
4
|
+
prompt: string;
|
|
5
|
+
requirements: string[];
|
|
6
|
+
}
|
|
7
|
+
export interface ClarifyOutput {
|
|
8
|
+
satisfied: boolean;
|
|
9
|
+
missingRequirements: string[];
|
|
10
|
+
clarificationQuestions: string[];
|
|
11
|
+
}
|
|
12
|
+
export declare const clarifyTool: InternalTool;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** orxa:classify@1.0.0 — select best match from suggestions with confidence. */
|
|
2
|
+
import type { InternalTool } from '../types';
|
|
3
|
+
export interface ClassifyInput {
|
|
4
|
+
request: string;
|
|
5
|
+
suggestions: string[];
|
|
6
|
+
}
|
|
7
|
+
export interface ClassifyOutput {
|
|
8
|
+
selectedIndex: number;
|
|
9
|
+
confidence: number;
|
|
10
|
+
reasoning: string;
|
|
11
|
+
}
|
|
12
|
+
export declare const classifyTool: InternalTool;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** orxa:score@1.0.0 — score how well an answer fulfills a task, per criteria. */
|
|
2
|
+
import type { InternalTool } from '../types';
|
|
3
|
+
export interface ScoreInput {
|
|
4
|
+
task: string;
|
|
5
|
+
answer: string;
|
|
6
|
+
criteria?: string[];
|
|
7
|
+
}
|
|
8
|
+
export interface ScoreOutput {
|
|
9
|
+
score: number;
|
|
10
|
+
breakdown: Record<string, number>;
|
|
11
|
+
feedback: string;
|
|
12
|
+
}
|
|
13
|
+
export declare const scoreTool: InternalTool;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** orxa:structure@1.0.0 — extract structured JSON from unstructured text per schema. */
|
|
2
|
+
import type { InternalTool } from '../types';
|
|
3
|
+
import type { JsonSchema } from '../../../llm/types/tools';
|
|
4
|
+
export interface StructureInput {
|
|
5
|
+
request: string;
|
|
6
|
+
schema: JsonSchema;
|
|
7
|
+
}
|
|
8
|
+
export interface StructureOutput {
|
|
9
|
+
[key: string]: unknown;
|
|
10
|
+
}
|
|
11
|
+
export declare const structureTool: InternalTool;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** orxa:summarize@1.0.0 — compact long content while preserving key facts.
|
|
2
|
+
* Uses provider-specific variants because strict fact-preservation helps
|
|
3
|
+
* Haiku and Flash-Lite (they over-paraphrase by default) but hurts Nano
|
|
4
|
+
* (which becomes too literal and fails to compress). */
|
|
5
|
+
import type { InternalTool } from '../types';
|
|
6
|
+
export interface SummarizeInput {
|
|
7
|
+
content: string;
|
|
8
|
+
/** Target max characters for the summary text. Converted to max_tokens via catalog ratio. */
|
|
9
|
+
maxLength?: number;
|
|
10
|
+
/** Target max tokens for the LLM response. Takes precedence over maxLength. */
|
|
11
|
+
maxTokens?: number;
|
|
12
|
+
/** Optional focus for the summary (narrows the content angle). */
|
|
13
|
+
focus?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface SummarizeOutput {
|
|
16
|
+
summary: string;
|
|
17
|
+
keyPoints: string[];
|
|
18
|
+
}
|
|
19
|
+
export declare const summarizeTool: InternalTool;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Tool ID parsing and version matching helpers.
|
|
2
|
+
* Format: "namespace:name@semver" (e.g. "orxa:summarize@1.0.0"). */
|
|
3
|
+
export interface ParsedToolId {
|
|
4
|
+
namespace: string;
|
|
5
|
+
name: string;
|
|
6
|
+
version: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function parseToolId(id: string): ParsedToolId;
|
|
9
|
+
export declare function tryParseToolId(id: string): ParsedToolId | null;
|
|
10
|
+
export declare function formatToolId(namespace: string, name: string, version: string): string;
|
|
11
|
+
export declare function matchesVersion(requested: string, actual: string): boolean;
|
|
12
|
+
export declare function idWithoutVersion(id: string): string;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** ToolRegistry — unified access across multiple backends with caching, search, filtering. */
|
|
2
|
+
import type { InternalTool, ToolBackend, ToolFilter, SearchOptions } from './types';
|
|
3
|
+
import type { ModelCatalog } from '../model-catalog/catalog';
|
|
4
|
+
export declare class ToolRegistry {
|
|
5
|
+
private backends;
|
|
6
|
+
private cache;
|
|
7
|
+
/** Add a backend. First-added wins on ID conflicts. Returns this for chaining. */
|
|
8
|
+
addBackend(backend: ToolBackend): this;
|
|
9
|
+
removeBackend(name: string): boolean;
|
|
10
|
+
invalidate(): void;
|
|
11
|
+
get(id: string): Promise<InternalTool | null>;
|
|
12
|
+
list(): Promise<InternalTool[]>;
|
|
13
|
+
find(filter: ToolFilter, catalog?: ModelCatalog): Promise<InternalTool[]>;
|
|
14
|
+
search(query: string, opts?: SearchOptions): Promise<InternalTool[]>;
|
|
15
|
+
/** Models with acceptable compatibility score for this tool, derived from
|
|
16
|
+
* catalog's `toolCompat` field on each ModelInfo. */
|
|
17
|
+
modelsFor(toolId: string, opts?: {
|
|
18
|
+
minScore?: number;
|
|
19
|
+
catalog?: ModelCatalog;
|
|
20
|
+
}): string[];
|
|
21
|
+
private ensureCache;
|
|
22
|
+
private matchesFilter;
|
|
23
|
+
private scoreMatch;
|
|
24
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** defineLLMTool — convert a declarative LLMToolDefinition into an InternalTool
|
|
2
|
+
* with execute() that renders templates, calls LLM, parses output. */
|
|
3
|
+
import type { InternalTool } from '../types';
|
|
4
|
+
import type { LLMToolDefinition } from './types';
|
|
5
|
+
export declare const LLM_DEF_KEY: unique symbol;
|
|
6
|
+
export declare function getLLMToolDefinition(tool: InternalTool): LLMToolDefinition | null;
|
|
7
|
+
export declare function defineLLMTool(def: LLMToolDefinition): InternalTool;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
/** JSON output enforcement — system prompt that forces strict JSON-only output. */
|
|
2
|
+
export declare const JSON_API_SYSTEM_PROMPT = "You are a JSON API endpoint. Your output is parsed directly by code, not read by humans.\n\nABSOLUTE REQUIREMENTS:\n- Output ONLY valid JSON. Nothing else. No exceptions.\n- Your entire response must be parseable by JSON.parse()\n- First character of response must be { and last must be }\n\nFORBIDDEN (will cause parsing errors):\n- NO markdown: ```json or ``` blocks\n- NO prose: \"Here is the JSON:\" or \"Sure, here's...\"\n- NO explanations before or after the JSON\n- NO comments inside JSON\n- NO trailing text\n\nCORRECT OUTPUT FORMAT:\n{\"field\": \"value\", \"number\": 42}\n\nWRONG OUTPUT FORMAT (DO NOT DO THIS):\n```json\n{\"field\": \"value\"}\n```\n\nJSON SYNTAX RULES:\n- Double quotes for all strings and keys\n- No trailing commas\n- Numbers as numeric values (0.85 not \"0.85\")\n- Use null for unknown values, [] for empty arrays\n\nRESPOND WITH RAW JSON ONLY. START WITH { END WITH }";
|
|
3
|
+
export declare function composeJsonSystemPrompt(toolSystemPrompt: string): string;
|