@keystrokehq/keystroke 1.0.13 → 1.0.15

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.
Files changed (63) hide show
  1. package/dist/action.cjs +1 -1
  2. package/dist/action.mjs +1 -1
  3. package/dist/agent.cjs +119 -12
  4. package/dist/agent.cjs.map +1 -1
  5. package/dist/agent.d.cts +1 -1
  6. package/dist/agent.d.mts +1 -1
  7. package/dist/agent.mjs +119 -12
  8. package/dist/agent.mjs.map +1 -1
  9. package/dist/app.cjs +1 -1
  10. package/dist/app.mjs +1 -1
  11. package/dist/client.cjs +1 -1
  12. package/dist/client.mjs +1 -1
  13. package/dist/config.d.cts +2 -2
  14. package/dist/config.d.cts.map +1 -1
  15. package/dist/config.d.mts +2 -2
  16. package/dist/config.d.mts.map +1 -1
  17. package/dist/credentials.cjs +1 -1
  18. package/dist/credentials.mjs +1 -1
  19. package/dist/{dist-DtejauR-.mjs → dist-BWGuF7Bi.mjs} +22 -9
  20. package/dist/dist-BWGuF7Bi.mjs.map +1 -0
  21. package/dist/{dist-C5UmW-zB.cjs → dist-CDMCEgV0.cjs} +22 -9
  22. package/dist/dist-CDMCEgV0.cjs.map +1 -0
  23. package/dist/{dist-DpZL1LE1.cjs → dist-CIXPxH8Y.cjs} +7 -3
  24. package/dist/dist-CIXPxH8Y.cjs.map +1 -0
  25. package/dist/{dist-DSbrc1sP.mjs → dist-DESn8Gyx.mjs} +3 -3
  26. package/dist/{dist-DSbrc1sP.mjs.map → dist-DESn8Gyx.mjs.map} +1 -1
  27. package/dist/{dist-Zh8nB_45.cjs → dist-jju5p8QW.cjs} +3 -3
  28. package/dist/{dist-Zh8nB_45.cjs.map → dist-jju5p8QW.cjs.map} +1 -1
  29. package/dist/{dist-D53HZMV9.mjs → dist-qrlBz5eZ.mjs} +7 -3
  30. package/dist/dist-qrlBz5eZ.mjs.map +1 -0
  31. package/dist/{index-Ohwnfidc.d.cts → index-BQEzTb7P.d.cts} +3 -3
  32. package/dist/index-BQEzTb7P.d.cts.map +1 -0
  33. package/dist/index-BTz2OMAM.d.cts.map +1 -1
  34. package/dist/index-Cq2F2XdS.d.mts.map +1 -1
  35. package/dist/index-WT4ULMiw.d.cts.map +1 -1
  36. package/dist/index-WT4ULMiw.d.mts.map +1 -1
  37. package/dist/{index-DdAOmbQc.d.mts → index-ub0OqZXh.d.mts} +3 -3
  38. package/dist/index-ub0OqZXh.d.mts.map +1 -0
  39. package/dist/{mistral-tahkZ8Hu.mjs → mistral-B3AiRi15.mjs} +2 -2
  40. package/dist/{mistral-tahkZ8Hu.mjs.map → mistral-B3AiRi15.mjs.map} +1 -1
  41. package/dist/{mistral-6XMKgah3.cjs → mistral-HS6Ekkp2.cjs} +2 -2
  42. package/dist/{mistral-6XMKgah3.cjs.map → mistral-HS6Ekkp2.cjs.map} +1 -1
  43. package/dist/{sse-CSbz_aIR.mjs → sse-DISKrIFa.mjs} +2 -2
  44. package/dist/{sse-CSbz_aIR.mjs.map → sse-DISKrIFa.mjs.map} +1 -1
  45. package/dist/{sse-PotOG2Pc.cjs → sse-ELfo0nZE.cjs} +2 -2
  46. package/dist/{sse-PotOG2Pc.cjs.map → sse-ELfo0nZE.cjs.map} +1 -1
  47. package/dist/trigger.cjs +135 -35
  48. package/dist/trigger.cjs.map +1 -1
  49. package/dist/trigger.d.cts +88 -21
  50. package/dist/trigger.d.cts.map +1 -1
  51. package/dist/trigger.d.mts +88 -21
  52. package/dist/trigger.d.mts.map +1 -1
  53. package/dist/trigger.mjs +122 -36
  54. package/dist/trigger.mjs.map +1 -1
  55. package/dist/workflow.cjs +1 -1
  56. package/dist/workflow.mjs +1 -1
  57. package/package.json +3 -3
  58. package/dist/dist-C5UmW-zB.cjs.map +0 -1
  59. package/dist/dist-D53HZMV9.mjs.map +0 -1
  60. package/dist/dist-DpZL1LE1.cjs.map +0 -1
  61. package/dist/dist-DtejauR-.mjs.map +0 -1
  62. package/dist/index-DdAOmbQc.d.mts.map +0 -1
  63. package/dist/index-Ohwnfidc.d.cts.map +0 -1
