promptlayer 1.2.2 → 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.ts CHANGED
@@ -23,6 +23,89 @@ interface Pagination {
23
23
  per_page?: number;
24
24
  label?: string;
25
25
  }
26
+ interface PullSkillCollectionParams {
27
+ label?: string;
28
+ version?: number;
29
+ format?: string;
30
+ }
31
+ interface InitialSkillFileUpdate {
32
+ path: string;
33
+ content: string;
34
+ [k: string]: unknown;
35
+ }
36
+ interface SkillFileUpdate extends InitialSkillFileUpdate {
37
+ }
38
+ interface SkillFileMove {
39
+ from: string;
40
+ to: string;
41
+ [k: string]: unknown;
42
+ }
43
+ type SkillCollectionProvider = "claude_code" | "openai" | "openclaw";
44
+ interface PublishSkillCollectionFromFiles {
45
+ name: string;
46
+ folderId?: number;
47
+ provider: SkillCollectionProvider;
48
+ files?: InitialSkillFileUpdate[];
49
+ commitMessage?: string;
50
+ }
51
+ type SkillCollectionZipSource = Blob | ArrayBuffer | Uint8Array;
52
+ interface PublishSkillCollectionFromZip {
53
+ name: string;
54
+ zipFile: SkillCollectionZipSource;
55
+ fileName?: string;
56
+ folderId?: number;
57
+ provider: SkillCollectionProvider;
58
+ commitMessage?: string;
59
+ }
60
+ type PublishSkillCollection = PublishSkillCollectionFromFiles | PublishSkillCollectionFromZip;
61
+ interface SaveSkillCollectionVersion {
62
+ fileUpdates?: SkillFileUpdate[];
63
+ moves?: SkillFileMove[];
64
+ deletes?: string[];
65
+ commitMessage?: string;
66
+ releaseLabel?: string;
67
+ provider?: SkillCollectionProvider;
68
+ }
69
+ interface UpdateSkillCollection extends SaveSkillCollectionVersion {
70
+ name?: string;
71
+ }
72
+ interface SkillCollection {
73
+ id: string | number;
74
+ name: string;
75
+ provider?: SkillCollectionProvider | null;
76
+ folder_id?: number | null;
77
+ created_at?: string;
78
+ updated_at?: string;
79
+ [k: string]: unknown;
80
+ }
81
+ interface SkillCollectionVersion {
82
+ id?: string | number;
83
+ version?: number;
84
+ provider?: SkillCollectionProvider | null;
85
+ release_label?: string | null;
86
+ commit_message?: string | null;
87
+ created_at?: string;
88
+ [k: string]: unknown;
89
+ }
90
+ interface PublishSkillCollectionResponse {
91
+ success: boolean;
92
+ skill_collection: SkillCollection;
93
+ version?: SkillCollectionVersion | null;
94
+ [k: string]: unknown;
95
+ }
96
+ interface PullSkillCollectionResponse {
97
+ success: boolean;
98
+ skill_collection: SkillCollection;
99
+ files: Record<string, string>;
100
+ version: SkillCollectionVersion | null;
101
+ [k: string]: unknown;
102
+ }
103
+ interface UpdateSkillCollectionResponse {
104
+ success: boolean;
105
+ skill_collection: SkillCollection;
106
+ version?: SkillCollectionVersion | null;
107
+ [k: string]: unknown;
108
+ }
26
109
  interface CustomProvider {
27
110
  id: number;
28
111
  name: string;
@@ -39,6 +122,7 @@ interface GetPromptTemplateParams {
39
122
  metadata_filters?: Record<string, string>;
40
123
  model?: string;
41
124
  model_parameter_overrides?: Record<string, unknown>;
125
+ skip_input_variable_rendering?: boolean;
42
126
  }
43
127
  declare const templateFormat: readonly ["f-string", "jinja2"];
44
128
  type TemplateFormat = (typeof templateFormat)[number];
@@ -506,15 +590,72 @@ declare class GroupManager {
506
590
  create: () => Promise<number | boolean>;
507
591
  }
508
592
 
593
+ type PullSkillCollectionResult = PullSkillCollectionResponse | ArrayBuffer | null;
594
+
595
+ declare class SkillManager {
596
+ apiKey: string;
597
+ baseURL: string;
598
+ throwOnError: boolean;
599
+ constructor(apiKey: string, baseURL: string, throwOnError?: boolean);
600
+ pull: (identifier: string, params?: Partial<PullSkillCollectionParams>) => Promise<PullSkillCollectionResult>;
601
+ publish: (body: PublishSkillCollection) => Promise<PublishSkillCollectionResponse | null>;
602
+ update: (identifier: string, body: UpdateSkillCollection) => Promise<UpdateSkillCollectionResponse | null>;
603
+ }
604
+
509
605
  declare const wrapWithSpan: (functionName: string, func: Function, attributes?: Record<string, any>) => (...args: any[]) => any;
510
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
+
511
648
  declare class TemplateManager {
512
649
  apiKey: string;
513
650
  baseURL: string;
514
651
  throwOnError: boolean;
515
- constructor(apiKey: string, baseURL: string, throwOnError?: boolean);
652
+ private _cache;
653
+ constructor(apiKey: string, baseURL: string, throwOnError?: boolean, cache?: PromptTemplateCache | null);
516
654
  get: (promptName: string, params?: Partial<GetPromptTemplateParams>) => Promise<GetPromptTemplateResponse | null>;
655
+ private _fetchNormal;
656
+ private _getWithCache;
517
657
  publish: (body: PublishPromptTemplate) => Promise<PublishPromptTemplateResponse>;
658
+ invalidate: (promptName?: string) => void;
518
659
  all: (params?: Pagination) => Promise<ListPromptTemplatesResponse[]>;
519
660
  }
520
661
 
@@ -535,17 +676,25 @@ interface ClientOptions {
535
676
  workspaceId?: number;
536
677
  throwOnError?: boolean;
537
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;
538
685
  }
539
686
  declare class PromptLayer {
540
687
  apiKey: string;
541
688
  baseURL: string;
542
689
  templates: TemplateManager;
690
+ skills: SkillManager;
543
691
  group: GroupManager;
544
692
  track: TrackManager;
545
693
  enableTracing: boolean;
546
694
  throwOnError: boolean;
547
695
  wrapWithSpan: typeof wrapWithSpan;
548
- constructor({ apiKey, baseURL, enableTracing, throwOnError, }?: ClientOptions);
696
+ constructor({ apiKey, baseURL, enableTracing, throwOnError, cacheTtlSeconds, }?: ClientOptions);
697
+ invalidate(promptName?: string): void;
549
698
  get Anthropic(): any;
550
699
  get OpenAI(): any;
551
700
  run({ promptName, promptVersion, promptReleaseLabel, inputVariables, tags, metadata, groupId, modelParameterOverrides, stream, provider, model, }: RunRequest): Promise<AsyncGenerator<{
@@ -562,4 +711,4 @@ declare class PromptLayer {
562
711
  logRequest(body: LogRequest): Promise<RequestLog | null>;
563
712
  }
564
713
 
565
- export { type ClientOptions, PromptLayer };
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 };