promptlayer 1.3.0 → 1.3.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/dist/index.d.mts CHANGED
@@ -41,7 +41,7 @@ interface SkillFileMove {
41
41
  [k: string]: unknown;
42
42
  }
43
43
  type SkillCollectionProvider = "claude_code" | "openai" | "openclaw";
44
- interface CreateSkillCollection {
44
+ interface PublishSkillCollectionFromFiles {
45
45
  name: string;
46
46
  folderId?: number;
47
47
  provider: SkillCollectionProvider;
@@ -57,7 +57,7 @@ interface PublishSkillCollectionFromZip {
57
57
  provider: SkillCollectionProvider;
58
58
  commitMessage?: string;
59
59
  }
60
- type PublishSkillCollection = CreateSkillCollection | PublishSkillCollectionFromZip;
60
+ type PublishSkillCollection = PublishSkillCollectionFromFiles | PublishSkillCollectionFromZip;
61
61
  interface SaveSkillCollectionVersion {
62
62
  fileUpdates?: SkillFileUpdate[];
63
63
  moves?: SkillFileMove[];
@@ -87,13 +87,12 @@ interface SkillCollectionVersion {
87
87
  created_at?: string;
88
88
  [k: string]: unknown;
89
89
  }
90
- interface CreateSkillCollectionResponse {
90
+ interface PublishSkillCollectionResponse {
91
91
  success: boolean;
92
92
  skill_collection: SkillCollection;
93
93
  version?: SkillCollectionVersion | null;
94
94
  [k: string]: unknown;
95
95
  }
96
- type PublishSkillCollectionResponse = CreateSkillCollectionResponse;
97
96
  interface PullSkillCollectionResponse {
98
97
  success: boolean;
99
98
  skill_collection: SkillCollection;
@@ -123,6 +122,7 @@ interface GetPromptTemplateParams {
123
122
  metadata_filters?: Record<string, string>;
124
123
  model?: string;
125
124
  model_parameter_overrides?: Record<string, unknown>;
125
+ skip_input_variable_rendering?: boolean;
126
126
  }
127
127
  declare const templateFormat: readonly ["f-string", "jinja2"];
128
128
  type TemplateFormat = (typeof templateFormat)[number];
@@ -604,13 +604,58 @@ declare class SkillManager {
604
604
 
605
605
  declare const wrapWithSpan: (functionName: string, func: Function, attributes?: Record<string, any>) => (...args: any[]) => any;
606
606
 
607
+ /**
608
+ * Tuple: [promptName, version, label, provider, model]
609
+ * Serialized to a JSON string for use as a Map key.
610
+ */
611
+ type CacheKeyTuple = [
612
+ string,
613
+ number | null,
614
+ string | null,
615
+ string | null,
616
+ string | null
617
+ ];
618
+ /**
619
+ * In-memory TTL cache for prompt templates.
620
+ *
621
+ * Stores unrendered API responses keyed by (promptName, version, label,
622
+ * provider, model). Supports stale-while-error: if the TTL has expired but
623
+ * the API is unreachable, the stale entry can be re-rendered as a fallback.
624
+ */
625
+ declare class PromptTemplateCache {
626
+ private readonly ttlMs;
627
+ private readonly maxSize;
628
+ private readonly entries;
629
+ private readonly nonRenderable;
630
+ constructor(ttlSeconds: number, maxSize?: number);
631
+ static makeKey(promptName: string, params?: Record<string, unknown> | null): CacheKeyTuple;
632
+ private static serialize;
633
+ /**
634
+ * Returns `[deepClone | null, isFresh]`.
635
+ * The returned object is safe to mutate.
636
+ */
637
+ get(key: CacheKeyTuple): [Record<string, unknown> | null, boolean];
638
+ put(key: CacheKeyTuple, response: Record<string, unknown>): void;
639
+ isNonRenderable(key: CacheKeyTuple): boolean;
640
+ markNonRenderable(key: CacheKeyTuple): void;
641
+ clear(): void;
642
+ /** Remove all entries whose cache key starts with `promptName`. */
643
+ invalidate(promptName: string): void;
644
+ private evictOldestEntry;
645
+ private evictOldestNonRenderable;
646
+ }
647
+
607
648
  declare class TemplateManager {
608
649
  apiKey: string;
609
650
  baseURL: string;
610
651
  throwOnError: boolean;
611
- constructor(apiKey: string, baseURL: string, throwOnError?: boolean);
652
+ private _cache;
653
+ constructor(apiKey: string, baseURL: string, throwOnError?: boolean, cache?: PromptTemplateCache | null);
612
654
  get: (promptName: string, params?: Partial<GetPromptTemplateParams>) => Promise<GetPromptTemplateResponse | null>;
655
+ private _fetchNormal;
656
+ private _getWithCache;
613
657
  publish: (body: PublishPromptTemplate) => Promise<PublishPromptTemplateResponse>;
658
+ invalidate: (promptName?: string) => void;
614
659
  all: (params?: Pagination) => Promise<ListPromptTemplatesResponse[]>;
615
660
  }
616
661
 
@@ -631,6 +676,12 @@ interface ClientOptions {
631
676
  workspaceId?: number;
632
677
  throwOnError?: boolean;
633
678
  baseURL?: string;
679
+ /**
680
+ * When > 0, enables in-memory TTL caching of prompt templates.
681
+ * Templates are fetched unrendered and substituted locally, reducing
682
+ * API calls. Default: 0 (disabled).
683
+ */
684
+ cacheTtlSeconds?: number;
634
685
  }
635
686
  declare class PromptLayer {
636
687
  apiKey: string;
@@ -642,7 +693,8 @@ declare class PromptLayer {
642
693
  enableTracing: boolean;
643
694
  throwOnError: boolean;
644
695
  wrapWithSpan: typeof wrapWithSpan;
645
- constructor({ apiKey, baseURL, enableTracing, throwOnError, }?: ClientOptions);
696
+ constructor({ apiKey, baseURL, enableTracing, throwOnError, cacheTtlSeconds, }?: ClientOptions);
697
+ invalidate(promptName?: string): void;
646
698
  get Anthropic(): any;
647
699
  get OpenAI(): any;
648
700
  run({ promptName, promptVersion, promptReleaseLabel, inputVariables, tags, metadata, groupId, modelParameterOverrides, stream, provider, model, }: RunRequest): Promise<AsyncGenerator<{
@@ -659,4 +711,4 @@ declare class PromptLayer {
659
711
  logRequest(body: LogRequest): Promise<RequestLog | null>;
660
712
  }
661
713
 
662
- export { type ClientOptions, type CreateSkillCollection, type CreateSkillCollectionResponse, type InitialSkillFileUpdate, PromptLayer, type PublishSkillCollection, type PublishSkillCollectionFromZip, type PublishSkillCollectionResponse, type PullSkillCollectionParams, type PullSkillCollectionResponse, type SaveSkillCollectionVersion, type SkillCollection, type SkillCollectionVersion, type SkillFileMove, type SkillFileUpdate, type UpdateSkillCollection, type UpdateSkillCollectionResponse };
714
+ export { type ClientOptions, type InitialSkillFileUpdate, PromptLayer, type PublishSkillCollection, type PublishSkillCollectionFromFiles, type PublishSkillCollectionFromZip, type PublishSkillCollectionResponse, type PullSkillCollectionParams, type PullSkillCollectionResponse, type SaveSkillCollectionVersion, type SkillCollection, type SkillCollectionVersion, type SkillFileMove, type SkillFileUpdate, type UpdateSkillCollection, type UpdateSkillCollectionResponse };
package/dist/index.d.ts CHANGED
@@ -41,7 +41,7 @@ interface SkillFileMove {
41
41
  [k: string]: unknown;
42
42
  }
43
43
  type SkillCollectionProvider = "claude_code" | "openai" | "openclaw";
44
- interface CreateSkillCollection {
44
+ interface PublishSkillCollectionFromFiles {
45
45
  name: string;
46
46
  folderId?: number;
47
47
  provider: SkillCollectionProvider;
@@ -57,7 +57,7 @@ interface PublishSkillCollectionFromZip {
57
57
  provider: SkillCollectionProvider;
58
58
  commitMessage?: string;
59
59
  }
60
- type PublishSkillCollection = CreateSkillCollection | PublishSkillCollectionFromZip;
60
+ type PublishSkillCollection = PublishSkillCollectionFromFiles | PublishSkillCollectionFromZip;
61
61
  interface SaveSkillCollectionVersion {
62
62
  fileUpdates?: SkillFileUpdate[];
63
63
  moves?: SkillFileMove[];
@@ -87,13 +87,12 @@ interface SkillCollectionVersion {
87
87
  created_at?: string;
88
88
  [k: string]: unknown;
89
89
  }
90
- interface CreateSkillCollectionResponse {
90
+ interface PublishSkillCollectionResponse {
91
91
  success: boolean;
92
92
  skill_collection: SkillCollection;
93
93
  version?: SkillCollectionVersion | null;
94
94
  [k: string]: unknown;
95
95
  }
96
- type PublishSkillCollectionResponse = CreateSkillCollectionResponse;
97
96
  interface PullSkillCollectionResponse {
98
97
  success: boolean;
99
98
  skill_collection: SkillCollection;
@@ -123,6 +122,7 @@ interface GetPromptTemplateParams {
123
122
  metadata_filters?: Record<string, string>;
124
123
  model?: string;
125
124
  model_parameter_overrides?: Record<string, unknown>;
125
+ skip_input_variable_rendering?: boolean;
126
126
  }
127
127
  declare const templateFormat: readonly ["f-string", "jinja2"];
128
128
  type TemplateFormat = (typeof templateFormat)[number];
@@ -604,13 +604,58 @@ declare class SkillManager {
604
604
 
605
605
  declare const wrapWithSpan: (functionName: string, func: Function, attributes?: Record<string, any>) => (...args: any[]) => any;
606
606
 
607
+ /**
608
+ * Tuple: [promptName, version, label, provider, model]
609
+ * Serialized to a JSON string for use as a Map key.
610
+ */
611
+ type CacheKeyTuple = [
612
+ string,
613
+ number | null,
614
+ string | null,
615
+ string | null,
616
+ string | null
617
+ ];
618
+ /**
619
+ * In-memory TTL cache for prompt templates.
620
+ *
621
+ * Stores unrendered API responses keyed by (promptName, version, label,
622
+ * provider, model). Supports stale-while-error: if the TTL has expired but
623
+ * the API is unreachable, the stale entry can be re-rendered as a fallback.
624
+ */
625
+ declare class PromptTemplateCache {
626
+ private readonly ttlMs;
627
+ private readonly maxSize;
628
+ private readonly entries;
629
+ private readonly nonRenderable;
630
+ constructor(ttlSeconds: number, maxSize?: number);
631
+ static makeKey(promptName: string, params?: Record<string, unknown> | null): CacheKeyTuple;
632
+ private static serialize;
633
+ /**
634
+ * Returns `[deepClone | null, isFresh]`.
635
+ * The returned object is safe to mutate.
636
+ */
637
+ get(key: CacheKeyTuple): [Record<string, unknown> | null, boolean];
638
+ put(key: CacheKeyTuple, response: Record<string, unknown>): void;
639
+ isNonRenderable(key: CacheKeyTuple): boolean;
640
+ markNonRenderable(key: CacheKeyTuple): void;
641
+ clear(): void;
642
+ /** Remove all entries whose cache key starts with `promptName`. */
643
+ invalidate(promptName: string): void;
644
+ private evictOldestEntry;
645
+ private evictOldestNonRenderable;
646
+ }
647
+
607
648
  declare class TemplateManager {
608
649
  apiKey: string;
609
650
  baseURL: string;
610
651
  throwOnError: boolean;
611
- constructor(apiKey: string, baseURL: string, throwOnError?: boolean);
652
+ private _cache;
653
+ constructor(apiKey: string, baseURL: string, throwOnError?: boolean, cache?: PromptTemplateCache | null);
612
654
  get: (promptName: string, params?: Partial<GetPromptTemplateParams>) => Promise<GetPromptTemplateResponse | null>;
655
+ private _fetchNormal;
656
+ private _getWithCache;
613
657
  publish: (body: PublishPromptTemplate) => Promise<PublishPromptTemplateResponse>;
658
+ invalidate: (promptName?: string) => void;
614
659
  all: (params?: Pagination) => Promise<ListPromptTemplatesResponse[]>;
615
660
  }
616
661
 
@@ -631,6 +676,12 @@ interface ClientOptions {
631
676
  workspaceId?: number;
632
677
  throwOnError?: boolean;
633
678
  baseURL?: string;
679
+ /**
680
+ * When > 0, enables in-memory TTL caching of prompt templates.
681
+ * Templates are fetched unrendered and substituted locally, reducing
682
+ * API calls. Default: 0 (disabled).
683
+ */
684
+ cacheTtlSeconds?: number;
634
685
  }
635
686
  declare class PromptLayer {
636
687
  apiKey: string;
@@ -642,7 +693,8 @@ declare class PromptLayer {
642
693
  enableTracing: boolean;
643
694
  throwOnError: boolean;
644
695
  wrapWithSpan: typeof wrapWithSpan;
645
- constructor({ apiKey, baseURL, enableTracing, throwOnError, }?: ClientOptions);
696
+ constructor({ apiKey, baseURL, enableTracing, throwOnError, cacheTtlSeconds, }?: ClientOptions);
697
+ invalidate(promptName?: string): void;
646
698
  get Anthropic(): any;
647
699
  get OpenAI(): any;
648
700
  run({ promptName, promptVersion, promptReleaseLabel, inputVariables, tags, metadata, groupId, modelParameterOverrides, stream, provider, model, }: RunRequest): Promise<AsyncGenerator<{
@@ -659,4 +711,4 @@ declare class PromptLayer {
659
711
  logRequest(body: LogRequest): Promise<RequestLog | null>;
660
712
  }
661
713
 
662
- export { type ClientOptions, type CreateSkillCollection, type CreateSkillCollectionResponse, type InitialSkillFileUpdate, PromptLayer, type PublishSkillCollection, type PublishSkillCollectionFromZip, type PublishSkillCollectionResponse, type PullSkillCollectionParams, type PullSkillCollectionResponse, type SaveSkillCollectionVersion, type SkillCollection, type SkillCollectionVersion, type SkillFileMove, type SkillFileUpdate, type UpdateSkillCollection, type UpdateSkillCollectionResponse };
714
+ export { type ClientOptions, type InitialSkillFileUpdate, PromptLayer, type PublishSkillCollection, type PublishSkillCollectionFromFiles, type PublishSkillCollectionFromZip, type PublishSkillCollectionResponse, type PullSkillCollectionParams, type PullSkillCollectionResponse, type SaveSkillCollectionVersion, type SkillCollection, type SkillCollectionVersion, type SkillFileMove, type SkillFileUpdate, type UpdateSkillCollection, type UpdateSkillCollectionResponse };