package/dist/action.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_dist = require("./dist-C5UmW-zB.cjs");
2
+ const require_dist = require("./dist-CDMCEgV0.cjs");
3
3
  exports.CREDENTIAL_SCOPE_TYPES = require_dist.CREDENTIAL_SCOPE_TYPES;
4
4
  exports.actionCoreSchema = require_dist.actionCoreSchema;
5
5
  exports.createStepInvocation = require_dist.createStepInvocation;
package/dist/action.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { C as credentialInputSchema, D as normalizeCredentialList, O as toCredentialRequirement, S as credential, T as isCredentialInput, _ as runWithMcpCredentialContext, a as getActionCredentialRequirements, b as CREDENTIAL_SCOPE_TYPES, c as getRunSignal, d as isStepInvocation, f as isWithinActionExecution, g as runOutsideActionExecution, h as resolveActionTool, i as executeAction, l as getWorkflowRunHandle, m as registerWorkflowRunGetter, n as createStepInvocation, o as getRegisteredMcpCredentialContext, p as registerProjectScopeGetter, r as defineAction, s as getRegisteredProjectScopeId, t as actionCoreSchema, u as isAction, v as runWithRunSignal, w as defineCredential, y as runWithinActionExecution } from "./dist-DtejauR-.mjs";
1
+ import { C as credentialInputSchema, D as normalizeCredentialList, O as toCredentialRequirement, S as credential, T as isCredentialInput, _ as runWithMcpCredentialContext, a as getActionCredentialRequirements, b as CREDENTIAL_SCOPE_TYPES, c as getRunSignal, d as isStepInvocation, f as isWithinActionExecution, g as runOutsideActionExecution, h as resolveActionTool, i as executeAction, l as getWorkflowRunHandle, m as registerWorkflowRunGetter, n as createStepInvocation, o as getRegisteredMcpCredentialContext, p as registerProjectScopeGetter, r as defineAction, s as getRegisteredProjectScopeId, t as actionCoreSchema, u as isAction, v as runWithRunSignal, w as defineCredential, y as runWithinActionExecution } from "./dist-BWGuF7Bi.mjs";
2
2
  export { CREDENTIAL_SCOPE_TYPES, actionCoreSchema, createStepInvocation, credential, credentialInputSchema, defineAction, defineCredential, executeAction, getActionCredentialRequirements, getRegisteredMcpCredentialContext, getRegisteredProjectScopeId, getRunSignal, getWorkflowRunHandle, isAction, isCredentialInput, isStepInvocation, isWithinActionExecution, normalizeCredentialList, registerProjectScopeGetter, registerWorkflowRunGetter, resolveActionTool, runOutsideActionExecution, runWithMcpCredentialContext, runWithRunSignal, runWithinActionExecution, toCredentialRequirement };
