@agentplat/framework 0.2.0-beta.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/LICENSE +202 -0
- package/README.md +22 -0
- package/dist/index.d.ts +73 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +139 -0
- package/dist/index.js.map +1 -0
- package/package.json +39 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
202
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# @agentplat/framework
|
|
2
|
+
|
|
3
|
+
High-level composition for applications that want a short path to AgentPlat
|
|
4
|
+
without hiding the replaceable runtime and Room contracts.
|
|
5
|
+
|
|
6
|
+
```ts
|
|
7
|
+
import { AgentPlat } from '@agentplat/framework';
|
|
8
|
+
import { openAICompatible } from '@agentplat/model-openai-compatible';
|
|
9
|
+
|
|
10
|
+
const result = await AgentPlat.quickRun({
|
|
11
|
+
adapter: openAICompatible({
|
|
12
|
+
apiKey: process.env.OPENAI_API_KEY,
|
|
13
|
+
defaultModel: process.env.OPENAI_MODEL,
|
|
14
|
+
}),
|
|
15
|
+
instructions: 'Be concise.',
|
|
16
|
+
input: 'Draft a launch message.',
|
|
17
|
+
});
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
`quickRun` is intentionally ephemeral: it does not create a Room, durable
|
|
21
|
+
events or approvals. Pass a Room repository in `rooms` to `createAgentplat`
|
|
22
|
+
when building a governed Agent Room platform.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { AgentPlatID, JsonObject, Metadata, TenantContext } from '@agentplat/core';
|
|
2
|
+
import type { ModelAdapter } from '@agentplat/model';
|
|
3
|
+
import { RoomService } from '@agentplat/rooms';
|
|
4
|
+
import type { RoomServiceOptions } from '@agentplat/rooms';
|
|
5
|
+
import type { AgentProvider, AgentRunInput, AgentRunResult, AgentRuntime, AgentStreamEvent } from '@agentplat/runtime';
|
|
6
|
+
/** Options used to assemble a high-level AgentPlat client. */
|
|
7
|
+
export interface CreateAgentPlatOptions {
|
|
8
|
+
/** Direct model adapter wrapped in a one-generation ChatAgentProvider. */
|
|
9
|
+
adapter?: ModelAdapter;
|
|
10
|
+
/** Full agent provider for custom loops, handoffs or orchestration. */
|
|
11
|
+
provider?: AgentProvider;
|
|
12
|
+
/** Reuse an existing runtime registry instead of creating one. */
|
|
13
|
+
runtime?: AgentRuntime;
|
|
14
|
+
/** Registry key for the supplied adapter/provider. Defaults to `chat`. */
|
|
15
|
+
platform?: string;
|
|
16
|
+
/** Defaults to the isolated local tenant. */
|
|
17
|
+
tenant?: TenantContext;
|
|
18
|
+
/** Execution-only credentials. They are never placed in result metadata. */
|
|
19
|
+
credentials?: Record<string, string>;
|
|
20
|
+
/** Optional governed Room service configuration using the same runtime. */
|
|
21
|
+
rooms?: Omit<RoomServiceOptions, 'runtime'>;
|
|
22
|
+
idGenerator?: () => AgentPlatID;
|
|
23
|
+
clock?: () => Date;
|
|
24
|
+
}
|
|
25
|
+
/** Input accepted by the ephemeral quick-run facade. */
|
|
26
|
+
export interface QuickRunInput {
|
|
27
|
+
instructions: string;
|
|
28
|
+
input: AgentRunInput['input'];
|
|
29
|
+
name?: string;
|
|
30
|
+
description?: string;
|
|
31
|
+
agentId?: AgentPlatID;
|
|
32
|
+
runId?: AgentPlatID;
|
|
33
|
+
modelName?: string;
|
|
34
|
+
config?: JsonObject;
|
|
35
|
+
metadata?: Metadata;
|
|
36
|
+
signal?: AbortSignal;
|
|
37
|
+
}
|
|
38
|
+
/** Static quick-run input including its model adapter and local context. */
|
|
39
|
+
export interface StaticQuickRunInput extends QuickRunInput {
|
|
40
|
+
adapter: ModelAdapter;
|
|
41
|
+
tenantId?: AgentPlatID;
|
|
42
|
+
credentials?: Record<string, string>;
|
|
43
|
+
platform?: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Lightweight application facade over the public runtime and Room services.
|
|
47
|
+
* Infrastructure objects remain accessible so applications are not locked
|
|
48
|
+
* into this convenience layer.
|
|
49
|
+
*/
|
|
50
|
+
export declare class AgentPlatFramework {
|
|
51
|
+
readonly runtime: AgentRuntime;
|
|
52
|
+
readonly rooms?: RoomService;
|
|
53
|
+
readonly tenant: TenantContext;
|
|
54
|
+
private readonly platform;
|
|
55
|
+
private readonly credentials?;
|
|
56
|
+
private readonly idGenerator;
|
|
57
|
+
private readonly clock;
|
|
58
|
+
constructor(options?: CreateAgentPlatOptions);
|
|
59
|
+
/** Execute a single ephemeral agent run with safe, tool-free defaults. */
|
|
60
|
+
quickRun(input: QuickRunInput): Promise<AgentRunResult>;
|
|
61
|
+
/** Stream a single ephemeral agent run as normalized runtime events. */
|
|
62
|
+
stream(input: QuickRunInput): AsyncIterable<AgentStreamEvent>;
|
|
63
|
+
private execution;
|
|
64
|
+
}
|
|
65
|
+
/** Create a reusable framework facade. */
|
|
66
|
+
export declare function createAgentplat(options?: CreateAgentPlatOptions): AgentPlatFramework;
|
|
67
|
+
/** Minimal stateless entry point for prototypes and examples. */
|
|
68
|
+
export declare const AgentPlat: {
|
|
69
|
+
create: typeof createAgentplat;
|
|
70
|
+
quickRun(input: StaticQuickRunInput): Promise<AgentRunResult>;
|
|
71
|
+
stream(input: StaticQuickRunInput): AsyncIterable<AgentStreamEvent>;
|
|
72
|
+
};
|
|
73
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],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from '@agentplat/core';
|
|
2
|
+
import { RoomService } from '@agentplat/rooms';
|
|
3
|
+
import { ChatAgentProvider, DefaultAgentRuntime } from '@agentplat/runtime';
|
|
4
|
+
const quickRunPolicies = {
|
|
5
|
+
mode: 'quick_run',
|
|
6
|
+
tools: 'denied',
|
|
7
|
+
externalWrites: 'denied',
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Lightweight application facade over the public runtime and Room services.
|
|
11
|
+
* Infrastructure objects remain accessible so applications are not locked
|
|
12
|
+
* into this convenience layer.
|
|
13
|
+
*/
|
|
14
|
+
export class AgentPlatFramework {
|
|
15
|
+
runtime;
|
|
16
|
+
rooms;
|
|
17
|
+
tenant;
|
|
18
|
+
platform;
|
|
19
|
+
credentials;
|
|
20
|
+
idGenerator;
|
|
21
|
+
clock;
|
|
22
|
+
constructor(options = {}) {
|
|
23
|
+
if (options.adapter && options.provider) {
|
|
24
|
+
throw new AgentPlatError('VALIDATION_ERROR', 'Configure either a model adapter or an agent provider, not both');
|
|
25
|
+
}
|
|
26
|
+
this.platform = normalizedPlatform(options.platform ?? 'chat');
|
|
27
|
+
this.tenant = options.tenant ?? { tenantId: 'local' };
|
|
28
|
+
if (!this.tenant.tenantId?.trim()) {
|
|
29
|
+
throw new AgentPlatError('VALIDATION_ERROR', 'tenant.tenantId is required');
|
|
30
|
+
}
|
|
31
|
+
this.runtime = options.runtime ?? new DefaultAgentRuntime();
|
|
32
|
+
this.credentials = options.credentials
|
|
33
|
+
? { ...options.credentials }
|
|
34
|
+
: undefined;
|
|
35
|
+
this.idGenerator =
|
|
36
|
+
options.idGenerator ?? (() => globalThis.crypto.randomUUID());
|
|
37
|
+
this.clock = options.clock ?? (() => new Date());
|
|
38
|
+
const provider = options.adapter
|
|
39
|
+
? new ChatAgentProvider(options.adapter)
|
|
40
|
+
: options.provider;
|
|
41
|
+
if (provider)
|
|
42
|
+
this.runtime.registerProvider(this.platform, provider);
|
|
43
|
+
if (options.rooms) {
|
|
44
|
+
this.rooms = new RoomService({
|
|
45
|
+
...options.rooms,
|
|
46
|
+
runtime: this.runtime,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/** Execute a single ephemeral agent run with safe, tool-free defaults. */
|
|
51
|
+
async quickRun(input) {
|
|
52
|
+
const execution = this.execution(input);
|
|
53
|
+
return this.runtime.run(execution.agent, execution.input, execution.context);
|
|
54
|
+
}
|
|
55
|
+
/** Stream a single ephemeral agent run as normalized runtime events. */
|
|
56
|
+
stream(input) {
|
|
57
|
+
const execution = this.execution(input);
|
|
58
|
+
return this.runtime.stream(execution.agent, execution.input, execution.context);
|
|
59
|
+
}
|
|
60
|
+
execution(input) {
|
|
61
|
+
required(input.instructions, 'instructions');
|
|
62
|
+
if (typeof input.input !== 'string' &&
|
|
63
|
+
(!Array.isArray(input.input) || input.input.length === 0)) {
|
|
64
|
+
throw new AgentPlatError('VALIDATION_ERROR', 'input is required');
|
|
65
|
+
}
|
|
66
|
+
const now = this.clock().toISOString();
|
|
67
|
+
const agentId = input.agentId ?? this.idGenerator();
|
|
68
|
+
const runId = input.runId ?? this.idGenerator();
|
|
69
|
+
const agent = {
|
|
70
|
+
id: agentId,
|
|
71
|
+
tenantId: this.tenant.tenantId,
|
|
72
|
+
name: input.name?.trim() || 'AgentPlat quick agent',
|
|
73
|
+
description: input.description,
|
|
74
|
+
instructions: input.instructions.trim(),
|
|
75
|
+
platform: this.platform,
|
|
76
|
+
modelName: input.modelName,
|
|
77
|
+
config: input.config,
|
|
78
|
+
metadata: input.metadata,
|
|
79
|
+
createdAt: now,
|
|
80
|
+
updatedAt: now,
|
|
81
|
+
};
|
|
82
|
+
return {
|
|
83
|
+
agent,
|
|
84
|
+
input: {
|
|
85
|
+
input: input.input,
|
|
86
|
+
mode: 'invoke',
|
|
87
|
+
metadata: input.metadata,
|
|
88
|
+
},
|
|
89
|
+
context: {
|
|
90
|
+
tenant: this.tenant,
|
|
91
|
+
runId,
|
|
92
|
+
agentId,
|
|
93
|
+
signal: input.signal,
|
|
94
|
+
credentials: this.credentials,
|
|
95
|
+
policies: quickRunPolicies,
|
|
96
|
+
metadata: input.metadata,
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/** Create a reusable framework facade. */
|
|
102
|
+
export function createAgentplat(options = {}) {
|
|
103
|
+
return new AgentPlatFramework(options);
|
|
104
|
+
}
|
|
105
|
+
/** Minimal stateless entry point for prototypes and examples. */
|
|
106
|
+
export const AgentPlat = {
|
|
107
|
+
create: createAgentplat,
|
|
108
|
+
async quickRun(input) {
|
|
109
|
+
const { adapter, tenantId = 'local', credentials, platform, ...run } = input;
|
|
110
|
+
return createAgentplat({
|
|
111
|
+
adapter,
|
|
112
|
+
tenant: { tenantId },
|
|
113
|
+
credentials,
|
|
114
|
+
platform,
|
|
115
|
+
}).quickRun(run);
|
|
116
|
+
},
|
|
117
|
+
stream(input) {
|
|
118
|
+
const { adapter, tenantId = 'local', credentials, platform, ...run } = input;
|
|
119
|
+
return createAgentplat({
|
|
120
|
+
adapter,
|
|
121
|
+
tenant: { tenantId },
|
|
122
|
+
credentials,
|
|
123
|
+
platform,
|
|
124
|
+
}).stream(run);
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
function normalizedPlatform(value) {
|
|
128
|
+
const platform = value.trim().toLowerCase();
|
|
129
|
+
if (!platform) {
|
|
130
|
+
throw new AgentPlatError('VALIDATION_ERROR', 'platform is required');
|
|
131
|
+
}
|
|
132
|
+
return platform;
|
|
133
|
+
}
|
|
134
|
+
function required(value, field) {
|
|
135
|
+
if (typeof value !== 'string' || !value.trim()) {
|
|
136
|
+
throw new AgentPlatError('VALIDATION_ERROR', `${field} is required`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"A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,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC;QAC/C,MAAM,IAAI,cAAc,CAAC,kBAAkB,EAAE,GAAG,KAAK,cAAc,CAAC,CAAC;IACvE,CAAC;AACH,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agentplat/framework",
|
|
3
|
+
"version": "0.2.0-beta.1",
|
|
4
|
+
"description": "Lightweight high-level composition and quick-run facade for AgentPlat.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"README.md"
|
|
19
|
+
],
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@agentplat/core": "^0.2.0-beta.1",
|
|
22
|
+
"@agentplat/model": "^0.2.0-beta.1",
|
|
23
|
+
"@agentplat/rooms": "^0.2.0-beta.1",
|
|
24
|
+
"@agentplat/runtime": "^0.2.0-beta.1"
|
|
25
|
+
},
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "git+https://github.com/Agentplat/agentplat.git",
|
|
32
|
+
"directory": "packages/framework"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tsc -p tsconfig.json",
|
|
36
|
+
"type-check": "tsc -p tsconfig.json --noEmit",
|
|
37
|
+
"clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\""
|
|
38
|
+
}
|
|
39
|
+
}
|