@c9up/polaris 0.1.0 → 0.1.1
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/README.md +614 -10
- package/dist/Polaris.d.ts +6 -2
- package/dist/Polaris.d.ts.map +1 -1
- package/dist/Polaris.js +14 -0
- package/dist/Polaris.js.map +1 -1
- package/dist/PolarisClient.d.ts +51 -3
- package/dist/PolarisClient.d.ts.map +1 -1
- package/dist/PolarisClient.js +213 -45
- package/dist/PolarisClient.js.map +1 -1
- package/dist/PolarisProvider.d.ts +7 -2
- package/dist/PolarisProvider.d.ts.map +1 -1
- package/dist/PolarisProvider.js +34 -2
- package/dist/PolarisProvider.js.map +1 -1
- package/dist/augmentations.d.ts +4 -1
- package/dist/augmentations.d.ts.map +1 -1
- package/dist/augmentations.js +1 -1
- package/dist/budget.d.ts +39 -6
- package/dist/budget.d.ts.map +1 -1
- package/dist/budget.js +79 -12
- package/dist/budget.js.map +1 -1
- package/dist/catalog/catalog.d.ts +37 -0
- package/dist/catalog/catalog.d.ts.map +1 -0
- package/dist/catalog/catalog.js +145 -0
- package/dist/catalog/catalog.js.map +1 -0
- package/dist/catalog/discover.d.ts +64 -0
- package/dist/catalog/discover.d.ts.map +1 -0
- package/dist/catalog/discover.js +148 -0
- package/dist/catalog/discover.js.map +1 -0
- package/dist/catalog/index.d.ts +8 -0
- package/dist/catalog/index.d.ts.map +1 -0
- package/dist/catalog/index.js +8 -0
- package/dist/catalog/index.js.map +1 -0
- package/dist/commands/index.d.ts +82 -0
- package/dist/commands/index.d.ts.map +1 -0
- package/dist/commands/index.js +278 -0
- package/dist/commands/index.js.map +1 -0
- package/dist/cost.d.ts +3 -1
- package/dist/cost.d.ts.map +1 -1
- package/dist/cost.js +8 -3
- package/dist/cost.js.map +1 -1
- package/dist/drivers/anthropic.d.ts +6 -1
- package/dist/drivers/anthropic.d.ts.map +1 -1
- package/dist/drivers/anthropic.js +166 -21
- package/dist/drivers/anthropic.js.map +1 -1
- package/dist/drivers/openai-compatible.d.ts +1 -1
- package/dist/drivers/openai-compatible.d.ts.map +1 -1
- package/dist/drivers/openai-compatible.js +106 -70
- package/dist/drivers/openai-compatible.js.map +1 -1
- package/dist/errors.d.ts +24 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +24 -0
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +6 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/json-schema.d.ts +33 -0
- package/dist/json-schema.d.ts.map +1 -0
- package/dist/json-schema.js +508 -0
- package/dist/json-schema.js.map +1 -0
- package/dist/log.d.ts.map +1 -1
- package/dist/log.js +3 -1
- package/dist/log.js.map +1 -1
- package/dist/mcp/client.d.ts +81 -0
- package/dist/mcp/client.d.ts.map +1 -0
- package/dist/mcp/client.js +401 -0
- package/dist/mcp/client.js.map +1 -0
- package/dist/mcp/endpoint.d.ts +54 -0
- package/dist/mcp/endpoint.d.ts.map +1 -0
- package/dist/mcp/endpoint.js +158 -0
- package/dist/mcp/endpoint.js.map +1 -0
- package/dist/mcp/host.d.ts +42 -0
- package/dist/mcp/host.d.ts.map +1 -0
- package/dist/mcp/host.js +111 -0
- package/dist/mcp/host.js.map +1 -0
- package/dist/mcp/http.d.ts +32 -0
- package/dist/mcp/http.d.ts.map +1 -0
- package/dist/mcp/http.js +190 -0
- package/dist/mcp/http.js.map +1 -0
- package/dist/mcp/index.d.ts +23 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +21 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/manifest.d.ts +36 -0
- package/dist/mcp/manifest.d.ts.map +1 -0
- package/dist/mcp/manifest.js +40 -0
- package/dist/mcp/manifest.js.map +1 -0
- package/dist/mcp/rpc.d.ts +39 -0
- package/dist/mcp/rpc.d.ts.map +1 -0
- package/dist/mcp/rpc.js +149 -0
- package/dist/mcp/rpc.js.map +1 -0
- package/dist/mcp/stdio.d.ts +24 -0
- package/dist/mcp/stdio.d.ts.map +1 -0
- package/dist/mcp/stdio.js +157 -0
- package/dist/mcp/stdio.js.map +1 -0
- package/dist/mcp/worker-main.d.ts +6 -0
- package/dist/mcp/worker-main.d.ts.map +1 -0
- package/dist/mcp/worker-main.js +17 -0
- package/dist/mcp/worker-main.js.map +1 -0
- package/dist/mcp/worker.d.ts +54 -0
- package/dist/mcp/worker.d.ts.map +1 -0
- package/dist/mcp/worker.js +166 -0
- package/dist/mcp/worker.js.map +1 -0
- package/dist/meter.d.ts +6 -0
- package/dist/meter.d.ts.map +1 -1
- package/dist/meter.js +6 -3
- package/dist/meter.js.map +1 -1
- package/dist/redact.d.ts +4 -3
- package/dist/redact.d.ts.map +1 -1
- package/dist/redact.js +5 -4
- package/dist/redact.js.map +1 -1
- package/dist/redis-budget.d.ts +45 -0
- package/dist/redis-budget.d.ts.map +1 -0
- package/dist/redis-budget.js +56 -0
- package/dist/redis-budget.js.map +1 -0
- package/dist/response.d.ts +21 -3
- package/dist/response.d.ts.map +1 -1
- package/dist/response.js +71 -7
- package/dist/response.js.map +1 -1
- package/dist/server-sent.d.ts +9 -0
- package/dist/server-sent.d.ts.map +1 -0
- package/dist/server-sent.js +74 -0
- package/dist/server-sent.js.map +1 -0
- package/dist/server-tools.d.ts +12 -0
- package/dist/server-tools.d.ts.map +1 -0
- package/dist/server-tools.js +71 -0
- package/dist/server-tools.js.map +1 -0
- package/dist/services/catalog.d.ts +19 -0
- package/dist/services/catalog.d.ts.map +1 -0
- package/dist/services/catalog.js +37 -0
- package/dist/services/catalog.js.map +1 -0
- package/dist/skills/folder.d.ts +32 -0
- package/dist/skills/folder.d.ts.map +1 -0
- package/dist/skills/folder.js +170 -0
- package/dist/skills/folder.js.map +1 -0
- package/dist/skills/frontmatter.d.ts +15 -0
- package/dist/skills/frontmatter.d.ts.map +1 -0
- package/dist/skills/frontmatter.js +92 -0
- package/dist/skills/frontmatter.js.map +1 -0
- package/dist/skills/index.d.ts +18 -0
- package/dist/skills/index.d.ts.map +1 -0
- package/dist/skills/index.js +18 -0
- package/dist/skills/index.js.map +1 -0
- package/dist/skills/kit.d.ts +39 -0
- package/dist/skills/kit.d.ts.map +1 -0
- package/dist/skills/kit.js +124 -0
- package/dist/skills/kit.js.map +1 -0
- package/dist/skills/skill.d.ts +67 -0
- package/dist/skills/skill.d.ts.map +1 -0
- package/dist/skills/skill.js +114 -0
- package/dist/skills/skill.js.map +1 -0
- package/dist/sse.d.ts +43 -6
- package/dist/sse.d.ts.map +1 -1
- package/dist/sse.js +44 -18
- package/dist/sse.js.map +1 -1
- package/dist/testing/FakeProvider.d.ts.map +1 -1
- package/dist/testing/FakeProvider.js +1 -0
- package/dist/testing/FakeProvider.js.map +1 -1
- package/dist/tool-modules.d.ts +17 -0
- package/dist/tool-modules.d.ts.map +1 -0
- package/dist/tool-modules.js +43 -0
- package/dist/tool-modules.js.map +1 -0
- package/dist/tools.d.ts +69 -5
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +174 -31
- package/dist/tools.js.map +1 -1
- package/dist/transport.d.ts +8 -3
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +19 -4
- package/dist/transport.js.map +1 -1
- package/dist/types.d.ts +106 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +22 -1
- package/src/Polaris.ts +25 -1
- package/src/PolarisClient.ts +288 -51
- package/src/PolarisProvider.ts +40 -2
- package/src/augmentations.ts +4 -1
- package/src/budget.ts +115 -15
- package/src/catalog/catalog.ts +180 -0
- package/src/catalog/discover.ts +234 -0
- package/src/catalog/index.ts +19 -0
- package/src/commands/index.ts +412 -0
- package/src/cost.ts +9 -3
- package/src/drivers/anthropic.ts +203 -20
- package/src/drivers/openai-compatible.ts +143 -76
- package/src/errors.ts +41 -0
- package/src/index.ts +16 -0
- package/src/json-schema.ts +597 -0
- package/src/log.ts +3 -1
- package/src/mcp/client.ts +532 -0
- package/src/mcp/endpoint.ts +229 -0
- package/src/mcp/host.ts +140 -0
- package/src/mcp/http.ts +276 -0
- package/src/mcp/index.ts +51 -0
- package/src/mcp/manifest.ts +73 -0
- package/src/mcp/rpc.ts +197 -0
- package/src/mcp/stdio.ts +190 -0
- package/src/mcp/worker-main.ts +18 -0
- package/src/mcp/worker.ts +212 -0
- package/src/meter.ts +13 -2
- package/src/redact.ts +6 -3
- package/src/redis-budget.ts +85 -0
- package/src/response.ts +86 -8
- package/src/server-sent.ts +70 -0
- package/src/server-tools.ts +77 -0
- package/src/services/catalog.ts +43 -0
- package/src/skills/folder.ts +231 -0
- package/src/skills/frontmatter.ts +92 -0
- package/src/skills/index.ts +38 -0
- package/src/skills/kit.ts +163 -0
- package/src/skills/skill.ts +171 -0
- package/src/sse.ts +88 -22
- package/src/testing/FakeProvider.ts +1 -0
- package/src/tool-modules.ts +49 -0
- package/src/tools.ts +260 -27
- package/src/transport.ts +25 -3
- package/src/types.ts +108 -2
package/src/types.ts
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import type { BudgetConfig } from "./budget.js";
|
|
13
|
+
import type { CatalogConfig } from "./catalog/discover.js";
|
|
13
14
|
import type { Cost, Pricing } from "./cost.js";
|
|
14
15
|
import type { ExchangeLog } from "./log.js";
|
|
15
16
|
|
|
@@ -138,6 +139,22 @@ export interface ChatRequest {
|
|
|
138
139
|
readonly output?: OutputFormat;
|
|
139
140
|
readonly stopSequences?: readonly string[];
|
|
140
141
|
readonly effort?: Effort;
|
|
142
|
+
/**
|
|
143
|
+
* Ask the provider to cache the request's prefix (tools, system prompt,
|
|
144
|
+
* messages), so the next request that starts the same way reads it at the
|
|
145
|
+
* cache price instead of the full input price. Claude caches only when
|
|
146
|
+
* asked, for 5 minutes from the last read; the OpenAI-compatible services
|
|
147
|
+
* cache on their own, or not at all, and ignore the option. Check
|
|
148
|
+
* `usage.cacheReadTokens` to see it work.
|
|
149
|
+
*/
|
|
150
|
+
readonly cache?: boolean;
|
|
151
|
+
/**
|
|
152
|
+
* Tools the provider runs on its own servers: code execution, its skills,
|
|
153
|
+
* and the MCP servers it calls itself. Only the drivers that declare the
|
|
154
|
+
* `serverTools` feature take it (Anthropic); the others refuse the request
|
|
155
|
+
* with `E_POLARIS_UNSUPPORTED`.
|
|
156
|
+
*/
|
|
157
|
+
readonly server?: ServerTools;
|
|
141
158
|
/**
|
|
142
159
|
* Provider-specific fields, passed through by the driver that knows them
|
|
143
160
|
* and ignored by the others.
|
|
@@ -145,6 +162,51 @@ export interface ChatRequest {
|
|
|
145
162
|
readonly providerOptions?: { readonly [provider: string]: unknown };
|
|
146
163
|
}
|
|
147
164
|
|
|
165
|
+
/**
|
|
166
|
+
* What a provider runs on its own side for a request. Its tool calls never
|
|
167
|
+
* reach the application: they come back as `provider` parts, with their
|
|
168
|
+
* results, and the run goes on without polaris running anything.
|
|
169
|
+
*/
|
|
170
|
+
export interface ServerTools {
|
|
171
|
+
/**
|
|
172
|
+
* Let the model run code in the provider's container. Implied by `skills`,
|
|
173
|
+
* which need it.
|
|
174
|
+
*/
|
|
175
|
+
readonly codeExecution?: boolean;
|
|
176
|
+
/** Skills the provider loads into the container, at most 20. */
|
|
177
|
+
readonly skills?: readonly ServerSkill[];
|
|
178
|
+
/** MCP servers the provider connects to and calls itself. */
|
|
179
|
+
readonly mcpServers?: readonly ServerMcpServer[];
|
|
180
|
+
/**
|
|
181
|
+
* The container to work in again: a previous response's `container.id`,
|
|
182
|
+
* so the files it holds are still there. `run()` carries it from one step
|
|
183
|
+
* to the next by itself.
|
|
184
|
+
*/
|
|
185
|
+
readonly container?: string;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** A skill the provider runs, as it knows it. */
|
|
189
|
+
export interface ServerSkill {
|
|
190
|
+
/** `anthropic` for the provider's own skills (`xlsx`, `pptx`…), `custom` for one uploaded to the account. */
|
|
191
|
+
readonly source: "anthropic" | "custom";
|
|
192
|
+
/** `xlsx`, or a custom skill's `skill_…` id. */
|
|
193
|
+
readonly id: string;
|
|
194
|
+
/** A version the provider names (`20251013`, `skver_…`). Default `latest`. */
|
|
195
|
+
readonly version?: string;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** An MCP server the provider calls over the internet. */
|
|
199
|
+
export interface ServerMcpServer {
|
|
200
|
+
/** Its name in the request: unique, and how the model's calls name it. */
|
|
201
|
+
readonly name: string;
|
|
202
|
+
/** Its `https://` endpoint (Streamable HTTP or SSE). */
|
|
203
|
+
readonly url: string;
|
|
204
|
+
/** Sent to the server as its OAuth bearer token. Redacted from logs and errors. */
|
|
205
|
+
readonly authorizationToken?: string;
|
|
206
|
+
/** Only these of its tools. Default: all of them. */
|
|
207
|
+
readonly tools?: readonly string[];
|
|
208
|
+
}
|
|
209
|
+
|
|
148
210
|
/**
|
|
149
211
|
* Why the model stopped.
|
|
150
212
|
*
|
|
@@ -168,8 +230,9 @@ export type StopReason =
|
|
|
168
230
|
| "other";
|
|
169
231
|
|
|
170
232
|
/**
|
|
171
|
-
* Tokens a request used. Counts a provider does not report are 0
|
|
172
|
-
* input counts do not overlap, so each is billed
|
|
233
|
+
* Tokens a request used. Counts a provider does not report are 0 (see
|
|
234
|
+
* `usageUnknown`). The three input counts do not overlap, so each is billed
|
|
235
|
+
* at its own price.
|
|
173
236
|
*/
|
|
174
237
|
export interface Usage {
|
|
175
238
|
/** Input tokens billed at the full input price: neither read from nor written to a cache. */
|
|
@@ -179,6 +242,12 @@ export interface Usage {
|
|
|
179
242
|
readonly cacheReadTokens: number;
|
|
180
243
|
/** Input tokens written to the provider's prompt cache. */
|
|
181
244
|
readonly cacheWriteTokens: number;
|
|
245
|
+
/**
|
|
246
|
+
* Requests to tools the provider ran itself, by tool, as it counts them:
|
|
247
|
+
* `{ codeExecutionRequests: 2 }`. Absent when it reports none. Tokens those
|
|
248
|
+
* tools read or wrote are in the counts above.
|
|
249
|
+
*/
|
|
250
|
+
readonly serverToolUse?: { readonly [counter: string]: number };
|
|
182
251
|
}
|
|
183
252
|
|
|
184
253
|
export interface ChatResponse {
|
|
@@ -197,8 +266,27 @@ export interface ChatResponse {
|
|
|
197
266
|
readonly toolCalls: readonly ToolCallPart[];
|
|
198
267
|
readonly stopReason: StopReason;
|
|
199
268
|
readonly usage: Usage;
|
|
269
|
+
/**
|
|
270
|
+
* The provider reported no token counts, left out the input or output
|
|
271
|
+
* count, or reported counts that cannot be right (negative, fractional):
|
|
272
|
+
* `usage` holds 0 where it had nothing usable, the
|
|
273
|
+
* response has no `cost`, and a budget keeps the call's estimate.
|
|
274
|
+
*/
|
|
275
|
+
readonly usageUnknown?: boolean;
|
|
200
276
|
/** What the request cost, when the config has a price for the model. */
|
|
201
277
|
readonly cost?: Cost;
|
|
278
|
+
/**
|
|
279
|
+
* The provider's container the reply ran code in, while it is kept: send
|
|
280
|
+
* its id back as `server.container` to work on its files again.
|
|
281
|
+
*/
|
|
282
|
+
readonly container?: ServerContainer;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/** A provider's code execution container. */
|
|
286
|
+
export interface ServerContainer {
|
|
287
|
+
readonly id: string;
|
|
288
|
+
/** When the provider drops it, as it reports it (ISO 8601). */
|
|
289
|
+
readonly expiresAt?: string;
|
|
202
290
|
}
|
|
203
291
|
|
|
204
292
|
/**
|
|
@@ -227,6 +315,11 @@ export interface EmbedResponse {
|
|
|
227
315
|
/** One vector per input, in input order. */
|
|
228
316
|
readonly vectors: readonly Float32Array[];
|
|
229
317
|
readonly usage: { readonly inputTokens: number };
|
|
318
|
+
/**
|
|
319
|
+
* The provider reported no token count, or one that cannot be right: the
|
|
320
|
+
* response has no `cost`, and a budget keeps the call's estimate.
|
|
321
|
+
*/
|
|
322
|
+
readonly usageUnknown?: boolean;
|
|
230
323
|
/** What the request cost, when the config has a price for the model. */
|
|
231
324
|
readonly cost?: Cost;
|
|
232
325
|
}
|
|
@@ -267,6 +360,8 @@ export interface DriverFeatures {
|
|
|
267
360
|
readonly tools: boolean;
|
|
268
361
|
readonly structuredOutput: boolean;
|
|
269
362
|
readonly images: boolean;
|
|
363
|
+
/** Takes a request's `server` tools. Default false. */
|
|
364
|
+
readonly serverTools?: boolean;
|
|
270
365
|
}
|
|
271
366
|
|
|
272
367
|
/**
|
|
@@ -283,6 +378,12 @@ export interface PolarisDriver {
|
|
|
283
378
|
* before it is sent (a budget needs it).
|
|
284
379
|
*/
|
|
285
380
|
readonly defaults?: DriverDefaults;
|
|
381
|
+
/**
|
|
382
|
+
* The credentials the driver sends on its own: its configured key, one it
|
|
383
|
+
* reads from the environment, the values of headers it was given. polaris
|
|
384
|
+
* keeps them out of the errors it raises, as it does a per-call key.
|
|
385
|
+
*/
|
|
386
|
+
readonly secrets?: readonly string[];
|
|
286
387
|
chat(request: ChatRequest, call: DriverCall): Promise<ChatResponse>;
|
|
287
388
|
stream?(request: ChatRequest, call: DriverCall): AsyncIterable<StreamEvent>;
|
|
288
389
|
embed?(request: EmbedRequest, call: DriverCall): Promise<EmbedResponse>;
|
|
@@ -313,6 +414,11 @@ export interface PolarisConfig<
|
|
|
313
414
|
/** The provider `use()` returns when given no name. */
|
|
314
415
|
readonly default?: keyof KnownProviders & string;
|
|
315
416
|
readonly providers: KnownProviders;
|
|
417
|
+
/**
|
|
418
|
+
* Where `PolarisProvider` and `ream polaris:index` find the application's
|
|
419
|
+
* tools and skills (see `@c9up/polaris/catalog`). `false`: none.
|
|
420
|
+
*/
|
|
421
|
+
readonly catalog?: CatalogConfig | false;
|
|
316
422
|
}
|
|
317
423
|
|
|
318
424
|
/**
|