@paddockai/server 0.0.4 → 0.0.5
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.cjs +80 -135
- package/dist/index.d.cts +578 -605
- package/dist/index.d.ts +578 -605
- package/dist/index.js +79 -123
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -11,8 +11,10 @@ var streamEventNames = [
|
|
|
11
11
|
"config.applied",
|
|
12
12
|
"session.status",
|
|
13
13
|
"outbox.queued",
|
|
14
|
+
"outbox.retrying",
|
|
14
15
|
"outbox.delivered",
|
|
15
16
|
"outbox.failed",
|
|
17
|
+
"inbox.failed",
|
|
16
18
|
"status.update",
|
|
17
19
|
"error"
|
|
18
20
|
];
|
|
@@ -513,9 +515,12 @@ var SessionOperations = class {
|
|
|
513
515
|
get base() {
|
|
514
516
|
return `/sessions/${segment(this.id)}`;
|
|
515
517
|
}
|
|
516
|
-
/**
|
|
517
|
-
|
|
518
|
-
|
|
518
|
+
/**
|
|
519
|
+
* Stores a user message; resolves with its event once stored (004#messages). author, the person
|
|
520
|
+
* the message speaks for, is allowed with an API key or a function token, never a session token.
|
|
521
|
+
*/
|
|
522
|
+
send(text, options = {}) {
|
|
523
|
+
return this.transport.request({ method: "POST", path: `${this.base}/messages`, json: { text, ...options } });
|
|
519
524
|
}
|
|
520
525
|
/** Stores a stop.requested event and resolves with it. */
|
|
521
526
|
stop() {
|
|
@@ -525,13 +530,15 @@ var SessionOperations = class {
|
|
|
525
530
|
stream(options = {}) {
|
|
526
531
|
return new EventStream(this.transport, `${this.base}/stream`, options);
|
|
527
532
|
}
|
|
528
|
-
/**
|
|
533
|
+
/**
|
|
534
|
+
* Mints a session token for the browser: ttl in seconds; participant authors the token's
|
|
535
|
+
* messages; readOnly makes a token that can only read and follow the session (004#credentials).
|
|
536
|
+
*/
|
|
529
537
|
createToken(options) {
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
});
|
|
538
|
+
const json = { ttlSeconds: options.ttl };
|
|
539
|
+
if (options.participant) json.participant = options.participant;
|
|
540
|
+
if (options.readOnly) json.readOnly = true;
|
|
541
|
+
return this.transport.request({ method: "POST", path: `${this.base}/tokens`, json });
|
|
535
542
|
}
|
|
536
543
|
/** Reads the session. */
|
|
537
544
|
get() {
|
|
@@ -540,7 +547,7 @@ var SessionOperations = class {
|
|
|
540
547
|
};
|
|
541
548
|
|
|
542
549
|
// src/version.ts
|
|
543
|
-
var version = "0.0.
|
|
550
|
+
var version = "0.0.5";
|
|
544
551
|
|
|
545
552
|
// src/client.ts
|
|
546
553
|
function nodeProcess() {
|
|
@@ -623,7 +630,7 @@ var Paddock = class {
|
|
|
623
630
|
modelProviders;
|
|
624
631
|
agents;
|
|
625
632
|
sessions;
|
|
626
|
-
|
|
633
|
+
inbox;
|
|
627
634
|
outbox;
|
|
628
635
|
constructor(options = {}) {
|
|
629
636
|
const { apiKey, baseUrl } = lookup(options);
|
|
@@ -640,7 +647,7 @@ var Paddock = class {
|
|
|
640
647
|
this.modelProviders = new ModelProviders(transport);
|
|
641
648
|
this.agents = new Agents(transport);
|
|
642
649
|
this.sessions = new Sessions(transport);
|
|
643
|
-
this.
|
|
650
|
+
this.inbox = new Inbox(transport);
|
|
644
651
|
this.outbox = new Outbox(transport);
|
|
645
652
|
}
|
|
646
653
|
};
|
|
@@ -650,18 +657,35 @@ var Templates = class {
|
|
|
650
657
|
}
|
|
651
658
|
t;
|
|
652
659
|
/**
|
|
653
|
-
*
|
|
654
|
-
*
|
|
655
|
-
*
|
|
656
|
-
*
|
|
660
|
+
* Creates a template version from a bundle, the gzip tar that `paddock templates create DIR`
|
|
661
|
+
* builds from a template directory (014#build). secrets holds values of the template's
|
|
662
|
+
* template secrets. The server assigns the version; a bundle whose digest equals the latest
|
|
663
|
+
* version returns that version. With dryRun, the server checks everything and returns the
|
|
664
|
+
* version a create would return, storing nothing.
|
|
657
665
|
*/
|
|
658
|
-
async create(
|
|
666
|
+
async create(bundle, options = {}) {
|
|
659
667
|
const query = options.dryRun ? { dryRun: true } : void 0;
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
668
|
+
const form = new FormData();
|
|
669
|
+
const blob = bundle instanceof Blob ? bundle : new Blob([bundle], { type: "application/gzip" });
|
|
670
|
+
form.append("bundle", blob, "bundle.tar.gz");
|
|
671
|
+
if (options.secrets && Object.keys(options.secrets).length > 0)
|
|
672
|
+
form.append("secrets", JSON.stringify(options.secrets));
|
|
673
|
+
return this.t.request({ method: "POST", path: "/templates", query, body: form });
|
|
674
|
+
}
|
|
675
|
+
/** Each inbox entry of a template name's latest version with its template URL (010#endpoints). */
|
|
676
|
+
async inbox(name) {
|
|
677
|
+
return (await this.t.request({ method: "GET", path: `/templates/${segment(name)}/inbox` })).data;
|
|
678
|
+
}
|
|
679
|
+
/** A template name's template secrets, shared by its versions: names and set times, never values. */
|
|
680
|
+
secrets(name) {
|
|
681
|
+
const base = `/templates/${segment(name)}/secrets`;
|
|
682
|
+
return {
|
|
683
|
+
list: async () => (await this.t.request({ method: "GET", path: base })).data,
|
|
684
|
+
set: (secret, value) => this.t.request({ method: "PUT", path: `${base}/${segment(secret)}`, json: { value } }),
|
|
685
|
+
delete: async (secret) => {
|
|
686
|
+
await this.t.request({ method: "DELETE", path: `${base}/${segment(secret)}`, read: "none" });
|
|
687
|
+
}
|
|
688
|
+
};
|
|
665
689
|
}
|
|
666
690
|
/** "name@version" reads that version; "name" reads the latest. */
|
|
667
691
|
get(ref) {
|
|
@@ -741,6 +765,11 @@ var Agents = class {
|
|
|
741
765
|
this.t = t;
|
|
742
766
|
}
|
|
743
767
|
t;
|
|
768
|
+
/**
|
|
769
|
+
* Creates an agent from "name@version". env holds its own env values, which override the
|
|
770
|
+
* template's by name; secrets a value for every agent secret the template declares; harness,
|
|
771
|
+
* when given, replaces the template's harness block for this agent (014#harness-override).
|
|
772
|
+
*/
|
|
744
773
|
async create(options) {
|
|
745
774
|
return agentHandle(this.t, await this.t.request({ method: "POST", path: "/agents", json: options }));
|
|
746
775
|
}
|
|
@@ -841,8 +870,10 @@ var AgentResources = class {
|
|
|
841
870
|
/** The value is null when neither the agent nor its template sets one. */
|
|
842
871
|
systemPrompt;
|
|
843
872
|
workflows;
|
|
844
|
-
/** The agent's effective
|
|
873
|
+
/** The agent's effective configuration as paddock.yaml in JSON, secrets by name only. */
|
|
845
874
|
export;
|
|
875
|
+
/** The agent's secrets: names and set times, never values. */
|
|
876
|
+
secrets;
|
|
846
877
|
/**
|
|
847
878
|
* Sends text to the agent's default session, its newest session whose defaultSession
|
|
848
879
|
* metadata is "true", created on the first send; resolves with the stored user
|
|
@@ -850,8 +881,6 @@ var AgentResources = class {
|
|
|
850
881
|
*/
|
|
851
882
|
send;
|
|
852
883
|
permissions;
|
|
853
|
-
/** The key patterns the agent may send to: its own list, or else the template's (015#allow). */
|
|
854
|
-
outbox;
|
|
855
884
|
memory;
|
|
856
885
|
files;
|
|
857
886
|
sessions;
|
|
@@ -867,16 +896,15 @@ var AgentResources = class {
|
|
|
867
896
|
const workflows = new Collection(t, `${base}/workflows`);
|
|
868
897
|
this.workflows = { list: (o) => workflows.list(o), get: (name) => workflows.get(name) };
|
|
869
898
|
this.export = () => t.request({ method: "GET", path: `${base}/export` });
|
|
870
|
-
this.
|
|
899
|
+
this.secrets = {
|
|
900
|
+
list: async () => (await t.request({ method: "GET", path: `${base}/secrets` })).data,
|
|
901
|
+
set: (name, value) => t.request({ method: "PUT", path: `${base}/secrets/${segment(name)}`, json: { value } })
|
|
902
|
+
};
|
|
903
|
+
this.send = (text, options = {}) => t.request({ method: "POST", path: `${base}/messages`, json: { text, ...options } });
|
|
871
904
|
this.permissions = {
|
|
872
905
|
get: () => t.request({ method: "GET", path: `${base}/permissions` }),
|
|
873
906
|
set: (spec) => t.request({ method: "PUT", path: `${base}/permissions`, json: spec })
|
|
874
907
|
};
|
|
875
|
-
this.outbox = {
|
|
876
|
-
get: () => t.request({ method: "GET", path: `${base}/outbox` }),
|
|
877
|
-
set: (spec) => t.request({ method: "PUT", path: `${base}/outbox`, json: spec }),
|
|
878
|
-
delete: () => t.request({ method: "DELETE", path: `${base}/outbox` })
|
|
879
|
-
};
|
|
880
908
|
const memoryPath = (p) => `${base}/memory/${segment(p, true)}`;
|
|
881
909
|
this.memory = {
|
|
882
910
|
list: () => t.request({ method: "GET", path: `${base}/memory`, timeoutMs: longTimeoutMs }),
|
|
@@ -924,7 +952,7 @@ var AgentResources = class {
|
|
|
924
952
|
const page = await t.request({
|
|
925
953
|
method: "GET",
|
|
926
954
|
path: `${base}/sessions`,
|
|
927
|
-
query: { metadata: o.metadata, limit: o.limit, cursor: cursor ?? o.cursor }
|
|
955
|
+
query: { metadata: o.metadata, key: o.key, limit: o.limit, cursor: cursor ?? o.cursor }
|
|
928
956
|
});
|
|
929
957
|
return { ...page, data: page.data.map((s) => sessionHandle(t, s)) };
|
|
930
958
|
})
|
|
@@ -962,6 +990,7 @@ var Sessions = class {
|
|
|
962
990
|
query: {
|
|
963
991
|
agentId: options.agentId,
|
|
964
992
|
metadata: options.metadata,
|
|
993
|
+
key: options.key,
|
|
965
994
|
createdAfter: options.createdAfter,
|
|
966
995
|
createdBefore: options.createdBefore,
|
|
967
996
|
limit: options.limit,
|
|
@@ -978,116 +1007,43 @@ var Sessions = class {
|
|
|
978
1007
|
await this.t.request({ method: "DELETE", path: `/sessions/${segment(id)}`, read: "none" });
|
|
979
1008
|
}
|
|
980
1009
|
};
|
|
981
|
-
var
|
|
982
|
-
constructor(t) {
|
|
983
|
-
this.t = t;
|
|
984
|
-
}
|
|
985
|
-
t;
|
|
986
|
-
/** Creates a connector with the sides given; the secret is generated when omitted. */
|
|
987
|
-
async create(spec) {
|
|
988
|
-
return connectorHandle(
|
|
989
|
-
this.t,
|
|
990
|
-
await this.t.request({ method: "POST", path: "/connectors", json: spec })
|
|
991
|
-
);
|
|
992
|
-
}
|
|
993
|
-
/** The connectors, newest first. */
|
|
994
|
-
list(options = {}) {
|
|
995
|
-
return new PageList(async (cursor) => {
|
|
996
|
-
const page = await this.t.request({
|
|
997
|
-
method: "GET",
|
|
998
|
-
path: "/connectors",
|
|
999
|
-
query: { limit: options.limit, cursor: cursor ?? options.cursor }
|
|
1000
|
-
});
|
|
1001
|
-
return { ...page, data: page.data.map((c) => connectorHandle(this.t, c)) };
|
|
1002
|
-
});
|
|
1003
|
-
}
|
|
1004
|
-
/** By ID or by name. */
|
|
1005
|
-
async get(idOrName) {
|
|
1006
|
-
return connectorHandle(
|
|
1007
|
-
this.t,
|
|
1008
|
-
await this.t.request({ method: "GET", path: `/connectors/${segment(idOrName)}` })
|
|
1009
|
-
);
|
|
1010
|
-
}
|
|
1011
|
-
/** Sets which sides exist and the outbound rate limit; a side omitted or null is removed with its function. */
|
|
1012
|
-
async update(id, spec) {
|
|
1013
|
-
return connectorHandle(
|
|
1014
|
-
this.t,
|
|
1015
|
-
await this.t.request({ method: "PUT", path: `/connectors/${segment(id)}`, json: spec })
|
|
1016
|
-
);
|
|
1017
|
-
}
|
|
1018
|
-
/** Deletes its functions first; its URL answers 404 at once, and its deliveries and outbox messages are removed. */
|
|
1019
|
-
async delete(id) {
|
|
1020
|
-
await this.t.request({ method: "DELETE", path: `/connectors/${segment(id)}`, read: "none" });
|
|
1021
|
-
}
|
|
1022
|
-
/** Stock function code per side, in both runtimes, with the params each reads (015#presets). */
|
|
1023
|
-
async functionPresets() {
|
|
1024
|
-
const out = await this.t.request({
|
|
1025
|
-
method: "GET",
|
|
1026
|
-
path: "/connectors/function-presets"
|
|
1027
|
-
});
|
|
1028
|
-
return out.presets;
|
|
1029
|
-
}
|
|
1030
|
-
};
|
|
1031
|
-
var ConnectorResources = class {
|
|
1032
|
-
/** The connector's named secrets, whose values only these return; name defaults to "default". */
|
|
1033
|
-
secret;
|
|
1034
|
-
/** The code each side runs: inbound on every request, outbound on every message sent. */
|
|
1035
|
-
functions;
|
|
1010
|
+
var Inbox = class {
|
|
1036
1011
|
deliveries;
|
|
1037
|
-
constructor(t
|
|
1038
|
-
const base = `/connectors/${segment(connectorId)}`;
|
|
1039
|
-
this.secret = {
|
|
1040
|
-
get: (o = {}) => t.request({ method: "GET", path: `${base}/secret`, query: { name: o.name } }),
|
|
1041
|
-
rotate: (o = {}) => t.request({ method: "POST", path: `${base}/secret`, json: o }),
|
|
1042
|
-
delete: async (o) => {
|
|
1043
|
-
await t.request({ method: "DELETE", path: `${base}/secret`, query: { name: o.name }, read: "none" });
|
|
1044
|
-
}
|
|
1045
|
-
};
|
|
1046
|
-
const fn = (side) => `${base}/functions/${segment(side)}`;
|
|
1047
|
-
this.functions = {
|
|
1048
|
-
get: (side) => t.request({ method: "GET", path: fn(side) }),
|
|
1049
|
-
set: (side, spec) => t.request({ method: "PUT", path: fn(side), json: spec }),
|
|
1050
|
-
delete: async (side) => {
|
|
1051
|
-
await t.request({ method: "DELETE", path: fn(side), read: "none" });
|
|
1052
|
-
},
|
|
1053
|
-
test: (side, request) => t.request({ method: "POST", path: `${fn(side)}/test`, json: request })
|
|
1054
|
-
};
|
|
1012
|
+
constructor(t) {
|
|
1055
1013
|
this.deliveries = {
|
|
1056
1014
|
list: (o = {}) => new PageList(
|
|
1057
1015
|
(cursor) => t.request({
|
|
1058
1016
|
method: "GET",
|
|
1059
|
-
path:
|
|
1060
|
-
query: {
|
|
1017
|
+
path: "/inbox/deliveries",
|
|
1018
|
+
query: {
|
|
1019
|
+
template: o.template,
|
|
1020
|
+
entry: o.entry,
|
|
1021
|
+
agentId: o.agentId,
|
|
1022
|
+
status: o.status,
|
|
1023
|
+
limit: o.limit,
|
|
1024
|
+
cursor: cursor ?? o.cursor
|
|
1025
|
+
}
|
|
1061
1026
|
})
|
|
1062
1027
|
),
|
|
1063
|
-
get: (id) => t.request({ method: "GET", path:
|
|
1064
|
-
replay: (id) => t.request({ method: "POST", path:
|
|
1028
|
+
get: (id) => t.request({ method: "GET", path: `/inbox/deliveries/${segment(id)}` }),
|
|
1029
|
+
replay: (id) => t.request({ method: "POST", path: `/inbox/deliveries/${segment(id)}/replay` })
|
|
1065
1030
|
};
|
|
1066
1031
|
}
|
|
1067
1032
|
};
|
|
1068
|
-
function connectorHandle(t, connector) {
|
|
1069
|
-
const resources = new ConnectorResources(t, connector.id);
|
|
1070
|
-
const handle = { ...connector };
|
|
1071
|
-
for (const [name, value] of Object.entries(resources)) {
|
|
1072
|
-
Object.defineProperty(handle, name, { value, enumerable: false });
|
|
1073
|
-
}
|
|
1074
|
-
return handle;
|
|
1075
|
-
}
|
|
1076
1033
|
var Outbox = class {
|
|
1077
1034
|
constructor(t) {
|
|
1078
1035
|
this.t = t;
|
|
1079
1036
|
}
|
|
1080
1037
|
t;
|
|
1081
|
-
/**
|
|
1038
|
+
/** Outbox messages newest first; every filter left out matches all. */
|
|
1082
1039
|
list(options = {}) {
|
|
1083
1040
|
return new PageList(
|
|
1084
1041
|
(cursor) => this.t.request({
|
|
1085
1042
|
method: "GET",
|
|
1086
1043
|
path: "/outbox",
|
|
1087
1044
|
query: {
|
|
1088
|
-
|
|
1045
|
+
agentId: options.agentId,
|
|
1089
1046
|
sessionId: options.sessionId,
|
|
1090
|
-
key: options.key,
|
|
1091
1047
|
status: options.status,
|
|
1092
1048
|
limit: options.limit,
|
|
1093
1049
|
cursor: cursor ?? options.cursor
|
|
@@ -1095,10 +1051,11 @@ var Outbox = class {
|
|
|
1095
1051
|
})
|
|
1096
1052
|
);
|
|
1097
1053
|
}
|
|
1054
|
+
/** A message with each entry's deliver step and each target input's status, attempts, and last answer. */
|
|
1098
1055
|
get(id) {
|
|
1099
1056
|
return this.t.request({ method: "GET", path: `/outbox/${segment(id)}` });
|
|
1100
1057
|
}
|
|
1101
|
-
/** Queues
|
|
1058
|
+
/** Queues the message's failed steps again with their idempotency keys and their places in order. */
|
|
1102
1059
|
retry(id) {
|
|
1103
1060
|
return this.t.request({ method: "POST", path: `/outbox/${segment(id)}/retry` });
|
|
1104
1061
|
}
|
|
@@ -1107,9 +1064,8 @@ export {
|
|
|
1107
1064
|
AgentResources,
|
|
1108
1065
|
Agents,
|
|
1109
1066
|
Collection,
|
|
1110
|
-
ConnectorResources,
|
|
1111
|
-
Connectors,
|
|
1112
1067
|
EventStream,
|
|
1068
|
+
Inbox,
|
|
1113
1069
|
Marketplaces,
|
|
1114
1070
|
ModelProviders,
|
|
1115
1071
|
Models,
|