package/dist/agent.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_chunk = require("./chunk-DHdmVzO2.cjs");
3
- const require_dist$1 = require("./dist-C5UmW-zB.cjs");
4
- const require_dist$2 = require("./dist-DpZL1LE1.cjs");
3
+ const require_dist$1 = require("./dist-CDMCEgV0.cjs");
4
+ const require_dist$2 = require("./dist-CIXPxH8Y.cjs");
5
5
  const require_dist$3 = require("./dist-DO51rYHS.cjs");
6
6
  require("./env-api-keys-BFptfIIs.cjs");
7
7
  const require_event_stream = require("./event-stream-CS-ls7wC.cjs");
@@ -902,7 +902,7 @@ function loadGoogleVertexProviderModule() {
902
902
  return googleVertexProviderModulePromise;
903
903
  }
904
904
  function loadMistralProviderModule() {
905
- mistralProviderModulePromise ||= Promise.resolve().then(() => require("./mistral-6XMKgah3.cjs")).then((module) => {
905
+ mistralProviderModulePromise ||= Promise.resolve().then(() => require("./mistral-HS6Ekkp2.cjs")).then((module) => {
906
906
  const provider = module;
907
907
  return {
908
908
  stream: provider.streamMistral,
@@ -5325,10 +5325,29 @@ function validateToolArguments(tool, toolCall) {
5325
5325
  throw new Error(errorMessage);
5326
5326
  }
5327
5327
  //#endregion
5328
- //#region ../agent/dist/schemas-DCBOj0XY.mjs
5328
+ //#region ../agent/dist/schemas-T2usEGaN.mjs
5329
5329
  const getModelLoose = require_event_stream.getModel;
5330
+ const DEFAULT_GATEWAY_ORIGIN = "https://ai-gateway.vercel.sh";
5330
5331
  const AGENT_MODEL_ID_PATTERN = /^[a-z0-9-]+\/.+/;
5331
5332
  const AgentModelIdSchema = zod.z.custom((value) => typeof value === "string" && AGENT_MODEL_ID_PATTERN.test(value), "model must be vendor/model-id");
5333
+ const GatewayModelPricingSchema = zod.z.object({
5334
+ input: zod.z.string().optional(),
5335
+ output: zod.z.string().optional(),
5336
+ input_cache_read: zod.z.string().optional()
5337
+ });
5338
+ const GatewayModelResponseSchema = zod.z.object({
5339
+ id: zod.z.string().min(1),
5340
+ name: zod.z.string().optional(),
5341
+ type: zod.z.string().optional(),
5342
+ context_window: zod.z.number().int().positive().optional(),
5343
+ max_tokens: zod.z.number().int().positive().optional(),
5344
+ tags: zod.z.array(zod.z.string()).optional(),
5345
+ pricing: GatewayModelPricingSchema.optional()
5346
+ });
5347
+ function parseGatewayModelResponse(body) {
5348
+ const parsed = GatewayModelResponseSchema.safeParse(body);
5349
+ return parsed.success ? parsed.data : void 0;
5350
+ }
5332
5351
  function splitAgentModelId(modelId) {
5333
5352
  const slash = modelId.indexOf("/");
5334
5353
  return {
@@ -5359,11 +5378,95 @@ function resolveGatewayBaseUrl() {
5359
5378
  const projectId = require_dist$2.getProjectScopeId();
5360
5379
  return `${platformUrl.replace(/\/$/, "")}/internal/projects/${encodeURIComponent(projectId)}/llm`;
5361
5380
  }
5362
- function resolveGatewayModel(modelId) {
5381
+ function resolveGatewayOrigin(baseUrl) {
5382
+ return baseUrl ?? DEFAULT_GATEWAY_ORIGIN;
5383
+ }
5384
+ function pricePerMillion(value) {
5385
+ if (!value) return 0;
5386
+ const perToken = Number(value);
5387
+ if (!Number.isFinite(perToken) || perToken <= 0) return 0;
5388
+ return perToken * 1e6;
5389
+ }
5390
+ function buildGatewayModel(raw, baseUrl) {
5391
+ if (raw.type && raw.type !== "language") return;
5392
+ const tags = raw.tags ?? [];
5393
+ return {
5394
+ id: raw.id,
5395
+ name: raw.name ?? raw.id,
5396
+ api: "anthropic-messages",
5397
+ provider: "vercel-ai-gateway",
5398
+ baseUrl: resolveGatewayOrigin(baseUrl),
5399
+ reasoning: tags.includes("reasoning"),
5400
+ input: tags.includes("vision") ? ["text", "image"] : ["text"],
5401
+ cost: {
5402
+ input: pricePerMillion(raw.pricing?.input),
5403
+ output: pricePerMillion(raw.pricing?.output),
5404
+ cacheRead: pricePerMillion(raw.pricing?.input_cache_read),
5405
+ cacheWrite: 0
5406
+ },
5407
+ contextWindow: raw.context_window ?? 128e3,
5408
+ maxTokens: raw.max_tokens ?? 8192
5409
+ };
5410
+ }
5411
+ const gatewayModelCache = /* @__PURE__ */ new Map();
5412
+ const gatewayModelPending = /* @__PURE__ */ new Map();
5413
+ function gatewayModelCacheKey(modelId, baseUrl) {
5414
+ return `${resolveGatewayOrigin(baseUrl)}::${modelId}`;
5415
+ }
5416
+ function readCachedGatewayModel(cacheKey) {
5417
+ const entry = gatewayModelCache.get(cacheKey);
5418
+ if (!entry) return { cached: false };
5419
+ return {
5420
+ cached: true,
5421
+ model: entry.status === "found" ? entry.model : void 0
5422
+ };
5423
+ }
5424
+ function writeCachedGatewayModel(cacheKey, model) {
5425
+ gatewayModelCache.set(cacheKey, model ? {
5426
+ status: "found",
5427
+ model
5428
+ } : { status: "missing" });
5429
+ }
5430
+ async function fetchGatewayModel(modelId, baseUrl) {
5431
+ const cacheKey = gatewayModelCacheKey(modelId, baseUrl);
5432
+ const cached = readCachedGatewayModel(cacheKey);
5433
+ if (cached.cached) return cached.model;
5434
+ const pending = gatewayModelPending.get(cacheKey);
5435
+ if (pending) return pending;
5436
+ const request = (async () => {
5437
+ const gatewayApiKey = process.env.AI_GATEWAY_API_KEY?.trim();
5438
+ const headers = {};
5439
+ if (gatewayApiKey) headers.authorization = `Bearer ${gatewayApiKey}`;
5440
+ const url = `${resolveGatewayOrigin(baseUrl)}/v1/models/${modelId}`;
5441
+ try {
5442
+ const response = await fetch(url, { headers });
5443
+ if (!response.ok) {
5444
+ writeCachedGatewayModel(cacheKey, void 0);
5445
+ return;
5446
+ }
5447
+ const raw = parseGatewayModelResponse(await response.json());
5448
+ if (!raw) {
5449
+ writeCachedGatewayModel(cacheKey, void 0);
5450
+ return;
5451
+ }
5452
+ const model = buildGatewayModel(raw, baseUrl);
5453
+ writeCachedGatewayModel(cacheKey, model);
5454
+ return model;
5455
+ } catch {
5456
+ writeCachedGatewayModel(cacheKey, void 0);
5457
+ return;
5458
+ } finally {
5459
+ gatewayModelPending.delete(cacheKey);
5460
+ }
5461
+ })();
5462
+ gatewayModelPending.set(cacheKey, request);
5463
+ return request;
5464
+ }
5465
+ async function resolveGatewayModel(modelId) {
5466
+ const baseUrl = resolveGatewayBaseUrl();
5363
5467
  for (const candidate of agentModelIdCandidates(modelId)) {
5364
5468
  const registered = getModelLoose("vercel-ai-gateway", candidate);
5365
5469
  if (registered) {
5366
- const baseUrl = resolveGatewayBaseUrl();
5367
5470
  if (!baseUrl) return registered;
5368
5471
  return {
5369
5472
  ...registered,
@@ -5371,6 +5474,10 @@ function resolveGatewayModel(modelId) {
5371
5474
  };
5372
5475
  }
5373
5476
  }
5477
+ for (const candidate of agentModelIdCandidates(modelId)) {
5478
+ const fetched = await fetchGatewayModel(candidate, baseUrl);
5479
+ if (fetched) return fetched;
5480
+ }
5374
5481
  throw new Error(`Unknown gateway model: ${modelId}`);
5375
5482
  }
5376
5483
  function resolveDirectModel(modelId) {
@@ -5382,7 +5489,7 @@ function resolveDirectModel(modelId) {
5382
5489
  throw new Error(`Unknown model: ${modelId}`);
5383
5490
  }
5384
5491
  /** Resolve a user-authored model id to a pi-ai {@link Model} for the current runtime env. */
5385
- function resolveAgentModel(modelId) {
5492
+ async function resolveAgentModel(modelId) {
5386
5493
  if (shouldUseGatewayTransport()) return resolveGatewayModel(modelId);
5387
5494
  return resolveDirectModel(modelId);
5388
5495
  }
@@ -13940,7 +14047,7 @@ function normalizeTitle(raw) {
13940
14047
  async function generateSessionTitle(message) {
13941
14048
  const input = message.trim();
13942
14049
  if (!input) return null;
13943
- return normalizeTitle((await completeSimple(resolveAgentModel(TITLE_MODEL_ID), {
14050
+ return normalizeTitle((await completeSimple(await resolveAgentModel(TITLE_MODEL_ID), {
13944
14051
  systemPrompt: TITLE_SYSTEM_PROMPT,
13945
14052
  messages: [{
13946
14053
  role: "user",
@@ -14351,7 +14458,7 @@ async function buildAgentRuntime(def, ctx, runPrompt = {}, agentSlug) {
14351
14458
  return {
14352
14459
  ...createAgent({
14353
14460
  systemPrompt,
14354
- model: resolveAgentModel(def.model),
14461
+ model: await resolveAgentModel(def.model),
14355
14462
  thinkingLevel,
14356
14463
  messages: ctx.messages,
14357
14464
  tools
@@ -14529,7 +14636,7 @@ const RESPOND_TOOL_NAME = "respond";
14529
14636
  const STRUCTURED_OUTPUT_INSTRUCTION = "Respond only by calling `respond` with arguments matching the schema; do not answer in plain text.";
14530
14637
  const MAX_OBJECT_ATTEMPTS = 3;
14531
14638
  /** Same validation as `defineAgent` — format check before catalog lookup. */
14532
- function resolvePromptModel(model) {
14639
+ async function resolvePromptModel(model) {
14533
14640
  return resolveAgentModel(AgentModelIdSchema.parse(model));
14534
14641
  }
14535
14642
  /**
@@ -14580,7 +14687,7 @@ async function recordUsageFromMessage(message, hooks) {
14580
14687
  if (usage) await hooks?.onUsage?.(usage);
14581
14688
  }
14582
14689
  async function runPromptText(opts, hooks) {
14583
- const model = resolvePromptModel(opts.model);
14690
+ const model = await resolvePromptModel(opts.model);
14584
14691
  const reasoning = resolvePromptReasoning(opts.thinkingLevel);
14585
14692
  const message = await completeSimple(model, {
14586
14693
  systemPrompt: opts.system,
@@ -14601,7 +14708,7 @@ async function runPromptText(opts, hooks) {
14601
14708
  async function runPromptObject(opts, hooks) {
14602
14709
  const schema = opts.outputSchema;
14603
14710
  if (!schema) throw new Error("outputSchema is required for structured LLM output");
14604
- const model = resolvePromptModel(opts.model);
14711
+ const model = await resolvePromptModel(opts.model);
14605
14712
  const reasoning = resolvePromptReasoning(opts.thinkingLevel);
14606
14713
  const { toolSchema, unwrap } = wrapSchemaForTool(schema);
14607
14714
  const tool = buildRespondTool(toolSchema);